[llvm] r229001 - Support: Add dwarf::getOperationEncoding()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Thu Feb 12 17:05:01 PST 2015
Author: dexonsmith
Date: Thu Feb 12 19:05:00 2015
New Revision: 229001
URL: http://llvm.org/viewvc/llvm-project?rev=229001&view=rev
Log:
Support: Add dwarf::getOperationEncoding()
Modified:
llvm/trunk/include/llvm/Support/Dwarf.h
llvm/trunk/lib/Support/Dwarf.cpp
llvm/trunk/unittests/Support/DwarfTest.cpp
Modified: llvm/trunk/include/llvm/Support/Dwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Dwarf.h?rev=229001&r1=229000&r2=229001&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Dwarf.h (original)
+++ llvm/trunk/include/llvm/Support/Dwarf.h Thu Feb 12 19:05:00 2015
@@ -590,6 +590,7 @@ const char *GDBIndexEntryLinkageString(G
///
/// @{
unsigned getTag(StringRef TagString);
+unsigned getOperationEncoding(StringRef OperationEncodingString);
unsigned getVirtuality(StringRef VirtualityString);
unsigned getLanguage(StringRef LanguageString);
unsigned getAttributeEncoding(StringRef EncodingString);
Modified: llvm/trunk/lib/Support/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Dwarf.cpp?rev=229001&r1=229000&r2=229001&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Dwarf.cpp (original)
+++ llvm/trunk/lib/Support/Dwarf.cpp Thu Feb 12 19:05:00 2015
@@ -247,6 +247,13 @@ const char *llvm::dwarf::OperationEncodi
}
}
+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;
Modified: llvm/trunk/unittests/Support/DwarfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/DwarfTest.cpp?rev=229001&r1=229000&r2=229001&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/DwarfTest.cpp (original)
+++ llvm/trunk/unittests/Support/DwarfTest.cpp Thu Feb 12 19:05:00 2015
@@ -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));
More information about the llvm-commits
mailing list