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