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