[llvm] r228458 - Support: Add dwarf::getLanguage()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Feb 6 14:55:14 PST 2015
Author: dexonsmith
Date: Fri Feb 6 16:55:13 2015
New Revision: 228458
URL: http://llvm.org/viewvc/llvm-project?rev=228458&view=rev
Log:
Support: Add dwarf::getLanguage()
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=228458&r1=228457&r2=228458&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Dwarf.h (original)
+++ llvm/trunk/include/llvm/Support/Dwarf.h Fri Feb 6 16:55:13 2015
@@ -755,8 +755,16 @@ const char *GDBIndexEntryKindString(GDBI
const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
/// @}
-/// \brief Get the tag number associated with a tag string.
+/// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
+///
+/// These functions map their strings back to the corresponding enumeration
+/// value or return 0 if there is none. As an exception, \a getTag() returns
+/// \a DW_TAG_invalid on invalid input.
+///
+/// @{
unsigned getTag(StringRef TagString);
+unsigned getLanguage(StringRef LanguageString);
+/// @}
/// \brief Returns the symbolic string representing Val when used as a value
/// for attribute Attr.
Modified: llvm/trunk/lib/Support/Dwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Dwarf.cpp?rev=228458&r1=228457&r2=228458&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Dwarf.cpp (original)
+++ llvm/trunk/lib/Support/Dwarf.cpp Fri Feb 6 16:55:13 2015
@@ -489,6 +489,13 @@ const char *llvm::dwarf::LanguageString(
}
}
+unsigned llvm::dwarf::getLanguage(StringRef LanguageString) {
+ return StringSwitch<unsigned>(LanguageString)
+#define HANDLE_DW_LANG(ID, NAME) .Case("DW_LANG_" #NAME, DW_LANG_##NAME)
+#include "llvm/Support/Dwarf.def"
+ .Default(0);
+}
+
const char *llvm::dwarf::CaseString(unsigned Case) {
switch (Case) {
case DW_ID_case_sensitive: return "DW_ID_case_sensitive";
Modified: llvm/trunk/unittests/Support/DwarfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/DwarfTest.cpp?rev=228458&r1=228457&r2=228458&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/DwarfTest.cpp (original)
+++ llvm/trunk/unittests/Support/DwarfTest.cpp Fri Feb 6 16:55:13 2015
@@ -52,4 +52,21 @@ TEST(DwarfTest, LanguageStringOnInvalid)
EXPECT_EQ(nullptr, LanguageString(DW_LANG_hi_user));
}
+TEST(DwarfTest, getLanguage) {
+ // A couple of valid languages.
+ EXPECT_EQ(DW_LANG_C89, getLanguage("DW_LANG_C89"));
+ EXPECT_EQ(DW_LANG_C_plus_plus_11, getLanguage("DW_LANG_C_plus_plus_11"));
+ EXPECT_EQ(DW_LANG_OCaml, getLanguage("DW_LANG_OCaml"));
+ EXPECT_EQ(DW_LANG_Mips_Assembler, getLanguage("DW_LANG_Mips_Assembler"));
+
+ // Invalid languages.
+ EXPECT_EQ(0u, getLanguage("DW_LANG_invalid"));
+ EXPECT_EQ(0u, getLanguage("DW_TAG_array_type"));
+ EXPECT_EQ(0u, getLanguage("something else"));
+
+ // Language range markers should not be recognized.
+ EXPECT_EQ(0u, getLanguage("DW_LANG_lo_user"));
+ EXPECT_EQ(0u, getLanguage("DW_LANG_hi_user"));
+}
+
} // end namespace
More information about the llvm-commits
mailing list