blob: f4fa326ef67a49968a58efe553b833b8a14d9c6a [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 ///
David Blaikie770530b2013-10-21 17:28:37 +000036 dwarf::Attribute Attribute;
Bill Wendling88423ee2009-05-15 00:11:17 +000037
38 /// Form - Dwarf form code.
39 ///
David Blaikie770530b2013-10-21 17:28:37 +000040 dwarf::Form Form;
Bill Wendling88423ee2009-05-15 00:11:17 +000041 public:
David Blaikie770530b2013-10-21 17:28:37 +000042 DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
Bill Wendling88423ee2009-05-15 00:11:17 +000043
44 // Accessors.
David Blaikie770530b2013-10-21 17:28:37 +000045 dwarf::Attribute getAttribute() const { return Attribute; }
46 dwarf::Form 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 ///
David Blaikie770530b2013-10-21 17:28:37 +000059 dwarf::Tag Tag;
Benjamin Kramere697b4f2012-01-24 12:08:28 +000060
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:
David Blaikie770530b2013-10-21 17:28:37 +000074 DIEAbbrev(dwarf::Tag T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
Bill Wendling88423ee2009-05-15 00:11:17 +000075
76 // Accessors.
David Blaikie770530b2013-10-21 17:28:37 +000077 dwarf::Tag 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 setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; }
Bill Wendling88423ee2009-05-15 00:11:17 +000082 void setNumber(unsigned N) { Number = N; }
83
84 /// AddAttribute - Adds another set of attribute information to the
85 /// abbreviation.
David Blaikie770530b2013-10-21 17:28:37 +000086 void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
Bill Wendling88423ee2009-05-15 00:11:17 +000087 Data.push_back(DIEAbbrevData(Attribute, Form));
88 }
89
Bill Wendling88423ee2009-05-15 00:11:17 +000090 /// 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 Lattnerd38fee82010-04-05 00:13:49 +000096 void Emit(AsmPrinter *AP) const;
Bill Wendling88423ee2009-05-15 00:11:17 +000097
98#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +000099 void print(raw_ostream &O);
Bill Wendling88423ee2009-05-15 00:11:17 +0000100 void dump();
101#endif
102 };
103
104 //===--------------------------------------------------------------------===//
105 /// DIE - A structured debug information entry. Has an abbreviation which
Eric Christopher0c5cdc52013-04-03 05:29:58 +0000106 /// describes its organization.
Bill Wendling88423ee2009-05-15 00:11:17 +0000107 class DIEValue;
108
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000109 class DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000110 protected:
Bill Wendling88423ee2009-05-15 00:11:17 +0000111 /// Offset - Offset in debug info section.
112 ///
113 unsigned Offset;
114
115 /// Size - Size of instance + children.
116 ///
117 unsigned Size;
118
Benjamin Kramere697b4f2012-01-24 12:08:28 +0000119 /// Abbrev - Buffer for constructing abbreviation.
120 ///
121 DIEAbbrev Abbrev;
122
Bill Wendling88423ee2009-05-15 00:11:17 +0000123 /// Children DIEs.
124 ///
125 std::vector<DIE *> Children;
126
Devang Patel6404e4e2009-12-15 19:16:48 +0000127 DIE *Parent;
128
Bill Wendling034b94b2012-12-19 07:18:57 +0000129 /// Attribute values.
Bill Wendling88423ee2009-05-15 00:11:17 +0000130 ///
Eric Christopher2df938a2013-03-29 20:23:06 +0000131 SmallVector<DIEValue*, 12> Values;
Bill Wendling88423ee2009-05-15 00:11:17 +0000132
Bill Wendling88423ee2009-05-15 00:11:17 +0000133 public:
134 explicit DIE(unsigned Tag)
David Blaikie770530b2013-10-21 17:28:37 +0000135 : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
136 Parent(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000137 virtual ~DIE();
138
139 // Accessors.
140 DIEAbbrev &getAbbrev() { return Abbrev; }
David Blaikie851aa942013-10-24 17:51:43 +0000141 const DIEAbbrev &getAbbrev() const { return Abbrev; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000142 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
David Blaikie770530b2013-10-21 17:28:37 +0000143 dwarf::Tag getTag() const { return Abbrev.getTag(); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000144 unsigned getOffset() const { return Offset; }
145 unsigned getSize() const { return Size; }
146 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopherf7cef702013-03-29 23:34:06 +0000147 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel6404e4e2009-12-15 19:16:48 +0000148 DIE *getParent() const { return Parent; }
Manman Ren3eabc2a2013-10-29 22:57:10 +0000149 /// Climb up the parent chain to get the compile unit DIE this DIE belongs
150 /// to.
151 const DIE *getCompileUnit() const;
Manman Renb8b70e12013-10-31 17:54:35 +0000152 /// Similar to getCompileUnit, returns null when DIE is not added to an
153 /// owner yet.
154 const DIE *getCompileUnitOrNull() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000155 void setOffset(unsigned O) { Offset = O; }
156 void setSize(unsigned S) { Size = S; }
Eric Christopherff348452013-01-07 22:40:45 +0000157
Devang Patel2c4ceb12009-11-21 02:48:08 +0000158 /// addValue - Add a value and attributes to a DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000159 ///
David Blaikie770530b2013-10-21 17:28:37 +0000160 void addValue(dwarf::Attribute Attribute, dwarf::Form Form,
161 DIEValue *Value) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000162 Abbrev.AddAttribute(Attribute, Form);
163 Values.push_back(Value);
164 }
165
Devang Patel2c4ceb12009-11-21 02:48:08 +0000166 /// addChild - Add a child to the DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000167 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000168 void addChild(DIE *Child) {
David Blaikiee5830c42013-10-03 20:07:20 +0000169 assert(!Child->getParent());
Bill Wendling88423ee2009-05-15 00:11:17 +0000170 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
171 Children.push_back(Child);
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000172 Child->Parent = this;
Bill Wendling88423ee2009-05-15 00:11:17 +0000173 }
174
Eric Christopherb7669132013-08-07 01:18:33 +0000175 /// findAttribute - Find a value in the DIE with the attribute given, returns NULL
176 /// if no such attribute exists.
Eric Christopher31667622013-08-08 01:41:00 +0000177 DIEValue *findAttribute(uint16_t Attribute);
Eric Christopherb7669132013-08-07 01:18:33 +0000178
Bill Wendling88423ee2009-05-15 00:11:17 +0000179#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000180 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000181 void dump();
182#endif
183 };
184
185 //===--------------------------------------------------------------------===//
186 /// DIEValue - A debug information entry value.
187 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000188 class DIEValue {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000189 virtual void anchor();
Bill Wendling88423ee2009-05-15 00:11:17 +0000190 public:
191 enum {
192 isInteger,
193 isString,
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000194 isExpr,
Bill Wendling88423ee2009-05-15 00:11:17 +0000195 isLabel,
Bill Wendling88423ee2009-05-15 00:11:17 +0000196 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 Blaikie770530b2013-10-21 17:28:37 +0000213 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000214
215 /// SizeOf - Return the size of a value in bytes.
216 ///
David Blaikie770530b2013-10-21 17:28:37 +0000217 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000218
Bill Wendling88423ee2009-05-15 00:11:17 +0000219#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000220 virtual void print(raw_ostream &O) const = 0;
221 void dump() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000222#endif
223 };
224
225 //===--------------------------------------------------------------------===//
226 /// DIEInteger - An integer value DIE.
227 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000228 class DIEInteger : public DIEValue {
Bill Wendling88423ee2009-05-15 00:11:17 +0000229 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 Blaikie770530b2013-10-21 17:28:37 +0000235 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000236 if (IsSigned) {
Hans Wennborga12c6742013-03-18 17:03:05 +0000237 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 Wendling88423ee2009-05-15 00:11:17 +0000241 } 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 Blaikie770530b2013-10-21 17:28:37 +0000251 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000252
Devang Patelf2548ca2010-04-16 23:33:45 +0000253 uint64_t getValue() const { return Integer; }
254
Bill Wendling88423ee2009-05-15 00:11:17 +0000255 /// SizeOf - Determine size of integer value in bytes.
256 ///
David Blaikie770530b2013-10-21 17:28:37 +0000257 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000258
Bill Wendling88423ee2009-05-15 00:11:17 +0000259 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000260 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
261
262#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000263 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000264#endif
265 };
266
267 //===--------------------------------------------------------------------===//
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000268 /// DIEExpr - An expression DIE.
269 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000270 class DIEExpr : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000271 const MCExpr *Expr;
272 public:
273 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
274
275 /// EmitValue - Emit expression value.
276 ///
David Blaikie770530b2013-10-21 17:28:37 +0000277 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000278
279 /// getValue - Get MCExpr.
280 ///
281 const MCExpr *getValue() const { return Expr; }
282
283 /// SizeOf - Determine size of expression value in bytes.
284 ///
David Blaikie770530b2013-10-21 17:28:37 +0000285 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000286
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 Wendling88423ee2009-05-15 00:11:17 +0000297 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000298 class DIELabel : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000299 const MCSymbol *Label;
Bill Wendling88423ee2009-05-15 00:11:17 +0000300 public:
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000301 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000302
303 /// EmitValue - Emit label value.
304 ///
David Blaikie770530b2013-10-21 17:28:37 +0000305 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000306
Devang Patelc3f5f782010-05-25 23:40:22 +0000307 /// getValue - Get MCSymbol.
308 ///
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000309 const MCSymbol *getValue() const { return Label; }
Devang Patelc3f5f782010-05-25 23:40:22 +0000310
Bill Wendling88423ee2009-05-15 00:11:17 +0000311 /// SizeOf - Determine size of label value in bytes.
312 ///
David Blaikie770530b2013-10-21 17:28:37 +0000313 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000314
Bill Wendling88423ee2009-05-15 00:11:17 +0000315 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000316 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
317
318#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000319 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000320#endif
321 };
322
323 //===--------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000324 /// DIEDelta - A simple label difference DIE.
325 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000326 class DIEDelta : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000327 const MCSymbol *LabelHi;
328 const MCSymbol *LabelLo;
Bill Wendling88423ee2009-05-15 00:11:17 +0000329 public:
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000330 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling88423ee2009-05-15 00:11:17 +0000331 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
332
333 /// EmitValue - Emit delta value.
334 ///
David Blaikie770530b2013-10-21 17:28:37 +0000335 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000336
337 /// SizeOf - Determine size of delta value in bytes.
338 ///
David Blaikie770530b2013-10-21 17:28:37 +0000339 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000340
Bill Wendling88423ee2009-05-15 00:11:17 +0000341 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000342 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
343
344#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000345 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000346#endif
347 };
348
349 //===--------------------------------------------------------------------===//
Eric Christopher3dee5752013-07-26 17:02:41 +0000350 /// DIEString - A container for string values.
351 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000352 class DIEString : public DIEValue {
Eric Christopher3dee5752013-07-26 17:02:41 +0000353 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 Blaikie770530b2013-10-21 17:28:37 +0000365 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000366
367 /// SizeOf - Determine size of delta value in bytes.
368 ///
David Blaikie770530b2013-10-21 17:28:37 +0000369 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000370
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 Lewycky024170f2011-10-18 22:39:43 +0000380 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling88423ee2009-05-15 00:11:17 +0000381 /// this class can also be used as a proxy for a debug information entry not
382 /// yet defined (ie. types.)
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000383 class DIEEntry : public DIEValue {
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000384 DIE *const Entry;
Bill Wendling88423ee2009-05-15 00:11:17 +0000385 public:
David Blaikie17a692e2013-05-14 00:35:19 +0000386 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
387 assert(E && "Cannot construct a DIEEntry with a null DIE");
388 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000389
390 DIE *getEntry() const { return Entry; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000391
392 /// EmitValue - Emit debug information entry offset.
393 ///
David Blaikie770530b2013-10-21 17:28:37 +0000394 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000395
396 /// SizeOf - Determine size of debug information entry in bytes.
397 ///
David Blaikie770530b2013-10-21 17:28:37 +0000398 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher31667622013-08-08 01:41:00 +0000399 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
400 : sizeof(int32_t);
Manman Ren624a93e2013-04-04 23:13:11 +0000401 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000402
Manman Ren0e6783f2013-07-02 23:40:10 +0000403 /// Returns size of a ref_addr entry.
404 static unsigned getRefAddrSize(AsmPrinter *AP);
405
Bill Wendling88423ee2009-05-15 00:11:17 +0000406 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000407 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
408
409#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000410 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000411#endif
412 };
413
414 //===--------------------------------------------------------------------===//
415 /// DIEBlock - A block of values. Primarily used for location expressions.
416 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000417 class DIEBlock : public DIEValue, public DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000418 unsigned Size; // Size in bytes excluding size header.
419 public:
David Blaikie770530b2013-10-21 17:28:37 +0000420 DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000421
422 /// ComputeSize - calculate the size of the block.
423 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000424 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling88423ee2009-05-15 00:11:17 +0000425
426 /// BestForm - Choose the best form for data.
427 ///
David Blaikie770530b2013-10-21 17:28:37 +0000428 dwarf::Form BestForm() const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000429 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 Blaikie770530b2013-10-21 17:28:37 +0000437 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000438
439 /// SizeOf - Determine size of block data in bytes.
440 ///
David Blaikie770530b2013-10-21 17:28:37 +0000441 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000442
Bill Wendling88423ee2009-05-15 00:11:17 +0000443 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000444 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
445
446#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000447 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000448#endif
449 };
450
451} // end llvm namespace
452
453#endif