Update year range in copyright notice of binutils files
[deliverable/binutils-gdb.git] / gas / config / tc-dlx.c
index ac0aabae622ba7d9a7a0a91b7b6e28e5d5608564..34a1d461a9e415d5c75912748a0994b61e789c4b 100644 (file)
@@ -1,11 +1,11 @@
-/* tc-ldx.c -- Assemble for the DLX
-   Copyright 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+/* tc-dlx.c -- Assemble for the DLX
+   Copyright (C) 2002-2018 Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
 
    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 2, or (at your option)
+   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,
 
 /* Initially created by Kuang Hwa Lin, 3/20/2002.  */
 
-#include "safe-ctype.h"
 #include "as.h"
+#include "safe-ctype.h"
 #include "tc-dlx.h"
 #include "opcode/dlx.h"
+#include "elf/dlx.h"
+#include "bfd/elf32-dlx.h"
 
 /* Make it easier to clone this machine desc into another one.  */
 #define        machine_opcode      dlx_opcode
@@ -52,7 +54,7 @@ struct machine_it
   int pcrel;
   int size;
   int reloc_offset;            /* Offset of reloc within insn.  */
-  int reloc;
+  bfd_reloc_code_real_type reloc;
   int HI;
   int LO;
 }
@@ -84,7 +86,7 @@ const char EXP_CHARS[] = "eE";
 const char FLT_CHARS[] = "rRsSfFdDxXpP";
 
 static void
-insert_sreg (char *regname, int regnum)
+insert_sreg (const char *regname, int regnum)
 {
   /* Must be large enough to hold the names of the special registers.  */
   char buf[80];
@@ -153,7 +155,7 @@ match_sft_register (char *name)
 #define MAX_REG_NO  35
 /* Currently we have 35 software registers defined -
    we borrowed from MIPS.   */
-  static char *soft_reg[] =
+  static const char *soft_reg[] =
     {
       "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
       "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8", "t9",
@@ -230,11 +232,10 @@ s_proc (int end_p)
          return;
        }
 
-      name = input_line_pointer;
-      delim1 = get_symbol_end ();
+      delim1 = get_symbol_name (&name);
       name = xstrdup (name);
       *input_line_pointer = delim1;
-      SKIP_WHITESPACE ();
+      SKIP_WHITESPACE_AFTER_NAME ();
 
       if (*input_line_pointer != ',')
        {
@@ -244,7 +245,12 @@ s_proc (int end_p)
          /* Missing entry point, use function's name with the leading
             char prepended.  */
          if (leading_char)
-           asprintf (&label, "%c%s", leading_char, name);
+           {
+             unsigned len = strlen (name) + 1;
+             label = XNEWVEC (char, len + 1);
+             label[0] = leading_char;
+             memcpy (label + 1, name, len);
+           }
          else
            label = name;
        }
@@ -252,10 +258,9 @@ s_proc (int end_p)
        {
          ++input_line_pointer;
          SKIP_WHITESPACE ();
-         label = input_line_pointer;
-         delim2 = get_symbol_end ();
+         delim2 = get_symbol_name (&label);
          label = xstrdup (label);
-         *input_line_pointer = delim2;
+         (void) restore_line_pointer (delim2);
        }
 
       current_name = name;
@@ -287,7 +292,7 @@ md_begin (void)
 
       if (retval != NULL)
        {
-         fprintf (stderr, "internal error: can't hash `%s': %s\n",
+         fprintf (stderr, _("internal error: can't hash `%s': %s\n"),
                   machine_opcodes[i].name, retval);
          lose = 1;
        }
@@ -594,7 +599,7 @@ static char *
 parse_operand (char *s, expressionS *operandp)
 {
   char *save = input_line_pointer;
-  char *new;
+  char *new_pos;
 
   the_insn.HI = the_insn.LO = 0;
 
@@ -641,9 +646,9 @@ parse_operand (char *s, expressionS *operandp)
       (void) expression (operandp);
     }
 
-  new = input_line_pointer;
+  new_pos = input_line_pointer;
   input_line_pointer = save;
-  return new;
+  return new_pos;
 }
 
 /* Instruction parsing.  Takes a string containing the opcode.
@@ -656,12 +661,14 @@ machine_ip (char *str)
   char *s;
   const char *args;
   struct machine_opcode *insn;
-  char *argsStart;
   unsigned long opcode;
   expressionS the_operand;
   expressionS *operand = &the_operand;
   unsigned int reg, reg_shift = 0;
 
+  memset (&the_insn, '\0', sizeof (the_insn));
+  the_insn.reloc = NO_RELOC;
+
   /* Fixup the opcode string to all lower cases, and also
      allow numerical digits.  */
   s = str;
@@ -686,30 +693,19 @@ machine_ip (char *str)
       return;
     }
 
