LLVM 22.0.0git
LinePrinter.h
Go to the documentation of this file.
1//===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
10#define LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
11
12#include "llvm/ADT/ArrayRef.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
19#include "llvm/Support/Regex.h"
21
22#include <list>
23
24// Container for filter options to control which elements will be printed.
26 std::list<std::string> ExcludeTypes;
27 std::list<std::string> ExcludeSymbols;
28 std::list<std::string> ExcludeCompilands;
29 std::list<std::string> IncludeTypes;
30 std::list<std::string> IncludeSymbols;
31 std::list<std::string> IncludeCompilands;
34 std::optional<uint32_t> DumpModi;
35 std::optional<uint32_t> ParentRecurseDepth;
36 std::optional<uint32_t> ChildrenRecurseDepth;
37 std::optional<uint32_t> SymbolOffset;
39};
40
41namespace llvm {
42namespace msf {
43class MSFStreamLayout;
44} // namespace msf
45namespace pdb {
46
47class ClassLayout;
48class PDBFile;
49class SymbolGroup;
50
52 friend class WithColor;
53
54public:
55 LLVM_ABI LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
56 const FilterOptions &Filters);
57
58 LLVM_ABI void Indent(uint32_t Amount = 0);
59 LLVM_ABI void Unindent(uint32_t Amount = 0);
60 LLVM_ABI void NewLine();
61
62 LLVM_ABI void printLine(const Twine &T);
63 LLVM_ABI void print(const Twine &T);
64 template <typename... Ts> void formatLine(const char *Fmt, Ts &&...Items) {
65 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
66 }
67 template <typename... Ts> void format(const char *Fmt, Ts &&...Items) {
68 print(formatv(Fmt, std::forward<Ts>(Items)...));
69 }
70
72 uint64_t StartOffset);
74 uint64_t BaseAddr, uint64_t StartOffset);
75
77 uint32_t StreamIdx, StringRef StreamPurpose,
80 const msf::MSFStreamLayout &Stream,
81 BinarySubstreamRef Substream);
83 const msf::MSFStreamLayout &Stream);
84
85 bool hasColor() const { return UseColor; }
86 raw_ostream &getStream() { return OS; }
87 int getIndentLevel() const { return CurrentIndent; }
88
93
94 const FilterOptions &getFilters() const { return Filters; }
95
96private:
97 template <typename Iter>
98 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
99 List.clear();
100 for (; Begin != End; ++Begin)
101 List.emplace_back(StringRef(*Begin));
102 }
103
104 raw_ostream &OS;
105 int IndentSpaces;
106 int CurrentIndent;
107 bool UseColor;
108 const FilterOptions &Filters;
109
110 std::list<Regex> ExcludeCompilandFilters;
111 std::list<Regex> ExcludeTypeFilters;
112 std::list<Regex> ExcludeSymbolFilters;
113
114 std::list<Regex> IncludeCompilandFilters;
115 std::list<Regex> IncludeTypeFilters;
116 std::list<Regex> IncludeSymbolFilters;
117};
118
129
131 return PrintScope{Scope, W};
132}
133
136 : L(&L), Amount(Amount) {
137 L.Indent(Amount);
138 }
139 explicit AutoIndent(const PrintScope &Scope) {
140 L = &Scope.P;
141 Amount = Scope.IndentLevel;
142 }
144 if (L)
145 L->Unindent(Amount);
146 }
147
148 LinePrinter *L = nullptr;
150};
151
152template <class T>
154 return Printer.getStream() << Item;
155}
156
171
173public:
176
177 raw_ostream &get() { return OS; }
178
179private:
180 void applyColor(PDB_ColorItem C);
181 raw_ostream &OS;
182 bool UseColor;
183};
184} // namespace pdb
185} // namespace llvm
186
187#endif
#define LLVM_ABI
Definition Compiler.h:213
dxil pretty DXIL Metadata Pretty Printer
#define T
#define P(N)
static ManagedStatic< cl::opt< cl::boolOrDefault >, CreateUseColor > UseColor
Definition WithColor.cpp:33
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
Describes the layout of a stream in an MSF layout.
Definition MSFCommon.h:78
bool hasColor() const
Definition LinePrinter.h:85
LLVM_ABI void print(const Twine &T)
void format(const char *Fmt, Ts &&...Items)
Definition LinePrinter.h:67
LLVM_ABI void printLine(const Twine &T)
const FilterOptions & getFilters() const
Definition LinePrinter.h:94
LLVM_ABI void Unindent(uint32_t Amount=0)
LLVM_ABI void NewLine()
LLVM_ABI void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx, StringRef StreamPurpose, uint64_t Offset, uint64_t Size)
int getIndentLevel() const
Definition LinePrinter.h:87
LLVM_ABI bool IsSymbolExcluded(llvm::StringRef SymbolName)
raw_ostream & getStream()
Definition LinePrinter.h:86
friend class WithColor
Definition LinePrinter.h:52
LLVM_ABI LinePrinter(int Indent, bool UseColor, raw_ostream &Stream, const FilterOptions &Filters)
LLVM_ABI void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream)
void formatLine(const char *Fmt, Ts &&...Items)
Definition LinePrinter.h:64
LLVM_ABI void formatBinary(StringRef Label, ArrayRef< uint8_t > Data, uint64_t StartOffset)
LLVM_ABI bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size)
LLVM_ABI bool IsClassExcluded(const ClassLayout &Class)
LLVM_ABI bool IsCompilandExcluded(llvm::StringRef CompilandName)
LLVM_ABI void Indent(uint32_t Amount=0)
raw_ostream & get()
LLVM_ABI WithColor(LinePrinter &P, PDB_ColorItem C)
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W)
raw_ostream & operator<<(LinePrinter &Printer, const T &Item)
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
@ Other
Any other memory.
Definition ModRef.h:68
std::list< std::string > IncludeCompilands
Definition LinePrinter.h:31
std::optional< uint32_t > DumpModi
Definition LinePrinter.h:34
std::list< std::string > IncludeTypes
Definition LinePrinter.h:29
std::list< std::string > IncludeSymbols
Definition LinePrinter.h:30
uint32_t SizeThreshold
Definition LinePrinter.h:33
std::list< std::string > ExcludeTypes
Definition LinePrinter.h:26
std::optional< uint32_t > SymbolOffset
Definition LinePrinter.h:37
std::optional< uint32_t > ChildrenRecurseDepth
Definition LinePrinter.h:36
uint32_t PaddingThreshold
Definition LinePrinter.h:32
std::list< std::string > ExcludeCompilands
Definition LinePrinter.h:28
std::optional< uint32_t > ParentRecurseDepth
Definition LinePrinter.h:35
std::list< std::string > ExcludeSymbols
Definition LinePrinter.h:27
AutoIndent(const PrintScope &Scope)
AutoIndent(LinePrinter &L, uint32_t Amount=0)
PrintScope(const PrintScope &Other, uint32_t LabelWidth)
PrintScope(LinePrinter &P, uint32_t IndentLevel)