blob: f4fd22bcb6f450523b69da8bf1db8625f285dd31 [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 Turnerb560fdf2017-06-15 19:34:41 +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 Turnerb560fdf2017-06-15 19:34:41 +000016#include "llvm/Support/FormatVariadic.h"
Zachary Turnerf5abda22015-03-01 06:49:49 +000017#include "llvm/Support/Regex.h"
Zachary Turnerb560fdf2017-06-15 19:34:41 +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 Turnerb560fdf2017-06-15 19:34:41 +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 Turnerb560fdf2017-06-15 19:34:41 +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);
48
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000049 bool hasColor() const { return UseColor; }
Zachary Turner2d11c202015-02-27 09:15:59 +000050 raw_ostream &getStream() { return OS; }
Zachary Turner7797c722015-03-02 04:39:56 +000051 int getIndentLevel() const { return CurrentIndent; }
Zachary Turner2d11c202015-02-27 09:15:59 +000052
Zachary Turner4dc4f012017-04-13 21:11:00 +000053 bool IsClassExcluded(const ClassLayout &Class);
54 bool IsTypeExcluded(llvm::StringRef TypeName, uint32_t Size);
Zachary Turnerf5abda22015-03-01 06:49:49 +000055 bool IsSymbolExcluded(llvm::StringRef SymbolName);
56 bool IsCompilandExcluded(llvm::StringRef CompilandName);
57
Zachary Turner2d11c202015-02-27 09:15:59 +000058private:
Zachary Turner7797c722015-03-02 04:39:56 +000059 template <typename Iter>
60 void SetFilters(std::list<Regex> &List, Iter Begin, Iter End) {
61 List.clear();
62 for (; Begin != End; ++Begin)
Benjamin Kramerf5e2fc42015-05-29 19:43:39 +000063 List.emplace_back(StringRef(*Begin));
Zachary Turner7797c722015-03-02 04:39:56 +000064 }
65
Zachary Turner2d11c202015-02-27 09:15:59 +000066 raw_ostream &OS;
67 int IndentSpaces;
68 int CurrentIndent;
Adrian McCarthy1aa207d2017-03-23 15:28:15 +000069 bool UseColor;
Zachary Turnerf5abda22015-03-01 06:49:49 +000070
Zachary Turner4dddcc62015-09-29 19:49:06 +000071 std::list<Regex> ExcludeCompilandFilters;
72 std::list<Regex> ExcludeTypeFilters;
73 std::list<Regex> ExcludeSymbolFilters;
74
75 std::list<Regex> IncludeCompilandFilters;
76 std::list<Regex> IncludeTypeFilters;
77 std::list<Regex> IncludeSymbolFilters;
Zachary Turner2d11c202015-02-27 09:15:59 +000078};
79
Zachary Turnerb560fdf2017-06-15 19:34:41 +000080struct AutoIndent {
81 explicit AutoIndent(LinePrinter &L, uint32_t Amount = 0)
82 : L(L), Amount(Amount) {
83 L.Indent(Amount);
84 }
85 ~AutoIndent() { L.Unindent(Amount); }
86
87 LinePrinter &L;
88 uint32_t Amount = 0;
89};
90
Zachary Turner2d11c202015-02-27 09:15:59 +000091template <class T>
92inline raw_ostream &operator<<(LinePrinter &Printer, const T &Item) {
93 Printer.getStream() << Item;
94 return Printer.getStream();
95}
96
97enum class PDB_ColorItem {
98 None,
99 Address,
100 Type,
Zachary Turner0c990bbe2017-04-10 19:33:29 +0000101 Comment,
102 Padding,
Zachary Turner2d11c202015-02-27 09:15:59 +0000103 Keyword,
104 Offset,
105 Identifier,
106 Path,
107 SectionHeader,
108 LiteralValue,
Zachary Turner7797c722015-03-02 04:39:56 +0000109 Register,
Zachary Turner2d11c202015-02-27 09:15:59 +0000110};
111
112class WithColor {
113public:
114 WithColor(LinePrinter &P, PDB_ColorItem C);
115 ~WithColor();
116
117 raw_ostream &get() { return OS; }
118
119private:
Rui Ueyamafa05aac2015-11-03 01:04:44 +0000120 void applyColor(PDB_ColorItem C);
Zachary Turner2d11c202015-02-27 09:15:59 +0000121 raw_ostream &OS;
Adrian McCarthy5fcfc2c2017-03-29 17:11:27 +0000122 bool UseColor;
Zachary Turner2d11c202015-02-27 09:15:59 +0000123};
124}
Zachary Turnerec28fc32016-05-04 20:32:13 +0000125}
Zachary Turner2d11c202015-02-27 09:15:59 +0000126
127#endif