aboutsummaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2013-11-11 14:47:11 +0000
committerPeter Zotov <whitequark@whitequark.org>2013-11-11 14:47:11 +0000
commit26f3bd89660e46a76a3b0267b23b00d917a45404 (patch)
tree12e5f7d7e2b1c5321eaeef1f65c76783875d4838 /bindings
parent9683888db61498edc05f37cf8f3a8253e47ba016 (diff)
downloadexternal_llvm-26f3bd89660e46a76a3b0267b23b00d917a45404.zip
external_llvm-26f3bd89660e46a76a3b0267b23b00d917a45404.tar.gz
external_llvm-26f3bd89660e46a76a3b0267b23b00d917a45404.tar.bz2
[OCaml] Make Llvm_target.DataLayout.t automatically managed
This breaks the API by removing Llvm_target.DataLayout.dispose. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194380 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/ocaml/executionengine/executionengine_ocaml.c7
-rw-r--r--bindings/ocaml/executionengine/llvm_executionengine.ml3
-rw-r--r--bindings/ocaml/target/llvm_target.ml3
-rw-r--r--bindings/ocaml/target/llvm_target.mli6
-rw-r--r--bindings/ocaml/target/target_ocaml.c92
5 files changed, 68 insertions, 43 deletions
diff --git a/bindings/ocaml/executionengine/executionengine_ocaml.c b/bindings/ocaml/executionengine/executionengine_ocaml.c
index 32f6c59..3d2c8b0 100644
--- a/bindings/ocaml/executionengine/executionengine_ocaml.c
+++ b/bindings/ocaml/executionengine/executionengine_ocaml.c
@@ -324,3 +324,10 @@ CAMLprim value llvm_ee_free_machine_code(LLVMValueRef F,
return Val_unit;
}
+extern value llvm_alloc_target_data(LLVMTargetDataRef TargetData);
+
+/* ExecutionEngine.t -> Llvm_target.TargetData.t */
+CAMLprim value llvm_ee_get_target_data(LLVMExecutionEngineRef EE) {
+ LLVMTargetDataRef TD = LLVMGetExecutionEngineTargetData(EE);
+ return llvm_alloc_target_data(TD);
+}
diff --git a/bindings/ocaml/executionengine/llvm_executionengine.ml b/bindings/ocaml/executionengine/llvm_executionengine.ml
index b083b7d..0199154 100644
--- a/bindings/ocaml/executionengine/llvm_executionengine.ml
+++ b/bindings/ocaml/executionengine/llvm_executionengine.ml
@@ -84,11 +84,10 @@ module ExecutionEngine = struct
= "llvm_ee_free_machine_code"
external target_data: t -> Llvm_target.DataLayout.t
- = "LLVMGetExecutionEngineTargetData"
+ = "llvm_ee_get_target_data"
(* The following are not bound. Patches are welcome.
- get_target_data: t -> lltargetdata
add_global_mapping: llvalue -> llgenericvalue -> t -> unit
clear_all_global_mappings: t -> unit
update_global_mapping: llvalue -> llgenericvalue -> t -> unit
diff --git a/bindings/ocaml/target/llvm_target.ml b/bindings/ocaml/target/llvm_target.ml
index 2959f0c..d892567 100644
--- a/bindings/ocaml/target/llvm_target.ml
+++ b/bindings/ocaml/target/llvm_target.ml
@@ -20,12 +20,11 @@ module DataLayout = struct
external add : t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit
= "llvm_targetdata_add"
external as_string : t -> string = "llvm_targetdata_as_string"
- external dispose : t -> unit = "llvm_targetdata_dispose"
end
external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
-external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
+external intptr_type : DataLayout.t -> Llvm.lltype = "llvm_intptr_type"
external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
= "llvm_size_in_bits"
external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
diff --git a/bindings/ocaml/target/llvm_target.mli b/bindings/ocaml/target/llvm_target.mli
index 667fef0..f5426af 100644
--- a/bindings/ocaml/target/llvm_target.mli
+++ b/bindings/ocaml/target/llvm_target.mli
@@ -34,10 +34,6 @@ module DataLayout : sig
(** [as_string td] is the string representation of the target data [td].
See the constructor llvm::DataLayout::DataLayout. *)
external as_string : t -> string = "llvm_targetdata_as_string"
-
- (** Deallocates a DataLayout.
- See the destructor llvm::DataLayout::~DataLayout. *)
- external dispose : t -> unit = "llvm_targetdata_dispose"
end
(** Returns the byte order of a target, either LLVMBigEndian or
@@ -51,7 +47,7 @@ external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
(** Returns the integer type that is the same size as a pointer on a target.
See the method llvm::DataLayout::getIntPtrType. *)
-external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
+external intptr_type : DataLayout.t -> Llvm.lltype = "llvm_intptr_type"
(** Computes the size of a type in bits for a target.
See the method llvm::DataLayout::getTypeSizeInBits. *)
diff --git a/bindings/ocaml/target/target_ocaml.c b/bindings/ocaml/target/target_ocaml.c
index 4d0beff..e457742 100644
--- a/bindings/ocaml/target/target_ocaml.c
+++ b/bindings/ocaml/target/target_ocaml.c
@@ -17,86 +17,110 @@
#include "llvm-c/Target.h"
#include "caml/alloc.h"
+#include "caml/custom.h"
+
+#define TargetData_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
+
+static void llvm_finalize_target_data(value TargetData) {
+ LLVMDisposeTargetData(TargetData_val(TargetData));
+}
+
+static struct custom_operations llvm_target_data_ops = {
+ (char *) "LLVMTargetData",
+ llvm_finalize_target_data,
+ custom_compare_default,
+ custom_hash_default,
+ custom_serialize_default,
+ custom_deserialize_default
+#ifdef custom_compare_ext_default
+ , custom_compare_ext_default
+#endif
+};
+
+value llvm_alloc_target_data(LLVMTargetDataRef TargetData) {
+ value V = alloc_custom(&llvm_target_data_ops, sizeof(LLVMTargetDataRef), 0, 1);
+ TargetData_val(V) = TargetData;
+ return V;
+}
/* string -> DataLayout.t */
-CAMLprim LLVMTargetDataRef llvm_targetdata_create(value StringRep) {
- return LLVMCreateTargetData(String_val(StringRep));
+CAMLprim value llvm_targetdata_create(value StringRep) {
+ return llvm_alloc_target_data(LLVMCreateTargetData(String_val(StringRep)));
}
/* DataLayout.t -> [<Llvm.PassManager.any] Llvm.PassManager.t -> unit */
-CAMLprim value llvm_targetdata_add(LLVMTargetDataRef TD, LLVMPassManagerRef PM){
- LLVMAddTargetData(TD, PM);
+CAMLprim value llvm_targetdata_add(value TD, LLVMPassManagerRef PM){
+ LLVMAddTargetData(TargetData_val(TD), PM);
return Val_unit;
}
/* DataLayout.t -> string */
-CAMLprim value llvm_targetdata_as_string(LLVMTargetDataRef TD) {
- char *StringRep = LLVMCopyStringRepOfTargetData(TD);
+CAMLprim value llvm_targetdata_as_string(value TD) {
+ char *StringRep = LLVMCopyStringRepOfTargetData(TargetData_val(TD));
value Copy = copy_string(StringRep);
LLVMDisposeMessage(StringRep);
return Copy;
}
-/* DataLayout.t -> unit */
-CAMLprim value llvm_targetdata_dispose(LLVMTargetDataRef TD) {
- LLVMDisposeTargetData(TD);
- return Val_unit;
-}
-
/* DataLayout.t -> Endian.t */
-CAMLprim value llvm_byte_order(LLVMTargetDataRef TD) {
- return Val_int(LLVMByteOrder(TD));
+CAMLprim value llvm_byte_order(value TD) {
+ return Val_int(LLVMByteOrder(TargetData_val(TD)));
}
/* DataLayout.t -> int */
-CAMLprim value llvm_pointer_size(LLVMTargetDataRef TD) {
- return Val_int(LLVMPointerSize(TD));
+CAMLprim value llvm_pointer_size(value TD) {
+ return Val_int(LLVMPointerSize(TargetData_val(TD)));
+}
+
+/* DataLayout.t -> int -> Llvm.lltype */
+CAMLprim LLVMTypeRef llvm_intptr_type(value TD) {
+ return LLVMIntPtrType(TargetData_val(TD));;
}
/* DataLayout.t -> Llvm.lltype -> Int64.t */
-CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
+CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) {
+ return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.lltype -> Int64.t */
-CAMLprim value llvm_store_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
+CAMLprim value llvm_store_size(value TD, LLVMTypeRef Ty) {
+ return caml_copy_int64(LLVMStoreSizeOfType(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.lltype -> Int64.t */
-CAMLprim value llvm_abi_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
+CAMLprim value llvm_abi_size(value TD, LLVMTypeRef Ty) {
+ return caml_copy_int64(LLVMABISizeOfType(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.lltype -> int */
-CAMLprim value llvm_abi_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return Val_int(LLVMABIAlignmentOfType(TD, Ty));
+CAMLprim value llvm_abi_align(value TD, LLVMTypeRef Ty) {
+ return Val_int(LLVMABIAlignmentOfType(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.lltype -> int */
-CAMLprim value llvm_stack_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
+CAMLprim value llvm_stack_align(value TD, LLVMTypeRef Ty) {
+ return Val_int(LLVMCallFrameAlignmentOfType(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.lltype -> int */
-CAMLprim value llvm_preferred_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
- return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
+CAMLprim value llvm_preferred_align(value TD, LLVMTypeRef Ty) {
+ return Val_int(LLVMPreferredAlignmentOfType(TargetData_val(TD), Ty));
}
/* DataLayout.t -> Llvm.llvalue -> int */
-CAMLprim value llvm_preferred_align_of_global(LLVMTargetDataRef TD,
+CAMLprim value llvm_preferred_align_of_global(value TD,
LLVMValueRef GlobalVar) {
- return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
+ return Val_int(LLVMPreferredAlignmentOfGlobal(TargetData_val(TD), GlobalVar));
}
/* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
-CAMLprim value llvm_element_at_offset(LLVMTargetDataRef TD, LLVMTypeRef Ty,
+CAMLprim value llvm_element_at_offset(value TD, LLVMTypeRef Ty,
value Offset) {
- return Val_int(LLVMElementAtOffset(TD, Ty, Int64_val(Offset)));
+ return Val_int(LLVMElementAtOffset(TargetData_val(TD), Ty, Int64_val(Offset)));
}
/* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
-CAMLprim value llvm_offset_of_element(LLVMTargetDataRef TD, LLVMTypeRef Ty,
+CAMLprim value llvm_offset_of_element(value TD, LLVMTypeRef Ty,
value Index) {
- return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));
+ return caml_copy_int64(LLVMOffsetOfElement(TargetData_val(TD), Ty, Int_val(Index)));
}