Support: Add dwarf::getOperationEncoding()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229001 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-13 01:05:00 +00:00
parent 5fc468cbf5
commit 191690dc8c
3 changed files with 22 additions and 0 deletions

View File

@ -590,6 +590,7 @@ const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
///
/// @{
unsigned getTag(StringRef TagString);
unsigned getOperationEncoding(StringRef OperationEncodingString);
unsigned getVirtuality(StringRef VirtualityString);
unsigned getLanguage(StringRef LanguageString);
unsigned getAttributeEncoding(StringRef EncodingString);

View File

@ -247,6 +247,13 @@ const char *llvm::dwarf::OperationEncodingString(unsigned Encoding) {
}
}
unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) {
return StringSwitch<unsigned>(OperationEncodingString)
#define HANDLE_DW_OP(ID, NAME) .Case("DW_OP_" #NAME, DW_OP_##NAME)
#include "llvm/Support/Dwarf.def"
.Default(0);
}
const char *llvm::dwarf::AttributeEncodingString(unsigned Encoding) {
switch (Encoding) {
default: return nullptr;

View File

@ -42,6 +42,20 @@ TEST(DwarfTest, getTag) {
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_user_base"));
}
TEST(DwarfTest, getOperationEncoding) {
// Some valid ops.
EXPECT_EQ(DW_OP_deref, getOperationEncoding("DW_OP_deref"));
EXPECT_EQ(DW_OP_bit_piece, getOperationEncoding("DW_OP_bit_piece"));
// Invalid ops.
EXPECT_EQ(0u, getOperationEncoding("DW_OP_otherthings"));
EXPECT_EQ(0u, getOperationEncoding("other"));
// Markers shouldn't be recognized.
EXPECT_EQ(0u, getOperationEncoding("DW_OP_lo_user"));
EXPECT_EQ(0u, getOperationEncoding("DW_OP_hi_user"));
}
TEST(DwarfTest, LanguageStringOnInvalid) {
// This is invalid, so it shouldn't be stringified.
EXPECT_EQ(nullptr, LanguageString(0));