]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-pdbutil/LinePrinter.h
Update tcpdump to 4.9.2
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-pdbutil / LinePrinter.h
1 //===- LinePrinter.h ------------------------------------------ *- C++ --*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
11 #define LLVM_TOOLS_LLVMPDBDUMP_LINEPRINTER_H
12
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/BinaryStreamRef.h"
17 #include "llvm/Support/FormatVariadic.h"
18 #include "llvm/Support/Regex.h"
19 #include "llvm/Support/raw_ostream.h"
20
21 #include <list>
22
23 namespace llvm {
24 class BinaryStreamReader;
25 namespace msf {
26 class MSFStreamLayout;
27 } // namespace msf
28 namespace pdb {
29
30 class ClassLayout;
31 class PDBFile;
32
33 class LinePrinter {
34   friend class WithColor;
35
36 public:
37   LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
38
39   void Indent(uint32_t Amount = 0);
40   void Unindent(uint32_t Amount = 0);
41   void NewLine();
42
43   void printLine(const Twine &T);
44   void print(const Twine &T);
45   template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
46     printLine(formatv(Fmt, std::forward<Ts>(Items)...));
47   }
48   template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
49     print(formatv(Fmt, std::forward<Ts>(Items)...));
50   }
51
52   void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
53                     uint32_t StartOffset);
54   void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
55                     uint32_t StartOffset);
56
57   void formatMsfStreamData(StringRef Label, PDBFile &File, uint32_t StreamIdx,
58                            StringRef StreamPurpose, uint32_t Offset,
59                            uint32_t Size);
60   void formatMsfStreamData(StringRef Label, PDBFile &File,
61                            const msf::MSFStreamLayout &Stream,
62                            BinarySubstreamRef Substream);
63
64   bool hasColor() const { return UseColor; }
65   raw_ostream &getStream() { return OS; }
66   int getIndentLevel() const { return CurrentIndent; }
67
68   bool IsClassExcluded(const ClassLayout &Class);
69   bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
70   bool IsSymbolExcluded(llvm::StringRef SymbolName);
71   bool IsCompilandExcluded(llvm::StringRef CompilandName);
72
73 private:
74   template <typename Iter>
75   void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
76     List.clear();
77     for (; Begin != End; ++Begin)
78       List.emplace_back(StringRef(*Begin));
79   }
80
81   raw_ostream &OS;
82   int IndentSpaces;
83   int CurrentIndent;
84   bool UseColor;
85
86   std::list<Regex> ExcludeCompilandFilters;
87   std::list<Regex> ExcludeTypeFilters;
88   std::list<Regex> ExcludeSymbolFilters;
89
90   std::list<Regex> IncludeCompilandFilters;
91   std::list<Regex> IncludeTypeFilters;
92   std::list<Regex> IncludeSymbolFilters;
93 };
94
95 struct AutoIndent {
96   explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
97       : L(L), Amount(Amount) {
98     L.Indent(Amount);
99   }
100   ~AutoIndent() { L.Unindent(Amount); }
101
102   LinePrinter &L;
103   uint32_t Amount = 0;
104 };
105
106 template <class T>
107 inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
108   Printer.getStream() << Item;
109   return Printer.getStream();
110 }
111
112 enum class PDB_ColorItem {
113   None,
114   Address,
115   Type,
116   Comment,
117   Padding,
118   Keyword,
119   Offset,
120   Identifier,
121   Path,
122   SectionHeader,
123   LiteralValue,
124   Register,
125 };
126
127 class WithColor {
128 public:
129   WithColor(LinePrinter &P, PDB_ColorItem C);
130   ~WithColor();
131
132   raw_ostream &get() { return OS; }
133
134 private:
135   void applyColor(PDB_ColorItem C);
136   raw_ostream &OS;
137   bool UseColor;
138 };
139 }
140 }
141
142 #endif