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 /// AccelNames - A map of names for the name accelerator table.
69 StringMap<DIE*> AccelNames;
70 StringMap<std::vector<DIE*> > AccelObjC;
71 StringMap<DIE*> AccelNamespace;
72 StringMap<DIE*> AccelTypes;
74 /// DIEBlocks - A list of all the DIEBlocks in use.
75 std::vector<DIEBlock *> DIEBlocks;
77 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
78 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
79 /// corresponds to the MDNode mapped with the subprogram DIE.
80 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
83 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
87 unsigned getID() const { return ID; }
88 DIE* getCUDie() const { return CUDie.get(); }
89 const StringMap<DIE*> &getGlobals() const { return Globals; }
90 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
92 const StringMap<DIE*> &getAccelNames() const { return AccelNames; }
93 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
96 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; }
97 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; }
99 /// hasContent - Return true if this compile unit has something to write out.
101 bool hasContent() const { return !CUDie->getChildren().empty(); }
103 /// addGlobal - Add a new global entity to the compile unit.
105 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
107 /// addGlobalType - Add a new global type to the compile unit.
109 void addGlobalType(DIType Ty);
112 /// addAccelName - Add a new name to the name accelerator table.
113 void addAccelName(StringRef Name, DIE *Die) { AccelNames[Name] = Die; }
114 void addAccelObjC(StringRef Name, DIE *Die) {
115 std::vector<DIE*> &DIEs = AccelObjC[Name];
118 void addAccelNamespace(StringRef Name, DIE *Die) {
119 AccelNamespace[Name] = Die;
121 void addAccelType(StringRef Name, DIE *Die) {
122 AccelTypes[Name] = Die;
125 /// getDIE - Returns the debug information entry map slot for the
126 /// specified debug variable.
127 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
129 DIEBlock *getDIEBlock() {
130 return new (DIEValueAllocator) DIEBlock();
133 /// insertDIE - Insert DIE into the map.
134 void insertDIE(const MDNode *N, DIE *D) {
135 MDNodeToDieMap.insert(std::make_pair(N, D));
138 /// getDIEEntry - Returns the debug information entry for the specified
140 DIEEntry *getDIEEntry(const MDNode *N) {
141 DenseMap<const MDNode *, DIEEntry *>::iterator I =
142 MDNodeToDIEEntryMap.find(N);
143 if (I == MDNodeToDIEEntryMap.end())
148 /// insertDIEEntry - Insert debug information entry into the map.
149 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
150 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
153 /// addDie - Adds or interns the DIE to the compile unit.
155 void addDie(DIE *Buffer) {
156 this->CUDie->addChild(Buffer);
159 // getIndexTyDie - Get an anonymous type for index type.
160 DIE *getIndexTyDie() {
164 // setIndexTyDie - Set D as anonymous type for index which can be reused
166 void setIndexTyDie(DIE *D) {
171 /// addUInt - Add an unsigned integer attribute data and value.
173 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
175 /// addSInt - Add an signed integer attribute data and value.
177 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
179 /// addString - Add a string attribute data and value.
181 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
183 /// addLabel - Add a Dwarf label attribute data and value.
185 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
186 const MCSymbol *Label);
188 /// addDelta - Add a label delta attribute data and value.
190 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
191 const MCSymbol *Hi, const MCSymbol *Lo);
193 /// addDIEEntry - Add a DIE attribute data and value.
195 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
197 /// addBlock - Add block data.
199 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
201 /// addSourceLine - Add location information to specified debug information
203 void addSourceLine(DIE *Die, DIVariable V);
204 void addSourceLine(DIE *Die, DIGlobalVariable G);
205 void addSourceLine(DIE *Die, DISubprogram SP);
206 void addSourceLine(DIE *Die, DIType Ty);
207 void addSourceLine(DIE *Die, DINameSpace NS);
209 /// addAddress - Add an address attribute to a die based on the location
211 void addAddress(DIE *Die, unsigned Attribute,
212 const MachineLocation &Location);
214 /// addConstantValue - Add constant value entry in variable DIE.
215 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
216 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
218 /// addConstantFPValue - Add constant value entry in variable DIE.
219 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
221 /// addTemplateParams - Add template parameters in buffer.
222 void addTemplateParams(DIE &Buffer, DIArray TParams);
224 /// addRegisterOp - Add register operand.
225 void addRegisterOp(DIE *TheDie, unsigned Reg);
227 /// addRegisterOffset - Add register offset.
228 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
230 /// addComplexAddress - Start with the address based on the location provided,
231 /// and generate the DWARF information necessary to find the actual variable
232 /// (navigating the extra location information encoded in the type) based on
233 /// the starting location. Add the DWARF information to the die.
235 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
236 const MachineLocation &Location);
238 // FIXME: Should be reformulated in terms of addComplexAddress.
239 /// addBlockByrefAddress - Start with the address based on the location
240 /// provided, and generate the DWARF information necessary to find the
241 /// actual Block variable (navigating the Block struct) based on the
242 /// starting location. Add the DWARF information to the die. Obsolete,
243 /// please use addComplexAddress instead.
245 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
246 const MachineLocation &Location);
248 /// addVariableAddress - Add DW_AT_location attribute for a
249 /// DbgVariable based on provided MachineLocation.
250 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
252 /// addToContextOwner - Add Die into the list of its context owner's children.
253 void addToContextOwner(DIE *Die, DIDescriptor Context);
255 /// addType - Add a new type attribute to the specified entity.
256 void addType(DIE *Entity, DIType Ty);
258 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
259 DIE *getOrCreateNameSpace(DINameSpace NS);
261 /// getOrCreateSubprogramDIE - Create new DIE using SP.
262 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
264 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
266 DIE *getOrCreateTypeDIE(const MDNode *N);
268 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
269 /// for the given DITemplateTypeParameter.
270 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
272 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
273 /// for the given DITemplateValueParameter.
274 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
276 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
277 /// information entry.
278 DIEEntry *createDIEEntry(DIE *Entry);
280 /// createGlobalVariableDIE - create global variable DIE.
281 void createGlobalVariableDIE(const MDNode *N);
283 void addPubTypes(DISubprogram SP);
285 /// constructTypeDIE - Construct basic type die from DIBasicType.
286 void constructTypeDIE(DIE &Buffer,
289 /// constructTypeDIE - Construct derived type die from DIDerivedType.
290 void constructTypeDIE(DIE &Buffer,
293 /// constructTypeDIE - Construct type DIE from DICompositeType.
294 void constructTypeDIE(DIE &Buffer,
295 DICompositeType CTy);
297 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
298 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
300 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
301 void constructArrayTypeDIE(DIE &Buffer,
302 DICompositeType *CTy);
304 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
305 DIE *constructEnumTypeDIE(DIEnumerator ETy);
307 /// constructContainingTypeDIEs - Construct DIEs for types that contain
309 void constructContainingTypeDIEs();
311 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
312 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
314 /// createMemberDIE - Create new member DIE.
315 DIE *createMemberDIE(DIDerivedType DT);
319 // DIEValueAllocator - All DIEValues are allocated through this allocator.
320 BumpPtrAllocator DIEValueAllocator;
321 DIEInteger *DIEIntegerOne;
324 } // end llvm namespace