Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: test/compiler-unittests/graph-unittest.cc

Issue 480863002: Refactor ChangeLowering class to avoid template specialization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/compiler-unittests/node-matchers.h" 5 #include "test/compiler-unittests/graph-unittest.h"
6 6
7 #include <ostream> // NOLINT(readability/streams) 7 #include <ostream> // NOLINT(readability/streams)
8 8
9 #include "src/compiler/node-properties-inl.h" 9 #include "src/compiler/node-properties-inl.h"
10 10
11 using testing::MakeMatcher; 11 using testing::MakeMatcher;
12 using testing::MatcherInterface; 12 using testing::MatcherInterface;
13 using testing::MatchResultListener; 13 using testing::MatchResultListener;
14 using testing::StringMatchResultListener; 14 using testing::StringMatchResultListener;
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 18
19 // TODO(bmeurer): Find a new home for these functions. 19 // TODO(bmeurer): Find a new home for these functions.
20 template <typename T> 20 template <typename T>
21 inline std::ostream& operator<<(std::ostream& os, 21 inline std::ostream& operator<<(std::ostream& os,
22 const PrintableUnique<T>& value) { 22 const PrintableUnique<T>& value) {
23 return os << value.string(); 23 return os << value.string();
24 } 24 }
25 25
26 namespace compiler { 26 namespace compiler {
27 27
28 GraphTest::GraphTest(int num_parameters) : graph_(zone()) {
29 graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
30 }
31
32
33 GraphTest::~GraphTest() {}
34
35
28 namespace { 36 namespace {
29 37
30 template <typename T> 38 template <typename T>
31 bool PrintMatchAndExplain(const T& value, const char* value_name, 39 bool PrintMatchAndExplain(const T& value, const char* value_name,
32 const Matcher<T>& value_matcher, 40 const Matcher<T>& value_matcher,
33 MatchResultListener* listener) { 41 MatchResultListener* listener) {
34 StringMatchResultListener value_listener; 42 StringMatchResultListener value_listener;
35 if (!value_matcher.MatchAndExplain(value, &value_listener)) { 43 if (!value_matcher.MatchAndExplain(value, &value_listener)) {
36 *listener << "whose " << value_name << " " << value << " doesn't match"; 44 *listener << "whose " << value_name << " " << value << " doesn't match";
37 if (value_listener.str() != "") { 45 if (value_listener.str() != "") {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 PrintMatchAndExplain(NodeProperties::GetControlInput(node), 102 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
95 "control", control_matcher_, listener)); 103 "control", control_matcher_, listener));
96 } 104 }
97 105
98 private: 106 private:
99 const Matcher<Node*> value_matcher_; 107 const Matcher<Node*> value_matcher_;
100 const Matcher<Node*> control_matcher_; 108 const Matcher<Node*> control_matcher_;
101 }; 109 };
102 110
103 111
112 class IsMergeMatcher V8_FINAL : public NodeMatcher {
113 public:
114 IsMergeMatcher(const Matcher<Node*>& control0_matcher,
115 const Matcher<Node*>& control1_matcher)
116 : NodeMatcher(IrOpcode::kMerge),
117 control0_matcher_(control0_matcher),
118 control1_matcher_(control1_matcher) {}
119
120 virtual void DescribeTo(std::ostream* os) const V8_OVERRIDE {
121 NodeMatcher::DescribeTo(os);
122 *os << " whose control0 (";
123 control0_matcher_.DescribeTo(os);
124 *os << ") and control1 (";
125 control1_matcher_.DescribeTo(os);
126 *os << ")";
127 }
128
129 virtual bool MatchAndExplain(Node* node, MatchResultListener* listener) const
130 V8_OVERRIDE {
131 return (NodeMatcher::MatchAndExplain(node, listener) &&
132 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
133 "control0", control0_matcher_, listener) &&
134 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 1),
135 "control1", control1_matcher_, listener));
136 }
137
138 private:
139 const Matcher<Node*> control0_matcher_;
140 const Matcher<Node*> control1_matcher_;
141 };
142
143
144 class IsIfTrueMatcher V8_FINAL : public NodeMatcher {
145 public:
146 explicit IsIfTrueMatcher(const Matcher<Node*>& control_matcher)
147 : NodeMatcher(IrOpcode::kIfTrue), control_matcher_(control_matcher) {}
148
149 virtual void DescribeTo(std::ostream* os) const V8_OVERRIDE {
150 NodeMatcher::DescribeTo(os);
151 *os << " whose control (";
152 control_matcher_.DescribeTo(os);
153 *os << ")";
154 }
155
156 virtual bool MatchAndExplain(Node* node, MatchResultListener* listener) const
157 V8_OVERRIDE {
158 return (NodeMatcher::MatchAndExplain(node, listener) &&
159 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
160 "control", control_matcher_, listener));
161 }
162
163 private:
164 const Matcher<Node*> control_matcher_;
165 };
166
167
168 class IsIfFalseMatcher V8_FINAL : public NodeMatcher {
169 public:
170 explicit IsIfFalseMatcher(const Matcher<Node*>& control_matcher)
171 : NodeMatcher(IrOpcode::kIfFalse), control_matcher_(control_matcher) {}
172
173 virtual void DescribeTo(std::ostream* os) const V8_OVERRIDE {
174 NodeMatcher::DescribeTo(os);
175 *os << " whose control (";
176 control_matcher_.DescribeTo(os);
177 *os << ")";
178 }
179
180 virtual bool MatchAndExplain(Node* node, MatchResultListener* listener) const
181 V8_OVERRIDE {
182 return (NodeMatcher::MatchAndExplain(node, listener) &&
183 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
184 "control", control_matcher_, listener));
185 }
186
187 private:
188 const Matcher<Node*> control_matcher_;
189 };
190
191
104 template <typename T> 192 template <typename T>
105 class IsConstantMatcher V8_FINAL : public NodeMatcher { 193 class IsConstantMatcher V8_FINAL : public NodeMatcher {
106 public: 194 public:
107 IsConstantMatcher(IrOpcode::Value opcode, const Matcher<T>& value_matcher) 195 IsConstantMatcher(IrOpcode::Value opcode, const Matcher<T>& value_matcher)
108 : NodeMatcher(opcode), value_matcher_(value_matcher) {} 196 : NodeMatcher(opcode), value_matcher_(value_matcher) {}
109 197
110 virtual void DescribeTo(std::ostream* os) const V8_OVERRIDE { 198 virtual void DescribeTo(std::ostream* os) const V8_OVERRIDE {
111 NodeMatcher::DescribeTo(os); 199 NodeMatcher::DescribeTo(os);
112 *os << " whose value ("; 200 *os << " whose value (";
113 value_matcher_.DescribeTo(os); 201 value_matcher_.DescribeTo(os);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 virtual bool MatchAndExplain(Node* node, MatchResultListener* listener) const 447 virtual bool MatchAndExplain(Node* node, MatchResultListener* listener) const
360 V8_OVERRIDE { 448 V8_OVERRIDE {
361 return (NodeMatcher::MatchAndExplain(node, listener) && 449 return (NodeMatcher::MatchAndExplain(node, listener) &&
362 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), 450 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
363 "input", input_matcher_, listener)); 451 "input", input_matcher_, listener));
364 } 452 }
365 453
366 private: 454 private:
367 const Matcher<Node*> input_matcher_; 455 const Matcher<Node*> input_matcher_;
368 }; 456 };
369
370 } 457 }
371 458
372 459
373 Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher, 460 Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
374 const Matcher<Node*>& control_matcher) { 461 const Matcher<Node*>& control_matcher) {
375 return MakeMatcher(new IsBranchMatcher(value_matcher, control_matcher)); 462 return MakeMatcher(new IsBranchMatcher(value_matcher, control_matcher));
376 } 463 }
377 464
378 465
466 Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
467 const Matcher<Node*>& control1_matcher) {
468 return MakeMatcher(new IsMergeMatcher(control0_matcher, control1_matcher));
469 }
470
471
472 Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher) {
473 return MakeMatcher(new IsIfTrueMatcher(control_matcher));
474 }
475
476
477 Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher) {
478 return MakeMatcher(new IsIfFalseMatcher(control_matcher));
479 }
480
481
379 Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher) { 482 Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher) {
380 return MakeMatcher( 483 return MakeMatcher(
381 new IsConstantMatcher<int32_t>(IrOpcode::kInt32Constant, value_matcher)); 484 new IsConstantMatcher<int32_t>(IrOpcode::kInt32Constant, value_matcher));
382 } 485 }
383 486
384 487
385 Matcher<Node*> IsHeapConstant( 488 Matcher<Node*> IsHeapConstant(
386 const Matcher<PrintableUnique<HeapObject> >& value_matcher) { 489 const Matcher<PrintableUnique<HeapObject> >& value_matcher) {
387 return MakeMatcher(new IsConstantMatcher<PrintableUnique<HeapObject> >( 490 return MakeMatcher(new IsConstantMatcher<PrintableUnique<HeapObject> >(
388 IrOpcode::kHeapConstant, value_matcher)); 491 IrOpcode::kHeapConstant, value_matcher));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 Matcher<Node*> Is##Name(const Matcher<Node*>& input_matcher) { \ 550 Matcher<Node*> Is##Name(const Matcher<Node*>& input_matcher) { \
448 return MakeMatcher(new IsUnopMatcher(IrOpcode::k##Name, input_matcher)); \ 551 return MakeMatcher(new IsUnopMatcher(IrOpcode::k##Name, input_matcher)); \
449 } 552 }
450 IS_UNOP_MATCHER(ConvertInt64ToInt32) 553 IS_UNOP_MATCHER(ConvertInt64ToInt32)
451 IS_UNOP_MATCHER(ChangeInt32ToFloat64) 554 IS_UNOP_MATCHER(ChangeInt32ToFloat64)
452 #undef IS_UNOP_MATCHER 555 #undef IS_UNOP_MATCHER
453 556
454 } // namespace compiler 557 } // namespace compiler
455 } // namespace internal 558 } // namespace internal
456 } // namespace v8 559 } // namespace v8
OLDNEW
« no previous file with comments | « test/compiler-unittests/graph-unittest.h ('k') | test/compiler-unittests/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698