mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 21:32:10 +00:00
C and Ocaml bindings for address spaces, for that burgeoning market
for Ocaml-based compilers targeting embedded devices. :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45096 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4374f8e208
commit
57cebeec7b
@ -144,11 +144,14 @@ external is_packed : lltype -> bool = "llvm_is_packed"
|
||||
|
||||
(*--... 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 ..........................................--*)
|
||||
|
@ -258,8 +258,15 @@ external is_packed : lltype -> bool = "llvm_is_packed"
|
||||
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 @@ external element_type : lltype -> lltype = "LLVMGetElementType"
|
||||
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"
|
||||
|
@ -163,6 +163,17 @@ CAMLprim LLVMTypeRef llvm_array_type(LLVMTypeRef ElementTy, value Count) {
|
||||
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));
|
||||
@ -173,6 +184,11 @@ CAMLprim value llvm_array_length(LLVMTypeRef ArrayTy) {
|
||||
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));
|
||||
@ -399,7 +415,7 @@ CAMLprim LLVMValueRef llvm_declare_global(LLVMTypeRef Ty, value Name,
|
||||
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 @@ CAMLprim LLVMValueRef llvm_declare_function(value Name, LLVMTypeRef Ty,
|
||||
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);
|
||||
|
@ -194,11 +194,12 @@ int LLVMIsPackedStruct(LLVMTypeRef StructTy);
|
||||
|
||||
/* 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 */
|
||||
|
@ -145,16 +145,15 @@ int LLVMIsPackedStruct(LLVMTypeRef StructTy) {
|
||||
|
||||
/*--.. 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 @@ unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
|
||||
return unwrap<ArrayType>(ArrayTy)->getNumElements();
|
||||
}
|
||||
|
||||
unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
|
||||
return unwrap<PointerType>(PointerTy)->getAddressSpace();
|
||||
}
|
||||
|
||||
unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
|
||||
return unwrap<VectorType>(VectorTy)->getNumElements();
|
||||
}
|
||||
|
@ -103,13 +103,24 @@ let test_types () =
|
||||
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
|
||||
*)
|
||||
|
Loading…
Reference in New Issue
Block a user