2007-12-23 17:59:28 +01:00
|
|
|
(*===-- llvm_executionengine.mli - LLVM Ocaml Interface ---------*- C++ -*-===*
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2007-12-29 23:59:10 +01:00
|
|
|
* This file is distributed under the University of Illinois Open Source
|
|
|
|
* License. See LICENSE.TXT for details.
|
2007-12-23 17:59:28 +01:00
|
|
|
*
|
|
|
|
*===----------------------------------------------------------------------===*)
|
|
|
|
|
2008-03-09 08:17:38 +01:00
|
|
|
(** JIT Interpreter.
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2008-03-09 08:17:38 +01:00
|
|
|
This interface provides an ocaml API for LLVM execution engine (JIT/
|
|
|
|
interpreter), the classes in the ExecutionEngine library. *)
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2008-03-09 08:17:38 +01:00
|
|
|
exception Error of string
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
module GenericValue: sig
|
|
|
|
(** [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
|
|
|
|
selection of types; for more complex argument types, it is necessary to
|
|
|
|
generate a stub function by hand or to pass parameters by reference.
|
2008-03-09 08:17:38 +01:00
|
|
|
See the struct [llvm::GenericValue]. *)
|
2007-12-23 17:59:28 +01:00
|
|
|
type t
|
|
|
|
|
|
|
|
(** [of_float fpty n] boxes the float [n] in a float-valued generic value
|
2008-03-09 08:17:38 +01:00
|
|
|
according to the floating point type [fpty]. See the fields
|
|
|
|
[llvm::GenericValue::DoubleVal] and [llvm::GenericValue::FloatVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external of_float : Llvm.lltype -> float -> t = "llvm_genericvalue_of_float"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [of_pointer v] boxes the pointer value [v] in a generic value. See the
|
2008-03-09 08:17:38 +01:00
|
|
|
field [llvm::GenericValue::PointerVal]. *)
|
2010-03-04 00:51:30 +01:00
|
|
|
external of_pointer : 'a -> t = "llvm_genericvalue_of_pointer"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [of_int32 n w] boxes the int32 [i] in a generic value with the bitwidth
|
2008-03-09 08:17:38 +01:00
|
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external of_int32 : Llvm.lltype -> int32 -> t = "llvm_genericvalue_of_int32"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [of_int n w] boxes the int [i] in a generic value with the bitwidth
|
2008-03-09 08:17:38 +01:00
|
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external of_int : Llvm.lltype -> int -> t = "llvm_genericvalue_of_int"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [of_natint n w] boxes the native int [i] in a generic value with the
|
2008-03-09 08:17:38 +01:00
|
|
|
bitwidth [w]. See the field [llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external of_nativeint : Llvm.lltype -> nativeint -> t
|
|
|
|
= "llvm_genericvalue_of_nativeint"
|
|
|
|
|
2007-12-23 17:59:28 +01:00
|
|
|
(** [of_int64 n w] boxes the int64 [i] in a generic value with the bitwidth
|
2008-03-09 08:17:38 +01:00
|
|
|
[w]. See the field [llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external of_int64 : Llvm.lltype -> int64 -> t = "llvm_genericvalue_of_int64"
|
|
|
|
|
2007-12-23 17:59:28 +01:00
|
|
|
(** [as_float fpty gv] unboxes the floating point-valued generic value [gv] of
|
|
|
|
floating point type [fpty]. See the fields [llvm::GenericValue::DoubleVal]
|
2008-03-09 08:17:38 +01:00
|
|
|
and [llvm::GenericValue::FloatVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external as_float : Llvm.lltype -> t -> float = "llvm_genericvalue_as_float"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [as_pointer gv] unboxes the pointer-valued generic value [gv]. See the
|
2008-03-09 08:17:38 +01:00
|
|
|
field [llvm::GenericValue::PointerVal]. *)
|
2010-03-04 00:51:30 +01:00
|
|
|
external as_pointer : t -> 'a = "llvm_genericvalue_as_pointer"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [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
|
2008-03-09 08:17:38 +01:00
|
|
|
[llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external as_int32 : t -> int32 = "llvm_genericvalue_as_int32"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [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
|
|
|
|
most significant bit may be lost). See the field
|
2008-03-09 08:17:38 +01:00
|
|
|
[llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external as_int : t -> int = "llvm_genericvalue_as_int"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [as_natint gv] unboxes the integer-valued generic value [gv] as a
|
|
|
|
[nativeint]. Is invalid if [gv] has a bitwidth greater than
|
2008-03-09 08:17:38 +01:00
|
|
|
[nativeint]. See the field [llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:30 +01:00
|
|
|
external as_nativeint : t -> nativeint = "llvm_genericvalue_as_nativeint"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [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
|
2008-03-09 08:17:38 +01:00
|
|
|
[llvm::GenericValue::IntVal]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external as_int64 : t -> int64 = "llvm_genericvalue_as_int64"
|
2007-12-23 17:59:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
module ExecutionEngine: sig
|
|
|
|
(** An execution engine is either a JIT compiler or an interpreter, capable of
|
|
|
|
directly loading an LLVM module and executing its functions without first
|
2008-03-09 08:17:38 +01:00
|
|
|
invoking a static compiler and generating a native executable. *)
|
2007-12-23 17:59:28 +01:00
|
|
|
type t
|
|
|
|
|
2010-03-03 00:59:00 +01:00
|
|
|
(** [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]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external create : Llvm.llmodule -> t = "llvm_ee_create"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2010-03-03 00:59:00 +01:00
|
|
|
(** [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].
|
2009-07-18 02:42:18 +02:00
|
|
|
See the function [llvm::EngineBuilder::create]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external create_interpreter : Llvm.llmodule -> t = "llvm_ee_create_interpreter"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2010-03-03 00:59:03 +01:00
|
|
|
(** [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].
|
2009-07-18 02:42:18 +02:00
|
|
|
See the function [llvm::EngineBuilder::create]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external create_jit : Llvm.llmodule -> int -> t = "llvm_ee_create_jit"
|
2010-03-03 00:59:03 +01:00
|
|
|
|
2007-12-23 17:59:28 +01:00
|
|
|
(** [dispose ee] releases the memory used by the execution engine and must be
|
2008-03-09 08:17:38 +01:00
|
|
|
invoked to avoid memory leaks. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external dispose : t -> unit = "llvm_ee_dispose"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2010-03-03 00:59:00 +01:00
|
|
|
(** [add_module m ee] adds the module [m] to the execution engine [ee]. *)
|
2010-03-04 00:51:30 +01:00
|
|
|
external add_module : Llvm.llmodule -> t -> unit = "llvm_ee_add_module"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2010-03-03 00:59:00 +01:00
|
|
|
(** [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. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external remove_module : Llvm.llmodule -> t -> Llvm.llmodule
|
|
|
|
= "llvm_ee_remove_module"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2008-03-09 08:17:38 +01:00
|
|
|
(** [find_function n ee] finds the function named [n] defined in any of the
|
2007-12-23 17:59:28 +01:00
|
|
|
modules owned by the execution engine [ee]. Returns [None] if the function
|
2008-03-09 08:17:38 +01:00
|
|
|
is not found and [Some f] otherwise. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external find_function : string -> t -> Llvm.llvalue option
|
|
|
|
= "llvm_ee_find_function"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [run_function f args ee] synchronously executes the function [f] with the
|
2008-03-09 08:17:38 +01:00
|
|
|
arguments [args], which must be compatible with the parameter types. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external run_function : Llvm.llvalue -> GenericValue.t array -> t ->
|
|
|
|
GenericValue.t
|
|
|
|
= "llvm_ee_run_function"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [run_static_ctors ee] executes the static constructors of each module in
|
2008-03-09 08:17:38 +01:00
|
|
|
the execution engine [ee]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external run_static_ctors : t -> unit = "llvm_ee_run_static_ctors"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [run_static_dtors ee] executes the static destructors of each module in
|
2008-03-09 08:17:38 +01:00
|
|
|
the execution engine [ee]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external run_static_dtors : t -> unit = "llvm_ee_run_static_dtors"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
2008-03-09 08:17:38 +01:00
|
|
|
(** [run_function_as_main f args env ee] executes the function [f] as a main
|
2007-12-23 17:59:28 +01:00
|
|
|
function, passing it [argv] and [argc] according to the string array
|
2008-03-09 08:17:38 +01:00
|
|
|
[args], and [envp] as specified by the array [env]. Returns the integer
|
|
|
|
return value of the function. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external run_function_as_main : Llvm.llvalue -> string array ->
|
|
|
|
(string * string) array -> t -> int
|
|
|
|
= "llvm_ee_run_function_as_main"
|
2007-12-23 17:59:28 +01:00
|
|
|
|
|
|
|
(** [free_machine_code f ee] releases the memory in the execution engine [ee]
|
2008-03-09 08:17:38 +01:00
|
|
|
used to store the machine code for the function [f]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external free_machine_code : Llvm.llvalue -> t -> unit
|
|
|
|
= "llvm_ee_free_machine_code"
|
2008-03-27 01:27:14 +01:00
|
|
|
|
|
|
|
(** [target_data ee] is the target data owned by the execution engine
|
|
|
|
[ee]. *)
|
2010-03-04 00:51:28 +01:00
|
|
|
external target_data : t -> Llvm_target.TargetData.t
|
|
|
|
= "LLVMGetExecutionEngineTargetData"
|
2007-12-23 17:59:28 +01:00
|
|
|
end
|
2009-09-14 23:54:32 +02:00
|
|
|
|
|
|
|
external initialize_native_target : unit -> bool
|
|
|
|
= "llvm_initialize_native_target"
|