1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

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

This reverts commit r283285 and re-commit r283275 with
a fix for format("%s", Str); where Str is a StringRef.

llvm-svn: 283298
This commit is contained in:
Mehdi Amini 2016-10-05 05:59:29 +00:00
parent 8bef9c6e21
commit b4869611fc
12 changed files with 146 additions and 130 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -54,8 +54,10 @@ static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data,
OS << format("0x%8.8x ", dieRef);
if (GnuStyle) {
PubIndexEntryDescriptor desc(pubNames.getU8(&offset));
OS << format("%-8s", dwarf::GDBIndexEntryLinkageString(desc.Linkage))
<< ' ' << format("%-8s", dwarf::GDBIndexEntryKindString(desc.Kind))
OS << format("%-8s",
dwarf::GDBIndexEntryLinkageString(desc.Linkage).data())
<< ' '
<< format("%-8s", dwarf::GDBIndexEntryKindString(desc.Kind).data())
<< ' ';
}
OS << '\"' << pubNames.getCStr(&offset) << "\"\n";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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