-
Notifications
You must be signed in to change notification settings - Fork 2
Program Structure
-
Main function creates a Context, and calls Context::init()
-
Context.init initializes ocaml datastructures
- Open and read executable
- Initialize the garbage collector
- Build the primitives tables (ocaml C builtin functions, and other imported functions)
- Load the data section of the file into the globals
-
Context.init creates a vector of instructions and reads them from the ocaml bytecode array with functions readInstructions and annotateNodes. This is done in the following steps:
- the readInstructions function reads the bytecode sequentially, and converts the code offsets contained in the instructions from relative position in the bytecode array to absolute position in the instruction vector. -the annotateNodes function marks every block and function beginning with an annotation, to facilitate the reconstruction of a control flow graph.
-
Context.init creates a GenModuleCreator initialized with the instructions.
-
GenModuleCreator.generate generates the Control Flow Graph. see CFG generation
-
Once the CFG is created, Context.init grabs the main function and generates it's code via the codeGen method. This will recursively generate all necessary functions. see Code generation
-
Once the code is generated, Context.init runs LLVM's optimization managers, and uses the module's execution engine to get a pointer to the main function, which will be implicitly generated and compiled by LLVM, and executes it. see Code Compilation and execution