e4dc674bb698ad2ce6a52a98b8a66733f82b758f
[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 LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11 #define LLVM_LIB_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 #include "AddressPool.h"
19 #include "DwarfStringPool.h"
20
21 #include <vector>
22 #include <string>
23 #include <memory>
24
25 namespace llvm {
26 class AsmPrinter;
27 class DbgVariable;
28 class DwarfUnit;
29 class DIEAbbrev;
30 class MCSymbol;
31 class DIE;
32 class DISubprogram;
33 class LexicalScope;
34 class StringRef;
35 class DwarfDebug;
36 class MCSection;
37 class DwarfFile {
38   // Target of Dwarf emission, used for sizing of abbreviations.
39   AsmPrinter *Asm;
40
41   DwarfDebug &DD;
42
43   // Used to uniquely define abbreviations.
44   FoldingSet<DIEAbbrev> AbbreviationsSet;
45
46   // A list of all the unique abbreviations in use.
47   std::vector<DIEAbbrev *> Abbreviations;
48
49   // A pointer to all units in the section.
50   SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
51
52   DwarfStringPool StrPool;
53
54   // Collection of dbg variables of a scope.
55   DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
56
57 public:
58   DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
59             BumpPtrAllocator &DA);
60
61   ~DwarfFile();
62
63   const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
64
65   /// \brief Compute the size and offset of a DIE given an incoming Offset.
66   unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
67
68   /// \brief Compute the size and offset of all the DIEs.
69   void computeSizeAndOffsets();
70
71   /// \brief Define a unique number for the abbreviation.
72   void assignAbbrevNumber(DIEAbbrev &Abbrev);
73
74   /// \brief Add a unit to the list of CUs.
75   void addUnit(std::unique_ptr<DwarfUnit> U);
76
77   /// \brief Emit all of the units to the section listed with the given
78   /// abbreviation section.
79   void emitUnits(const MCSymbol *ASectionSym);
80
81   /// \brief Emit a set of abbreviations to the specific section.
82   void emitAbbrevs(const MCSection *);
83
84   /// \brief Emit all of the strings to the section given.
85   void emitStrings(const MCSection *StrSection,
86                    const MCSection *OffsetSection = nullptr);
87
88   /// \brief Returns the string pool.
89   DwarfStringPool &getStringPool() { return StrPool; }
90
91   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
92
93   DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
94     return ScopeVariables;
95   }
96 };
97 }
98 #endif