Paired Nested Macroses Support

Jan Beulich jbeulich@suse.com
Thu Feb 16 16:31:50 GMT 2023


(re-sending with the list added back - please don't drop the list when
replying to earlier list communication, unless there's a very specific
reason to do so)

On 16.02.2023 16:06, Dmytro Tarasiuk wrote:
> on, 16.02.2023 10:04 Jan Beulich <jbeulich@suse.com> wrote:
>> On 16.02.2023 00:37, Dmytro Tarasiuk via Binutils wrote:
>>> Writing paired nested macros is not possible in the gas macro assembler.
>>> For example, BEGIN/WHILE macros for loops, etc.  This is important to me
>>> for writing portable pseudocode between different architectures that
>>> supports gas.
>>
>> Without explaining (perhaps by way of providing an example) it's unclear
>> what you mean here.
>>
> 
> Excuse me. Here is an example of the macroses for nested cycles:

Thanks for the example. My first conclusion is - there's no nesting
of macros here. Instead you want multiple macros to interact with
one another in a certain way. I think this can be achieved without
patching the assembler, using alternative macro mode (.altmacro) and
the special unary % operator that this mode supports. That may
require helper macros, yes, so the set of macros overall may end up
bigger (and uglier), but that's still not necessarily a reason to
extend gas.

Furthermore ...

>     .macro DO
>         LABEL_DO\(++DO)_start:

... while this syntax may indeed have a low chance of colliding with
anything people already use (simply because it is pretty unlikely
for anyone to use two + in a row), ...

>     .endm
> 
>     .macro DO_WHILE cond
>             j\cond LABEL_DO_WHILE\@continue
>             jmp LABEL_DONE\(DO)_end

... this is a problem: There's nothing wrong with somebody having a
construct like this in an existing macro, while at the same time
also having a macro somewhere with the name DO. If you wanted to
extend the language, you would need to make sure that this cannot
break existing code.

Irrespective of the ++ being not as much of a problem syntax-wise, I
hope you're aware that without further changes elsewhere \(+ +DO)
may end up being seen as \(++DO) by the time the (scrubbed) input
reaches the parsing logic here. That's because unlike in C ++ (and
-- as well) do not form a "token"; they're always two separate +,
and hence whitespace between them may be dropped by the scrubber.

>         LABEL_DO_WHILE\@continue:
>     .endm
> 
>     .macro DONE_WHEN cond
>             j\cond LABEL_DONE\(DO)_end
>             jmp LABEL_DO\(DO)_start
>         LABEL_DONE\(DO--)_end:
>     .endm
> 
>     .macro DONE
>             jmp LABEL_DO\(DO)_start
>         LABEL_DONE\(DO--)_end:
>     .endm
> 
> Using macroses above (which is not translated without patching) I able to
> write program like below:
> 
>                 DO
>                     xor %rax, %rax
>                     mov counter, %eax

Just as an aside: The "xor" here is pointless.

Jan


More information about the Binutils mailing list