blob: c29144d9ce2b10b1d914e671a279ebff093f7d43 [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"
Chris Lattnerb01acfa2009-08-23 01:01:17 +000021#include <vector>
Bill Wendling88423ee2009-05-15 00:11:17 +000022
23namespace llvm {
24 class AsmPrinter;
Chris Lattner858431d2010-01-16 18:50:28 +000025 class MCSymbol;
Chris Lattnerb98b1bf2010-03-08 22:23:36 +000026 class raw_ostream;
Bill Wendling88423ee2009-05-15 00:11:17 +000027
28 //===--------------------------------------------------------------------===//
Eric Christopher0fbaa372013-06-10 22:24:07 +000029 /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
Bill Wendling88423ee2009-05-15 00:11:17 +000030 /// Dwarf abbreviation.
Nick Lewycky381afae2009-11-17 09:17:08 +000031 class DIEAbbrevData {
Bill Wendling88423ee2009-05-15 00:11:17 +000032 /// Attribute - Dwarf attribute code.
33 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000034 uint16_t Attribute;
Bill Wendling88423ee2009-05-15 00:11:17 +000035
36 /// Form - Dwarf form code.
37 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000038 uint16_t Form;
Bill Wendling88423ee2009-05-15 00:11:17 +000039 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000040 DIEAbbrevData(uint16_t A, uint16_t F) : Attribute(A), Form(F) {}
Bill Wendling88423ee2009-05-15 00:11:17 +000041
42 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000043 uint16_t getAttribute() const { return Attribute; }
44 uint16_t getForm() const { return Form; }
Bill Wendling88423ee2009-05-15 00:11:17 +000045
46 /// Profile - Used to gather unique data for the abbreviation folding set.
47 ///
48 void Profile(FoldingSetNodeID &ID) const;
49 };
50
51 //===--------------------------------------------------------------------===//
52 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
53 /// information object.
Nick Lewycky381afae2009-11-17 09:17:08 +000054 class DIEAbbrev : public FoldingSetNode {
Bill Wendling88423ee2009-05-15 00:11:17 +000055 /// Tag - Dwarf tag code.
56 ///
Benjamin Kramere697b4f2012-01-24 12:08:28 +000057 uint16_t Tag;
58
59 /// ChildrenFlag - Dwarf children flag.
60 ///
61 uint16_t ChildrenFlag;
Bill Wendling88423ee2009-05-15 00:11:17 +000062
63 /// Unique number for node.
64 ///
65 unsigned Number;
66
Bill Wendling88423ee2009-05-15 00:11:17 +000067 /// Data - Raw data bytes for abbreviation.
68 ///
Eric Christopher2df938a2013-03-29 20:23:06 +000069 SmallVector<DIEAbbrevData, 12> Data;
Devang Patel6404e4e2009-12-15 19:16:48 +000070
Bill Wendling88423ee2009-05-15 00:11:17 +000071 public:
Benjamin Kramere697b4f2012-01-24 12:08:28 +000072 DIEAbbrev(uint16_t T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
Bill Wendling88423ee2009-05-15 00:11:17 +000073
74 // Accessors.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000075 uint16_t getTag() const { return Tag; }
Bill Wendling88423ee2009-05-15 00:11:17 +000076 unsigned getNumber() const { return Number; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000077 uint16_t getChildrenFlag() const { return ChildrenFlag; }
Eric Christopherf7cef702013-03-29 23:34:06 +000078 const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
Benjamin Kramere697b4f2012-01-24 12:08:28 +000079 void setTag(uint16_t T) { Tag = T; }
80 void setChildrenFlag(uint16_t CF) { ChildrenFlag = CF; }
Bill Wendling88423ee2009-05-15 00:11:17 +000081 void setNumber(unsigned N) { Number = N; }
82
83 /// AddAttribute - Adds another set of attribute information to the
84 /// abbreviation.
Benjamin Kramere697b4f2012-01-24 12:08:28 +000085 void AddAttribute(uint16_t Attribute, uint16_t Form) {
Bill Wendling88423ee2009-05-15 00:11:17 +000086 Data.push_back(DIEAbbrevData(Attribute, Form));
87 }
88
Bill Wendling88423ee2009-05-15 00:11:17 +000089 /// Profile - Used to gather unique data for the abbreviation folding set.
90 ///
91 void Profile(FoldingSetNodeID &ID) const;
92
93 /// Emit - Print the abbreviation using the specified asm printer.
94 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +000095 void Emit(AsmPrinter *AP) const;
Bill Wendling88423ee2009-05-15 00:11:17 +000096
97#ifndef NDEBUG
Chris Lattnerb01acfa2009-08-23 01:01:17 +000098 void print(raw_ostream &O);
Bill Wendling88423ee2009-05-15 00:11:17 +000099 void dump();
100#endif
101 };
102
103 //===--------------------------------------------------------------------===//
104 /// DIE - A structured debug information entry. Has an abbreviation which
Eric Christopher0c5cdc52013-04-03 05:29:58 +0000105 /// describes its organization.
Bill Wendling88423ee2009-05-15 00:11:17 +0000106 class DIEValue;
107
Devang Patel6f01d9c2009-11-21 00:31:03 +0000108 class DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000109 protected:
Bill Wendling88423ee2009-05-15 00:11:17 +0000110 /// Offset - Offset in debug info section.
111 ///
112 unsigned Offset;
113
114 /// Size - Size of instance + children.
115 ///
116 unsigned Size;
117
Benjamin Kramere697b4f2012-01-24 12:08:28 +0000118 /// Abbrev - Buffer for constructing abbreviation.
119 ///
120 DIEAbbrev Abbrev;
121
Bill Wendling88423ee2009-05-15 00:11:17 +0000122 /// Children DIEs.
123 ///
124 std::vector<DIE *> Children;
125
Devang Patel6404e4e2009-12-15 19:16:48 +0000126 DIE *Parent;
127
Bill Wendling034b94b2012-12-19 07:18:57 +0000128 /// Attribute values.
Bill Wendling88423ee2009-05-15 00:11:17 +0000129 ///
Eric Christopher2df938a2013-03-29 20:23:06 +0000130 SmallVector<DIEValue*, 12> Values;
Bill Wendling88423ee2009-05-15 00:11:17 +0000131
Eric Christopherd32d7a52013-06-10 20:58:53 +0000132#ifndef NDEBUG
Owen Andersond5509f22009-06-24 23:13:56 +0000133 // Private data for print()
134 mutable unsigned IndentCount;
Eric Christopherd32d7a52013-06-10 20:58:53 +0000135#endif
Bill Wendling88423ee2009-05-15 00:11:17 +0000136 public:
137 explicit DIE(unsigned Tag)
Eric Christopher30cb8362013-05-06 17:50:50 +0000138 : Offset(0), Size(0), Abbrev(Tag, dwarf::DW_CHILDREN_no), Parent(0) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000139 virtual ~DIE();
140
141 // Accessors.
142 DIEAbbrev &getAbbrev() { return Abbrev; }
143 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
144 unsigned getTag() const { return Abbrev.getTag(); }
145 unsigned getOffset() const { return Offset; }
146 unsigned getSize() const { return Size; }
147 const std::vector<DIE *> &getChildren() const { return Children; }
Eric Christopherf7cef702013-03-29 23:34:06 +0000148 const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
Devang Patel6404e4e2009-12-15 19:16:48 +0000149 DIE *getParent() const { return Parent; }
Manman Renbc3e96f2013-03-12 18:27:15 +0000150 /// Climb up the parent chain to get the compile unit DIE this DIE belongs
151 /// to.
Eric Christopher4d7f2ce2013-05-14 21:33:10 +0000152 DIE *getCompileUnit();
Bill Wendling88423ee2009-05-15 00:11:17 +0000153 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
154 void setOffset(unsigned O) { Offset = O; }
155 void setSize(unsigned S) { Size = S; }
Eric Christopherff348452013-01-07 22:40:45 +0000156
Devang Patel2c4ceb12009-11-21 02:48:08 +0000157 /// addValue - Add a value and attributes to a DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000158 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000159 void addValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000160 Abbrev.AddAttribute(Attribute, Form);
161 Values.push_back(Value);
162 }
163
Devang Patel2c4ceb12009-11-21 02:48:08 +0000164 /// addChild - Add a child to the DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000165 ///
Devang Patel2c4ceb12009-11-21 02:48:08 +0000166 void addChild(DIE *Child) {
Devang Patel6404e4e2009-12-15 19:16:48 +0000167 if (Child->getParent()) {
168 assert (Child->getParent() == this && "Unexpected DIE Parent!");
169 return;
170 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000171 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
172 Children.push_back(Child);
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000173 Child->Parent = this;
Bill Wendling88423ee2009-05-15 00:11:17 +0000174 }
175
Bill Wendling88423ee2009-05-15 00:11:17 +0000176#ifndef NDEBUG
Eric Christopher30cb8362013-05-06 17:50:50 +0000177 void print(raw_ostream &O, unsigned IndentCount = 0) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000178 void dump();
179#endif
180 };
181
182 //===--------------------------------------------------------------------===//
183 /// DIEValue - A debug information entry value.
184 ///
Devang Patel6f01d9c2009-11-21 00:31:03 +0000185 class DIEValue {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000186 virtual void anchor();
Bill Wendling88423ee2009-05-15 00:11:17 +0000187 public:
188 enum {
189 isInteger,
190 isString,
191 isLabel,
Bill Wendling88423ee2009-05-15 00:11:17 +0000192 isDelta,
193 isEntry,
194 isBlock
195 };
196 protected:
197 /// Type - Type of data stored in the value.
198 ///
199 unsigned Type;
200 public:
201 explicit DIEValue(unsigned T) : Type(T) {}
202 virtual ~DIEValue() {}
203
204 // Accessors
205 unsigned getType() const { return Type; }
206
207 /// EmitValue - Emit value via the Dwarf writer.
208 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000209 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000210
211 /// SizeOf - Return the size of a value in bytes.
212 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000213 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const = 0;
Bill Wendling88423ee2009-05-15 00:11:17 +0000214
Bill Wendling88423ee2009-05-15 00:11:17 +0000215#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000216 virtual void print(raw_ostream &O) const = 0;
217 void dump() const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000218#endif
219 };
220
221 //===--------------------------------------------------------------------===//
222 /// DIEInteger - An integer value DIE.
223 ///
Nick Lewycky381afae2009-11-17 09:17:08 +0000224 class DIEInteger : public DIEValue {
Bill Wendling88423ee2009-05-15 00:11:17 +0000225 uint64_t Integer;
226 public:
227 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
228
229 /// BestForm - Choose the best form for integer.
230 ///
231 static unsigned BestForm(bool IsSigned, uint64_t Int) {
232 if (IsSigned) {
Hans Wennborga12c6742013-03-18 17:03:05 +0000233 const int64_t SignedInt = Int;
234 if ((char)Int == SignedInt) return dwarf::DW_FORM_data1;
235 if ((short)Int == SignedInt) return dwarf::DW_FORM_data2;
236 if ((int)Int == SignedInt) return dwarf::DW_FORM_data4;
Bill Wendling88423ee2009-05-15 00:11:17 +0000237 } else {
238 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
239 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
240 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
241 }
242 return dwarf::DW_FORM_data8;
243 }
244
245 /// EmitValue - Emit integer of appropriate size.
246 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000247 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000248
Devang Patelf2548ca2010-04-16 23:33:45 +0000249 uint64_t getValue() const { return Integer; }
250
Bill Wendling88423ee2009-05-15 00:11:17 +0000251 /// SizeOf - Determine size of integer value in bytes.
252 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000253 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000254
Bill Wendling88423ee2009-05-15 00:11:17 +0000255 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000256 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
257
258#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000259 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000260#endif
261 };
262
263 //===--------------------------------------------------------------------===//
Chris Lattner4faf59a2010-03-08 22:31:46 +0000264 /// DIELabel - A label expression DIE.
Bill Wendling88423ee2009-05-15 00:11:17 +0000265 //
Chris Lattner4faf59a2010-03-08 22:31:46 +0000266 class DIELabel : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000267 const MCSymbol *Label;
Bill Wendling88423ee2009-05-15 00:11:17 +0000268 public:
Chris Lattner4faf59a2010-03-08 22:31:46 +0000269 explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
Bill Wendling88423ee2009-05-15 00:11:17 +0000270
271 /// EmitValue - Emit label value.
272 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000273 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000274
Devang Patelc3f5f782010-05-25 23:40:22 +0000275 /// getValue - Get MCSymbol.
276 ///
Eric Christopher1d186292013-06-11 23:41:38 +0000277 const MCSymbol *getValue() const { return Label; }
Devang Patelc3f5f782010-05-25 23:40:22 +0000278
Bill Wendling88423ee2009-05-15 00:11:17 +0000279 /// SizeOf - Determine size of label value in bytes.
280 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000281 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000282
Bill Wendling88423ee2009-05-15 00:11:17 +0000283 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000284 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
285
286#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000287 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000288#endif
289 };
290
291 //===--------------------------------------------------------------------===//
Bill Wendling88423ee2009-05-15 00:11:17 +0000292 /// DIEDelta - A simple label difference DIE.
293 ///
Nick Lewycky381afae2009-11-17 09:17:08 +0000294 class DIEDelta : public DIEValue {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000295 const MCSymbol *LabelHi;
296 const MCSymbol *LabelLo;
Bill Wendling88423ee2009-05-15 00:11:17 +0000297 public:
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000298 DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
Bill Wendling88423ee2009-05-15 00:11:17 +0000299 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
300
301 /// EmitValue - Emit delta value.
302 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000303 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000304
305 /// SizeOf - Determine size of delta value in bytes.
306 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000307 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000308
Bill Wendling88423ee2009-05-15 00:11:17 +0000309 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000310 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
311
312#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000313 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000314#endif
315 };
316
317 //===--------------------------------------------------------------------===//
Nick Lewycky024170f2011-10-18 22:39:43 +0000318 /// DIEEntry - A pointer to another debug information entry. An instance of
Bill Wendling88423ee2009-05-15 00:11:17 +0000319 /// this class can also be used as a proxy for a debug information entry not
320 /// yet defined (ie. types.)
Nick Lewycky381afae2009-11-17 09:17:08 +0000321 class DIEEntry : public DIEValue {
Jeffrey Yasskin5c213dc2010-03-12 17:45:06 +0000322 DIE *const Entry;
Bill Wendling88423ee2009-05-15 00:11:17 +0000323 public:
David Blaikie17a692e2013-05-14 00:35:19 +0000324 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
325 assert(E && "Cannot construct a DIEEntry with a null DIE");
326 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000327
328 DIE *getEntry() const { return Entry; }
Bill Wendling88423ee2009-05-15 00:11:17 +0000329
330 /// EmitValue - Emit debug information entry offset.
331 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000332 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000333
334 /// SizeOf - Determine size of debug information entry in bytes.
335 ///
Manman Ren624a93e2013-04-04 23:13:11 +0000336 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const {
337 return sizeof(int32_t);
338 }
Bill Wendling88423ee2009-05-15 00:11:17 +0000339
Bill Wendling88423ee2009-05-15 00:11:17 +0000340 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000341 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
342
343#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000344 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000345#endif
346 };
347
348 //===--------------------------------------------------------------------===//
349 /// DIEBlock - A block of values. Primarily used for location expressions.
350 //
Nick Lewycky381afae2009-11-17 09:17:08 +0000351 class DIEBlock : public DIEValue, public DIE {
Bill Wendling88423ee2009-05-15 00:11:17 +0000352 unsigned Size; // Size in bytes excluding size header.
353 public:
354 DIEBlock()
355 : DIEValue(isBlock), DIE(0), Size(0) {}
356 virtual ~DIEBlock() {}
357
358 /// ComputeSize - calculate the size of the block.
359 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000360 unsigned ComputeSize(AsmPrinter *AP);
Bill Wendling88423ee2009-05-15 00:11:17 +0000361
362 /// BestForm - Choose the best form for data.
363 ///
364 unsigned BestForm() const {
365 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
366 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
367 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
368 return dwarf::DW_FORM_block;
369 }
370
371 /// EmitValue - Emit block data.
372 ///
Chris Lattnerd38fee82010-04-05 00:13:49 +0000373 virtual void EmitValue(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000374
375 /// SizeOf - Determine size of block data in bytes.
376 ///
Chris Lattnera37d5382010-04-05 00:18:22 +0000377 virtual unsigned SizeOf(AsmPrinter *AP, unsigned Form) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000378
Bill Wendling88423ee2009-05-15 00:11:17 +0000379 // Implement isa/cast/dyncast.
Bill Wendling88423ee2009-05-15 00:11:17 +0000380 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
381
382#ifndef NDEBUG
Eric Christopher813419e2013-05-31 22:50:40 +0000383 virtual void print(raw_ostream &O) const;
Bill Wendling88423ee2009-05-15 00:11:17 +0000384#endif
385 };
386
387} // end llvm namespace
388
389#endif