tidy up
[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,
40                               MachineModuleInfo *MMI,
41                               raw_ostream &OS, AsmPrinter *A,
42                               const TargetAsmInfo *T) {
43   DE = new DwarfException(OS, A, T);
44   DD = new DwarfDebug(OS, A, T);
45   DE->BeginModule(M, MMI);
46   DD->BeginModule(M, MMI);
47 }
48
49 /// EndModule - Emit all Dwarf sections that should come after the content.
50 ///
51 void DwarfWriter::EndModule() {
52   DE->EndModule();
53   DD->EndModule();
54 }
55
56 /// BeginFunction - Gather pre-function debug information.  Assumes being
57 /// emitted immediately after the function entry point.
58 void DwarfWriter::BeginFunction(MachineFunction *MF) {
59   DE->BeginFunction(MF);
60   DD->BeginFunction(MF);
61 }
62
63 /// EndFunction - Gather and emit post-function debug information.
64 ///
65 void DwarfWriter::EndFunction(MachineFunction *MF) {
66   DD->EndFunction(MF);
67   DE->EndFunction();
68
69   if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
70     // Clear function debug information.
71     MMI->EndFunction();
72 }
73
74 /// RecordSourceLine - Records location information and associates it with a 
75 /// label. Returns a unique label ID used to generate a label and provide
76 /// correspondence to the source line list.
77 unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, 
78                                        DICompileUnit CU) {
79   return DD->RecordSourceLine(Line, Col, CU);
80 }
81
82 /// RecordRegionStart - Indicate the start of a region.
83 unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) {
84   return DD->RecordRegionStart(V);
85 }
86
87 /// RecordRegionEnd - Indicate the end of a region.
88 unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) {
89   return DD->RecordRegionEnd(V);
90 }
91
92 /// getRecordSourceLineCount - Count source lines.
93 unsigned DwarfWriter::getRecordSourceLineCount() {
94   return DD->getRecordSourceLineCount();
95 }
96
97 /// RecordVariable - Indicate the declaration of  a local variable.
98 ///
99 void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
100                                  const MachineInstr *MI) {
101   DD->RecordVariable(GV, FrameIndex, MI);
102 }
103
104 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
105 /// be emitted.
106 bool DwarfWriter::ShouldEmitDwarfDebug() const {
107   return DD && DD->ShouldEmitDwarfDebug();
108 }
109
110 //// RecordInlinedFnStart - Global variable GV is inlined at the location marked
111 //// by LabelID label.
112 unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU,
113                                            unsigned Line, unsigned Col) {
114   return DD->RecordInlinedFnStart(SP, CU, Line, Col);
115 }
116
117 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
118 unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
119   return DD->RecordInlinedFnEnd(SP);
120 }
121
122 /// RecordVariableScope - Record scope for the variable declared by
123 /// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
124 void DwarfWriter::RecordVariableScope(DIVariable &DV,
125                                       const MachineInstr *DeclareMI) {
126   DD->RecordVariableScope(DV, DeclareMI);
127 }