-  /* Hash the opcode, insn will have the string from opcode table.
-     also initialized the_insn struct.  */
+  /* Hash the opcode, insn will have the string from opcode table.  */
   if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
     {
       /* Handle the ret and return macro here.  */
       if ((strcmp (str, "ret") == 0) || (strcmp (str, "return") == 0))
-       {
-         memset (&the_insn, '\0', sizeof (the_insn));
-         the_insn.reloc = NO_RELOC;
-         the_insn.pcrel = 0;
-         the_insn.opcode =
-           (unsigned long)(JROP | 0x03e00000);    /* 0x03e00000 = r31 << 21 */
-       }
+       the_insn.opcode = JROP | 0x03e00000;    /* 0x03e00000 = r31 << 21 */
       else
        as_bad (_("Unknown opcode `%s'."), str);
 
       return;
     }
 
-  argsStart = s;
   opcode = insn->opcode;
-  memset (&the_insn, '\0', sizeof (the_insn));
-  the_insn.reloc = NO_RELOC;
-  the_insn.pcrel = 0;
 
   /* Set the sip reloc HI16 flag.  */
   if (!set_dlx_skip_hi16_flag (1))
@@ -780,10 +776,11 @@ machine_ip (char *str)
          /* Macro move operand/reg.  */
          if (operand->X_op == O_register)
            {
-             /* Its a register.  */
+             /* It's a register.  */
              reg_shift = 21;
              goto general_reg;
            }
+         /* Fall through.  */
 
          /* The immediate 16 bits literal, bit 0-15.  */
        case 'i':
@@ -807,7 +804,7 @@ machine_ip (char *str)
              continue;
            }
 
-         the_insn.reloc        = (the_insn.HI) ? RELOC_DLX_HI16 
+         the_insn.reloc        = (the_insn.HI) ? RELOC_DLX_HI16
            : (the_insn.LO ? RELOC_DLX_LO16 : RELOC_DLX_16);
          the_insn.reloc_offset = 2;
          the_insn.size         = 2;
@@ -889,7 +886,7 @@ machine_ip (char *str)
        }
 
       /* Types or values of args don't match.  */
-      as_bad ("Invalid operands");
+      as_bad (_("Invalid operands"));
       return;
     }
 }
@@ -908,6 +905,8 @@ md_assemble (char *str)
   know (str);
   machine_ip (str);
   toP = frag_more (4);
+  dwarf2_emit_insn (4);
+
   /* Put out the opcode.  */
   md_number_to_chars (toP, the_insn.opcode, 4);
 
