blob: 08e1bbce08f48d640596cea481bd9952357bcdd2 [file] [log] [blame]
Shih-wei Liaoe264f622010-02-10 11:10:31 -08001//===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing dwarf info into asm files.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/DwarfWriter.h"
15#include "DwarfDebug.h"
16#include "DwarfException.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
18
19using namespace llvm;
20
21static RegisterPass<DwarfWriter>
22X("dwarfwriter", "DWARF Information Writer");
23char DwarfWriter::ID = 0;
24
25//===----------------------------------------------------------------------===//
26/// DwarfWriter Implementation
27///
28
29DwarfWriter::DwarfWriter()
30 : ImmutablePass(&ID), DD(0), DE(0) {}
31
32DwarfWriter::~DwarfWriter() {
33 delete DE;
34 delete DD;
35}
36
37/// BeginModule - Emit all Dwarf sections that should come prior to the
38/// content.
39void DwarfWriter::BeginModule(Module *M,
40 MachineModuleInfo *MMI,
41 raw_ostream &OS, AsmPrinter *A,
42 const MCAsmInfo *T) {
43 DE = new DwarfException(OS, A, T);
44 DD = new DwarfDebug(OS, A, T);
45 DE->BeginModule(M, MMI);
46 DD->beginModule(M, MMI);
47}
48
49/// EndModule - Emit all Dwarf sections that should come after the content.
50///
51void DwarfWriter::EndModule() {
52 DE->EndModule();
53 DD->endModule();
54 delete DD; DD = 0;
55 delete DE; DE = 0;
56}
57
58/// BeginFunction - Gather pre-function debug information. Assumes being
59/// emitted immediately after the function entry point.
60void DwarfWriter::BeginFunction(const MachineFunction *MF) {
61 DE->BeginFunction(MF);
62 DD->beginFunction(MF);
63}
64
65/// EndFunction - Gather and emit post-function debug information.
66///
67void DwarfWriter::EndFunction(const MachineFunction *MF) {
68 DD->endFunction(MF);
69 DE->EndFunction();
70
71 if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
72 // Clear function debug information.
73 MMI->EndFunction();
74}
75
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,
80 MDNode *Scope) {
81 return DD->recordSourceLine(Line, Col, Scope);
82}
83
84/// getRecordSourceLineCount - Count source lines.
85unsigned DwarfWriter::getRecordSourceLineCount() {
86 return DD->getSourceLineCount();
87}
88
89/// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
90/// be emitted.
91bool DwarfWriter::ShouldEmitDwarfDebug() const {
92 return DD && DD->ShouldEmitDwarfDebug();
93}
94
95void DwarfWriter::BeginScope(const MachineInstr *MI, unsigned L) {
96 DD->beginScope(MI, L);
97}
98void DwarfWriter::EndScope(const MachineInstr *MI) {
99 DD->endScope(MI);
100}