]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - lib/CodeGen/AsmPrinter/DIE.h
Debug info: Implement (rvalue) reference qualifiers for C++11 non-static
[opencl/llvm.git] / lib / CodeGen / AsmPrinter / DIE.h
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 "llvm/ADT/FoldingSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/Dwarf.h"
21 #include "llvm/MC/MCExpr.h"
22 #include <vector>
24 namespace llvm {
25   class AsmPrinter;
26   class MCSymbol;
27   class MCSymbolRefExpr;
28   class raw_ostream;
29   class DwarfTypeUnit;
31   //===--------------------------------------------------------------------===//
32   /// DIEAbbrevData - Dwarf abbreviation data, describes one attribute of a
33   /// Dwarf abbreviation.
34   class DIEAbbrevData {
35     /// Attribute - Dwarf attribute code.
36     ///
37     dwarf::Attribute Attribute;
39     /// Form - Dwarf form code.
40     ///
41     dwarf::Form Form;
42   public:
43     DIEAbbrevData(dwarf::Attribute A, dwarf::Form F) : Attribute(A), Form(F) {}
45     // Accessors.
46     dwarf::Attribute getAttribute() const { return Attribute; }
47     dwarf::Form getForm() const { return Form; }
49     /// Profile - Used to gather unique data for the abbreviation folding set.
50     ///
51     void Profile(FoldingSetNodeID &ID) const;
52   };
54   //===--------------------------------------------------------------------===//
55   /// DIEAbbrev - Dwarf abbreviation, describes the organization of a debug
56   /// information object.
57   class DIEAbbrev : public FoldingSetNode {
58     /// Tag - Dwarf tag code.
59     ///
60     dwarf::Tag Tag;
62     /// ChildrenFlag - Dwarf children flag.
63     ///
64     uint16_t ChildrenFlag;
66     /// Unique number for node.
67     ///
68     unsigned Number;
70     /// Data - Raw data bytes for abbreviation.
71     ///
72     SmallVector<DIEAbbrevData, 12> Data;
74   public:
75     DIEAbbrev(dwarf::Tag T, uint16_t C) : Tag(T), ChildrenFlag(C), Data() {}
77     // Accessors.
78     dwarf::Tag getTag() const { return Tag; }
79     unsigned getNumber() const { return Number; }
80     uint16_t getChildrenFlag() const { return ChildrenFlag; }
81     const SmallVectorImpl<DIEAbbrevData> &getData() const { return Data; }
82     void setChildrenFlag(uint16_t 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(dwarf::Attribute Attribute, dwarf::Form Form) {
88       Data.push_back(DIEAbbrevData(Attribute, Form));
89     }
91     /// Profile - Used to gather unique data for the abbreviation folding set.
92     ///
93     void Profile(FoldingSetNodeID &ID) const;
95     /// Emit - Print the abbreviation using the specified asm printer.
96     ///
97     void Emit(AsmPrinter *AP) const;
99 #ifndef NDEBUG
100     void print(raw_ostream &O);
101     void dump();
102 #endif
103   };
105   //===--------------------------------------------------------------------===//
106   /// DIE - A structured debug information entry.  Has an abbreviation which
107   /// describes its organization.
108   class DIEValue;
110   class DIE {
111   protected:
112     /// Offset - Offset in debug info section.
113     ///
114     unsigned Offset;
116     /// Size - Size of instance + children.
117     ///
118     unsigned Size;
120     /// Abbrev - Buffer for constructing abbreviation.
121     ///
122     DIEAbbrev Abbrev;
124     /// Children DIEs.
125     ///
126     std::vector<DIE *> Children;
128     DIE *Parent;
130     /// Attribute values.
131     ///
132     SmallVector<DIEValue*, 12> Values;
134   public:
135     explicit DIE(unsigned Tag)
136         : Offset(0), Size(0), Abbrev((dwarf::Tag)Tag, dwarf::DW_CHILDREN_no),
137           Parent(0) {}
138     ~DIE();
140     // Accessors.
141     DIEAbbrev &getAbbrev() { return Abbrev; }
142     const DIEAbbrev &getAbbrev() const { return Abbrev; }
143     unsigned getAbbrevNumber() const { return Abbrev.getNumber(); }
144     dwarf::Tag 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; }
148     const SmallVectorImpl<DIEValue*> &getValues() const { return Values; }
149     DIE *getParent() const { return Parent; }
150     /// 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
154     /// owner yet.
155     const DIE *getUnitOrNull() const;
156     void setOffset(unsigned O) { Offset = O; }
157     void setSize(unsigned S) { Size = S; }
159     /// addValue - Add a value and attributes to a DIE.
160     ///
161     void addValue(dwarf::Attribute Attribute, dwarf::Form Form,
162                   DIEValue *Value) {
163       Abbrev.AddAttribute(Attribute, Form);
164       Values.push_back(Value);
165     }
167     /// addChild - Add a child to the DIE.
168     ///
169     void addChild(DIE *Child) {
170       assert(!Child->getParent());
171       Abbrev.setChildrenFlag(dwarf::DW_CHILDREN_yes);
172       Children.push_back(Child);
173       Child->Parent = this;
174     }
176     /// findAttribute - Find a value in the DIE with the attribute given,
177     /// returns NULL if no such attribute exists.
178     DIEValue *findAttribute(uint16_t Attribute) const;
180 #ifndef NDEBUG
181     void print(raw_ostream &O, unsigned IndentCount = 0) const;
182     void dump();
183 #endif
184   };
186   //===--------------------------------------------------------------------===//
187   /// DIEValue - A debug information entry value.
188   ///
189   class DIEValue {
190     virtual void anchor();
191   public:
192     enum {
193       isInteger,
194       isString,
195       isExpr,
196       isLabel,
197       isDelta,
198       isEntry,
199       isTypeSignature,
200       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() {}
210     // Accessors
211     unsigned getType()  const { return Type; }
213     /// EmitValue - Emit value via the Dwarf writer.
214     ///
215     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const = 0;
217     /// SizeOf - Return the size of a value in bytes.
218     ///
219     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const = 0;
221 #ifndef NDEBUG
222     virtual void print(raw_ostream &O) const = 0;
223     void dump() const;
224 #endif
225   };
227   //===--------------------------------------------------------------------===//
228   /// DIEInteger - An integer value DIE.
229   ///
230   class DIEInteger : public DIEValue {
231     uint64_t Integer;
232   public:
233     explicit DIEInteger(uint64_t I) : DIEValue(isInteger), Integer(I) {}
235     /// BestForm - Choose the best form for integer.
236     ///
237     static dwarf::Form BestForm(bool IsSigned, uint64_t Int) {
238       if (IsSigned) {
239         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;
243       } 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     }
251     /// EmitValue - Emit integer of appropriate size.
252     ///
253     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
255     uint64_t getValue() const { return Integer; }
257     /// SizeOf - Determine size of integer value in bytes.
258     ///
259     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
261     // Implement isa/cast/dyncast.
262     static bool classof(const DIEValue *I) { return I->getType() == isInteger; }
264 #ifndef NDEBUG
265     virtual void print(raw_ostream &O) const;
266 #endif
267   };
269   //===--------------------------------------------------------------------===//
270   /// DIEExpr - An expression DIE.
271   //
272   class DIEExpr : public DIEValue {
273     const MCExpr *Expr;
274   public:
275     explicit DIEExpr(const MCExpr *E) : DIEValue(isExpr), Expr(E) {}
277     /// EmitValue - Emit expression value.
278     ///
279     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
281     /// getValue - Get MCExpr.
282     ///
283     const MCExpr *getValue() const { return Expr; }
285     /// SizeOf - Determine size of expression value in bytes.
286     ///
287     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
289     // Implement isa/cast/dyncast.
290     static bool classof(const DIEValue *E) { return E->getType() == isExpr; }
292 #ifndef NDEBUG
293     virtual void print(raw_ostream &O) const;
294 #endif
295   };
297   //===--------------------------------------------------------------------===//
298   /// DIELabel - A label DIE.
299   //
300   class DIELabel : public DIEValue {
301     const MCSymbol *Label;
302   public:
303     explicit DIELabel(const MCSymbol *L) : DIEValue(isLabel), Label(L) {}
305     /// EmitValue - Emit label value.
306     ///
307     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
309     /// getValue - Get MCSymbol.
310     ///
311     const MCSymbol *getValue() const { return Label; }
313     /// SizeOf - Determine size of label value in bytes.
314     ///
315     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
317     // Implement isa/cast/dyncast.
318     static bool classof(const DIEValue *L) { return L->getType() == isLabel; }
320 #ifndef NDEBUG
321     virtual void print(raw_ostream &O) const;
322 #endif
323   };
325   //===--------------------------------------------------------------------===//
326   /// DIEDelta - A simple label difference DIE.
327   ///
328   class DIEDelta : public DIEValue {
329     const MCSymbol *LabelHi;
330     const MCSymbol *LabelLo;
331   public:
332     DIEDelta(const MCSymbol *Hi, const MCSymbol *Lo)
333       : DIEValue(isDelta), LabelHi(Hi), LabelLo(Lo) {}
335     /// EmitValue - Emit delta value.
336     ///
337     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
339     /// SizeOf - Determine size of delta value in bytes.
340     ///
341     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
343     // Implement isa/cast/dyncast.
344     static bool classof(const DIEValue *D) { return D->getType() == isDelta; }
346 #ifndef NDEBUG
347     virtual void print(raw_ostream &O) const;
348 #endif
349   };
351   //===--------------------------------------------------------------------===//
352   /// DIEString - A container for string values.
353   ///
354   class DIEString : public DIEValue {
355     const DIEValue *Access;
356     const StringRef Str;
358   public:
359     DIEString(const DIEValue *Acc, const StringRef S)
360         : DIEValue(isString), Access(Acc), Str(S) {}
362     /// getString - Grab the string out of the object.
363     StringRef getString() const { return Str; }
365     /// EmitValue - Emit delta value.
366     ///
367     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
369     /// SizeOf - Determine size of delta value in bytes.
370     ///
371     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
373     // Implement isa/cast/dyncast.
374     static bool classof(const DIEValue *D) { return D->getType() == isString; }
376   #ifndef NDEBUG
377     virtual void print(raw_ostream &O) const;
378   #endif
379   };
381   //===--------------------------------------------------------------------===//
382   /// DIEEntry - A pointer to another debug information entry.  An instance of
383   /// this class can also be used as a proxy for a debug information entry not
384   /// yet defined (ie. types.)
385   class DIEEntry : public DIEValue {
386     DIE *const Entry;
387   public:
388     explicit DIEEntry(DIE *E) : DIEValue(isEntry), Entry(E) {
389       assert(E && "Cannot construct a DIEEntry with a null DIE");
390     }
392     DIE *getEntry() const { return Entry; }
394     /// EmitValue - Emit debug information entry offset.
395     ///
396     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
398     /// SizeOf - Determine size of debug information entry in bytes.
399     ///
400     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
401       return Form == dwarf::DW_FORM_ref_addr ? getRefAddrSize(AP)
402                                              : sizeof(int32_t);
403     }
405     /// Returns size of a ref_addr entry.
406     static unsigned getRefAddrSize(AsmPrinter *AP);
408     // Implement isa/cast/dyncast.
409     static bool classof(const DIEValue *E) { return E->getType() == isEntry; }
411 #ifndef NDEBUG
412     virtual void print(raw_ostream &O) const;
413 #endif
414   };
416   //===--------------------------------------------------------------------===//
417   /// \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) {}
424     /// \brief Emit type unit signature.
425     virtual void EmitValue(AsmPrinter *Asm, dwarf::Form Form) const;
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     }
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   };
443   //===--------------------------------------------------------------------===//
444   /// DIEBlock - A block of values.  Primarily used for location expressions.
445   //
446   class DIEBlock : public DIEValue, public DIE {
447     unsigned Size;                // Size in bytes excluding size header.
448   public:
449     DIEBlock() : DIEValue(isBlock), DIE(0), Size(0) {}
451     /// ComputeSize - calculate the size of the block.
452     ///
453     unsigned ComputeSize(AsmPrinter *AP);
455     /// BestForm - Choose the best form for data.
456     ///
457     dwarf::Form BestForm() const {
458       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     }
464     /// EmitValue - Emit block data.
465     ///
466     virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
468     /// SizeOf - Determine size of block data in bytes.
469     ///
470     virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
472     // Implement isa/cast/dyncast.
473     static bool classof(const DIEValue *E) { return E->getType() == isBlock; }
475 #ifndef NDEBUG
476     virtual void print(raw_ostream &O) const;
477 #endif
478   };
480 } // end llvm namespace
482 #endif