Mercurial > projects > ldc
comparison gen/todebug.cpp @ 139:0ab29b838084 trunk
[svn r143] Fixed: a few bugs in debug information, still only line info, but should be correct files now :)
Fixed: tango.io.Console seems to be working now.
author | lindquist |
---|---|
date | Tue, 22 Jan 2008 00:01:16 +0100 |
parents | 0e28624814e8 |
children | ffcc9a2f3d9d |
comparison
equal
deleted
inserted
replaced
138:aeddd4d533b3 | 139:0ab29b838084 |
---|---|
8 | 8 |
9 #include "gen/todebug.h" | 9 #include "gen/todebug.h" |
10 #include "gen/irstate.h" | 10 #include "gen/irstate.h" |
11 #include "gen/tollvm.h" | 11 #include "gen/tollvm.h" |
12 #include "gen/logger.h" | 12 #include "gen/logger.h" |
13 | |
14 #include "ir/irmodule.h" | |
13 | 15 |
14 using namespace llvm::dwarf; | 16 using namespace llvm::dwarf; |
15 | 17 |
16 static const llvm::PointerType* ptrTy(const llvm::Type* t) | 18 static const llvm::PointerType* ptrTy(const llvm::Type* t) |
17 { | 19 { |
108 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); | 110 return isaStruct(gIR->module->getTypeByName("llvm.dbg.subprogram.type")); |
109 } | 111 } |
110 | 112 |
111 ////////////////////////////////////////////////////////////////////////////////////////////////// | 113 ////////////////////////////////////////////////////////////////////////////////////////////////// |
112 | 114 |
113 llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m, bool define) | 115 llvm::GlobalVariable* DtoDwarfCompileUnit(Module* m) |
114 { | 116 { |
117 if (!m->irModule) | |
118 m->irModule = new IrModule(m); | |
119 else if (m->irModule->dwarfCompileUnit) | |
120 { | |
121 if (m->irModule->dwarfCompileUnit->getParent() == gIR->module) | |
122 return m->irModule->dwarfCompileUnit; | |
123 } | |
124 | |
125 // create a valid compile unit constant for the current module | |
126 | |
115 llvm::Constant* c = NULL; | 127 llvm::Constant* c = NULL; |
116 if (1 || define) { | 128 |
117 std::vector<llvm::Constant*> vals; | 129 std::vector<llvm::Constant*> vals; |
118 vals.push_back(llvm::ConstantExpr::getAdd( | 130 vals.push_back(llvm::ConstantExpr::getAdd( |
119 DtoConstUint(DW_TAG_compile_unit), | 131 DtoConstUint(DW_TAG_compile_unit), |
120 DtoConstUint(llvm::LLVMDebugVersion))); | 132 DtoConstUint(llvm::LLVMDebugVersion))); |
121 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_compile_unit))); | 133 vals.push_back(dbgToArrTy(GetDwarfAnchor(DW_TAG_compile_unit))); |
122 | 134 |
123 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work | 135 vals.push_back(DtoConstUint(DW_LANG_C));// _D)); // doesn't seem to work |
124 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata")); | 136 vals.push_back(DtoConstStringPtr(m->srcfile->name->toChars(), "llvm.metadata")); |
125 std::string srcpath(FileName::path(m->srcfile->name->toChars())); | 137 std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
126 //srcpath.append("/"); | 138 if (srcpath.empty()) |
127 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata")); | 139 srcpath = "."; |
128 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata")); | 140 vals.push_back(DtoConstStringPtr(srcpath.c_str(), "llvm.metadata")); |
129 | 141 vals.push_back(DtoConstStringPtr("LLVMDC (http://www.dsource.org/projects/llvmdc)", "llvm.metadata")); |
130 c = llvm::ConstantStruct::get(GetDwarfCompileUnitType(), vals); | 142 |
131 } | 143 c = llvm::ConstantStruct::get(GetDwarfCompileUnitType(), vals); |
144 | |
132 llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module); | 145 llvm::GlobalVariable* gv = new llvm::GlobalVariable(GetDwarfCompileUnitType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.compile_unit", gIR->module); |
133 gv->setSection("llvm.metadata"); | 146 gv->setSection("llvm.metadata"); |
147 | |
148 m->irModule->dwarfCompileUnit = gv; | |
134 return gv; | 149 return gv; |
135 } | 150 } |
136 | 151 |
137 ////////////////////////////////////////////////////////////////////////////////////////////////// | 152 ////////////////////////////////////////////////////////////////////////////////////////////////// |
138 | 153 |
179 void DtoDwarfStopPoint(unsigned ln) | 194 void DtoDwarfStopPoint(unsigned ln) |
180 { | 195 { |
181 std::vector<llvm::Value*> args; | 196 std::vector<llvm::Value*> args; |
182 args.push_back(DtoConstUint(ln)); | 197 args.push_back(DtoConstUint(ln)); |
183 args.push_back(DtoConstUint(0)); | 198 args.push_back(DtoConstUint(0)); |
184 assert(gIR->dmodule->llvmCompileUnit); | 199 FuncDeclaration* fd = gIR->func()->decl; |
185 args.push_back(dbgToArrTy(gIR->dmodule->llvmCompileUnit)); | 200 args.push_back(dbgToArrTy(DtoDwarfCompileUnit(fd->getModule()))); |
186 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); | 201 gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.stoppoint"), args.begin(), args.end()); |
187 } | 202 } |