<commit_before>/* tc-riscv.c -- RISC-V assembler
   Copyright 2011-2015 Free Software Foundation, Inc.

   Contributed by <NAME> (<EMAIL>) at UC Berkeley.
   Based on MIPS target.

   This file is part of GAS.

   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING3. If not,
   see <http://www.gnu.org/licenses/>.  */

#include "as.h"
#include "config.h"
#include "subsegs.h"
#include "safe-ctype.h"

#include "itbl-ops.h"
#include "dwarf2dbg.h"
#include "dw2gencfi.h"

#include "elf/riscv.h"
#include "opcode/riscv.h"

#include <execinfo.h>
#include <stdint.h>

/* Information about an instruction, including its format, operands
   and fixups.  */
struct riscv_cl_insn
{
  /* The opcode's entry in riscv_opcodes.  */
  const struct riscv_opcode *insn_mo;

  /* The encoded instruction bits.  */
  insn_t insn_opcode;

  /* The frag that contains the instruction.  */
  struct frag *frag;

  /* The offset into FRAG of the first instruction byte.  */
  long where;

  /* The relocs associated with the instruction, if any.  */
  fixS *fixp;
};

/* The default architecture.  */
#ifndef DEFAULT_ARCH
#define DEFAULT_ARCH "riscv64"
#endif
static const char default_arch[] = DEFAULT_ARCH;

unsigned xlen = 0; /* width of an x-register */
#define LOAD_ADDRESS_INSN (xlen == 64 ? "ld" : "lw")
#define ADD32_INSN (xlen == 64 ? "addiw" : "addi")

static unsigned elf_flags = 0;

/* This is the set of options which the .option pseudo-op may modify.  */

struct riscv_set_options
{
  int pic; /* Generate position-independent code.  */
  int rvc; /* Generate RVC code.  */
};

static struct riscv_set_options riscv_opts =
{
  0,	/* pic */
  0,	/* rvc */
};

static void
riscv_set_rvc (bfd_boolean rvc_value)
{
  if (rvc_value)
    elf_flags |= EF_RISCV_RVC;

  riscv_opts.rvc = rvc_value;
}

struct riscv_subset
{
  const char *name;
  int version_major;
  int version_minor;

  struct riscv_subset *next;
};

static struct riscv_subset *riscv_subsets;

static bfd_boolean
riscv_subset_supports (const char *feature)
{
  struct riscv_subset *s;
  char *p;
  unsigned xlen_required = strtoul (feature, &p, 10);

  if (xlen_required && xlen != xlen_required)
    return FALSE;

  for (s = riscv_subsets; s != NULL; s = s->next)
    if (strcmp (s->name, p) == 0)
      /* FIXME: once we support version numbers:
	 return major == s->version_major && minor <= s->version_minor; */
      return TRUE;

  return FALSE;
}

static void
riscv_add_subset (const char *subset)
{
  struct riscv_subset *s = xmalloc (sizeof *s);
  s->name = xstrdup (subset);
  s->version_major = 1;
  s->version_minor = 0;
  s->next = riscv_subsets;
  riscv_subsets = s;
}

/* Set which ISA and extensions are available.  Formally, ISA strings must
   begin with RV32 or RV64, but we allow the prefix to be omitted.

   FIXME: Version numbers are not supported yet.  */
static void
riscv_set_arch (const char *arg)
{
  char *uppercase = xstrdup (arg);
  char *p = uppercase;
  const char *all_subsets = "IMAFDC";
  const char *extension = NULL;<commit_msg>Handle lower-case ISA strings<commit_after>/* tc-riscv.c -- RISC-V assembler
   Copyright 2011-2015 Free Software Foundation, Inc.

   Contributed by <NAME> (<EMAIL>) at UC Berkeley.
   Based on MIPS target.

   This file is part of GAS.

   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING3. If not,
   see <http://www.gnu.org/licenses/>.  */

#include "as.h"
#include "config.h"
#include "subsegs.h"
#include "safe-ctype.h"

#include "itbl-ops.h"
#include "dwarf2dbg.h"
#include "dw2gencfi.h"

#include "elf/riscv.h"
#include "opcode/riscv.h"

#include <execinfo.h>
#include <stdint.h>

/* Information about an instruction, including its format, operands
   and fixups.  */
struct riscv_cl_insn
{
  /* The opcode's entry in riscv_opcodes.  */
  const struct riscv_opcode *insn_mo;

  /* The encoded instruction bits.  */
  insn_t insn_opcode;

  /* The frag that contains the instruction.  */
  struct frag *frag;

  /* The offset into FRAG of the first instruction byte.  */
  long where;

  /* The relocs associated with the instruction, if any.  */
  fixS *fixp;
};

/* The default architecture.  */
#ifndef DEFAULT_ARCH
#define DEFAULT_ARCH "riscv64"
#endif
static const char default_arch[] = DEFAULT_ARCH;

unsigned xlen = 0; /* width of an x-register */
#define LOAD_ADDRESS_INSN (xlen == 64 ? "ld" : "lw")
#define ADD32_INSN (xlen == 64 ? "addiw" : "addi")

static unsigned elf_flags = 0;

/* This is the set of options which the .option pseudo-op may modify.  */

struct riscv_set_options
{
  int pic; /* Generate position-independent code.  */
  int rvc; /* Generate RVC code.  */
};

static struct riscv_set_options riscv_opts =
{
  0,	/* pic */
  0,	/* rvc */
};

static void
riscv_set_rvc (bfd_boolean rvc_value)
{
  if (rvc_value)
    elf_flags |= EF_RISCV_RVC;

  riscv_opts.rvc = rvc_value;
}

struct riscv_subset
{
  const char *name;
  int version_major;
  int version_minor;

  struct riscv_subset *next;
};

static struct riscv_subset *riscv_subsets;

static bfd_boolean
riscv_subset_supports (const char *feature)
{
  struct riscv_subset *s;
  char *p;
  unsigned xlen_required = strtoul (feature, &p, 10);

  if (xlen_required && xlen != xlen_required)
    return FALSE;

  for (s = riscv_subsets; s != NULL; s = s->next)
    if (strcasecmp (s->name, p) == 0)
      /* FIXME: once we support version numbers:
	 return major == s->version_major && minor <= s->version_minor; */
      return TRUE;

  return FALSE;
}

static void
riscv_add_subset (const char *subset)
{
  struct riscv_subset *s = xmalloc (sizeof *s);
  s->name = xstrdup (subset);
  s->version_major = 1;
  s->version_minor = 0;
  s->next = riscv_subsets;
  riscv_subsets = s;
}

/* Set which ISA and extensions are available.  Formally, ISA strings must
   begin with RV32 or RV64, but we allow the prefix to be omitted.

   FIXME: Version numbers are not supported yet.  */
static void
riscv_set_arch (const char *arg)
{
  char *uppercase = xstrdup (arg);
  char *p = uppercase;
  const char *all_subsets = "IMAFDC";
  const char *extension = NULL;
{'fraction_non_alphanumeric': 0.10348216793035664, 'fraction_numerical': 0.009267059814658803, 'mean_word_length': 3.4602379461490296, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5806322', 'n_tokens_mistral': 2491, 'n_tokens_neox': 2444, 'n_words': 852}