On Saturday, 6 August 2022 at 08:04:37 UTC, rempas wrote:
>On Saturday, 6 August 2022 at 07:10:43 UTC, user1234 wrote:
>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.
- Create an AST visitor that generate MIR format after DMDFE semantics
- 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)
Thank you for the info! The thing is (and why I make the question originally)
how do I find info about how to get started? I don't even know how DMD
works and how it's IR works. Does DMD's frontend parses the text and then
outputs something like LLVM-IR (but for DMD) which we can take and then
translate it to the final backend that we need (in our case mir) or something
else? That's what I want to know. So yeah, is there a legit documentation or
something or do backend developers have to guess how things work and do
"hacking"?
[...]
You'll have to read DMD code to get familiar with its code base (another way in the past was fixing bugs, unfortunately there are not much easy ones anymore). Fortunately you'll dont have to understand the whole thing. In a first time I'd suggest you to follow the lifetime of one particular construct and that for each big family of node.
Choose
- a Type (maybe the one for
int
) - a Statement (maybe the ReturnStatement)
- a Declaration (the FunctionDeclaration)
- an Expression (maybe the IntegerExp).
Try to follow what is happening during the different passes.
That way you'll have a good idea of what the compiler does for
int i(){return 0;}
and where you could generate MIR stuff.