Fix comment for consistency sake.
[llvm/avr.git] / lib / CodeGen / AsmPrinter / DIE.h
blob62b51ecd18ac60e0e076681dc428f5652793b27d
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 <vector>
24 namespace llvm {
25 class AsmPrinter;
26 class Dwarf;
27 class TargetData;
29 //===--------------------------------------------------------------------===//
30 /// DIEAbbrevData - Dwarf abbreviation data, describes the one attribute of a
31 /// Dwarf abbreviation.
32 class VISIBILITY_HIDDEN DIEAbbrevData {
33 /// Attribute - Dwarf attribute code.
34 ///
35 unsigned Attribute;
37 /// Form - Dwarf form code.
38 ///
39 unsigned Form;
40 public:
41 DIEAbbrevData(unsigned A, unsigned F) : Attribute(A), Form(F) {}
43 // Accessors.
44 unsigned getAttribute() const { return Attribute; }
45 unsigned getForm() const { return Form; }
47 /// Profile - Used to gather unique data for the abbreviation folding set.
48 ///
49 void Profile(FoldingSetNodeID &ID) const;
52 //===--------------------------------------------------------------------===//
53 /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
54 /// information object.
55 class VISIBILITY_HIDDEN DIEAbbrev : public FoldingSetNode {
56 /// Tag - Dwarf tag code.
57 ///
58 unsigned Tag;
60 /// Unique number for node.
61 ///
62 unsigned Number;
64 /// ChildrenFlag - Dwarf children flag.
65 ///
66 unsigned ChildrenFlag;
68 /// Data - Raw data bytes for abbreviation.
69 ///
70 SmallVector<DIEAbbrevData, 8> Data;
71 public:
72 DIEAbbrev(unsigned T, unsigned C) : Tag(T), ChildrenFlag(C), Data() {}
73 virtual ~DIEAbbrev() {}
75 // Accessors.
76 unsigned getTag() const { return Tag; }
77 unsigned getNumber() const { return Number; }
78 unsigned getChildrenFlag() const { return ChildrenFlag; }
79 const SmallVector<DIEAbbrevData, 8> &getData() const { return Data; }
80 void setTag(unsigned T) { Tag = T; }
81 void setChildrenFlag(unsigned CF) { ChildrenFlag = CF; }
82 void setNumber(unsigned N) { Number = N; }
84 /// AddAttribute - Adds another set of attribute information to the
85 /// abbreviation.
86 void AddAttribute(unsigned Attribute, unsigned Form) {
87 Data.push_back(DIEAbbrevData(Attribute, Form));
90 /// AddFirstAttribute - Adds a set of attribute information to the front
91 /// of the abbreviation.
92 void AddFirstAttribute(unsigned Attribute, unsigned Form) {
93 Data.insert(Data.begin(), DIEAbbrevData(Attribute, Form));
96 /// Profile - Used to gather unique data for the abbreviation folding set.
97 ///
98 void Profile(FoldingSetNodeID &ID) const;
100 /// Emit - Print the abbreviation using the specified asm printer.
102 void Emit(const AsmPrinter *Asm) const;
104 #ifndef NDEBUG
105 void print(raw_ostream &O);
106 void dump();
107 #endif
110 //===--------------------------------------------------------------------===//
111 /// DIE - A structured debug information entry. Has an abbreviation which
112 /// describes it's organization.
113 class CompileUnit;
114 class DIEValue;
116 class VISIBILITY_HIDDEN DIE : public FoldingSetNode {
117 protected:
118 /// Abbrev - Buffer for constructing abbreviation.
120 DIEAbbrev Abbrev;
122 /// Offset - Offset in debug info section.
124 unsigned Offset;
126 /// Size - Size of instance + children.
128 unsigned Size;
130 /// Children DIEs.
132 std::vector<DIE *> Children;
134 /// Attributes values.
136 SmallVector<DIEValue*, 32> Values;
138 /// Abstract compile unit.
139 CompileUnit *AbstractCU;
141 // Private data for print()
142 mutable unsigned IndentCount;
143 public:
144 explicit DIE(unsigned Tag)
145 : Abbrev(Tag, dwarf::DW_CHILDREN_no), Offset(0),
146 Size(0), IndentCount(0) {}
147 virtual ~DIE();
149 // Accessors.
150 DIEAbbrev &getAbbrev() { return Abbrev; }
151 unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
152 unsigned getTag() const { return Abbrev.getTag(); }
153 unsigned getOffset() const { return Offset; }
154 unsigned getSize() const { return Size; }
155 const std::vector<DIE *> &getChildren() const { return Children; }
156 SmallVector<DIEValue*, 32> &getValues() { return Values; }
157 CompileUnit *getAbstractCompileUnit() const { return AbstractCU; }
159 void setTag(unsigned Tag) { Abbrev.setTag(Tag); }
160 void setOffset(unsigned O) { Offset = O; }
161 void setSize(unsigned S) { Size = S; }
162 void setAbstractCompileUnit(CompileUnit *CU) { AbstractCU = CU; }
164 /// AddValue - Add a value and attributes to a DIE.
166 void AddValue(unsigned Attribute, unsigned Form, DIEValue *Value) {
167 Abbrev.AddAttribute(Attribute, Form);
168 Values.push_back(Value);
171 /// SiblingOffset - Return the offset of the debug information entry's
172 /// sibling.
173 unsigned SiblingOffset() const { return Offset + Size; }
175 /// AddSiblingOffset - Add a sibling offset field to the front of the DIE.
177 void AddSiblingOffset();
179 /// AddChild - Add a child to the DIE.
181 void AddChild(DIE *Child) {
182 Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
183 Children.push_back(Child);
186 /// Detach - Detaches objects connected to it after copying.
188 void Detach() {
189 Children.clear();
192 /// Profile - Used to gather unique data for the value folding set.
194 void Profile(FoldingSetNodeID &ID) ;
196 #ifndef NDEBUG
197 void print(raw_ostream &O, unsigned IncIndent = 0);
198 void dump();
199 #endif
202 //===--------------------------------------------------------------------===//
203 /// DIEValue - A debug information entry value.
205 class VISIBILITY_HIDDEN DIEValue : public FoldingSetNode {
206 public:
207 enum {
208 isInteger,
209 isString,
210 isLabel,
211 isAsIsLabel,
212 isSectionOffset,
213 isDelta,
214 isEntry,
215 isBlock
217 protected:
218 /// Type - Type of data stored in the value.
220 unsigned Type;
221 public:
222 explicit DIEValue(unsigned T) : Type(T) {}
223 virtual ~DIEValue() {}
225 // Accessors
226 unsigned getType() const { return Type; }
228 /// EmitValue - Emit value via the Dwarf writer.
230 virtual void EmitValue(Dwarf *D, unsigned Form) const = 0;
232 /// SizeOf - Return the size of a value in bytes.
234 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const = 0;
236 /// Profile - Used to gather unique data for the value folding set.
238 virtual void Profile(FoldingSetNodeID &ID) = 0;
240 // Implement isa/cast/dyncast.
241 static bool classof(const DIEValue *) { return true; }
243 #ifndef NDEBUG
244 virtual void print(raw_ostream &O) = 0;
245 void dump();
246 #endif
249 //===--------------------------------------------------------------------===//
250 /// DIEInteger - An integer value DIE.
252 class VISIBILITY_HIDDEN DIEInteger : public DIEValue {
253 uint64_t Integer;
254 public:
255 explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
257 /// BestForm - Choose the best form for integer.
259 static unsigned BestForm(bool IsSigned, uint64_t Int) {
260 if (IsSigned) {
261 if ((char)Int == (signed)Int) return dwarf::DW_FORM_data1;
262 if ((short)Int == (signed)Int) return dwarf::DW_FORM_data2;
263 if ((int)Int == (signed)Int) return dwarf::DW_FORM_data4;
264 } else {
265 if ((unsigned char)Int == Int) return dwarf::DW_FORM_data1;
266 if ((unsigned short)Int == Int) return dwarf::DW_FORM_data2;
267 if ((unsigned int)Int == Int) return dwarf::DW_FORM_data4;
269 return dwarf::DW_FORM_data8;
272 /// EmitValue - Emit integer of appropriate size.
274 virtual void EmitValue(Dwarf *D, unsigned Form) const;
276 /// SizeOf - Determine size of integer value in bytes.
278 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
280 /// Profile - Used to gather unique data for the value folding set.
282 static void Profile(FoldingSetNodeID &ID, unsigned Int);
283 virtual void Profile(FoldingSetNodeID &ID);
285 // Implement isa/cast/dyncast.
286 static bool classof(const DIEInteger *) { return true; }
287 static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
289 #ifndef NDEBUG
290 virtual void print(raw_ostream &O);
291 #endif
294 //===--------------------------------------------------------------------===//
295 /// DIEString - A string value DIE.
297 class VISIBILITY_HIDDEN DIEString : public DIEValue {
298 const std::string Str;
299 public:
300 explicit DIEString(const std::string &S) : DIEValue(isString), Str(S) {}
302 /// EmitValue - Emit string value.
304 virtual void EmitValue(Dwarf *D, unsigned Form) const;
306 /// SizeOf - Determine size of string value in bytes.
308 virtual unsigned SizeOf(const TargetData *, unsigned /*Form*/) const {
309 return Str.size() + sizeof(char); // sizeof('\0');
312 /// Profile - Used to gather unique data for the value folding set.
314 static void Profile(FoldingSetNodeID &ID, const std::string &Str);
315 virtual void Profile(FoldingSetNodeID &ID);
317 // Implement isa/cast/dyncast.
318 static bool classof(const DIEString *) { return true; }
319 static bool classof(const DIEValue *S) { return S->getType() == isString; }
321 #ifndef NDEBUG
322 virtual void print(raw_ostream &O);
323 #endif
326 //===--------------------------------------------------------------------===//
327 /// DIEDwarfLabel - A Dwarf internal label expression DIE.
329 class VISIBILITY_HIDDEN DIEDwarfLabel : public DIEValue {
330 const DWLabel Label;
331 public:
332 explicit DIEDwarfLabel(const DWLabel &L) : DIEValue(isLabel), Label(L) {}
334 /// EmitValue - Emit label value.
336 virtual void EmitValue(Dwarf *D, unsigned Form) const;
338 /// SizeOf - Determine size of label value in bytes.
340 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
342 /// Profile - Used to gather unique data for the value folding set.
344 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label);
345 virtual void Profile(FoldingSetNodeID &ID);
347 // Implement isa/cast/dyncast.
348 static bool classof(const DIEDwarfLabel *) { return true; }
349 static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
351 #ifndef NDEBUG
352 virtual void print(raw_ostream &O);
353 #endif
356 //===--------------------------------------------------------------------===//
357 /// DIEObjectLabel - A label to an object in code or data.
359 class VISIBILITY_HIDDEN DIEObjectLabel : public DIEValue {
360 const std::string Label;
361 public:
362 explicit DIEObjectLabel(const std::string &L)
363 : DIEValue(isAsIsLabel), Label(L) {}
365 /// EmitValue - Emit label value.
367 virtual void EmitValue(Dwarf *D, unsigned Form) const;
369 /// SizeOf - Determine size of label value in bytes.
371 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
373 /// Profile - Used to gather unique data for the value folding set.
375 static void Profile(FoldingSetNodeID &ID, const std::string &Label);
376 virtual void Profile(FoldingSetNodeID &ID);
378 // Implement isa/cast/dyncast.
379 static bool classof(const DIEObjectLabel *) { return true; }
380 static bool classof(const DIEValue *L) {
381 return L->getType() == isAsIsLabel;
384 #ifndef NDEBUG
385 virtual void print(raw_ostream &O);
386 #endif
389 //===--------------------------------------------------------------------===//
390 /// DIESectionOffset - A section offset DIE.
392 class VISIBILITY_HIDDEN DIESectionOffset : public DIEValue {
393 const DWLabel Label;
394 const DWLabel Section;
395 bool IsEH : 1;
396 bool UseSet : 1;
397 public:
398 DIESectionOffset(const DWLabel &Lab, const DWLabel &Sec,
399 bool isEH = false, bool useSet = true)
400 : DIEValue(isSectionOffset), Label(Lab), Section(Sec),
401 IsEH(isEH), UseSet(useSet) {}
403 /// EmitValue - Emit section offset.
405 virtual void EmitValue(Dwarf *D, unsigned Form) const;
407 /// SizeOf - Determine size of section offset value in bytes.
409 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
411 /// Profile - Used to gather unique data for the value folding set.
413 static void Profile(FoldingSetNodeID &ID, const DWLabel &Label,
414 const DWLabel &Section);
415 virtual void Profile(FoldingSetNodeID &ID);
417 // Implement isa/cast/dyncast.
418 static bool classof(const DIESectionOffset *) { return true; }
419 static bool classof(const DIEValue *D) {
420 return D->getType() == isSectionOffset;
423 #ifndef NDEBUG
424 virtual void print(raw_ostream &O);
425 #endif
428 //===--------------------------------------------------------------------===//
429 /// DIEDelta - A simple label difference DIE.
431 class VISIBILITY_HIDDEN DIEDelta : public DIEValue {
432 const DWLabel LabelHi;
433 const DWLabel LabelLo;
434 public:
435 DIEDelta(const DWLabel &Hi, const DWLabel &Lo)
436 : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
438 /// EmitValue - Emit delta value.
440 virtual void EmitValue(Dwarf *D, unsigned Form) const;
442 /// SizeOf - Determine size of delta value in bytes.
444 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
446 /// Profile - Used to gather unique data for the value folding set.
448 static void Profile(FoldingSetNodeID &ID, const DWLabel &LabelHi,
449 const DWLabel &LabelLo);
450 virtual void Profile(FoldingSetNodeID &ID);
452 // Implement isa/cast/dyncast.
453 static bool classof(const DIEDelta *) { return true; }
454 static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
456 #ifndef NDEBUG
457 virtual void print(raw_ostream &O);
458 #endif
461 //===--------------------------------------------------------------------===//
462 /// DIEntry - A pointer to another debug information entry. An instance of
463 /// this class can also be used as a proxy for a debug information entry not
464 /// yet defined (ie. types.)
465 class VISIBILITY_HIDDEN DIEEntry : public DIEValue {
466 DIE *Entry;
467 public:
468 explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {}
470 DIE *getEntry() const { return Entry; }
471 void setEntry(DIE *E) { Entry = E; }
473 /// EmitValue - Emit debug information entry offset.
475 virtual void EmitValue(Dwarf *D, unsigned Form) const;
477 /// SizeOf - Determine size of debug information entry in bytes.
479 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const {
480 return sizeof(int32_t);
483 /// Profile - Used to gather unique data for the value folding set.
485 static void Profile(FoldingSetNodeID &ID, DIE *Entry);
486 virtual void Profile(FoldingSetNodeID &ID);
488 // Implement isa/cast/dyncast.
489 static bool classof(const DIEEntry *) { return true; }
490 static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
492 #ifndef NDEBUG
493 virtual void print(raw_ostream &O);
494 #endif
497 //===--------------------------------------------------------------------===//
498 /// DIEBlock - A block of values. Primarily used for location expressions.
500 class VISIBILITY_HIDDEN DIEBlock : public DIEValue, public DIE {
501 unsigned Size; // Size in bytes excluding size header.
502 public:
503 DIEBlock()
504 : DIEValue(isBlock), DIE(0), Size(0) {}
505 virtual ~DIEBlock() {}
507 /// ComputeSize - calculate the size of the block.
509 unsigned ComputeSize(const TargetData *TD);
511 /// BestForm - Choose the best form for data.
513 unsigned BestForm() const {
514 if ((unsigned char)Size == Size) return dwarf::DW_FORM_block1;
515 if ((unsigned short)Size == Size) return dwarf::DW_FORM_block2;
516 if ((unsigned int)Size == Size) return dwarf::DW_FORM_block4;
517 return dwarf::DW_FORM_block;
520 /// EmitValue - Emit block data.
522 virtual void EmitValue(Dwarf *D, unsigned Form) const;
524 /// SizeOf - Determine size of block data in bytes.
526 virtual unsigned SizeOf(const TargetData *TD, unsigned Form) const;
528 /// Profile - Used to gather unique data for the value folding set.
530 virtual void Profile(FoldingSetNodeID &ID);
532 // Implement isa/cast/dyncast.
533 static bool classof(const DIEBlock *) { return true; }
534 static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
536 #ifndef NDEBUG
537 virtual void print(raw_ostream &O);
538 #endif
541 } // end llvm namespace
543 #endif