mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-23 11:04:49 +00:00
DebugInfo: Move DIFlag-related API from DIDescriptor to DebugNode
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234274 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
329f8219cd
commit
5f3bcf7dc4
@ -77,16 +77,6 @@ public:
|
||||
FlagAccessibility = DebugNode::FlagAccessibility
|
||||
};
|
||||
|
||||
static unsigned getFlag(StringRef Flag);
|
||||
static const char *getFlagString(unsigned Flag);
|
||||
|
||||
/// \brief Split up a flags bitfield.
|
||||
///
|
||||
/// Split \c Flags into \c SplitFlags, a vector of its components. Returns
|
||||
/// any remaining (unrecognized) bits.
|
||||
static unsigned splitFlags(unsigned Flags,
|
||||
SmallVectorImpl<unsigned> &SplitFlags);
|
||||
|
||||
protected:
|
||||
const MDNode *DbgNode;
|
||||
|
||||
|
@ -175,6 +175,16 @@ public:
|
||||
FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
|
||||
};
|
||||
|
||||
static unsigned getFlag(StringRef Flag);
|
||||
static const char *getFlagString(unsigned Flag);
|
||||
|
||||
/// \brief Split up a flags bitfield.
|
||||
///
|
||||
/// Split \c Flags into \c SplitFlags, a vector of its components. Returns
|
||||
/// any remaining (unrecognized) bits.
|
||||
static unsigned splitFlags(unsigned Flags,
|
||||
SmallVectorImpl<unsigned> &SplitFlags);
|
||||
|
||||
DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
|
||||
|
||||
static bool classof(const Metadata *MD) {
|
||||
|
@ -3165,7 +3165,7 @@ bool LLParser::ParseMDField(LocTy Loc, StringRef Name, DIFlagField &Result) {
|
||||
if (Lex.getKind() != lltok::DIFlag)
|
||||
return TokError("expected debug info flag");
|
||||
|
||||
Val = DIDescriptor::getFlag(Lex.getStrVal());
|
||||
Val = DebugNode::getFlag(Lex.getStrVal());
|
||||
if (!Val)
|
||||
return TokError(Twine("invalid debug info flag flag '") +
|
||||
Lex.getStrVal() + "'");
|
||||
|
@ -1443,11 +1443,11 @@ void MDFieldPrinter::printDIFlags(StringRef Name, unsigned Flags) {
|
||||
Out << FS << Name << ": ";
|
||||
|
||||
SmallVector<unsigned, 8> SplitFlags;
|
||||
unsigned Extra = DIDescriptor::splitFlags(Flags, SplitFlags);
|
||||
unsigned Extra = DebugNode::splitFlags(Flags, SplitFlags);
|
||||
|
||||
FieldSeparator FlagsFS(" | ");
|
||||
for (unsigned F : SplitFlags) {
|
||||
const char *StringF = DIDescriptor::getFlagString(F);
|
||||
const char *StringF = DebugNode::getFlagString(F);
|
||||
assert(StringF && "Expected valid flag");
|
||||
Out << FlagsFS << StringF;
|
||||
}
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Analysis/ValueTracking.h"
|
||||
#include "llvm/IR/Constants.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
@ -38,48 +37,6 @@ using namespace llvm::dwarf;
|
||||
// DIDescriptor
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
unsigned DIDescriptor::getFlag(StringRef Flag) {
|
||||
return StringSwitch<unsigned>(Flag)
|
||||
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
.Default(0);
|
||||
}
|
||||
|
||||
const char *DIDescriptor::getFlagString(unsigned Flag) {
|
||||
switch (Flag) {
|
||||
default:
|
||||
return "";
|
||||
#define HANDLE_DI_FLAG(ID, NAME) \
|
||||
case Flag##NAME: \
|
||||
return "DIFlag" #NAME;
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
}
|
||||
}
|
||||
|
||||
unsigned DIDescriptor::splitFlags(unsigned Flags,
|
||||
SmallVectorImpl<unsigned> &SplitFlags) {
|
||||
// Accessibility flags need to be specially handled, since they're packed
|
||||
// together.
|
||||
if (unsigned A = Flags & FlagAccessibility) {
|
||||
if (A == FlagPrivate)
|
||||
SplitFlags.push_back(FlagPrivate);
|
||||
else if (A == FlagProtected)
|
||||
SplitFlags.push_back(FlagProtected);
|
||||
else
|
||||
SplitFlags.push_back(FlagPublic);
|
||||
Flags &= ~A;
|
||||
}
|
||||
|
||||
#define HANDLE_DI_FLAG(ID, NAME) \
|
||||
if (unsigned Bit = Flags & ID) { \
|
||||
SplitFlags.push_back(Bit); \
|
||||
Flags &= ~Bit; \
|
||||
}
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
|
||||
return Flags;
|
||||
}
|
||||
|
||||
static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
|
||||
if (!DbgNode || Elt >= DbgNode->getNumOperands())
|
||||
return nullptr;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "llvm/IR/DebugInfoMetadata.h"
|
||||
#include "LLVMContextImpl.h"
|
||||
#include "MetadataImpl.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
|
||||
using namespace llvm;
|
||||
@ -65,6 +66,49 @@ MDLocation *MDLocation::getImpl(LLVMContext &Context, unsigned Line,
|
||||
Storage, Context.pImpl->MDLocations);
|
||||
}
|
||||
|
||||
unsigned DebugNode::getFlag(StringRef Flag) {
|
||||
return StringSwitch<unsigned>(Flag)
|
||||
#define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
.Default(0);
|
||||
}
|
||||
|
||||
const char *DebugNode::getFlagString(unsigned Flag) {
|
||||
switch (Flag) {
|
||||
default:
|
||||
return "";
|
||||
#define HANDLE_DI_FLAG(ID, NAME) \
|
||||
case Flag##NAME: \
|
||||
return "DIFlag" #NAME;
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
}
|
||||
}
|
||||
|
||||
unsigned DebugNode::splitFlags(unsigned Flags,
|
||||
SmallVectorImpl<unsigned> &SplitFlags) {
|
||||
// Accessibility flags need to be specially handled, since they're packed
|
||||
// together.
|
||||
if (unsigned A = Flags & FlagAccessibility) {
|
||||
if (A == FlagPrivate)
|
||||
SplitFlags.push_back(FlagPrivate);
|
||||
else if (A == FlagProtected)
|
||||
SplitFlags.push_back(FlagProtected);
|
||||
else
|
||||
SplitFlags.push_back(FlagPublic);
|
||||
Flags &= ~A;
|
||||
}
|
||||
|
||||
#define HANDLE_DI_FLAG(ID, NAME) \
|
||||
if (unsigned Bit = Flags & ID) { \
|
||||
SplitFlags.push_back(Bit); \
|
||||
Flags &= ~Bit; \
|
||||
}
|
||||
#include "llvm/IR/DebugInfoFlags.def"
|
||||
|
||||
return Flags;
|
||||
}
|
||||
|
||||
|
||||
static StringRef getString(const MDString *S) {
|
||||
if (S)
|
||||
return S->getString();
|
||||
|
@ -7,76 +7,75 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
#include "llvm/IR/DebugInfoMetadata.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
TEST(DIDescriptorTest, getFlag) {
|
||||
TEST(DebugNodeTest, getFlag) {
|
||||
// Some valid flags.
|
||||
EXPECT_EQ(DIDescriptor::FlagPublic, DIDescriptor::getFlag("DIFlagPublic"));
|
||||
EXPECT_EQ(DIDescriptor::FlagProtected,
|
||||
DIDescriptor::getFlag("DIFlagProtected"));
|
||||
EXPECT_EQ(DIDescriptor::FlagPrivate, DIDescriptor::getFlag("DIFlagPrivate"));
|
||||
EXPECT_EQ(DIDescriptor::FlagVector, DIDescriptor::getFlag("DIFlagVector"));
|
||||
EXPECT_EQ(DIDescriptor::FlagRValueReference,
|
||||
DIDescriptor::getFlag("DIFlagRValueReference"));
|
||||
EXPECT_EQ(DebugNode::FlagPublic, DebugNode::getFlag("DIFlagPublic"));
|
||||
EXPECT_EQ(DebugNode::FlagProtected, DebugNode::getFlag("DIFlagProtected"));
|
||||
EXPECT_EQ(DebugNode::FlagPrivate, DebugNode::getFlag("DIFlagPrivate"));
|
||||
EXPECT_EQ(DebugNode::FlagVector, DebugNode::getFlag("DIFlagVector"));
|
||||
EXPECT_EQ(DebugNode::FlagRValueReference,
|
||||
DebugNode::getFlag("DIFlagRValueReference"));
|
||||
|
||||
// FlagAccessibility shouldn't work.
|
||||
EXPECT_EQ(0u, DIDescriptor::getFlag("DIFlagAccessibility"));
|
||||
EXPECT_EQ(0u, DebugNode::getFlag("DIFlagAccessibility"));
|
||||
|
||||
// Some other invalid strings.
|
||||
EXPECT_EQ(0u, DIDescriptor::getFlag("FlagVector"));
|
||||
EXPECT_EQ(0u, DIDescriptor::getFlag("Vector"));
|
||||
EXPECT_EQ(0u, DIDescriptor::getFlag("other things"));
|
||||
EXPECT_EQ(0u, DIDescriptor::getFlag("DIFlagOther"));
|
||||
EXPECT_EQ(0u, DebugNode::getFlag("FlagVector"));
|
||||
EXPECT_EQ(0u, DebugNode::getFlag("Vector"));
|
||||
EXPECT_EQ(0u, DebugNode::getFlag("other things"));
|
||||
EXPECT_EQ(0u, DebugNode::getFlag("DIFlagOther"));
|
||||
}
|
||||
|
||||
TEST(DIDescriptorTest, getFlagString) {
|
||||
TEST(DebugNodeTest, getFlagString) {
|
||||
// Some valid flags.
|
||||
EXPECT_EQ(StringRef("DIFlagPublic"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagPublic));
|
||||
DebugNode::getFlagString(DebugNode::FlagPublic));
|
||||
EXPECT_EQ(StringRef("DIFlagProtected"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagProtected));
|
||||
DebugNode::getFlagString(DebugNode::FlagProtected));
|
||||
EXPECT_EQ(StringRef("DIFlagPrivate"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagPrivate));
|
||||
DebugNode::getFlagString(DebugNode::FlagPrivate));
|
||||
EXPECT_EQ(StringRef("DIFlagVector"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagVector));
|
||||
DebugNode::getFlagString(DebugNode::FlagVector));
|
||||
EXPECT_EQ(StringRef("DIFlagRValueReference"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagRValueReference));
|
||||
DebugNode::getFlagString(DebugNode::FlagRValueReference));
|
||||
|
||||
// FlagAccessibility actually equals FlagPublic.
|
||||
EXPECT_EQ(StringRef("DIFlagPublic"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagAccessibility));
|
||||
DebugNode::getFlagString(DebugNode::FlagAccessibility));
|
||||
|
||||
// Some other invalid flags.
|
||||
EXPECT_EQ(StringRef(), DIDescriptor::getFlagString(DIDescriptor::FlagPublic |
|
||||
DIDescriptor::FlagVector));
|
||||
EXPECT_EQ(StringRef(),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagFwdDecl |
|
||||
DIDescriptor::FlagArtificial));
|
||||
EXPECT_EQ(StringRef(), DIDescriptor::getFlagString(0xffff));
|
||||
EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagPublic |
|
||||
DebugNode::FlagVector));
|
||||
EXPECT_EQ(StringRef(), DebugNode::getFlagString(DebugNode::FlagFwdDecl |
|
||||
DebugNode::FlagArtificial));
|
||||
EXPECT_EQ(StringRef(), DebugNode::getFlagString(0xffff));
|
||||
}
|
||||
|
||||
TEST(DIDescriptorTest, splitFlags) {
|
||||
// Some valid flags.
|
||||
TEST(DebugNodeTest, splitFlags) {
|
||||
// Some valid flags.
|
||||
#define CHECK_SPLIT(FLAGS, VECTOR, REMAINDER) \
|
||||
{ \
|
||||
SmallVector<unsigned, 8> V; \
|
||||
EXPECT_EQ(REMAINDER, DIDescriptor::splitFlags(FLAGS, V)); \
|
||||
EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
|
||||
EXPECT_EQ(REMAINDER, DebugNode::splitFlags(FLAGS, V)); \
|
||||
EXPECT_TRUE(makeArrayRef(V).equals(VECTOR)); \
|
||||
}
|
||||
CHECK_SPLIT(DIDescriptor::FlagPublic, {DIDescriptor::FlagPublic}, 0u);
|
||||
CHECK_SPLIT(DIDescriptor::FlagProtected, {DIDescriptor::FlagProtected}, 0u);
|
||||
CHECK_SPLIT(DIDescriptor::FlagPrivate, {DIDescriptor::FlagPrivate}, 0u);
|
||||
CHECK_SPLIT(DIDescriptor::FlagVector, {DIDescriptor::FlagVector}, 0u);
|
||||
CHECK_SPLIT(DIDescriptor::FlagRValueReference, {DIDescriptor::FlagRValueReference}, 0u);
|
||||
unsigned Flags[] = {DIDescriptor::FlagFwdDecl, DIDescriptor::FlagVector};
|
||||
CHECK_SPLIT(DIDescriptor::FlagFwdDecl | DIDescriptor::FlagVector, Flags, 0u);
|
||||
CHECK_SPLIT(DebugNode::FlagPublic, {DebugNode::FlagPublic}, 0u);
|
||||
CHECK_SPLIT(DebugNode::FlagProtected, {DebugNode::FlagProtected}, 0u);
|
||||
CHECK_SPLIT(DebugNode::FlagPrivate, {DebugNode::FlagPrivate}, 0u);
|
||||
CHECK_SPLIT(DebugNode::FlagVector, {DebugNode::FlagVector}, 0u);
|
||||
CHECK_SPLIT(DebugNode::FlagRValueReference, {DebugNode::FlagRValueReference},
|
||||
0u);
|
||||
unsigned Flags[] = {DebugNode::FlagFwdDecl, DebugNode::FlagVector};
|
||||
CHECK_SPLIT(DebugNode::FlagFwdDecl | DebugNode::FlagVector, Flags, 0u);
|
||||
CHECK_SPLIT(0x100000u, {}, 0x100000u);
|
||||
CHECK_SPLIT(0x100000u | DIDescriptor::FlagVector, {DIDescriptor::FlagVector},
|
||||
CHECK_SPLIT(0x100000u | DebugNode::FlagVector, {DebugNode::FlagVector},
|
||||
0x100000u);
|
||||
#undef CHECK_SPLIT
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user