1 //===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
10 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/Support/BinaryStreamRef.h"
16 #include "llvm/Support/FormatVariadic.h"
17 #include "llvm/Support/Regex.h"
18 #include "llvm/Support/raw_ostream.h"
24 class MSFStreamLayout
;
32 friend class WithColor
;
35 LinePrinter(int Indent
, bool UseColor
, raw_ostream
&Stream
);
37 void Indent(uint32_t Amount
= 0);
38 void Unindent(uint32_t Amount
= 0);
41 void printLine(const Twine
&T
);
42 void print(const Twine
&T
);
43 template <typename
... Ts
> void formatLine(const char *Fmt
, Ts
&&... Items
) {
44 printLine(formatv(Fmt
, std::forward
<Ts
>(Items
)...));
46 template <typename
... Ts
> void format(const char *Fmt
, Ts
&&... Items
) {
47 print(formatv(Fmt
, std::forward
<Ts
>(Items
)...));
50 void formatBinary(StringRef Label
, ArrayRef
<uint8_t> Data
,
51 uint64_t StartOffset
);
52 void formatBinary(StringRef Label
, ArrayRef
<uint8_t> Data
, uint64_t BaseAddr
,
53 uint64_t StartOffset
);
55 void formatMsfStreamData(StringRef Label
, PDBFile
&File
, uint32_t StreamIdx
,
56 StringRef StreamPurpose
, uint64_t Offset
,
58 void formatMsfStreamData(StringRef Label
, PDBFile
&File
,
59 const msf::MSFStreamLayout
&Stream
,
60 BinarySubstreamRef Substream
);
61 void formatMsfStreamBlocks(PDBFile
&File
, const msf::MSFStreamLayout
&Stream
);
63 bool hasColor() const { return UseColor
; }
64 raw_ostream
&getStream() { return OS
; }
65 int getIndentLevel() const { return CurrentIndent
; }
67 bool IsClassExcluded(const ClassLayout
&Class
);
68 bool IsTypeExcluded(llvm::StringRef TypeName
, uint64_t Size
);
69 bool IsSymbolExcluded(llvm::StringRef SymbolName
);
70 bool IsCompilandExcluded(llvm::StringRef CompilandName
);
73 template <typename Iter
>
74 void SetFilters(std::list
<Regex
> &List
, Iter Begin
, Iter End
) {
76 for (; Begin
!= End
; ++Begin
)
77 List
.emplace_back(StringRef(*Begin
));
85 std::list
<Regex
> ExcludeCompilandFilters
;
86 std::list
<Regex
> ExcludeTypeFilters
;
87 std::list
<Regex
> ExcludeSymbolFilters
;
89 std::list
<Regex
> IncludeCompilandFilters
;
90 std::list
<Regex
> IncludeTypeFilters
;
91 std::list
<Regex
> IncludeSymbolFilters
;
95 explicit PrintScope(LinePrinter
&P
, uint32_t IndentLevel
)
96 : P(P
), IndentLevel(IndentLevel
) {}
97 explicit PrintScope(const PrintScope
&Other
, uint32_t LabelWidth
)
98 : P(Other
.P
), IndentLevel(Other
.IndentLevel
), LabelWidth(LabelWidth
) {}
101 uint32_t IndentLevel
;
102 uint32_t LabelWidth
= 0;
105 inline Optional
<PrintScope
> withLabelWidth(const Optional
<PrintScope
> &Scope
,
109 return PrintScope
{*Scope
, W
};
113 explicit AutoIndent(LinePrinter
&L
, uint32_t Amount
= 0)
114 : L(&L
), Amount(Amount
) {
117 explicit AutoIndent(const Optional
<PrintScope
> &Scope
) {
118 if (Scope
.hasValue()) {
120 Amount
= Scope
->IndentLevel
;
128 LinePrinter
*L
= nullptr;
133 inline raw_ostream
&operator<<(LinePrinter
&Printer
, const T
&Item
) {
134 return Printer
.getStream() << Item
;
137 enum class PDB_ColorItem
{
154 WithColor(LinePrinter
&P
, PDB_ColorItem C
);
157 raw_ostream
&get() { return OS
; }
160 void applyColor(PDB_ColorItem C
);