OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_UNIT_TEST_H_ | 5 #ifndef VM_UNIT_TEST_H_ |
6 #define VM_UNIT_TEST_H_ | 6 #define VM_UNIT_TEST_H_ |
7 | 7 |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 | 9 |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 ASSERT(assembler != NULL); | 353 ASSERT(assembler != NULL); |
354 } | 354 } |
355 ~AssemblerTest() { } | 355 ~AssemblerTest() { } |
356 | 356 |
357 Assembler* assembler() const { return assembler_; } | 357 Assembler* assembler() const { return assembler_; } |
358 | 358 |
359 const Code& code() const { return code_; } | 359 const Code& code() const { return code_; } |
360 | 360 |
361 uword entry() const { return code_.EntryPoint(); } | 361 uword entry() const { return code_.EntryPoint(); } |
362 | 362 |
363 // Invoke/InvokeWithCode is used to call assembler test functions using the | 363 // Invoke/InvokeWithCodeAndThread is used to call assembler test functions |
364 // ABI calling convention. | 364 // using the ABI calling convention. |
365 // ResultType is the return type of the assembler test function. | 365 // ResultType is the return type of the assembler test function. |
366 // ArgNType is the type of the Nth argument. | 366 // ArgNType is the type of the Nth argument. |
367 #if defined(USING_SIMULATOR) | 367 #if defined(USING_SIMULATOR) |
368 | 368 |
369 #if defined(ARCH_IS_64_BIT) | 369 #if defined(ARCH_IS_64_BIT) |
370 // TODO(fschneider): Make InvokeWithCode<> more general and work on 32-bit. | 370 // TODO(fschneider): Make InvokeWithCodeAndThread<> more general and work on |
| 371 // 32-bit. |
371 // Since Simulator::Call always return a int64_t, bit_cast does not work | 372 // Since Simulator::Call always return a int64_t, bit_cast does not work |
372 // on 32-bit platforms when returning an int32_t. Since template functions | 373 // on 32-bit platforms when returning an int32_t. Since template functions |
373 // don't support partial specialization, we'd need to introduce a helper | 374 // don't support partial specialization, we'd need to introduce a helper |
374 // class to support 32-bit return types. | 375 // class to support 32-bit return types. |
375 template<typename ResultType> ResultType InvokeWithCode() { | 376 template<typename ResultType> ResultType InvokeWithCodeAndThread() { |
376 const bool fp_return = is_double<ResultType>::value; | 377 const bool fp_return = is_double<ResultType>::value; |
377 const bool fp_args = false; | 378 const bool fp_args = false; |
| 379 Thread* thread = Thread::Current(); |
| 380 ASSERT(thread != NULL); |
378 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call( | 381 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call( |
379 bit_cast<intptr_t, uword>(entry()), | 382 bit_cast<intptr_t, uword>(entry()), |
380 reinterpret_cast<intptr_t>(&code_), 0, 0, 0, fp_return, fp_args)); | 383 reinterpret_cast<intptr_t>(&code_), |
| 384 reinterpret_cast<intptr_t>(thread), |
| 385 0, 0, fp_return, fp_args)); |
381 } | 386 } |
382 template<typename ResultType, typename Arg1Type> | 387 template<typename ResultType, typename Arg1Type> |
383 ResultType InvokeWithCode(Arg1Type arg1) { | 388 ResultType InvokeWithCodeAndThread(Arg1Type arg1) { |
384 const bool fp_return = is_double<ResultType>::value; | 389 const bool fp_return = is_double<ResultType>::value; |
385 const bool fp_args = is_double<Arg1Type>::value; | 390 const bool fp_args = is_double<Arg1Type>::value; |
386 // TODO(fschneider): Support double arguments for simulator calls. | 391 // TODO(fschneider): Support double arguments for simulator calls. |
387 COMPILE_ASSERT(!fp_args); | 392 COMPILE_ASSERT(!fp_args); |
| 393 Thread* thread = Thread::Current(); |
| 394 ASSERT(thread != NULL); |
388 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call( | 395 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call( |
389 bit_cast<intptr_t, uword>(entry()), | 396 bit_cast<intptr_t, uword>(entry()), |
390 reinterpret_cast<intptr_t>(&code_), | 397 reinterpret_cast<intptr_t>(&code_), |
| 398 reinterpret_cast<intptr_t>(thread), |
391 reinterpret_cast<intptr_t>(arg1), | 399 reinterpret_cast<intptr_t>(arg1), |
392 0, 0, fp_return, fp_args)); | 400 0, fp_return, fp_args)); |
393 } | 401 } |
394 #endif // ARCH_IS_64_BIT | 402 #endif // ARCH_IS_64_BIT |
395 | 403 |
396 template<typename ResultType, | 404 template<typename ResultType, |
397 typename Arg1Type, | 405 typename Arg1Type, |
398 typename Arg2Type, | 406 typename Arg2Type, |
399 typename Arg3Type> | 407 typename Arg3Type> |
400 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | 408 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { |
401 // TODO(fschneider): Support double arguments for simulator calls. | 409 // TODO(fschneider): Support double arguments for simulator calls. |
402 COMPILE_ASSERT(is_void<ResultType>::value); | 410 COMPILE_ASSERT(is_void<ResultType>::value); |
403 COMPILE_ASSERT(!is_double<Arg1Type>::value); | 411 COMPILE_ASSERT(!is_double<Arg1Type>::value); |
404 COMPILE_ASSERT(!is_double<Arg2Type>::value); | 412 COMPILE_ASSERT(!is_double<Arg2Type>::value); |
405 COMPILE_ASSERT(!is_double<Arg3Type>::value); | 413 COMPILE_ASSERT(!is_double<Arg3Type>::value); |
406 const bool fp_args = false; | 414 const bool fp_args = false; |
407 const bool fp_return = false; | 415 const bool fp_return = false; |
408 Simulator::Current()->Call( | 416 Simulator::Current()->Call( |
409 bit_cast<intptr_t, uword>(entry()), | 417 bit_cast<intptr_t, uword>(entry()), |
410 reinterpret_cast<intptr_t>(arg1), | 418 reinterpret_cast<intptr_t>(arg1), |
411 reinterpret_cast<intptr_t>(arg2), | 419 reinterpret_cast<intptr_t>(arg2), |
412 reinterpret_cast<intptr_t>(arg3), | 420 reinterpret_cast<intptr_t>(arg3), |
413 0, fp_return, fp_args); | 421 0, fp_return, fp_args); |
414 } | 422 } |
415 #else | 423 #else |
416 template<typename ResultType> ResultType InvokeWithCode() { | 424 template<typename ResultType> ResultType InvokeWithCodeAndThread() { |
417 typedef ResultType (*FunctionType) (const Code&); | 425 Thread* thread = Thread::Current(); |
418 return reinterpret_cast<FunctionType>(entry())(code_); | 426 ASSERT(thread != NULL); |
| 427 typedef ResultType (*FunctionType) (const Code&, Thread*); |
| 428 return reinterpret_cast<FunctionType>(entry())(code_, thread); |
419 } | 429 } |
420 | 430 |
421 template<typename ResultType, typename Arg1Type> | 431 template<typename ResultType, typename Arg1Type> |
422 ResultType InvokeWithCode(Arg1Type arg1) { | 432 ResultType InvokeWithCodeAndThread(Arg1Type arg1) { |
423 typedef ResultType (*FunctionType) (const Code&, Arg1Type); | 433 Thread* thread = Thread::Current(); |
424 return reinterpret_cast<FunctionType>(entry())(code_, arg1); | 434 ASSERT(thread != NULL); |
| 435 typedef ResultType (*FunctionType) (const Code&, Thread*, Arg1Type); |
| 436 return reinterpret_cast<FunctionType>(entry())(code_, thread, arg1); |
425 } | 437 } |
426 | 438 |
427 template<typename ResultType, | 439 template<typename ResultType, |
428 typename Arg1Type, | 440 typename Arg1Type, |
429 typename Arg2Type, | 441 typename Arg2Type, |
430 typename Arg3Type> | 442 typename Arg3Type> |
431 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | 443 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { |
432 typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type); | 444 typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type); |
433 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3); | 445 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3); |
434 } | 446 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 // Yields: | 549 // Yields: |
538 // | 550 // |
539 // out = "\"id\":\"\"" | 551 // out = "\"id\":\"\"" |
540 // | 552 // |
541 void ElideJSONSubstring(const char* prefix, const char* in, char* out); | 553 void ElideJSONSubstring(const char* prefix, const char* in, char* out); |
542 | 554 |
543 | 555 |
544 } // namespace dart | 556 } // namespace dart |
545 | 557 |
546 #endif // VM_UNIT_TEST_H_ | 558 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |