Rearrange symbol_create parameters
[deliverable/binutils-gdb.git] / gas / config / tc-tic4x.c
index c44201d004ac57cfaf9c30cd0c194d4da7f075b0..a6db99091d5beb2d4a7a639c76c71adf5eb65af8 100644 (file)
@@ -1,5 +1,5 @@
 /* tc-tic4x.c -- Assemble for the Texas Instruments TMS320C[34]x.
-   Copyright (C) 1997-2016 Free Software Foundation, Inc.
+   Copyright (C) 1997-2020 Free Software Foundation, Inc.
 
    Contributed by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
 
 
 #define TIC4X_ALT_SYNTAX
 
-/* Equal to MAX_PRECISION in atof-ieee.c.  */
-#define MAX_LITTLENUMS 6       /* (12 bytes) */
-
 /* Handle of the inst mnemonic hash table.  */
-static struct hash_control *tic4x_op_hash = NULL;
+static htab_t tic4x_op_hash = NULL;
 
 /* Handle asg pseudo.  */
-static struct hash_control *tic4x_asg_hash = NULL;
+static htab_t tic4x_asg_hash = NULL;
 
 static unsigned int tic4x_cpu = 0;        /* Default to TMS320C40.  */
 static unsigned int tic4x_revision = 0;   /* CPU revision */
@@ -124,7 +121,8 @@ typedef struct tic4x_insn
     unsigned int nchars;       /* This is always 4 for the C30.  */
     unsigned long opcode;      /* Opcode number.  */
     expressionS exp;           /* Expression required for relocation.  */
-    int reloc;                 /* Relocation type required.  */
+    /* Relocation type required.  */
+    bfd_reloc_code_real_type reloc;
     int pcrel;                 /* True if relocation PC relative.  */
     char *pname;               /* Name of instruction in parallel.  */
     unsigned int num_operands; /* Number of operands in total.  */
@@ -222,7 +220,7 @@ const char FLT_CHARS[] = "fFilsS";
 extern FLONUM_TYPE generic_floating_point_number;
 
 /* Precision in LittleNums.  */
-#define MAX_PRECISION (4)       /* Its a bit overkill for us, but the code
+#define MAX_PRECISION (4)       /* It's a bit overkill for us, but the code
                                    requires it... */
 #define S_PRECISION (1)                /* Short float constants 16-bit.  */
 #define F_PRECISION (2)                /* Float and double types 32-bit.  */
@@ -623,14 +621,14 @@ tic4x_insert_reg (const char *regname, int regnum)
   char buf[32];
   int i;
 
-  symbol_table_insert (symbol_new (regname, reg_section, (valueT) regnum,
-                                  &zero_address_frag));
+  symbol_table_insert (symbol_new (regname, reg_section,
+                                  &zero_address_frag, regnum));
   for (i = 0; regname[i]; i++)
     buf[i] = ISLOWER (regname[i]) ? TOUPPER (regname[i]) : regname[i];
   buf[i] = '\0';
 
-  symbol_table_insert (symbol_new (buf, reg_section, (valueT) regnum,
-                                  &zero_address_frag));
+  symbol_table_insert (symbol_new (buf, reg_section,
+                                  &zero_address_frag, regnum));
 }
 
 static void
@@ -639,7 +637,7 @@ tic4x_insert_sym (const char *symname, int value)
   symbolS *symbolP;
 
   symbolP = symbol_new (symname, absolute_section,
-                       (valueT) value, &zero_address_frag);
+                       &zero_address_frag, value);
   SF_SET_LOCAL (symbolP);
   symbol_table_insert (symbolP);
 }
@@ -729,10 +727,7 @@ tic4x_asg (int x ATTRIBUTE_UNUSED)
   c = get_symbol_name (&name); /* Get terminator.  */
   str = xstrdup (str);
   name = xstrdup (name);
-  if (hash_find (tic4x_asg_hash, name))
-    hash_replace (tic4x_asg_hash, name, (void *) str);
-  else
-    hash_insert (tic4x_asg_hash, name, (void *) str);
+  str_hash_insert (tic4x_asg_hash, name, str);
   (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
@@ -902,7 +897,7 @@ tic4x_stringer (int append_zero)
               as_bad (_("Non-constant symbols not allowed\n"));
               return;
             }
-          exp.X_add_number &= 255; /* Limit numeber to 8-bit */
+          exp.X_add_number &= 255; /* Limit number to 8-bit */
          emit_expr (&exp, 1);
           bytes++;
        }
