Indentation change.
[llvm/avr.git] / lib / CodeGen / AsmPrinter / DIE.h
blob5b60327f9036c8e23c3344325953ffc4c4fef7e5
1 //===--- 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.
11 //
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DIE_H__
15 #define CODEGEN_ASMPRINTER_DIE_H__
17 #include "DwarfLabel.h"
18 #include "llvm/ADT/FoldingSet.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/Dwarf.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include <iosfwd>
25 namespace llvm {
26 class AsmPrinter;
27 class Dwarf;
28 class TargetData;
30 //===--------------------------------------------------------------------===//
31 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
32 /// Dwarf abbreviation.
33 class VISIBILITY_HIDDEN DIEAbbrevData {
34 /// Attribute - Dwarf attribute code.
35 ///
36 unsigned Attribute;
38 /// Form - Dwarf form code.
39 ///
40 unsigned Form;
41 public:
42 DIEAbbrevData(unsigned A, unsigned F) : Attribute(A), Form(F) {}
44 // Accessors.
45 unsigned getAttribute() const { return Attribute; }
46 unsigned getForm() const { return Form; }
48 /// Profile - Used to gather unique data for the abbreviation folding set.
49 ///
50 void Profile(FoldingSetNodeID &ID) const;
53 //===--------------------------------------------------------------------===//
54 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
55 /// information object.
56 class VISIBILITY_HIDDEN DIEAbbrev : public FoldingSetNode {
57 /// Tag - Dwarf tag code.
58 ///
59 unsigned Tag;
61 /// Unique number for node.
62 ///
63 unsigned Number;
65 /// ChildrenFlag - Dwarf children flag.
66 ///
67 unsigned ChildrenFlag;
69 /// Data - Raw data bytes for abbreviation.
70 ///
71 SmallVector<DIEAbbrevData, 8> Data;
72 public:
73 DIEAbbrev(unsigned T, unsigned C) : Tag(T), ChildrenFlag(C), Data() {}
74 virtual ~DIEAbbrev() {}
76 // Accessors.
77 unsigned getTag() const { return Tag; }
78 unsigned getNumber() const { return Number; }
79 unsigned getChildrenFlag() const { return ChildrenFlag; }
80 const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; }
81 void setTag(unsigned T) { Tag = T; }
82 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
83 void setNumber(unsigned N) { Number = N; }
85 /// AddAttribute - Adds another set of attribute information to the
86 /// abbreviation.
87 void AddAttribute(unsigned Attribute, unsigned Form) {
88 Data.push_back(DIEAbbrevData(Attribute, Form));
91 /// AddFirstAttribute - Adds a set of attribute information to the front
92 /// of the abbreviation.
93 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
94 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
97 /// Profile - Used to gather unique data for the abbreviation folding set.
98 ///
99 void Profile(FoldingSetNodeID &ID) const;
101 /// Emit - Print the abbreviation using the specified asm printer.
103 void Emit(const AsmPrinter *Asm) const;
105 #ifndef NDEBUG
106 void print(std::ostream *O) {
107 if (O) print(*O);
109 void print(std::ostream &O);
110 void dump();
111 #endif
114 //===--------------------------------------------------------------------===//
115 /// DIE - A structured debug information entry. Has an abbreviation which
116 /// describes it's organization.
117 class CompileUnit;
118 class DIEValue;
120 class VISIBILITY_HIDDEN DIE : public FoldingSetNode {
121 protected:
122 /// Abbrev - Buffer for constructing abbreviation.
124 DIEAbbrev Abbrev;
126 /// Offset - Offset in debug info section.
128 unsigned Offset;
130 /// Size - Size of instance + children.
132 unsigned Size;
134 /// Children DIEs.
136 std::vector<DIE *> Children;
138 /// Attributes values.
140 SmallVector<DIEValue*, 32> Values;
142 /// Abstract compile unit.
143 CompileUnit *AbstractCU;
145 // Private data for print()
146 mutable unsigned IndentCount;
147 public:
148 explicit DIE(unsigned Tag)
149 : Abbrev(Tag, dwarf::DW_CHILDREN_no), Offset(0),
150 Size(0), IndentCount(0) {}
151 virtual ~DIE();
153 // Accessors.
154 DIEAbbrev &getAbbrev() { return Abbrev; }
155 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
156 unsigned getTag() const { return Abbrev.getTag(); }
157 unsigned getOffset() const { return Offset; }
158 unsigned getSize() const { return Size; }
159 const std::vector<DIE *> &getChildren() const { return Children; }
160 SmallVector<DIEValue*, 32> &getValues() { return Values; }
161 CompileUnit *getAbstractCompileUnit() const { return AbstractCU; }
163 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
164 void setOffset(unsigned O) { Offset = O; }
165 void setSize(unsigned S) { Size = S; }
166 void setAbstractCompileUnit(CompileUnit *CU) { AbstractCU = CU; }
168 /// AddValue - Add a value and attributes to a DIE.
170 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
171 Abbrev.AddAttribute(Attribute, Form);
172 Values.push_back(Value);
175 /// SiblingOffset - Return the offset of the debug information entry's
176 /// sibling.
177 unsigned SiblingOffset() const { return Offset + Size; }
179 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
181 void AddSiblingOffset();
183 /// AddChild - Add a child to the DIE.
185 void AddChild(DIE *Child) {
186 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
187 Children.push_back(Child);
190 /// Detach - Detaches objects connected to it after copying.
192 void Detach() {
193 Children.clear();
196 /// Profile - Used to gather unique data for the value folding set.
198 void Profile(FoldingSetNodeID &ID) ;
200 #ifndef NDEBUG
201 void print(std::ostream *O, unsigned IncIndent = 0) {
202 if (O) print(*O, IncIndent);
204 void print(std::ostream &O, unsigned IncIndent = 0);
205 void dump();
206 #endif
209 //===--------------------------------------------------------------------===//
210 /// DIEValue - A debug information entry value.
212 class VISIBILITY_HIDDEN DIEValue : public FoldingSetNode {
213 public:
214 enum {
215 isInteger,
216 isString,
217 isLabel,
218 isAsIsLabel,
219 isSectionOffset,
220 isDelta,
221 isEntry,
222 isBlock
224 protected:
225 /// Type - Type of data stored in the value.
227 unsigned Type;
228 public:
229 explicit DIEValue(unsigned T) : Type(T) {}
230 virtual ~DIEValue() {}
232 // Accessors
233 unsigned getType() const { return Type; }
235 /// EmitValue - Emit value via the Dwarf writer.
237 virtual void EmitValue(Dwarf *D, unsigned Form) const = 0;
239 /// SizeOf - Return the size of a value in bytes.
241 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const = 0;
243 /// Profile - Used to gather unique data for the value folding set.
245 virtual void Profile(FoldingSetNodeID &ID) = 0;
247 // Implement isa/cast/dyncast.
248 static bool classof(const DIEValue *) { return true; }
250 #ifndef NDEBUG
251 void print(std::ostream *O) {
252 if (O) print(*O);
254 virtual void print(std::ostream &O) = 0;
255 void dump();
256 #endif
259 //===--------------------------------------------------------------------===//
260 /// DIEInteger - An integer value DIE.
262 class VISIBILITY_HIDDEN DIEInteger : public DIEValue {
263 uint64_t Integer;
264 public:
265 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
267 /// BestForm - Choose the best form for integer.
269 static unsigned BestForm(bool IsSigned, uint64_t Int) {
270 if (IsSigned) {
271 if ((char)Int == (signed)Int) return dwarf::DW_FORM_data1;
272 if ((short)Int == (signed)Int) return dwarf::DW_FORM_data2;
273 if ((int)Int == (signed)Int) return dwarf::DW_FORM_data4;
274 } else {
275 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
276 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
277 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
279 return dwarf::DW_FORM_data8;
282 /// EmitValue - Emit integer of appropriate size.
284 virtual void EmitValue(Dwarf *D, unsigned Form) const;
286 /// SizeOf - Determine size of integer value in bytes.
288 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
290 /// Profile - Used to gather unique data for the value folding set.
292 static void Profile(FoldingSetNodeID &ID, unsigned Int);
293 virtual void Profile(FoldingSetNodeID &ID);
295 // Implement isa/cast/dyncast.
296 static bool classof(const DIEInteger *) { return true; }
297 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
299 #ifndef NDEBUG
300 virtual void print(std::ostream &O);
301 #endif
304 //===--------------------------------------------------------------------===//
305 /// DIEString - A string value DIE.
307 class VISIBILITY_HIDDEN DIEString : public DIEValue {
308 const std::string Str;
309 public:
310 explicit DIEString(const std::string &S) : DIEValue(isString), Str(S) {}
312 /// EmitValue - Emit string value.
314 virtual void EmitValue(Dwarf *D, unsigned Form) const;
316 /// SizeOf - Determine size of string value in bytes.
318 virtual unsigned SizeOf(const TargetData *, unsigned /*Form*/) const {
319 return Str.size() + sizeof(char); // sizeof('\0');
322 /// Profile - Used to gather unique data for the value folding set.
324 static void Profile(FoldingSetNodeID &ID, const std::string &Str);
325 virtual void Profile(FoldingSetNodeID &ID);
327 // Implement isa/cast/dyncast.
328 static bool classof(const DIEString *) { return true; }
329 static bool classof(const DIEValue *S) { return S->getType() == isString; }
331 #ifndef NDEBUG
332 virtual void print(std::ostream &O);
333 #endif
336 //===--------------------------------------------------------------------===//
337 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
339 class VISIBILITY_HIDDEN DIEDwarfLabel : public DIEValue {
340 const DWLabel Label;
341 public:
342 explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
344 /// EmitValue - Emit label value.
346 virtual void EmitValue(Dwarf *D, unsigned Form) const;
348 /// SizeOf - Determine size of label value in bytes.
350 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
352 /// Profile - Used to gather unique data for the value folding set.
354 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label);
355 virtual void Profile(FoldingSetNodeID &ID);
357 // Implement isa/cast/dyncast.
358 static bool classof(const DIEDwarfLabel *) { return true; }
359 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
361 #ifndef NDEBUG
362 virtual void print(std::ostream &O);
363 #endif
366 //===--------------------------------------------------------------------===//
367 /// DIEObjectLabel - A label to an object in code or data.
369 class VISIBILITY_HIDDEN DIEObjectLabel : public DIEValue {
370 const std::string Label;
371 public:
372 explicit DIEObjectLabel(const std::string &L)
373 : DIEValue(isAsIsLabel), Label(L) {}
375 /// EmitValue - Emit label value.
377 virtual void EmitValue(Dwarf *D, unsigned Form) const;
379 /// SizeOf - Determine size of label value in bytes.
381 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
383 /// Profile - Used to gather unique data for the value folding set.
385 static void Profile(FoldingSetNodeID &ID, const std::string &Label);
386 virtual void Profile(FoldingSetNodeID &ID);
388 // Implement isa/cast/dyncast.
389 static bool classof(const DIEObjectLabel *) { return true; }
390 static bool classof(const DIEValue *L) {
391 return L->getType() == isAsIsLabel;
394 #ifndef NDEBUG
395 virtual void print(std::ostream &O);
396 #endif
399 //===--------------------------------------------------------------------===//
400 /// DIESectionOffset - A section offset DIE.
402 class VISIBILITY_HIDDEN DIESectionOffset : public DIEValue {
403 const DWLabel Label;
404 const DWLabel Section;
405 bool IsEH : 1;
406 bool UseSet : 1;
407 public:
408 DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec,
409 bool isEH = false, bool useSet = true)
410 : DIEValue(isSectionOffset), Label(Lab), Section(Sec),
411 IsEH(isEH), UseSet(useSet) {}
413 /// EmitValue - Emit section offset.
415 virtual void EmitValue(Dwarf *D, unsigned Form) const;
417 /// SizeOf - Determine size of section offset value in bytes.
419 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
421 /// Profile - Used to gather unique data for the value folding set.
423 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label,
424 const DWLabel &Section);
425 virtual void Profile(FoldingSetNodeID &ID);
427 // Implement isa/cast/dyncast.
428 static bool classof(const DIESectionOffset *) { return true; }
429 static bool classof(const DIEValue *D) {
430 return D->getType() == isSectionOffset;
433 #ifndef NDEBUG
434 virtual void print(std::ostream &O);
435 #endif
438 //===--------------------------------------------------------------------===//
439 /// DIEDelta - A simple label difference DIE.
441 class VISIBILITY_HIDDEN DIEDelta : public DIEValue {
442 const DWLabel LabelHi;
443 const DWLabel LabelLo;
444 public:
445 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
446 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
448 /// EmitValue - Emit delta value.
450 virtual void EmitValue(Dwarf *D, unsigned Form) const;
452 /// SizeOf - Determine size of delta value in bytes.
454 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
456 /// Profile - Used to gather unique data for the value folding set.
458 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
459 const DWLabel &LabelLo);
460 virtual void Profile(FoldingSetNodeID &ID);
462 // Implement isa/cast/dyncast.
463 static bool classof(const DIEDelta *) { return true; }
464 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
466 #ifndef NDEBUG
467 virtual void print(std::ostream &O);
468 #endif
471 //===--------------------------------------------------------------------===//
472 /// DIEntry - A pointer to another debug information entry. An instance of
473 /// this class can also be used as a proxy for a debug information entry not
474 /// yet defined (ie. types.)
475 class VISIBILITY_HIDDEN DIEEntry : public DIEValue {
476 DIE *Entry;
477 public:
478 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
480 DIE *getEntry() const { return Entry; }
481 void setEntry(DIE *E) { Entry = E; }
483 /// EmitValue - Emit debug information entry offset.
485 virtual void EmitValue(Dwarf *D, unsigned Form) const;
487 /// SizeOf - Determine size of debug information entry in bytes.
489 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const {
490 return sizeof(int32_t);
493 /// Profile - Used to gather unique data for the value folding set.
495 static void Profile(FoldingSetNodeID &ID, DIE *Entry);
496 virtual void Profile(FoldingSetNodeID &ID);
498 // Implement isa/cast/dyncast.
499 static bool classof(const DIEEntry *) { return true; }
500 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
502 #ifndef NDEBUG
503 virtual void print(std::ostream &O);
504 #endif
507 //===--------------------------------------------------------------------===//
508 /// DIEBlock - A block of values. Primarily used for location expressions.
510 class VISIBILITY_HIDDEN DIEBlock : public DIEValue, public DIE {
511 unsigned Size; // Size in bytes excluding size header.
512 public:
513 DIEBlock()
514 : DIEValue(isBlock), DIE(0), Size(0) {}
515 virtual ~DIEBlock() {}
517 /// ComputeSize - calculate the size of the block.
519 unsigned ComputeSize(const TargetData *TD);
521 /// BestForm - Choose the best form for data.
523 unsigned BestForm() const {
524 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
525 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
526 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
527 return dwarf::DW_FORM_block;
530 /// EmitValue - Emit block data.
532 virtual void EmitValue(Dwarf *D, unsigned Form) const;
534 /// SizeOf - Determine size of block data in bytes.
536 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
538 /// Profile - Used to gather unique data for the value folding set.
540 virtual void Profile(FoldingSetNodeID &ID);
542 // Implement isa/cast/dyncast.
543 static bool classof(const DIEBlock *) { return true; }
544 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
546 #ifndef NDEBUG
547 virtual void print(std::ostream &O);
548 #endif
551 } // end llvm namespace
553 #endif