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 /// GlobalTypes - A map of globally visible types for this unit.
61 StringMap<DIE*> GlobalTypes;
63 /// AccelNames - A map of names for the name accelerator table.
65 StringMap<std::vector<DIE*> > AccelNames;
66 StringMap<std::vector<DIE*> > AccelObjC;
67 StringMap<std::vector<DIE*> > AccelNamespace;
68 StringMap<std::vector<DIE*> > AccelTypes;
70 /// DIEBlocks - A list of all the DIEBlocks in use.
71 std::vector<DIEBlock *> DIEBlocks;
73 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that
74 /// need DW_AT_containing_type attribute. This attribute points to a DIE that
75 /// corresponds to the MDNode mapped with the subprogram DIE.
76 DenseMap<DIE *, const MDNode *> ContainingTypeMap;
79 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
83 unsigned getID() const { return ID; }
84 DIE* getCUDie() const { return CUDie.get(); }
85 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
87 const StringMap<std::vector<DIE*> > &getAccelNames() const {
90 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
93 const StringMap<std::vector<DIE*> > &getAccelNamespace() const {
94 return AccelNamespace;
96 const StringMap<std::vector<DIE*> > &getAccelTypes() const {
100 /// hasContent - Return true if this compile unit has something to write out.
102 bool hasContent() const { return !CUDie->getChildren().empty(); }
104 /// addGlobalType - Add a new global type to the compile unit.
106 void addGlobalType(DIType Ty);
109 /// addAccelName - Add a new name to the name accelerator table.
110 void addAccelName(StringRef Name, DIE *Die) {
111 std::vector<DIE*> &DIEs = AccelNames[Name];
114 void addAccelObjC(StringRef Name, DIE *Die) {
115 std::vector<DIE*> &DIEs = AccelObjC[Name];
118 void addAccelNamespace(StringRef Name, DIE *Die) {
119 std::vector<DIE*> &DIEs = AccelNamespace[Name];
122 void addAccelType(StringRef Name, DIE *Die) {
123 std::vector<DIE*> &DIEs = AccelTypes[Name];
127 /// getDIE - Returns the debug information entry map slot for the
128 /// specified debug variable.
129 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
131 DIEBlock *getDIEBlock() {
132 return new (DIEValueAllocator) DIEBlock();
135 /// insertDIE - Insert DIE into the map.
136 void insertDIE(const MDNode *N, DIE *D) {
137 MDNodeToDieMap.insert(std::make_pair(N, D));
140 /// getDIEEntry - Returns the debug information entry for the specified
142 DIEEntry *getDIEEntry(const MDNode *N) {
143 DenseMap<const MDNode *, DIEEntry *>::iterator I =
144 MDNodeToDIEEntryMap.find(N);
145 if (I == MDNodeToDIEEntryMap.end())
150 /// insertDIEEntry - Insert debug information entry into the map.
151 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
152 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
155 /// addDie - Adds or interns the DIE to the compile unit.
157 void addDie(DIE *Buffer) {
158 this->CUDie->addChild(Buffer);
161 // getIndexTyDie - Get an anonymous type for index type.
162 DIE *getIndexTyDie() {
166 // setIndexTyDie - Set D as anonymous type for index which can be reused
168 void setIndexTyDie(DIE *D) {
173 /// addUInt - Add an unsigned integer attribute data and value.
175 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
177 /// addSInt - Add an signed integer attribute data and value.
179 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
181 /// addString - Add a string attribute data and value.
183 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
185 /// addLabel - Add a Dwarf label attribute data and value.
187 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
188 const MCSymbol *Label);
190 /// addDelta - Add a label delta attribute data and value.
192 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
193 const MCSymbol *Hi, const MCSymbol *Lo);
195 /// addDIEEntry - Add a DIE attribute data and value.
197 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
199 /// addBlock - Add block data.
201 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
203 /// addSourceLine - Add location information to specified debug information
205 void addSourceLine(DIE *Die, DIVariable V);
206 void addSourceLine(DIE *Die, DIGlobalVariable G);
207 void addSourceLine(DIE *Die, DISubprogram SP);
208 void addSourceLine(DIE *Die, DIType Ty);
209 void addSourceLine(DIE *Die, DINameSpace NS);
211 /// addAddress - Add an address attribute to a die based on the location
213 void addAddress(DIE *Die, unsigned Attribute,
214 const MachineLocation &Location);
216 /// addConstantValue - Add constant value entry in variable DIE.
217 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
218 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
220 /// addConstantFPValue - Add constant value entry in variable DIE.
221 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
223 /// addTemplateParams - Add template parameters in buffer.
224 void addTemplateParams(DIE &Buffer, DIArray TParams);
226 /// addRegisterOp - Add register operand.
227 void addRegisterOp(DIE *TheDie, unsigned Reg);
229 /// addRegisterOffset - Add register offset.
230 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
232 /// addComplexAddress - Start with the address based on the location provided,
233 /// and generate the DWARF information necessary to find the actual variable
234 /// (navigating the extra location information encoded in the type) based on
235 /// the starting location. Add the DWARF information to the die.
237 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
238 const MachineLocation &Location);
240 // FIXME: Should be reformulated in terms of addComplexAddress.
241 /// addBlockByrefAddress - Start with the address based on the location
242 /// provided, and generate the DWARF information necessary to find the
243 /// actual Block variable (navigating the Block struct) based on the
244 /// starting location. Add the DWARF information to the die. Obsolete,
245 /// please use addComplexAddress instead.
247 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
248 const MachineLocation &Location);
250 /// addVariableAddress - Add DW_AT_location attribute for a
251 /// DbgVariable based on provided MachineLocation.
252 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
254 /// addToContextOwner - Add Die into the list of its context owner's children.
255 void addToContextOwner(DIE *Die, DIDescriptor Context);
257 /// addType - Add a new type attribute to the specified entity.
258 void addType(DIE *Entity, DIType Ty);
260 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
261 DIE *getOrCreateNameSpace(DINameSpace NS);
263 /// getOrCreateSubprogramDIE - Create new DIE using SP.
264 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
266 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
268 DIE *getOrCreateTypeDIE(const MDNode *N);
270 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
271 /// for the given DITemplateTypeParameter.
272 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
274 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
275 /// for the given DITemplateValueParameter.
276 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
278 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
279 /// information entry.
280 DIEEntry *createDIEEntry(DIE *Entry);
282 /// createGlobalVariableDIE - create global variable DIE.
283 void createGlobalVariableDIE(const MDNode *N);
285 void addPubTypes(DISubprogram SP);
287 /// constructTypeDIE - Construct basic type die from DIBasicType.
288 void constructTypeDIE(DIE &Buffer,
291 /// constructTypeDIE - Construct derived type die from DIDerivedType.
292 void constructTypeDIE(DIE &Buffer,
295 /// constructTypeDIE - Construct type DIE from DICompositeType.
296 void constructTypeDIE(DIE &Buffer,
297 DICompositeType CTy);
299 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
300 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
302 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
303 void constructArrayTypeDIE(DIE &Buffer,
304 DICompositeType *CTy);
306 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
307 DIE *constructEnumTypeDIE(DIEnumerator ETy);
309 /// constructContainingTypeDIEs - Construct DIEs for types that contain
311 void constructContainingTypeDIEs();
313 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
314 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
316 /// createMemberDIE - Create new member DIE.
317 DIE *createMemberDIE(DIDerivedType DT);
321 // DIEValueAllocator - All DIEValues are allocated through this allocator.
322 BumpPtrAllocator DIEValueAllocator;
323 DIEInteger *DIEIntegerOne;
326 } // end llvm namespace