diff options
-rw-r--r-- | llvm/include/llvm/Support/ScopedPrinter.h (renamed from llvm/tools/llvm-readobj/StreamWriter.h) | 107 | ||||
-rw-r--r-- | llvm/lib/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Support/ScopedPrinter.cpp (renamed from llvm/tools/llvm-readobj/StreamWriter.cpp) | 9 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ARMAttributeParser.cpp | 2 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ARMAttributeParser.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ARMEHABIPrinter.h | 10 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ARMWinEHPrinter.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/COFFDumper.cpp | 14 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 34 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/MachODumper.cpp | 11 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ObjDumper.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/ObjDumper.h | 12 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/Win64EHDumper.h | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-readobj/llvm-readobj.cpp | 7 |
15 files changed, 106 insertions, 126 deletions
diff --git a/llvm/tools/llvm-readobj/StreamWriter.h b/llvm/include/llvm/Support/ScopedPrinter.h index 9b0e5a6d398..c29d532a557 100644 --- a/llvm/tools/llvm-readobj/StreamWriter.h +++ b/llvm/include/llvm/Support/ScopedPrinter.h @@ -1,4 +1,4 @@ -//===-- StreamWriter.h ----------------------------------------------------===// +//===-- ScopedPrinter.h ---------------------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H -#define LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H +#ifndef LLVM_SUPPORT_SCOPEDPRINTER_H +#define LLVM_SUPPORT_SCOPEDPRINTER_H #include "llvm/ADT/APSInt.h" #include "llvm/ADT/ArrayRef.h" @@ -23,8 +23,7 @@ using namespace llvm; namespace llvm { -template<typename T> -struct EnumEntry { +template <typename T> struct EnumEntry { StringRef Name; // While Name suffices in most of the cases, in certain cases // GNU style and LLVM style of ELFDumper do not @@ -44,21 +43,22 @@ struct HexNumber { // unsigned type. The overloads are here so that every type that is implicitly // convertible to an integer (including enums and endian helpers) can be used // without requiring type traits or call-site changes. - HexNumber(char Value) : Value(static_cast<unsigned char>(Value)) { } - HexNumber(signed char Value) : Value(static_cast<unsigned char>(Value)) { } - HexNumber(signed short Value) : Value(static_cast<unsigned short>(Value)) { } - HexNumber(signed int Value) : Value(static_cast<unsigned int>(Value)) { } - HexNumber(signed long Value) : Value(static_cast<unsigned long>(Value)) { } - HexNumber(signed long long Value) : Value(static_cast<unsigned long long>(Value)) { } - HexNumber(unsigned char Value) : Value(Value) { } - HexNumber(unsigned short Value) : Value(Value) { } - HexNumber(unsigned int Value) : Value(Value) { } - HexNumber(unsigned long Value) : Value(Value) { } - HexNumber(unsigned long long Value) : Value(Value) { } + HexNumber(char Value) : Value(static_cast<unsigned char>(Value)) {} + HexNumber(signed char Value) : Value(static_cast<unsigned char>(Value)) {} + HexNumber(signed short Value) : Value(static_cast<unsigned short>(Value)) {} + HexNumber(signed int Value) : Value(static_cast<unsigned int>(Value)) {} + HexNumber(signed long Value) : Value(static_cast<unsigned long>(Value)) {} + HexNumber(signed long long Value) + : Value(static_cast<unsigned long long>(Value)) {} + HexNumber(unsigned char Value) : Value(Value) {} + HexNumber(unsigned short Value) : Value(Value) {} + HexNumber(unsigned int Value) : Value(Value) {} + HexNumber(unsigned long Value) : Value(Value) {} + HexNumber(unsigned long long Value) : Value(Value) {} uint64_t Value; }; -raw_ostream &operator<<(raw_ostream &OS, const HexNumber& Value); +raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value); const std::string to_hexString(uint64_t Value, bool UpperCase = true); template <class T> const std::string to_string(const T &Value) { @@ -68,20 +68,13 @@ template <class T> const std::string to_string(const T &Value) { return stream.str(); } -class StreamWriter { +class ScopedPrinter { public: - StreamWriter(raw_ostream &OS) - : OS(OS) - , IndentLevel(0) { - } + ScopedPrinter(raw_ostream &OS) : OS(OS), IndentLevel(0) {} - void flush() { - OS.flush(); - } + void flush() { OS.flush(); } - void indent(int Levels = 1) { - IndentLevel += Levels; - } + void indent(int Levels = 1) { IndentLevel += Levels; } void unindent(int Levels = 1) { IndentLevel = std::max(0, IndentLevel - Levels); @@ -92,14 +85,11 @@ public: OS << " "; } - template<typename T> - HexNumber hex(T Value) { - return HexNumber(Value); - } + template <typename T> HexNumber hex(T Value) { return HexNumber(Value); } - template<typename T, typename TEnum> + template <typename T, typename TEnum> void printEnum(StringRef Label, T Value, - ArrayRef<EnumEntry<TEnum> > EnumValues) { + ArrayRef<EnumEntry<TEnum>> EnumValues) { StringRef Name; bool Found = false; for (const auto &EnumItem : EnumValues) { @@ -138,7 +128,7 @@ public: EnumMask = EnumMask3; bool IsEnum = (Flag.Value & EnumMask) != 0; if ((!IsEnum && (Value & Flag.Value) == Flag.Value) || - (IsEnum && (Value & EnumMask) == Flag.Value)) { + (IsEnum && (Value & EnumMask) == Flag.Value)) { SetFlags.push_back(Flag); } } @@ -152,8 +142,7 @@ public: startLine() << "]\n"; } - template<typename T> - void printFlags(StringRef Label, T Value) { + template <typename T> void printFlags(StringRef Label, T Value) { startLine() << Label << " [ (" << hex(Value) << ")\n"; uint64_t Flag = 1; uint64_t Curr = Value; @@ -206,8 +195,7 @@ public: startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n'; } - template <typename T> - void printList(StringRef Label, const T &List) { + template <typename T> void printList(StringRef Label, const T &List) { startLine() << Label << ": ["; bool Comma = false; for (const auto &Item : List) { @@ -219,8 +207,7 @@ public: OS << "]\n"; } - template <typename T> - void printHexList(StringRef Label, const T &List) { + template <typename T> void printHexList(StringRef Label, const T &List) { startLine() << Label << ": ["; bool Comma = false; for (const auto &Item : List) { @@ -232,13 +219,11 @@ public: OS << "]\n"; } - template<typename T> - void printHex(StringRef Label, T Value) { + template <typename T> void printHex(StringRef Label, T Value) { startLine() << Label << ": " << hex(Value) << "\n"; } - template<typename T> - void printHex(StringRef Label, StringRef Str, T Value) { + template <typename T> void printHex(StringRef Label, StringRef Str, T Value) { startLine() << Label << ": " << Str << " (" << hex(Value) << ")\n"; } @@ -255,7 +240,7 @@ public: startLine() << Label << ": " << Value << "\n"; } - template<typename T> + template <typename T> void printNumber(StringRef Label, StringRef Str, T Value) { startLine() << Label << ": " << Str << " (" << Value << ")\n"; } @@ -265,7 +250,7 @@ public: } void printBinary(StringRef Label, StringRef Str, ArrayRef<char> Value) { - auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()), + auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()), Value.size()); printBinaryImpl(Label, Str, V, false); } @@ -275,35 +260,33 @@ public: } void printBinary(StringRef Label, ArrayRef<char> Value) { - auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()), + auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()), Value.size()); printBinaryImpl(Label, StringRef(), V, false); } void printBinary(StringRef Label, StringRef Value) { - auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()), + auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()), Value.size()); printBinaryImpl(Label, StringRef(), V, false); } void printBinaryBlock(StringRef Label, StringRef Value) { - auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()), + auto V = makeArrayRef(reinterpret_cast<const uint8_t *>(Value.data()), Value.size()); printBinaryImpl(Label, StringRef(), V, true); } - raw_ostream& startLine() { + raw_ostream &startLine() { printIndent(); return OS; } - raw_ostream& getOStream() { - return OS; - } + raw_ostream &getOStream() { return OS; } private: - template<typename T> - static bool flagName(const EnumEntry<T>& lhs, const EnumEntry<T>& rhs) { + template <typename T> + static bool flagName(const EnumEntry<T> &lhs, const EnumEntry<T> &rhs) { return lhs.Name < rhs.Name; } @@ -316,13 +299,13 @@ private: template <> inline void -StreamWriter::printHex<support::ulittle16_t>(StringRef Label, - support::ulittle16_t Value) { +ScopedPrinter::printHex<support::ulittle16_t>(StringRef Label, + support::ulittle16_t Value) { startLine() << Label << ": " << hex(Value) << "\n"; } struct DictScope { - DictScope(StreamWriter& W, StringRef N) : W(W) { + DictScope(ScopedPrinter &W, StringRef N) : W(W) { W.startLine() << N << " {\n"; W.indent(); } @@ -332,11 +315,11 @@ struct DictScope { W.startLine() << "}\n"; } - StreamWriter& W; + ScopedPrinter &W; }; struct ListScope { - ListScope(StreamWriter& W, StringRef N) : W(W) { + ListScope(ScopedPrinter &W, StringRef N) : W(W) { W.startLine() << N << " [\n"; W.indent(); } @@ -346,7 +329,7 @@ struct ListScope { W.startLine() << "]\n"; } - StreamWriter& W; + ScopedPrinter &W; }; } // namespace llvm diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 0de1972b3c5..3d718e6a11c 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -76,6 +76,7 @@ add_llvm_library(LLVMSupport RandomNumberGenerator.cpp Regex.cpp ScaledNumber.cpp + ScopedPrinter.cpp SHA1.cpp SmallPtrSet.cpp SmallVector.cpp diff --git a/llvm/tools/llvm-readobj/StreamWriter.cpp b/llvm/lib/Support/ScopedPrinter.cpp index 391c12691da..0225f01156a 100644 --- a/llvm/tools/llvm-readobj/StreamWriter.cpp +++ b/llvm/lib/Support/ScopedPrinter.cpp @@ -1,4 +1,5 @@ -#include "StreamWriter.h" +#include "llvm/Support/ScopedPrinter.h" + #include "llvm/ADT/StringExtras.h" #include "llvm/Support/Format.h" #include <cctype> @@ -7,7 +8,7 @@ using namespace llvm::support; namespace llvm { -raw_ostream &operator<<(raw_ostream &OS, const HexNumber& Value) { +raw_ostream &operator<<(raw_ostream &OS, const HexNumber &Value) { OS << "0x" << to_hexString(Value.Value); return OS; } @@ -19,8 +20,8 @@ const std::string to_hexString(uint64_t Value, bool UpperCase) { return stream.str(); } -void StreamWriter::printBinaryImpl(StringRef Label, StringRef Str, - ArrayRef<uint8_t> Data, bool Block) { +void ScopedPrinter::printBinaryImpl(StringRef Label, StringRef Str, + ArrayRef<uint8_t> Data, bool Block) { if (Data.size() > 16) Block = true; diff --git a/llvm/tools/llvm-readobj/ARMAttributeParser.cpp b/llvm/tools/llvm-readobj/ARMAttributeParser.cpp index 76de1440d09..877dd71c907 100644 --- a/llvm/tools/llvm-readobj/ARMAttributeParser.cpp +++ b/llvm/tools/llvm-readobj/ARMAttributeParser.cpp @@ -8,10 +8,10 @@ //===----------------------------------------------------------------------===// #include "ARMAttributeParser.h" -#include "StreamWriter.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/LEB128.h" +#include "llvm/Support/ScopedPrinter.h" using namespace llvm; using namespace llvm::ARMBuildAttrs; diff --git a/llvm/tools/llvm-readobj/ARMAttributeParser.h b/llvm/tools/llvm-readobj/ARMAttributeParser.h index a58285688f2..6936b70ca12 100644 --- a/llvm/tools/llvm-readobj/ARMAttributeParser.h +++ b/llvm/tools/llvm-readobj/ARMAttributeParser.h @@ -10,14 +10,14 @@ #ifndef LLVM_TOOLS_LLVM_READOBJ_ARMATTRIBUTEPARSER_H #define LLVM_TOOLS_LLVM_READOBJ_ARMATTRIBUTEPARSER_H -#include "StreamWriter.h" #include "llvm/Support/ARMBuildAttributes.h" +#include "llvm/Support/ScopedPrinter.h" namespace llvm { class StringRef; class ARMAttributeParser { - StreamWriter &SW; + ScopedPrinter &SW; struct DisplayHandler { ARMBuildAttrs::AttrType Attribute; @@ -115,7 +115,7 @@ class ARMAttributeParser { SmallVectorImpl<uint8_t> &IndexList); void ParseSubsection(const uint8_t *Data, uint32_t Length); public: - ARMAttributeParser(StreamWriter &SW) : SW(SW) {} + ARMAttributeParser(ScopedPrinter &SW) : SW(SW) {} void Parse(ArrayRef<uint8_t> Section); }; diff --git a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h index 5845eb02d11..59c9b713d85 100644 --- a/llvm/tools/llvm-readobj/ARMEHABIPrinter.h +++ b/llvm/tools/llvm-readobj/ARMEHABIPrinter.h @@ -11,7 +11,6 @@ #define LLVM_TOOLS_LLVM_READOBJ_ARMEHABIPRINTER_H #include "Error.h" -#include "StreamWriter.h" #include "llvm-readobj.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Object/ELF.h" @@ -20,6 +19,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Format.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/type_traits.h" namespace llvm { @@ -27,7 +27,7 @@ namespace ARM { namespace EHABI { class OpcodeDecoder { - StreamWriter &SW; + ScopedPrinter &SW; raw_ostream &OS; struct RingEntry { @@ -64,7 +64,7 @@ class OpcodeDecoder { void PrintRegisters(uint32_t Mask, StringRef Prefix); public: - OpcodeDecoder(StreamWriter &SW) : SW(SW), OS(SW.getOStream()) {} + OpcodeDecoder(ScopedPrinter &SW) : SW(SW), OS(SW.getOStream()) {} void Decode(const uint8_t *Opcodes, off_t Offset, size_t Length); }; @@ -311,7 +311,7 @@ class PrinterContext { typedef typename object::ELFFile<ET>::Elf_Rel Elf_Rel; typedef typename object::ELFFile<ET>::Elf_Word Elf_Word; - StreamWriter &SW; + ScopedPrinter &SW; const object::ELFFile<ET> *ELF; const Elf_Shdr *Symtab; ArrayRef<Elf_Word> ShndxTable; @@ -335,7 +335,7 @@ class PrinterContext { void PrintOpcodes(const uint8_t *Entry, size_t Length, off_t Offset) const; public: - PrinterContext(StreamWriter &SW, const object::ELFFile<ET> *ELF, + PrinterContext(ScopedPrinter &SW, const object::ELFFile<ET> *ELF, const Elf_Shdr *Symtab) : SW(SW), ELF(ELF), Symtab(Symtab) {} diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.h b/llvm/tools/llvm-readobj/ARMWinEHPrinter.h index 274ef114841..95f52170226 100644 --- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.h +++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.h @@ -10,9 +10,9 @@ #ifndef LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H #define LLVM_TOOLS_LLVM_READOBJ_ARMWINEHPRINTER_H -#include "StreamWriter.h" #include "llvm/Object/COFF.h" #include "llvm/Support/ErrorOr.h" +#include "llvm/Support/ScopedPrinter.h" namespace llvm { namespace ARM { @@ -22,7 +22,7 @@ class RuntimeFunction; class Decoder { static const size_t PDataEntrySize; - StreamWriter &SW; + ScopedPrinter &SW; raw_ostream &OS; struct RingEntry { @@ -107,7 +107,7 @@ class Decoder { const object::SectionRef Section); public: - Decoder(StreamWriter &SW) : SW(SW), OS(SW.getOStream()) {} + Decoder(ScopedPrinter &SW) : SW(SW), OS(SW.getOStream()) {} std::error_code dumpProcedureData(const object::COFFObjectFile &COFF); }; } diff --git a/llvm/tools/llvm-readobj/CMakeLists.txt b/llvm/tools/llvm-readobj/CMakeLists.txt index a06b678780c..e167874c1a1 100644 --- a/llvm/tools/llvm-readobj/CMakeLists.txt +++ b/llvm/tools/llvm-readobj/CMakeLists.txt @@ -13,6 +13,5 @@ add_llvm_tool(llvm-readobj llvm-readobj.cpp MachODumper.cpp ObjDumper.cpp - StreamWriter.cpp Win64EHDumper.cpp ) diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp index a782d2a68c0..48e8178788b 100644 --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -12,23 +12,22 @@ /// //===----------------------------------------------------------------------===// -#include "llvm-readobj.h" #include "ARMWinEHPrinter.h" #include "CodeView.h" #include "Error.h" #include "ObjDumper.h" #include "StackMapPrinter.h" -#include "StreamWriter.h" #include "Win64EHDumper.h" +#include "llvm-readobj.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/DebugInfo/CodeView/CodeView.h" #include "llvm/DebugInfo/CodeView/Line.h" +#include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/CodeView/TypeIndex.h" #include "llvm/DebugInfo/CodeView/TypeRecord.h" -#include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/Object/COFF.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/COFF.h" @@ -36,6 +35,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Format.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/Win64EH.h" #include "llvm/Support/raw_ostream.h" @@ -54,7 +54,7 @@ namespace { class CVTypeDumper { public: - CVTypeDumper(StreamWriter &W) : W(W) {} + CVTypeDumper(ScopedPrinter &W) : W(W) {} StringRef getTypeName(TypeIndex TI); void printTypeIndex(StringRef FieldName, TypeIndex TI); @@ -65,7 +65,7 @@ private: void printCodeViewFieldList(StringRef FieldData); void printMemberAttributes(MemberAttributes Attrs); - StreamWriter &W; + ScopedPrinter &W; /// All user defined type records in .debug$T live in here. Type indices /// greater than 0x1000 are user defined. Subtract 0x1000 from the index to @@ -77,7 +77,7 @@ private: class COFFDumper : public ObjDumper { public: - COFFDumper(const llvm::object::COFFObjectFile *Obj, StreamWriter &Writer) + COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer) : ObjDumper(Writer), Obj(Obj), CVTD(Writer) {} void printFileHeaders() override; @@ -166,7 +166,7 @@ private: namespace llvm { std::error_code createCOFFDumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { const COFFObjectFile *COFFObj = dyn_cast<COFFObjectFile>(Obj); if (!COFFObj) diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 4905b43a453..31bf5693502 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -12,13 +12,12 @@ /// //===----------------------------------------------------------------------===// -#include "llvm-readobj.h" #include "ARMAttributeParser.h" #include "ARMEHABIPrinter.h" #include "Error.h" #include "ObjDumper.h" #include "StackMapPrinter.h" -#include "StreamWriter.h" +#include "llvm-readobj.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" @@ -26,10 +25,11 @@ #include "llvm/Support/ARMBuildAttributes.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Format.h" +#include "llvm/Support/FormattedStream.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MipsABIFlags.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/FormattedStream.h" using namespace llvm; using namespace llvm::object; @@ -97,7 +97,7 @@ struct DynRegionInfo { template<typename ELFT> class ELFDumper : public ObjDumper { public: - ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer); + ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer); void printFileHeaders() override; void printSections() override; @@ -300,7 +300,7 @@ template <typename ELFT> class GNUStyle : public DumpStyle<ELFT> { formatted_raw_ostream OS; public: TYPEDEF_ELF_TYPES(ELFT) - GNUStyle(StreamWriter &W, ELFDumper<ELFT> *Dumper) + GNUStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) : DumpStyle<ELFT>(Dumper), OS(W.getOStream()) {} void printFileHeaders(const ELFO *Obj) override; void printGroupSections(const ELFFile<ELFT> *Obj) override; @@ -353,7 +353,7 @@ private: template <typename ELFT> class LLVMStyle : public DumpStyle<ELFT> { public: TYPEDEF_ELF_TYPES(ELFT) - LLVMStyle(StreamWriter &W, ELFDumper<ELFT> *Dumper) + LLVMStyle(ScopedPrinter &W, ELFDumper<ELFT> *Dumper) : DumpStyle<ELFT>(Dumper), W(W) {} void printFileHeaders(const ELFO *Obj) override; @@ -372,7 +372,7 @@ private: void printDynamicRelocation(const ELFO *Obj, Elf_Rela Rel); void printSymbol(const ELFO *Obj, const Elf_Sym *Symbol, const Elf_Sym *First, StringRef StrTable, bool IsDynamic) override; - StreamWriter &W; + ScopedPrinter &W; }; } // namespace @@ -381,14 +381,14 @@ namespace llvm { template <class ELFT> static std::error_code createELFDumper(const ELFFile<ELFT> *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { Result.reset(new ELFDumper<ELFT>(Obj, Writer)); return readobj_error::success; } std::error_code createELFDumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { // Little-endian 32-bit if (const ELF32LEObjectFile *ELFObj = dyn_cast<ELF32LEObjectFile>(Obj)) @@ -491,12 +491,10 @@ template <class ELFT> void ELFDumper<ELFT>::LoadVersionMap() const { LoadVersionNeeds(dot_gnu_version_r_sec); } - template <typename ELFO, class ELFT> -static void printVersionSymbolSection(ELFDumper<ELFT> *Dumper, - const ELFO *Obj, +static void printVersionSymbolSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, const typename ELFO::Elf_Shdr *Sec, - StreamWriter &W) { + ScopedPrinter &W) { DictScope SS(W, "Version symbols"); if (!Sec) return; @@ -525,7 +523,7 @@ template <typename ELFO, class ELFT> static void printVersionDefinitionSection(ELFDumper<ELFT> *Dumper, const ELFO *Obj, const typename ELFO::Elf_Shdr *Sec, - StreamWriter &W) { + ScopedPrinter &W) { DictScope SD(W, "Version definition"); if (!Sec) return; @@ -1217,7 +1215,7 @@ static const EnumEntry<unsigned> ElfMips16SymOtherFlags[] = { }; template <typename ELFT> -ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, StreamWriter &Writer) +ELFDumper<ELFT>::ELFDumper(const ELFFile<ELFT> *Obj, ScopedPrinter &Writer) : ObjDumper(Writer), Obj(Obj) { SmallVector<const Elf_Phdr *, 4> LoadSegments; @@ -1795,7 +1793,7 @@ public: typedef typename ELFO::Elf_Rela Elf_Rela; MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, - Elf_Dyn_Range DynTable, StreamWriter &W); + Elf_Dyn_Range DynTable, ScopedPrinter &W); void parseGOT(); void parsePLT(); @@ -1803,7 +1801,7 @@ public: private: ELFDumper<ELFT> *Dumper; const ELFO *Obj; - StreamWriter &W; + ScopedPrinter &W; llvm::Optional<uint64_t> DtPltGot; llvm::Optional<uint64_t> DtLocalGotNum; llvm::Optional<uint64_t> DtGotSym; @@ -1828,7 +1826,7 @@ private: template <class ELFT> MipsGOTParser<ELFT>::MipsGOTParser(ELFDumper<ELFT> *Dumper, const ELFO *Obj, - Elf_Dyn_Range DynTable, StreamWriter &W) + Elf_Dyn_Range DynTable, ScopedPrinter &W) : Dumper(Dumper), Obj(Obj), W(W) { for (const auto &Entry : DynTable) { switch (Entry.getTag()) { diff --git a/llvm/tools/llvm-readobj/MachODumper.cpp b/llvm/tools/llvm-readobj/MachODumper.cpp index cc57211b280..3773df25057 100644 --- a/llvm/tools/llvm-readobj/MachODumper.cpp +++ b/llvm/tools/llvm-readobj/MachODumper.cpp @@ -11,15 +11,15 @@ // //===----------------------------------------------------------------------===// -#include "llvm-readobj.h" #include "Error.h" #include "ObjDumper.h" #include "StackMapPrinter.h" -#include "StreamWriter.h" +#include "llvm-readobj.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Object/MachO.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/ScopedPrinter.h" using namespace llvm; using namespace object; @@ -28,9 +28,8 @@ namespace { class MachODumper : public ObjDumper { public: - MachODumper(const MachOObjectFile *Obj, StreamWriter& Writer) - : ObjDumper(Writer) - , Obj(Obj) { } + MachODumper(const MachOObjectFile *Obj, ScopedPrinter &Writer) + : ObjDumper(Writer), Obj(Obj) {} void printFileHeaders() override; void printSections() override; @@ -69,7 +68,7 @@ private: namespace llvm { std::error_code createMachODumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { const MachOObjectFile *MachOObj = dyn_cast<MachOObjectFile>(Obj); if (!MachOObj) diff --git a/llvm/tools/llvm-readobj/ObjDumper.cpp b/llvm/tools/llvm-readobj/ObjDumper.cpp index 91803de1a1d..2a0a90e5cfd 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.cpp +++ b/llvm/tools/llvm-readobj/ObjDumper.cpp @@ -14,15 +14,13 @@ #include "ObjDumper.h" #include "Error.h" -#include "StreamWriter.h" #include "llvm/Object/ObjectFile.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/raw_ostream.h" namespace llvm { -ObjDumper::ObjDumper(StreamWriter& Writer) - : W(Writer) { -} +ObjDumper::ObjDumper(ScopedPrinter &Writer) : W(Writer) {} ObjDumper::~ObjDumper() { } diff --git a/llvm/tools/llvm-readobj/ObjDumper.h b/llvm/tools/llvm-readobj/ObjDumper.h index 2a633411933..e34789e1bdb 100644 --- a/llvm/tools/llvm-readobj/ObjDumper.h +++ b/llvm/tools/llvm-readobj/ObjDumper.h @@ -19,11 +19,11 @@ class COFFImportFile; class ObjectFile; } -class StreamWriter; +class ScopedPrinter; class ObjDumper { public: - ObjDumper(StreamWriter& Writer); + ObjDumper(ScopedPrinter &Writer); virtual ~ObjDumper(); virtual void printFileHeaders() = 0; @@ -71,19 +71,19 @@ public: virtual void printStackMap() const = 0; protected: - StreamWriter& W; + ScopedPrinter &W; }; std::error_code createCOFFDumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result); std::error_code createELFDumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result); std::error_code createMachODumper(const object::ObjectFile *Obj, - StreamWriter &Writer, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result); void dumpCOFFImportFile(const object::COFFImportFile *File); diff --git a/llvm/tools/llvm-readobj/Win64EHDumper.h b/llvm/tools/llvm-readobj/Win64EHDumper.h index a80df9c4f94..772f68bf283 100644 --- a/llvm/tools/llvm-readobj/Win64EHDumper.h +++ b/llvm/tools/llvm-readobj/Win64EHDumper.h @@ -10,7 +10,7 @@ #ifndef LLVM_TOOLS_LLVM_READOBJ_WIN64EHDUMPER_H #define LLVM_TOOLS_LLVM_READOBJ_WIN64EHDUMPER_H -#include "StreamWriter.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/Win64EH.h" namespace llvm { @@ -22,7 +22,7 @@ struct coff_section; namespace Win64EH { class Dumper { - StreamWriter &SW; + ScopedPrinter &SW; raw_ostream &OS; public: @@ -53,7 +53,7 @@ private: uint64_t SectionOffset, const RuntimeFunction &RF); public: - Dumper(StreamWriter &SW) : SW(SW), OS(SW.getOStream()) {} + Dumper(ScopedPrinter &SW) : SW(SW), OS(SW.getOStream()) {} void printData(const Context &Ctx); }; diff --git a/llvm/tools/llvm-readobj/llvm-readobj.cpp b/llvm/tools/llvm-readobj/llvm-readobj.cpp index 58241ab43d6..fe075a54f96 100644 --- a/llvm/tools/llvm-readobj/llvm-readobj.cpp +++ b/llvm/tools/llvm-readobj/llvm-readobj.cpp @@ -22,7 +22,6 @@ #include "llvm-readobj.h" #include "Error.h" #include "ObjDumper.h" -#include "StreamWriter.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFFImportFile.h" #include "llvm/Object/ELFObjectFile.h" @@ -35,6 +34,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/Signals.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" @@ -293,7 +293,8 @@ static bool isMipsArch(unsigned Arch) { } /// @brief Creates an format-specific object file dumper. -static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, +static std::error_code createDumper(const ObjectFile *Obj, + ScopedPrinter &Writer, std::unique_ptr<ObjDumper> &Result) { if (!Obj) return readobj_error::unsupported_file_format; @@ -310,7 +311,7 @@ static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer, /// @brief Dumps the specified object file. static void dumpObject(const ObjectFile *Obj) { - StreamWriter Writer(outs()); + ScopedPrinter Writer(outs()); std::unique_ptr<ObjDumper> Dumper; if (std::error_code EC = createDumper(Obj, Writer, Dumper)) reportError(Obj->getFileName(), EC); |