1 //===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CODEGEN_ASMPRINTER_DWARFFILE_H__
11 #define CODEGEN_ASMPRINTER_DWARFFILE_H__
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"
33 // Target of Dwarf emission, used for sizing of abbreviations.
36 // Used to uniquely define abbreviations.
37 FoldingSet<DIEAbbrev> AbbreviationsSet;
39 // A list of all the unique abbreviations in use.
40 std::vector<DIEAbbrev *> Abbreviations;
42 // A pointer to all units in the section.
43 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
45 // Collection of strings for this unit and assorted symbols.
46 // A String->Symbol mapping of strings used by indirect
48 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
51 unsigned NextStringPoolNumber;
52 std::string StringPref;
54 struct AddressPoolEntry {
57 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
59 // Collection of addresses for this unit and assorted labels.
60 // A Symbol->unsigned mapping of addresses used by indirect
62 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool;
66 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
70 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
72 /// \brief Compute the size and offset of a DIE given an incoming Offset.
73 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
75 /// \brief Compute the size and offset of all the DIEs.
76 void computeSizeAndOffsets();
78 /// \brief Define a unique number for the abbreviation.
79 void assignAbbrevNumber(DIEAbbrev &Abbrev);
81 /// \brief Add a unit to the list of CUs.
82 void addUnit(std::unique_ptr<DwarfUnit> U);
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);
88 /// \brief Emit a set of abbreviations to the specific section.
89 void emitAbbrevs(const MCSection *);
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);
96 /// \brief Emit all of the addresses to the section given.
97 void emitAddresses(const MCSection *AddrSection);
99 /// \brief Returns the entry into the start of the pool.
100 MCSymbol *getStringPoolSym();
102 /// \brief Returns an entry into the string pool with the given
104 MCSymbol *getStringPoolEntry(StringRef Str);
106 /// \brief Returns the index into the string pool with the given
108 unsigned getStringPoolIndex(StringRef Str);
110 /// \brief Returns the string pool.
111 StrPool *getStringPool() { return &StringPool; }
113 /// \brief Returns the index into the address pool with the given
115 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false);
117 /// \brief Returns the address pool.
118 AddrPool *getAddrPool() { return &AddressPool; }