2 ms·
Not OP and I agree, "IR" is just the data structure that holds the AST or a human readable version of it. That said I think what they're getting at is that the
by unlinked_dll 7y ago
Not OP and I agree, "IR" is just the data structure that holds the AST or a human readable version of it.
That said I think what they're getting at is that the interesting bits of modern compilers are transforms between ASTs to lower from one IR to another either to perform some kind of optimization or to replace an abstraction with an implementation before it gets to codegen.
For example if you have generators in your language it's pretty easy to see how to turn a "yield" statement into an AST node. But to actually make the system work you'll probably need a compiler pass over your AST to transform coroutine definitions to subroutine definitions and a state machine to represent the execution context and a constructor/destructor for the state.
Same goes for all interesting language concepts, in the compiler the interesting bit is the pass that transforms the top level AST/IR into more explicit IR and going through the pipeline to get to codegen. Which is as complex as everything else these days when it needs to be fast.
The example talks about this but doesn't dive too deep.
- agumonkey 7y agoNot really agreeing on this one. By IR people means middle ground between various semantics. Parsing gets you an abstract structure of the semantic-world you typed in. An IR would be a something bridging the gap between concepts and register machines, or whatever.