[llvm] r268342 - Move llvm-readobj/StreamWriter to Support.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 17:28:04 PDT 2016


Author: zturner
Date: Mon May  2 19:28:04 2016
New Revision: 268342

URL: http://llvm.org/viewvc/llvm-project?rev=268342&view=rev
Log:
Move llvm-readobj/StreamWriter to Support.

We wish to re-use this from llvm-pdbdump, and it provides a nice
way to print structured data in scoped format that could prove
useful for many other dumping tools as well.  Moving to support
and changing name to ScopedPrinter to better reflect its purpose.

Added:
    llvm/trunk/include/llvm/Support/ScopedPrinter.h
      - copied, changed from r268340, llvm/trunk/tools/llvm-readobj/StreamWriter.h
    llvm/trunk/lib/Support/ScopedPrinter.cpp
      - copied, changed from r268340, llvm/trunk/tools/llvm-readobj/StreamWriter.cpp
Removed:
    llvm/trunk/tools/llvm-readobj/StreamWriter.cpp
    llvm/trunk/tools/llvm-readobj/StreamWriter.h
Modified:
    llvm/trunk/lib/Support/CMakeLists.txt
    llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
    llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h
    llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
    llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.h
    llvm/trunk/tools/llvm-readobj/CMakeLists.txt
    llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
    llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
    llvm/trunk/tools/llvm-readobj/MachODumper.cpp
    llvm/trunk/tools/llvm-readobj/ObjDumper.cpp
    llvm/trunk/tools/llvm-readobj/ObjDumper.h
    llvm/trunk/tools/llvm-readobj/Win64EHDumper.h
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Copied: llvm/trunk/include/llvm/Support/ScopedPrinter.h (from r268340, llvm/trunk/tools/llvm-readobj/StreamWriter.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ScopedPrinter.h?p2=llvm/trunk/include/llvm/Support/ScopedPrinter.h&p1=llvm/trunk/tools/llvm-readobj/StreamWriter.h&r1=268340&r2=268342&rev=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/StreamWriter.h (original)
+++ llvm/trunk/include/llvm/Support/ScopedPrinter.h Mon May  2 19:28:04 2016
@@ -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_
   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

Modified: llvm/trunk/lib/Support/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CMakeLists.txt?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CMakeLists.txt (original)
+++ llvm/trunk/lib/Support/CMakeLists.txt Mon May  2 19:28:04 2016
@@ -76,6 +76,7 @@ add_llvm_library(LLVMSupport
   RandomNumberGenerator.cpp
   Regex.cpp
   ScaledNumber.cpp
+  ScopedPrinter.cpp
   SHA1.cpp
   SmallPtrSet.cpp
   SmallVector.cpp

Copied: llvm/trunk/lib/Support/ScopedPrinter.cpp (from r268340, llvm/trunk/tools/llvm-readobj/StreamWriter.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ScopedPrinter.cpp?p2=llvm/trunk/lib/Support/ScopedPrinter.cpp&p1=llvm/trunk/tools/llvm-readobj/StreamWriter.cpp&r1=268340&r2=268342&rev=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/StreamWriter.cpp (original)
+++ llvm/trunk/lib/Support/ScopedPrinter.cpp Mon May  2 19:28:04 2016
@@ -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
   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;
 

Modified: llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ARMAttributeParser.cpp Mon May  2 19:28:04 2016
@@ -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;

Modified: llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMAttributeParser.h Mon May  2 19:28:04 2016
@@ -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);
 };

Modified: llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMEHABIPrinter.h Mon May  2 19:28:04 2016
@@ -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) {}
 

Modified: llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.h?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.h (original)
+++ llvm/trunk/tools/llvm-readobj/ARMWinEHPrinter.h Mon May  2 19:28:04 2016
@@ -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);
 };
 }

Modified: llvm/trunk/tools/llvm-readobj/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/CMakeLists.txt?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-readobj/CMakeLists.txt Mon May  2 19:28:04 2016
@@ -13,6 +13,5 @@ add_llvm_tool(llvm-readobj
   llvm-readobj.cpp
   MachODumper.cpp
   ObjDumper.cpp
-  StreamWriter.cpp
   Win64EHDumper.cpp
   )

