Setting up the module and the driver
We collect all the functions and global variables of a compilation unit in an LLVM module. To ease the IR generation process, we can wrap all the functions from the previous sections into 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 will implement this in this and the next few chapters, starting with the code generator.
Wrapping all in 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, 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) { ...