Mercurial > projects > ldc
diff gen/toobj.c @ 82:d8dd47ef3973 trunk
[svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
Initial support for debug information. Very limited, but MUCH better than nothing :)
author | lindquist |
---|---|
date | Fri, 02 Nov 2007 01:17:26 +0100 |
parents | 3587401b6eeb |
children | 169711a7126e |
line wrap: on
line diff
--- a/gen/toobj.c Thu Nov 01 17:27:18 2007 +0100 +++ b/gen/toobj.c Fri Nov 02 01:17:26 2007 +0100 @@ -36,6 +36,7 @@ #include "gen/logger.h" #include "gen/tollvm.h" #include "gen/arrays.h" +#include "gen/todebug.h" ////////////////////////////////////////////////////////////////////////////////////////// @@ -75,6 +76,12 @@ llvm::TargetMachine &targetMachine = *targetPtr.get(); gTargetData = targetMachine.getTargetData(); + // debug info + if (global.params.symdebug) { + RegisterDwarfSymbols(ir.module); + ir.dwarfCompileUnit = DtoDwarfCompileUnit(this); + } + // process module members for (int k=0; k < members->dim; k++) { Dsymbol* dsym = (Dsymbol*)(members->data[k]); @@ -750,6 +757,11 @@ return; // we wait with the definition as they might invoke a virtual method and the vtable is not yet complete } + // debug info + if (global.params.symdebug) { + llvmDwarfSubProgram = DtoDwarfSubProgram(this); + } + assert(f->llvmType); const llvm::FunctionType* functype = llvm::cast<llvm::FunctionType>(llvmValue->getType()->getContainedType(0)); @@ -809,6 +821,29 @@ f->llvmAllocaPoint = new llvm::BitCastInst(llvm::ConstantInt::get(llvm::Type::Int32Ty,0,false),llvm::Type::Int32Ty,"alloca point",gIR->scopebb()); gIR->func().allocapoint = f->llvmAllocaPoint; + // give arguments storage + size_t n = Argument::dim(f->parameters); + for (int i=0; i < n; ++i) { + Argument* arg = Argument::getNth(f->parameters, i); + if (arg && arg->vardecl) { + VarDeclaration* vd = arg->vardecl; + if (!vd->llvmNeedsStorage || vd->nestedref || vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)) + continue; + llvm::Value* a = vd->llvmValue; + assert(a); + std::string s(a->getName()); + Logger::println("giving argument '%s' storage", s.c_str()); + s.append("_storage"); + llvm::Value* v = new llvm::AllocaInst(a->getType(),s,f->llvmAllocaPoint); + gIR->ir->CreateStore(a,v); + vd->llvmValue = v; + } + else assert(0); + } + + // debug info + if (global.params.symdebug) DtoDwarfFuncStart(this); + llvm::Value* parentNested = NULL; if (FuncDeclaration* fd = toParent()->isFuncDeclaration()) { parentNested = fd->llvmNested; @@ -866,7 +901,7 @@ if (!isMain()) { if (!gIR->scopereturned()) { // pass the previous block into this block - //new llvm::BranchInst(irs.end, irs.begin); + if (global.params.symdebug) DtoDwarfFuncEnd(this); if (func->getReturnType() == llvm::Type::VoidTy) { new llvm::ReturnInst(gIR->scopebb()); }