make md_parse_option () take a const char *
[deliverable/binutils-gdb.git] / gas / config / tc-tic54x.c
index 1a00bb49554efc174118c0573d08455c3069b84f..b8897045973bd32562c5b5158bb33a5de5711e30 100644 (file)
@@ -1,6 +1,5 @@
 /* tc-tic54x.c -- Assembly code for the Texas Instruments TMS320C54X
-   Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009  Free Software Foundation, Inc.
+   Copyright (C) 1999-2016 Free Software Foundation, Inc.
    Contributed by Timothy Wall (twall@cygnus.com)
 
    This file is part of GAS, the GNU Assembler.
@@ -45,8 +44,8 @@
    COFF1 limits section names to 8 characters.
    Some of the default behavior changed from COFF1 to COFF2.  */
 
-#include <limits.h>
 #include "as.h"
+#include <limits.h>
 #include "safe-ctype.h"
 #include "sb.h"
 #include "macro.h"
@@ -323,7 +322,6 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
   int c;
   char *name;
   char *str;
-  char *tmp;
   int quoted = *input_line_pointer == '"';
 
   ILLEGAL_WITHIN_STRUCT ();
@@ -352,8 +350,8 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
       return;
     }
 
-  name = ++input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  ++input_line_pointer;
+  c = get_symbol_name (&name); /* Get terminator.  */
   if (!ISALPHA (*name))
     {
       as_bad (_("symbols assigned with .asg must begin with a letter"));
@@ -361,14 +359,10 @@ tic54x_asg (int x ATTRIBUTE_UNUSED)
       return;
     }
 
-  tmp = xmalloc (strlen (str) + 1);
-  strcpy (tmp, str);
-  str = tmp;
-  tmp = xmalloc (strlen (name) + 1);
-  strcpy (tmp, name);
-  name = tmp;
+  str = xstrdup (str);
+  name = xstrdup (name);
   subsym_create_or_replace (name, str);
-  *input_line_pointer = c;
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
 
@@ -412,11 +406,10 @@ tic54x_eval (int x ATTRIBUTE_UNUSED)
       ignore_rest_of_line ();
       return;
     }
-  name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&name); /* Get terminator.  */
   tmp = xmalloc (strlen (name) + 1);
   name = strcpy (tmp, name);
