blob: 7aa928170cc34560c1184e0c017b68fb4f67d1da [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.
Chris Lattner75f50722010-04-04 07:48:20 +000039void DwarfWriter::BeginModule(Module *M, AsmPrinter *A) {
40 DE = new DwarfException(A);
41 DD = new DwarfDebug(A);
42 DE->BeginModule(M);
43 DD->beginModule(M);
Jim Laskey65195462006-10-30 13:35:07 +000044}
45
46/// EndModule - Emit all Dwarf sections that should come after the content.
47///
48void DwarfWriter::EndModule() {
Jim Laskey072200c2007-01-29 18:51:14 +000049 DE->EndModule();
Devang Patel2c4ceb12009-11-21 02:48:08 +000050 DD->endModule();
Duncan Sands597f9792009-09-11 17:24:29 +000051 delete DD; DD = 0;
52 delete DE; DE = 0;
Jim Laskey65195462006-10-30 13:35:07 +000053}
54
Anton Korobeynikovffe31d72008-08-16 12:57:46 +000055/// BeginFunction - Gather pre-function debug information. Assumes being
Jim Laskey65195462006-10-30 13:35:07 +000056/// emitted immediately after the function entry point.
Chris Lattnereec791a2010-01-26 23:18:02 +000057void DwarfWriter::BeginFunction(const MachineFunction *MF) {
Jim Laskey072200c2007-01-29 18:51:14 +000058 DE->BeginFunction(MF);
Devang Patel2c4ceb12009-11-21 02:48:08 +000059 DD->beginFunction(MF);
Jim Laskey65195462006-10-30 13:35:07 +000060}
61
62/// EndFunction - Gather and emit post-function debug information.
63///
Chris Lattnereec791a2010-01-26 23:18:02 +000064void DwarfWriter::EndFunction(const MachineFunction *MF) {
Devang Patel2c4ceb12009-11-21 02:48:08 +000065 DD->endFunction(MF);
Jim Laskeyb82313f2007-02-01 16:31:34 +000066 DE->EndFunction();
Anton Korobeynikovffe31d72008-08-16 12:57:46 +000067
Bill Wendlingc91d0b92008-07-22 00:53:37 +000068 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
Jim Laskeyb82313f2007-02-01 16:31:34 +000069 // Clear function debug information.
70 MMI->EndFunction();
Jim Laskey65195462006-10-30 13:35:07 +000071}
Devang Patelccca7fe2009-01-12 19:17:34 +000072
Bill Wendling4ed0c5f2009-02-20 00:44:43 +000073/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
74/// be emitted.
75bool DwarfWriter::ShouldEmitDwarfDebug() const {
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000076 return DD && DD->ShouldEmitDwarfDebug();
Bill Wendling4ed0c5f2009-02-20 00:44:43 +000077}
Devang Patel0f7fef32009-04-13 17:02:03 +000078
Devang Patel553881b2010-03-29 17:20:31 +000079void DwarfWriter::BeginScope(const MachineInstr *MI) {
80 DD->beginScope(MI);
Devang Patel0f7fef32009-04-13 17:02:03 +000081}
Devang Patel53bb5c92009-11-10 23:06:00 +000082void DwarfWriter::EndScope(const MachineInstr *MI) {
Devang Patel2c4ceb12009-11-21 02:48:08 +000083 DD->endScope(MI);
Devang Patel60b35bd2009-10-06 18:37:31 +000084}