David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 1 | //===-- 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 Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H |
| 11 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 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 Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 18 | #include "AddressPool.h" |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 19 | #include "DwarfStringPool.h" |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 20 | |
| 21 | #include <vector> |
| 22 | #include <string> |
| 23 | #include <memory> |
| 24 | |
| 25 | namespace llvm { |
| 26 | class AsmPrinter; |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 27 | class DbgVariable; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 28 | class DwarfUnit; |
| 29 | class DIEAbbrev; |
| 30 | class MCSymbol; |
| 31 | class DIE; |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 32 | class DISubprogram; |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 33 | class LexicalScope; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 34 | class StringRef; |
| 35 | class DwarfDebug; |
| 36 | class MCSection; |
| 37 | class DwarfFile { |
| 38 | // Target of Dwarf emission, used for sizing of abbreviations. |
| 39 | AsmPrinter *Asm; |
| 40 | |
David Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 41 | DwarfDebug ⅅ |
| 42 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 43 | // 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 Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 52 | DwarfStringPool StrPool; |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 53 | |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 54 | // Collection of dbg variables of a scope. |
| 55 | DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables; |
| 56 | |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame^] | 57 | // Collection of abstract subprogram DIEs. |
| 58 | DenseMap<const MDNode *, DIE *> AbstractSPDies; |
| 59 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 60 | public: |
David Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 61 | DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref, |
| 62 | BumpPtrAllocator &DA); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 63 | |
| 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 Blaikie | 2b22b1e | 2014-10-23 00:16:03 +0000 | [diff] [blame] | 82 | void emitUnits(const MCSymbol *ASectionSym); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 83 | |
| 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 Blaikie | 6741bb0 | 2014-09-11 21:12:48 +0000 | [diff] [blame] | 89 | const MCSection *OffsetSection = nullptr); |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 90 | |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 91 | /// \brief Returns the string pool. |
David Blaikie | daefdbf | 2014-04-25 21:34:35 +0000 | [diff] [blame] | 92 | DwarfStringPool &getStringPool() { return StrPool; } |
David Blaikie | f299947 | 2014-10-23 00:16:05 +0000 | [diff] [blame] | 93 | |
David Blaikie | f4c504e | 2014-10-24 00:43:47 +0000 | [diff] [blame] | 94 | void addScopeVariable(LexicalScope *LS, DbgVariable *Var); |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 95 | |
| 96 | DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { |
| 97 | return ScopeVariables; |
| 98 | } |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame^] | 99 | |
| 100 | DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { |
| 101 | return AbstractSPDies; |
| 102 | } |
David Blaikie | 85f80d7 | 2014-04-23 18:54:00 +0000 | [diff] [blame] | 103 | }; |
| 104 | } |
| 105 | #endif |