This is the mail archive of the binutils@sources.redhat.com 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]

Re: GASP really obsolete?


Frank Mehnert <fm3@os.inf.tu-dresden.de> writes:

> I have to maintain GAS assembler files which contain a lot of GASP
> macros. The original author of these files wrote some macros to make 
> it easier to understand the assembler program. For instance, he was
> able to write such code:
> 
>   IFNZ variable_a, $0
>     call handle_case_a_not_null
>   ELSE
>     call handle_case_a_is_null
>   ENDIF
> 
> ...
> 
> He implemented the IFNZ, ELSE and ENDIF using GASP macros:
> I have to replace that code using features of GAS because the maintainer
> of binutils deceided to drop GASP -- they claim that GAS includes all 
> features of GASP.
> 
> I have no idea how to translate these macros from GASP to GAS. The main
> feature I miss is that I can't create labels containing variable numeric
> parts.

Well, you're right.  Nobody has bothered to implement preprocessing
variables in gas.  Typically such uses would be handled via m4 or some
other preprocessing language.  But that won't help much with existing
code.

The way to implement preprocessing variables would be to change read.c
to check at each line for uses of \&SYM, where SYM is a defined symbol
in absolute_section, and to replace \&SYM with the value of SYM.

(Checking at macro expansion time doesn't work, because then \&SYM
will be resolved to the value of SYM before the macro expansion, not
during the macro expansion.)q

Unfortunately, checking at read time would be pretty inefficient.

Here is a really bad, really inefficient, buggy example of what I am
talking about.

Ian

Index: read.c
===================================================================
RCS file: /cvs/src/src/gas/read.c,v
retrieving revision 1.51
diff -u -p -r1.51 read.c
--- read.c	3 May 2002 02:25:33 -0000	1.51
+++ read.c	11 Jun 2002 16:33:16 -0000
@@ -630,6 +630,55 @@ read_a_source_file (name)
 	     assembler, which then wastes more time decoding it.
 	     (And communicating via (linear) files is silly!
 	     If you must pass stuff, please pass a tree!)  */
+
+	  {
+	    char* p;
+
+	    for (p = input_line_pointer;
+		 ! is_end_of_line[*p];
+		 ++p)
+	      {
+		if (*p == '\\'
+		    && p[1] == '&'
+		    && is_name_beginner(p[2]))
+		  {
+		    char c2;
+		    char *p2 = p + 2;
+		    symbolS *sym;
+
+		    while (is_part_of_name (c2 = *p2++))
+		      ;
+		    if (is_name_ender (c2))
+		      c2 = *p2++;
+		    *--p2 = '\0';
+
+		    sym = symbol_find (p + 2);
+		    if (sym != NULL && S_GET_SEGMENT (sym) == absolute_section)
+		      {
+			int d;
+
+			sprintf (buffer, "%d", (int) S_GET_VALUE (sym));
+			assert (p2 - p >= strlen (buffer));
+			strcpy (p, buffer);
+			p += strlen (buffer);
+			d = p2 - p;
+			*p2 = c2;
+			if (d > 0)
+			  {
+			    memmove (p, p2, buffer_limit - p2);
+			    buffer_limit -= d;
+			  }
+			--p;
+		      }
+		    else
+		      {
+			*p2 = c2;
+			p = p2;
+		      }
+		  }
+	      }
+	  }
+
 	  if ((c = *input_line_pointer++) == '\t'
 	      || c == ' '
 	      || c == '\f'


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