2015-02-27 10:15:59 +01:00
|
|
|
//===- LinePrinter.cpp ------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LinePrinter.h"
|
|
|
|
|
2015-03-02 05:39:56 +01:00
|
|
|
#include "llvm-pdbdump.h"
|
|
|
|
|
2015-12-01 08:49:23 +01:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2015-03-01 07:49:49 +01:00
|
|
|
#include "llvm/Support/Regex.h"
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2016-05-04 22:32:13 +02:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::pdb;
|
|
|
|
|
2015-09-29 21:49:06 +02:00
|
|
|
namespace {
|
|
|
|
bool IsItemExcluded(llvm::StringRef Item,
|
|
|
|
std::list<llvm::Regex> &IncludeFilters,
|
|
|
|
std::list<llvm::Regex> &ExcludeFilters) {
|
|
|
|
if (Item.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto match_pred = [Item](llvm::Regex &R) { return R.match(Item); };
|
|
|
|
|
|
|
|
// Include takes priority over exclude. If the user specified include
|
|
|
|
// filters, and none of them include this item, them item is gone.
|
2015-12-01 08:49:23 +01:00
|
|
|
if (!IncludeFilters.empty() && !any_of(IncludeFilters, match_pred))
|
2015-09-29 21:49:06 +02:00
|
|
|
return true;
|
|
|
|
|
2015-12-01 08:49:23 +01:00
|
|
|
if (any_of(ExcludeFilters, match_pred))
|
2015-09-29 21:49:06 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
LinePrinter::LinePrinter(int Indent, llvm::raw_ostream &Stream)
|
2015-03-02 05:39:56 +01:00
|
|
|
: OS(Stream), IndentSpaces(Indent), CurrentIndent(0) {
|
2016-06-30 19:42:48 +02:00
|
|
|
SetFilters(ExcludeTypeFilters, opts::pretty::ExcludeTypes.begin(),
|
|
|
|
opts::pretty::ExcludeTypes.end());
|
|
|
|
SetFilters(ExcludeSymbolFilters, opts::pretty::ExcludeSymbols.begin(),
|
|
|
|
opts::pretty::ExcludeSymbols.end());
|
|
|
|
SetFilters(ExcludeCompilandFilters, opts::pretty::ExcludeCompilands.begin(),
|
|
|
|
opts::pretty::ExcludeCompilands.end());
|
|
|
|
|
|
|
|
SetFilters(IncludeTypeFilters, opts::pretty::IncludeTypes.begin(),
|
|
|
|
opts::pretty::IncludeTypes.end());
|
|
|
|
SetFilters(IncludeSymbolFilters, opts::pretty::IncludeSymbols.begin(),
|
|
|
|
opts::pretty::IncludeSymbols.end());
|
|
|
|
SetFilters(IncludeCompilandFilters, opts::pretty::IncludeCompilands.begin(),
|
|
|
|
opts::pretty::IncludeCompilands.end());
|
2015-03-02 05:39:56 +01:00
|
|
|
}
|
2015-02-27 10:15:59 +01:00
|
|
|
|
|
|
|
void LinePrinter::Indent() { CurrentIndent += IndentSpaces; }
|
|
|
|
|
|
|
|
void LinePrinter::Unindent() {
|
|
|
|
CurrentIndent = std::max(0, CurrentIndent - IndentSpaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LinePrinter::NewLine() {
|
|
|
|
OS << "\n";
|
|
|
|
OS.indent(CurrentIndent);
|
|
|
|
}
|
|
|
|
|
2015-03-01 07:49:49 +01:00
|
|
|
bool LinePrinter::IsTypeExcluded(llvm::StringRef TypeName) {
|
2015-09-29 21:49:06 +02:00
|
|
|
return IsItemExcluded(TypeName, IncludeTypeFilters, ExcludeTypeFilters);
|
2015-03-01 07:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LinePrinter::IsSymbolExcluded(llvm::StringRef SymbolName) {
|
2015-09-29 21:49:06 +02:00
|
|
|
return IsItemExcluded(SymbolName, IncludeSymbolFilters, ExcludeSymbolFilters);
|
2015-03-01 07:49:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LinePrinter::IsCompilandExcluded(llvm::StringRef CompilandName) {
|
2015-09-29 21:49:06 +02:00
|
|
|
return IsItemExcluded(CompilandName, IncludeCompilandFilters,
|
|
|
|
ExcludeCompilandFilters);
|
2015-03-01 07:49:49 +01:00
|
|
|
}
|
|
|
|
|
2015-02-27 10:15:59 +01:00
|
|
|
WithColor::WithColor(LinePrinter &P, PDB_ColorItem C) : OS(P.OS) {
|
2015-11-03 02:04:44 +01:00
|
|
|
applyColor(C);
|
2015-02-27 10:15:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
WithColor::~WithColor() { OS.resetColor(); }
|
|
|
|
|
2015-11-03 02:04:44 +01:00
|
|
|
void WithColor::applyColor(PDB_ColorItem C) {
|
2015-02-27 10:15:59 +01:00
|
|
|
switch (C) {
|
2015-11-03 02:04:44 +01:00
|
|
|
case PDB_ColorItem::None:
|
|
|
|
OS.resetColor();
|
|
|
|
return;
|
2015-02-27 10:15:59 +01:00
|
|
|
case PDB_ColorItem::Address:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::YELLOW, /*bold=*/true);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::Keyword:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::MAGENTA, true);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
2015-03-02 05:39:56 +01:00
|
|
|
case PDB_ColorItem::Register:
|
2015-02-27 10:15:59 +01:00
|
|
|
case PDB_ColorItem::Offset:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::YELLOW, false);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::Type:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::CYAN, true);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::Identifier:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::CYAN, false);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::Path:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::CYAN, false);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::SectionHeader:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::RED, true);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
case PDB_ColorItem::LiteralValue:
|
2015-11-03 02:04:44 +01:00
|
|
|
OS.changeColor(raw_ostream::GREEN, true);
|
2015-02-27 10:15:59 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|