mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Support: Add string => unsigned mapping for DW_TAG
Add `dwarf::getTag()` to translate from `StringRef` to `unsigned`. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228031 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b3d53c6065
commit
5ff000f15e
@ -20,6 +20,7 @@
|
||||
#ifndef LLVM_SUPPORT_DWARF_H
|
||||
#define LLVM_SUPPORT_DWARF_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
|
||||
@ -783,6 +784,9 @@ const char *GDBIndexEntryKindString(GDBIndexEntryKind Kind);
|
||||
const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
|
||||
/// @}
|
||||
|
||||
/// \brief Get the tag number associated with a tag string.
|
||||
unsigned getTag(StringRef TagString);
|
||||
|
||||
/// \brief Returns the symbolic string representing Val when used as a value
|
||||
/// for attribute Attr.
|
||||
const char *AttributeValueString(uint16_t Attr, unsigned Val);
|
||||
|
@ -12,6 +12,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
|
||||
using namespace llvm;
|
||||
@ -27,6 +28,13 @@ const char *llvm::dwarf::TagString(unsigned Tag) {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned llvm::dwarf::getTag(StringRef TagString) {
|
||||
return StringSwitch<unsigned>(TagString)
|
||||
#define HANDLE_DW_TAG(ID, NAME) .Case("DW_TAG_" #NAME, DW_TAG_##NAME)
|
||||
#include "llvm/Support/Dwarf.def"
|
||||
.Default(DW_TAG_invalid);
|
||||
}
|
||||
|
||||
const char *llvm::dwarf::ChildrenString(unsigned Children) {
|
||||
switch (Children) {
|
||||
case DW_CHILDREN_no: return "DW_CHILDREN_no";
|
||||
|
@ -26,4 +26,20 @@ TEST(DwarfTest, TagStringOnInvalid) {
|
||||
EXPECT_EQ(nullptr, TagString(DW_TAG_user_base));
|
||||
}
|
||||
|
||||
TEST(DwarfTest, getTag) {
|
||||
// A couple of valid tags.
|
||||
EXPECT_EQ(DW_TAG_array_type, getTag("DW_TAG_array_type"));
|
||||
EXPECT_EQ(DW_TAG_module, getTag("DW_TAG_module"));
|
||||
|
||||
// Invalid tags.
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_invalid"));
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_madeuptag"));
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("something else"));
|
||||
|
||||
// Tag range markers should not be recognized.
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_lo_user"));
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_hi_user"));
|
||||
EXPECT_EQ(DW_TAG_invalid, getTag("DW_TAG_user_base"));
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user