blob: 40b496d3adb9fab75c8c88e8ea4d36dda6770397 [file] [log] [blame]
Bill Wendling47054f32009-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 Christopherb800ff72013-01-07 22:40:45 +000011//
Bill Wendling47054f32009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
Bill Wendling2f921f82009-05-15 09:23:25 +000014#ifndef CODEGEN_ASMPRINTER_DIE_H__
15#define CODEGEN_ASMPRINTER_DIE_H__
Bill Wendling47054f32009-05-15 00:11:17 +000016
Bill Wendling47054f32009-05-15 00:11:17 +000017#include "llvm/ADT/FoldingSet.h"
18#include "llvm/ADT/SmallVector.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000019#include "llvm/MC/MCExpr.h"
Bill Wendling47054f32009-05-15 00:11:17 +000020#include "llvm/Support/Compiler.h"
21#include "llvm/Support/Dwarf.h"
Chris Lattner74725712009-08-23 01:01:17 +000022#include <vector>
Bill Wendling47054f32009-05-15 00:11:17 +000023
24namespace llvm {
25 class AsmPrinter;
Chris Lattner06d45f62010-01-16 18:50:28 +000026 class MCSymbol;
David Blaikief3cd7c52013-06-28 20:05:04 +000027 class MCSymbolRefExpr;
Chris Lattnerbc9210c2010-03-08 22:23:36 +000028 class raw_ostream;
David Blaikie47f615e2013-12-17 23:32:35 +000029 class DwarfTypeUnit;
Bill Wendling47054f32009-05-15 00:11:17 +000030
31 //===--------------------------------------------------------------------===//
Eric Christopher2280c5b2013-06-10 22:24:07 +000032 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
Bill Wendling47054f32009-05-15 00:11:17 +000033 /// Dwarf abbreviation.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000034 class DIEAbbrevData {
Bill Wendling47054f32009-05-15 00:11:17 +000035 /// Attribute - Dwarf attribute code.
36 ///
David Blaikief2443192013-10-21 17:28:37 +000037 dwarf::Attribute Attribute;
Bill Wendling47054f32009-05-15 00:11:17 +000038
39 /// Form - Dwarf form code.
40 ///
David Blaikief2443192013-10-21 17:28:37 +000041 dwarf::Form Form;
Bill Wendling47054f32009-05-15 00:11:17 +000042 public:
David Blaikief2443192013-10-21 17:28:37 +000043 DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
Bill Wendling47054f32009-05-15 00:11:17 +000044
45 // Accessors.
David Blaikief2443192013-10-21 17:28:37 +000046 dwarf::Attribute getAttribute() const { return Attribute; }
47 dwarf::Form getForm() const { return Form; }
Bill Wendling47054f32009-05-15 00:11:17 +000048
49 /// Profile - Used to gather unique data for the abbreviation folding set.
50 ///
51 void Profile(FoldingSetNodeID &ID) const;
52 };
53
54 //===--------------------------------------------------------------------===//
55 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
56 /// information object.
Benjamin Kramer079b96e2013-09-11 18:05:11 +000057 class DIEAbbrev : public FoldingSetNode {
Bill Wendling47054f32009-05-15 00:11:17 +000058 /// Tag - Dwarf tag code.
59 ///
David Blaikief2443192013-10-21 17:28:37 +000060 dwarf::Tag Tag;
Benjamin Kramer8aefffc2012-01-24 12:08:28 +000061
62 /// ChildrenFlag - Dwarf children flag.
63 ///
64 uint16_t ChildrenFlag;
Bill Wendling47054f32009-05-15 00:11:17 +000065
66 /// Unique number for node.
67 ///
68 unsigned Number;
69
Bill Wendling47054f32009-05-15 00:11:17 +000070 /// Data - Raw data bytes for abbreviation.
71 ///
Eric Christopher9c8414f2013-03-29 20:23:06 +000072 SmallVector<DIEAbbrevData, 12> Data;
Devang Patel1f4690c2009-12-15 19:16:48 +000073
Bill Wendling47054f32009-05-15 00:11:17 +000074 public:
David Blaikief2443192013-10-21 17:28:37 +000075 DIEAbbrev(dwarf::Tag T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
Bill Wendling47054f32009-05-15 00:11:17 +000076
77 // Accessors.
David Blaikief2443192013-10-21 17:28:37 +000078 dwarf::Tag getTag() const { return Tag; }
Bill Wendling47054f32009-05-15 00:11:17 +000079 unsigned getNumber() const { return Number; }
Benjamin Kramer8aefffc2012-01-24 12:08:28 +000080 uint16_t getChildrenFlag() const { return ChildrenFlag; }
Eric Christopher4887c8f2013-03-29 23:34:06 +000081 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
Benjamin Kramer8aefffc2012-01-24 12:08:28 +000082 void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; }
Bill Wendling47054f32009-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.
David Blaikief2443192013-10-21 17:28:37 +000087 void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form) {
Bill Wendling47054f32009-05-15 00:11:17 +000088 Data.push_back(DIEAbbrevData(Attribute, Form));
89 }
90
Bill Wendling47054f32009-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 Lattner3a383cb2010-04-05 00:13:49 +000097 void Emit(AsmPrinter *AP) const;
Bill Wendling47054f32009-05-15 00:11:17 +000098
99#ifndef NDEBUG
Chris Lattner74725712009-08-23 01:01:17 +0000100 void print(raw_ostream &O);
Bill Wendling47054f32009-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 Christopher14c20672013-04-03 05:29:58 +0000107 /// describes its organization.
Bill Wendling47054f32009-05-15 00:11:17 +0000108 class DIEValue;
109
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000110 class DIE {
Bill Wendling47054f32009-05-15 00:11:17 +0000111 protected:
Bill Wendling47054f32009-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 Kramer8aefffc2012-01-24 12:08:28 +0000120 /// Abbrev - Buffer for constructing abbreviation.
121 ///
122 DIEAbbrev Abbrev;
123
Bill Wendling47054f32009-05-15 00:11:17 +0000124 /// Children DIEs.
125 ///
126 std::vector<DIE *> Children;
127
Devang Patel1f4690c2009-12-15 19:16:48 +0000128 DIE *Parent;
129
Bill Wendling3d7b0b82012-12-19 07:18:57 +0000130 /// Attribute values.
Bill Wendling47054f32009-05-15 00:11:17 +0000131 ///
Eric Christopher9c8414f2013-03-29 20:23:06 +0000132 SmallVector<DIEValue*, 12> Values;
Bill Wendling47054f32009-05-15 00:11:17 +0000133
Bill Wendling47054f32009-05-15 00:11:17 +0000134 public:
135 explicit DIE(unsigned Tag)
David Blaikief2443192013-10-21 17:28:37 +0000136 : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
137 Parent(0) {}
Eric Christopher3262a112013-11-20 00:54:31 +0000138 ~DIE();
Bill Wendling47054f32009-05-15 00:11:17 +0000139
140 // Accessors.
141 DIEAbbrev &getAbbrev() { return Abbrev; }
David Blaikieafcb9652013-10-24 17:51:43 +0000142 const DIEAbbrev &getAbbrev() const { return Abbrev; }
Bill Wendling47054f32009-05-15 00:11:17 +0000143 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
David Blaikief2443192013-10-21 17:28:37 +0000144 dwarf::Tag getTag() const { return Abbrev.getTag(); }
Bill Wendling47054f32009-05-15 00:11:17 +0000145 unsigned getOffset() const { return Offset; }
146 unsigned getSize() const { return Size; }
147 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopher4887c8f2013-03-29 23:34:06 +0000148 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel1f4690c2009-12-15 19:16:48 +0000149 DIE *getParent() const { return Parent; }
David Blaikie409dd9c2013-11-19 23:08:21 +0000150 /// Climb up the parent chain to get the compile or type unit DIE this DIE
151 /// belongs to.
152 const DIE *getUnit() const;
153 /// Similar to getUnit, returns null when DIE is not added to an
Manman Ren4dbdc902013-10-31 17:54:35 +0000154 /// owner yet.
David Blaikie409dd9c2013-11-19 23:08:21 +0000155 const DIE *getUnitOrNull() const;
Bill Wendling47054f32009-05-15 00:11:17 +0000156 void setOffset(unsigned O) { Offset = O; }
157 void setSize(unsigned S) { Size = S; }
Eric Christopherb800ff72013-01-07 22:40:45 +0000158
Devang Patel930143b2009-11-21 02:48:08 +0000159 /// addValue - Add a value and attributes to a DIE.
Bill Wendling47054f32009-05-15 00:11:17 +0000160 ///
David Blaikief2443192013-10-21 17:28:37 +0000161 void addValue(dwarf::Attribute Attribute, dwarf::Form Form,
162 DIEValue *Value) {
Bill Wendling47054f32009-05-15 00:11:17 +0000163 Abbrev.AddAttribute(Attribute, Form);
164 Values.push_back(Value);
165 }
166
Devang Patel930143b2009-11-21 02:48:08 +0000167 /// addChild - Add a child to the DIE.
Bill Wendling47054f32009-05-15 00:11:17 +0000168 ///
Devang Patel930143b2009-11-21 02:48:08 +0000169 void addChild(DIE *Child) {
David Blaikie811bfe62013-10-03 20:07:20 +0000170 assert(!Child->getParent());
Bill Wendling47054f32009-05-15 00:11:17 +0000171 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
172 Children.push_back(Child);
Jeffrey Yasskin35b4e4f2010-03-12 17:45:06 +0000173 Child->Parent = this;
Bill Wendling47054f32009-05-15 00:11:17 +0000174 }
175
Eric Christophera07e4f52013-11-19 09:28:34 +0000176 /// findAttribute - Find a value in the DIE with the attribute given,
177 /// returns NULL if no such attribute exists.
Eric Christopher0fe676a2013-11-21 00:48:22 +0000178 DIEValue *findAttribute(uint16_t Attribute) const;
Eric Christopher8552e222013-08-07 01:18:33 +0000179
Bill Wendling47054f32009-05-15 00:11:17 +0000180#ifndef NDEBUG
Eric Christopher6c6de842013-05-06 17:50:50 +0000181 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000182 void dump();
183#endif
184 };
185
186 //===--------------------------------------------------------------------===//
187 /// DIEValue - A debug information entry value.
188 ///
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000189 class DIEValue {
David Blaikiea379b1812011-12-20 02:50:00 +0000190 virtual void anchor();
Bill Wendling47054f32009-05-15 00:11:17 +0000191 public:
192 enum {
193 isInteger,
194 isString,
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000195 isExpr,
Bill Wendling47054f32009-05-15 00:11:17 +0000196 isLabel,
Bill Wendling47054f32009-05-15 00:11:17 +0000197 isDelta,
198 isEntry,
David Blaikie47f615e2013-12-17 23:32:35 +0000199 isTypeSignature,
Bill Wendling47054f32009-05-15 00:11:17 +0000200 isBlock
201 };
202 protected:
203 /// Type - Type of data stored in the value.
204 ///
205 unsigned Type;
206 public:
207 explicit DIEValue(unsigned T) : Type(T) {}
208 virtual ~DIEValue() {}
209
210 // Accessors
211 unsigned getType() const { return Type; }
212
213 /// EmitValue - Emit value via the Dwarf writer.
214 ///
David Blaikief2443192013-10-21 17:28:37 +0000215 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling47054f32009-05-15 00:11:17 +0000216
217 /// SizeOf - Return the size of a value in bytes.
218 ///
David Blaikief2443192013-10-21 17:28:37 +0000219 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
Bill Wendling47054f32009-05-15 00:11:17 +0000220
Bill Wendling47054f32009-05-15 00:11:17 +0000221#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000222 virtual void print(raw_ostream &O) const = 0;
223 void dump() const;
Bill Wendling47054f32009-05-15 00:11:17 +0000224#endif
225 };
226
227 //===--------------------------------------------------------------------===//
228 /// DIEInteger - An integer value DIE.
229 ///
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000230 class DIEInteger : public DIEValue {
Bill Wendling47054f32009-05-15 00:11:17 +0000231 uint64_t Integer;
232 public:
233 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
234
235 /// BestForm - Choose the best form for integer.
236 ///
David Blaikief2443192013-10-21 17:28:37 +0000237 static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
Bill Wendling47054f32009-05-15 00:11:17 +0000238 if (IsSigned) {
Hans Wennborg7504cef2013-03-18 17:03:05 +0000239 const int64_t SignedInt = Int;
240 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1;
241 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2;
242 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4;
Bill Wendling47054f32009-05-15 00:11:17 +0000243 } else {
244 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
245 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
246 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
247 }
248 return dwarf::DW_FORM_data8;
249 }
250
251 /// EmitValue - Emit integer of appropriate size.
252 ///
David Blaikief2443192013-10-21 17:28:37 +0000253 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000254
Devang Patel12563b32010-04-16 23:33:45 +0000255 uint64_t getValue() const { return Integer; }
256
Bill Wendling47054f32009-05-15 00:11:17 +0000257 /// SizeOf - Determine size of integer value in bytes.
258 ///
David Blaikief2443192013-10-21 17:28:37 +0000259 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000260
Bill Wendling47054f32009-05-15 00:11:17 +0000261 // Implement isa/cast/dyncast.
Bill Wendling47054f32009-05-15 00:11:17 +0000262 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
263
264#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000265 virtual void print(raw_ostream &O) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000266#endif
267 };
268
269 //===--------------------------------------------------------------------===//
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000270 /// DIEExpr - An expression DIE.
271 //
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000272 class DIEExpr : public DIEValue {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000273 const MCExpr *Expr;
274 public:
275 explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
276
277 /// EmitValue - Emit expression value.
278 ///
David Blaikief2443192013-10-21 17:28:37 +0000279 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000280
281 /// getValue - Get MCExpr.
282 ///
283 const MCExpr *getValue() const { return Expr; }
284
285 /// SizeOf - Determine size of expression value in bytes.
286 ///
David Blaikief2443192013-10-21 17:28:37 +0000287 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000288
289 // Implement isa/cast/dyncast.
290 static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
291
292#ifndef NDEBUG
293 virtual void print(raw_ostream &O) const;
294#endif
295 };
296
297 //===--------------------------------------------------------------------===//
298 /// DIELabel - A label DIE.
Bill Wendling47054f32009-05-15 00:11:17 +0000299 //
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000300 class DIELabel : public DIEValue {
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000301 const MCSymbol *Label;
Bill Wendling47054f32009-05-15 00:11:17 +0000302 public:
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000303 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling47054f32009-05-15 00:11:17 +0000304
305 /// EmitValue - Emit label value.
306 ///
David Blaikief2443192013-10-21 17:28:37 +0000307 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000308
Devang Patel9fc11702010-05-25 23:40:22 +0000309 /// getValue - Get MCSymbol.
310 ///
Ulrich Weigand396ba8b2013-07-02 18:46:26 +0000311 const MCSymbol *getValue() const { return Label; }
Devang Patel9fc11702010-05-25 23:40:22 +0000312
Bill Wendling47054f32009-05-15 00:11:17 +0000313 /// SizeOf - Determine size of label value in bytes.
314 ///
David Blaikief2443192013-10-21 17:28:37 +0000315 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000316
Bill Wendling47054f32009-05-15 00:11:17 +0000317 // Implement isa/cast/dyncast.
Bill Wendling47054f32009-05-15 00:11:17 +0000318 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
319
320#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000321 virtual void print(raw_ostream &O) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000322#endif
323 };
324
325 //===--------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000326 /// DIEDelta - A simple label difference DIE.
327 ///
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000328 class DIEDelta : public DIEValue {
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000329 const MCSymbol *LabelHi;
330 const MCSymbol *LabelLo;
Bill Wendling47054f32009-05-15 00:11:17 +0000331 public:
Chris Lattnerbc9210c2010-03-08 22:23:36 +0000332 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling47054f32009-05-15 00:11:17 +0000333 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
334
335 /// EmitValue - Emit delta value.
336 ///
David Blaikief2443192013-10-21 17:28:37 +0000337 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000338
339 /// SizeOf - Determine size of delta value in bytes.
340 ///
David Blaikief2443192013-10-21 17:28:37 +0000341 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000342
Bill Wendling47054f32009-05-15 00:11:17 +0000343 // Implement isa/cast/dyncast.
Bill Wendling47054f32009-05-15 00:11:17 +0000344 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
345
346#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000347 virtual void print(raw_ostream &O) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000348#endif
349 };
350
351 //===--------------------------------------------------------------------===//
Eric Christopher67646432013-07-26 17:02:41 +0000352 /// DIEString - A container for string values.
353 ///
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000354 class DIEString : public DIEValue {
Eric Christopher67646432013-07-26 17:02:41 +0000355 const DIEValue *Access;
356 const StringRef Str;
357
358 public:
359 DIEString(const DIEValue *Acc, const StringRef S)
360 : DIEValue(isString), Access(Acc), Str(S) {}
361
362 /// getString - Grab the string out of the object.
363 StringRef getString() const { return Str; }
364
365 /// EmitValue - Emit delta value.
366 ///
David Blaikief2443192013-10-21 17:28:37 +0000367 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher67646432013-07-26 17:02:41 +0000368
369 /// SizeOf - Determine size of delta value in bytes.
370 ///
David Blaikief2443192013-10-21 17:28:37 +0000371 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Eric Christopher67646432013-07-26 17:02:41 +0000372
373 // Implement isa/cast/dyncast.
374 static bool classof(const DIEValue *D) { return D->getType() == isString; }
375
376 #ifndef NDEBUG
377 virtual void print(raw_ostream &O) const;
378 #endif
379 };
380
381 //===--------------------------------------------------------------------===//
Nick Lewycky5ca33ac2011-10-18 22:39:43 +0000382 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling47054f32009-05-15 00:11:17 +0000383 /// this class can also be used as a proxy for a debug information entry not
384 /// yet defined (ie. types.)
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000385 class DIEEntry : public DIEValue {
Jeffrey Yasskin35b4e4f2010-03-12 17:45:06 +0000386 DIE *const Entry;
Bill Wendling47054f32009-05-15 00:11:17 +0000387 public:
David Blaikie7b770c62013-05-14 00:35:19 +0000388 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
389 assert(E && "Cannot construct a DIEEntry with a null DIE");
390 }
Bill Wendling47054f32009-05-15 00:11:17 +0000391
392 DIE *getEntry() const { return Entry; }
Bill Wendling47054f32009-05-15 00:11:17 +0000393
394 /// EmitValue - Emit debug information entry offset.
395 ///
David Blaikief2443192013-10-21 17:28:37 +0000396 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000397
398 /// SizeOf - Determine size of debug information entry in bytes.
399 ///
David Blaikief2443192013-10-21 17:28:37 +0000400 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
Eric Christopher31b05762013-08-08 01:41:00 +0000401 return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
402 : sizeof(int32_t);
Manman Renbdcb4462013-04-04 23:13:11 +0000403 }
Bill Wendling47054f32009-05-15 00:11:17 +0000404
Manman Renac8062b2013-07-02 23:40:10 +0000405 /// Returns size of a ref_addr entry.
406 static unsigned getRefAddrSize(AsmPrinter *AP);
407
Bill Wendling47054f32009-05-15 00:11:17 +0000408 // Implement isa/cast/dyncast.
Bill Wendling47054f32009-05-15 00:11:17 +0000409 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
410
411#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000412 virtual void print(raw_ostream &O) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000413#endif
414 };
415
416 //===--------------------------------------------------------------------===//
David Blaikie47f615e2013-12-17 23:32:35 +0000417 /// \brief A signature reference to a type unit.
418 class DIETypeSignature : public DIEValue {
419 const DwarfTypeUnit &Unit;
420 public:
421 explicit DIETypeSignature(const DwarfTypeUnit &Unit)
422 : DIEValue(isTypeSignature), Unit(Unit) {}
423
424 /// \brief Emit type unit signature.
425 virtual void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const;
426
427 /// Returns size of a ref_sig8 entry.
428 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
429 assert(Form == dwarf::DW_FORM_ref_sig8);
430 return 8;
431 }
432
433 // \brief Implement isa/cast/dyncast.
434 static bool classof(const DIEValue *E) {
435 return E->getType() == isTypeSignature;
436 }
437#ifndef NDEBUG
438 virtual void print(raw_ostream &O) const;
439 void dump() const;
440#endif
441 };
442
443 //===--------------------------------------------------------------------===//
Bill Wendling47054f32009-05-15 00:11:17 +0000444 /// DIEBlock - A block of values. Primarily used for location expressions.
445 //
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000446 class DIEBlock : public DIEValue, public DIE {
Bill Wendling47054f32009-05-15 00:11:17 +0000447 unsigned Size; // Size in bytes excluding size header.
448 public:
David Blaikief2443192013-10-21 17:28:37 +0000449 DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {}
Bill Wendling47054f32009-05-15 00:11:17 +0000450
451 /// ComputeSize - calculate the size of the block.
452 ///
Chris Lattner5a00dea2010-04-05 00:18:22 +0000453 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling47054f32009-05-15 00:11:17 +0000454
455 /// BestForm - Choose the best form for data.
456 ///
David Blaikief2443192013-10-21 17:28:37 +0000457 dwarf::Form BestForm() const {
Bill Wendling47054f32009-05-15 00:11:17 +0000458 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
459 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
460 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
461 return dwarf::DW_FORM_block;
462 }
463
464 /// EmitValue - Emit block data.
465 ///
David Blaikief2443192013-10-21 17:28:37 +0000466 virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000467
468 /// SizeOf - Determine size of block data in bytes.
469 ///
David Blaikief2443192013-10-21 17:28:37 +0000470 virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000471
Bill Wendling47054f32009-05-15 00:11:17 +0000472 // Implement isa/cast/dyncast.
Bill Wendling47054f32009-05-15 00:11:17 +0000473 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
474
475#ifndef NDEBUG
Eric Christopher65ac02a2013-05-31 22:50:40 +0000476 virtual void print(raw_ostream &O) const;
Bill Wendling47054f32009-05-15 00:11:17 +0000477#endif
478 };
479
480} // end llvm namespace
481
482#endif