@@ -934,7 +933,7 @@ md_assemble (char *str)
       switch (fixP->fx_r_type)
        {
        case RELOC_DLX_REL26:
-         bitP = malloc (sizeof (bit_fixS));
+         bitP = XNEW (bit_fixS);
          bitP->fx_bit_size = 26;
          bitP->fx_bit_offset = 25;
          bitP->fx_bit_base = the_insn.opcode & 0xFC000000;
@@ -946,7 +945,7 @@ md_assemble (char *str)
          break;
        case RELOC_DLX_LO16:
        case RELOC_DLX_REL16:
-         bitP = malloc (sizeof (bit_fixS));
+         bitP = XNEW (bit_fixS);
          bitP->fx_bit_size = 16;
          bitP->fx_bit_offset = 15;
          bitP->fx_bit_base = the_insn.opcode & 0xFFFF0000;
@@ -957,7 +956,7 @@ md_assemble (char *str)
          fixP->fx_bit_fixP = bitP;
          break;
        case RELOC_DLX_HI16:
-         bitP = malloc (sizeof (bit_fixS));
+         bitP = XNEW (bit_fixS);
          bitP->fx_bit_size = 16;
          bitP->fx_bit_offset = 15;
          bitP->fx_bit_base = the_insn.opcode & 0xFFFF0000;
@@ -975,69 +974,13 @@ md_assemble (char *str)
 }
 
 /* This is identical to the md_atof in m68k.c.  I think this is right,
-   but I'm not sure.
-
-   Turn a string in input_line_pointer into a floating point constant
-   of type TYPE, and store the appropriate bytes in *LITP.  The number
-   of LITTLENUMS emitted is stored in *SIZEP.  An error message is
-   returned, or NULL on OK.  */
-/* Dlx will not use it anyway, so I just leave it here for now.  */
+   but I'm not sure.  Dlx will not use it anyway, so I just leave it
+   here for now.  */
 
-/* Equal to MAX_PRECISION in atof-ieee.c.  */
-#define MAX_LITTLENUMS 6
-
-char *
+const char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  int prec;
-  LITTLENUM_TYPE words[MAX_LITTLENUMS];
-  LITTLENUM_TYPE *wordP;
-  char *t;
-
-  switch (type)
-    {
-    case 'f':
-    case 'F':
-    case 's':
-    case 'S':
-      prec = 2;
-      break;
-
-    case 'd':
-    case 'D':
-    case 'r':
-    case 'R':
-      prec = 4;
-      break;
-
-    case 'x':
-    case 'X':
-      prec = 6;
-      break;
-
-    case 'p':
-    case 'P':
-      prec = 6;
-      break;
-
-    default:
-      *sizeP = 0;
-      return "Bad call to MD_ATOF()";
-    }
-
-  t = atof_ieee (input_line_pointer, type, words);
-  if (t)
-    input_line_pointer = t;
-
-  *sizeP = prec * sizeof (LITTLENUM_TYPE);
-
-  for (wordP = words; prec--;)
-    {
-      md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
-      litP += sizeof (LITTLENUM_TYPE);
-    }
-
-  return 0;
+  return ieee_md_atof (type, litP, sizeP, TRUE);
 }
 
 /* Write out big-endian.  */
@@ -1136,7 +1079,7 @@ size_t md_longopts_size = sizeof (md_longopts);
 
 int
 md_parse_option (int c     ATTRIBUTE_UNUSED,
-                char *arg ATTRIBUTE_UNUSED)
+                const char *arg ATTRIBUTE_UNUSED)
 {
   return 0;
 }
@@ -1247,21 +1190,21 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
 {
   arelent * reloc;
 
-  reloc = xmalloc (sizeof (arelent));
+  reloc = XNEW (arelent);
   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixP->fx_r_type);
 
   if (reloc->howto == NULL)
     {
       as_bad_where (fixP->fx_file, fixP->fx_line,
-                   "internal error: can't export reloc type %d (`%s')",
+                   _("internal error: can't export reloc type %d (`%s')"),
                    fixP->fx_r_type,
                    bfd_get_reloc_code_name (fixP->fx_r_type));
       return NULL;
     }
 
-  assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
+  gas_assert (!fixP->fx_pcrel == !reloc->howto->pc_relative);
 
-  reloc->sym_ptr_ptr = 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;
 
@@ -1276,7 +1219,7 @@ const pseudo_typeS
 dlx_pseudo_table[] =
 {
   /* Some additional ops that are used by gcc-dlx.  */
-  {"asciiz", stringer, 1},
+  {"asciiz", stringer, 8 + 1},
   {"half", cons, 2},
   {"dword", cons, 8},
   {"word", cons, 4},
@@ -1291,4 +1234,3 @@ dlx_pop_insert (void)
   pop_insert (dlx_pseudo_table);
   return ;
 }
-
This page took 0.028885 seconds and 4 git commands to generate.