blob: 15a02dd9d452d32499f0086032db961b2f90ba41 [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.
Chris Lattner75e113c2010-04-04 07:48:20 +000039void DwarfWriter::BeginModule(Module *M, AsmPrinter *A) {
40 DE = new DwarfException(A);
Chris Lattnerec9a1f42010-04-05 05:11:15 +000041 DD = new DwarfDebug(A, M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042}
43
44/// EndModule - Emit all Dwarf sections that should come after the content.
45///
46void DwarfWriter::EndModule() {
47 DE->EndModule();
Devang Patelc50078e2009-11-21 02:48:08 +000048 DD->endModule();
Duncan Sandsa24946a2009-09-11 17:24:29 +000049 delete DD; DD = 0;
50 delete DE; DE = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051}
52
aslc200b112008-08-16 12:57:46 +000053/// BeginFunction - Gather pre-function debug information. Assumes being
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054/// emitted immediately after the function entry point.
Chris Lattner69a76972010-01-26 23:18:02 +000055void DwarfWriter::BeginFunction(const MachineFunction *MF) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 DE->BeginFunction(MF);
Devang Patelc50078e2009-11-21 02:48:08 +000057 DD->beginFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058}
59
60/// EndFunction - Gather and emit post-function debug information.
61///
Chris Lattner69a76972010-01-26 23:18:02 +000062void DwarfWriter::EndFunction(const MachineFunction *MF) {
Devang Patelc50078e2009-11-21 02:48:08 +000063 DD->endFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 DE->EndFunction();
aslc200b112008-08-16 12:57:46 +000065
Chris Lattnerf2691ed2010-04-05 00:26:50 +000066 if (MachineModuleInfo *MMI = DE->MMI)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067 // Clear function debug information.
68 MMI->EndFunction();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069}
Devang Patelcb59fd42009-01-12 19:17:34 +000070
Bill Wendling50db0792009-02-20 00:44:43 +000071/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
72/// be emitted.
73bool DwarfWriter::ShouldEmitDwarfDebug() const {
Chris Lattnera52b6172010-04-05 02:19:28 +000074 return DD && DD->MMI->hasDebugInfo();
Bill Wendling50db0792009-02-20 00:44:43 +000075}
Devang Patel88bf96e2009-04-13 17:02:03 +000076
Devang Patelabc2b352010-03-29 17:20:31 +000077void DwarfWriter::BeginScope(const MachineInstr *MI) {
78 DD->beginScope(MI);
Devang Patel88bf96e2009-04-13 17:02:03 +000079}
Devang Patel90a0fe32009-11-10 23:06:00 +000080void DwarfWriter::EndScope(const MachineInstr *MI) {
Devang Patelc50078e2009-11-21 02:48:08 +000081 DD->endScope(MI);
Devang Patel0feae422009-10-06 18:37:31 +000082}