1 //===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf compile unit.
12 //===----------------------------------------------------------------------===//
14 #ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
15 #define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
18 #include "llvm/Analysis/DebugInfo.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/OwningPtr.h"
26 class MachineLocation;
31 //===----------------------------------------------------------------------===//
32 /// CompileUnit - This dwarf writer support class manages information associated
33 /// with a source file.
35 /// ID - File identifier for source.
39 /// Die - Compile unit debug information entry.
41 const OwningPtr<DIE> CUDie;
43 /// Asm - Target of Dwarf emission.
48 /// IndexTyDie - An anonymous type for index type. Owned by CUDie.
51 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton
52 /// variables to debug information entries.
53 DenseMap<const MDNode *, DIE *> MDNodeToDieMap;
55 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton
56 /// descriptors to debug information entries using a DIEEntry proxy.
57 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap;
59 /// Globals - A map of globally visible named entities for this unit.
61 StringMap<DIE*> Globals;
63 /// GlobalTypes - A map of globally visible types for this unit.
65 StringMap<DIE*> GlobalTypes;
67 /// DIEBlocks - A list of all the DIEBlocks in use.
68 std::vector<DIEBlock *> DIEBlocks;
70 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
71 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
72 /// corresponds to the MDNode mapped with the subprogram DIE.
73 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
76 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
80 unsigned getID() const { return ID; }
81 DIE* getCUDie() const { return CUDie.get(); }
82 const StringMap<DIE*> &getGlobals() const { return Globals; }
83 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
85 /// hasContent - Return true if this compile unit has something to write out.
87 bool hasContent() const { return !CUDie->getChildren().empty(); }
89 /// addGlobal - Add a new global entity to the compile unit.
91 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
93 /// addGlobalType - Add a new global type to the compile unit.
95 void addGlobalType(DIType Ty);
97 /// getDIE - Returns the debug information entry map slot for the
98 /// specified debug variable.
99 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
101 DIEBlock *getDIEBlock() {
102 return new (DIEValueAllocator) DIEBlock();
105 /// insertDIE - Insert DIE into the map.
106 void insertDIE(const MDNode *N, DIE *D) {
107 MDNodeToDieMap.insert(std::make_pair(N, D));
110 /// getDIEEntry - Returns the debug information entry for the specified
112 DIEEntry *getDIEEntry(const MDNode *N) {
113 DenseMap<const MDNode *, DIEEntry *>::iterator I =
114 MDNodeToDIEEntryMap.find(N);
115 if (I == MDNodeToDIEEntryMap.end())
120 /// insertDIEEntry - Insert debug information entry into the map.
121 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
122 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
125 /// addDie - Adds or interns the DIE to the compile unit.
127 void addDie(DIE *Buffer) {
128 this->CUDie->addChild(Buffer);
131 // getIndexTyDie - Get an anonymous type for index type.
132 DIE *getIndexTyDie() {
136 // setIndexTyDie - Set D as anonymous type for index which can be reused
138 void setIndexTyDie(DIE *D) {
143 /// addUInt - Add an unsigned integer attribute data and value.
145 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
147 /// addSInt - Add an signed integer attribute data and value.
149 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
151 /// addString - Add a string attribute data and value.
153 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
155 /// addLabel - Add a Dwarf label attribute data and value.
157 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
158 const MCSymbol *Label);
160 /// addDelta - Add a label delta attribute data and value.
162 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
163 const MCSymbol *Hi, const MCSymbol *Lo);
165 /// addDIEEntry - Add a DIE attribute data and value.
167 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
169 /// addBlock - Add block data.
171 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
173 /// addSourceLine - Add location information to specified debug information
175 void addSourceLine(DIE *Die, DIVariable V);
176 void addSourceLine(DIE *Die, DIGlobalVariable G);
177 void addSourceLine(DIE *Die, DISubprogram SP);
178 void addSourceLine(DIE *Die, DIType Ty);
179 void addSourceLine(DIE *Die, DINameSpace NS);
181 /// addAddress - Add an address attribute to a die based on the location
183 void addAddress(DIE *Die, unsigned Attribute,
184 const MachineLocation &Location);
186 /// addConstantValue - Add constant value entry in variable DIE.
187 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
188 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
190 /// addConstantFPValue - Add constant value entry in variable DIE.
191 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
193 /// addTemplateParams - Add template parameters in buffer.
194 void addTemplateParams(DIE &Buffer, DIArray TParams);
196 /// addRegisterOp - Add register operand.
197 void addRegisterOp(DIE *TheDie, unsigned Reg);
199 /// addRegisterOffset - Add register offset.
200 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
202 /// addComplexAddress - Start with the address based on the location provided,
203 /// and generate the DWARF information necessary to find the actual variable
204 /// (navigating the extra location information encoded in the type) based on
205 /// the starting location. Add the DWARF information to the die.
207 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
208 const MachineLocation &Location);
210 // FIXME: Should be reformulated in terms of addComplexAddress.
211 /// addBlockByrefAddress - Start with the address based on the location
212 /// provided, and generate the DWARF information necessary to find the
213 /// actual Block variable (navigating the Block struct) based on the
214 /// starting location. Add the DWARF information to the die. Obsolete,
215 /// please use addComplexAddress instead.
217 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
218 const MachineLocation &Location);
220 /// addVariableAddress - Add DW_AT_location attribute for a
221 /// DbgVariable based on provided MachineLocation.
222 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
224 /// addToContextOwner - Add Die into the list of its context owner's children.
225 void addToContextOwner(DIE *Die, DIDescriptor Context);
227 /// addType - Add a new type attribute to the specified entity.
228 void addType(DIE *Entity, DIType Ty);
230 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
231 DIE *getOrCreateNameSpace(DINameSpace NS);
233 /// getOrCreateSubprogramDIE - Create new DIE using SP.
234 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
236 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
238 DIE *getOrCreateTypeDIE(const MDNode *N);
240 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
241 /// for the given DITemplateTypeParameter.
242 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
244 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
245 /// for the given DITemplateValueParameter.
246 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
248 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
249 /// information entry.
250 DIEEntry *createDIEEntry(DIE *Entry);
252 /// createGlobalVariableDIE - create global variable DIE.
253 void createGlobalVariableDIE(const MDNode *N);
255 void addPubTypes(DISubprogram SP);
257 /// constructTypeDIE - Construct basic type die from DIBasicType.
258 void constructTypeDIE(DIE &Buffer,
261 /// constructTypeDIE - Construct derived type die from DIDerivedType.
262 void constructTypeDIE(DIE &Buffer,
265 /// constructTypeDIE - Construct type DIE from DICompositeType.
266 void constructTypeDIE(DIE &Buffer,
267 DICompositeType CTy);
269 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
270 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
272 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
273 void constructArrayTypeDIE(DIE &Buffer,
274 DICompositeType *CTy);
276 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
277 DIE *constructEnumTypeDIE(DIEnumerator ETy);
279 /// constructContainingTypeDIEs - Construct DIEs for types that contain
281 void constructContainingTypeDIEs();
283 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
284 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
286 /// createMemberDIE - Create new member DIE.
287 DIE *createMemberDIE(DIDerivedType DT);
291 // DIEValueAllocator - All DIEValues are allocated through this allocator.
292 BumpPtrAllocator DIEValueAllocator;
293 DIEInteger *DIEIntegerOne;
296 } // end llvm namespace