Index: bindings/ocaml/llvm/llvm.ml =================================================================== --- bindings/ocaml/llvm/llvm.ml +++ bindings/ocaml/llvm/llvm.ml @@ -459,6 +459,7 @@ external is_opaque : lltype -> bool = "llvm_is_opaque" (*--... Operations on pointer, vector, and array types .....................--*) +external contained_type : lltype -> int -> lltype = "llvm_contained_type" external array_type : lltype -> int -> lltype = "llvm_array_type" external pointer_type : lltype -> lltype = "llvm_pointer_type" external qualified_pointer_type : lltype -> int -> lltype Index: bindings/ocaml/llvm/llvm.mli =================================================================== --- bindings/ocaml/llvm/llvm.mli +++ bindings/ocaml/llvm/llvm.mli @@ -658,6 +658,9 @@ (** {7 Operations on pointer, vector, and array types} *) +(** [contained_type ty n] returns the [n]'th type 'contained' in the derived type *) +val contained_type : lltype -> int -> lltype + (** [array_type ty n] returns the array type containing [n] elements of type [ty]. See the method [llvm::ArrayType::get]. *) val array_type : lltype -> int -> lltype Index: bindings/ocaml/llvm/llvm_ocaml.c =================================================================== --- bindings/ocaml/llvm/llvm_ocaml.c +++ bindings/ocaml/llvm/llvm_ocaml.c @@ -507,6 +507,11 @@ /*--... Operations on array, pointer, and vector types .....................--*/ /* lltype -> int -> lltype */ +CAMLprim LLVMTypeRef llvm_contained_type(LLVMTypeRef Ty, value ElementNum) { + return LLVMGetContainedType(Ty, Int_val(ElementNum)); +} + +/* lltype -> int -> lltype */ CAMLprim LLVMTypeRef llvm_array_type(LLVMTypeRef ElementTy, value Count) { return LLVMArrayType(ElementTy, Int_val(Count)); } Index: include/llvm-c/Core.h =================================================================== --- include/llvm-c/Core.h +++ include/llvm-c/Core.h @@ -1040,6 +1040,13 @@ LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); /** + * Returns the types 'contained' in the derived type + * + * @see llvm::Type::getContainedType() + */ +LLVMTypeRef LLVMGetContainedType(LLVMTypeRef Tp, unsigned ElementNum); + +/** * Create a fixed size array type that refers to a specific type. * * The created type will exist in the context that its element type Index: lib/IR/Core.cpp =================================================================== --- lib/IR/Core.cpp +++ lib/IR/Core.cpp @@ -568,6 +568,10 @@ /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/ +LLVMTypeRef LLVMGetContainedType(LLVMTypeRef Tp, unsigned ElementNum) { + return wrap(unwrap(Tp)->getContainedType(ElementNum)); +} + LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) { return wrap(ArrayType::get(unwrap(ElementType), ElementCount)); } Index: test/Bindings/OCaml/core.ml =================================================================== --- test/Bindings/OCaml/core.ml +++ test/Bindings/OCaml/core.ml @@ -66,6 +66,17 @@ let filename = Sys.argv.(1) let m = create_module context filename +(*===-- Contained types --------------------------------------------------===*) + +let test_contained_types () = + let pointer_i32 = pointer_type i32_type in + let contained_i32 = contained_type pointer_i32 0 in + insist (i32_type = contained_i32); + + let pointer_to_pointer = pointer_type (pointer_type i8_type) in + let pp = contained_type pointer_to_pointer 0 in + insist ((pointer_type i8_type) = pp ); + insist (i8_type = (contained_type pp 0)) (*===-- Conversion --------------------------------------------------------===*) @@ -1533,6 +1544,7 @@ (*===-- Driver ------------------------------------------------------------===*) let _ = + suite "contained types" test_contained_types; suite "conversion" test_conversion; suite "target" test_target; suite "constants" test_constants;