LLVM API Documentation

DwarfWriter.cpp

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework --------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains support for writing dwarf info into asm files.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "llvm/CodeGen/DwarfWriter.h"
00015 #include "DwarfDebug.h"
00016 #include "DwarfException.h"
00017 #include "llvm/CodeGen/MachineModuleInfo.h"
00018 
00019 using namespace llvm;
00020 
00021 static RegisterPass<DwarfWriter>
00022 X("dwarfwriter", "DWARF Information Writer");
00023 char DwarfWriter::ID = 0;
00024 
00025 //===----------------------------------------------------------------------===//
00026 /// DwarfWriter Implementation
00027 ///
00028 
00029 DwarfWriter::DwarfWriter()
00030   : ImmutablePass(&ID), DD(0), DE(0) {}
00031 
00032 DwarfWriter::~DwarfWriter() {
00033   delete DE;
00034   delete DD;
00035 }
00036 
00037 /// BeginModule - Emit all Dwarf sections that should come prior to the
00038 /// content.
00039 void DwarfWriter::BeginModule(Module *M,
00040                               MachineModuleInfo *MMI,
00041                               raw_ostream &OS, AsmPrinter *A,
00042                               const TargetAsmInfo *T) {
00043   DE = new DwarfException(OS, A, T);
00044   DD = new DwarfDebug(OS, A, T);
00045   DE->BeginModule(M, MMI);
00046   DD->BeginModule(M, MMI);
00047 }
00048 
00049 /// EndModule - Emit all Dwarf sections that should come after the content.
00050 ///
00051 void DwarfWriter::EndModule() {
00052   DE->EndModule();
00053   DD->EndModule();
00054 }
00055 
00056 /// BeginFunction - Gather pre-function debug information.  Assumes being
00057 /// emitted immediately after the function entry point.
00058 void DwarfWriter::BeginFunction(MachineFunction *MF) {
00059   DE->BeginFunction(MF);
00060   DD->BeginFunction(MF);
00061 }
00062 
00063 /// EndFunction - Gather and emit post-function debug information.
00064 ///
00065 void DwarfWriter::EndFunction(MachineFunction *MF) {
00066   DD->EndFunction(MF);
00067   DE->EndFunction();
00068 
00069   if (MachineModuleInfo *MMI = DD->getMMI() ? DD->getMMI() : DE->getMMI())
00070     // Clear function debug information.
00071     MMI->EndFunction();
00072 }
00073 
00074 /// RecordSourceLine - Records location information and associates it with a 
00075 /// label. Returns a unique label ID used to generate a label and provide
00076 /// correspondence to the source line list.
00077 unsigned DwarfWriter::RecordSourceLine(unsigned Line, unsigned Col, 
00078                                        DICompileUnit CU) {
00079   return DD->RecordSourceLine(Line, Col, CU);
00080 }
00081 
00082 /// RecordRegionStart - Indicate the start of a region.
00083 unsigned DwarfWriter::RecordRegionStart(GlobalVariable *V) {
00084   return DD->RecordRegionStart(V);
00085 }
00086 
00087 /// RecordRegionEnd - Indicate the end of a region.
00088 unsigned DwarfWriter::RecordRegionEnd(GlobalVariable *V) {
00089   return DD->RecordRegionEnd(V);
00090 }
00091 
00092 /// getRecordSourceLineCount - Count source lines.
00093 unsigned DwarfWriter::getRecordSourceLineCount() {
00094   return DD->getRecordSourceLineCount();
00095 }
00096 
00097 /// RecordVariable - Indicate the declaration of  a local variable.
00098 ///
00099 void DwarfWriter::RecordVariable(GlobalVariable *GV, unsigned FrameIndex,
00100                                  const MachineInstr *MI) {
00101   DD->RecordVariable(GV, FrameIndex, MI);
00102 }
00103 
00104 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
00105 /// be emitted.
00106 bool DwarfWriter::ShouldEmitDwarfDebug() const {
00107   return DD && DD->ShouldEmitDwarfDebug();
00108 }
00109 
00110 //// RecordInlinedFnStart - Global variable GV is inlined at the location marked
00111 //// by LabelID label.
00112 unsigned DwarfWriter::RecordInlinedFnStart(DISubprogram SP, DICompileUnit CU,
00113                                            unsigned Line, unsigned Col) {
00114   return DD->RecordInlinedFnStart(SP, CU, Line, Col);
00115 }
00116 
00117 /// RecordInlinedFnEnd - Indicate the end of inlined subroutine.
00118 unsigned DwarfWriter::RecordInlinedFnEnd(DISubprogram SP) {
00119   return DD->RecordInlinedFnEnd(SP);
00120 }
00121 
00122 /// RecordVariableScope - Record scope for the variable declared by
00123 /// DeclareMI. DeclareMI must describe TargetInstrInfo::DECLARE.
00124 void DwarfWriter::RecordVariableScope(DIVariable &DV,
00125                                       const MachineInstr *DeclareMI) {
00126   DD->RecordVariableScope(DV, DeclareMI);
00127 }