| 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 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 | 1147 |
| 1148 namespace { | 1148 namespace { |
| 1149 // A helper for tests that require a module environment for functions and | 1149 // A helper for tests that require a module environment for functions and |
| 1150 // globals. | 1150 // globals. |
| 1151 class TestModuleEnv : public ModuleEnv { | 1151 class TestModuleEnv : public ModuleEnv { |
| 1152 public: | 1152 public: |
| 1153 TestModuleEnv() { | 1153 TestModuleEnv() { |
| 1154 instance = nullptr; | 1154 instance = nullptr; |
| 1155 module = &mod; | 1155 module = &mod; |
| 1156 } | 1156 } |
| 1157 byte AddGlobal(MachineType mem_type) { | 1157 byte AddGlobal(LocalType type) { |
| 1158 mod.globals.push_back({0, 0, mem_type, 0, false}); | 1158 mod.globals.push_back({0, 0, type, 0, false}); |
| 1159 CHECK(mod.globals.size() <= 127); | 1159 CHECK(mod.globals.size() <= 127); |
| 1160 return static_cast<byte>(mod.globals.size() - 1); | 1160 return static_cast<byte>(mod.globals.size() - 1); |
| 1161 } | 1161 } |
| 1162 byte AddSignature(FunctionSig* sig) { | 1162 byte AddSignature(FunctionSig* sig) { |
| 1163 mod.signatures.push_back(sig); | 1163 mod.signatures.push_back(sig); |
| 1164 CHECK(mod.signatures.size() <= 127); | 1164 CHECK(mod.signatures.size() <= 127); |
| 1165 return static_cast<byte>(mod.signatures.size() - 1); | 1165 return static_cast<byte>(mod.signatures.size() - 1); |
| 1166 } | 1166 } |
| 1167 byte AddFunction(FunctionSig* sig) { | 1167 byte AddFunction(FunctionSig* sig) { |
| 1168 mod.functions.push_back({sig, // sig | 1168 mod.functions.push_back({sig, // sig |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(16))); | 1338 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(16))); |
| 1339 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I64V_1(16))); | 1339 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I64V_1(16))); |
| 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(MachineType::Int8()); | 1348 module_env.AddGlobal(kAstI32); |
| 1349 module_env.AddGlobal(MachineType::Uint8()); | |
| 1350 module_env.AddGlobal(MachineType::Int16()); | |
| 1351 module_env.AddGlobal(MachineType::Uint16()); | |
| 1352 module_env.AddGlobal(MachineType::Int32()); | |
| 1353 module_env.AddGlobal(MachineType::Uint32()); | |
| 1354 | 1349 |
| 1355 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1350 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); |
| 1356 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1)); | |
| 1357 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(2)); | |
| 1358 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(3)); | |
| 1359 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(4)); | |
| 1360 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(5)); | |
| 1361 | |
| 1362 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1351 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1363 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); | |
| 1364 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); | |
| 1365 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); | |
| 1366 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(4, WASM_GET_LOCAL(0))); | |
| 1367 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(5, WASM_GET_LOCAL(0))); | |
| 1368 } | 1352 } |
| 1369 | 1353 |
| 1370 TEST_F(AstDecoderTest, Int32Globals_fail) { | 1354 TEST_F(AstDecoderTest, Int32Globals_fail) { |
| 1371 FunctionSig* sig = sigs.i_i(); | 1355 FunctionSig* sig = sigs.i_i(); |
| 1372 TestModuleEnv module_env; | 1356 TestModuleEnv module_env; |
| 1373 module = &module_env; | 1357 module = &module_env; |
| 1374 | 1358 |
| 1375 module_env.AddGlobal(MachineType::Int64()); | 1359 module_env.AddGlobal(kAstI64); |
| 1376 module_env.AddGlobal(MachineType::Uint64()); | 1360 module_env.AddGlobal(kAstI64); |
| 1377 module_env.AddGlobal(MachineType::Float32()); | 1361 module_env.AddGlobal(kAstF32); |
| 1378 module_env.AddGlobal(MachineType::Float64()); | 1362 module_env.AddGlobal(kAstF64); |
| 1379 | 1363 |
| 1380 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1364 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(0)); |
| 1381 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(1)); | 1365 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(1)); |
| 1382 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(2)); | 1366 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(2)); |
| 1383 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(3)); | 1367 EXPECT_FAILURE_INLINE(sig, WASM_LOAD_GLOBAL(3)); |
| 1384 | 1368 |
| 1385 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1369 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1386 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); | 1370 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); |
| 1387 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); | 1371 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(2, WASM_GET_LOCAL(0))); |
| 1388 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); | 1372 EXPECT_FAILURE_INLINE(sig, WASM_STORE_GLOBAL(3, WASM_GET_LOCAL(0))); |
| 1389 } | 1373 } |
| 1390 | 1374 |
| 1391 TEST_F(AstDecoderTest, Int64Globals) { | 1375 TEST_F(AstDecoderTest, Int64Globals) { |
| 1392 FunctionSig* sig = sigs.l_l(); | 1376 FunctionSig* sig = sigs.l_l(); |
| 1393 TestModuleEnv module_env; | 1377 TestModuleEnv module_env; |
| 1394 module = &module_env; | 1378 module = &module_env; |
| 1395 | 1379 |
| 1396 module_env.AddGlobal(MachineType::Int64()); | 1380 module_env.AddGlobal(kAstI64); |
| 1397 module_env.AddGlobal(MachineType::Uint64()); | 1381 module_env.AddGlobal(kAstI64); |
| 1398 | 1382 |
| 1399 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1383 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); |
| 1400 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1)); | 1384 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(1)); |
| 1401 | 1385 |
| 1402 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1386 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1403 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); | 1387 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(1, WASM_GET_LOCAL(0))); |
| 1404 } | 1388 } |
| 1405 | 1389 |
| 1406 TEST_F(AstDecoderTest, Float32Globals) { | 1390 TEST_F(AstDecoderTest, Float32Globals) { |
| 1407 FunctionSig* sig = sigs.f_ff(); | 1391 FunctionSig* sig = sigs.f_ff(); |
| 1408 TestModuleEnv module_env; | 1392 TestModuleEnv module_env; |
| 1409 module = &module_env; | 1393 module = &module_env; |
| 1410 | 1394 |
| 1411 module_env.AddGlobal(MachineType::Float32()); | 1395 module_env.AddGlobal(kAstF32); |
| 1412 | 1396 |
| 1413 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1397 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); |
| 1414 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1398 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1415 } | 1399 } |
| 1416 | 1400 |
| 1417 TEST_F(AstDecoderTest, Float64Globals) { | 1401 TEST_F(AstDecoderTest, Float64Globals) { |
| 1418 FunctionSig* sig = sigs.d_dd(); | 1402 FunctionSig* sig = sigs.d_dd(); |
| 1419 TestModuleEnv module_env; | 1403 TestModuleEnv module_env; |
| 1420 module = &module_env; | 1404 module = &module_env; |
| 1421 | 1405 |
| 1422 module_env.AddGlobal(MachineType::Float64()); | 1406 module_env.AddGlobal(kAstF64); |
| 1423 | 1407 |
| 1424 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); | 1408 EXPECT_VERIFIES_INLINE(sig, WASM_LOAD_GLOBAL(0)); |
| 1425 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1409 EXPECT_VERIFIES_INLINE(sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1426 } | 1410 } |
| 1427 | 1411 |
| 1428 TEST_F(AstDecoderTest, AllLoadGlobalCombinations) { | 1412 TEST_F(AstDecoderTest, AllLoadGlobalCombinations) { |
| 1429 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1413 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
| 1430 LocalType local_type = kLocalTypes[i]; | 1414 LocalType local_type = kLocalTypes[i]; |
| 1431 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1415 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
| 1432 MachineType mem_type = machineTypes[j]; | 1416 LocalType global_type = kLocalTypes[j]; |
| 1433 FunctionSig sig(1, 0, &local_type); | 1417 FunctionSig sig(1, 0, &local_type); |
| 1434 TestModuleEnv module_env; | 1418 TestModuleEnv module_env; |
| 1435 module = &module_env; | 1419 module = &module_env; |
| 1436 module_env.AddGlobal(mem_type); | 1420 module_env.AddGlobal(global_type); |
| 1437 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1421 if (local_type == global_type) { |
| 1438 EXPECT_VERIFIES_INLINE(&sig, WASM_LOAD_GLOBAL(0)); | 1422 EXPECT_VERIFIES_INLINE(&sig, WASM_LOAD_GLOBAL(0)); |
| 1439 } else { | 1423 } else { |
| 1440 EXPECT_FAILURE_INLINE(&sig, WASM_LOAD_GLOBAL(0)); | 1424 EXPECT_FAILURE_INLINE(&sig, WASM_LOAD_GLOBAL(0)); |
| 1441 } | 1425 } |
| 1442 } | 1426 } |
| 1443 } | 1427 } |
| 1444 } | 1428 } |
| 1445 | 1429 |
| 1446 TEST_F(AstDecoderTest, AllStoreGlobalCombinations) { | 1430 TEST_F(AstDecoderTest, AllStoreGlobalCombinations) { |
| 1447 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1431 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
| 1448 LocalType local_type = kLocalTypes[i]; | 1432 LocalType local_type = kLocalTypes[i]; |
| 1449 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1433 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
| 1450 MachineType mem_type = machineTypes[j]; | 1434 LocalType global_type = kLocalTypes[j]; |
| 1451 FunctionSig sig(0, 1, &local_type); | 1435 FunctionSig sig(0, 1, &local_type); |
| 1452 TestModuleEnv module_env; | 1436 TestModuleEnv module_env; |
| 1453 module = &module_env; | 1437 module = &module_env; |
| 1454 module_env.AddGlobal(mem_type); | 1438 module_env.AddGlobal(global_type); |
| 1455 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1439 if (local_type == global_type) { |
| 1456 EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1440 EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1457 } else { | 1441 } else { |
| 1458 EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); | 1442 EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); |
| 1459 } | 1443 } |
| 1460 } | 1444 } |
| 1461 } | 1445 } |
| 1462 } | 1446 } |
| 1463 | 1447 |
| 1464 TEST_F(AstDecoderTest, BreakEnd) { | 1448 TEST_F(AstDecoderTest, BreakEnd) { |
| 1465 EXPECT_VERIFIES_INLINE(sigs.i_i(), | 1449 EXPECT_VERIFIES_INLINE(sigs.i_i(), |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2480 iter.next(); | 2464 iter.next(); |
| 2481 EXPECT_TRUE(iter.has_next()); | 2465 EXPECT_TRUE(iter.has_next()); |
| 2482 EXPECT_EQ(kExprI8Const, iter.current()); | 2466 EXPECT_EQ(kExprI8Const, iter.current()); |
| 2483 iter.next(); | 2467 iter.next(); |
| 2484 EXPECT_FALSE(iter.has_next()); | 2468 EXPECT_FALSE(iter.has_next()); |
| 2485 } | 2469 } |
| 2486 | 2470 |
| 2487 } // namespace wasm | 2471 } // namespace wasm |
| 2488 } // namespace internal | 2472 } // namespace internal |
| 2489 } // namespace v8 | 2473 } // namespace v8 |
| OLD | NEW |