I know that an AST
generated by the parser is used to generate IR in the frontend.
I am wondering how AST to be parsed and then transformed to IR (prob assembly or bitcode),
AST is a tree, what are the steps involved in the transformation from AST to IR.
LLVM IR is a low-level intermediate representation used by the LLVM compiler framework. You can think of LLVM IR as a platform-independent assembly language with an infinite number of function local registers.
A developer uses the API to generate instructions in a format called an intermediate representation, or IR. LLVM can then compile the IR into a standalone binary or perform a JIT (just-in-time) compilation on the code to run in the context of another program, such as an interpreter or runtime for the language.
2.2. The Abstract Syntax Tree (AST) The AST for a program captures its behavior in such a way that it is easy for later stages of the compiler (e.g. code generation) to interpret. We basically want one object for each construct in the language, and the AST should closely model the language.
Emitting LLVM IR from Clang ASTs
happens in Clang's code gen
stage. The code for this stage lives in lib/CodeGen/
(relative to Clang's source root). There's no need to parse the AST since Clang has the AST in an in-memory data structure. Code generation is essentially a recursive walk of the AST that emits IR into a Module
. If there's any specific step of it that interests you, the best way to examine it would be to look in the code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With