#include "llvm/GlobalVariable.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Support/DebugLoc.h"
-#include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/FormattedStream.h"
using namespace llvm;
CTy.getName(TagName);
// UniqueSuffix is .number where number is obtained from
// llvm.dbg.composite<number>.
- std::string UniqueSuffix = "." + Ty.getGV()->getName().substr(18);
+ std::string UniqueSuffix = "." + Ty.getGV()->getNameStr().substr(18);
TagName += UniqueSuffix;
unsigned short size = CTy.getSizeInBits()/8;
// 7th and 8th byte represent size.
/// required initializations.
void PIC16DbgInfo::BeginModule(Module &M) {
// Emit file directive for module.
- GlobalVariable *CU = M.getNamedGlobal("llvm.dbg.compile_unit");
- if (CU) {
+ DebugInfoFinder DbgFinder;
+ DbgFinder.processModule(M);
+ if (DbgFinder.compile_unit_count() != 0) {
+ // FIXME : What if more then one CUs are present in a module ?
+ GlobalVariable *CU = *DbgFinder.compile_unit_begin();
EmitDebugDirectives = true;
SwitchToCU(CU);
}
// Retreive the first valid debug Loc and process it.
const DebugLoc &DL = GetDebugLocForFunction(MF);
- ChangeDebugLoc(MF, DL, true);
-
- EmitFunctBeginDI(MF.getFunction());
-
+ // Emit debug info only if valid debug info is available.
+ if (!DL.isUnknown()) {
+ ChangeDebugLoc(MF, DL, true);
+ EmitFunctBeginDI(MF.getFunction());
+ }
// Set current line to 0 so that.line directive is genearted after .bf.
CurLine = 0;
}
///
void PIC16DbgInfo::EndFunction(const MachineFunction &MF) {
if (! EmitDebugDirectives) return;
- EmitFunctEndDI(MF.getFunction(), CurLine);
+ const DebugLoc &DL = GetDebugLocForFunction(MF);
+ // Emit debug info only if valid debug info is available.
+ if (!DL.isUnknown())
+ EmitFunctEndDI(MF.getFunction(), CurLine);
}
/// EndModule - Emit .eof for end of module.
// Get mangleddd name for this structure/union element.
std::string MangMemName = ElementName + UniqueSuffix;
PopulateDebugInfo(DITy, TypeNo, HasAux, ElementAux, TagName);
- short Class;
+ short Class = 0;
if( CTy.getTag() == dwarf::DW_TAG_union_type)
Class = PIC16Dbg::C_MOU;
else if (CTy.getTag() == dwarf::DW_TAG_structure_type)
E = M.getGlobalList().end(); I != E; I++) {
// Structures and union declaration's debug info has llvm.dbg.composite
// in its name.
- if(I->getName().find("llvm.dbg.composite") != std::string::npos) {
+ // FIXME: Checking and relying on llvm.dbg.composite name is not a good idea.
+ if(I->getNameStr().find("llvm.dbg.composite") != std::string::npos) {
GlobalVariable *GV = cast<GlobalVariable >(I);
DICompositeType CTy(GV);
if (CTy.getTag() == dwarf::DW_TAG_union_type ||
/// EmitVarDebugInfo - Emit debug information for all variables.
///
void PIC16DbgInfo::EmitVarDebugInfo(Module &M) {
- GlobalVariable *Root = M.getGlobalVariable("llvm.dbg.global_variables");
- if (!Root)
- return;
-
- Constant *RootC = cast<Constant>(*Root->use_begin());
- for (Value::use_iterator UI = RootC->use_begin(), UE = Root->use_end();
- UI != UE; ++UI) {
- for (Value::use_iterator UUI = UI->use_begin(), UUE = UI->use_end();
- UUI != UUE; ++UUI) {
- DIGlobalVariable DIGV(cast<GlobalVariable>(*UUI));
- DIType Ty = DIGV.getType();
- unsigned short TypeNo = 0;
- bool HasAux = false;
- int Aux[PIC16Dbg::AuxSize] = { 0 };
- std::string TagName = "";
- std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getName();
- PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
- // Emit debug info only if type information is availaible.
- if (TypeNo != PIC16Dbg::T_NULL) {
- O << "\n\t.type " << VarName << ", " << TypeNo;
- short ClassNo = getStorageClass(DIGV);
- O << "\n\t.class " << VarName << ", " << ClassNo;
- if (HasAux)
- EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
- }
+ DebugInfoFinder DbgFinder;
+ DbgFinder.processModule(M);
+
+ for (DebugInfoFinder::iterator I = DbgFinder.global_variable_begin(),
+ E = DbgFinder.global_variable_end(); I != E; ++I) {
+ DIGlobalVariable DIGV(*I);
+ DIType Ty = DIGV.getType();
+ unsigned short TypeNo = 0;
+ bool HasAux = false;
+ int Aux[PIC16Dbg::AuxSize] = { 0 };
+ std::string TagName = "";
+ std::string VarName = TAI->getGlobalPrefix()+DIGV.getGlobal()->getNameStr();
+ PopulateDebugInfo(Ty, TypeNo, HasAux, Aux, TagName);
+ // Emit debug info only if type information is availaible.
+ if (TypeNo != PIC16Dbg::T_NULL) {
+ O << "\n\t.type " << VarName << ", " << TypeNo;
+ short ClassNo = getStorageClass(DIGV);
+ O << "\n\t.class " << VarName << ", " << ClassNo;
+ if (HasAux)
+ EmitAuxEntry(VarName, Aux, PIC16Dbg::AuxSize, TagName);
}
}
O << "\n";