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