Skip to content
raph-amiard edited this page Feb 21, 2012 · 3 revisions

Flow of execution

  1. Main function creates a Context, and calls Context::init()

  2. 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
  3. 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.
  4. Context.init creates a GenModuleCreator initialized with the instructions.

  5. GenModuleCreator.generate generates the Control Flow Graph. see CFG generation

  6. 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

  7. 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

Clone this wiki locally