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_CALL_TESTER_H_ | 5 #ifndef V8_CCTEST_COMPILER_CALL_TESTER_H_ |
6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_ | 6 #define V8_CCTEST_COMPILER_CALL_TESTER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/simulator.h" | 10 #include "src/simulator.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return static_cast<int64_t>(static_cast<int32_t>(r)); | 115 return static_cast<int64_t>(static_cast<int32_t>(r)); |
116 } | 116 } |
117 }; | 117 }; |
118 | 118 |
119 #endif // !V8_TARGET_ARCH_64_BIT | 119 #endif // !V8_TARGET_ARCH_64_BIT |
120 | 120 |
121 | 121 |
122 template <typename R> | 122 template <typename R> |
123 class CallHelper { | 123 class CallHelper { |
124 public: | 124 public: |
125 explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig) | 125 explicit CallHelper(Isolate* isolate, CSignature* csig) |
126 : machine_sig_(machine_sig), isolate_(isolate) { | 126 : csig_(csig), isolate_(isolate) { |
127 USE(isolate_); | 127 USE(isolate_); |
128 } | 128 } |
129 virtual ~CallHelper() {} | 129 virtual ~CallHelper() {} |
130 | 130 |
131 R Call() { | 131 R Call() { |
132 typedef R V8_CDECL FType(); | 132 typedef R V8_CDECL FType(); |
133 VerifyParameters0(); | 133 csig_->VerifyParams(); |
134 return DoCall(FUNCTION_CAST<FType*>(Generate())); | 134 return DoCall(FUNCTION_CAST<FType*>(Generate())); |
135 } | 135 } |
136 | 136 |
137 template <typename P1> | 137 template <typename P1> |
138 R Call(P1 p1) { | 138 R Call(P1 p1) { |
139 typedef R V8_CDECL FType(P1); | 139 typedef R V8_CDECL FType(P1); |
140 VerifyParameters1<P1>(); | 140 csig_->VerifyParams<P1>(); |
141 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1); | 141 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1); |
142 } | 142 } |
143 | 143 |
144 template <typename P1, typename P2> | 144 template <typename P1, typename P2> |
145 R Call(P1 p1, P2 p2) { | 145 R Call(P1 p1, P2 p2) { |
146 typedef R V8_CDECL FType(P1, P2); | 146 typedef R V8_CDECL FType(P1, P2); |
147 VerifyParameters2<P1, P2>(); | 147 csig_->VerifyParams<P1, P2>(); |
148 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2); | 148 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2); |
149 } | 149 } |
150 | 150 |
151 template <typename P1, typename P2, typename P3> | 151 template <typename P1, typename P2, typename P3> |
152 R Call(P1 p1, P2 p2, P3 p3) { | 152 R Call(P1 p1, P2 p2, P3 p3) { |
153 typedef R V8_CDECL FType(P1, P2, P3); | 153 typedef R V8_CDECL FType(P1, P2, P3); |
154 VerifyParameters3<P1, P2, P3>(); | 154 csig_->VerifyParams<P1, P2, P3>(); |
155 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3); | 155 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3); |
156 } | 156 } |
157 | 157 |
158 template <typename P1, typename P2, typename P3, typename P4> | 158 template <typename P1, typename P2, typename P3, typename P4> |
159 R Call(P1 p1, P2 p2, P3 p3, P4 p4) { | 159 R Call(P1 p1, P2 p2, P3 p3, P4 p4) { |
160 typedef R V8_CDECL FType(P1, P2, P3, P4); | 160 typedef R V8_CDECL FType(P1, P2, P3, P4); |
161 VerifyParameters4<P1, P2, P3, P4>(); | 161 csig_->VerifyParams<P1, P2, P3, P4>(); |
162 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3, p4); | 162 return DoCall(FUNCTION_CAST<FType*>(Generate()), p1, p2, p3, p4); |
163 } | 163 } |
164 | 164 |
165 protected: | 165 protected: |
166 MachineSignature* machine_sig_; | 166 CSignature* csig_; |
167 | |
168 void VerifyParameters(size_t parameter_count, MachineType* parameter_types) { | |
169 CHECK(machine_sig_->parameter_count() == parameter_count); | |
170 for (size_t i = 0; i < parameter_count; i++) { | |
171 CHECK_EQ(machine_sig_->GetParam(i), parameter_types[i]); | |
172 } | |
173 } | |
174 | 167 |
175 virtual byte* Generate() = 0; | 168 virtual byte* Generate() = 0; |
176 | 169 |
177 private: | 170 private: |
178 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 | 171 #if USE_SIMULATOR && V8_TARGET_ARCH_ARM64 |
179 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { | 172 uintptr_t CallSimulator(byte* f, Simulator::CallArgument* args) { |
180 Simulator* simulator = Simulator::current(isolate_); | 173 Simulator* simulator = Simulator::current(isolate_); |
181 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); | 174 return static_cast<uintptr_t>(simulator->CallInt64(f, args)); |
182 } | 175 } |
183 | 176 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 template <typename F, typename P1, typename P2, typename P3> | 294 template <typename F, typename P1, typename P2, typename P3> |
302 R DoCall(F* f, P1 p1, P2 p2, P3 p3) { | 295 R DoCall(F* f, P1 p1, P2 p2, P3 p3) { |
303 return f(p1, p2, p3); | 296 return f(p1, p2, p3); |
304 } | 297 } |
305 template <typename F, typename P1, typename P2, typename P3, typename P4> | 298 template <typename F, typename P1, typename P2, typename P3, typename P4> |
306 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) { | 299 R DoCall(F* f, P1 p1, P2 p2, P3 p3, P4 p4) { |
307 return f(p1, p2, p3, p4); | 300 return f(p1, p2, p3, p4); |
308 } | 301 } |
309 #endif | 302 #endif |
310 | 303 |
311 #ifndef DEBUG | |
312 void VerifyParameters0() {} | |
313 | |
314 template <typename P1> | |
315 void VerifyParameters1() {} | |
316 | |
317 template <typename P1, typename P2> | |
318 void VerifyParameters2() {} | |
319 | |
320 template <typename P1, typename P2, typename P3> | |
321 void VerifyParameters3() {} | |
322 | |
323 template <typename P1, typename P2, typename P3, typename P4> | |
324 void VerifyParameters4() {} | |
325 #else | |
326 void VerifyParameters0() { VerifyParameters(0, NULL); } | |
327 | |
328 template <typename P1> | |
329 void VerifyParameters1() { | |
330 MachineType parameters[] = {MachineTypeForC<P1>()}; | |
331 VerifyParameters(arraysize(parameters), parameters); | |
332 } | |
333 | |
334 template <typename P1, typename P2> | |
335 void VerifyParameters2() { | |
336 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>()}; | |
337 VerifyParameters(arraysize(parameters), parameters); | |
338 } | |
339 | |
340 template <typename P1, typename P2, typename P3> | |
341 void VerifyParameters3() { | |
342 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(), | |
343 MachineTypeForC<P3>()}; | |
344 VerifyParameters(arraysize(parameters), parameters); | |
345 } | |
346 | |
347 template <typename P1, typename P2, typename P3, typename P4> | |
348 void VerifyParameters4() { | |
349 MachineType parameters[] = {MachineTypeForC<P1>(), MachineTypeForC<P2>(), | |
350 MachineTypeForC<P3>(), MachineTypeForC<P4>()}; | |
351 VerifyParameters(arraysize(parameters), parameters); | |
352 } | |
353 #endif | |
354 | |
355 Isolate* isolate_; | 304 Isolate* isolate_; |
356 }; | 305 }; |
357 | 306 |
358 } // namespace compiler | 307 } // namespace compiler |
359 } // namespace internal | 308 } // namespace internal |
360 } // namespace v8 | 309 } // namespace v8 |
361 | 310 |
362 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ | 311 #endif // V8_CCTEST_COMPILER_CALL_TESTER_H_ |
OLD | NEW |