1 //===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
11 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/BinaryStreamRef.h"
17 #include "llvm/Support/FormatVariadic.h"
18 #include "llvm/Support/Regex.h"
19 #include "llvm/Support/raw_ostream.h"
24 class BinaryStreamReader;
26 class MSFStreamLayout;
34 friend class WithColor;
37 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
39 void Indent(uint32_t Amount = 0);
40 void Unindent(uint32_t Amount = 0);
43 void printLine(const Twine &T);
44 void print(const Twine &T);
45 template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
46 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
48 template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
49 print(formatv(Fmt, std::forward<Ts>(Items)...));
52 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
53 uint32_t StartOffset);
54 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
55 uint32_t StartOffset);
57 void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
58 StringRef StreamPurpose, uint32_t Offset,
60 void formatMsfStreamData(StringRef Label, PDBFile &File,
61 const msf::MSFStreamLayout &Stream,
62 BinarySubstreamRef Substream);
63 void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
65 bool hasColor() const { return UseColor; }
66 raw_ostream &getStream() { return OS; }
67 int getIndentLevel() const { return CurrentIndent; }
69 bool IsClassExcluded(const ClassLayout &Class);
70 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
71 bool IsSymbolExcluded(llvm::StringRef SymbolName);
72 bool IsCompilandExcluded(llvm::StringRef CompilandName);
75 template <typename Iter>
76 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
78 for (; Begin != End; ++Begin)
79 List.emplace_back(StringRef(*Begin));
87 std::list<Regex> ExcludeCompilandFilters;
88 std::list<Regex> ExcludeTypeFilters;
89 std::list<Regex> ExcludeSymbolFilters;
91 std::list<Regex> IncludeCompilandFilters;
92 std::list<Regex> IncludeTypeFilters;
93 std::list<Regex> IncludeSymbolFilters;
97 explicit PrintScope(LinePrinter &P, uint32_t IndentLevel)
98 : P(P), IndentLevel(IndentLevel) {}
99 explicit PrintScope(const PrintScope &Other, uint32_t LabelWidth)
100 : P(Other.P), IndentLevel(Other.IndentLevel), LabelWidth(LabelWidth) {}
103 uint32_t IndentLevel;
104 uint32_t LabelWidth = 0;
107 inline Optional<PrintScope> withLabelWidth(const Optional<PrintScope> &Scope,
111 return PrintScope{*Scope, W};
115 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
116 : L(&L), Amount(Amount) {
119 explicit AutoIndent(const Optional<PrintScope> &Scope) {
120 if (Scope.hasValue()) {
122 Amount = Scope->IndentLevel;
130 LinePrinter *L = nullptr;
135 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
136 Printer.getStream() << Item;
137 return Printer.getStream();
140 enum class PDB_ColorItem {
157 WithColor(LinePrinter &P, PDB_ColorItem C);
160 raw_ostream &get() { return OS; }
163 void applyColor(PDB_ColorItem C);