Rearrange symbol_create parameters
[deliverable/binutils-gdb.git] / gas / config / tc-nios2.c
index 372d550c366d941ade5ac3b0bbe6fec5656a7000..a8bbe5bf1b626357d8e6c3fdc5b587e9e253495e 100644 (file)
@@ -1,5 +1,5 @@
 /* Altera Nios II assembler.
-   Copyright (C) 2012-2017 Free Software Foundation, Inc.
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
    Contributed by Nigel Gray (ngray@altera.com).
    Contributed by Mentor Graphics, Inc.
 
@@ -184,20 +184,20 @@ typedef struct nios2_ps_insn_info
 } nios2_ps_insn_infoS;
 
 /* Opcode hash table.  */
-static struct hash_control *nios2_opcode_hash = NULL;
+static htab_t nios2_opcode_hash = NULL;
 #define nios2_opcode_lookup(NAME) \
-  ((struct nios2_opcode *) hash_find (nios2_opcode_hash, (NAME)))
+  ((struct nios2_opcode *) str_hash_find (nios2_opcode_hash, (NAME)))
 
 /* Register hash table.  */
-static struct hash_control *nios2_reg_hash = NULL;
+static htab_t nios2_reg_hash = NULL;
 #define nios2_reg_lookup(NAME) \
-  ((struct nios2_reg *) hash_find (nios2_reg_hash, (NAME)))
+  ((struct nios2_reg *) str_hash_find (nios2_reg_hash, (NAME)))
 
 
 /* Pseudo-op hash table.  */
-static struct hash_control *nios2_ps_hash = NULL;
+static htab_t nios2_ps_hash = NULL;
 #define nios2_ps_lookup(NAME) \
-  ((nios2_ps_insn_infoS *) hash_find (nios2_ps_hash, (NAME)))
+  ((nios2_ps_insn_infoS *) str_hash_find (nios2_ps_hash, (NAME)))
 
 /* The known current alignment of the current section.  */
 static int nios2_current_align;
@@ -1384,7 +1384,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
            nios2_diagnose_overflow (fixup, howto, fixP, value);
 
          /* Apply the right shift.  */
-         fixup = ((signed)fixup) >> howto->rightshift;
+         fixup = (offsetT) fixup >> howto->rightshift;
 
          /* Truncate the fixup to right size.  */
          switch (fixP->fx_r_type)
@@ -1396,13 +1396,11 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
              fixup = fixup & 0xFFFF;
              break;
            case BFD_RELOC_NIOS2_HIADJ16:
-             fixup = ((((fixup >> 16) & 0xFFFF) + ((fixup >> 15) & 0x01))
-                      & 0xFFFF);
+             fixup = ((fixup + 0x8000) >> 16) & 0xFFFF;
              break;
            default:
              {
-               int n = sizeof (fixup) * 8 - howto->bitsize;
-               fixup = (fixup << n) >> n;
+               fixup &= ((valueT) 1 << howto->bitsize) - 1;
                break;
              }
            }
@@ -2712,7 +2710,7 @@ nios2_assemble_arg_R (const char *token, nios2_insn_infoS *insn)
          mask = (reglist & 0x00ffc000) >> 14;
          if (reglist & (1 << 28))
            mask |= 1 << 10;
-         if (reglist & (1 << 31))
+         if (reglist & (1u << 31))
            mask |= 1 << 11;
        }
       insn->insn_code |= SET_IW_F1X4L17_REGMASK (mask);
@@ -3232,11 +3230,8 @@ nios2_insert_arg (char **parsed_args, const char *insert, int num,
 static void
 nios2_free_arg (char **parsed_args, int num ATTRIBUTE_UNUSED, int start)
 {
-  if (parsed_args[start])
-    {
-      free (parsed_args[start]);
-      parsed_args[start] = NULL;
-    }
+  free (parsed_args[start]);
+  parsed_args[start] = NULL;
 }
 
 /* This function swaps the pseudo-op for a real op.  */
@@ -3608,7 +3603,6 @@ void
 md_begin (void)
 {
   int i;
-  const char *inserted;
 
   switch (nios2_architecture)
     {
@@ -3625,52 +3619,21 @@ md_begin (void)
 
   /* Create and fill a hashtable for the Nios II opcodes, registers and
      arguments.  */
-  nios2_opcode_hash = hash_new ();
-  nios2_reg_hash = hash_new ();
-  nios2_ps_hash = hash_new ();
+  nios2_opcode_hash = str_htab_create ();
+  nios2_reg_hash = str_htab_create ();
+  nios2_ps_hash = str_htab_create ();
 
   for (i = 0; i < nios2_num_opcodes; ++i)
-    {
-      inserted
-       = hash_insert (nios2_opcode_hash, nios2_opcodes[i].name,
-                      (PTR) & nios2_opcodes[i]);
-      if (inserted != NULL)
-       {
-         fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
-                  nios2_opcodes[i].name, inserted);
-         /* Probably a memory allocation problem?  Give up now.  */
-         as_fatal (_("Broken assembler.  No assembly attempted."));
-       }
-    }
+    str_hash_insert (nios2_opcode_hash, nios2_opcodes[i].name,
+                    (PTR) & nios2_opcodes[i]);
 
   for (i = 0; i < nios2_num_regs; ++i)
-    {
-      inserted
-       = hash_insert (nios2_reg_hash, nios2_regs[i].name,
-                      (PTR) & nios2_regs[i]);
-      if (inserted != NULL)
-       {
-         fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
-                  nios2_regs[i].name, inserted);
-         /* Probably a memory allocation problem?  Give up now.  */
-         as_fatal (_("Broken assembler.  No assembly attempted."));
-       }
-
-    }
+    str_hash_insert (nios2_reg_hash, nios2_regs[i].name,
+                    (PTR) & nios2_regs[i]);
 
   for (i = 0; i < nios2_num_ps_insn_info_structs; ++i)
-    {
-      inserted
-       = hash_insert (nios2_ps_hash, nios2_ps_insn_info_structs[i].pseudo_insn,
-                      (PTR) & nios2_ps_insn_info_structs[i]);
-      if (inserted != NULL)
-       {
-         fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
-                  nios2_ps_insn_info_structs[i].pseudo_insn, inserted);
-         /* Probably a memory allocation problem?  Give up now.  */
-         as_fatal (_("Broken assembler.  No assembly attempted."));
-       }
-    }
+    str_hash_insert (nios2_ps_hash, nios2_ps_insn_info_structs[i].pseudo_insn,
+                    (PTR) & nios2_ps_insn_info_structs[i]);
 
   /* Assembler option defaults.  */
   nios2_as_options.noat = FALSE;
