Refactor the DIFile (2nd) parameter to DITypes to be an MDNode reference to a raw...
[oota-llvm.git] / include / llvm / DebugInfo.h
1 //===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a bunch of datatypes that are useful for creating and
11 // walking debug info in LLVM IR form. They essentially provide wrappers around
12 // the information in the global variables that's needed when constructing the
13 // DWARF information.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_DEBUGINFO_H
18 #define LLVM_DEBUGINFO_H
19
20 #include "llvm/ADT/SmallPtrSet.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringRef.h"
23 #include "llvm/Support/Dwarf.h"
24
25 namespace llvm {
26   class BasicBlock;
27   class Constant;
28   class Function;
29   class GlobalVariable;
30   class Module;
31   class Type;
32   class Value;
33   class DbgDeclareInst;
34   class Instruction;
35   class MDNode;
36   class NamedMDNode;
37   class LLVMContext;
38   class raw_ostream;
39
40   class DIFile;
41   class DISubprogram;
42   class DILexicalBlock;
43   class DILexicalBlockFile;
44   class DIVariable;
45   class DIType;
46   class DIObjCProperty;
47
48   /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
49   /// This should not be stored in a container, because the underlying MDNode
50   /// may change in certain situations.
51   class DIDescriptor {
52   public:
53     enum {
54       FlagPrivate            = 1 << 0,
55       FlagProtected          = 1 << 1,
56       FlagFwdDecl            = 1 << 2,
57       FlagAppleBlock         = 1 << 3,
58       FlagBlockByrefStruct   = 1 << 4,
59       FlagVirtual            = 1 << 5,
60       FlagArtificial         = 1 << 6,
61       FlagExplicit           = 1 << 7,
62       FlagPrototyped         = 1 << 8,
63       FlagObjcClassComplete  = 1 << 9,
64       FlagObjectPointer      = 1 << 10,
65       FlagVector             = 1 << 11,
66       FlagStaticMember       = 1 << 12
67     };
68   protected:
69     const MDNode *DbgNode;
70
71     StringRef getStringField(unsigned Elt) const;
72     unsigned getUnsignedField(unsigned Elt) const {
73       return (unsigned)getUInt64Field(Elt);
74     }
75     uint64_t getUInt64Field(unsigned Elt) const;
76     int64_t getInt64Field(unsigned Elt) const;
77     DIDescriptor getDescriptorField(unsigned Elt) const;
78
79     template <typename DescTy>
80     DescTy getFieldAs(unsigned Elt) const {
81       return DescTy(getDescriptorField(Elt));
82     }
83
84     GlobalVariable *getGlobalVariableField(unsigned Elt) const;
85     Constant *getConstantField(unsigned Elt) const;
86     Function *getFunctionField(unsigned Elt) const;
87     void replaceFunctionField(unsigned Elt, Function *F);
88
89   public:
90     explicit DIDescriptor() : DbgNode(0) {}
91     explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
92     explicit DIDescriptor(const DIFile F);
93     explicit DIDescriptor(const DISubprogram F);
94     explicit DIDescriptor(const DILexicalBlockFile F);
95     explicit DIDescriptor(const DILexicalBlock F);
96     explicit DIDescriptor(const DIVariable F);
97     explicit DIDescriptor(const DIType F);
98
99     bool Verify() const;
100
101     operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
102     MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
103
104     unsigned getTag() const {
105       return getUnsignedField(0) & ~LLVMDebugVersionMask;
106     }
107
108     bool isDerivedType() const;
109     bool isCompositeType() const;
110     bool isBasicType() const;
111     bool isVariable() const;
112     bool isSubprogram() const;
113     bool isGlobalVariable() const;
114     bool isScope() const;
115     bool isFile() const;
116     bool isCompileUnit() const;
117     bool isNameSpace() const;
118     bool isLexicalBlockFile() const;
119     bool isLexicalBlock() const;
120     bool isSubrange() const;
121     bool isEnumerator() const;
122     bool isType() const;
123     bool isGlobal() const;
124     bool isUnspecifiedParameter() const;
125     bool isTemplateTypeParameter() const;
126     bool isTemplateValueParameter() const;
127     bool isObjCProperty() const;
128
129     /// print - print descriptor.
130     void print(raw_ostream &OS) const;
131
132     /// dump - print descriptor to dbgs() with a newline.
133     void dump() const;
134   };
135
136   /// DISubrange - This is used to represent ranges, for array bounds.
137   class DISubrange : public DIDescriptor {
138     friend class DIDescriptor;
139     void printInternal(raw_ostream &OS) const;
140   public:
141     explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
142
143     int64_t getLo() const { return getInt64Field(1); }
144     int64_t  getCount() const { return getInt64Field(2); }
145     bool Verify() const;
146   };
147
148   /// DIArray - This descriptor holds an array of descriptors.
149   class DIArray : public DIDescriptor {
150   public:
151     explicit DIArray(const MDNode *N = 0)
152       : DIDescriptor(N) {}
153
154     unsigned getNumElements() const;
155     DIDescriptor getElement(unsigned Idx) const {
156       return getDescriptorField(Idx);
157     }
158   };
159
160   /// DIScope - A base class for various scopes.
161   class DIScope : public DIDescriptor {
162   protected:
163     friend class DIDescriptor;
164     void printInternal(raw_ostream &OS) const;
165   public:
166     explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
167
168     StringRef getFilename() const;
169     StringRef getDirectory() const;
170   };
171
172   /// DIFile - This is a wrapper for a file.
173   class DIFile : public DIScope {
174     friend class DIDescriptor;
175   public:
176     explicit DIFile(const MDNode *N = 0) : DIScope(N) {
177       if (DbgNode && !isFile())
178         DbgNode = 0;
179     }
180     MDNode *getFileNode() const;
181     bool Verify() const;
182   };
183
184   /// DICompileUnit - A wrapper for a compile unit.
185   class DICompileUnit : public DIScope {
186     friend class DIDescriptor;
187     void printInternal(raw_ostream &OS) const;
188   public:
189     explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
190
191     unsigned getLanguage() const { return getUnsignedField(2); }
192     StringRef getFilename() const {
193       return getFieldAs<DIFile>(3).getFilename();
194     }
195     StringRef getDirectory() const {
196       return getFieldAs<DIFile>(3).getDirectory();
197     }
198     StringRef getProducer() const { return getStringField(4); }
199
200     bool isOptimized() const { return getUnsignedField(5) != 0; }
201     StringRef getFlags() const { return getStringField(6); }
202     unsigned getRunTimeVersion() const { return getUnsignedField(7); }
203
204     DIArray getEnumTypes() const;
205     DIArray getRetainedTypes() const;
206     DIArray getSubprograms() const;
207     DIArray getGlobalVariables() const;
208
209     StringRef getSplitDebugFilename() const { return getStringField(12); }
210
211     /// Verify - Verify that a compile unit is well formed.
212     bool Verify() const;
213   };
214
215   /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
216   /// FIXME: it seems strange that this doesn't have either a reference to the
217   /// type/precision or a file/line pair for location info.
218   class DIEnumerator : public DIDescriptor {
219     friend class DIDescriptor;
220     void printInternal(raw_ostream &OS) const;
221   public:
222     explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
223
224     StringRef getName() const        { return getStringField(1); }
225     uint64_t getEnumValue() const      { return getUInt64Field(2); }
226     bool Verify() const;
227   };
228
229   /// DIType - This is a wrapper for a type.
230   /// FIXME: Types should be factored much better so that CV qualifiers and
231   /// others do not require a huge and empty descriptor full of zeros.
232   class DIType : public DIScope {
233   protected:
234     friend class DIDescriptor;
235     void printInternal(raw_ostream &OS) const;
236     // This ctor is used when the Tag has already been validated by a derived
237     // ctor.
238     DIType(const MDNode *N, bool, bool) : DIScope(N) {}
239   public:
240     /// Verify - Verify that a type descriptor is well formed.
241     bool Verify() const;
242     explicit DIType(const MDNode *N);
243     explicit DIType() {}
244
245     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
246     StringRef getName() const           { return getStringField(3);     }
247     unsigned getLineNumber() const      { return getUnsignedField(4); }
248     uint64_t getSizeInBits() const      { return getUInt64Field(5); }
249     uint64_t getAlignInBits() const     { return getUInt64Field(6); }
250     // FIXME: Offset is only used for DW_TAG_member nodes.  Making every type
251     // carry this is just plain insane.
252     uint64_t getOffsetInBits() const    { return getUInt64Field(7); }
253     unsigned getFlags() const           { return getUnsignedField(8); }
254     bool isPrivate() const {
255       return (getFlags() & FlagPrivate) != 0;
256     }
257     bool isProtected() const {
258       return (getFlags() & FlagProtected) != 0;
259     }
260     bool isForwardDecl() const {
261       return (getFlags() & FlagFwdDecl) != 0;
262     }
263     // isAppleBlock - Return true if this is the Apple Blocks extension.
264     bool isAppleBlockExtension() const {
265       return (getFlags() & FlagAppleBlock) != 0;
266     }
267     bool isBlockByrefStruct() const {
268       return (getFlags() & FlagBlockByrefStruct) != 0;
269     }
270     bool isVirtual() const {
271       return (getFlags() & FlagVirtual) != 0;
272     }
273     bool isArtificial() const {
274       return (getFlags() & FlagArtificial) != 0;
275     }
276     bool isObjectPointer() const {
277       return (getFlags() & FlagObjectPointer) != 0;
278     }
279     bool isObjcClassComplete() const {
280       return (getFlags() & FlagObjcClassComplete) != 0;
281     }
282     bool isVector() const {
283       return (getFlags() & FlagVector) != 0;
284     }
285     bool isStaticMember() const {
286       return (getFlags() & FlagStaticMember) != 0;
287     }
288     bool isValid() const {
289       return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
290     }
291
292     /// isUnsignedDIType - Return true if type encoding is unsigned.
293     bool isUnsignedDIType();
294
295     /// replaceAllUsesWith - Replace all uses of debug info referenced by
296     /// this descriptor.
297     void replaceAllUsesWith(DIDescriptor &D);
298     void replaceAllUsesWith(MDNode *D);
299   };
300
301   /// DIBasicType - A basic type, like 'int' or 'float'.
302   class DIBasicType : public DIType {
303   public:
304     explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
305
306     unsigned getEncoding() const { return getUnsignedField(9); }
307
308     /// Verify - Verify that a basic type descriptor is well formed.
309     bool Verify() const;
310   };
311
312   /// DIDerivedType - A simple derived type, like a const qualified type,
313   /// a typedef, a pointer or reference, et cetera.  Or, a data member of
314   /// a class/struct/union.
315   class DIDerivedType : public DIType {
316     friend class DIDescriptor;
317     void printInternal(raw_ostream &OS) const;
318   protected:
319     explicit DIDerivedType(const MDNode *N, bool, bool)
320       : DIType(N, true, true) {}
321   public:
322     explicit DIDerivedType(const MDNode *N = 0)
323       : DIType(N, true, true) {}
324
325     DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
326
327     /// getOriginalTypeSize - If this type is derived from a base type then
328     /// return base type size.
329     uint64_t getOriginalTypeSize() const;
330
331     /// getObjCProperty - Return property node, if this ivar is
332     /// associated with one.
333     MDNode *getObjCProperty() const;
334
335     DIType getClassType() const {
336       assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
337       return getFieldAs<DIType>(10);
338     }
339
340     Constant *getConstant() const {
341       assert((getTag() == dwarf::DW_TAG_member) && isStaticMember());
342       return getConstantField(10);
343     }
344
345     /// Verify - Verify that a derived type descriptor is well formed.
346     bool Verify() const;
347   };
348
349   /// DICompositeType - This descriptor holds a type that can refer to multiple
350   /// other types, like a function or struct.
351   /// FIXME: Why is this a DIDerivedType??
352   class DICompositeType : public DIDerivedType {
353     friend class DIDescriptor;
354     void printInternal(raw_ostream &OS) const;
355   public:
356     explicit DICompositeType(const MDNode *N = 0)
357       : DIDerivedType(N, true, true) {
358       if (N && !isCompositeType())
359         DbgNode = 0;
360     }
361
362     DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
363     unsigned getRunTimeLang() const { return getUnsignedField(11); }
364     DICompositeType getContainingType() const {
365       return getFieldAs<DICompositeType>(12);
366     }
367     DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
368
369     /// Verify - Verify that a composite type descriptor is well formed.
370     bool Verify() const;
371   };
372
373   /// DITemplateTypeParameter - This is a wrapper for template type parameter.
374   class DITemplateTypeParameter : public DIDescriptor {
375   public:
376     explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
377
378     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
379     StringRef getName() const        { return getStringField(2); }
380     DIType getType() const           { return getFieldAs<DIType>(3); }
381     StringRef getFilename() const    {
382       return getFieldAs<DIFile>(4).getFilename();
383     }
384     StringRef getDirectory() const   {
385       return getFieldAs<DIFile>(4).getDirectory();
386     }
387     unsigned getLineNumber() const   { return getUnsignedField(5); }
388     unsigned getColumnNumber() const { return getUnsignedField(6); }
389     bool Verify() const;
390   };
391
392   /// DITemplateValueParameter - This is a wrapper for template value parameter.
393   class DITemplateValueParameter : public DIDescriptor {
394   public:
395     explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
396
397     DIScope getContext() const       { return getFieldAs<DIScope>(1); }
398     StringRef getName() const        { return getStringField(2); }
399     DIType getType() const           { return getFieldAs<DIType>(3); }
400     uint64_t getValue() const         { return getUInt64Field(4); }
401     StringRef getFilename() const    {
402       return getFieldAs<DIFile>(5).getFilename();
403     }
404     StringRef getDirectory() const   {
405       return getFieldAs<DIFile>(5).getDirectory();
406     }
407     unsigned getLineNumber() const   { return getUnsignedField(6); }
408     unsigned getColumnNumber() const { return getUnsignedField(7); }
409     bool Verify() const;
410   };
411
412   /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
413   class DISubprogram : public DIScope {
414     friend class DIDescriptor;
415     void printInternal(raw_ostream &OS) const;
416   public:
417     explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
418
419     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
420     StringRef getName() const         { return getStringField(3); }
421     StringRef getDisplayName() const  { return getStringField(4); }
422     StringRef getLinkageName() const  { return getStringField(5); }
423     unsigned getLineNumber() const      { return getUnsignedField(7); }
424     DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
425
426     /// getReturnTypeName - Subprogram return types are encoded either as
427     /// DIType or as DICompositeType.
428     StringRef getReturnTypeName() const {
429       DICompositeType DCT(getFieldAs<DICompositeType>(8));
430       if (DCT.Verify()) {
431         DIArray A = DCT.getTypeArray();
432         DIType T(A.getElement(0));
433         return T.getName();
434       }
435       DIType T(getFieldAs<DIType>(8));
436       return T.getName();
437     }
438
439     /// isLocalToUnit - Return true if this subprogram is local to the current
440     /// compile unit, like 'static' in C.
441     unsigned isLocalToUnit() const     { return getUnsignedField(9); }
442     unsigned isDefinition() const      { return getUnsignedField(10); }
443
444     unsigned getVirtuality() const { return getUnsignedField(11); }
445     unsigned getVirtualIndex() const { return getUnsignedField(12); }
446
447     DICompositeType getContainingType() const {
448       return getFieldAs<DICompositeType>(13);
449     }
450
451     unsigned getFlags() const {
452       return getUnsignedField(14);
453     }
454
455     unsigned isArtificial() const    {
456       return (getUnsignedField(14) & FlagArtificial) != 0;
457     }
458     /// isPrivate - Return true if this subprogram has "private"
459     /// access specifier.
460     bool isPrivate() const    {
461       return (getUnsignedField(14) & FlagPrivate) != 0;
462     }
463     /// isProtected - Return true if this subprogram has "protected"
464     /// access specifier.
465     bool isProtected() const    {
466       return (getUnsignedField(14) & FlagProtected) != 0;
467     }
468     /// isExplicit - Return true if this subprogram is marked as explicit.
469     bool isExplicit() const    {
470       return (getUnsignedField(14) & FlagExplicit) != 0;
471     }
472     /// isPrototyped - Return true if this subprogram is prototyped.
473     bool isPrototyped() const    {
474       return (getUnsignedField(14) & FlagPrototyped) != 0;
475     }
476
477     unsigned isOptimized() const;
478
479     StringRef getFilename() const    {
480       return getFieldAs<DIFile>(6).getFilename();
481     }
482
483     StringRef getDirectory() const   {
484       return getFieldAs<DIFile>(6).getDirectory();
485     }
486
487     DIFile getFile() const {
488       return getFieldAs<DIFile>(6);
489     }
490
491     /// getScopeLineNumber - Get the beginning of the scope of the
492     /// function, not necessarily where the name of the program
493     /// starts.
494     unsigned getScopeLineNumber() const { return getUnsignedField(20); }
495
496     /// Verify - Verify that a subprogram descriptor is well formed.
497     bool Verify() const;
498
499     /// describes - Return true if this subprogram provides debugging
500     /// information for the function F.
501     bool describes(const Function *F);
502
503     Function *getFunction() const { return getFunctionField(16); }
504     void replaceFunction(Function *F) { replaceFunctionField(16, F); }
505     DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
506     DISubprogram getFunctionDeclaration() const {
507       return getFieldAs<DISubprogram>(18);
508     }
509     MDNode *getVariablesNodes() const;
510     DIArray getVariables() const;
511   };
512
513   /// DIGlobalVariable - This is a wrapper for a global variable.
514   class DIGlobalVariable : public DIDescriptor {
515     friend class DIDescriptor;
516     void printInternal(raw_ostream &OS) const;
517   public:
518     explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
519
520     DIScope getContext() const          { return getFieldAs<DIScope>(2); }
521     StringRef getName() const         { return getStringField(3); }
522     StringRef getDisplayName() const  { return getStringField(4); }
523     StringRef getLinkageName() const  { return getStringField(5); }
524     StringRef getFilename() const {
525       return getFieldAs<DIFile>(6).getFilename();
526     }
527     StringRef getDirectory() const {
528       return getFieldAs<DIFile>(6).getDirectory();
529
530     }
531
532     unsigned getLineNumber() const      { return getUnsignedField(7); }
533     DIType getType() const              { return getFieldAs<DIType>(8); }
534     unsigned isLocalToUnit() const      { return getUnsignedField(9); }
535     unsigned isDefinition() const       { return getUnsignedField(10); }
536
537     GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
538     Constant *getConstant() const   { return getConstantField(11); }
539     DIDerivedType getStaticDataMemberDeclaration() const {
540       return getFieldAs<DIDerivedType>(12);
541     }
542
543     /// Verify - Verify that a global variable descriptor is well formed.
544     bool Verify() const;
545   };
546
547   /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
548   /// global etc).
549   class DIVariable : public DIDescriptor {
550     friend class DIDescriptor;
551     void printInternal(raw_ostream &OS) const;
552   public:
553     explicit DIVariable(const MDNode *N = 0)
554       : DIDescriptor(N) {}
555
556     DIScope getContext() const          { return getFieldAs<DIScope>(1); }
557     StringRef getName() const           { return getStringField(2);     }
558     DIFile getFile() const              { return getFieldAs<DIFile>(3); }
559     unsigned getLineNumber() const      {
560       return (getUnsignedField(4) << 8) >> 8;
561     }
562     unsigned getArgNumber() const       {
563       unsigned L = getUnsignedField(4);
564       return L >> 24;
565     }
566     DIType getType() const              { return getFieldAs<DIType>(5); }
567
568     /// isArtificial - Return true if this variable is marked as "artificial".
569     bool isArtificial() const    {
570       return (getUnsignedField(6) & FlagArtificial) != 0;
571     }
572
573     bool isObjectPointer() const {
574       return (getUnsignedField(6) & FlagObjectPointer) != 0;
575     }
576
577     /// getInlinedAt - If this variable is inlined then return inline location.
578     MDNode *getInlinedAt() const;
579
580     /// Verify - Verify that a variable descriptor is well formed.
581     bool Verify() const;
582
583     /// HasComplexAddr - Return true if the variable has a complex address.
584     bool hasComplexAddress() const {
585       return getNumAddrElements() > 0;
586     }
587
588     unsigned getNumAddrElements() const;
589
590     uint64_t getAddrElement(unsigned Idx) const {
591       return getUInt64Field(Idx+8);
592     }
593
594     /// isBlockByrefVariable - Return true if the variable was declared as
595     /// a "__block" variable (Apple Blocks).
596     bool isBlockByrefVariable() const {
597       return getType().isBlockByrefStruct();
598     }
599
600     /// isInlinedFnArgument - Return true if this variable provides debugging
601     /// information for an inlined function arguments.
602     bool isInlinedFnArgument(const Function *CurFn);
603
604     void printExtendedName(raw_ostream &OS) const;
605   };
606
607   /// DILexicalBlock - This is a wrapper for a lexical block.
608   class DILexicalBlock : public DIScope {
609   public:
610     explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
611     DIScope getContext() const       { return getFieldAs<DIScope>(1);      }
612     unsigned getLineNumber() const   { return getUnsignedField(2);         }
613     unsigned getColumnNumber() const { return getUnsignedField(3);         }
614     StringRef getDirectory() const {
615       return getFieldAs<DIFile>(4).getDirectory();
616     }
617     StringRef getFilename() const {
618       return getFieldAs<DIFile>(4).getFilename();
619     }
620     bool Verify() const;
621   };
622
623   /// DILexicalBlockFile - This is a wrapper for a lexical block with
624   /// a filename change.
625   class DILexicalBlockFile : public DIScope {
626   public:
627     explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
628     DIScope getContext() const { if (getScope().isSubprogram()) return getScope(); return getScope().getContext(); }
629     unsigned getLineNumber() const { return getScope().getLineNumber(); }
630     unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
631     StringRef getDirectory() const {
632       return getFieldAs<DIFile>(2).getDirectory();
633     }
634     StringRef getFilename() const {
635       return getFieldAs<DIFile>(2).getFilename();
636     }
637     DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
638     bool Verify() const;
639   };
640
641   /// DINameSpace - A wrapper for a C++ style name space.
642   class DINameSpace : public DIScope {
643   public:
644     explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
645     DIScope getContext() const     { return getFieldAs<DIScope>(1);      }
646     StringRef getName() const      { return getStringField(2);           }
647     StringRef getDirectory() const  {
648       return getFieldAs<DIFile>(3).getDirectory();
649     }
650     StringRef getFilename() const  {
651       return getFieldAs<DIFile>(3).getFilename();
652     }
653     unsigned getLineNumber() const { return getUnsignedField(4);         }
654     bool Verify() const;
655   };
656
657   /// DILocation - This object holds location information. This object
658   /// is not associated with any DWARF tag.
659   class DILocation : public DIDescriptor {
660   public:
661     explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
662
663     unsigned getLineNumber() const     { return getUnsignedField(0); }
664     unsigned getColumnNumber() const   { return getUnsignedField(1); }
665     DIScope  getScope() const          { return getFieldAs<DIScope>(2); }
666     DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
667     StringRef getFilename() const    { return getScope().getFilename(); }
668     StringRef getDirectory() const   { return getScope().getDirectory(); }
669     bool Verify() const;
670   };
671
672   class DIObjCProperty : public DIDescriptor {
673     friend class DIDescriptor;
674     void printInternal(raw_ostream &OS) const;
675   public:
676     explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
677
678     StringRef getObjCPropertyName() const { return getStringField(1); }
679     DIFile getFile() const { return getFieldAs<DIFile>(2); }
680     unsigned getLineNumber() const { return getUnsignedField(3); }
681
682     StringRef getObjCPropertyGetterName() const {
683       return getStringField(4);
684     }
685     StringRef getObjCPropertySetterName() const {
686       return getStringField(5);
687     }
688     bool isReadOnlyObjCProperty() {
689       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
690     }
691     bool isReadWriteObjCProperty() {
692       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
693     }
694     bool isAssignObjCProperty() {
695       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
696     }
697     bool isRetainObjCProperty() {
698       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
699     }
700     bool isCopyObjCProperty() {
701       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
702     }
703     bool isNonAtomicObjCProperty() {
704       return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
705     }
706
707     DIType getType() const { return getFieldAs<DIType>(7); }
708
709     /// Verify - Verify that a derived type descriptor is well formed.
710     bool Verify() const;
711   };
712
713   /// getDISubprogram - Find subprogram that is enclosing this scope.
714   DISubprogram getDISubprogram(const MDNode *Scope);
715
716   /// getDICompositeType - Find underlying composite type.
717   DICompositeType getDICompositeType(DIType T);
718
719   /// isSubprogramContext - Return true if Context is either a subprogram
720   /// or another context nested inside a subprogram.
721   bool isSubprogramContext(const MDNode *Context);
722
723   /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
724   /// to hold function specific information.
725   NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
726
727   /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
728   /// suitable to hold function specific information.
729   NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
730
731   /// createInlinedVariable - Create a new inlined variable based on current
732   /// variable.
733   /// @param DV            Current Variable.
734   /// @param InlinedScope  Location at current variable is inlined.
735   DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
736                                    LLVMContext &VMContext);
737
738   /// cleanseInlinedVariable - Remove inlined scope from the variable.
739   DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
740
741   class DebugInfoFinder {
742   public:
743     /// processModule - Process entire module and collect debug info
744     /// anchors.
745     void processModule(const Module &M);
746
747   private:
748     /// processType - Process DIType.
749     void processType(DIType DT);
750
751     /// processLexicalBlock - Process DILexicalBlock.
752     void processLexicalBlock(DILexicalBlock LB);
753
754     /// processSubprogram - Process DISubprogram.
755     void processSubprogram(DISubprogram SP);
756
757     /// processDeclare - Process DbgDeclareInst.
758     void processDeclare(const DbgDeclareInst *DDI);
759
760     /// processLocation - Process DILocation.
761     void processLocation(DILocation Loc);
762
763     /// addCompileUnit - Add compile unit into CUs.
764     bool addCompileUnit(DICompileUnit CU);
765
766     /// addGlobalVariable - Add global variable into GVs.
767     bool addGlobalVariable(DIGlobalVariable DIG);
768
769     // addSubprogram - Add subprogram into SPs.
770     bool addSubprogram(DISubprogram SP);
771
772     /// addType - Add type into Tys.
773     bool addType(DIType DT);
774
775   public:
776     typedef SmallVector<MDNode *, 8>::const_iterator iterator;
777     iterator compile_unit_begin()    const { return CUs.begin(); }
778     iterator compile_unit_end()      const { return CUs.end(); }
779     iterator subprogram_begin()      const { return SPs.begin(); }
780     iterator subprogram_end()        const { return SPs.end(); }
781     iterator global_variable_begin() const { return GVs.begin(); }
782     iterator global_variable_end()   const { return GVs.end(); }
783     iterator type_begin()            const { return TYs.begin(); }
784     iterator type_end()              const { return TYs.end(); }
785
786     unsigned compile_unit_count()    const { return CUs.size(); }
787     unsigned global_variable_count() const { return GVs.size(); }
788     unsigned subprogram_count()      const { return SPs.size(); }
789     unsigned type_count()            const { return TYs.size(); }
790
791   private:
792     SmallVector<MDNode *, 8> CUs;  // Compile Units
793     SmallVector<MDNode *, 8> SPs;  // Subprograms
794     SmallVector<MDNode *, 8> GVs;  // Global Variables;
795     SmallVector<MDNode *, 8> TYs;  // Types
796     SmallPtrSet<MDNode *, 64> NodesSeen;
797   };
798 } // end namespace llvm
799
800 #endif