OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
10 | 10 |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 } | 886 } |
887 | 887 |
888 TEST_F(AstDecoderTest, GrowMemory) { | 888 TEST_F(AstDecoderTest, GrowMemory) { |
889 byte code[] = {kExprGrowMemory, kExprGetLocal, 0}; | 889 byte code[] = {kExprGrowMemory, kExprGetLocal, 0}; |
890 EXPECT_VERIFIES(sigs.i_i(), code); | 890 EXPECT_VERIFIES(sigs.i_i(), code); |
891 EXPECT_FAILURE(sigs.i_d(), code); | 891 EXPECT_FAILURE(sigs.i_d(), code); |
892 } | 892 } |
893 | 893 |
894 TEST_F(AstDecoderTest, LoadMemOffset) { | 894 TEST_F(AstDecoderTest, LoadMemOffset) { |
895 for (int offset = 0; offset < 128; offset += 7) { | 895 for (int offset = 0; offset < 128; offset += 7) { |
896 byte code[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), | 896 byte code[] = {kExprI32LoadMem, ZERO_ALIGNMENT, static_cast<byte>(offset), |
897 static_cast<byte>(offset), kExprI8Const, 0}; | 897 kExprI8Const, 0}; |
898 EXPECT_VERIFIES(sigs.i_i(), code); | 898 EXPECT_VERIFIES(sigs.i_i(), code); |
899 } | 899 } |
900 } | 900 } |
901 | 901 |
902 TEST_F(AstDecoderTest, StoreMemOffset) { | 902 TEST_F(AstDecoderTest, StoreMemOffset) { |
903 for (int offset = 0; offset < 128; offset += 7) { | 903 for (int offset = 0; offset < 128; offset += 7) { |
904 byte code[] = {kExprI32StoreMem, | 904 byte code[] = { |
905 WasmOpcodes::LoadStoreAccessOf(true), | 905 kExprI32StoreMem, 0, static_cast<byte>(offset), kExprI8Const, 0, |
906 static_cast<byte>(offset), | 906 kExprI8Const, 0}; |
907 kExprI8Const, | |
908 0, | |
909 kExprI8Const, | |
910 0}; | |
911 EXPECT_VERIFIES(sigs.i_i(), code); | 907 EXPECT_VERIFIES(sigs.i_i(), code); |
912 } | 908 } |
913 } | 909 } |
914 | 910 |
915 TEST_F(AstDecoderTest, LoadMemOffset_varint) { | 911 TEST_F(AstDecoderTest, LoadMemOffset_varint) { |
916 byte code1[] = {kExprI32LoadMem, WasmOpcodes::LoadStoreAccessOf(true), 0, | 912 byte code1[] = {kExprI32LoadMem, ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, |
917 kExprI8Const, 0}; | |
918 byte code2[] = {kExprI32LoadMem, | |
919 WasmOpcodes::LoadStoreAccessOf(true), | |
920 0x80, | |
921 1, | |
922 kExprI8Const, | |
923 0}; | 913 0}; |
924 byte code3[] = {kExprI32LoadMem, | 914 byte code2[] = {kExprI32LoadMem, ZERO_ALIGNMENT, 0x80, 1, kExprI8Const, 0}; |
925 WasmOpcodes::LoadStoreAccessOf(true), | 915 byte code3[] = { |
926 0x81, | 916 kExprI32LoadMem, ZERO_ALIGNMENT, 0x81, 0x82, 5, kExprI8Const, 0}; |
927 0x82, | 917 byte code4[] = { |
928 5, | 918 kExprI32LoadMem, ZERO_ALIGNMENT, 0x83, 0x84, 0x85, 7, kExprI8Const, 0}; |
929 kExprI8Const, | |
930 0}; | |
931 byte code4[] = {kExprI32LoadMem, | |
932 WasmOpcodes::LoadStoreAccessOf(true), | |
933 0x83, | |
934 0x84, | |
935 0x85, | |
936 7, | |
937 kExprI8Const, | |
938 0}; | |
939 | 919 |
940 EXPECT_VERIFIES(sigs.i_i(), code1); | 920 EXPECT_VERIFIES(sigs.i_i(), code1); |
941 EXPECT_VERIFIES(sigs.i_i(), code2); | 921 EXPECT_VERIFIES(sigs.i_i(), code2); |
942 EXPECT_VERIFIES(sigs.i_i(), code3); | 922 EXPECT_VERIFIES(sigs.i_i(), code3); |
943 EXPECT_VERIFIES(sigs.i_i(), code4); | 923 EXPECT_VERIFIES(sigs.i_i(), code4); |
944 } | 924 } |
945 | 925 |
946 TEST_F(AstDecoderTest, StoreMemOffset_varint) { | 926 TEST_F(AstDecoderTest, StoreMemOffset_varint) { |
947 byte code1[] = {kExprI32StoreMem, | 927 byte code1[] = { |
948 WasmOpcodes::LoadStoreAccessOf(true), | 928 kExprI32StoreMem, ZERO_ALIGNMENT, 0, kExprI8Const, 0, kExprI8Const, 0}; |
949 0, | |
950 kExprI8Const, | |
951 0, | |
952 kExprI8Const, | |
953 0}; | |
954 byte code2[] = {kExprI32StoreMem, | 929 byte code2[] = {kExprI32StoreMem, |
955 WasmOpcodes::LoadStoreAccessOf(true), | 930 ZERO_ALIGNMENT, |
956 0x80, | 931 0x80, |
957 1, | 932 1, |
958 kExprI8Const, | 933 kExprI8Const, |
959 0, | 934 0, |
960 kExprI8Const, | 935 kExprI8Const, |
961 0}; | 936 0}; |
962 byte code3[] = {kExprI32StoreMem, | 937 byte code3[] = {kExprI32StoreMem, |
963 WasmOpcodes::LoadStoreAccessOf(true), | 938 ZERO_ALIGNMENT, |
964 0x81, | 939 0x81, |
965 0x82, | 940 0x82, |
966 5, | 941 5, |
967 kExprI8Const, | 942 kExprI8Const, |
968 0, | 943 0, |
969 kExprI8Const, | 944 kExprI8Const, |
970 0}; | 945 0}; |
971 byte code4[] = {kExprI32StoreMem, | 946 byte code4[] = {kExprI32StoreMem, |
972 WasmOpcodes::LoadStoreAccessOf(true), | 947 ZERO_ALIGNMENT, |
973 0x83, | 948 0x83, |
974 0x84, | 949 0x84, |
975 0x85, | 950 0x85, |
976 7, | 951 7, |
977 kExprI8Const, | 952 kExprI8Const, |
978 0, | 953 0, |
979 kExprI8Const, | 954 kExprI8Const, |
980 0}; | 955 0}; |
981 | 956 |
982 EXPECT_VERIFIES(sigs.i_i(), code1); | 957 EXPECT_VERIFIES(sigs.i_i(), code1); |
983 EXPECT_VERIFIES(sigs.i_i(), code2); | 958 EXPECT_VERIFIES(sigs.i_i(), code2); |
984 EXPECT_VERIFIES(sigs.i_i(), code3); | 959 EXPECT_VERIFIES(sigs.i_i(), code3); |
985 EXPECT_VERIFIES(sigs.i_i(), code4); | 960 EXPECT_VERIFIES(sigs.i_i(), code4); |
986 } | 961 } |
987 | 962 |
988 TEST_F(AstDecoderTest, AllLoadMemCombinations) { | 963 TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
989 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 964 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
990 LocalType local_type = kLocalTypes[i]; | 965 LocalType local_type = kLocalTypes[i]; |
991 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 966 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
992 MachineType mem_type = machineTypes[j]; | 967 MachineType mem_type = machineTypes[j]; |
993 byte code[] = { | 968 byte code[] = { |
994 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)), | 969 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)), |
995 WasmOpcodes::LoadStoreAccessOf(false), kExprI8Const, 0}; | 970 ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, 0}; |
996 FunctionSig sig(1, 0, &local_type); | 971 FunctionSig sig(1, 0, &local_type); |
997 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 972 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
998 EXPECT_VERIFIES(&sig, code); | 973 EXPECT_VERIFIES(&sig, code); |
999 } else { | 974 } else { |
1000 EXPECT_FAILURE(&sig, code); | 975 EXPECT_FAILURE(&sig, code); |
1001 } | 976 } |
1002 } | 977 } |
1003 } | 978 } |
1004 } | 979 } |
1005 | 980 |
1006 TEST_F(AstDecoderTest, AllStoreMemCombinations) { | 981 TEST_F(AstDecoderTest, AllStoreMemCombinations) { |
1007 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 982 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1008 LocalType local_type = kLocalTypes[i]; | 983 LocalType local_type = kLocalTypes[i]; |
1009 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 984 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1010 MachineType mem_type = machineTypes[j]; | 985 MachineType mem_type = machineTypes[j]; |
1011 byte code[] = { | 986 byte code[] = { |
1012 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)), | 987 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)), |
1013 WasmOpcodes::LoadStoreAccessOf(false), | 988 ZERO_ALIGNMENT, |
| 989 ZERO_OFFSET, |
1014 kExprI8Const, | 990 kExprI8Const, |
1015 0, | 991 0, |
1016 kExprGetLocal, | 992 kExprGetLocal, |
1017 0}; | 993 0}; |
1018 FunctionSig sig(0, 1, &local_type); | 994 FunctionSig sig(0, 1, &local_type); |
1019 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 995 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
1020 EXPECT_VERIFIES(&sig, code); | 996 EXPECT_VERIFIES(&sig, code); |
1021 } else { | 997 } else { |
1022 EXPECT_FAILURE(&sig, code); | 998 EXPECT_FAILURE(&sig, code); |
1023 } | 999 } |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 | 1768 |
1793 EXPECT_EQ(2, OpcodeLength(size2, size2 + sizeof(size2))); | 1769 EXPECT_EQ(2, OpcodeLength(size2, size2 + sizeof(size2))); |
1794 EXPECT_EQ(3, OpcodeLength(size3, size3 + sizeof(size3))); | 1770 EXPECT_EQ(3, OpcodeLength(size3, size3 + sizeof(size3))); |
1795 EXPECT_EQ(4, OpcodeLength(size4, size4 + sizeof(size4))); | 1771 EXPECT_EQ(4, OpcodeLength(size4, size4 + sizeof(size4))); |
1796 EXPECT_EQ(5, OpcodeLength(size5, size5 + sizeof(size5))); | 1772 EXPECT_EQ(5, OpcodeLength(size5, size5 + sizeof(size5))); |
1797 EXPECT_EQ(6, OpcodeLength(size6, size6 + sizeof(size6))); | 1773 EXPECT_EQ(6, OpcodeLength(size6, size6 + sizeof(size6))); |
1798 } | 1774 } |
1799 | 1775 |
1800 | 1776 |
1801 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { | 1777 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { |
1802 EXPECT_LENGTH(2, kExprI32LoadMem8S); | 1778 EXPECT_LENGTH(3, kExprI32LoadMem8S); |
1803 EXPECT_LENGTH(2, kExprI32LoadMem8U); | 1779 EXPECT_LENGTH(3, kExprI32LoadMem8U); |
1804 EXPECT_LENGTH(2, kExprI32LoadMem16S); | 1780 EXPECT_LENGTH(3, kExprI32LoadMem16S); |
1805 EXPECT_LENGTH(2, kExprI32LoadMem16U); | 1781 EXPECT_LENGTH(3, kExprI32LoadMem16U); |
1806 EXPECT_LENGTH(2, kExprI32LoadMem); | 1782 EXPECT_LENGTH(3, kExprI32LoadMem); |
1807 EXPECT_LENGTH(2, kExprI64LoadMem8S); | 1783 EXPECT_LENGTH(3, kExprI64LoadMem8S); |
1808 EXPECT_LENGTH(2, kExprI64LoadMem8U); | 1784 EXPECT_LENGTH(3, kExprI64LoadMem8U); |
1809 EXPECT_LENGTH(2, kExprI64LoadMem16S); | 1785 EXPECT_LENGTH(3, kExprI64LoadMem16S); |
1810 EXPECT_LENGTH(2, kExprI64LoadMem16U); | 1786 EXPECT_LENGTH(3, kExprI64LoadMem16U); |
1811 EXPECT_LENGTH(2, kExprI64LoadMem32S); | 1787 EXPECT_LENGTH(3, kExprI64LoadMem32S); |
1812 EXPECT_LENGTH(2, kExprI64LoadMem32U); | 1788 EXPECT_LENGTH(3, kExprI64LoadMem32U); |
1813 EXPECT_LENGTH(2, kExprI64LoadMem); | 1789 EXPECT_LENGTH(3, kExprI64LoadMem); |
1814 EXPECT_LENGTH(2, kExprF32LoadMem); | 1790 EXPECT_LENGTH(3, kExprF32LoadMem); |
1815 EXPECT_LENGTH(2, kExprF64LoadMem); | 1791 EXPECT_LENGTH(3, kExprF64LoadMem); |
1816 | 1792 |
1817 EXPECT_LENGTH(2, kExprI32StoreMem8); | 1793 EXPECT_LENGTH(3, kExprI32StoreMem8); |
1818 EXPECT_LENGTH(2, kExprI32StoreMem16); | 1794 EXPECT_LENGTH(3, kExprI32StoreMem16); |
1819 EXPECT_LENGTH(2, kExprI32StoreMem); | 1795 EXPECT_LENGTH(3, kExprI32StoreMem); |
1820 EXPECT_LENGTH(2, kExprI64StoreMem8); | 1796 EXPECT_LENGTH(3, kExprI64StoreMem8); |
1821 EXPECT_LENGTH(2, kExprI64StoreMem16); | 1797 EXPECT_LENGTH(3, kExprI64StoreMem16); |
1822 EXPECT_LENGTH(2, kExprI64StoreMem32); | 1798 EXPECT_LENGTH(3, kExprI64StoreMem32); |
1823 EXPECT_LENGTH(2, kExprI64StoreMem); | 1799 EXPECT_LENGTH(3, kExprI64StoreMem); |
1824 EXPECT_LENGTH(2, kExprF32StoreMem); | 1800 EXPECT_LENGTH(3, kExprF32StoreMem); |
1825 EXPECT_LENGTH(2, kExprF64StoreMem); | 1801 EXPECT_LENGTH(3, kExprF64StoreMem); |
1826 } | 1802 } |
1827 | 1803 |
1828 | 1804 |
1829 TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) { | 1805 TEST_F(WasmOpcodeLengthTest, MiscMemExpressions) { |
1830 EXPECT_LENGTH(1, kExprMemorySize); | 1806 EXPECT_LENGTH(1, kExprMemorySize); |
1831 EXPECT_LENGTH(1, kExprGrowMemory); | 1807 EXPECT_LENGTH(1, kExprGrowMemory); |
1832 } | 1808 } |
1833 | 1809 |
1834 | 1810 |
1835 TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { | 1811 TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2288 pos = ExpectRun(map, pos, kAstI32, 1337); | 2264 pos = ExpectRun(map, pos, kAstI32, 1337); |
2289 pos = ExpectRun(map, pos, kAstI64, 212); | 2265 pos = ExpectRun(map, pos, kAstI64, 212); |
2290 | 2266 |
2291 if (map) delete map; | 2267 if (map) delete map; |
2292 delete[] data; | 2268 delete[] data; |
2293 } | 2269 } |
2294 | 2270 |
2295 } // namespace wasm | 2271 } // namespace wasm |
2296 } // namespace internal | 2272 } // namespace internal |
2297 } // namespace v8 | 2273 } // namespace v8 |
OLD | NEW |