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 associate
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, unsigned Form,
154 const StringRef Str);
156 /// addLabel - Add a Dwarf label attribute data and value.
158 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
159 const MCSymbol *Label);
161 /// addDelta - Add a label delta attribute data and value.
163 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
164 const MCSymbol *Hi, const MCSymbol *Lo);
166 /// addDIEEntry - Add a DIE attribute data and value.
168 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
170 /// addBlock - Add block data.
172 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
174 /// addSourceLine - Add location information to specified debug information
176 void addSourceLine(DIE *Die, DIVariable V);
177 void addSourceLine(DIE *Die, DIGlobalVariable G);
178 void addSourceLine(DIE *Die, DISubprogram SP);
179 void addSourceLine(DIE *Die, DIType Ty);
180 void addSourceLine(DIE *Die, DINameSpace NS);
182 /// addAddress - Add an address attribute to a die based on the location
184 void addAddress(DIE *Die, unsigned Attribute,
185 const MachineLocation &Location);
187 /// addConstantValue - Add constant value entry in variable DIE.
188 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
189 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
191 /// addConstantFPValue - Add constant value entry in variable DIE.
192 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
194 /// addTemplateParams - Add template parameters in buffer.
195 void addTemplateParams(DIE &Buffer, DIArray TParams);
197 /// addRegisterOp - Add register operand.
198 void addRegisterOp(DIE *TheDie, unsigned Reg);
200 /// addRegisterOffset - Add register offset.
201 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
203 /// addComplexAddress - Start with the address based on the location provided,
204 /// and generate the DWARF information necessary to find the actual variable
205 /// (navigating the extra location information encoded in the type) based on
206 /// the starting location. Add the DWARF information to the die.
208 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
209 const MachineLocation &Location);
211 // FIXME: Should be reformulated in terms of addComplexAddress.
212 /// addBlockByrefAddress - Start with the address based on the location
213 /// provided, and generate the DWARF information necessary to find the
214 /// actual Block variable (navigating the Block struct) based on the
215 /// starting location. Add the DWARF information to the die. Obsolete,
216 /// please use addComplexAddress instead.
218 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
219 const MachineLocation &Location);
221 /// addVariableAddress - Add DW_AT_location attribute for a
222 /// DbgVariable based on provided MachineLocation.
223 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
225 /// addToContextOwner - Add Die into the list of its context owner's children.
226 void addToContextOwner(DIE *Die, DIDescriptor Context);
228 /// addType - Add a new type attribute to the specified entity.
229 void addType(DIE *Entity, DIType Ty);
231 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
232 DIE *getOrCreateNameSpace(DINameSpace NS);
234 /// getOrCreateSubprogramDIE - Create new DIE using SP.
235 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
237 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
239 DIE *getOrCreateTypeDIE(DIType Ty);
241 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
242 /// for the given DITemplateTypeParameter.
243 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
245 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
246 /// for the given DITemplateValueParameter.
247 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
249 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
250 /// information entry.
251 DIEEntry *createDIEEntry(DIE *Entry);
253 /// createGlobalVariableDIE - create global variable DIE.
254 void createGlobalVariableDIE(const MDNode *N);
256 void addPubTypes(DISubprogram SP);
258 /// constructTypeDIE - Construct basic type die from DIBasicType.
259 void constructTypeDIE(DIE &Buffer,
262 /// constructTypeDIE - Construct derived type die from DIDerivedType.
263 void constructTypeDIE(DIE &Buffer,
266 /// constructTypeDIE - Construct type DIE from DICompositeType.
267 void constructTypeDIE(DIE &Buffer,
268 DICompositeType CTy);
270 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
271 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
273 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
274 void constructArrayTypeDIE(DIE &Buffer,
275 DICompositeType *CTy);
277 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
278 DIE *constructEnumTypeDIE(DIEnumerator ETy);
280 /// constructContainingTypeDIEs - Construct DIEs for types that contain
282 void constructContainingTypeDIEs();
284 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
285 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
287 /// createMemberDIE - Create new member DIE.
288 DIE *createMemberDIE(DIDerivedType DT);
292 // DIEValueAllocator - All DIEValues are allocated through this allocator.
293 BumpPtrAllocator DIEValueAllocator;
294 DIEInteger *DIEIntegerOne;
297 } // end llvm namespace