@@ -3944,7 +3907,7 @@ md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
            as_bad ("GOT already in the symbol table");
 
          GOT_symbol = symbol_new (name, undefined_section,
-                                  (valueT) 0, &zero_address_frag);
+                                  &zero_address_frag, 0);
        }
 
       return GOT_symbol;
@@ -4013,31 +3976,48 @@ nios2_elf_section_flags (flagword flags, int attr, int type ATTRIBUTE_UNUSED)
   return flags;
 }
 
-/* Implement TC_PARSE_CONS_EXPRESSION to handle %tls_ldo(...) */
+/* Implement TC_PARSE_CONS_EXPRESSION to handle %tls_ldo(...) and
+   %gotoff(...).  */
 bfd_reloc_code_real_type
 nios2_cons (expressionS *exp, int size)
 {
-  bfd_reloc_code_real_type nios2_tls_ldo_reloc = BFD_RELOC_NONE;
+  bfd_reloc_code_real_type explicit_reloc = BFD_RELOC_NONE;
+  const char *reloc_name = NULL;
 
   SKIP_WHITESPACE ();
   if (input_line_pointer[0] == '%')
     {
       if (strprefix (input_line_pointer + 1, "tls_ldo"))
        {
+         reloc_name = "%tls_ldo";
          if (size != 4)
            as_bad (_("Illegal operands: %%tls_ldo in %d-byte data field"),
                    size);
          else
            {
              input_line_pointer += 8;
-             nios2_tls_ldo_reloc = BFD_RELOC_NIOS2_TLS_DTPREL;
+             explicit_reloc = BFD_RELOC_NIOS2_TLS_DTPREL;
            }
        }
-      if (nios2_tls_ldo_reloc != BFD_RELOC_NONE)
+      else if (strprefix (input_line_pointer + 1, "gotoff"))
+       {
+         reloc_name = "%gotoff";
+         if (size != 4)
+           as_bad (_("Illegal operands: %%gotoff in %d-byte data field"),
+                   size);
+         else
+           {
+             input_line_pointer += 7;
+             explicit_reloc = BFD_RELOC_NIOS2_GOTOFF;
+           }
+       }
+
+      if (explicit_reloc != BFD_RELOC_NONE)
        {
          SKIP_WHITESPACE ();
          if (input_line_pointer[0] != '(')
-           as_bad (_("Illegal operands: %%tls_ldo requires arguments in ()"));
+           as_bad (_("Illegal operands: %s requires arguments in ()"),
+                   reloc_name);
          else
            {
              int c;
@@ -4055,29 +4035,32 @@ nios2_cons (expressionS *exp, int size)
                  }
 
              if (c != ')')
-               as_bad (_("Illegal operands: %%tls_ldo requires arguments in ()"));
+               as_bad (_("Illegal operands: %s requires arguments in ()"),
+                       reloc_name);
              else
                {
                  *end = '\0';
                  expression (exp);
                  *end = c;
                  if (input_line_pointer != end)
-                   as_bad (_("Illegal operands: %%tls_ldo requires arguments in ()"));
+                   as_bad (_("Illegal operands: %s requires arguments in ()"),
+                           reloc_name);
                  else
                    {
                      input_line_pointer++;
                      SKIP_WHITESPACE ();
                      c = *input_line_pointer;
                      if (! is_end_of_line[c] && c != ',')
-                       as_bad (_("Illegal operands: garbage after %%tls_ldo()"));
+                       as_bad (_("Illegal operands: garbage after %s()"),
+                               reloc_name);
                    }
                }
            }
        }
     }
-  if (nios2_tls_ldo_reloc == BFD_RELOC_NONE)
+  if (explicit_reloc == BFD_RELOC_NONE)
     expression (exp);
-  return nios2_tls_ldo_reloc;
+  return explicit_reloc;
 }
 
 /* Implement HANDLE_ALIGN.  */
This page took 0.026768 seconds and 4 git commands to generate.