LLVM  15.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.
24 struct FilterOptions {
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;
37  bool JustMyCode;
38 };
39 
40 namespace llvm {
41 namespace msf {
42 class MSFStreamLayout;
43 } // namespace msf
44 namespace pdb {
45 
46 class ClassLayout;
47 class PDBFile;
48 class SymbolGroup;
49 
50 class LinePrinter {
51  friend class WithColor;
52 
53 public:
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,
77  uint64_t Size);
79  const msf::MSFStreamLayout &Stream,
80  BinarySubstreamRef Substream);
82 
83  bool hasColor() const { return UseColor; }
84  raw_ostream &getStream() { return OS; }
85  int getIndentLevel() const { return CurrentIndent; }
86 
87  bool IsClassExcluded(const ClassLayout &Class);
90  bool IsCompilandExcluded(llvm::StringRef CompilandName);
91 
92  const FilterOptions &getFilters() const { return Filters; }
93 
94 private:
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 
102  raw_ostream &OS;
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 
117 struct PrintScope {
119  : P(P), IndentLevel(IndentLevel) {}
120  explicit PrintScope(const PrintScope &Other, uint32_t LabelWidth)
122 
126 };
127 
129  return PrintScope{Scope, W};
130 }
131 
132 struct AutoIndent {
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 
150 template <class T>
151 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
152  return Printer.getStream() << Item;
153 }
154 
155 enum class PDB_ColorItem {
156  None,
157  Address,
158  Type,
159  Comment,
160  Padding,
161  Keyword,
162  Offset,
163  Identifier,
164  Path,
166  LiteralValue,
167  Register,
168 };
169 
170 class WithColor {
171 public:
173  ~WithColor();
174 
175  raw_ostream &get() { return OS; }
176 
177 private:
178  void applyColor(PDB_ColorItem C);
179  raw_ostream &OS;
180  bool UseColor;
181 };
182 } // namespace pdb
183 } // namespace llvm
184 
185 #endif
UseColor
static ManagedStatic< cl::opt< cl::boolOrDefault >, CreateUseColor > UseColor
Definition: WithColor.cpp:33
llvm::Check::Size
@ Size
Definition: FileCheck.h:77
FilterOptions::DumpModi
llvm::Optional< uint32_t > DumpModi
Definition: LinePrinter.h:33
FilterOptions::SymbolOffset
llvm::Optional< uint32_t > SymbolOffset
Definition: LinePrinter.h:36
FilterOptions::PaddingThreshold
uint32_t PaddingThreshold
Definition: LinePrinter.h:31
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::pdb::LinePrinter
Definition: LinePrinter.h:50
FilterOptions::IncludeTypes
std::list< std::string > IncludeTypes
Definition: LinePrinter.h:28
llvm::RISCVFenceField::W
@ W
Definition: RISCVBaseInfo.h:242
llvm::pdb::PDB_ColorItem::SectionHeader
@ SectionHeader
llvm::pdb::WithColor::WithColor
WithColor(LinePrinter &P, PDB_ColorItem C)
Definition: LinePrinter.cpp:294
llvm::pdb::PrintScope::IndentLevel
uint32_t IndentLevel
Definition: LinePrinter.h:124
llvm::pdb::PDB_ColorItem::Comment
@ Comment
llvm::pdb::LinePrinter::LinePrinter
LinePrinter(int Indent, bool UseColor, raw_ostream &Stream, const FilterOptions &Filters)
Definition: LinePrinter.cpp:56
llvm::Optional< uint32_t >
T
#define T
Definition: Mips16ISelLowering.cpp:341
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:79
FilterOptions::ExcludeSymbols
std::list< std::string > ExcludeSymbols
Definition: LinePrinter.h:26
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::pdb::WithColor::~WithColor
~WithColor()
Definition: LinePrinter.cpp:300
llvm::pdb::LinePrinter::IsCompilandExcluded
bool IsCompilandExcluded(llvm::StringRef CompilandName)
Definition: LinePrinter.cpp:289
llvm::pdb::LinePrinter::print
void print(const Twine &T)
Definition: LinePrinter.cpp:92
llvm::pdb::withLabelWidth
PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W)
Definition: LinePrinter.h:128
Printer
print alias Alias Set Printer
Definition: AliasSetTracker.cpp:733
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
FilterOptions
Definition: LinePrinter.h:24
llvm::pdb::WithColor
Definition: LinePrinter.h:170
llvm::pdb::PrintScope::PrintScope
PrintScope(LinePrinter &P, uint32_t IndentLevel)
Definition: LinePrinter.h:118
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::BinarySubstreamRef
Definition: BinaryStreamRef.h:199
Twine.h
FilterOptions::IncludeCompilands
std::list< std::string > IncludeCompilands
Definition: LinePrinter.h:30
llvm::pdb::WithColor::get
raw_ostream & get()
Definition: LinePrinter.h:175
llvm::pdb::LinePrinter::getStream
raw_ostream & getStream()
Definition: LinePrinter.h:84
llvm::pdb::LinePrinter::Indent
void Indent(uint32_t Amount=0)
Definition: LinePrinter.cpp:75
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::pdb::LinePrinter::IsTypeExcluded
bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size)
Definition: LinePrinter.cpp:277
llvm::pdb::AutoIndent::L
LinePrinter * L
Definition: LinePrinter.h:146
llvm::pdb::LinePrinter::formatBinary
void formatBinary(StringRef Label, ArrayRef< uint8_t > Data, uint64_t StartOffset)
Definition: LinePrinter.cpp:107
llvm::pdb::AutoIndent
Definition: LinePrinter.h:132
llvm::pdb::PrintScope::P
LinePrinter & P
Definition: LinePrinter.h:123
llvm::pdb::PDB_ColorItem::Path
@ Path
FormatVariadic.h
llvm::pdb::LinePrinter::formatMsfStreamBlocks
void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream)
Definition: LinePrinter.cpp:252
llvm::pdb::LinePrinter::format
void format(const char *Fmt, Ts &&...Items)
Definition: LinePrinter.h:66
llvm::pdb::LinePrinter::formatMsfStreamData
void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx, StringRef StreamPurpose, uint64_t Offset, uint64_t Size)
Definition: LinePrinter.cpp:180
llvm::pdb::LinePrinter::IsSymbolExcluded
bool IsSymbolExcluded(llvm::StringRef SymbolName)
Definition: LinePrinter.cpp:285
llvm::pdb::PDB_ColorItem::Address
@ Address
llvm::pdb::PDB_ColorItem::Register
@ Register
uint64_t
llvm::pdb::PDB_ColorItem::None
@ None
llvm::pdb::LinePrinter::formatLine
void formatLine(const char *Fmt, Ts &&...Items)
Definition: LinePrinter.h:63
llvm::pdb::PDB_ColorItem::Type
@ Type
llvm::pdb::AutoIndent::~AutoIndent
~AutoIndent()
Definition: LinePrinter.h:141
ArrayRef.h
FilterOptions::ChildrenRecurseDepth
llvm::Optional< uint32_t > ChildrenRecurseDepth
Definition: LinePrinter.h:35
Regex.h
llvm::pdb::LinePrinter::Unindent
void Unindent(uint32_t Amount=0)
Definition: LinePrinter.cpp:81
llvm::pdb::LinePrinter::printLine
void printLine(const Twine &T)
Definition: LinePrinter.cpp:94
llvm::pdb::LinePrinter::hasColor
bool hasColor() const
Definition: LinePrinter.h:83
llvm::pdb::LinePrinter::IsClassExcluded
bool IsClassExcluded(const ClassLayout &Class)
Definition: LinePrinter.cpp:99
FilterOptions::ExcludeCompilands
std::list< std::string > ExcludeCompilands
Definition: LinePrinter.h:27
FilterOptions::ExcludeTypes
std::list< std::string > ExcludeTypes
Definition: LinePrinter.h:25
llvm::pdb::LinePrinter::getFilters
const FilterOptions & getFilters() const
Definition: LinePrinter.h:92
llvm::pdb::PDB_ColorItem::Offset
@ Offset
llvm::ArrayRef< uint8_t >
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
BinaryStreamRef.h
llvm::pdb::LinePrinter::getIndentLevel
int getIndentLevel() const
Definition: LinePrinter.h:85
uint32_t
llvm::pdb::PDB_ColorItem::LiteralValue
@ LiteralValue
llvm::AMDGPU::HSAMD::Kernel::Key::SymbolName
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Definition: AMDGPUMetadata.h:386
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::pdb::LinePrinter::NewLine
void NewLine()
Definition: LinePrinter.cpp:87
llvm::pdb::operator<<
raw_ostream & operator<<(LinePrinter &Printer, const T &Item)
Definition: LinePrinter.h:151
llvm::AMDGPU::HSAMD::Kernel::Arg::Key::TypeName
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
Definition: AMDGPUMetadata.h:175
FormatUtil.h
llvm::tgtok::Class
@ Class
Definition: TGLexer.h:50
FilterOptions::JustMyCode
bool JustMyCode
Definition: LinePrinter.h:37
llvm::pdb::PDB_ColorItem::Padding
@ Padding
llvm::pdb::PDB_ColorItem::Identifier
@ Identifier
FilterOptions::IncludeSymbols
std::list< std::string > IncludeSymbols
Definition: LinePrinter.h:29
llvm::pdb::PDBFile
Definition: PDBFile.h:40
List
const NodeList & List
Definition: RDFGraph.cpp:199
llvm::pdb::PDB_ColorItem
PDB_ColorItem
Definition: LinePrinter.h:155
FilterOptions::SizeThreshold
uint32_t SizeThreshold
Definition: LinePrinter.h:32
llvm::pdb::PrintScope::PrintScope
PrintScope(const PrintScope &Other, uint32_t LabelWidth)
Definition: LinePrinter.h:120
llvm::pdb::PrintScope
Definition: LinePrinter.h:117
llvm::pdb::AutoIndent::Amount
uint32_t Amount
Definition: LinePrinter.h:147
llvm::pdb::PDB_ColorItem::Keyword
@ Keyword
llvm::ARMBuildAttrs::File
@ File
Definition: ARMBuildAttributes.h:36
llvm::pdb::PrintScope::LabelWidth
uint32_t LabelWidth
Definition: LinePrinter.h:125
raw_ostream.h
llvm::pdb::AutoIndent::AutoIndent
AutoIndent(const PrintScope &Scope)
Definition: LinePrinter.h:137
llvm::pdb::ClassLayout
Definition: UDTLayout.h:161
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1238
llvm::pdb::AutoIndent::AutoIndent
AutoIndent(LinePrinter &L, uint32_t Amount=0)
Definition: LinePrinter.h:133
FilterOptions::ParentRecurseDepth
llvm::Optional< uint32_t > ParentRecurseDepth
Definition: LinePrinter.h:34
llvm::msf::MSFStreamLayout
Describes the layout of a stream in an MSF layout.
Definition: MSFCommon.h:77