00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
00018 #define LLVM_ANALYSIS_DEBUGINFO_H
00019
00020 #include "llvm/ADT/SmallVector.h"
00021 #include "llvm/ADT/SmallPtrSet.h"
00022 #include "llvm/ADT/StringRef.h"
00023 #include "llvm/Support/Dwarf.h"
00024
00025 namespace llvm {
00026 class BasicBlock;
00027 class Constant;
00028 class Function;
00029 class GlobalVariable;
00030 class Module;
00031 class Type;
00032 class Value;
00033 class DbgDeclareInst;
00034 class DebugLoc;
00035 struct DebugLocTracker;
00036 class Instruction;
00037 class MDNode;
00038 class LLVMContext;
00039
00043 class DIDescriptor {
00044 protected:
00045 MDNode *DbgNode;
00046
00047 StringRef getStringField(unsigned Elt) const;
00048 unsigned getUnsignedField(unsigned Elt) const {
00049 return (unsigned)getUInt64Field(Elt);
00050 }
00051 uint64_t getUInt64Field(unsigned Elt) const;
00052 DIDescriptor getDescriptorField(unsigned Elt) const;
00053
00054 template <typename DescTy>
00055 DescTy getFieldAs(unsigned Elt) const {
00056 return DescTy(getDescriptorField(Elt).getNode());
00057 }
00058
00059 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
00060
00061 public:
00062 explicit DIDescriptor() : DbgNode(0) {}
00063 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
00064
00065 bool Verify() const { return DbgNode != 0; }
00066
00067 MDNode *getNode() const { return DbgNode; }
00068
00069 unsigned getVersion() const {
00070 return getUnsignedField(0) & LLVMDebugVersionMask;
00071 }
00072
00073 unsigned getTag() const {
00074 return getUnsignedField(0) & ~LLVMDebugVersionMask;
00075 }
00076
00078 static bool ValidDebugInfo(MDNode *N, unsigned OptLevel);
00079
00081 void dump() const;
00082
00083 bool isDerivedType() const;
00084 bool isCompositeType() const;
00085 bool isBasicType() const;
00086 bool isVariable() const;
00087 bool isSubprogram() const;
00088 bool isGlobalVariable() const;
00089 bool isScope() const;
00090 bool isFile() const;
00091 bool isCompileUnit() const;
00092 bool isNameSpace() const;
00093 bool isLexicalBlock() const;
00094 bool isSubrange() const;
00095 bool isEnumerator() const;
00096 bool isType() const;
00097 bool isGlobal() const;
00098 };
00099
00101 class DISubrange : public DIDescriptor {
00102 public:
00103 explicit DISubrange(MDNode *N = 0) : DIDescriptor(N) {}
00104
00105 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
00106 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
00107 };
00108
00110 class DIArray : public DIDescriptor {
00111 public:
00112 explicit DIArray(MDNode *N = 0)
00113 : DIDescriptor(N) {}
00114
00115 unsigned getNumElements() const;
00116 DIDescriptor getElement(unsigned Idx) const {
00117 return getDescriptorField(Idx);
00118 }
00119 };
00120
00122 class DIScope : public DIDescriptor {
00123 public:
00124 explicit DIScope(MDNode *N = 0) : DIDescriptor (N) {}
00125 virtual ~DIScope() {}
00126
00127 StringRef getFilename() const;
00128 StringRef getDirectory() const;
00129 };
00130
00132 class DICompileUnit : public DIScope {
00133 public:
00134 explicit DICompileUnit(MDNode *N = 0) : DIScope(N) {}
00135
00136 unsigned getLanguage() const { return getUnsignedField(2); }
00137 StringRef getFilename() const { return getStringField(3); }
00138 StringRef getDirectory() const { return getStringField(4); }
00139 StringRef getProducer() const { return getStringField(5); }
00140
00149
00150 bool isMain() const { return getUnsignedField(6); }
00151 bool isOptimized() const { return getUnsignedField(7); }
00152 StringRef getFlags() const { return getStringField(8); }
00153 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
00154
00156 bool Verify() const;
00157
00159 void dump() const;
00160 };
00161
00163 class DIFile : public DIScope {
00164 public:
00165 explicit DIFile(MDNode *N = 0) : DIScope(N) {
00166 if (DbgNode && !isFile())
00167 DbgNode = 0;
00168 }
00169 StringRef getFilename() const { return getStringField(1); }
00170 StringRef getDirectory() const { return getStringField(2); }
00171 DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
00172 };
00173
00177 class DIEnumerator : public DIDescriptor {
00178 public:
00179 explicit DIEnumerator(MDNode *N = 0) : DIDescriptor(N) {}
00180
00181 StringRef getName() const { return getStringField(1); }
00182 uint64_t getEnumValue() const { return getUInt64Field(2); }
00183 };
00184
00188 class DIType : public DIScope {
00189 public:
00190 enum {
00191 FlagPrivate = 1 << 0,
00192 FlagProtected = 1 << 1,
00193 FlagFwdDecl = 1 << 2,
00194 FlagAppleBlock = 1 << 3,
00195 FlagBlockByrefStruct = 1 << 4,
00196 FlagVirtual = 1 << 5,
00197 FlagArtificial = 1 << 6