blob: 9293c49132d58dc6df746cd160d5b0506fb84640 [file] [log] [blame]
Zachary Turner2d11c202015-02-27 09:15:59 +00001//===- 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
Zachary Turner63055452017-06-15 22:24:24 +000013#include "llvm/ADT/ArrayRef.h"
Zachary Turner98162462015-03-01 06:59:57 +000014#include "llvm/ADT/StringRef.h"
Zachary Turner2d11c202015-02-27 09:15:59 +000015#include "llvm/ADT/Twine.h"
Zachary Turner63055452017-06-15 22:24:24 +000016#include "llvm/Support/FormatVariadic.h"
Zachary Turnerda504b72017-06-15 20:55:51 +000017#include "llvm/Support/Regex.h"
Zachary Turner63055452017-06-15 22:24:24 +000018#include "llvm/Support/raw_ostream.h"
Zachary Turnerf5abda22015-03-01 06:49:49 +000019
20#include <list>
Zachary Turner2d11c202015-02-27 09:15:59 +000021
22namespace llvm {
Zachary Turnerec28fc32016-05-04 20:32:13 +000023namespace pdb {
Zachary Turner2d11c202015-02-27 09:15:59 +000024
Zachary Turner4dc4f012017-04-13 21:11:00 +000025class ClassLayout;
26
Zachary Turner2d11c202015-02-27 09:15:59 +000027class LinePrinter {
28 friend class WithColor;
29
30public:
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000031 LinePrinter(int Indent, bool UseColor, raw_ostream &Stream);
Zachary Turner2d11c202015-02-27 09:15:59 +000032
Zachary Turner63055452017-06-15 22:24:24 +000033 void Indent(uint32_t Amount = 0);
34 void Unindent(uint32_t Amount = 0);
Zachary Turner2d11c202015-02-27 09:15:59 +000035 void NewLine();
36
Zachary Turner63055452017-06-15 22:24:24 +000037 void printLine(const Twine &T);
38 void print(const Twine &T);
39 template <typename... Ts> void formatLine(const char *Fmt, Ts &&... Items) {
40 printLine(formatv(Fmt, std::forward<Ts>(Items)...));
41 }
42 template <typename... Ts> void format(const char *Fmt, Ts &&... Items) {
43 print(formatv(Fmt, std::forward<Ts>(Items)...));
44 }
45
46 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data,
47 uint32_t StartOffset);
Zachary Turner99402032017-06-22 20:58:11 +000048 void formatBinary(StringRef Label, ArrayRef<uint8_t> Data, uint64_t BaseAddr,
49 uint32_t StartOffset);
Zachary Turner63055452017-06-15 22:24:24 +000050
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000051 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000052 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000053 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000054
Zachary Turner4dc4f012017-04-13 21:11:00 +000055 bool IsClassExcluded(const ClassLayout &Class);
56 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000057 bool IsSymbolExcluded(llvm::StringRef SymbolName);
58 bool IsCompilandExcluded(llvm::StringRef CompilandName);
59
Zachary Turner2d11c202015-02-27 09:15:59 +000060private:
Zachary Turner7797c722015-03-02 04:39:56 +000061 template <typename Iter>
62 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
63 List.clear();
64 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000065 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000066 }
67
Zachary Turner2d11c202015-02-27 09:15:59 +000068 raw_ostream &OS;
69 int IndentSpaces;
70 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000071 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000072
Zachary Turner4dddcc62015-09-29 19:49:06 +000073 std::list<Regex> ExcludeCompilandFilters;
74 std::list<Regex> ExcludeTypeFilters;
75 std::list<Regex> ExcludeSymbolFilters;
76
77 std::list<Regex> IncludeCompilandFilters;
78 std::list<Regex> IncludeTypeFilters;
79 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000080};
81
Zachary Turner63055452017-06-15 22:24:24 +000082struct AutoIndent {
83 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
84 : L(L), Amount(Amount) {
85 L.Indent(Amount);
86 }
87 ~AutoIndent() { L.Unindent(Amount); }
88
89 LinePrinter &L;
90 uint32_t Amount = 0;
91};
92
Zachary Turner2d11c202015-02-27 09:15:59 +000093template <class T>
94inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
95 Printer.getStream() << Item;
96 return Printer.getStream();
97}
98
99enum class PDB_ColorItem {
100 None,
101 Address,
102 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +0000103 Comment,
104 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +0000105 Keyword,
106 Offset,
107 Identifier,
108 Path,
109 SectionHeader,
110 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +0000111 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +0000112};
113
114class WithColor {
115public:
116 WithColor(LinePrinter &P, PDB_ColorItem C);
117 ~WithColor();
118
119 raw_ostream &get() { return OS; }
120
121private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +0000122 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +0000123 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +0000124 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +0000125};
126}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000127}
Zachary Turner2d11c202015-02-27 09:15:59 +0000128
129#endif