@@ -964,8 +959,7 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
   if (c == '"')
     c = * ++ input_line_pointer;
   input_line_pointer++;                /* Skip null symbol terminator.  */
-  name = xmalloc (input_line_pointer - section_name + 1);
-  strcpy (name, section_name);
+  name = xstrdup (section_name);
 
   /* TI C from version 5.0 allows a section name to contain a
      subsection name as well. The subsection name is separated by a
@@ -1004,9 +998,9 @@ tic4x_sect (int x ATTRIBUTE_UNUSED)
       symbol_set_frag (line_label, frag_now);
     }
 
-  if (bfd_get_section_flags (stdoutput, seg) == SEC_NO_FLAGS)
+  if (bfd_section_flags (seg) == SEC_NO_FLAGS)
     {
-      if (!bfd_set_section_flags (stdoutput, seg, SEC_DATA))
+      if (!bfd_set_section_flags (seg, SEC_DATA))
        as_warn (_("Error setting flags for \"%s\": %s"), name,
                 bfd_errmsg (bfd_get_error ()));
     }
@@ -1075,8 +1069,7 @@ tic4x_usect (int x ATTRIBUTE_UNUSED)
   if (c == '"')
     c = * ++ input_line_pointer;
   input_line_pointer++;                /* Skip null symbol terminator.  */
-  name = xmalloc (input_line_pointer - section_name + 1);
-  strcpy (name, section_name);
+  name = xstrdup (section_name);
 
   if (c == ',')
     input_line_pointer =
@@ -1108,7 +1101,7 @@ tic4x_usect (int x ATTRIBUTE_UNUSED)
       S_SET_VALUE (line_label, frag_now_fix ());
     }
   seg_info (seg)->bss = 1;     /* Uninitialised data.  */
-  if (!bfd_set_section_flags (stdoutput, seg, SEC_ALLOC))
+  if (!bfd_set_section_flags (seg, SEC_ALLOC))
     as_warn (_("Error setting flags for \"%s\": %s"), name,
             bfd_errmsg (bfd_get_error ()));
   tic4x_seg_alloc (name, seg, size, line_label);
@@ -1213,23 +1206,17 @@ tic4x_init_symbols (void)
 }
 
 /* Insert a new instruction template into hash table.  */
-static int
+static void
 tic4x_inst_insert (const tic4x_inst_t *inst)
 {
   static char prev_name[16];
-  const char *retval = NULL;
 
   /* Only insert the first name if have several similar entries.  */
   if (!strcmp (inst->name, prev_name) || inst->name[0] == '\0')
-    return 1;
+    return;
 
-  retval = hash_insert (tic4x_op_hash, inst->name, (void *) inst);
-  if (retval != NULL)
-    fprintf (stderr, "internal error: can't hash `%s': %s\n",
-            inst->name, retval);
-  else
-    strcpy (prev_name, inst->name);
-  return retval == NULL;
+  str_hash_insert (tic4x_op_hash, inst->name, (void *) inst);
+  strcpy (prev_name, inst->name);
 }
 
 /* Make a new instruction template.  */
@@ -1243,10 +1230,9 @@ tic4x_inst_make (const char *name, unsigned long opcode, const char *args)
   if (insts == NULL)
     {
       /* Allocate memory to store name strings.  */
-      names = (char *) xmalloc (sizeof (char) * 8192);
+      names = XNEWVEC (char, 8192);
       /* Allocate memory for additional insts.  */
-      insts = (tic4x_inst_t *)
-       xmalloc (sizeof (tic4x_inst_t) * 1024);
+      insts = XNEWVEC (tic4x_inst_t, 1024);
     }
   insts[iindex].name = names;
   insts[iindex].opcode = opcode;
@@ -1263,13 +1249,12 @@ tic4x_inst_make (const char *name, unsigned long opcode, const char *args)
 }
 
 /* Add instruction template, creating dynamic templates as required.  */
