mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-04 10:30:01 +00:00
IR: Add debug info flag string conversions
Add `DIDescriptor::getFlag(StringRef)` and `DIDescriptor::getFlagString(unsigned)`. The latter only converts exact matches; I'll add separate API for breaking the flags bitfield up into parts. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230107 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5eba204198
commit
2e19fabc26
@ -137,6 +137,9 @@ public:
|
||||
FlagAccessibility = FlagPrivate | FlagProtected | FlagPublic
|
||||
};
|
||||
|
||||
static unsigned getFlag(StringRef Flag);
|
||||
static const char *getFlagString(unsigned Flag);
|
||||
|
||||
protected:
|
||||
const MDNode *DbgNode;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#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"
|
||||
@ -36,6 +37,24 @@ 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"
|
||||
}
|
||||
}
|
||||
|
||||
bool DIDescriptor::Verify() const {
|
||||
return DbgNode &&
|
||||
(DIDerivedType(DbgNode).Verify() ||
|
||||
|
@ -65,4 +65,50 @@ TEST(DebugInfoTest, DIHeaderFieldIterator) {
|
||||
ASSERT_EQ("stuff", *++MAKE_FIELD_ITERATOR("\0stuff"));
|
||||
}
|
||||
|
||||
TEST(DIDescriptorTest, 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"));
|
||||
|
||||
// FlagAccessibility shouldn't work.
|
||||
EXPECT_EQ(0u, DIDescriptor::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"));
|
||||
}
|
||||
|
||||
TEST(DIDescriptorTest, getFlagString) {
|
||||
// Some valid flags.
|
||||
EXPECT_EQ(StringRef("DIFlagPublic"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagPublic));
|
||||
EXPECT_EQ(StringRef("DIFlagProtected"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagProtected));
|
||||
EXPECT_EQ(StringRef("DIFlagPrivate"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagPrivate));
|
||||
EXPECT_EQ(StringRef("DIFlagVector"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagVector));
|
||||
EXPECT_EQ(StringRef("DIFlagRValueReference"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::FlagRValueReference));
|
||||
|
||||
// FlagAccessibility actually equals FlagPublic.
|
||||
EXPECT_EQ(StringRef("DIFlagPublic"),
|
||||
DIDescriptor::getFlagString(DIDescriptor::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));
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user