blob: 9d64bfcdb9cfb45f5de1865a9e47566b334762ea [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 Blaikie9bfd7a92014-11-04 22:12:18 +000060 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
61 /// be shared across CUs, that is why we keep the map here instead
62 /// of in DwarfCompileUnit.
63 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
64
David Blaikie85f80d72014-04-23 18:54:00 +000065public:
David Blaikie2b22b1e2014-10-23 00:16:03 +000066 DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
67 BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000068
69 ~DwarfFile();
70
71 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
72
73 /// \brief Compute the size and offset of a DIE given an incoming Offset.
74 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
75
76 /// \brief Compute the size and offset of all the DIEs.
77 void computeSizeAndOffsets();
78
79 /// \brief Define a unique number for the abbreviation.
80 void assignAbbrevNumber(DIEAbbrev &Abbrev);
81
82 /// \brief Add a unit to the list of CUs.
83 void addUnit(std::unique_ptr<DwarfUnit> U);
84
85 /// \brief Emit all of the units to the section listed with the given
86 /// abbreviation section.
David Blaikie2b22b1e2014-10-23 00:16:03 +000087 void emitUnits(const MCSymbol *ASectionSym);
David Blaikie85f80d72014-04-23 18:54:00 +000088
89 /// \brief Emit a set of abbreviations to the specific section.
90 void emitAbbrevs(const MCSection *);
91
92 /// \brief Emit all of the strings to the section given.
93 void emitStrings(const MCSection *StrSection,
David Blaikie6741bb02014-09-11 21:12:48 +000094 const MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +000095
David Blaikie85f80d72014-04-23 18:54:00 +000096 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +000097 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +000098
David Blaikief4c504e2014-10-24 00:43:47 +000099 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +0000100
101 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
102 return ScopeVariables;
103 }
David Blaikief6dac292014-11-01 17:21:26 +0000104
105 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
106 return AbstractSPDies;
107 }
David Blaikie9bfd7a92014-11-04 22:12:18 +0000108
109 void insertDIE(const MDNode *TypeMD, DIE *Die) {
110 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
111 }
112 DIE *getDIE(const MDNode *TypeMD) {
113 return MDTypeNodeToDieMap.lookup(TypeMD);
114 }
David Blaikie85f80d72014-04-23 18:54:00 +0000115};
116}
117#endif