OLD | NEW |
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 #ifndef V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 5 #ifndef V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
6 #define V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 6 #define V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 #include "test/cctest/cctest.h" | 9 #include "test/cctest/cctest.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace compiler { | 21 namespace compiler { |
22 | 22 |
23 class GraphAndBuilders { | 23 class GraphAndBuilders { |
24 public: | 24 public: |
25 explicit GraphAndBuilders(Zone* zone) | 25 explicit GraphAndBuilders(Zone* zone) |
26 : main_graph_(new (zone) Graph(zone)), | 26 : main_graph_(new (zone) Graph(zone)), |
27 main_common_(zone), | 27 main_common_(zone), |
28 main_machine_(zone), | 28 main_machine_(zone), |
29 main_simplified_(zone) {} | 29 main_simplified_(zone) {} |
30 | 30 |
31 Graph* graph() const { return main_graph_; } | |
32 Zone* zone() const { return graph()->zone(); } | |
33 CommonOperatorBuilder* common() { return &main_common_; } | |
34 MachineOperatorBuilder* machine() { return &main_machine_; } | |
35 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } | |
36 | |
37 protected: | 31 protected: |
38 // Prefixed with main_ to avoid naming conflicts. | 32 // Prefixed with main_ to avoid naming conflicts. |
39 Graph* main_graph_; | 33 Graph* main_graph_; |
40 CommonOperatorBuilder main_common_; | 34 CommonOperatorBuilder main_common_; |
41 MachineOperatorBuilder main_machine_; | 35 MachineOperatorBuilder main_machine_; |
42 SimplifiedOperatorBuilder main_simplified_; | 36 SimplifiedOperatorBuilder main_simplified_; |
43 }; | 37 }; |
44 | 38 |
45 | 39 |
46 template <typename ReturnType> | 40 template <typename ReturnType> |
47 class GraphBuilderTester : public HandleAndZoneScope, | 41 class GraphBuilderTester : public HandleAndZoneScope, |
48 public GraphAndBuilders, | 42 private GraphAndBuilders, |
49 public CallHelper<ReturnType> { | 43 public CallHelper<ReturnType> { |
50 public: | 44 public: |
51 explicit GraphBuilderTester(MachineType p0 = kMachNone, | 45 explicit GraphBuilderTester(MachineType p0 = kMachNone, |
52 MachineType p1 = kMachNone, | 46 MachineType p1 = kMachNone, |
53 MachineType p2 = kMachNone, | 47 MachineType p2 = kMachNone, |
54 MachineType p3 = kMachNone, | 48 MachineType p3 = kMachNone, |
55 MachineType p4 = kMachNone) | 49 MachineType p4 = kMachNone) |
56 : GraphAndBuilders(main_zone()), | 50 : GraphAndBuilders(main_zone()), |
57 CallHelper<ReturnType>( | 51 CallHelper<ReturnType>( |
58 main_isolate(), | 52 main_isolate(), |
59 CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1, | 53 CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1, |
60 p2, p3, p4)), | 54 p2, p3, p4)), |
61 effect_(NULL), | 55 effect_(NULL), |
62 return_(NULL), | 56 return_(NULL), |
63 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { | 57 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { |
64 Begin(static_cast<int>(parameter_count())); | 58 Begin(static_cast<int>(parameter_count())); |
65 InitParameters(); | 59 InitParameters(); |
66 } | 60 } |
67 virtual ~GraphBuilderTester() {} | 61 virtual ~GraphBuilderTester() {} |
68 | 62 |
69 void GenerateCode() { Generate(); } | 63 void GenerateCode() { Generate(); } |
70 Node* Parameter(size_t index) { | 64 Node* Parameter(size_t index) { |
71 DCHECK(index < parameter_count()); | 65 DCHECK(index < parameter_count()); |
72 return parameters_[index]; | 66 return parameters_[index]; |
73 } | 67 } |
74 | 68 |
75 Isolate* isolate() { return main_isolate(); } | 69 Isolate* isolate() { return main_isolate(); } |
| 70 Graph* graph() const { return main_graph_; } |
| 71 Zone* zone() const { return graph()->zone(); } |
76 Factory* factory() { return isolate()->factory(); } | 72 Factory* factory() { return isolate()->factory(); } |
| 73 CommonOperatorBuilder* common() { return &main_common_; } |
| 74 MachineOperatorBuilder* machine() { return &main_machine_; } |
| 75 SimplifiedOperatorBuilder* simplified() { return &main_simplified_; } |
77 | 76 |
78 // Initialize graph and builder. | 77 // Initialize graph and builder. |
79 void Begin(int num_parameters) { | 78 void Begin(int num_parameters) { |
80 DCHECK(graph()->start() == NULL); | 79 DCHECK(graph()->start() == NULL); |
81 Node* start = graph()->NewNode(common()->Start(num_parameters + 3)); | 80 Node* start = graph()->NewNode(common()->Start(num_parameters + 3)); |
82 graph()->SetStart(start); | 81 graph()->SetStart(start); |
83 effect_ = start; | 82 effect_ = start; |
84 } | 83 } |
85 | 84 |
86 void Return(Node* value) { | 85 void Return(Node* value) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 Node* return_; | 297 Node* return_; |
299 Node** parameters_; | 298 Node** parameters_; |
300 MaybeHandle<Code> code_; | 299 MaybeHandle<Code> code_; |
301 }; | 300 }; |
302 | 301 |
303 } // namespace compiler | 302 } // namespace compiler |
304 } // namespace internal | 303 } // namespace internal |
305 } // namespace v8 | 304 } // namespace v8 |
306 | 305 |
307 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 306 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
OLD | NEW |