Split out DwarfFile from DwarfDebug into its own .h/.cpp files.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfFile.h
1 //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- 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 #ifndef CODEGEN_ASMPRINTER_DWARFFILE_H__
11 #define CODEGEN_ASMPRINTER_DWARFFILE_H__
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/FoldingSet.h"
15 #include "llvm/ADT/SmallVector.h"
16 #include "llvm/ADT/StringMap.h"
17 #include "llvm/Support/Allocator.h"
18
19 #include <vector>
20 #include <string>
21 #include <memory>
22
23 namespace llvm {
24 class AsmPrinter;
25 class DwarfUnit;
26 class DIEAbbrev;
27 class MCSymbol;
28 class DIE;
29 class StringRef;
30 class DwarfDebug;
31 class MCSection;
32 class DwarfFile {
33   // Target of Dwarf emission, used for sizing of abbreviations.
34   AsmPrinter *Asm;
35
36   // Used to uniquely define abbreviations.
37   FoldingSet<DIEAbbrev> AbbreviationsSet;
38
39   // A list of all the unique abbreviations in use.
40   std::vector<DIEAbbrev *> Abbreviations;
41
42   // A pointer to all units in the section.
43   SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
44
45   // Collection of strings for this unit and assorted symbols.
46   // A String->Symbol mapping of strings used by indirect
47   // references.
48   typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
49   StrPool;
50   StrPool StringPool;
51   unsigned NextStringPoolNumber;
52   std::string StringPref;
53
54   struct AddressPoolEntry {
55     unsigned Number;
56     bool TLS;
57     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
58   };
59   // Collection of addresses for this unit and assorted labels.
60   // A Symbol->unsigned mapping of addresses used by indirect
61   // references.
62   typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
63   AddrPool AddressPool;
64
65 public:
66   DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
67
68   ~DwarfFile();
69
70   const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
71
72   /// \brief Compute the size and offset of a DIE given an incoming Offset.
73   unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
74
75   /// \brief Compute the size and offset of all the DIEs.
76   void computeSizeAndOffsets();
77
78   /// \brief Define a unique number for the abbreviation.
79   void assignAbbrevNumber(DIEAbbrev &Abbrev);
80
81   /// \brief Add a unit to the list of CUs.
82   void addUnit(std::unique_ptr<DwarfUnit> U);
83
84   /// \brief Emit all of the units to the section listed with the given
85   /// abbreviation section.
86   void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
87
88   /// \brief Emit a set of abbreviations to the specific section.
89   void emitAbbrevs(const MCSection *);
90
91   /// \brief Emit all of the strings to the section given.
92   void emitStrings(const MCSection *StrSection,
93                    const MCSection *OffsetSection = nullptr,
94                    const MCSymbol *StrSecSym = nullptr);
95
96   /// \brief Emit all of the addresses to the section given.
97   void emitAddresses(const MCSection *AddrSection);
98
99   /// \brief Returns the entry into the start of the pool.
100   MCSymbol *getStringPoolSym();
101
102   /// \brief Returns an entry into the string pool with the given
103   /// string text.
104   MCSymbol *getStringPoolEntry(StringRef Str);
105
106   /// \brief Returns the index into the string pool with the given
107   /// string text.
108   unsigned getStringPoolIndex(StringRef Str);
109
110   /// \brief Returns the string pool.
111   StrPool *getStringPool() { return &StringPool; }
112
113   /// \brief Returns the index into the address pool with the given
114   /// label/symbol.
115   unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
116
117   /// \brief Returns the address pool.
118   AddrPool *getAddrPool() { return &AddressPool; }
119 };
120 }
121 #endif