LLVM 20.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"
18#include "llvm/Support/Regex.h"
20
21#include <list>
22
23// Container for filter options to control which elements will be printed.
25 std::list<std::string> ExcludeTypes;
26 std::list<std::string> ExcludeSymbols;
27 std::list<std::string> ExcludeCompilands;
28 std::list<std::string> IncludeTypes;
29 std::list<std::string> IncludeSymbols;
30 std::list<std::string> IncludeCompilands;
33 std::optional<uint32_t> DumpModi;
34 std::optional<uint32_t> ParentRecurseDepth;
35 std::optional<uint32_t> ChildrenRecurseDepth;
36 std::optional<uint32_t> SymbolOffset;
38};
39
40namespace llvm {
41namespace msf {
42class MSFStreamLayout;
43} // namespace msf
44namespace pdb {
45
46class ClassLayout;
47class PDBFile;
48class SymbolGroup;
49
51 friend class WithColor;
52
53public:
54 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
55 const FilterOptions &Filters);
56
57 void Indent(uint32_t Amount = 0);
58 void Unindent(uint32_t Amount = 0);
59 void NewLine();
60
61 void printLine(const Twine &T);
62 void print(const Twine &T);
63 template <typename... Ts> void formatLine(const char *Fmt, Ts &&...Items) {
64 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
65 }
66 template <typename... Ts> void format(const char *Fmt, Ts &&...Items) {
67 print(formatv(Fmt, std::forward<Ts>(Items)...));
68 }
69
71 uint64_t StartOffset);
73 uint64_t StartOffset);
74
75 void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
76 StringRef StreamPurpose, uint64_t Offset,
79 const msf::MSFStreamLayout &Stream,
80 BinarySubstreamRef Substream);
81 void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
82
83 bool hasColor() const { return UseColor; }
84 raw_ostream &getStream() { return OS; }
85 int getIndentLevel() const { return CurrentIndent; }
86
89 bool IsSymbolExcluded(llvm::StringRef SymbolName);
90 bool IsCompilandExcluded(llvm::StringRef CompilandName);
91
92 const FilterOptions &getFilters() const { return Filters; }
93
94private:
95 template <typename Iter>
96 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
97 List.clear();
98 for (; Begin != End; ++Begin)
99 List.emplace_back(StringRef(*Begin));
100 }
101
103 int IndentSpaces;
104 int CurrentIndent;
105 bool UseColor;
106 const FilterOptions &Filters;
107
108 std::list<Regex> ExcludeCompilandFilters;
109 std::list<Regex> ExcludeTypeFilters;
110 std::list<Regex> ExcludeSymbolFilters;
111
112 std::list<Regex> IncludeCompilandFilters;
113 std::list<Regex> IncludeTypeFilters;
114 std::list<Regex> IncludeSymbolFilters;
115};
116
119 : P(P), IndentLevel(IndentLevel) {}
122
126};
127
129 return PrintScope{Scope, W};
130}
131
134 : L(&L), Amount(Amount) {
135 L.Indent(Amount);
136 }
137 explicit AutoIndent(const PrintScope &Scope) {
138 L = &Scope.P;
139 Amount = Scope.IndentLevel;
140 }
142 if (L)
143 L->Unindent(Amount);
144 }
145
146 LinePrinter *L = nullptr;
148};
149
150template <class T>
152 return Printer.getStream() << Item;
153}
154
155enum class PDB_ColorItem {
156 None,
157 Address,
158 Type,
159 Comment,
160 Padding,
161 Keyword,
162 Offset,
164 Path,
167 Register,
168};
169
171public:
173 ~WithColor();
174
175 raw_ostream &get() { return OS; }
176
177private:
178 void applyColor(PDB_ColorItem C);
179 raw_ostream &OS;
180 bool UseColor;
181};
182} // namespace pdb
183} // namespace llvm
184
185#endif
dxil pretty DXIL Metadata Pretty Printer
uint64_t Size
bool End
Definition: ELF_riscv.cpp:480
#define P(N)
raw_pwrite_stream & OS
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:51
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
Describes the layout of a stream in an MSF layout.
Definition: MSFCommon.h:77
bool hasColor() const
Definition: LinePrinter.h:83
void print(const Twine &T)
Definition: LinePrinter.cpp:91
void format(const char *Fmt, Ts &&...Items)
Definition: LinePrinter.h:66
void printLine(const Twine &T)
Definition: LinePrinter.cpp:93
const FilterOptions & getFilters() const
Definition: LinePrinter.h:92
void Unindent(uint32_t Amount=0)
Definition: LinePrinter.cpp:80
void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx, StringRef StreamPurpose, uint64_t Offset, uint64_t Size)
int getIndentLevel() const
Definition: LinePrinter.h:85
bool IsSymbolExcluded(llvm::StringRef SymbolName)
raw_ostream & getStream()
Definition: LinePrinter.h:84
void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream)
void formatLine(const char *Fmt, Ts &&...Items)
Definition: LinePrinter.h:63
void formatBinary(StringRef Label, ArrayRef< uint8_t > Data, uint64_t StartOffset)
bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size)
bool IsClassExcluded(const ClassLayout &Class)
Definition: LinePrinter.cpp:98
bool IsCompilandExcluded(llvm::StringRef CompilandName)
void Indent(uint32_t Amount=0)
Definition: LinePrinter.cpp:74
raw_ostream & get()
Definition: LinePrinter.h:175
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W)
Definition: LinePrinter.h:128
raw_ostream & operator<<(LinePrinter &Printer, const T &Item)
Definition: LinePrinter.h:151
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
@ Other
Any other memory.
std::list< std::string > IncludeCompilands
Definition: LinePrinter.h:30
std::optional< uint32_t > DumpModi
Definition: LinePrinter.h:33
std::list< std::string > IncludeTypes
Definition: LinePrinter.h:28
std::list< std::string > IncludeSymbols
Definition: LinePrinter.h:29
uint32_t SizeThreshold
Definition: LinePrinter.h:32
std::list< std::string > ExcludeTypes
Definition: LinePrinter.h:25
std::optional< uint32_t > SymbolOffset
Definition: LinePrinter.h:36
std::optional< uint32_t > ChildrenRecurseDepth
Definition: LinePrinter.h:35
uint32_t PaddingThreshold
Definition: LinePrinter.h:31
std::list< std::string > ExcludeCompilands
Definition: LinePrinter.h:27
std::optional< uint32_t > ParentRecurseDepth
Definition: LinePrinter.h:34
std::list< std::string > ExcludeSymbols
Definition: LinePrinter.h:26
AutoIndent(const PrintScope &Scope)
Definition: LinePrinter.h:137
AutoIndent(LinePrinter &L, uint32_t Amount=0)
Definition: LinePrinter.h:133
PrintScope(const PrintScope &Other, uint32_t LabelWidth)
Definition: LinePrinter.h:120
PrintScope(LinePrinter &P, uint32_t IndentLevel)
Definition: LinePrinter.h:118