This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 04/13] make as_where () return the file name


From: Trevor Saunders <tbsaunde+binutils@tbsaunde.org>

This makes some callers a little simpler, and should be ever so slightly faster
on some machines.  It also makes it easier to work towards returning a const
char *.

gas/ChangeLog:

2016-02-21  Trevor Saunders  <tbsaunde+binutils@tbsaunde.org>

	* input-scrub.c (as_where): Return the file name.
	* as.h (as_where): Adjust prototype.
	* app.c (do_scrub_chars): Adjust.
	* cond.c (s_elseif): Likewise.
	(s_else): Likewise.
	(initialize_cframe): Likewise.
	* config/obj-coff.c (obj_coff_init_stab_section): Likewise.
	* config/obj-elf.c (obj_elf_init_stab_section): Likewise.
	* config/obj-som.c (obj_som_init_stab_section): Likewise.
	* config/tc-aarch64.c (output_info): Likewise.
	* config/tc-ia64.c (md_assemble): Likewise.
	(dot_alias): Likewise.
	* config/tc-m68k.c (m68k_frob_label): Likewise.
	* config/tc-mmix.c (s_bspec): Likewise.
	(mmix_handle_mmixal): Likewise.
	* config/tc-rx.c (rx_include): Likewise.
	* config/tc-tic54x.c (tic54x_set_default_include): Likewise.
	(tic54x_adjust_symtab): Likewise.
	* config/tc-xtensa.c (directive_push): Likewise.
	(xtensa_sanity_check): Likewise.
	(xtensa_relax_frag): Likewise.
	(md_convert_frag): Likewise.
	(tinsn_to_slotbuf): Likewise.
	* dwarf2dbg.c (dwarf2_where): Likewise.
	* ecoff.c (add_file): Likewise.
	(ecoff_generate_asm_lineno): Likewise.
	* expr.c (make_expr_symbol): Likewise.
	* frags.c (frag_new): Likewise.
	(frag_var_init): Likewise.
	* listing.c (listing_newline): Likewise.
	* messages.c (identify): Likewise.
	(as_show_where): Likewise.
	(as_warn_internal): Likewise.
	(as_bad_internal): Likewise.
	* read.c (s_irp): Likewise.
	(s_macro): Likewise.
	(s_reloc): Likewise.
	* stabs.c (stabs_generate_asm_file): Likewise.
	(stabs_generate_asm_lineno): Likewise.
	(stabs_generate_asm_func): Likewise.
	* write.c (fix_new_internal): Likewise.
---
 gas/app.c               |  2 +-
 gas/as.h                |  2 +-
 gas/cond.c              | 12 ++++++------
 gas/config/obj-coff.c   |  2 +-
 gas/config/obj-elf.c    |  2 +-
 gas/config/obj-som.c    |  2 +-
 gas/config/tc-aarch64.c |  2 +-
 gas/config/tc-ia64.c    |  4 ++--
 gas/config/tc-m68k.c    |  2 +-
 gas/config/tc-mmix.c    |  8 +++-----
 gas/config/tc-rx.c      |  2 +-
 gas/config/tc-tic54x.c  |  4 ++--
 gas/config/tc-xtensa.c  | 10 +++++-----
 gas/dwarf2dbg.c         |  3 +--
 gas/ecoff.c             |  4 ++--
 gas/expr.c              |  2 +-
 gas/frags.c             |  4 ++--
 gas/input-scrub.c       | 14 ++++++--------
 gas/listing.c           |  2 +-
 gas/messages.c          |  8 ++++----
 gas/read.c              |  6 +++---
 gas/stabs.c             |  7 +++----
 gas/write.c             |  2 +-
 23 files changed, 50 insertions(+), 56 deletions(-)

diff --git a/gas/app.c b/gas/app.c
index 074c447..f53e7ce 100644
--- a/gas/app.c
+++ b/gas/app.c
@@ -1291,7 +1291,7 @@ do_scrub_chars (size_t (*get) (char *, size_t), char *tostart, size_t tolen)
 
 #ifdef WARN_COMMENTS
 	  if (!found_comment)
