llvm.org GIT mirror llvm / c44943e
C/OCaml API to retrieve struct name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141285 91177308-0d34-0410-b5e6-96231b3b80d8 Torok Edwin 8 years ago
5 changed file(s) with 28 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
196196 external struct_type : llcontext -> lltype array -> lltype = "llvm_struct_type"
197197 external packed_struct_type : llcontext -> lltype array -> lltype
198198 = "llvm_packed_struct_type"
199 external struct_name : lltype -> string option = "llvm_struct_name"
199200 external struct_element_types : lltype -> lltype array
200201 = "llvm_struct_element_types"
201202 external is_packed : lltype -> bool = "llvm_is_packed"
371371 [llvm::StructType::get]. *)
372372 val packed_struct_type : llcontext -> lltype array -> lltype
373373
374 (** [struct_name ty] returns the name of the named structure type [ty],
375 * or None if the structure type is not named *)
376 val struct_name : lltype -> string option
377
374378
375379 (** [struct_element_types sty] returns the constituent types of the struct type
376380 [sty]. See the method [llvm::StructType::getElementType]. *)
286286 Wosize_val(ElementTypes), 1);
287287 }
288288
289 /* lltype -> string option */
290 CAMLprim value llvm_struct_name(LLVMTypeRef Ty)
291 {
292 CAMLparam0();
293 const char *C = LLVMGetStructName(Ty);
294 if (C) {
295 CAMLlocal1(result);
296 result = caml_alloc_small(1, 0);
297 Store_field(result, 0, caml_copy_string(C));
298 CAMLreturn(result);
299 }
300 CAMLreturn(Val_int(0));
301 }
302
289303 /* lltype -> lltype array */
290304 CAMLprim value llvm_struct_element_types(LLVMTypeRef StructTy) {
291305 value Tys = alloc(LLVMCountStructElementTypes(StructTy), 0);
402402 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, unsigned ElementCount,
403403 LLVMBool Packed);
404404 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name);
405 const char *LLVMGetStructName(LLVMTypeRef Ty);
405406 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
406407 unsigned ElementCount, LLVMBool Packed);
407408
299299 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
300300 {
301301 return wrap(StructType::create(*unwrap(C), Name));
302 }
303
304 const char *LLVMGetStructName(LLVMTypeRef Ty)
305 {
306 StructType *Type = unwrap(Ty);
307 if (!Type->hasName())
308 return 0;
309 return Type->getName().data();
302310 }
303311
304312 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,