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" |
| 13 | #include "llvm/DerivedTypes.h" |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 14 | #include "llvm/GlobalVariable.h" |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 15 | #include "llvm/Intrinsics.h" |
| 16 | #include "llvm/Instructions.h" |
| 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/Support/Dwarf.h" |
| 19 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 20 | #include <iostream> |
| 21 | |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 23 | using namespace llvm::dwarf; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 24 | |
| 25 | // Handle the Pass registration stuff necessary to use TargetData's. |
| 26 | namespace { |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 27 | RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information"); |
| 28 | } |
Jim Laskey | 063e765 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 29 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
| 31 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 32 | /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 33 | /// specified value in their initializer somewhere. |
| 34 | static void |
| 35 | getGlobalVariablesUsing(Value *V, std::vector<GlobalVariable*> &Result) { |
| 36 | // Scan though value users. |
| 37 | for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) { |
| 38 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(*I)) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 39 | // If the user is a GlobalVariable then add to result. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 40 | Result.push_back(GV); |
| 41 | } else if (Constant *C = dyn_cast<Constant>(*I)) { |
| 42 | // If the user is a constant variable then scan its users |
| 43 | getGlobalVariablesUsing(C, Result); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 48 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 49 | /// named GlobalVariable. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 50 | static std::vector<GlobalVariable*> |
| 51 | getGlobalVariablesUsing(Module &M, const std::string &RootName) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 52 | std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 53 | |
| 54 | std::vector<const Type*> FieldTypes; |
| 55 | FieldTypes.push_back(Type::UIntTy); |
| 56 | FieldTypes.push_back(PointerType::get(Type::SByteTy)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 57 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 58 | // Get the GlobalVariable root. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 59 | GlobalVariable *UseRoot = M.getGlobalVariable(RootName, |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 60 | StructType::get(FieldTypes)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 61 | |
| 62 | // If present and linkonce then scan for users. |
| 63 | if (UseRoot && UseRoot->hasLinkOnceLinkage()) { |
| 64 | getGlobalVariablesUsing(UseRoot, Result); |
| 65 | } |
| 66 | |
| 67 | return Result; |
| 68 | } |
| 69 | |
| 70 | /// getStringValue - Turn an LLVM constant pointer that eventually points to a |
| 71 | /// global into a string value. Return an empty string if we can't do it. |
| 72 | /// |
Chris Lattner | 22760af | 2006-01-27 17:31:30 +0000 | [diff] [blame] | 73 | static const std::string getStringValue(Value *V, unsigned Offset = 0) { |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 74 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 75 | if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { |
| 76 | ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); |
| 77 | if (Init->isString()) { |
| 78 | std::string Result = Init->getAsString(); |
| 79 | if (Offset < Result.size()) { |
| 80 | // If we are pointing INTO The string, erase the beginning... |
| 81 | Result.erase(Result.begin(), Result.begin()+Offset); |
| 82 | |
| 83 | // Take off the null terminator, and any string fragments after it. |
| 84 | std::string::size_type NullPos = Result.find_first_of((char)0); |
| 85 | if (NullPos != std::string::npos) |
| 86 | Result.erase(Result.begin()+NullPos, Result.end()); |
| 87 | return Result; |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | } else if (Constant *C = dyn_cast<Constant>(V)) { |
| 92 | if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 93 | return getStringValue(GV, Offset); |
| 94 | else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { |
| 95 | if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 96 | // Turn a gep into the specified offset. |
| 97 | if (CE->getNumOperands() == 3 && |
| 98 | cast<Constant>(CE->getOperand(1))->isNullValue() && |
| 99 | isa<ConstantInt>(CE->getOperand(2))) { |
| 100 | return getStringValue(CE->getOperand(0), |
| 101 | Offset+cast<ConstantInt>(CE->getOperand(2))->getRawValue()); |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | return ""; |
| 107 | } |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 108 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 109 | /// isStringValue - Return true if the given value can be coerced to a string. |
| 110 | /// |
| 111 | static bool isStringValue(Value *V) { |
| 112 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 113 | if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) { |
| 114 | ConstantArray *Init = cast<ConstantArray>(GV->getInitializer()); |
| 115 | return Init->isString(); |
| 116 | } |
| 117 | } else if (Constant *C = dyn_cast<Constant>(V)) { |
| 118 | if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) |
| 119 | return isStringValue(GV); |
| 120 | else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { |
| 121 | if (CE->getOpcode() == Instruction::GetElementPtr) { |
| 122 | if (CE->getNumOperands() == 3 && |
| 123 | cast<Constant>(CE->getOperand(1))->isNullValue() && |
| 124 | isa<ConstantInt>(CE->getOperand(2))) { |
| 125 | return isStringValue(CE->getOperand(0)); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | return false; |
| 131 | } |
| 132 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 133 | /// getGlobalVariable - Return either a direct or cast Global value. |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 134 | /// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 135 | static GlobalVariable *getGlobalVariable(Value *V) { |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 136 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) { |
| 137 | return GV; |
| 138 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 139 | if (CE->getOpcode() == Instruction::Cast) { |
| 140 | return dyn_cast<GlobalVariable>(CE->getOperand(0)); |
| 141 | } |
Jim Laskey | d8f77ba | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 142 | } |
| 143 | return NULL; |
| 144 | } |
| 145 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 146 | /// isGlobalVariable - Return true if the given value can be coerced to a |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 147 | /// GlobalVariable. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 148 | static bool isGlobalVariable(Value *V) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 149 | if (isa<GlobalVariable>(V) || isa<ConstantPointerNull>(V)) { |
| 150 | return true; |
| 151 | } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
| 152 | if (CE->getOpcode() == Instruction::Cast) { |
| 153 | return isa<GlobalVariable>(CE->getOperand(0)); |
| 154 | } |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 159 | /// getUIntOperand - Return ith operand if it is an unsigned integer. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 160 | /// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 161 | static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 162 | // Make sure the GlobalVariable has an initializer. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 163 | if (!GV->hasInitializer()) return NULL; |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 164 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 165 | // Get the initializer constant. |
| 166 | ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer()); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 167 | if (!CI) return NULL; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 168 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 169 | // Check if there is at least i + 1 operands. |
| 170 | unsigned N = CI->getNumOperands(); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 171 | if (i >= N) return NULL; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 172 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 173 | // Check constant. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 174 | return dyn_cast<ConstantUInt>(CI->getOperand(i)); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 175 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 176 | //===----------------------------------------------------------------------===// |
| 177 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 178 | /// ApplyToFields - Target the visitor to each field of the debug information |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 179 | /// descriptor. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 180 | void DIVisitor::ApplyToFields(DebugInfoDesc *DD) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 181 | DD->ApplyToFields(this); |
| 182 | } |
| 183 | |
| 184 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 185 | /// DICountVisitor - This DIVisitor counts all the fields in the supplied debug |
| 186 | /// the supplied DebugInfoDesc. |
| 187 | class DICountVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 188 | private: |
| 189 | unsigned Count; // Running count of fields. |
| 190 | |
| 191 | public: |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 192 | DICountVisitor() : DIVisitor(), Count(0) {} |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 193 | |
| 194 | // Accessors. |
| 195 | unsigned getCount() const { return Count; } |
| 196 | |
| 197 | /// Apply - Count each of the fields. |
| 198 | /// |
| 199 | virtual void Apply(int &Field) { ++Count; } |
| 200 | virtual void Apply(unsigned &Field) { ++Count; } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 201 | virtual void Apply(int64_t &Field) { ++Count; } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 202 | virtual void Apply(uint64_t &Field) { ++Count; } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 203 | virtual void Apply(bool &Field) { ++Count; } |
| 204 | virtual void Apply(std::string &Field) { ++Count; } |
| 205 | virtual void Apply(DebugInfoDesc *&Field) { ++Count; } |
| 206 | virtual void Apply(GlobalVariable *&Field) { ++Count; } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 207 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 208 | ++Count; |
| 209 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 213 | /// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the |
| 214 | /// supplied DebugInfoDesc. |
| 215 | class DIDeserializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 216 | private: |
| 217 | DIDeserializer &DR; // Active deserializer. |
| 218 | unsigned I; // Current operand index. |
| 219 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 220 | |
| 221 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 222 | DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV) |
| 223 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 224 | , DR(D) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 225 | , I(0) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 226 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 227 | {} |
| 228 | |
| 229 | /// Apply - Set the value of each of the fields. |
| 230 | /// |
| 231 | virtual void Apply(int &Field) { |
| 232 | Constant *C = CI->getOperand(I++); |
| 233 | Field = cast<ConstantSInt>(C)->getValue(); |
| 234 | } |
| 235 | virtual void Apply(unsigned &Field) { |
| 236 | Constant *C = CI->getOperand(I++); |
| 237 | Field = cast<ConstantUInt>(C)->getValue(); |
| 238 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 239 | virtual void Apply(int64_t &Field) { |
| 240 | Constant *C = CI->getOperand(I++); |
| 241 | Field = cast<ConstantSInt>(C)->getValue(); |
| 242 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 243 | virtual void Apply(uint64_t &Field) { |
| 244 | Constant *C = CI->getOperand(I++); |
| 245 | Field = cast<ConstantUInt>(C)->getValue(); |
| 246 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 247 | virtual void Apply(bool &Field) { |
| 248 | Constant *C = CI->getOperand(I++); |
| 249 | Field = cast<ConstantBool>(C)->getValue(); |
| 250 | } |
| 251 | virtual void Apply(std::string &Field) { |
| 252 | Constant *C = CI->getOperand(I++); |
| 253 | Field = getStringValue(C); |
| 254 | } |
| 255 | virtual void Apply(DebugInfoDesc *&Field) { |
| 256 | Constant *C = CI->getOperand(I++); |
| 257 | Field = DR.Deserialize(C); |
| 258 | } |
| 259 | virtual void Apply(GlobalVariable *&Field) { |
| 260 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 261 | Field = getGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 262 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 263 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 264 | Constant *C = CI->getOperand(I++); |
| 265 | GlobalVariable *GV = getGlobalVariable(C); |
| 266 | ConstantArray *CA = cast<ConstantArray>(GV->getInitializer()); |
| 267 | Field.resize(0); |
| 268 | for (unsigned i = 0, N = CA->getNumOperands(); i < N; ++i) { |
| 269 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 270 | DebugInfoDesc *DE = DR.Deserialize(GVE); |
| 271 | Field.push_back(DE); |
| 272 | } |
| 273 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 277 | /// DISerializeVisitor - This DIVisitor serializes all the fields in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 278 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 279 | class DISerializeVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 280 | private: |
| 281 | DISerializer &SR; // Active serializer. |
| 282 | std::vector<Constant*> &Elements; // Element accumulator. |
| 283 | |
| 284 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 285 | DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E) |
| 286 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 287 | , SR(S) |
| 288 | , Elements(E) |
| 289 | {} |
| 290 | |
| 291 | /// Apply - Set the value of each of the fields. |
| 292 | /// |
| 293 | virtual void Apply(int &Field) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 294 | Elements.push_back(ConstantSInt::get(Type::IntTy, Field)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 295 | } |
| 296 | virtual void Apply(unsigned &Field) { |
| 297 | Elements.push_back(ConstantUInt::get(Type::UIntTy, Field)); |
| 298 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 299 | virtual void Apply(int64_t &Field) { |
| 300 | Elements.push_back(ConstantSInt::get(Type::IntTy, Field)); |
| 301 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 302 | virtual void Apply(uint64_t &Field) { |
| 303 | Elements.push_back(ConstantUInt::get(Type::UIntTy, Field)); |
| 304 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 305 | virtual void Apply(bool &Field) { |
| 306 | Elements.push_back(ConstantBool::get(Field)); |
| 307 | } |
| 308 | virtual void Apply(std::string &Field) { |
| 309 | Elements.push_back(SR.getString(Field)); |
| 310 | } |
| 311 | virtual void Apply(DebugInfoDesc *&Field) { |
| 312 | GlobalVariable *GV = NULL; |
| 313 | |
| 314 | // If non-NULL the convert to global. |
| 315 | if (Field) GV = SR.Serialize(Field); |
| 316 | |
| 317 | // FIXME - At some point should use specific type. |
| 318 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 319 | |
| 320 | if (GV) { |
| 321 | // Set to pointer to global. |
| 322 | Elements.push_back(ConstantExpr::getCast(GV, EmptyTy)); |
| 323 | } else { |
| 324 | // Use NULL. |
| 325 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 326 | } |
| 327 | } |
| 328 | virtual void Apply(GlobalVariable *&Field) { |
| 329 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 330 | if (Field) { |
| 331 | Elements.push_back(ConstantExpr::getCast(Field, EmptyTy)); |
| 332 | } else { |
| 333 | Elements.push_back(ConstantPointerNull::get(EmptyTy)); |
| 334 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 335 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 336 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 337 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 338 | unsigned N = Field.size(); |
| 339 | ArrayType *AT = ArrayType::get(EmptyTy, N); |
| 340 | std::vector<Constant *> ArrayElements; |
| 341 | |
| 342 | for (unsigned i = 0, N = Field.size(); i < N; ++i) { |
| 343 | GlobalVariable *GVE = SR.Serialize(Field[i]); |
| 344 | Constant *CE = ConstantExpr::getCast(GVE, EmptyTy); |
| 345 | ArrayElements.push_back(cast<Constant>(CE)); |
| 346 | } |
| 347 | |
| 348 | Constant *CA = ConstantArray::get(AT, ArrayElements); |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 349 | GlobalVariable *CAGV = new GlobalVariable(AT, true, |
| 350 | GlobalValue::InternalLinkage, |
| 351 | CA, "llvm.dbg.array", |
| 352 | SR.getModule()); |
| 353 | Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy); |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 354 | Elements.push_back(CAE); |
| 355 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 359 | /// DIGetTypesVisitor - This DIVisitor gathers all the field types in |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 360 | /// the supplied DebugInfoDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 361 | class DIGetTypesVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 362 | private: |
| 363 | DISerializer &SR; // Active serializer. |
| 364 | std::vector<const Type*> &Fields; // Type accumulator. |
| 365 | |
| 366 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 367 | DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F) |
| 368 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 369 | , SR(S) |
| 370 | , Fields(F) |
| 371 | {} |
| 372 | |
| 373 | /// Apply - Set the value of each of the fields. |
| 374 | /// |
| 375 | virtual void Apply(int &Field) { |
| 376 | Fields.push_back(Type::IntTy); |
| 377 | } |
| 378 | virtual void Apply(unsigned &Field) { |
| 379 | Fields.push_back(Type::UIntTy); |
| 380 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 381 | virtual void Apply(int64_t &Field) { |
| 382 | Fields.push_back(Type::IntTy); |
| 383 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 384 | virtual void Apply(uint64_t &Field) { |
| 385 | Fields.push_back(Type::UIntTy); |
| 386 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 387 | virtual void Apply(bool &Field) { |
| 388 | Fields.push_back(Type::BoolTy); |
| 389 | } |
| 390 | virtual void Apply(std::string &Field) { |
| 391 | Fields.push_back(SR.getStrPtrType()); |
| 392 | } |
| 393 | virtual void Apply(DebugInfoDesc *&Field) { |
| 394 | // FIXME - At some point should use specific type. |
| 395 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 396 | Fields.push_back(EmptyTy); |
| 397 | } |
| 398 | virtual void Apply(GlobalVariable *&Field) { |
| 399 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 400 | Fields.push_back(EmptyTy); |
| 401 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 402 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 403 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 404 | Fields.push_back(EmptyTy); |
| 405 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 406 | }; |
| 407 | |
| 408 | //===----------------------------------------------------------------------===// |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 409 | /// DIVerifyVisitor - This DIVisitor verifies all the field types against |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 410 | /// a constant initializer. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 411 | class DIVerifyVisitor : public DIVisitor { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 412 | private: |
| 413 | DIVerifier &VR; // Active verifier. |
| 414 | bool IsValid; // Validity status. |
| 415 | unsigned I; // Current operand index. |
| 416 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 417 | |
| 418 | public: |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 419 | DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV) |
| 420 | : DIVisitor() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 421 | , VR(V) |
| 422 | , IsValid(true) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 423 | , I(0) |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 424 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 425 | { |
| 426 | } |
| 427 | |
| 428 | // Accessors. |
| 429 | bool isValid() const { return IsValid; } |
| 430 | |
| 431 | /// Apply - Set the value of each of the fields. |
| 432 | /// |
| 433 | virtual void Apply(int &Field) { |
| 434 | Constant *C = CI->getOperand(I++); |
| 435 | IsValid = IsValid && isa<ConstantInt>(C); |
| 436 | } |
| 437 | virtual void Apply(unsigned &Field) { |
| 438 | Constant *C = CI->getOperand(I++); |
| 439 | IsValid = IsValid && isa<ConstantInt>(C); |
| 440 | } |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 441 | virtual void Apply(int64_t &Field) { |
| 442 | Constant *C = CI->getOperand(I++); |
| 443 | IsValid = IsValid && isa<ConstantInt>(C); |
| 444 | } |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 445 | virtual void Apply(uint64_t &Field) { |
| 446 | Constant *C = CI->getOperand(I++); |
| 447 | IsValid = IsValid && isa<ConstantInt>(C); |
| 448 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 449 | virtual void Apply(bool &Field) { |
| 450 | Constant *C = CI->getOperand(I++); |
| 451 | IsValid = IsValid && isa<ConstantBool>(C); |
| 452 | } |
| 453 | virtual void Apply(std::string &Field) { |
| 454 | Constant *C = CI->getOperand(I++); |
| 455 | IsValid = IsValid && isStringValue(C); |
| 456 | } |
| 457 | virtual void Apply(DebugInfoDesc *&Field) { |
| 458 | // FIXME - Prepare the correct descriptor. |
| 459 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 460 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 461 | } |
| 462 | virtual void Apply(GlobalVariable *&Field) { |
| 463 | Constant *C = CI->getOperand(I++); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 464 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 465 | } |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 466 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 467 | Constant *C = CI->getOperand(I++); |
| 468 | IsValid = IsValid && isGlobalVariable(C); |
| 469 | if (!IsValid) return; |
| 470 | |
| 471 | GlobalVariable *GV = getGlobalVariable(C); |
| 472 | IsValid = IsValid && GV && GV->hasInitializer(); |
| 473 | if (!IsValid) return; |
| 474 | |
| 475 | ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 476 | IsValid = IsValid && CA; |
| 477 | if (!IsValid) return; |
| 478 | |
| 479 | for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) { |
| 480 | IsValid = IsValid && isGlobalVariable(CA->getOperand(i)); |
| 481 | if (!IsValid) return; |
| 482 | |
| 483 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 484 | VR.Verify(GVE); |
| 485 | } |
| 486 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 487 | }; |
| 488 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 489 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 490 | //===----------------------------------------------------------------------===// |
| 491 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 492 | /// TagFromGlobal - Returns the Tag number from a debug info descriptor |
| 493 | /// GlobalVariable. |
| 494 | unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) { |
| 495 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 496 | return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /// DescFactory - Create an instance of debug info descriptor based on Tag. |
| 500 | /// Return NULL if not a recognized Tag. |
| 501 | DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { |
| 502 | switch (Tag) { |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 503 | case DW_TAG_anchor: return new AnchorDesc(); |
| 504 | case DW_TAG_compile_unit: return new CompileUnitDesc(); |
| 505 | case DW_TAG_variable: return new GlobalVariableDesc(); |
| 506 | case DW_TAG_subprogram: return new SubprogramDesc(); |
| 507 | case DW_TAG_base_type: return new BasicTypeDesc(); |
| 508 | case DW_TAG_typedef: |
| 509 | case DW_TAG_pointer_type: |
| 510 | case DW_TAG_reference_type: |
| 511 | case DW_TAG_const_type: |
| 512 | case DW_TAG_volatile_type: |
| 513 | case DW_TAG_restrict_type: return new DerivedTypeDesc(Tag); |
| 514 | case DW_TAG_array_type: |
| 515 | case DW_TAG_structure_type: |
| 516 | case DW_TAG_union_type: |
| 517 | case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag); |
| 518 | case DW_TAG_subrange_type: return new SubrangeDesc(); |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 519 | case DW_TAG_enumerator: return new EnumeratorDesc(); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 520 | default: break; |
| 521 | } |
| 522 | return NULL; |
| 523 | } |
| 524 | |
| 525 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 526 | /// |
| 527 | GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const { |
| 528 | return GlobalValue::InternalLinkage; |
| 529 | } |
| 530 | |
| 531 | /// ApplyToFields - Target the vistor to the fields of the descriptor. |
| 532 | /// |
| 533 | void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) { |
| 534 | Visitor->Apply(Tag); |
| 535 | } |
| 536 | |
| 537 | //===----------------------------------------------------------------------===// |
| 538 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 539 | AnchorDesc::AnchorDesc() |
| 540 | : DebugInfoDesc(DW_TAG_anchor) |
| 541 | , Name("") |
| 542 | {} |
| 543 | AnchorDesc::AnchorDesc(const std::string &N) |
| 544 | : DebugInfoDesc(DW_TAG_anchor) |
| 545 | , Name(N) |
| 546 | {} |
| 547 | |
| 548 | // Implement isa/cast/dyncast. |
| 549 | bool AnchorDesc::classof(const DebugInfoDesc *D) { |
| 550 | return D->getTag() == DW_TAG_anchor; |
| 551 | } |
| 552 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 553 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 554 | /// |
| 555 | GlobalValue::LinkageTypes AnchorDesc::getLinkage() const { |
| 556 | return GlobalValue::LinkOnceLinkage; |
| 557 | } |
| 558 | |
| 559 | /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc. |
| 560 | /// |
| 561 | void AnchorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 562 | DebugInfoDesc::ApplyToFields(Visitor); |
| 563 | |
| 564 | Visitor->Apply(Name); |
| 565 | } |
| 566 | |
| 567 | /// getDescString - Return a string used to compose global names and labels. |
| 568 | /// |
| 569 | const char *AnchorDesc::getDescString() const { |
| 570 | return Name.c_str(); |
| 571 | } |
| 572 | |
| 573 | /// getTypeString - Return a string used to label this descriptors type. |
| 574 | /// |
| 575 | const char *AnchorDesc::getTypeString() const { |
| 576 | return "llvm.dbg.anchor.type"; |
| 577 | } |
| 578 | |
| 579 | #ifndef NDEBUG |
| 580 | void AnchorDesc::dump() { |
| 581 | std::cerr << getDescString() << " " |
| 582 | << "Tag(" << getTag() << "), " |
| 583 | << "Name(" << Name << ")\n"; |
| 584 | } |
| 585 | #endif |
| 586 | |
| 587 | //===----------------------------------------------------------------------===// |
| 588 | |
| 589 | AnchoredDesc::AnchoredDesc(unsigned T) |
| 590 | : DebugInfoDesc(T) |
| 591 | , Anchor(NULL) |
| 592 | {} |
| 593 | |
| 594 | /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc. |
| 595 | /// |
| 596 | void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) { |
| 597 | DebugInfoDesc::ApplyToFields(Visitor); |
| 598 | |
| 599 | Visitor->Apply((DebugInfoDesc *&)Anchor); |
| 600 | } |
| 601 | |
| 602 | //===----------------------------------------------------------------------===// |
| 603 | |
| 604 | CompileUnitDesc::CompileUnitDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 605 | : AnchoredDesc(DW_TAG_compile_unit) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 606 | , DebugVersion(LLVMDebugVersion) |
| 607 | , Language(0) |
| 608 | , FileName("") |
| 609 | , Directory("") |
| 610 | , Producer("") |
| 611 | {} |
| 612 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 613 | // Implement isa/cast/dyncast. |
| 614 | bool CompileUnitDesc::classof(const DebugInfoDesc *D) { |
| 615 | return D->getTag() == DW_TAG_compile_unit; |
| 616 | } |
| 617 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 618 | /// DebugVersionFromGlobal - Returns the version number from a compile unit |
| 619 | /// GlobalVariable. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 620 | unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 621 | ConstantUInt *C = getUIntOperand(GV, 2); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 622 | return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 625 | /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. |
| 626 | /// |
| 627 | void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 628 | AnchoredDesc::ApplyToFields(Visitor); |
| 629 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 630 | Visitor->Apply(DebugVersion); |
| 631 | Visitor->Apply(Language); |
| 632 | Visitor->Apply(FileName); |
| 633 | Visitor->Apply(Directory); |
| 634 | Visitor->Apply(Producer); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 637 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 638 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 639 | const char *CompileUnitDesc::getDescString() const { |
| 640 | return "llvm.dbg.compile_unit"; |
| 641 | } |
| 642 | |
| 643 | /// getTypeString - Return a string used to label this descriptors type. |
| 644 | /// |
| 645 | const char *CompileUnitDesc::getTypeString() const { |
| 646 | return "llvm.dbg.compile_unit.type"; |
| 647 | } |
| 648 | |
| 649 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 650 | /// |
| 651 | const char *CompileUnitDesc::getAnchorString() const { |
| 652 | return "llvm.dbg.compile_units"; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 655 | #ifndef NDEBUG |
| 656 | void CompileUnitDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 657 | std::cerr << getDescString() << " " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 658 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 659 | << "Anchor(" << getAnchor() << "), " |
| 660 | << "DebugVersion(" << DebugVersion << "), " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 661 | << "Language(" << Language << "), " |
| 662 | << "FileName(\"" << FileName << "\"), " |
| 663 | << "Directory(\"" << Directory << "\"), " |
| 664 | << "Producer(\"" << Producer << "\")\n"; |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | //===----------------------------------------------------------------------===// |
| 669 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 670 | TypeDesc::TypeDesc(unsigned T) |
| 671 | : DebugInfoDesc(T) |
| 672 | , Context(NULL) |
| 673 | , Name("") |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 674 | , File(NULL) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 675 | , Size(0) |
| 676 | {} |
| 677 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 678 | /// ApplyToFields - Target the visitor to the fields of the TypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 679 | /// |
| 680 | void TypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 681 | DebugInfoDesc::ApplyToFields(Visitor); |
| 682 | |
| 683 | Visitor->Apply(Context); |
| 684 | Visitor->Apply(Name); |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 685 | Visitor->Apply((DebugInfoDesc *&)File); |
| 686 | Visitor->Apply(Line); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 687 | Visitor->Apply(Size); |
| 688 | } |
| 689 | |
| 690 | /// getDescString - Return a string used to compose global names and labels. |
| 691 | /// |
| 692 | const char *TypeDesc::getDescString() const { |
| 693 | return "llvm.dbg.type"; |
| 694 | } |
| 695 | |
| 696 | /// getTypeString - Return a string used to label this descriptor's type. |
| 697 | /// |
| 698 | const char *TypeDesc::getTypeString() const { |
| 699 | return "llvm.dbg.type.type"; |
| 700 | } |
| 701 | |
| 702 | #ifndef NDEBUG |
| 703 | void TypeDesc::dump() { |
| 704 | std::cerr << getDescString() << " " |
| 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 | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 710 | << "Size(" << Size << ")\n"; |
| 711 | } |
| 712 | #endif |
| 713 | |
| 714 | //===----------------------------------------------------------------------===// |
| 715 | |
| 716 | BasicTypeDesc::BasicTypeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 717 | : TypeDesc(DW_TAG_base_type) |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 718 | , Encoding(0) |
| 719 | {} |
| 720 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 721 | // Implement isa/cast/dyncast. |
| 722 | bool BasicTypeDesc::classof(const DebugInfoDesc *D) { |
| 723 | return D->getTag() == DW_TAG_base_type; |
| 724 | } |
| 725 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 726 | /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc. |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 727 | /// |
| 728 | void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 729 | TypeDesc::ApplyToFields(Visitor); |
| 730 | |
| 731 | Visitor->Apply(Encoding); |
| 732 | } |
| 733 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 734 | /// getDescString - Return a string used to compose global names and labels. |
| 735 | /// |
| 736 | const char *BasicTypeDesc::getDescString() const { |
| 737 | return "llvm.dbg.basictype"; |
| 738 | } |
| 739 | |
| 740 | /// getTypeString - Return a string used to label this descriptor's type. |
| 741 | /// |
| 742 | const char *BasicTypeDesc::getTypeString() const { |
| 743 | return "llvm.dbg.basictype.type"; |
| 744 | } |
| 745 | |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 746 | #ifndef NDEBUG |
| 747 | void BasicTypeDesc::dump() { |
| 748 | std::cerr << getDescString() << " " |
| 749 | << "Tag(" << getTag() << "), " |
| 750 | << "Context(" << getContext() << "), " |
| 751 | << "Name(\"" << getName() << "\"), " |
| 752 | << "Size(" << getSize() << "), " |
| 753 | << "Encoding(" << Encoding << ")\n"; |
| 754 | } |
| 755 | #endif |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 756 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 757 | //===----------------------------------------------------------------------===// |
| 758 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 759 | DerivedTypeDesc::DerivedTypeDesc(unsigned T) |
| 760 | : TypeDesc(T) |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 761 | , FromType(NULL) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 762 | {} |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 763 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 764 | // Implement isa/cast/dyncast. |
| 765 | bool DerivedTypeDesc::classof(const DebugInfoDesc *D) { |
| 766 | unsigned T = D->getTag(); |
| 767 | switch (T) { |
| 768 | case DW_TAG_typedef: |
| 769 | case DW_TAG_pointer_type: |
| 770 | case DW_TAG_reference_type: |
| 771 | case DW_TAG_const_type: |
| 772 | case DW_TAG_volatile_type: |
| 773 | case DW_TAG_restrict_type: |
| 774 | return true; |
| 775 | default: break; |
| 776 | } |
| 777 | return false; |
| 778 | } |
| 779 | |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 780 | /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 781 | /// |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 782 | void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 783 | TypeDesc::ApplyToFields(Visitor); |
| 784 | |
| 785 | Visitor->Apply((DebugInfoDesc *&)FromType); |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 788 | /// getDescString - Return a string used to compose global names and labels. |
| 789 | /// |
| 790 | const char *DerivedTypeDesc::getDescString() const { |
| 791 | return "llvm.dbg.derivedtype"; |
| 792 | } |
| 793 | |
| 794 | /// getTypeString - Return a string used to label this descriptor's type. |
| 795 | /// |
| 796 | const char *DerivedTypeDesc::getTypeString() const { |
| 797 | return "llvm.dbg.derivedtype.type"; |
| 798 | } |
| 799 | |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 800 | #ifndef NDEBUG |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 801 | void DerivedTypeDesc::dump() { |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 802 | std::cerr << getDescString() << " " |
| 803 | << "Tag(" << getTag() << "), " |
| 804 | << "Context(" << getContext() << "), " |
| 805 | << "Name(\"" << getName() << "\"), " |
| 806 | << "Size(" << getSize() << "), " |
Jim Laskey | 6990600 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 807 | << "File(" << getFile() << "), " |
| 808 | << "Line(" << getLine() << "), " |
| 809 | << "FromType(" << FromType << ")\n"; |
Jim Laskey | 434b40b | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 810 | } |
| 811 | #endif |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 812 | |
| 813 | //===----------------------------------------------------------------------===// |
| 814 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 815 | CompositeTypeDesc::CompositeTypeDesc(unsigned T) |
| 816 | : DerivedTypeDesc(T) |
| 817 | , Elements() |
| 818 | {} |
| 819 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 820 | // Implement isa/cast/dyncast. |
| 821 | bool CompositeTypeDesc::classof(const DebugInfoDesc *D) { |
| 822 | unsigned T = D->getTag(); |
| 823 | switch (T) { |
| 824 | case DW_TAG_array_type: |
| 825 | case DW_TAG_structure_type: |
| 826 | case DW_TAG_union_type: |
| 827 | case DW_TAG_enumeration_type: |
| 828 | return true; |
| 829 | default: break; |
| 830 | } |
| 831 | return false; |
| 832 | } |
| 833 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 834 | /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc. |
| 835 | /// |
| 836 | void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 837 | DerivedTypeDesc::ApplyToFields(Visitor); |
| 838 | |
| 839 | Visitor->Apply(Elements); |
| 840 | } |
| 841 | |
| 842 | /// getDescString - Return a string used to compose global names and labels. |
| 843 | /// |
| 844 | const char *CompositeTypeDesc::getDescString() const { |
| 845 | return "llvm.dbg.compositetype"; |
| 846 | } |
| 847 | |
| 848 | /// getTypeString - Return a string used to label this descriptor's type. |
| 849 | /// |
| 850 | const char *CompositeTypeDesc::getTypeString() const { |
| 851 | return "llvm.dbg.compositetype.type"; |
| 852 | } |
| 853 | |
| 854 | #ifndef NDEBUG |
| 855 | void CompositeTypeDesc::dump() { |
| 856 | std::cerr << getDescString() << " " |
| 857 | << "Tag(" << getTag() << "), " |
| 858 | << "Context(" << getContext() << "), " |
| 859 | << "Name(\"" << getName() << "\"), " |
| 860 | << "Size(" << getSize() << "), " |
| 861 | << "File(" << getFile() << "), " |
| 862 | << "Line(" << getLine() << "), " |
| 863 | << "FromType(" << getFromType() << "), " |
| 864 | << "Elements.size(" << Elements.size() << ")\n"; |
| 865 | } |
| 866 | #endif |
| 867 | |
| 868 | //===----------------------------------------------------------------------===// |
| 869 | |
| 870 | SubrangeDesc::SubrangeDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 871 | : DebugInfoDesc(DW_TAG_subrange_type) |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 872 | , Lo(0) |
| 873 | , Hi(0) |
| 874 | {} |
| 875 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 876 | // Implement isa/cast/dyncast. |
| 877 | bool SubrangeDesc::classof(const DebugInfoDesc *D) { |
| 878 | return D->getTag() == DW_TAG_subrange_type; |
| 879 | } |
| 880 | |
Jim Laskey | f8913f1 | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 881 | /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc. |
| 882 | /// |
| 883 | void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 884 | DebugInfoDesc::ApplyToFields(Visitor); |
| 885 | |
| 886 | Visitor->Apply(Lo); |
| 887 | Visitor->Apply(Hi); |
| 888 | } |
| 889 | |
| 890 | /// getDescString - Return a string used to compose global names and labels. |
| 891 | /// |
| 892 | const char *SubrangeDesc::getDescString() const { |
| 893 | return "llvm.dbg.subrange"; |
| 894 | } |
| 895 | |
| 896 | /// getTypeString - Return a string used to label this descriptor's type. |
| 897 | /// |
| 898 | const char *SubrangeDesc::getTypeString() const { |
| 899 | return "llvm.dbg.subrange.type"; |
| 900 | } |
| 901 | |
| 902 | #ifndef NDEBUG |
| 903 | void SubrangeDesc::dump() { |
| 904 | std::cerr << getDescString() << " " |
| 905 | << "Tag(" << getTag() << "), " |
| 906 | << "Lo(" << Lo << "), " |
| 907 | << "Hi(" << Hi << ")\n"; |
| 908 | } |
| 909 | #endif |
| 910 | |
| 911 | //===----------------------------------------------------------------------===// |
| 912 | |
Jim Laskey | 6a3eb01 | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 913 | EnumeratorDesc::EnumeratorDesc() |
| 914 | : DebugInfoDesc(DW_TAG_enumerator) |
| 915 | , Name("") |
| 916 | , Value(0) |
| 917 | {} |
| 918 | |
| 919 | // Implement isa/cast/dyncast. |
| 920 | bool EnumeratorDesc::classof(const DebugInfoDesc *D) { |
| 921 | return D->getTag() == DW_TAG_enumerator; |
| 922 | } |
| 923 | |
| 924 | /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc. |
| 925 | /// |
| 926 | void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 927 | DebugInfoDesc::ApplyToFields(Visitor); |
| 928 | |
| 929 | Visitor->Apply(Name); |
| 930 | Visitor->Apply(Value); |
| 931 | } |
| 932 | |
| 933 | /// getDescString - Return a string used to compose global names and labels. |
| 934 | /// |
| 935 | const char *EnumeratorDesc::getDescString() const { |
| 936 | return "llvm.dbg.enumerator"; |
| 937 | } |
| 938 | |
| 939 | /// getTypeString - Return a string used to label this descriptor's type. |
| 940 | /// |
| 941 | const char *EnumeratorDesc::getTypeString() const { |
| 942 | return "llvm.dbg.enumerator.type"; |
| 943 | } |
| 944 | |
| 945 | #ifndef NDEBUG |
| 946 | void EnumeratorDesc::dump() { |
| 947 | std::cerr << getDescString() << " " |
| 948 | << "Tag(" << getTag() << "), " |
| 949 | << "Name(" << Name << "), " |
| 950 | << "Value(" << Value << ")\n"; |
| 951 | } |
| 952 | #endif |
| 953 | |
| 954 | //===----------------------------------------------------------------------===// |
| 955 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 956 | GlobalDesc::GlobalDesc(unsigned T) |
| 957 | : AnchoredDesc(T) |
| 958 | , Context(0) |
| 959 | , Name("") |
| 960 | , TyDesc(NULL) |
| 961 | , IsStatic(false) |
| 962 | , IsDefinition(false) |
| 963 | {} |
| 964 | |
| 965 | /// ApplyToFields - Target the visitor to the fields of the global. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 966 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 967 | void GlobalDesc::ApplyToFields(DIVisitor *Visitor) { |
| 968 | AnchoredDesc::ApplyToFields(Visitor); |
| 969 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 970 | Visitor->Apply(Context); |
| 971 | Visitor->Apply(Name); |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 972 | Visitor->Apply((DebugInfoDesc *&)TyDesc); |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 973 | Visitor->Apply(IsStatic); |
| 974 | Visitor->Apply(IsDefinition); |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | //===----------------------------------------------------------------------===// |
| 978 | |
| 979 | GlobalVariableDesc::GlobalVariableDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 980 | : GlobalDesc(DW_TAG_variable) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 981 | , Global(NULL) |
| 982 | {} |
| 983 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 984 | // Implement isa/cast/dyncast. |
| 985 | bool GlobalVariableDesc::classof(const DebugInfoDesc *D) { |
| 986 | return D->getTag() == DW_TAG_variable; |
| 987 | } |
| 988 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 989 | /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. |
| 990 | /// |
| 991 | void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 992 | GlobalDesc::ApplyToFields(Visitor); |
| 993 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 994 | Visitor->Apply(Global); |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 995 | Visitor->Apply(Line); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 998 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 999 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1000 | const char *GlobalVariableDesc::getDescString() const { |
| 1001 | return "llvm.dbg.global_variable"; |
| 1002 | } |
| 1003 | |
| 1004 | /// getTypeString - Return a string used to label this descriptors type. |
| 1005 | /// |
| 1006 | const char *GlobalVariableDesc::getTypeString() const { |
| 1007 | return "llvm.dbg.global_variable.type"; |
| 1008 | } |
| 1009 | |
| 1010 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1011 | /// |
| 1012 | const char *GlobalVariableDesc::getAnchorString() const { |
| 1013 | return "llvm.dbg.global_variables"; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1016 | #ifndef NDEBUG |
| 1017 | void GlobalVariableDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1018 | std::cerr << getDescString() << " " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1019 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1020 | << "Anchor(" << getAnchor() << "), " |
| 1021 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 1022 | << "Type(\"" << getTypeDesc() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1023 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1024 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1025 | << "Global(" << Global << "), " |
| 1026 | << "Line(" << Line << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1027 | } |
| 1028 | #endif |
| 1029 | |
| 1030 | //===----------------------------------------------------------------------===// |
| 1031 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1032 | SubprogramDesc::SubprogramDesc() |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1033 | : GlobalDesc(DW_TAG_subprogram) |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1034 | {} |
| 1035 | |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1036 | // Implement isa/cast/dyncast. |
| 1037 | bool SubprogramDesc::classof(const DebugInfoDesc *D) { |
| 1038 | return D->getTag() == DW_TAG_subprogram; |
| 1039 | } |
| 1040 | |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1041 | /// ApplyToFields - Target the visitor to the fields of the |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1042 | /// SubprogramDesc. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1043 | void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1044 | GlobalDesc::ApplyToFields(Visitor); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1047 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1048 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1049 | const char *SubprogramDesc::getDescString() const { |
| 1050 | return "llvm.dbg.subprogram"; |
| 1051 | } |
| 1052 | |
| 1053 | /// getTypeString - Return a string used to label this descriptors type. |
| 1054 | /// |
| 1055 | const char *SubprogramDesc::getTypeString() const { |
| 1056 | return "llvm.dbg.subprogram.type"; |
| 1057 | } |
| 1058 | |
| 1059 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1060 | /// |
| 1061 | const char *SubprogramDesc::getAnchorString() const { |
| 1062 | return "llvm.dbg.subprograms"; |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1065 | #ifndef NDEBUG |
| 1066 | void SubprogramDesc::dump() { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1067 | std::cerr << getDescString() << " " |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1068 | << "Tag(" << getTag() << "), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1069 | << "Anchor(" << getAnchor() << "), " |
| 1070 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | f4afdd9 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 1071 | << "Type(\"" << getTypeDesc() << "\"), " |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1072 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1073 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1074 | } |
| 1075 | #endif |
| 1076 | |
Jim Laskey | 45ccae5 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 1077 | //===----------------------------------------------------------------------===// |
| 1078 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1079 | DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1080 | return Deserialize(getGlobalVariable(V)); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1081 | } |
| 1082 | DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1083 | // Handle NULL. |
| 1084 | if (!GV) return NULL; |
| 1085 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1086 | // Check to see if it has been already deserialized. |
| 1087 | DebugInfoDesc *&Slot = GlobalDescs[GV]; |
| 1088 | if (Slot) return Slot; |
| 1089 | |
| 1090 | // Get the Tag from the global. |
| 1091 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
| 1092 | |
| 1093 | // Get the debug version if a compile unit. |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1094 | if (Tag == DW_TAG_compile_unit) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1095 | DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV); |
| 1096 | } |
| 1097 | |
| 1098 | // Create an empty instance of the correct sort. |
| 1099 | Slot = DebugInfoDesc::DescFactory(Tag); |
| 1100 | assert(Slot && "Unknown Tag"); |
| 1101 | |
| 1102 | // Deserialize the fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1103 | DIDeserializeVisitor DRAM(*this, GV); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1104 | DRAM.ApplyToFields(Slot); |
| 1105 | |
| 1106 | return Slot; |
| 1107 | } |
| 1108 | |
| 1109 | //===----------------------------------------------------------------------===// |
| 1110 | |
| 1111 | /// getStrPtrType - Return a "sbyte *" type. |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1112 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1113 | const PointerType *DISerializer::getStrPtrType() { |
| 1114 | // If not already defined. |
| 1115 | if (!StrPtrTy) { |
| 1116 | // Construct the pointer to signed bytes. |
| 1117 | StrPtrTy = PointerType::get(Type::SByteTy); |
| 1118 | } |
| 1119 | |
| 1120 | return StrPtrTy; |
| 1121 | } |
| 1122 | |
| 1123 | /// getEmptyStructPtrType - Return a "{ }*" type. |
| 1124 | /// |
| 1125 | const PointerType *DISerializer::getEmptyStructPtrType() { |
| 1126 | // If not already defined. |
| 1127 | if (!EmptyStructPtrTy) { |
| 1128 | // Construct the empty structure type. |
| 1129 | const StructType *EmptyStructTy = |
| 1130 | StructType::get(std::vector<const Type*>()); |
| 1131 | // Construct the pointer to empty structure type. |
| 1132 | EmptyStructPtrTy = PointerType::get(EmptyStructTy); |
| 1133 | } |
| 1134 | |
| 1135 | return EmptyStructPtrTy; |
| 1136 | } |
| 1137 | |
| 1138 | /// getTagType - Return the type describing the specified descriptor (via tag.) |
| 1139 | /// |
| 1140 | const StructType *DISerializer::getTagType(DebugInfoDesc *DD) { |
| 1141 | // Attempt to get the previously defined type. |
| 1142 | StructType *&Ty = TagTypes[DD->getTag()]; |
| 1143 | |
| 1144 | // If not already defined. |
| 1145 | if (!Ty) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1146 | // Set up fields vector. |
| 1147 | std::vector<const Type*> Fields; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1148 | // Get types of fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1149 | DIGetTypesVisitor GTAM(*this, Fields); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1150 | GTAM.ApplyToFields(DD); |
| 1151 | |
| 1152 | // Construct structured type. |
| 1153 | Ty = StructType::get(Fields); |
| 1154 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1155 | // Register type name with module. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1156 | M->addTypeName(DD->getTypeString(), Ty); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | return Ty; |
| 1160 | } |
| 1161 | |
| 1162 | /// getString - Construct the string as constant string global. |
| 1163 | /// |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1164 | Constant *DISerializer::getString(const std::string &String) { |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1165 | // Check string cache for previous edition. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1166 | Constant *&Slot = StringCache[String]; |
| 1167 | // return Constant if previously defined. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1168 | if (Slot) return Slot; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1169 | // Construct string as an llvm constant. |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1170 | Constant *ConstStr = ConstantArray::get(String); |
| 1171 | // Otherwise create and return a new string global. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1172 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 1173 | GlobalVariable::InternalLinkage, |
| 1174 | ConstStr, "str", M); |
| 1175 | // Convert to generic string pointer. |
| 1176 | Slot = ConstantExpr::getCast(StrGV, getStrPtrType()); |
| 1177 | return Slot; |
| 1178 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | /// Serialize - Recursively cast the specified descriptor into a GlobalVariable |
| 1182 | /// so that it can be serialized to a .bc or .ll file. |
| 1183 | GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) { |
| 1184 | // Check if the DebugInfoDesc is already in the map. |
| 1185 | GlobalVariable *&Slot = DescGlobals[DD]; |
| 1186 | |
| 1187 | // See if DebugInfoDesc exists, if so return prior GlobalVariable. |
| 1188 | if (Slot) return Slot; |
| 1189 | |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1190 | // Get the type associated with the Tag. |
| 1191 | const StructType *Ty = getTagType(DD); |
| 1192 | |
| 1193 | // Create the GlobalVariable early to prevent infinite recursion. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1194 | GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(), |
| 1195 | NULL, DD->getDescString(), M); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Insert new GlobalVariable in DescGlobals map. |
| 1198 | Slot = GV; |
| 1199 | |
| 1200 | // Set up elements vector |
| 1201 | std::vector<Constant*> Elements; |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1202 | // Add fields. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1203 | DISerializeVisitor SRAM(*this, Elements); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1204 | SRAM.ApplyToFields(DD); |
| 1205 | |
| 1206 | // Set the globals initializer. |
| 1207 | GV->setInitializer(ConstantStruct::get(Ty, Elements)); |
| 1208 | |
| 1209 | return GV; |
| 1210 | } |
| 1211 | |
| 1212 | //===----------------------------------------------------------------------===// |
| 1213 | |
| 1214 | /// markVisited - Return true if the GlobalVariable hase been "seen" before. |
| 1215 | /// Mark visited otherwise. |
| 1216 | bool DIVerifier::markVisited(GlobalVariable *GV) { |
| 1217 | // Check if the GlobalVariable is already in the Visited set. |
| 1218 | std::set<GlobalVariable *>::iterator VI = Visited.lower_bound(GV); |
| 1219 | |
| 1220 | // See if GlobalVariable exists. |
| 1221 | bool Exists = VI != Visited.end() && *VI == GV; |
| 1222 | |
| 1223 | // Insert in set. |
| 1224 | if (!Exists) Visited.insert(VI, GV); |
| 1225 | |
| 1226 | return Exists; |
| 1227 | } |
| 1228 | |
| 1229 | /// Verify - Return true if the GlobalVariable appears to be a valid |
| 1230 | /// serialization of a DebugInfoDesc. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1231 | bool DIVerifier::Verify(Value *V) { |
| 1232 | return Verify(getGlobalVariable(V)); |
| 1233 | } |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1234 | bool DIVerifier::Verify(GlobalVariable *GV) { |
| 1235 | // Check if seen before. |
| 1236 | if (markVisited(GV)) return true; |
| 1237 | |
| 1238 | // Get the Tag |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1239 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1240 | if (Tag == DW_TAG_invalid) return false; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1241 | |
| 1242 | // If a compile unit we need the debug version. |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1243 | if (Tag == DW_TAG_compile_unit) { |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1244 | DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV); |
Jim Laskey | 9c4447a | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1245 | if (DebugVersion == DW_TAG_invalid) return false; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | // Construct an empty DebugInfoDesc. |
| 1249 | DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag); |
| 1250 | if (!DD) return false; |
| 1251 | |
| 1252 | // Get the initializer constant. |
| 1253 | ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer()); |
| 1254 | |
| 1255 | // Get the operand count. |
| 1256 | unsigned N = CI->getNumOperands(); |
| 1257 | |
| 1258 | // Get the field count. |
| 1259 | unsigned &Slot = Counts[Tag]; |
| 1260 | if (!Slot) { |
| 1261 | // Check the operand count to the field count |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1262 | DICountVisitor CTAM; |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1263 | CTAM.ApplyToFields(DD); |
| 1264 | Slot = CTAM.getCount(); |
| 1265 | } |
| 1266 | |
| 1267 | // Field count must equal operand count. |
| 1268 | if (Slot != N) { |
| 1269 | delete DD; |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | // Check each field for valid type. |
Jim Laskey | c2f0c8d | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1274 | DIVerifyVisitor VRAM(*this, GV); |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1275 | VRAM.ApplyToFields(DD); |
| 1276 | |
| 1277 | // Release empty DebugInfoDesc. |
| 1278 | delete DD; |
| 1279 | |
| 1280 | // Return result of field tests. |
| 1281 | return VRAM.isValid(); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | //===----------------------------------------------------------------------===// |
| 1285 | |
| 1286 | |
| 1287 | MachineDebugInfo::MachineDebugInfo() |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1288 | : DR() |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1289 | , CompileUnits() |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1290 | , Directories() |
| 1291 | , SourceFiles() |
| 1292 | , Lines() |
| 1293 | { |
| 1294 | |
| 1295 | } |
| 1296 | MachineDebugInfo::~MachineDebugInfo() { |
| 1297 | |
| 1298 | } |
| 1299 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1300 | /// doInitialization - Initialize the debug state for a new module. |
| 1301 | /// |
| 1302 | bool MachineDebugInfo::doInitialization() { |
| 1303 | return false; |
Jim Laskey | 6af5681 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
Jim Laskey | b2efb85 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1306 | /// doFinalization - Tear down the debug state after completion of a module. |
| 1307 | /// |
| 1308 | bool MachineDebugInfo::doFinalization() { |
| 1309 | return false; |
| 1310 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1311 | |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1312 | /// getDescFor - Convert a Value to a debug information descriptor. |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1313 | /// |
Jim Laskey | d96185a | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1314 | // FIXME - use new Value type when available. |
| 1315 | DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) { |
Jim Laskey | ce72b17 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1316 | return DR.Deserialize(V); |
| 1317 | } |
| 1318 | |
| 1319 | /// Verify - Verify that a Value is debug information descriptor. |
| 1320 | /// |
| 1321 | bool MachineDebugInfo::Verify(Value *V) { |
| 1322 | DIVerifier VR; |
| 1323 | return VR.Verify(V); |
| 1324 | } |
| 1325 | |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1326 | /// AnalyzeModule - Scan the module for global debug information. |
| 1327 | /// |
| 1328 | void MachineDebugInfo::AnalyzeModule(Module &M) { |
| 1329 | SetupCompileUnits(M); |
| 1330 | } |
| 1331 | |
| 1332 | /// SetupCompileUnits - Set up the unique vector of compile units. |
| 1333 | /// |
| 1334 | void MachineDebugInfo::SetupCompileUnits(Module &M) { |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1335 | std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1336 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1337 | for (unsigned i = 0, N = CU.size(); i < N; i++) { |
| 1338 | CompileUnits.insert(CU[i]); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1339 | } |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1340 | } |
| 1341 | |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1342 | /// getCompileUnits - Return a vector of debug compile units. |
| 1343 | /// |
Jim Laskey | 86cbdba | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1344 | const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{ |
Jim Laskey | 6e87c0e | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1345 | return CompileUnits; |
| 1346 | } |
| 1347 | |
Jim Laskey | 0420f2a | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1348 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 1349 | /// named GlobalVariable. |
| 1350 | std::vector<GlobalVariable*> |
| 1351 | MachineDebugInfo::getGlobalVariablesUsing(Module &M, |
| 1352 | const std::string &RootName) { |
| 1353 | return ::getGlobalVariablesUsing(M, RootName); |
Jim Laskey | b3e789a | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1354 | } |