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