LinePrinter.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include "LinePrinter.h"
  10. #include "llvm-pdbdump.h"
  11. #include "llvm/Support/Regex.h"
  12. #include <algorithm>
  13. using namespace llvm;
  14. LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
  15. : OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
  16. SetFilters(TypeFilters, opts::ExcludeTypes.begin(), opts::ExcludeTypes.end());
  17. SetFilters(SymbolFilters, opts::ExcludeSymbols.begin(),
  18. opts::ExcludeSymbols.end());
  19. SetFilters(CompilandFilters, opts::ExcludeCompilands.begin(),
  20. opts::ExcludeCompilands.end());
  21. }
  22. void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
  23. void LinePrinter::Unindent() {
  24. CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
  25. }
  26. void LinePrinter::NewLine() {
  27. OS << "\n";
  28. OS.indent(CurrentIndent);
  29. }
  30. bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
  31. if (TypeName.empty())
  32. return false;
  33. for (auto &Expr : TypeFilters) {
  34. if (Expr.match(TypeName))
  35. return true;
  36. }
  37. return false;
  38. }
  39. bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
  40. if (SymbolName.empty())
  41. return false;
  42. for (auto &Expr : SymbolFilters) {
  43. if (Expr.match(SymbolName))
  44. return true;
  45. }
  46. return false;
  47. }
  48. bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
  49. if (CompilandName.empty())
  50. return false;
  51. for (auto &Expr : CompilandFilters) {
  52. if (Expr.match(CompilandName))
  53. return true;
  54. }
  55. return false;
  56. }
  57. WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
  58. if (C == PDB_ColorItem::None)
  59. OS.resetColor();
  60. else {
  61. raw_ostream::Colors Color;
  62. bool Bold;
  63. translateColor(C, Color, Bold);
  64. OS.changeColor(Color, Bold);
  65. }
  66. }
  67. WithColor::~WithColor() { OS.resetColor(); }
  68. void WithColor::translateColor(PDB_ColorItem C, raw_ostream::Colors &Color,
  69. bool &Bold) const {
  70. switch (C) {
  71. case PDB_ColorItem::Address:
  72. Color = raw_ostream::YELLOW;
  73. Bold = true;
  74. return;
  75. case PDB_ColorItem::Keyword:
  76. Color = raw_ostream::MAGENTA;
  77. Bold = true;
  78. return;
  79. case PDB_ColorItem::Register:
  80. case PDB_ColorItem::Offset:
  81. Color = raw_ostream::YELLOW;
  82. Bold = false;
  83. return;
  84. case PDB_ColorItem::Type:
  85. Color = raw_ostream::CYAN;
  86. Bold = true;
  87. return;
  88. case PDB_ColorItem::Identifier:
  89. Color = raw_ostream::CYAN;
  90. Bold = false;
  91. return;
  92. case PDB_ColorItem::Path:
  93. Color = raw_ostream::CYAN;
  94. Bold = false;
  95. return;
  96. case PDB_ColorItem::SectionHeader:
  97. Color = raw_ostream::RED;
  98. Bold = true;
  99. return;
  100. case PDB_ColorItem::LiteralValue:
  101. Color = raw_ostream::GREEN;
  102. Bold = true;
  103. default:
  104. return;
  105. }
  106. }