This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
gas: parsing source lines containing macro args
- To: binutils at sourceware dot cygnus dot com
- Subject: gas: parsing source lines containing macro args
- From: Andrew Haley <aph at pasanda dot cygnus dot co dot uk>
- Date: 8 Nov 1999 16:51:20 -0000
Consider a source file that looks like this:
-----------------------------------------------------------------------
.macro foo_macro arg0, arg1
foo \arg0,\arg1,0
.endm
.vu
n1: foo_macro %r01,%r00
n2: foo %r01,%r00,0
-----------------------------------------------------------------------
Line n1 expands to "foo %r01,%r00,0", which is the same as line n2.
However, if there is another token on the line inside the macro, bad
things happen:
-----------------------------------------------------------------------
.macro foo_macro arg0, arg1
bar foo \arg0,\arg1,0
.endm
.vu
n1: foo_macro %r01,%r00
n2: bar foo %r01,%r00,0
-----------------------------------------------------------------------
Instead of being expanded to "bar foo %r01,%r00,0", line n1 is
expanded to "bar foo%r01,%r00,0": a space has disappeared. This
happens becase when gas is scanning Line n1, any spaces after the
second operand are ignored *unless* they occur immediately before an
operand character. Unfortunately, in this case the space in question
is immediately before a backslash, which is not an operand character,
so the space is dropped.
My patch fixes this by outputting a space when going from State 10
(after seeing whitespace in state 9) to State 3 (after second white on
line) iff the non-whitepsace character which caused the transition was
a backslash.
I thin that this genuinely is a special case, because a backslash
should only be treated as an operand char when the backslash appears
as the first character of an operand.
Andrew.
1999-11-08 Andrew Haley <aph@cygnus.com>
* app.c (do_scrub_chars): When in State 10, treat backslash
characters in the same way as as symbol characters.
Index: app.c
===================================================================
RCS file: /cvs/binutils/binutils/gas/app.c,v
retrieving revision 1.3
diff -p -r1.3 app.c
*** app.c 1999/07/11 20:19:53 1.3
--- app.c 1999/11/08 16:48:03
*************** do_scrub_chars (get, tostart, tolen)
*** 1227,1232 ****
--- 1227,1242 ----
}
else if (state == 10)
{
+ if (ch == '\\')
+ {
+ /* Special handling for backslash: a backslash may
+ be the beginning of a formal parameter (of a
+ macro) following another symbol character, with
+ whitespace in between. We skipped the whitespace
+ earlier, so output it now. */
+ PUT (' ');
+ }
+
state = 3;
}
PUT (ch);