annotate tools/llvm-pdbutil/DiffPrinter.h @ 133:c60214abe0e8

fix intrin.h
author mir3636
date Fri, 16 Feb 2018 19:10:49 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- DiffPrinter.h ------------------------------------------ *- C++ --*-===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #ifndef LLVM_TOOLS_LLVMPDBDUMP_DIFFPRINTER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 #define LLVM_TOOLS_LLVMPDBDUMP_DIFFPRINTER_H
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/ADT/ArrayRef.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/ADT/StringMap.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/ADT/StringRef.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/DebugInfo/PDB/Native/RawConstants.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17 #include "llvm/Support/FormatVariadic.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 #include "llvm/Support/raw_ostream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 #include <list>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 #include <unordered_set>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 namespace std {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 template <> struct hash<llvm::pdb::PdbRaw_FeatureSig> {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 typedef llvm::pdb::PdbRaw_FeatureSig argument_type;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 typedef std::size_t result_type;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 result_type operator()(argument_type Item) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 return std::hash<uint32_t>{}(uint32_t(Item));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 } // namespace std
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 namespace llvm {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 namespace pdb {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 class PDBFile;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 enum class DiffResult { UNSPECIFIED, IDENTICAL, EQUIVALENT, DIFFERENT };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 struct IdenticalDiffProvider {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 template <typename T, typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 DiffResult compare(const T &Left, const U &Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 return (Left == Right) ? DiffResult::IDENTICAL : DiffResult::DIFFERENT;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 template <typename T> std::string format(const T &Item, bool Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 return formatv("{0}", Item).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 struct EquivalentDiffProvider {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 template <typename T, typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 DiffResult compare(const T &Left, const U &Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 return (Left == Right) ? DiffResult::IDENTICAL : DiffResult::EQUIVALENT;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 template <typename T> std::string format(const T &Item, bool Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 return formatv("{0}", Item).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 class DiffPrinter {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 public:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 DiffPrinter(uint32_t Indent, StringRef Header, uint32_t PropertyWidth,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 uint32_t FieldWidth, bool Result, bool Values,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 raw_ostream &Stream);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 ~DiffPrinter();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69 template <typename T, typename U> struct Identical {};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 template <typename Provider = IdenticalDiffProvider, typename T, typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 void print(StringRef Property, const T &Left, const U &Right,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 Provider P = Provider()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 std::string L = P.format(Left, false);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 std::string R = P.format(Right, true);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 DiffResult Result = P.compare(Left, Right);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 printExplicit(Property, Result, L, R);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 void printExplicit(StringRef Property, DiffResult C, StringRef Left,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 StringRef Right);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 template <typename T, typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 void printExplicit(StringRef Property, DiffResult C, const T &Left,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 const U &Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 std::string L = formatv("{0}", Left).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 std::string R = formatv("{0}", Right).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 printExplicit(Property, C, StringRef(L), StringRef(R));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 template <typename T, typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 void diffUnorderedArray(StringRef Property, ArrayRef<T> Left,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 ArrayRef<U> Right) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95 std::unordered_set<T> LS(Left.begin(), Left.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 std::unordered_set<U> RS(Right.begin(), Right.end());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97 std::string Count1 = formatv("{0} element(s)", Left.size());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 std::string Count2 = formatv("{0} element(s)", Right.size());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 print(std::string(Property) + "s (set)", Count1, Count2);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 for (const auto &L : LS) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101 auto Iter = RS.find(L);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 std::string Text = formatv("{0}", L).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 if (Iter == RS.end()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 print(Property, Text, "(not present)");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107 print(Property, Text, Text);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 RS.erase(Iter);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110 for (const auto &R : RS) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 auto Iter = LS.find(R);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 std::string Text = formatv("{0}", R).str();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 if (Iter == LS.end()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 print(Property, "(not present)", Text);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117 print(Property, Text, Text);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 template <typename ValueProvider = IdenticalDiffProvider, typename T,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 typename U>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 void diffUnorderedMap(StringRef Property, const StringMap<T> &Left,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 const StringMap<U> &Right,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125 ValueProvider P = ValueProvider()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 StringMap<U> RightCopy(Right);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 std::string Count1 = formatv("{0} element(s)", Left.size());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 std::string Count2 = formatv("{0} element(s)", Right.size());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130 print(std::string(Property) + "s (map)", Count1, Count2);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 for (const auto &L : Left) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 auto Iter = RightCopy.find(L.getKey());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 if (Iter == RightCopy.end()) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 printExplicit(L.getKey(), DiffResult::DIFFERENT, L.getValue(),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 "(not present)");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 continue;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 print(L.getKey(), L.getValue(), Iter->getValue(), P);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 RightCopy.erase(Iter);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 for (const auto &R : RightCopy) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145 printExplicit(R.getKey(), DiffResult::DIFFERENT, "(not present)",
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 R.getValue());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150 void printFullRow(StringRef Text);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 private:
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 uint32_t tableWidth() const;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 void printHeaderRow();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156 void printSeparatorRow();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 void newLine(char InitialChar = '|');
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 void printValue(StringRef Value, DiffResult C, AlignStyle Style,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 uint32_t Width, bool Force);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160 void printResult(DiffResult Result);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 bool PrintResult;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 bool PrintValues;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 uint32_t Indent;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 uint32_t PropertyWidth;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 uint32_t FieldWidth;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 raw_ostream &OS;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168 };
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 } // namespace pdb
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 } // namespace llvm
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 #endif