[DebugInfo] Extract a helper function to return the DWARF format name, NFC [1/10]
authorIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 2 Jun 2020 05:16:51 +0000 (12:16 +0700)
committerIgor Kudrin <ikudrin@accesssoftek.com>
Tue, 2 Jun 2020 10:55:30 +0000 (17:55 +0700)
Differential Revision: https://reviews.llvm.org/D80523

llvm/include/llvm/BinaryFormat/Dwarf.h
llvm/lib/BinaryFormat/Dwarf.cpp
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

index 3f36221..1caf4d9 100644 (file)
@@ -481,6 +481,7 @@ StringRef AtomTypeString(unsigned Atom);
 StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind);
 StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
 StringRef IndexString(unsigned Idx);
+StringRef FormatString(DwarfFormat Format);
 /// @}
 
 /// \defgroup DwarfConstantsParsing Dwarf constants parsing functions
index 30c7e9c..08ecd77 100644 (file)
@@ -770,6 +770,16 @@ bool llvm::dwarf::isValidFormForVersion(Form F, unsigned Version,
   return ExtensionsOk;
 }
 
+StringRef llvm::dwarf::FormatString(DwarfFormat Format) {
+  switch (Format) {
+  case DWARF32:
+    return "DWARF32";
+  case DWARF64:
+    return "DWARF64";
+  }
+  return StringRef();
+}
+
 constexpr char llvm::dwarf::EnumTraits<Attribute>::Type[];
 constexpr char llvm::dwarf::EnumTraits<Form>::Type[];
 constexpr char llvm::dwarf::EnumTraits<Index>::Type[];
index b6e0d93..9447ea8 100644 (file)
@@ -190,7 +190,7 @@ static void dumpStringOffsetsSection(raw_ostream &OS, DIDumpOptions DumpOpts,
     // version field and the padding, a total of 4 bytes). Add them back in
     // for reporting.
     OS << "Contribution size = " << (Contribution->Size + (Version < 5 ? 0 : 4))
-       << ", Format = " << (Format == DWARF32 ? "DWARF32" : "DWARF64")
+       << ", Format = " << dwarf::FormatString(Format)
        << ", Version = " << Version << "\n";
 
     Offset = Contribution->Base;