This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: macro behavior
- From: Erik Christiansen <erik at dd dot nec dot com dot au>
- To: Jan Beulich <JBeulich at novell dot com>
- Cc: binutils at sources dot redhat dot com
- Date: Fri, 15 Apr 2005 12:47:03 +1000
- Subject: Re: macro behavior
- References: <s25e8f7d.048@emea1-mh.id2.novell.com>
On Thu, Apr 14, 2005 at 04:42:59PM +0200, Jan Beulich wrote:
> (1) If I want to append a constant suffix to the expanded string, I
> see no way to do so in default mode; in .altmacro mode I am able to do
> so using the & macro operator:
>
> .macro m sym
> .equiv &sym&_, 1
> .endm
For me, prepending of constants, and appending of the constant '.' and
parameter names works fine in gas. (Tested only on avr-as 20030512, so far,
I'm afraid). For some odd reason, your choice of '_' does break the
appending mechanism. Here is what works for me:
.macro struct_elem name, size, elem ; Declare an element of struct "name"
\name.\elem = oneof_\name ; Generate element offset.
oneof_\name = oneof_\name + \size ; Size of one struct.
.endm
The following expands happily:
.section .data,"aw"
struct fruit
struct_elem fruit,1,apple
struct_elem fruit,3,orange
struct_elem fruit,1,banana
end_struct fruit,4 ; Array of 4 structs.
to:
60 .section .data,"aw"
61 struct fruit
61 > oneof_fruit =0
62 struct_elem fruit,1,apple
62 > fruit.apple =oneof_fruit
62 > oneof_fruit =oneof_fruit+1
63 struct_elem fruit,3,orange
63 > fruit.orange =oneof_fruit
63 > oneof_fruit =oneof_fruit+3
64 struct_elem fruit,1,banana
64 > fruit.banana =oneof_fruit
64 > oneof_fruit =oneof_fruit+1
65 end_struct fruit,4 ; Array of 4 structs.
65 > sizeof_fruit =oneof_fruit*4
65 > numof_fruit =4
65 > fruit:.space sizeof_fruit
65 0000 0000 0000 > .space sizeof_fruit
65 0000 0000
allowing stuff like:
ldd r16,Y + fruit.banana ; r16 = fruit[3].banana
And, yep, it's '_' that is your bugbear with .equiv syntax also,
'cos this works too:
64 struct_elem fruit,1,banana
64 > .equiv fruit.banana,oneof_fruit
If a more flexible syntax evolves, that would be nifty, but the
existing code is in volume production, so is fixing what we have an
option? ;-)
Erik