Inter-compiler portability of asm between gdc and ldc2 (and dmd)

Iain Buclaw ibuclaw at gdcproject.org
Fri Jul 17 21:03:46 UTC 2020



On 17/07/2020 05:14, Cecil Ward via Digitalmars-d wrote:
> On Friday, 17 July 2020 at 00:38:23 UTC, kinke wrote:
>> On Thursday, 16 July 2020 at 23:06:24 UTC, Cecil Ward wrote:
>>> The serious problem though is the error
>>>     "Error: symbolic names for operands in GCC-style assembly are not supported yet"
>>> I use symbolic names for registers everywhere, for readability and for order-independence. So that means I am dead.
>>
>> Or hopefully motivated enough to open a PR with a little extension to [1] - all that should be needed from the LDC side is replacing all occurrences of the symbolic names in the template string by their according operand index (LLVM has no implicit support for these symbolic names). And of course getting rid of the error msg in [2].
>>
>> [1] https://github.com/ldc-developers/ldc/blob/424064438ec7f3ab202da982227e95660eca7c3e/gen/asm-gcc.cpp#L24-L53
>> [2] https://github.com/ldc-developers/ldc/blob/424064438ec7f3ab202da982227e95660eca7c3e/gen/asm-gcc.cpp#L186-L194
> 
> Grave health difficulties mean that my abilities are very limited just now so I will have to hope that those with the required experience will have this on their things to do list at some point.
> 
> Thank you for pointing me at the right place,

There's nothing magical going on in order to resolve symbolic names.  Each output, input and label operand has an index value from 0 to N, and you just need to replace "%[symbol]" with "%3".

https://github.com/gcc-mirror/gcc/blob/f1b6e46c417224887c2f21baa6d4c538a25fe9fb/gcc/stmt.c#L528-L603
https://github.com/gcc-mirror/gcc/blob/f1b6e46c417224887c2f21baa6d4c538a25fe9fb/gcc/stmt.c#L605-L663

This could even be done in the semantic pass of GccAsmStatement (dmd/iasmgcc.d), so no need for LDC to duplicate this locally (plus, you are in the safe land of D to do the required string manipulation).


More information about the Digitalmars-d mailing list