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 speciefied
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 /// addRegisterAddress - Add register location entry in variable DIE.
185 bool addRegisterAddress(DIE *Die, const MachineOperand &MO);
187 /// addConstantValue - Add constant value entry in variable DIE.
188 bool addConstantValue(DIE *Die, const MachineOperand &MO);
189 bool addConstantValue(DIE *Die, ConstantInt *CI, bool Unsigned);
191 /// addConstantFPValue - Add constant value entry in variable DIE.
192 bool addConstantFPValue(DIE *Die, const MachineOperand &MO);
194 /// addTemplateParams - Add template parameters in buffer.
195 void addTemplateParams(DIE &Buffer, DIArray TParams);
197 /// addComplexAddress - Start with the address based on the location provided,
198 /// and generate the DWARF information necessary to find the actual variable
199 /// (navigating the extra location information encoded in the type) based on
200 /// the starting location. Add the DWARF information to the die.
202 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
203 const MachineLocation &Location);
205 // FIXME: Should be reformulated in terms of addComplexAddress.
206 /// addBlockByrefAddress - Start with the address based on the location
207 /// provided, and generate the DWARF information necessary to find the
208 /// actual Block variable (navigating the Block struct) based on the
209 /// starting location. Add the DWARF information to the die. Obsolete,
210 /// please use addComplexAddress instead.
212 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute,
213 const MachineLocation &Location);
215 /// addFrameVariableAddress - Add DW_AT_location attribute for a DbgVariable
216 /// based on provided frame index.
217 void addFrameVariableAddress(DbgVariable *&DV, DIE *Die, int64_t FI);
219 /// addToContextOwner - Add Die into the list of its context owner's children.
220 void addToContextOwner(DIE *Die, DIDescriptor Context);
222 /// addType - Add a new type attribute to the specified entity.
223 void addType(DIE *Entity, DIType Ty);
225 /// getOrCreateNameSpace - Create a DIE for DINameSpace.
226 DIE *getOrCreateNameSpace(DINameSpace NS);
228 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the
230 DIE *getOrCreateTypeDIE(DIType Ty);
232 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE
233 /// for the given DITemplateTypeParameter.
234 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP);
236 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE
237 /// for the given DITemplateValueParameter.
238 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP);
240 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug
241 /// information entry.
242 DIEEntry *createDIEEntry(DIE *Entry);
244 void addPubTypes(DISubprogram SP);
246 /// constructTypeDIE - Construct basic type die from DIBasicType.
247 void constructTypeDIE(DIE &Buffer,
250 /// constructTypeDIE - Construct derived type die from DIDerivedType.
251 void constructTypeDIE(DIE &Buffer,
254 /// constructTypeDIE - Construct type DIE from DICompositeType.
255 void constructTypeDIE(DIE &Buffer,
256 DICompositeType CTy);
258 /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
259 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
261 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
262 void constructArrayTypeDIE(DIE &Buffer,
263 DICompositeType *CTy);
265 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
266 DIE *constructEnumTypeDIE(DIEnumerator ETy);
268 /// createMemberDIE - Create new member DIE.
269 DIE *createMemberDIE(DIDerivedType DT);
273 // DIEValueAllocator - All DIEValues are allocated through this allocator.
274 BumpPtrAllocator DIEValueAllocator;
275 DIEInteger *DIEIntegerOne;
278 } // end llvm namespace