|
@@ -14,6 +14,17 @@
|
|
|
|
|
|
exception Error of string
|
|
exception Error of string
|
|
|
|
|
|
|
|
+(** The JIT code model. See [llvm::CodeModel::Model]. *)
|
|
|
|
+module CodeModel : sig
|
|
|
|
+ type t =
|
|
|
|
+ | Default
|
|
|
|
+ | JIT_default
|
|
|
|
+ | Small
|
|
|
|
+ | Kernel
|
|
|
|
+ | Medium
|
|
|
|
+ | Large
|
|
|
|
+end
|
|
|
|
+
|
|
module GenericValue: sig
|
|
module GenericValue: sig
|
|
(** [GenericValue.t] is a boxed union type used to portably pass arguments to
|
|
(** [GenericValue.t] is a boxed union type used to portably pass arguments to
|
|
and receive values from the execution engine. It supports only a limited
|
|
and receive values from the execution engine. It supports only a limited
|
|
@@ -21,24 +32,24 @@ module GenericValue: sig
|
|
generate a stub function by hand or to pass parameters by reference.
|
|
generate a stub function by hand or to pass parameters by reference.
|
|
See the struct [llvm::GenericValue]. *)
|
|
See the struct [llvm::GenericValue]. *)
|
|
type t
|
|
type t
|
|
-
|
|
|
|
|
|
+
|
|
(** [of_float fpty n] boxes the float [n] in a float-valued generic value
|
|
(** [of_float fpty n] boxes the float [n] in a float-valued generic value
|
|
according to the floating point type [fpty]. See the fields
|
|
according to the floating point type [fpty]. See the fields
|
|
[llvm::GenericValue::DoubleVal] and [llvm::GenericValue::FloatVal]. *)
|
|
[llvm::GenericValue::DoubleVal] and [llvm::GenericValue::FloatVal]. *)
|
|
val of_float : Llvm.lltype -> float -> t
|
|
val of_float : Llvm.lltype -> float -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [of_pointer v] boxes the pointer value [v] in a generic value. See the
|
|
(** [of_pointer v] boxes the pointer value [v] in a generic value. See the
|
|
field [llvm::GenericValue::PointerVal]. *)
|
|
field [llvm::GenericValue::PointerVal]. *)
|
|
val of_pointer : 'a -> t
|
|
val of_pointer : 'a -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [of_int32 n w] boxes the int32 [i] in a generic value with the bitwidth
|
|
(** [of_int32 n w] boxes the int32 [i] in a generic value with the bitwidth
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
val of_int32 : Llvm.lltype -> int32 -> t
|
|
val of_int32 : Llvm.lltype -> int32 -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [of_int n w] boxes the int [i] in a generic value with the bitwidth
|
|
(** [of_int n w] boxes the int [i] in a generic value with the bitwidth
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
val of_int : Llvm.lltype -> int -> t
|
|
val of_int : Llvm.lltype -> int -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [of_natint n w] boxes the native int [i] in a generic value with the
|
|
(** [of_natint n w] boxes the native int [i] in a generic value with the
|
|
bitwidth [w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
bitwidth [w]. See the field [llvm::GenericValue::IntVal]. *)
|
|
val of_nativeint : Llvm.lltype -> nativeint -> t
|
|
val of_nativeint : Llvm.lltype -> nativeint -> t
|
|
@@ -51,27 +62,27 @@ module GenericValue: sig
|
|
floating point type [fpty]. See the fields [llvm::GenericValue::DoubleVal]
|
|
floating point type [fpty]. See the fields [llvm::GenericValue::DoubleVal]
|
|
and [llvm::GenericValue::FloatVal]. *)
|
|
and [llvm::GenericValue::FloatVal]. *)
|
|
val as_float : Llvm.lltype -> t -> float
|
|
val as_float : Llvm.lltype -> t -> float
|
|
-
|
|
|
|
|
|
+
|
|
(** [as_pointer gv] unboxes the pointer-valued generic value [gv]. See the
|
|
(** [as_pointer gv] unboxes the pointer-valued generic value [gv]. See the
|
|
field [llvm::GenericValue::PointerVal]. *)
|
|
field [llvm::GenericValue::PointerVal]. *)
|
|
val as_pointer : t -> 'a
|
|
val as_pointer : t -> 'a
|
|
-
|
|
|
|
|
|
+
|
|
(** [as_int32 gv] unboxes the integer-valued generic value [gv] as an [int32].
|
|
(** [as_int32 gv] unboxes the integer-valued generic value [gv] as an [int32].
|
|
Is invalid if [gv] has a bitwidth greater than 32 bits. See the field
|
|
Is invalid if [gv] has a bitwidth greater than 32 bits. See the field
|
|
[llvm::GenericValue::IntVal]. *)
|
|
[llvm::GenericValue::IntVal]. *)
|
|
val as_int32 : t -> int32
|
|
val as_int32 : t -> int32
|
|
-
|
|
|
|
|
|
+
|
|
(** [as_int gv] unboxes the integer-valued generic value [gv] as an [int].
|
|
(** [as_int gv] unboxes the integer-valued generic value [gv] as an [int].
|
|
Is invalid if [gv] has a bitwidth greater than the host bit width (but the
|
|
Is invalid if [gv] has a bitwidth greater than the host bit width (but the
|
|
most significant bit may be lost). See the field
|
|
most significant bit may be lost). See the field
|
|
[llvm::GenericValue::IntVal]. *)
|
|
[llvm::GenericValue::IntVal]. *)
|
|
val as_int : t -> int
|
|
val as_int : t -> int
|
|
-
|
|
|
|
|
|
+
|
|
(** [as_natint gv] unboxes the integer-valued generic value [gv] as a
|
|
(** [as_natint gv] unboxes the integer-valued generic value [gv] as a
|
|
[nativeint]. Is invalid if [gv] has a bitwidth greater than
|
|
[nativeint]. Is invalid if [gv] has a bitwidth greater than
|
|
[nativeint]. See the field [llvm::GenericValue::IntVal]. *)
|
|
[nativeint]. See the field [llvm::GenericValue::IntVal]. *)
|
|
val as_nativeint : t -> nativeint
|
|
val as_nativeint : t -> nativeint
|
|
-
|
|
|
|
|
|
+
|
|
(** [as_int64 gv] returns the integer-valued generic value [gv] as an [int64].
|
|
(** [as_int64 gv] returns the integer-valued generic value [gv] as an [int64].
|
|
Is invalid if [gv] has a bitwidth greater than [int64]. See the field
|
|
Is invalid if [gv] has a bitwidth greater than [int64]. See the field
|
|
[llvm::GenericValue::IntVal]. *)
|
|
[llvm::GenericValue::IntVal]. *)
|
|
@@ -84,35 +95,57 @@ module ExecutionEngine: sig
|
|
directly loading an LLVM module and executing its functions without first
|
|
directly loading an LLVM module and executing its functions without first
|
|
invoking a static compiler and generating a native executable. *)
|
|
invoking a static compiler and generating a native executable. *)
|
|
type t
|
|
type t
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ (** MCJIT compiler options. See [llvm::TargetOptions]. *)
|
|
|
|
+ type compileroptions = {
|
|
|
|
+ opt_level: int;
|
|
|
|
+ code_model: CodeModel.t;
|
|
|
|
+ no_framepointer_elim: bool;
|
|
|
|
+ enable_fast_isel: bool;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ (** Default MCJIT compiler options:
|
|
|
|
+ [{ opt_level = 0; code_model = CodeModel.JIT_default;
|
|
|
|
+ no_framepointer_elim = false; enable_fast_isel = false }] *)
|
|
|
|
+ val default_compiler_options : compileroptions
|
|
|
|
+
|
|
(** [create m] creates a new execution engine, taking ownership of the
|
|
(** [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
|
|
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
|
|
interpreter. Raises [Error msg] if an error occurrs. The execution engine
|
|
is not garbage collected and must be destroyed with [dispose ee].
|
|
is not garbage collected and must be destroyed with [dispose ee].
|
|
See the function [llvm::EngineBuilder::create]. *)
|
|
See the function [llvm::EngineBuilder::create]. *)
|
|
val create : Llvm.llmodule -> t
|
|
val create : Llvm.llmodule -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [create_interpreter m] creates a new interpreter, taking ownership of the
|
|
(** [create_interpreter m] creates a new interpreter, taking ownership of the
|
|
module [m] if successful. Raises [Error msg] if an error occurrs. The
|
|
module [m] if successful. Raises [Error msg] if an error occurrs. The
|
|
execution engine is not garbage collected and must be destroyed with
|
|
execution engine is not garbage collected and must be destroyed with
|
|
[dispose ee].
|
|
[dispose ee].
|
|
See the function [llvm::EngineBuilder::create]. *)
|
|
See the function [llvm::EngineBuilder::create]. *)
|
|
val create_interpreter : Llvm.llmodule -> t
|
|
val create_interpreter : Llvm.llmodule -> t
|
|
-
|
|
|
|
|
|
+
|
|
(** [create_jit m optlevel] creates a new JIT (just-in-time compiler), taking
|
|
(** [create_jit m optlevel] creates a new JIT (just-in-time compiler), taking
|
|
ownership of the module [m] if successful with the desired optimization
|
|
ownership of the module [m] if successful with the desired optimization
|
|
level [optlevel]. Raises [Error msg] if an error occurrs. The execution
|
|
level [optlevel]. Raises [Error msg] if an error occurrs. The execution
|
|
engine is not garbage collected and must be destroyed with [dispose ee].
|
|
engine is not garbage collected and must be destroyed with [dispose ee].
|
|
- See the function [llvm::EngineBuilder::create]. *)
|
|
|
|
|
|
+ See the function [llvm::EngineBuilder::create].
|
|
|
|
+
|
|
|
|
+ Deprecated; use {!create_mcjit}. This function is a shim for {!create_mcjit}. *)
|
|
val create_jit : Llvm.llmodule -> int -> t
|
|
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 create_mcjit : Llvm.llmodule -> compileroptions -> t
|
|
|
|
+
|
|
(** [dispose ee] releases the memory used by the execution engine and must be
|
|
(** [dispose ee] releases the memory used by the execution engine and must be
|
|
invoked to avoid memory leaks. *)
|
|
invoked to avoid memory leaks. *)
|
|
val dispose : t -> unit
|
|
val dispose : t -> unit
|
|
|
|
|
|
(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)
|
|
(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)
|
|
val add_module : Llvm.llmodule -> t -> unit
|
|
val add_module : Llvm.llmodule -> t -> unit
|
|
-
|
|
|
|
|
|
+
|
|
(** [remove_module m ee] removes the module [m] from the execution engine
|
|
(** [remove_module m ee] removes the module [m] from the execution engine
|
|
[ee], disposing of [m] and the module referenced by [mp]. Raises
|
|
[ee], disposing of [m] and the module referenced by [mp]. Raises
|
|
[Error msg] if an error occurs. *)
|
|
[Error msg] if an error occurs. *)
|
|
@@ -122,7 +155,7 @@ module ExecutionEngine: sig
|
|
modules owned by the execution engine [ee]. Returns [None] if the function
|
|
modules owned by the execution engine [ee]. Returns [None] if the function
|
|
is not found and [Some f] otherwise. *)
|
|
is not found and [Some f] otherwise. *)
|
|
val find_function : string -> t -> Llvm.llvalue option
|
|
val find_function : string -> t -> Llvm.llvalue option
|
|
-
|
|
|
|
|
|
+
|
|
(** [run_function f args ee] synchronously executes the function [f] with the
|
|
(** [run_function f args ee] synchronously executes the function [f] with the
|
|
arguments [args], which must be compatible with the parameter types. *)
|
|
arguments [args], which must be compatible with the parameter types. *)
|
|
val run_function : Llvm.llvalue -> GenericValue.t array -> t ->
|
|
val run_function : Llvm.llvalue -> GenericValue.t array -> t ->
|
|
@@ -131,11 +164,11 @@ module ExecutionEngine: sig
|
|
(** [run_static_ctors ee] executes the static constructors of each module in
|
|
(** [run_static_ctors ee] executes the static constructors of each module in
|
|
the execution engine [ee]. *)
|
|
the execution engine [ee]. *)
|
|
val run_static_ctors : t -> unit
|
|
val run_static_ctors : t -> unit
|
|
-
|
|
|
|
|
|
+
|
|
(** [run_static_dtors ee] executes the static destructors of each module in
|
|
(** [run_static_dtors ee] executes the static destructors of each module in
|
|
the execution engine [ee]. *)
|
|
the execution engine [ee]. *)
|
|
val run_static_dtors : t -> unit
|
|
val run_static_dtors : t -> unit
|
|
-
|
|
|
|
|
|
+
|
|
(** [run_function_as_main f args env ee] executes the function [f] as a main
|
|
(** [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
|
|
function, passing it [argv] and [argc] according to the string array
|
|
[args], and [envp] as specified by the array [env]. Returns the integer
|
|
[args], and [envp] as specified by the array [env]. Returns the integer
|