Emit file directives correctly in case of a .bc is generated by llvm-ld after linking in several .bc files.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72781 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjiv Gupta 2009-06-03 16:27:49 +00:00
parent 4734ed8b87
commit 3fc7e532aa
3 changed files with 34 additions and 11 deletions

View File

@ -47,6 +47,7 @@ bool PIC16AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
const Function *F = MF.getFunction(); const Function *F = MF.getFunction();
CurrentFnName = Mang->getValueName(F); CurrentFnName = Mang->getValueName(F);
DbgInfo.EmitFileDirective(F);
// Emit the function variables. // Emit the function variables.
EmitFunctionFrame(MF); EmitFunctionFrame(MF);
@ -181,17 +182,11 @@ void PIC16AsmPrinter::printLibcallDecls(void) {
bool PIC16AsmPrinter::doInitialization (Module &M) { bool PIC16AsmPrinter::doInitialization (Module &M) {
bool Result = AsmPrinter::doInitialization(M); bool Result = AsmPrinter::doInitialization(M);
DbgInfo.EmitFileDirective(M);
// FIXME:: This is temporary solution to generate the include file. // FIXME:: This is temporary solution to generate the include file.
// The processor should be passed to llc as in input and the header file // The processor should be passed to llc as in input and the header file
// should be generated accordingly. // should be generated accordingly.
O << "\n\t#include P16F1937.INC\n"; O << "\n\t#include P16F1937.INC\n";
MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
assert(MMI);
DwarfWriter *DW = getAnalysisIfAvailable<DwarfWriter>();
assert(DW && "Dwarf Writer is not available");
DW->BeginModule(&M, MMI, O, this, TAI);
// Set the section names for all globals. // Set the section names for all globals.
for (Module::global_iterator I = M.global_begin(), E = M.global_end(); for (Module::global_iterator I = M.global_begin(), E = M.global_end();
@ -199,13 +194,14 @@ bool PIC16AsmPrinter::doInitialization (Module &M) {
I->setSection(TAI->SectionForGlobal(I)->getName()); I->setSection(TAI->SectionForGlobal(I)->getName());
} }
DbgInfo.EmitFileDirective(M);
EmitFunctionDecls(M); EmitFunctionDecls(M);
EmitUndefinedVars(M); EmitUndefinedVars(M);
EmitDefinedVars(M); EmitDefinedVars(M);
EmitIData(M); EmitIData(M);
EmitUData(M); EmitUData(M);
EmitRomData(M); EmitRomData(M);
DbgInfo.PopulateFunctsDI(M); DbgInfo.PopulateFunctsDI(M);
return Result; return Result;
} }
@ -285,7 +281,7 @@ void PIC16AsmPrinter::EmitRomData (Module &M)
bool PIC16AsmPrinter::doFinalization(Module &M) { bool PIC16AsmPrinter::doFinalization(Module &M) {
printLibcallDecls(); printLibcallDecls();
DbgInfo.EmitVarDebugInfo(M); DbgInfo.EmitVarDebugInfo(M);
O << "\n\t" << ".EOF"; DbgInfo.EmitEOF();
O << "\n\t" << "END\n"; O << "\n\t" << "END\n";
bool Result = AsmPrinter::doFinalization(M); bool Result = AsmPrinter::doFinalization(M);
return Result; return Result;

View File

@ -264,7 +264,29 @@ void PIC16DbgInfo::EmitFileDirective(Module &M) {
if (CU) { if (CU) {
DICompileUnit DIUnit(CU); DICompileUnit DIUnit(CU);
std::string Dir, FN; std::string Dir, FN;
O << "\n\t.file\t\"" << DIUnit.getDirectory(Dir) <<"/" std::string File = DIUnit.getDirectory(Dir) + "/" + DIUnit.getFilename(FN);
<< DIUnit.getFilename(FN) << "\"" ; O << "\n\t.file\t\"" << File << "\"\n" ;
CurFile = File;
} }
} }
void PIC16DbgInfo::EmitFileDirective(const Function *F) {
std::string FunctName = F->getName();
DISubprogram *SP = getFunctDI(FunctName);
if (SP) {
std::string Dir, FN;
DICompileUnit CU = SP->getCompileUnit();
std::string File = CU.getDirectory(Dir) + "/" + CU.getFilename(FN);
if ( File != CurFile) {
EmitEOF();
O << "\n\t.file\t\"" << File << "\"\n" ;
CurFile = File;
}
}
}
void PIC16DbgInfo::EmitEOF() {
if (CurFile != "")
O << "\n\t.EOF";
}

View File

@ -94,8 +94,11 @@ namespace llvm {
std::map <std::string, DISubprogram *> FunctNameMap; std::map <std::string, DISubprogram *> FunctNameMap;
raw_ostream &O; raw_ostream &O;
const TargetAsmInfo *TAI; const TargetAsmInfo *TAI;
std::string CurFile;
public: public:
PIC16DbgInfo(raw_ostream &o, const TargetAsmInfo *T) : O(o), TAI(T) {} PIC16DbgInfo(raw_ostream &o, const TargetAsmInfo *T) : O(o), TAI(T) {
CurFile = "";
}
~PIC16DbgInfo(); ~PIC16DbgInfo();
void PopulateDebugInfo(DIType Ty, unsigned short &TypeNo, bool &HasAux, void PopulateDebugInfo(DIType Ty, unsigned short &TypeNo, bool &HasAux,
int Aux[], std::string &TypeName); int Aux[], std::string &TypeName);
@ -109,6 +112,8 @@ namespace llvm {
inline void EmitSymbol(std::string Name, int Class); inline void EmitSymbol(std::string Name, int Class);
void EmitVarDebugInfo(Module &M); void EmitVarDebugInfo(Module &M);
void EmitFileDirective(Module &M); void EmitFileDirective(Module &M);
void EmitFileDirective(const Function *F);
void EmitEOF();
}; };
} // end namespace llvm; } // end namespace llvm;
#endif #endif