| 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 |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 __ PushConstant(Object::null_object()); | 697 __ PushConstant(Object::null_object()); |
| 698 __ AssertBoolean(0); | 698 __ AssertBoolean(0); |
| 699 __ ReturnTOS(); | 699 __ ReturnTOS(); |
| 700 } | 700 } |
| 701 | 701 |
| 702 | 702 |
| 703 ASSEMBLER_TEST_RUN(AssertBooleanFail2, test) { | 703 ASSEMBLER_TEST_RUN(AssertBooleanFail2, test) { |
| 704 EXPECT(EXECUTE_TEST_CODE_OBJECT(test->code()).IsError()); | 704 EXPECT(EXECUTE_TEST_CODE_OBJECT(test->code()).IsError()); |
| 705 } | 705 } |
| 706 | 706 |
| 707 |
| 708 // - Drop1; DropR n; Drop n |
| 709 // |
| 710 // Drop 1 or n values from the stack, if instruction is DropR push the first |
| 711 // dropped value to the stack; |
| 712 ASSEMBLER_TEST_GENERATE(Drop1, assembler) { |
| 713 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 714 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 715 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 716 __ Drop1(); |
| 717 __ ReturnTOS(); |
| 718 } |
| 719 |
| 720 |
| 721 ASSEMBLER_TEST_RUN(Drop1, test) { |
| 722 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 723 } |
| 724 |
| 725 |
| 726 ASSEMBLER_TEST_GENERATE(Drop, assembler) { |
| 727 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 728 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 729 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 730 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 731 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 732 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 733 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 734 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 735 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 736 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 737 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 738 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 739 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 740 __ Drop(11); |
| 741 __ ReturnTOS(); |
| 742 } |
| 743 |
| 744 |
| 745 ASSEMBLER_TEST_RUN(Drop, test) { |
| 746 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 747 } |
| 748 |
| 749 |
| 750 ASSEMBLER_TEST_GENERATE(DropR, assembler) { |
| 751 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 752 __ PushConstant(Smi::Handle(Smi::New(1))); |
| 753 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 754 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 755 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 756 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 757 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 758 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 759 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 760 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 761 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 762 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 763 __ PushConstant(Smi::Handle(Smi::New(37))); |
| 764 __ PushConstant(Smi::Handle(Smi::New(41))); |
| 765 __ DropR(11); |
| 766 __ AddTOS(); |
| 767 __ PushConstant(Smi::Handle(Smi::New(0))); // Should be skipped. |
| 768 __ ReturnTOS(); |
| 769 } |
| 770 |
| 771 |
| 772 ASSEMBLER_TEST_RUN(DropR, test) { |
| 773 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 774 } |
| 775 |
| 776 |
| 777 // - Frame D |
| 778 // |
| 779 // Reserve and initialize with null space for D local variables. |
| 780 ASSEMBLER_TEST_GENERATE(FrameInitialized1, assembler) { |
| 781 __ Frame(1); |
| 782 __ ReturnTOS(); |
| 783 } |
| 784 |
| 785 |
| 786 ASSEMBLER_TEST_RUN(FrameInitialized1, test) { |
| 787 EXPECT(EXECUTE_TEST_CODE_OBJECT(test->code()).IsNull()); |
| 788 } |
| 789 |
| 790 |
| 791 ASSEMBLER_TEST_GENERATE(FrameInitialized, assembler) { |
| 792 Label error; |
| 793 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 794 __ Frame(4); |
| 795 __ PushConstant(Object::null_object()); |
| 796 __ IfNeStrictTOS(); |
| 797 __ Jump(&error); |
| 798 __ PushConstant(Object::null_object()); |
| 799 __ IfNeStrictTOS(); |
| 800 __ Jump(&error); |
| 801 __ PushConstant(Object::null_object()); |
| 802 __ IfNeStrictTOS(); |
| 803 __ Jump(&error); |
| 804 __ PushConstant(Object::null_object()); |
| 805 __ IfNeStrictTOS(); |
| 806 __ Jump(&error); |
| 807 __ ReturnTOS(); |
| 808 |
| 809 // If a frame slot was not initialized to null. |
| 810 __ Bind(&error); |
| 811 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 812 __ ReturnTOS(); |
| 813 } |
| 814 |
| 815 |
| 816 ASSEMBLER_TEST_RUN(FrameInitialized, test) { |
| 817 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 818 } |
| 819 |
| 820 |
| 821 // - StoreLocal rX; PopLocal rX |
| 822 // |
| 823 // Store top of the stack into FP[rX] and pop it if needed. |
| 824 // |
| 825 // - Push rX |
| 826 // |
| 827 // Push FP[rX] to the stack. |
| 828 ASSEMBLER_TEST_GENERATE(StoreLocalPush, assembler) { |
| 829 __ Frame(1); |
| 830 __ PushConstant(Smi::Handle(Smi::New(21))); |
| 831 __ StoreLocal(0); |
| 832 __ Push(0); |
| 833 __ AddTOS(); |
| 834 __ PushConstant(Smi::Handle(Smi::New(0))); // Should be skipped. |
| 835 __ ReturnTOS(); |
| 836 } |
| 837 |
| 838 |
| 839 ASSEMBLER_TEST_RUN(StoreLocalPush, test) { |
| 840 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 841 } |
| 842 |
| 843 |
| 844 ASSEMBLER_TEST_GENERATE(PopLocalPush, assembler) { |
| 845 __ Frame(1); |
| 846 __ PushConstant(Smi::Handle(Smi::New(21))); |
| 847 __ PopLocal(0); |
| 848 __ Push(0); |
| 849 __ Push(0); |
| 850 __ AddTOS(); |
| 851 __ PushConstant(Smi::Handle(Smi::New(0))); // Should be skipped. |
| 852 __ ReturnTOS(); |
| 853 } |
| 854 |
| 855 |
| 856 ASSEMBLER_TEST_RUN(PopLocalPush, test) { |
| 857 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 858 } |
| 859 |
| 860 |
| 861 ASSEMBLER_TEST_GENERATE(LoadConstantPush, assembler) { |
| 862 __ Frame(1); |
| 863 __ LoadConstant(0, Smi::Handle(Smi::New(21))); |
| 864 __ Push(0); |
| 865 __ Push(0); |
| 866 __ AddTOS(); |
| 867 __ PushConstant(Smi::Handle(Smi::New(0))); // Should be skipped. |
| 868 __ ReturnTOS(); |
| 869 } |
| 870 |
| 871 |
| 872 ASSEMBLER_TEST_RUN(LoadConstantPush, test) { |
| 873 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 874 } |
| 875 |
| 876 |
| 877 // - Move rA, rX |
| 878 // |
| 879 // FP[rA] <- FP[rX] |
| 880 // Note: rX is signed so it can be used to address parameters which are |
| 881 // at negative indices with respect to FP. |
| 882 ASSEMBLER_TEST_GENERATE(MoveLocalLocal, assembler) { |
| 883 __ Frame(2); |
| 884 __ PushConstant(Smi::Handle(Smi::New(21))); |
| 885 __ PopLocal(0); |
| 886 __ Move(1, 0); |
| 887 __ Push(0); |
| 888 __ Push(1); |
| 889 __ AddTOS(); |
| 890 __ PushConstant(Smi::Handle(Smi::New(0))); // Should be skipped. |
| 891 __ ReturnTOS(); |
| 892 } |
| 893 |
| 894 |
| 895 ASSEMBLER_TEST_RUN(MoveLocalLocal, test) { |
| 896 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 897 } |
| 898 |
| 899 |
| 900 // - Return R; ReturnTOS |
| 901 // |
| 902 // Return to the caller using either a value from the given register or a |
| 903 // value from the top-of-stack as a result. |
| 904 ASSEMBLER_TEST_GENERATE(Return1, assembler) { |
| 905 __ Frame(1); |
| 906 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 907 __ StoreLocal(0); |
| 908 __ Return(0); |
| 909 } |
| 910 |
| 911 |
| 912 ASSEMBLER_TEST_RUN(Return1, test) { |
| 913 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 914 } |
| 915 |
| 916 |
| 917 ASSEMBLER_TEST_GENERATE(Return2, assembler) { |
| 918 __ Frame(2); |
| 919 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 920 __ StoreLocal(1); |
| 921 __ Return(1); |
| 922 } |
| 923 |
| 924 |
| 925 ASSEMBLER_TEST_RUN(Return2, test) { |
| 926 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 927 } |
| 928 |
| 929 |
| 930 ASSEMBLER_TEST_GENERATE(Loop, assembler) { |
| 931 __ Frame(2); |
| 932 __ LoadConstant(0, Smi::Handle(Smi::New(42))); |
| 933 __ LoadConstant(1, Smi::Handle(Smi::New(0))); |
| 934 |
| 935 Label loop_entry, error; |
| 936 __ Bind(&loop_entry); |
| 937 // Add 1 to FP[1]. |
| 938 __ PushConstant(Smi::Handle(Smi::New(1))); |
| 939 __ Push(1); |
| 940 __ AddTOS(); |
| 941 __ Jump(&error); |
| 942 __ PopLocal(1); |
| 943 |
| 944 // Subtract 1 from FP[0]. |
| 945 __ Push(0); |
| 946 __ PushConstant(Smi::Handle(Smi::New(1))); |
| 947 __ SubTOS(); |
| 948 __ Jump(&error); |
| 949 |
| 950 // Jump to loop_entry if FP[0] != 0. |
| 951 __ StoreLocal(0); |
| 952 __ PushConstant(Smi::Handle(Smi::New(0))); |
| 953 __ IfNeStrictNumTOS(); |
| 954 __ Jump(&loop_entry); |
| 955 |
| 956 __ Return(1); |
| 957 |
| 958 __ Bind(&error); |
| 959 __ LoadConstant(1, Smi::Handle(Smi::New(-42))); |
| 960 __ Return(1); |
| 961 } |
| 962 |
| 963 |
| 964 ASSEMBLER_TEST_RUN(Loop, test) { |
| 965 EXPECT_EQ(42, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 966 } |
| 967 |
| 968 |
| 969 // - LoadClassIdTOS, LoadClassId rA, D |
| 970 // |
| 971 // LoadClassIdTOS loads the class id from the object at SP[0] and stores it |
| 972 // to SP[0]. LoadClassId loads the class id from FP[rA] and stores it to |
| 973 // FP[D]. |
| 974 ASSEMBLER_TEST_GENERATE(LoadClassIdTOS, assembler) { |
| 975 __ PushConstant(Smi::Handle(Smi::New(42))); |
| 976 __ LoadClassIdTOS(); |
| 977 __ ReturnTOS(); |
| 978 } |
| 979 |
| 980 |
| 981 ASSEMBLER_TEST_RUN(LoadClassIdTOS, test) { |
| 982 EXPECT_EQ(kSmiCid, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 983 } |
| 984 |
| 985 |
| 986 ASSEMBLER_TEST_GENERATE(LoadClassId, assembler) { |
| 987 __ Frame(2); |
| 988 __ LoadConstant(0, Smi::Handle(Smi::New(42))); |
| 989 __ LoadClassId(1, 0); |
| 990 __ Return(1); |
| 991 } |
| 992 |
| 993 |
| 994 ASSEMBLER_TEST_RUN(LoadClassId, test) { |
| 995 EXPECT_EQ(kSmiCid, EXECUTE_TEST_CODE_INTPTR(test->code())); |
| 996 } |
| 997 |
| 998 |
| 999 // - CreateArrayTOS |
| 1000 // |
| 1001 // Allocate array of length SP[0] with type arguments SP[-1]. |
| 1002 ASSEMBLER_TEST_GENERATE(CreateArrayTOS, assembler) { |
| 1003 __ PushConstant(Object::null_object()); |
| 1004 __ PushConstant(Smi::Handle(Smi::New(10))); |
| 1005 __ CreateArrayTOS(); |
| 1006 __ ReturnTOS(); |
| 1007 } |
| 1008 |
| 1009 |
| 1010 ASSEMBLER_TEST_RUN(CreateArrayTOS, test) { |
| 1011 const Object& obj = EXECUTE_TEST_CODE_OBJECT(test->code()); |
| 1012 EXPECT(obj.IsArray()); |
| 1013 Array& array = Array::Handle(); |
| 1014 array ^= obj.raw(); |
| 1015 EXPECT_EQ(10, array.Length()); |
| 1016 } |
| 1017 |
| 707 } // namespace dart | 1018 } // namespace dart |
| 708 | 1019 |
| 709 #endif // defined(TARGET_ARCH_DBC) | 1020 #endif // defined(TARGET_ARCH_DBC) |
| OLD | NEW |