Index: bindings/ocaml/llvm/llvm.ml =================================================================== --- bindings/ocaml/llvm/llvm.ml +++ bindings/ocaml/llvm/llvm.ml @@ -459,6 +459,9 @@ external is_opaque : lltype -> bool = "llvm_is_opaque" (*--... Operations on pointer, vector, and array types .....................--*) + +external num_contained_types : lltype -> int = "llvm_num_contained_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,12 @@ (** {7 Operations on pointer, vector, and array types} *) +(** [num_contained_types ty] returns the number of types in the derived type *) +val num_contained_types : lltype -> int + +(** [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,15 @@ /*--... 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)); +} + +CAMLprim value llvm_num_contained_types(LLVMTypeRef Ty) { + return Val_int(LLVMGetNumContainedTypes(Ty)); +} + +/* 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,20 @@ LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty); /** + * Return the number of types in the derived type. + * + * @see llvm::Type::getNumContainedTypes() + */ +unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp); + +/** + * 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)); } @@ -587,6 +591,10 @@ return wrap(cast(Ty)->getElementType()); } +unsigned LLVMGetNumContainedTypes(LLVMTypeRef Tp) { + return unwrap(Tp)->getNumContainedTypes(); +} + unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) { return unwrap(ArrayTy)->getNumElements(); } Index: test/Bindings/OCaml/core.ml =================================================================== --- test/Bindings/OCaml/core.ml +++ test/Bindings/OCaml/core.ml @@ -66,6 +66,19 @@ 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 (1 = num_contained_types pointer_i32); + 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 ( 1 = num_contained_types pp ); + insist ((pointer_type i8_type) = pp ); + insist (i8_type = (contained_type pp 0)) (*===-- Conversion --------------------------------------------------------===*) @@ -1533,6 +1546,7 @@ (*===-- Driver ------------------------------------------------------------===*) let _ = + suite "contained types" test_contained_types; suite "conversion" test_conversion; suite "target" test_target; suite "constants" test_constants;