# Module Llvm_executionengine.ExecutionEngine

    module ExecutionEngine: sig .. end

    type t

An execution engine is either a JIT compiler or an interpreter, capable of directly loading an LLVM module and executing its functions without first invoking a static compiler and generating a native executable.

    val create : Llvm.llmodule -> t

`create m` creates a new execution engine, taking ownership of the module `m` if successful. Creates a JIT if possible, else falls back to an interpreter. Raises `Error msg` if an error occurrs. The execution engine is not garbage collected and must be destroyed with `dispose ee`. See the function `llvm::EngineBuilder::create`.

    val create_interpreter : Llvm.llmodule -> t

`create_interpreter m` creates a new interpreter, taking ownership of the module `m` if successful. Raises `Error msg` if an error occurrs. The execution engine is not garbage collected and must be destroyed with `dispose ee`. See the function `llvm::EngineBuilder::create`.

    val create_jit : Llvm.llmodule -> int -> t

`create_jit m optlevel` creates a new JIT (just-in-time compiler), taking ownership of the module `m` if successful with the desired optimization level `optlevel`. Raises `Error msg` if an error occurrs. The execution engine is not garbage collected and must be destroyed with `dispose ee`. See the function `llvm::EngineBuilder::create`.

    val dispose : t -> unit

`dispose ee` releases the memory used by the execution engine and must be invoked to avoid memory leaks.

    val add_module : Llvm.llmodule -> t -> unit

`add_module m ee` adds the module `m` to the execution engine `ee`.

    val remove_module : Llvm.llmodule -> t -> Llvm.llmodule

`remove_module m ee` removes the module `m` from the execution engine `ee`, disposing of `m` and the module referenced by `mp`. Raises `Error msg` if an error occurs.

    val find_function : string -> t -> Llvm.llvalue option

`find_function n ee` finds the function named `n` defined in any of the modules owned by the execution engine `ee`. Returns `None` if the function is not found and `Some f` otherwise.

    val run_function : Llvm.llvalue ->
           Llvm_executionengine.GenericValue.t array ->
           t -> Llvm_executionengine.GenericValue.t

`run_function f args ee` synchronously executes the function `f` with the arguments `args`, which must be compatible with the parameter types.

    val run_static_ctors : t -> unit

`run_static_ctors ee` executes the static constructors of each module in the execution engine `ee`.

    val run_static_dtors : t -> unit

`run_static_dtors ee` executes the static destructors of each module in the execution engine `ee`.

    val run_function_as_main : Llvm.llvalue ->
           string array ->
           (string * string) array -> t -> int

`run_function_as_main f args env ee` executes the function `f` as a main function, passing it `argv` and `argc` according to the string array `args`, and `envp` as specified by the array `env`. Returns the integer return value of the function.

    val free_machine_code : Llvm.llvalue -> t -> unit

`free_machine_code f ee` releases the memory in the execution engine `ee` used to store the machine code for the function `f`.

    val data_layout : t -> Llvm_target.DataLayout.t

`data_layout ee` is the data layout of the execution engine `ee`.