Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ |
| 6 | #define V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ |
| 7 | |
| 8 | #include "src/compiler/common-operator.h" |
| 9 | #include "src/compiler/graph.h" |
| 10 | #include "src/compiler/typer.h" |
| 11 | #include "test/unittests/test-utils.h" |
| 12 | #include "testing/gmock/include/gmock/gmock.h" |
| 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
| 17 | // Forward declarations. |
| 18 | template <class T> |
| 19 | class Handle; |
| 20 | class HeapObject; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 21 | |
| 22 | namespace compiler { |
| 23 | |
| 24 | using ::testing::Matcher; |
| 25 | |
| 26 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 27 | class GraphTest : public TestWithContext, public TestWithIsolateAndZone { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 28 | public: |
| 29 | explicit GraphTest(int num_parameters = 1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 30 | ~GraphTest() override; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 31 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | Node* start() { return graph()->start(); } |
| 33 | Node* end() { return graph()->end(); } |
| 34 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 35 | Node* Parameter(int32_t index = 0); |
| 36 | Node* Float32Constant(volatile float value); |
| 37 | Node* Float64Constant(volatile double value); |
| 38 | Node* Int32Constant(int32_t value); |
| 39 | Node* Uint32Constant(uint32_t value) { |
| 40 | return Int32Constant(bit_cast<int32_t>(value)); |
| 41 | } |
| 42 | Node* Int64Constant(int64_t value); |
| 43 | Node* NumberConstant(volatile double value); |
| 44 | Node* HeapConstant(const Handle<HeapObject>& value); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 45 | Node* FalseConstant(); |
| 46 | Node* TrueConstant(); |
| 47 | Node* UndefinedConstant(); |
| 48 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 49 | Node* EmptyFrameState(); |
| 50 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 51 | Matcher<Node*> IsBooleanConstant(bool value) { |
| 52 | return value ? IsTrueConstant() : IsFalseConstant(); |
| 53 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 54 | Matcher<Node*> IsFalseConstant(); |
| 55 | Matcher<Node*> IsTrueConstant(); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | Matcher<Node*> IsUndefinedConstant(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 57 | |
| 58 | CommonOperatorBuilder* common() { return &common_; } |
| 59 | Graph* graph() { return &graph_; } |
| 60 | |
| 61 | private: |
| 62 | CommonOperatorBuilder common_; |
| 63 | Graph graph_; |
| 64 | }; |
| 65 | |
| 66 | |
| 67 | class TypedGraphTest : public GraphTest { |
| 68 | public: |
| 69 | explicit TypedGraphTest(int num_parameters = 1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 70 | ~TypedGraphTest() override; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 71 | |
| 72 | protected: |
| 73 | Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); } |
| 74 | Node* Parameter(Type* type, int32_t index = 0); |
| 75 | |
| 76 | Typer* typer() { return &typer_; } |
| 77 | |
| 78 | private: |
| 79 | Typer typer_; |
| 80 | }; |
| 81 | |
| 82 | } // namespace compiler |
| 83 | } // namespace internal |
| 84 | } // namespace v8 |
| 85 | |
| 86 | #endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ |