blob: cfca3666f0f84f86f8d990eacdca55ce3acbd868 [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 Blaikief2999472014-10-23 00:16:05 +000032class LexicalScope;
David Blaikie85f80d72014-04-23 18:54:00 +000033class StringRef;
34class DwarfDebug;
35class MCSection;
36class DwarfFile {
37 // Target of Dwarf emission, used for sizing of abbreviations.
38 AsmPrinter *Asm;
39
David Blaikie2b22b1e2014-10-23 00:16:03 +000040 DwarfDebug &DD;
41
David Blaikie85f80d72014-04-23 18:54:00 +000042 // Used to uniquely define abbreviations.
43 FoldingSet<DIEAbbrev> AbbreviationsSet;
44
45 // A list of all the unique abbreviations in use.
46 std::vector<DIEAbbrev *> Abbreviations;
47
48 // A pointer to all units in the section.
49 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
50
David Blaikiedaefdbf2014-04-25 21:34:35 +000051 DwarfStringPool StrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000052
David Blaikie80e5b1e2014-10-24 17:57:34 +000053 // Collection of dbg variables of a scope.
54 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
55
David Blaikie85f80d72014-04-23 18:54:00 +000056public:
David Blaikie2b22b1e2014-10-23 00:16:03 +000057 DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
58 BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000059
60 ~DwarfFile();
61
62 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
63
64 /// \brief Compute the size and offset of a DIE given an incoming Offset.
65 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
66
67 /// \brief Compute the size and offset of all the DIEs.
68 void computeSizeAndOffsets();
69
70 /// \brief Define a unique number for the abbreviation.
71 void assignAbbrevNumber(DIEAbbrev &Abbrev);
72
73 /// \brief Add a unit to the list of CUs.
74 void addUnit(std::unique_ptr<DwarfUnit> U);
75
76 /// \brief Emit all of the units to the section listed with the given
77 /// abbreviation section.
David Blaikie2b22b1e2014-10-23 00:16:03 +000078 void emitUnits(const MCSymbol *ASectionSym);
David Blaikie85f80d72014-04-23 18:54:00 +000079
80 /// \brief Emit a set of abbreviations to the specific section.
81 void emitAbbrevs(const MCSection *);
82
83 /// \brief Emit all of the strings to the section given.
84 void emitStrings(const MCSection *StrSection,
David Blaikie6741bb02014-09-11 21:12:48 +000085 const MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +000086
David Blaikie85f80d72014-04-23 18:54:00 +000087 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +000088 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +000089
David Blaikief4c504e2014-10-24 00:43:47 +000090 void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +000091
92 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
93 return ScopeVariables;
94 }
David Blaikie85f80d72014-04-23 18:54:00 +000095};
96}
97#endif