Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MachineDebugInfo.cpp -----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by James M. Laskey and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 9 | |
| 10 | #include "llvm/CodeGen/MachineDebugInfo.h" |
| 11 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 12 | #include "llvm/Constants.h" |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 13 | #include "llvm/CodeGen/MachineLocation.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 14 | #include "llvm/DerivedTypes.h" |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 15 | #include "llvm/GlobalVariable.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 16 | #include "llvm/Intrinsics.h" |
| 17 | #include "llvm/Instructions.h" |
| 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/Support/Dwarf.h" |
| 20 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 21 | #include <iostream> |
| 22 | |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 24 | using namespace llvm::dwarf; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 25 | |
| 26 | // Handle the Pass registration stuff necessary to use TargetData's. |
| 27 | namespace { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 28 | RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information"); |
| 29 | } |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 30 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 31 | //===----------------------------------------------------------------------===// |
| 32 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 33 | /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 34 | /// specified value in their initializer somewhere. |
| 35 | static void |
| 36 | getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) { |
| 37 | // Scan though value users. |
| 38 | for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { |
| 39 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 40 | // If the user is a GlobalVariable then add to result. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 41 | Result.push_back(GV); |
| 42 | } else if (Constant *C = dyn_cast<Constant>(*I)) { |
| 43 | // If the user is a constant variable then scan its users |
| 44 | getGlobalVariablesUsing(C, Result); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 49 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 50 | /// named GlobalVariable. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 51 | static std::vector<GlobalVariable*> |
| 52 | getGlobalVariablesUsing(Module &M, const std::string &RootName) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 53 | std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 54 | |
| 55 | std::vector<const Type*> FieldTypes; |
| 56 | FieldTypes.push_back(Type::UIntTy); |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 57 | FieldTypes.push_back(Type::UIntTy); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 58 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 59 | // Get the GlobalVariable root. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 60 | GlobalVariable *UseRoot = M.getGlobalVariable(RootName, |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 61 | StructType::get(FieldTypes)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 62 | |
| 63 | // If present and linkonce then scan for users. |
| 64 | if (UseRoot && UseRoot->hasLinkOnceLinkage()) { |
| 65 | getGlobalVariablesUsing(UseRoot, Result); |
| 66 | } |
| 67 | |
| 68 | return Result; |
| 69 | } |
| 70 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 71 | /// isStringValue - Return true if the given value can be coerced to a string. |
| 72 | /// |
| 73 | static bool isStringValue(Value *V) { |
| 74 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 75 | if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { |
| 76 | ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); |
| 77 | return Init->isString(); |
| 78 | } |
| 79 | } else if (Constant *C = dyn_cast<Constant>(V)) { |
| 80 | if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 81 | return isStringValue(GV); |
| 82 | else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { |
| 83 | if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 84 | if (CE->getNumOperands() == 3 && |
| 85 | cast<Constant>(CE->getOperand(1))->isNullValue() && |
| 86 | isa<ConstantInt>(CE->getOperand(2))) { |
| 87 | return isStringValue(CE->getOperand(0)); |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 95 | /// getGlobalVariable - Return either a direct or cast Global value. |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 96 | /// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 97 | static GlobalVariable *getGlobalVariable(Value *V) { |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 98 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 99 | return GV; |
| 100 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 101 | if (CE->getOpcode() == Instruction::Cast) { |
| 102 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
| 103 | } |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 104 | } |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 108 | /// isGlobalVariable - Return true if the given value can be coerced to a |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 109 | /// GlobalVariable. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 110 | static bool isGlobalVariable(Value *V) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 111 | if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) { |
| 112 | return true; |
| 113 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
| 114 | if (CE->getOpcode() == Instruction::Cast) { |
| 115 | return isa<GlobalVariable>(CE->getOperand(0)); |
| 116 | } |
| 117 | } |
| 118 | return false; |
| 119 | } |
| 120 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 121 | /// getUIntOperand - Return ith operand if it is an unsigned integer. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 122 | /// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 123 | static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 124 | // Make sure the GlobalVariable has an initializer. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 125 | if (!GV->hasInitializer()) return NULL; |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 126 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 127 | // Get the initializer constant. |
| 128 | ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer()); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 129 | if (!CI) return NULL; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 130 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 131 | // Check if there is at least i + 1 operands. |
| 132 | unsigned N = CI->getNumOperands(); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 133 | if (i >= N) return NULL; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 134 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 135 | // Check constant. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 136 | return dyn_cast<ConstantUInt>(CI->getOperand(i)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 137 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 138 | //===----------------------------------------------------------------------===// |
| 139 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 140 | /// ApplyToFields - Target the visitor to each field of the debug information |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 141 | /// descriptor. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 142 | void DIVisitor::ApplyToFields(DebugInfoDesc *DD) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 143 | DD->ApplyToFields(this); |
| 144 | } |
| 145 | |
| 146 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 147 | /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug |
| 148 | /// the supplied DebugInfoDesc. |
| 149 | class DICountVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 150 | private: |
| 151 | unsigned Count; // Running count of fields. |
| 152 | |
| 153 | public: |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 154 | DICountVisitor() : DIVisitor(), Count(0) {} |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 155 | |
| 156 | // Accessors. |
| 157 | unsigned getCount() const { return Count; } |
| 158 | |
| 159 | /// Apply - Count each of the fields. |
| 160 | /// |
| 161 | virtual void Apply(int &Field) { ++Count; } |
| 162 | virtual void Apply(unsigned &Field) { ++Count; } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 163 | virtual void Apply(int64_t &Field) { ++Count; } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 164 | virtual void Apply(uint64_t &Field) { ++Count; } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 165 | virtual void Apply(bool &Field) { ++Count; } |
| 166 | virtual void Apply(std::string &Field) { ++Count; } |
| 167 | virtual void Apply(DebugInfoDesc *&Field) { ++Count; } |
| 168 | virtual void Apply(GlobalVariable *&Field) { ++Count; } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 169 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 170 | ++Count; |
| 171 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 175 | /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the |
| 176 | /// supplied DebugInfoDesc. |
| 177 | class DIDeserializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 178 | private: |
| 179 | DIDeserializer &DR; // Active deserializer. |
| 180 | unsigned I; // Current operand index. |
| 181 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 182 | |
| 183 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 184 | DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV) |
| 185 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 186 | , DR(D) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 187 | , I(0) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 188 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 189 | {} |
| 190 | |
| 191 | /// Apply - Set the value of each of the fields. |
| 192 | /// |
| 193 | virtual void Apply(int &Field) { |
| 194 | Constant *C = CI->getOperand(I++); |
| 195 | Field = cast<ConstantSInt>(C)->getValue(); |
| 196 | } |
| 197 | virtual void Apply(unsigned &Field) { |
| 198 | Constant *C = CI->getOperand(I++); |
| 199 | Field = cast<ConstantUInt>(C)->getValue(); |
| 200 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 201 | virtual void Apply(int64_t &Field) { |
| 202 | Constant *C = CI->getOperand(I++); |
| 203 | Field = cast<ConstantSInt>(C)->getValue(); |
| 204 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 205 | virtual void Apply(uint64_t &Field) { |
| 206 | Constant *C = CI->getOperand(I++); |
| 207 | Field = cast<ConstantUInt>(C)->getValue(); |
| 208 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 209 | virtual void Apply(bool &Field) { |
| 210 | Constant *C = CI->getOperand(I++); |
| 211 | Field = cast<ConstantBool>(C)->getValue(); |
| 212 | } |
| 213 | virtual void Apply(std::string &Field) { |
| 214 | Constant *C = CI->getOperand(I++); |
Jim Laskey | 21b6c9d | 2006-03-08 18:11:07 +0000 | [diff] [blame] | 215 | Field = C->getStringValue(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 216 | } |
| 217 | virtual void Apply(DebugInfoDesc *&Field) { |
| 218 | Constant *C = CI->getOperand(I++); |
| 219 | Field = DR.Deserialize(C); |
| 220 | } |
| 221 | virtual void Apply(GlobalVariable *&Field) { |
| 222 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 223 | Field = getGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 224 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 225 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 226 | Field.resize(0); |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 227 | Constant *C = CI->getOperand(I++); |
| 228 | GlobalVariable *GV = getGlobalVariable(C); |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 229 | if (GV->hasInitializer()) { |
| 230 | if (ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer())) { |
| 231 | for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) { |
| 232 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 233 | DebugInfoDesc *DE = DR.Deserialize(GVE); |
| 234 | Field.push_back(DE); |
| 235 | } |
| 236 | } else if (GV->getInitializer()->isNullValue()) { |
| 237 | if (const ArrayType *T = |
| 238 | dyn_cast<ArrayType>(GV->getType()->getElementType())) { |
| 239 | Field.resize(T->getNumElements()); |
| 240 | } |
Jim Laskey | 2b0e309 | 2006-03-08 02:07:02 +0000 | [diff] [blame] | 241 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 247 | /// DISerializeVisitor - This DIVisitor serializes all the fields in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 248 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 249 | class DISerializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 250 | private: |
| 251 | DISerializer &SR; // Active serializer. |
| 252 | std::vector<Constant*> &Elements; // Element accumulator. |
| 253 | |
| 254 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 255 | DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E) |
| 256 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 257 | , SR(S) |
| 258 | , Elements(E) |
| 259 | {} |
| 260 | |
| 261 | /// Apply - Set the value of each of the fields. |
| 262 | /// |
| 263 | virtual void Apply(int &Field) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 264 | Elements.push_back(ConstantSInt::get(Type::IntTy, Field)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 265 | } |
| 266 | virtual void Apply(unsigned &Field) { |
| 267 | Elements.push_back(ConstantUInt::get(Type::UIntTy, Field)); |
| 268 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 269 | virtual void Apply(int64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 270 | Elements.push_back(ConstantSInt::get(Type::LongTy, Field)); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 271 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 272 | virtual void Apply(uint64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 273 | Elements.push_back(ConstantUInt::get(Type::ULongTy, Field)); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 274 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 275 | virtual void Apply(bool &Field) { |
| 276 | Elements.push_back(ConstantBool::get(Field)); |
| 277 | } |
| 278 | virtual void Apply(std::string &Field) { |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 279 | Elements.push_back(SR.getString(Field)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 280 | } |
| 281 | virtual void Apply(DebugInfoDesc *&Field) { |
| 282 | GlobalVariable *GV = NULL; |
| 283 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 284 | // If non-NULL then convert to global. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 285 | if (Field) GV = SR.Serialize(Field); |
| 286 | |
| 287 | // FIXME - At some point should use specific type. |
| 288 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 289 | |
| 290 | if (GV) { |
| 291 | // Set to pointer to global. |
| 292 | Elements.push_back(ConstantExpr::getCast(GV, EmptyTy)); |
| 293 | } else { |
| 294 | // Use NULL. |
| 295 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 296 | } |
| 297 | } |
| 298 | virtual void Apply(GlobalVariable *&Field) { |
| 299 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 300 | if (Field) { |
| 301 | Elements.push_back(ConstantExpr::getCast(Field, EmptyTy)); |
| 302 | } else { |
| 303 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 304 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 305 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 306 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 307 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 308 | unsigned N = Field.size(); |
| 309 | ArrayType *AT = ArrayType::get(EmptyTy, N); |
| 310 | std::vector<Constant *> ArrayElements; |
| 311 | |
| 312 | for (unsigned i = 0, N = Field.size(); i < N; ++i) { |
Jim Laskey | d04c159 | 2006-07-13 15:27:42 +0000 | [diff] [blame] | 313 | if (DebugInfoDesc *Element = Field[i]) { |
| 314 | GlobalVariable *GVE = SR.Serialize(Element); |
| 315 | Constant *CE = ConstantExpr::getCast(GVE, EmptyTy); |
| 316 | ArrayElements.push_back(cast<Constant>(CE)); |
| 317 | } else { |
| 318 | ArrayElements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 319 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | Constant *CA = ConstantArray::get(AT, ArrayElements); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 323 | GlobalVariable *CAGV = new GlobalVariable(AT, true, |
| 324 | GlobalValue::InternalLinkage, |
| 325 | CA, "llvm.dbg.array", |
| 326 | SR.getModule()); |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 327 | CAGV->setSection("llvm.metadata"); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 328 | Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy); |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 329 | Elements.push_back(CAE); |
| 330 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 334 | /// DIGetTypesVisitor - This DIVisitor gathers all the field types in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 335 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 336 | class DIGetTypesVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 337 | private: |
| 338 | DISerializer &SR; // Active serializer. |
| 339 | std::vector<const Type*> &Fields; // Type accumulator. |
| 340 | |
| 341 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 342 | DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F) |
| 343 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 344 | , SR(S) |
| 345 | , Fields(F) |
| 346 | {} |
| 347 | |
| 348 | /// Apply - Set the value of each of the fields. |
| 349 | /// |
| 350 | virtual void Apply(int &Field) { |
| 351 | Fields.push_back(Type::IntTy); |
| 352 | } |
| 353 | virtual void Apply(unsigned &Field) { |
| 354 | Fields.push_back(Type::UIntTy); |
| 355 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 356 | virtual void Apply(int64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 357 | Fields.push_back(Type::LongTy); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 358 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 359 | virtual void Apply(uint64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 360 | Fields.push_back(Type::ULongTy); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 361 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 362 | virtual void Apply(bool &Field) { |
| 363 | Fields.push_back(Type::BoolTy); |
| 364 | } |
| 365 | virtual void Apply(std::string &Field) { |
| 366 | Fields.push_back(SR.getStrPtrType()); |
| 367 | } |
| 368 | virtual void Apply(DebugInfoDesc *&Field) { |
| 369 | // FIXME - At some point should use specific type. |
| 370 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 371 | Fields.push_back(EmptyTy); |
| 372 | } |
| 373 | virtual void Apply(GlobalVariable *&Field) { |
| 374 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 375 | Fields.push_back(EmptyTy); |
| 376 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 377 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 378 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 379 | Fields.push_back(EmptyTy); |
| 380 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 384 | /// DIVerifyVisitor - This DIVisitor verifies all the field types against |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 385 | /// a constant initializer. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 386 | class DIVerifyVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 387 | private: |
| 388 | DIVerifier &VR; // Active verifier. |
| 389 | bool IsValid; // Validity status. |
| 390 | unsigned I; // Current operand index. |
| 391 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 392 | |
| 393 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 394 | DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV) |
| 395 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 396 | , VR(V) |
| 397 | , IsValid(true) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 398 | , I(0) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 399 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 400 | { |
| 401 | } |
| 402 | |
| 403 | // Accessors. |
| 404 | bool isValid() const { return IsValid; } |
| 405 | |
| 406 | /// Apply - Set the value of each of the fields. |
| 407 | /// |
| 408 | virtual void Apply(int &Field) { |
| 409 | Constant *C = CI->getOperand(I++); |
| 410 | IsValid = IsValid && isa<ConstantInt>(C); |
| 411 | } |
| 412 | virtual void Apply(unsigned &Field) { |
| 413 | Constant *C = CI->getOperand(I++); |
| 414 | IsValid = IsValid && isa<ConstantInt>(C); |
| 415 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 416 | virtual void Apply(int64_t &Field) { |
| 417 | Constant *C = CI->getOperand(I++); |
| 418 | IsValid = IsValid && isa<ConstantInt>(C); |
| 419 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 420 | virtual void Apply(uint64_t &Field) { |
| 421 | Constant *C = CI->getOperand(I++); |
| 422 | IsValid = IsValid && isa<ConstantInt>(C); |
| 423 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 424 | virtual void Apply(bool &Field) { |
| 425 | Constant *C = CI->getOperand(I++); |
| 426 | IsValid = IsValid && isa<ConstantBool>(C); |
| 427 | } |
| 428 | virtual void Apply(std::string &Field) { |
| 429 | Constant *C = CI->getOperand(I++); |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 430 | IsValid = IsValid && (!C || isStringValue(C)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 431 | } |
| 432 | virtual void Apply(DebugInfoDesc *&Field) { |
| 433 | // FIXME - Prepare the correct descriptor. |
| 434 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 435 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 436 | } |
| 437 | virtual void Apply(GlobalVariable *&Field) { |
| 438 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 439 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 440 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 441 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 442 | Constant *C = CI->getOperand(I++); |
| 443 | IsValid = IsValid && isGlobalVariable(C); |
| 444 | if (!IsValid) return; |
| 445 | |
| 446 | GlobalVariable *GV = getGlobalVariable(C); |
| 447 | IsValid = IsValid && GV && GV->hasInitializer(); |
| 448 | if (!IsValid) return; |
| 449 | |
| 450 | ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 451 | IsValid = IsValid && CA; |
| 452 | if (!IsValid) return; |
| 453 | |
| 454 | for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) { |
| 455 | IsValid = IsValid && isGlobalVariable(CA->getOperand(i)); |
| 456 | if (!IsValid) return; |
| 457 | |
| 458 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 459 | VR.Verify(GVE); |
| 460 | } |
| 461 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 462 | }; |
| 463 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 464 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 465 | //===----------------------------------------------------------------------===// |
| 466 | |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 467 | /// TagFromGlobal - Returns the tag number from a debug info descriptor |
| 468 | /// GlobalVariable. Return DIIValid if operand is not an unsigned int. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 469 | unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) { |
| 470 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 471 | return C ? ((unsigned)C->getValue() & ~LLVMDebugVersionMask) : |
| 472 | (unsigned)DW_TAG_invalid; |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /// VersionFromGlobal - Returns the version number from a debug info |
| 476 | /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned |
| 477 | /// int. |
| 478 | unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) { |
| 479 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 480 | return C ? ((unsigned)C->getValue() & LLVMDebugVersionMask) : |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 481 | (unsigned)DW_TAG_invalid; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /// DescFactory - Create an instance of debug info descriptor based on Tag. |
| 485 | /// Return NULL if not a recognized Tag. |
| 486 | DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { |
| 487 | switch (Tag) { |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 488 | case DW_TAG_anchor: return new AnchorDesc(); |
| 489 | case DW_TAG_compile_unit: return new CompileUnitDesc(); |
| 490 | case DW_TAG_variable: return new GlobalVariableDesc(); |
| 491 | case DW_TAG_subprogram: return new SubprogramDesc(); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 492 | case DW_TAG_lexical_block: return new BlockDesc(); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 493 | case DW_TAG_base_type: return new BasicTypeDesc(); |
| 494 | case DW_TAG_typedef: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 495 | case DW_TAG_pointer_type: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 496 | case DW_TAG_reference_type: |
| 497 | case DW_TAG_const_type: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 498 | case DW_TAG_volatile_type: |
| 499 | case DW_TAG_restrict_type: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 500 | case DW_TAG_member: return new DerivedTypeDesc(Tag); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 501 | case DW_TAG_array_type: |
| 502 | case DW_TAG_structure_type: |
| 503 | case DW_TAG_union_type: |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 504 | case DW_TAG_enumeration_type: |
Jim Laskey | 650f609 | 2006-06-20 19:41:06 +0000 | [diff] [blame] | 505 | case DW_TAG_vector_type: |
| 506 | case DW_TAG_subroutine_type: return new CompositeTypeDesc(Tag); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 507 | case DW_TAG_subrange_type: return new SubrangeDesc(); |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 508 | case DW_TAG_enumerator: return new EnumeratorDesc(); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 509 | case DW_TAG_return_variable: |
| 510 | case DW_TAG_arg_variable: |
| 511 | case DW_TAG_auto_variable: return new VariableDesc(Tag); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 512 | default: break; |
| 513 | } |
| 514 | return NULL; |
| 515 | } |
| 516 | |
| 517 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 518 | /// |
| 519 | GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const { |
| 520 | return GlobalValue::InternalLinkage; |
| 521 | } |
| 522 | |
| 523 | /// ApplyToFields - Target the vistor to the fields of the descriptor. |
| 524 | /// |
| 525 | void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) { |
| 526 | Visitor->Apply(Tag); |
| 527 | } |
| 528 | |
| 529 | //===----------------------------------------------------------------------===// |
| 530 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 531 | AnchorDesc::AnchorDesc() |
| 532 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 533 | , AnchorTag(0) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 534 | {} |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 535 | AnchorDesc::AnchorDesc(AnchoredDesc *D) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 536 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 537 | , AnchorTag(D->getTag()) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 538 | {} |
| 539 | |
| 540 | // Implement isa/cast/dyncast. |
| 541 | bool AnchorDesc::classof(const DebugInfoDesc *D) { |
| 542 | return D->getTag() == DW_TAG_anchor; |
| 543 | } |
| 544 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 545 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 546 | /// |
| 547 | GlobalValue::LinkageTypes AnchorDesc::getLinkage() const { |
| 548 | return GlobalValue::LinkOnceLinkage; |
| 549 | } |
| 550 | |
| 551 | /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc. |
| 552 | /// |
| 553 | void AnchorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 554 | DebugInfoDesc::ApplyToFields(Visitor); |
| 555 | |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 556 | Visitor->Apply(AnchorTag); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 559 | /// getDescString - Return a string used to compose global names and labels. A |
| 560 | /// A global variable name needs to be defined for each debug descriptor that is |
Jim Laskey | 21b6c9d | 2006-03-08 18:11:07 +0000 | [diff] [blame] | 561 | /// anchored. NOTE: that each global variable named here also needs to be added |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 562 | /// to the list of names left external in the internalizer. |
| 563 | /// ExternalNames.insert("llvm.dbg.compile_units"); |
| 564 | /// ExternalNames.insert("llvm.dbg.global_variables"); |
| 565 | /// ExternalNames.insert("llvm.dbg.subprograms"); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 566 | const char *AnchorDesc::getDescString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 567 | switch (AnchorTag) { |
| 568 | case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString; |
| 569 | case DW_TAG_variable: return GlobalVariableDesc::AnchorString; |
| 570 | case DW_TAG_subprogram: return SubprogramDesc::AnchorString; |
| 571 | default: break; |
| 572 | } |
| 573 | |
| 574 | assert(0 && "Tag does not have a case for anchor string"); |
| 575 | return ""; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /// getTypeString - Return a string used to label this descriptors type. |
| 579 | /// |
| 580 | const char *AnchorDesc::getTypeString() const { |
| 581 | return "llvm.dbg.anchor.type"; |
| 582 | } |
| 583 | |
| 584 | #ifndef NDEBUG |
| 585 | void AnchorDesc::dump() { |
| 586 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 587 | << "Version(" << getVersion() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 588 | << "Tag(" << getTag() << "), " |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 589 | << "AnchorTag(" << AnchorTag << ")\n"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 590 | } |
| 591 | #endif |
| 592 | |
| 593 | //===----------------------------------------------------------------------===// |
| 594 | |
| 595 | AnchoredDesc::AnchoredDesc(unsigned T) |
| 596 | : DebugInfoDesc(T) |
| 597 | , Anchor(NULL) |
| 598 | {} |
| 599 | |
| 600 | /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc. |
| 601 | /// |
| 602 | void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) { |
| 603 | DebugInfoDesc::ApplyToFields(Visitor); |
| 604 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 605 | Visitor->Apply(Anchor); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | //===----------------------------------------------------------------------===// |
| 609 | |
| 610 | CompileUnitDesc::CompileUnitDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 611 | : AnchoredDesc(DW_TAG_compile_unit) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 612 | , Language(0) |
| 613 | , FileName("") |
| 614 | , Directory("") |
| 615 | , Producer("") |
| 616 | {} |
| 617 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 618 | // Implement isa/cast/dyncast. |
| 619 | bool CompileUnitDesc::classof(const DebugInfoDesc *D) { |
| 620 | return D->getTag() == DW_TAG_compile_unit; |
| 621 | } |
| 622 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 623 | /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. |
| 624 | /// |
| 625 | void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 626 | AnchoredDesc::ApplyToFields(Visitor); |
Jim Laskey | ca0dc56 | 2006-06-19 12:54:15 +0000 | [diff] [blame] | 627 | |
| 628 | // Handle cases out of sync with compiler. |
| 629 | if (getVersion() == 0) { |
| 630 | unsigned DebugVersion; |
| 631 | Visitor->Apply(DebugVersion); |
| 632 | } |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 633 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 634 | Visitor->Apply(Language); |
| 635 | Visitor->Apply(FileName); |
| 636 | Visitor->Apply(Directory); |
| 637 | Visitor->Apply(Producer); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 640 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 641 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 642 | const char *CompileUnitDesc::getDescString() const { |
| 643 | return "llvm.dbg.compile_unit"; |
| 644 | } |
| 645 | |
| 646 | /// getTypeString - Return a string used to label this descriptors type. |
| 647 | /// |
| 648 | const char *CompileUnitDesc::getTypeString() const { |
| 649 | return "llvm.dbg.compile_unit.type"; |
| 650 | } |
| 651 | |
| 652 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 653 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 654 | const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 655 | const char *CompileUnitDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 656 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 657 | } |
| 658 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 659 | #ifndef NDEBUG |
| 660 | void CompileUnitDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 661 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 662 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 663 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 664 | << "Anchor(" << getAnchor() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 665 | << "Language(" << Language << "), " |
| 666 | << "FileName(\"" << FileName << "\"), " |
| 667 | << "Directory(\"" << Directory << "\"), " |
| 668 | << "Producer(\"" << Producer << "\")\n"; |
| 669 | } |
| 670 | #endif |
| 671 | |
| 672 | //===----------------------------------------------------------------------===// |
| 673 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 674 | TypeDesc::TypeDesc(unsigned T) |
| 675 | : DebugInfoDesc(T) |
| 676 | , Context(NULL) |
| 677 | , Name("") |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 678 | , File(NULL) |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 679 | , Line(0) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 680 | , Size(0) |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 681 | , Align(0) |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 682 | , Offset(0) |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 683 | , Flags(0) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 684 | {} |
| 685 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 686 | /// ApplyToFields - Target the visitor to the fields of the TypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 687 | /// |
| 688 | void TypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 689 | DebugInfoDesc::ApplyToFields(Visitor); |
| 690 | |
| 691 | Visitor->Apply(Context); |
| 692 | Visitor->Apply(Name); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 693 | Visitor->Apply(File); |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 694 | Visitor->Apply(Line); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 695 | Visitor->Apply(Size); |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 696 | Visitor->Apply(Align); |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 697 | Visitor->Apply(Offset); |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 698 | if (getVersion() > LLVMDebugVersion4) Visitor->Apply(Flags); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /// getDescString - Return a string used to compose global names and labels. |
| 702 | /// |
| 703 | const char *TypeDesc::getDescString() const { |
| 704 | return "llvm.dbg.type"; |
| 705 | } |
| 706 | |
| 707 | /// getTypeString - Return a string used to label this descriptor's type. |
| 708 | /// |
| 709 | const char *TypeDesc::getTypeString() const { |
| 710 | return "llvm.dbg.type.type"; |
| 711 | } |
| 712 | |
| 713 | #ifndef NDEBUG |
| 714 | void TypeDesc::dump() { |
| 715 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 716 | << "Version(" << getVersion() << "), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 717 | << "Tag(" << getTag() << "), " |
| 718 | << "Context(" << Context << "), " |
| 719 | << "Name(\"" << Name << "\"), " |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 720 | << "File(" << File << "), " |
| 721 | << "Line(" << Line << "), " |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 722 | << "Size(" << Size << "), " |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 723 | << "Align(" << Align << "), " |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 724 | << "Offset(" << Offset << "), " |
| 725 | << "Flags(" << Flags << ")\n"; |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 726 | } |
| 727 | #endif |
| 728 | |
| 729 | //===----------------------------------------------------------------------===// |
| 730 | |
| 731 | BasicTypeDesc::BasicTypeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 732 | : TypeDesc(DW_TAG_base_type) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 733 | , Encoding(0) |
| 734 | {} |
| 735 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 736 | // Implement isa/cast/dyncast. |
| 737 | bool BasicTypeDesc::classof(const DebugInfoDesc *D) { |
| 738 | return D->getTag() == DW_TAG_base_type; |
| 739 | } |
| 740 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 741 | /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 742 | /// |
| 743 | void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 744 | TypeDesc::ApplyToFields(Visitor); |
| 745 | |
| 746 | Visitor->Apply(Encoding); |
| 747 | } |
| 748 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 749 | /// getDescString - Return a string used to compose global names and labels. |
| 750 | /// |
| 751 | const char *BasicTypeDesc::getDescString() const { |
| 752 | return "llvm.dbg.basictype"; |
| 753 | } |
| 754 | |
| 755 | /// getTypeString - Return a string used to label this descriptor's type. |
| 756 | /// |
| 757 | const char *BasicTypeDesc::getTypeString() const { |
| 758 | return "llvm.dbg.basictype.type"; |
| 759 | } |
| 760 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 761 | #ifndef NDEBUG |
| 762 | void BasicTypeDesc::dump() { |
| 763 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 764 | << "Version(" << getVersion() << "), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 765 | << "Tag(" << getTag() << "), " |
| 766 | << "Context(" << getContext() << "), " |
| 767 | << "Name(\"" << getName() << "\"), " |
| 768 | << "Size(" << getSize() << "), " |
| 769 | << "Encoding(" << Encoding << ")\n"; |
| 770 | } |
| 771 | #endif |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 772 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 773 | //===----------------------------------------------------------------------===// |
| 774 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 775 | DerivedTypeDesc::DerivedTypeDesc(unsigned T) |
| 776 | : TypeDesc(T) |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 777 | , FromType(NULL) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 778 | {} |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 779 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 780 | // Implement isa/cast/dyncast. |
| 781 | bool DerivedTypeDesc::classof(const DebugInfoDesc *D) { |
| 782 | unsigned T = D->getTag(); |
| 783 | switch (T) { |
| 784 | case DW_TAG_typedef: |
| 785 | case DW_TAG_pointer_type: |
| 786 | case DW_TAG_reference_type: |
| 787 | case DW_TAG_const_type: |
| 788 | case DW_TAG_volatile_type: |
| 789 | case DW_TAG_restrict_type: |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 790 | case DW_TAG_member: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 791 | return true; |
| 792 | default: break; |
| 793 | } |
| 794 | return false; |
| 795 | } |
| 796 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 797 | /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 798 | /// |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 799 | void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 800 | TypeDesc::ApplyToFields(Visitor); |
| 801 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 802 | Visitor->Apply(FromType); |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 805 | /// getDescString - Return a string used to compose global names and labels. |
| 806 | /// |
| 807 | const char *DerivedTypeDesc::getDescString() const { |
| 808 | return "llvm.dbg.derivedtype"; |
| 809 | } |
| 810 | |
| 811 | /// getTypeString - Return a string used to label this descriptor's type. |
| 812 | /// |
| 813 | const char *DerivedTypeDesc::getTypeString() const { |
| 814 | return "llvm.dbg.derivedtype.type"; |
| 815 | } |
| 816 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 817 | #ifndef NDEBUG |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 818 | void DerivedTypeDesc::dump() { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 819 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 820 | << "Version(" << getVersion() << "), " |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 821 | << "Tag(" << getTag() << "), " |
| 822 | << "Context(" << getContext() << "), " |
| 823 | << "Name(\"" << getName() << "\"), " |
| 824 | << "Size(" << getSize() << "), " |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 825 | << "File(" << getFile() << "), " |
| 826 | << "Line(" << getLine() << "), " |
| 827 | << "FromType(" << FromType << ")\n"; |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 828 | } |
| 829 | #endif |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 830 | |
| 831 | //===----------------------------------------------------------------------===// |
| 832 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 833 | CompositeTypeDesc::CompositeTypeDesc(unsigned T) |
| 834 | : DerivedTypeDesc(T) |
| 835 | , Elements() |
| 836 | {} |
| 837 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 838 | // Implement isa/cast/dyncast. |
| 839 | bool CompositeTypeDesc::classof(const DebugInfoDesc *D) { |
| 840 | unsigned T = D->getTag(); |
| 841 | switch (T) { |
| 842 | case DW_TAG_array_type: |
| 843 | case DW_TAG_structure_type: |
| 844 | case DW_TAG_union_type: |
| 845 | case DW_TAG_enumeration_type: |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 846 | case DW_TAG_vector_type: |
Jim Laskey | 650f609 | 2006-06-20 19:41:06 +0000 | [diff] [blame] | 847 | case DW_TAG_subroutine_type: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 848 | return true; |
| 849 | default: break; |
| 850 | } |
| 851 | return false; |
| 852 | } |
| 853 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 854 | /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc. |
| 855 | /// |
| 856 | void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 857 | DerivedTypeDesc::ApplyToFields(Visitor); |
| 858 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 859 | Visitor->Apply(Elements); |
| 860 | } |
| 861 | |
| 862 | /// getDescString - Return a string used to compose global names and labels. |
| 863 | /// |
| 864 | const char *CompositeTypeDesc::getDescString() const { |
| 865 | return "llvm.dbg.compositetype"; |
| 866 | } |
| 867 | |
| 868 | /// getTypeString - Return a string used to label this descriptor's type. |
| 869 | /// |
| 870 | const char *CompositeTypeDesc::getTypeString() const { |
| 871 | return "llvm.dbg.compositetype.type"; |
| 872 | } |
| 873 | |
| 874 | #ifndef NDEBUG |
| 875 | void CompositeTypeDesc::dump() { |
| 876 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 877 | << "Version(" << getVersion() << "), " |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 878 | << "Tag(" << getTag() << "), " |
| 879 | << "Context(" << getContext() << "), " |
| 880 | << "Name(\"" << getName() << "\"), " |
| 881 | << "Size(" << getSize() << "), " |
| 882 | << "File(" << getFile() << "), " |
| 883 | << "Line(" << getLine() << "), " |
| 884 | << "FromType(" << getFromType() << "), " |
| 885 | << "Elements.size(" << Elements.size() << ")\n"; |
| 886 | } |
| 887 | #endif |
| 888 | |
| 889 | //===----------------------------------------------------------------------===// |
| 890 | |
| 891 | SubrangeDesc::SubrangeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 892 | : DebugInfoDesc(DW_TAG_subrange_type) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 893 | , Lo(0) |
| 894 | , Hi(0) |
| 895 | {} |
| 896 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 897 | // Implement isa/cast/dyncast. |
| 898 | bool SubrangeDesc::classof(const DebugInfoDesc *D) { |
| 899 | return D->getTag() == DW_TAG_subrange_type; |
| 900 | } |
| 901 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 902 | /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc. |
| 903 | /// |
| 904 | void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 905 | DebugInfoDesc::ApplyToFields(Visitor); |
| 906 | |
| 907 | Visitor->Apply(Lo); |
| 908 | Visitor->Apply(Hi); |
| 909 | } |
| 910 | |
| 911 | /// getDescString - Return a string used to compose global names and labels. |
| 912 | /// |
| 913 | const char *SubrangeDesc::getDescString() const { |
| 914 | return "llvm.dbg.subrange"; |
| 915 | } |
| 916 | |
| 917 | /// getTypeString - Return a string used to label this descriptor's type. |
| 918 | /// |
| 919 | const char *SubrangeDesc::getTypeString() const { |
| 920 | return "llvm.dbg.subrange.type"; |
| 921 | } |
| 922 | |
| 923 | #ifndef NDEBUG |
| 924 | void SubrangeDesc::dump() { |
| 925 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 926 | << "Version(" << getVersion() << "), " |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 927 | << "Tag(" << getTag() << "), " |
| 928 | << "Lo(" << Lo << "), " |
| 929 | << "Hi(" << Hi << ")\n"; |
| 930 | } |
| 931 | #endif |
| 932 | |
| 933 | //===----------------------------------------------------------------------===// |
| 934 | |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 935 | EnumeratorDesc::EnumeratorDesc() |
| 936 | : DebugInfoDesc(DW_TAG_enumerator) |
| 937 | , Name("") |
| 938 | , Value(0) |
| 939 | {} |
| 940 | |
| 941 | // Implement isa/cast/dyncast. |
| 942 | bool EnumeratorDesc::classof(const DebugInfoDesc *D) { |
| 943 | return D->getTag() == DW_TAG_enumerator; |
| 944 | } |
| 945 | |
| 946 | /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc. |
| 947 | /// |
| 948 | void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 949 | DebugInfoDesc::ApplyToFields(Visitor); |
| 950 | |
| 951 | Visitor->Apply(Name); |
| 952 | Visitor->Apply(Value); |
| 953 | } |
| 954 | |
| 955 | /// getDescString - Return a string used to compose global names and labels. |
| 956 | /// |
| 957 | const char *EnumeratorDesc::getDescString() const { |
| 958 | return "llvm.dbg.enumerator"; |
| 959 | } |
| 960 | |
| 961 | /// getTypeString - Return a string used to label this descriptor's type. |
| 962 | /// |
| 963 | const char *EnumeratorDesc::getTypeString() const { |
| 964 | return "llvm.dbg.enumerator.type"; |
| 965 | } |
| 966 | |
| 967 | #ifndef NDEBUG |
| 968 | void EnumeratorDesc::dump() { |
| 969 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 970 | << "Version(" << getVersion() << "), " |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 971 | << "Tag(" << getTag() << "), " |
| 972 | << "Name(" << Name << "), " |
| 973 | << "Value(" << Value << ")\n"; |
| 974 | } |
| 975 | #endif |
| 976 | |
| 977 | //===----------------------------------------------------------------------===// |
| 978 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 979 | VariableDesc::VariableDesc(unsigned T) |
| 980 | : DebugInfoDesc(T) |
| 981 | , Context(NULL) |
| 982 | , Name("") |
| 983 | , File(NULL) |
| 984 | , Line(0) |
| 985 | , TyDesc(0) |
| 986 | {} |
| 987 | |
| 988 | // Implement isa/cast/dyncast. |
| 989 | bool VariableDesc::classof(const DebugInfoDesc *D) { |
| 990 | unsigned T = D->getTag(); |
| 991 | switch (T) { |
| 992 | case DW_TAG_auto_variable: |
| 993 | case DW_TAG_arg_variable: |
| 994 | case DW_TAG_return_variable: |
| 995 | return true; |
| 996 | default: break; |
| 997 | } |
| 998 | return false; |
| 999 | } |
| 1000 | |
| 1001 | /// ApplyToFields - Target the visitor to the fields of the VariableDesc. |
| 1002 | /// |
| 1003 | void VariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1004 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1005 | |
| 1006 | Visitor->Apply(Context); |
| 1007 | Visitor->Apply(Name); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1008 | Visitor->Apply(File); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1009 | Visitor->Apply(Line); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1010 | Visitor->Apply(TyDesc); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /// getDescString - Return a string used to compose global names and labels. |
| 1014 | /// |
| 1015 | const char *VariableDesc::getDescString() const { |
| 1016 | return "llvm.dbg.variable"; |
| 1017 | } |
| 1018 | |
| 1019 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1020 | /// |
| 1021 | const char *VariableDesc::getTypeString() const { |
| 1022 | return "llvm.dbg.variable.type"; |
| 1023 | } |
| 1024 | |
| 1025 | #ifndef NDEBUG |
| 1026 | void VariableDesc::dump() { |
| 1027 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1028 | << "Version(" << getVersion() << "), " |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1029 | << "Tag(" << getTag() << "), " |
| 1030 | << "Context(" << Context << "), " |
| 1031 | << "Name(\"" << Name << "\"), " |
| 1032 | << "File(" << File << "), " |
| 1033 | << "Line(" << Line << "), " |
| 1034 | << "TyDesc(" << TyDesc << ")\n"; |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
| 1038 | //===----------------------------------------------------------------------===// |
| 1039 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1040 | GlobalDesc::GlobalDesc(unsigned T) |
| 1041 | : AnchoredDesc(T) |
| 1042 | , Context(0) |
| 1043 | , Name("") |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 1044 | , DisplayName("") |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1045 | , File(NULL) |
| 1046 | , Line(0) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1047 | , TyDesc(NULL) |
| 1048 | , IsStatic(false) |
| 1049 | , IsDefinition(false) |
| 1050 | {} |
| 1051 | |
| 1052 | /// ApplyToFields - Target the visitor to the fields of the global. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1053 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1054 | void GlobalDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1055 | AnchoredDesc::ApplyToFields(Visitor); |
| 1056 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1057 | Visitor->Apply(Context); |
| 1058 | Visitor->Apply(Name); |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 1059 | if (getVersion() > LLVMDebugVersion4) Visitor->Apply(DisplayName); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1060 | Visitor->Apply(File); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1061 | Visitor->Apply(Line); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1062 | Visitor->Apply(TyDesc); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1063 | Visitor->Apply(IsStatic); |
| 1064 | Visitor->Apply(IsDefinition); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | //===----------------------------------------------------------------------===// |
| 1068 | |
| 1069 | GlobalVariableDesc::GlobalVariableDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1070 | : GlobalDesc(DW_TAG_variable) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1071 | , Global(NULL) |
| 1072 | {} |
| 1073 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1074 | // Implement isa/cast/dyncast. |
| 1075 | bool GlobalVariableDesc::classof(const DebugInfoDesc *D) { |
| 1076 | return D->getTag() == DW_TAG_variable; |
| 1077 | } |
| 1078 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1079 | /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. |
| 1080 | /// |
| 1081 | void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1082 | GlobalDesc::ApplyToFields(Visitor); |
| 1083 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1084 | Visitor->Apply(Global); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1087 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1088 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1089 | const char *GlobalVariableDesc::getDescString() const { |
| 1090 | return "llvm.dbg.global_variable"; |
| 1091 | } |
| 1092 | |
| 1093 | /// getTypeString - Return a string used to label this descriptors type. |
| 1094 | /// |
| 1095 | const char *GlobalVariableDesc::getTypeString() const { |
| 1096 | return "llvm.dbg.global_variable.type"; |
| 1097 | } |
| 1098 | |
| 1099 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1100 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1101 | const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1102 | const char *GlobalVariableDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1103 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1106 | #ifndef NDEBUG |
| 1107 | void GlobalVariableDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1108 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1109 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1110 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1111 | << "Anchor(" << getAnchor() << "), " |
| 1112 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 1113 | << "DisplayName(\"" << getDisplayName() << "\"), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1114 | << "File(" << getFile() << ")," |
| 1115 | << "Line(" << getLine() << ")," |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1116 | << "Type(\"" << getType() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1117 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1118 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1119 | << "Global(" << Global << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1120 | } |
| 1121 | #endif |
| 1122 | |
| 1123 | //===----------------------------------------------------------------------===// |
| 1124 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1125 | SubprogramDesc::SubprogramDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1126 | : GlobalDesc(DW_TAG_subprogram) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1127 | {} |
| 1128 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1129 | // Implement isa/cast/dyncast. |
| 1130 | bool SubprogramDesc::classof(const DebugInfoDesc *D) { |
| 1131 | return D->getTag() == DW_TAG_subprogram; |
| 1132 | } |
| 1133 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1134 | /// ApplyToFields - Target the visitor to the fields of the |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1135 | /// SubprogramDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1136 | void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1137 | GlobalDesc::ApplyToFields(Visitor); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1140 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1141 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1142 | const char *SubprogramDesc::getDescString() const { |
| 1143 | return "llvm.dbg.subprogram"; |
| 1144 | } |
| 1145 | |
| 1146 | /// getTypeString - Return a string used to label this descriptors type. |
| 1147 | /// |
| 1148 | const char *SubprogramDesc::getTypeString() const { |
| 1149 | return "llvm.dbg.subprogram.type"; |
| 1150 | } |
| 1151 | |
| 1152 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1153 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1154 | const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1155 | const char *SubprogramDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1156 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1159 | #ifndef NDEBUG |
| 1160 | void SubprogramDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1161 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1162 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1163 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1164 | << "Anchor(" << getAnchor() << "), " |
| 1165 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | e2a78f2 | 2006-07-11 15:58:09 +0000 | [diff] [blame] | 1166 | << "DisplayName(\"" << getDisplayName() << "\"), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1167 | << "File(" << getFile() << ")," |
| 1168 | << "Line(" << getLine() << ")," |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1169 | << "Type(\"" << getType() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1170 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1171 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1172 | } |
| 1173 | #endif |
| 1174 | |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 1175 | //===----------------------------------------------------------------------===// |
| 1176 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1177 | BlockDesc::BlockDesc() |
| 1178 | : DebugInfoDesc(DW_TAG_lexical_block) |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1179 | , Context(NULL) |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1180 | {} |
| 1181 | |
| 1182 | // Implement isa/cast/dyncast. |
| 1183 | bool BlockDesc::classof(const DebugInfoDesc *D) { |
| 1184 | return D->getTag() == DW_TAG_lexical_block; |
| 1185 | } |
| 1186 | |
| 1187 | /// ApplyToFields - Target the visitor to the fields of the BlockDesc. |
| 1188 | /// |
| 1189 | void BlockDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1190 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1191 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1192 | Visitor->Apply(Context); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /// getDescString - Return a string used to compose global names and labels. |
| 1196 | /// |
| 1197 | const char *BlockDesc::getDescString() const { |
| 1198 | return "llvm.dbg.block"; |
| 1199 | } |
| 1200 | |
| 1201 | /// getTypeString - Return a string used to label this descriptors type. |
| 1202 | /// |
| 1203 | const char *BlockDesc::getTypeString() const { |
| 1204 | return "llvm.dbg.block.type"; |
| 1205 | } |
| 1206 | |
| 1207 | #ifndef NDEBUG |
| 1208 | void BlockDesc::dump() { |
| 1209 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1210 | << "Version(" << getVersion() << "), " |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1211 | << "Tag(" << getTag() << ")," |
| 1212 | << "Context(" << Context << ")\n"; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1213 | } |
| 1214 | #endif |
| 1215 | |
| 1216 | //===----------------------------------------------------------------------===// |
| 1217 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1218 | DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1219 | return Deserialize(getGlobalVariable(V)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1220 | } |
| 1221 | DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1222 | // Handle NULL. |
| 1223 | if (!GV) return NULL; |
| 1224 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1225 | // Check to see if it has been already deserialized. |
| 1226 | DebugInfoDesc *&Slot = GlobalDescs[GV]; |
| 1227 | if (Slot) return Slot; |
| 1228 | |
| 1229 | // Get the Tag from the global. |
| 1230 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
| 1231 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1232 | // Create an empty instance of the correct sort. |
| 1233 | Slot = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1234 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1235 | // If not a user defined descriptor. |
| 1236 | if (Slot) { |
| 1237 | // Deserialize the fields. |
| 1238 | DIDeserializeVisitor DRAM(*this, GV); |
| 1239 | DRAM.ApplyToFields(Slot); |
| 1240 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1241 | |
| 1242 | return Slot; |
| 1243 | } |
| 1244 | |
| 1245 | //===----------------------------------------------------------------------===// |
| 1246 | |
| 1247 | /// getStrPtrType - Return a "sbyte *" type. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1248 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1249 | const PointerType *DISerializer::getStrPtrType() { |
| 1250 | // If not already defined. |
| 1251 | if (!StrPtrTy) { |
| 1252 | // Construct the pointer to signed bytes. |
| 1253 | StrPtrTy = PointerType::get(Type::SByteTy); |
| 1254 | } |
| 1255 | |
| 1256 | return StrPtrTy; |
| 1257 | } |
| 1258 | |
| 1259 | /// getEmptyStructPtrType - Return a "{ }*" type. |
| 1260 | /// |
| 1261 | const PointerType *DISerializer::getEmptyStructPtrType() { |
| 1262 | // If not already defined. |
| 1263 | if (!EmptyStructPtrTy) { |
| 1264 | // Construct the empty structure type. |
| 1265 | const StructType *EmptyStructTy = |
| 1266 | StructType::get(std::vector<const Type*>()); |
| 1267 | // Construct the pointer to empty structure type. |
| 1268 | EmptyStructPtrTy = PointerType::get(EmptyStructTy); |
| 1269 | } |
| 1270 | |
| 1271 | return EmptyStructPtrTy; |
| 1272 | } |
| 1273 | |
| 1274 | /// getTagType - Return the type describing the specified descriptor (via tag.) |
| 1275 | /// |
| 1276 | const StructType *DISerializer::getTagType(DebugInfoDesc *DD) { |
| 1277 | // Attempt to get the previously defined type. |
| 1278 | StructType *&Ty = TagTypes[DD->getTag()]; |
| 1279 | |
| 1280 | // If not already defined. |
| 1281 | if (!Ty) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1282 | // Set up fields vector. |
| 1283 | std::vector<const Type*> Fields; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1284 | // Get types of fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1285 | DIGetTypesVisitor GTAM(*this, Fields); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1286 | GTAM.ApplyToFields(DD); |
| 1287 | |
| 1288 | // Construct structured type. |
| 1289 | Ty = StructType::get(Fields); |
| 1290 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1291 | // Register type name with module. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1292 | M->addTypeName(DD->getTypeString(), Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | return Ty; |
| 1296 | } |
| 1297 | |
| 1298 | /// getString - Construct the string as constant string global. |
| 1299 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1300 | Constant *DISerializer::getString(const std::string &String) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1301 | // Check string cache for previous edition. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1302 | Constant *&Slot = StringCache[String]; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1303 | // Return Constant if previously defined. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1304 | if (Slot) return Slot; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1305 | // If empty string then use a sbyte* null instead. |
| 1306 | if (String.empty()) { |
| 1307 | Slot = ConstantPointerNull::get(getStrPtrType()); |
| 1308 | } else { |
| 1309 | // Construct string as an llvm constant. |
| 1310 | Constant *ConstStr = ConstantArray::get(String); |
| 1311 | // Otherwise create and return a new string global. |
| 1312 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 1313 | GlobalVariable::InternalLinkage, |
| 1314 | ConstStr, "str", M); |
| 1315 | StrGV->setSection("llvm.metadata"); |
| 1316 | // Convert to generic string pointer. |
| 1317 | Slot = ConstantExpr::getCast(StrGV, getStrPtrType()); |
| 1318 | } |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1319 | return Slot; |
| 1320 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /// Serialize - Recursively cast the specified descriptor into a GlobalVariable |
| 1324 | /// so that it can be serialized to a .bc or .ll file. |
| 1325 | GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) { |
| 1326 | // Check if the DebugInfoDesc is already in the map. |
| 1327 | GlobalVariable *&Slot = DescGlobals[DD]; |
| 1328 | |
| 1329 | // See if DebugInfoDesc exists, if so return prior GlobalVariable. |
| 1330 | if (Slot) return Slot; |
| 1331 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1332 | // Get the type associated with the Tag. |
| 1333 | const StructType *Ty = getTagType(DD); |
| 1334 | |
| 1335 | // Create the GlobalVariable early to prevent infinite recursion. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1336 | GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(), |
| 1337 | NULL, DD->getDescString(), M); |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 1338 | GV->setSection("llvm.metadata"); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1339 | |
| 1340 | // Insert new GlobalVariable in DescGlobals map. |
| 1341 | Slot = GV; |
| 1342 | |
| 1343 | // Set up elements vector |
| 1344 | std::vector<Constant*> Elements; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1345 | // Add fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1346 | DISerializeVisitor SRAM(*this, Elements); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1347 | SRAM.ApplyToFields(DD); |
| 1348 | |
| 1349 | // Set the globals initializer. |
| 1350 | GV->setInitializer(ConstantStruct::get(Ty, Elements)); |
| 1351 | |
| 1352 | return GV; |
| 1353 | } |
| 1354 | |
| 1355 | //===----------------------------------------------------------------------===// |
| 1356 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1357 | /// Verify - Return true if the GlobalVariable appears to be a valid |
| 1358 | /// serialization of a DebugInfoDesc. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1359 | bool DIVerifier::Verify(Value *V) { |
Jim Laskey | aaa80eb | 2006-03-28 01:30:18 +0000 | [diff] [blame] | 1360 | return !V || Verify(getGlobalVariable(V)); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1361 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1362 | bool DIVerifier::Verify(GlobalVariable *GV) { |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1363 | // NULLs are valid. |
| 1364 | if (!GV) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1365 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1366 | // Check prior validity. |
| 1367 | unsigned &ValiditySlot = Validity[GV]; |
| 1368 | |
| 1369 | // If visited before then use old state. |
| 1370 | if (ValiditySlot) return ValiditySlot == Valid; |
| 1371 | |
| 1372 | // Assume validity for the time being (recursion.) |
| 1373 | ValiditySlot = Valid; |
Jim Laskey | a8299de | 2006-03-27 01:51:47 +0000 | [diff] [blame] | 1374 | |
| 1375 | // Make sure the global is internal or link once (anchor.) |
| 1376 | if (GV->getLinkage() != GlobalValue::InternalLinkage && |
| 1377 | GV->getLinkage() != GlobalValue::LinkOnceLinkage) { |
| 1378 | ValiditySlot = Invalid; |
| 1379 | return false; |
| 1380 | } |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1381 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1382 | // Get the Tag |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1383 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1384 | |
| 1385 | // Check for user defined descriptors. |
| 1386 | if (Tag == DW_TAG_invalid) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1387 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1388 | // Construct an empty DebugInfoDesc. |
| 1389 | DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1390 | |
| 1391 | // Allow for user defined descriptors. |
| 1392 | if (!DD) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1393 | |
| 1394 | // Get the initializer constant. |
| 1395 | ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer()); |
| 1396 | |
| 1397 | // Get the operand count. |
| 1398 | unsigned N = CI->getNumOperands(); |
| 1399 | |
| 1400 | // Get the field count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1401 | unsigned &CountSlot = Counts[Tag]; |
| 1402 | if (!CountSlot) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1403 | // Check the operand count to the field count |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1404 | DICountVisitor CTAM; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1405 | CTAM.ApplyToFields(DD); |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1406 | CountSlot = CTAM.getCount(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1409 | // Field count must be at most equal operand count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1410 | if (CountSlot > N) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1411 | delete DD; |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1412 | ValiditySlot = Invalid; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1413 | return false; |
| 1414 | } |
| 1415 | |
| 1416 | // Check each field for valid type. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1417 | DIVerifyVisitor VRAM(*this, GV); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1418 | VRAM.ApplyToFields(DD); |
| 1419 | |
| 1420 | // Release empty DebugInfoDesc. |
| 1421 | delete DD; |
| 1422 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1423 | // If fields are not valid. |
| 1424 | if (!VRAM.isValid()) { |
| 1425 | ValiditySlot = Invalid; |
| 1426 | return false; |
| 1427 | } |
| 1428 | |
| 1429 | return true; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | //===----------------------------------------------------------------------===// |
| 1433 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1434 | DebugScope::~DebugScope() { |
| 1435 | for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i]; |
| 1436 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j]; |
| 1437 | } |
| 1438 | |
| 1439 | //===----------------------------------------------------------------------===// |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1440 | |
| 1441 | MachineDebugInfo::MachineDebugInfo() |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1442 | : DR() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1443 | , VR() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1444 | , CompileUnits() |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1445 | , Directories() |
| 1446 | , SourceFiles() |
| 1447 | , Lines() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1448 | , LabelID(0) |
| 1449 | , ScopeMap() |
| 1450 | , RootScope(NULL) |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1451 | , FrameMoves() |
| 1452 | {} |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1453 | MachineDebugInfo::~MachineDebugInfo() { |
| 1454 | |
| 1455 | } |
| 1456 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1457 | /// doInitialization - Initialize the debug state for a new module. |
| 1458 | /// |
| 1459 | bool MachineDebugInfo::doInitialization() { |
| 1460 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1461 | } |
| 1462 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1463 | /// doFinalization - Tear down the debug state after completion of a module. |
| 1464 | /// |
| 1465 | bool MachineDebugInfo::doFinalization() { |
| 1466 | return false; |
| 1467 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1468 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1469 | /// BeginFunction - Begin gathering function debug information. |
| 1470 | /// |
| 1471 | void MachineDebugInfo::BeginFunction(MachineFunction *MF) { |
| 1472 | // Coming soon. |
| 1473 | } |
| 1474 | |
| 1475 | /// MachineDebugInfo::EndFunction - Discard function debug information. |
| 1476 | /// |
| 1477 | void MachineDebugInfo::EndFunction() { |
| 1478 | // Clean up scope information. |
| 1479 | if (RootScope) { |
| 1480 | delete RootScope; |
| 1481 | ScopeMap.clear(); |
| 1482 | RootScope = NULL; |
| 1483 | } |
| 1484 | |
| 1485 | // Clean up frame info. |
| 1486 | for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i]; |
| 1487 | FrameMoves.clear(); |
| 1488 | } |
| 1489 | |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1490 | /// getDescFor - Convert a Value to a debug information descriptor. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1491 | /// |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1492 | // FIXME - use new Value type when available. |
| 1493 | DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1494 | return DR.Deserialize(V); |
| 1495 | } |
| 1496 | |
| 1497 | /// Verify - Verify that a Value is debug information descriptor. |
| 1498 | /// |
| 1499 | bool MachineDebugInfo::Verify(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1500 | return VR.Verify(V); |
| 1501 | } |
| 1502 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1503 | /// AnalyzeModule - Scan the module for global debug information. |
| 1504 | /// |
| 1505 | void MachineDebugInfo::AnalyzeModule(Module &M) { |
| 1506 | SetupCompileUnits(M); |
| 1507 | } |
| 1508 | |
| 1509 | /// SetupCompileUnits - Set up the unique vector of compile units. |
| 1510 | /// |
| 1511 | void MachineDebugInfo::SetupCompileUnits(Module &M) { |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1512 | std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1513 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1514 | for (unsigned i = 0, N = CU.size(); i < N; i++) { |
| 1515 | CompileUnits.insert(CU[i]); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1516 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1519 | /// getCompileUnits - Return a vector of debug compile units. |
| 1520 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1521 | const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{ |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1522 | return CompileUnits; |
| 1523 | } |
| 1524 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1525 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 1526 | /// named GlobalVariable. |
| 1527 | std::vector<GlobalVariable*> |
| 1528 | MachineDebugInfo::getGlobalVariablesUsing(Module &M, |
| 1529 | const std::string &RootName) { |
| 1530 | return ::getGlobalVariablesUsing(M, RootName); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1531 | } |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1532 | |
| 1533 | /// RecordLabel - Records location information and associates it with a |
| 1534 | /// debug label. Returns a unique label ID used to generate a label and |
| 1535 | /// provide correspondence to the source line list. |
| 1536 | unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column, |
| 1537 | unsigned Source) { |
| 1538 | unsigned ID = NextLabelID(); |
| 1539 | Lines.push_back(new SourceLineInfo(Line, Column, Source, ID)); |
| 1540 | return ID; |
| 1541 | } |
| 1542 | |
| 1543 | /// RecordSource - Register a source file with debug info. Returns an source |
| 1544 | /// ID. |
| 1545 | unsigned MachineDebugInfo::RecordSource(const std::string &Directory, |
| 1546 | const std::string &Source) { |
| 1547 | unsigned DirectoryID = Directories.insert(Directory); |
| 1548 | return SourceFiles.insert(SourceFileInfo(DirectoryID, Source)); |
| 1549 | } |
| 1550 | unsigned MachineDebugInfo::RecordSource(const CompileUnitDesc *CompileUnit) { |
| 1551 | return RecordSource(CompileUnit->getDirectory(), |
| 1552 | CompileUnit->getFileName()); |
| 1553 | } |
| 1554 | |
| 1555 | /// RecordRegionStart - Indicate the start of a region. |
| 1556 | /// |
| 1557 | unsigned MachineDebugInfo::RecordRegionStart(Value *V) { |
| 1558 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1559 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1560 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1561 | unsigned ID = NextLabelID(); |
| 1562 | if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID); |
| 1563 | return ID; |
| 1564 | } |
| 1565 | |
| 1566 | /// RecordRegionEnd - Indicate the end of a region. |
| 1567 | /// |
| 1568 | unsigned MachineDebugInfo::RecordRegionEnd(Value *V) { |
| 1569 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1570 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1571 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1572 | unsigned ID = NextLabelID(); |
| 1573 | Scope->setEndLabelID(ID); |
| 1574 | return ID; |
| 1575 | } |
| 1576 | |
| 1577 | /// RecordVariable - Indicate the declaration of a local variable. |
| 1578 | /// |
| 1579 | void MachineDebugInfo::RecordVariable(Value *V, unsigned FrameIndex) { |
| 1580 | VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(V)); |
| 1581 | DebugScope *Scope = getOrCreateScope(VD->getContext()); |
| 1582 | DebugVariable *DV = new DebugVariable(VD, FrameIndex); |
| 1583 | Scope->AddVariable(DV); |
| 1584 | } |
| 1585 | |
| 1586 | /// getOrCreateScope - Returns the scope associated with the given descriptor. |
| 1587 | /// |
| 1588 | DebugScope *MachineDebugInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) { |
| 1589 | DebugScope *&Slot = ScopeMap[ScopeDesc]; |
| 1590 | if (!Slot) { |
| 1591 | // FIXME - breaks down when the context is an inlined function. |
| 1592 | DebugInfoDesc *ParentDesc = NULL; |
| 1593 | if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) { |
| 1594 | ParentDesc = Block->getContext(); |
| 1595 | } |
| 1596 | DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL; |
| 1597 | Slot = new DebugScope(Parent, ScopeDesc); |
| 1598 | if (Parent) { |
| 1599 | Parent->AddScope(Slot); |
| 1600 | } else if (RootScope) { |
| 1601 | // FIXME - Add inlined function scopes to the root so we can delete |
| 1602 | // them later. Long term, handle inlined functions properly. |
| 1603 | RootScope->AddScope(Slot); |
| 1604 | } else { |
| 1605 | // First function is top level function. |
| 1606 | RootScope = Slot; |
| 1607 | } |
| 1608 | } |
| 1609 | return Slot; |
| 1610 | } |
| 1611 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1612 | |