Devang Patel | 8b9df62 | 2011-04-12 17:40:32 +0000 | [diff] [blame^] | 1 | //===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- 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 | // This file contains support for writing dwarf compile unit. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 15 | #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H |
| 16 | |
| 17 | #include "DIE.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
| 19 | #include "llvm/ADT/StringMap.h" |
| 20 | #include "llvm/ADT/OwningPtr.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | /// CompileUnit - This dwarf writer support class manages information associate |
| 26 | /// with a source file. |
| 27 | class CompileUnit { |
| 28 | /// ID - File identifier for source. |
| 29 | /// |
| 30 | unsigned ID; |
| 31 | |
| 32 | /// Die - Compile unit debug information entry. |
| 33 | /// |
| 34 | const OwningPtr<DIE> CUDie; |
| 35 | |
| 36 | /// IndexTyDie - An anonymous type for index type. Owned by CUDie. |
| 37 | DIE *IndexTyDie; |
| 38 | |
| 39 | /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton |
| 40 | /// variables to debug information entries. |
| 41 | DenseMap<const MDNode *, DIE *> MDNodeToDieMap; |
| 42 | |
| 43 | /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton |
| 44 | /// descriptors to debug information entries using a DIEEntry proxy. |
| 45 | DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap; |
| 46 | |
| 47 | /// Globals - A map of globally visible named entities for this unit. |
| 48 | /// |
| 49 | StringMap<DIE*> Globals; |
| 50 | |
| 51 | /// GlobalTypes - A map of globally visible types for this unit. |
| 52 | /// |
| 53 | StringMap<DIE*> GlobalTypes; |
| 54 | |
| 55 | public: |
| 56 | CompileUnit(unsigned I, DIE *D) |
| 57 | : ID(I), CUDie(D), IndexTyDie(0) {} |
| 58 | |
| 59 | // Accessors. |
| 60 | unsigned getID() const { return ID; } |
| 61 | DIE* getCUDie() const { return CUDie.get(); } |
| 62 | const StringMap<DIE*> &getGlobals() const { return Globals; } |
| 63 | const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; } |
| 64 | |
| 65 | /// hasContent - Return true if this compile unit has something to write out. |
| 66 | /// |
| 67 | bool hasContent() const { return !CUDie->getChildren().empty(); } |
| 68 | |
| 69 | /// addGlobal - Add a new global entity to the compile unit. |
| 70 | /// |
| 71 | void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; } |
| 72 | |
| 73 | /// addGlobalType - Add a new global type to the compile unit. |
| 74 | /// |
| 75 | void addGlobalType(StringRef Name, DIE *Die) { |
| 76 | GlobalTypes[Name] = Die; |
| 77 | } |
| 78 | |
| 79 | /// getDIE - Returns the debug information entry map slot for the |
| 80 | /// specified debug variable. |
| 81 | DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); } |
| 82 | |
| 83 | /// insertDIE - Insert DIE into the map. |
| 84 | void insertDIE(const MDNode *N, DIE *D) { |
| 85 | MDNodeToDieMap.insert(std::make_pair(N, D)); |
| 86 | } |
| 87 | |
| 88 | /// getDIEEntry - Returns the debug information entry for the speciefied |
| 89 | /// debug variable. |
| 90 | DIEEntry *getDIEEntry(const MDNode *N) { |
| 91 | DenseMap<const MDNode *, DIEEntry *>::iterator I = |
| 92 | MDNodeToDIEEntryMap.find(N); |
| 93 | if (I == MDNodeToDIEEntryMap.end()) |
| 94 | return NULL; |
| 95 | return I->second; |
| 96 | } |
| 97 | |
| 98 | /// insertDIEEntry - Insert debug information entry into the map. |
| 99 | void insertDIEEntry(const MDNode *N, DIEEntry *E) { |
| 100 | MDNodeToDIEEntryMap.insert(std::make_pair(N, E)); |
| 101 | } |
| 102 | |
| 103 | /// addDie - Adds or interns the DIE to the compile unit. |
| 104 | /// |
| 105 | void addDie(DIE *Buffer) { |
| 106 | this->CUDie->addChild(Buffer); |
| 107 | } |
| 108 | |
| 109 | // getIndexTyDie - Get an anonymous type for index type. |
| 110 | DIE *getIndexTyDie() { |
| 111 | return IndexTyDie; |
| 112 | } |
| 113 | |
| 114 | // setIndexTyDie - Set D as anonymous type for index which can be reused |
| 115 | // later. |
| 116 | void setIndexTyDie(DIE *D) { |
| 117 | IndexTyDie = D; |
| 118 | } |
| 119 | |
| 120 | }; |
| 121 | |
| 122 | } // end llvm namespace |
| 123 | #endif |