MCDwarf.h revision 47b7efc0828d9587613b2f2865a6d07ed55c5bec
1//===- MCDwarf.h - Machine Code Dwarf support -------------------*- C++ -*-===// 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 the declaration of the MCDwarfFile to support the dwarf 11// .file directive. 12// TODO: add the support needed for the .loc directive. 13// 14//===----------------------------------------------------------------------===// 15 16#ifndef LLVM_MC_MCDWARF_H 17#define LLVM_MC_MCDWARF_H 18 19#include "llvm/ADT/StringRef.h" 20#include <vector> 21 22namespace llvm { 23 class MCContext; 24 class MCSection; 25 class MCSymbol; 26 class raw_ostream; 27 28 /// MCDwarfFile - Instances of this class represent the name of the dwarf 29 /// .file directive and its associated dwarf file number in the MC file, 30 /// and MCDwarfFile's are created and unique'd by the MCContext class where 31 /// the file number for each is its index into the vector of DwarfFiles (note 32 /// index 0 is not used and not a valid dwarf file number). 33 class MCDwarfFile { 34 // Name - the base name of the file without its directory path. 35 // The StringRef references memory allocated in the MCContext. 36 StringRef Name; 37 38 // DirIndex - the index into the list of directory names for this file name. 39 unsigned DirIndex; 40 41 private: // MCContext creates and uniques these. 42 friend class MCContext; 43 MCDwarfFile(StringRef name, unsigned dirIndex) 44 : Name(name), DirIndex(dirIndex) {} 45 46 MCDwarfFile(const MCDwarfFile&); // DO NOT IMPLEMENT 47 void operator=(const MCDwarfFile&); // DO NOT IMPLEMENT 48 public: 49 /// getName - Get the base name of this MCDwarfFile. 50 StringRef getName() const { return Name; } 51 52 /// getDirIndex - Get the dirIndex of this MCDwarfFile. 53 unsigned getDirIndex() const { return DirIndex; } 54 55 56 /// print - Print the value to the stream \arg OS. 57 void print(raw_ostream &OS) const; 58 59 /// dump - Print the value to stderr. 60 void dump() const; 61 }; 62 63 inline raw_ostream &operator<<(raw_ostream &OS, const MCDwarfFile &DwarfFile){ 64 DwarfFile.print(OS); 65 return OS; 66 } 67 68 /// MCDwarfLoc - Instances of this class represent the information from a 69 /// dwarf .loc directive. 70 class MCDwarfLoc { 71 // FileNum - the file number. 72 unsigned FileNum; 73 // Line - the line number. 74 unsigned Line; 75 // Column - the column position. 76 unsigned Column; 77 // Flags (see #define's below) 78 unsigned Flags; 79 // Isa 80 unsigned Isa; 81 82#define DWARF2_FLAG_IS_STMT (1 << 0) 83#define DWARF2_FLAG_BASIC_BLOCK (1 << 1) 84#define DWARF2_FLAG_PROLOGUE_END (1 << 2) 85#define DWARF2_FLAG_EPILOGUE_BEGIN (1 << 3) 86 87 private: // MCContext manages these 88 friend class MCContext; 89 friend class MCLineEntry; 90 MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags, 91 unsigned isa) 92 : FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa) {} 93 94 // Allow the default copy constructor and assignment operator to be used 95 // for an MCDwarfLoc object. 96 97 public: 98 /// setFileNum - Set the FileNum of this MCDwarfLoc. 99 void setFileNum(unsigned fileNum) { FileNum = fileNum; } 100 101 /// setLine - Set the Line of this MCDwarfLoc. 102 void setLine(unsigned line) { Line = line; } 103 104 /// setColumn - Set the Column of this MCDwarfLoc. 105 void setColumn(unsigned column) { Column = column; } 106 107 /// setFlags - Set the Flags of this MCDwarfLoc. 108 void setFlags(unsigned flags) { Flags = flags; } 109 110 /// setIsa - Set the Isa of this MCDwarfLoc. 111 void setIsa(unsigned isa) { Isa = isa; } 112 }; 113 114 /// MCLineEntry - Instances of this class represent the line information for 115 /// the dwarf line table entries. Which is created after a machine 116 /// instruction is assembled and uses an address from a temporary label 117 /// created at the current address in the current section and the info from 118 /// the last .loc directive seen as stored in the context. 119 class MCLineEntry : public MCDwarfLoc { 120 MCSymbol *Label; 121 122 private: 123 // Allow the default copy constructor and assignment operator to be used 124 // for an MCLineEntry object. 125 126 public: 127 // Constructor to create an MCLineEntry given a symbol and the dwarf loc. 128 MCLineEntry(MCSymbol *label, const MCDwarfLoc loc) : MCDwarfLoc(loc), 129 Label(label) {} 130 }; 131 132 /// MCLineSection - Instances of this class represent the line information 133 /// for a section where machine instructions have been assembled after seeing 134 /// .loc directives. This is the information used to build the dwarf line 135 /// table for a section. 136 class MCLineSection { 137 std::vector<MCLineEntry> MCLineEntries; 138 139 private: 140 MCLineSection(const MCLineSection&); // DO NOT IMPLEMENT 141 void operator=(const MCLineSection&); // DO NOT IMPLEMENT 142 143 public: 144 // Constructor to create an MCLineSection with an empty MCLineEntries 145 // vector. 146 MCLineSection() {} 147 148 // addLineEntry - adds an entry to this MCLineSection's line entries 149 void addLineEntry(const MCLineEntry &LineEntry) { 150 MCLineEntries.push_back(LineEntry); 151 } 152 }; 153 154} // end namespace llvm 155 156#endif 157