-module ExecutionEngine = struct
- type t
-
- (* FIXME: Ocaml is not running this setup code unless we use 'val' in the
- interface, which causes the emission of a stub for each function;
- using 'external' in the module allows direct calls into
- ocaml_executionengine.c. This is hardly fatal, but it is unnecessary
- overhead on top of the two stubs that are already invoked for each
- call into LLVM. *)
- let _ = register_exns (Error "")
-
- external create: Llvm.llmoduleprovider -> t
- = "llvm_ee_create"
- external create_interpreter: Llvm.llmoduleprovider -> t
- = "llvm_ee_create_interpreter"
- external create_jit: Llvm.llmoduleprovider -> t
- = "llvm_ee_create_jit"
- external create_fast_jit: Llvm.llmoduleprovider -> t
- = "llvm_ee_create_fast_jit"
- external dispose: t -> unit
- = "llvm_ee_dispose"
- external add_module_provider: Llvm.llmoduleprovider -> t -> unit
- = "llvm_ee_add_mp"
- external remove_module_provider: Llvm.llmoduleprovider -> t -> Llvm.llmodule
- = "llvm_ee_remove_mp"
- external find_function: string -> t -> Llvm.llvalue option
- = "llvm_ee_find_function"
- external run_function: Llvm.llvalue -> GenericValue.t array -> t ->
- GenericValue.t
- = "llvm_ee_run_function"
- external run_static_ctors: t -> unit
- = "llvm_ee_run_static_ctors"
- external run_static_dtors: t -> unit
- = "llvm_ee_run_static_dtors"
- external run_function_as_main: Llvm.llvalue -> string array ->
- (string * string) array -> t -> int
- = "llvm_ee_run_function_as_main"
- external free_machine_code: Llvm.llvalue -> t -> unit
- = "llvm_ee_free_machine_code"
+let get_global_value_address name typ ee =
+ let vptr = get_global_value_address_ name ee in
+ if Nativeint.to_int vptr <> 0 then
+ let open Ctypes in !@ (coerce (ptr void) (ptr typ) (ptr_of_raw_address vptr))
+ else
+ raise (Error ("Value " ^ name ^ " not found"))