-  *input_line_pointer = c;
+  (void) restore_line_pointer (c);
 
   if (!ISALPHA (*name))
     {
@@ -472,8 +465,9 @@ tic54x_bss (int x ATTRIBUTE_UNUSED)
   current_seg = now_seg;       /* Save current seg.  */
   current_subseg = now_subseg; /* Save current subseg.  */
 
-  name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
+  c = get_symbol_name (&name); /* Get terminator.  */
+  if (c == '"')
+    c = * ++ input_line_pointer;
   if (c != ',')
     {
       as_bad (_(".bss size argument missing\n"));
@@ -550,21 +544,16 @@ stag_add_field_symbols (struct stag *stag,
                        symbolS *rootsym,
                        const char *root_stag_name)
 {
-  char prefix[strlen (path) + 2];
+  char * prefix;
   struct stag_field *field = stag->field;
 
   /* Construct a symbol for every field contained within this structure
      including fields within structure fields.  */
-  strcpy (prefix, path);
-  if (*path)
-    strcat (prefix, ".");
+  prefix = concat (path, *path ? "." : "", NULL);
 
   while (field != NULL)
     {
-      int len = strlen (prefix) + strlen (field->name) + 2;
-      char *name = xmalloc (len);
-      strcpy (name, prefix);
-      strcat (name, field->name);
+      char *name = concat (prefix, field->name, NULL);
 
       if (rootsym == NULL)
        {
@@ -578,12 +567,10 @@ stag_add_field_symbols (struct stag *stag,
        }
       else
        {
-         char *replacement = xmalloc (strlen (name)
-                                      + strlen (stag->name) + 2);
-         strcpy (replacement, S_GET_NAME (rootsym));
-         strcat (replacement, "+");
-         strcat (replacement, root_stag_name);
-         strcat (replacement, name + strlen (S_GET_NAME (rootsym)));
+         char *replacement;
+
+         replacement = concat (S_GET_NAME (rootsym), "+", root_stag_name,
+                               name + strlen (S_GET_NAME (rootsym)), NULL);
          hash_insert (subsym_hash[0], name, replacement);
        }
 
@@ -594,7 +581,9 @@ stag_add_field_symbols (struct stag *stag,
                                field->offset,
                                rootsym, root_stag_name);
       field = field->next;
+      free (name);
     }
+  free (prefix);
 }
 
 /* Keep track of stag fields so that when structures are nested we can add the
@@ -696,11 +685,12 @@ tic54x_struct (int arg)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label)) + 1];
-      strcpy (label, S_GET_NAME (line_label));
-      current_stag->sym = symbol_new (label, absolute_section,
+      char * label = xstrdup (S_GET_NAME (line_label));
+      current_stag->sym = symbol_new (label,
+                                     absolute_section,
                                      (valueT) abs_section_offset,
                                      &zero_address_frag);
+      free (label);
     }
   current_stag->name = S_GET_NAME (current_stag->sym);
   SF_SET_LOCAL (current_stag->sym);
@@ -783,8 +773,8 @@ tic54x_endstruct (int is_union)
 static void
 tic54x_tag (int ignore ATTRIBUTE_UNUSED)
 {
-  char *name = input_line_pointer;
-  int c = get_symbol_end ();
+  char *name;
+  int c = get_symbol_name (&name);
   struct stag *stag = (struct stag *) hash_find (stag_hash, name);
 
   if (!stag)
@@ -804,9 +794,9 @@ tic54x_tag (int ignore ATTRIBUTE_UNUSED)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label)) + 1];
+      char * label;
 
-      strcpy (label, S_GET_NAME (line_label));
+      label = xstrdup (S_GET_NAME (line_label));
       if (current_stag != NULL)
        stag_add_field (current_stag, label,
                        abs_section_offset - S_GET_VALUE (current_stag->sym),
@@ -819,18 +809,20 @@ tic54x_tag (int ignore ATTRIBUTE_UNUSED)
            {
              as_bad (_(".tag target '%s' undefined"), label);
              ignore_rest_of_line ();
+             free (label);
              return;
            }
          stag_add_field_symbols (stag, S_GET_NAME (sym),
                                  S_GET_VALUE (stag->sym), sym, stag->name);
        }
+      free (label);
     }
 
   /* Bump by the struct size, but only if we're within a .struct section.  */
   if (current_stag != NULL && !current_stag->is_union)
     abs_section_offset += stag->size;
 
-  *input_line_pointer = c;
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
   line_label = NULL;
 }
@@ -934,12 +926,13 @@ tic54x_struct_field (int type)
     }
   else
     {
-      char label[strlen (S_GET_NAME (line_label) + 1)];
+      char * label;
 
-      strcpy (label, S_GET_NAME (line_label));
+      label = xstrdup (S_GET_NAME (line_label));
       stag_add_field (current_stag, label,
                      abs_section_offset - S_GET_VALUE (current_stag->sym),
                      NULL);
+      free (label);
     }
 
   if (current_stag->is_union)
@@ -1110,11 +1103,10 @@ tic54x_global (int type)
 
   do
     {
-      name = input_line_pointer;
-      c = get_symbol_end ();
+      c = get_symbol_name (&name);
       symbolP = symbol_find_or_make (name);
+      c = restore_line_pointer (c);
 
-      *input_line_pointer = c;
       S_SET_STORAGE_CLASS (symbolP, C_EXT);
       if (c == ',')
        {
@@ -1185,13 +1177,14 @@ tic54x_sect (int arg)
       else
        {
          int c;
-         name = input_line_pointer;
-         c = get_symbol_end ();
+
+         c = get_symbol_name (&name);
           len = strlen(name);
          name = strcpy (xmalloc (len + 10), name);
-         *input_line_pointer = c;
+         (void) restore_line_pointer (c);
          demand_empty_rest_of_line ();
        }
+
       /* Make sure all named initialized sections flagged properly.  If we
          encounter instructions, we'll flag it with SEC_CODE as well.  */
       strcat (name, ",\"w\"\n");
@@ -1367,17 +1360,14 @@ tic54x_usect (int x ATTRIBUTE_UNUSED)
   current_seg = now_seg;       /* Save current seg.  */
   current_subseg = now_subseg; /* Save current subseg.  */
 
-  if (*input_line_pointer == '"')
-    input_line_pointer++;
-  section_name = input_line_pointer;
-  c = get_symbol_end ();       /* Get terminator.  */
-  input_line_pointer++;                /* Skip null symbol terminator.  */
+  c = get_symbol_name (&section_name); /* Get terminator.  */
   name = xmalloc (input_line_pointer - section_name + 1);
   strcpy (name, section_name);
-
-  if (*input_line_pointer == ',')
+  c = restore_line_pointer (c);
+  
+  if (c == ',')
     ++input_line_pointer;
-  else if (c != ',')
+  else
     {
       as_bad (_("Missing size argument"));
       ignore_rest_of_line ();
@@ -1570,7 +1560,6 @@ static void
 tic54x_stringer (int type)
 {
   unsigned int c;
-  char *start;
   int append_zero = type == 'S' || type == 'P';
   int packed = type == 'p' || type == 'P';
   int last_char = -1; /* Packed strings need two bytes at a time to encode.  */
@@ -1600,7 +1589,6 @@ tic54x_stringer (int type)
          }
        case '\"':
          ++input_line_pointer; /* -> 1st char of string.  */
-         start = input_line_pointer;
          while (is_a_char (c = next_char_of_string ()))
            {
              if (!packed)
@@ -1877,15 +1865,15 @@ tic54x_clink (int ignored ATTRIBUTE_UNUSED)
 static void
 tic54x_set_default_include (int dot)
 {
-  char *dir = ".";
+  const char *dir = ".";
   char *tmp = NULL;
 
   if (!dot)
     {
-      char *curfile;
+      const char *curfile;
       unsigned lineno;
 
-      as_where (&curfile, &lineno);
+      curfile = as_where (&lineno);
       dir = strcpy (xmalloc (strlen (curfile) + 1), curfile);
       tmp = strrchr (dir, '/');
     }
@@ -1897,7 +1885,7 @@ tic54x_set_default_include (int dot)
       len = strlen (dir);
       if (include_dir_count == 0)
        {
-         include_dirs = (char **) xmalloc (sizeof (*include_dirs));
+         include_dirs = XNEWVEC (const char *, 1);
          include_dir_count = 1;
        }
       include_dirs[0] = dir;
@@ -2011,17 +1999,17 @@ tic54x_message (int type)
 static void
 tic54x_label (int ignored ATTRIBUTE_UNUSED)
 {
-  char *name = input_line_pointer;
+  char *name;
   symbolS *symbolP;
   int c;
 
   ILLEGAL_WITHIN_STRUCT ();
 
-  c = get_symbol_end ();
+  c = get_symbol_name (&name);
   symbolP = colon (name);
   S_SET_STORAGE_CLASS (symbolP, C_STATLAB);
 
-  *input_line_pointer = c;
+  (void) restore_line_pointer (c);
   demand_empty_rest_of_line ();
 }
 
@@ -2144,12 +2132,12 @@ tic54x_sblock (int ignore ATTRIBUTE_UNUSED)
        }
       else
        {
-         char *section_name = input_line_pointer;
+         char *section_name;
 
-         c = get_symbol_end ();
+         c = get_symbol_name (&section_name);
          name = xmalloc (strlen (section_name) + 1);
          strcpy (name, section_name);
-         *input_line_pointer = c;
+         (void) restore_line_pointer (c);
        }
 
       seg = bfd_get_section_by_name (stdoutput, name);
@@ -2259,12 +2247,11 @@ tic54x_var (int ignore ATTRIBUTE_UNUSED)
          ignore_rest_of_line ();
          return;
        }
-      name = input_line_pointer;
-      c = get_symbol_end ();
+      c = get_symbol_name (&name);
       /* .var symbols start out with a null string.  */
       name = strcpy (xmalloc (strlen (name) + 1), name);
       hash_insert (subsym_hash[macro_level], name, empty);
-      *input_line_pointer = c;
+      c = restore_line_pointer (c);
       if (c == ',')
        {
          ++input_line_pointer;
@@ -2371,13 +2358,13 @@ tic54x_mlib (int ignore ATTRIBUTE_UNUSED)
       FILE *ftmp;
 
       /* We're not sure how big it is, but it will be smaller than "size".  */
-      bfd_bread (buf, size, mbfd);
+      size = bfd_bread (buf, size, mbfd);
 
       /* Write to a temporary file, then use s_include to include it
         a bit of a hack.  */
       ftmp = fopen (fname, "w+b");
       fwrite ((void *) buf, size, 1, ftmp);
-      if (buf[size - 1] != '\n')
+      if (size == 0 || buf[size - 1] != '\n')
        fwrite ("\n", 1, 1, ftmp);
       fclose (ftmp);
       free (buf);
@@ -2474,7 +2461,7 @@ const pseudo_typeS md_pseudo_table[] =
 };
 
 int
-md_parse_option (int c, char *arg)
+md_parse_option (int c, const char *arg)
 {
   switch (c)
     {
@@ -2503,7 +2490,7 @@ md_parse_option (int c, char *arg)
       break;
     case OPTION_STDERR_TO_FILE:
       {
-       char *filename = arg;
+       const char *filename = arg;
        FILE *fp = fopen (filename, "w+");
 
        if (fp == NULL)
@@ -2919,7 +2906,7 @@ math_tanh (float arg1, float ignore ATTRIBUTE_UNUSED)
 /* Built-in substitution symbol functions and math functions.  */
 typedef struct
 {
-  char *name;
+  const char *name;
   int (*proc) (char *, char *);
   int nargs;
 } subsym_proc_entry;
@@ -2943,7 +2930,7 @@ static const subsym_proc_entry subsym_procs[] =
 
 typedef struct
 {
-  char *name;
+  const char *name;
   float (*proc) (float, float);
   int nargs;
   int int_return;
@@ -4303,7 +4290,7 @@ tic54x_parse_parallel_insn_lastline (tic54x_insn *insn, char *line)
    replacement on the value.  */
 
 static char *
-subsym_get_arg (char *line, char *terminators, char **str, int nosub)
+subsym_get_arg (char *line, const char *terminators, char **str, int nosub)
 {
   char *ptr = line;
   char *endp;
@@ -4335,7 +4322,7 @@ subsym_get_arg (char *line, char *terminators, char **str, int nosub)
     }
   else
     {
-      char *term = terminators;
+      const char *term = terminators;
       char *value = NULL;
 
       while (*ptr && *ptr != *term)
@@ -4503,8 +4490,8 @@ subsym_substitute (char *line, int forced)
          if (forced)
            ++ptr;
 
-         name = input_line_pointer = ptr;
-         c = get_symbol_end ();
+         input_line_pointer = ptr;
+         c = get_symbol_name (&name);
          /* '?' is not normally part of a symbol, but it IS part of a local
             label.  */
          if (c == '?')
@@ -4535,7 +4522,7 @@ subsym_substitute (char *line, int forced)
              if (value == NULL)
                {
                  char digit[11];
-                 char *namecopy = strcpy (xmalloc (strlen (name) + 1), name);
+                 char *namecopy = xstrdup (name);
 
                  value = strcpy (xmalloc (strlen (name) + sizeof (digit) + 1),
                                  name);
@@ -4660,7 +4647,7 @@ subsym_substitute (char *line, int forced)
                 substitutions are performed, or a substitution that has been
                 previously made is encountered again.
 
-                put the symbol into the recursion hash table so we only
+                Put the symbol into the recursion hash table so we only
                 try to replace a symbol once.  */
              if (recurse)
                {
@@ -4780,7 +4767,7 @@ tic54x_start_line_hook (void)
   line[endp - input_line_pointer] = 0;
 
   /* Scan ahead for parallel insns.  */
-  parallel_on_next_line_hint = next_line_shows_parallel (endp + 1);
+  parallel_on_next_line_hint = next_line_shows_parallel (endp);
 
   /* If within a macro, first process forced replacements.  */
   if (macro_level > 0)
@@ -4849,7 +4836,7 @@ md_assemble (char *line)
   int c;
 
   input_line_pointer = line;
-  c = get_symbol_end ();
+  c = get_symbol_name (&line);
 
   if (cpu == VNONE)
     cpu = V542;
@@ -5009,9 +4996,8 @@ tic54x_adjust_symtab (void)
   if (symbol_rootP == NULL
       || S_GET_STORAGE_CLASS (symbol_rootP) != C_FILE)
     {
-      char *filename;
       unsigned lineno;
-      as_where (&filename, &lineno);
+      const char * filename = as_where (&lineno);
       c_dot_file_symbol (filename, 0);
     }
 }
@@ -5124,10 +5110,9 @@ tc_gen_reloc (asection *section, fixS *fixP)
 /* Handle cons expressions.  */
 
 void
-tic54x_cons_fix_new (fragS *frag, int where, int octets, expressionS *expn)
+tic54x_cons_fix_new (fragS *frag, int where, int octets, expressionS *expn,
+                    bfd_reloc_code_real_type r)
 {
-  bfd_reloc_code_real_type r;
-
   switch (octets)
     {
     default:
@@ -5365,22 +5350,21 @@ tic54x_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
    syntax puts the symbol *before* the pseudo (which is kinda like MRI syntax,
    I guess, except I've never seen a definition of MRI syntax).
 
-   C is the character that used to be at *REST, which points to the end of the
-   label.
-
    Don't allow labels to start with '.'  */
 
 int
-tic54x_start_label (int c, char *rest)
+tic54x_start_label (int nul_char, int next_char)
 {
+  char *rest;
+
   /* If within .struct/.union, no auto line labels, please.  */
   if (current_stag != NULL)
     return 0;
 
   /* Disallow labels starting with "."  */
-  if (c != ':')
+  if (next_char != ':')
     {
-      char *label = rest;
+      char *label = input_line_pointer;
 
       while (!is_end_of_line[(int) label[-1]])
        --label;
@@ -5391,22 +5375,22 @@ tic54x_start_label (int c, char *rest)
        }
     }
 
-  if (is_end_of_line[(int) c])
+  if (is_end_of_line[(int) next_char])
     return 1;
 
-  if (ISSPACE (c))
-    while (ISSPACE (c = *++rest))
-      ;
-  if (c == '.')
-    {
-      /* Don't let colon () define a label for any of these...  */
-      return (strncasecmp (rest, ".tag", 4) != 0 || !ISSPACE (rest[4]))
-       && (strncasecmp (rest, ".struct", 7) != 0 || !ISSPACE (rest[7]))
-       && (strncasecmp (rest, ".union", 6) != 0 || !ISSPACE (rest[6]))
-       && (strncasecmp (rest, ".macro", 6) != 0 || !ISSPACE (rest[6]))
-       && (strncasecmp (rest, ".set", 4) != 0 || !ISSPACE (rest[4]))
-       && (strncasecmp (rest, ".equ", 4) != 0 || !ISSPACE (rest[4]));
-    }
+  rest = input_line_pointer;
+  if (nul_char == '"')
+    ++rest;
+  while (ISSPACE (next_char))
+    next_char = *++rest;
+  if (next_char != '.')
+    return 1;
 
-  return 1;
+  /* Don't let colon () define a label for any of these...  */
+  return ((strncasecmp (rest, ".tag", 4) != 0 || !ISSPACE (rest[4]))
+         && (strncasecmp (rest, ".struct", 7) != 0 || !ISSPACE (rest[7]))
+         && (strncasecmp (rest, ".union", 6) != 0 || !ISSPACE (rest[6]))
+         && (strncasecmp (rest, ".macro", 6) != 0 || !ISSPACE (rest[6]))
+         && (strncasecmp (rest, ".set", 4) != 0 || !ISSPACE (rest[4]))
+         && (strncasecmp (rest, ".equ", 4) != 0 || !ISSPACE (rest[4])));
 }
This page took 0.033405 seconds and 4 git commands to generate.