Chromium Code Reviews| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 } | 314 } |
| 315 Isolate* isolate() const { return isolate_; } | 315 Isolate* isolate() const { return isolate_; } |
| 316 | 316 |
| 317 private: | 317 private: |
| 318 Isolate* isolate_; | 318 Isolate* isolate_; |
| 319 | 319 |
| 320 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); | 320 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); |
| 321 }; | 321 }; |
| 322 | 322 |
| 323 | 323 |
| 324 template<typename T> struct is_void { | |
| 325 static const bool value = false; | |
| 326 }; | |
| 327 | |
| 328 | |
| 329 template<> struct is_void<void> { | |
| 330 static const bool value = true; | |
| 331 }; | |
| 332 | |
| 333 | |
| 334 template<typename T> struct is_double { | |
| 335 static const bool value = false; | |
| 336 }; | |
| 337 | |
| 338 | |
| 339 template<> struct is_double<double> { | |
| 340 static const bool value = true; | |
| 341 }; | |
| 342 | |
| 343 | |
| 324 class AssemblerTest { | 344 class AssemblerTest { |
| 325 public: | 345 public: |
| 326 AssemblerTest(const char* name, Assembler* assembler) | 346 AssemblerTest(const char* name, Assembler* assembler) |
| 327 : name_(name), | 347 : name_(name), |
| 328 assembler_(assembler), | 348 assembler_(assembler), |
| 329 code_(Code::ZoneHandle()) { | 349 code_(Code::ZoneHandle()) { |
| 330 ASSERT(name != NULL); | 350 ASSERT(name != NULL); |
| 331 ASSERT(assembler != NULL); | 351 ASSERT(assembler != NULL); |
| 332 } | 352 } |
| 333 ~AssemblerTest() { } | 353 ~AssemblerTest() { } |
| 334 | 354 |
| 335 Assembler* assembler() const { return assembler_; } | 355 Assembler* assembler() const { return assembler_; } |
| 336 | 356 |
| 337 const Code& code() const { return code_; } | 357 const Code& code() const { return code_; } |
| 338 | 358 |
| 339 uword entry() const { return entry_; } | 359 uword entry() const { return entry_; } |
| 360 #if defined(USING_SIMULATOR) | |
|
srdjan
2015/08/10 16:23:51
I am not sure I found this more readable and maint
zra
2015/08/10 16:43:32
This makes writing the assembler tests a bit easie
Florian Schneider
2015/08/11 07:58:28
Yes, I just added the variants necessary.
The comp
Florian Schneider
2015/08/11 07:58:28
There may be even more elegant ways to solve this
| |
| 361 template<typename ResultType> ResultType Invoke() { | |
| 362 const bool fp_return = is_double<ResultType>::value; | |
| 363 const bool fp_args = false; | |
| 364 return static_cast<ResultType>(Simulator::Current()->Call( | |
| 365 bit_cast<int64_t, uword>(entry()), 0, 0, 0, 0, fp_return, fp_args)); | |
| 366 } | |
|
zra
2015/08/10 16:43:32
Missing newline
| |
| 367 template<typename ResultType, typename Arg1Type> | |
| 368 ResultType Invoke(Arg1Type arg1) { | |
| 369 const bool fp_return = is_double<ResultType>::value; | |
| 370 COMPILE_ASSERT(!is_double<Arg1Type>::value); | |
| 371 const bool fp_args = false; | |
| 372 return static_cast<ResultType>(Simulator::Current()->Call( | |
| 373 bit_cast<int64_t, uword>(entry()), reinterpret_cast<int64_t>(arg1), | |
| 374 0, 0, 0, fp_return, fp_args)); | |
| 375 } | |
|
zra
2015/08/10 16:43:32
Missing newline
Florian Schneider
2015/08/11 07:58:28
Not between template functions
| |
| 376 template<typename ResultType, | |
| 377 typename Arg1Type, | |
| 378 typename Arg2Type, | |
| 379 typename Arg3Type> | |
| 380 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | |
|
zra
2015/08/10 16:43:32
The first two Invokes appear to be used for assemb
Florian Schneider
2015/08/11 07:58:28
This one is used ony for one test right now (Store
| |
| 381 COMPILE_ASSERT(is_void<ResultType>::value); | |
| 382 const bool fp_return = false; | |
| 383 COMPILE_ASSERT(!is_double<Arg1Type>::value); | |
| 384 const bool fp_args = false; | |
| 385 return static_cast<ResultType>(Simulator::Current()->Call( | |
| 386 bit_cast<int64_t, uword>(entry()), | |
| 387 reinterpret_cast<int64_t>(arg1), | |
| 388 reinterpret_cast<int64_t>(arg2), | |
| 389 reinterpret_cast<int64_t>(arg3), | |
| 390 0, fp_return, fp_args)); | |
| 391 } | |
| 392 #else | |
| 393 template<typename ResultType> ResultType Invoke() { | |
| 394 typedef ResultType (*FunctionType) (); | |
| 395 return reinterpret_cast<FunctionType>(entry())(); | |
| 396 } | |
| 397 | |
| 398 template<typename ResultType, typename Arg1Type> | |
| 399 ResultType Invoke(Arg1Type arg1) { | |
| 400 typedef ResultType (*FunctionType) (Arg1Type); | |
|
zra
2015/08/10 16:43:31
Is there some reason not to have the same asserts
Florian Schneider
2015/08/11 07:58:28
No, regular invocation just works with all types.
zra
2015/08/11 19:48:17
I think it would be good to have consistent behavi
Florian Schneider
2015/08/12 07:30:53
Why add assertions that don't guard against anythi
zra
2015/08/17 16:35:43
The assertions guard against doing something in ar
| |
| 401 return reinterpret_cast<FunctionType>(entry())(arg1); | |
| 402 } | |
| 403 | |
| 404 template<typename ResultType, | |
| 405 typename Arg1Type, | |
| 406 typename Arg2Type, | |
| 407 typename Arg3Type> | |
| 408 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | |
| 409 typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type); | |
|
zra
2015/08/10 16:43:32
Same question.
| |
| 410 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3); | |
| 411 } | |
| 412 #endif | |
| 340 | 413 |
| 341 // Assemble test and set code_ and entry_. | 414 // Assemble test and set code_ and entry_. |
| 342 void Assemble(); | 415 void Assemble(); |
| 343 | 416 |
| 344 private: | 417 private: |
| 345 const char* name_; | 418 const char* name_; |
| 346 Assembler* assembler_; | 419 Assembler* assembler_; |
| 347 Code& code_; | 420 Code& code_; |
| 348 uword entry_; | 421 uword entry_; |
| 349 | 422 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 } \ | 497 } \ |
| 425 } else { \ | 498 } else { \ |
| 426 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ | 499 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ |
| 427 #handle); \ | 500 #handle); \ |
| 428 } \ | 501 } \ |
| 429 } while (0) | 502 } while (0) |
| 430 | 503 |
| 431 } // namespace dart | 504 } // namespace dart |
| 432 | 505 |
| 433 #endif // VM_UNIT_TEST_H_ | 506 #endif // VM_UNIT_TEST_H_ |
| OLD | NEW |