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 | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 20 | #include "llvm/Metadata.h" |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/StringMap.h" |
| 23 | #include "llvm/ADT/DenseMap.h" |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/SmallVector.h" |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallPtrSet.h" |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Dwarf.h" |
Daniel Dunbar | 48a097b | 2009-09-22 02:03:18 +0000 | [diff] [blame] | 27 | #include "llvm/Support/ValueHandle.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | class BasicBlock; |
| 31 | class Constant; |
| 32 | class Function; |
| 33 | class GlobalVariable; |
| 34 | class Module; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 35 | class Type; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 36 | class Value; |
Cedric Venet | aff9c27 | 2009-02-14 16:06:42 +0000 | [diff] [blame] | 37 | struct DbgStopPointInst; |
| 38 | struct DbgDeclareInst; |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 39 | struct DbgFuncStartInst; |
| 40 | struct DbgRegionStartInst; |
| 41 | struct DbgRegionEndInst; |
| 42 | class DebugLoc; |
Daniel Dunbar | 460d16e | 2009-07-12 22:46:08 +0000 | [diff] [blame] | 43 | struct DebugLocTracker; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 44 | class Instruction; |
Benjamin Kramer | 12ddd40 | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 45 | class LLVMContext; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 46 | |
Devang Patel | a2b3cdc | 2009-11-13 21:45:04 +0000 | [diff] [blame] | 47 | /// DIDescriptor - A thin wraper around MDNode to access encoded debug info. This should not |
| 48 | /// be stored in a container, because underly MDNode may change in certain situations. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 49 | class DIDescriptor { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 50 | protected: |
Devang Patel | a2b3cdc | 2009-11-13 21:45:04 +0000 | [diff] [blame] | 51 | MDNode *DbgNode; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 52 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 53 | /// DIDescriptor constructor. If the specified node is non-null, check |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 54 | /// to make sure that the tag in the descriptor matches 'RequiredTag'. If |
| 55 | /// not, the debug info is corrupt and we ignore it. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 56 | DIDescriptor(MDNode *N, unsigned RequiredTag); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 57 | |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 58 | const char *getStringField(unsigned Elt) const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 59 | unsigned getUnsignedField(unsigned Elt) const { |
| 60 | return (unsigned)getUInt64Field(Elt); |
| 61 | } |
| 62 | uint64_t getUInt64Field(unsigned Elt) const; |
| 63 | DIDescriptor getDescriptorField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 64 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 65 | template <typename DescTy> |
| 66 | DescTy getFieldAs(unsigned Elt) const { |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 67 | return DescTy(getDescriptorField(Elt).getNode()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 68 | } |
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 | GlobalVariable *getGlobalVariableField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 71 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 72 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 73 | explicit DIDescriptor() : DbgNode(0) {} |
| 74 | explicit DIDescriptor(MDNode *N) : DbgNode(N) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 75 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 76 | bool isNull() const { return DbgNode == 0; } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 77 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 78 | MDNode *getNode() const { return DbgNode; } |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 79 | |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 80 | unsigned getVersion() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 81 | return getUnsignedField(0) & LLVMDebugVersionMask; |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 82 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 83 | |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 84 | unsigned getTag() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 85 | return getUnsignedField(0) & ~LLVMDebugVersionMask; |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 86 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 87 | |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 88 | /// ValidDebugInfo - Return true if N represents valid debug info value. |
| 89 | static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel); |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 90 | |
Bill Wendling | 16de013 | 2009-05-05 22:19:25 +0000 | [diff] [blame] | 91 | /// dump - print descriptor. |
| 92 | void dump() const; |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 93 | |
| 94 | bool isDerivedType() const; |
| 95 | bool isCompositeType() const; |
| 96 | bool isBasicType() const; |
| 97 | bool isVariable() const; |
| 98 | bool isSubprogram() const; |
| 99 | bool isGlobalVariable() const; |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 100 | bool isScope() const; |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 101 | bool isCompileUnit() const; |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 102 | bool isLexicalBlock() const; |
Devang Patel | ecbeb1a | 2009-09-30 22:34:41 +0000 | [diff] [blame] | 103 | bool isSubrange() const; |
| 104 | bool isEnumerator() const; |
| 105 | bool isType() const; |
| 106 | bool isGlobal() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 107 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 108 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 109 | /// DISubrange - This is used to represent ranges, for array bounds. |
| 110 | class DISubrange : public DIDescriptor { |
| 111 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 112 | explicit DISubrange(MDNode *N = 0) |
| 113 | : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 114 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 115 | int64_t getLo() const { return (int64_t)getUInt64Field(1); } |
| 116 | int64_t getHi() const { return (int64_t)getUInt64Field(2); } |
| 117 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 118 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 119 | /// DIArray - This descriptor holds an array of descriptors. |
| 120 | class DIArray : public DIDescriptor { |
| 121 | public: |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 122 | explicit DIArray(MDNode *N = 0) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 123 | : DIDescriptor(N) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 124 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 125 | unsigned getNumElements() const; |
Devang Patel | a22d57d | 2009-01-05 19:55:07 +0000 | [diff] [blame] | 126 | DIDescriptor getElement(unsigned Idx) const { |
| 127 | return getDescriptorField(Idx); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 128 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 129 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 130 | |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 131 | /// DIScope - A base class for various scopes. |
| 132 | class DIScope : public DIDescriptor { |
| 133 | public: |
| 134 | explicit DIScope(MDNode *N = 0) : DIDescriptor (N) { |
| 135 | if (DbgNode && !isScope()) |
| 136 | DbgNode = 0; |
| 137 | } |
Devang Patel | e5b1454 | 2009-09-01 05:04:28 +0000 | [diff] [blame] | 138 | virtual ~DIScope() {} |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 139 | |
Devang Patel | ecbeb1a | 2009-09-30 22:34:41 +0000 | [diff] [blame] | 140 | const char *getFilename() const; |
| 141 | const char *getDirectory() const; |
Devang Patel | 43d98b3 | 2009-08-31 20:44:45 +0000 | [diff] [blame] | 142 | }; |
| 143 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 144 | /// DICompileUnit - A wrapper for a compile unit. |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 145 | class DICompileUnit : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 146 | public: |
Daniel Dunbar | 7dd76a1 | 2009-09-19 20:40:28 +0000 | [diff] [blame] | 147 | explicit DICompileUnit(MDNode *N = 0) : DIScope(N) { |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 148 | if (DbgNode && !isCompileUnit()) |
Daniel Dunbar | 3fc19bb | 2009-09-19 20:40:21 +0000 | [diff] [blame] | 149 | DbgNode = 0; |
Devang Patel | c9f322d | 2009-08-31 21:34:44 +0000 | [diff] [blame] | 150 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 151 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 152 | unsigned getLanguage() const { return getUnsignedField(2); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 153 | const char *getFilename() const { return getStringField(3); } |
| 154 | const char *getDirectory() const { return getStringField(4); } |
| 155 | const char *getProducer() const { return getStringField(5); } |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 156 | |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 157 | /// isMain - Each input file is encoded as a separate compile unit in LLVM |
| 158 | /// debugging information output. However, many target specific tool chains |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 159 | /// 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] | 160 | /// situation, the LLVM code generator will include debugging information |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 161 | /// 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] | 162 | /// code generator accepts maximum one main compile unit per module. If a |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 163 | /// module does not contain any main compile unit then the code generator |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 164 | /// will emit multiple compile units in the output object file. |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 165 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 166 | bool isMain() const { return getUnsignedField(6); } |
| 167 | bool isOptimized() const { return getUnsignedField(7); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 168 | const char *getFlags() const { return getStringField(8); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 169 | unsigned getRunTimeVersion() const { return getUnsignedField(9); } |
Devang Patel | ce31b02 | 2009-01-20 18:13:03 +0000 | [diff] [blame] | 170 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 171 | /// Verify - Verify that a compile unit is well formed. |
| 172 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 173 | |
| 174 | /// dump - print compile unit. |
| 175 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). |
| 179 | /// FIXME: it seems strange that this doesn't have either a reference to the |
| 180 | /// type/precision or a file/line pair for location info. |
| 181 | class DIEnumerator : public DIDescriptor { |
| 182 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 183 | explicit DIEnumerator(MDNode *N = 0) |
| 184 | : DIDescriptor(N, dwarf::DW_TAG_enumerator) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 185 | |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 186 | const char *getName() const { return getStringField(1); } |
| 187 | uint64_t getEnumValue() const { return getUInt64Field(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 188 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 189 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 190 | /// DIType - This is a wrapper for a type. |
| 191 | /// FIXME: Types should be factored much better so that CV qualifiers and |
| 192 | /// others do not require a huge and empty descriptor full of zeros. |
| 193 | class DIType : public DIDescriptor { |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 194 | public: |
| 195 | enum { |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 196 | FlagPrivate = 1 << 0, |
| 197 | FlagProtected = 1 << 1, |
| 198 | FlagFwdDecl = 1 << 2, |
| 199 | FlagAppleBlock = 1 << 3, |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 200 | FlagBlockByrefStruct = 1 << 4 |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 201 | }; |
| 202 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 203 | protected: |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 204 | DIType(MDNode *N, unsigned Tag) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 205 | : DIDescriptor(N, Tag) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 206 | // This ctor is used when the Tag has already been validated by a derived |
| 207 | // ctor. |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 208 | DIType(MDNode *N, bool, bool) : DIDescriptor(N) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 209 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 210 | public: |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 211 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 212 | /// Verify - Verify that a type descriptor is well formed. |
| 213 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 214 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 215 | explicit DIType(MDNode *N); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 216 | explicit DIType() {} |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 217 | virtual ~DIType() {} |
| 218 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 219 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 220 | const char *getName() const { return getStringField(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 221 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 222 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 223 | uint64_t getSizeInBits() const { return getUInt64Field(5); } |
| 224 | uint64_t getAlignInBits() const { return getUInt64Field(6); } |
| 225 | // FIXME: Offset is only used for DW_TAG_member nodes. Making every type |
| 226 | // carry this is just plain insane. |
| 227 | uint64_t getOffsetInBits() const { return getUInt64Field(7); } |
| 228 | unsigned getFlags() const { return getUnsignedField(8); } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 229 | bool isPrivate() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 230 | return (getFlags() & FlagPrivate) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 231 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 232 | bool isProtected() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 233 | return (getFlags() & FlagProtected) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 234 | } |
Chris Lattner | e1f515e | 2009-08-26 04:21:30 +0000 | [diff] [blame] | 235 | bool isForwardDecl() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 236 | return (getFlags() & FlagFwdDecl) != 0; |
Devang Patel | e2d5a6c | 2009-07-27 20:30:05 +0000 | [diff] [blame] | 237 | } |
Devang Patel | a1ba269 | 2009-08-27 23:51:51 +0000 | [diff] [blame] | 238 | // isAppleBlock - Return true if this is the Apple Blocks extension. |
| 239 | bool isAppleBlockExtension() const { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 240 | return (getFlags() & FlagAppleBlock) != 0; |
Devang Patel | 8af76bd | 2009-08-26 00:39:50 +0000 | [diff] [blame] | 241 | } |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 242 | bool isBlockByrefStruct() const { |
| 243 | return (getFlags() & FlagBlockByrefStruct) != 0; |
| 244 | } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 245 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 246 | /// dump - print type. |
| 247 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 248 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 249 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 250 | /// DIBasicType - A basic type, like 'int' or 'float'. |
| 251 | class DIBasicType : public DIType { |
| 252 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 253 | explicit DIBasicType(MDNode *N = 0) |
| 254 | : DIType(N, dwarf::DW_TAG_base_type) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 255 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 256 | unsigned getEncoding() const { return getUnsignedField(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 257 | |
| 258 | /// dump - print basic type. |
| 259 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 260 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 261 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 262 | /// DIDerivedType - A simple derived type, like a const qualified type, |
| 263 | /// a typedef, a pointer or reference, etc. |
| 264 | class DIDerivedType : public DIType { |
| 265 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 266 | explicit DIDerivedType(MDNode *N, bool, bool) |
| 267 | : DIType(N, true, true) {} |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 268 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 269 | explicit DIDerivedType(MDNode *N = 0) |
| 270 | : DIType(N, true, true) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 271 | if (DbgNode && !isDerivedType()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 272 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 275 | DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 276 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 277 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 278 | /// return base type size. |
| 279 | uint64_t getOriginalTypeSize() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 280 | /// dump - print derived type. |
| 281 | void dump() const; |
Devang Patel | c4999d7 | 2009-07-22 18:23:44 +0000 | [diff] [blame] | 282 | |
| 283 | /// replaceAllUsesWith - Replace all uses of debug info referenced by |
| 284 | /// this descriptor. After this completes, the current debug info value |
| 285 | /// is erased. |
| 286 | void replaceAllUsesWith(DIDescriptor &D); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 287 | }; |
| 288 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 289 | /// DICompositeType - This descriptor holds a type that can refer to multiple |
| 290 | /// other types, like a function or struct. |
| 291 | /// FIXME: Why is this a DIDerivedType?? |
| 292 | class DICompositeType : public DIDerivedType { |
| 293 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 294 | explicit DICompositeType(MDNode *N = 0) |
| 295 | : DIDerivedType(N, true, true) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 296 | if (N && !isCompositeType()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 297 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 300 | DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 301 | unsigned getRunTimeLang() const { return getUnsignedField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 302 | |
| 303 | /// Verify - Verify that a composite type descriptor is well formed. |
| 304 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 305 | |
| 306 | /// dump - print composite type. |
| 307 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 308 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 309 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 310 | /// DIGlobal - This is a common class for global variables and subprograms. |
| 311 | class DIGlobal : public DIDescriptor { |
| 312 | protected: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 313 | explicit DIGlobal(MDNode *N, unsigned RequiredTag) |
| 314 | : DIDescriptor(N, RequiredTag) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 315 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 316 | public: |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 317 | virtual ~DIGlobal() {} |
| 318 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 319 | DIDescriptor getContext() const { return getDescriptorField(2); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 320 | const char *getName() const { return getStringField(3); } |
| 321 | const char *getDisplayName() const { return getStringField(4); } |
| 322 | const char *getLinkageName() const { return getStringField(5); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 323 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } |
| 324 | unsigned getLineNumber() const { return getUnsignedField(7); } |
| 325 | DIType getType() const { return getFieldAs<DIType>(8); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 326 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 327 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 328 | /// compile unit, like 'static' in C. |
| 329 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 330 | unsigned isDefinition() const { return getUnsignedField(10); } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 331 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 332 | /// dump - print global. |
| 333 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 334 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 335 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 336 | /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 337 | class DISubprogram : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 338 | public: |
Daniel Dunbar | 7dd76a1 | 2009-09-19 20:40:28 +0000 | [diff] [blame] | 339 | explicit DISubprogram(MDNode *N = 0) : DIScope(N) { |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 340 | if (DbgNode && !isSubprogram()) |
Daniel Dunbar | 3fc19bb | 2009-09-19 20:40:21 +0000 | [diff] [blame] | 341 | DbgNode = 0; |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 342 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 343 | |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 344 | DIDescriptor getContext() const { return getDescriptorField(2); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 345 | const char *getName() const { return getStringField(3); } |
| 346 | const char *getDisplayName() const { return getStringField(4); } |
| 347 | const char *getLinkageName() const { return getStringField(5); } |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 348 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } |
| 349 | unsigned getLineNumber() const { return getUnsignedField(7); } |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 350 | DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 351 | |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 352 | /// getReturnTypeName - Subprogram return types are encoded either as |
| 353 | /// DIType or as DICompositeType. |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 354 | const char *getReturnTypeName() const { |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 355 | DICompositeType DCT(getFieldAs<DICompositeType>(8)); |
| 356 | if (!DCT.isNull()) { |
| 357 | DIArray A = DCT.getTypeArray(); |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 358 | DIType T(A.getElement(0).getNode()); |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 359 | return T.getName(); |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 360 | } |
| 361 | DIType T(getFieldAs<DIType>(8)); |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 362 | return T.getName(); |
Devang Patel | 0de4fa6 | 2009-06-23 22:07:48 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Devang Patel | 82dfc0c | 2009-08-31 22:47:13 +0000 | [diff] [blame] | 365 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 366 | /// compile unit, like 'static' in C. |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 367 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 368 | unsigned isDefinition() const { return getUnsignedField(10); } |
| 369 | const char *getFilename() const { return getCompileUnit().getFilename();} |
| 370 | const char *getDirectory() const { return getCompileUnit().getDirectory();} |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 371 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 372 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 373 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 374 | |
| 375 | /// dump - print subprogram. |
| 376 | void dump() const; |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 377 | |
| 378 | /// describes - Return true if this subprogram provides debugging |
| 379 | /// information for the function F. |
| 380 | bool describes(const Function *F); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 381 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 382 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 383 | /// DIGlobalVariable - This is a wrapper for a global variable. |
| 384 | class DIGlobalVariable : public DIGlobal { |
| 385 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 386 | explicit DIGlobalVariable(MDNode *N = 0) |
| 387 | : DIGlobal(N, dwarf::DW_TAG_variable) {} |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 388 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 389 | GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 390 | |
| 391 | /// Verify - Verify that a global variable descriptor is well formed. |
| 392 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 393 | |
| 394 | /// dump - print global variable. |
| 395 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 396 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 397 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 398 | /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, |
| 399 | /// global etc). |
| 400 | class DIVariable : public DIDescriptor { |
| 401 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 402 | explicit DIVariable(MDNode *N = 0) |
| 403 | : DIDescriptor(N) { |
Devang Patel | 6ceea33 | 2009-08-31 18:49:10 +0000 | [diff] [blame] | 404 | if (DbgNode && !isVariable()) |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 405 | DbgNode = 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 406 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 407 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 408 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 409 | const char *getName() const { return getStringField(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 410 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 411 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 412 | DIType getType() const { return getFieldAs<DIType>(5); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 413 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 414 | |
| 415 | /// Verify - Verify that a variable descriptor is well formed. |
| 416 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 417 | |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 418 | /// HasComplexAddr - Return true if the variable has a complex address. |
| 419 | bool hasComplexAddress() const { |
| 420 | return getNumAddrElements() > 0; |
| 421 | } |
| 422 | |
| 423 | unsigned getNumAddrElements() const { return DbgNode->getNumElements()-6; } |
| 424 | |
| 425 | uint64_t getAddrElement(unsigned Idx) const { |
| 426 | return getUInt64Field(Idx+6); |
| 427 | } |
| 428 | |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 429 | /// isBlockByrefVariable - Return true if the variable was declared as |
| 430 | /// a "__block" variable (Apple Blocks). |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 431 | bool isBlockByrefVariable() const { |
| 432 | return getType().isBlockByrefStruct(); |
Caroline Tice | dc8f604 | 2009-08-31 21:19:37 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 435 | /// dump - print variable. |
| 436 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 437 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 438 | |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 439 | /// DILexicalBlock - This is a wrapper for a lexical block. |
| 440 | class DILexicalBlock : public DIScope { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 441 | public: |
Daniel Dunbar | 7dd76a1 | 2009-09-19 20:40:28 +0000 | [diff] [blame] | 442 | explicit DILexicalBlock(MDNode *N = 0) : DIScope(N) { |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 443 | if (DbgNode && !isLexicalBlock()) |
Daniel Dunbar | 3fc19bb | 2009-09-19 20:40:21 +0000 | [diff] [blame] | 444 | DbgNode = 0; |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 445 | } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 446 | DIScope getContext() const { return getFieldAs<DIScope>(1); } |
Devang Patel | ecbeb1a | 2009-09-30 22:34:41 +0000 | [diff] [blame] | 447 | const char *getDirectory() const { return getContext().getDirectory(); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 448 | const char *getFilename() const { return getContext().getFilename(); } |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 449 | }; |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 450 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 451 | /// DILocation - This object holds location information. This object |
| 452 | /// is not associated with any DWARF tag. |
| 453 | class DILocation : public DIDescriptor { |
| 454 | public: |
Daniel Dunbar | 7dd76a1 | 2009-09-19 20:40:28 +0000 | [diff] [blame] | 455 | explicit DILocation(MDNode *N) : DIDescriptor(N) { ; } |
Devang Patel | 58e7a2d | 2009-09-01 00:53:21 +0000 | [diff] [blame] | 456 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 457 | unsigned getLineNumber() const { return getUnsignedField(0); } |
| 458 | unsigned getColumnNumber() const { return getUnsignedField(1); } |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 459 | DIScope getScope() const { return getFieldAs<DIScope>(2); } |
| 460 | DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); } |
| 461 | const char *getFilename() const { return getScope().getFilename(); } |
| 462 | const char *getDirectory() const { return getScope().getDirectory(); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 463 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 464 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 465 | /// DIFactory - This object assists with the construction of the various |
| 466 | /// descriptors. |
| 467 | class DIFactory { |
| 468 | Module &M; |
Owen Anderson | 9903527 | 2009-07-07 17:12:53 +0000 | [diff] [blame] | 469 | LLVMContext& VMContext; |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 470 | |
Devang Patel | 3ddf704 | 2009-11-13 02:27:33 +0000 | [diff] [blame] | 471 | const Type *EmptyStructPtr; // "{}*". |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 472 | Function *DeclareFn; // llvm.dbg.declare |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 473 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 474 | DIFactory(const DIFactory &); // DO NOT IMPLEMENT |
| 475 | void operator=(const DIFactory&); // DO NOT IMPLEMENT |
| 476 | public: |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 477 | enum ComplexAddrKind { OpPlus=1, OpDeref }; |
| 478 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 479 | explicit DIFactory(Module &m); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 480 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 481 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 482 | /// This implicitly uniques the arrays created. |
| 483 | DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); |
| 484 | |
| 485 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 486 | /// implicitly uniques the values returned. |
| 487 | DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 488 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 489 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 490 | /// unit. |
| 491 | DICompileUnit CreateCompileUnit(unsigned LangID, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 492 | const char * Filename, |
| 493 | const char * Directory, |
| 494 | const char * Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 495 | bool isMain = false, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 496 | bool isOptimized = false, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 497 | const char *Flags = "", |
| 498 | unsigned RunTimeVer = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 499 | |
| 500 | /// CreateEnumerator - Create a single enumerator value. |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 501 | DIEnumerator CreateEnumerator(const char * Name, uint64_t Val); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 502 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 503 | /// CreateBasicType - Create a basic type like int, float, etc. |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 504 | DIBasicType CreateBasicType(DIDescriptor Context, const char * Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 505 | DICompileUnit CompileUnit, unsigned LineNumber, |
| 506 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 507 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 508 | unsigned Encoding); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 509 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 510 | /// CreateBasicType - Create a basic type like int, float, etc. |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 511 | DIBasicType CreateBasicTypeEx(DIDescriptor Context, const char * Name, |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 512 | DICompileUnit CompileUnit, unsigned LineNumber, |
| 513 | Constant *SizeInBits, Constant *AlignInBits, |
| 514 | Constant *OffsetInBits, unsigned Flags, |
| 515 | unsigned Encoding); |
| 516 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 517 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 518 | /// pointer, typedef, etc. |
| 519 | DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 520 | const char * Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 521 | DICompileUnit CompileUnit, |
| 522 | unsigned LineNumber, |
| 523 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 524 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 525 | DIType DerivedFrom); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 526 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 527 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 528 | /// pointer, typedef, etc. |
| 529 | DIDerivedType CreateDerivedTypeEx(unsigned Tag, DIDescriptor Context, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 530 | const char * Name, |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 531 | DICompileUnit CompileUnit, |
| 532 | unsigned LineNumber, |
| 533 | Constant *SizeInBits, Constant *AlignInBits, |
| 534 | Constant *OffsetInBits, unsigned Flags, |
| 535 | DIType DerivedFrom); |
| 536 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 537 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 538 | DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 539 | const char * Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 540 | DICompileUnit CompileUnit, |
| 541 | unsigned LineNumber, |
| 542 | uint64_t SizeInBits, |
| 543 | uint64_t AlignInBits, |
| 544 | uint64_t OffsetInBits, unsigned Flags, |
| 545 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 546 | DIArray Elements, |
| 547 | unsigned RunTimeLang = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 548 | |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 549 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 550 | DICompositeType CreateCompositeTypeEx(unsigned Tag, DIDescriptor Context, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 551 | const char * Name, |
Devang Patel | ac16d44 | 2009-10-26 16:54:35 +0000 | [diff] [blame] | 552 | DICompileUnit CompileUnit, |
| 553 | unsigned LineNumber, |
| 554 | Constant *SizeInBits, |
| 555 | Constant *AlignInBits, |
| 556 | Constant *OffsetInBits, unsigned Flags, |
| 557 | DIType DerivedFrom, |
| 558 | DIArray Elements, |
| 559 | unsigned RunTimeLang = 0); |
| 560 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 561 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 562 | /// See comments in DISubprogram for descriptions of these fields. |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 563 | DISubprogram CreateSubprogram(DIDescriptor Context, const char * Name, |
| 564 | const char * DisplayName, |
| 565 | const char * LinkageName, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 566 | DICompileUnit CompileUnit, unsigned LineNo, |
| 567 | DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 568 | bool isDefinition); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 569 | |
| 570 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 571 | DIGlobalVariable |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 572 | CreateGlobalVariable(DIDescriptor Context, const char * Name, |
| 573 | const char * DisplayName, |
| 574 | const char * LinkageName, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 575 | DICompileUnit CompileUnit, |
| 576 | unsigned LineNo, DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 577 | bool isDefinition, llvm::GlobalVariable *GV); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 578 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 579 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 580 | DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, |
Devang Patel | afa5a34 | 2009-11-12 00:50:58 +0000 | [diff] [blame] | 581 | const char * Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 582 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 583 | DIType Type); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 584 | |
Mike Stump | 3e4c9bd | 2009-09-30 00:08:22 +0000 | [diff] [blame] | 585 | /// CreateComplexVariable - Create a new descriptor for the specified |
| 586 | /// variable which has a complex address expression for its address. |
| 587 | DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Context, |
| 588 | const std::string &Name, |
| 589 | DICompileUnit CompileUnit, unsigned LineNo, |
| 590 | DIType Type, |
| 591 | SmallVector<Value *, 9> &addr); |
| 592 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 593 | /// CreateLexicalBlock - This creates a descriptor for a lexical block |
Devang Patel | 5e005d8 | 2009-08-31 22:00:15 +0000 | [diff] [blame] | 594 | /// with the specified parent context. |
| 595 | DILexicalBlock CreateLexicalBlock(DIDescriptor Context); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 596 | |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 597 | /// CreateLocation - Creates a debug info location. |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 598 | DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo, |
Daniel Dunbar | 3fc19bb | 2009-09-19 20:40:21 +0000 | [diff] [blame] | 599 | DIScope S, DILocation OrigLoc); |
Devang Patel | f98d8fe | 2009-09-01 01:14:15 +0000 | [diff] [blame] | 600 | |
Devang Patel | e54a5e8 | 2009-11-23 19:11:20 +0000 | [diff] [blame^] | 601 | /// CreateLocation - Creates a debug info location. |
| 602 | DILocation CreateLocation(unsigned LineNo, unsigned ColumnNo, |
| 603 | DIScope S, MDNode *OrigLoc = 0); |
| 604 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 605 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 606 | Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D, |
| 607 | BasicBlock *InsertAtEnd); |
Mike Stump | e425039 | 2009-10-01 22:08:58 +0000 | [diff] [blame] | 608 | |
| 609 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 610 | Instruction *InsertDeclare(llvm::Value *Storage, DIVariable D, |
| 611 | Instruction *InsertBefore); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 612 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 613 | private: |
| 614 | Constant *GetTagConstant(unsigned TAG); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 615 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 616 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 617 | /// Finds the stoppoint coressponding to this instruction, that is the |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 618 | /// stoppoint that dominates this instruction |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 619 | const DbgStopPointInst *findStopPoint(const Instruction *Inst); |
| 620 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 621 | /// Finds the stoppoint corresponding to first real (non-debug intrinsic) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 622 | /// instruction in this Basic Block, and returns the stoppoint for it. |
| 623 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB); |
| 624 | |
| 625 | /// Finds the dbg.declare intrinsic corresponding to this value if any. |
| 626 | /// It looks through pointer casts too. |
| 627 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 628 | |
| 629 | /// Find the debug info descriptor corresponding to this global variable. |
| 630 | Value *findDbgGlobalDeclare(GlobalVariable *V); |
| 631 | |
Devang Patel | 5ccdd10 | 2009-09-29 18:40:58 +0000 | [diff] [blame] | 632 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 633 | std::string &Type, unsigned &LineNo, std::string &File, |
| 634 | std::string &Dir); |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 635 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 636 | /// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 637 | /// info intrinsic. |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 638 | bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 639 | CodeGenOpt::Level OptLev); |
| 640 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 641 | /// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 642 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 643 | bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI, |
| 644 | CodeGenOpt::Level OptLev); |
| 645 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 646 | /// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 647 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 648 | bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI, |
| 649 | CodeGenOpt::Level OptLev); |
| 650 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 651 | /// isValidDebugInfoIntrinsic - Return true if REI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 652 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 653 | bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI, |
| 654 | CodeGenOpt::Level OptLev); |
| 655 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 656 | /// isValidDebugInfoIntrinsic - Return true if DI is a valid debug |
Devang Patel | dfc8536 | 2009-07-02 17:17:03 +0000 | [diff] [blame] | 657 | /// info intrinsic. |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 658 | bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI, |
| 659 | CodeGenOpt::Level OptLev); |
| 660 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 661 | /// ExtractDebugLocation - Extract debug location information |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 662 | /// from llvm.dbg.stoppoint intrinsic. |
| 663 | DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 664 | DebugLocTracker &DebugLocInfo); |
| 665 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 666 | /// ExtractDebugLocation - Extract debug location information |
Devang Patel | 1b75f44 | 2009-09-16 18:20:05 +0000 | [diff] [blame] | 667 | /// from DILocation. |
| 668 | DebugLoc ExtractDebugLocation(DILocation &Loc, |
| 669 | DebugLocTracker &DebugLocInfo); |
| 670 | |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 671 | /// ExtractDebugLocation - Extract debug location information |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 672 | /// from llvm.dbg.func_start intrinsic. |
| 673 | DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI, |
Devang Patel | 9e529c3 | 2009-07-02 01:15:24 +0000 | [diff] [blame] | 674 | DebugLocTracker &DebugLocInfo); |
| 675 | |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 676 | class DebugInfoFinder { |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 677 | |
| 678 | public: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 679 | /// processModule - Process entire module and collect debug info |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 680 | /// anchors. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 681 | void processModule(Module &M); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 682 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 683 | private: |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 684 | /// processType - Process DIType. |
| 685 | void processType(DIType DT); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 686 | |
Devang Patel | beab41b | 2009-10-07 22:04:08 +0000 | [diff] [blame] | 687 | /// processLexicalBlock - Process DILexicalBlock. |
| 688 | void processLexicalBlock(DILexicalBlock LB); |
| 689 | |
| 690 | /// processSubprogram - Process DISubprogram. |
Devang Patel | 98c6517 | 2009-07-30 18:25:15 +0000 | [diff] [blame] | 691 | void processSubprogram(DISubprogram SP); |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 692 | |
Devang Patel | b4d3130 | 2009-07-31 18:18:52 +0000 | [diff] [blame] | 693 | /// processDeclare - Process DbgDeclareInst. |
| 694 | void processDeclare(DbgDeclareInst *DDI); |
| 695 | |
Devang Patel | 6daf99b | 2009-11-10 22:05:35 +0000 | [diff] [blame] | 696 | /// processLocation - Process DILocation. |
| 697 | void processLocation(DILocation Loc); |
| 698 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 699 | /// addCompileUnit - Add compile unit into CUs. |
| 700 | bool addCompileUnit(DICompileUnit CU); |
Daniel Dunbar | f612ff6 | 2009-09-19 20:40:05 +0000 | [diff] [blame] | 701 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 702 | /// addGlobalVariable - Add global variable into GVs. |
| 703 | bool addGlobalVariable(DIGlobalVariable DIG); |
| 704 | |
| 705 | // addSubprogram - Add subprgoram into SPs. |
| 706 | bool addSubprogram(DISubprogram SP); |
| 707 | |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 708 | /// addType - Add type into Tys. |
| 709 | bool addType(DIType DT); |
| 710 | |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 711 | public: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 712 | typedef SmallVector<MDNode *, 8>::iterator iterator; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 713 | iterator compile_unit_begin() { return CUs.begin(); } |
| 714 | iterator compile_unit_end() { return CUs.end(); } |
| 715 | iterator subprogram_begin() { return SPs.begin(); } |
| 716 | iterator subprogram_end() { return SPs.end(); } |
| 717 | iterator global_variable_begin() { return GVs.begin(); } |
| 718 | iterator global_variable_end() { return GVs.end(); } |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 719 | iterator type_begin() { return TYs.begin(); } |
| 720 | iterator type_end() { return TYs.end(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 721 | |
| 722 | unsigned compile_unit_count() { return CUs.size(); } |
| 723 | unsigned global_variable_count() { return GVs.size(); } |
| 724 | unsigned subprogram_count() { return SPs.size(); } |
Devang Patel | 72bcdb6 | 2009-08-10 22:09:58 +0000 | [diff] [blame] | 725 | unsigned type_count() { return TYs.size(); } |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 726 | |
| 727 | private: |
Devang Patel | e4b2756 | 2009-08-28 23:24:31 +0000 | [diff] [blame] | 728 | SmallVector<MDNode *, 8> CUs; // Compile Units |
| 729 | SmallVector<MDNode *, 8> SPs; // Subprograms |
| 730 | SmallVector<MDNode *, 8> GVs; // Global Variables; |
| 731 | SmallVector<MDNode *, 8> TYs; // Types |
| 732 | SmallPtrSet<MDNode *, 64> NodesSeen; |
Devang Patel | d2f79a1 | 2009-07-28 19:55:13 +0000 | [diff] [blame] | 733 | }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 734 | } // end namespace llvm |
| 735 | |
| 736 | #endif |