1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Revert "Re-commit "Use StringRef in Support/Darf APIs (NFC)""

One test seems randomly broken: DebugInfo/X86/gnu-public-names.ll

llvm-svn: 283285
This commit is contained in:
Mehdi Amini 2016-10-05 01:04:02 +00:00
parent 1ab7cb5cc2
commit c494f9f824
11 changed files with 128 additions and 142 deletions

View File

@ -606,31 +606,31 @@ enum GDBIndexEntryLinkage {
/// known. /// known.
/// ///
/// @{ /// @{
StringRef TagString(unsigned Tag); const char *TagString(unsigned Tag);
StringRef ChildrenString(unsigned Children); const char *ChildrenString(unsigned Children);
StringRef AttributeString(unsigned Attribute); const char *AttributeString(unsigned Attribute);
StringRef FormEncodingString(unsigned Encoding); const char *FormEncodingString(unsigned Encoding);
StringRef OperationEncodingString(unsigned Encoding); const char *OperationEncodingString(unsigned Encoding);
StringRef AttributeEncodingString(unsigned Encoding); const char *AttributeEncodingString(unsigned Encoding);
StringRef DecimalSignString(unsigned Sign); const char *DecimalSignString(unsigned Sign);
StringRef EndianityString(unsigned Endian); const char *EndianityString(unsigned Endian);
StringRef AccessibilityString(unsigned Access); const char *AccessibilityString(unsigned Access);
StringRef VisibilityString(unsigned Visibility); const char *VisibilityString(unsigned Visibility);
StringRef VirtualityString(unsigned Virtuality); const char *VirtualityString(unsigned Virtuality);
StringRef LanguageString(unsigned Language); const char *LanguageString(unsigned Language);
StringRef CaseString(unsigned Case); const char *CaseString(unsigned Case);
StringRef ConventionString(unsigned Convention); const char *ConventionString(unsigned Convention);
StringRef InlineCodeString(unsigned Code); const char *InlineCodeString(unsigned Code);
StringRef ArrayOrderString(unsigned Order); const char *ArrayOrderString(unsigned Order);
StringRef DiscriminantString(unsigned Discriminant); const char *DiscriminantString(unsigned Discriminant);
StringRef LNStandardString(unsigned Standard); const char *LNStandardString(unsigned Standard);
StringRef LNExtendedString(unsigned Encoding); const char *LNExtendedString(unsigned Encoding);
StringRef MacinfoString(unsigned Encoding); const char *MacinfoString(unsigned Encoding);
StringRef CallFrameString(unsigned Encoding); const char *CallFrameString(unsigned Encoding);
StringRef ApplePropertyString(unsigned); const char *ApplePropertyString(unsigned);
StringRef AtomTypeString(unsigned Atom); const char *AtomTypeString(unsigned Atom);
StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind); const char *GDBIndexEntryKindString(GDBIndexEntryKind Kind);
StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage); const char *GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
/// @} /// @}
/// \defgroup DwarfConstantsParsing Dwarf constants parsing functions /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
@ -654,7 +654,7 @@ unsigned getMacinfo(StringRef MacinfoString);
/// \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.
StringRef AttributeValueString(uint16_t Attr, unsigned Val); const char *AttributeValueString(uint16_t Attr, unsigned Val);
/// \brief Decsribes an entry of the various gnu_pub* debug sections. /// \brief Decsribes an entry of the various gnu_pub* debug sections.
/// ///

View File

