change AsmPrinter to use DwarfDebug/DwarfException directly
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfWriter.cpp
1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing dwarf info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/DwarfWriter.h"
15 #include "DwarfDebug.h"
16 #include "DwarfException.h"
17 #include "llvm/CodeGen/MachineModuleInfo.h"
18
19 using namespace llvm;
20
21 static RegisterPass<DwarfWriter>
22 X("dwarfwriter", "DWARF Information Writer");
23 char DwarfWriter::ID = 0;
24
25 //===----------------------------------------------------------------------===//
26 /// DwarfWriter Implementation
27 ///
28
29 DwarfWriter::DwarfWriter()
30   : ImmutablePass(&ID), DD(0), DE(0) {}
31
32 DwarfWriter::~DwarfWriter() {
33   delete DE;
34   delete DD;
35 }
36
37 /// BeginModule - Emit all Dwarf sections that should come prior to the
38 /// content.
39 void DwarfWriter::BeginModule(Module *M, AsmPrinter *A) {
40   DE = new DwarfException(A);
41   DD = new DwarfDebug(A, M);
42 }
43
44 /// EndModule - Emit all Dwarf sections that should come after the content.
45 ///
46 void DwarfWriter::EndModule() {
47   DE->EndModule();
48   DD->endModule();
49   delete DD; DD = 0;
50   delete DE; DE = 0;
51 }
52
53 /// BeginFunction - Gather pre-function debug information.  Assumes being
54 /// emitted immediately after the function entry point.
55 void DwarfWriter::BeginFunction(const MachineFunction *MF) {
56   DE->BeginFunction(MF);
57   DD->beginFunction(MF);
58 }
59
60 /// EndFunction - Gather and emit post-function debug information.
61 ///
62 void DwarfWriter::EndFunction(const MachineFunction *MF) {
63   DD->endFunction(MF);
64   DE->EndFunction();
65
66   if (MachineModuleInfo *MMI = DE->MMI)
67     // Clear function debug information.
68     MMI->EndFunction();
69 }
70
71 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
72 /// be emitted.
73 bool DwarfWriter::ShouldEmitDwarfDebug() const {
74   return DD && DD->MMI->hasDebugInfo();
75 }
76
77 void DwarfWriter::BeginScope(const MachineInstr *MI) {
78   DD->beginScope(MI);
79 }
80 void DwarfWriter::EndScope(const MachineInstr *MI) {
81   DD->endScope(MI);
82 }