mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
DebugInfo: Remove dead code for accessing fields
Most fields are now accessed via the new debug info hierarchy. I'll make the rest of this code dead soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234182 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e75a8c3855
commit
c6370a13cf
@ -58,65 +58,6 @@ class DIObjCProperty;
|
||||
/// \brief Maps from type identifier to the actual MDNode.
|
||||
typedef DenseMap<const MDString *, MDNode *> DITypeIdentifierMap;
|
||||
|
||||
class DIHeaderFieldIterator
|
||||
: public std::iterator<std::input_iterator_tag, StringRef, std::ptrdiff_t,
|
||||
const StringRef *, StringRef> {
|
||||
StringRef Header;
|
||||
StringRef Current;
|
||||
|
||||
public:
|
||||
DIHeaderFieldIterator() {}
|
||||
explicit DIHeaderFieldIterator(StringRef Header)
|
||||
: Header(Header), Current(Header.slice(0, Header.find('\0'))) {}
|
||||
StringRef operator*() const { return Current; }
|
||||
const StringRef *operator->() const { return &Current; }
|
||||
DIHeaderFieldIterator &operator++() {
|
||||
increment();
|
||||
return *this;
|
||||
}
|
||||
DIHeaderFieldIterator operator++(int) {
|
||||
DIHeaderFieldIterator X(*this);
|
||||
increment();
|
||||
return X;
|
||||
}
|
||||
bool operator==(const DIHeaderFieldIterator &X) const {
|
||||
return Current.data() == X.Current.data();
|
||||
}
|
||||
bool operator!=(const DIHeaderFieldIterator &X) const {
|
||||
return !(*this == X);
|
||||
}
|
||||
|
||||
StringRef getHeader() const { return Header; }
|
||||
StringRef getCurrent() const { return Current; }
|
||||
StringRef getPrefix() const {
|
||||
if (Current.begin() == Header.begin())
|
||||
return StringRef();
|
||||
return Header.slice(0, Current.begin() - Header.begin() - 1);
|
||||
}
|
||||
StringRef getSuffix() const {
|
||||
if (Current.end() == Header.end())
|
||||
return StringRef();
|
||||
return Header.slice(Current.end() - Header.begin() + 1, StringRef::npos);
|
||||
}
|
||||
|
||||
/// \brief Get the current field as a number.
|
||||
///
|
||||
/// Convert the current field into a number. Return \c 0 on error.
|
||||
template <class T> T getNumber() const {
|
||||
T Int;
|
||||
if (getCurrent().getAsInteger(0, Int))
|
||||
return 0;
|
||||
return Int;
|
||||
}
|
||||
|
||||
private:
|
||||
void increment() {
|
||||
assert(Current.data() != nullptr && "Cannot increment past the end");
|
||||
StringRef Suffix = getSuffix();
|
||||
Current = Suffix.slice(0, Suffix.find('\0'));
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief A thin wraper around MDNode to access encoded debug info.
|
||||
///
|
||||
/// This should not be stored in a container, because the underlying MDNode may
|
||||
@ -149,22 +90,11 @@ public:
|
||||
protected:
|
||||
const MDNode *DbgNode;
|
||||
|
||||
StringRef getStringField(unsigned Elt) const;
|
||||
unsigned getUnsignedField(unsigned Elt) const {
|
||||
return (unsigned)getUInt64Field(Elt);
|
||||
}
|
||||
uint64_t getUInt64Field(unsigned Elt) const;
|
||||
int64_t getInt64Field(unsigned Elt) const;
|
||||
DIDescriptor getDescriptorField(unsigned Elt) const;
|
||||
|
||||
template <typename DescTy> DescTy getFieldAs(unsigned Elt) const {
|
||||
return DescTy(getDescriptorField(Elt));
|
||||
}
|
||||
|
||||
GlobalVariable *getGlobalVariableField(unsigned Elt) const;
|
||||
Constant *getConstantField(unsigned Elt) const;
|
||||
Function *getFunctionField(unsigned Elt) const;
|
||||
|
||||
public:
|
||||
explicit DIDescriptor(const MDNode *N = nullptr) : DbgNode(N) {}
|
||||
|
||||
@ -188,35 +118,6 @@ public:
|
||||
bool operator==(DIDescriptor Other) const { return DbgNode == Other.DbgNode; }
|
||||
bool operator!=(DIDescriptor Other) const { return !operator==(Other); }
|
||||
|
||||
StringRef getHeader() const { return getStringField(0); }
|
||||
|
||||
size_t getNumHeaderFields() const {
|
||||
return std::distance(DIHeaderFieldIterator(getHeader()),
|
||||
DIHeaderFieldIterator());
|
||||
}
|
||||
|
||||
DIHeaderFieldIterator header_begin() const {
|
||||
return DIHeaderFieldIterator(getHeader());
|
||||
}
|
||||
DIHeaderFieldIterator header_end() const { return DIHeaderFieldIterator(); }
|
||||
|
||||
DIHeaderFieldIterator getHeaderIterator(unsigned Index) const {
|
||||
// Since callers expect an empty string for out-of-range accesses, we can't
|
||||
// use std::advance() here.
|
||||
for (auto I = header_begin(), E = header_end(); I != E; ++I, --Index)
|
||||
if (!Index)
|
||||
return I;
|
||||
return header_end();
|
||||
}
|
||||
|
||||
StringRef getHeaderField(unsigned Index) const {
|
||||
return *getHeaderIterator(Index);
|
||||
}
|
||||
|
||||
template <class T> T getHeaderFieldAs(unsigned Index) const {
|
||||
return getHeaderIterator(Index).getNumber<T>();
|
||||
}
|
||||
|
||||
uint16_t getTag() const {
|
||||
if (auto *N = dyn_cast_or_null<DebugNode>(get()))
|
||||
return N->getTag();
|
||||
|
@ -106,56 +106,11 @@ static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) {
|
||||
return dyn_cast_or_null<MDNode>(getField(DbgNode, Elt));
|
||||
}
|
||||
|
||||
static StringRef getStringField(const MDNode *DbgNode, unsigned Elt) {
|
||||
if (MDString *MDS = dyn_cast_or_null<MDString>(getField(DbgNode, Elt)))
|
||||
return MDS->getString();
|
||||
return StringRef();
|
||||
}
|
||||
|
||||
StringRef DIDescriptor::getStringField(unsigned Elt) const {
|
||||
return ::getStringField(DbgNode, Elt);
|
||||
}
|
||||
|
||||
uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
|
||||
if (auto *C = getConstantField(Elt))
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
|
||||
return CI->getZExtValue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int64_t DIDescriptor::getInt64Field(unsigned Elt) const {
|
||||
if (auto *C = getConstantField(Elt))
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(C))
|
||||
return CI->getZExtValue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
|
||||
MDNode *Field = getNodeField(DbgNode, Elt);
|
||||
return DIDescriptor(Field);
|
||||
}
|
||||
|
||||
GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
|
||||
return dyn_cast_or_null<GlobalVariable>(getConstantField(Elt));
|
||||
}
|
||||
|
||||
Constant *DIDescriptor::getConstantField(unsigned Elt) const {
|
||||
if (!DbgNode)
|
||||
return nullptr;
|
||||
|
||||
if (Elt < DbgNode->getNumOperands())
|
||||
if (auto *C =
|
||||
dyn_cast_or_null<ConstantAsMetadata>(DbgNode->getOperand(Elt)))
|
||||
return C->getValue();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Function *DIDescriptor::getFunctionField(unsigned Elt) const {
|
||||
return dyn_cast_or_null<Function>(getConstantField(Elt));
|
||||
}
|
||||
|
||||
/// \brief Return the size reported by the variable's type.
|
||||
unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
|
||||
DIType Ty = getType().resolve(Map);
|
||||
|
@ -12,59 +12,8 @@
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace llvm {
|
||||
|
||||
static void PrintTo(const StringRef &S, ::std::ostream *os) {
|
||||
*os << "(" << (const void *)S.data() << "," << S.size() << ") = '";
|
||||
for (auto C : S)
|
||||
if (C)
|
||||
*os << C;
|
||||
else
|
||||
*os << "\\00";
|
||||
*os << "'";
|
||||
}
|
||||
static void PrintTo(const DIHeaderFieldIterator &I, ::std::ostream *os) {
|
||||
PrintTo(I.getCurrent(), os);
|
||||
*os << " in ";
|
||||
PrintTo(I.getHeader(), os);
|
||||
}
|
||||
|
||||
} // end namespace llvm
|
||||
|
||||
namespace {
|
||||
|
||||
#define MAKE_FIELD_ITERATOR(S) \
|
||||
DIHeaderFieldIterator(StringRef(S, sizeof(S) - 1))
|
||||
TEST(DebugInfoTest, DIHeaderFieldIterator) {
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), DIHeaderFieldIterator());
|
||||
|
||||
ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR(""));
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR(""));
|
||||
ASSERT_EQ("", *DIHeaderFieldIterator(""));
|
||||
|
||||
ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff"));
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff"));
|
||||
ASSERT_EQ("stuff", *DIHeaderFieldIterator("stuff"));
|
||||
|
||||
ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("st\0uff"));
|
||||
ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("st\0uff"));
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("st\0uff"));
|
||||
ASSERT_EQ("st", *MAKE_FIELD_ITERATOR("st\0uff"));
|
||||
ASSERT_EQ("uff", *++MAKE_FIELD_ITERATOR("st\0uff"));
|
||||
|
||||
ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("stuff\0"));
|
||||
ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("stuff\0"));
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("stuff\0"));
|
||||
ASSERT_EQ("stuff", *MAKE_FIELD_ITERATOR("stuff\0"));
|
||||
ASSERT_EQ("", *++MAKE_FIELD_ITERATOR("stuff\0"));
|
||||
|
||||
ASSERT_NE(DIHeaderFieldIterator(), MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
ASSERT_NE(DIHeaderFieldIterator(), ++MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
ASSERT_EQ(DIHeaderFieldIterator(), ++++MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
ASSERT_EQ("", *MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
ASSERT_EQ("stuff", *++MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
}
|
||||
|
||||
TEST(DIDescriptorTest, getFlag) {
|
||||
// Some valid flags.
|
||||
EXPECT_EQ(DIDescriptor::FlagPublic, DIDescriptor::getFlag("DIFlagPublic"));
|
||||
|
Loading…
Reference in New Issue
Block a user