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 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_F32(17.6))); | 1340 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_F32(17.6))); |
1341 } | 1341 } |
1342 | 1342 |
1343 TEST_F(AstDecoderTest, Int32Globals) { | 1343 TEST_F(AstDecoderTest, Int32Globals) { |
1344 FunctionSig* sig = sigs.i_i(); | 1344 FunctionSig* sig = sigs.i_i(); |
1345 TestModuleEnv module_env; | 1345 TestModuleEnv module_env; |
1346 module = &module_env; | 1346 module = &module_env; |
1347 | 1347 |
1348 module_env.AddGlobal(kAstI32); | 1348 module_env.AddGlobal(kAstI32); |
1349 | 1349 |
1350 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1350 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
1351 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1351 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1352 } | 1352 } |
1353 | 1353 |
1354 TEST_F(AstDecoderTest, Int32Globals_fail) { | 1354 TEST_F(AstDecoderTest, Int32Globals_fail) { |
1355 FunctionSig* sig = sigs.i_i(); | 1355 FunctionSig* sig = sigs.i_i(); |
1356 TestModuleEnv module_env; | 1356 TestModuleEnv module_env; |
1357 module = &module_env; | 1357 module = &module_env; |
1358 | 1358 |
1359 module_env.AddGlobal(kAstI64); | 1359 module_env.AddGlobal(kAstI64); |
1360 module_env.AddGlobal(kAstI64); | 1360 module_env.AddGlobal(kAstI64); |
1361 module_env.AddGlobal(kAstF32); | 1361 module_env.AddGlobal(kAstF32); |
1362 module_env.AddGlobal(kAstF64); | 1362 module_env.AddGlobal(kAstF64); |
1363 | 1363 |
1364 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1364 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(0)); |
1365 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(1)); | 1365 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(1)); |
1366 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(2)); | 1366 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(2)); |
1367 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(3)); | 1367 EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(3)); |
1368 | 1368 |
1369 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1369 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1370 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); | 1370 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); |
1371 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); | 1371 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0))); |
1372 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); | 1372 EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0))); |
1373 } | 1373 } |
1374 | 1374 |
1375 TEST_F(AstDecoderTest, Int64Globals) { | 1375 TEST_F(AstDecoderTest, Int64Globals) { |
1376 FunctionSig* sig = sigs.l_l(); | 1376 FunctionSig* sig = sigs.l_l(); |
1377 TestModuleEnv module_env; | 1377 TestModuleEnv module_env; |
1378 module = &module_env; | 1378 module = &module_env; |
1379 | 1379 |
1380 module_env.AddGlobal(kAstI64); | 1380 module_env.AddGlobal(kAstI64); |
1381 module_env.AddGlobal(kAstI64); | 1381 module_env.AddGlobal(kAstI64); |
1382 | 1382 |
1383 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1383 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
1384 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1)); | 1384 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(1)); |
1385 | 1385 |
1386 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1386 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1387 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); | 1387 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); |
1388 } | 1388 } |
1389 | 1389 |
1390 TEST_F(AstDecoderTest, Float32Globals) { | 1390 TEST_F(AstDecoderTest, Float32Globals) { |
1391 FunctionSig* sig = sigs.f_ff(); | 1391 FunctionSig* sig = sigs.f_ff(); |
1392 TestModuleEnv module_env; | 1392 TestModuleEnv module_env; |
1393 module = &module_env; | 1393 module = &module_env; |
1394 | 1394 |
1395 module_env.AddGlobal(kAstF32); | 1395 module_env.AddGlobal(kAstF32); |
1396 | 1396 |
1397 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1397 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
1398 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1398 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1399 } | 1399 } |
1400 | 1400 |
1401 TEST_F(AstDecoderTest, Float64Globals) { | 1401 TEST_F(AstDecoderTest, Float64Globals) { |
1402 FunctionSig* sig = sigs.d_dd(); | 1402 FunctionSig* sig = sigs.d_dd(); |
1403 TestModuleEnv module_env; | 1403 TestModuleEnv module_env; |
1404 module = &module_env; | 1404 module = &module_env; |
1405 | 1405 |
1406 module_env.AddGlobal(kAstF64); | 1406 module_env.AddGlobal(kAstF64); |
1407 | 1407 |
1408 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1408 EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
1409 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1409 EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1410 } | 1410 } |
1411 | 1411 |
1412 TEST_F(AstDecoderTest, AllLoadGlobalCombinations) { | 1412 TEST_F(AstDecoderTest, AllGetGlobalCombinations) { |
1413 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1413 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1414 LocalType local_type = kLocalTypes[i]; | 1414 LocalType local_type = kLocalTypes[i]; |
1415 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1415 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1416 LocalType global_type = kLocalTypes[j]; | 1416 LocalType global_type = kLocalTypes[j]; |
1417 FunctionSig sig(1, 0, &local_type); | 1417 FunctionSig sig(1, 0, &local_type); |
1418 TestModuleEnv module_env; | 1418 TestModuleEnv module_env; |
1419 module = &module_env; | 1419 module = &module_env; |
1420 module_env.AddGlobal(global_type); | 1420 module_env.AddGlobal(global_type); |
1421 if (local_type == global_type) { | 1421 if (local_type == global_type) { |
1422 EXPECT_VERIFIES_INLINE(&sig, WASM_LOAD_GLOBAL(0)); | 1422 EXPECT_VERIFIES_INLINE(&sig, WASM_GET_GLOBAL(0)); |
1423 } else { | 1423 } else { |
1424 EXPECT_FAILURE_INLINE(&sig, WASM_LOAD_GLOBAL(0)); | 1424 EXPECT_FAILURE_INLINE(&sig, WASM_GET_GLOBAL(0)); |
1425 } | 1425 } |
1426 } | 1426 } |
1427 } | 1427 } |
1428 } | 1428 } |
1429 | 1429 |
1430 TEST_F(AstDecoderTest, AllStoreGlobalCombinations) { | 1430 TEST_F(AstDecoderTest, AllSetGlobalCombinations) { |
1431 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1431 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1432 LocalType local_type = kLocalTypes[i]; | 1432 LocalType local_type = kLocalTypes[i]; |
1433 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1433 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1434 LocalType global_type = kLocalTypes[j]; | 1434 LocalType global_type = kLocalTypes[j]; |
1435 FunctionSig sig(0, 1, &local_type); | 1435 FunctionSig sig(0, 1, &local_type); |
1436 TestModuleEnv module_env; | 1436 TestModuleEnv module_env; |
1437 module = &module_env; | 1437 module = &module_env; |
1438 module_env.AddGlobal(global_type); | 1438 module_env.AddGlobal(global_type); |
1439 if (local_type == global_type) { | 1439 if (local_type == global_type) { |
1440 EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1440 EXPECT_VERIFIES_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1441 } else { | 1441 } else { |
1442 EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1442 EXPECT_FAILURE_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1443 } | 1443 } |
1444 } | 1444 } |
1445 } | 1445 } |
1446 } | 1446 } |
1447 | 1447 |
1448 TEST_F(AstDecoderTest, BreakEnd) { | 1448 TEST_F(AstDecoderTest, BreakEnd) { |
1449 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 1449 EXPECT_VERIFIES_INLINE(sigs.i_i(), |
1450 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); | 1450 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
1451 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 1451 EXPECT_VERIFIES_INLINE(sigs.i_i(), |
1452 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); | 1452 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 EXPECT_LENGTH(3, kExprBr); | 1857 EXPECT_LENGTH(3, kExprBr); |
1858 EXPECT_LENGTH(3, kExprBrIf); | 1858 EXPECT_LENGTH(3, kExprBrIf); |
1859 } | 1859 } |
1860 | 1860 |
1861 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { | 1861 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { |
1862 EXPECT_LENGTH(2, kExprI8Const); | 1862 EXPECT_LENGTH(2, kExprI8Const); |
1863 EXPECT_LENGTH(5, kExprF32Const); | 1863 EXPECT_LENGTH(5, kExprF32Const); |
1864 EXPECT_LENGTH(9, kExprF64Const); | 1864 EXPECT_LENGTH(9, kExprF64Const); |
1865 EXPECT_LENGTH(2, kExprGetLocal); | 1865 EXPECT_LENGTH(2, kExprGetLocal); |
1866 EXPECT_LENGTH(2, kExprSetLocal); | 1866 EXPECT_LENGTH(2, kExprSetLocal); |
1867 EXPECT_LENGTH(2, kExprLoadGlobal); | 1867 EXPECT_LENGTH(2, kExprGetGlobal); |
1868 EXPECT_LENGTH(2, kExprStoreGlobal); | 1868 EXPECT_LENGTH(2, kExprSetGlobal); |
1869 EXPECT_LENGTH(3, kExprCallFunction); | 1869 EXPECT_LENGTH(3, kExprCallFunction); |
1870 EXPECT_LENGTH(3, kExprCallImport); | 1870 EXPECT_LENGTH(3, kExprCallImport); |
1871 EXPECT_LENGTH(3, kExprCallIndirect); | 1871 EXPECT_LENGTH(3, kExprCallIndirect); |
1872 EXPECT_LENGTH(1, kExprIf); | 1872 EXPECT_LENGTH(1, kExprIf); |
1873 EXPECT_LENGTH(1, kExprBlock); | 1873 EXPECT_LENGTH(1, kExprBlock); |
1874 EXPECT_LENGTH(1, kExprLoop); | 1874 EXPECT_LENGTH(1, kExprLoop); |
1875 EXPECT_LENGTH(3, kExprBr); | 1875 EXPECT_LENGTH(3, kExprBr); |
1876 EXPECT_LENGTH(3, kExprBrIf); | 1876 EXPECT_LENGTH(3, kExprBrIf); |
1877 } | 1877 } |
1878 | 1878 |
(...skipping 11 matching lines...) Expand all Loading... |
1890 EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999)); | 1890 EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999)); |
1891 EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999)); | 1891 EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999)); |
1892 EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999)); | 1892 EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999)); |
1893 EXPECT_LENGTH_N(7, WASM_I64V_6(777777)); | 1893 EXPECT_LENGTH_N(7, WASM_I64V_6(777777)); |
1894 EXPECT_LENGTH_N(8, WASM_I64V_7(7777777)); | 1894 EXPECT_LENGTH_N(8, WASM_I64V_7(7777777)); |
1895 EXPECT_LENGTH_N(9, WASM_I64V_8(77777777)); | 1895 EXPECT_LENGTH_N(9, WASM_I64V_8(77777777)); |
1896 EXPECT_LENGTH_N(10, WASM_I64V_9(777777777)); | 1896 EXPECT_LENGTH_N(10, WASM_I64V_9(777777777)); |
1897 } | 1897 } |
1898 | 1898 |
1899 TEST_F(WasmOpcodeLengthTest, VariableLength) { | 1899 TEST_F(WasmOpcodeLengthTest, VariableLength) { |
1900 EXPECT_LENGTH_N(2, kExprLoadGlobal, U32V_1(1)); | 1900 EXPECT_LENGTH_N(2, kExprGetGlobal, U32V_1(1)); |
1901 EXPECT_LENGTH_N(3, kExprLoadGlobal, U32V_2(33)); | 1901 EXPECT_LENGTH_N(3, kExprGetGlobal, U32V_2(33)); |
1902 EXPECT_LENGTH_N(4, kExprLoadGlobal, U32V_3(44)); | 1902 EXPECT_LENGTH_N(4, kExprGetGlobal, U32V_3(44)); |
1903 EXPECT_LENGTH_N(5, kExprLoadGlobal, U32V_4(66)); | 1903 EXPECT_LENGTH_N(5, kExprGetGlobal, U32V_4(66)); |
1904 EXPECT_LENGTH_N(6, kExprLoadGlobal, U32V_5(77)); | 1904 EXPECT_LENGTH_N(6, kExprGetGlobal, U32V_5(77)); |
1905 } | 1905 } |
1906 | 1906 |
1907 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { | 1907 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { |
1908 EXPECT_LENGTH(3, kExprI32LoadMem8S); | 1908 EXPECT_LENGTH(3, kExprI32LoadMem8S); |
1909 EXPECT_LENGTH(3, kExprI32LoadMem8U); | 1909 EXPECT_LENGTH(3, kExprI32LoadMem8U); |
1910 EXPECT_LENGTH(3, kExprI32LoadMem16S); | 1910 EXPECT_LENGTH(3, kExprI32LoadMem16S); |
1911 EXPECT_LENGTH(3, kExprI32LoadMem16U); | 1911 EXPECT_LENGTH(3, kExprI32LoadMem16U); |
1912 EXPECT_LENGTH(3, kExprI32LoadMem); | 1912 EXPECT_LENGTH(3, kExprI32LoadMem); |
1913 EXPECT_LENGTH(3, kExprI64LoadMem8S); | 1913 EXPECT_LENGTH(3, kExprI64LoadMem8S); |
1914 EXPECT_LENGTH(3, kExprI64LoadMem8U); | 1914 EXPECT_LENGTH(3, kExprI64LoadMem8U); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 } | 2100 } |
2101 | 2101 |
2102 TEST_F(WasmOpcodeArityTest, Misc) { | 2102 TEST_F(WasmOpcodeArityTest, Misc) { |
2103 EXPECT_ARITY(0, kExprI8Const); | 2103 EXPECT_ARITY(0, kExprI8Const); |
2104 EXPECT_ARITY(0, kExprI32Const); | 2104 EXPECT_ARITY(0, kExprI32Const); |
2105 EXPECT_ARITY(0, kExprF32Const); | 2105 EXPECT_ARITY(0, kExprF32Const); |
2106 EXPECT_ARITY(0, kExprI64Const); | 2106 EXPECT_ARITY(0, kExprI64Const); |
2107 EXPECT_ARITY(0, kExprF64Const); | 2107 EXPECT_ARITY(0, kExprF64Const); |
2108 EXPECT_ARITY(0, kExprGetLocal); | 2108 EXPECT_ARITY(0, kExprGetLocal); |
2109 EXPECT_ARITY(1, kExprSetLocal); | 2109 EXPECT_ARITY(1, kExprSetLocal); |
2110 EXPECT_ARITY(0, kExprLoadGlobal); | 2110 EXPECT_ARITY(0, kExprGetGlobal); |
2111 EXPECT_ARITY(1, kExprStoreGlobal); | 2111 EXPECT_ARITY(1, kExprSetGlobal); |
2112 } | 2112 } |
2113 | 2113 |
2114 TEST_F(WasmOpcodeArityTest, Calls) { | 2114 TEST_F(WasmOpcodeArityTest, Calls) { |
2115 { | 2115 { |
2116 EXPECT_ARITY(2, kExprCallFunction, 2, 0); | 2116 EXPECT_ARITY(2, kExprCallFunction, 2, 0); |
2117 EXPECT_ARITY(2, kExprCallImport, 2, 0); | 2117 EXPECT_ARITY(2, kExprCallImport, 2, 0); |
2118 EXPECT_ARITY(3, kExprCallIndirect, 2, 0); | 2118 EXPECT_ARITY(3, kExprCallIndirect, 2, 0); |
2119 | 2119 |
2120 EXPECT_ARITY(1, kExprBr, ARITY_1); | 2120 EXPECT_ARITY(1, kExprBr, ARITY_1); |
2121 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | 2121 EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 iter.next(); | 2464 iter.next(); |
2465 EXPECT_TRUE(iter.has_next()); | 2465 EXPECT_TRUE(iter.has_next()); |
2466 EXPECT_EQ(kExprI8Const, iter.current()); | 2466 EXPECT_EQ(kExprI8Const, iter.current()); |
2467 iter.next(); | 2467 iter.next(); |
2468 EXPECT_FALSE(iter.has_next()); | 2468 EXPECT_FALSE(iter.has_next()); |
2469 } | 2469 } |
2470 | 2470 |
2471 } // namespace wasm | 2471 } // namespace wasm |
2472 } // namespace internal | 2472 } // namespace internal |
2473 } // namespace v8 | 2473 } // namespace v8 |
OLD | NEW |