C/OCaml API to retrieve struct name.
authorTorok Edwin <edwintorok@gmail.com>
Thu, 6 Oct 2011 12:12:50 +0000 (12:12 +0000)
committerTorok Edwin <edwintorok@gmail.com>
Thu, 6 Oct 2011 12:12:50 +0000 (12:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141285 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e335eb8d39dddf92bd52e1e4db60337991d0e79a..e46ea040d923099dc689e1736957c3da858b4ef1 100644 (file)
@@ -197,6 +197,7 @@ external param_types : lltype -> lltype array = "llvm_param_types"
 external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type"
 external packed_struct_type : llcontext -> lltype array -> lltype
                             = "llvm_packed_struct_type"
 external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type"
 external packed_struct_type : llcontext -> lltype array -> lltype
                             = "llvm_packed_struct_type"
+external struct_name : lltype -> string option = "llvm_struct_name"
 external struct_element_types : lltype -> lltype array
                               = "llvm_struct_element_types"
 external is_packed : lltype -> bool = "llvm_is_packed"
 external struct_element_types : lltype -> lltype array
                               = "llvm_struct_element_types"
 external is_packed : lltype -> bool = "llvm_is_packed"
index ef7c986e91ca778a1455312b3e7856e0db1f8699..c0701701344d98027a36d087c436c4ee5c81c984 100644 (file)
@@ -372,6 +372,10 @@ val struct_type : llcontext -> lltype array -> lltype
     [llvm::StructType::get]. *)
 val packed_struct_type : llcontext -> lltype array -> lltype
 
     [llvm::StructType::get]. *)
 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
     [sty]. See the method [llvm::StructType::getElementType]. *)
 
 (** [struct_element_types sty] returns the constituent types of the struct type
     [sty]. See the method [llvm::StructType::getElementType]. *)
index 1c1a526fd71a0522beb38aab10246564151b5ab4..28f0977aba2a2cac61562096a744650a9e44a769 100644 (file)
@@ -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 */
 CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) {
   value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0);
 /* lltype -> lltype array */
 CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) {
   value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0);
index 84ddfbcf89000ca56a4ffbec72b1c4a0ce09a823..4569109b7cb7d682d915562af97580360baf98b0 100644 (file)
@@ -403,6 +403,7 @@ LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
                            LLVMBool Packed);
 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
                            LLVMBool Packed);
 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
+const char *LLVMGetStructName(LLVMTypeRef Ty);
 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
                        unsigned ElementCount, LLVMBool Packed);
 
 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
                        unsigned ElementCount, LLVMBool Packed);
 
index e2b659b6a2b78c802798c4f4258dc377abe354fa..8560de4455c0994eb1b56f1b58c3c25ed5a8f7b7 100644 (file)
@@ -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,
                        unsigned ElementCount, LLVMBool Packed) {
   ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
                        unsigned ElementCount, LLVMBool Packed) {
   ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);