blob: bebf8e079975f4b4a653ab19c183bcd1445708b4 [file] [log] [blame]
Bill Wendlinga89e67d2009-05-10 23:14:38 +00001//===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing dwarf info into asm files.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/DwarfWriter.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000015#include "DwarfDebug.h"
Bill Wendling1b43db72009-05-15 01:12:28 +000016#include "DwarfException.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "llvm/CodeGen/MachineModuleInfo.h"
Bill Wendlingb12b3d72009-05-15 09:23:25 +000018
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019using namespace llvm;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020
Devang Patelaa1e8432009-01-08 23:40:34 +000021static RegisterPass<DwarfWriter>
22X("dwarfwriter", "DWARF Information Writer");
23char DwarfWriter::ID = 0;
24
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025//===----------------------------------------------------------------------===//
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026/// DwarfWriter Implementation
27///
28
Bill Wendlingcb3661f2009-03-10 20:41:52 +000029DwarfWriter::DwarfWriter()
Bill Wendlingd9308a62009-03-10 21:23:25 +000030 : ImmutablePass(&ID), DD(0), DE(0) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031
32DwarfWriter::~DwarfWriter() {
33 delete DE;
34 delete DD;
35}
36
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037/// BeginModule - Emit all Dwarf sections that should come prior to the
38/// content.
Devang Patelaa1e8432009-01-08 23:40:34 +000039void DwarfWriter::BeginModule(Module *M,
40 MachineModuleInfo *MMI,
41 raw_ostream &OS, AsmPrinter *A,
Chris Lattner621c44d2009-08-22 20:48:53 +000042 const MCAsmInfo *T) {
Devang Patelaa1e8432009-01-08 23:40:34 +000043 DE = new DwarfException(OS, A, T);
44 DD = new DwarfDebug(OS, A, T);
Devang Patel59a1d422009-06-25 22:36:02 +000045 DE->BeginModule(M, MMI);
46 DD->BeginModule(M, MMI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047}
48
49/// EndModule - Emit all Dwarf sections that should come after the content.
50///
51void DwarfWriter::EndModule() {
52 DE->EndModule();
53 DD->EndModule();
Duncan Sandsa24946a2009-09-11 17:24:29 +000054 delete DD; DD = 0;
55 delete DE; DE = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}
57
aslc200b112008-08-16 12:57:46 +000058/// BeginFunction - Gather pre-function debug information. Assumes being
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059/// emitted immediately after the function entry point.
60void DwarfWriter::BeginFunction(MachineFunction *MF) {
61 DE->BeginFunction(MF);
62 DD->BeginFunction(MF);
63}
64
65/// EndFunction - Gather and emit post-function debug information.
66///
Bill Wendlingb22ae7d2008-09-26 00:28:12 +000067void DwarfWriter::EndFunction(MachineFunction *MF) {
68 DD->EndFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069 DE->EndFunction();
aslc200b112008-08-16 12:57:46 +000070
Bill Wendling5b4796a2008-07-22 00:53:37 +000071 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072 // Clear function debug information.
73 MMI->EndFunction();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000074}
Devang Patelcb59fd42009-01-12 19:17:34 +000075
76/// RecordSourceLine - Records location information and associates it with a
77/// label. Returns a unique label ID used to generate a label and provide
78/// correspondence to the source line list.
79unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col,
Devang Patel4d23d842009-09-30 22:51:28 +000080 MDNode *Scope) {
81 return DD->RecordSourceLine(Line, Col, Scope);
Devang Patelcb59fd42009-01-12 19:17:34 +000082}
83
84/// RecordRegionStart - Indicate the start of a region.
Devang Patel15e723d2009-08-28 23:24:31 +000085unsigned DwarfWriter::RecordRegionStart(MDNode *N) {
86 return DD->RecordRegionStart(N);
Devang Patelcb59fd42009-01-12 19:17:34 +000087}
88
89/// RecordRegionEnd - Indicate the end of a region.
Devang Patel15e723d2009-08-28 23:24:31 +000090unsigned DwarfWriter::RecordRegionEnd(MDNode *N) {
91 return DD->RecordRegionEnd(N);
Devang Patelcb59fd42009-01-12 19:17:34 +000092}
93
94/// getRecordSourceLineCount - Count source lines.
95unsigned DwarfWriter::getRecordSourceLineCount() {
Bill Wendlingd9308a62009-03-10 21:23:25 +000096 return DD->getRecordSourceLineCount();
Devang Patelcb59fd42009-01-12 19:17:34 +000097}
Devang Patel70190872009-01-13 21:25:00 +000098
Devang Patelfe359e72009-01-13 21:44:10 +000099/// RecordVariable - Indicate the declaration of a local variable.
100///
Devang Patel15e723d2009-08-28 23:24:31 +0000101void DwarfWriter::RecordVariable(MDNode *N, unsigned FrameIndex) {
102 DD->RecordVariable(N, FrameIndex);
Devang Patelfe359e72009-01-13 21:44:10 +0000103}
Devang Patel42f6bed2009-01-13 23:54:55 +0000104
Bill Wendling50db0792009-02-20 00:44:43 +0000105/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
106/// be emitted.
107bool DwarfWriter::ShouldEmitDwarfDebug() const {
Argiris Kirtzidis25657342009-05-03 08:50:41 +0000108 return DD && DD->ShouldEmitDwarfDebug();
Bill Wendling50db0792009-02-20 00:44:43 +0000109}
Devang Patel88bf96e2009-04-13 17:02:03 +0000110
Devang Patel15e723d2009-08-28 23:24:31 +0000111//// RecordInlinedFnStart
Argiris Kirtzidisf4510c02009-05-07 00:16:31 +0000112unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU,
113 unsigned Line, unsigned Col) {
114 return DD->RecordInlinedFnStart(SP, CU, Line, Col);
Devang Patel88bf96e2009-04-13 17:02:03 +0000115}
116
Devang Patel8a9a7dc2009-04-15 00:10:26 +0000117/// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
Argiris Kirtzidisf4510c02009-05-07 00:16:31 +0000118unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
Devang Patel8a9a7dc2009-04-15 00:10:26 +0000119 return DD->RecordInlinedFnEnd(SP);
120}
121