1
0
mirror of https://github.com/RPCSX/llvm.git synced 2025-04-08 19:22:03 +00:00

C/OCaml API to retrieve struct name.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141285 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Torok Edwin 2011-10-06 12:12:50 +00:00
parent 624c5edcd4
commit c44943ed4f
5 changed files with 28 additions and 0 deletions
bindings/ocaml/llvm
include/llvm-c
lib/VMCore

@ -197,6 +197,7 @@ external param_types : lltype -> lltype array = "llvm_param_types"
external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type" external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type"
external packed_struct_type : llcontext -> lltype array -> lltype external packed_struct_type : llcontext -> lltype array -> lltype
= "llvm_packed_struct_type" = "llvm_packed_struct_type"
external struct_name : lltype -> string option = "llvm_struct_name"
external struct_element_types : lltype -> lltype array external struct_element_types : lltype -> lltype array
= "llvm_struct_element_types" = "llvm_struct_element_types"
external is_packed : lltype -> bool = "llvm_is_packed" external is_packed : lltype -> bool = "llvm_is_packed"

@ -372,6 +372,10 @@ val struct_type : llcontext -> lltype array -> lltype
[llvm::StructType::get]. *) [llvm::StructType::get]. *)
val packed_struct_type : llcontext -> lltype array -> lltype val packed_struct_type : llcontext -> lltype array -> lltype
(** [struct_name ty] returns the name of the named structure type [ty],
* or None if the structure type is not named *)
val struct_name : lltype -> string option
(** [struct_element_types sty] returns the constituent types of the struct type (** [struct_element_types sty] returns the constituent types of the struct type
[sty]. See the method [llvm::StructType::getElementType]. *) [sty]. See the method [llvm::StructType::getElementType]. *)

@ -287,6 +287,20 @@ CAMLprim LLVMTypeRef llvm_packed_struct_type(LLVMContextRef C,
Wosize_val(ElementTypes), 1); Wosize_val(ElementTypes), 1);
} }
/* lltype -> string option */
CAMLprim value llvm_struct_name(LLVMTypeRef Ty)
{
CAMLparam0();
const char *C = LLVMGetStructName(Ty);
if (C) {
CAMLlocal1(result);
result = caml_alloc_small(1, 0);
Store_field(result, 0, caml_copy_string(C));
CAMLreturn(result);
}
CAMLreturn(Val_int(0));
}
/* lltype -> lltype array */ /* lltype -> lltype array */
CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) { CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) {
value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0); value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0);

@ -403,6 +403,7 @@ LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount, LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
LLVMBool Packed); LLVMBool Packed);
LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name); LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
const char *LLVMGetStructName(LLVMTypeRef Ty);
void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
unsigned ElementCount, LLVMBool Packed); unsigned ElementCount, LLVMBool Packed);

@ -302,6 +302,14 @@ LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
return wrap(StructType::create(*unwrap(C), Name)); return wrap(StructType::create(*unwrap(C), Name));
} }
const char *LLVMGetStructName(LLVMTypeRef Ty)
{
StructType *Type = unwrap<StructType>(Ty);
if (!Type->hasName())
return 0;
return Type->getName().data();
}
void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes, void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
unsigned ElementCount, LLVMBool Packed) { unsigned ElementCount, LLVMBool Packed) {
ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount); ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);