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