Modified: llvm/trunk/tools/llvm-readobj/COFFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/COFFDumper.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/COFFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/COFFDumper.cpp Mon May  2 19:28:04 2016
@@ -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)

Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Mon May  2 19:28:04 2016
@@ -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
   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<ELF
     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> ElfMips
 };
 
 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()) {

Modified: llvm/trunk/tools/llvm-readobj/MachODumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/MachODumper.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/MachODumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/MachODumper.cpp Mon May  2 19:28:04 2016
@@ -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)

Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.cpp Mon May  2 19:28:04 2016
@@ -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() {
 }

Modified: llvm/trunk/tools/llvm-readobj/ObjDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ObjDumper.h?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ObjDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/ObjDumper.h Mon May  2 19:28:04 2016
@@ -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);

Removed: llvm/trunk/tools/llvm-readobj/StreamWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/StreamWriter.cpp?rev=268341&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-readobj/StreamWriter.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/StreamWriter.cpp (removed)
@@ -1,71 +0,0 @@
-#include "StreamWriter.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Support/Format.h"
-#include <cctype>
-
-using namespace llvm::support;
-
-namespace llvm {
-
-raw_ostream &operator<<(raw_ostream &OS, const HexNumber& Value) {
-  OS << "0x" << to_hexString(Value.Value);
-  return OS;
-}
-
-const std::string to_hexString(uint64_t Value, bool UpperCase) {
-  std::string number;
-  llvm::raw_string_ostream stream(number);
-  stream << format_hex_no_prefix(Value, 1, UpperCase);
-  return stream.str();
-}
-
-void StreamWriter::printBinaryImpl(StringRef Label, StringRef Str,
-                                   ArrayRef<uint8_t> Data, bool Block) {
-  if (Data.size() > 16)
-    Block = true;
-
-  if (Block) {
-    startLine() << Label;
-    if (Str.size() > 0)
-      OS << ": " << Str;
-    OS << " (\n";
-    for (size_t addr = 0, end = Data.size(); addr < end; addr += 16) {
-      startLine() << format("  %04" PRIX64 ": ", uint64_t(addr));
-      // Dump line of hex.
-      for (size_t i = 0; i < 16; ++i) {
-        if (i != 0 && i % 4 == 0)
-          OS << ' ';
-        if (addr + i < end)
-          OS << hexdigit((Data[addr + i] >> 4) & 0xF, false)
-             << hexdigit(Data[addr + i] & 0xF, false);
-        else
-          OS << "  ";
-      }
-      // Print ascii.
-      OS << "  |";
-      for (std::size_t i = 0; i < 16 && addr + i < end; ++i) {
-        if (std::isprint(Data[addr + i] & 0xFF))
-          OS << Data[addr + i];
-        else
-          OS << ".";
-      }
-      OS << "|\n";
-    }
-
-    startLine() << ")\n";
-  } else {
-    startLine() << Label << ":";
-    if (Str.size() > 0)
-      OS << " " << Str;
-    OS << " (";
-    for (size_t i = 0; i < Data.size(); ++i) {
-      if (i > 0)
-        OS << " ";
-
-      OS << format("%02X", static_cast<int>(Data[i]));
-    }
-    OS << ")\n";
-  }
-}
-
-} // namespace llvm

