X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=bindings%2Focaml%2Fexecutionengine%2Fllvm_executionengine.ml;h=34031bed603160eec05d80616f8ada5a73d3f8d0;hb=0357f8735ed3f102248961dbc5fa48f2f21e395e;hp=c0ff3308dd095b3c8eaf3d41d3627b30cb2e8ffe;hpb=43e17cfe852f8f56175314ace78354221ab1a247;p=oota-llvm.git diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml index c0ff3308dd0..34031bed603 100644 --- a/bindings/ocaml/executionengine/llvm_executionengine.ml +++ b/bindings/ocaml/executionengine/llvm_executionengine.ml @@ -45,15 +45,27 @@ external data_layout : llexecutionengine -> Llvm_target.DataLayout.t = "llvm_ee_get_data_layout" external add_global_mapping_ : Llvm.llvalue -> int64 -> llexecutionengine -> unit = "llvm_ee_add_global_mapping" -external get_pointer_to_global_ : Llvm.llvalue -> llexecutionengine -> int64 - = "llvm_ee_get_pointer_to_global" +external get_global_value_address_ : string -> llexecutionengine -> int64 + = "llvm_ee_get_global_value_address" +external get_function_address_ : string -> llexecutionengine -> int64 + = "llvm_ee_get_function_address" let add_global_mapping llval ptr ee = add_global_mapping_ llval (Ctypes.raw_address_of_ptr (Ctypes.to_voidp ptr)) ee -let get_pointer_to_global llval typ ee = - Ctypes.coerce (let open Ctypes in ptr void) typ - (Ctypes.ptr_of_raw_address (get_pointer_to_global_ llval ee)) +let get_global_value_address name typ ee = + let vptr = get_global_value_address_ name ee in + if Int64.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")) + +let get_function_address name typ ee = + let fptr = get_function_address_ name ee in + if Int64.to_int fptr <> 0 then + let open Ctypes in coerce (ptr void) typ (ptr_of_raw_address fptr) + else + raise (Error ("Function " ^ name ^ " not found")) (* The following are not bound. Patches are welcome. target_machine : llexecutionengine -> Llvm_target.TargetMachine.t