Line data Source code
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/compiler-source-position-table.h"
10 : #include "src/compiler/graph.h"
11 : #include "src/compiler/node-origin-table.h"
12 : #include "src/compiler/typer.h"
13 : #include "src/handles.h"
14 : #include "test/unittests/test-utils.h"
15 : #include "testing/gmock/include/gmock/gmock.h"
16 :
17 : namespace v8 {
18 : namespace internal {
19 :
20 : // Forward declarations.
21 : class HeapObject;
22 :
23 : namespace compiler {
24 :
25 : using ::testing::Matcher;
26 :
27 1761 : class GraphTest : public TestWithNativeContextAndZone {
28 : public:
29 : explicit GraphTest(int num_parameters = 1);
30 : ~GraphTest() override;
31 :
32 : Node* start() { return graph()->start(); }
33 : Node* end() { return graph()->end(); }
34 :
35 : Node* Parameter(int32_t index = 0);
36 : Node* Parameter(Type type, int32_t index = 0);
37 : Node* Float32Constant(volatile float value);
38 : Node* Float64Constant(volatile double value);
39 : Node* Int32Constant(int32_t value);
40 : Node* Uint32Constant(uint32_t value) {
41 14369 : 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 100 : Matcher<Node*> IsBooleanConstant(bool value) {
53 100 : return value ? IsTrueConstant() : IsFalseConstant();
54 : }
55 : Matcher<Node*> IsFalseConstant();
56 : Matcher<Node*> IsTrueConstant();
57 : Matcher<Node*> IsNullConstant();
58 : Matcher<Node*> IsUndefinedConstant();
59 :
60 721706 : CommonOperatorBuilder* common() { return &common_; }
61 828269 : Graph* graph() { return &graph_; }
62 23 : SourcePositionTable* source_positions() { return &source_positions_; }
63 23 : NodeOriginTable* node_origins() { return &node_origins_; }
64 11434 : JSHeapBroker* broker() { return &broker_; }
65 :
66 : private:
67 : CanonicalHandleScope canonical_;
68 : CommonOperatorBuilder common_;
69 : Graph graph_;
70 : JSHeapBroker broker_;
71 : SourcePositionTable source_positions_;
72 : NodeOriginTable node_origins_;
73 : };
74 :
75 :
76 238 : class TypedGraphTest : public GraphTest {
77 : public:
78 : explicit TypedGraphTest(int num_parameters = 1);
79 : ~TypedGraphTest() override;
80 :
81 : protected:
82 : Typer* typer() { return &typer_; }
83 :
84 : private:
85 : Typer typer_;
86 : };
87 :
88 : } // namespace compiler
89 : } // namespace internal
90 : } // namespace v8
91 :
92 : #endif // V8_UNITTESTS_COMPILER_GRAPH_UNITTEST_H_
|