[fpc-devel] Macro expansion in assembler code

Florian Klämpfl florian at freepascal.org
Sat Jan 25 15:13:55 CET 2020


Am 25.01.20 um 08:02 schrieb Christo Crause via fpc-devel:
> I noticed that macro's in assembler code is not expanded before the code 
> is parsed. Is there are technical reason this is not done, or is it 
> merely a historical artefact?

Probably both: token reading is not shared between pascal and assembler 
scanners.

> 
> My question is prompted by the latest assembler code modifications to 
> accommodate avrtiny subarch in the AVR RTL, where the following type of 
> snippets are used in several places to accommodate the differences in 
> registers:
> {$ifdef CPUAVR_16_REGS}
>    in r16,63
> {$else CPUAVR_16_REGS}
>    in r0,63
> {$endif CPUAVR_16_REGS}
> 
> It would seem neater to use a macro (defined by compiler in this case) 
> to indicate which register should be used as temp reg (similar to GCC):
> {$ifdef CPUAVR_16_REGS}
>    {$define AVR_TEMPREG := r16}
> {$else CPUAVR_16_REGS}
>    {$define AVR_TEMPREG := r0}
> {$endif CPUAVR_16_REGS}
> 
> The assembler code can then more cleanly be written without further 
> conditional checks by using the macro:
>    in AVR_TEMPREG, 63
> 
> Similarly reference to the zero register (r1 or r17) can benefit from 
> being defined through a macro.

Maybe in this case just supporting zeroreg/tmpreg as aliases in the 
assembler readers would be easier/better?


More information about the fpc-devel mailing list