blob: 40454cec3f42a27395041af30b5920ad51fe7659 [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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
David Blaikie85f80d72014-04-23 18:54:00 +000012
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 Blaikiedaefdbf2014-04-25 21:34:35 +000019#include "DwarfStringPool.h"
David Blaikie85f80d72014-04-23 18:54:00 +000020
21#include <vector>
22#include <string>
23#include <memory>
24
25namespace llvm {
26class AsmPrinter;
David Blaikief2999472014-10-23 00:16:05 +000027class DbgVariable;
David Blaikie85f80d72014-04-23 18:54:00 +000028class DwarfUnit;
29class DIEAbbrev;
30class MCSymbol;
31class DIE;
David Blaikie1d96cc22014-10-31 22:30:30 +000032class DISubprogram;
David Blaikief2999472014-10-23 00:16:05 +000033class LexicalScope;
David Blaikie85f80d72014-04-23 18:54:00 +000034class StringRef;
35class DwarfDebug;
36class MCSection;
37class DwarfFile {
38 // Target of Dwarf emission, used for sizing of abbreviations.
39 AsmPrinter *Asm;
40
David Blaikie2b22b1e2014-10-23 00:16:03 +000041 DwarfDebug &DD;
42
David Blaikie85f80d72014-04-23 18:54:00 +000043 // 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
David Blaikiedaefdbf2014-04-25 21:34:35 +000052 DwarfStringPool StrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000053
David Blaikie80e5b1e2014-10-24 17:57:34 +000054 // Collection of dbg variables of a scope.
55 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
56
David Blaikief6dac292014-11-01 17:21:26 +000057 // Collection of abstract subprogram DIEs.
58 DenseMap<const MDNode *, DIE *> AbstractSPDies;
59
David Blaikie85f80d72014-04-23 18:54:00 +000060public:
David Blaikie2b22b1e2014-10-23 00:16:03 +000061 DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
62 BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000063
64 ~DwarfFile();
65
66 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
67
68 /// \brief Compute the size and offset of a DIE given an incoming Offset.
69 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
70
71 /// \brief Compute the size and offset of all the DIEs.
72 void computeSizeAndOffsets();
73
74 /// \brief Define a unique number for the abbreviation.
75 void assignAbbrevNumber(DIEAbbrev &Abbrev);
76
77 /// \brief Add a unit to the list of CUs.
78 void addUnit(std::unique_ptr<DwarfUnit> U);
79
80 /// \brief Emit all of the units to the section listed with the given
81 /// abbreviation section.
David Blaikie2b22b1e2014-10-23 00:16:03 +000082 void emitUnits(const MCSymbol *ASectionSym);
David Blaikie85f80d72014-04-23 18:54:00 +000083
84 /// \brief Emit a set of abbreviations to the specific section.
85 void emitAbbrevs(const MCSection *);
86
87 /// \brief Emit all of the strings to the section given.
88 void emitStrings(const MCSection *StrSection,
David Blaikie6741bb02014-09-11 21:12:48 +000089 const MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +000090
David Blaikie85f80d72014-04-23 18:54:00 +000091 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +000092 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +000093
David Blaikief4c504e2014-10-24 00:43:47 +000094 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +000095
96 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
97 return ScopeVariables;
98 }
David Blaikief6dac292014-11-01 17:21:26 +000099
100 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
101 return AbstractSPDies;
102 }
David Blaikie85f80d72014-04-23 18:54:00 +0000103};
104}
105#endif