| 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 |
| 11 #include "src/compiler/common-operator.h" | 11 #include "src/compiler/common-operator.h" |
| 12 #include "src/compiler/graph-builder.h" | 12 #include "src/compiler/graph-builder.h" |
| 13 #include "src/compiler/linkage.h" |
| 13 #include "src/compiler/machine-operator.h" | 14 #include "src/compiler/machine-operator.h" |
| 15 #include "src/compiler/pipeline.h" |
| 14 #include "src/compiler/simplified-operator.h" | 16 #include "src/compiler/simplified-operator.h" |
| 15 #include "test/cctest/compiler/call-tester.h" | 17 #include "test/cctest/compiler/call-tester.h" |
| 16 #include "test/cctest/compiler/simplified-graph-builder.h" | 18 #include "test/cctest/compiler/simplified-graph-builder.h" |
| 17 | 19 |
| 18 namespace v8 { | 20 namespace v8 { |
| 19 namespace internal { | 21 namespace internal { |
| 20 namespace compiler { | 22 namespace compiler { |
| 21 | 23 |
| 22 class MachineCallHelper : public CallHelper { | |
| 23 public: | |
| 24 MachineCallHelper(Isolate* isolate, MachineSignature* machine_sig); | |
| 25 | |
| 26 Node* Parameter(size_t index); | |
| 27 | |
| 28 void GenerateCode() { Generate(); } | |
| 29 | |
| 30 protected: | |
| 31 virtual byte* Generate(); | |
| 32 void InitParameters(GraphBuilder* builder, CommonOperatorBuilder* common); | |
| 33 | |
| 34 protected: | |
| 35 size_t parameter_count() const { return machine_sig_->parameter_count(); } | |
| 36 | |
| 37 private: | |
| 38 Node** parameters_; | |
| 39 // TODO(dcarney): shouldn't need graph stored. | |
| 40 Isolate* isolate_; | |
| 41 Graph* graph_; | |
| 42 MaybeHandle<Code> code_; | |
| 43 }; | |
| 44 | |
| 45 | |
| 46 class GraphAndBuilders { | 24 class GraphAndBuilders { |
| 47 public: | 25 public: |
| 48 explicit GraphAndBuilders(Zone* zone) | 26 explicit GraphAndBuilders(Zone* zone) |
| 49 : main_graph_(new (zone) Graph(zone)), | 27 : main_graph_(new (zone) Graph(zone)), |
| 50 main_common_(zone), | 28 main_common_(zone), |
| 51 main_machine_(zone), | 29 main_machine_(zone), |
| 52 main_simplified_(zone) {} | 30 main_simplified_(zone) {} |
| 53 | 31 |
| 54 protected: | 32 protected: |
| 55 // Prefixed with main_ to avoid naiming conflicts. | 33 // Prefixed with main_ to avoid naming conflicts. |
| 56 Graph* main_graph_; | 34 Graph* main_graph_; |
| 57 CommonOperatorBuilder main_common_; | 35 CommonOperatorBuilder main_common_; |
| 58 MachineOperatorBuilder main_machine_; | 36 MachineOperatorBuilder main_machine_; |
| 59 SimplifiedOperatorBuilder main_simplified_; | 37 SimplifiedOperatorBuilder main_simplified_; |
| 60 }; | 38 }; |
| 61 | 39 |
| 62 | 40 |
| 63 template <typename ReturnType> | 41 template <typename ReturnType> |
| 64 class GraphBuilderTester | 42 class GraphBuilderTester |
| 65 : public HandleAndZoneScope, | 43 : public HandleAndZoneScope, |
| 66 private GraphAndBuilders, | 44 private GraphAndBuilders, |
| 67 public MachineCallHelper, | 45 public CallHelper, |
| 68 public SimplifiedGraphBuilder, | 46 public SimplifiedGraphBuilder, |
| 69 public CallHelper2<ReturnType, GraphBuilderTester<ReturnType> > { | 47 public CallHelper2<ReturnType, GraphBuilderTester<ReturnType> > { |
| 70 public: | 48 public: |
| 71 explicit GraphBuilderTester(MachineType p0 = kMachNone, | 49 explicit GraphBuilderTester(MachineType p0 = kMachNone, |
| 72 MachineType p1 = kMachNone, | 50 MachineType p1 = kMachNone, |
| 73 MachineType p2 = kMachNone, | 51 MachineType p2 = kMachNone, |
| 74 MachineType p3 = kMachNone, | 52 MachineType p3 = kMachNone, |
| 75 MachineType p4 = kMachNone) | 53 MachineType p4 = kMachNone) |
| 76 : GraphAndBuilders(main_zone()), | 54 : GraphAndBuilders(main_zone()), |
| 77 MachineCallHelper( | 55 CallHelper( |
| 78 main_isolate(), | 56 main_isolate(), |
| 79 MakeMachineSignature( | 57 MakeMachineSignature( |
| 80 main_zone(), ReturnValueTraits<ReturnType>::Representation(), | 58 main_zone(), ReturnValueTraits<ReturnType>::Representation(), |
| 81 p0, p1, p2, p3, p4)), | 59 p0, p1, p2, p3, p4)), |
| 82 SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_, | 60 SimplifiedGraphBuilder(main_isolate(), main_graph_, &main_common_, |
| 83 &main_machine_, &main_simplified_) { | 61 &main_machine_, &main_simplified_), |
| 62 parameters_(main_zone()->template NewArray<Node*>(parameter_count())) { |
| 84 Begin(static_cast<int>(parameter_count())); | 63 Begin(static_cast<int>(parameter_count())); |
| 85 InitParameters(this, &main_common_); | 64 InitParameters(); |
| 86 } | 65 } |
| 87 virtual ~GraphBuilderTester() {} | 66 virtual ~GraphBuilderTester() {} |
| 88 | 67 |
| 68 void GenerateCode() { Generate(); } |
| 69 Node* Parameter(size_t index) { |
| 70 DCHECK(index < parameter_count()); |
| 71 return parameters_[index]; |
| 72 } |
| 73 |
| 89 Factory* factory() const { return isolate()->factory(); } | 74 Factory* factory() const { return isolate()->factory(); } |
| 75 |
| 76 protected: |
| 77 virtual byte* Generate() { |
| 78 if (!Pipeline::SupportedBackend()) return NULL; |
| 79 if (code_.is_null()) { |
| 80 Zone* zone = graph()->zone(); |
| 81 CallDescriptor* desc = |
| 82 Linkage::GetSimplifiedCDescriptor(zone, machine_sig_); |
| 83 code_ = Pipeline::GenerateCodeForTesting(main_isolate(), desc, graph()); |
| 84 } |
| 85 return code_.ToHandleChecked()->entry(); |
| 86 } |
| 87 |
| 88 void InitParameters() { |
| 89 int param_count = static_cast<int>(parameter_count()); |
| 90 for (int i = 0; i < param_count; ++i) { |
| 91 parameters_[i] = this->NewNode(common()->Parameter(i), graph()->start()); |
| 92 } |
| 93 } |
| 94 |
| 95 size_t parameter_count() const { return machine_sig_->parameter_count(); } |
| 96 |
| 97 private: |
| 98 Node** parameters_; |
| 99 MaybeHandle<Code> code_; |
| 90 }; | 100 }; |
| 101 |
| 91 } // namespace compiler | 102 } // namespace compiler |
| 92 } // namespace internal | 103 } // namespace internal |
| 93 } // namespace v8 | 104 } // namespace v8 |
| 94 | 105 |
| 95 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ | 106 #endif // V8_CCTEST_COMPILER_GRAPH_BUILDER_TESTER_H_ |
| OLD | NEW |