1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf info into asm files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/CodeGen/DwarfWriter.h"
15 #include "DwarfDebug.h"
16 #include "DwarfException.h"
17 #include "llvm/CodeGen/MachineModuleInfo.h"
21 static RegisterPass
<DwarfWriter
>
22 X("dwarfwriter", "DWARF Information Writer");
23 char DwarfWriter::ID
= 0;
25 //===----------------------------------------------------------------------===//
26 /// DwarfWriter Implementation
29 DwarfWriter::DwarfWriter()
30 : ImmutablePass(&ID
), DD(0), DE(0) {}
32 DwarfWriter::~DwarfWriter() {
37 /// BeginModule - Emit all Dwarf sections that should come prior to the
39 void DwarfWriter::BeginModule(Module
*M
,
40 MachineModuleInfo
*MMI
,
41 raw_ostream
&OS
, AsmPrinter
*A
,
43 DE
= new DwarfException(OS
, A
, T
);
44 DD
= new DwarfDebug(OS
, A
, T
);
45 DE
->BeginModule(M
, MMI
);
46 DD
->BeginModule(M
, MMI
);
49 /// EndModule - Emit all Dwarf sections that should come after the content.
51 void DwarfWriter::EndModule() {
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
);
63 /// EndFunction - Gather and emit post-function debug information.
65 void DwarfWriter::EndFunction(MachineFunction
*MF
) {
69 if (MachineModuleInfo
*MMI
= DD
->getMMI() ? DD
->getMMI() : DE
->getMMI())
70 // Clear function debug information.
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
,
79 return DD
->RecordSourceLine(Line
, Col
, CU
);
82 /// RecordRegionStart - Indicate the start of a region.
83 unsigned DwarfWriter::RecordRegionStart(MDNode
*N
) {
84 return DD
->RecordRegionStart(N
);
87 /// RecordRegionEnd - Indicate the end of a region.
88 unsigned DwarfWriter::RecordRegionEnd(MDNode
*N
) {
89 return DD
->RecordRegionEnd(N
);
92 /// getRecordSourceLineCount - Count source lines.
93 unsigned DwarfWriter::getRecordSourceLineCount() {
94 return DD
->getRecordSourceLineCount();
97 /// RecordVariable - Indicate the declaration of a local variable.
99 void DwarfWriter::RecordVariable(MDNode
*N
, unsigned FrameIndex
) {
100 DD
->RecordVariable(N
, FrameIndex
);
103 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
105 bool DwarfWriter::ShouldEmitDwarfDebug() const {
106 return DD
&& DD
->ShouldEmitDwarfDebug();
109 //// RecordInlinedFnStart
110 unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP
, DICompileUnit CU
,
111 unsigned Line
, unsigned Col
) {
112 return DD
->RecordInlinedFnStart(SP
, CU
, Line
, Col
);
115 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
116 unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP
) {
117 return DD
->RecordInlinedFnEnd(SP
);