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 21 matching lines...) Expand all Loading... |
32 protected: | 32 protected: |
33 // Prefixed with main_ to avoid naming conflicts. | 33 // Prefixed with main_ to avoid naming conflicts. |
34 Graph* main_graph_; | 34 Graph* main_graph_; |
35 CommonOperatorBuilder main_common_; | 35 CommonOperatorBuilder main_common_; |
36 MachineOperatorBuilder main_machine_; | 36 MachineOperatorBuilder main_machine_; |
37 SimplifiedOperatorBuilder main_simplified_; | 37 SimplifiedOperatorBuilder main_simplified_; |
38 }; | 38 }; |
39 | 39 |
40 | 40 |
41 template <typename ReturnType> | 41 template <typename ReturnType> |
42 class GraphBuilderTester | 42 class GraphBuilderTester : public HandleAndZoneScope, |
43 : public HandleAndZoneScope, | 43 private GraphAndBuilders, |
44 private GraphAndBuilders, | 44 public CallHelper<ReturnType>, |
45 public CallHelper, | 45 public SimplifiedGraphBuilder { |
46 public SimplifiedGraphBuilder, | |
47 public CallHelper2<ReturnType, GraphBuilderTester<ReturnType> > { | |
48 public: | 46 public: |
49 explicit GraphBuilderTester(MachineType p0 = kMachNone, | 47 explicit GraphBuilderTester(MachineType p0 = kMachNone, |
50 MachineType p1 = kMachNone, | 48 MachineType p1 = kMachNone, |
51 MachineType p2 = kMachNone, | 49 MachineType p2 = kMachNone, |
52 MachineType p3 = kMachNone, | 50 MachineType p3 = kMachNone, |
53 MachineType p4 = kMachNone) | 51 MachineType p4 = kMachNone) |
54 : GraphAndBuilders(main_zone()), | 52 : GraphAndBuilders(main_zone()), |
55 CallHelper( | 53 CallHelper<ReturnType>( |
56 main_isolate(), | 54 main_isolate(), |
57 MakeMachineSignature( | 55 MakeMachineSignature( |
58 main_zone(), ReturnValueTraits<ReturnType>::Representation(), | 56 main_zone(), ReturnValueTraits<ReturnType>::Representation(), |
59 p0, p1, p2, p3, p4)), | 57 p0, p1, p2, p3, p4)), |
60 SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_, | 58 SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_, |
61 &main_machine_, &main_simplified_), | 59 &main_machine_, &main_simplified_), |
62 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { | 60 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { |
63 Begin(static_cast<int>(parameter_count())); | 61 Begin(static_cast<int>(parameter_count())); |
64 InitParameters(); | 62 InitParameters(); |
65 } | 63 } |
66 virtual ~GraphBuilderTester() {} | 64 virtual ~GraphBuilderTester() {} |
67 | 65 |
68 void GenerateCode() { Generate(); } | 66 void GenerateCode() { Generate(); } |
69 Node* Parameter(size_t index) { | 67 Node* Parameter(size_t index) { |
70 DCHECK(index < parameter_count()); | 68 DCHECK(index < parameter_count()); |
71 return parameters_[index]; | 69 return parameters_[index]; |
72 } | 70 } |
73 | 71 |
74 Factory* factory() const { return isolate()->factory(); } | 72 Factory* factory() const { return isolate()->factory(); } |
75 | 73 |
76 protected: | 74 protected: |
77 virtual byte* Generate() { | 75 virtual byte* Generate() { |
78 if (!Pipeline::SupportedBackend()) return NULL; | 76 if (!Pipeline::SupportedBackend()) return NULL; |
79 if (code_.is_null()) { | 77 if (code_.is_null()) { |
80 Zone* zone = graph()->zone(); | 78 Zone* zone = graph()->zone(); |
81 CallDescriptor* desc = | 79 CallDescriptor* desc = |
82 Linkage::GetSimplifiedCDescriptor(zone, machine_sig_); | 80 Linkage::GetSimplifiedCDescriptor(zone, this->machine_sig_); |
83 code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph()); | 81 code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph()); |
84 } | 82 } |
85 return code_.ToHandleChecked()->entry(); | 83 return code_.ToHandleChecked()->entry(); |
86 } | 84 } |
87 | 85 |
88 void InitParameters() { | 86 void InitParameters() { |
89 int param_count = static_cast<int>(parameter_count()); | 87 int param_count = static_cast<int>(parameter_count()); |
90 for (int i = 0; i < param_count; ++i) { | 88 for (int i = 0; i < param_count; ++i) { |
91 parameters_[i] = this->NewNode(common()->Parameter(i), graph()->start()); | 89 parameters_[i] = this->NewNode(common()->Parameter(i), graph()->start()); |
92 } | 90 } |
93 } | 91 } |
94 | 92 |
95 size_t parameter_count() const { return machine_sig_->parameter_count(); } | 93 size_t parameter_count() const { |
| 94 return this->machine_sig_->parameter_count(); |
| 95 } |
96 | 96 |
97 private: | 97 private: |
98 Node** parameters_; | 98 Node** parameters_; |
99 MaybeHandle<Code> code_; | 99 MaybeHandle<Code> code_; |
| 100 |
| 101 // TODO(titzer): factor me elsewhere. |
| 102 static MachineSignature* MakeMachineSignature( |
| 103 Zone* zone, MachineType return_type, MachineType p0 = kMachNone, |
| 104 MachineType p1 = kMachNone, MachineType p2 = kMachNone, |
| 105 MachineType p3 = kMachNone, MachineType p4 = kMachNone) { |
| 106 // Count the number of parameters. |
| 107 size_t param_count = 5; |
| 108 MachineType types[] = {p0, p1, p2, p3, p4}; |
| 109 while (param_count > 0 && types[param_count - 1] == kMachNone) |
| 110 param_count--; |
| 111 size_t return_count = return_type == kMachNone ? 0 : 1; |
| 112 |
| 113 // Build the machine signature. |
| 114 MachineSignature::Builder builder(zone, return_count, param_count); |
| 115 if (return_count > 0) builder.AddReturn(return_type); |
| 116 for (size_t i = 0; i < param_count; i++) { |
| 117 builder.AddParam(types[i]); |
| 118 } |
| 119 return builder.Build(); |
| 120 } |
100 }; | 121 }; |
101 | 122 |
102 } // namespace compiler | 123 } // namespace compiler |
103 } // namespace internal | 124 } // namespace internal |
104 } // namespace v8 | 125 } // namespace v8 |
105 | 126 |
106 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 127 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
OLD | NEW |