Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 1 | //===--- lib/CodeGen/DIE.h - DWARF Info Entries -----------------*- 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 | // Data structures for DWARF info entries. |
Eric Christopher | ff34845 | 2013-01-07 22:40:45 +0000 | [diff] [blame] | 11 | // |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Bill Wendling | 0310d76 | 2009-05-15 09:23:25 +0000 | [diff] [blame] | 14 | #ifndef CODEGEN_ASMPRINTER_DIE_H__ |
| 15 | #define CODEGEN_ASMPRINTER_DIE_H__ |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 16 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/FoldingSet.h" |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/Support/Compiler.h" |
| 20 | #include "llvm/Support/Dwarf.h" |
David Blaikie | 95e72c9 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCExpr.h" |
Chris Lattner | b01acfa | 2009-08-23 01:01:17 +0000 | [diff] [blame] | 22 | #include <vector> |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | class AsmPrinter; |
Chris Lattner | 858431d | 2010-01-16 18:50:28 +0000 | [diff] [blame] | 26 | class MCSymbol; |
David Blaikie | 95e72c9 | 2013-06-28 20:05:04 +0000 | [diff] [blame] | 27 | class MCSymbolRefExpr; |
Chris Lattner | b98b1bf | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 28 | class raw_ostream; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 29 | |
| 30 | //===--------------------------------------------------------------------===// |
Eric Christopher | 0fbaa37 | 2013-06-10 22:24:07 +0000 | [diff] [blame] | 31 | /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 32 | /// Dwarf abbreviation. |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 33 | class DIEAbbrevData { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 34 | /// Attribute - Dwarf attribute code. |
| 35 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 36 | dwarf::Attribute Attribute; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 37 | |
| 38 | /// Form - Dwarf form code. |
| 39 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 40 | dwarf::Form Form; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 41 | public: |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 42 | DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {} |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 43 | |
| 44 | // Accessors. |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 45 | dwarf::Attribute getAttribute() const { return Attribute; } |
| 46 | dwarf::Form getForm() const { return Form; } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 47 | |
| 48 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 49 | /// |
| 50 | void Profile(FoldingSetNodeID &ID) const; |
| 51 | }; |
| 52 | |
| 53 | //===--------------------------------------------------------------------===// |
| 54 | /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug |
| 55 | /// information object. |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 56 | class DIEAbbrev : public FoldingSetNode { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 57 | /// Tag - Dwarf tag code. |
| 58 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 59 | dwarf::Tag Tag; |
Benjamin Kramer | e697b4f | 2012-01-24 12:08:28 +0000 | [diff] [blame] | 60 | |
| 61 | /// ChildrenFlag - Dwarf children flag. |
| 62 | /// |
| 63 | uint16_t ChildrenFlag; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 64 | |
| 65 | /// Unique number for node. |
| 66 | /// |
| 67 | unsigned Number; |
| 68 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 69 | /// Data - Raw data bytes for abbreviation. |
| 70 | /// |
Eric Christopher | 2df938a | 2013-03-29 20:23:06 +0000 | [diff] [blame] | 71 | SmallVector<DIEAbbrevData, 12> Data; |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 72 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 73 | public: |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 74 | DIEAbbrev(dwarf::Tag T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {} |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 75 | |
| 76 | // Accessors. |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 77 | dwarf::Tag getTag() const { return Tag; } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 78 | unsigned getNumber() const { return Number; } |
Benjamin Kramer | e697b4f | 2012-01-24 12:08:28 +0000 | [diff] [blame] | 79 | uint16_t getChildrenFlag() const { return ChildrenFlag; } |
Eric Christopher | f7cef70 | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 80 | const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; } |
Benjamin Kramer | e697b4f | 2012-01-24 12:08:28 +0000 | [diff] [blame] | 81 | void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 82 | void setNumber(unsigned N) { Number = N; } |
| 83 | |
| 84 | /// AddAttribute - Adds another set of attribute information to the |
| 85 | /// abbreviation. |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 86 | void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 87 | Data.push_back(DIEAbbrevData(Attribute, Form)); |
| 88 | } |
| 89 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 90 | /// Profile - Used to gather unique data for the abbreviation folding set. |
| 91 | /// |
| 92 | void Profile(FoldingSetNodeID &ID) const; |
| 93 | |
| 94 | /// Emit - Print the abbreviation using the specified asm printer. |
| 95 | /// |
Chris Lattner | d38fee8 | 2010-04-05 00:13:49 +0000 | [diff] [blame] | 96 | void Emit(AsmPrinter *AP) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 97 | |
| 98 | #ifndef NDEBUG |
Chris Lattner | b01acfa | 2009-08-23 01:01:17 +0000 | [diff] [blame] | 99 | void print(raw_ostream &O); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 100 | void dump(); |
| 101 | #endif |
| 102 | }; |
| 103 | |
| 104 | //===--------------------------------------------------------------------===// |
| 105 | /// DIE - A structured debug information entry. Has an abbreviation which |
Eric Christopher | 0c5cdc5 | 2013-04-03 05:29:58 +0000 | [diff] [blame] | 106 | /// describes its organization. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 107 | class DIEValue; |
| 108 | |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 109 | class DIE { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 110 | protected: |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 111 | /// Offset - Offset in debug info section. |
| 112 | /// |
| 113 | unsigned Offset; |
| 114 | |
| 115 | /// Size - Size of instance + children. |
| 116 | /// |
| 117 | unsigned Size; |
| 118 | |
Benjamin Kramer | e697b4f | 2012-01-24 12:08:28 +0000 | [diff] [blame] | 119 | /// Abbrev - Buffer for constructing abbreviation. |
| 120 | /// |
| 121 | DIEAbbrev Abbrev; |
| 122 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 123 | /// Children DIEs. |
| 124 | /// |
| 125 | std::vector<DIE *> Children; |
| 126 | |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 127 | DIE *Parent; |
| 128 | |
Bill Wendling | 034b94b | 2012-12-19 07:18:57 +0000 | [diff] [blame] | 129 | /// Attribute values. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 130 | /// |
Eric Christopher | 2df938a | 2013-03-29 20:23:06 +0000 | [diff] [blame] | 131 | SmallVector<DIEValue*, 12> Values; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 132 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 133 | public: |
| 134 | explicit DIE(unsigned Tag) |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 135 | : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no), |
| 136 | Parent(0) {} |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 137 | virtual ~DIE(); |
| 138 | |
| 139 | // Accessors. |
| 140 | DIEAbbrev &getAbbrev() { return Abbrev; } |
David Blaikie | 851aa94 | 2013-10-24 17:51:43 +0000 | [diff] [blame] | 141 | const DIEAbbrev &getAbbrev() const { return Abbrev; } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 142 | unsigned getAbbrevNumber() const { return Abbrev.getNumber(); } |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 143 | dwarf::Tag getTag() const { return Abbrev.getTag(); } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 144 | unsigned getOffset() const { return Offset; } |
| 145 | unsigned getSize() const { return Size; } |
| 146 | const std::vector<DIE *> &getChildren() const { return Children; } |
Eric Christopher | f7cef70 | 2013-03-29 23:34:06 +0000 | [diff] [blame] | 147 | const SmallVectorImpl<DIEValue*> &getValues() const { return Values; } |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 148 | DIE *getParent() const { return Parent; } |
Manman Ren | 3eabc2a | 2013-10-29 22:57:10 +0000 | [diff] [blame] | 149 | /// Climb up the parent chain to get the compile unit DIE this DIE belongs |
| 150 | /// to. |
| 151 | const DIE *getCompileUnit() const; |
Manman Ren | b8b70e1 | 2013-10-31 17:54:35 +0000 | [diff] [blame] | 152 | /// Similar to getCompileUnit, returns null when DIE is not added to an |
| 153 | /// owner yet. |
| 154 | const DIE *getCompileUnitOrNull() const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 155 | void setOffset(unsigned O) { Offset = O; } |
| 156 | void setSize(unsigned S) { Size = S; } |
Eric Christopher | ff34845 | 2013-01-07 22:40:45 +0000 | [diff] [blame] | 157 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 158 | /// addValue - Add a value and attributes to a DIE. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 159 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 160 | void addValue(dwarf::Attribute Attribute, dwarf::Form Form, |
| 161 | DIEValue *Value) { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 162 | Abbrev.AddAttribute(Attribute, Form); |
| 163 | Values.push_back(Value); |
| 164 | } |
| 165 | |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 166 | /// addChild - Add a child to the DIE. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 167 | /// |
Devang Patel | 2c4ceb1 | 2009-11-21 02:48:08 +0000 | [diff] [blame] | 168 | void addChild(DIE *Child) { |
David Blaikie | e5830c4 | 2013-10-03 20:07:20 +0000 | [diff] [blame] | 169 | assert(!Child->getParent()); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 170 | Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes); |
| 171 | Children.push_back(Child); |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 172 | Child->Parent = this; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Eric Christopher | b766913 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 175 | /// findAttribute - Find a value in the DIE with the attribute given, returns NULL |
| 176 | /// if no such attribute exists. |
Eric Christopher | 3166762 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 177 | DIEValue *findAttribute(uint16_t Attribute); |
Eric Christopher | b766913 | 2013-08-07 01:18:33 +0000 | [diff] [blame] | 178 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 179 | #ifndef NDEBUG |
Eric Christopher | 30cb836 | 2013-05-06 17:50:50 +0000 | [diff] [blame] | 180 | void print(raw_ostream &O, unsigned IndentCount = 0) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 181 | void dump(); |
| 182 | #endif |
| 183 | }; |
| 184 | |
| 185 | //===--------------------------------------------------------------------===// |
| 186 | /// DIEValue - A debug information entry value. |
| 187 | /// |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 188 | class DIEValue { |
David Blaikie | 2d24e2a | 2011-12-20 02:50:00 +0000 | [diff] [blame] | 189 | virtual void anchor(); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 190 | public: |
| 191 | enum { |
| 192 | isInteger, |
| 193 | isString, |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 194 | isExpr, |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 195 | isLabel, |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 196 | isDelta, |
| 197 | isEntry, |
| 198 | isBlock |
| 199 | }; |
| 200 | protected: |
| 201 | /// Type - Type of data stored in the value. |
| 202 | /// |
| 203 | unsigned Type; |
| 204 | public: |
| 205 | explicit DIEValue(unsigned T) : Type(T) {} |
| 206 | virtual ~DIEValue() {} |
| 207 | |
| 208 | // Accessors |
| 209 | unsigned getType() const { return Type; } |
| 210 | |
| 211 | /// EmitValue - Emit value via the Dwarf writer. |
| 212 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 213 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 214 | |
| 215 | /// SizeOf - Return the size of a value in bytes. |
| 216 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 217 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 218 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 219 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 220 | virtual void print(raw_ostream &O) const = 0; |
| 221 | void dump() const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 222 | #endif |
| 223 | }; |
| 224 | |
| 225 | //===--------------------------------------------------------------------===// |
| 226 | /// DIEInteger - An integer value DIE. |
| 227 | /// |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 228 | class DIEInteger : public DIEValue { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 229 | uint64_t Integer; |
| 230 | public: |
| 231 | explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {} |
| 232 | |
| 233 | /// BestForm - Choose the best form for integer. |
| 234 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 235 | static dwarf::Form BestForm(bool IsSigned, uint64_t Int) { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 236 | if (IsSigned) { |
Hans Wennborg | a12c674 | 2013-03-18 17:03:05 +0000 | [diff] [blame] | 237 | const int64_t SignedInt = Int; |
| 238 | if ((char)Int == SignedInt) return dwarf::DW_FORM_data1; |
| 239 | if ((short)Int == SignedInt) return dwarf::DW_FORM_data2; |
| 240 | if ((int)Int == SignedInt) return dwarf::DW_FORM_data4; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 241 | } else { |
| 242 | if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1; |
| 243 | if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2; |
| 244 | if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4; |
| 245 | } |
| 246 | return dwarf::DW_FORM_data8; |
| 247 | } |
| 248 | |
| 249 | /// EmitValue - Emit integer of appropriate size. |
| 250 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 251 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 252 | |
Devang Patel | f2548ca | 2010-04-16 23:33:45 +0000 | [diff] [blame] | 253 | uint64_t getValue() const { return Integer; } |
| 254 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 255 | /// SizeOf - Determine size of integer value in bytes. |
| 256 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 257 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 258 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 259 | // Implement isa/cast/dyncast. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 260 | static bool classof(const DIEValue *I) { return I->getType() == isInteger; } |
| 261 | |
| 262 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 263 | virtual void print(raw_ostream &O) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 264 | #endif |
| 265 | }; |
| 266 | |
| 267 | //===--------------------------------------------------------------------===// |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 268 | /// DIEExpr - An expression DIE. |
| 269 | // |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 270 | class DIEExpr : public DIEValue { |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 271 | const MCExpr *Expr; |
| 272 | public: |
| 273 | explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {} |
| 274 | |
| 275 | /// EmitValue - Emit expression value. |
| 276 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 277 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 278 | |
| 279 | /// getValue - Get MCExpr. |
| 280 | /// |
| 281 | const MCExpr *getValue() const { return Expr; } |
| 282 | |
| 283 | /// SizeOf - Determine size of expression value in bytes. |
| 284 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 285 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 286 | |
| 287 | // Implement isa/cast/dyncast. |
| 288 | static bool classof(const DIEValue *E) { return E->getType() == isExpr; } |
| 289 | |
| 290 | #ifndef NDEBUG |
| 291 | virtual void print(raw_ostream &O) const; |
| 292 | #endif |
| 293 | }; |
| 294 | |
| 295 | //===--------------------------------------------------------------------===// |
| 296 | /// DIELabel - A label DIE. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 297 | // |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 298 | class DIELabel : public DIEValue { |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 299 | const MCSymbol *Label; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 300 | public: |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 301 | explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {} |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 302 | |
| 303 | /// EmitValue - Emit label value. |
| 304 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 305 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 306 | |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 307 | /// getValue - Get MCSymbol. |
| 308 | /// |
Ulrich Weigand | 1f8aacd | 2013-07-02 18:46:26 +0000 | [diff] [blame] | 309 | const MCSymbol *getValue() const { return Label; } |
Devang Patel | c3f5f78 | 2010-05-25 23:40:22 +0000 | [diff] [blame] | 310 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 311 | /// SizeOf - Determine size of label value in bytes. |
| 312 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 313 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 314 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 315 | // Implement isa/cast/dyncast. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 316 | static bool classof(const DIEValue *L) { return L->getType() == isLabel; } |
| 317 | |
| 318 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 319 | virtual void print(raw_ostream &O) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 320 | #endif |
| 321 | }; |
| 322 | |
| 323 | //===--------------------------------------------------------------------===// |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 324 | /// DIEDelta - A simple label difference DIE. |
| 325 | /// |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 326 | class DIEDelta : public DIEValue { |
Chris Lattner | b98b1bf | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 327 | const MCSymbol *LabelHi; |
| 328 | const MCSymbol *LabelLo; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 329 | public: |
Chris Lattner | b98b1bf | 2010-03-08 22:23:36 +0000 | [diff] [blame] | 330 | DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo) |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 331 | : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {} |
| 332 | |
| 333 | /// EmitValue - Emit delta value. |
| 334 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 335 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 336 | |
| 337 | /// SizeOf - Determine size of delta value in bytes. |
| 338 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 339 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 340 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 341 | // Implement isa/cast/dyncast. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 342 | static bool classof(const DIEValue *D) { return D->getType() == isDelta; } |
| 343 | |
| 344 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 345 | virtual void print(raw_ostream &O) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 346 | #endif |
| 347 | }; |
| 348 | |
| 349 | //===--------------------------------------------------------------------===// |
Eric Christopher | 3dee575 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 350 | /// DIEString - A container for string values. |
| 351 | /// |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 352 | class DIEString : public DIEValue { |
Eric Christopher | 3dee575 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 353 | const DIEValue *Access; |
| 354 | const StringRef Str; |
| 355 | |
| 356 | public: |
| 357 | DIEString(const DIEValue *Acc, const StringRef S) |
| 358 | : DIEValue(isString), Access(Acc), Str(S) {} |
| 359 | |
| 360 | /// getString - Grab the string out of the object. |
| 361 | StringRef getString() const { return Str; } |
| 362 | |
| 363 | /// EmitValue - Emit delta value. |
| 364 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 365 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Eric Christopher | 3dee575 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 366 | |
| 367 | /// SizeOf - Determine size of delta value in bytes. |
| 368 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 369 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Eric Christopher | 3dee575 | 2013-07-26 17:02:41 +0000 | [diff] [blame] | 370 | |
| 371 | // Implement isa/cast/dyncast. |
| 372 | static bool classof(const DIEValue *D) { return D->getType() == isString; } |
| 373 | |
| 374 | #ifndef NDEBUG |
| 375 | virtual void print(raw_ostream &O) const; |
| 376 | #endif |
| 377 | }; |
| 378 | |
| 379 | //===--------------------------------------------------------------------===// |
Nick Lewycky | 024170f | 2011-10-18 22:39:43 +0000 | [diff] [blame] | 380 | /// DIEEntry - A pointer to another debug information entry. An instance of |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 381 | /// this class can also be used as a proxy for a debug information entry not |
| 382 | /// yet defined (ie. types.) |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 383 | class DIEEntry : public DIEValue { |
Jeffrey Yasskin | 5c213dc | 2010-03-12 17:45:06 +0000 | [diff] [blame] | 384 | DIE *const Entry; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 385 | public: |
David Blaikie | 17a692e | 2013-05-14 00:35:19 +0000 | [diff] [blame] | 386 | explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) { |
| 387 | assert(E && "Cannot construct a DIEEntry with a null DIE"); |
| 388 | } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 389 | |
| 390 | DIE *getEntry() const { return Entry; } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 391 | |
| 392 | /// EmitValue - Emit debug information entry offset. |
| 393 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 394 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 395 | |
| 396 | /// SizeOf - Determine size of debug information entry in bytes. |
| 397 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 398 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const { |
Eric Christopher | 3166762 | 2013-08-08 01:41:00 +0000 | [diff] [blame] | 399 | return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP) |
| 400 | : sizeof(int32_t); |
Manman Ren | 624a93e | 2013-04-04 23:13:11 +0000 | [diff] [blame] | 401 | } |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 402 | |
Manman Ren | 0e6783f | 2013-07-02 23:40:10 +0000 | [diff] [blame] | 403 | /// Returns size of a ref_addr entry. |
| 404 | static unsigned getRefAddrSize(AsmPrinter *AP); |
| 405 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 406 | // Implement isa/cast/dyncast. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 407 | static bool classof(const DIEValue *E) { return E->getType() == isEntry; } |
| 408 | |
| 409 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 410 | virtual void print(raw_ostream &O) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 411 | #endif |
| 412 | }; |
| 413 | |
| 414 | //===--------------------------------------------------------------------===// |
| 415 | /// DIEBlock - A block of values. Primarily used for location expressions. |
| 416 | // |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 417 | class DIEBlock : public DIEValue, public DIE { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 418 | unsigned Size; // Size in bytes excluding size header. |
| 419 | public: |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 420 | DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {} |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 421 | |
| 422 | /// ComputeSize - calculate the size of the block. |
| 423 | /// |
Chris Lattner | a37d538 | 2010-04-05 00:18:22 +0000 | [diff] [blame] | 424 | unsigned ComputeSize(AsmPrinter *AP); |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 425 | |
| 426 | /// BestForm - Choose the best form for data. |
| 427 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 428 | dwarf::Form BestForm() const { |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 429 | if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1; |
| 430 | if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2; |
| 431 | if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4; |
| 432 | return dwarf::DW_FORM_block; |
| 433 | } |
| 434 | |
| 435 | /// EmitValue - Emit block data. |
| 436 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 437 | virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 438 | |
| 439 | /// SizeOf - Determine size of block data in bytes. |
| 440 | /// |
David Blaikie | 770530b | 2013-10-21 17:28:37 +0000 | [diff] [blame] | 441 | virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 442 | |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 443 | // Implement isa/cast/dyncast. |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 444 | static bool classof(const DIEValue *E) { return E->getType() == isBlock; } |
| 445 | |
| 446 | #ifndef NDEBUG |
Eric Christopher | 813419e | 2013-05-31 22:50:40 +0000 | [diff] [blame] | 447 | virtual void print(raw_ostream &O) const; |
Bill Wendling | 88423ee | 2009-05-15 00:11:17 +0000 | [diff] [blame] | 448 | #endif |
| 449 | }; |
| 450 | |
| 451 | } // end llvm namespace |
| 452 | |
| 453 | #endif |