blob: 08e1bbce08f48d640596cea481bd9952357bcdd2 [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);
Devang Patelc50078e2009-11-21 02:48:08 +000046 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();
Devang Patelc50078e2009-11-21 02:48:08 +000053 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.
Chris Lattner69a76972010-01-26 23:18:02 +000060void DwarfWriter::BeginFunction(const MachineFunction *MF) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 DE->BeginFunction(MF);
Devang Patelc50078e2009-11-21 02:48:08 +000062 DD->beginFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063}
64
65/// EndFunction - Gather and emit post-function debug information.
66///
Chris Lattner69a76972010-01-26 23:18:02 +000067void DwarfWriter::EndFunction(const MachineFunction *MF) {
Devang Patelc50078e2009-11-21 02:48:08 +000068 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) {
Devang Patelc50078e2009-11-21 02:48:08 +000081 return DD->recordSourceLine(Line, Col, Scope);
Devang Patelcb59fd42009-01-12 19:17:34 +000082}
83
Devang Patelcb59fd42009-01-12 19:17:34 +000084/// getRecordSourceLineCount - Count source lines.
85unsigned DwarfWriter::getRecordSourceLineCount() {
Devang Patelc50078e2009-11-21 02:48:08 +000086 return DD->getSourceLineCount();
Devang Patelcb59fd42009-01-12 19:17:34 +000087}
Devang Patel70190872009-01-13 21:25:00 +000088
Bill Wendling50db0792009-02-20 00:44:43 +000089/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
90/// be emitted.
91bool DwarfWriter::ShouldEmitDwarfDebug() const {
Argiris Kirtzidis25657342009-05-03 08:50:41 +000092 return DD && DD->ShouldEmitDwarfDebug();
Bill Wendling50db0792009-02-20 00:44:43 +000093}
Devang Patel88bf96e2009-04-13 17:02:03 +000094
Devang Patel90a0fe32009-11-10 23:06:00 +000095void DwarfWriter::BeginScope(const MachineInstr *MI, unsigned L) {
Devang Patelc50078e2009-11-21 02:48:08 +000096 DD->beginScope(MI, L);
Devang Patel88bf96e2009-04-13 17:02:03 +000097}
Devang Patel90a0fe32009-11-10 23:06:00 +000098void DwarfWriter::EndScope(const MachineInstr *MI) {
Devang Patelc50078e2009-11-21 02:48:08 +000099 DD->endScope(MI);
Devang Patel0feae422009-10-06 18:37:31 +0000100}