void* mono_llvm_di_create_file (void *di_builder, const char *dir, const char *file) { DIBuilder *builder = (DIBuilder*)di_builder; return builder->createFile (file, dir); }
int DefineNamespace( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc != 6) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder scope name file line"); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; DIScope *scope; if (GetMetadataFromObj(interp, objv[2], "scope", scope) != TCL_OK) return TCL_ERROR; std::string name = Tcl_GetString(objv[3]); DIFile *file; if (GetMetadataFromObj(interp, objv[4], "file", file) != TCL_OK) return TCL_ERROR; int line; if (Tcl_GetIntFromObj(interp, objv[5], &line) != TCL_OK) return TCL_ERROR; auto val = builder->createNameSpace(scope, name, file, line); Tcl_SetObjResult(interp, NewMetadataObj(val, "Namespace")); return TCL_OK; }
void* mono_llvm_di_create_compile_unit (void *di_builder, const char *cu_name, const char *dir, const char *producer) { DIBuilder *builder = (DIBuilder*)di_builder; return builder->createCompileUnit (dwarf::DW_LANG_C99, cu_name, dir, producer, true, "", 0); }
int DefineCompileUnit( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc != 5) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder file directory producer"); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; unsigned lang = dwarf::DW_LANG_lo_user;//No standard value for Tcl! std::string file = Tcl_GetString(objv[2]); std::string dir = Tcl_GetString(objv[3]); std::string producer = Tcl_GetString(objv[4]); std::string flags = ""; unsigned runtimeVersion = 0; auto val = builder->createCompileUnit(lang, file, dir, producer, true, flags, runtimeVersion); Tcl_SetObjResult(interp, NewMetadataObj(val, "CompileUnit")); return TCL_OK; }
LLVMValueRef LLVMDIBuilderCreateEnumerationType( LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, LLVMValueRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, LLVMValueRef Elements, LLVMValueRef UnderlyingType, const char *UniqueIdentifier) { DIBuilder *db = unwrap(D); DICompositeType CT = db->createEnumerationType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, unwrapDI<DIArray>(Elements), unwrapDI<DIType>(UnderlyingType), UniqueIdentifier); return wrap(CT); }
LLVMValueRef LLVMDIBuilderCreateCompileUnit( LLVMDIBuilderRef D, unsigned Lang, const char *File, const char *Dir, const char *Producer, bool Optimized, const char *Flags, unsigned RuntimeVersion) { DIBuilder *db = unwrap(D); DICompileUnit CU = db->createCompileUnit( Lang, File, Dir, Producer, Optimized, Flags, RuntimeVersion); return wrap(CU); //LLVMValueRef val; // return reinterpret_cast<LLVMValueRef>(&CU); // return reinterpret_cast<LLVMValueRef>(const_cast<DICompileUnit*>(CU)); }
LLVMValueRef LLVMDIBuilderCreateClassType( LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, LLVMValueRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, LLVMValueRef DerivedFrom, LLVMValueRef Elements) { DIBuilder *db = unwrap(D); DICompositeType CT = db->createClassType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(DerivedFrom), unwrapDI<DIArray>(Elements)); return wrap(CT); }
LLVMValueRef LLVMDIBuilderCreateMemberType( LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, LLVMValueRef File, unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, LLVMValueRef Ty) { DIBuilder *db = unwrap(D); DIDerivedType DT = db->createMemberType( unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line, SizeInBits, AlignInBits, OffsetInBits, Flags, unwrapDI<DIType>(Ty)); return wrap(DT); }
LLVMValueRef LLVMDIBuilderCreateReplaceableForwardDecl( LLVMDIBuilderRef D, unsigned Tag, const char *Name, LLVMValueRef Scope, LLVMValueRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, const char *UniqueIdentifier) { DIBuilder *db = unwrap(D); DICompositeType CT = db->createReplaceableForwardDecl( Tag, Name, unwrapDI<DIScope>(Scope), unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits, AlignInBits, UniqueIdentifier); return wrap(CT); }
LLVMValueRef LLVMDIBuilderCreateLocalVariable( LLVMDIBuilderRef D, unsigned Tag, LLVMValueRef Scope, const char *Name, LLVMValueRef File, unsigned Line, LLVMValueRef Ty, bool AlwaysPreserve, unsigned Flags, unsigned ArgNo) { DIBuilder *db = unwrap(D); DIVariable V = db->createLocalVariable( Tag, unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIFile>(File), Line, unwrapDI<DIType>(Ty), AlwaysPreserve, Flags, ArgNo); return wrap(V); }
LLVMValueRef LLVMDIBuilderCreateFunction( LLVMDIBuilderRef D, LLVMValueRef Scope, const char *Name, const char *LinkageName, LLVMValueRef File, unsigned Line, LLVMValueRef CompositeType, bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, unsigned Flags, bool IsOptimized, LLVMValueRef Func) { DIBuilder *db = unwrap(D); DISubprogram SP = db->createFunction( unwrapDI<DIDescriptor>(Scope), Name, LinkageName, unwrapDI<DIFile>(File), Line, unwrapDI<DICompositeType>(CompositeType), IsLocalToUnit, IsDefinition, ScopeLine, Flags, IsOptimized, unwrap<Function>(Func)); return wrap(SP); }
void Variables::updateMetadata(Module& module, Value* oldTarget, Value* newTarget, Type* newType) { vector<Instruction*> to_remove; if (newTarget) { errs() << "\tChanging metadata for: " << newTarget->getName() << "\n"; bool changed = false; for(Module::iterator f = module.begin(), fe = module.end(); f != fe; f++) { for(Function::iterator b = f->begin(), be = f->end(); b != be; b++) { for(BasicBlock::iterator i = b->begin(), ie = b->end(); i != ie; i++) { if (DbgDeclareInst *oldDeclare = dyn_cast<DbgDeclareInst>(i)) { if (Value *address = oldDeclare->getAddress()) { if (AllocaInst *allocaInst = dyn_cast<AllocaInst>(address)) { if (allocaInst == oldTarget) { // the alloca we are looking for DIVariable oldDIVar(oldDeclare->getVariable()); MDNode* newDIType = getTypeMetadata(module, oldDIVar, newType); // construct new DIVariable with new type descriptor vector<Value*> doperands; for(unsigned i = 0; i < oldDIVar->getNumOperands(); i++) { if (i == 5) { // the argument that corresponds to the type descriptor doperands.push_back(newDIType); } else { doperands.push_back(oldDIVar->getOperand(i)); // preserve other descriptors } } ArrayRef<Value*> *arrayRefDOperands = new ArrayRef<Value*>(doperands); MDNode* newMDNode = MDNode::get(module.getContext(), *arrayRefDOperands); DIVariable newDIVar(newMDNode); // insert new declare instruction DIBuilder* builder = new DIBuilder(module); Instruction *newDeclare = builder->insertDeclare(newTarget, newDIVar, oldDeclare); // make sure the declare instruction preserves its own metadata unsigned id = 0; if (oldDeclare->getMetadata(id)) { newDeclare->setMetadata(id, oldDeclare->getMetadata(id)); } to_remove.push_back(oldDeclare); // can't erase while iterating through instructions changed = true; } } } } } } } for(unsigned i = 0; i < to_remove.size(); i++) { to_remove[i]->eraseFromParent(); } if (!changed) { errs() << "\tNo metadata to change\n"; } } return; }
void mono_llvm_di_builder_finalize (void *di_builder) { DIBuilder *builder = (DIBuilder*)di_builder; builder->finalize (); }
int DefineAliasType( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc != 7) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder type name file line contextScope"); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; DIType *type; if (GetMetadataFromObj(interp, objv[2], "type", type) != TCL_OK) return TCL_ERROR; std::string name = Tcl_GetString(objv[3]); DIFile *file; if (GetMetadataFromObj(interp, objv[4], "file", file) != TCL_OK) return TCL_ERROR; int line; if (Tcl_GetIntFromObj(interp, objv[5], &line) != TCL_OK) return TCL_ERROR; DIScope *context; if (GetMetadataFromObj(interp, objv[6], "context", context) != TCL_OK) return TCL_ERROR; auto val = builder->createTypedef(type, name, file, line, context); Tcl_SetObjResult(interp, NewMetadataObj(val, "AliasType")); return TCL_OK; }
int DefineBasicType( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc != 5) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder name sizeInBits dwarfTypeCode"); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; std::string name = Tcl_GetString(objv[2]); int size, align = 0, dwarfTypeCode; if (Tcl_GetIntFromObj(interp, objv[3], &size) != TCL_OK) return TCL_ERROR; if (Tcl_GetIntFromObj(interp, objv[4], &dwarfTypeCode) != TCL_OK) return TCL_ERROR; auto val = builder->createBasicType(name, (uint64_t) size, (uint64_t) align, (unsigned) dwarfTypeCode); Tcl_SetObjResult(interp, NewMetadataObj(val, "BasicType")); return TCL_OK; }
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMMetadataRef File, LLVMMetadataRef ParameterTypes) { DIBuilder *D = unwrap(Dref); return wrap( D->createSubroutineType(DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); }
int DefinePointerType( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc != 3) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder pointee"); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; DIType *pointee; if (GetMetadataFromObj(interp, objv[2], "type", pointee) != TCL_OK) return TCL_ERROR; size_t size = sizeof(pointee) * 8; auto val = builder->createPointerType(pointee, size); Tcl_SetObjResult(interp, NewMetadataObj(val, "PointerType")); return TCL_OK; }
int DefineFunctionType( ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, "DIBuilder file returnType argumentType..."); return TCL_ERROR; } DIBuilder *builder; if (GetDIBuilderFromObj(interp, objv[1], builder) != TCL_OK) return TCL_ERROR; DIFile *file; if (GetMetadataFromObj(interp, objv[2], "file", file) != TCL_OK) return TCL_ERROR; std::vector<Metadata *> elements; for (int i=3 ; i<objc ; i++) { DIType *type; if (GetMetadataFromObj(interp, objv[i], "type", type) != TCL_OK) return TCL_ERROR; elements.push_back(type); } auto val = builder->createSubroutineType(file, builder->getOrCreateTypeArray(elements)); Tcl_SetObjResult(interp, NewMetadataObj(val, "FunctionType")); return TCL_OK; }
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, const char *Name, uint64_t SizeInBits, unsigned Encoding) { DIBuilder *D = unwrap(Dref); return wrap(D->createBasicType(Name, SizeInBits, Encoding)); }
LLVMValueRef DIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef dref, LLVMValueRef *data, size_t length) { DIBuilder *d = unwrap(dref); Value **dataValue = unwrap(data); ArrayRef<Value *> elements(dataValue, length); DITypeArray a = d->getOrCreateTypeArray(elements); return wrap(a); }
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator) { DIBuilder *D = unwrap(Dref); return wrap(D->createLexicalBlockFile(unwrap<DILocalScope>(Scope), unwrap<DIFile>(File), Discriminator)); }
LLVMValueRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Dref, LLVMValueRef *Data, size_t Length) { DIBuilder *D = unwrap(Dref); Value **DataValue = unwrap(Data); ArrayRef<Value *> Elements(DataValue, Length); DIArray A = D->getOrCreateArray(Elements); return wrap(A); }
LLVMValueRef DIBuilderCreateSubroutineType(LLVMDIBuilderRef dref, LLVMValueRef diFile, LLVMValueRef diParameterTypes) { DIBuilder *d = unwrap(dref); DICompositeType ct = d->createSubroutineType( unwrapDI<DIFile>(diFile), unwrapDI<DITypeArray>(diParameterTypes)); return wrap(ct); }
LLVMValueRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref, const char *Name, uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding) { DIBuilder *D = unwrap(Dref); DIBasicType T = D->createBasicType(Name, SizeInBits, AlignInBits, Encoding); return wrap(T); }
LLVMValueRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Dref, LLVMValueRef File, LLVMValueRef ParameterTypes) { DIBuilder *D = unwrap(Dref); DICompositeType CT = D->createSubroutineType( unwrapDI<DIFile>(File), unwrapDI<DITypeArray>(ParameterTypes)); return wrap(CT); }
LLVMValueRef DIBuilderCreateBasicType(LLVMDIBuilderRef dref, const char *name, uint64_t sizeInBits, uint64_t alignInBits, unsigned encoding) { DIBuilder *d = unwrap(dref); DIBasicType t = d->createBasicType(StringRef(name), sizeInBits, alignInBits, encoding); return wrap(t); }
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, LLVMMetadataRef PointeeType, uint64_t SizeInBits, uint32_t AlignInBits, const char *Name) { DIBuilder *D = unwrap(Dref); return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits, AlignInBits, Name)); }
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Dref, LLVMMetadataRef *Data, size_t Length) { DIBuilder *D = unwrap(Dref); Metadata **DataValue = unwrap(Data); ArrayRef<Metadata *> Elements(DataValue, Length); DITypeRefArray A = D->getOrCreateTypeArray(Elements); return wrap(A.get()); }
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref, LLVMMetadataRef Ty, const char *Name, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Context) { DIBuilder *D = unwrap(Dref); return wrap(D->createTypedef(unwrap<DIType>(Ty), Name, File ? unwrap<DIFile>(File) : nullptr, Line, Context ? unwrap<DIScope>(Context) : nullptr)); }
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable( LLVMDIBuilderRef Dref, LLVMMetadataRef Scope, const char *Name, unsigned ArgNo, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef Ty, int AlwaysPreserve, unsigned Flags) { DIBuilder *D = unwrap(Dref); return wrap(D->createParameterVariable( unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File), Line, unwrap<DIType>(Ty), AlwaysPreserve, static_cast<DINode::DIFlags>(Flags))); }