(*--... Operations on pointer, vector, and array types .....................--*)
external array_type : lltype -> int -> lltype = "llvm_array_type"
-external pointer_type : lltype -> lltype = "LLVMPointerType"
+external pointer_type : lltype -> lltype = "llvm_pointer_type"
+external qualified_pointer_type : lltype -> int -> lltype
+ = "llvm_qualified_pointer_type"
external vector_type : lltype -> int -> lltype = "llvm_vector_type"
external element_type : lltype -> lltype = "LLVMGetElementType"
external array_length : lltype -> int = "llvm_array_length"
+external address_space : lltype -> int = "llvm_address_space"
external vector_size : lltype -> int = "llvm_vector_size"
(*--... Operations on other types ..........................................--*)
external array_type : lltype -> int -> lltype = "llvm_array_type"
(** [pointer_type ty] returns the pointer type referencing objects of type
- [ty]. See the method [llvm::PointerType::get]. **)
-external pointer_type : lltype -> lltype = "LLVMPointerType"
+ [ty] in the default address space (0).
+ See the method [llvm::PointerType::getUnqual]. **)
+external pointer_type : lltype -> lltype = "llvm_pointer_type"
+
+(** [qualified_pointer_type ty as] returns the pointer type referencing objects
+ of type [ty] in address space [as].
+ See the method [llvm::PointerType::get]. **)
+external qualified_pointer_type : lltype -> int -> lltype
+ = "llvm_qualified_pointer_type"
(** [vector_type ty n] returns the array type containing [n] elements of the
primitive type [ty]. See the method [llvm::ArrayType::get]. **)
See the method [llvm::ArrayType::getNumElements]. **)
external array_length : lltype -> int = "llvm_array_length"
+(** [address_space pty] returns the address space qualifier of the pointer type
+ [pty]. See the method [llvm::PointerType::getAddressSpace]. **)
+external address_space : lltype -> int = "llvm_address_space"
+
(** [element_type ty] returns the element count of the vector type [ty].
See the method [llvm::VectorType::getNumElements]. **)
external vector_size : lltype -> int = "llvm_vector_size"
return LLVMArrayType(ElementTy, Int_val(Count));
}
+/* lltype -> lltype */
+CAMLprim LLVMTypeRef llvm_pointer_type(LLVMTypeRef ElementTy) {
+ return LLVMPointerType(ElementTy, 0);
+}
+
+/* lltype -> int -> lltype */
+CAMLprim LLVMTypeRef llvm_qualified_pointer_type(LLVMTypeRef ElementTy,
+ value AddressSpace) {
+ return LLVMPointerType(ElementTy, Int_val(AddressSpace));
+}
+
/* lltype -> int -> lltype */
CAMLprim LLVMTypeRef llvm_vector_type(LLVMTypeRef ElementTy, value Count) {
return LLVMVectorType(ElementTy, Int_val(Count));
return Val_int(LLVMGetArrayLength(ArrayTy));
}
+/* lltype -> int */
+CAMLprim value llvm_address_space(LLVMTypeRef PtrTy) {
+ return Val_int(LLVMGetPointerAddressSpace(PtrTy));
+}
+
/* lltype -> int */
CAMLprim value llvm_vector_size(LLVMTypeRef VectorTy) {
return Val_int(LLVMGetVectorSize(VectorTy));
LLVMValueRef GlobalVar;
if ((GlobalVar = LLVMGetNamedGlobal(M, String_val(Name)))) {
if (LLVMGetElementType(LLVMTypeOf(GlobalVar)) != Ty)
- return LLVMConstBitCast(GlobalVar, LLVMPointerType(Ty));
+ return LLVMConstBitCast(GlobalVar, LLVMPointerType(Ty, 0));
return GlobalVar;
}
return LLVMAddGlobal(M, Ty, String_val(Name));
LLVMValueRef Fn;
if ((Fn = LLVMGetNamedFunction(M, String_val(Name)))) {
if (LLVMGetElementType(LLVMTypeOf(Fn)) != Ty)
- return LLVMConstBitCast(Fn, LLVMPointerType(Ty));
+ return LLVMConstBitCast(Fn, LLVMPointerType(Ty, 0));
return Fn;
}
return LLVMAddFunction(M, String_val(Name), Ty);
/* Operations on array, pointer, and vector types (sequence types) */
LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount);
-LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType);
+LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace);
LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount);
LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy);
+unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy);
/* Operations on other types */
/*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
-LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount){
+LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
}
-LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType) {
- // FIXME: Needst to handle address spaces
- return wrap(PointerType::getUnqual(unwrap(ElementType)));
+LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
+ return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
}
-LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType,unsigned ElementCount){
+LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
return wrap(VectorType::get(unwrap(ElementType), ElementCount));
}
return unwrap<ArrayType>(ArrayTy)->getNumElements();
}
+unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
+ return unwrap<PointerType>(PointerTy)->getAddressSpace();
+}
+
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
return unwrap<VectorType>(VectorTy)->getNumElements();
}
insist (i8_type == element_type ty);
insist (Array_type == classify_type ty);
- (* RUN: grep {Ty10.*float\*} < %t.ll
- *)
- group "pointer";
- let ty = pointer_type float_type in
- insist (define_type_name "Ty10" ty m);
- insist (float_type == element_type ty);
- insist (Pointer_type == classify_type ty);
+ begin group "pointer";
+ (* RUN: grep {UnqualPtrTy.*float\*} < %t.ll
+ *)
+ let ty = pointer_type float_type in
+ insist (define_type_name "UnqualPtrTy" ty m);
+ insist (float_type == element_type ty);
+ insist (0 == address_space ty);
+ insist (Pointer_type == classify_type ty)
+ end;
+
+ begin group "qualified_pointer";
+ (* RUN: grep {QualPtrTy.*i8.*3.*\*} < %t.ll
+ *)
+ let ty = qualified_pointer_type i8_type 3 in
+ insist (define_type_name "QualPtrTy" ty m);
+ insist (i8_type == element_type ty);
+ insist (3 == address_space ty)
+ end;
(* RUN: grep {Ty11.*\<4 x i16\>} < %t.ll
*)