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<DIE*> AccelNames;
66 StringMap<std::vector<DIE*> > AccelObjC;
67 StringMap<DIE*> AccelNamespace;
68 StringMap<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<DIE*> &getAccelNames() const { return AccelNames; }
88 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
91 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; }
92 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; }
94 /// hasContent - Return true if this compile unit has something to write out.
96 bool hasContent() const { return !CUDie->getChildren().empty(); }
98 /// addGlobalType - Add a new global type to the compile unit.
100 void addGlobalType(DIType Ty);
103 /// addAccelName - Add a new name to the name accelerator table.
104 void addAccelName(StringRef Name, DIE *Die) { AccelNames[Name] = Die; }
105 void addAccelObjC(StringRef Name, DIE *Die) {
106 std::vector<DIE*> &DIEs = AccelObjC[Name];
109 void addAccelNamespace(StringRef Name, DIE *Die) {
110 AccelNamespace[Name] = Die;
112 void addAccelType(StringRef Name, DIE *Die) {
113 AccelTypes[Name] = Die;
116 /// getDIE - Returns the debug information entry map slot for the
117 /// specified debug variable.
118 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
120 DIEBlock *getDIEBlock() {
121 return new (DIEValueAllocator) DIEBlock();
124 /// insertDIE - Insert DIE into the map.
125 void insertDIE(const MDNode *N, DIE *D) {
126 MDNodeToDieMap.insert(std::make_pair(N, D));
129 /// getDIEEntry - Returns the debug information entry for the specified
131 DIEEntry *getDIEEntry(const MDNode *N) {
132 DenseMap<const MDNode *, DIEEntry *>::iterator I =
133 MDNodeToDIEEntryMap.find(N);
134 if (I == MDNodeToDIEEntryMap.end())
139 /// insertDIEEntry - Insert debug information entry into the map.
140 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
141 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
144 /// addDie - Adds or interns the DIE to the compile unit.
146 void addDie(DIE *Buffer) {
147 this->CUDie->addChild(Buffer);
150 // getIndexTyDie - Get an anonymous type for index type.
151 DIE *getIndexTyDie() {
155 // setIndexTyDie - Set D as anonymous type for index which can be reused
157 void setIndexTyDie(DIE *D) {
162 /// addUInt - Add an unsigned integer attribute data and value.
164 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
166 /// addSInt - Add an signed integer attribute data and value.
168 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
170 /// addString - Add a string attribute data and value.
172 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
174 /// addLabel - Add a Dwarf label attribute data and value.
176 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
177 const MCSymbol *Label);
179 /// addDelta - Add a label delta attribute data and value.
181 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
182 const MCSymbol *Hi, const MCSymbol *Lo);
184 /// addDIEEntry - Add a DIE attribute data and value.
186 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
188 /// addBlock - Add block data.
190 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
192 /// addSourceLine - Add location information to specified debug information
194 void addSourceLine(DIE *Die, DIVariable V);
195 void addSourceLine(DIE *Die, DIGlobalVariable G);
196 void addSourceLine(DIE *Die, DISubprogram SP);
197 void addSourceLine(DIE *Die, DIType Ty);
198 void addSourceLine(DIE *Die, DINameSpace NS);
200 /// addAddress - Add an address attribute to a die based on the location
202 void addAddress(DIE *Die, unsigned Attribute,
203 const MachineLocation &Location);
205 /// addConstantValue - Add constant value entry in variable DIE.
206 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
207 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
209 /// addConstantFPValue - Add constant value entry in variable DIE.
210 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
212 /// addTemplateParams - Add template parameters in buffer.
213 void addTemplateParams(DIE &Buffer, DIArray TParams);
215 /// addRegisterOp - Add register operand.
216 void addRegisterOp(DIE *TheDie, unsigned Reg);
218 /// addRegisterOffset - Add register offset.
219 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
221 /// addComplexAddress - Start with the address based on the location provided,
222 /// and generate the DWARF information necessary to find the actual variable
223 /// (navigating the extra location information encoded in the type) based on
224 /// the starting location. Add the DWARF information to the die.
226 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
227 const MachineLocation &Location);
229 // FIXME: Should be reformulated in terms of addComplexAddress.
230 /// addBlockByrefAddress - Start with the address based on the location
231 /// provided, and generate the DWARF information necessary to find the
232 /// actual Block variable (navigating the Block struct) based on the
233 /// starting location. Add the DWARF information to the die. Obsolete,
234 /// please use addComplexAddress instead.
236 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
237 const MachineLocation &Location);
239 /// addVariableAddress - Add DW_AT_location attribute for a
240 /// DbgVariable based on provided MachineLocation.
241 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
243 /// addToContextOwner - Add Die into the list of its context owner's children.
244 void addToContextOwner(DIE *Die, DIDescriptor Context);
246 /// addType - Add a new type attribute to the specified entity.
247 void addType(DIE *Entity, DIType Ty);
249 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
250 DIE *getOrCreateNameSpace(DINameSpace NS);
252 /// getOrCreateSubprogramDIE - Create new DIE using SP.
253 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
255 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
257 DIE *getOrCreateTypeDIE(const MDNode *N);
259 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
260 /// for the given DITemplateTypeParameter.
261 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
263 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
264 /// for the given DITemplateValueParameter.
265 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
267 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
268 /// information entry.
269 DIEEntry *createDIEEntry(DIE *Entry);
271 /// createGlobalVariableDIE - create global variable DIE.
272 void createGlobalVariableDIE(const MDNode *N);
274 void addPubTypes(DISubprogram SP);
276 /// constructTypeDIE - Construct basic type die from DIBasicType.
277 void constructTypeDIE(DIE &Buffer,
280 /// constructTypeDIE - Construct derived type die from DIDerivedType.
281 void constructTypeDIE(DIE &Buffer,
284 /// constructTypeDIE - Construct type DIE from DICompositeType.
285 void constructTypeDIE(DIE &Buffer,
286 DICompositeType CTy);
288 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
289 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
291 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
292 void constructArrayTypeDIE(DIE &Buffer,
293 DICompositeType *CTy);
295 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
296 DIE *constructEnumTypeDIE(DIEnumerator ETy);
298 /// constructContainingTypeDIEs - Construct DIEs for types that contain
300 void constructContainingTypeDIEs();
302 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
303 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
305 /// createMemberDIE - Create new member DIE.
306 DIE *createMemberDIE(DIDerivedType DT);
310 // DIEValueAllocator - All DIEValues are allocated through this allocator.
311 BumpPtrAllocator DIEValueAllocator;
312 DIEInteger *DIEIntegerOne;
315 } // end llvm namespace