How hard would it be to create a new backend in D?

user1234 user1234 at 12.de
Sat Aug 6 07:10:43 UTC 2022


On Saturday, 6 August 2022 at 04:41:24 UTC, rempas wrote:
> On Friday, 5 August 2022 at 22:09:44 UTC, user1234 wrote:
>>
>> I think you can try things without writing a backend. If I 
>> believe the diagram of what currently works that seems 
>> possible to use LDC to produce LLVM IR and then MIR in theory 
>> could use that, ...
>
> LLVM is the slow part of LDC (D's frontend is actually faster 
> than
> C's frontend for LLVM as LDC compiles cod faster than Clang) so
> this will not help...

I suggested to experiment MIR like that, it was not a proposal on 
the final design.
Experimenting using LLVM IR could be useful to determine if 
working seriously on the project is worth.

Anyway if you want to put your hand in the hard stuff from the 
start I think you have two options.

1. Create an AST visitor that generate MIR format after DMDFE 
semantics
2. Create the MIR representation after the part of the backend 
that generate DMD IR (s2ir, e2ir, etc.) has run.

The second option might be easier because the production will 
most of the time map 1:1 to a MIR equivalent.

The first option is IMO would be harder because of forward 
references and imports. and even without that, that would require 
to split visiting in several passes (decls, aggregate members, 
function headers, function bodies)

About the "how hard" I think that compiler programming is not 
hard but that takes time. I estimate that this could take you 
from 1 month to 3 months to finish however you 'd get results 
much earlier, e.g if you handle just a few constructs.





More information about the Digitalmars-d mailing list