3a3f1660c937cabad259d06e43be5c3ea42862e0
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfUnit.h
1 //===-- llvm/CodeGen/DwarfUnit.h - Dwarf Compile Unit ---*- 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 // This file contains support for writing dwarf compile unit.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
16
17 #include "DIE.h"
18 #include "DwarfDebug.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/Optional.h"
21 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/IR/DIBuilder.h"
24 #include "llvm/IR/DebugInfo.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCSection.h"
27
28 namespace llvm {
29
30 class MachineLocation;
31 class MachineOperand;
32 class ConstantInt;
33 class ConstantFP;
34 class DbgVariable;
35 class DwarfCompileUnit;
36
37 // Data structure to hold a range for range lists.
38 class RangeSpan {
39 public:
40   RangeSpan(MCSymbol *S, MCSymbol *E) : Start(S), End(E) {}
41   const MCSymbol *getStart() const { return Start; }
42   const MCSymbol *getEnd() const { return End; }
43
44 private:
45   const MCSymbol *Start, *End;
46 };
47
48 class RangeSpanList {
49 private:
50   // Index for locating within the debug_range section this particular span.
51   MCSymbol *RangeSym;
52   // List of ranges.
53   SmallVector<RangeSpan, 2> Ranges;
54
55 public:
56   RangeSpanList(MCSymbol *Sym) : RangeSym(Sym) {}
57   MCSymbol *getSym() const { return RangeSym; }
58   const SmallVectorImpl<RangeSpan> &getRanges() const { return Ranges; }
59   void addRange(RangeSpan Range) { Ranges.push_back(Range); }
60 };
61
62 //===----------------------------------------------------------------------===//
63 /// Unit - This dwarf writer support class manages information associated
64 /// with a source file.
65 class DwarfUnit {
66 protected:
67   /// UniqueID - a numeric ID unique among all CUs in the module
68   unsigned UniqueID;
69
70   /// Node - MDNode for the compile unit.
71   DICompileUnit CUNode;
72
73   /// Unit debug information entry.
74   const OwningPtr<DIE> UnitDie;
75
76   /// Offset of the UnitDie from beginning of debug info section.
77   unsigned DebugInfoOffset;
78
79   /// Asm - Target of Dwarf emission.
80   AsmPrinter *Asm;
81
82   // Holders for some common dwarf information.
83   DwarfDebug *DD;
84   DwarfFile *DU;
85
86   /// IndexTyDie - An anonymous type for index type.  Owned by UnitDie.
87   DIE *IndexTyDie;
88
89   /// MDNodeToDieMap - Tracks the mapping of unit level debug information
90   /// variables to debug information entries.
91   DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
92
93   /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug information
94   /// descriptors to debug information entries using a DIEEntry proxy.
95   DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
96
97   /// GlobalNames - A map of globally visible named entities for this unit.
98   StringMap<const DIE *> GlobalNames;
99
100   /// GlobalTypes - A map of globally visible types for this unit.
101   StringMap<const DIE *> GlobalTypes;
102
103   /// AccelNames - A map of names for the name accelerator table.
104   StringMap<std::vector<const DIE *> > AccelNames;
105
106   /// AccelObjC - A map of objc spec for the objc accelerator table.
107   StringMap<std::vector<const DIE *> > AccelObjC;
108
109   /// AccelNamespace - A map of names for the namespace accelerator table.
110   StringMap<std::vector<const DIE *> > AccelNamespace;
111
112   /// AccelTypes - A map of names for the type accelerator table.
113   StringMap<std::vector<std::pair<const DIE *, unsigned> > > AccelTypes;
114
115   /// DIEBlocks - A list of all the DIEBlocks in use.
116   std::vector<DIEBlock *> DIEBlocks;
117   
118   /// DIELocs - A list of all the DIELocs in use.
119   std::vector<DIELoc *> DIELocs;
120
121   /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
122   /// need DW_AT_containing_type attribute. This attribute points to a DIE that
123   /// corresponds to the MDNode mapped with the subprogram DIE.
124   DenseMap<DIE *, const MDNode *> ContainingTypeMap;
125
126   // List of ranges for a given compile unit.
127   SmallVector<RangeSpan, 1> CURanges;
128
129   // List of range lists for a given compile unit, separate from the ranges for
130   // the CU itself.
131   SmallVector<RangeSpanList, 1> CURangeLists;
132
133   // DIEValueAllocator - All DIEValues are allocated through this allocator.
134   BumpPtrAllocator DIEValueAllocator;
135
136   // DIEIntegerOne - A preallocated DIEValue because 1 is used frequently.
137   DIEInteger *DIEIntegerOne;
138
139   /// The section this unit will be emitted in.
140   const MCSection *Section;
141
142   /// A label at the start of the non-dwo section related to this unit.
143   MCSymbol *SectionSym;
144
145   /// The start of the unit within its section.
146   MCSymbol *LabelBegin;
147
148   /// The end of the unit within its section.
149   MCSymbol *LabelEnd;
150
151   /// The label for the start of the range sets for the elements of this unit.
152   MCSymbol *LabelRange;
153
154   /// Skeleton unit associated with this unit.
155   DwarfUnit *Skeleton;
156
157   DwarfUnit(unsigned UID, DIE *D, DICompileUnit CU, AsmPrinter *A,
158             DwarfDebug *DW, DwarfFile *DWU);
159
160 public:
161   virtual ~DwarfUnit();
162
163   /// Set the skeleton unit associated with this unit.
164   void setSkeleton(DwarfUnit *Skel) { Skeleton = Skel; }
165
166   /// Get the skeleton unit associated with this unit.
167   DwarfUnit *getSkeleton() const { return Skeleton; }
168
169   /// Pass in the SectionSym even though we could recreate it in every compile
170   /// unit (type units will have actually distinct symbols once they're in
171   /// comdat sections).
172   void initSection(const MCSection *Section, MCSymbol *SectionSym) {
173     assert(!this->Section);
174     this->Section = Section;
175     this->SectionSym = SectionSym;
176     this->LabelBegin =
177         Asm->GetTempSymbol(Section->getLabelBeginName(), getUniqueID());
178     this->LabelEnd =
179         Asm->GetTempSymbol(Section->getLabelEndName(), getUniqueID());
180     this->LabelRange = Asm->GetTempSymbol("gnu_ranges", getUniqueID());
181   }
182
183   const MCSection *getSection() const {
184     assert(Section);
185     return Section;
186   }
187
188   /// If there's a skeleton then return the section symbol for the skeleton
189   /// unit, otherwise return the section symbol for this unit.
190   MCSymbol *getLocalSectionSym() const {
191     if (Skeleton)
192       return Skeleton->getSectionSym();
193     return getSectionSym();
194   }
195
196   MCSymbol *getSectionSym() const {
197     assert(Section);
198     return SectionSym;
199   }
200
201   /// If there's a skeleton then return the begin label for the skeleton unit,
202   /// otherwise return the local label for this unit.
203   MCSymbol *getLocalLabelBegin() const {
204     if (Skeleton)
205       return Skeleton->getLabelBegin();
206     return getLabelBegin();
207   }
208
209   MCSymbol *getLabelBegin() const {
210     assert(Section);
211     return LabelBegin;
212   }
213
214   MCSymbol *getLabelEnd() const {
215     assert(Section);
216     return LabelEnd;
217   }
218
219   MCSymbol *getLabelRange() const {
220     assert(Section);
221     return LabelRange;
222   }
223
224   // Accessors.
225   unsigned getUniqueID() const { return UniqueID; }
226   uint16_t getLanguage() const { return CUNode.getLanguage(); }
227   DICompileUnit getCUNode() const { return CUNode; }
228   DIE *getUnitDie() const { return UnitDie.get(); }
229   const StringMap<const DIE *> &getGlobalNames() const { return GlobalNames; }
230   const StringMap<const DIE *> &getGlobalTypes() const { return GlobalTypes; }
231
232   const StringMap<std::vector<const DIE *> > &getAccelNames() const {
233     return AccelNames;
234   }
235   const StringMap<std::vector<const DIE *> > &getAccelObjC() const {
236     return AccelObjC;
237   }
238   const StringMap<std::vector<const DIE *> > &getAccelNamespace() const {
239     return AccelNamespace;
240   }
241   const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &
242   getAccelTypes() const {
243     return AccelTypes;
244   }
245
246   unsigned getDebugInfoOffset() const { return DebugInfoOffset; }
247   void setDebugInfoOffset(unsigned DbgInfoOff) { DebugInfoOffset = DbgInfoOff; }
248
249   /// hasContent - Return true if this compile unit has something to write out.
250   bool hasContent() const { return !UnitDie->getChildren().empty(); }
251
252   /// addRange - Add an address range to the list of ranges for this unit.
253   void addRange(RangeSpan Range) {
254     // Only add a range for this unit if we're emitting full debug.
255     if (getCUNode().getEmissionKind() == DIBuilder::FullDebug)
256       CURanges.push_back(Range);
257   }
258
259   /// getRanges - Get the list of ranges for this unit.
260   const SmallVectorImpl<RangeSpan> &getRanges() const { return CURanges; }
261   SmallVectorImpl<RangeSpan> &getRanges() { return CURanges; }
262
263   /// addRangeList - Add an address range list to the list of range lists.
264   void addRangeList(RangeSpanList Ranges) { CURangeLists.push_back(Ranges); }
265
266   /// getRangeLists - Get the vector of range lists.
267   const SmallVectorImpl<RangeSpanList> &getRangeLists() const {
268     return CURangeLists;
269   }
270   SmallVectorImpl<RangeSpanList> &getRangeLists() { return CURangeLists; }
271
272   /// getParentContextString - Get a string containing the language specific
273   /// context for a global name.
274   std::string getParentContextString(DIScope Context) const;
275
276   /// addGlobalName - Add a new global entity to the compile unit.
277   ///
278   void addGlobalName(StringRef Name, DIE *Die, DIScope Context);
279
280   /// addAccelName - Add a new name to the name accelerator table.
281   void addAccelName(StringRef Name, const DIE *Die);
282
283   /// addAccelObjC - Add a new name to the ObjC accelerator table.
284   void addAccelObjC(StringRef Name, const DIE *Die);
285
286   /// addAccelNamespace - Add a new name to the namespace accelerator table.
287   void addAccelNamespace(StringRef Name, const DIE *Die);
288
289   /// addAccelType - Add a new type to the type accelerator table.
290   void addAccelType(StringRef Name, std::pair<const DIE *, unsigned> Die);
291
292   /// getDIE - Returns the debug information entry map slot for the
293   /// specified debug variable. We delegate the request to DwarfDebug
294   /// when the MDNode can be part of the type system, since DIEs for
295   /// the type system can be shared across CUs and the mappings are
296   /// kept in DwarfDebug.
297   DIE *getDIE(DIDescriptor D) const;
298
299   /// getDIELoc - Returns a fresh newly allocated DIELoc.
300   DIELoc *getDIELoc() { return new (DIEValueAllocator) DIELoc(); }
301
302   /// insertDIE - Insert DIE into the map. We delegate the request to DwarfDebug
303   /// when the MDNode can be part of the type system, since DIEs for
304   /// the type system can be shared across CUs and the mappings are
305   /// kept in DwarfDebug.
306   void insertDIE(DIDescriptor Desc, DIE *D);
307
308   /// addDie - Adds or interns the DIE to the compile unit.
309   ///
310   void addDie(DIE *Buffer) { UnitDie->addChild(Buffer); }
311
312   /// addFlag - Add a flag that is true to the DIE.
313   void addFlag(DIE *Die, dwarf::Attribute Attribute);
314
315   /// addUInt - Add an unsigned integer attribute data and value.
316   void addUInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
317                uint64_t Integer);
318
319   void addUInt(DIE *Block, dwarf::Form Form, uint64_t Integer);
320
321   /// addSInt - Add an signed integer attribute data and value.
322   void addSInt(DIE *Die, dwarf::Attribute Attribute, Optional<dwarf::Form> Form,
323                int64_t Integer);
324
325   void addSInt(DIELoc *Die, Optional<dwarf::Form> Form, int64_t Integer);
326
327   /// addString - Add a string attribute data and value.
328   void addString(DIE *Die, dwarf::Attribute Attribute, const StringRef Str);
329
330   /// addLocalString - Add a string attribute data and value.
331   void addLocalString(DIE *Die, dwarf::Attribute Attribute,
332                       const StringRef Str);
333
334   /// addExpr - Add a Dwarf expression attribute data and value.
335   void addExpr(DIELoc *Die, dwarf::Form Form, const MCExpr *Expr);
336
337   /// addLabel - Add a Dwarf label attribute data and value.
338   void addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
339                 const MCSymbol *Label);
340
341   void addLabel(DIELoc *Die, dwarf::Form Form, const MCSymbol *Label);
342
343   /// addLocationList - Add a Dwarf loclistptr attribute data and value.
344   void addLocationList(DIE *Die, dwarf::Attribute Attribute, unsigned Index);
345
346   /// addSectionLabel - Add a Dwarf section label attribute data and value.
347   ///
348   void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,
349                        const MCSymbol *Label);
350
351   /// addSectionOffset - Add an offset into a section attribute data and value.
352   ///
353   void addSectionOffset(DIE *Die, dwarf::Attribute Attribute, uint64_t Integer);
354
355   /// addOpAddress - Add a dwarf op address data and value using the
356   /// form given and an op of either DW_FORM_addr or DW_FORM_GNU_addr_index.
357   void addOpAddress(DIELoc *Die, const MCSymbol *Label);
358
359   /// addSectionDelta - Add a label delta attribute data and value.
360   void addSectionDelta(DIE *Die, dwarf::Attribute Attribute, const MCSymbol *Hi,
361                        const MCSymbol *Lo);
362
363   /// addDIEEntry - Add a DIE attribute data and value.
364   void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIE *Entry);
365
366   /// addDIEEntry - Add a DIE attribute data and value.
367   void addDIEEntry(DIE *Die, dwarf::Attribute Attribute, DIEEntry *Entry);
368
369   void addDIETypeSignature(DIE *Die, const DwarfTypeUnit &Type);
370
371   /// addBlock - Add block data.
372   void addBlock(DIE *Die, dwarf::Attribute Attribute, DIELoc *Block);
373
374   /// addBlock - Add block data.
375   void addBlock(DIE *Die, dwarf::Attribute Attribute, DIEBlock *Block);
376
377   /// addSourceLine - Add location information to specified debug information
378   /// entry.
379   void addSourceLine(DIE *Die, unsigned Line, StringRef File,
380                      StringRef Directory);
381   void addSourceLine(DIE *Die, DIVariable V);
382   void addSourceLine(DIE *Die, DIGlobalVariable G);
383   void addSourceLine(DIE *Die, DISubprogram SP);
384   void addSourceLine(DIE *Die, DIType Ty);
385   void addSourceLine(DIE *Die, DINameSpace NS);
386   void addSourceLine(DIE *Die, DIObjCProperty Ty);
387
388   /// addAddress - Add an address attribute to a die based on the location
389   /// provided.
390   void addAddress(DIE *Die, dwarf::Attribute Attribute,
391                   const MachineLocation &Location, bool Indirect = false);
392
393   /// addConstantValue - Add constant value entry in variable DIE.
394   void addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
395   void addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
396   void addConstantValue(DIE *Die, const APInt &Val, bool Unsigned);
397
398   /// addConstantFPValue - Add constant value entry in variable DIE.
399   void addConstantFPValue(DIE *Die, const MachineOperand &MO);
400   void addConstantFPValue(DIE *Die, const ConstantFP *CFP);
401
402   /// addTemplateParams - Add template parameters in buffer.
403   void addTemplateParams(DIE &Buffer, DIArray TParams);
404
405   /// addRegisterOp - Add register operand.
406   void addRegisterOp(DIELoc *TheDie, unsigned Reg);
407
408   /// addRegisterOffset - Add register offset.
409   void addRegisterOffset(DIELoc *TheDie, unsigned Reg, int64_t Offset);
410
411   /// addComplexAddress - Start with the address based on the location provided,
412   /// and generate the DWARF information necessary to find the actual variable
413   /// (navigating the extra location information encoded in the type) based on
414   /// the starting location.  Add the DWARF information to the die.
415   void addComplexAddress(const DbgVariable &DV, DIE *Die,
416                          dwarf::Attribute Attribute,
417                          const MachineLocation &Location);
418
419   // FIXME: Should be reformulated in terms of addComplexAddress.
420   /// addBlockByrefAddress - Start with the address based on the location
421   /// provided, and generate the DWARF information necessary to find the
422   /// actual Block variable (navigating the Block struct) based on the
423   /// starting location.  Add the DWARF information to the die.  Obsolete,
424   /// please use addComplexAddress instead.
425   void addBlockByrefAddress(const DbgVariable &DV, DIE *Die,
426                             dwarf::Attribute Attribute,
427                             const MachineLocation &Location);
428
429   /// addVariableAddress - Add DW_AT_location attribute for a
430   /// DbgVariable based on provided MachineLocation.
431   void addVariableAddress(const DbgVariable &DV, DIE *Die,
432                           MachineLocation Location);
433
434   /// addType - Add a new type attribute to the specified entity. This takes
435   /// and attribute parameter because DW_AT_friend attributes are also
436   /// type references.
437   void addType(DIE *Entity, DIType Ty,
438                dwarf::Attribute Attribute = dwarf::DW_AT_type);
439
440   /// getOrCreateNameSpace - Create a DIE for DINameSpace.
441   DIE *getOrCreateNameSpace(DINameSpace NS);
442
443   /// getOrCreateSubprogramDIE - Create new DIE using SP.
444   DIE *getOrCreateSubprogramDIE(DISubprogram SP);
445
446   /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
447   /// given DIType.
448   DIE *getOrCreateTypeDIE(const MDNode *N);
449
450   /// getOrCreateContextDIE - Get context owner's DIE.
451   DIE *createTypeDIE(DICompositeType Ty);
452
453   /// getOrCreateContextDIE - Get context owner's DIE.
454   DIE *getOrCreateContextDIE(DIScope Context);
455
456   /// constructContainingTypeDIEs - Construct DIEs for types that contain
457   /// vtables.
458   void constructContainingTypeDIEs();
459
460   /// constructVariableDIE - Construct a DIE for the given DbgVariable.
461   DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
462
463   /// constructSubprogramArguments - Construct function argument DIEs.
464   void constructSubprogramArguments(DIE &Buffer, DIArray Args);
465
466   /// Create a DIE with the given Tag, add the DIE to its parent, and
467   /// call insertDIE if MD is not null.
468   DIE *createAndAddDIE(unsigned Tag, DIE &Parent,
469                        DIDescriptor N = DIDescriptor());
470
471   /// Compute the size of a header for this unit, not including the initial
472   /// length field.
473   virtual unsigned getHeaderSize() const {
474     return sizeof(int16_t) + // DWARF version number
475            sizeof(int32_t) + // Offset Into Abbrev. Section
476            sizeof(int8_t);   // Pointer Size (in bytes)
477   }
478
479   /// Emit the header for this unit, not including the initial length field.
480   virtual void emitHeader(const MCSection *ASection,
481                           const MCSymbol *ASectionSym) const;
482
483   virtual DwarfCompileUnit &getCU() = 0;
484
485 protected:
486   /// getOrCreateStaticMemberDIE - Create new static data member DIE.
487   DIE *getOrCreateStaticMemberDIE(DIDerivedType DT);
488
489 private:
490   /// constructTypeDIE - Construct basic type die from DIBasicType.
491   void constructTypeDIE(DIE &Buffer, DIBasicType BTy);
492
493   /// constructTypeDIE - Construct derived type die from DIDerivedType.
494   void constructTypeDIE(DIE &Buffer, DIDerivedType DTy);
495
496   /// constructTypeDIE - Construct type DIE from DICompositeType.
497   void constructTypeDIE(DIE &Buffer, DICompositeType CTy);
498
499   /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
500   void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
501
502   /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
503   void constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy);
504
505   /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
506   void constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy);
507
508   /// constructMemberDIE - Construct member DIE from DIDerivedType.
509   void constructMemberDIE(DIE &Buffer, DIDerivedType DT);
510
511   /// constructTemplateTypeParameterDIE - Construct new DIE for the given
512   /// DITemplateTypeParameter.
513   void constructTemplateTypeParameterDIE(DIE &Buffer,
514                                          DITemplateTypeParameter TP);
515
516   /// constructTemplateValueParameterDIE - Construct new DIE for the given
517   /// DITemplateValueParameter.
518   void constructTemplateValueParameterDIE(DIE &Buffer,
519                                           DITemplateValueParameter TVP);
520
521   /// getLowerBoundDefault - Return the default lower bound for an array. If the
522   /// DWARF version doesn't handle the language, return -1.
523   int64_t getDefaultLowerBound() const;
524
525   /// getDIEEntry - Returns the debug information entry for the specified
526   /// debug variable.
527   DIEEntry *getDIEEntry(const MDNode *N) const {
528     return MDNodeToDIEEntryMap.lookup(N);
529   }
530
531   /// insertDIEEntry - Insert debug information entry into the map.
532   void insertDIEEntry(const MDNode *N, DIEEntry *E) {
533     MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
534   }
535
536   // getIndexTyDie - Get an anonymous type for index type.
537   DIE *getIndexTyDie() { return IndexTyDie; }
538
539   // setIndexTyDie - Set D as anonymous type for index which can be reused
540   // later.
541   void setIndexTyDie(DIE *D) { IndexTyDie = D; }
542
543   /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
544   /// information entry.
545   DIEEntry *createDIEEntry(DIE *Entry);
546
547   /// resolve - Look in the DwarfDebug map for the MDNode that
548   /// corresponds to the reference.
549   template <typename T> T resolve(DIRef<T> Ref) const {
550     return DD->resolve(Ref);
551   }
552
553   /// If this is a named finished type then include it in the list of types for
554   /// the accelerator tables.
555   void updateAcceleratorTables(DIScope Context, DIType Ty, const DIE *TyDIE);
556 };
557
558 class DwarfCompileUnit : public DwarfUnit {
559   /// The attribute index of DW_AT_stmt_list in the compile unit DIE, avoiding
560   /// the need to search for it in applyStmtList.
561   unsigned stmtListIndex;
562
563 public:
564   DwarfCompileUnit(unsigned UID, DIE *D, DICompileUnit Node, AsmPrinter *A,
565                    DwarfDebug *DW, DwarfFile *DWU);
566
567   void initStmtList(MCSymbol *DwarfLineSectionSym);
568
569   /// Apply the DW_AT_stmt_list from this compile unit to the specified DIE.
570   void applyStmtList(DIE &D);
571
572   /// createGlobalVariableDIE - create global variable DIE.
573   void createGlobalVariableDIE(DIGlobalVariable GV);
574
575   /// addLabelAddress - Add a dwarf label attribute data and value using
576   /// either DW_FORM_addr or DW_FORM_GNU_addr_index.
577   void addLabelAddress(DIE *Die, dwarf::Attribute Attribute, MCSymbol *Label);
578
579   DwarfCompileUnit &getCU() override { return *this; }
580 };
581
582 class DwarfTypeUnit : public DwarfUnit {
583 private:
584   uint64_t TypeSignature;
585   const DIE *Ty;
586   DwarfCompileUnit &CU;
587
588 public:
589   DwarfTypeUnit(unsigned UID, DIE *D, DwarfCompileUnit &CU, AsmPrinter *A,
590                 DwarfDebug *DW, DwarfFile *DWU);
591
592   void setTypeSignature(uint64_t Signature) { TypeSignature = Signature; }
593   uint64_t getTypeSignature() const { return TypeSignature; }
594   void setType(const DIE *Ty) { this->Ty = Ty; }
595
596   /// Emit the header for this unit, not including the initial length field.
597   void emitHeader(const MCSection *ASection, const MCSymbol *ASectionSym) const
598       override;
599   unsigned getHeaderSize() const override {
600     return DwarfUnit::getHeaderSize() + sizeof(uint64_t) + // Type Signature
601            sizeof(uint32_t);                               // Type DIE Offset
602   }
603   void initSection(const MCSection *Section);
604   DwarfCompileUnit &getCU() override { return CU; }
605 };
606 } // end llvm namespace
607 #endif