@ -74,8 +74,7 @@ void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
// filenames), so just print a few useful things. // filenames), so just print a few useful things.
for (DICompileUnit *CU : Finder.compile_units()) { for (DICompileUnit *CU : Finder.compile_units()) {
O << "Compile unit: "; O << "Compile unit: ";
auto Lang = dwarf::LanguageString(CU->getSourceLanguage()); if (const char *Lang = dwarf::LanguageString(CU->getSourceLanguage()))
if (!Lang.empty())
O << Lang; O << Lang;
else else
O << "unknown-language(" << CU->getSourceLanguage() << ")"; O << "unknown-language(" << CU->getSourceLanguage() << ")";
@ -106,15 +105,14 @@ void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
printFile(O, T->getFilename(), T->getDirectory(), T->getLine()); printFile(O, T->getFilename(), T->getDirectory(), T->getLine());
if (auto *BT = dyn_cast<DIBasicType>(T)) { if (auto *BT = dyn_cast<DIBasicType>(T)) {
O << " "; O << " ";
auto Encoding = dwarf::AttributeEncodingString(BT->getEncoding()); if (const char *Encoding =
if (!Encoding.empty()) dwarf::AttributeEncodingString(BT->getEncoding()))
O << Encoding; O << Encoding;
else else
O << "unknown-encoding(" << BT->getEncoding() << ')'; O << "unknown-encoding(" << BT->getEncoding() << ')';
} else { } else {
O << ' '; O << ' ';
auto Tag = dwarf::TagString(T->getTag()); if (const char *Tag = dwarf::TagString(T->getTag()))
if (!Tag.empty())
O << Tag; O << Tag;
else else
O << "unknown-tag(" << T->getTag() << ")"; O << "unknown-tag(" << T->getTag() << ")";

View File

@ -63,10 +63,10 @@ void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
/// ///
void DIEAbbrev::Emit(const AsmPrinter *AP) const { void DIEAbbrev::Emit(const AsmPrinter *AP) const {
// Emit its Dwarf tag type. // Emit its Dwarf tag type.
AP->EmitULEB128(Tag, dwarf::TagString(Tag).data()); AP->EmitULEB128(Tag, dwarf::TagString(Tag));
// Emit whether it has children DIEs. // Emit whether it has children DIEs.
AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data()); AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children));
// For each attribute description. // For each attribute description.
for (unsigned i = 0, N = Data.size(); i < N; ++i) { for (unsigned i = 0, N = Data.size(); i < N; ++i) {
@ -74,11 +74,11 @@ void DIEAbbrev::Emit(const AsmPrinter *AP) const {
// Emit attribute type. // Emit attribute type.
AP->EmitULEB128(AttrData.getAttribute(), AP->EmitULEB128(AttrData.getAttribute(),
dwarf::AttributeString(AttrData.getAttribute()).data()); dwarf::AttributeString(AttrData.getAttribute()));
// Emit form type. // Emit form type.
AP->EmitULEB128(AttrData.getForm(), AP->EmitULEB128(AttrData.getForm(),
dwarf::FormEncodingString(AttrData.getForm()).data()); dwarf::FormEncodingString(AttrData.getForm()));
} }
// Mark end of abbreviation. // Mark end of abbreviation.

View File

@ -62,23 +62,23 @@ DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
} }
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const { void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
auto tagString = TagString(getTag()); const char *tagString = TagString(getTag());
OS << '[' << getCode() << "] "; OS << '[' << getCode() << "] ";
if (!tagString.empty()) if (tagString)
OS << tagString; OS << tagString;
else else
OS << format("DW_TAG_Unknown_%x", getTag()); OS << format("DW_TAG_Unknown_%x", getTag());
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n'; OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
for (const AttributeSpec &Spec : AttributeSpecs) { for (const AttributeSpec &Spec : AttributeSpecs) {
OS << '\t'; OS << '\t';
auto attrString = AttributeString(Spec.Attr); const char *attrString = AttributeString(Spec.Attr);
if (!attrString.empty()) if (attrString)
OS << attrString; OS << attrString;
else else
OS << format("DW_AT_Unknown_%x", Spec.Attr); OS << format("DW_AT_Unknown_%x", Spec.Attr);
OS << '\t'; OS << '\t';
auto formString = FormEncodingString(Spec.Form); const char *formString = FormEncodingString(Spec.Form);
if (!formString.empty()) if (formString)
OS << formString; OS << formString;
else else
OS << format("DW_FORM_Unknown_%x", Spec.Form); OS << format("DW_FORM_Unknown_%x", Spec.Form);

View File

@ -61,14 +61,12 @@ void DWARFAcceleratorTable::dump(raw_ostream &OS) const {
SmallVector<DWARFFormValue, 3> AtomForms; SmallVector<DWARFFormValue, 3> AtomForms;
for (const auto &Atom: HdrData.Atoms) { for (const auto &Atom: HdrData.Atoms) {
OS << format("Atom[%d] Type: ", i++); OS << format("Atom[%d] Type: ", i++);
auto TypeString = dwarf::AtomTypeString(Atom.first); if (const char *TypeString = dwarf::AtomTypeString(Atom.first))
if (!TypeString.empty())
OS << TypeString; OS << TypeString;
else else
OS << format("DW_ATOM_Unknown_0x%x", Atom.first); OS << format("DW_ATOM_Unknown_0x%x", Atom.first);
OS << " Form: "; OS << " Form: ";
auto FormString = dwarf::FormEncodingString(Atom.second); if (const char *FormString = dwarf::FormEncodingString(Atom.second))
if (!FormString.empty())
OS << FormString; OS << FormString;
else else
OS << format("DW_FORM_Unknown_0x%x", Atom.second); OS << format("DW_FORM_Unknown_0x%x", Atom.second);

View File

@ -394,15 +394,13 @@ static void printOperand(raw_ostream &OS, uint8_t Opcode, unsigned OperandIdx,
OperandType Type = OpTypes[Opcode][OperandIdx]; OperandType Type = OpTypes[Opcode][OperandIdx];
switch (Type) { switch (Type) {
case OT_Unset: { case OT_Unset:
OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to"; OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to";
auto OpcodeName = CallFrameString(Opcode); if (const char *OpcodeName = CallFrameString(Opcode))
if (!OpcodeName.empty())
OS << " " << OpcodeName; OS << " " << OpcodeName;
else else
OS << format(" Opcode %x", Opcode); OS << format(" Opcode %x", Opcode);
break; break;
}
case OT_None: case OT_None:
break; break;
case OT_Address: case OT_Address:

View File

@ -45,12 +45,12 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u,
if (abbrCode) { if (abbrCode) {
if (AbbrevDecl) { if (AbbrevDecl) {
auto tagString = TagString(getTag()); const char *tagString = TagString(getTag());
if (!tagString.empty()) if (tagString)
WithColor(OS, syntax::Tag).get().indent(indent) << tagString; WithColor(OS, syntax::Tag).get().indent(indent) << tagString;
else else
WithColor(OS, syntax::Tag).get().indent(indent) WithColor(OS, syntax::Tag).get().indent(indent) <<
<< format("DW_TAG_Unknown_%x", getTag()); format("DW_TAG_Unknown_%x", getTag());
OS << format(" [%u] %c\n", abbrCode, OS << format(" [%u] %c\n", abbrCode,
AbbrevDecl->hasChildren() ? '*' : ' '); AbbrevDecl->hasChildren() ? '*' : ' ');
@ -83,8 +83,7 @@ static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
uint64_t Shift = countTrailingZeros(Val); uint64_t Shift = countTrailingZeros(Val);
assert(Shift < 64 && "undefined behavior"); assert(Shift < 64 && "undefined behavior");
uint64_t Bit = 1ULL << Shift; uint64_t Bit = 1ULL << Shift;
auto PropName = ApplePropertyString(Bit); if (const char *PropName = ApplePropertyString(Bit))
if (!PropName.empty())
OS << PropName; OS << PropName;
else else
OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit); OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
@ -117,14 +116,14 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
const char BaseIndent[] = " "; const char BaseIndent[] = " ";
OS << BaseIndent; OS << BaseIndent;
OS.indent(indent+2); OS.indent(indent+2);
auto attrString = AttributeString(attr); const char *attrString = AttributeString(attr);
if (!attrString.empty()) if (attrString)
WithColor(OS, syntax::Attribute) << attrString; WithColor(OS, syntax::Attribute) << attrString;
else else
WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", attr); WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", attr);
auto formString = FormEncodingString(form); const char *formString = FormEncodingString(form);
if (!formString.empty()) if (formString)
OS << " [" << formString << ']'; OS << " [" << formString << ']';
else else
OS << format(" [DW_FORM_Unknown_%x]", form); OS << format(" [DW_FORM_Unknown_%x]", form);
@ -135,8 +134,8 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
return; return;
OS << "\t("; OS << "\t(";
StringRef Name; const char *Name = nullptr;
std::string File; std::string File;
auto Color = syntax::Enumerator; auto Color = syntax::Enumerator;
if (attr == DW_AT_decl_file || attr == DW_AT_call_file) { if (attr == DW_AT_decl_file || attr == DW_AT_call_file) {
@ -147,12 +146,12 @@ void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
u->getCompilationDir(), u->getCompilationDir(),
DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) { DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, File)) {
File = '"' + File + '"'; File = '"' + File + '"';
Name = File; Name = File.c_str();
} }
} else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant()) } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
Name = AttributeValueString(attr, *Val); Name = AttributeValueString(attr, *Val);
if (!Name.empty()) if (Name)
WithColor(OS, Color) << Name; WithColor(OS, Color) << Name;
else if (attr == DW_AT_decl_line || attr == DW_AT_call_line) else if (attr == DW_AT_decl_line || attr == DW_AT_call_line)
OS << *formValue.getAsUnsignedConstant(); OS << *formValue.getAsUnsignedConstant();

View File

@ -42,8 +42,8 @@ void DWARFDebugLine::Prologue::dump(raw_ostream &OS) const {
<< format(" opcode_base: %u\n", OpcodeBase); << format(" opcode_base: %u\n", OpcodeBase);
for (uint32_t i = 0; i < StandardOpcodeLengths.size(); ++i) for (uint32_t i = 0; i < StandardOpcodeLengths.size(); ++i)
OS << format("standard_opcode_lengths[%s] = %u\n", OS << format("standard_opcode_lengths[%s] = %u\n", LNStandardString(i + 1),
LNStandardString(i + 1).data(), StandardOpcodeLengths[i]); StandardOpcodeLengths[i]);
if (!IncludeDirectories.empty()) if (!IncludeDirectories.empty())
for (uint32_t i = 0; i < IncludeDirectories.size(); ++i) for (uint32_t i = 0; i < IncludeDirectories.size(); ++i)

View File

@ -1418,8 +1418,7 @@ struct MDFieldPrinter {
void MDFieldPrinter::printTag(const DINode *N) { void MDFieldPrinter::printTag(const DINode *N) {
Out << FS << "tag: "; Out << FS << "tag: ";
auto Tag = dwarf::TagString(N->getTag()); if (const char *Tag = dwarf::TagString(N->getTag()))
if (!Tag.empty())
Out << Tag; Out << Tag;
else else
Out << N->getTag(); Out << N->getTag();
@ -1427,8 +1426,7 @@ void MDFieldPrinter::printTag(const DINode *N) {
void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) { void MDFieldPrinter::printMacinfoType(const DIMacroNode *N) {
Out << FS << "type: "; Out << FS << "type: ";
auto Type = dwarf::MacinfoString(N->getMacinfoType()); if (const char *Type = dwarf::MacinfoString(N->getMacinfoType()))
if (!Type.empty())
Out << Type; Out << Type;
else else
Out << N->getMacinfoType(); Out << N->getMacinfoType();
@ -1511,8 +1509,7 @@ void MDFieldPrinter::printDwarfEnum(StringRef Name, IntTy Value,
return; return;
Out << FS << Name << ": "; Out << FS << Name << ": ";
auto S = toString(Value); if (const char *S = toString(Value))
if (!S.empty())
Out << S; Out << S;
else else
Out << Value; Out << Value;
@ -1846,8 +1843,8 @@ static void writeDIExpression(raw_ostream &Out, const DIExpression *N,
FieldSeparator FS; FieldSeparator FS;
if (N->isValid()) { if (N->isValid()) {
for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) { for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) {
auto OpStr = dwarf::OperationEncodingString(I->getOp()); const char *OpStr = dwarf::OperationEncodingString(I->getOp());
assert(!OpStr.empty() && "Expected valid opcode"); assert(OpStr && "Expected valid opcode");
Out << FS << OpStr; Out << FS << OpStr;
for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A) for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A)

View File

@ -18,10 +18,9 @@
using namespace llvm; using namespace llvm;
using namespace dwarf; using namespace dwarf;
StringRef llvm::dwarf::TagString(unsigned Tag) { const char *llvm::dwarf::TagString(unsigned Tag) {
switch (Tag) { switch (Tag) {
default: default: return nullptr;
return StringRef();
#define HANDLE_DW_TAG(ID, NAME) \ #define HANDLE_DW_TAG(ID, NAME) \
case DW_TAG_##NAME: \ case DW_TAG_##NAME: \
return "DW_TAG_" #NAME; return "DW_TAG_" #NAME;
@ -36,15 +35,15 @@ unsigned llvm::dwarf::getTag(StringRef TagString) {
.Default(DW_TAG_invalid); .Default(DW_TAG_invalid);
} }
StringRef 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";
case DW_CHILDREN_yes: return "DW_CHILDREN_yes"; case DW_CHILDREN_yes: return "DW_CHILDREN_yes";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::AttributeString(unsigned Attribute) { const char *llvm::dwarf::AttributeString(unsigned Attribute) {
switch (Attribute) { switch (Attribute) {
case DW_AT_sibling: return "DW_AT_sibling"; case DW_AT_sibling: return "DW_AT_sibling";
case DW_AT_location: return "DW_AT_location"; case DW_AT_location: return "DW_AT_location";
@ -222,10 +221,10 @@ StringRef llvm::dwarf::AttributeString(unsigned Attribute) {
case DW_AT_GNU_pubtypes: return "DW_AT_GNU_pubtypes"; case DW_AT_GNU_pubtypes: return "DW_AT_GNU_pubtypes";
case DW_AT_GNU_discriminator: return "DW_AT_GNU_discriminator"; case DW_AT_GNU_discriminator: return "DW_AT_GNU_discriminator";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) { const char *llvm::dwarf::FormEncodingString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
case DW_FORM_addr: return "DW_FORM_addr"; case DW_FORM_addr: return "DW_FORM_addr";
case DW_FORM_block2: return "DW_FORM_block2"; case DW_FORM_block2: return "DW_FORM_block2";
@ -261,13 +260,12 @@ StringRef llvm::dwarf::FormEncodingString(unsigned Encoding) {
case DW_FORM_GNU_ref_alt: return "DW_FORM_GNU_ref_alt"; case DW_FORM_GNU_ref_alt: return "DW_FORM_GNU_ref_alt";
case DW_FORM_GNU_strp_alt: return "DW_FORM_GNU_strp_alt"; case DW_FORM_GNU_strp_alt: return "DW_FORM_GNU_strp_alt";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::OperationEncodingString(unsigned Encoding) { const char *llvm::dwarf::OperationEncodingString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
default: default: return nullptr;
return StringRef();
#define HANDLE_DW_OP(ID, NAME) \ #define HANDLE_DW_OP(ID, NAME) \
case DW_OP_##NAME: \ case DW_OP_##NAME: \
return "DW_OP_" #NAME; return "DW_OP_" #NAME;
@ -282,10 +280,9 @@ unsigned llvm::dwarf::getOperationEncoding(StringRef OperationEncodingString) {
.Default(0); .Default(0);
} }
StringRef llvm::dwarf::AttributeEncodingString(unsigned Encoding) { const char *llvm::dwarf::AttributeEncodingString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
default: default: return nullptr;
return StringRef();
#define HANDLE_DW_ATE(ID, NAME) \ #define HANDLE_DW_ATE(ID, NAME) \
case DW_ATE_##NAME: \ case DW_ATE_##NAME: \
return "DW_ATE_" #NAME; return "DW_ATE_" #NAME;
@ -300,7 +297,7 @@ unsigned llvm::dwarf::getAttributeEncoding(StringRef EncodingString) {
.Default(0); .Default(0);
} }
StringRef llvm::dwarf::DecimalSignString(unsigned Sign) { const char *llvm::dwarf::DecimalSignString(unsigned Sign) {
switch (Sign) { switch (Sign) {
case DW_DS_unsigned: return "DW_DS_unsigned"; case DW_DS_unsigned: return "DW_DS_unsigned";
case DW_DS_leading_overpunch: return "DW_DS_leading_overpunch"; case DW_DS_leading_overpunch: return "DW_DS_leading_overpunch";
@ -308,10 +305,10 @@ StringRef llvm::dwarf::DecimalSignString(unsigned Sign) {
case DW_DS_leading_separate: return "DW_DS_leading_separate"; case DW_DS_leading_separate: return "DW_DS_leading_separate";
case DW_DS_trailing_separate: return "DW_DS_trailing_separate"; case DW_DS_trailing_separate: return "DW_DS_trailing_separate";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::EndianityString(unsigned Endian) { const char *llvm::dwarf::EndianityString(unsigned Endian) {
switch (Endian) { switch (Endian) {
case DW_END_default: return "DW_END_default"; case DW_END_default: return "DW_END_default";
case DW_END_big: return "DW_END_big"; case DW_END_big: return "DW_END_big";
@ -319,32 +316,32 @@ StringRef llvm::dwarf::EndianityString(unsigned Endian) {
case DW_END_lo_user: return "DW_END_lo_user"; case DW_END_lo_user: return "DW_END_lo_user";
case DW_END_hi_user: return "DW_END_hi_user"; case DW_END_hi_user: return "DW_END_hi_user";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::AccessibilityString(unsigned Access) { const char *llvm::dwarf::AccessibilityString(unsigned Access) {
switch (Access) { switch (Access) {
// Accessibility codes // Accessibility codes
case DW_ACCESS_public: return "DW_ACCESS_public"; case DW_ACCESS_public: return "DW_ACCESS_public";
case DW_ACCESS_protected: return "DW_ACCESS_protected"; case DW_ACCESS_protected: return "DW_ACCESS_protected";
case DW_ACCESS_private: return "DW_ACCESS_private"; case DW_ACCESS_private: return "DW_ACCESS_private";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::VisibilityString(unsigned Visibility) { const char *llvm::dwarf::VisibilityString(unsigned Visibility) {
switch (Visibility) { switch (Visibility) {
case DW_VIS_local: return "DW_VIS_local"; case DW_VIS_local: return "DW_VIS_local";
case DW_VIS_exported: return "DW_VIS_exported"; case DW_VIS_exported: return "DW_VIS_exported";
case DW_VIS_qualified: return "DW_VIS_qualified"; case DW_VIS_qualified: return "DW_VIS_qualified";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::VirtualityString(unsigned Virtuality) { const char *llvm::dwarf::VirtualityString(unsigned Virtuality) {
switch (Virtuality) { switch (Virtuality) {
default: default:
return StringRef(); return nullptr;
#define HANDLE_DW_VIRTUALITY(ID, NAME) \ #define HANDLE_DW_VIRTUALITY(ID, NAME) \
case DW_VIRTUALITY_##NAME: \ case DW_VIRTUALITY_##NAME: \
return "DW_VIRTUALITY_" #NAME; return "DW_VIRTUALITY_" #NAME;
@ -360,10 +357,10 @@ unsigned llvm::dwarf::getVirtuality(StringRef VirtualityString) {
.Default(DW_VIRTUALITY_invalid); .Default(DW_VIRTUALITY_invalid);
} }
StringRef llvm::dwarf::LanguageString(unsigned Language) { const char *llvm::dwarf::LanguageString(unsigned Language) {
switch (Language) { switch (Language) {
default: default:
return StringRef(); return nullptr;
#define HANDLE_DW_LANG(ID, NAME) \ #define HANDLE_DW_LANG(ID, NAME) \
case DW_LANG_##NAME: \ case DW_LANG_##NAME: \
return "DW_LANG_" #NAME; return "DW_LANG_" #NAME;
@ -378,20 +375,20 @@ unsigned llvm::dwarf::getLanguage(StringRef LanguageString) {
.Default(0); .Default(0);
} }
StringRef llvm::dwarf::CaseString(unsigned Case) { const char *llvm::dwarf::CaseString(unsigned Case) {
switch (Case) { switch (Case) {
case DW_ID_case_sensitive: return "DW_ID_case_sensitive"; case DW_ID_case_sensitive: return "DW_ID_case_sensitive";
case DW_ID_up_case: return "DW_ID_up_case"; case DW_ID_up_case: return "DW_ID_up_case";
case DW_ID_down_case: return "DW_ID_down_case"; case DW_ID_down_case: return "DW_ID_down_case";
case DW_ID_case_insensitive: return "DW_ID_case_insensitive"; case DW_ID_case_insensitive: return "DW_ID_case_insensitive";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::ConventionString(unsigned CC) { const char *llvm::dwarf::ConventionString(unsigned CC) {
switch (CC) { switch (CC) {
default: default:
return StringRef(); return nullptr;
#define HANDLE_DW_CC(ID, NAME) \ #define HANDLE_DW_CC(ID, NAME) \
case DW_CC_##NAME: \ case DW_CC_##NAME: \
return "DW_CC_" #NAME; return "DW_CC_" #NAME;
@ -406,33 +403,33 @@ unsigned llvm::dwarf::getCallingConvention(StringRef CCString) {
.Default(0); .Default(0);
} }
StringRef llvm::dwarf::InlineCodeString(unsigned Code) { const char *llvm::dwarf::InlineCodeString(unsigned Code) {
switch (Code) { switch (Code) {
case DW_INL_not_inlined: return "DW_INL_not_inlined"; case DW_INL_not_inlined: return "DW_INL_not_inlined";
case DW_INL_inlined: return "DW_INL_inlined"; case DW_INL_inlined: return "DW_INL_inlined";
case DW_INL_declared_not_inlined: return "DW_INL_declared_not_inlined"; case DW_INL_declared_not_inlined: return "DW_INL_declared_not_inlined";
case DW_INL_declared_inlined: return "DW_INL_declared_inlined"; case DW_INL_declared_inlined: return "DW_INL_declared_inlined";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::ArrayOrderString(unsigned Order) { const char *llvm::dwarf::ArrayOrderString(unsigned Order) {
switch (Order) { switch (Order) {
case DW_ORD_row_major: return "DW_ORD_row_major"; case DW_ORD_row_major: return "DW_ORD_row_major";
case DW_ORD_col_major: return "DW_ORD_col_major"; case DW_ORD_col_major: return "DW_ORD_col_major";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::DiscriminantString(unsigned Discriminant) { const char *llvm::dwarf::DiscriminantString(unsigned Discriminant) {
switch (Discriminant) { switch (Discriminant) {
case DW_DSC_label: return "DW_DSC_label"; case DW_DSC_label: return "DW_DSC_label";
case DW_DSC_range: return "DW_DSC_range"; case DW_DSC_range: return "DW_DSC_range";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::LNStandardString(unsigned Standard) { const char *llvm::dwarf::LNStandardString(unsigned Standard) {
switch (Standard) { switch (Standard) {
case DW_LNS_copy: return "DW_LNS_copy"; case DW_LNS_copy: return "DW_LNS_copy";
case DW_LNS_advance_pc: return "DW_LNS_advance_pc"; case DW_LNS_advance_pc: return "DW_LNS_advance_pc";
@ -447,10 +444,10 @@ StringRef llvm::dwarf::LNStandardString(unsigned Standard) {
case DW_LNS_set_epilogue_begin: return "DW_LNS_set_epilogue_begin"; case DW_LNS_set_epilogue_begin: return "DW_LNS_set_epilogue_begin";
case DW_LNS_set_isa: return "DW_LNS_set_isa"; case DW_LNS_set_isa: return "DW_LNS_set_isa";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) { const char *llvm::dwarf::LNExtendedString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
// Line Number Extended Opcode Encodings // Line Number Extended Opcode Encodings
case DW_LNE_end_sequence: return "DW_LNE_end_sequence"; case DW_LNE_end_sequence: return "DW_LNE_end_sequence";
@ -460,10 +457,10 @@ StringRef llvm::dwarf::LNExtendedString(unsigned Encoding) {
case DW_LNE_lo_user: return "DW_LNE_lo_user"; case DW_LNE_lo_user: return "DW_LNE_lo_user";
case DW_LNE_hi_user: return "DW_LNE_hi_user"; case DW_LNE_hi_user: return "DW_LNE_hi_user";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::MacinfoString(unsigned Encoding) { const char *llvm::dwarf::MacinfoString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
// Macinfo Type Encodings // Macinfo Type Encodings
case DW_MACINFO_define: return "DW_MACINFO_define"; case DW_MACINFO_define: return "DW_MACINFO_define";
@ -473,7 +470,7 @@ StringRef llvm::dwarf::MacinfoString(unsigned Encoding) {
case DW_MACINFO_vendor_ext: return "DW_MACINFO_vendor_ext"; case DW_MACINFO_vendor_ext: return "DW_MACINFO_vendor_ext";
case DW_MACINFO_invalid: return "DW_MACINFO_invalid"; case DW_MACINFO_invalid: return "DW_MACINFO_invalid";
} }
return StringRef(); return nullptr;
} }
unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) { unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) {
@ -486,7 +483,7 @@ unsigned llvm::dwarf::getMacinfo(StringRef MacinfoString) {
.Default(DW_MACINFO_invalid); .Default(DW_MACINFO_invalid);
} }
StringRef llvm::dwarf::CallFrameString(unsigned Encoding) { const char *llvm::dwarf::CallFrameString(unsigned Encoding) {
switch (Encoding) { switch (Encoding) {
case DW_CFA_nop: return "DW_CFA_nop"; case DW_CFA_nop: return "DW_CFA_nop";
case DW_CFA_advance_loc: return "DW_CFA_advance_loc"; case DW_CFA_advance_loc: return "DW_CFA_advance_loc";
@ -520,10 +517,10 @@ StringRef llvm::dwarf::CallFrameString(unsigned Encoding) {
case DW_CFA_lo_user: return "DW_CFA_lo_user"; case DW_CFA_lo_user: return "DW_CFA_lo_user";
case DW_CFA_hi_user: return "DW_CFA_hi_user"; case DW_CFA_hi_user: return "DW_CFA_hi_user";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) { const char *llvm::dwarf::ApplePropertyString(unsigned Prop) {
switch (Prop) { switch (Prop) {
case DW_APPLE_PROPERTY_readonly: case DW_APPLE_PROPERTY_readonly:
return "DW_APPLE_PROPERTY_readonly"; return "DW_APPLE_PROPERTY_readonly";
@ -556,10 +553,10 @@ StringRef llvm::dwarf::ApplePropertyString(unsigned Prop) {
case DW_APPLE_PROPERTY_class: case DW_APPLE_PROPERTY_class:
return "DW_APPLE_PROPERTY_class"; return "DW_APPLE_PROPERTY_class";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::AtomTypeString(unsigned AT) { const char *llvm::dwarf::AtomTypeString(unsigned AT) {
switch (AT) { switch (AT) {
case dwarf::DW_ATOM_null: case dwarf::DW_ATOM_null:
return "DW_ATOM_null"; return "DW_ATOM_null";
@ -572,10 +569,10 @@ StringRef llvm::dwarf::AtomTypeString(unsigned AT) {
case DW_ATOM_type_flags: case DW_ATOM_type_flags:
return "DW_ATOM_type_flags"; return "DW_ATOM_type_flags";
} }
return StringRef(); return nullptr;
} }
StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) { const char *llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) {
switch (Kind) { switch (Kind) {
case GIEK_NONE: case GIEK_NONE:
return "NONE"; return "NONE";
@ -597,8 +594,7 @@ StringRef llvm::dwarf::GDBIndexEntryKindString(GDBIndexEntryKind Kind) {
llvm_unreachable("Unknown GDBIndexEntryKind value"); llvm_unreachable("Unknown GDBIndexEntryKind value");
} }
StringRef const char *llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
switch (Linkage) { switch (Linkage) {
case GIEL_EXTERNAL: case GIEL_EXTERNAL:
return "EXTERNAL"; return "EXTERNAL";
@ -608,7 +604,7 @@ llvm::dwarf::GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage) {
llvm_unreachable("Unknown GDBIndexEntryLinkage value"); llvm_unreachable("Unknown GDBIndexEntryLinkage value");
} }
StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) { const char *llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
switch (Attr) { switch (Attr) {
case DW_AT_accessibility: case DW_AT_accessibility:
return AccessibilityString(Val); return AccessibilityString(Val);
@ -636,5 +632,5 @@ StringRef llvm::dwarf::AttributeValueString(uint16_t Attr, unsigned Val) {
return DiscriminantString(Val); return DiscriminantString(Val);
} }
return StringRef(); return nullptr;
} }

View File

@ -17,13 +17,13 @@ namespace {
TEST(DwarfTest, TagStringOnInvalid) { TEST(DwarfTest, TagStringOnInvalid) {
// This is invalid, so it shouldn't be stringified. // This is invalid, so it shouldn't be stringified.
EXPECT_EQ(StringRef(), TagString(DW_TAG_invalid)); EXPECT_EQ(nullptr, TagString(DW_TAG_invalid));
// These aren't really tags: they describe ranges within tags. They // These aren't really tags: they describe ranges within tags. They
// shouldn't be stringified either. // shouldn't be stringified either.
EXPECT_EQ(StringRef(), TagString(DW_TAG_lo_user)); EXPECT_EQ(nullptr, TagString(DW_TAG_lo_user));
EXPECT_EQ(StringRef(), TagString(DW_TAG_hi_user)); EXPECT_EQ(nullptr, TagString(DW_TAG_hi_user));
EXPECT_EQ(StringRef(), TagString(DW_TAG_user_base)); EXPECT_EQ(nullptr, TagString(DW_TAG_user_base));
} }
TEST(DwarfTest, getTag) { TEST(DwarfTest, getTag) {
@ -58,12 +58,12 @@ TEST(DwarfTest, getOperationEncoding) {
TEST(DwarfTest, LanguageStringOnInvalid) { TEST(DwarfTest, LanguageStringOnInvalid) {
// This is invalid, so it shouldn't be stringified. // This is invalid, so it shouldn't be stringified.
EXPECT_EQ(StringRef(), LanguageString(0)); EXPECT_EQ(nullptr, LanguageString(0));
// These aren't really tags: they describe ranges within tags. They // These aren't really tags: they describe ranges within tags. They
// shouldn't be stringified either. // shouldn't be stringified either.
EXPECT_EQ(StringRef(), LanguageString(DW_LANG_lo_user)); EXPECT_EQ(nullptr, LanguageString(DW_LANG_lo_user));
EXPECT_EQ(StringRef(), LanguageString(DW_LANG_hi_user)); EXPECT_EQ(nullptr, LanguageString(DW_LANG_hi_user));
} }
TEST(DwarfTest, getLanguage) { TEST(DwarfTest, getLanguage) {
@ -85,12 +85,12 @@ TEST(DwarfTest, getLanguage) {
TEST(DwarfTest, AttributeEncodingStringOnInvalid) { TEST(DwarfTest, AttributeEncodingStringOnInvalid) {
// This is invalid, so it shouldn't be stringified. // This is invalid, so it shouldn't be stringified.
EXPECT_EQ(StringRef(), AttributeEncodingString(0)); EXPECT_EQ(nullptr, AttributeEncodingString(0));
// These aren't really tags: they describe ranges within tags. They // These aren't really tags: they describe ranges within tags. They
// shouldn't be stringified either. // shouldn't be stringified either.
EXPECT_EQ(StringRef(), AttributeEncodingString(DW_ATE_lo_user)); EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_lo_user));
EXPECT_EQ(StringRef(), AttributeEncodingString(DW_ATE_hi_user)); EXPECT_EQ(nullptr, AttributeEncodingString(DW_ATE_hi_user));
} }
TEST(DwarfTest, getAttributeEncoding) { TEST(DwarfTest, getAttributeEncoding) {
@ -122,8 +122,8 @@ TEST(DwarfTest, VirtualityString) {
VirtualityString(DW_VIRTUALITY_max)); VirtualityString(DW_VIRTUALITY_max));
// Invalid numbers shouldn't be stringified. // Invalid numbers shouldn't be stringified.
EXPECT_EQ(StringRef(), VirtualityString(DW_VIRTUALITY_max + 1)); EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 1));
EXPECT_EQ(StringRef(), VirtualityString(DW_VIRTUALITY_max + 77)); EXPECT_EQ(nullptr, VirtualityString(DW_VIRTUALITY_max + 77));
} }
TEST(DwarfTest, getVirtuality) { TEST(DwarfTest, getVirtuality) {