blob: 35b76b52c1f217a4ef5b8a6a4c5ff4cde9217c1d [file] [log] [blame]
Bill Wendling88423ee2009-05-15 00:11:17 +00001//===--- 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 Christopherff348452013-01-07 22:40:45 +000011//
Bill Wendling88423ee2009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
Bill Wendling0310d762009-05-15 09:23:25 +000014#ifndef CODEGEN_ASMPRINTER_DIE_H__
15#define CODEGEN_ASMPRINTER_DIE_H__
Bill Wendling88423ee2009-05-15 00:11:17 +000016
Bill Wendling88423ee2009-05-15 00:11:17 +000017#include "llvm/ADT/FoldingSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/Support/Compiler.h"
20#include "llvm/Support/Dwarf.h"
David Blaikie95e72c92013-06-28 20:05:04 +000021#include "llvm/MC/MCExpr.h"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000022#include <vector>
Bill Wendling88423ee2009-05-15 00:11:17 +000023
24namespace llvm {
25 class AsmPrinter;
Chris Lattner858431d2010-01-16 18:50:28 +000026 class MCSymbol;
David Blaikie95e72c92013-06-28 20:05:04 +000027 class MCSymbolRefExpr;
Chris Lattnerb98b1bf2010-03-08 22:23:36 +000028 class raw_ostream;
Bill Wendling88423ee2009-05-15 00:11:17 +000029
30 //===--------------------------------------------------------------------===//
Eric Christopher0fbaa372013-06-10 22:24:07 +000031 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
Bill Wendling88423ee2009-05-15 00:11:17 +000032 /// Dwarf abbreviation.
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000033 class DIEAbbrevData {
Bill Wendling88423ee2009-05-15 00:11:17 +000034 /// Attribute - Dwarf attribute code.
35 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000036 uint16_t Attribute;
Bill Wendling88423ee2009-05-15 00:11:17 +000037
38 /// Form - Dwarf form code.
39 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000040 uint16_t Form;
Bill Wendling88423ee2009-05-15 00:11:17 +000041 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000042 DIEAbbrevData(uint16_t A, uint16_t F) : Attribute(A), Form(F) {}
Bill Wendling88423ee2009-05-15 00:11:17 +000043
44 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000045 uint16_t getAttribute() const { return Attribute; }
46 uint16_t getForm() const { return Form; }
Bill Wendling88423ee2009-05-15 00:11:17 +000047
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 Kramer55c06ae2013-09-11 18:05:11 +000056 class DIEAbbrev : public FoldingSetNode {
Bill Wendling88423ee2009-05-15 00:11:17 +000057 /// Tag - Dwarf tag code.
58 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000059 uint16_t Tag;
60
61 /// ChildrenFlag - Dwarf children flag.
62 ///
63 uint16_t ChildrenFlag;
Bill Wendling88423ee2009-05-15 00:11:17 +000064
65 /// Unique number for node.
66 ///
67 unsigned Number;
68
Bill Wendling88423ee2009-05-15 00:11:17 +000069 /// Data - Raw data bytes for abbreviation.
70 ///
Eric Christopher2df938a2013-03-29 20:23:06 +000071 SmallVector<DIEAbbrevData, 12> Data;
Devang Patel6404e4e2009-12-15 19:16:48 +000072
Bill Wendling88423ee2009-05-15 00:11:17 +000073 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000074 DIEAbbrev(uint16_t T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
Bill Wendling88423ee2009-05-15 00:11:17 +000075
76 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000077 uint16_t getTag() const { return Tag; }
Bill Wendling88423ee2009-05-15 00:11:17 +000078 unsigned getNumber() const { return Number; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000079 uint16_t getChildrenFlag() const { return ChildrenFlag; }
Eric Christopherf7cef702013-03-29 23:34:06 +000080 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000081 void setTag(uint16_t T) { Tag = T; }
82 void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; }
Bill Wendling88423ee2009-05-15 00:11:17 +000083 void setNumber(unsigned N) { Number = N; }
84
85 /// AddAttribute - Adds another set of attribute information to the
86 /// abbreviation.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000087 void AddAttribute(uint16_t Attribute, uint16_t Form) {
Bill Wendling88423ee2009-05-15 00:11:17 +000088 Data.push_back(DIEAbbrevData(Attribute, Form));
89 }
90
Bill Wendling88423ee2009-05-15 00:11:17 +000091 /// Profile - Used to gather unique data for the abbreviation folding set.
92 ///
93 void Profile(FoldingSetNodeID &ID) const;
94
95 /// Emit - Print the abbreviation using the specified asm printer.
96 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +000097 void Emit(AsmPrinter *AP) const;
Bill Wendling88423ee2009-05-15 00:11:17 +000098
99#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +0000100 void print(raw_ostream &O);
Bill Wendling88423ee2009-05-15 00:11:17 +0000101 void dump();
102#endif
103 };
104
105 //===--------------------------------------------------------------------===//
106 /// DIE - A structured debug information entry. Has an abbreviation which
Eric Christopher0c5cdc52013-04-03 05:29:58 +0000107 /// describes its organization.
Bill Wendling88423ee2009-05-15 00:11:17 +0000108 class DIEValue;
109
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000110 class DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000111 protected:
Bill Wendling88423ee2009-05-15 00:11:17 +0000112 /// Offset - Offset in debug info section.
113 ///
114 unsigned Offset;
115
116 /// Size - Size of instance + children.
117 ///
118 unsigned Size;
119
Benjamin Kramere697b4f2012-01-24 12:08:28 +0000120 /// Abbrev - Buffer for constructing abbreviation.
121 ///
122 DIEAbbrev Abbrev;
123
Bill Wendling88423ee2009-05-15 00:11:17 +0000124 /// Children DIEs.
125 ///
126 std::vector<DIE *> Children;
127
Devang Patel6404e4e2009-12-15 19:16:48 +0000128 DIE *Parent;
129
Bill Wendling034b94b2012-12-19 07:18:57 +0000130 /// Attribute values.
Bill Wendling88423ee2009-05-15 00:11:17 +0000131 ///
Eric Christopher2df938a2013-03-29 20:23:06 +0000132 SmallVector<DIEValue*, 12> Values;
Bill Wendling88423ee2009-05-15 00:11:17 +0000133
Eric Christopherd32d7a52013-06-10 20:58:53 +0000134#ifndef NDEBUG
Owen Andersond5509f22009-06-24 23:13:56 +0000135 // Private data for print()
136 mutable unsigned IndentCount;
Eric Christopherd32d7a52013-06-10 20:58:53 +0000137#endif
Bill Wendling88423ee2009-05-15 00:11:17 +0000138 public:
139 explicit DIE(unsigned Tag)
Eric Christopher30cb8362013-05-06 17:50:50 +0000140 : Offset(0), Size(0), Abbrev(Tag, dwarf::DW_CHILDREN_no), Parent(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000141 virtual ~DIE();
142
143 // Accessors.
144 DIEAbbrev &getAbbrev() { return Abbrev; }
145 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
Eric Christopher31667622013-08-08 01:41:00 +0000146 uint16_t getTag() const { return Abbrev.getTag(); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000147 unsigned getOffset() const { return Offset; }
148 unsigned getSize() const { return Size; }
149 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopherf7cef702013-03-29 23:34:06 +0000150 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel6404e4e2009-12-15 19:16:48 +0000151 DIE *getParent() const { return Parent; }
Manman Renbc3e96f2013-03-12 18:27:15 +0000152 /// Climb up the parent chain to get the compile unit DIE this DIE belongs
153 /// to.
Eric Christopher4d7f2ce2013-05-14 21:33:10 +0000154 DIE *getCompileUnit();
Manman Ren620f4362013-10-01 19:52:23 +0000155 /// Similar to getCompileUnit, returns null when DIE is not added to an
156 /// owner yet.
157 DIE *checkCompileUnit();
Eric Christopher31667622013-08-08 01:41:00 +0000158 void setTag(uint16_t Tag) { Abbrev.setTag(Tag); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000159 void setOffset(unsigned O) { Offset = O; }
160 void setSize(unsigned S) { Size = S; }
Eric Christopherff348452013-01-07 22:40:45 +0000161
Devang Patel2c4ceb12009-11-21 02:48:08 +0000162 /// addValue - Add a value and attributes to a DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000163 ///
Eric Christopher31667622013-08-08 01:41:00 +0000164 void addValue(uint16_t Attribute, uint16_t Form, DIEValue *Value) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000165 Abbrev.AddAttribute(Attribute, Form);
166 Values.push_back(Value);
167 }
168
Devang Patel2c4ceb12009-11-21 02:48:08 +0000169 /// addChild - Add a child to the DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000170 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000171 void addChild(DIE *Child) {
Devang Patel6404e4e2009-12-15 19:16:48 +0000172 if (Child->getParent()) {
173 assert (Child->getParent() == this && "Unexpected DIE Parent!");
174 return;
175 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000176 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
177 Children.push_back(Child);
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000178 Child->Parent = this;
Bill Wendling88423ee2009-05-15 00:11:17 +0000179 }
180
Eric Christopherb7669132013-08-07 01:18:33 +0000181 /// findAttribute - Find a value in the DIE with the attribute given, returns NULL
182 /// if no such attribute exists.
Eric Christopher31667622013-08-08 01:41:00 +0000183 DIEValue *findAttribute(uint16_t Attribute);
Eric Christopherb7669132013-08-07 01:18:33 +0000184
Bill Wendling88423ee2009-05-15 00:11:17 +0000185#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000186 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000187 void dump();
188#endif
189 };
190
191 //===--------------------------------------------------------------------===//
192 /// DIEValue - A debug information entry value.
193 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000194 class DIEValue {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000195 virtual void anchor();
Bill Wendling88423ee2009-05-15 00:11:17 +0000196 public:
197 enum {
198 isInteger,
199 isString,
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000200 isExpr,
Bill Wendling88423ee2009-05-15 00:11:17 +0000201 isLabel,
Bill Wendling88423ee2009-05-15 00:11:17 +0000202 isDelta,
203 isEntry,
204 isBlock
205 };
206 protected:
207 /// Type - Type of data stored in the value.
208 ///
209 unsigned Type;
210 public:
211 explicit DIEValue(unsigned T) : Type(T) {}
212 virtual ~DIEValue() {}
213
214 // Accessors
215 unsigned getType() const { return Type; }
216
217 /// EmitValue - Emit value via the Dwarf writer.
218 ///
Eric Christopher31667622013-08-08 01:41:00 +0000219 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000220
221 /// SizeOf - Return the size of a value in bytes.
222 ///
Eric Christopher31667622013-08-08 01:41:00 +0000223 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000224
Bill Wendling88423ee2009-05-15 00:11:17 +0000225#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000226 virtual void print(raw_ostream &O) const = 0;
227 void dump() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000228#endif
229 };
230
231 //===--------------------------------------------------------------------===//
232 /// DIEInteger - An integer value DIE.
233 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000234 class DIEInteger : public DIEValue {
Bill Wendling88423ee2009-05-15 00:11:17 +0000235 uint64_t Integer;
236 public:
237 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
238
239 /// BestForm - Choose the best form for integer.
240 ///
Eric Christopher31667622013-08-08 01:41:00 +0000241 static uint16_t BestForm(bool IsSigned, uint64_t Int) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000242 if (IsSigned) {
Hans Wennborga12c6742013-03-18 17:03:05 +0000243 const int64_t SignedInt = Int;
244 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1;
245 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2;
246 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4;
Bill Wendling88423ee2009-05-15 00:11:17 +0000247 } else {
248 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
249 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
250 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
251 }
252 return dwarf::DW_FORM_data8;
253 }
254
255 /// EmitValue - Emit integer of appropriate size.
256 ///
Eric Christopher31667622013-08-08 01:41:00 +0000257 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000258
Devang Patelf2548ca2010-04-16 23:33:45 +0000259 uint64_t getValue() const { return Integer; }
260
Bill Wendling88423ee2009-05-15 00:11:17 +0000261 /// SizeOf - Determine size of integer value in bytes.
262 ///
Eric Christopher31667622013-08-08 01:41:00 +0000263 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000264
Bill Wendling88423ee2009-05-15 00:11:17 +0000265 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000266 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
267
268#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000269 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000270#endif
271 };
272
273 //===--------------------------------------------------------------------===//
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000274 /// DIEExpr - An expression DIE.
275 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000276 class DIEExpr : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000277 const MCExpr *Expr;
278 public:
279 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
280
281 /// EmitValue - Emit expression value.
282 ///
Eric Christopher31667622013-08-08 01:41:00 +0000283 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000284
285 /// getValue - Get MCExpr.
286 ///
287 const MCExpr *getValue() const { return Expr; }
288
289 /// SizeOf - Determine size of expression value in bytes.
290 ///
Eric Christopher31667622013-08-08 01:41:00 +0000291 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000292
293 // Implement isa/cast/dyncast.
294 static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
295
296#ifndef NDEBUG
297 virtual void print(raw_ostream &O) const;
298#endif
299 };
300
301 //===--------------------------------------------------------------------===//
302 /// DIELabel - A label DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000303 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000304 class DIELabel : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000305 const MCSymbol *Label;
Bill Wendling88423ee2009-05-15 00:11:17 +0000306 public:
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000307 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000308
309 /// EmitValue - Emit label value.
310 ///
Eric Christopher31667622013-08-08 01:41:00 +0000311 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000312
Devang Patelc3f5f782010-05-25 23:40:22 +0000313 /// getValue - Get MCSymbol.
314 ///
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000315 const MCSymbol *getValue() const { return Label; }
Devang Patelc3f5f782010-05-25 23:40:22 +0000316
Bill Wendling88423ee2009-05-15 00:11:17 +0000317 /// SizeOf - Determine size of label value in bytes.
318 ///
Eric Christopher31667622013-08-08 01:41:00 +0000319 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000320
Bill Wendling88423ee2009-05-15 00:11:17 +0000321 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000322 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
323
324#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000325 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000326#endif
327 };
328
329 //===--------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000330 /// DIEDelta - A simple label difference DIE.
331 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000332 class DIEDelta : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000333 const MCSymbol *LabelHi;
334 const MCSymbol *LabelLo;
Bill Wendling88423ee2009-05-15 00:11:17 +0000335 public:
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000336 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling88423ee2009-05-15 00:11:17 +0000337 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
338
339 /// EmitValue - Emit delta value.
340 ///
Eric Christopher31667622013-08-08 01:41:00 +0000341 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000342
343 /// SizeOf - Determine size of delta value in bytes.
344 ///
Eric Christopher31667622013-08-08 01:41:00 +0000345 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000346
Bill Wendling88423ee2009-05-15 00:11:17 +0000347 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000348 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
349
350#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000351 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000352#endif
353 };
354
355 //===--------------------------------------------------------------------===//
Eric Christopher3dee5752013-07-26 17:02:41 +0000356 /// DIEString - A container for string values.
357 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000358 class DIEString : public DIEValue {
Eric Christopher3dee5752013-07-26 17:02:41 +0000359 const DIEValue *Access;
360 const StringRef Str;
361
362 public:
363 DIEString(const DIEValue *Acc, const StringRef S)
364 : DIEValue(isString), Access(Acc), Str(S) {}
365
366 /// getString - Grab the string out of the object.
367 StringRef getString() const { return Str; }
368
369 /// EmitValue - Emit delta value.
370 ///
Eric Christopher31667622013-08-08 01:41:00 +0000371 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000372
373 /// SizeOf - Determine size of delta value in bytes.
374 ///
Eric Christopher31667622013-08-08 01:41:00 +0000375 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000376
377 // Implement isa/cast/dyncast.
378 static bool classof(const DIEValue *D) { return D->getType() == isString; }
379
380 #ifndef NDEBUG
381 virtual void print(raw_ostream &O) const;
382 #endif
383 };
384
385 //===--------------------------------------------------------------------===//
Nick Lewycky024170f2011-10-18 22:39:43 +0000386 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling88423ee2009-05-15 00:11:17 +0000387 /// this class can also be used as a proxy for a debug information entry not
388 /// yet defined (ie. types.)
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000389 class DIEEntry : public DIEValue {
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000390 DIE *const Entry;
Bill Wendling88423ee2009-05-15 00:11:17 +0000391 public:
David Blaikie17a692e2013-05-14 00:35:19 +0000392 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
393 assert(E && "Cannot construct a DIEEntry with a null DIE");
394 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000395
396 DIE *getEntry() const { return Entry; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000397
398 /// EmitValue - Emit debug information entry offset.
399 ///
Eric Christopher31667622013-08-08 01:41:00 +0000400 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000401
402 /// SizeOf - Determine size of debug information entry in bytes.
403 ///
Eric Christopher31667622013-08-08 01:41:00 +0000404 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const {
405 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
406 : sizeof(int32_t);
Manman Ren624a93e2013-04-04 23:13:11 +0000407 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000408
Manman Ren0e6783f2013-07-02 23:40:10 +0000409 /// Returns size of a ref_addr entry.
410 static unsigned getRefAddrSize(AsmPrinter *AP);
411
Bill Wendling88423ee2009-05-15 00:11:17 +0000412 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000413 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
414
415#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000416 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000417#endif
418 };
419
420 //===--------------------------------------------------------------------===//
421 /// DIEBlock - A block of values. Primarily used for location expressions.
422 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000423 class DIEBlock : public DIEValue, public DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000424 unsigned Size; // Size in bytes excluding size header.
425 public:
426 DIEBlock()
427 : DIEValue(isBlock), DIE(0), Size(0) {}
428 virtual ~DIEBlock() {}
429
430 /// ComputeSize - calculate the size of the block.
431 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000432 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling88423ee2009-05-15 00:11:17 +0000433
434 /// BestForm - Choose the best form for data.
435 ///
Eric Christopher31667622013-08-08 01:41:00 +0000436 uint16_t BestForm() const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000437 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
438 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
439 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
440 return dwarf::DW_FORM_block;
441 }
442
443 /// EmitValue - Emit block data.
444 ///
Eric Christopher31667622013-08-08 01:41:00 +0000445 virtual void EmitValue(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000446
447 /// SizeOf - Determine size of block data in bytes.
448 ///
Eric Christopher31667622013-08-08 01:41:00 +0000449 virtual unsigned SizeOf(AsmPrinter *AP, uint16_t Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000450
Bill Wendling88423ee2009-05-15 00:11:17 +0000451 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000452 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
453
454#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000455 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000456#endif
457 };
458
459} // end llvm namespace
460
461#endif