#ifndef LLVM_CODEGEN_DWARFWRITER_H
#define LLVM_CODEGEN_DWARFWRITER_H
+#include "llvm/Pass.h"
+
namespace llvm {
class AsmPrinter;
// DwarfWriter - Emits Dwarf debug and exception handling directives.
//
-class DwarfWriter {
+class DwarfWriter : public ImmutablePass {
private:
/// DD - Provides the DwarfWriter debug implementation.
///
DwarfException *DE;
public:
- DwarfWriter(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T);
+ static char ID; // Pass identification, replacement for typeid
+
+ DwarfWriter();
virtual ~DwarfWriter();
- /// SetModuleInfo - Set machine module info when it's known that pass manager
- /// has created it. Set by the target AsmPrinter.
- void SetModuleInfo(MachineModuleInfo *MMI);
-
//===--------------------------------------------------------------------===//
// Main entry points.
//
/// BeginModule - Emit all Dwarf sections that should come prior to the
/// content.
- void BeginModule(Module *M);
+ void BeginModule(Module *M, MachineModuleInfo *MMI, raw_ostream &OS,
+ AsmPrinter *A, const TargetAsmInfo *T);
/// EndModule - Emit all Dwarf sections that should come after the content.
///
using namespace llvm;
using namespace llvm::dwarf;
+static RegisterPass<DwarfWriter>
+X("dwarfwriter", "DWARF Information Writer");
+char DwarfWriter::ID = 0;
+
namespace llvm {
//===----------------------------------------------------------------------===//
/// DwarfWriter Implementation
///
-DwarfWriter::DwarfWriter(raw_ostream &OS, AsmPrinter *A,
- const TargetAsmInfo *T) {
- DE = new DwarfException(OS, A, T);
- DD = new DwarfDebug(OS, A, T);
+DwarfWriter::DwarfWriter() : ImmutablePass(&ID), DD(NULL), DE(NULL) {
}
DwarfWriter::~DwarfWriter() {
delete DD;
}
-/// SetModuleInfo - Set machine module info when it's known that pass manager
-/// has created it. Set by the target AsmPrinter.
-void DwarfWriter::SetModuleInfo(MachineModuleInfo *MMI) {
- DD->SetModuleInfo(MMI);
- DE->SetModuleInfo(MMI);
-}
-
/// BeginModule - Emit all Dwarf sections that should come prior to the
/// content.
-void DwarfWriter::BeginModule(Module *M) {
+void DwarfWriter::BeginModule(Module *M,
+ MachineModuleInfo *MMI,
+ raw_ostream &OS, AsmPrinter *A,
+ const TargetAsmInfo *T) {
+ DE = new DwarfException(OS, A, T);
+ DD = new DwarfDebug(OS, A, T);
DE->BeginModule(M);
DD->BeginModule(M);
+ DD->SetModuleInfo(MMI);
+ DE->SetModuleInfo(MMI);
}
/// EndModule - Emit all Dwarf sections that should come after the content.
namespace {
struct VISIBILITY_HIDDEN ARMAsmPrinter : public AsmPrinter {
ARMAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
- : AsmPrinter(O, TM, T), DW(O, this, T), MMI(NULL), AFI(NULL), MCP(NULL),
+ : AsmPrinter(O, TM, T), DW(0), MMI(NULL), AFI(NULL), MCP(NULL),
InCPMode(false) {
Subtarget = &TM.getSubtarget<ARMSubtarget>();
}
- DwarfWriter DW;
+ DwarfWriter *DW;
MachineModuleInfo *MMI;
/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can
AsmPrinter::getAnalysisUsage(AU);
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
}
};
} // end of anonymous namespace
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
if (Subtarget->isTargetDarwin()) {
// If the function is empty, then we need to emit *something*. Otherwise,
O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
O.flush();
}
bool ARMAsmPrinter::doInitialization(Module &M) {
- // Emit initial debug information.
- DW.BeginModule(&M);
bool Result = AsmPrinter::doInitialization(M);
- // AsmPrinter::doInitialization should have done this analysis.
+ // Emit initial debug information.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
- DW.SetModuleInfo(MMI);
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ assert(DW && "Dwarf Writer is not available");
+ DW->BeginModule(&M, MMI, O, this, TAI);
// Darwin wants symbols to be quoted if they have complex names.
if (Subtarget->isTargetDarwin())
// Emit initial debug information.
- DW.EndModule();
+ DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
O << "\t.subsections_via_symbols\n";
} else {
// Emit final debug information for ELF.
- DW.EndModule();
+ DW->EndModule();
}
return AsmPrinter::doFinalization(M);
/// LinuxAsmPrinter - SPU assembly printer, customized for Linux
struct VISIBILITY_HIDDEN LinuxAsmPrinter : public SPUAsmPrinter {
- DwarfWriter DW;
+ DwarfWriter *DW;
MachineModuleInfo *MMI;
LinuxAsmPrinter(raw_ostream &O, SPUTargetMachine &TM,
const TargetAsmInfo *T) :
SPUAsmPrinter(O, TM, T),
- DW(O, this, T),
+ DW(0),
MMI(0)
{ }
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
SPUAsmPrinter::getAnalysisUsage(AU);
}
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
// We didn't modify anything.
return false;
bool Result = AsmPrinter::doInitialization(M);
SwitchToTextSection("\t.text");
// Emit initial debug information.
- DW.BeginModule(&M);
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ assert(DW && "Dwarf Writer is not available");
MMI = getAnalysisToUpdate<MachineModuleInfo>();
- DW.SetModuleInfo(MMI);
+ DW->BeginModule(&M, MMI, O, this, TAI);
return Result;
}
// TODO
// Emit initial debug information.
- DW.EndModule();
+ DW->EndModule();
return AsmPrinter::doFinalization(M);
}
/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
struct VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
-
- DwarfWriter DW;
+ DwarfWriter *DW;
MachineModuleInfo *MMI;
PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
const TargetAsmInfo *T)
- : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
+ : PPCAsmPrinter(O, TM, T), DW(0), MMI(0) {
}
virtual const char *getPassName() const {
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
/// OS X
struct VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
- DwarfWriter DW;
+ DwarfWriter *DW;
MachineModuleInfo *MMI;
-
+ raw_ostream &OS;
PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
const TargetAsmInfo *T)
- : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
+ : PPCAsmPrinter(O, TM, T), DW(0), MMI(0), OS(O) {
}
virtual const char *getPassName() const {
void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
PPCAsmPrinter::getAnalysisUsage(AU);
}
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
SwitchToSection(TAI->SectionForGlobal(F));
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
O.flush();
bool Result = AsmPrinter::doInitialization(M);
// Emit initial debug information.
- DW.BeginModule(&M);
-
- // AsmPrinter::doInitialization should have done this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
- DW.SetModuleInfo(MMI);
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ assert(DW && "DwarfWriter is not available");
+ DW->BeginModule(&M, MMI, O, this, TAI);
// GNU as handles section names wrapped in quotes
Mang->setUseQuotes(true);
// TODO
// Emit initial debug information.
- DW.EndModule();
+ DW->EndModule();
return AsmPrinter::doFinalization(M);
}
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// If the function is empty, then we need to emit *something*. Otherwise, the
// function's label might be associated with something that it wasn't meant to
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
// We didn't modify anything.
return false;
bool Result = AsmPrinter::doInitialization(M);
// Emit initial debug information.
- DW.BeginModule(&M);
-
// We need this for Personality functions.
// AsmPrinter::doInitialization should have done this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
assert(MMI);
- DW.SetModuleInfo(MMI);
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ assert(DW && "DwarfWriter is not available");
+ DW->BeginModule(&M, MMI, O, this, TAI);
// Darwin wants symbols to be quoted if they have complex names.
Mang->setUseQuotes(true);
// Emit initial debug information.
- DW.EndModule();
+ DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
// Emit pre-function debug and/or EH information.
if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// Print out code for the function.
bool hasAnyRealCode = false;
// Emit post-function debug information.
if (TAI->doesSupportDebugInformation())
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
// Print out jump tables referenced by the function.
EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
/// doInitialization
bool X86ATTAsmPrinter::doInitialization(Module &M) {
- if (TAI->doesSupportDebugInformation()) {
- // Emit initial debug information.
- DW.BeginModule(&M);
- }
bool Result = AsmPrinter::doInitialization(M);
// the MachineModuleInfo address on to DwarfWriter.
// AsmPrinter::doInitialization did this analysis.
MMI = getAnalysisToUpdate<MachineModuleInfo>();
- DW.SetModuleInfo(MMI);
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ DW->BeginModule(&M, MMI, O, this, TAI);
}
// Darwin wants symbols to be quoted if they have complex names.
}
// Emit final debug information.
- DW.EndModule();
+ DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
+ DW->EndModule();
// Funny Darwin hack: This flag tells the linker that no global symbols
// contain code that falls through to other global symbols (e.g. the obvious
}
// Emit final debug information.
- DW.EndModule();
+ DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
+ DW->EndModule();
} else if (Subtarget->isTargetELF()) {
// Emit final debug information.
- DW.EndModule();
+ DwarfWriter *DW = getAnalysisToUpdate<DwarfWriter>();
+ DW->EndModule();
}
return AsmPrinter::doFinalization(M);
struct MachineJumpTableInfo;
struct VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
- DwarfWriter DW;
+ DwarfWriter *DW;
MachineModuleInfo *MMI;
-
const X86Subtarget *Subtarget;
X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
const TargetAsmInfo *T)
- : AsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
+ : AsmPrinter(O, TM, T), DW(0), MMI(0) {
Subtarget = &TM.getSubtarget<X86Subtarget>();
}
Subtarget->isTargetCygMing()) {
AU.addRequired<MachineModuleInfo>();
}
+ AU.addRequired<DwarfWriter>();
AsmPrinter::getAnalysisUsage(AU);
}
struct VISIBILITY_HIDDEN XCoreAsmPrinter : public AsmPrinter {
XCoreAsmPrinter(raw_ostream &O, XCoreTargetMachine &TM,
const TargetAsmInfo *T)
- : AsmPrinter(O, TM, T), DW(O, this, T),
+ : AsmPrinter(O, TM, T), DW(0),
Subtarget(*TM.getSubtargetImpl()) { }
- DwarfWriter DW;
+ DwarfWriter *DW;
const XCoreSubtarget &Subtarget;
virtual const char *getPassName() const {
AsmPrinter::getAnalysisUsage(AU);
AU.setPreservesAll();
AU.addRequired<MachineModuleInfo>();
+ AU.addRequired<DwarfWriter>();
}
};
} // end of anonymous namespace
emitFunctionStart(MF);
// Emit pre-function debug information.
- DW.BeginFunction(&MF);
+ DW->BeginFunction(&MF);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
emitFunctionEnd(MF);
// Emit post-function debug information.
- DW.EndFunction(&MF);
+ DW->EndFunction(&MF);
// We didn't modify anything.
return false;
}
// Emit initial debug information.
- DW.BeginModule(&M);
-
- DW.SetModuleInfo(getAnalysisToUpdate<MachineModuleInfo>());
+ DW = getAnalysisToUpdate<DwarfWriter>();
+ assert(DW && "Dwarf Writer is not available");
+ DW->BeginModule(&M, getAnalysisToUpdate<MachineModuleInfo>(),
+ O, this, TAI);
return Result;
}
}
// Emit final debug information.
- DW.EndModule();
+ DW->EndModule();
return AsmPrinter::doFinalization(M);
}