1 //===- LinePrinter.cpp ------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "LinePrinter.h" 11 12 #include "llvm-pdbdump.h" 13 14 #include "llvm/Support/Regex.h" 15 16 #include <algorithm> 17 18 using namespace llvm; 19 20 LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream) 21 : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) { 22 SetFilters(TypeFilters, opts::ExcludeTypes.begin(), opts::ExcludeTypes.end()); 23 SetFilters(SymbolFilters, opts::ExcludeSymbols.begin(), 24 opts::ExcludeSymbols.end()); 25 SetFilters(CompilandFilters, opts::ExcludeCompilands.begin(), 26 opts::ExcludeCompilands.end()); 27 } 28 29 void LinePrinter::Indent() { CurrentIndent += IndentSpaces; } 30 31 void LinePrinter::Unindent() { 32 CurrentIndent = std::max(0, CurrentIndent - IndentSpaces); 33 } 34 35 void LinePrinter::NewLine() { 36 OS << "\n"; 37 OS.indent(CurrentIndent); 38 } 39 40 bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) { 41 if (TypeName.empty()) 42 return false; 43 44 for (auto &Expr : TypeFilters) { 45 if (Expr.match(TypeName)) 46 return true; 47 } 48 return false; 49 } 50 51 bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) { 52 if (SymbolName.empty()) 53 return false; 54 55 for (auto &Expr : SymbolFilters) { 56 if (Expr.match(SymbolName)) 57 return true; 58 } 59 return false; 60 } 61 62 bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) { 63 if (CompilandName.empty()) 64 return false; 65 66 for (auto &Expr : CompilandFilters) { 67 if (Expr.match(CompilandName)) 68 return true; 69 } 70 return false; 71 } 72 73 WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) { 74 if (C == PDB_ColorItem::None) 75 OS.resetColor(); 76 else { 77 raw_ostream::Colors Color; 78 bool Bold; 79 translateColor(C, Color, Bold); 80 OS.changeColor(Color, Bold); 81 } 82 } 83 84 WithColor::~WithColor() { OS.resetColor(); } 85 86 void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color, 87 bool &Bold) const { 88 switch (C) { 89 case PDB_ColorItem::Address: 90 Color = raw_ostream::YELLOW; 91 Bold = true; 92 return; 93 case PDB_ColorItem::Keyword: 94 Color = raw_ostream::MAGENTA; 95 Bold = true; 96 return; 97 case PDB_ColorItem::Register: 98 case PDB_ColorItem::Offset: 99 Color = raw_ostream::YELLOW; 100 Bold = false; 101 return; 102 case PDB_ColorItem::Type: 103 Color = raw_ostream::CYAN; 104 Bold = true; 105 return; 106 case PDB_ColorItem::Identifier: 107 Color = raw_ostream::CYAN; 108 Bold = false; 109 return; 110 case PDB_ColorItem::Path: 111 Color = raw_ostream::CYAN; 112 Bold = false; 113 return; 114 case PDB_ColorItem::SectionHeader: 115 Color = raw_ostream::RED; 116 Bold = true; 117 return; 118 case PDB_ColorItem::LiteralValue: 119 Color = raw_ostream::GREEN; 120 Bold = true; 121 default: 122 return; 123 } 124 } 125