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