[llvm] 729e3d8 - [llvm-ocaml] Add binding for constructing opaque pointers
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 14:39:07 PDT 2022
Author: Alan Hu
Date: 2022-10-03T14:38:48-07:00
New Revision: 729e3d8aa76cf3098672a9466b23dbfd3bd0bf49
URL: https://github.com/llvm/llvm-project/commit/729e3d8aa76cf3098672a9466b23dbfd3bd0bf49
DIFF: https://github.com/llvm/llvm-project/commit/729e3d8aa76cf3098672a9466b23dbfd3bd0bf49.diff
LOG: [llvm-ocaml] Add binding for constructing opaque pointers
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D134916
Added:
Modified:
llvm/bindings/ocaml/llvm/llvm.ml
llvm/bindings/ocaml/llvm/llvm.mli
llvm/bindings/ocaml/llvm/llvm_ocaml.c
llvm/test/Bindings/OCaml/core.ml
Removed:
################################################################################
diff --git a/llvm/bindings/ocaml/llvm/llvm.ml b/llvm/bindings/ocaml/llvm/llvm.ml
index 993fa6f1d6c6e..45ded667cf903 100644
--- a/llvm/bindings/ocaml/llvm/llvm.ml
+++ b/llvm/bindings/ocaml/llvm/llvm.ml
@@ -508,6 +508,8 @@ external array_type : lltype -> int -> lltype = "llvm_array_type"
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 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
index ae8ca9e42e582..b8b014f4b3d83 100644
--- a/llvm/bindings/ocaml/llvm/llvm.mli
+++ b/llvm/bindings/ocaml/llvm/llvm.mli
@@ -726,6 +726,11 @@ val pointer_type : lltype -> lltype
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 space [as].
+ See the method [llvm::PointerType::get]. *)
+val pointer_type_in_context : llcontext -> int -> lltype
+
(** [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
index e950972fc02ff..7f306625f0850 100644
--- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c
+++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c
@@ -581,6 +581,11 @@ LLVMTypeRef llvm_qualified_pointer_type(LLVMTypeRef ElementTy,
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 -> 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
index bd93a4ac12321..6472b2f82a9a1 100644
--- a/llvm/test/Bindings/OCaml/core.ml
+++ b/llvm/test/Bindings/OCaml/core.ml
@@ -41,6 +41,10 @@ let test_contained_types () =
insist (i32_type = (Array.get (subtypes ar)) 0);
insist (i8_type = (Array.get (subtypes ar)) 1)
+(*===-- Pointer types ----------------------------------------------------===*)
+let test_pointer_types () =
+ insist (address_space (pointer_type_in_context context 0) = 0);
+ insist (address_space (pointer_type_in_context context 1) = 1)
(*===-- Conversion --------------------------------------------------------===*)
@@ -1502,6 +1506,7 @@ let test_writer () =
let _ =
suite "contained types" test_contained_types;
+ suite "pointer types" test_pointer_types;
suite "conversion" test_conversion;
suite "target" test_target;
suite "constants" test_constants;
More information about the llvm-commits
mailing list