blob: 483ee559ffe907eba77bebd64e90c181d4ffc024 [file] [log] [blame]
Bill Wendlinga5c8a4e2009-05-10 23:14:38 +00001//===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
Jim Laskeye5032892005-12-21 19:48:16 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskeye5032892005-12-21 19:48:16 +00007//
8//===----------------------------------------------------------------------===//
9//
Jim Laskey072200c2007-01-29 18:51:14 +000010// This file contains support for writing dwarf info into asm files.
Jim Laskeye5032892005-12-21 19:48:16 +000011//
12//===----------------------------------------------------------------------===//
Jim Laskey3ea0e0e2006-01-27 18:32:41 +000013
Jim Laskeyb2efb852006-01-04 22:28:25 +000014#include "llvm/CodeGen/DwarfWriter.h"
Bill Wendling0310d762009-05-15 09:23:25 +000015#include "DwarfDebug.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000016#include "DwarfException.h"
Jim Laskey44c3b9f2007-01-26 21:22:28 +000017#include "llvm/CodeGen/MachineModuleInfo.h"
Bill Wendling0310d762009-05-15 09:23:25 +000018
Jim Laskeyb2efb852006-01-04 22:28:25 +000019using namespace llvm;
Jim Laskeya7cea6f2006-01-04 13:52:30 +000020
Devang Pateleb3fc282009-01-08 23:40:34 +000021static RegisterPass<DwarfWriter>
22X("dwarfwriter", "DWARF Information Writer");
23char DwarfWriter::ID = 0;
24
Jim Laskey063e7652006-01-17 17:31:53 +000025//===----------------------------------------------------------------------===//
Jim Laskey65195462006-10-30 13:35:07 +000026/// DwarfWriter Implementation
Jim Laskeyef42a012006-11-02 20:12:39 +000027///
Jim Laskey65195462006-10-30 13:35:07 +000028
Bill Wendling91b8b802009-03-10 20:41:52 +000029DwarfWriter::DwarfWriter()
Bill Wendling163ba3f2009-03-10 21:23:25 +000030 : ImmutablePass(&ID), DD(0), DE(0) {}
Jim Laskey65195462006-10-30 13:35:07 +000031
32DwarfWriter::~DwarfWriter() {
Jim Laskey072200c2007-01-29 18:51:14 +000033 delete DE;
34 delete DD;
Jim Laskey65195462006-10-30 13:35:07 +000035}
36
Jim Laskey65195462006-10-30 13:35:07 +000037/// BeginModule - Emit all Dwarf sections that should come prior to the
38/// content.
Devang Pateleb3fc282009-01-08 23:40:34 +000039void 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);
Jim Laskey072200c2007-01-29 18:51:14 +000045 DE->BeginModule(M);
46 DD->BeginModule(M);
Devang Patel7bb89ed2009-01-13 00:20:51 +000047 DD->SetDebugInfo(MMI);
Devang Pateleb3fc282009-01-08 23:40:34 +000048 DE->SetModuleInfo(MMI);
Jim Laskey65195462006-10-30 13:35:07 +000049}
50
51/// EndModule - Emit all Dwarf sections that should come after the content.
52///
53void DwarfWriter::EndModule() {
Jim Laskey072200c2007-01-29 18:51:14 +000054 DE->EndModule();
55 DD->EndModule();
Jim Laskey65195462006-10-30 13:35:07 +000056}
57
Anton Korobeynikovffe31d72008-08-16 12:57:46 +000058/// BeginFunction - Gather pre-function debug information. Assumes being
Jim Laskey65195462006-10-30 13:35:07 +000059/// emitted immediately after the function entry point.
60void DwarfWriter::BeginFunction(MachineFunction *MF) {
Jim Laskey072200c2007-01-29 18:51:14 +000061 DE->BeginFunction(MF);
62 DD->BeginFunction(MF);
Jim Laskey65195462006-10-30 13:35:07 +000063}
64
65/// EndFunction - Gather and emit post-function debug information.
66///
Bill Wendlingd751c642008-09-26 00:28:12 +000067void DwarfWriter::EndFunction(MachineFunction *MF) {
68 DD->EndFunction(MF);
Jim Laskeyb82313f2007-02-01 16:31:34 +000069 DE->EndFunction();
Anton Korobeynikovffe31d72008-08-16 12:57:46 +000070
Bill Wendlingc91d0b92008-07-22 00:53:37 +000071 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
Jim Laskeyb82313f2007-02-01 16:31:34 +000072 // Clear function debug information.
73 MMI->EndFunction();
Jim Laskey65195462006-10-30 13:35:07 +000074}
Devang Patelccca7fe2009-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,
Argyrios Kyrtzidisa26eae62009-04-30 23:22:31 +000080 DICompileUnit CU) {
81 return DD->RecordSourceLine(Line, Col, CU);
Devang Patelccca7fe2009-01-12 19:17:34 +000082}
83
84/// RecordRegionStart - Indicate the start of a region.
85unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) {
Bill Wendling163ba3f2009-03-10 21:23:25 +000086 return DD->RecordRegionStart(V);
Devang Patelccca7fe2009-01-12 19:17:34 +000087}
88
89/// RecordRegionEnd - Indicate the end of a region.
Dan Gohman9a38e3e2009-05-07 19:46:24 +000090unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) {
91 return DD->RecordRegionEnd(V);
Devang Patelccca7fe2009-01-12 19:17:34 +000092}
93
94/// getRecordSourceLineCount - Count source lines.
95unsigned DwarfWriter::getRecordSourceLineCount() {
Bill Wendling163ba3f2009-03-10 21:23:25 +000096 return DD->getRecordSourceLineCount();
Devang Patelccca7fe2009-01-12 19:17:34 +000097}
Devang Patelbb8c5952009-01-13 21:25:00 +000098
Devang Patelc48c5502009-01-13 21:44:10 +000099/// RecordVariable - Indicate the declaration of a local variable.
100///
Devang Patel1be3ecc2009-04-15 00:10:26 +0000101void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
102 const MachineInstr *MI) {
103 DD->RecordVariable(GV, FrameIndex, MI);
Devang Patelc48c5502009-01-13 21:44:10 +0000104}
Devang Patelbbdc8202009-01-13 23:54:55 +0000105
Bill Wendling4ed0c5f2009-02-20 00:44:43 +0000106/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
107/// be emitted.
108bool DwarfWriter::ShouldEmitDwarfDebug() const {
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +0000109 return DD && DD->ShouldEmitDwarfDebug();
Bill Wendling4ed0c5f2009-02-20 00:44:43 +0000110}
Devang Patel0f7fef32009-04-13 17:02:03 +0000111
Devang Patel1be3ecc2009-04-15 00:10:26 +0000112//// RecordInlinedFnStart - Global variable GV is inlined at the location marked
Devang Patel0f7fef32009-04-13 17:02:03 +0000113//// by LabelID label.
Argyrios Kyrtzidis116b2742009-05-07 00:16:31 +0000114unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU,
115 unsigned Line, unsigned Col) {
116 return DD->RecordInlinedFnStart(SP, CU, Line, Col);
Devang Patel0f7fef32009-04-13 17:02:03 +0000117}
118
Devang Patel1be3ecc2009-04-15 00:10:26 +0000119/// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
Argyrios Kyrtzidis116b2742009-05-07 00:16:31 +0000120unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
Devang Patel1be3ecc2009-04-15 00:10:26 +0000121 return DD->RecordInlinedFnEnd(SP);
122}
123
124/// RecordVariableScope - Record scope for the variable declared by
125/// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
126void DwarfWriter::RecordVariableScope(DIVariable &DV,
127 const MachineInstr *DeclareMI) {
128 DD->RecordVariableScope(DV, DeclareMI);
129}