mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-15 19:24:33 +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:
@@ -20,6 +20,7 @@
|
|||||||
#ifndef LLVM_SUPPORT_DWARF_H
|
#ifndef LLVM_SUPPORT_DWARF_H
|
||||||
#define LLVM_SUPPORT_DWARF_H
|
#define LLVM_SUPPORT_DWARF_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
|
|
||||||
@@ -783,6 +784,9 @@ const char *GDBIndexEntryKindString(GDBIndexEntryKind Kind);
|
|||||||
const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
|
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
|
/// \brief Returns the symbolic string representing Val when used as a value
|
||||||
/// for attribute Attr.
|
/// for attribute Attr.
|
||||||
const char *AttributeValueString(uint16_t Attr, unsigned Val);
|
const char *AttributeValueString(uint16_t Attr, unsigned Val);
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Support/Dwarf.h"
|
#include "llvm/Support/Dwarf.h"
|
||||||
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
|
|
||||||
using namespace llvm;
|
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) {
|
const char *llvm::dwarf::ChildrenString(unsigned Children) {
|
||||||
switch (Children) {
|
switch (Children) {
|
||||||
case DW_CHILDREN_no: return "DW_CHILDREN_no";
|
case DW_CHILDREN_no: return "DW_CHILDREN_no";
|
||||||
|
@@ -26,4 +26,20 @@ TEST(DwarfTest, TagStringOnInvalid) {
|
|||||||
EXPECT_EQ(nullptr, TagString(DW_TAG_user_base));
|
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
|
} // end namespace
|
||||||
|
Reference in New Issue
Block a user