Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:44

0001 //===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
0010 #define LLVM_DEBUGINFO_PDB_NATIVE_LINEPRINTER_H
0011 
0012 #include "llvm/ADT/ArrayRef.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/ADT/Twine.h"
0015 #include "llvm/DebugInfo/PDB/Native/FormatUtil.h"
0016 #include "llvm/Support/BinaryStreamRef.h"
0017 #include "llvm/Support/FormatVariadic.h"
0018 #include "llvm/Support/Regex.h"
0019 #include "llvm/Support/raw_ostream.h"
0020 
0021 #include <list>
0022 
0023 // Container for filter options to control which elements will be printed.
0024 struct FilterOptions {
0025   std::list<std::string> ExcludeTypes;
0026   std::list<std::string> ExcludeSymbols;
0027   std::list<std::string> ExcludeCompilands;
0028   std::list<std::string> IncludeTypes;
0029   std::list<std::string> IncludeSymbols;
0030   std::list<std::string> IncludeCompilands;
0031   uint32_t PaddingThreshold;
0032   uint32_t SizeThreshold;
0033   std::optional<uint32_t> DumpModi;
0034   std::optional<uint32_t> ParentRecurseDepth;
0035   std::optional<uint32_t> ChildrenRecurseDepth;
0036   std::optional<uint32_t> SymbolOffset;
0037   bool JustMyCode;
0038 };
0039 
0040 namespace llvm {
0041 namespace msf {
0042 class MSFStreamLayout;
0043 } // namespace msf
0044 namespace pdb {
0045 
0046 class ClassLayout;
0047 class PDBFile;
0048 class SymbolGroup;
0049 
0050 class LinePrinter {
0051   friend class WithColor;
0052 
0053 public:
0054   LinePrinter(int Indent, bool UseColor, raw_ostream &Stream,
0055               const FilterOptions &Filters);
0056 
0057   void Indent(uint32_t Amount = 0);
0058   void Unindent(uint32_t Amount = 0);
0059   void NewLine();
0060 
0061   void printLine(const Twine &T);
0062   void print(const Twine &T);
0063   template <typename... Ts> void formatLine(const char *Fmt, Ts &&...Items) {
0064     printLine(formatv(Fmt, std::forward<Ts>(Items)...));
0065   }
0066   template <typename... Ts> void format(const char *Fmt, Ts &&...Items) {
0067     print(formatv(Fmt, std::forward<Ts>(Items)...));
0068   }
0069 
0070   void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
0071                     uint64_t StartOffset);
0072   void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
0073                     uint64_t StartOffset);
0074 
0075   void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
0076                            StringRef StreamPurpose, uint64_t Offset,
0077                            uint64_t Size);
0078   void formatMsfStreamData(StringRef Label, PDBFile &File,
0079                            const msf::MSFStreamLayout &Stream,
0080                            BinarySubstreamRef Substream);
0081   void formatMsfStreamBlocks(PDBFile &File, const msf::MSFStreamLayout &Stream);
0082 
0083   bool hasColor() const { return UseColor; }
0084   raw_ostream &getStream() { return OS; }
0085   int getIndentLevel() const { return CurrentIndent; }
0086 
0087   bool IsClassExcluded(const ClassLayout &Class);
0088   bool IsTypeExcluded(llvm::StringRef TypeName, uint64_t Size);
0089   bool IsSymbolExcluded(llvm::StringRef SymbolName);
0090   bool IsCompilandExcluded(llvm::StringRef CompilandName);
0091 
0092   const FilterOptions &getFilters() const { return Filters; }
0093 
0094 private:
0095   template <typename Iter>
0096   void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
0097     List.clear();
0098     for (; Begin != End; ++Begin)
0099       List.emplace_back(StringRef(*Begin));
0100   }
0101 
0102   raw_ostream &OS;
0103   int IndentSpaces;
0104   int CurrentIndent;
0105   bool UseColor;
0106   const FilterOptions &Filters;
0107 
0108   std::list<Regex> ExcludeCompilandFilters;
0109   std::list<Regex> ExcludeTypeFilters;
0110   std::list<Regex> ExcludeSymbolFilters;
0111 
0112   std::list<Regex> IncludeCompilandFilters;
0113   std::list<Regex> IncludeTypeFilters;
0114   std::list<Regex> IncludeSymbolFilters;
0115 };
0116 
0117 struct PrintScope {
0118   explicit PrintScope(LinePrinter &P, uint32_t IndentLevel)
0119       : P(P), IndentLevel(IndentLevel) {}
0120   explicit PrintScope(const PrintScope &Other, uint32_t LabelWidth)
0121       : P(Other.P), IndentLevel(Other.IndentLevel), LabelWidth(LabelWidth) {}
0122 
0123   LinePrinter &P;
0124   uint32_t IndentLevel;
0125   uint32_t LabelWidth = 0;
0126 };
0127 
0128 inline PrintScope withLabelWidth(const PrintScope &Scope, uint32_t W) {
0129   return PrintScope{Scope, W};
0130 }
0131 
0132 struct AutoIndent {
0133   explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
0134       : L(&L), Amount(Amount) {
0135     L.Indent(Amount);
0136   }
0137   explicit AutoIndent(const PrintScope &Scope) {
0138     L = &Scope.P;
0139     Amount = Scope.IndentLevel;
0140   }
0141   ~AutoIndent() {
0142     if (L)
0143       L->Unindent(Amount);
0144   }
0145 
0146   LinePrinter *L = nullptr;
0147   uint32_t Amount = 0;
0148 };
0149 
0150 template <class T>
0151 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
0152   return Printer.getStream() << Item;
0153 }
0154 
0155 enum class PDB_ColorItem {
0156   None,
0157   Address,
0158   Type,
0159   Comment,
0160   Padding,
0161   Keyword,
0162   Offset,
0163   Identifier,
0164   Path,
0165   SectionHeader,
0166   LiteralValue,
0167   Register,
0168 };
0169 
0170 class WithColor {
0171 public:
0172   WithColor(LinePrinter &P, PDB_ColorItem C);
0173   ~WithColor();
0174 
0175   raw_ostream &get() { return OS; }
0176 
0177 private:
0178   void applyColor(PDB_ColorItem C);
0179   raw_ostream &OS;
0180   bool UseColor;
0181 };
0182 } // namespace pdb
0183 } // namespace llvm
0184 
0185 #endif