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) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 265 | Elements.push_back(ConstantSInt::get(Type::LongTy, Field)); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 266 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 267 | virtual void Apply(uint64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 268 | Elements.push_back(ConstantUInt::get(Type::ULongTy, Field)); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 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) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 348 | Fields.push_back(Type::LongTy); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 349 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 350 | virtual void Apply(uint64_t &Field) { |
Jim Laskey | 014f98c | 2006-06-14 11:35:03 +0000 | [diff] [blame] | 351 | Fields.push_back(Type::ULongTy); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 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 | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 458 | /// TagFromGlobal - Returns the tag number from a debug info descriptor |
| 459 | /// GlobalVariable. Return DIIValid if operand is not an unsigned int. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 460 | unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) { |
| 461 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 462 | return C ? ((unsigned)C->getValue() & ~LLVMDebugVersionMask) : |
| 463 | (unsigned)DW_TAG_invalid; |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /// VersionFromGlobal - Returns the version number from a debug info |
| 467 | /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned |
| 468 | /// int. |
| 469 | unsigned DebugInfoDesc::VersionFromGlobal(GlobalVariable *GV) { |
| 470 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 471 | return C ? ((unsigned)C->getValue() & LLVMDebugVersionMask) : |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 472 | (unsigned)DW_TAG_invalid; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /// DescFactory - Create an instance of debug info descriptor based on Tag. |
| 476 | /// Return NULL if not a recognized Tag. |
| 477 | DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { |
| 478 | switch (Tag) { |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 479 | case DW_TAG_anchor: return new AnchorDesc(); |
| 480 | case DW_TAG_compile_unit: return new CompileUnitDesc(); |
| 481 | case DW_TAG_variable: return new GlobalVariableDesc(); |
| 482 | case DW_TAG_subprogram: return new SubprogramDesc(); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 483 | case DW_TAG_lexical_block: return new BlockDesc(); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 484 | case DW_TAG_base_type: return new BasicTypeDesc(); |
| 485 | case DW_TAG_typedef: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 486 | case DW_TAG_pointer_type: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 487 | case DW_TAG_reference_type: |
| 488 | case DW_TAG_const_type: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 489 | case DW_TAG_volatile_type: |
| 490 | case DW_TAG_restrict_type: |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 491 | case DW_TAG_member: return new DerivedTypeDesc(Tag); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 492 | case DW_TAG_array_type: |
| 493 | case DW_TAG_structure_type: |
| 494 | case DW_TAG_union_type: |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 495 | case DW_TAG_enumeration_type: |
| 496 | case DW_TAG_vector_type: return new CompositeTypeDesc(Tag); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 497 | case DW_TAG_subrange_type: return new SubrangeDesc(); |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 498 | case DW_TAG_enumerator: return new EnumeratorDesc(); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 499 | case DW_TAG_return_variable: |
| 500 | case DW_TAG_arg_variable: |
| 501 | case DW_TAG_auto_variable: return new VariableDesc(Tag); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 502 | default: break; |
| 503 | } |
| 504 | return NULL; |
| 505 | } |
| 506 | |
| 507 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 508 | /// |
| 509 | GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const { |
| 510 | return GlobalValue::InternalLinkage; |
| 511 | } |
| 512 | |
| 513 | /// ApplyToFields - Target the vistor to the fields of the descriptor. |
| 514 | /// |
| 515 | void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) { |
| 516 | Visitor->Apply(Tag); |
| 517 | } |
| 518 | |
| 519 | //===----------------------------------------------------------------------===// |
| 520 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 521 | AnchorDesc::AnchorDesc() |
| 522 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 523 | , AnchorTag(0) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 524 | {} |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 525 | AnchorDesc::AnchorDesc(AnchoredDesc *D) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 526 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 527 | , AnchorTag(D->getTag()) |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 528 | {} |
| 529 | |
| 530 | // Implement isa/cast/dyncast. |
| 531 | bool AnchorDesc::classof(const DebugInfoDesc *D) { |
| 532 | return D->getTag() == DW_TAG_anchor; |
| 533 | } |
| 534 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 535 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 536 | /// |
| 537 | GlobalValue::LinkageTypes AnchorDesc::getLinkage() const { |
| 538 | return GlobalValue::LinkOnceLinkage; |
| 539 | } |
| 540 | |
| 541 | /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc. |
| 542 | /// |
| 543 | void AnchorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 544 | DebugInfoDesc::ApplyToFields(Visitor); |
| 545 | |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 546 | Visitor->Apply(AnchorTag); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 547 | } |
| 548 | |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 549 | /// getDescString - Return a string used to compose global names and labels. A |
| 550 | /// 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] | 551 | /// 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] | 552 | /// to the list of names left external in the internalizer. |
| 553 | /// ExternalNames.insert("llvm.dbg.compile_units"); |
| 554 | /// ExternalNames.insert("llvm.dbg.global_variables"); |
| 555 | /// ExternalNames.insert("llvm.dbg.subprograms"); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 556 | const char *AnchorDesc::getDescString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 557 | switch (AnchorTag) { |
| 558 | case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString; |
| 559 | case DW_TAG_variable: return GlobalVariableDesc::AnchorString; |
| 560 | case DW_TAG_subprogram: return SubprogramDesc::AnchorString; |
| 561 | default: break; |
| 562 | } |
| 563 | |
| 564 | assert(0 && "Tag does not have a case for anchor string"); |
| 565 | return ""; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /// getTypeString - Return a string used to label this descriptors type. |
| 569 | /// |
| 570 | const char *AnchorDesc::getTypeString() const { |
| 571 | return "llvm.dbg.anchor.type"; |
| 572 | } |
| 573 | |
| 574 | #ifndef NDEBUG |
| 575 | void AnchorDesc::dump() { |
| 576 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 577 | << "Version(" << getVersion() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 578 | << "Tag(" << getTag() << "), " |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 579 | << "AnchorTag(" << AnchorTag << ")\n"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 580 | } |
| 581 | #endif |
| 582 | |
| 583 | //===----------------------------------------------------------------------===// |
| 584 | |
| 585 | AnchoredDesc::AnchoredDesc(unsigned T) |
| 586 | : DebugInfoDesc(T) |
| 587 | , Anchor(NULL) |
| 588 | {} |
| 589 | |
| 590 | /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc. |
| 591 | /// |
| 592 | void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) { |
| 593 | DebugInfoDesc::ApplyToFields(Visitor); |
| 594 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 595 | Visitor->Apply(Anchor); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | //===----------------------------------------------------------------------===// |
| 599 | |
| 600 | CompileUnitDesc::CompileUnitDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 601 | : AnchoredDesc(DW_TAG_compile_unit) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 602 | , Language(0) |
| 603 | , FileName("") |
| 604 | , Directory("") |
| 605 | , Producer("") |
| 606 | {} |
| 607 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 608 | // Implement isa/cast/dyncast. |
| 609 | bool CompileUnitDesc::classof(const DebugInfoDesc *D) { |
| 610 | return D->getTag() == DW_TAG_compile_unit; |
| 611 | } |
| 612 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 613 | /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. |
| 614 | /// |
| 615 | void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 616 | AnchoredDesc::ApplyToFields(Visitor); |
Jim Laskey | ca0dc56 | 2006-06-19 12:54:15 +0000 | [diff] [blame] | 617 | |
| 618 | // Handle cases out of sync with compiler. |
| 619 | if (getVersion() == 0) { |
| 620 | unsigned DebugVersion; |
| 621 | Visitor->Apply(DebugVersion); |
| 622 | } |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 623 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 624 | Visitor->Apply(Language); |
| 625 | Visitor->Apply(FileName); |
| 626 | Visitor->Apply(Directory); |
| 627 | Visitor->Apply(Producer); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 628 | } |
| 629 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 630 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 631 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 632 | const char *CompileUnitDesc::getDescString() const { |
| 633 | return "llvm.dbg.compile_unit"; |
| 634 | } |
| 635 | |
| 636 | /// getTypeString - Return a string used to label this descriptors type. |
| 637 | /// |
| 638 | const char *CompileUnitDesc::getTypeString() const { |
| 639 | return "llvm.dbg.compile_unit.type"; |
| 640 | } |
| 641 | |
| 642 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 643 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 644 | const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 645 | const char *CompileUnitDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 646 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 649 | #ifndef NDEBUG |
| 650 | void CompileUnitDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 651 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 652 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 653 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 654 | << "Anchor(" << getAnchor() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 655 | << "Language(" << Language << "), " |
| 656 | << "FileName(\"" << FileName << "\"), " |
| 657 | << "Directory(\"" << Directory << "\"), " |
| 658 | << "Producer(\"" << Producer << "\")\n"; |
| 659 | } |
| 660 | #endif |
| 661 | |
| 662 | //===----------------------------------------------------------------------===// |
| 663 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 664 | TypeDesc::TypeDesc(unsigned T) |
| 665 | : DebugInfoDesc(T) |
| 666 | , Context(NULL) |
| 667 | , Name("") |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 668 | , File(NULL) |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 669 | , Line(0) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 670 | , Size(0) |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 671 | , Align(0) |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 672 | , Offset(0) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 673 | {} |
| 674 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 675 | /// ApplyToFields - Target the visitor to the fields of the TypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 676 | /// |
| 677 | void TypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 678 | DebugInfoDesc::ApplyToFields(Visitor); |
| 679 | |
| 680 | Visitor->Apply(Context); |
| 681 | Visitor->Apply(Name); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 682 | Visitor->Apply(File); |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 683 | Visitor->Apply(Line); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 684 | Visitor->Apply(Size); |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 685 | Visitor->Apply(Align); |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 686 | Visitor->Apply(Offset); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | /// getDescString - Return a string used to compose global names and labels. |
| 690 | /// |
| 691 | const char *TypeDesc::getDescString() const { |
| 692 | return "llvm.dbg.type"; |
| 693 | } |
| 694 | |
| 695 | /// getTypeString - Return a string used to label this descriptor's type. |
| 696 | /// |
| 697 | const char *TypeDesc::getTypeString() const { |
| 698 | return "llvm.dbg.type.type"; |
| 699 | } |
| 700 | |
| 701 | #ifndef NDEBUG |
| 702 | void TypeDesc::dump() { |
| 703 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 704 | << "Version(" << getVersion() << "), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 705 | << "Tag(" << getTag() << "), " |
| 706 | << "Context(" << Context << "), " |
| 707 | << "Name(\"" << Name << "\"), " |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 708 | << "File(" << File << "), " |
| 709 | << "Line(" << Line << "), " |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 710 | << "Size(" << Size << "), " |
Chris Lattner | 2695de4 | 2006-03-09 17:48:46 +0000 | [diff] [blame] | 711 | << "Align(" << Align << "), " |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 712 | << "Offset(" << Offset << ")\n"; |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 713 | } |
| 714 | #endif |
| 715 | |
| 716 | //===----------------------------------------------------------------------===// |
| 717 | |
| 718 | BasicTypeDesc::BasicTypeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 719 | : TypeDesc(DW_TAG_base_type) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 720 | , Encoding(0) |
| 721 | {} |
| 722 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 723 | // Implement isa/cast/dyncast. |
| 724 | bool BasicTypeDesc::classof(const DebugInfoDesc *D) { |
| 725 | return D->getTag() == DW_TAG_base_type; |
| 726 | } |
| 727 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 728 | /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 729 | /// |
| 730 | void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 731 | TypeDesc::ApplyToFields(Visitor); |
| 732 | |
| 733 | Visitor->Apply(Encoding); |
| 734 | } |
| 735 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 736 | /// getDescString - Return a string used to compose global names and labels. |
| 737 | /// |
| 738 | const char *BasicTypeDesc::getDescString() const { |
| 739 | return "llvm.dbg.basictype"; |
| 740 | } |
| 741 | |
| 742 | /// getTypeString - Return a string used to label this descriptor's type. |
| 743 | /// |
| 744 | const char *BasicTypeDesc::getTypeString() const { |
| 745 | return "llvm.dbg.basictype.type"; |
| 746 | } |
| 747 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 748 | #ifndef NDEBUG |
| 749 | void BasicTypeDesc::dump() { |
| 750 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 751 | << "Version(" << getVersion() << "), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 752 | << "Tag(" << getTag() << "), " |
| 753 | << "Context(" << getContext() << "), " |
| 754 | << "Name(\"" << getName() << "\"), " |
| 755 | << "Size(" << getSize() << "), " |
| 756 | << "Encoding(" << Encoding << ")\n"; |
| 757 | } |
| 758 | #endif |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 759 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 760 | //===----------------------------------------------------------------------===// |
| 761 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 762 | DerivedTypeDesc::DerivedTypeDesc(unsigned T) |
| 763 | : TypeDesc(T) |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 764 | , FromType(NULL) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 765 | {} |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 766 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 767 | // Implement isa/cast/dyncast. |
| 768 | bool DerivedTypeDesc::classof(const DebugInfoDesc *D) { |
| 769 | unsigned T = D->getTag(); |
| 770 | switch (T) { |
| 771 | case DW_TAG_typedef: |
| 772 | case DW_TAG_pointer_type: |
| 773 | case DW_TAG_reference_type: |
| 774 | case DW_TAG_const_type: |
| 775 | case DW_TAG_volatile_type: |
| 776 | case DW_TAG_restrict_type: |
Jim Laskey | f01e547 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 777 | case DW_TAG_member: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 778 | return true; |
| 779 | default: break; |
| 780 | } |
| 781 | return false; |
| 782 | } |
| 783 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 784 | /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 785 | /// |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 786 | void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 787 | TypeDesc::ApplyToFields(Visitor); |
| 788 | |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 789 | Visitor->Apply(FromType); |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 792 | /// getDescString - Return a string used to compose global names and labels. |
| 793 | /// |
| 794 | const char *DerivedTypeDesc::getDescString() const { |
| 795 | return "llvm.dbg.derivedtype"; |
| 796 | } |
| 797 | |
| 798 | /// getTypeString - Return a string used to label this descriptor's type. |
| 799 | /// |
| 800 | const char *DerivedTypeDesc::getTypeString() const { |
| 801 | return "llvm.dbg.derivedtype.type"; |
| 802 | } |
| 803 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 804 | #ifndef NDEBUG |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 805 | void DerivedTypeDesc::dump() { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 806 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 807 | << "Version(" << getVersion() << "), " |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 808 | << "Tag(" << getTag() << "), " |
| 809 | << "Context(" << getContext() << "), " |
| 810 | << "Name(\"" << getName() << "\"), " |
| 811 | << "Size(" << getSize() << "), " |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 812 | << "File(" << getFile() << "), " |
| 813 | << "Line(" << getLine() << "), " |
| 814 | << "FromType(" << FromType << ")\n"; |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 815 | } |
| 816 | #endif |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 817 | |
| 818 | //===----------------------------------------------------------------------===// |
| 819 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 820 | CompositeTypeDesc::CompositeTypeDesc(unsigned T) |
| 821 | : DerivedTypeDesc(T) |
| 822 | , Elements() |
| 823 | {} |
| 824 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 825 | // Implement isa/cast/dyncast. |
| 826 | bool CompositeTypeDesc::classof(const DebugInfoDesc *D) { |
| 827 | unsigned T = D->getTag(); |
| 828 | switch (T) { |
| 829 | case DW_TAG_array_type: |
| 830 | case DW_TAG_structure_type: |
| 831 | case DW_TAG_union_type: |
| 832 | case DW_TAG_enumeration_type: |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 833 | case DW_TAG_vector_type: |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 834 | return true; |
| 835 | default: break; |
| 836 | } |
| 837 | return false; |
| 838 | } |
| 839 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 840 | /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc. |
| 841 | /// |
| 842 | void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 843 | DerivedTypeDesc::ApplyToFields(Visitor); |
| 844 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 845 | Visitor->Apply(Elements); |
| 846 | } |
| 847 | |
| 848 | /// getDescString - Return a string used to compose global names and labels. |
| 849 | /// |
| 850 | const char *CompositeTypeDesc::getDescString() const { |
| 851 | return "llvm.dbg.compositetype"; |
| 852 | } |
| 853 | |
| 854 | /// getTypeString - Return a string used to label this descriptor's type. |
| 855 | /// |
| 856 | const char *CompositeTypeDesc::getTypeString() const { |
| 857 | return "llvm.dbg.compositetype.type"; |
| 858 | } |
| 859 | |
| 860 | #ifndef NDEBUG |
| 861 | void CompositeTypeDesc::dump() { |
| 862 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 863 | << "Version(" << getVersion() << "), " |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 864 | << "Tag(" << getTag() << "), " |
| 865 | << "Context(" << getContext() << "), " |
| 866 | << "Name(\"" << getName() << "\"), " |
| 867 | << "Size(" << getSize() << "), " |
| 868 | << "File(" << getFile() << "), " |
| 869 | << "Line(" << getLine() << "), " |
| 870 | << "FromType(" << getFromType() << "), " |
| 871 | << "Elements.size(" << Elements.size() << ")\n"; |
| 872 | } |
| 873 | #endif |
| 874 | |
| 875 | //===----------------------------------------------------------------------===// |
| 876 | |
| 877 | SubrangeDesc::SubrangeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 878 | : DebugInfoDesc(DW_TAG_subrange_type) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 879 | , Lo(0) |
| 880 | , Hi(0) |
| 881 | {} |
| 882 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 883 | // Implement isa/cast/dyncast. |
| 884 | bool SubrangeDesc::classof(const DebugInfoDesc *D) { |
| 885 | return D->getTag() == DW_TAG_subrange_type; |
| 886 | } |
| 887 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 888 | /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc. |
| 889 | /// |
| 890 | void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 891 | DebugInfoDesc::ApplyToFields(Visitor); |
| 892 | |
| 893 | Visitor->Apply(Lo); |
| 894 | Visitor->Apply(Hi); |
| 895 | } |
| 896 | |
| 897 | /// getDescString - Return a string used to compose global names and labels. |
| 898 | /// |
| 899 | const char *SubrangeDesc::getDescString() const { |
| 900 | return "llvm.dbg.subrange"; |
| 901 | } |
| 902 | |
| 903 | /// getTypeString - Return a string used to label this descriptor's type. |
| 904 | /// |
| 905 | const char *SubrangeDesc::getTypeString() const { |
| 906 | return "llvm.dbg.subrange.type"; |
| 907 | } |
| 908 | |
| 909 | #ifndef NDEBUG |
| 910 | void SubrangeDesc::dump() { |
| 911 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 912 | << "Version(" << getVersion() << "), " |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 913 | << "Tag(" << getTag() << "), " |
| 914 | << "Lo(" << Lo << "), " |
| 915 | << "Hi(" << Hi << ")\n"; |
| 916 | } |
| 917 | #endif |
| 918 | |
| 919 | //===----------------------------------------------------------------------===// |
| 920 | |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 921 | EnumeratorDesc::EnumeratorDesc() |
| 922 | : DebugInfoDesc(DW_TAG_enumerator) |
| 923 | , Name("") |
| 924 | , Value(0) |
| 925 | {} |
| 926 | |
| 927 | // Implement isa/cast/dyncast. |
| 928 | bool EnumeratorDesc::classof(const DebugInfoDesc *D) { |
| 929 | return D->getTag() == DW_TAG_enumerator; |
| 930 | } |
| 931 | |
| 932 | /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc. |
| 933 | /// |
| 934 | void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 935 | DebugInfoDesc::ApplyToFields(Visitor); |
| 936 | |
| 937 | Visitor->Apply(Name); |
| 938 | Visitor->Apply(Value); |
| 939 | } |
| 940 | |
| 941 | /// getDescString - Return a string used to compose global names and labels. |
| 942 | /// |
| 943 | const char *EnumeratorDesc::getDescString() const { |
| 944 | return "llvm.dbg.enumerator"; |
| 945 | } |
| 946 | |
| 947 | /// getTypeString - Return a string used to label this descriptor's type. |
| 948 | /// |
| 949 | const char *EnumeratorDesc::getTypeString() const { |
| 950 | return "llvm.dbg.enumerator.type"; |
| 951 | } |
| 952 | |
| 953 | #ifndef NDEBUG |
| 954 | void EnumeratorDesc::dump() { |
| 955 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 956 | << "Version(" << getVersion() << "), " |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 957 | << "Tag(" << getTag() << "), " |
| 958 | << "Name(" << Name << "), " |
| 959 | << "Value(" << Value << ")\n"; |
| 960 | } |
| 961 | #endif |
| 962 | |
| 963 | //===----------------------------------------------------------------------===// |
| 964 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 965 | VariableDesc::VariableDesc(unsigned T) |
| 966 | : DebugInfoDesc(T) |
| 967 | , Context(NULL) |
| 968 | , Name("") |
| 969 | , File(NULL) |
| 970 | , Line(0) |
| 971 | , TyDesc(0) |
| 972 | {} |
| 973 | |
| 974 | // Implement isa/cast/dyncast. |
| 975 | bool VariableDesc::classof(const DebugInfoDesc *D) { |
| 976 | unsigned T = D->getTag(); |
| 977 | switch (T) { |
| 978 | case DW_TAG_auto_variable: |
| 979 | case DW_TAG_arg_variable: |
| 980 | case DW_TAG_return_variable: |
| 981 | return true; |
| 982 | default: break; |
| 983 | } |
| 984 | return false; |
| 985 | } |
| 986 | |
| 987 | /// ApplyToFields - Target the visitor to the fields of the VariableDesc. |
| 988 | /// |
| 989 | void VariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 990 | DebugInfoDesc::ApplyToFields(Visitor); |
| 991 | |
| 992 | Visitor->Apply(Context); |
| 993 | Visitor->Apply(Name); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 994 | Visitor->Apply(File); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 995 | Visitor->Apply(Line); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 996 | Visitor->Apply(TyDesc); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /// getDescString - Return a string used to compose global names and labels. |
| 1000 | /// |
| 1001 | const char *VariableDesc::getDescString() const { |
| 1002 | return "llvm.dbg.variable"; |
| 1003 | } |
| 1004 | |
| 1005 | /// getTypeString - Return a string used to label this descriptor's type. |
| 1006 | /// |
| 1007 | const char *VariableDesc::getTypeString() const { |
| 1008 | return "llvm.dbg.variable.type"; |
| 1009 | } |
| 1010 | |
| 1011 | #ifndef NDEBUG |
| 1012 | void VariableDesc::dump() { |
| 1013 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1014 | << "Version(" << getVersion() << "), " |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1015 | << "Tag(" << getTag() << "), " |
| 1016 | << "Context(" << Context << "), " |
| 1017 | << "Name(\"" << Name << "\"), " |
| 1018 | << "File(" << File << "), " |
| 1019 | << "Line(" << Line << "), " |
| 1020 | << "TyDesc(" << TyDesc << ")\n"; |
| 1021 | } |
| 1022 | #endif |
| 1023 | |
| 1024 | //===----------------------------------------------------------------------===// |
| 1025 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1026 | GlobalDesc::GlobalDesc(unsigned T) |
| 1027 | : AnchoredDesc(T) |
| 1028 | , Context(0) |
| 1029 | , Name("") |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1030 | , File(NULL) |
| 1031 | , Line(0) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1032 | , TyDesc(NULL) |
| 1033 | , IsStatic(false) |
| 1034 | , IsDefinition(false) |
| 1035 | {} |
| 1036 | |
| 1037 | /// ApplyToFields - Target the visitor to the fields of the global. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1038 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1039 | void GlobalDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1040 | AnchoredDesc::ApplyToFields(Visitor); |
| 1041 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1042 | Visitor->Apply(Context); |
| 1043 | Visitor->Apply(Name); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1044 | Visitor->Apply(File); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1045 | Visitor->Apply(Line); |
Jim Laskey | 7089f45 | 2006-06-16 13:14:03 +0000 | [diff] [blame] | 1046 | Visitor->Apply(TyDesc); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1047 | Visitor->Apply(IsStatic); |
| 1048 | Visitor->Apply(IsDefinition); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | //===----------------------------------------------------------------------===// |
| 1052 | |
| 1053 | GlobalVariableDesc::GlobalVariableDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1054 | : GlobalDesc(DW_TAG_variable) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1055 | , Global(NULL) |
| 1056 | {} |
| 1057 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1058 | // Implement isa/cast/dyncast. |
| 1059 | bool GlobalVariableDesc::classof(const DebugInfoDesc *D) { |
| 1060 | return D->getTag() == DW_TAG_variable; |
| 1061 | } |
| 1062 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1063 | /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. |
| 1064 | /// |
| 1065 | void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1066 | GlobalDesc::ApplyToFields(Visitor); |
| 1067 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1068 | Visitor->Apply(Global); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1071 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1072 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1073 | const char *GlobalVariableDesc::getDescString() const { |
| 1074 | return "llvm.dbg.global_variable"; |
| 1075 | } |
| 1076 | |
| 1077 | /// getTypeString - Return a string used to label this descriptors type. |
| 1078 | /// |
| 1079 | const char *GlobalVariableDesc::getTypeString() const { |
| 1080 | return "llvm.dbg.global_variable.type"; |
| 1081 | } |
| 1082 | |
| 1083 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1084 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1085 | const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1086 | const char *GlobalVariableDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1087 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1090 | #ifndef NDEBUG |
| 1091 | void GlobalVariableDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1092 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1093 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1094 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1095 | << "Anchor(" << getAnchor() << "), " |
| 1096 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1097 | << "File(" << getFile() << ")," |
| 1098 | << "Line(" << getLine() << ")," |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1099 | << "Type(\"" << getType() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1100 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1101 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1102 | << "Global(" << Global << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1103 | } |
| 1104 | #endif |
| 1105 | |
| 1106 | //===----------------------------------------------------------------------===// |
| 1107 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1108 | SubprogramDesc::SubprogramDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1109 | : GlobalDesc(DW_TAG_subprogram) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1110 | {} |
| 1111 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1112 | // Implement isa/cast/dyncast. |
| 1113 | bool SubprogramDesc::classof(const DebugInfoDesc *D) { |
| 1114 | return D->getTag() == DW_TAG_subprogram; |
| 1115 | } |
| 1116 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1117 | /// ApplyToFields - Target the visitor to the fields of the |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1118 | /// SubprogramDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1119 | void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1120 | GlobalDesc::ApplyToFields(Visitor); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1123 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1124 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1125 | const char *SubprogramDesc::getDescString() const { |
| 1126 | return "llvm.dbg.subprogram"; |
| 1127 | } |
| 1128 | |
| 1129 | /// getTypeString - Return a string used to label this descriptors type. |
| 1130 | /// |
| 1131 | const char *SubprogramDesc::getTypeString() const { |
| 1132 | return "llvm.dbg.subprogram.type"; |
| 1133 | } |
| 1134 | |
| 1135 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1136 | /// |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1137 | const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms"; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1138 | const char *SubprogramDesc::getAnchorString() const { |
Jim Laskey | e8c3e3b | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1139 | return AnchorString; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1142 | #ifndef NDEBUG |
| 1143 | void SubprogramDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1144 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1145 | << "Version(" << getVersion() << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1146 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1147 | << "Anchor(" << getAnchor() << "), " |
| 1148 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1149 | << "File(" << getFile() << ")," |
| 1150 | << "Line(" << getLine() << ")," |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1151 | << "Type(\"" << getType() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1152 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1153 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1154 | } |
| 1155 | #endif |
| 1156 | |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 1157 | //===----------------------------------------------------------------------===// |
| 1158 | |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1159 | BlockDesc::BlockDesc() |
| 1160 | : DebugInfoDesc(DW_TAG_lexical_block) |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1161 | , Context(NULL) |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1162 | {} |
| 1163 | |
| 1164 | // Implement isa/cast/dyncast. |
| 1165 | bool BlockDesc::classof(const DebugInfoDesc *D) { |
| 1166 | return D->getTag() == DW_TAG_lexical_block; |
| 1167 | } |
| 1168 | |
| 1169 | /// ApplyToFields - Target the visitor to the fields of the BlockDesc. |
| 1170 | /// |
| 1171 | void BlockDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1172 | DebugInfoDesc::ApplyToFields(Visitor); |
| 1173 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1174 | Visitor->Apply(Context); |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | /// getDescString - Return a string used to compose global names and labels. |
| 1178 | /// |
| 1179 | const char *BlockDesc::getDescString() const { |
| 1180 | return "llvm.dbg.block"; |
| 1181 | } |
| 1182 | |
| 1183 | /// getTypeString - Return a string used to label this descriptors type. |
| 1184 | /// |
| 1185 | const char *BlockDesc::getTypeString() const { |
| 1186 | return "llvm.dbg.block.type"; |
| 1187 | } |
| 1188 | |
| 1189 | #ifndef NDEBUG |
| 1190 | void BlockDesc::dump() { |
| 1191 | std::cerr << getDescString() << " " |
Jim Laskey | ed4e566 | 2006-06-14 14:45:39 +0000 | [diff] [blame] | 1192 | << "Version(" << getVersion() << "), " |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1193 | << "Tag(" << getTag() << ")," |
| 1194 | << "Context(" << Context << ")\n"; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1195 | } |
| 1196 | #endif |
| 1197 | |
| 1198 | //===----------------------------------------------------------------------===// |
| 1199 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1200 | DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1201 | return Deserialize(getGlobalVariable(V)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1202 | } |
| 1203 | DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1204 | // Handle NULL. |
| 1205 | if (!GV) return NULL; |
| 1206 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1207 | // Check to see if it has been already deserialized. |
| 1208 | DebugInfoDesc *&Slot = GlobalDescs[GV]; |
| 1209 | if (Slot) return Slot; |
| 1210 | |
| 1211 | // Get the Tag from the global. |
| 1212 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
| 1213 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1214 | // Create an empty instance of the correct sort. |
| 1215 | Slot = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1216 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1217 | // If not a user defined descriptor. |
| 1218 | if (Slot) { |
| 1219 | // Deserialize the fields. |
| 1220 | DIDeserializeVisitor DRAM(*this, GV); |
| 1221 | DRAM.ApplyToFields(Slot); |
| 1222 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1223 | |
| 1224 | return Slot; |
| 1225 | } |
| 1226 | |
| 1227 | //===----------------------------------------------------------------------===// |
| 1228 | |
| 1229 | /// getStrPtrType - Return a "sbyte *" type. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1230 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1231 | const PointerType *DISerializer::getStrPtrType() { |
| 1232 | // If not already defined. |
| 1233 | if (!StrPtrTy) { |
| 1234 | // Construct the pointer to signed bytes. |
| 1235 | StrPtrTy = PointerType::get(Type::SByteTy); |
| 1236 | } |
| 1237 | |
| 1238 | return StrPtrTy; |
| 1239 | } |
| 1240 | |
| 1241 | /// getEmptyStructPtrType - Return a "{ }*" type. |
| 1242 | /// |
| 1243 | const PointerType *DISerializer::getEmptyStructPtrType() { |
| 1244 | // If not already defined. |
| 1245 | if (!EmptyStructPtrTy) { |
| 1246 | // Construct the empty structure type. |
| 1247 | const StructType *EmptyStructTy = |
| 1248 | StructType::get(std::vector<const Type*>()); |
| 1249 | // Construct the pointer to empty structure type. |
| 1250 | EmptyStructPtrTy = PointerType::get(EmptyStructTy); |
| 1251 | } |
| 1252 | |
| 1253 | return EmptyStructPtrTy; |
| 1254 | } |
| 1255 | |
| 1256 | /// getTagType - Return the type describing the specified descriptor (via tag.) |
| 1257 | /// |
| 1258 | const StructType *DISerializer::getTagType(DebugInfoDesc *DD) { |
| 1259 | // Attempt to get the previously defined type. |
| 1260 | StructType *&Ty = TagTypes[DD->getTag()]; |
| 1261 | |
| 1262 | // If not already defined. |
| 1263 | if (!Ty) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1264 | // Set up fields vector. |
| 1265 | std::vector<const Type*> Fields; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1266 | // Get types of fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1267 | DIGetTypesVisitor GTAM(*this, Fields); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1268 | GTAM.ApplyToFields(DD); |
| 1269 | |
| 1270 | // Construct structured type. |
| 1271 | Ty = StructType::get(Fields); |
| 1272 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1273 | // Register type name with module. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1274 | M->addTypeName(DD->getTypeString(), Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | return Ty; |
| 1278 | } |
| 1279 | |
| 1280 | /// getString - Construct the string as constant string global. |
| 1281 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1282 | Constant *DISerializer::getString(const std::string &String) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1283 | // Check string cache for previous edition. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1284 | Constant *&Slot = StringCache[String]; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1285 | // Return Constant if previously defined. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1286 | if (Slot) return Slot; |
Jim Laskey | 9d0ff8e | 2006-03-15 19:09:58 +0000 | [diff] [blame] | 1287 | // If empty string then use a sbyte* null instead. |
| 1288 | if (String.empty()) { |
| 1289 | Slot = ConstantPointerNull::get(getStrPtrType()); |
| 1290 | } else { |
| 1291 | // Construct string as an llvm constant. |
| 1292 | Constant *ConstStr = ConstantArray::get(String); |
| 1293 | // Otherwise create and return a new string global. |
| 1294 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 1295 | GlobalVariable::InternalLinkage, |
| 1296 | ConstStr, "str", M); |
| 1297 | StrGV->setSection("llvm.metadata"); |
| 1298 | // Convert to generic string pointer. |
| 1299 | Slot = ConstantExpr::getCast(StrGV, getStrPtrType()); |
| 1300 | } |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1301 | return Slot; |
| 1302 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | /// Serialize - Recursively cast the specified descriptor into a GlobalVariable |
| 1306 | /// so that it can be serialized to a .bc or .ll file. |
| 1307 | GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) { |
| 1308 | // Check if the DebugInfoDesc is already in the map. |
| 1309 | GlobalVariable *&Slot = DescGlobals[DD]; |
| 1310 | |
| 1311 | // See if DebugInfoDesc exists, if so return prior GlobalVariable. |
| 1312 | if (Slot) return Slot; |
| 1313 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1314 | // Get the type associated with the Tag. |
| 1315 | const StructType *Ty = getTagType(DD); |
| 1316 | |
| 1317 | // Create the GlobalVariable early to prevent infinite recursion. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1318 | GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(), |
| 1319 | NULL, DD->getDescString(), M); |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 1320 | GV->setSection("llvm.metadata"); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1321 | |
| 1322 | // Insert new GlobalVariable in DescGlobals map. |
| 1323 | Slot = GV; |
| 1324 | |
| 1325 | // Set up elements vector |
| 1326 | std::vector<Constant*> Elements; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1327 | // Add fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1328 | DISerializeVisitor SRAM(*this, Elements); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1329 | SRAM.ApplyToFields(DD); |
| 1330 | |
| 1331 | // Set the globals initializer. |
| 1332 | GV->setInitializer(ConstantStruct::get(Ty, Elements)); |
| 1333 | |
| 1334 | return GV; |
| 1335 | } |
| 1336 | |
| 1337 | //===----------------------------------------------------------------------===// |
| 1338 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1339 | /// Verify - Return true if the GlobalVariable appears to be a valid |
| 1340 | /// serialization of a DebugInfoDesc. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1341 | bool DIVerifier::Verify(Value *V) { |
Jim Laskey | aaa80eb | 2006-03-28 01:30:18 +0000 | [diff] [blame] | 1342 | return !V || Verify(getGlobalVariable(V)); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1343 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1344 | bool DIVerifier::Verify(GlobalVariable *GV) { |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1345 | // NULLs are valid. |
| 1346 | if (!GV) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1347 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1348 | // Check prior validity. |
| 1349 | unsigned &ValiditySlot = Validity[GV]; |
| 1350 | |
| 1351 | // If visited before then use old state. |
| 1352 | if (ValiditySlot) return ValiditySlot == Valid; |
| 1353 | |
| 1354 | // Assume validity for the time being (recursion.) |
| 1355 | ValiditySlot = Valid; |
Jim Laskey | a8299de | 2006-03-27 01:51:47 +0000 | [diff] [blame] | 1356 | |
| 1357 | // Make sure the global is internal or link once (anchor.) |
| 1358 | if (GV->getLinkage() != GlobalValue::InternalLinkage && |
| 1359 | GV->getLinkage() != GlobalValue::LinkOnceLinkage) { |
| 1360 | ValiditySlot = Invalid; |
| 1361 | return false; |
| 1362 | } |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1363 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1364 | // Get the Tag |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1365 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1366 | |
| 1367 | // Check for user defined descriptors. |
| 1368 | if (Tag == DW_TAG_invalid) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1369 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1370 | // Construct an empty DebugInfoDesc. |
| 1371 | DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag); |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1372 | |
| 1373 | // Allow for user defined descriptors. |
| 1374 | if (!DD) return true; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1375 | |
| 1376 | // Get the initializer constant. |
| 1377 | ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer()); |
| 1378 | |
| 1379 | // Get the operand count. |
| 1380 | unsigned N = CI->getNumOperands(); |
| 1381 | |
| 1382 | // Get the field count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1383 | unsigned &CountSlot = Counts[Tag]; |
| 1384 | if (!CountSlot) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1385 | // Check the operand count to the field count |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1386 | DICountVisitor CTAM; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1387 | CTAM.ApplyToFields(DD); |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1388 | CountSlot = CTAM.getCount(); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
Jim Laskey | 2140798 | 2006-03-14 18:37:57 +0000 | [diff] [blame] | 1391 | // Field count must be at most equal operand count. |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1392 | if (CountSlot > N) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1393 | delete DD; |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1394 | ValiditySlot = Invalid; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1395 | return false; |
| 1396 | } |
| 1397 | |
| 1398 | // Check each field for valid type. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1399 | DIVerifyVisitor VRAM(*this, GV); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1400 | VRAM.ApplyToFields(DD); |
| 1401 | |
| 1402 | // Release empty DebugInfoDesc. |
| 1403 | delete DD; |
| 1404 | |
Jim Laskey | 98e0410 | 2006-03-26 22:45:20 +0000 | [diff] [blame] | 1405 | // If fields are not valid. |
| 1406 | if (!VRAM.isValid()) { |
| 1407 | ValiditySlot = Invalid; |
| 1408 | return false; |
| 1409 | } |
| 1410 | |
| 1411 | return true; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | //===----------------------------------------------------------------------===// |
| 1415 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1416 | DebugScope::~DebugScope() { |
| 1417 | for (unsigned i = 0, N = Scopes.size(); i < N; ++i) delete Scopes[i]; |
| 1418 | for (unsigned j = 0, M = Variables.size(); j < M; ++j) delete Variables[j]; |
| 1419 | } |
| 1420 | |
| 1421 | //===----------------------------------------------------------------------===// |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1422 | |
| 1423 | MachineDebugInfo::MachineDebugInfo() |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1424 | : DR() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1425 | , VR() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1426 | , CompileUnits() |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1427 | , Directories() |
| 1428 | , SourceFiles() |
| 1429 | , Lines() |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1430 | , LabelID(0) |
| 1431 | , ScopeMap() |
| 1432 | , RootScope(NULL) |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1433 | , FrameMoves() |
| 1434 | {} |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1435 | MachineDebugInfo::~MachineDebugInfo() { |
| 1436 | |
| 1437 | } |
| 1438 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1439 | /// doInitialization - Initialize the debug state for a new module. |
| 1440 | /// |
| 1441 | bool MachineDebugInfo::doInitialization() { |
| 1442 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1445 | /// doFinalization - Tear down the debug state after completion of a module. |
| 1446 | /// |
| 1447 | bool MachineDebugInfo::doFinalization() { |
| 1448 | return false; |
| 1449 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1450 | |
Jim Laskey | 4188699 | 2006-04-07 16:34:46 +0000 | [diff] [blame] | 1451 | /// BeginFunction - Begin gathering function debug information. |
| 1452 | /// |
| 1453 | void MachineDebugInfo::BeginFunction(MachineFunction *MF) { |
| 1454 | // Coming soon. |
| 1455 | } |
| 1456 | |
| 1457 | /// MachineDebugInfo::EndFunction - Discard function debug information. |
| 1458 | /// |
| 1459 | void MachineDebugInfo::EndFunction() { |
| 1460 | // Clean up scope information. |
| 1461 | if (RootScope) { |
| 1462 | delete RootScope; |
| 1463 | ScopeMap.clear(); |
| 1464 | RootScope = NULL; |
| 1465 | } |
| 1466 | |
| 1467 | // Clean up frame info. |
| 1468 | for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i]; |
| 1469 | FrameMoves.clear(); |
| 1470 | } |
| 1471 | |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1472 | /// getDescFor - Convert a Value to a debug information descriptor. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1473 | /// |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1474 | // FIXME - use new Value type when available. |
| 1475 | DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1476 | return DR.Deserialize(V); |
| 1477 | } |
| 1478 | |
| 1479 | /// Verify - Verify that a Value is debug information descriptor. |
| 1480 | /// |
| 1481 | bool MachineDebugInfo::Verify(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1482 | return VR.Verify(V); |
| 1483 | } |
| 1484 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1485 | /// AnalyzeModule - Scan the module for global debug information. |
| 1486 | /// |
| 1487 | void MachineDebugInfo::AnalyzeModule(Module &M) { |
| 1488 | SetupCompileUnits(M); |
| 1489 | } |
| 1490 | |
| 1491 | /// SetupCompileUnits - Set up the unique vector of compile units. |
| 1492 | /// |
| 1493 | void MachineDebugInfo::SetupCompileUnits(Module &M) { |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1494 | std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1495 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1496 | for (unsigned i = 0, N = CU.size(); i < N; i++) { |
| 1497 | CompileUnits.insert(CU[i]); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1498 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1501 | /// getCompileUnits - Return a vector of debug compile units. |
| 1502 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1503 | const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{ |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1504 | return CompileUnits; |
| 1505 | } |
| 1506 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1507 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 1508 | /// named GlobalVariable. |
| 1509 | std::vector<GlobalVariable*> |
| 1510 | MachineDebugInfo::getGlobalVariablesUsing(Module &M, |
| 1511 | const std::string &RootName) { |
| 1512 | return ::getGlobalVariablesUsing(M, RootName); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1513 | } |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1514 | |
| 1515 | /// RecordLabel - Records location information and associates it with a |
| 1516 | /// debug label. Returns a unique label ID used to generate a label and |
| 1517 | /// provide correspondence to the source line list. |
| 1518 | unsigned MachineDebugInfo::RecordLabel(unsigned Line, unsigned Column, |
| 1519 | unsigned Source) { |
| 1520 | unsigned ID = NextLabelID(); |
| 1521 | Lines.push_back(new SourceLineInfo(Line, Column, Source, ID)); |
| 1522 | return ID; |
| 1523 | } |
| 1524 | |
| 1525 | /// RecordSource - Register a source file with debug info. Returns an source |
| 1526 | /// ID. |
| 1527 | unsigned MachineDebugInfo::RecordSource(const std::string &Directory, |
| 1528 | const std::string &Source) { |
| 1529 | unsigned DirectoryID = Directories.insert(Directory); |
| 1530 | return SourceFiles.insert(SourceFileInfo(DirectoryID, Source)); |
| 1531 | } |
| 1532 | unsigned MachineDebugInfo::RecordSource(const CompileUnitDesc *CompileUnit) { |
| 1533 | return RecordSource(CompileUnit->getDirectory(), |
| 1534 | CompileUnit->getFileName()); |
| 1535 | } |
| 1536 | |
| 1537 | /// RecordRegionStart - Indicate the start of a region. |
| 1538 | /// |
| 1539 | unsigned MachineDebugInfo::RecordRegionStart(Value *V) { |
| 1540 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1541 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1542 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1543 | unsigned ID = NextLabelID(); |
| 1544 | if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID); |
| 1545 | return ID; |
| 1546 | } |
| 1547 | |
| 1548 | /// RecordRegionEnd - Indicate the end of a region. |
| 1549 | /// |
| 1550 | unsigned MachineDebugInfo::RecordRegionEnd(Value *V) { |
| 1551 | // FIXME - need to be able to handle split scopes because of bb cloning. |
| 1552 | DebugInfoDesc *ScopeDesc = DR.Deserialize(V); |
| 1553 | DebugScope *Scope = getOrCreateScope(ScopeDesc); |
| 1554 | unsigned ID = NextLabelID(); |
| 1555 | Scope->setEndLabelID(ID); |
| 1556 | return ID; |
| 1557 | } |
| 1558 | |
| 1559 | /// RecordVariable - Indicate the declaration of a local variable. |
| 1560 | /// |
| 1561 | void MachineDebugInfo::RecordVariable(Value *V, unsigned FrameIndex) { |
| 1562 | VariableDesc *VD = cast<VariableDesc>(DR.Deserialize(V)); |
| 1563 | DebugScope *Scope = getOrCreateScope(VD->getContext()); |
| 1564 | DebugVariable *DV = new DebugVariable(VD, FrameIndex); |
| 1565 | Scope->AddVariable(DV); |
| 1566 | } |
| 1567 | |
| 1568 | /// getOrCreateScope - Returns the scope associated with the given descriptor. |
| 1569 | /// |
| 1570 | DebugScope *MachineDebugInfo::getOrCreateScope(DebugInfoDesc *ScopeDesc) { |
| 1571 | DebugScope *&Slot = ScopeMap[ScopeDesc]; |
| 1572 | if (!Slot) { |
| 1573 | // FIXME - breaks down when the context is an inlined function. |
| 1574 | DebugInfoDesc *ParentDesc = NULL; |
| 1575 | if (BlockDesc *Block = dyn_cast<BlockDesc>(ScopeDesc)) { |
| 1576 | ParentDesc = Block->getContext(); |
| 1577 | } |
| 1578 | DebugScope *Parent = ParentDesc ? getOrCreateScope(ParentDesc) : NULL; |
| 1579 | Slot = new DebugScope(Parent, ScopeDesc); |
| 1580 | if (Parent) { |
| 1581 | Parent->AddScope(Slot); |
| 1582 | } else if (RootScope) { |
| 1583 | // FIXME - Add inlined function scopes to the root so we can delete |
| 1584 | // them later. Long term, handle inlined functions properly. |
| 1585 | RootScope->AddScope(Slot); |
| 1586 | } else { |
| 1587 | // First function is top level function. |
| 1588 | RootScope = Slot; |
| 1589 | } |
| 1590 | } |
| 1591 | return Slot; |
| 1592 | } |
| 1593 | |
Jim Laskey | b8509c5 | 2006-03-23 18:07:55 +0000 | [diff] [blame] | 1594 | |