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;
71 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW);
75 unsigned getID() const { return ID; }
76 DIE* getCUDie() const { return CUDie.get(); }
77 const StringMap<DIE*> &getGlobals() const { return Globals; }
78 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; }
80 /// hasContent - Return true if this compile unit has something to write out.
82 bool hasContent() const { return !CUDie->getChildren().empty(); }
84 /// addGlobal - Add a new global entity to the compile unit.
86 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; }
88 /// addGlobalType - Add a new global type to the compile unit.
90 void addGlobalType(StringRef Name, DIE *Die) {
91 GlobalTypes[Name] = Die;
94 /// getDIE - Returns the debug information entry map slot for the
95 /// specified debug variable.
96 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); }
98 DIEBlock *getDIEBlock() {
99 return new (DIEValueAllocator) DIEBlock();
102 /// insertDIE - Insert DIE into the map.
103 void insertDIE(const MDNode *N, DIE *D) {
104 MDNodeToDieMap.insert(std::make_pair(N, D));
107 /// getDIEEntry - Returns the debug information entry for the specified
109 DIEEntry *getDIEEntry(const MDNode *N) {
110 DenseMap<const MDNode *, DIEEntry *>::iterator I =
111 MDNodeToDIEEntryMap.find(N);
112 if (I == MDNodeToDIEEntryMap.end())
117 /// insertDIEEntry - Insert debug information entry into the map.
118 void insertDIEEntry(const MDNode *N, DIEEntry *E) {
119 MDNodeToDIEEntryMap.insert(std::make_pair(N, E));
122 /// addDie - Adds or interns the DIE to the compile unit.
124 void addDie(DIE *Buffer) {
125 this->CUDie->addChild(Buffer);
128 // getIndexTyDie - Get an anonymous type for index type.
129 DIE *getIndexTyDie() {
133 // setIndexTyDie - Set D as anonymous type for index which can be reused
135 void setIndexTyDie(DIE *D) {
140 /// addUInt - Add an unsigned integer attribute data and value.
142 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer);
144 /// addSInt - Add an signed integer attribute data and value.
146 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer);
148 /// addString - Add a string attribute data and value.
150 void addString(DIE *Die, unsigned Attribute, unsigned Form,
151 const StringRef Str);
153 /// addLabel - Add a Dwarf label attribute data and value.
155 void addLabel(DIE *Die, unsigned Attribute, unsigned Form,
156 const MCSymbol *Label);
158 /// addDelta - Add a label delta attribute data and value.
160 void addDelta(DIE *Die, unsigned Attribute, unsigned Form,
161 const MCSymbol *Hi, const MCSymbol *Lo);
163 /// addDIEEntry - Add a DIE attribute data and value.
165 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry);
167 /// addBlock - Add block data.
169 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block);
171 /// addSourceLine - Add location information to specified debug information
173 void addSourceLine(DIE *Die, DIVariable V);
174 void addSourceLine(DIE *Die, DIGlobalVariable G);
175 void addSourceLine(DIE *Die, DISubprogram SP);
176 void addSourceLine(DIE *Die, DIType Ty);
177 void addSourceLine(DIE *Die, DINameSpace NS);
179 /// addAddress - Add an address attribute to a die based on the location
181 void addAddress(DIE *Die, unsigned Attribute,
182 const MachineLocation &Location);
184 /// addConstantValue - Add constant value entry in variable DIE.
185 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty);
186 bool addConstantValue(DIE *Die, ConstantInt *CI, bool Unsigned);
188 /// addConstantFPValue - Add constant value entry in variable DIE.
189 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
191 /// addTemplateParams - Add template parameters in buffer.
192 void addTemplateParams(DIE &Buffer, DIArray TParams);
194 /// addRegisterOp - Add register operand.
195 void addRegisterOp(DIE *TheDie, unsigned Reg);
197 /// addRegisterOffset - Add register offset.
198 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset);
200 /// addComplexAddress - Start with the address based on the location provided,
201 /// and generate the DWARF information necessary to find the actual variable
202 /// (navigating the extra location information encoded in the type) based on
203 /// the starting location. Add the DWARF information to the die.
205 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
206 const MachineLocation &Location);
208 // FIXME: Should be reformulated in terms of addComplexAddress.
209 /// addBlockByrefAddress - Start with the address based on the location
210 /// provided, and generate the DWARF information necessary to find the
211 /// actual Block variable (navigating the Block struct) based on the
212 /// starting location. Add the DWARF information to the die. Obsolete,
213 /// please use addComplexAddress instead.
215 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
216 const MachineLocation &Location);
218 /// addVariableAddress - Add DW_AT_location attribute for a
219 /// DbgVariable based on provided MachineLocation.
220 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location);
222 /// addToContextOwner - Add Die into the list of its context owner's children.
223 void addToContextOwner(DIE *Die, DIDescriptor Context);
225 /// addType - Add a new type attribute to the specified entity.
226 void addType(DIE *Entity, DIType Ty);
228 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
229 DIE *getOrCreateNameSpace(DINameSpace NS);
231 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
233 DIE *getOrCreateTypeDIE(DIType Ty);
235 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
236 /// for the given DITemplateTypeParameter.
237 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
239 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
240 /// for the given DITemplateValueParameter.
241 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
243 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
244 /// information entry.
245 DIEEntry *createDIEEntry(DIE *Entry);
247 void addPubTypes(DISubprogram SP);
249 /// constructTypeDIE - Construct basic type die from DIBasicType.
250 void constructTypeDIE(DIE &Buffer,
253 /// constructTypeDIE - Construct derived type die from DIDerivedType.
254 void constructTypeDIE(DIE &Buffer,
257 /// constructTypeDIE - Construct type DIE from DICompositeType.
258 void constructTypeDIE(DIE &Buffer,
259 DICompositeType CTy);
261 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
262 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
264 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
265 void constructArrayTypeDIE(DIE &Buffer,
266 DICompositeType *CTy);
268 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
269 DIE *constructEnumTypeDIE(DIEnumerator ETy);
271 /// createMemberDIE - Create new member DIE.
272 DIE *createMemberDIE(DIDerivedType DT);
276 // DIEValueAllocator - All DIEValues are allocated through this allocator.
277 BumpPtrAllocator DIEValueAllocator;
278 DIEInteger *DIEIntegerOne;
281 } // end llvm namespace