| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 static RawObject* ExecuteTest(const Code& code) { |
| 14 Thread* thread = Thread::Current(); |
| 15 TransitionToGenerated transition(thread); |
| 16 return Simulator::Current()->Call( |
| 17 code, |
| 18 Array::Handle(ArgumentsDescriptor::New(0)), |
| 19 Array::Handle(Array::New(0)), |
| 20 thread); |
| 21 } |
| 22 |
| 23 |
| 24 #define EXECUTE_TEST_CODE_INTPTR(code) \ |
| 25 Smi::Value(Smi::RawCast(ExecuteTest(code))) |
| 26 #define EXECUTE_TEST_CODE_BOOL(code) \ |
| 27 (Bool::RawCast(ExecuteTest(code)) == Bool::True().raw()) |
| 28 #define EXECUTE_TEST_CODE_OBJECT(code) \ |
| 29 Object::Handle(ExecuteTest(code)) |
| 30 |
| 13 #define __ assembler-> | 31 #define __ assembler-> |
| 14 | 32 |
| 33 |
| 15 ASSEMBLER_TEST_GENERATE(Simple, assembler) { | 34 ASSEMBLER_TEST_GENERATE(Simple, assembler) { |
| 16 __ PushConstant(Smi::Handle(Smi::New(42))); | 35 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 17 __ ReturnTOS(); | 36 __ ReturnTOS(); |
| 18 } | 37 } |
| 19 | 38 |
| 20 | 39 |
| 21 ASSEMBLER_TEST_RUN(Simple, test) { | 40 ASSEMBLER_TEST_RUN(Simple, test) { |
| 22 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); | 41 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 23 } | 42 } |
| 24 | 43 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 __ Bind(&branch_taken); | 607 __ Bind(&branch_taken); |
| 589 __ PushConstant(Smi::Handle(Smi::New(0))); | 608 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 590 __ ReturnTOS(); | 609 __ ReturnTOS(); |
| 591 } | 610 } |
| 592 | 611 |
| 593 | 612 |
| 594 ASSEMBLER_TEST_RUN(IfEqStrictNumTOSNotTakenDouble, test) { | 613 ASSEMBLER_TEST_RUN(IfEqStrictNumTOSNotTakenDouble, test) { |
| 595 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); | 614 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 596 } | 615 } |
| 597 | 616 |
| 617 |
| 618 // - BooleanNegateTOS |
| 619 // |
| 620 // SP[0] = !SP[0] |
| 621 ASSEMBLER_TEST_GENERATE(BooleanNegateTOSTrue, assembler) { |
| 622 __ PushConstant(Bool::True()); |
| 623 __ BooleanNegateTOS(); |
| 624 __ ReturnTOS(); |
| 625 } |
| 626 |
| 627 |
| 628 ASSEMBLER_TEST_RUN(BooleanNegateTOSTrue, test) { |
| 629 EXPECT(!EXECUTE_TEST_CODE_BOOL(test->code())); |
| 630 } |
| 631 |
| 632 |
| 633 ASSEMBLER_TEST_GENERATE(BooleanNegateTOSFalse, assembler) { |
| 634 __ PushConstant(Bool::False()); |
| 635 __ BooleanNegateTOS(); |
| 636 __ ReturnTOS(); |
| 637 } |
| 638 |
| 639 |
| 640 ASSEMBLER_TEST_RUN(BooleanNegateTOSFalse, test) { |
| 641 EXPECT(EXECUTE_TEST_CODE_BOOL(test->code())); |
| 642 } |
| 643 |
| 644 |
| 645 // - AssertBoolean A |
| 646 // |
| 647 // Assert that TOS is a boolean (A = 1) or that TOS is not null (A = 0). |
| 648 ASSEMBLER_TEST_GENERATE(AssertBooleanTrue, assembler) { |
| 649 __ PushConstant(Bool::True()); |
| 650 __ AssertBoolean(1); |
| 651 __ ReturnTOS(); |
| 652 } |
| 653 |
| 654 |
| 655 ASSEMBLER_TEST_RUN(AssertBooleanTrue, test) { |
| 656 EXPECT(EXECUTE_TEST_CODE_BOOL(test->code())); |
| 657 } |
| 658 |
| 659 |
| 660 ASSEMBLER_TEST_GENERATE(AssertBooleanFalse, assembler) { |
| 661 __ PushConstant(Bool::False()); |
| 662 __ AssertBoolean(1); |
| 663 __ ReturnTOS(); |
| 664 } |
| 665 |
| 666 |
| 667 ASSEMBLER_TEST_RUN(AssertBooleanFalse, test) { |
| 668 EXPECT(!EXECUTE_TEST_CODE_BOOL(test->code())); |
| 669 } |
| 670 |
| 671 |
| 672 ASSEMBLER_TEST_GENERATE(AssertBooleanNotNull, assembler) { |
| 673 __ PushConstant(Bool::True()); |
| 674 __ AssertBoolean(0); |
| 675 __ ReturnTOS(); |
| 676 } |
| 677 |
| 678 |
| 679 ASSEMBLER_TEST_RUN(AssertBooleanNotNull, test) { |
| 680 EXPECT(EXECUTE_TEST_CODE_BOOL(test->code())); |
| 681 } |
| 682 |
| 683 |
| 684 ASSEMBLER_TEST_GENERATE(AssertBooleanFail1, assembler) { |
| 685 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 686 __ AssertBoolean(1); |
| 687 __ ReturnTOS(); |
| 688 } |
| 689 |
| 690 |
| 691 ASSEMBLER_TEST_RUN(AssertBooleanFail1, test) { |
| 692 EXPECT(EXECUTE_TEST_CODE_OBJECT(test->code()).IsError()); |
| 693 } |
| 694 |
| 695 |
| 696 ASSEMBLER_TEST_GENERATE(AssertBooleanFail2, assembler) { |
| 697 __ PushConstant(Object::null_object()); |
| 698 __ AssertBoolean(0); |
| 699 __ ReturnTOS(); |
| 700 } |
| 701 |
| 702 |
| 703 ASSEMBLER_TEST_RUN(AssertBooleanFail2, test) { |
| 704 EXPECT(EXECUTE_TEST_CODE_OBJECT(test->code()).IsError()); |
| 705 } |
| 706 |
| 598 } // namespace dart | 707 } // namespace dart |
| 599 | 708 |
| 600 #endif // defined(TARGET_ARCH_DBC) | 709 #endif // defined(TARGET_ARCH_DBC) |
| OLD | NEW |