[llvm] r228470 - Support: Add dwarf::getAttributeEncoding()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Feb 6 15:46:49 PST 2015
Author: dexonsmith
Date: Fri Feb 6 17:46:49 2015
New Revision: 228470
URL: http://llvm.org/viewvc/llvm-project?rev=228470&view=rev
Log:
Support: Add dwarf::getAttributeEncoding()
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=228470&r1=228469&r2=228470&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Dwarf.h (original)
+++ llvm/trunk/include/llvm/Support/Dwarf.h Fri Feb 6 17:46:49 2015
@@ -749,6 +749,7 @@ const char *GDBIndexEntryLinkageString(G
/// @{
unsigned getTag(StringRef TagString);
unsigned getLanguage(StringRef LanguageString);
+unsigned getAttributeEncoding(StringRef EncodingString);
/// @}
/// \brief Returns the symbolic string representing Val when used as a value
Modified: llvm/trunk/lib/Support/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Dwarf.cpp?rev=228470&r1=228469&r2=228470&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Dwarf.cpp (original)
+++ llvm/trunk/lib/Support/Dwarf.cpp Fri Feb 6 17:46:49 2015
@@ -414,6 +414,13 @@ const char *llvm::dwarf::AttributeEncodi
}
}
+unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) {
+ return StringSwitch<unsigned>(EncodingString)
+#define HANDLE_DW_ATE(ID, NAME) .Case("DW_ATE_" #NAME, DW_ATE_##NAME)
+#include "llvm/Support/Dwarf.def"
+ .Default(0);
+}
+
const char *llvm::dwarf::DecimalSignString(unsigned Sign) {
switch (Sign) {
case DW_DS_unsigned: return "DW_DS_unsigned";
Modified: llvm/trunk/unittests/Support/DwarfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/DwarfTest.cpp?rev=228470&r1=228469&r2=228470&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/DwarfTest.cpp (original)
+++ llvm/trunk/unittests/Support/DwarfTest.cpp Fri Feb 6 17:46:49 2015
@@ -79,4 +79,20 @@ TEST(DwarfTest, AttributeEncodingStringO
EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_hi_user));
}
+TEST(DwarfTest, getAttributeEncoding) {
+ // A couple of valid languages.
+ EXPECT_EQ(DW_ATE_boolean, getAttributeEncoding("DW_ATE_boolean"));
+ EXPECT_EQ(DW_ATE_imaginary_float,
+ getAttributeEncoding("DW_ATE_imaginary_float"));
+
+ // Invalid languages.
+ EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_invalid"));
+ EXPECT_EQ(0u, getAttributeEncoding("DW_TAG_array_type"));
+ EXPECT_EQ(0u, getAttributeEncoding("something else"));
+
+ // AttributeEncoding range markers should not be recognized.
+ EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_lo_user"));
+ EXPECT_EQ(0u, getAttributeEncoding("DW_ATE_hi_user"));
+}
+
} // end namespace
More information about the llvm-commits
mailing list