1 //===- MCDwarf.h - Machine Code Dwarf support -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the MCDwarfFile to support the dwarf
12 // TODO: add the support needed for the .loc directive.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_MC_MCDWARF_H
17 #define LLVM_MC_MCDWARF_H
19 #include "llvm/ADT/StringRef.h"
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).
34 // Name - the base name of the file without its directory path.
35 // The StringRef references memory allocated in the MCContext.
38 // DirIndex - the index into the list of directory names for this file name.
41 private: // MCContext creates and uniques these.
42 friend class MCContext;
43 MCDwarfFile(StringRef name, unsigned dirIndex)
44 : Name(name), DirIndex(dirIndex) {}
46 MCDwarfFile(const MCDwarfFile&); // DO NOT IMPLEMENT
47 void operator=(const MCDwarfFile&); // DO NOT IMPLEMENT
49 /// getName - Get the base name of this MCDwarfFile.
50 StringRef getName() const { return Name; }
52 /// getDirIndex - Get the dirIndex of this MCDwarfFile.
53 unsigned getDirIndex() const { return DirIndex; }
56 /// print - Print the value to the stream \arg OS.
57 void print(raw_ostream &OS) const;
59 /// dump - Print the value to stderr.
63 inline raw_ostream &operator<<(raw_ostream &OS, const MCDwarfFile &DwarfFile){
68 /// MCDwarfLoc - Instances of this class represent the information from a
69 /// dwarf .loc directive.
71 // FileNum - the file number.
73 // Line - the line number.
75 // Column - the column position.
77 // Flags (see #define's below)
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)
87 private: // MCContext manages these
88 friend class MCContext;
89 friend class MCLineEntry;
90 MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
92 : FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa) {}
94 // Allow the default copy constructor and assignment operator to be used
95 // for an MCDwarfLoc object.
98 /// setFileNum - Set the FileNum of this MCDwarfLoc.
99 void setFileNum(unsigned fileNum) { FileNum = fileNum; }
101 /// setLine - Set the Line of this MCDwarfLoc.
102 void setLine(unsigned line) { Line = line; }
104 /// setColumn - Set the Column of this MCDwarfLoc.
105 void setColumn(unsigned column) { Column = column; }
107 /// setFlags - Set the Flags of this MCDwarfLoc.
108 void setFlags(unsigned flags) { Flags = flags; }
110 /// setIsa - Set the Isa of this MCDwarfLoc.
111 void setIsa(unsigned isa) { Isa = isa; }
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 {
123 // Allow the default copy constructor and assignment operator to be used
124 // for an MCLineEntry object.
127 // Constructor to create an MCLineEntry given a symbol and the dwarf loc.
128 MCLineEntry(MCSymbol *label, const MCDwarfLoc loc) : MCDwarfLoc(loc),
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;
140 MCLineSection(const MCLineSection&); // DO NOT IMPLEMENT
141 void operator=(const MCLineSection&); // DO NOT IMPLEMENT
144 // Constructor to create an MCLineSection with an empty MCLineEntries
148 // addLineEntry - adds an entry to this MCLineSection's line entries
149 void addLineEntry(const MCLineEntry &LineEntry) {
150 MCLineEntries.push_back(LineEntry);
154 } // end namespace llvm