1) make DIE take AsmPrinter instead of DwarfPrinter.
[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);
42   DE->BeginModule(M);
43   DD->beginModule(M);
44 }
45
46 /// EndModule - Emit all Dwarf sections that should come after the content.
47 ///
48 void DwarfWriter::EndModule() {
49   DE->EndModule();
50   DD->endModule();
51   delete DD; DD = 0;
52   delete DE; DE = 0;
53 }
54
55 /// BeginFunction - Gather pre-function debug information.  Assumes being
56 /// emitted immediately after the function entry point.
57 void DwarfWriter::BeginFunction(const MachineFunction *MF) {
58   DE->BeginFunction(MF);
59   DD->beginFunction(MF);
60 }
61
62 /// EndFunction - Gather and emit post-function debug information.
63 ///
64 void DwarfWriter::EndFunction(const MachineFunction *MF) {
65   DD->endFunction(MF);
66   DE->EndFunction();
67
68   if (MachineModuleInfo *MMI = DE->getMMI())
69     // Clear function debug information.
70     MMI->EndFunction();
71 }
72
73 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
74 /// be emitted.
75 bool DwarfWriter::ShouldEmitDwarfDebug() const {
76   return DD && DD->ShouldEmitDwarfDebug();
77 }
78
79 void DwarfWriter::BeginScope(const MachineInstr *MI) {
80   DD->beginScope(MI);
81 }
82 void DwarfWriter::EndScope(const MachineInstr *MI) {
83   DD->endScope(MI);
84 }