-static int
+static void
 tic4x_inst_add (const tic4x_inst_t *insts)
 {
   const char *s = insts->name;
   char *d;
   unsigned int i;
-  int ok = 1;
   char name[16];
 
   d = name;
@@ -1277,7 +1262,7 @@ tic4x_inst_add (const tic4x_inst_t *insts)
   /* We do not care about INSNs that is not a part of our
      oplevel setting.  */
   if ((insts->oplevel & tic4x_oplevel) == 0)
-    return ok;
+    return;
 
   while (1)
     {
@@ -1301,8 +1286,8 @@ tic4x_inst_add (const tic4x_inst_t *insts)
              *e = '\0';
 
              /* If instruction found then have already processed it.  */
-             if (hash_find (tic4x_op_hash, name))
-               return 1;
+             if (str_hash_find (tic4x_op_hash, name))
+               return;
 
              do
                {
@@ -1311,18 +1296,17 @@ tic4x_inst_add (const tic4x_inst_t *insts)
                                         (*s == 'B' ? 16 : 23)),
                                        insts[k].args);
                  if (k == 0)   /* Save strcmp() with following func.  */
-                   ok &= tic4x_inst_insert (inst);
+                   tic4x_inst_insert (inst);
                  k++;
                }
              while (!strcmp (insts->name,
                              insts[k].name));
            }
-         return ok;
-         break;
+         return;
 
        case '\0':
-         return tic4x_inst_insert (insts);
-         break;
+         tic4x_inst_insert (insts);
+         return;
 
        default:
          *d++ = *s++;
@@ -1337,7 +1321,6 @@ tic4x_inst_add (const tic4x_inst_t *insts)
 void
 md_begin (void)
 {
-  int ok = 1;
   unsigned int i;
 
   /* Setup the proper opcode level according to the
@@ -1369,21 +1352,18 @@ md_begin (void)
     tic4x_oplevel |= OP_IDLE2;
 
   /* Create hash table for mnemonics.  */
-  tic4x_op_hash = hash_new ();
+  tic4x_op_hash = str_htab_create ();
 
   /* Create hash table for asg pseudo.  */
-  tic4x_asg_hash = hash_new ();
+  tic4x_asg_hash = str_htab_create ();
 
   /* Add mnemonics to hash table, expanding conditional mnemonics on fly.  */
   for (i = 0; i < tic4x_num_insts; i++)
-    ok &= tic4x_inst_add (tic4x_insts + i);
+    tic4x_inst_add (tic4x_insts + i);
 
   /* Create dummy inst to avoid errors accessing end of table.  */
   tic4x_inst_make ("", 0, "");
 
-  if (!ok)
-    as_fatal ("Broken assembler.  No assembly attempted.");
-
   /* Add registers to symbol table.  */
   tic4x_init_regtable ();
 
@@ -1514,7 +1494,7 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
 
   c = get_symbol_name (&str);  /* Get terminator.  */
   new_pointer = input_line_pointer;
-  if (strlen (str) && (entry = hash_find (tic4x_asg_hash, str)) != NULL)
+  if (strlen (str) && (entry = str_hash_find (tic4x_asg_hash, str)) != NULL)
     {
       (void) restore_line_pointer (c);
       input_line_pointer = (char *) entry;
@@ -1555,10 +1535,10 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
       /* Allow ori ^foo, ar0 to be equivalent to ldi .hi.foo, ar0  */
       /* WARNING : The TI C40 assembler cannot do this.  */
       else if (exp->X_op == O_symbol)
-       {
-         operand->mode = M_HI;
-         break;
-       }
+       operand->mode = M_HI;
+      else
+       as_bad (_("Expecting a constant value"));
+      break;
 
     case '#':
       input_line_pointer = tic4x_expression (++input_line_pointer, exp);
@@ -1578,14 +1558,11 @@ tic4x_operand_parse (char *s, tic4x_operand_t *operand)
       /* Allow ori foo, ar0 to be equivalent to ldi .lo.foo, ar0  */
       /* WARNING : The TI C40 assembler cannot do this.  */
       else if (exp->X_op == O_symbol)
-       {
-         operand->mode = M_IMMED;
-         break;
-       }
-
+       operand->mode = M_IMMED;
       else
        as_bad (_("Expecting a constant value"));
       break;
+
     case '\\':
 #endif
     case '@':
@@ -2201,7 +2178,7 @@ tic4x_operands_match (tic4x_inst_t *inst, tic4x_insn_t *tinsn, int check)
                }
              else if (exp->X_add_number < 32 && IS_CPU_TIC3X (tic4x_cpu))
                {
-                 INSERTU (opcode, exp->X_add_number | 0x20, 4, 0);
+                 INSERTU (opcode, exp->X_add_number | 0x20, 5, 0);
                  continue;
                }
              else
@@ -2358,7 +2335,7 @@ tic4x_insn_check (tic4x_insn_t *tinsn)
       if (tinsn->operands[1].mode == M_REGISTER
          && tinsn->operands[tinsn->num_operands-1].mode == M_REGISTER
          && tinsn->operands[1].expr.X_add_number == tinsn->operands[tinsn->num_operands-1].expr.X_add_number )
-        as_warn (_("Equal parallell destination registers, one result will be discarded"));
+        as_warn (_("Equal parallel destination registers, one result will be discarded"));
     }
 }
 