Removed: llvm/trunk/tools/llvm-readobj/StreamWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/StreamWriter.h?rev=268341&view=auto
==============================================================================
--- llvm/trunk/tools/llvm-readobj/StreamWriter.h (original)
+++ llvm/trunk/tools/llvm-readobj/StreamWriter.h (removed)
@@ -1,354 +0,0 @@
-//===-- StreamWriter.h ----------------------------------------------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H
-#define LLVM_TOOLS_LLVM_READOBJ_STREAMWRITER_H
-
-#include "llvm/ADT/APSInt.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
-#include "llvm/Support/Endian.h"
-#include "llvm/Support/raw_ostream.h"
-#include <algorithm>
-
-using namespace llvm;
-
-namespace llvm {
-
-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
-  // display same string for same enum. The AltName if initialized appropriately
-  // will hold the string that GNU style emits.
-  // Example:
-  // "EM_X86_64" string on LLVM style for Elf_Ehdr->e_machine corresponds to
-  // "Advanced Micro Devices X86-64" on GNU style
-  StringRef AltName;
-  T Value;
-  EnumEntry(StringRef N, StringRef A, T V) : Name(N), AltName(A), Value(V) {}
-  EnumEntry(StringRef N, T V) : Name(N), AltName(N), Value(V) {}
-};
-
-struct HexNumber {
-  // To avoid sign-extension we have to explicitly cast to the appropriate
-  // 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) { }
-  uint64_t 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) {
-  std::string number;
-  llvm::raw_string_ostream stream(number);
-  stream << Value;
-  return stream.str();
-}
-
-class StreamWriter {
-public:
-  StreamWriter(raw_ostream &OS)
-    : OS(OS)
-    , IndentLevel(0) {
-  }
-
-  void flush() {
-    OS.flush();
-  }
-
-  void indent(int Levels = 1) {
-    IndentLevel += Levels;
-  }
-
-  void unindent(int Levels = 1) {
-    IndentLevel = std::max(0, IndentLevel - Levels);
-  }
-
-  void printIndent() {
-    for (int i = 0; i < IndentLevel; ++i)
-      OS << "  ";
-  }
-
-  template<typename T>
-  HexNumber hex(T Value) {
-    return HexNumber(Value);
-  }
-
-  template<typename T, typename TEnum>
-  void printEnum(StringRef Label, T Value,
-                 ArrayRef<EnumEntry<TEnum> > EnumValues) {
-    StringRef Name;
-    bool Found = false;
-    for (const auto &EnumItem : EnumValues) {
-      if (EnumItem.Value == Value) {
-        Name = EnumItem.Name;
-        Found = true;
-        break;
-      }
-    }
-
-    if (Found) {
-      startLine() << Label << ": " << Name << " (" << hex(Value) << ")\n";
-    } else {
-      startLine() << Label << ": " << hex(Value) << "\n";
-    }
-  }
-
-  template <typename T, typename TFlag>
-  void printFlags(StringRef Label, T Value, ArrayRef<EnumEntry<TFlag>> Flags,
-                  TFlag EnumMask1 = {}, TFlag EnumMask2 = {},
-                  TFlag EnumMask3 = {}) {
-    typedef EnumEntry<TFlag> FlagEntry;
-    typedef SmallVector<FlagEntry, 10> FlagVector;
-    FlagVector SetFlags;
-
-    for (const auto &Flag : Flags) {
-      if (Flag.Value == 0)
-        continue;
-
-      TFlag EnumMask{};
-      if (Flag.Value & EnumMask1)
-        EnumMask = EnumMask1;
-      else if (Flag.Value & EnumMask2)
-        EnumMask = EnumMask2;
-      else if (Flag.Value & EnumMask3)
-        EnumMask = EnumMask3;
-      bool IsEnum = (Flag.Value & EnumMask) != 0;
-      if ((!IsEnum && (Value & Flag.Value) == Flag.Value) ||
-          (IsEnum  && (Value & EnumMask) == Flag.Value)) {
-        SetFlags.push_back(Flag);
-      }
-    }
-
-    std::sort(SetFlags.begin(), SetFlags.end(), &flagName<TFlag>);
-
-    startLine() << Label << " [ (" << hex(Value) << ")\n";
-    for (const auto &Flag : SetFlags) {
-      startLine() << "  " << Flag.Name << " (" << hex(Flag.Value) << ")\n";
-    }
-    startLine() << "]\n";
-  }
-
-  template<typename T>
-  void printFlags(StringRef Label, T Value) {
-    startLine() << Label << " [ (" << hex(Value) << ")\n";
-    uint64_t Flag = 1;
-    uint64_t Curr = Value;
-    while (Curr > 0) {
-      if (Curr & 1)
-        startLine() << "  " << hex(Flag) << "\n";
-      Curr >>= 1;
-      Flag <<= 1;
-    }
-    startLine() << "]\n";
-  }
-
-  void printNumber(StringRef Label, uint64_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, uint32_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, uint16_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, uint8_t Value) {
-    startLine() << Label << ": " << unsigned(Value) << "\n";
-  }
-
-  void printNumber(StringRef Label, int64_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, int32_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, int16_t Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printNumber(StringRef Label, int8_t Value) {
-    startLine() << Label << ": " << int(Value) << "\n";
-  }
-
-  void printNumber(StringRef Label, APSInt Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printBoolean(StringRef Label, bool Value) {
-    startLine() << Label << ": " << (Value ? "Yes" : "No") << '\n';
-  }
-
-  template <typename T>
-  void printList(StringRef Label, const T &List) {
-    startLine() << Label << ": [";
-    bool Comma = false;
-    for (const auto &Item : List) {
-      if (Comma)
-        OS << ", ";
-      OS << Item;
-      Comma = true;
-    }
-    OS << "]\n";
-  }
-
-  template <typename T>
-  void printHexList(StringRef Label, const T &List) {
-    startLine() << Label << ": [";
-    bool Comma = false;
-    for (const auto &Item : List) {
-      if (Comma)
-        OS << ", ";
-      OS << hex(Item);
-      Comma = true;
-    }
-    OS << "]\n";
-  }
-
-  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) {
-    startLine() << Label << ": " << Str << " (" << hex(Value) << ")\n";
-  }
-
-  template <typename T>
-  void printSymbolOffset(StringRef Label, StringRef Symbol, T Value) {
-    startLine() << Label << ": " << Symbol << '+' << hex(Value) << '\n';
-  }
-
-  void printString(StringRef Label, StringRef Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  void printString(StringRef Label, const std::string &Value) {
-    startLine() << Label << ": " << Value << "\n";
-  }
-
-  template<typename T>
-  void printNumber(StringRef Label, StringRef Str, T Value) {
-    startLine() << Label << ": " << Str << " (" << Value << ")\n";
-  }
-
-  void printBinary(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value) {
-    printBinaryImpl(Label, Str, Value, false);
-  }
-
-  void printBinary(StringRef Label, StringRef Str, ArrayRef<char> Value) {
-    auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
-                          Value.size());
-    printBinaryImpl(Label, Str, V, false);
-  }
-
-  void printBinary(StringRef Label, ArrayRef<uint8_t> Value) {
-    printBinaryImpl(Label, StringRef(), Value, false);
-  }
-
-  void printBinary(StringRef Label, ArrayRef<char> Value) {
-    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()),
-                          Value.size());
-    printBinaryImpl(Label, StringRef(), V, false);
-  }
-
-  void printBinaryBlock(StringRef Label, StringRef Value) {
-    auto V = makeArrayRef(reinterpret_cast<const uint8_t*>(Value.data()),
-                          Value.size());
-    printBinaryImpl(Label, StringRef(), V, true);
-  }
-
-  raw_ostream& startLine() {
-    printIndent();
-    return OS;
-  }
-
-  raw_ostream& getOStream() {
-    return OS;
-  }
-
-private:
-  template<typename T>
-  static bool flagName(const EnumEntry<T>& lhs, const EnumEntry<T>& rhs) {
-    return lhs.Name < rhs.Name;
-  }
-
-  void printBinaryImpl(StringRef Label, StringRef Str, ArrayRef<uint8_t> Value,
-                       bool Block);
-
-  raw_ostream &OS;
-  int IndentLevel;
-};
-
-template <>
-inline void
-StreamWriter::printHex<support::ulittle16_t>(StringRef Label,
-                                             support::ulittle16_t Value) {
-  startLine() << Label << ": " << hex(Value) << "\n";
-}
-
-struct DictScope {
-  DictScope(StreamWriter& W, StringRef N) : W(W) {
-    W.startLine() << N << " {\n";
-    W.indent();
-  }
-
-  ~DictScope() {
-    W.unindent();
-    W.startLine() << "}\n";
-  }
-
-  StreamWriter& W;
-};
-
-struct ListScope {
-  ListScope(StreamWriter& W, StringRef N) : W(W) {
-    W.startLine() << N << " [\n";
-    W.indent();
-  }
-
-  ~ListScope() {
-    W.unindent();
-    W.startLine() << "]\n";
-  }
-
-  StreamWriter& W;
-};
-
-} // namespace llvm
-
-#endif

Modified: llvm/trunk/tools/llvm-readobj/Win64EHDumper.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/Win64EHDumper.h?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/Win64EHDumper.h (original)
+++ llvm/trunk/tools/llvm-readobj/Win64EHDumper.h Mon May  2 19:28:04 2016
@@ -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);
 };

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=268342&r1=268341&r2=268342&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Mon May  2 19:28:04 2016
@@ -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(cons
 
 /// @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);




More information about the llvm-commits mailing list