blob: 44b71fae539d38f2ab91ac073eb611900adb1110 [file] [log] [blame]
Jim Laskey6af56812006-01-04 13:36:38 +00001//===-- 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 Laskey6af56812006-01-04 13:36:38 +00009
10#include "llvm/CodeGen/MachineDebugInfo.h"
11
Jim Laskeyb3e789a2006-01-26 20:21:46 +000012#include "llvm/Constants.h"
13#include "llvm/DerivedTypes.h"
Jim Laskey86cbdba2006-02-06 15:33:21 +000014#include "llvm/GlobalVariable.h"
Jim Laskeyb3e789a2006-01-26 20:21:46 +000015#include "llvm/Intrinsics.h"
16#include "llvm/Instructions.h"
17#include "llvm/Module.h"
18#include "llvm/Support/Dwarf.h"
19
Jim Laskey86cbdba2006-02-06 15:33:21 +000020#include <iostream>
21
Jim Laskey6af56812006-01-04 13:36:38 +000022using namespace llvm;
23
24// Handle the Pass registration stuff necessary to use TargetData's.
25namespace {
Jim Laskeyb2efb852006-01-04 22:28:25 +000026 RegisterPass<MachineDebugInfo> X("machinedebuginfo", "Debug Information");
27}
Jim Laskey063e7652006-01-17 17:31:53 +000028
Jim Laskeyb3e789a2006-01-26 20:21:46 +000029//===----------------------------------------------------------------------===//
30
Jim Laskey86cbdba2006-02-06 15:33:21 +000031/// getGlobalVariablesUsing - Return all of the GlobalVariables which have the
Jim Laskeyb3e789a2006-01-26 20:21:46 +000032/// specified value in their initializer somewhere.
33static void
34getGlobalVariablesUsing(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 Laskey86cbdba2006-02-06 15:33:21 +000038 // If the user is a GlobalVariable then add to result.
Jim Laskeyb3e789a2006-01-26 20:21:46 +000039 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 Laskey86cbdba2006-02-06 15:33:21 +000047/// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
48/// named GlobalVariable.
Jim Laskeyb3e789a2006-01-26 20:21:46 +000049static std::vector<GlobalVariable*>
50getGlobalVariablesUsing(Module &M, const std::string &RootName) {
Jim Laskey86cbdba2006-02-06 15:33:21 +000051 std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
Jim Laskeyce72b172006-02-11 01:01:30 +000052
53 std::vector<const Type*> FieldTypes;
54 FieldTypes.push_back(Type::UIntTy);
55 FieldTypes.push_back(PointerType::get(Type::SByteTy));
Jim Laskeyb3e789a2006-01-26 20:21:46 +000056
Jim Laskey86cbdba2006-02-06 15:33:21 +000057 // Get the GlobalVariable root.
Jim Laskeyb3e789a2006-01-26 20:21:46 +000058 GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
Jim Laskeyce72b172006-02-11 01:01:30 +000059 StructType::get(FieldTypes));
Jim Laskeyb3e789a2006-01-26 20:21:46 +000060
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 Lattner22760af2006-01-27 17:31:30 +000072static const std::string getStringValue(Value *V, unsigned Offset = 0) {
Jim Laskeyb3e789a2006-01-26 20:21:46 +000073 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 Laskeyd8f77ba2006-01-27 15:20:54 +0000107
Jim Laskey86cbdba2006-02-06 15:33:21 +0000108/// isStringValue - Return true if the given value can be coerced to a string.
109///
110static 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000132/// getGlobalVariable - Return either a direct or cast Global value.
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000133///
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000134static GlobalVariable *getGlobalVariable(Value *V) {
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000135 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
136 return GV;
137 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000138 if (CE->getOpcode() == Instruction::Cast) {
139 return dyn_cast<GlobalVariable>(CE->getOperand(0));
140 }
Jim Laskeyd8f77ba2006-01-27 15:20:54 +0000141 }
142 return NULL;
143}
144
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000145/// isGlobalVariable - Return true if the given value can be coerced to a
Jim Laskey86cbdba2006-02-06 15:33:21 +0000146/// GlobalVariable.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000147static bool isGlobalVariable(Value *V) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000148 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000158/// getUIntOperand - Return ith operand if it is an unsigned integer.
Jim Laskey86cbdba2006-02-06 15:33:21 +0000159///
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000160static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000161 // Make sure the GlobalVariable has an initializer.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000162 if (!GV->hasInitializer()) return NULL;
Jim Laskeyb2efb852006-01-04 22:28:25 +0000163
Jim Laskey86cbdba2006-02-06 15:33:21 +0000164 // Get the initializer constant.
165 ConstantStruct *CI = dyn_cast<ConstantStruct>(GV->getInitializer());
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000166 if (!CI) return NULL;
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000167
Jim Laskey86cbdba2006-02-06 15:33:21 +0000168 // Check if there is at least i + 1 operands.
169 unsigned N = CI->getNumOperands();
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000170 if (i >= N) return NULL;
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000171
Jim Laskey86cbdba2006-02-06 15:33:21 +0000172 // Check constant.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000173 return dyn_cast<ConstantUInt>(CI->getOperand(i));
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000174}
Jim Laskey86cbdba2006-02-06 15:33:21 +0000175//===----------------------------------------------------------------------===//
176
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000177/// ApplyToFields - Target the visitor to each field of the debug information
Jim Laskey86cbdba2006-02-06 15:33:21 +0000178/// descriptor.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000179void DIVisitor::ApplyToFields(DebugInfoDesc *DD) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000180 DD->ApplyToFields(this);
181}
182
183//===----------------------------------------------------------------------===//
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000184/// DICountVisitor - This DIVisitor counts all the fields in the supplied debug
185/// the supplied DebugInfoDesc.
186class DICountVisitor : public DIVisitor {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000187private:
188 unsigned Count; // Running count of fields.
189
190public:
Jim Laskeyce72b172006-02-11 01:01:30 +0000191 DICountVisitor() : DIVisitor(), Count(0) {}
Jim Laskey86cbdba2006-02-06 15:33:21 +0000192
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 Laskeyf4afdd92006-02-23 16:58:18 +0000200 virtual void Apply(uint64_t &Field) { ++Count; }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000201 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000208/// DIDeserializeVisitor - This DIVisitor deserializes all the fields in the
209/// supplied DebugInfoDesc.
210class DIDeserializeVisitor : public DIVisitor {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000211private:
212 DIDeserializer &DR; // Active deserializer.
213 unsigned I; // Current operand index.
214 ConstantStruct *CI; // GlobalVariable constant initializer.
215
216public:
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000217 DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
218 : DIVisitor()
Jim Laskey86cbdba2006-02-06 15:33:21 +0000219 , DR(D)
Jim Laskeyce72b172006-02-11 01:01:30 +0000220 , I(0)
Jim Laskey86cbdba2006-02-06 15:33:21 +0000221 , 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 Laskeyf4afdd92006-02-23 16:58:18 +0000234 virtual void Apply(uint64_t &Field) {
235 Constant *C = CI->getOperand(I++);
236 Field = cast<ConstantUInt>(C)->getValue();
237 }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000238 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000252 Field = getGlobalVariable(C);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000253 }
254};
255
256//===----------------------------------------------------------------------===//
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000257/// DISerializeVisitor - This DIVisitor serializes all the fields in
Jim Laskey86cbdba2006-02-06 15:33:21 +0000258/// the supplied DebugInfoDesc.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000259class DISerializeVisitor : public DIVisitor {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000260private:
261 DISerializer &SR; // Active serializer.
262 std::vector<Constant*> &Elements; // Element accumulator.
263
264public:
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000265 DISerializeVisitor(DISerializer &S, std::vector<Constant*> &E)
266 : DIVisitor()
Jim Laskey86cbdba2006-02-06 15:33:21 +0000267 , 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 Laskeyce72b172006-02-11 01:01:30 +0000274 Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
Jim Laskey86cbdba2006-02-06 15:33:21 +0000275 }
276 virtual void Apply(unsigned &Field) {
277 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
278 }
Jim Laskeyf4afdd92006-02-23 16:58:18 +0000279 virtual void Apply(uint64_t &Field) {
280 Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
281 }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000282 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 Laskeyce72b172006-02-11 01:01:30 +0000307 if (Field) {
308 Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
309 } else {
310 Elements.push_back(ConstantPointerNull::get(EmptyTy));
311 }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000312 }
313};
314
315//===----------------------------------------------------------------------===//
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000316/// DIGetTypesVisitor - This DIVisitor gathers all the field types in
Jim Laskey86cbdba2006-02-06 15:33:21 +0000317/// the supplied DebugInfoDesc.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000318class DIGetTypesVisitor : public DIVisitor {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000319private:
320 DISerializer &SR; // Active serializer.
321 std::vector<const Type*> &Fields; // Type accumulator.
322
323public:
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000324 DIGetTypesVisitor(DISerializer &S, std::vector<const Type*> &F)
325 : DIVisitor()
Jim Laskey86cbdba2006-02-06 15:33:21 +0000326 , 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 Laskeyf4afdd92006-02-23 16:58:18 +0000338 virtual void Apply(uint64_t &Field) {
339 Fields.push_back(Type::UIntTy);
340 }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000341 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000359/// DIVerifyVisitor - This DIVisitor verifies all the field types against
Jim Laskey86cbdba2006-02-06 15:33:21 +0000360/// a constant initializer.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000361class DIVerifyVisitor : public DIVisitor {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000362private:
363 DIVerifier &VR; // Active verifier.
364 bool IsValid; // Validity status.
365 unsigned I; // Current operand index.
366 ConstantStruct *CI; // GlobalVariable constant initializer.
367
368public:
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000369 DIVerifyVisitor(DIVerifier &V, GlobalVariable *GV)
370 : DIVisitor()
Jim Laskey86cbdba2006-02-06 15:33:21 +0000371 , VR(V)
372 , IsValid(true)
Jim Laskeyce72b172006-02-11 01:01:30 +0000373 , I(0)
Jim Laskey86cbdba2006-02-06 15:33:21 +0000374 , 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 Laskeyf4afdd92006-02-23 16:58:18 +0000391 virtual void Apply(uint64_t &Field) {
392 Constant *C = CI->getOperand(I++);
393 IsValid = IsValid && isa<ConstantInt>(C);
394 }
Jim Laskey86cbdba2006-02-06 15:33:21 +0000395 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 Laskeyc2f0c8d2006-02-06 19:12:02 +0000406 IsValid = IsValid && isGlobalVariable(C);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000407 }
408 virtual void Apply(GlobalVariable *&Field) {
409 Constant *C = CI->getOperand(I++);
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000410 IsValid = IsValid && isGlobalVariable(C);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000411 }
412};
413
Jim Laskeyce72b172006-02-11 01:01:30 +0000414
Jim Laskey86cbdba2006-02-06 15:33:21 +0000415//===----------------------------------------------------------------------===//
416
Jim Laskeyce72b172006-02-11 01:01:30 +0000417/// TagFromGlobal - Returns the Tag number from a debug info descriptor
418/// GlobalVariable.
419unsigned 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.
426DebugInfoDesc *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 Laskeyf4afdd92006-02-23 16:58:18 +0000432 case DI_TAG_basictype: return new BasicTypeDesc();
Jim Laskeyce72b172006-02-11 01:01:30 +0000433 default: break;
434 }
435 return NULL;
436}
437
438/// getLinkage - get linkage appropriate for this type of descriptor.
439///
440GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
441 return GlobalValue::InternalLinkage;
442}
443
444/// ApplyToFields - Target the vistor to the fields of the descriptor.
445///
446void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
447 Visitor->Apply(Tag);
448}
449
450//===----------------------------------------------------------------------===//
451
452/// getLinkage - get linkage appropriate for this type of descriptor.
453///
454GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
455 return GlobalValue::LinkOnceLinkage;
456}
457
458/// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
459///
460void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
461 DebugInfoDesc::ApplyToFields(Visitor);
462
463 Visitor->Apply(Name);
464}
465
466/// getDescString - Return a string used to compose global names and labels.
467///
468const char *AnchorDesc::getDescString() const {
469 return Name.c_str();
470}
471
472/// getTypeString - Return a string used to label this descriptors type.
473///
474const char *AnchorDesc::getTypeString() const {
475 return "llvm.dbg.anchor.type";
476}
477
478#ifndef NDEBUG
479void AnchorDesc::dump() {
480 std::cerr << getDescString() << " "
481 << "Tag(" << getTag() << "), "
482 << "Name(" << Name << ")\n";
483}
484#endif
485
486//===----------------------------------------------------------------------===//
487
488AnchoredDesc::AnchoredDesc(unsigned T)
489: DebugInfoDesc(T)
490, Anchor(NULL)
491{}
492
493/// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
494///
495void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
496 DebugInfoDesc::ApplyToFields(Visitor);
497
498 Visitor->Apply((DebugInfoDesc *&)Anchor);
499}
500
501//===----------------------------------------------------------------------===//
502
503CompileUnitDesc::CompileUnitDesc()
504: AnchoredDesc(DI_TAG_compile_unit)
505, DebugVersion(LLVMDebugVersion)
506, Language(0)
507, FileName("")
508, Directory("")
509, Producer("")
510{}
511
Jim Laskey86cbdba2006-02-06 15:33:21 +0000512/// DebugVersionFromGlobal - Returns the version number from a compile unit
513/// GlobalVariable.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000514unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000515 ConstantUInt *C = getUIntOperand(GV, 2);
Jim Laskeyf60c2412006-02-06 21:54:05 +0000516 return C ? (unsigned)C->getValue() : (unsigned)DIInvalid;
Jim Laskey86cbdba2006-02-06 15:33:21 +0000517}
518
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000519/// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
520///
521void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000522 AnchoredDesc::ApplyToFields(Visitor);
523
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000524 Visitor->Apply(DebugVersion);
525 Visitor->Apply(Language);
526 Visitor->Apply(FileName);
527 Visitor->Apply(Directory);
528 Visitor->Apply(Producer);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000529}
530
Jim Laskeyce72b172006-02-11 01:01:30 +0000531/// getDescString - Return a string used to compose global names and labels.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000532///
Jim Laskeyce72b172006-02-11 01:01:30 +0000533const char *CompileUnitDesc::getDescString() const {
534 return "llvm.dbg.compile_unit";
535}
536
537/// getTypeString - Return a string used to label this descriptors type.
538///
539const char *CompileUnitDesc::getTypeString() const {
540 return "llvm.dbg.compile_unit.type";
541}
542
543/// getAnchorString - Return a string used to label this descriptor's anchor.
544///
545const char *CompileUnitDesc::getAnchorString() const {
546 return "llvm.dbg.compile_units";
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000547}
548
Jim Laskey86cbdba2006-02-06 15:33:21 +0000549#ifndef NDEBUG
550void CompileUnitDesc::dump() {
Jim Laskeyce72b172006-02-11 01:01:30 +0000551 std::cerr << getDescString() << " "
Jim Laskey86cbdba2006-02-06 15:33:21 +0000552 << "Tag(" << getTag() << "), "
Jim Laskeyce72b172006-02-11 01:01:30 +0000553 << "Anchor(" << getAnchor() << "), "
554 << "DebugVersion(" << DebugVersion << "), "
Jim Laskey86cbdba2006-02-06 15:33:21 +0000555 << "Language(" << Language << "), "
556 << "FileName(\"" << FileName << "\"), "
557 << "Directory(\"" << Directory << "\"), "
558 << "Producer(\"" << Producer << "\")\n";
559}
560#endif
561
562//===----------------------------------------------------------------------===//
563
Jim Laskeyf4afdd92006-02-23 16:58:18 +0000564//===----------------------------------------------------------------------===//
565
566TypeDesc::TypeDesc(unsigned T)
567: DebugInfoDesc(T)
568, Context(NULL)
569, Name("")
570, Size(0)
571{}
572
573/// ApplyToFields - Target the visitor to the fields of the TypeDesc.
574///
575void TypeDesc::ApplyToFields(DIVisitor *Visitor) {
576 DebugInfoDesc::ApplyToFields(Visitor);
577
578 Visitor->Apply(Context);
579 Visitor->Apply(Name);
580 Visitor->Apply(Size);
581}
582
583/// getDescString - Return a string used to compose global names and labels.
584///
585const char *TypeDesc::getDescString() const {
586 return "llvm.dbg.type";
587}
588
589/// getTypeString - Return a string used to label this descriptor's type.
590///
591const char *TypeDesc::getTypeString() const {
592 return "llvm.dbg.type.type";
593}
594
595#ifndef NDEBUG
596void TypeDesc::dump() {
597 std::cerr << getDescString() << " "
598 << "Tag(" << getTag() << "), "
599 << "Context(" << Context << "), "
600 << "Name(\"" << Name << "\"), "
601 << "Size(" << Size << ")\n";
602}
603#endif
604
605//===----------------------------------------------------------------------===//
606
607BasicTypeDesc::BasicTypeDesc()
608: TypeDesc(DI_TAG_basictype)
609, Encoding(0)
610{}
611
612/// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
613///
614void BasicTypeDesc::ApplyToFields(DIVisitor *Visitor) {
615 TypeDesc::ApplyToFields(Visitor);
616
617 Visitor->Apply(Encoding);
618}
619
620#ifndef NDEBUG
621void BasicTypeDesc::dump() {
622 std::cerr << getDescString() << " "
623 << "Tag(" << getTag() << "), "
624 << "Context(" << getContext() << "), "
625 << "Name(\"" << getName() << "\"), "
626 << "Size(" << getSize() << "), "
627 << "Encoding(" << Encoding << ")\n";
628}
629#endif
630
631//===----------------------------------------------------------------------===//
632
Jim Laskeyce72b172006-02-11 01:01:30 +0000633GlobalDesc::GlobalDesc(unsigned T)
634: AnchoredDesc(T)
635, Context(0)
636, Name("")
637, TyDesc(NULL)
638, IsStatic(false)
639, IsDefinition(false)
640{}
641
642/// ApplyToFields - Target the visitor to the fields of the global.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000643///
Jim Laskeyce72b172006-02-11 01:01:30 +0000644void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
645 AnchoredDesc::ApplyToFields(Visitor);
646
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000647 Visitor->Apply(Context);
648 Visitor->Apply(Name);
Jim Laskeyf4afdd92006-02-23 16:58:18 +0000649 Visitor->Apply((DebugInfoDesc *&)TyDesc);
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000650 Visitor->Apply(IsStatic);
651 Visitor->Apply(IsDefinition);
Jim Laskeyce72b172006-02-11 01:01:30 +0000652}
653
654//===----------------------------------------------------------------------===//
655
656GlobalVariableDesc::GlobalVariableDesc()
657: GlobalDesc(DI_TAG_global_variable)
658, Global(NULL)
659{}
660
661/// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
662///
663void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
664 GlobalDesc::ApplyToFields(Visitor);
665
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000666 Visitor->Apply(Global);
Jim Laskey0420f2a2006-02-22 19:02:11 +0000667 Visitor->Apply(Line);
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000668}
669
Jim Laskeyce72b172006-02-11 01:01:30 +0000670/// getDescString - Return a string used to compose global names and labels.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000671///
Jim Laskeyce72b172006-02-11 01:01:30 +0000672const char *GlobalVariableDesc::getDescString() const {
673 return "llvm.dbg.global_variable";
674}
675
676/// getTypeString - Return a string used to label this descriptors type.
677///
678const char *GlobalVariableDesc::getTypeString() const {
679 return "llvm.dbg.global_variable.type";
680}
681
682/// getAnchorString - Return a string used to label this descriptor's anchor.
683///
684const char *GlobalVariableDesc::getAnchorString() const {
685 return "llvm.dbg.global_variables";
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000686}
687
Jim Laskey86cbdba2006-02-06 15:33:21 +0000688#ifndef NDEBUG
689void GlobalVariableDesc::dump() {
Jim Laskeyce72b172006-02-11 01:01:30 +0000690 std::cerr << getDescString() << " "
Jim Laskey86cbdba2006-02-06 15:33:21 +0000691 << "Tag(" << getTag() << "), "
Jim Laskeyce72b172006-02-11 01:01:30 +0000692 << "Anchor(" << getAnchor() << "), "
693 << "Name(\"" << getName() << "\"), "
Jim Laskeyf4afdd92006-02-23 16:58:18 +0000694 << "Type(\"" << getTypeDesc() << "\"), "
Jim Laskeyce72b172006-02-11 01:01:30 +0000695 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
696 << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
Jim Laskey0420f2a2006-02-22 19:02:11 +0000697 << "Global(" << Global << "), "
698 << "Line(" << Line << ")\n";
Jim Laskey86cbdba2006-02-06 15:33:21 +0000699}
700#endif
701
702//===----------------------------------------------------------------------===//
703
Jim Laskeyce72b172006-02-11 01:01:30 +0000704SubprogramDesc::SubprogramDesc()
705: GlobalDesc(DI_TAG_subprogram)
706{}
707
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000708/// ApplyToFields - Target the visitor to the fields of the
Jim Laskey86cbdba2006-02-06 15:33:21 +0000709/// SubprogramDesc.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000710void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000711 GlobalDesc::ApplyToFields(Visitor);
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000712}
713
Jim Laskeyce72b172006-02-11 01:01:30 +0000714/// getDescString - Return a string used to compose global names and labels.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000715///
Jim Laskeyce72b172006-02-11 01:01:30 +0000716const char *SubprogramDesc::getDescString() const {
717 return "llvm.dbg.subprogram";
718}
719
720/// getTypeString - Return a string used to label this descriptors type.
721///
722const char *SubprogramDesc::getTypeString() const {
723 return "llvm.dbg.subprogram.type";
724}
725
726/// getAnchorString - Return a string used to label this descriptor's anchor.
727///
728const char *SubprogramDesc::getAnchorString() const {
729 return "llvm.dbg.subprograms";
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000730}
731
Jim Laskey86cbdba2006-02-06 15:33:21 +0000732#ifndef NDEBUG
733void SubprogramDesc::dump() {
Jim Laskeyce72b172006-02-11 01:01:30 +0000734 std::cerr << getDescString() << " "
Jim Laskey86cbdba2006-02-06 15:33:21 +0000735 << "Tag(" << getTag() << "), "
Jim Laskeyce72b172006-02-11 01:01:30 +0000736 << "Anchor(" << getAnchor() << "), "
737 << "Name(\"" << getName() << "\"), "
Jim Laskeyf4afdd92006-02-23 16:58:18 +0000738 << "Type(\"" << getTypeDesc() << "\"), "
Jim Laskeyce72b172006-02-11 01:01:30 +0000739 << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
740 << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
Jim Laskey86cbdba2006-02-06 15:33:21 +0000741}
742#endif
743
Jim Laskey86cbdba2006-02-06 15:33:21 +0000744DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000745 return Deserialize(getGlobalVariable(V));
Jim Laskey86cbdba2006-02-06 15:33:21 +0000746}
747DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000748 // Handle NULL.
749 if (!GV) return NULL;
750
Jim Laskey86cbdba2006-02-06 15:33:21 +0000751 // Check to see if it has been already deserialized.
752 DebugInfoDesc *&Slot = GlobalDescs[GV];
753 if (Slot) return Slot;
754
755 // Get the Tag from the global.
756 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
757
758 // Get the debug version if a compile unit.
759 if (Tag == DI_TAG_compile_unit) {
760 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
761 }
762
763 // Create an empty instance of the correct sort.
764 Slot = DebugInfoDesc::DescFactory(Tag);
765 assert(Slot && "Unknown Tag");
766
767 // Deserialize the fields.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000768 DIDeserializeVisitor DRAM(*this, GV);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000769 DRAM.ApplyToFields(Slot);
770
771 return Slot;
772}
773
774//===----------------------------------------------------------------------===//
775
776/// getStrPtrType - Return a "sbyte *" type.
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000777///
Jim Laskey86cbdba2006-02-06 15:33:21 +0000778const PointerType *DISerializer::getStrPtrType() {
779 // If not already defined.
780 if (!StrPtrTy) {
781 // Construct the pointer to signed bytes.
782 StrPtrTy = PointerType::get(Type::SByteTy);
783 }
784
785 return StrPtrTy;
786}
787
788/// getEmptyStructPtrType - Return a "{ }*" type.
789///
790const PointerType *DISerializer::getEmptyStructPtrType() {
791 // If not already defined.
792 if (!EmptyStructPtrTy) {
793 // Construct the empty structure type.
794 const StructType *EmptyStructTy =
795 StructType::get(std::vector<const Type*>());
796 // Construct the pointer to empty structure type.
797 EmptyStructPtrTy = PointerType::get(EmptyStructTy);
798 }
799
800 return EmptyStructPtrTy;
801}
802
803/// getTagType - Return the type describing the specified descriptor (via tag.)
804///
805const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
806 // Attempt to get the previously defined type.
807 StructType *&Ty = TagTypes[DD->getTag()];
808
809 // If not already defined.
810 if (!Ty) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000811 // Set up fields vector.
812 std::vector<const Type*> Fields;
Jim Laskeyce72b172006-02-11 01:01:30 +0000813 // Get types of fields.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000814 DIGetTypesVisitor GTAM(*this, Fields);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000815 GTAM.ApplyToFields(DD);
816
817 // Construct structured type.
818 Ty = StructType::get(Fields);
819
Jim Laskey86cbdba2006-02-06 15:33:21 +0000820 // Register type name with module.
Jim Laskeyce72b172006-02-11 01:01:30 +0000821 M->addTypeName(DD->getTypeString(), Ty);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000822 }
823
824 return Ty;
825}
826
827/// getString - Construct the string as constant string global.
828///
Jim Laskeyce72b172006-02-11 01:01:30 +0000829Constant *DISerializer::getString(const std::string &String) {
Jim Laskey86cbdba2006-02-06 15:33:21 +0000830 // Check string cache for previous edition.
Jim Laskeyce72b172006-02-11 01:01:30 +0000831 Constant *&Slot = StringCache[String];
832 // return Constant if previously defined.
Jim Laskey86cbdba2006-02-06 15:33:21 +0000833 if (Slot) return Slot;
Jim Laskeyce72b172006-02-11 01:01:30 +0000834 // Construct string as an llvm constant.
Jim Laskey86cbdba2006-02-06 15:33:21 +0000835 Constant *ConstStr = ConstantArray::get(String);
836 // Otherwise create and return a new string global.
Jim Laskeyce72b172006-02-11 01:01:30 +0000837 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
838 GlobalVariable::InternalLinkage,
839 ConstStr, "str", M);
840 // Convert to generic string pointer.
841 Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
842 return Slot;
843
Jim Laskey86cbdba2006-02-06 15:33:21 +0000844}
845
846/// Serialize - Recursively cast the specified descriptor into a GlobalVariable
847/// so that it can be serialized to a .bc or .ll file.
848GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
849 // Check if the DebugInfoDesc is already in the map.
850 GlobalVariable *&Slot = DescGlobals[DD];
851
852 // See if DebugInfoDesc exists, if so return prior GlobalVariable.
853 if (Slot) return Slot;
854
Jim Laskey86cbdba2006-02-06 15:33:21 +0000855 // Get the type associated with the Tag.
856 const StructType *Ty = getTagType(DD);
857
858 // Create the GlobalVariable early to prevent infinite recursion.
Jim Laskeyce72b172006-02-11 01:01:30 +0000859 GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
860 NULL, DD->getDescString(), M);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000861
862 // Insert new GlobalVariable in DescGlobals map.
863 Slot = GV;
864
865 // Set up elements vector
866 std::vector<Constant*> Elements;
Jim Laskeyce72b172006-02-11 01:01:30 +0000867 // Add fields.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000868 DISerializeVisitor SRAM(*this, Elements);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000869 SRAM.ApplyToFields(DD);
870
871 // Set the globals initializer.
872 GV->setInitializer(ConstantStruct::get(Ty, Elements));
873
874 return GV;
875}
876
877//===----------------------------------------------------------------------===//
878
879/// markVisited - Return true if the GlobalVariable hase been "seen" before.
880/// Mark visited otherwise.
881bool DIVerifier::markVisited(GlobalVariable *GV) {
882 // Check if the GlobalVariable is already in the Visited set.
883 std::set<GlobalVariable *>::iterator VI = Visited.lower_bound(GV);
884
885 // See if GlobalVariable exists.
886 bool Exists = VI != Visited.end() && *VI == GV;
887
888 // Insert in set.
889 if (!Exists) Visited.insert(VI, GV);
890
891 return Exists;
892}
893
894/// Verify - Return true if the GlobalVariable appears to be a valid
895/// serialization of a DebugInfoDesc.
Jim Laskeyce72b172006-02-11 01:01:30 +0000896bool DIVerifier::Verify(Value *V) {
897 return Verify(getGlobalVariable(V));
898}
Jim Laskey86cbdba2006-02-06 15:33:21 +0000899bool DIVerifier::Verify(GlobalVariable *GV) {
900 // Check if seen before.
901 if (markVisited(GV)) return true;
902
903 // Get the Tag
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000904 unsigned Tag = DebugInfoDesc::TagFromGlobal(GV);
Jim Laskeyf60c2412006-02-06 21:54:05 +0000905 if (Tag == DIInvalid) return false;
Jim Laskey86cbdba2006-02-06 15:33:21 +0000906
907 // If a compile unit we need the debug version.
908 if (Tag == DI_TAG_compile_unit) {
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000909 DebugVersion = CompileUnitDesc::DebugVersionFromGlobal(GV);
Jim Laskeyf60c2412006-02-06 21:54:05 +0000910 if (DebugVersion == DIInvalid) return false;
Jim Laskey86cbdba2006-02-06 15:33:21 +0000911 }
912
913 // Construct an empty DebugInfoDesc.
914 DebugInfoDesc *DD = DebugInfoDesc::DescFactory(Tag);
915 if (!DD) return false;
916
917 // Get the initializer constant.
918 ConstantStruct *CI = cast<ConstantStruct>(GV->getInitializer());
919
920 // Get the operand count.
921 unsigned N = CI->getNumOperands();
922
923 // Get the field count.
924 unsigned &Slot = Counts[Tag];
925 if (!Slot) {
926 // Check the operand count to the field count
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000927 DICountVisitor CTAM;
Jim Laskey86cbdba2006-02-06 15:33:21 +0000928 CTAM.ApplyToFields(DD);
929 Slot = CTAM.getCount();
930 }
931
932 // Field count must equal operand count.
933 if (Slot != N) {
934 delete DD;
935 return false;
936 }
937
938 // Check each field for valid type.
Jim Laskeyc2f0c8d2006-02-06 19:12:02 +0000939 DIVerifyVisitor VRAM(*this, GV);
Jim Laskey86cbdba2006-02-06 15:33:21 +0000940 VRAM.ApplyToFields(DD);
941
942 // Release empty DebugInfoDesc.
943 delete DD;
944
945 // Return result of field tests.
946 return VRAM.isValid();
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000947}
948
949//===----------------------------------------------------------------------===//
950
951
952MachineDebugInfo::MachineDebugInfo()
Jim Laskeyce72b172006-02-11 01:01:30 +0000953: DR()
Jim Laskey86cbdba2006-02-06 15:33:21 +0000954, CompileUnits()
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000955, Directories()
956, SourceFiles()
957, Lines()
958{
959
960}
961MachineDebugInfo::~MachineDebugInfo() {
962
963}
964
Jim Laskeyb2efb852006-01-04 22:28:25 +0000965/// doInitialization - Initialize the debug state for a new module.
966///
967bool MachineDebugInfo::doInitialization() {
968 return false;
Jim Laskey6af56812006-01-04 13:36:38 +0000969}
970
Jim Laskeyb2efb852006-01-04 22:28:25 +0000971/// doFinalization - Tear down the debug state after completion of a module.
972///
973bool MachineDebugInfo::doFinalization() {
974 return false;
975}
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000976
Jim Laskeyd96185a2006-02-13 12:50:39 +0000977/// getDescFor - Convert a Value to a debug information descriptor.
Jim Laskeyce72b172006-02-11 01:01:30 +0000978///
Jim Laskeyd96185a2006-02-13 12:50:39 +0000979// FIXME - use new Value type when available.
980DebugInfoDesc *MachineDebugInfo::getDescFor(Value *V) {
Jim Laskeyce72b172006-02-11 01:01:30 +0000981 return DR.Deserialize(V);
982}
983
984/// Verify - Verify that a Value is debug information descriptor.
985///
986bool MachineDebugInfo::Verify(Value *V) {
987 DIVerifier VR;
988 return VR.Verify(V);
989}
990
Jim Laskeyb3e789a2006-01-26 20:21:46 +0000991/// AnalyzeModule - Scan the module for global debug information.
992///
993void MachineDebugInfo::AnalyzeModule(Module &M) {
994 SetupCompileUnits(M);
995}
996
997/// SetupCompileUnits - Set up the unique vector of compile units.
998///
999void MachineDebugInfo::SetupCompileUnits(Module &M) {
Jim Laskey0420f2a2006-02-22 19:02:11 +00001000 std::vector<CompileUnitDesc *>CU = getAnchoredDescriptors<CompileUnitDesc>(M);
Jim Laskeyb3e789a2006-01-26 20:21:46 +00001001
Jim Laskey0420f2a2006-02-22 19:02:11 +00001002 for (unsigned i = 0, N = CU.size(); i < N; i++) {
1003 CompileUnits.insert(CU[i]);
Jim Laskeyb3e789a2006-01-26 20:21:46 +00001004 }
Jim Laskeyb3e789a2006-01-26 20:21:46 +00001005}
1006
Jim Laskey6e87c0e2006-01-26 21:22:49 +00001007/// getCompileUnits - Return a vector of debug compile units.
1008///
Jim Laskey86cbdba2006-02-06 15:33:21 +00001009const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
Jim Laskey6e87c0e2006-01-26 21:22:49 +00001010 return CompileUnits;
1011}
1012
Jim Laskey0420f2a2006-02-22 19:02:11 +00001013/// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1014/// named GlobalVariable.
1015std::vector<GlobalVariable*>
1016MachineDebugInfo::getGlobalVariablesUsing(Module &M,
1017 const std::string &RootName) {
1018 return ::getGlobalVariablesUsing(M, RootName);
Jim Laskeyb3e789a2006-01-26 20:21:46 +00001019}