llvm.org GIT mirror llvm / 26f3bd8
[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 Peter Zotov 7 years ago
9 changed file(s) with 72 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
323323 return Val_unit;
324324 }
325325
326 extern value llvm_alloc_target_data(LLVMTargetDataRef TargetData);
327
328 /* ExecutionEngine.t -> Llvm_target.TargetData.t */
329 CAMLprim value llvm_ee_get_target_data(LLVMExecutionEngineRef EE) {
330 LLVMTargetDataRef TD = LLVMGetExecutionEngineTargetData(EE);
331 return llvm_alloc_target_data(TD);
332 }
8383 = "llvm_ee_free_machine_code"
8484
8585 external target_data: t -> Llvm_target.DataLayout.t
86 = "LLVMGetExecutionEngineTargetData"
86 = "llvm_ee_get_target_data"
8787
8888 (* The following are not bound. Patches are welcome.
8989
90 get_target_data: t -> lltargetdata
9190 add_global_mapping: llvalue -> llgenericvalue -> t -> unit
9291 clear_all_global_mappings: t -> unit
9392 update_global_mapping: llvalue -> llgenericvalue -> t -> unit
1919 external add : t -> [ unit
2020 = "llvm_targetdata_add"
2121 external as_string : t -> string = "llvm_targetdata_as_string"
22 external dispose : t -> unit = "llvm_targetdata_dispose"
2322 end
2423
2524 external byte_order : DataLayout.t -> Endian.t = "llvm_byte_order"
2625 external pointer_size : DataLayout.t -> int = "llvm_pointer_size"
27 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
26 external intptr_type : DataLayout.t -> Llvm.lltype = "llvm_intptr_type"
2827 external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t
2928 = "llvm_size_in_bits"
3029 external store_size : DataLayout.t -> Llvm.lltype -> Int64.t = "llvm_store_size"
3333 (** [as_string td] is the string representation of the target data [td].
3434 See the constructor llvm::DataLayout::DataLayout. *)
3535 external as_string : t -> string = "llvm_targetdata_as_string"
36
37 (** Deallocates a DataLayout.
38 See the destructor llvm::DataLayout::~DataLayout. *)
39 external dispose : t -> unit = "llvm_targetdata_dispose"
4036 end
4137
4238 (** Returns the byte order of a target, either LLVMBigEndian or
5046
5147 (** Returns the integer type that is the same size as a pointer on a target.
5248 See the method llvm::DataLayout::getIntPtrType. *)
53 external intptr_type : DataLayout.t -> Llvm.lltype = "LLVMIntPtrType"
49 external intptr_type : DataLayout.t -> Llvm.lltype = "llvm_intptr_type"
5450
5551 (** Computes the size of a type in bits for a target.
5652 See the method llvm::DataLayout::getTypeSizeInBits. *)
1616
1717 #include "llvm-c/Target.h"
1818 #include "caml/alloc.h"
19 #include "caml/custom.h"
20
21 #define TargetData_val(v) (*(LLVMTargetDataRef *)(Data_custom_val(v)))
22
23 static void llvm_finalize_target_data(value TargetData) {
24 LLVMDisposeTargetData(TargetData_val(TargetData));
25 }
26
27 static struct custom_operations llvm_target_data_ops = {
28 (char *) "LLVMTargetData",
29 llvm_finalize_target_data,
30 custom_compare_default,
31 custom_hash_default,
32 custom_serialize_default,
33 custom_deserialize_default
34 #ifdef custom_compare_ext_default
35 , custom_compare_ext_default
36 #endif
37 };
38
39 value llvm_alloc_target_data(LLVMTargetDataRef TargetData) {
40 value V = alloc_custom(&llvm_target_data_ops, sizeof(LLVMTargetDataRef), 0, 1);
41 TargetData_val(V) = TargetData;
42 return V;
43 }
1944
2045 /* string -> DataLayout.t */
21 CAMLprim LLVMTargetDataRef llvm_targetdata_create(value StringRep) {
22 return LLVMCreateTargetData(String_val(StringRep));
46 CAMLprim value llvm_targetdata_create(value StringRep) {
47 return llvm_alloc_target_data(LLVMCreateTargetData(String_val(StringRep)));
2348 }
2449
2550 /* DataLayout.t -> [ unit */
26 CAMLprim value llvm_targetdata_add(LLVMTargetDataRef TD, LLVMPassManagerRef PM){
27 LLVMAddTargetData(TD, PM);
51 CAMLprim value llvm_targetdata_add(value TD, LLVMPassManagerRef PM){
52 LLVMAddTargetData(TargetData_val(TD), PM);
2853 return Val_unit;
2954 }
3055
3156 /* DataLayout.t -> string */
32 CAMLprim value llvm_targetdata_as_string(LLVMTargetDataRef TD) {
33 char *StringRep = LLVMCopyStringRepOfTargetData(TD);
57 CAMLprim value llvm_targetdata_as_string(value TD) {
58 char *StringRep = LLVMCopyStringRepOfTargetData(TargetData_val(TD));
3459 value Copy = copy_string(StringRep);
3560 LLVMDisposeMessage(StringRep);
3661 return Copy;
3762 }
3863
39 /* DataLayout.t -> unit */
40 CAMLprim value llvm_targetdata_dispose(LLVMTargetDataRef TD) {
41 LLVMDisposeTargetData(TD);
42 return Val_unit;
43 }
44
4564 /* DataLayout.t -> Endian.t */
46 CAMLprim value llvm_byte_order(LLVMTargetDataRef TD) {
47 return Val_int(LLVMByteOrder(TD));
65 CAMLprim value llvm_byte_order(value TD) {
66 return Val_int(LLVMByteOrder(TargetData_val(TD)));
4867 }
4968
5069 /* DataLayout.t -> int */
51 CAMLprim value llvm_pointer_size(LLVMTargetDataRef TD) {
52 return Val_int(LLVMPointerSize(TD));
70 CAMLprim value llvm_pointer_size(value TD) {
71 return Val_int(LLVMPointerSize(TargetData_val(TD)));
72 }
73
74 /* DataLayout.t -> int -> Llvm.lltype */
75 CAMLprim LLVMTypeRef llvm_intptr_type(value TD) {
76 return LLVMIntPtrType(TargetData_val(TD));;
5377 }
5478
5579 /* DataLayout.t -> Llvm.lltype -> Int64.t */
56 CAMLprim value llvm_size_in_bits(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
57 return caml_copy_int64(LLVMSizeOfTypeInBits(TD, Ty));
80 CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) {
81 return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty));
5882 }
5983
6084 /* DataLayout.t -> Llvm.lltype -> Int64.t */
61 CAMLprim value llvm_store_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
62 return caml_copy_int64(LLVMStoreSizeOfType(TD, Ty));
85 CAMLprim value llvm_store_size(value TD, LLVMTypeRef Ty) {
86 return caml_copy_int64(LLVMStoreSizeOfType(TargetData_val(TD), Ty));
6387 }
6488
6589 /* DataLayout.t -> Llvm.lltype -> Int64.t */
66 CAMLprim value llvm_abi_size(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
67 return caml_copy_int64(LLVMABISizeOfType(TD, Ty));
90 CAMLprim value llvm_abi_size(value TD, LLVMTypeRef Ty) {
91 return caml_copy_int64(LLVMABISizeOfType(TargetData_val(TD), Ty));
6892 }
6993
7094 /* DataLayout.t -> Llvm.lltype -> int */
71 CAMLprim value llvm_abi_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
72 return Val_int(LLVMABIAlignmentOfType(TD, Ty));
95 CAMLprim value llvm_abi_align(value TD, LLVMTypeRef Ty) {
96 return Val_int(LLVMABIAlignmentOfType(TargetData_val(TD), Ty));
7397 }
7498
7599 /* DataLayout.t -> Llvm.lltype -> int */
76 CAMLprim value llvm_stack_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
77 return Val_int(LLVMCallFrameAlignmentOfType(TD, Ty));
100 CAMLprim value llvm_stack_align(value TD, LLVMTypeRef Ty) {
101 return Val_int(LLVMCallFrameAlignmentOfType(TargetData_val(TD), Ty));
78102 }
79103
80104 /* DataLayout.t -> Llvm.lltype -> int */
81 CAMLprim value llvm_preferred_align(LLVMTargetDataRef TD, LLVMTypeRef Ty) {
82 return Val_int(LLVMPreferredAlignmentOfType(TD, Ty));
105 CAMLprim value llvm_preferred_align(value TD, LLVMTypeRef Ty) {
106 return Val_int(LLVMPreferredAlignmentOfType(TargetData_val(TD), Ty));
83107 }
84108
85109 /* DataLayout.t -> Llvm.llvalue -> int */
86 CAMLprim value llvm_preferred_align_of_global(LLVMTargetDataRef TD,
110 CAMLprim value llvm_preferred_align_of_global(value TD,
87111 LLVMValueRef GlobalVar) {
88 return Val_int(LLVMPreferredAlignmentOfGlobal(TD, GlobalVar));
112 return Val_int(LLVMPreferredAlignmentOfGlobal(TargetData_val(TD), GlobalVar));
89113 }
90114
91115 /* DataLayout.t -> Llvm.lltype -> Int64.t -> int */
92 CAMLprim value llvm_element_at_offset(LLVMTargetDataRef TD, LLVMTypeRef Ty,
116 CAMLprim value llvm_element_at_offset(value TD, LLVMTypeRef Ty,
93117 value Offset) {
94 return Val_int(LLVMElementAtOffset(TD, Ty, Int64_val(Offset)));
118 return Val_int(LLVMElementAtOffset(TargetData_val(TD), Ty, Int64_val(Offset)));
95119 }
96120
97121 /* DataLayout.t -> Llvm.lltype -> int -> Int64.t */
98 CAMLprim value llvm_offset_of_element(LLVMTargetDataRef TD, LLVMTypeRef Ty,
122 CAMLprim value llvm_offset_of_element(value TD, LLVMTypeRef Ty,
99123 value Index) {
100 return caml_copy_int64(LLVMOffsetOfElement(TD, Ty, Int_val(Index)));
124 return caml_copy_int64(LLVMOffsetOfElement(TargetData_val(TD), Ty, Int_val(Index)));
101125 }
6464 ++ add_strip_dead_prototypes
6565 ++ add_strip_symbols
6666 ++ PassManager.run_module m
67 ++ PassManager.dispose);
68
69 DataLayout.dispose td
67 ++ PassManager.dispose)
7068
7169
7270 (*===-- Driver ------------------------------------------------------------===*)
7979 ++ PassManager.initialize
8080 ++ PassManager.run_function fn
8181 ++ PassManager.finalize
82 ++ PassManager.dispose);
83
84 DataLayout.dispose td
82 ++ PassManager.dispose)
8583
8684
8785 (*===-- Driver ------------------------------------------------------------===*)
5353 assert_equal (preferred_align td sty) 8;
5454 assert_equal (preferred_align_of_global td (declare_global sty "g" m)) 8;
5555 assert_equal (element_at_offset td sty (Int64.of_int 1)) 0;
56 assert_equal (offset_of_element td sty 1) (Int64.of_int 4);
57 DataLayout.dispose td
56 assert_equal (offset_of_element td sty 1) (Int64.of_int 4)
5857
5958
6059 (*===-- Driver ------------------------------------------------------------===*)
4848 ++ add_loop_vectorize
4949 ++ add_slp_vectorize
5050 ++ PassManager.run_module m
51 ++ PassManager.dispose);
52
53 DataLayout.dispose td
51 ++ PassManager.dispose)
5452
5553
5654 (*===-- Driver ------------------------------------------------------------===*)