Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 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 |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 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. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Evan Cheng | 891415b | 2009-01-26 07:31:20 +0000 | [diff] [blame] | 17 | #ifndef LLVM_ANALYSIS_DEBUGINFO_H |
| 18 | #define LLVM_ANALYSIS_DEBUGINFO_H |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 19 | |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/SmallPtrSet.h" |
Chris Lattner | f0908a3 | 2009-12-31 03:02:08 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringRef.h" |
Chris Lattner | 210d0fe | 2009-12-31 03:02:42 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | class BasicBlock; |
| 27 | class Constant; |
| 28 | class Function; |
| 29 | class GlobalVariable; |
| 30 | class Module; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 31 | class Type; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 32 | class Value; |
Douglas Gregor | b419a5c | 2010-01-06 17:16:00 +0000 | [diff] [blame] | 33 | class DbgDeclareInst; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 34 | class Instruction; |
Chris Lattner | f0908a3 | 2009-12-31 03:02:08 +0000 | [diff] [blame] | 35 | class MDNode; |
| 36 | class LLVMContext; |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 37 | class raw_ostream; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 38 | |
Devang Patel | 5b164b5 | 2010-08-02 22:51:46 +0000 | [diff] [blame] | 39 | class DIFile; |
| 40 | class DISubprogram; |
| 41 | class DILexicalBlock; |
| 42 | class DIVariable; |
| 43 | class DIType; |
| 44 | |
Chris Lattner | 784b850 | 2009-12-29 09:15:46 +0000 | [diff] [blame] | 45 | /// DIDescriptor - A thin wraper around MDNode to access encoded debug info. |
| 46 | /// This should not be stored in a container, because underly MDNode may |
| 47 | /// change in certain situations. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 48 | class DIDescriptor { |
Devang Patel | 9dd2b47 | 2010-09-29 21:04:46 +0000 | [diff] [blame] | 49 | public: |
| 50 | enum { |
| 51 | FlagPrivate = 1 << 0, |
| 52 | FlagProtected = 1 << 1, |
| 53 | FlagFwdDecl = 1 << 2, |
| 54 | FlagAppleBlock = 1 << 3, |
| 55 | FlagBlockByrefStruct = 1 << 4, |
| 56 | FlagVirtual = 1 << 5, |
Devang Patel | 21ea1d5 | 2010-10-01 23:31:40 +0000 | [diff] [blame^] | 57 | FlagArtificial = 1 << 6, |
| 58 | FlagExplicit = 1 << 7 |
Devang Patel | 9dd2b47 | 2010-09-29 21:04:46 +0000 | [diff] [blame] | 59 | }; |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 60 | protected: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 61 | const MDNode *DbgNode; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 62 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 63 | StringRef getStringField(unsigned Elt) const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 64 | unsigned getUnsignedField(unsigned Elt) const { |
| 65 | return (unsigned)getUInt64Field(Elt); |
| 66 | } |
| 67 | uint64_t getUInt64Field(unsigned Elt) const; |
| 68 | DIDescriptor getDescriptorField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 69 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 70 | template <typename DescTy> |
| 71 | DescTy getFieldAs(unsigned Elt) const { |
Devang Patel | ebe57f1 | 2010-05-07 18:36:34 +0000 | [diff] [blame] | 72 | return DescTy(getDescriptorField(Elt)); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 73 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 74 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 75 | GlobalVariable *getGlobalVariableField(unsigned Elt) const; |
Devang Patel | 2739896 | 2010-08-09 21:39:24 +0000 | [diff] [blame] | 76 | Constant *getConstantField(unsigned Elt) const; |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 77 | Function *getFunctionField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 78 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 79 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 80 | explicit DIDescriptor() : DbgNode(0) {} |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 81 | explicit DIDescriptor(const MDNode *N) : DbgNode(N) {} |
Devang Patel | 5b164b5 | 2010-08-02 22:51:46 +0000 | [diff] [blame] | 82 | explicit DIDescriptor(const DIFile F); |
| 83 | explicit DIDescriptor(const DISubprogram F); |
| 84 | explicit DIDescriptor(const DILexicalBlock F); |
| 85 | explicit DIDescriptor(const DIVariable F); |
| 86 | explicit DIDescriptor(const DIType F); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 87 | |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 88 | bool Verify() const { return DbgNode != 0; } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 89 | |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 90 | operator MDNode *() const { return const_cast<MDNode*>(DbgNode); } |
| 91 | MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); } |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 92 | |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 93 | unsigned getVersion() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 94 | return getUnsignedField(0) & LLVMDebugVersionMask; |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 95 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 96 | |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 97 | unsigned getTag() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 98 | return getUnsignedField(0) & ~LLVMDebugVersionMask; |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 99 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 100 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 101 | /// print - print descriptor. |
| 102 | void print(raw_ostream &OS) const; |
| 103 | |
| 104 | /// dump - print descriptor to dbgs() with a newline. |
Bill Wendling | 16de013 | 2009-05-05 22:19:25 +0000 | [diff] [blame] | 105 | void dump() const; |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 106 | |
| 107 | bool isDerivedType() const; |
| 108 | bool isCompositeType() const; |
| 109 | bool isBasicType() const; |
| 110 | bool isVariable() const; |
| 111 | bool isSubprogram() const; |
| 112 | bool isGlobalVariable() const; |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 113 | bool isScope() const; |
Devang Patel | 7aa8189 | 2010-03-08 22:27:22 +0000 | [diff] [blame] | 114 | bool isFile() const; |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 115 | bool isCompileUnit() const; |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 116 | bool isNameSpace() const; |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 117 | bool isLexicalBlock() const; |
Devang Patel | ecbeb1a | 2009-09-30 22:34:41 +0000 | [diff] [blame] | 118 | bool isSubrange() const; |
| 119 | bool isEnumerator() const; |
| 120 | bool isType() const; |
| 121 | bool isGlobal() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 122 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 123 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 124 | /// DISubrange - This is used to represent ranges, for array bounds. |
| 125 | class DISubrange : public DIDescriptor { |
| 126 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 127 | explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 128 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 129 | int64_t getLo() const { return (int64_t)getUInt64Field(1); } |
| 130 | int64_t getHi() const { return (int64_t)getUInt64Field(2); } |
| 131 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 132 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 133 | /// DIArray - This descriptor holds an array of descriptors. |
| 134 | class DIArray : public DIDescriptor { |
| 135 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 136 | explicit DIArray(const MDNode *N = 0) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 137 | : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 138 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 139 | unsigned getNumElements() const; |
Devang Patel | a22d57d | 2009-01-05 19:55:07 +0000 | [diff] [blame] | 140 | DIDescriptor getElement(unsigned Idx) const { |
| 141 | return getDescriptorField(Idx); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 142 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 143 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 144 | |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 145 | /// DIScope - A base class for various scopes. |
| 146 | class DIScope : public DIDescriptor { |
| 147 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 148 | explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {} |
Devang Patel | e5b1454 | 2009-09-01 05:04:28 +0000 | [diff] [blame] | 149 | virtual ~DIScope() {} |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 150 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 151 | StringRef getFilename() const; |
| 152 | StringRef getDirectory() const; |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 155 | /// DICompileUnit - A wrapper for a compile unit. |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 156 | class DICompileUnit : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 157 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 158 | explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 159 | |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 160 | unsigned getLanguage() const { return getUnsignedField(2); } |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 161 | StringRef getFilename() const { return getStringField(3); } |
| 162 | StringRef getDirectory() const { return getStringField(4); } |
| 163 | StringRef getProducer() const { return getStringField(5); } |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 164 | |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 165 | /// isMain - Each input file is encoded as a separate compile unit in LLVM |
| 166 | /// debugging information output. However, many target specific tool chains |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 167 | /// prefer to encode only one compile unit in an object file. In this |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 168 | /// situation, the LLVM code generator will include debugging information |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 169 | /// entities in the compile unit that is marked as main compile unit. The |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 170 | /// code generator accepts maximum one main compile unit per module. If a |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 171 | /// module does not contain any main compile unit then the code generator |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 172 | /// will emit multiple compile units in the output object file. |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 173 | |
Oscar Fuentes | 429c75b | 2010-09-25 20:27:36 +0000 | [diff] [blame] | 174 | bool isMain() const { return getUnsignedField(6) != 0; } |
| 175 | bool isOptimized() const { return getUnsignedField(7) != 0; } |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 176 | StringRef getFlags() const { return getStringField(8); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 177 | unsigned getRunTimeVersion() const { return getUnsignedField(9); } |
Devang Patel | ce31b02 | 2009-01-20 18:13:03 +0000 | [diff] [blame] | 178 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 179 | /// Verify - Verify that a compile unit is well formed. |
| 180 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 181 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 182 | /// print - print compile unit. |
| 183 | void print(raw_ostream &OS) const; |
| 184 | |
| 185 | /// dump - print compile unit to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 186 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
Devang Patel | 7aa8189 | 2010-03-08 22:27:22 +0000 | [diff] [blame] | 189 | /// DIFile - This is a wrapper for a file. |
| 190 | class DIFile : public DIScope { |
| 191 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 192 | explicit DIFile(const MDNode *N = 0) : DIScope(N) { |
Devang Patel | 7aa8189 | 2010-03-08 22:27:22 +0000 | [diff] [blame] | 193 | if (DbgNode && !isFile()) |
| 194 | DbgNode = 0; |
| 195 | } |
| 196 | StringRef getFilename() const { return getStringField(1); } |
| 197 | StringRef getDirectory() const { return getStringField(2); } |
| 198 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 199 | }; |
| 200 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 201 | /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). |
| 202 | /// FIXME: it seems strange that this doesn't have either a reference to the |
| 203 | /// type/precision or a file/line pair for location info. |
| 204 | class DIEnumerator : public DIDescriptor { |
| 205 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 206 | explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 207 | |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 208 | StringRef getName() const { return getStringField(1); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 209 | uint64_t getEnumValue() const { return getUInt64Field(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 210 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 211 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 212 | /// DIType - This is a wrapper for a type. |
| 213 | /// FIXME: Types should be factored much better so that CV qualifiers and |
| 214 | /// others do not require a huge and empty descriptor full of zeros. |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 215 | class DIType : public DIScope { |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 216 | public: |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 217 | protected: |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 218 | // This ctor is used when the Tag has already been validated by a derived |
| 219 | // ctor. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 220 | DIType(const MDNode *N, bool, bool) : DIScope(N) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 221 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 222 | public: |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 223 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 224 | /// Verify - Verify that a type descriptor is well formed. |
| 225 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 226 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 227 | explicit DIType(const MDNode *N); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 228 | explicit DIType() {} |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 229 | virtual ~DIType() {} |
| 230 | |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 231 | DIScope getContext() const { return getFieldAs<DIScope>(1); } |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 232 | StringRef getName() const { return getStringField(2); } |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 233 | DICompileUnit getCompileUnit() const{ |
| 234 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 235 | return getFieldAs<DICompileUnit>(3); |
| 236 | |
| 237 | DIFile F = getFieldAs<DIFile>(3); |
| 238 | return F.getCompileUnit(); |
| 239 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 240 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 241 | uint64_t getSizeInBits() const { return getUInt64Field(5); } |
| 242 | uint64_t getAlignInBits() const { return getUInt64Field(6); } |
| 243 | // FIXME: Offset is only used for DW_TAG_member nodes. Making every type |
| 244 | // carry this is just plain insane. |
| 245 | uint64_t getOffsetInBits() const { return getUInt64Field(7); } |
| 246 | unsigned getFlags() const { return getUnsignedField(8); } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 247 | bool isPrivate() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 248 | return (getFlags() & FlagPrivate) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 249 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 250 | bool isProtected() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 251 | return (getFlags() & FlagProtected) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 252 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 253 | bool isForwardDecl() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 254 | return (getFlags() & FlagFwdDecl) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 255 | } |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 256 | // isAppleBlock - Return true if this is the Apple Blocks extension. |
| 257 | bool isAppleBlockExtension() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 258 | return (getFlags() & FlagAppleBlock) != 0; |
Devang Patel | 8af76bd | 2009-08-26 00:39:50 +0000 | [diff] [blame] | 259 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 260 | bool isBlockByrefStruct() const { |
| 261 | return (getFlags() & FlagBlockByrefStruct) != 0; |
| 262 | } |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 263 | bool isVirtual() const { |
| 264 | return (getFlags() & FlagVirtual) != 0; |
| 265 | } |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 266 | bool isArtificial() const { |
| 267 | return (getFlags() & FlagArtificial) != 0; |
| 268 | } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 269 | bool isValid() const { |
| 270 | return DbgNode && (isBasicType() || isDerivedType() || isCompositeType()); |
| 271 | } |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 272 | StringRef getFilename() const { return getCompileUnit().getFilename();} |
| 273 | StringRef getDirectory() const { return getCompileUnit().getDirectory();} |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 274 | |
Dan Gohman | 489b29b | 2010-08-20 22:02:26 +0000 | [diff] [blame] | 275 | /// replaceAllUsesWith - Replace all uses of debug info referenced by |
| 276 | /// this descriptor. |
| 277 | void replaceAllUsesWith(DIDescriptor &D); |
| 278 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 279 | /// print - print type. |
| 280 | void print(raw_ostream &OS) const; |
| 281 | |
| 282 | /// dump - print type to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 283 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 284 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 285 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 286 | /// DIBasicType - A basic type, like 'int' or 'float'. |
| 287 | class DIBasicType : public DIType { |
| 288 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 289 | explicit DIBasicType(const MDNode *N = 0) : DIType(N) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 290 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 291 | unsigned getEncoding() const { return getUnsignedField(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 292 | |
Devang Patel | 0c4720c | 2010-08-23 18:25:56 +0000 | [diff] [blame] | 293 | /// Verify - Verify that a basic type descriptor is well formed. |
| 294 | bool Verify() const; |
| 295 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 296 | /// print - print basic type. |
| 297 | void print(raw_ostream &OS) const; |
| 298 | |
| 299 | /// dump - print basic type to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 300 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 301 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 302 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 303 | /// DIDerivedType - A simple derived type, like a const qualified type, |
| 304 | /// a typedef, a pointer or reference, etc. |
| 305 | class DIDerivedType : public DIType { |
| 306 | protected: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 307 | explicit DIDerivedType(const MDNode *N, bool, bool) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 308 | : DIType(N, true, true) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 309 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 310 | explicit DIDerivedType(const MDNode *N = 0) |
Devang Patel | f17f5eb | 2010-03-08 21:32:10 +0000 | [diff] [blame] | 311 | : DIType(N, true, true) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 312 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 313 | DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 314 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 315 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 316 | /// return base type size. |
| 317 | uint64_t getOriginalTypeSize() const; |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 318 | |
Devang Patel | 0c4720c | 2010-08-23 18:25:56 +0000 | [diff] [blame] | 319 | /// Verify - Verify that a derived type descriptor is well formed. |
| 320 | bool Verify() const; |
| 321 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 322 | /// print - print derived type. |
| 323 | void print(raw_ostream &OS) const; |
| 324 | |
| 325 | /// dump - print derived type to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 326 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 329 | /// DICompositeType - This descriptor holds a type that can refer to multiple |
| 330 | /// other types, like a function or struct. |
| 331 | /// FIXME: Why is this a DIDerivedType?? |
| 332 | class DICompositeType : public DIDerivedType { |
| 333 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 334 | explicit DICompositeType(const MDNode *N = 0) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 335 | : DIDerivedType(N, true, true) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 336 | if (N && !isCompositeType()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 337 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 338 | } |
| 339 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 340 | DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 341 | unsigned getRunTimeLang() const { return getUnsignedField(11); } |
Devang Patel | 0fd7f9d | 2010-01-26 21:14:59 +0000 | [diff] [blame] | 342 | DICompositeType getContainingType() const { |
| 343 | return getFieldAs<DICompositeType>(12); |
| 344 | } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 345 | |
| 346 | /// Verify - Verify that a composite type descriptor is well formed. |
| 347 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 348 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 349 | /// print - print composite type. |
| 350 | void print(raw_ostream &OS) const; |
| 351 | |
| 352 | /// dump - print composite type to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 353 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 354 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 355 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 356 | /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 357 | class DISubprogram : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 358 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 359 | explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 360 | |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 361 | DIScope getContext() const { return getFieldAs<DIScope>(2); } |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 362 | StringRef getName() const { return getStringField(3); } |
| 363 | StringRef getDisplayName() const { return getStringField(4); } |
| 364 | StringRef getLinkageName() const { return getStringField(5); } |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 365 | DICompileUnit getCompileUnit() const{ |
| 366 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 367 | return getFieldAs<DICompileUnit>(6); |
| 368 | |
| 369 | DIFile F = getFieldAs<DIFile>(6); |
| 370 | return F.getCompileUnit(); |
| 371 | } |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 372 | unsigned getLineNumber() const { return getUnsignedField(7); } |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 373 | DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 374 | |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 375 | /// getReturnTypeName - Subprogram return types are encoded either as |
| 376 | /// DIType or as DICompositeType. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 377 | StringRef getReturnTypeName() const { |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 378 | DICompositeType DCT(getFieldAs<DICompositeType>(8)); |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 379 | if (DCT.Verify()) { |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 380 | DIArray A = DCT.getTypeArray(); |
Devang Patel | 2db49d7 | 2010-05-07 18:11:54 +0000 | [diff] [blame] | 381 | DIType T(A.getElement(0)); |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 382 | return T.getName(); |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 383 | } |
| 384 | DIType T(getFieldAs<DIType>(8)); |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 385 | return T.getName(); |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 388 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 389 | /// compile unit, like 'static' in C. |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 390 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 391 | unsigned isDefinition() const { return getUnsignedField(10); } |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 392 | |
Chris Lattner | f0908a3 | 2009-12-31 03:02:08 +0000 | [diff] [blame] | 393 | unsigned getVirtuality() const { return getUnsignedField(11); } |
| 394 | unsigned getVirtualIndex() const { return getUnsignedField(12); } |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 395 | |
| 396 | DICompositeType getContainingType() const { |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 397 | return getFieldAs<DICompositeType>(13); |
| 398 | } |
Devang Patel | 9dd2b47 | 2010-09-29 21:04:46 +0000 | [diff] [blame] | 399 | unsigned isArtificial() const { |
| 400 | if (getVersion() <= llvm::LLVMDebugVersion8) |
| 401 | return getUnsignedField(14); |
| 402 | return (getUnsignedField(14) & FlagArtificial) != 0; |
| 403 | } |
Devang Patel | 1a30123 | 2010-09-29 21:44:16 +0000 | [diff] [blame] | 404 | /// isPrivate - Return true if this subprogram has "private" |
| 405 | /// access specifier. |
| 406 | bool isPrivate() const { |
| 407 | if (getVersion() <= llvm::LLVMDebugVersion8) |
| 408 | return false; |
| 409 | return (getUnsignedField(14) & FlagPrivate) != 0; |
| 410 | } |
| 411 | /// isProtected - Return true if this subprogram has "protected" |
| 412 | /// access specifier. |
| 413 | bool isProtected() const { |
| 414 | if (getVersion() <= llvm::LLVMDebugVersion8) |
| 415 | return false; |
| 416 | return (getUnsignedField(14) & FlagProtected) != 0; |
| 417 | } |
Devang Patel | 21ea1d5 | 2010-10-01 23:31:40 +0000 | [diff] [blame^] | 418 | /// isExplicit - Return true if this subprogram is marked as explicit. |
| 419 | bool isExplicit() const { |
| 420 | if (getVersion() <= llvm::LLVMDebugVersion8) |
| 421 | return false; |
| 422 | return (getUnsignedField(14) & FlagExplicit) != 0; |
| 423 | } |
| 424 | |
Devang Patel | ccff812 | 2010-04-30 19:38:23 +0000 | [diff] [blame] | 425 | unsigned isOptimized() const; |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 426 | |
Devang Patel | 8fe7979 | 2010-03-24 18:48:00 +0000 | [diff] [blame] | 427 | StringRef getFilename() const { |
| 428 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 429 | return getCompileUnit().getFilename(); |
| 430 | |
| 431 | DIFile F = getFieldAs<DIFile>(6); |
| 432 | return F.getFilename(); |
| 433 | } |
| 434 | |
| 435 | StringRef getDirectory() const { |
| 436 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 437 | return getCompileUnit().getFilename(); |
| 438 | |
| 439 | DIFile F = getFieldAs<DIFile>(6); |
| 440 | return F.getDirectory(); |
| 441 | } |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 442 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 443 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 444 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 445 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 446 | /// print - print subprogram. |
| 447 | void print(raw_ostream &OS) const; |
| 448 | |
| 449 | /// dump - print subprogram to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 450 | void dump() const; |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 451 | |
| 452 | /// describes - Return true if this subprogram provides debugging |
| 453 | /// information for the function F. |
| 454 | bool describes(const Function *F); |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 455 | |
| 456 | Function *getFunction() const { return getFunctionField(16); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 457 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 458 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 459 | /// DIGlobalVariable - This is a wrapper for a global variable. |
Devang Patel | a49d877 | 2010-05-07 23:19:07 +0000 | [diff] [blame] | 460 | class DIGlobalVariable : public DIDescriptor { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 461 | public: |
Devang Patel | a49d877 | 2010-05-07 23:19:07 +0000 | [diff] [blame] | 462 | explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {} |
| 463 | |
| 464 | DIScope getContext() const { return getFieldAs<DIScope>(2); } |
| 465 | StringRef getName() const { return getStringField(3); } |
| 466 | StringRef getDisplayName() const { return getStringField(4); } |
| 467 | StringRef getLinkageName() const { return getStringField(5); } |
| 468 | DICompileUnit getCompileUnit() const{ |
| 469 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 470 | return getFieldAs<DICompileUnit>(6); |
| 471 | |
| 472 | DIFile F = getFieldAs<DIFile>(6); |
| 473 | return F.getCompileUnit(); |
| 474 | } |
| 475 | |
| 476 | unsigned getLineNumber() const { return getUnsignedField(7); } |
| 477 | DIType getType() const { return getFieldAs<DIType>(8); } |
| 478 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 479 | unsigned isDefinition() const { return getUnsignedField(10); } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 480 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 481 | GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } |
Devang Patel | 2739896 | 2010-08-09 21:39:24 +0000 | [diff] [blame] | 482 | Constant *getConstant() const { return getConstantField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 483 | |
| 484 | /// Verify - Verify that a global variable descriptor is well formed. |
| 485 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 486 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 487 | /// print - print global variable. |
| 488 | void print(raw_ostream &OS) const; |
| 489 | |
| 490 | /// dump - print global variable to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 491 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 492 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 493 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 494 | /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, |
| 495 | /// global etc). |
| 496 | class DIVariable : public DIDescriptor { |
| 497 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 498 | explicit DIVariable(const MDNode *N = 0) |
Devang Patel | f17f5eb | 2010-03-08 21:32:10 +0000 | [diff] [blame] | 499 | : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 500 | |
Devang Patel | 77bf295 | 2010-03-08 22:02:50 +0000 | [diff] [blame] | 501 | DIScope getContext() const { return getFieldAs<DIScope>(1); } |
| 502 | StringRef getName() const { return getStringField(2); } |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 503 | DICompileUnit getCompileUnit() const{ |
| 504 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 505 | return getFieldAs<DICompileUnit>(3); |
| 506 | |
| 507 | DIFile F = getFieldAs<DIFile>(3); |
| 508 | return F.getCompileUnit(); |
| 509 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 510 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 511 | DIType getType() const { return getFieldAs<DIType>(5); } |
Devang Patel | 3cf763d | 2010-09-29 23:07:21 +0000 | [diff] [blame] | 512 | |
| 513 | /// isArtificial - Return true if this variable is marked as "artificial". |
| 514 | bool isArtificial() const { |
| 515 | if (getVersion() <= llvm::LLVMDebugVersion8) |
| 516 | return false; |
| 517 | return (getUnsignedField(6) & FlagArtificial) != 0; |
| 518 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 519 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 520 | |
| 521 | /// Verify - Verify that a variable descriptor is well formed. |
| 522 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 523 | |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 524 | /// HasComplexAddr - Return true if the variable has a complex address. |
| 525 | bool hasComplexAddress() const { |
| 526 | return getNumAddrElements() > 0; |
| 527 | } |
| 528 | |
Chris Lattner | f0908a3 | 2009-12-31 03:02:08 +0000 | [diff] [blame] | 529 | unsigned getNumAddrElements() const; |
| 530 | |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 531 | uint64_t getAddrElement(unsigned Idx) const { |
| 532 | return getUInt64Field(Idx+6); |
| 533 | } |
| 534 | |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 535 | /// isBlockByrefVariable - Return true if the variable was declared as |
| 536 | /// a "__block" variable (Apple Blocks). |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 537 | bool isBlockByrefVariable() const { |
| 538 | return getType().isBlockByrefStruct(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Devang Patel | 22070e8 | 2010-04-29 20:48:12 +0000 | [diff] [blame] | 541 | /// isInlinedFnArgument - Return trule if this variable provides debugging |
| 542 | /// information for an inlined function arguments. |
| 543 | bool isInlinedFnArgument(const Function *CurFn); |
| 544 | |
Dan Gohman | 5040436 | 2010-05-07 15:30:29 +0000 | [diff] [blame] | 545 | /// print - print variable. |
| 546 | void print(raw_ostream &OS) const; |
| 547 | |
| 548 | /// dump - print variable to dbgs() with a newline. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 549 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 550 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 551 | |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 552 | /// DILexicalBlock - This is a wrapper for a lexical block. |
| 553 | class DILexicalBlock : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 554 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 555 | explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {} |
Devang Patel | 3d821aa | 2010-02-16 21:39:34 +0000 | [diff] [blame] | 556 | DIScope getContext() const { return getFieldAs<DIScope>(1); } |
Devang Patel | 3d821aa | 2010-02-16 21:39:34 +0000 | [diff] [blame] | 557 | unsigned getLineNumber() const { return getUnsignedField(2); } |
| 558 | unsigned getColumnNumber() const { return getUnsignedField(3); } |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 559 | StringRef getDirectory() const { |
| 560 | DIFile F = getFieldAs<DIFile>(4); |
| 561 | StringRef dir = F.getDirectory(); |
| 562 | return !dir.empty() ? dir : getContext().getDirectory(); |
| 563 | } |
| 564 | StringRef getFilename() const { |
| 565 | DIFile F = getFieldAs<DIFile>(4); |
| 566 | StringRef filename = F.getFilename(); |
| 567 | return !filename.empty() ? filename : getContext().getFilename(); |
| 568 | } |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 569 | }; |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 570 | |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 571 | /// DINameSpace - A wrapper for a C++ style name space. |
| 572 | class DINameSpace : public DIScope { |
| 573 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 574 | explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {} |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 575 | DIScope getContext() const { return getFieldAs<DIScope>(1); } |
| 576 | StringRef getName() const { return getStringField(2); } |
| 577 | StringRef getDirectory() const { return getContext().getDirectory(); } |
| 578 | StringRef getFilename() const { return getContext().getFilename(); } |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 579 | DICompileUnit getCompileUnit() const{ |
| 580 | if (getVersion() == llvm::LLVMDebugVersion7) |
| 581 | return getFieldAs<DICompileUnit>(3); |
| 582 | |
| 583 | DIFile F = getFieldAs<DIFile>(3); |
| 584 | return F.getCompileUnit(); |
| 585 | } |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 586 | unsigned getLineNumber() const { return getUnsignedField(4); } |
Devang Patel | 47e2265 | 2010-05-07 23:04:32 +0000 | [diff] [blame] | 587 | bool Verify() const; |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 588 | }; |
| 589 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 590 | /// DILocation - This object holds location information. This object |
| 591 | /// is not associated with any DWARF tag. |
| 592 | class DILocation : public DIDescriptor { |
| 593 | public: |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 594 | explicit DILocation(const MDNode *N) : DIDescriptor(N) { } |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 595 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 596 | unsigned getLineNumber() const { return getUnsignedField(0); } |
| 597 | unsigned getColumnNumber() const { return getUnsignedField(1); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 598 | DIScope getScope() const { return getFieldAs<DIScope>(2); } |
| 599 | DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); } |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 600 | StringRef getFilename() const { return getScope().getFilename(); } |
| 601 | StringRef getDirectory() const { return getScope().getDirectory(); } |
Devang Patel | 3c91b05 | 2010-03-08 20:52:55 +0000 | [diff] [blame] | 602 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 603 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 604 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 605 | /// DIFactory - This object assists with the construction of the various |
| 606 | /// descriptors. |
| 607 | class DIFactory { |
| 608 | Module &M; |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 609 | LLVMContext& VMContext; |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 610 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 611 | Function *DeclareFn; // llvm.dbg.declare |
Victor Hernandez | 2f9dac7 | 2009-12-07 19:36:34 +0000 | [diff] [blame] | 612 | Function *ValueFn; // llvm.dbg.value |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 613 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 614 | DIFactory(const DIFactory &); // DO NOT IMPLEMENT |
| 615 | void operator=(const DIFactory&); // DO NOT IMPLEMENT |
| 616 | public: |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 617 | enum ComplexAddrKind { OpPlus=1, OpDeref }; |
| 618 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 619 | explicit DIFactory(Module &m); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 620 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 621 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 622 | /// This implicitly uniques the arrays created. |
| 623 | DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); |
| 624 | |
| 625 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 626 | /// implicitly uniques the values returned. |
| 627 | DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 628 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 629 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 630 | /// unit. |
| 631 | DICompileUnit CreateCompileUnit(unsigned LangID, |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 632 | StringRef Filename, |
| 633 | StringRef Directory, |
| 634 | StringRef Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 635 | bool isMain = false, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 636 | bool isOptimized = false, |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 637 | StringRef Flags = "", |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 638 | unsigned RunTimeVer = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 639 | |
Devang Patel | 7aa8189 | 2010-03-08 22:27:22 +0000 | [diff] [blame] | 640 | /// CreateFile - Create a new descriptor for the specified file. |
Eric Christopher | 0764e39 | 2010-07-13 05:50:08 +0000 | [diff] [blame] | 641 | DIFile CreateFile(StringRef Filename, StringRef Directory, |
| 642 | DICompileUnit CU); |
Devang Patel | 7aa8189 | 2010-03-08 22:27:22 +0000 | [diff] [blame] | 643 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 644 | /// CreateEnumerator - Create a single enumerator value. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 645 | DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 646 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 647 | /// CreateBasicType - Create a basic type like int, float, etc. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 648 | DIBasicType CreateBasicType(DIDescriptor Context, StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 649 | DIFile F, unsigned LineNumber, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 650 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 651 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 652 | unsigned Encoding); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 653 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 654 | /// CreateBasicType - Create a basic type like int, float, etc. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 655 | DIBasicType CreateBasicTypeEx(DIDescriptor Context, StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 656 | DIFile F, unsigned LineNumber, |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 657 | Constant *SizeInBits, Constant *AlignInBits, |
| 658 | Constant *OffsetInBits, unsigned Flags, |
| 659 | unsigned Encoding); |
| 660 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 661 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 662 | /// pointer, typedef, etc. |
| 663 | DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 664 | StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 665 | DIFile F, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 666 | unsigned LineNumber, |
| 667 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 668 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 669 | DIType DerivedFrom); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 670 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 671 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 672 | /// pointer, typedef, etc. |
| 673 | DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 674 | StringRef Name, |
| 675 | DIFile F, |
| 676 | unsigned LineNumber, |
| 677 | Constant *SizeInBits, |
| 678 | Constant *AlignInBits, |
| 679 | Constant *OffsetInBits, unsigned Flags, |
| 680 | DIType DerivedFrom); |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 681 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 682 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 683 | DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 684 | StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 685 | DIFile F, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 686 | unsigned LineNumber, |
| 687 | uint64_t SizeInBits, |
| 688 | uint64_t AlignInBits, |
| 689 | uint64_t OffsetInBits, unsigned Flags, |
| 690 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 691 | DIArray Elements, |
Devang Patel | 0fd7f9d | 2010-01-26 21:14:59 +0000 | [diff] [blame] | 692 | unsigned RunTimeLang = 0, |
| 693 | MDNode *ContainingType = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 694 | |
Dan Gohman | 489b29b | 2010-08-20 22:02:26 +0000 | [diff] [blame] | 695 | /// CreateTemporaryType - Create a temporary forward-declared type. |
Dan Gohman | a3833f1 | 2010-08-20 22:39:47 +0000 | [diff] [blame] | 696 | DIType CreateTemporaryType(); |
Dan Gohman | 489b29b | 2010-08-20 22:02:26 +0000 | [diff] [blame] | 697 | |
Devang Patel | b464564 | 2010-02-06 01:02:37 +0000 | [diff] [blame] | 698 | /// CreateArtificialType - Create a new DIType with "artificial" flag set. |
| 699 | DIType CreateArtificialType(DIType Ty); |
| 700 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 701 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 702 | DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 703 | StringRef Name, |
| 704 | DIFile F, |
| 705 | unsigned LineNumber, |
| 706 | Constant *SizeInBits, |
| 707 | Constant *AlignInBits, |
| 708 | Constant *OffsetInBits, |
| 709 | unsigned Flags, |
| 710 | DIType DerivedFrom, |
| 711 | DIArray Elements, |
Devang Patel | 6bf058c | 2010-08-10 20:22:49 +0000 | [diff] [blame] | 712 | unsigned RunTimeLang = 0, |
| 713 | MDNode *ContainingType = 0); |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 714 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 715 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 716 | /// See comments in DISubprogram for descriptions of these fields. |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 717 | DISubprogram CreateSubprogram(DIDescriptor Context, StringRef Name, |
| 718 | StringRef DisplayName, |
| 719 | StringRef LinkageName, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 720 | DIFile F, unsigned LineNo, |
Devang Patel | 2e36993 | 2010-01-23 00:26:28 +0000 | [diff] [blame] | 721 | DIType Ty, bool isLocalToUnit, |
Devang Patel | 5d11eb0 | 2009-12-03 19:11:07 +0000 | [diff] [blame] | 722 | bool isDefinition, |
| 723 | unsigned VK = 0, |
| 724 | unsigned VIndex = 0, |
Devang Patel | 4e0d19d | 2010-02-03 19:57:19 +0000 | [diff] [blame] | 725 | DIType = DIType(), |
Devang Patel | 9dd2b47 | 2010-09-29 21:04:46 +0000 | [diff] [blame] | 726 | unsigned Flags = 0, |
Stuart Hastings | 215aa15 | 2010-06-11 20:08:44 +0000 | [diff] [blame] | 727 | bool isOptimized = false, |
| 728 | Function *Fn = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 729 | |
Devang Patel | e3a18de | 2009-12-01 23:09:02 +0000 | [diff] [blame] | 730 | /// CreateSubprogramDefinition - Create new subprogram descriptor for the |
| 731 | /// given declaration. |
| 732 | DISubprogram CreateSubprogramDefinition(DISubprogram &SPDeclaration); |
| 733 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 734 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 735 | DIGlobalVariable |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 736 | CreateGlobalVariable(DIDescriptor Context, StringRef Name, |
| 737 | StringRef DisplayName, |
| 738 | StringRef LinkageName, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 739 | DIFile F, |
Devang Patel | 2e36993 | 2010-01-23 00:26:28 +0000 | [diff] [blame] | 740 | unsigned LineNo, DIType Ty, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 741 | bool isDefinition, llvm::GlobalVariable *GV); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 742 | |
Devang Patel | 2739896 | 2010-08-09 21:39:24 +0000 | [diff] [blame] | 743 | /// CreateGlobalVariable - Create a new descriptor for the specified constant. |
| 744 | DIGlobalVariable |
| 745 | CreateGlobalVariable(DIDescriptor Context, StringRef Name, |
| 746 | StringRef DisplayName, |
| 747 | StringRef LinkageName, |
| 748 | DIFile F, |
| 749 | unsigned LineNo, DIType Ty, bool isLocalToUnit, |
| 750 | bool isDefinition, llvm::Constant *C); |
| 751 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 752 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 753 | DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, |
Devang Patel | 65dbc90 | 2009-11-25 17:36:49 +0000 | [diff] [blame] | 754 | StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 755 | DIFile F, unsigned LineNo, |
Devang Patel | 3cf763d | 2010-09-29 23:07:21 +0000 | [diff] [blame] | 756 | DIType Ty, bool AlwaysPreserve = false, |
| 757 | unsigned Flags = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 758 | |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 759 | /// CreateComplexVariable - Create a new descriptor for the specified |
| 760 | /// variable which has a complex address expression for its address. |
| 761 | DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context, |
Benjamin Kramer | 28b4afc | 2010-09-21 16:00:03 +0000 | [diff] [blame] | 762 | StringRef Name, DIFile F, unsigned LineNo, |
| 763 | DIType Ty, Value *const *Addr, |
| 764 | unsigned NumAddr); |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 765 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 766 | /// CreateLexicalBlock - This creates a descriptor for a lexical block |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 767 | /// with the specified parent context. |
Stuart Hastings | 0db4271 | 2010-07-19 23:56:30 +0000 | [diff] [blame] | 768 | DILexicalBlock CreateLexicalBlock(DIDescriptor Context, DIFile F, |
| 769 | unsigned Line = 0, unsigned Col = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 770 | |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 771 | /// CreateNameSpace - This creates new descriptor for a namespace |
| 772 | /// with the specified parent context. |
| 773 | DINameSpace CreateNameSpace(DIDescriptor Context, StringRef Name, |
Devang Patel | 4b94550 | 2010-03-09 00:44:10 +0000 | [diff] [blame] | 774 | DIFile F, unsigned LineNo); |
Devang Patel | 6404e4e | 2009-12-15 19:16:48 +0000 | [diff] [blame] | 775 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 776 | /// CreateLocation - Creates a debug info location. |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 777 | DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo, |
Daniel Dunbar | 3fc19bb | 2009-09-19 20:40:21 +0000 | [diff] [blame] | 778 | DIScope S, DILocation OrigLoc); |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 779 | |
Devang Patel | e54a5e8 | 2009-11-23 19:11:20 +0000 | [diff] [blame] | 780 | /// CreateLocation - Creates a debug info location. |
| 781 | DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo, |
| 782 | DIScope S, MDNode *OrigLoc = 0); |
| 783 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 784 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 785 | Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D, |
| 786 | BasicBlock *InsertAtEnd); |
Mike Stump | e425039 | 2009-10-01 22:08:58 +0000 | [diff] [blame] | 787 | |
| 788 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 789 | Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D, |
| 790 | Instruction *InsertBefore); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 791 | |
Victor Hernandez | c59b335 | 2009-12-07 21:54:43 +0000 | [diff] [blame] | 792 | /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
Victor Hernandez | 5b7e48b | 2010-01-11 07:45:19 +0000 | [diff] [blame] | 793 | Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset, |
Victor Hernandez | c59b335 | 2009-12-07 21:54:43 +0000 | [diff] [blame] | 794 | DIVariable D, BasicBlock *InsertAtEnd); |
Victor Hernandez | 2f9dac7 | 2009-12-07 19:36:34 +0000 | [diff] [blame] | 795 | |
Victor Hernandez | c59b335 | 2009-12-07 21:54:43 +0000 | [diff] [blame] | 796 | /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. |
Victor Hernandez | 5b7e48b | 2010-01-11 07:45:19 +0000 | [diff] [blame] | 797 | Instruction *InsertDbgValueIntrinsic(llvm::Value *V, uint64_t Offset, |
Victor Hernandez | c59b335 | 2009-12-07 21:54:43 +0000 | [diff] [blame] | 798 | DIVariable D, Instruction *InsertBefore); |
Devang Patel | 1a7ca03 | 2010-09-28 18:08:20 +0000 | [diff] [blame] | 799 | |
| 800 | // RecordType - Record DIType in a module such that it is not lost even if |
| 801 | // it is not referenced through debug info anchors. |
| 802 | void RecordType(DIType T); |
| 803 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 804 | private: |
| 805 | Constant *GetTagConstant(unsigned TAG); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 806 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 807 | |
Chris Lattner | 784b850 | 2009-12-29 09:15:46 +0000 | [diff] [blame] | 808 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 809 | std::string &Type, unsigned &LineNo, std::string &File, |
| 810 | std::string &Dir); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 811 | |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 812 | /// getDISubprogram - Find subprogram that is enclosing this scope. |
Devang Patel | e9f8f5e | 2010-05-07 20:54:48 +0000 | [diff] [blame] | 813 | DISubprogram getDISubprogram(const MDNode *Scope); |
Devang Patel | 193f720 | 2009-11-24 01:14:22 +0000 | [diff] [blame] | 814 | |
| 815 | /// getDICompositeType - Find underlying composite type. |
| 816 | DICompositeType getDICompositeType(DIType T); |
| 817 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 818 | class DebugInfoFinder { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 819 | public: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 820 | /// processModule - Process entire module and collect debug info |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 821 | /// anchors. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 822 | void processModule(Module &M); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 823 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 824 | private: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 825 | /// processType - Process DIType. |
| 826 | void processType(DIType DT); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 827 | |
Devang Patel | beab41b | 2009-10-07 22:04:08 +0000 | [diff] [blame] | 828 | /// processLexicalBlock - Process DILexicalBlock. |
| 829 | void processLexicalBlock(DILexicalBlock LB); |
| 830 | |
| 831 | /// processSubprogram - Process DISubprogram. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 832 | void processSubprogram(DISubprogram SP); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 833 | |
Devang Patel | b4d3130 | 2009-07-31 18:18:52 +0000 | [diff] [blame] | 834 | /// processDeclare - Process DbgDeclareInst. |
| 835 | void processDeclare(DbgDeclareInst *DDI); |
| 836 | |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 837 | /// processLocation - Process DILocation. |
| 838 | void processLocation(DILocation Loc); |
| 839 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 840 | /// addCompileUnit - Add compile unit into CUs. |
| 841 | bool addCompileUnit(DICompileUnit CU); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 842 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 843 | /// addGlobalVariable - Add global variable into GVs. |
| 844 | bool addGlobalVariable(DIGlobalVariable DIG); |
| 845 | |
| 846 | // addSubprogram - Add subprgoram into SPs. |
| 847 | bool addSubprogram(DISubprogram SP); |
| 848 | |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 849 | /// addType - Add type into Tys. |
| 850 | bool addType(DIType DT); |
| 851 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 852 | public: |
Dan Gohman | 5374195 | 2010-05-07 15:36:10 +0000 | [diff] [blame] | 853 | typedef SmallVector<MDNode *, 8>::const_iterator iterator; |
| 854 | iterator compile_unit_begin() const { return CUs.begin(); } |
| 855 | iterator compile_unit_end() const { return CUs.end(); } |
| 856 | iterator subprogram_begin() const { return SPs.begin(); } |
| 857 | iterator subprogram_end() const { return SPs.end(); } |
| 858 | iterator global_variable_begin() const { return GVs.begin(); } |
| 859 | iterator global_variable_end() const { return GVs.end(); } |
| 860 | iterator type_begin() const { return TYs.begin(); } |
| 861 | iterator type_end() const { return TYs.end(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 862 | |
Dan Gohman | 5374195 | 2010-05-07 15:36:10 +0000 | [diff] [blame] | 863 | unsigned compile_unit_count() const { return CUs.size(); } |
| 864 | unsigned global_variable_count() const { return GVs.size(); } |
| 865 | unsigned subprogram_count() const { return SPs.size(); } |
| 866 | unsigned type_count() const { return TYs.size(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 867 | |
| 868 | private: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 869 | SmallVector<MDNode *, 8> CUs; // Compile Units |
| 870 | SmallVector<MDNode *, 8> SPs; // Subprograms |
| 871 | SmallVector<MDNode *, 8> GVs; // Global Variables; |
| 872 | SmallVector<MDNode *, 8> TYs; // Types |
| 873 | SmallPtrSet<MDNode *, 64> NodesSeen; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 874 | }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 875 | } // end namespace llvm |
| 876 | |
| 877 | #endif |