blob: 2316566c2de08c1afd571867b814014530e06055 [file] [log] [blame]
David Blaikie85f80d72014-04-23 18:54:00 +00001//===-- 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"
David Blaikiee226b082014-04-23 21:04:59 +000018#include "AddressPool.h"
David Blaikie85f80d72014-04-23 18:54:00 +000019
20#include <vector>
21#include <string>
22#include <memory>
23
24namespace llvm {
25class AsmPrinter;
26class DwarfUnit;
27class DIEAbbrev;
28class MCSymbol;
29class DIE;
30class StringRef;
31class DwarfDebug;
32class MCSection;
33class DwarfFile {
34 // Target of Dwarf emission, used for sizing of abbreviations.
35 AsmPrinter *Asm;
36
37 // Used to uniquely define abbreviations.
38 FoldingSet<DIEAbbrev> AbbreviationsSet;
39
40 // A list of all the unique abbreviations in use.
41 std::vector<DIEAbbrev *> Abbreviations;
42
43 // A pointer to all units in the section.
44 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
45
46 // Collection of strings for this unit and assorted symbols.
47 // A String->Symbol mapping of strings used by indirect
48 // references.
49 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &>
50 StrPool;
51 StrPool StringPool;
52 unsigned NextStringPoolNumber;
53 std::string StringPref;
54
David Blaikiee226b082014-04-23 21:04:59 +000055 AddressPool AddrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000056public:
57 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA);
58
59 ~DwarfFile();
60
61 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
62
63 /// \brief Compute the size and offset of a DIE given an incoming Offset.
64 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
65
66 /// \brief Compute the size and offset of all the DIEs.
67 void computeSizeAndOffsets();
68
69 /// \brief Define a unique number for the abbreviation.
70 void assignAbbrevNumber(DIEAbbrev &Abbrev);
71
72 /// \brief Add a unit to the list of CUs.
73 void addUnit(std::unique_ptr<DwarfUnit> U);
74
75 /// \brief Emit all of the units to the section listed with the given
76 /// abbreviation section.
77 void emitUnits(DwarfDebug *DD, const MCSymbol *ASectionSym);
78
79 /// \brief Emit a set of abbreviations to the specific section.
80 void emitAbbrevs(const MCSection *);
81
82 /// \brief Emit all of the strings to the section given.
83 void emitStrings(const MCSection *StrSection,
84 const MCSection *OffsetSection = nullptr,
85 const MCSymbol *StrSecSym = nullptr);
86
David Blaikie85f80d72014-04-23 18:54:00 +000087 /// \brief Returns the entry into the start of the pool.
88 MCSymbol *getStringPoolSym();
89
90 /// \brief Returns an entry into the string pool with the given
91 /// string text.
92 MCSymbol *getStringPoolEntry(StringRef Str);
93
94 /// \brief Returns the index into the string pool with the given
95 /// string text.
96 unsigned getStringPoolIndex(StringRef Str);
97
98 /// \brief Returns the string pool.
99 StrPool *getStringPool() { return &StringPool; }
100
David Blaikiee226b082014-04-23 21:04:59 +0000101 AddressPool &getAddressPool() { return AddrPool; }
David Blaikie85f80d72014-04-23 18:54:00 +0000102};
103}
104#endif