summaryrefslogtreecommitdiffstats
path: root/llvm/bindings
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2014-12-24 01:52:51 +0000
committerPeter Zotov <whitequark@whitequark.org>2014-12-24 01:52:51 +0000
commitaf6535bf12eea3f6c704a12fbf7a198fbc26ec1b (patch)
treed2d4891b0a3196c49930ccf0e70c116068891178 /llvm/bindings
parentffb7ce56a6e1b4477b656d8e2313ba7c1ac4c83f (diff)
downloadbcm5719-llvm-af6535bf12eea3f6c704a12fbf7a198fbc26ec1b.tar.gz
bcm5719-llvm-af6535bf12eea3f6c704a12fbf7a198fbc26ec1b.zip
[OCaml] Expose Llvm_executionengine.get_{global_value,function}_address.
Patch by Ramkumar Ramachandra <artagnon@gmail.com>. Also remove Llvm_executionengine.get_pointer_to_global, as it is actually deprecated and didn't appear in a stable release. llvm-svn: 224801
Diffstat (limited to 'llvm/bindings')
-rw-r--r--llvm/bindings/ocaml/executionengine/executionengine_ocaml.c12
-rw-r--r--llvm/bindings/ocaml/executionengine/llvm_executionengine.ml22
-rw-r--r--llvm/bindings/ocaml/executionengine/llvm_executionengine.mli21
3 files changed, 40 insertions, 15 deletions
diff --git a/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c b/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
index 0557efc5c9d..b7992508bf9 100644
--- a/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
+++ b/llvm/bindings/ocaml/executionengine/executionengine_ocaml.c
@@ -115,8 +115,12 @@ CAMLprim value llvm_ee_add_global_mapping(LLVMValueRef Global, value Ptr,
return Val_unit;
}
-/* Llvm.llvalue -> llexecutionengine -> int64 */
-CAMLprim value llvm_ee_get_pointer_to_global(LLVMValueRef Global,
- LLVMExecutionEngineRef EE) {
- return caml_copy_int64((int64_t) LLVMGetPointerToGlobal(EE, Global));
+CAMLprim value llvm_ee_get_global_value_address(value Name,
+ LLVMExecutionEngineRef EE) {
+ return caml_copy_int64((int64_t) LLVMGetGlobalValueAddress(EE, String_val(Name)));
+}
+
+CAMLprim value llvm_ee_get_function_address(value Name,
+ LLVMExecutionEngineRef EE) {
+ return caml_copy_int64((int64_t) LLVMGetFunctionAddress(EE, String_val(Name)));
}
diff --git a/llvm/bindings/ocaml/executionengine/llvm_executionengine.ml b/llvm/bindings/ocaml/executionengine/llvm_executionengine.ml
index c0ff3308dd0..34031bed603 100644
--- a/llvm/bindings/ocaml/executionengine/llvm_executionengine.ml
+++ b/llvm/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
diff --git a/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli b/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli
index b07151df744..bc076beacea 100644
--- a/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli
+++ b/llvm/bindings/ocaml/executionengine/llvm_executionengine.mli
@@ -76,9 +76,18 @@ val data_layout : llexecutionengine -> Llvm_target.DataLayout.t
All uses of [gv] in the compiled code will refer to [ptr]. *)
val add_global_mapping : Llvm.llvalue -> 'a Ctypes.ptr -> llexecutionengine -> unit
-(** [get_pointer_to_global gv typ ee] returns the value of the global
- variable [gv] in the execution engine [ee] as type [typ], which may
- be a pointer type (e.g. [int ptr typ]) for global variables or
- a function (e.g. [(int -> int) typ]) type for functions, and which
- will be live as long as [gv] and [ee] are. *)
-val get_pointer_to_global : Llvm.llvalue -> 'a Ctypes.typ -> llexecutionengine -> 'a
+(** [get_global_value_address id typ ee] returns a pointer to the
+ identifier [id] as type [typ], which will be a pointer type for a
+ value, and which will be live as long as [id] and [ee]
+ are. Caution: this function finalizes, i.e. forces code
+ generation, all loaded modules. Further modifications to the
+ modules will not have any effect. *)
+val get_global_value_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
+
+(** [get_function_address fn typ ee] returns a pointer to the function
+ [fn] as type [typ], which will be a pointer type for a function
+ (e.g. [(int -> int) typ]), and which will be live as long as [fn]
+ and [ee] are. Caution: this function finalizes, i.e. forces code
+ generation, all loaded modules. Further modifications to the
+ modules will not have any effect. *)
+val get_function_address : string -> 'a Ctypes.typ -> llexecutionengine -> 'a
OpenPOWER on IntegriCloud