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