Support: Add dwarf::getAttributeEncoding()

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228470 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-02-06 23:46:49 +00:00
parent 87c9a125d8
commit e29c334dd4
3 changed files with 24 additions and 0 deletions

View File

@ -749,6 +749,7 @@ const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
/// @{
unsigned getTag(StringRef TagString);
unsigned getLanguage(StringRef LanguageString);
unsigned getAttributeEncoding(StringRef EncodingString);
/// @}
/// \brief Returns the symbolic string representing Val when used as a value

View File

@ -414,6 +414,13 @@ const char *llvm::dwarf::AttributeEncodingString(unsigned Encoding) {
}
}
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";

View File

@ -79,4 +79,20 @@ TEST(DwarfTest, AttributeEncodingStringOnInvalid) {
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