diff options
-rw-r--r-- | bindings/ocaml/target/llvm_target.ml | 5 | ||||
-rw-r--r-- | bindings/ocaml/target/llvm_target.mli | 12 | ||||
-rw-r--r-- | bindings/ocaml/target/target_ocaml.c | 11 | ||||
-rw-r--r-- | test/Bindings/Ocaml/target.ml | 2 |
4 files changed, 30 insertions, 0 deletions
diff --git a/bindings/ocaml/target/llvm_target.ml b/bindings/ocaml/target/llvm_target.ml index b6a4d51ebb..8a6aabf3c6 100644 --- a/bindings/ocaml/target/llvm_target.ml +++ b/bindings/ocaml/target/llvm_target.ml @@ -26,6 +26,11 @@ 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.llcontext -> Llvm.lltype = "llvm_intptr_type" +external qualified_pointer_size : DataLayout.t -> int -> int + = "llvm_qualified_pointer_size" +external qualified_intptr_type : DataLayout.t -> Llvm.llcontext -> + int -> Llvm.lltype + = "llvm_qualified_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 7c255ad4ad..87b70059ae 100644 --- a/bindings/ocaml/target/llvm_target.mli +++ b/bindings/ocaml/target/llvm_target.mli @@ -50,6 +50,18 @@ external pointer_size : DataLayout.t -> int = "llvm_pointer_size" external intptr_type : DataLayout.t -> Llvm.llcontext -> Llvm.lltype = "llvm_intptr_type" +(** Returns the pointer size in bytes for a target in a given address space. + See the method llvm::DataLayout::getPointerSize. *) +external qualified_pointer_size : DataLayout.t -> int -> int + = "llvm_qualified_pointer_size" + +(** Returns the integer type that is the same size as a pointer on a target + in a given address space. + See the method llvm::DataLayout::getIntPtrType. *) +external qualified_intptr_type : DataLayout.t -> Llvm.llcontext -> + int -> Llvm.lltype + = "llvm_qualified_intptr_type" + (** Computes the size of a type in bits for a target. See the method llvm::DataLayout::getTypeSizeInBits. *) external size_in_bits : DataLayout.t -> Llvm.lltype -> Int64.t diff --git a/bindings/ocaml/target/target_ocaml.c b/bindings/ocaml/target/target_ocaml.c index 46bf8dc454..5178c09fde 100644 --- a/bindings/ocaml/target/target_ocaml.c +++ b/bindings/ocaml/target/target_ocaml.c @@ -77,6 +77,17 @@ CAMLprim LLVMTypeRef llvm_intptr_type(value TD, LLVMContextRef C) { return LLVMIntPtrTypeInContext(C, TargetData_val(TD));; } +/* DataLayout.t -> int -> int */ +CAMLprim value llvm_qualified_pointer_size(LLVMTargetDataRef TD, value AS) { + return Val_int(LLVMPointerSizeForAS(TargetData_val(TD), Int_val(AS))); +} + +/* DataLayout.t -> int -> Llvm.lltype */ +CAMLprim LLVMTypeRef llvm_qualified_intptr_type(LLVMTargetDataRef TD, + LLVMContextRef C, value AS) { + return LLVMIntPtrTypeForASInContext(C, TargetData_val(TD), Int_val(AS)); +} + /* DataLayout.t -> Llvm.lltype -> Int64.t */ CAMLprim value llvm_size_in_bits(value TD, LLVMTypeRef Ty) { return caml_copy_int64(LLVMSizeOfTypeInBits(TargetData_val(TD), Ty)); diff --git a/test/Bindings/Ocaml/target.ml b/test/Bindings/Ocaml/target.ml index 017a886059..25a96647b0 100644 --- a/test/Bindings/Ocaml/target.ml +++ b/test/Bindings/Ocaml/target.ml @@ -47,6 +47,8 @@ let test_target_data () = assert_equal (byte_order td) Endian.Little; assert_equal (pointer_size td) 4; assert_equal (intptr_type td context) i32_type; + assert_equal (qualified_pointer_size td 0) 4; + assert_equal (qualified_intptr_type td context 0) i32_type; assert_equal (size_in_bits td sty) (Int64.of_int 96); assert_equal (store_size td sty) (Int64.of_int 12); assert_equal (abi_size td sty) (Int64.of_int 12); |