mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Support: Add dwarf::getLanguage()
llvm-svn: 228458
This commit is contained in:
parent
b69d0ef5cb
commit
b2bb076de9
@ -755,8 +755,16 @@ const char *GDBIndexEntryKindString(GDBIndexEntryKind Kind);
|
||||
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.
|
||||
|
@ -489,6 +489,13 @@ const char *llvm::dwarf::LanguageString(unsigned Language) {
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user