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

Iain Buclaw ibuclaw at gdcproject.org
Sat Oct 3 22:50:26 UTC 2020


On Saturday, 3 October 2020 at 22:33:03 UTC, IGotD- wrote:
> On Saturday, 3 October 2020 at 13:27:23 UTC, kinke wrote:
>>
>> Yeah sure. See 
>> https://github.com/ldc-developers/ldc/blob/master/gen/asm-x86.h for an incomplete x86 implementation. And now imagine something like this for every ISA supported by GCC and LLVM, and keeping it up-to-date. - The whole point of the GCC/GDC-style assembly is genericity - an instructions template provided by the user as a string to be forwarded to the assembler (opaque for the optimizer), and outputs/inputs/clobbers provided separately because that's the only thing the pre-assembler stages need to know.
>>
>> Considering inline asm is mostly used as a last resort for 
>> some very low-level stuff, extending the front-end by a 
>> full-blown parser for every ISA would be an absolutely 
>> improportionate effort.
>
> One thing that has puzzled me for some time with the GCC syntax 
> is the necessity to include the clobber information. Can't that 
> process be automated, for example the assembler returns 
> information to the compiler about this?

That would require actually parsing the instruction string, and 
having a built-in understanding of what every instruction does.  
The compilation process can be thought of as a series of pipes, 
each part is ran in a separate process.  For gcc C code the steps 
would look something like: `cpp main.c | cc | as | ld -o 
main.exe`.  There is no bidirectional communication between each 
layer.


More information about the Digitalmars-d mailing list