From fa6ab4393ebb7add77a4a957dc50453d07b54a62 Mon Sep 17 00:00:00 2001 From: Peter Zotov Date: Mon, 11 Nov 2013 14:47:28 +0000 Subject: [PATCH] [OCaml] Add missing Llvm_target functions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194382 91177308-0d34-0410-b5e6-96231b3b80d8 --- bindings/ocaml/target/llvm_target.ml | 5 +++++ bindings/ocaml/target/llvm_target.mli | 12 ++++++++++++ bindings/ocaml/target/target_ocaml.c | 11 +++++++++++ test/Bindings/Ocaml/target.ml | 2 ++ 4 files changed, 30 insertions(+) diff --git a/bindings/ocaml/target/llvm_target.ml b/bindings/ocaml/target/llvm_target.ml index b6a4d51ebb1..8a6aabf3c6c 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 7c255ad4ad7..87b70059ae6 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 46bf8dc4548..5178c09fde5 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 017a886059c..25a96647b0d 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);