//===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file implements the helper classes used to build and interpret debug
// information in LLVM IR form.
//
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Support/Streams.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
// DIDescriptor
//===----------------------------------------------------------------------===//
DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) {
GV = gv;
// If this is non-null, check to see if the Tag matches. If not, set to null.
if (GV && getTag() != RequiredTag)
GV = 0;
}
const std::string &
DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
if (GV == 0) {
Result.clear();
return Result;
}
Constant *C = GV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands()) {
Result.clear();
return Result;
}
// Fills in the string if it succeeds
if (!GetConstantStringInfo(C->getOperand(Elt), Result))
Result.clear();
return Result;
}
uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
if (GV == 0) return 0;
Constant *C = GV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return 0;
if (ConstantInt *CI = dyn_cast<ConstantInt>(C->getOperand(Elt)))
return CI->getZExtValue();
return 0;
}
DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
if (GV == 0) return DIDescriptor();
Constant *C = GV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return DIDescriptor();
C = C->getOperand(Elt);
return DIDescriptor(dyn_cast<GlobalVariable>(C->stripPointerCasts()));
}
GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
if (GV == 0) return 0;
Constant *C = GV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return 0;
C = C->getOperand(Elt);
return dyn_cast<GlobalVariable>(C->stripPointerCasts());
}
//===----------------------------------------------------------------------===//
// Simple Descriptor Constructors and other Methods
//===----------------------------------------------------------------------===//
DIAnchor::DIAnchor(GlobalVariable *GV)
: DIDescriptor(GV, dwarf::DW_TAG_anchor) {}
DIEnumerator::DIEnumerator(GlobalVariable *GV)
: DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
DISubrange::DISubrange(GlobalVariable *GV)
: DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
DICompileUnit::DICompileUnit(GlobalVariable *GV)
: DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
DIBasicType::DIBasicType(GlobalVariable *GV)
: DIType(GV, dwarf::DW_TAG_base_type) {}
DISubprogram::DISubprogram(GlobalVariable *GV)
: DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
DIGlobalVariable::DIGlobalVariable(GlobalVariable *GV)
: DIGlobal(GV, dwarf::DW_TAG_variable) {}
DIBlock::DIBlock(GlobalVariable *GV)
: DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
// needed by DIVariable::getType()
DIType::DIType(GlobalVariable *<