From 191690dc8c0076ce1b3f7a36a4681082e3361b86 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 13 Feb 2015 01:05:00 +0000 Subject: [PATCH] Support: Add dwarf::getOperationEncoding() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229001 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/Dwarf.h | 1 + lib/Support/Dwarf.cpp | 7 +++++++ unittests/Support/DwarfTest.cpp | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/llvm/Support/Dwarf.h b/include/llvm/Support/Dwarf.h index bff8162fdeb..c294a72a04b 100644 --- a/include/llvm/Support/Dwarf.h +++ b/include/llvm/Support/Dwarf.h @@ -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); diff --git a/lib/Support/Dwarf.cpp b/lib/Support/Dwarf.cpp index a2bd6cb7061..95c4bc32701 100644 --- a/lib/Support/Dwarf.cpp +++ b/lib/Support/Dwarf.cpp @@ -247,6 +247,13 @@ const char *llvm::dwarf::OperationEncodingString(unsigned Encoding) { } } +unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) { + return StringSwitch(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; diff --git a/unittests/Support/DwarfTest.cpp b/unittests/Support/DwarfTest.cpp index 5352982aa13..74fcc989b45 100644 --- a/unittests/Support/DwarfTest.cpp +++ b/unittests/Support/DwarfTest.cpp @@ -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));