blob: 51773ad9fe030db89fe9b66dd52c00cb3ca05062 [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; }
141 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
David Blaikie770530b2013-10-21 17:28:37 +0000142 dwarf::Tag getTag() const { return Abbrev.getTag(); }
Bill Wendling88423ee2009-05-15 00:11:17 +0000143 unsigned getOffset() const { return Offset; }
144 unsigned getSize() const { return Size; }
145 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopherf7cef702013-03-29 23:34:06 +0000146 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel6404e4e2009-12-15 19:16:48 +0000147 DIE *getParent() const { return Parent; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000148 void setOffset(unsigned O) { Offset = O; }
149 void setSize(unsigned S) { Size = S; }
Eric Christopherff348452013-01-07 22:40:45 +0000150
Devang Patel2c4ceb12009-11-21 02:48:08 +0000151 /// addValue - Add a value and attributes to a DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000152 ///
David Blaikie770530b2013-10-21 17:28:37 +0000153 void addValue(dwarf::Attribute Attribute, dwarf::Form Form,
154 DIEValue *Value) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000155 Abbrev.AddAttribute(Attribute, Form);
156 Values.push_back(Value);
157 }
158
Devang Patel2c4ceb12009-11-21 02:48:08 +0000159 /// addChild - Add a child to the DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000160 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000161 void addChild(DIE *Child) {
David Blaikiee5830c42013-10-03 20:07:20 +0000162 assert(!Child->getParent());
Bill Wendling88423ee2009-05-15 00:11:17 +0000163 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
164 Children.push_back(Child);
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000165 Child->Parent = this;
Bill Wendling88423ee2009-05-15 00:11:17 +0000166 }
167
Eric Christopherb7669132013-08-07 01:18:33 +0000168 /// findAttribute - Find a value in the DIE with the attribute given, returns NULL
169 /// if no such attribute exists.
Eric Christopher31667622013-08-08 01:41:00 +0000170 DIEValue *findAttribute(uint16_t Attribute);
Eric Christopherb7669132013-08-07 01:18:33 +0000171
Bill Wendling88423ee2009-05-15 00:11:17 +0000172#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000173 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000174 void dump();
175#endif
176 };
177
178 //===--------------------------------------------------------------------===//
179 /// DIEValue - A debug information entry value.
180 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000181 class DIEValue {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000182 virtual void anchor();
Bill Wendling88423ee2009-05-15 00:11:17 +0000183 public:
184 enum {
185 isInteger,
186 isString,
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000187 isExpr,
Bill Wendling88423ee2009-05-15 00:11:17 +0000188 isLabel,
Bill Wendling88423ee2009-05-15 00:11:17 +0000189 isDelta,
190 isEntry,
191 isBlock
192 };
193 protected:
194 /// Type - Type of data stored in the value.
195 ///
196 unsigned Type;
197 public:
198 explicit DIEValue(unsigned T) : Type(T) {}
199 virtual ~DIEValue() {}
200
201 // Accessors
202 unsigned getType() const { return Type; }
203
204 /// EmitValue - Emit value via the Dwarf writer.
205 ///
David Blaikie770530b2013-10-21 17:28:37 +0000206 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000207
208 /// SizeOf - Return the size of a value in bytes.
209 ///
David Blaikie770530b2013-10-21 17:28:37 +0000210 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000211
Bill Wendling88423ee2009-05-15 00:11:17 +0000212#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000213 virtual void print(raw_ostream &O) const = 0;
214 void dump() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000215#endif
216 };
217
218 //===--------------------------------------------------------------------===//
219 /// DIEInteger - An integer value DIE.
220 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000221 class DIEInteger : public DIEValue {
Bill Wendling88423ee2009-05-15 00:11:17 +0000222 uint64_t Integer;
223 public:
224 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
225
226 /// BestForm - Choose the best form for integer.
227 ///
David Blaikie770530b2013-10-21 17:28:37 +0000228 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000229 if (IsSigned) {
Hans Wennborga12c6742013-03-18 17:03:05 +0000230 const int64_t SignedInt = Int;
231 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1;
232 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2;
233 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4;
Bill Wendling88423ee2009-05-15 00:11:17 +0000234 } else {
235 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
236 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
237 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
238 }
239 return dwarf::DW_FORM_data8;
240 }
241
242 /// EmitValue - Emit integer of appropriate size.
243 ///
David Blaikie770530b2013-10-21 17:28:37 +0000244 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000245
Devang Patelf2548ca2010-04-16 23:33:45 +0000246 uint64_t getValue() const { return Integer; }
247
Bill Wendling88423ee2009-05-15 00:11:17 +0000248 /// SizeOf - Determine size of integer value in bytes.
249 ///
David Blaikie770530b2013-10-21 17:28:37 +0000250 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000251
Bill Wendling88423ee2009-05-15 00:11:17 +0000252 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000253 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
254
255#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000256 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000257#endif
258 };
259
260 //===--------------------------------------------------------------------===//
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000261 /// DIEExpr - An expression DIE.
262 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000263 class DIEExpr : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000264 const MCExpr *Expr;
265 public:
266 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
267
268 /// EmitValue - Emit expression value.
269 ///
David Blaikie770530b2013-10-21 17:28:37 +0000270 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000271
272 /// getValue - Get MCExpr.
273 ///
274 const MCExpr *getValue() const { return Expr; }
275
276 /// SizeOf - Determine size of expression value in bytes.
277 ///
David Blaikie770530b2013-10-21 17:28:37 +0000278 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000279
280 // Implement isa/cast/dyncast.
281 static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
282
283#ifndef NDEBUG
284 virtual void print(raw_ostream &O) const;
285#endif
286 };
287
288 //===--------------------------------------------------------------------===//
289 /// DIELabel - A label DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000290 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000291 class DIELabel : public DIEValue {
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000292 const MCSymbol *Label;
Bill Wendling88423ee2009-05-15 00:11:17 +0000293 public:
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000294 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000295
296 /// EmitValue - Emit label value.
297 ///
David Blaikie770530b2013-10-21 17:28:37 +0000298 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000299
Devang Patelc3f5f782010-05-25 23:40:22 +0000300 /// getValue - Get MCSymbol.
301 ///
Ulrich Weigand1f8aacd2013-07-02 18:46:26 +0000302 const MCSymbol *getValue() const { return Label; }
Devang Patelc3f5f782010-05-25 23:40:22 +0000303
Bill Wendling88423ee2009-05-15 00:11:17 +0000304 /// SizeOf - Determine size of label value in bytes.
305 ///
David Blaikie770530b2013-10-21 17:28:37 +0000306 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000307
Bill Wendling88423ee2009-05-15 00:11:17 +0000308 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000309 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
310
311#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000312 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000313#endif
314 };
315
316 //===--------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000317 /// DIEDelta - A simple label difference DIE.
318 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000319 class DIEDelta : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000320 const MCSymbol *LabelHi;
321 const MCSymbol *LabelLo;
Bill Wendling88423ee2009-05-15 00:11:17 +0000322 public:
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000323 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling88423ee2009-05-15 00:11:17 +0000324 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
325
326 /// EmitValue - Emit delta value.
327 ///
David Blaikie770530b2013-10-21 17:28:37 +0000328 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000329
330 /// SizeOf - Determine size of delta value in bytes.
331 ///
David Blaikie770530b2013-10-21 17:28:37 +0000332 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000333
Bill Wendling88423ee2009-05-15 00:11:17 +0000334 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000335 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
336
337#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000338 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000339#endif
340 };
341
342 //===--------------------------------------------------------------------===//
Eric Christopher3dee5752013-07-26 17:02:41 +0000343 /// DIEString - A container for string values.
344 ///
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000345 class DIEString : public DIEValue {
Eric Christopher3dee5752013-07-26 17:02:41 +0000346 const DIEValue *Access;
347 const StringRef Str;
348
349 public:
350 DIEString(const DIEValue *Acc, const StringRef S)
351 : DIEValue(isString), Access(Acc), Str(S) {}
352
353 /// getString - Grab the string out of the object.
354 StringRef getString() const { return Str; }
355
356 /// EmitValue - Emit delta value.
357 ///
David Blaikie770530b2013-10-21 17:28:37 +0000358 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000359
360 /// SizeOf - Determine size of delta value in bytes.
361 ///
David Blaikie770530b2013-10-21 17:28:37 +0000362 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher3dee5752013-07-26 17:02:41 +0000363
364 // Implement isa/cast/dyncast.
365 static bool classof(const DIEValue *D) { return D->getType() == isString; }
366
367 #ifndef NDEBUG
368 virtual void print(raw_ostream &O) const;
369 #endif
370 };
371
372 //===--------------------------------------------------------------------===//
Nick Lewycky024170f2011-10-18 22:39:43 +0000373 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling88423ee2009-05-15 00:11:17 +0000374 /// this class can also be used as a proxy for a debug information entry not
375 /// yet defined (ie. types.)
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000376 class DIEEntry : public DIEValue {
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000377 DIE *const Entry;
Bill Wendling88423ee2009-05-15 00:11:17 +0000378 public:
David Blaikie17a692e2013-05-14 00:35:19 +0000379 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
380 assert(E && "Cannot construct a DIEEntry with a null DIE");
381 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000382
383 DIE *getEntry() const { return Entry; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000384
385 /// EmitValue - Emit debug information entry offset.
386 ///
David Blaikie770530b2013-10-21 17:28:37 +0000387 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000388
389 /// SizeOf - Determine size of debug information entry in bytes.
390 ///
David Blaikie770530b2013-10-21 17:28:37 +0000391 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher31667622013-08-08 01:41:00 +0000392 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
393 : sizeof(int32_t);
Manman Ren624a93e2013-04-04 23:13:11 +0000394 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000395
Manman Ren0e6783f2013-07-02 23:40:10 +0000396 /// Returns size of a ref_addr entry.
397 static unsigned getRefAddrSize(AsmPrinter *AP);
398
Bill Wendling88423ee2009-05-15 00:11:17 +0000399 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000400 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
401
402#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000403 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000404#endif
405 };
406
407 //===--------------------------------------------------------------------===//
408 /// DIEBlock - A block of values. Primarily used for location expressions.
409 //
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000410 class DIEBlock : public DIEValue, public DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000411 unsigned Size; // Size in bytes excluding size header.
412 public:
David Blaikie770530b2013-10-21 17:28:37 +0000413 DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000414
415 /// ComputeSize - calculate the size of the block.
416 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000417 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling88423ee2009-05-15 00:11:17 +0000418
419 /// BestForm - Choose the best form for data.
420 ///
David Blaikie770530b2013-10-21 17:28:37 +0000421 dwarf::Form BestForm() const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000422 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
423 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
424 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
425 return dwarf::DW_FORM_block;
426 }
427
428 /// EmitValue - Emit block data.
429 ///
David Blaikie770530b2013-10-21 17:28:37 +0000430 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000431
432 /// SizeOf - Determine size of block data in bytes.
433 ///
David Blaikie770530b2013-10-21 17:28:37 +0000434 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000435
Bill Wendling88423ee2009-05-15 00:11:17 +0000436 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000437 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
438
439#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000440 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000441#endif
442 };
443
444} // end llvm namespace
445
446#endif