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