Jim Laskey | 4431739 | 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 | 4431739 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 9 | |
| 10 | #include "llvm/CodeGen/MachineDebugInfo.h" |
| 11 | |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 12 | #include "llvm/Constants.h" |
| 13 | #include "llvm/DerivedTypes.h" |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 14 | #include "llvm/GlobalVariable.h" |
Jim Laskey | 0bbdc55 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 20 | #include <iostream> |
| 21 | |
Jim Laskey | 4431739 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 23 | using namespace llvm::dwarf; |
Jim Laskey | 4431739 | 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 | 219d559 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 27 | RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information"); |
| 28 | } |
Jim Laskey | b996602 | 2006-01-17 17:31:53 +0000 | [diff] [blame] | 29 | |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 30 | //===----------------------------------------------------------------------===// |
| 31 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 32 | /// getGlobalVariablesUsing - Return all of the GlobalVariables which have the |
Jim Laskey | 0bbdc55 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 39 | // If the user is a GlobalVariable then add to result. |
Jim Laskey | 0bbdc55 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 48 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 49 | /// named GlobalVariable. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 50 | static std::vector<GlobalVariable*> |
| 51 | getGlobalVariablesUsing(Module &M, const std::string &RootName) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 52 | std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 53 | |
| 54 | std::vector<const Type*> FieldTypes; |
| 55 | FieldTypes.push_back(Type::UIntTy); |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 56 | FieldTypes.push_back(Type::UIntTy); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 57 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 58 | // Get the GlobalVariable root. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 59 | GlobalVariable *UseRoot = M.getGlobalVariable(RootName, |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 60 | StructType::get(FieldTypes)); |
Jim Laskey | 0bbdc55 | 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 | ecd7e61 | 2006-01-27 17:31:30 +0000 | [diff] [blame] | 73 | static const std::string getStringValue(Value *V, unsigned Offset = 0) { |
Jim Laskey | 0bbdc55 | 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 | f98fc84 | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 108 | |
Jim Laskey | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 133 | /// getGlobalVariable - Return either a direct or cast Global value. |
Jim Laskey | f98fc84 | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 134 | /// |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 135 | static GlobalVariable *getGlobalVariable(Value *V) { |
Jim Laskey | f98fc84 | 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 | 8526323 | 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 | f98fc84 | 2006-01-27 15:20:54 +0000 | [diff] [blame] | 142 | } |
| 143 | return NULL; |
| 144 | } |
| 145 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 146 | /// isGlobalVariable - Return true if the given value can be coerced to a |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 147 | /// GlobalVariable. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 148 | static bool isGlobalVariable(Value *V) { |
Jim Laskey | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 159 | /// getUIntOperand - Return ith operand if it is an unsigned integer. |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 160 | /// |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 161 | static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 162 | // Make sure the GlobalVariable has an initializer. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 163 | if (!GV->hasInitializer()) return NULL; |
Jim Laskey | 219d559 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 164 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 165 | // Get the initializer constant. |
| 166 | ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer()); |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 167 | if (!CI) return NULL; |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 168 | |
Jim Laskey | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 171 | if (i >= N) return NULL; |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 172 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 173 | // Check constant. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 174 | return dyn_cast<ConstantUInt>(CI->getOperand(i)); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 175 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 176 | //===----------------------------------------------------------------------===// |
| 177 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 178 | /// ApplyToFields - Target the visitor to each field of the debug information |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 179 | /// descriptor. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 180 | void DIVisitor::ApplyToFields(DebugInfoDesc *DD) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 181 | DD->ApplyToFields(this); |
| 182 | } |
| 183 | |
| 184 | //===----------------------------------------------------------------------===// |
Jim Laskey | b643ff5 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 188 | private: |
| 189 | unsigned Count; // Running count of fields. |
| 190 | |
| 191 | public: |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 192 | DICountVisitor() : DIVisitor(), Count(0) {} |
Jim Laskey | 8526323 | 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 | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 201 | virtual void Apply(int64_t &Field) { ++Count; } |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 202 | virtual void Apply(uint64_t &Field) { ++Count; } |
Jim Laskey | 8526323 | 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 | 716edb9 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 207 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 208 | ++Count; |
| 209 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | //===----------------------------------------------------------------------===// |
Jim Laskey | b643ff5 | 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 | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 222 | DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV) |
| 223 | : DIVisitor() |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 224 | , DR(D) |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 225 | , I(0) |
Jim Laskey | 8526323 | 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 | b9ac4cb | 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 | 69b9e26 | 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 | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 261 | Field = getGlobalVariable(C); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 262 | } |
Jim Laskey | 716edb9 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 274 | }; |
| 275 | |
| 276 | //===----------------------------------------------------------------------===// |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 277 | /// DISerializeVisitor - This DIVisitor serializes all the fields in |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 278 | /// the supplied DebugInfoDesc. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 279 | class DISerializeVisitor : public DIVisitor { |
Jim Laskey | 8526323 | 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 | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 285 | DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E) |
| 286 | : DIVisitor() |
Jim Laskey | 8526323 | 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 | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 294 | Elements.push_back(ConstantSInt::get(Type::IntTy, Field)); |
Jim Laskey | 8526323 | 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 | b9ac4cb | 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 | 69b9e26 | 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 | 8526323 | 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 | 5995d01 | 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 | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 335 | } |
Jim Laskey | 716edb9 | 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 | b9ac4cb | 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()); |
Jim Laskey | 313570f | 2006-03-07 22:00:35 +0000 | [diff] [blame^] | 353 | CAGV->setSection("llvm.metadata"); |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 354 | Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy); |
Jim Laskey | 716edb9 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 355 | Elements.push_back(CAE); |
| 356 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | //===----------------------------------------------------------------------===// |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 360 | /// DIGetTypesVisitor - This DIVisitor gathers all the field types in |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 361 | /// the supplied DebugInfoDesc. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 362 | class DIGetTypesVisitor : public DIVisitor { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 363 | private: |
| 364 | DISerializer &SR; // Active serializer. |
| 365 | std::vector<const Type*> &Fields; // Type accumulator. |
| 366 | |
| 367 | public: |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 368 | DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F) |
| 369 | : DIVisitor() |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 370 | , SR(S) |
| 371 | , Fields(F) |
| 372 | {} |
| 373 | |
| 374 | /// Apply - Set the value of each of the fields. |
| 375 | /// |
| 376 | virtual void Apply(int &Field) { |
| 377 | Fields.push_back(Type::IntTy); |
| 378 | } |
| 379 | virtual void Apply(unsigned &Field) { |
| 380 | Fields.push_back(Type::UIntTy); |
| 381 | } |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 382 | virtual void Apply(int64_t &Field) { |
| 383 | Fields.push_back(Type::IntTy); |
| 384 | } |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 385 | virtual void Apply(uint64_t &Field) { |
| 386 | Fields.push_back(Type::UIntTy); |
| 387 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 388 | virtual void Apply(bool &Field) { |
| 389 | Fields.push_back(Type::BoolTy); |
| 390 | } |
| 391 | virtual void Apply(std::string &Field) { |
| 392 | Fields.push_back(SR.getStrPtrType()); |
| 393 | } |
| 394 | virtual void Apply(DebugInfoDesc *&Field) { |
| 395 | // FIXME - At some point should use specific type. |
| 396 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 397 | Fields.push_back(EmptyTy); |
| 398 | } |
| 399 | virtual void Apply(GlobalVariable *&Field) { |
| 400 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 401 | Fields.push_back(EmptyTy); |
| 402 | } |
Jim Laskey | 716edb9 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 403 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 404 | const PointerType *EmptyTy = SR.getEmptyStructPtrType(); |
| 405 | Fields.push_back(EmptyTy); |
| 406 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | //===----------------------------------------------------------------------===// |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 410 | /// DIVerifyVisitor - This DIVisitor verifies all the field types against |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 411 | /// a constant initializer. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 412 | class DIVerifyVisitor : public DIVisitor { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 413 | private: |
| 414 | DIVerifier &VR; // Active verifier. |
| 415 | bool IsValid; // Validity status. |
| 416 | unsigned I; // Current operand index. |
| 417 | ConstantStruct *CI; // GlobalVariable constant initializer. |
| 418 | |
| 419 | public: |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 420 | DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV) |
| 421 | : DIVisitor() |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 422 | , VR(V) |
| 423 | , IsValid(true) |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 424 | , I(0) |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 425 | , CI(cast<ConstantStruct>(GV->getInitializer())) |
| 426 | { |
| 427 | } |
| 428 | |
| 429 | // Accessors. |
| 430 | bool isValid() const { return IsValid; } |
| 431 | |
| 432 | /// Apply - Set the value of each of the fields. |
| 433 | /// |
| 434 | virtual void Apply(int &Field) { |
| 435 | Constant *C = CI->getOperand(I++); |
| 436 | IsValid = IsValid && isa<ConstantInt>(C); |
| 437 | } |
| 438 | virtual void Apply(unsigned &Field) { |
| 439 | Constant *C = CI->getOperand(I++); |
| 440 | IsValid = IsValid && isa<ConstantInt>(C); |
| 441 | } |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 442 | virtual void Apply(int64_t &Field) { |
| 443 | Constant *C = CI->getOperand(I++); |
| 444 | IsValid = IsValid && isa<ConstantInt>(C); |
| 445 | } |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 446 | virtual void Apply(uint64_t &Field) { |
| 447 | Constant *C = CI->getOperand(I++); |
| 448 | IsValid = IsValid && isa<ConstantInt>(C); |
| 449 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 450 | virtual void Apply(bool &Field) { |
| 451 | Constant *C = CI->getOperand(I++); |
| 452 | IsValid = IsValid && isa<ConstantBool>(C); |
| 453 | } |
| 454 | virtual void Apply(std::string &Field) { |
| 455 | Constant *C = CI->getOperand(I++); |
| 456 | IsValid = IsValid && isStringValue(C); |
| 457 | } |
| 458 | virtual void Apply(DebugInfoDesc *&Field) { |
| 459 | // FIXME - Prepare the correct descriptor. |
| 460 | Constant *C = CI->getOperand(I++); |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 461 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 462 | } |
| 463 | virtual void Apply(GlobalVariable *&Field) { |
| 464 | Constant *C = CI->getOperand(I++); |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 465 | IsValid = IsValid && isGlobalVariable(C); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 466 | } |
Jim Laskey | 716edb9 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 467 | virtual void Apply(std::vector<DebugInfoDesc *> &Field) { |
| 468 | Constant *C = CI->getOperand(I++); |
| 469 | IsValid = IsValid && isGlobalVariable(C); |
| 470 | if (!IsValid) return; |
| 471 | |
| 472 | GlobalVariable *GV = getGlobalVariable(C); |
| 473 | IsValid = IsValid && GV && GV->hasInitializer(); |
| 474 | if (!IsValid) return; |
| 475 | |
| 476 | ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer()); |
| 477 | IsValid = IsValid && CA; |
| 478 | if (!IsValid) return; |
| 479 | |
| 480 | for (unsigned i = 0, N = CA->getNumOperands(); IsValid && i < N; ++i) { |
| 481 | IsValid = IsValid && isGlobalVariable(CA->getOperand(i)); |
| 482 | if (!IsValid) return; |
| 483 | |
| 484 | GlobalVariable *GVE = getGlobalVariable(CA->getOperand(i)); |
| 485 | VR.Verify(GVE); |
| 486 | } |
| 487 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 488 | }; |
| 489 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 490 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 491 | //===----------------------------------------------------------------------===// |
| 492 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 493 | /// TagFromGlobal - Returns the Tag number from a debug info descriptor |
| 494 | /// GlobalVariable. |
| 495 | unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) { |
| 496 | ConstantUInt *C = getUIntOperand(GV, 0); |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 497 | return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /// DescFactory - Create an instance of debug info descriptor based on Tag. |
| 501 | /// Return NULL if not a recognized Tag. |
| 502 | DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) { |
| 503 | switch (Tag) { |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 504 | case DW_TAG_anchor: return new AnchorDesc(); |
| 505 | case DW_TAG_compile_unit: return new CompileUnitDesc(); |
| 506 | case DW_TAG_variable: return new GlobalVariableDesc(); |
| 507 | case DW_TAG_subprogram: return new SubprogramDesc(); |
| 508 | case DW_TAG_base_type: return new BasicTypeDesc(); |
| 509 | case DW_TAG_typedef: |
| 510 | case DW_TAG_pointer_type: |
| 511 | case DW_TAG_reference_type: |
| 512 | case DW_TAG_const_type: |
| 513 | case DW_TAG_volatile_type: |
| 514 | case DW_TAG_restrict_type: return new DerivedTypeDesc(Tag); |
| 515 | case DW_TAG_array_type: |
| 516 | case DW_TAG_structure_type: |
| 517 | case DW_TAG_union_type: |
| 518 | case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag); |
| 519 | case DW_TAG_subrange_type: return new SubrangeDesc(); |
Jim Laskey | 88f0fe1 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 520 | case DW_TAG_member: return new DerivedTypeDesc(DW_TAG_member); |
Jim Laskey | 862001a | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 521 | case DW_TAG_enumerator: return new EnumeratorDesc(); |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 522 | default: break; |
| 523 | } |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 528 | /// |
| 529 | GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const { |
| 530 | return GlobalValue::InternalLinkage; |
| 531 | } |
| 532 | |
| 533 | /// ApplyToFields - Target the vistor to the fields of the descriptor. |
| 534 | /// |
| 535 | void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) { |
| 536 | Visitor->Apply(Tag); |
| 537 | } |
| 538 | |
| 539 | //===----------------------------------------------------------------------===// |
| 540 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 541 | AnchorDesc::AnchorDesc() |
| 542 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 543 | , AnchorTag(0) |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 544 | {} |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 545 | AnchorDesc::AnchorDesc(AnchoredDesc *D) |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 546 | : DebugInfoDesc(DW_TAG_anchor) |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 547 | , AnchorTag(D->getTag()) |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 548 | {} |
| 549 | |
| 550 | // Implement isa/cast/dyncast. |
| 551 | bool AnchorDesc::classof(const DebugInfoDesc *D) { |
| 552 | return D->getTag() == DW_TAG_anchor; |
| 553 | } |
| 554 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 555 | /// getLinkage - get linkage appropriate for this type of descriptor. |
| 556 | /// |
| 557 | GlobalValue::LinkageTypes AnchorDesc::getLinkage() const { |
| 558 | return GlobalValue::LinkOnceLinkage; |
| 559 | } |
| 560 | |
| 561 | /// ApplyToFields - Target the visitor to the fields of the TransUnitDesc. |
| 562 | /// |
| 563 | void AnchorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 564 | DebugInfoDesc::ApplyToFields(Visitor); |
| 565 | |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 566 | Visitor->Apply(AnchorTag); |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 567 | } |
| 568 | |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 569 | /// getDescString - Return a string used to compose global names and labels. A |
| 570 | /// A global variable name needs to be defined for each debug descriptor that is |
| 571 | /// anchored. NOTE: that each global variable name here also needs to be added |
| 572 | /// to the list of names left external in the internalizer. |
| 573 | /// ExternalNames.insert("llvm.dbg.compile_units"); |
| 574 | /// ExternalNames.insert("llvm.dbg.global_variables"); |
| 575 | /// ExternalNames.insert("llvm.dbg.subprograms"); |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 576 | const char *AnchorDesc::getDescString() const { |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 577 | switch (AnchorTag) { |
| 578 | case DW_TAG_compile_unit: return CompileUnitDesc::AnchorString; |
| 579 | case DW_TAG_variable: return GlobalVariableDesc::AnchorString; |
| 580 | case DW_TAG_subprogram: return SubprogramDesc::AnchorString; |
| 581 | default: break; |
| 582 | } |
| 583 | |
| 584 | assert(0 && "Tag does not have a case for anchor string"); |
| 585 | return ""; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /// getTypeString - Return a string used to label this descriptors type. |
| 589 | /// |
| 590 | const char *AnchorDesc::getTypeString() const { |
| 591 | return "llvm.dbg.anchor.type"; |
| 592 | } |
| 593 | |
| 594 | #ifndef NDEBUG |
| 595 | void AnchorDesc::dump() { |
| 596 | std::cerr << getDescString() << " " |
| 597 | << "Tag(" << getTag() << "), " |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 598 | << "AnchorTag(" << AnchorTag << ")\n"; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 599 | } |
| 600 | #endif |
| 601 | |
| 602 | //===----------------------------------------------------------------------===// |
| 603 | |
| 604 | AnchoredDesc::AnchoredDesc(unsigned T) |
| 605 | : DebugInfoDesc(T) |
| 606 | , Anchor(NULL) |
| 607 | {} |
| 608 | |
| 609 | /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc. |
| 610 | /// |
| 611 | void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) { |
| 612 | DebugInfoDesc::ApplyToFields(Visitor); |
| 613 | |
| 614 | Visitor->Apply((DebugInfoDesc *&)Anchor); |
| 615 | } |
| 616 | |
| 617 | //===----------------------------------------------------------------------===// |
| 618 | |
| 619 | CompileUnitDesc::CompileUnitDesc() |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 620 | : AnchoredDesc(DW_TAG_compile_unit) |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 621 | , DebugVersion(LLVMDebugVersion) |
| 622 | , Language(0) |
| 623 | , FileName("") |
| 624 | , Directory("") |
| 625 | , Producer("") |
| 626 | {} |
| 627 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 628 | // Implement isa/cast/dyncast. |
| 629 | bool CompileUnitDesc::classof(const DebugInfoDesc *D) { |
| 630 | return D->getTag() == DW_TAG_compile_unit; |
| 631 | } |
| 632 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 633 | /// DebugVersionFromGlobal - Returns the version number from a compile unit |
| 634 | /// GlobalVariable. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 635 | unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 636 | ConstantUInt *C = getUIntOperand(GV, 2); |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 637 | return C ? (unsigned)C->getValue() : (unsigned)DW_TAG_invalid; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 640 | /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. |
| 641 | /// |
| 642 | void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 643 | AnchoredDesc::ApplyToFields(Visitor); |
| 644 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 645 | Visitor->Apply(DebugVersion); |
| 646 | Visitor->Apply(Language); |
| 647 | Visitor->Apply(FileName); |
| 648 | Visitor->Apply(Directory); |
| 649 | Visitor->Apply(Producer); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 652 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 653 | /// |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 654 | const char *CompileUnitDesc::getDescString() const { |
| 655 | return "llvm.dbg.compile_unit"; |
| 656 | } |
| 657 | |
| 658 | /// getTypeString - Return a string used to label this descriptors type. |
| 659 | /// |
| 660 | const char *CompileUnitDesc::getTypeString() const { |
| 661 | return "llvm.dbg.compile_unit.type"; |
| 662 | } |
| 663 | |
| 664 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 665 | /// |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 666 | const char *CompileUnitDesc::AnchorString = "llvm.dbg.compile_units"; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 667 | const char *CompileUnitDesc::getAnchorString() const { |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 668 | return AnchorString; |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 669 | } |
| 670 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 671 | #ifndef NDEBUG |
| 672 | void CompileUnitDesc::dump() { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 673 | std::cerr << getDescString() << " " |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 674 | << "Tag(" << getTag() << "), " |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 675 | << "Anchor(" << getAnchor() << "), " |
| 676 | << "DebugVersion(" << DebugVersion << "), " |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 677 | << "Language(" << Language << "), " |
| 678 | << "FileName(\"" << FileName << "\"), " |
| 679 | << "Directory(\"" << Directory << "\"), " |
| 680 | << "Producer(\"" << Producer << "\")\n"; |
| 681 | } |
| 682 | #endif |
| 683 | |
| 684 | //===----------------------------------------------------------------------===// |
| 685 | |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 686 | TypeDesc::TypeDesc(unsigned T) |
| 687 | : DebugInfoDesc(T) |
| 688 | , Context(NULL) |
| 689 | , Name("") |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 690 | , File(NULL) |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 691 | , Size(0) |
Jim Laskey | 88f0fe1 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 692 | , Offset(0) |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 693 | {} |
| 694 | |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 695 | /// ApplyToFields - Target the visitor to the fields of the TypeDesc. |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 696 | /// |
| 697 | void TypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 698 | DebugInfoDesc::ApplyToFields(Visitor); |
| 699 | |
| 700 | Visitor->Apply(Context); |
| 701 | Visitor->Apply(Name); |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 702 | Visitor->Apply((DebugInfoDesc *&)File); |
| 703 | Visitor->Apply(Line); |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 704 | Visitor->Apply(Size); |
Jim Laskey | 88f0fe1 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 705 | Visitor->Apply(Offset); |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /// getDescString - Return a string used to compose global names and labels. |
| 709 | /// |
| 710 | const char *TypeDesc::getDescString() const { |
| 711 | return "llvm.dbg.type"; |
| 712 | } |
| 713 | |
| 714 | /// getTypeString - Return a string used to label this descriptor's type. |
| 715 | /// |
| 716 | const char *TypeDesc::getTypeString() const { |
| 717 | return "llvm.dbg.type.type"; |
| 718 | } |
| 719 | |
| 720 | #ifndef NDEBUG |
| 721 | void TypeDesc::dump() { |
| 722 | std::cerr << getDescString() << " " |
| 723 | << "Tag(" << getTag() << "), " |
| 724 | << "Context(" << Context << "), " |
| 725 | << "Name(\"" << Name << "\"), " |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 726 | << "File(" << File << "), " |
| 727 | << "Line(" << Line << "), " |
Jim Laskey | 88f0fe1 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 728 | << "Size(" << Size << "), " |
| 729 | << "Offset(" << Offset << ")\n"; |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 730 | } |
| 731 | #endif |
| 732 | |
| 733 | //===----------------------------------------------------------------------===// |
| 734 | |
| 735 | BasicTypeDesc::BasicTypeDesc() |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 736 | : TypeDesc(DW_TAG_base_type) |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 737 | , Encoding(0) |
| 738 | {} |
| 739 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 740 | // Implement isa/cast/dyncast. |
| 741 | bool BasicTypeDesc::classof(const DebugInfoDesc *D) { |
| 742 | return D->getTag() == DW_TAG_base_type; |
| 743 | } |
| 744 | |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 745 | /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc. |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 746 | /// |
| 747 | void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 748 | TypeDesc::ApplyToFields(Visitor); |
| 749 | |
| 750 | Visitor->Apply(Encoding); |
| 751 | } |
| 752 | |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 753 | /// getDescString - Return a string used to compose global names and labels. |
| 754 | /// |
| 755 | const char *BasicTypeDesc::getDescString() const { |
| 756 | return "llvm.dbg.basictype"; |
| 757 | } |
| 758 | |
| 759 | /// getTypeString - Return a string used to label this descriptor's type. |
| 760 | /// |
| 761 | const char *BasicTypeDesc::getTypeString() const { |
| 762 | return "llvm.dbg.basictype.type"; |
| 763 | } |
| 764 | |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 765 | #ifndef NDEBUG |
| 766 | void BasicTypeDesc::dump() { |
| 767 | std::cerr << getDescString() << " " |
| 768 | << "Tag(" << getTag() << "), " |
| 769 | << "Context(" << getContext() << "), " |
| 770 | << "Name(\"" << getName() << "\"), " |
| 771 | << "Size(" << getSize() << "), " |
| 772 | << "Encoding(" << Encoding << ")\n"; |
| 773 | } |
| 774 | #endif |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 775 | |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 776 | //===----------------------------------------------------------------------===// |
| 777 | |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 778 | DerivedTypeDesc::DerivedTypeDesc(unsigned T) |
| 779 | : TypeDesc(T) |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 780 | , FromType(NULL) |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 781 | {} |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 782 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 783 | // Implement isa/cast/dyncast. |
| 784 | bool DerivedTypeDesc::classof(const DebugInfoDesc *D) { |
| 785 | unsigned T = D->getTag(); |
| 786 | switch (T) { |
| 787 | case DW_TAG_typedef: |
| 788 | case DW_TAG_pointer_type: |
| 789 | case DW_TAG_reference_type: |
| 790 | case DW_TAG_const_type: |
| 791 | case DW_TAG_volatile_type: |
| 792 | case DW_TAG_restrict_type: |
Jim Laskey | 88f0fe1 | 2006-03-03 15:06:57 +0000 | [diff] [blame] | 793 | case DW_TAG_member: |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 794 | return true; |
| 795 | default: break; |
| 796 | } |
| 797 | return false; |
| 798 | } |
| 799 | |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 800 | /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc. |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 801 | /// |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 802 | void DerivedTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 803 | TypeDesc::ApplyToFields(Visitor); |
| 804 | |
| 805 | Visitor->Apply((DebugInfoDesc *&)FromType); |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 806 | } |
| 807 | |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 808 | /// getDescString - Return a string used to compose global names and labels. |
| 809 | /// |
| 810 | const char *DerivedTypeDesc::getDescString() const { |
| 811 | return "llvm.dbg.derivedtype"; |
| 812 | } |
| 813 | |
| 814 | /// getTypeString - Return a string used to label this descriptor's type. |
| 815 | /// |
| 816 | const char *DerivedTypeDesc::getTypeString() const { |
| 817 | return "llvm.dbg.derivedtype.type"; |
| 818 | } |
| 819 | |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 820 | #ifndef NDEBUG |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 821 | void DerivedTypeDesc::dump() { |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 822 | std::cerr << getDescString() << " " |
| 823 | << "Tag(" << getTag() << "), " |
| 824 | << "Context(" << getContext() << "), " |
| 825 | << "Name(\"" << getName() << "\"), " |
| 826 | << "Size(" << getSize() << "), " |
Jim Laskey | 723d3e0 | 2006-02-24 16:46:40 +0000 | [diff] [blame] | 827 | << "File(" << getFile() << "), " |
| 828 | << "Line(" << getLine() << "), " |
| 829 | << "FromType(" << FromType << ")\n"; |
Jim Laskey | e5386d4 | 2006-02-23 22:37:30 +0000 | [diff] [blame] | 830 | } |
| 831 | #endif |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 832 | |
| 833 | //===----------------------------------------------------------------------===// |
| 834 | |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 835 | CompositeTypeDesc::CompositeTypeDesc(unsigned T) |
| 836 | : DerivedTypeDesc(T) |
| 837 | , Elements() |
| 838 | {} |
| 839 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 840 | // Implement isa/cast/dyncast. |
| 841 | bool CompositeTypeDesc::classof(const DebugInfoDesc *D) { |
| 842 | unsigned T = D->getTag(); |
| 843 | switch (T) { |
| 844 | case DW_TAG_array_type: |
| 845 | case DW_TAG_structure_type: |
| 846 | case DW_TAG_union_type: |
| 847 | case DW_TAG_enumeration_type: |
| 848 | return true; |
| 849 | default: break; |
| 850 | } |
| 851 | return false; |
| 852 | } |
| 853 | |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 854 | /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc. |
| 855 | /// |
| 856 | void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 857 | DerivedTypeDesc::ApplyToFields(Visitor); |
| 858 | |
| 859 | Visitor->Apply(Elements); |
| 860 | } |
| 861 | |
| 862 | /// getDescString - Return a string used to compose global names and labels. |
| 863 | /// |
| 864 | const char *CompositeTypeDesc::getDescString() const { |
| 865 | return "llvm.dbg.compositetype"; |
| 866 | } |
| 867 | |
| 868 | /// getTypeString - Return a string used to label this descriptor's type. |
| 869 | /// |
| 870 | const char *CompositeTypeDesc::getTypeString() const { |
| 871 | return "llvm.dbg.compositetype.type"; |
| 872 | } |
| 873 | |
| 874 | #ifndef NDEBUG |
| 875 | void CompositeTypeDesc::dump() { |
| 876 | std::cerr << getDescString() << " " |
| 877 | << "Tag(" << getTag() << "), " |
| 878 | << "Context(" << getContext() << "), " |
| 879 | << "Name(\"" << getName() << "\"), " |
| 880 | << "Size(" << getSize() << "), " |
| 881 | << "File(" << getFile() << "), " |
| 882 | << "Line(" << getLine() << "), " |
| 883 | << "FromType(" << getFromType() << "), " |
| 884 | << "Elements.size(" << Elements.size() << ")\n"; |
| 885 | } |
| 886 | #endif |
| 887 | |
| 888 | //===----------------------------------------------------------------------===// |
| 889 | |
| 890 | SubrangeDesc::SubrangeDesc() |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 891 | : DebugInfoDesc(DW_TAG_subrange_type) |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 892 | , Lo(0) |
| 893 | , Hi(0) |
| 894 | {} |
| 895 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 896 | // Implement isa/cast/dyncast. |
| 897 | bool SubrangeDesc::classof(const DebugInfoDesc *D) { |
| 898 | return D->getTag() == DW_TAG_subrange_type; |
| 899 | } |
| 900 | |
Jim Laskey | b9ac4cb | 2006-03-01 17:53:02 +0000 | [diff] [blame] | 901 | /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc. |
| 902 | /// |
| 903 | void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) { |
| 904 | DebugInfoDesc::ApplyToFields(Visitor); |
| 905 | |
| 906 | Visitor->Apply(Lo); |
| 907 | Visitor->Apply(Hi); |
| 908 | } |
| 909 | |
| 910 | /// getDescString - Return a string used to compose global names and labels. |
| 911 | /// |
| 912 | const char *SubrangeDesc::getDescString() const { |
| 913 | return "llvm.dbg.subrange"; |
| 914 | } |
| 915 | |
| 916 | /// getTypeString - Return a string used to label this descriptor's type. |
| 917 | /// |
| 918 | const char *SubrangeDesc::getTypeString() const { |
| 919 | return "llvm.dbg.subrange.type"; |
| 920 | } |
| 921 | |
| 922 | #ifndef NDEBUG |
| 923 | void SubrangeDesc::dump() { |
| 924 | std::cerr << getDescString() << " " |
| 925 | << "Tag(" << getTag() << "), " |
| 926 | << "Lo(" << Lo << "), " |
| 927 | << "Hi(" << Hi << ")\n"; |
| 928 | } |
| 929 | #endif |
| 930 | |
| 931 | //===----------------------------------------------------------------------===// |
| 932 | |
Jim Laskey | 862001a | 2006-03-01 23:52:37 +0000 | [diff] [blame] | 933 | EnumeratorDesc::EnumeratorDesc() |
| 934 | : DebugInfoDesc(DW_TAG_enumerator) |
| 935 | , Name("") |
| 936 | , Value(0) |
| 937 | {} |
| 938 | |
| 939 | // Implement isa/cast/dyncast. |
| 940 | bool EnumeratorDesc::classof(const DebugInfoDesc *D) { |
| 941 | return D->getTag() == DW_TAG_enumerator; |
| 942 | } |
| 943 | |
| 944 | /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc. |
| 945 | /// |
| 946 | void EnumeratorDesc::ApplyToFields(DIVisitor *Visitor) { |
| 947 | DebugInfoDesc::ApplyToFields(Visitor); |
| 948 | |
| 949 | Visitor->Apply(Name); |
| 950 | Visitor->Apply(Value); |
| 951 | } |
| 952 | |
| 953 | /// getDescString - Return a string used to compose global names and labels. |
| 954 | /// |
| 955 | const char *EnumeratorDesc::getDescString() const { |
| 956 | return "llvm.dbg.enumerator"; |
| 957 | } |
| 958 | |
| 959 | /// getTypeString - Return a string used to label this descriptor's type. |
| 960 | /// |
| 961 | const char *EnumeratorDesc::getTypeString() const { |
| 962 | return "llvm.dbg.enumerator.type"; |
| 963 | } |
| 964 | |
| 965 | #ifndef NDEBUG |
| 966 | void EnumeratorDesc::dump() { |
| 967 | std::cerr << getDescString() << " " |
| 968 | << "Tag(" << getTag() << "), " |
| 969 | << "Name(" << Name << "), " |
| 970 | << "Value(" << Value << ")\n"; |
| 971 | } |
| 972 | #endif |
| 973 | |
| 974 | //===----------------------------------------------------------------------===// |
| 975 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 976 | GlobalDesc::GlobalDesc(unsigned T) |
| 977 | : AnchoredDesc(T) |
| 978 | , Context(0) |
| 979 | , Name("") |
| 980 | , TyDesc(NULL) |
| 981 | , IsStatic(false) |
| 982 | , IsDefinition(false) |
| 983 | {} |
| 984 | |
| 985 | /// ApplyToFields - Target the visitor to the fields of the global. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 986 | /// |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 987 | void GlobalDesc::ApplyToFields(DIVisitor *Visitor) { |
| 988 | AnchoredDesc::ApplyToFields(Visitor); |
| 989 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 990 | Visitor->Apply(Context); |
| 991 | Visitor->Apply(Name); |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 992 | Visitor->Apply((DebugInfoDesc *&)TyDesc); |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 993 | Visitor->Apply(IsStatic); |
| 994 | Visitor->Apply(IsDefinition); |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | //===----------------------------------------------------------------------===// |
| 998 | |
| 999 | GlobalVariableDesc::GlobalVariableDesc() |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1000 | : GlobalDesc(DW_TAG_variable) |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1001 | , Global(NULL) |
| 1002 | {} |
| 1003 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1004 | // Implement isa/cast/dyncast. |
| 1005 | bool GlobalVariableDesc::classof(const DebugInfoDesc *D) { |
| 1006 | return D->getTag() == DW_TAG_variable; |
| 1007 | } |
| 1008 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1009 | /// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. |
| 1010 | /// |
| 1011 | void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { |
| 1012 | GlobalDesc::ApplyToFields(Visitor); |
| 1013 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1014 | Visitor->Apply(Global); |
Jim Laskey | 2fa33a9 | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1015 | Visitor->Apply(Line); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1018 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1019 | /// |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1020 | const char *GlobalVariableDesc::getDescString() const { |
| 1021 | return "llvm.dbg.global_variable"; |
| 1022 | } |
| 1023 | |
| 1024 | /// getTypeString - Return a string used to label this descriptors type. |
| 1025 | /// |
| 1026 | const char *GlobalVariableDesc::getTypeString() const { |
| 1027 | return "llvm.dbg.global_variable.type"; |
| 1028 | } |
| 1029 | |
| 1030 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1031 | /// |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1032 | const char *GlobalVariableDesc::AnchorString = "llvm.dbg.global_variables"; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1033 | const char *GlobalVariableDesc::getAnchorString() const { |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1034 | return AnchorString; |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1037 | #ifndef NDEBUG |
| 1038 | void GlobalVariableDesc::dump() { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1039 | std::cerr << getDescString() << " " |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1040 | << "Tag(" << getTag() << "), " |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1041 | << "Anchor(" << getAnchor() << "), " |
| 1042 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 1043 | << "Type(\"" << getTypeDesc() << "\"), " |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1044 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1045 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " |
Jim Laskey | 2fa33a9 | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1046 | << "Global(" << Global << "), " |
| 1047 | << "Line(" << Line << ")\n"; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1048 | } |
| 1049 | #endif |
| 1050 | |
| 1051 | //===----------------------------------------------------------------------===// |
| 1052 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1053 | SubprogramDesc::SubprogramDesc() |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1054 | : GlobalDesc(DW_TAG_subprogram) |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1055 | {} |
| 1056 | |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1057 | // Implement isa/cast/dyncast. |
| 1058 | bool SubprogramDesc::classof(const DebugInfoDesc *D) { |
| 1059 | return D->getTag() == DW_TAG_subprogram; |
| 1060 | } |
| 1061 | |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1062 | /// ApplyToFields - Target the visitor to the fields of the |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1063 | /// SubprogramDesc. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1064 | void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1065 | GlobalDesc::ApplyToFields(Visitor); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1068 | /// getDescString - Return a string used to compose global names and labels. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1069 | /// |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1070 | const char *SubprogramDesc::getDescString() const { |
| 1071 | return "llvm.dbg.subprogram"; |
| 1072 | } |
| 1073 | |
| 1074 | /// getTypeString - Return a string used to label this descriptors type. |
| 1075 | /// |
| 1076 | const char *SubprogramDesc::getTypeString() const { |
| 1077 | return "llvm.dbg.subprogram.type"; |
| 1078 | } |
| 1079 | |
| 1080 | /// getAnchorString - Return a string used to label this descriptor's anchor. |
| 1081 | /// |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1082 | const char *SubprogramDesc::AnchorString = "llvm.dbg.subprograms"; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1083 | const char *SubprogramDesc::getAnchorString() const { |
Jim Laskey | 69effa2 | 2006-03-07 20:53:47 +0000 | [diff] [blame] | 1084 | return AnchorString; |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1087 | #ifndef NDEBUG |
| 1088 | void SubprogramDesc::dump() { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1089 | std::cerr << getDescString() << " " |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1090 | << "Tag(" << getTag() << "), " |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1091 | << "Anchor(" << getAnchor() << "), " |
| 1092 | << "Name(\"" << getName() << "\"), " |
Jim Laskey | 69b9e26 | 2006-02-23 16:58:18 +0000 | [diff] [blame] | 1093 | << "Type(\"" << getTypeDesc() << "\"), " |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1094 | << "IsStatic(" << (isStatic() ? "true" : "false") << "), " |
| 1095 | << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1096 | } |
| 1097 | #endif |
| 1098 | |
Jim Laskey | 716edb9 | 2006-02-28 20:15:07 +0000 | [diff] [blame] | 1099 | //===----------------------------------------------------------------------===// |
| 1100 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1101 | DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1102 | return Deserialize(getGlobalVariable(V)); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1103 | } |
| 1104 | DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1105 | // Handle NULL. |
| 1106 | if (!GV) return NULL; |
| 1107 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1108 | // Check to see if it has been already deserialized. |
| 1109 | DebugInfoDesc *&Slot = GlobalDescs[GV]; |
| 1110 | if (Slot) return Slot; |
| 1111 | |
| 1112 | // Get the Tag from the global. |
| 1113 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
| 1114 | |
| 1115 | // Get the debug version if a compile unit. |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1116 | if (Tag == DW_TAG_compile_unit) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1117 | DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV); |
| 1118 | } |
| 1119 | |
| 1120 | // Create an empty instance of the correct sort. |
| 1121 | Slot = DebugInfoDesc::DescFactory(Tag); |
| 1122 | assert(Slot && "Unknown Tag"); |
| 1123 | |
| 1124 | // Deserialize the fields. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1125 | DIDeserializeVisitor DRAM(*this, GV); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1126 | DRAM.ApplyToFields(Slot); |
| 1127 | |
| 1128 | return Slot; |
| 1129 | } |
| 1130 | |
| 1131 | //===----------------------------------------------------------------------===// |
| 1132 | |
| 1133 | /// getStrPtrType - Return a "sbyte *" type. |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1134 | /// |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1135 | const PointerType *DISerializer::getStrPtrType() { |
| 1136 | // If not already defined. |
| 1137 | if (!StrPtrTy) { |
| 1138 | // Construct the pointer to signed bytes. |
| 1139 | StrPtrTy = PointerType::get(Type::SByteTy); |
| 1140 | } |
| 1141 | |
| 1142 | return StrPtrTy; |
| 1143 | } |
| 1144 | |
| 1145 | /// getEmptyStructPtrType - Return a "{ }*" type. |
| 1146 | /// |
| 1147 | const PointerType *DISerializer::getEmptyStructPtrType() { |
| 1148 | // If not already defined. |
| 1149 | if (!EmptyStructPtrTy) { |
| 1150 | // Construct the empty structure type. |
| 1151 | const StructType *EmptyStructTy = |
| 1152 | StructType::get(std::vector<const Type*>()); |
| 1153 | // Construct the pointer to empty structure type. |
| 1154 | EmptyStructPtrTy = PointerType::get(EmptyStructTy); |
| 1155 | } |
| 1156 | |
| 1157 | return EmptyStructPtrTy; |
| 1158 | } |
| 1159 | |
| 1160 | /// getTagType - Return the type describing the specified descriptor (via tag.) |
| 1161 | /// |
| 1162 | const StructType *DISerializer::getTagType(DebugInfoDesc *DD) { |
| 1163 | // Attempt to get the previously defined type. |
| 1164 | StructType *&Ty = TagTypes[DD->getTag()]; |
| 1165 | |
| 1166 | // If not already defined. |
| 1167 | if (!Ty) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1168 | // Set up fields vector. |
| 1169 | std::vector<const Type*> Fields; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1170 | // Get types of fields. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1171 | DIGetTypesVisitor GTAM(*this, Fields); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1172 | GTAM.ApplyToFields(DD); |
| 1173 | |
| 1174 | // Construct structured type. |
| 1175 | Ty = StructType::get(Fields); |
| 1176 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1177 | // Register type name with module. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1178 | M->addTypeName(DD->getTypeString(), Ty); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | return Ty; |
| 1182 | } |
| 1183 | |
| 1184 | /// getString - Construct the string as constant string global. |
| 1185 | /// |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1186 | Constant *DISerializer::getString(const std::string &String) { |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1187 | // Check string cache for previous edition. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1188 | Constant *&Slot = StringCache[String]; |
| 1189 | // return Constant if previously defined. |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1190 | if (Slot) return Slot; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1191 | // Construct string as an llvm constant. |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1192 | Constant *ConstStr = ConstantArray::get(String); |
| 1193 | // Otherwise create and return a new string global. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1194 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 1195 | GlobalVariable::InternalLinkage, |
| 1196 | ConstStr, "str", M); |
Jim Laskey | 313570f | 2006-03-07 22:00:35 +0000 | [diff] [blame^] | 1197 | StrGV->setSection("llvm.metadata"); |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1198 | // Convert to generic string pointer. |
| 1199 | Slot = ConstantExpr::getCast(StrGV, getStrPtrType()); |
| 1200 | return Slot; |
| 1201 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /// Serialize - Recursively cast the specified descriptor into a GlobalVariable |
| 1205 | /// so that it can be serialized to a .bc or .ll file. |
| 1206 | GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) { |
| 1207 | // Check if the DebugInfoDesc is already in the map. |
| 1208 | GlobalVariable *&Slot = DescGlobals[DD]; |
| 1209 | |
| 1210 | // See if DebugInfoDesc exists, if so return prior GlobalVariable. |
| 1211 | if (Slot) return Slot; |
| 1212 | |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1213 | // Get the type associated with the Tag. |
| 1214 | const StructType *Ty = getTagType(DD); |
| 1215 | |
| 1216 | // Create the GlobalVariable early to prevent infinite recursion. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1217 | GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(), |
| 1218 | NULL, DD->getDescString(), M); |
Jim Laskey | 313570f | 2006-03-07 22:00:35 +0000 | [diff] [blame^] | 1219 | GV->setSection("llvm.metadata"); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Insert new GlobalVariable in DescGlobals map. |
| 1222 | Slot = GV; |
| 1223 | |
| 1224 | // Set up elements vector |
| 1225 | std::vector<Constant*> Elements; |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1226 | // Add fields. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1227 | DISerializeVisitor SRAM(*this, Elements); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1228 | SRAM.ApplyToFields(DD); |
| 1229 | |
| 1230 | // Set the globals initializer. |
| 1231 | GV->setInitializer(ConstantStruct::get(Ty, Elements)); |
| 1232 | |
| 1233 | return GV; |
| 1234 | } |
| 1235 | |
| 1236 | //===----------------------------------------------------------------------===// |
| 1237 | |
| 1238 | /// markVisited - Return true if the GlobalVariable hase been "seen" before. |
| 1239 | /// Mark visited otherwise. |
| 1240 | bool DIVerifier::markVisited(GlobalVariable *GV) { |
| 1241 | // Check if the GlobalVariable is already in the Visited set. |
| 1242 | std::set<GlobalVariable *>::iterator VI = Visited.lower_bound(GV); |
| 1243 | |
| 1244 | // See if GlobalVariable exists. |
| 1245 | bool Exists = VI != Visited.end() && *VI == GV; |
| 1246 | |
| 1247 | // Insert in set. |
| 1248 | if (!Exists) Visited.insert(VI, GV); |
| 1249 | |
| 1250 | return Exists; |
| 1251 | } |
| 1252 | |
| 1253 | /// Verify - Return true if the GlobalVariable appears to be a valid |
| 1254 | /// serialization of a DebugInfoDesc. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1255 | bool DIVerifier::Verify(Value *V) { |
| 1256 | return Verify(getGlobalVariable(V)); |
| 1257 | } |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1258 | bool DIVerifier::Verify(GlobalVariable *GV) { |
| 1259 | // Check if seen before. |
| 1260 | if (markVisited(GV)) return true; |
| 1261 | |
| 1262 | // Get the Tag |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1263 | unsigned Tag = DebugInfoDesc::TagFromGlobal(GV); |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1264 | if (Tag == DW_TAG_invalid) return false; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1265 | |
| 1266 | // If a compile unit we need the debug version. |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1267 | if (Tag == DW_TAG_compile_unit) { |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1268 | DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV); |
Jim Laskey | 4e71db1 | 2006-03-01 20:39:36 +0000 | [diff] [blame] | 1269 | if (DebugVersion == DW_TAG_invalid) return false; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | // Construct an empty DebugInfoDesc. |
| 1273 | DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag); |
| 1274 | if (!DD) return false; |
| 1275 | |
| 1276 | // Get the initializer constant. |
| 1277 | ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer()); |
| 1278 | |
| 1279 | // Get the operand count. |
| 1280 | unsigned N = CI->getNumOperands(); |
| 1281 | |
| 1282 | // Get the field count. |
| 1283 | unsigned &Slot = Counts[Tag]; |
| 1284 | if (!Slot) { |
| 1285 | // Check the operand count to the field count |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1286 | DICountVisitor CTAM; |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1287 | CTAM.ApplyToFields(DD); |
| 1288 | Slot = CTAM.getCount(); |
| 1289 | } |
| 1290 | |
| 1291 | // Field count must equal operand count. |
| 1292 | if (Slot != N) { |
| 1293 | delete DD; |
| 1294 | return false; |
| 1295 | } |
| 1296 | |
| 1297 | // Check each field for valid type. |
Jim Laskey | b643ff5 | 2006-02-06 19:12:02 +0000 | [diff] [blame] | 1298 | DIVerifyVisitor VRAM(*this, GV); |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1299 | VRAM.ApplyToFields(DD); |
| 1300 | |
| 1301 | // Release empty DebugInfoDesc. |
| 1302 | delete DD; |
| 1303 | |
| 1304 | // Return result of field tests. |
| 1305 | return VRAM.isValid(); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | //===----------------------------------------------------------------------===// |
| 1309 | |
| 1310 | |
| 1311 | MachineDebugInfo::MachineDebugInfo() |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1312 | : DR() |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1313 | , CompileUnits() |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1314 | , Directories() |
| 1315 | , SourceFiles() |
| 1316 | , Lines() |
| 1317 | { |
| 1318 | |
| 1319 | } |
| 1320 | MachineDebugInfo::~MachineDebugInfo() { |
| 1321 | |
| 1322 | } |
| 1323 | |
Jim Laskey | 219d559 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1324 | /// doInitialization - Initialize the debug state for a new module. |
| 1325 | /// |
| 1326 | bool MachineDebugInfo::doInitialization() { |
| 1327 | return false; |
Jim Laskey | 4431739 | 2006-01-04 13:36:38 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
Jim Laskey | 219d559 | 2006-01-04 22:28:25 +0000 | [diff] [blame] | 1330 | /// doFinalization - Tear down the debug state after completion of a module. |
| 1331 | /// |
| 1332 | bool MachineDebugInfo::doFinalization() { |
| 1333 | return false; |
| 1334 | } |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1335 | |
Jim Laskey | 390c63e | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1336 | /// getDescFor - Convert a Value to a debug information descriptor. |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1337 | /// |
Jim Laskey | 390c63e | 2006-02-13 12:50:39 +0000 | [diff] [blame] | 1338 | // FIXME - use new Value type when available. |
| 1339 | DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) { |
Jim Laskey | 5995d01 | 2006-02-11 01:01:30 +0000 | [diff] [blame] | 1340 | return DR.Deserialize(V); |
| 1341 | } |
| 1342 | |
| 1343 | /// Verify - Verify that a Value is debug information descriptor. |
| 1344 | /// |
| 1345 | bool MachineDebugInfo::Verify(Value *V) { |
| 1346 | DIVerifier VR; |
| 1347 | return VR.Verify(V); |
| 1348 | } |
| 1349 | |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1350 | /// AnalyzeModule - Scan the module for global debug information. |
| 1351 | /// |
| 1352 | void MachineDebugInfo::AnalyzeModule(Module &M) { |
| 1353 | SetupCompileUnits(M); |
| 1354 | } |
| 1355 | |
| 1356 | /// SetupCompileUnits - Set up the unique vector of compile units. |
| 1357 | /// |
| 1358 | void MachineDebugInfo::SetupCompileUnits(Module &M) { |
Jim Laskey | 2fa33a9 | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1359 | std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1360 | |
Jim Laskey | 2fa33a9 | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1361 | for (unsigned i = 0, N = CU.size(); i < N; i++) { |
| 1362 | CompileUnits.insert(CU[i]); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1363 | } |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1364 | } |
| 1365 | |
Jim Laskey | 0689dfa | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1366 | /// getCompileUnits - Return a vector of debug compile units. |
| 1367 | /// |
Jim Laskey | 8526323 | 2006-02-06 15:33:21 +0000 | [diff] [blame] | 1368 | const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{ |
Jim Laskey | 0689dfa | 2006-01-26 21:22:49 +0000 | [diff] [blame] | 1369 | return CompileUnits; |
| 1370 | } |
| 1371 | |
Jim Laskey | 2fa33a9 | 2006-02-22 19:02:11 +0000 | [diff] [blame] | 1372 | /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the |
| 1373 | /// named GlobalVariable. |
| 1374 | std::vector<GlobalVariable*> |
| 1375 | MachineDebugInfo::getGlobalVariablesUsing(Module &M, |
| 1376 | const std::string &RootName) { |
| 1377 | return ::getGlobalVariablesUsing(M, RootName); |
Jim Laskey | 0bbdc55 | 2006-01-26 20:21:46 +0000 | [diff] [blame] | 1378 | } |