Bill Wendling | a89e67d | 2009-05-10 23:14:38 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains support for writing dwarf info into asm files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/DwarfWriter.h" |
Bill Wendling | b12b3d7 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 15 | #include "DwarfDebug.h" |
Bill Wendling | 1b43db7 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 16 | #include "DwarfException.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Bill Wendling | b12b3d7 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 18 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 19 | using namespace llvm; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 20 | |
Devang Patel | aa1e843 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 21 | static RegisterPass<DwarfWriter> |
| 22 | X("dwarfwriter", "DWARF Information Writer"); |
| 23 | char DwarfWriter::ID = 0; |
| 24 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 26 | /// DwarfWriter Implementation |
| 27 | /// |
| 28 | |
Bill Wendling | cb3661f | 2009-03-10 20:41:52 +0000 | [diff] [blame] | 29 | DwarfWriter::DwarfWriter() |
Bill Wendling | d9308a6 | 2009-03-10 21:23:25 +0000 | [diff] [blame] | 30 | : ImmutablePass(&ID), DD(0), DE(0) {} |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 31 | |
| 32 | DwarfWriter::~DwarfWriter() { |
| 33 | delete DE; |
| 34 | delete DD; |
| 35 | } |
| 36 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 37 | /// BeginModule - Emit all Dwarf sections that should come prior to the |
| 38 | /// content. |
Devang Patel | aa1e843 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 39 | void DwarfWriter::BeginModule(Module *M, |
| 40 | MachineModuleInfo *MMI, |
| 41 | raw_ostream &OS, AsmPrinter *A, |
Chris Lattner | 621c44d | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 42 | const MCAsmInfo *T) { |
Devang Patel | aa1e843 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 43 | DE = new DwarfException(OS, A, T); |
| 44 | DD = new DwarfDebug(OS, A, T); |
Devang Patel | 59a1d42 | 2009-06-25 22:36:02 +0000 | [diff] [blame] | 45 | DE->BeginModule(M, MMI); |
| 46 | DD->BeginModule(M, MMI); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /// EndModule - Emit all Dwarf sections that should come after the content. |
| 50 | /// |
| 51 | void DwarfWriter::EndModule() { |
| 52 | DE->EndModule(); |
| 53 | DD->EndModule(); |
Duncan Sands | a24946a | 2009-09-11 17:24:29 +0000 | [diff] [blame] | 54 | delete DD; DD = 0; |
| 55 | delete DE; DE = 0; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 56 | } |
| 57 | |
asl | c200b11 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 58 | /// BeginFunction - Gather pre-function debug information. Assumes being |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 59 | /// emitted immediately after the function entry point. |
| 60 | void DwarfWriter::BeginFunction(MachineFunction *MF) { |
| 61 | DE->BeginFunction(MF); |
| 62 | DD->BeginFunction(MF); |
| 63 | } |
| 64 | |
| 65 | /// EndFunction - Gather and emit post-function debug information. |
| 66 | /// |
Bill Wendling | b22ae7d | 2008-09-26 00:28:12 +0000 | [diff] [blame] | 67 | void DwarfWriter::EndFunction(MachineFunction *MF) { |
| 68 | DD->EndFunction(MF); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 69 | DE->EndFunction(); |
asl | c200b11 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 70 | |
Bill Wendling | 5b4796a | 2008-07-22 00:53:37 +0000 | [diff] [blame] | 71 | if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI()) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 72 | // Clear function debug information. |
| 73 | MMI->EndFunction(); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 74 | } |
Devang Patel | cb59fd4 | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 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. |
| 79 | unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, |
Devang Patel | 4d23d84 | 2009-09-30 22:51:28 +0000 | [diff] [blame^] | 80 | MDNode *Scope) { |
| 81 | return DD->RecordSourceLine(Line, Col, Scope); |
Devang Patel | cb59fd4 | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /// RecordRegionStart - Indicate the start of a region. |
Devang Patel | 15e723d | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 85 | unsigned DwarfWriter::RecordRegionStart(MDNode *N) { |
| 86 | return DD->RecordRegionStart(N); |
Devang Patel | cb59fd4 | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /// RecordRegionEnd - Indicate the end of a region. |
Devang Patel | 15e723d | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 90 | unsigned DwarfWriter::RecordRegionEnd(MDNode *N) { |
| 91 | return DD->RecordRegionEnd(N); |
Devang Patel | cb59fd4 | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /// getRecordSourceLineCount - Count source lines. |
| 95 | unsigned DwarfWriter::getRecordSourceLineCount() { |
Bill Wendling | d9308a6 | 2009-03-10 21:23:25 +0000 | [diff] [blame] | 96 | return DD->getRecordSourceLineCount(); |
Devang Patel | cb59fd4 | 2009-01-12 19:17:34 +0000 | [diff] [blame] | 97 | } |
Devang Patel | 7019087 | 2009-01-13 21:25:00 +0000 | [diff] [blame] | 98 | |
Devang Patel | fe359e7 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 99 | /// RecordVariable - Indicate the declaration of a local variable. |
| 100 | /// |
Devang Patel | 15e723d | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 101 | void DwarfWriter::RecordVariable(MDNode *N, unsigned FrameIndex) { |
| 102 | DD->RecordVariable(N, FrameIndex); |
Devang Patel | fe359e7 | 2009-01-13 21:44:10 +0000 | [diff] [blame] | 103 | } |
Devang Patel | 42f6bed | 2009-01-13 23:54:55 +0000 | [diff] [blame] | 104 | |
Bill Wendling | 50db079 | 2009-02-20 00:44:43 +0000 | [diff] [blame] | 105 | /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should |
| 106 | /// be emitted. |
| 107 | bool DwarfWriter::ShouldEmitDwarfDebug() const { |
Argiris Kirtzidis | 2565734 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 108 | return DD && DD->ShouldEmitDwarfDebug(); |
Bill Wendling | 50db079 | 2009-02-20 00:44:43 +0000 | [diff] [blame] | 109 | } |
Devang Patel | 88bf96e | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 110 | |
Devang Patel | 15e723d | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 111 | //// RecordInlinedFnStart |
Argiris Kirtzidis | f4510c0 | 2009-05-07 00:16:31 +0000 | [diff] [blame] | 112 | unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU, |
| 113 | unsigned Line, unsigned Col) { |
| 114 | return DD->RecordInlinedFnStart(SP, CU, Line, Col); |
Devang Patel | 88bf96e | 2009-04-13 17:02:03 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Devang Patel | 8a9a7dc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 117 | /// RecordInlinedFnEnd - Indicate the end of inlined subroutine. |
Argiris Kirtzidis | f4510c0 | 2009-05-07 00:16:31 +0000 | [diff] [blame] | 118 | unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) { |
Devang Patel | 8a9a7dc | 2009-04-15 00:10:26 +0000 | [diff] [blame] | 119 | return DD->RecordInlinedFnEnd(SP); |
| 120 | } |
| 121 | |