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