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<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<std::vector<DIE*> > &getAccelNames() const {
90 const StringMap<std::vector<DIE*> > &getAccelObjC() const {
93 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; }
94 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; }
96 /// hasContent - Return true if this compile unit has something to write out.
98 bool hasContent() const { return !CUDie->getChildren().empty(); }
100 /// addGlobalType - Add a new global type to the compile unit.
102 void addGlobalType(DIType Ty);
105 /// addAccelName - Add a new name to the name accelerator table.
106 void addAccelName(StringRef Name, DIE *Die) {
107 std::vector<DIE*> &DIEs = AccelNames[Name];
110 void addAccelObjC(StringRef Name, DIE *Die) {
111 std::vector<DIE*> &DIEs = AccelObjC[Name];
114 void addAccelNamespace(StringRef Name, DIE *Die) {
115 AccelNamespace[Name] = Die;
117 void addAccelType(StringRef Name, DIE *Die) {
118 AccelTypes[Name] = Die;
121 /// getDIE - Returns the debug information entry map slot for the
122 /// specified debug variable.
123 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
125 DIEBlock *getDIEBlock() {
126 return new (DIEValueAllocator) DIEBlock();
129 /// insertDIE - Insert DIE into the map.
130 void insertDIE(const MDNode *N, DIE *D) {
131 MDNodeToDieMap.insert(std::make_pair(N, D));
134 /// getDIEEntry - Returns the debug information entry for the specified
136 DIEEntry *getDIEEntry(const MDNode *N) {
137 DenseMap<const MDNode *, DIEEntry *>::iterator I =
138 MDNodeToDIEEntryMap.find(N);
139 if (I == MDNodeToDIEEntryMap.end())
144 /// insertDIEEntry - Insert debug information entry into the map.
145 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
146 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
149 /// addDie - Adds or interns the DIE to the compile unit.
151 void addDie(DIE *Buffer) {
152 this->CUDie->addChild(Buffer);
155 // getIndexTyDie - Get an anonymous type for index type.
156 DIE *getIndexTyDie() {
160 // setIndexTyDie - Set D as anonymous type for index which can be reused
162 void setIndexTyDie(DIE *D) {
167 /// addUInt - Add an unsigned integer attribute data and value.
169 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
171 /// addSInt - Add an signed integer attribute data and value.
173 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
175 /// addString - Add a string attribute data and value.
177 void addString(DIE *Die, unsigned Attribute, const StringRef Str);
179 /// addLabel - Add a Dwarf label attribute data and value.
181 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
182 const MCSymbol *Label);
184 /// addDelta - Add a label delta attribute data and value.
186 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
187 const MCSymbol *Hi, const MCSymbol *Lo);
189 /// addDIEEntry - Add a DIE attribute data and value.
191 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
193 /// addBlock - Add block data.
195 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
197 /// addSourceLine - Add location information to specified debug information
199 void addSourceLine(DIE *Die, DIVariable V);
200 void addSourceLine(DIE *Die, DIGlobalVariable G);
201 void addSourceLine(DIE *Die, DISubprogram SP);
202 void addSourceLine(DIE *Die, DIType Ty);
203 void addSourceLine(DIE *Die, DINameSpace NS);
205 /// addAddress - Add an address attribute to a die based on the location
207 void addAddress(DIE *Die, unsigned Attribute,
208 const MachineLocation &Location);
210 /// addConstantValue - Add constant value entry in variable DIE.
211 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
212 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned);
214 /// addConstantFPValue - Add constant value entry in variable DIE.
215 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
217 /// addTemplateParams - Add template parameters in buffer.
218 void addTemplateParams(DIE &Buffer, DIArray TParams);
220 /// addRegisterOp - Add register operand.
221 void addRegisterOp(DIE *TheDie, unsigned Reg);
223 /// addRegisterOffset - Add register offset.
224 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
226 /// addComplexAddress - Start with the address based on the location provided,
227 /// and generate the DWARF information necessary to find the actual variable
228 /// (navigating the extra location information encoded in the type) based on
229 /// the starting location. Add the DWARF information to the die.
231 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
232 const MachineLocation &Location);
234 // FIXME: Should be reformulated in terms of addComplexAddress.
235 /// addBlockByrefAddress - Start with the address based on the location
236 /// provided, and generate the DWARF information necessary to find the
237 /// actual Block variable (navigating the Block struct) based on the
238 /// starting location. Add the DWARF information to the die. Obsolete,
239 /// please use addComplexAddress instead.
241 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
242 const MachineLocation &Location);
244 /// addVariableAddress - Add DW_AT_location attribute for a
245 /// DbgVariable based on provided MachineLocation.
246 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
248 /// addToContextOwner - Add Die into the list of its context owner's children.
249 void addToContextOwner(DIE *Die, DIDescriptor Context);
251 /// addType - Add a new type attribute to the specified entity.
252 void addType(DIE *Entity, DIType Ty);
254 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
255 DIE *getOrCreateNameSpace(DINameSpace NS);
257 /// getOrCreateSubprogramDIE - Create new DIE using SP.
258 DIE *getOrCreateSubprogramDIE(DISubprogram SP);
260 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
262 DIE *getOrCreateTypeDIE(const MDNode *N);
264 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
265 /// for the given DITemplateTypeParameter.
266 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
268 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
269 /// for the given DITemplateValueParameter.
270 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
272 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
273 /// information entry.
274 DIEEntry *createDIEEntry(DIE *Entry);
276 /// createGlobalVariableDIE - create global variable DIE.
277 void createGlobalVariableDIE(const MDNode *N);
279 void addPubTypes(DISubprogram SP);
281 /// constructTypeDIE - Construct basic type die from DIBasicType.
282 void constructTypeDIE(DIE &Buffer,
285 /// constructTypeDIE - Construct derived type die from DIDerivedType.
286 void constructTypeDIE(DIE &Buffer,
289 /// constructTypeDIE - Construct type DIE from DICompositeType.
290 void constructTypeDIE(DIE &Buffer,
291 DICompositeType CTy);
293 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
294 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
296 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
297 void constructArrayTypeDIE(DIE &Buffer,
298 DICompositeType *CTy);
300 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
301 DIE *constructEnumTypeDIE(DIEnumerator ETy);
303 /// constructContainingTypeDIEs - Construct DIEs for types that contain
305 void constructContainingTypeDIEs();
307 /// constructVariableDIE - Construct a DIE for the given DbgVariable.
308 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract);
310 /// createMemberDIE - Create new member DIE.
311 DIE *createMemberDIE(DIDerivedType DT);
315 // DIEValueAllocator - All DIEValues are allocated through this allocator.
316 BumpPtrAllocator DIEValueAllocator;
317 DIEInteger *DIEIntegerOne;
320 } // end llvm namespace