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; 21 22 namespace compiler { 23 24 using ::testing::Matcher; 25 26 27 class GraphTest : public TestWithContext, public TestWithIsolateAndZone { 28 public: 29 explicit GraphTest(int num_parameters = 1); 30 ~GraphTest() override; 31 32 protected: start()33 Node* start() { return graph()->start(); } end()34 Node* end() { return graph()->end(); } 35 36 Node* Parameter(int32_t index = 0); 37 Node* Float32Constant(volatile float value); 38 Node* Float64Constant(volatile double value); 39 Node* Int32Constant(int32_t value); Uint32Constant(uint32_t value)40 Node* Uint32Constant(uint32_t value) { 41 return Int32Constant(bit_cast<int32_t>(value)); 42 } 43 Node* Int64Constant(int64_t value); 44 Node* NumberConstant(volatile double value); 45 Node* HeapConstant(const Handle<HeapObject>& value); 46 Node* FalseConstant(); 47 Node* TrueConstant(); 48 Node* UndefinedConstant(); 49 50 Node* EmptyFrameState(); 51 52 Matcher<Node*> IsFalseConstant(); 53 Matcher<Node*> IsTrueConstant(); 54 Matcher<Node*> IsUndefinedConstant(); 55 common()56 CommonOperatorBuilder* common() { return &common_; } graph()57 Graph* graph() { return &graph_; } 58 59 private: 60 CommonOperatorBuilder common_; 61 Graph graph_; 62 }; 63 64 65 class TypedGraphTest : public GraphTest { 66 public: 67 explicit TypedGraphTest(int num_parameters = 1); 68 ~TypedGraphTest() override; 69 70 protected: 71 Node* Parameter(int32_t index = 0) { return GraphTest::Parameter(index); } 72 Node* Parameter(Type* type, int32_t index = 0); 73 typer()74 Typer* typer() { return &typer_; } 75 76 private: 77 Typer typer_; 78 }; 79 80 } // namespace compiler 81 } // namespace internal 82 } // namespace v8 83 84 #endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_ 85