@@ -2452,7 +2429,7 @@ md_assemble (char *str)
       /* Skip past instruction mnemonic.  */
       while (*s && *s != ' ')
        s++;
-      if (*s)                  /* Null terminate for hash_find.  */
+      if (*s)                  /* Null terminate for str_hash_find.  */
        *s++ = '\0';            /* and skip past null.  */
       len = strlen (insn->name);
       snprintf (insn->name + len, TIC4X_NAME_MAX - len, "_%s", str);
@@ -2473,7 +2450,7 @@ md_assemble (char *str)
   if (insn->in_use)
     {
       if ((insn->inst = (struct tic4x_inst *)
-          hash_find (tic4x_op_hash, insn->name)) == NULL)
+          str_hash_find (tic4x_op_hash, insn->name)) == NULL)
        {
          as_bad (_("Unknown opcode `%s'."), insn->name);
          insn->parallel = 0;
@@ -2492,7 +2469,8 @@ md_assemble (char *str)
                 first_inst = inst;
               ok = 0;
             }
-      } while (!ok && !strcmp (inst->name, inst[1].name) && inst++);
+       }
+      while (!ok && !strcmp (inst->name, inst[1].name) && inst++);
 
       if (ok > 0)
         {
@@ -2515,7 +2493,7 @@ md_assemble (char *str)
       s = str;
       while (*s && *s != ' ')  /* Skip past instruction mnemonic.  */
        s++;
-      if (*s)                  /* Null terminate for hash_find.  */
+      if (*s)                  /* Null terminate for str_hash_find.  */
        *s++ = '\0';            /* and skip past null.  */
       strncpy (insn->name, str, TIC4X_NAME_MAX - 1);
       insn->name[TIC4X_NAME_MAX - 1] = '\0';
@@ -2643,9 +2621,11 @@ md_apply_fix (fixS *fixP, valueT *value, segT seg ATTRIBUTE_UNUSED)
     {
     case BFD_RELOC_32:
       buf[3] = val >> 24;
+      /* Fall through.  */
     case BFD_RELOC_24:
     case BFD_RELOC_24_PCREL:
       buf[2] = val >> 16;
+      /* Fall through.  */
     case BFD_RELOC_16:
     case BFD_RELOC_16_PCREL:
     case BFD_RELOC_LO16:
@@ -2723,24 +2703,28 @@ md_parse_option (int c, const char *arg)
 
     case 'b':
       as_warn (_("Option -b is depreciated, please use -mbig"));
+      /* Fall through.  */
     case OPTION_BIG:             /* big model */
       tic4x_big_model = 1;
       break;
 
     case 'p':
       as_warn (_("Option -p is depreciated, please use -mmemparm"));
+      /* Fall through.  */
     case OPTION_MEMPARM:         /* push args */
       tic4x_reg_args = 0;
       break;
 
     case 'r':
       as_warn (_("Option -r is depreciated, please use -mregparm"));
+      /* Fall through.  */
     case OPTION_REGPARM:        /* register args */
       tic4x_reg_args = 1;
       break;
 
     case 's':
       as_warn (_("Option -s is depreciated, please use -msmall"));
+      /* Fall through.  */
     case OPTION_SMALL:         /* small model */
       tic4x_big_model = 0;
       break;
@@ -2938,7 +2922,7 @@ md_pcrel_from (fixS *fixP)
   unsigned int op;
 
   buf = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
-  op = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+  op = ((unsigned) buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
 
   return ((fixP->fx_where + fixP->fx_frag->fr_address) >> 2) +
     tic4x_pc_offset (op);
@@ -3013,9 +2997,9 @@ tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixP)
 {
   arelent *reloc;
 
-  reloc = (arelent *) xmalloc (sizeof (arelent));
+  reloc = XNEW (arelent);
 
-  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
+  reloc->sym_ptr_ptr = XNEW (asymbol *);
   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy);
   reloc->address = fixP->fx_frag->fr_address + fixP->fx_where;
   reloc->address /= OCTETS_PER_BYTE;
This page took 0.03226 seconds and 4 git commands to generate.