-
Book Overview & Buying
-
Table Of Contents
Learn LLVM 12
By :
We collect all functions and global variables of a compilation unit in an LLVM module. To facilitate IR generation, we wrap all the functions from the previous sections in a code generator class. To get a working compiler, we also need to define the target architecture for which we want to generate code, and also add the passes that emit the code. We implement all this in the next chapters, starting with the code generator.
The IR module is the brace around all elements we generate for a compilation unit. At the global level, we iterate through the declarations at the module level and create global variables and call the code generation for procedures. A global variable in tinylang is mapped to an instance of the llvm::GobalValue class. This mapping is saved in Globals and made available to the code generation for procedures:
void CGModule::run(ModuleDeclaration *Mod) {
for (auto *Decl...