blob: 1b019cd294aa6b73491a57cfcd177397611ea601 [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);
41 DD = new DwarfDebug(A);
Chris Lattner75e113c2010-04-04 07:48:20 +000042 DD->beginModule(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043}
44
45/// EndModule - Emit all Dwarf sections that should come after the content.
46///
47void DwarfWriter::EndModule() {
48 DE->EndModule();
Devang Patelc50078e2009-11-21 02:48:08 +000049 DD->endModule();
Duncan Sandsa24946a2009-09-11 17:24:29 +000050 delete DD; DD = 0;
51 delete DE; DE = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052}
53
aslc200b112008-08-16 12:57:46 +000054/// BeginFunction - Gather pre-function debug information. Assumes being
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055/// emitted immediately after the function entry point.
Chris Lattner69a76972010-01-26 23:18:02 +000056void DwarfWriter::BeginFunction(const MachineFunction *MF) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 DE->BeginFunction(MF);
Devang Patelc50078e2009-11-21 02:48:08 +000058 DD->beginFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059}
60
61/// EndFunction - Gather and emit post-function debug information.
62///
Chris Lattner69a76972010-01-26 23:18:02 +000063void DwarfWriter::EndFunction(const MachineFunction *MF) {
Devang Patelc50078e2009-11-21 02:48:08 +000064 DD->endFunction(MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065 DE->EndFunction();
aslc200b112008-08-16 12:57:46 +000066
Chris Lattnerf2691ed2010-04-05 00:26:50 +000067 if (MachineModuleInfo *MMI = DE->MMI)
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068 // Clear function debug information.
69 MMI->EndFunction();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070}
Devang Patelcb59fd42009-01-12 19:17:34 +000071
Bill Wendling50db0792009-02-20 00:44:43 +000072/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
73/// be emitted.
74bool DwarfWriter::ShouldEmitDwarfDebug() const {
Argiris Kirtzidis25657342009-05-03 08:50:41 +000075 return DD && DD->ShouldEmitDwarfDebug();
Bill Wendling50db0792009-02-20 00:44:43 +000076}
Devang Patel88bf96e2009-04-13 17:02:03 +000077
Devang Patelabc2b352010-03-29 17:20:31 +000078void DwarfWriter::BeginScope(const MachineInstr *MI) {
79 DD->beginScope(MI);
Devang Patel88bf96e2009-04-13 17:02:03 +000080}
Devang Patel90a0fe32009-11-10 23:06:00 +000081void DwarfWriter::EndScope(const MachineInstr *MI) {
Devang Patelc50078e2009-11-21 02:48:08 +000082 DD->endScope(MI);
Devang Patel0feae422009-10-06 18:37:31 +000083}