[llvm-commits] [llvm] r45096 - in /llvm/trunk: bindings/ocaml/llvm/llvm.ml bindings/ocaml/llvm/llvm.mli bindings/ocaml/llvm/llvm_ocaml.c include/llvm-c/Core.h lib/VMCore/Core.cpp test/Bindings/Ocaml/vmcore.ml
Gordon Henriksen
gordonhenriksen at mac.com
Mon Dec 17 08:08:34 PST 2007
Author: gordon
Date: Mon Dec 17 10:08:32 2007
New Revision: 45096
URL: http://llvm.org/viewvc/llvm-project?rev=45096&view=rev
Log:
C and Ocaml bindings for address spaces, for that burgeoning market
for Ocaml-based compilers targeting embedded devices. :)
Modified:
llvm/trunk/bindings/ocaml/llvm/llvm.ml
llvm/trunk/bindings/ocaml/llvm/llvm.mli
llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
llvm/trunk/include/llvm-c/Core.h
llvm/trunk/lib/VMCore/Core.cpp
llvm/trunk/test/Bindings/Ocaml/vmcore.ml
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.ml?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.ml (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.ml Mon Dec 17 10:08:32 2007
@@ -144,11 +144,14 @@
(*--... 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 ..........................................--*)
Modified: llvm/trunk/bindings/ocaml/llvm/llvm.mli
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm.mli?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm.mli (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm.mli Mon Dec 17 10:08:32 2007
@@ -258,8 +258,15 @@
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]. **)
@@ -273,6 +280,10 @@
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"
Modified: llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c (original)
+++ llvm/trunk/bindings/ocaml/llvm/llvm_ocaml.c Mon Dec 17 10:08:32 2007
@@ -163,6 +163,17 @@
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));
@@ -174,6 +185,11 @@
}
/* 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));
}
@@ -399,7 +415,7 @@
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));
@@ -476,7 +492,7 @@
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);
Modified: llvm/trunk/include/llvm-c/Core.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Core.h?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Core.h (original)
+++ llvm/trunk/include/llvm-c/Core.h Mon Dec 17 10:08:32 2007
@@ -194,11 +194,12 @@
/* 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 */
Modified: llvm/trunk/lib/VMCore/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Core.cpp?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Core.cpp (original)
+++ llvm/trunk/lib/VMCore/Core.cpp Mon Dec 17 10:08:32 2007
@@ -145,16 +145,15 @@
/*--.. 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));
}
@@ -166,6 +165,10 @@
return unwrap<ArrayType>(ArrayTy)->getNumElements();
}
+unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
+ return unwrap<PointerType>(PointerTy)->getAddressSpace();
+}
+
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
return unwrap<VectorType>(VectorTy)->getNumElements();
}
Modified: llvm/trunk/test/Bindings/Ocaml/vmcore.ml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Ocaml/vmcore.ml?rev=45096&r1=45095&r2=45096&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Ocaml/vmcore.ml (original)
+++ llvm/trunk/test/Bindings/Ocaml/vmcore.ml Mon Dec 17 10:08:32 2007
@@ -103,13 +103,24 @@
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
*)
More information about the llvm-commits
mailing list