-	    as_where (&found_comment_file, &found_comment);
+	    found_comment_file = as_where (&found_comment);
 #endif
 	  do
 	    {
diff --git a/gas/as.h b/gas/as.h
index 0a7875f..7d69ad2 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -497,7 +497,7 @@ void   cond_finish_check (int);
 void   cond_exit_macro (int);
 int    seen_at_least_1_file (void);
 void   app_pop (char *);
-void   as_where (char **, unsigned int *);
+char * as_where (unsigned int *);
 void   bump_line_counters (void);
 void   do_scrub_begin (int);
 void   input_scrub_begin (void);
diff --git a/gas/cond.c b/gas/cond.c
index d99c1e0..4be6061 100644
--- a/gas/cond.c
+++ b/gas/cond.c
@@ -317,8 +317,8 @@ s_elseif (int arg)
     }
   else
     {
-      as_where (&current_cframe->else_file_line.file,
-		&current_cframe->else_file_line.line);
+      current_cframe->else_file_line.file
+       	= as_where (&current_cframe->else_file_line.line);
 
       current_cframe->dead_tree |= !current_cframe->ignoring;
       current_cframe->ignoring = current_cframe->dead_tree;
@@ -423,8 +423,8 @@ s_else (int arg ATTRIBUTE_UNUSED)
     }
   else
     {
-      as_where (&current_cframe->else_file_line.file,
-		&current_cframe->else_file_line.line);
+      current_cframe->else_file_line.file
+       	= as_where (&current_cframe->else_file_line.line);
 
       current_cframe->ignoring =
 	current_cframe->dead_tree | !current_cframe->ignoring;
@@ -527,8 +527,8 @@ static void
 initialize_cframe (struct conditional_frame *cframe)
 {
   memset (cframe, 0, sizeof (*cframe));
-  as_where (&cframe->if_file_line.file,
-	    &cframe->if_file_line.line);
+  cframe->if_file_line.file
+	    = as_where (&cframe->if_file_line.line);
   cframe->previous_cframe = current_cframe;
   cframe->dead_tree = current_cframe != NULL && current_cframe->ignoring;
   cframe->macro_nest = macro_nest;
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c
index c100c95..ef3747b 100644
--- a/gas/config/obj-coff.c
+++ b/gas/config/obj-coff.c
@@ -1819,7 +1819,7 @@ obj_coff_init_stab_section (segT seg)
   p = frag_more (12);
   /* Zero it out.  */
   memset (p, 0, 12);
-  as_where (&file, (unsigned int *) NULL);
+  file = as_where ((unsigned int *) NULL);
   stabstr_name = xmalloc (strlen (seg->name) + 4);
   strcpy (stabstr_name, seg->name);
   strcat (stabstr_name, "str");
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index 9af349c..31a2877 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -2058,7 +2058,7 @@ obj_elf_init_stab_section (segT seg)
   p = frag_more (12);
   /* Zero it out.  */
   memset (p, 0, 12);
-  as_where (&file, NULL);
+  file = as_where (NULL);
   stabstr_name = (char *) xmalloc (strlen (segment_name (seg)) + 4);
   strcpy (stabstr_name, segment_name (seg));
   strcat (stabstr_name, "str");
diff --git a/gas/config/obj-som.c b/gas/config/obj-som.c
index 953c3a7..34571e8 100644
--- a/gas/config/obj-som.c
+++ b/gas/config/obj-som.c
@@ -241,7 +241,7 @@ obj_som_init_stab_section (segT seg)
      the call to get_stab_string_offset.  */
   p = frag_more (12);
   memset (p, 0, 12);
-  as_where (&file, (unsigned int *) NULL);
+  file = as_where ((unsigned int *) NULL);
   stroff = get_stab_string_offset (file, "$GDB_STRINGS$");
   know (stroff == 1);
   md_number_to_chars (p, stroff, 4);
diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c
index dfcbd52..ca92ab0 100644
--- a/gas/config/tc-aarch64.c
+++ b/gas/config/tc-aarch64.c
@@ -4263,7 +4263,7 @@ output_info (const char *format, ...)
   unsigned int line;
   va_list args;
 
-  as_where (&file, &line);
+  file = as_where (&line);
   if (file)
     {
       if (line != 0)
diff --git a/gas/config/tc-ia64.c b/gas/config/tc-ia64.c
index f0ba4ae..987858c 100644
--- a/gas/config/tc-ia64.c
+++ b/gas/config/tc-ia64.c
@@ -10856,7 +10856,7 @@ md_assemble (char *str)
   /* Build the instruction.  */
   CURR_SLOT.qp_regno = qp_regno;
   CURR_SLOT.idesc = idesc;
-  as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
+  CURR_SLOT.src_file = as_where (&CURR_SLOT.src_line);
   dwarf2_where (&CURR_SLOT.debug_line);
   dwarf2_consume_line_info ();
 
@@ -11859,7 +11859,7 @@ dot_alias (int section)
     }
 
   h = (struct alias *) xmalloc (sizeof (struct alias));
-  as_where (&h->file, &h->line);
+  h->file = as_where (&h->line);
   h->name = name;
 
   error_string = hash_jam (ahash, alias, (void *) h);
diff --git a/gas/config/tc-m68k.c b/gas/config/tc-m68k.c
index 6bff4fb..be9fa3d 100644
--- a/gas/config/tc-m68k.c
+++ b/gas/config/tc-m68k.c
@@ -4792,7 +4792,7 @@ m68k_frob_label (symbolS *sym)
   n = (struct label_line *) xmalloc (sizeof *n);
   n->next = labels;
   n->label = sym;
-  as_where (&n->file, &n->line);
+  n->file = as_where (&n->line);
   n->text = 0;
   labels = n;
   current_label = n;
diff --git a/gas/config/tc-mmix.c b/gas/config/tc-mmix.c
index 34c22ef..b40f078 100644
--- a/gas/config/tc-mmix.c
+++ b/gas/config/tc-mmix.c
@@ -2141,7 +2141,7 @@ s_bspec (int unused ATTRIBUTE_UNUSED)
   subseg_set (sec, 0);
 
   /* Save position for missing ESPEC.  */
-  as_where (&bspec_file, &bspec_line);
+  bspec_file = as_where (&bspec_line);
 
   doing_bspec = 1;
 }
@@ -2939,18 +2939,16 @@ mmix_handle_mmixal (void)
 	 caller is about to bump the counters.  Adjust the error messages.  */
       if (is_end_of_line[(unsigned int) *s])
 	{
-	  char *name;
 	  unsigned int line;
-	  as_where (&name, &line);
+	  char * name = as_where (&line);
 	  as_bad_where (name, line + 1,
 			_("[0-9]H labels may not appear alone on a line"));
 	  current_fb_label = -1;
 	}
       if (*s == '.')
 	{
-	  char *name;
 	  unsigned int line;
-	  as_where (&name, &line);
+	  char * name  = as_where (&line);
 	  as_bad_where (name, line + 1,
 			_("[0-9]H labels do not mix with dot-pseudos"));
 	  current_fb_label = -1;
diff --git a/gas/config/tc-rx.c b/gas/config/tc-rx.c
index 24f47cc..aeb409e 100644
--- a/gas/config/tc-rx.c
+++ b/gas/config/tc-rx.c
@@ -300,7 +300,7 @@ rx_include (int ignore)
       return;
     }
 
-  as_where (& current_filename, NULL);
+   current_filename = as_where (NULL);
   f = (char *) xmalloc (strlen (current_filename) + strlen (filename) + 1);
 
   /* Check the filename.  If [@]..FILE[@] is found then replace
diff --git a/gas/config/tc-tic54x.c b/gas/config/tc-tic54x.c
index 1ff204b..a91f3e7 100644
--- a/gas/config/tc-tic54x.c
+++ b/gas/config/tc-tic54x.c
@@ -1879,7 +1879,7 @@ tic54x_set_default_include (int dot)
       char *curfile;
       unsigned lineno;
 
-      as_where (&curfile, &lineno);
+      curfile = as_where (&lineno);
       dir = strcpy (xmalloc (strlen (curfile) + 1), curfile);
       tmp = strrchr (dir, '/');
     }
@@ -5004,7 +5004,7 @@ tic54x_adjust_symtab (void)
     {
       char *filename;
       unsigned lineno;
-      as_where (&filename, &lineno);
+      filename = as_where (&lineno);
       c_dot_file_symbol (filename, 0);
     }
 }
diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c
index 79a0e76..f169ef8 100644
--- a/gas/config/tc-xtensa.c
+++ b/gas/config/tc-xtensa.c
@@ -1167,7 +1167,7 @@ directive_push (directiveE directive, bfd_boolean negated, const void *datum)
   unsigned int line;
   state_stackS *stack = (state_stackS *) xmalloc (sizeof (state_stackS));
 
-  as_where (&file, &line);
+  file = as_where (&line);
 
   stack->directive = directive;
   stack->negated = negated;
@@ -8490,7 +8490,7 @@ xtensa_sanity_check (void)
   frchainS *frchP;
   asection *s;
 
-  as_where (&file_name, &line);
+  file_name = as_where (&line);
   for (s = stdoutput->sections; s; s = s->next)
     for (frchP = seg_info (s)->frchainP; frchP; frchP = frchP->frch_next)
       {
@@ -9181,7 +9181,7 @@ xtensa_relax_frag (fragS *fragP, long stretch, int *stretched_p)
   int slot, num_slots;
   xtensa_format fmt;
 
-  as_where (&file_name, &line);
+  file_name = as_where (&line);
   new_logical_line (fragP->fr_file, fragP->fr_line);
 
   fragP->tc_frag_data.unreported_expansion = 0;
@@ -10290,7 +10290,7 @@ md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec, fragS *fragp)
   char *file_name;
   unsigned line;
 
-  as_where (&file_name, &line);
+  file_name = as_where (&line);
   new_logical_line (fragp->fr_file, fragp->fr_line);
 
   switch (fragp->fr_subtype)
@@ -12586,7 +12586,7 @@ tinsn_to_slotbuf (xtensa_format fmt,
 	case O_constant:
 	  if (xtensa_operand_is_visible (isa, opcode, i) == 0)
 	    break;
-	  as_where (&file_name, &line);
+	  file_name = as_where (&line);
 	  /* It is a constant and we called this function
 	     then we have to try to fit it.  */
 	  xtensa_insnbuf_set_operand (slotbuf, fmt, slot, opcode, i,
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 33703e8..c559cad 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -350,8 +350,7 @@ dwarf2_where (struct dwarf2_line_info *line)
 {
   if (debug_type == DEBUG_DWARF2)
     {
-      char *filename;
-      as_where (&filename, &line->line);
+      const char *filename = as_where (&line->line);
       line->filenum = get_filenum (filename, 0);
       line->column = 0;
       line->flags = DWARF2_FLAG_IS_STMT;
diff --git a/gas/ecoff.c b/gas/ecoff.c
index eb3beb3..d33ffc7 100644
--- a/gas/ecoff.c
+++ b/gas/ecoff.c
@@ -2200,7 +2200,7 @@ add_file (const char *file_name, int indx ATTRIBUTE_UNUSED, int fake)
 
       if (first_file != (efdr_t *) NULL)
 	as_fatal (_("fake .file after real one"));
-      as_where (&file, (unsigned int *) NULL);
+      file = as_where ((unsigned int *) NULL);
       file_name = (const char *) file;
 
       /* Automatically generate ECOFF debugging information, since I
@@ -5184,7 +5184,7 @@ ecoff_generate_asm_lineno (void)
   char *filename;
   lineno_list_t *list;
 
-  as_where (&filename, &lineno);
+  filename = as_where (&lineno);
 
   if (current_stabs_filename == (char *) NULL
       || filename_cmp (current_stabs_filename, filename))
diff --git a/gas/expr.c b/gas/expr.c
index 825818d..9256a3e 100644
--- a/gas/expr.c
+++ b/gas/expr.c
@@ -110,7 +110,7 @@ make_expr_symbol (expressionS *expressionP)
 
   n = (struct expr_symbol_line *) xmalloc (sizeof *n);
   n->sym = symbolP;
-  as_where (&n->file, &n->line);
+  n->file = as_where (&n->line);
   n->next = expr_symbol_lines;
   expr_symbol_lines = n;
 
diff --git a/gas/frags.c b/gas/frags.c
index cd3e990..9ff577f 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -176,7 +176,7 @@ frag_new (size_t old_frags_var_max_size
   gas_assert (former_last_fragP == frag_now);
   frag_now = frag_alloc (&frchP->frch_obstack);
 
-  as_where (&frag_now->fr_file, &frag_now->fr_line);
+  frag_now->fr_file = as_where (&frag_now->fr_line);
 
   /* Generally, frag_now->points to an address rounded up to next
      alignment.  However, characters will add to obstack frags
@@ -237,7 +237,7 @@ frag_var_init (relax_stateT type, size_t max_chars, size_t var,
 #ifdef TC_FRAG_INIT
   TC_FRAG_INIT (frag_now);
 #endif
-  as_where (&frag_now->fr_file, &frag_now->fr_line);
+  frag_now->fr_file = as_where (&frag_now->fr_line);
 
   frag_new (max_chars);
 }
diff --git a/gas/input-scrub.c b/gas/input-scrub.c
index 9d4d75a..ac71622 100644
--- a/gas/input-scrub.c
+++ b/gas/input-scrub.c
@@ -482,30 +482,28 @@ new_logical_line (char *fname, int line_number)
 }
 
 
-/* Return the current file name and line number.
-   namep should be char * const *, but there are compilers which screw
-   up declarations like that, and it's easier to avoid it.  */
+/* Return the current file name and line number.  */
 
-void
-as_where (char **namep, unsigned int *linep)
+char *
+as_where (unsigned int *linep)
 {
   if (logical_input_file != NULL
       && (linep == NULL || logical_input_line >= 0))
     {
-      *namep = logical_input_file;
       if (linep != NULL)
 	*linep = logical_input_line;
+      return logical_input_file;
     }
   else if (physical_input_file != NULL)
     {
-      *namep = physical_input_file;
       if (linep != NULL)
 	*linep = physical_input_line;
+      return physical_input_file;
     }
   else
     {
-      *namep = 0;
       if (linep != NULL)
 	*linep = 0;
+      return NULL;
     }
 }
diff --git a/gas/listing.c b/gas/listing.c
index a346f37..26f2722 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -327,7 +327,7 @@ listing_newline (char *ps)
     }
 #endif
 
-  as_where (&file, &line);
+  file = as_where (&line);
   if (ps == NULL)
     {
       if (line == last_line
diff --git a/gas/messages.c b/gas/messages.c
index 2c9f3da..905ff3f 100644
--- a/gas/messages.c
+++ b/gas/messages.c
@@ -72,7 +72,7 @@ identify (char *file)
   if (!file)
     {
       unsigned int x;
-      as_where (&file, &x);
+      file = as_where (&x);
     }
 
   if (file)
@@ -108,7 +108,7 @@ as_show_where (void)
   char *file;
   unsigned int line;
 
-  as_where (&file, &line);
+  file = as_where (&line);
   identify (file);
   if (file)
     {
@@ -145,7 +145,7 @@ as_warn_internal (char *file, unsigned int line, char *buffer)
   ++warning_count;
 
   if (file == NULL)
-    as_where (&file, &line);
+    file = as_where (&line);
 
   identify (file);
   if (file)
@@ -210,7 +210,7 @@ as_bad_internal (char *file, unsigned int line, char *buffer)
   ++error_count;
 
   if (file == NULL)
-    as_where (&file, &line);
+    file = as_where (&line);
 
   identify (file);
   if (file)
diff --git a/gas/read.c b/gas/read.c
index 5e0e3c8..f85a014 100644
--- a/gas/read.c
+++ b/gas/read.c
@@ -2354,7 +2354,7 @@ s_irp (int irpc)
   const char *err;
   sb out;
 
-  as_where (&file, &line);
+  file = as_where (&line);
 
   eol = find_end_of_line (input_line_pointer, 0);
   sb_build (&s, eol - input_line_pointer);
@@ -2689,7 +2689,7 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
   const char *err;
   const char *name;
 
-  as_where (&file, &line);
+  file = as_where (&line);
 
   eol = find_end_of_line (input_line_pointer, 0);
   sb_build (&s, eol - input_line_pointer);
@@ -4163,7 +4163,7 @@ s_reloc (int ignore ATTRIBUTE_UNUSED)
       break;
     }
 
-  as_where (&reloc->file, &reloc->line);
+  reloc->file = as_where (&reloc->line);
   reloc->next = reloc_list;
   reloc_list = reloc;
 
diff --git a/gas/stabs.c b/gas/stabs.c
index 3b56a48..b9ab2fa 100644
--- a/gas/stabs.c
+++ b/gas/stabs.c
@@ -493,7 +493,7 @@ stabs_generate_asm_file (void)
   char *file;
   unsigned int lineno;
 
-  as_where (&file, &lineno);
+  file = as_where (&lineno);
   if (use_gnu_debug_info_extensions)
     {
       const char *dir;
@@ -598,7 +598,7 @@ stabs_generate_asm_lineno (void)
 
   hold = input_line_pointer;
 
-  as_where (&file, &lineno);
+  file = as_where (&lineno);
 
   /* Don't emit sequences of stabs for the same line.  */
   if (prev_file == NULL)
@@ -661,7 +661,6 @@ stabs_generate_asm_func (const char *funcname, const char *startlabname)
   static int void_emitted_p;
   char *hold = input_line_pointer;
   char *buf;
-  char *file;
   unsigned int lineno;
 
   if (! void_emitted_p)
@@ -671,7 +670,7 @@ stabs_generate_asm_func (const char *funcname, const char *startlabname)
       void_emitted_p = 1;
     }
 
-  as_where (&file, &lineno);
+  as_where (&lineno);
   if (asprintf (&buf, "\"%s:F1\",%d,0,%d,%s",
 		funcname, N_FUN, lineno + 1, startlabname) == -1)
     as_fatal ("%s", xstrerror (errno));
diff --git a/gas/write.c b/gas/write.c
index 46ce5df..b1ccba2 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -192,7 +192,7 @@ fix_new_internal (fragS *frag,		/* Which frag?  */
   TC_INIT_FIX_DATA (fixP);
 #endif
 
-  as_where (&fixP->fx_file, &fixP->fx_line);
+  fixP->fx_file = as_where (&fixP->fx_line);
 
   {
 
-- 
2.7.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]