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