diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml --- a/llvm/bindings/ocaml/llvm/llvm.ml +++ b/llvm/bindings/ocaml/llvm/llvm.ml @@ -508,6 +508,10 @@ external pointer_type : lltype -> lltype = "llvm_pointer_type" external qualified_pointer_type : lltype -> int -> lltype = "llvm_qualified_pointer_type" +external pointer_type_in_context : llcontext -> int -> lltype + = "llvm_pointer_type_in_context" +external pointer_type_is_opaque : lltype -> bool + = "llvm_pointer_type_is_opaque" external vector_type : lltype -> int -> lltype = "llvm_vector_type" external element_type : lltype -> lltype = "LLVMGetElementType" diff --git a/llvm/bindings/ocaml/llvm/llvm.mli b/llvm/bindings/ocaml/llvm/llvm.mli --- a/llvm/bindings/ocaml/llvm/llvm.mli +++ b/llvm/bindings/ocaml/llvm/llvm.mli @@ -726,6 +726,15 @@ See the method [llvm::PointerType::get]. *) val qualified_pointer_type : lltype -> int -> lltype +(** [pointer_type_in_context context as] returns the opaque pointer type + referencing objects in address [as]. + See the method [llvm::PointerType::get]. *) +val pointer_type_in_context : llcontext -> int -> lltype + +(** [pointer_type_is_opaque pty] returns whether the pointer type [pty] + is opaque. See the method [llvm::PointerType::isOpaque]. *) +val pointer_type_is_opaque : lltype -> bool + (** [vector_type ty n] returns the array type containing [n] elements of the primitive type [ty]. See the method [llvm::ArrayType::get]. *) val vector_type : lltype -> int -> lltype diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c --- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -581,6 +581,16 @@ return LLVMPointerType(ElementTy, Int_val(AddressSpace)); } +/* llcontext -> int -> lltype */ +LLVMTypeRef llvm_pointer_type_in_context(LLVMContextRef C, value AddressSpace) { + return LLVMPointerTypeInContext(C, Int_val(AddressSpace)); +} + +/* lltype -> bool */ +value llvm_pointer_type_is_opaque(LLVMTypeRef PtrTy) { + return Val_bool(LLVMPointerTypeIsOpaque(PtrTy)); +} + /* lltype -> int -> lltype */ LLVMTypeRef llvm_vector_type(LLVMTypeRef ElementTy, value Count) { return LLVMVectorType(ElementTy, Int_val(Count)); diff --git a/llvm/test/Bindings/OCaml/core.ml b/llvm/test/Bindings/OCaml/core.ml --- a/llvm/test/Bindings/OCaml/core.ml +++ b/llvm/test/Bindings/OCaml/core.ml @@ -41,6 +41,10 @@ insist (i32_type = (Array.get (subtypes ar)) 0); insist (i8_type = (Array.get (subtypes ar)) 1) +(*===-- Pointer types ----------------------------------------------------===*) +let test_pointer_types () = + insist (pointer_type_is_opaque (pointer_type_in_context context 0)); + insist (not (pointer_type_is_opaque (pointer_type i8_type))) (*===-- Conversion --------------------------------------------------------===*)