Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c
- index 4b44a91..7463810 100644
- --- a/bindings/ocaml/executionengine/executionengine_ocaml.c
- +++ b/bindings/ocaml/executionengine/executionengine_ocaml.c
- @@ -200,6 +200,24 @@ llvm_ee_create_jit(LLVMModuleRef M, value OptLevel) {
- return JIT;
- }
- +/* llmodule -> llcompileroption -> ExecutionEngine.t */
- +CAMLprim LLVMExecutionEngineRef
- +llvm_ee_create_mcjit(LLVMModuleRef M, value OptRecord) {
- + LLVMExecutionEngineRef MCJIT;
- + char *Error;
- + struct LLVMMCJITCompilerOptions Options = {
- + .OptLevel = Int_val(Field(OptRecord, 0)),
- + .CodeModel = Int_val(Field(OptRecord, 1)),
- + .NoFramePointerElim = Int_val(Field(OptRecord, 2)),
- + .EnableFastISel = Int_val(Field(OptRecord, 3)),
- + .MCJMM = NULL
- + };
- + if (LLVMCreateMCJITCompilerForModule(&MCJIT, M, &Options,
- + sizeof(Options), &Error))
- + llvm_raise(llvm_ee_error_exn, Error);
- + return MCJIT;
- +}
- +
- /* ExecutionEngine.t -> unit */
- CAMLprim value llvm_ee_dispose(LLVMExecutionEngineRef EE) {
- LLVMDisposeExecutionEngine(EE);
- diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml
- index a738df7..64d21bc 100644
- --- a/bindings/ocaml/executionengine/llvm_executionengine.ml
- +++ b/bindings/ocaml/executionengine/llvm_executionengine.ml
- @@ -14,6 +14,25 @@ external register_exns: exn -> unit
- = "llvm_register_ee_exns"
- +module CodeModel = struct
- + type t =
- + | Default
- + | JIT_default
- + | Small
- + | Kernel
- + | Medium
- + | Large
- +end
- +
- +
- +type mcjitcompileroptions =
- + { opt_level: int;
- + code_model: CodeModel.t;
- + no_framepointer_elim: bool;
- + enable_fast_isel: bool;
- + }
- +
- +
- module GenericValue = struct
- type t
- @@ -62,6 +81,8 @@ module ExecutionEngine = struct
- = "llvm_ee_create_interpreter"
- external create_jit: Llvm.llmodule -> int -> t
- = "llvm_ee_create_jit"
- + external create_mcjit: Llvm.llmodule -> mcjitcompileroptions -> t
- + = "llvm_ee_create_mcjit"
- external dispose: t -> unit
- = "llvm_ee_dispose"
- external add_module: Llvm.llmodule -> t -> unit
- diff --git a/test/Bindings/Ocaml/executionengine.ml b/test/Bindings/Ocaml/executionengine.ml
- index 8e24949..be8b53c 100644
- --- a/test/Bindings/Ocaml/executionengine.ml
- +++ b/test/Bindings/Ocaml/executionengine.ml
- @@ -18,6 +18,9 @@ let i8_type = Llvm.i8_type context
- let i32_type = Llvm.i32_type context
- let i64_type = Llvm.i64_type context
- let double_type = Llvm.double_type context
- +type ee_engine = Interpreter
- + | JIT
- + | MCJIT
- let bomb msg =
- prerr_endline msg;
- @@ -60,7 +63,7 @@ let test_genericvalue () =
- let i64gv = GenericValue.of_int64 i64_type (Int64.of_int 6) in
- assert ((Int64.of_int 6) = GenericValue.as_int64 i64gv)
- -let test_executionengine () =
- +let test_executionengine ?(engine = Interpreter) () =
- (* create *)
- let m = create_module (global_context ()) "test_module" in
- let main = define_main_fn m 42 in
- @@ -68,7 +71,13 @@ let test_executionengine () =
- let m2 = create_module (global_context ()) "test_module2" in
- define_plus m2;
- - let ee = ExecutionEngine.create m in
- + let ee =
- + if engine = Interpreter then
- + ExecutionEngine.create_interpreter m
- + else if engine = JIT then
- + ExecutionEngine.create_jit m
- + else
- + ExecutionEngine.create_mcjit m in
- ExecutionEngine.add_module m2 ee;
- (* run_static_ctors *)
- @@ -115,4 +124,6 @@ let test_executionengine () =
- let _ =
- test_genericvalue ();
- - test_executionengine ()
- + test_executionengine ~engine:Interpreter ()
- + test_executionengine ~engine:JIT ()
- + test_executionengine ~engine:MCJIT ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement