[llvm-pdbdump] Colorize output.

llvm-svn: 230746
diff --git a/llvm/tools/llvm-pdbdump/VariableDumper.cpp b/llvm/tools/llvm-pdbdump/VariableDumper.cpp
index 371c270..90c418c 100644
--- a/llvm/tools/llvm-pdbdump/VariableDumper.cpp
+++ b/llvm/tools/llvm-pdbdump/VariableDumper.cpp
@@ -10,6 +10,7 @@
 #include "VariableDumper.h"
 
 #include "BuiltinDumper.h"
+#include "LinePrinter.h"
 #include "llvm-pdbdump.h"
 #include "FunctionDumper.h"
 
@@ -26,45 +27,51 @@
 
 using namespace llvm;
 
-VariableDumper::VariableDumper() : PDBSymDumper(true) {}
+VariableDumper::VariableDumper(LinePrinter &P)
+    : PDBSymDumper(true), Printer(P) {}
 
 void VariableDumper::start(const PDBSymbolData &Var, raw_ostream &OS,
                            int Indent) {
-  OS << newline(Indent);
-  OS << "data ";
+  Printer.NewLine();
+  Printer << "data ";
 
   auto VarType = Var.getType();
 
   switch (auto LocType = Var.getLocationType()) {
   case PDB_LocType::Static:
-    OS << "[" << format_hex(Var.getRelativeVirtualAddress(), 10) << "] ";
-    OS << "static ";
+    WithColor(Printer, PDB_ColorItem::Address).get()
+        << "[" << format_hex(Var.getRelativeVirtualAddress(), 10) << "] ";
+    WithColor(Printer, PDB_ColorItem::Keyword).get() << "static ";
     dumpSymbolTypeAndName(*VarType, Var.getName(), OS);
     break;
   case PDB_LocType::Constant:
-    OS << "const ";
+    WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
     dumpSymbolTypeAndName(*VarType, Var.getName(), OS);
-    OS << "[" << Var.getValue() << "]";
+    Printer << "[";
+    WithColor(Printer, PDB_ColorItem::LiteralValue).get() << Var.getValue();
+    Printer << "]";
     break;
   case PDB_LocType::ThisRel:
-    OS << "+" << format_hex(Var.getOffset(), 4) << " ";
+    WithColor(Printer, PDB_ColorItem::Offset).get()
+        << "+" << format_hex(Var.getOffset(), 4) << " ";
     dumpSymbolTypeAndName(*VarType, Var.getName(), OS);
     break;
   default:
+    OS << "unknown(" << LocType << ") ";
+    WithColor(Printer, PDB_ColorItem::Identifier).get() << Var.getName();
     break;
-    OS << "unknown(" << LocType << ") " << Var.getName();
   }
 }
 
 void VariableDumper::dump(const PDBSymbolTypeBuiltin &Symbol, raw_ostream &OS,
                           int Indent) {
-  BuiltinDumper Dumper;
+  BuiltinDumper Dumper(Printer);
   Dumper.start(Symbol, OS);
 }
 
 void VariableDumper::dump(const PDBSymbolTypeEnum &Symbol, raw_ostream &OS,
                           int Indent) {
-  OS << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
 }
 
 void VariableDumper::dump(const PDBSymbolTypeFunctionSig &Symbol,
@@ -77,29 +84,30 @@
     return;
 
   if (auto Func = dyn_cast<PDBSymbolFunc>(PointeeType.get())) {
-    FunctionDumper NestedDumper;
+    FunctionDumper NestedDumper(Printer);
     FunctionDumper::PointerType Pointer =
         Symbol.isReference() ? FunctionDumper::PointerType::Reference
                              : FunctionDumper::PointerType::Pointer;
     NestedDumper.start(*Func, Pointer, OS, Indent);
   } else {
     if (Symbol.isConstType())
-      OS << "const ";
+      WithColor(Printer, PDB_ColorItem::Keyword).get() << "const ";
     if (Symbol.isVolatileType())
-      OS << "volatile ";
+      WithColor(Printer, PDB_ColorItem::Keyword).get() << "volatile ";
     PointeeType->dump(OS, Indent, *this);
-    OS << (Symbol.isReference() ? "&" : "*");
+    Printer << (Symbol.isReference() ? "&" : "*");
   }
 }
 
 void VariableDumper::dump(const PDBSymbolTypeTypedef &Symbol, raw_ostream &OS,
                           int Indent) {
-  OS << "typedef " << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Keyword).get() << "typedef ";
+  WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
 }
 
 void VariableDumper::dump(const PDBSymbolTypeUDT &Symbol, raw_ostream &OS,
                           int Indent) {
-  OS << Symbol.getName();
+  WithColor(Printer, PDB_ColorItem::Type).get() << Symbol.getName();
 }
 
 void VariableDumper::dumpSymbolTypeAndName(const PDBSymbol &Type,
@@ -109,16 +117,19 @@
     raw_string_ostream IndexStream(IndexSpec);
     std::unique_ptr<PDBSymbol> ElementType = ArrayType->getElementType();
     while (auto NestedArray = dyn_cast<PDBSymbolTypeArray>(ElementType.get())) {
-      IndexStream << "[" << NestedArray->getCount() << "]";
+      IndexStream << "[";
+      IndexStream << NestedArray->getCount();
+      IndexStream << "]";
       ElementType = NestedArray->getElementType();
     }
     IndexStream << "[" << ArrayType->getCount() << "]";
     ElementType->dump(OS, 0, *this);
-    OS << " " << Name << IndexStream.str();
+    WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
+    Printer << IndexStream.str();
   } else {
     if (!tryDumpFunctionPointer(Type, Name, OS)) {
       Type.dump(OS, 0, *this);
-      OS << " " << Name;
+      WithColor(Printer, PDB_ColorItem::Identifier).get() << " " << Name;
     }
   }
 }
@@ -131,7 +142,7 @@
     auto PointeeType = PointerType->getPointeeType();
     if (auto *FunctionSig =
             dyn_cast<PDBSymbolTypeFunctionSig>(PointeeType.get())) {
-      FunctionDumper Dumper;
+      FunctionDumper Dumper(Printer);
       FunctionDumper::PointerType PT = FunctionDumper::PointerType::Pointer;
       if (PointerType->isReference())
         PT = FunctionDumper::PointerType::Reference;