This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: macro expansion and operator &&
Committed. I removed the comment about alternate mode because it
seems incorrect to me. If you comment out this sub_actual call, then
$ gas/as-new -alm --alternate /src/tmp/altmac.s
GAS LISTING /src/tmp/altmac.s page 1
1 .macro xxx x y
2 .long x&1
3 .long .&x
4 .long x&y
5 .endm
6
7 a = 4
8 a1 = 5
9 .a = 6
10 ab =7
11
12 xxx a b
12 0000 05000000 > .long a1
12 0004 06000000 > .long .a
12 0008 07000000 > .long ab
So looks to me like you can append and prepend literals to parameters
without this particular call.
* macro.c (sub_actual): Add back ampersand suffix when no
substitution.
(macro_expand_body): Correct comment.
Index: gas/macro.c
===================================================================
RCS file: /cvs/src/src/gas/macro.c,v
retrieving revision 1.53
diff -u -p -r1.53 macro.c
--- gas/macro.c 23 Jul 2010 06:44:25 -0000 1.53
+++ gas/macro.c 18 Aug 2010 04:54:05 -0000
@@ -748,6 +748,8 @@ sub_actual (int start, sb *in, sb *t, st
/* Doing this permits people to use & in macro bodies. */
sb_add_char (out, '&');
sb_add_sb (out, t);
+ if (src != start && in->ptr[src - 1] == '&')
+ sb_add_char (out, '&');
}
else if (copyifnotthere)
{
@@ -788,9 +790,8 @@ macro_expand_body (sb *in, sb *out, form
}
else
{
- /* FIXME: Why do we do this? */
- /* At least in alternate mode this seems correct; without this
- one can't append a literal to a parameter. */
+ /* Permit macro parameter substition delineated with
+ an '&' prefix and optional '&' suffix. */
src = sub_actual (src + 1, in, &t, formal_hash, '&', out, 0);
}
}
--
Alan Modra
Australia Development Lab, IBM