Commit 6709edd7 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Make WasmRunner the central test structure

The WasmRunner now always holds a TestingModule, and allows to add
several functions to it. The prepares a change to always run wasm code
with a full module behind it, removing the special handling for "no wasm
instance" at runtime (http://crrev.com/2551053002).
This CL here also templatizes the WasmRunner such that the Call method must
be called with the same signature specified for the WasmRunner. This
already catched several mismatches there.

R=titzer@chromium.org, ahaas@chromium.org
BUG=v8:5620

Review-Url: https://codereview.chromium.org/2551043002
Cr-Original-Commit-Position: refs/heads/master@{#41728}
Committed: https://chromium.googlesource.com/v8/v8/+/2ff59062314e9b86bcc28dfaa53cedf2d98e3a13
Review-Url: https://codereview.chromium.org/2551043002
Cr-Commit-Position: refs/heads/master@{#41747}
parent 4bd0cbdd
......@@ -120,7 +120,7 @@ WASM_EXEC_TEST(I64Const_many) {
WASM_EXEC_TEST(Return_I64) {
REQUIRE(I64Return);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_RETURN1(WASM_GET_LOCAL(0)));
......@@ -129,8 +129,7 @@ WASM_EXEC_TEST(Return_I64) {
WASM_EXEC_TEST(I64Add) {
REQUIRE(I64Add);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i + *j, r.Call(*i, *j)); }
......@@ -139,8 +138,7 @@ WASM_EXEC_TEST(I64Add) {
WASM_EXEC_TEST(I64Sub) {
REQUIRE(I64Sub);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i - *j, r.Call(*i, *j)); }
......@@ -150,8 +148,7 @@ WASM_EXEC_TEST(I64Sub) {
WASM_EXEC_TEST(I64AddUseOnlyLowWord) {
REQUIRE(I64Add);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
......@@ -164,8 +161,7 @@ WASM_EXEC_TEST(I64AddUseOnlyLowWord) {
WASM_EXEC_TEST(I64SubUseOnlyLowWord) {
REQUIRE(I64Sub);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
......@@ -178,8 +174,7 @@ WASM_EXEC_TEST(I64SubUseOnlyLowWord) {
WASM_EXEC_TEST(I64MulUseOnlyLowWord) {
REQUIRE(I64Mul);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
......@@ -192,8 +187,7 @@ WASM_EXEC_TEST(I64MulUseOnlyLowWord) {
WASM_EXEC_TEST(I64ShlUseOnlyLowWord) {
REQUIRE(I64Shl);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
......@@ -207,8 +201,7 @@ WASM_EXEC_TEST(I64ShlUseOnlyLowWord) {
WASM_EXEC_TEST(I64ShrUseOnlyLowWord) {
REQUIRE(I64ShrU);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_UINT64_INPUTS(i) {
......@@ -222,8 +215,7 @@ WASM_EXEC_TEST(I64ShrUseOnlyLowWord) {
WASM_EXEC_TEST(I64SarUseOnlyLowWord) {
REQUIRE(I64ShrS);
REQUIRE(I32ConvertI64);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I32_CONVERT_I64(
WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_INT64_INPUTS(i) {
......@@ -236,8 +228,7 @@ WASM_EXEC_TEST(I64SarUseOnlyLowWord) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS) {
REQUIRE(I64DivS);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) {
......@@ -254,8 +245,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) {
REQUIRE(I64DivS);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(0, r.Call(asi64(0), asi64(100)));
CHECK_TRAP64(r.Call(asi64(100), asi64(0)));
......@@ -267,7 +257,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) {
REQUIRE(I64DivS);
for (int8_t denom = -2; denom < 8; denom++) {
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
for (int64_t val = -7; val < 8; val++) {
if (denom == 0) {
......@@ -281,8 +271,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivS_Byzero_Const) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU) {
REQUIRE(I64DivU);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) {
......@@ -297,10 +286,9 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) {
REQUIRE(I64DivU);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(0u, r.Call(asu64(0), asu64(100)));
CHECK_EQ(0, r.Call(asu64(0), asu64(100)));
CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
......@@ -309,7 +297,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) {
REQUIRE(I64DivU);
for (uint64_t denom = 0xfffffffffffffffe; denom < 8; denom++) {
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64());
WasmRunner<uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(denom)));
for (uint64_t val = 0xfffffffffffffff0; val < 8; val++) {
......@@ -324,8 +312,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64DivU_Byzero_Const) {
WASM_EXEC_TEST_WITH_TRAP(I64RemS) {
REQUIRE(I64RemS);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) {
......@@ -340,8 +327,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS) {
WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) {
REQUIRE(I64RemS);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(33, r.Call(asi64(133), asi64(100)));
CHECK_EQ(0, r.Call(std::numeric_limits<int64_t>::min(), asi64(-1)));
......@@ -352,8 +338,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemS_Trap) {
WASM_EXEC_TEST_WITH_TRAP(I64RemU) {
REQUIRE(I64RemU);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) {
......@@ -368,10 +353,9 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU) {
WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) {
REQUIRE(I64RemU);
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17u, r.Call(asu64(217), asu64(100)));
CHECK_EQ(17, r.Call(asu64(217), asu64(100)));
CHECK_TRAP64(r.Call(asu64(100), asu64(0)));
CHECK_TRAP64(r.Call(asu64(1001), asu64(0)));
CHECK_TRAP64(r.Call(std::numeric_limits<uint64_t>::max(), asu64(0)));
......@@ -379,8 +363,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64RemU_Trap) {
WASM_EXEC_TEST(I64And) {
REQUIRE(I64And);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) & (*j), r.Call(*i, *j)); }
......@@ -389,8 +372,7 @@ WASM_EXEC_TEST(I64And) {
WASM_EXEC_TEST(I64Ior) {
REQUIRE(I64Ior);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) | (*j), r.Call(*i, *j)); }
......@@ -399,8 +381,7 @@ WASM_EXEC_TEST(I64Ior) {
WASM_EXEC_TEST(I64Xor) {
REQUIRE(I64Xor);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ((*i) ^ (*j), r.Call(*i, *j)); }
......@@ -410,8 +391,7 @@ WASM_EXEC_TEST(I64Xor) {
WASM_EXEC_TEST(I64Shl) {
REQUIRE(I64Shl);
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
......@@ -422,22 +402,22 @@ WASM_EXEC_TEST(I64Shl) {
}
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 0, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 32, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 20, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i << 40, r.Call(*i)); }
}
......@@ -446,8 +426,7 @@ WASM_EXEC_TEST(I64Shl) {
WASM_EXEC_TEST(I64ShrU) {
REQUIRE(I64ShrU);
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Uint64(),
MachineType::Uint64());
WasmRunner<uint64_t, uint64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
......@@ -458,22 +437,22 @@ WASM_EXEC_TEST(I64ShrU) {
}
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); }
}
{
WasmRunner<uint64_t> r(execution_mode, MachineType::Int64());
WasmRunner<uint64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); }
}
......@@ -482,8 +461,7 @@ WASM_EXEC_TEST(I64ShrU) {
WASM_EXEC_TEST(I64ShrS) {
REQUIRE(I64ShrS);
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
......@@ -494,22 +472,22 @@ WASM_EXEC_TEST(I64ShrS) {
}
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 0, r.Call(*i)); }
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(32)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 32, r.Call(*i)); }
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(20)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 20, r.Call(*i)); }
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(40)));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i >> 40, r.Call(*i)); }
}
......@@ -517,8 +495,7 @@ WASM_EXEC_TEST(I64ShrS) {
WASM_EXEC_TEST(I64Eq) {
REQUIRE(I64Eq);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i == *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -527,8 +504,7 @@ WASM_EXEC_TEST(I64Eq) {
WASM_EXEC_TEST(I64Ne) {
REQUIRE(I64Ne);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i != *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -537,8 +513,7 @@ WASM_EXEC_TEST(I64Ne) {
WASM_EXEC_TEST(I64LtS) {
REQUIRE(I64LtS);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -547,8 +522,7 @@ WASM_EXEC_TEST(I64LtS) {
WASM_EXEC_TEST(I64LeS) {
REQUIRE(I64LeS);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -557,8 +531,7 @@ WASM_EXEC_TEST(I64LeS) {
WASM_EXEC_TEST(I64LtU) {
REQUIRE(I64LtU);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i < *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -567,8 +540,7 @@ WASM_EXEC_TEST(I64LtU) {
WASM_EXEC_TEST(I64LeU) {
REQUIRE(I64LeU);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i <= *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -577,8 +549,7 @@ WASM_EXEC_TEST(I64LeU) {
WASM_EXEC_TEST(I64GtS) {
REQUIRE(I64GtS);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -587,8 +558,7 @@ WASM_EXEC_TEST(I64GtS) {
WASM_EXEC_TEST(I64GeS) {
REQUIRE(I64GeS);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -597,8 +567,7 @@ WASM_EXEC_TEST(I64GeS) {
WASM_EXEC_TEST(I64GtU) {
REQUIRE(I64GtU);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i > *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -607,8 +576,7 @@ WASM_EXEC_TEST(I64GtU) {
WASM_EXEC_TEST(I64GeU) {
REQUIRE(I64GeU);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
FOR_UINT64_INPUTS(j) { CHECK_EQ(*i >= *j ? 1 : 0, r.Call(*i, *j)); }
......@@ -626,14 +594,14 @@ WASM_EXEC_TEST(I32ConvertI64) {
WASM_EXEC_TEST(I64SConvertI32) {
REQUIRE(I64SConvertI32);
WasmRunner<int64_t> r(execution_mode, MachineType::Int32());
WasmRunner<int64_t, int32_t> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(I64UConvertI32) {
REQUIRE(I64UConvertI32);
WasmRunner<int64_t> r(execution_mode, MachineType::Uint32());
WasmRunner<int64_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_I32(WASM_GET_LOCAL(0)));
FOR_UINT32_INPUTS(i) { CHECK_EQ(static_cast<int64_t>(*i), r.Call(*i)); }
}
......@@ -648,7 +616,7 @@ WASM_EXEC_TEST(I64Popcnt) {
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
WasmRunner<int64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
......@@ -657,7 +625,7 @@ WASM_EXEC_TEST(I64Popcnt) {
WASM_EXEC_TEST(F32SConvertI64) {
REQUIRE(F32SConvertI64);
WasmRunner<float> r(execution_mode, MachineType::Int64());
WasmRunner<float, int64_t> r(execution_mode);
BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_FLOAT_EQ(static_cast<float>(*i), r.Call(*i)); }
}
......@@ -743,7 +711,7 @@ WASM_EXEC_TEST(F32UConvertI64) {
{0x8000008000000001, 0x5f000001},
{0x8000000000000400, 0x5f000000},
{0x8000000000000401, 0x5f000000}};
WasmRunner<float> r(execution_mode, MachineType::Uint64());
WasmRunner<float, uint64_t> r(execution_mode);
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input));
......@@ -752,7 +720,7 @@ WASM_EXEC_TEST(F32UConvertI64) {
WASM_EXEC_TEST(F64SConvertI64) {
REQUIRE(F64SConvertI64);
WasmRunner<double> r(execution_mode, MachineType::Int64());
WasmRunner<double, int64_t> r(execution_mode);
BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_DOUBLE_EQ(static_cast<double>(*i), r.Call(*i)); }
}
......@@ -837,7 +805,7 @@ WASM_EXEC_TEST(F64UConvertI64) {
{0x8000008000000001, 0x43e0000010000000},
{0x8000000000000400, 0x43e0000000000000},
{0x8000000000000401, 0x43e0000000000001}};
WasmRunner<double> r(execution_mode, MachineType::Uint64());
WasmRunner<double, uint64_t> r(execution_mode);
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input));
......@@ -845,7 +813,7 @@ WASM_EXEC_TEST(F64UConvertI64) {
}
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) {
WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
WasmRunner<int64_t, float> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -859,7 +827,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) {
WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
WasmRunner<int64_t, double> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -873,7 +841,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) {
WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
WasmRunner<uint64_t, float> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -887,7 +855,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32a) {
}
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) {
WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
WasmRunner<uint64_t, double> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -901,28 +869,23 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64a) {
}
WASM_EXEC_TEST(CallI64Parameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstI64;
param_types[3] = kAstI32;
param_types[4] = kAstI32;
FunctionSig sig(1, 19, param_types);
for (int i = 0; i < 19; i++) {
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
if (i == 2 || i == 3) {
continue;
} else {
BUILD(t, WASM_GET_LOCAL(i));
}
uint32_t index = t.CompileAndAdd();
if (i == 2 || i == 3) continue;
WasmRunner<int32_t> r(execution_mode);
// Build the target function.
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(i));
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(
r,
WASM_I32_CONVERT_I64(WASM_CALL_FUNCTION(
index, WASM_I64V_9(0xbcd12340000000b),
t.function_index(), WASM_I64V_9(0xbcd12340000000b),
WASM_I64V_9(0xbcd12340000000c), WASM_I32V_1(0xd),
WASM_I32_CONVERT_I64(WASM_I64V_9(0xbcd12340000000e)),
WASM_I64V_9(0xbcd12340000000f), WASM_I64V_10(0xbcd1234000000010),
......@@ -947,8 +910,7 @@ void TestI64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
......@@ -964,8 +926,7 @@ void TestI64Cmp(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int32_t, int64_t, int64_t> r(execution_mode);
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
......@@ -1068,7 +1029,7 @@ WASM_EXEC_TEST(I64Clz) {
{62, 0x0000000000000002}, {63, 0x0000000000000001},
{64, 0x0000000000000000}};
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
WasmRunner<int64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_CLZ(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
......@@ -1114,7 +1075,7 @@ WASM_EXEC_TEST(I64Ctz) {
{2, 0x000000009afdbc84}, {1, 0x000000009afdbc82},
{0, 0x000000009afdbc81}};
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
WasmRunner<int64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_CTZ(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
......@@ -1132,7 +1093,7 @@ WASM_EXEC_TEST(I64Popcnt2) {
{26, 0x1123456782345678},
{38, 0xffedcba09edcba09}};
WasmRunner<int64_t> r(execution_mode, MachineType::Uint64());
WasmRunner<int64_t, uint64_t> r(execution_mode);
BUILD(r, WASM_I64_POPCNT(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(values[i].expected, r.Call(values[i].input));
......@@ -1150,21 +1111,19 @@ WASM_EXEC_TEST(I64WasmRunner) {
}
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT64_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT64_INPUTS(i) {
FOR_INT64_INPUTS(j) { CHECK_EQ(*i ^ *j, r.Call(*i, *j)); }
}
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64(), MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0),
WASM_I64_XOR(WASM_GET_LOCAL(1), WASM_GET_LOCAL(2))));
FOR_INT64_INPUTS(i) {
......@@ -1176,9 +1135,7 @@ WASM_EXEC_TEST(I64WasmRunner) {
}
}
{
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64(), MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_XOR(WASM_GET_LOCAL(0),
WASM_I64_XOR(WASM_GET_LOCAL(1),
WASM_I64_XOR(WASM_GET_LOCAL(2),
......@@ -1196,16 +1153,15 @@ WASM_EXEC_TEST(I64WasmRunner) {
WASM_EXEC_TEST(Call_Int64Sub) {
REQUIRE(I64Sub);
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
// Build the target function.
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.l_ll(), &module);
WasmFunctionCompiler& t = r.NewFunction(sigs.l_ll());
BUILD(t, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
uint32_t index = t.CompileAndAdd();
// Build the caller function.
WasmRunner<int64_t> r(&module, MachineType::Int64(), MachineType::Int64());
BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
......@@ -1228,9 +1184,8 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
kExprI64LoadMem};
for (size_t m = 0; m < arraysize(loads); m++) {
TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(16);
WasmRunner<int64_t> r(&module);
WasmRunner<int64_t> r(execution_mode);
byte* memory = r.module().AddMemoryElems<byte>(16);
byte code[] = {
kExprI8Const, 8, // --
......@@ -1252,7 +1207,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
// Try a bunch of different negative values.
for (int i = -1; i >= -128; i -= 11) {
int size = 1 << m;
module.BlankMemory();
r.module().BlankMemory();
memory[size - 1] = static_cast<byte>(i); // set the high order byte.
int64_t expected = static_cast<int64_t>(i) << ((size - 1) * 8);
......@@ -1268,7 +1223,7 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) {
REQUIRE(I64SConvertF32);
WasmRunner<int64_t> r(execution_mode, MachineType::Float32());
WasmRunner<int64_t, float> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -1283,7 +1238,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF32b) {
WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) {
REQUIRE(I64SConvertF64);
WasmRunner<int64_t> r(execution_mode, MachineType::Float64());
WasmRunner<int64_t, double> r(execution_mode);
BUILD(r, WASM_I64_SCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -1298,7 +1253,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64SConvertF64b) {
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) {
REQUIRE(I64UConvertF32);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float32());
WasmRunner<uint64_t, float> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F32(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -1312,7 +1267,7 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF32b) {
WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) {
REQUIRE(I64UConvertF64);
WasmRunner<uint64_t> r(execution_mode, MachineType::Float64());
WasmRunner<uint64_t, double> r(execution_mode);
BUILD(r, WASM_I64_UCONVERT_F64(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -1326,25 +1281,23 @@ WASM_EXEC_TEST_WITH_TRAP(I64UConvertF64b) {
WASM_EXEC_TEST(I64ReinterpretF64) {
REQUIRE(I64ReinterpretF64);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module);
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
BUILD(r, WASM_I64_REINTERPRET_F64(
WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)));
FOR_INT32_INPUTS(i) {
int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
module.WriteMemory(&memory[0], expected);
r.module().WriteMemory(&memory[0], expected);
CHECK_EQ(expected, r.Call());
}
}
WASM_EXEC_TEST(F64ReinterpretI64) {
REQUIRE(F64ReinterpretI64);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
WasmRunner<int64_t> r(&module, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
BUILD(r, WASM_STORE_MEM(MachineType::Float64(), WASM_ZERO,
WASM_F64_REINTERPRET_I64(WASM_GET_LOCAL(0))),
......@@ -1353,47 +1306,45 @@ WASM_EXEC_TEST(F64ReinterpretI64) {
FOR_INT32_INPUTS(i) {
int64_t expected = static_cast<int64_t>(*i) * 0x300010001;
CHECK_EQ(expected, r.Call(expected));
CHECK_EQ(expected, module.ReadMemory<int64_t>(&memory[0]));
CHECK_EQ(expected, r.module().ReadMemory<int64_t>(&memory[0]));
}
}
WASM_EXEC_TEST(LoadMemI64) {
REQUIRE(I64LoadStore);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
module.RandomizeMemory(1111);
WasmRunner<int64_t> r(&module);
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0)));
module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
CHECK_EQ(0x33aabbccdd001122LL, r.Call());
module.WriteMemory<int64_t>(&memory[0], 77777777);
r.module().WriteMemory<int64_t>(&memory[0], 77777777);
CHECK_EQ(77777777, r.Call());
}
WASM_EXEC_TEST(LoadMemI64_alignment) {
REQUIRE(I64LoadStore);
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(8);
for (byte alignment = 0; alignment <= 3; alignment++) {
module.RandomizeMemory(1111);
WasmRunner<int64_t> r(&module);
WasmRunner<int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment));
module.WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call());
module.WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
r.module().WriteMemory<int64_t>(&memory[0], 0x33aabbccdd001122LL);
CHECK_EQ(0x33aabbccdd001122LL, r.Call());
module.WriteMemory<int64_t>(&memory[0], 77777777);
r.module().WriteMemory<int64_t>(&memory[0], 77777777);
CHECK_EQ(77777777, r.Call());
}
}
......@@ -1404,9 +1355,8 @@ WASM_EXEC_TEST(MemI64_Sum) {
REQUIRE(I64Sub);
REQUIRE(I64Phi);
const int kNumElems = 20;
TestingModule module(execution_mode);
uint64_t* memory = module.AddMemoryElems<uint64_t>(kNumElems);
WasmRunner<uint64_t> r(&module, MachineType::Int32());
WasmRunner<uint64_t, int32_t> r(execution_mode);
uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems);
const byte kSum = r.AllocateLocal(kAstI64);
BUILD(
......@@ -1423,10 +1373,10 @@ WASM_EXEC_TEST(MemI64_Sum) {
// Run 4 trials.
for (int i = 0; i < 3; i++) {
module.RandomizeMemory(i * 33);
r.module().RandomizeMemory(i * 33);
uint64_t expected = 0;
for (size_t j = kNumElems - 1; j > 0; j--) {
expected += module.ReadMemory(&memory[j]);
expected += r.module().ReadMemory(&memory[j]);
}
uint64_t result = r.Call(8 * (kNumElems - 1));
CHECK_EQ(expected, result);
......@@ -1434,20 +1384,19 @@ WASM_EXEC_TEST(MemI64_Sum) {
}
WASM_EXEC_TEST(StoreMemI64_alignment) {
TestingModule module(execution_mode);
int64_t* memory = module.AddMemoryElems<int64_t>(4);
const int64_t kWritten = 0x12345678abcd0011ll;
for (byte i = 0; i <= 3; i++) {
WasmRunner<int64_t> r(&module, MachineType::Int64());
WasmRunner<int64_t, int64_t> r(execution_mode);
int64_t* memory = r.module().AddMemoryElems<int64_t>(4);
BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, i,
WASM_GET_LOCAL(0)),
WASM_GET_LOCAL(0));
module.RandomizeMemory(1111);
module.WriteMemory<int64_t>(&memory[0], 0);
r.module().RandomizeMemory(1111);
r.module().WriteMemory<int64_t>(&memory[0], 0);
CHECK_EQ(kWritten, r.Call(kWritten));
CHECK_EQ(kWritten, module.ReadMemory(&memory[0]));
CHECK_EQ(kWritten, r.module().ReadMemory(&memory[0]));
}
}
......@@ -1456,16 +1405,15 @@ WASM_EXEC_TEST(I64Global) {
REQUIRE(I64SConvertI32);
REQUIRE(I64And);
REQUIRE(DepthFirst);
TestingModule module(execution_mode);
int64_t* global = module.AddGlobal<int64_t>(kAstI64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int64_t* global = r.module().AddGlobal<int64_t>();
// global = global + p0
BUILD(r, WASM_SET_GLOBAL(
0, WASM_I64_AND(WASM_GET_GLOBAL(0),
WASM_I64_SCONVERT_I32(WASM_GET_LOCAL(0)))),
WASM_ZERO);
module.WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL);
r.module().WriteMemory<int64_t>(global, 0xFFFFFFFFFFFFFFFFLL);
for (int i = 9; i < 444444; i += 111111) {
int64_t expected = *global & i;
r.Call(i);
......@@ -1476,7 +1424,7 @@ WASM_EXEC_TEST(I64Global) {
WASM_EXEC_TEST(I64Eqz) {
REQUIRE(I64Eq);
WasmRunner<int32_t> r(execution_mode, MachineType::Int64());
WasmRunner<int32_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_EQZ(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) {
......@@ -1487,8 +1435,7 @@ WASM_EXEC_TEST(I64Eqz) {
WASM_EXEC_TEST(I64Ror) {
REQUIRE(I64Ror);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
......@@ -1501,8 +1448,7 @@ WASM_EXEC_TEST(I64Ror) {
WASM_EXEC_TEST(I64Rol) {
REQUIRE(I64Rol);
WasmRunner<int64_t> r(execution_mode, MachineType::Int64(),
MachineType::Int64());
WasmRunner<int64_t, int64_t, int64_t> r(execution_mode);
BUILD(r, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT64_INPUTS(i) {
......@@ -1514,9 +1460,6 @@ WASM_EXEC_TEST(I64Rol) {
}
WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) {
TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(32);
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
......@@ -1524,8 +1467,9 @@ WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob_i64) {
MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); m++) {
module.RandomizeMemory(1119 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
WasmRunner<int32_t, uint32_t> r(execution_mode);
byte* memory = r.module().AddMemoryElems<byte>(32);
r.module().RandomizeMemory(1119 + static_cast<int>(m));
BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0),
WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
......@@ -1553,17 +1497,14 @@ static void CompileCallIndirectMany(LocalType param) {
// with many many parameters.
TestSignatures sigs;
for (byte num_params = 0; num_params < 40; num_params++) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
HandleScope scope(CcTest::InitIsolateOnce());
TestingModule module(kExecuteCompiled);
FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
WasmRunner<void> r(kExecuteCompiled);
FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params);
module.AddSignature(sig);
module.AddSignature(sig);
module.AddIndirectFunctionTable(nullptr, 0);
r.module().AddSignature(sig);
r.module().AddSignature(sig);
r.module().AddIndirectFunctionTable(nullptr, 0);
WasmFunctionCompiler t(sig, &module);
WasmFunctionCompiler& t = r.NewFunction(sig);
std::vector<byte> code;
for (byte p = 0; p < num_params; p++) {
......@@ -1573,7 +1514,6 @@ static void CompileCallIndirectMany(LocalType param) {
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
t.Compile();
}
}
......@@ -1595,28 +1535,25 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
for (int which = 0; which < num_params; which++) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
TestingModule module(execution_mode);
module.AddMemory(1024);
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemory(1024);
MachineType* memtypes = &mixed[start];
MachineType result = memtypes[which];
// =========================================================================
// Build the selector function.
// =========================================================================
uint32_t index;
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::LocalTypeFor(result));
for (int i = 0; i < num_params; i++) {
b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
}
WasmFunctionCompiler t(b.Build(), &module);
WasmFunctionCompiler& t = r.NewFunction(b.Build());
BUILD(t, WASM_GET_LOCAL(which));
index = t.CompileAndAdd();
// =========================================================================
// Build the calling function.
// =========================================================================
WasmRunner<int32_t> r(&module);
std::vector<byte> code;
// Load the offset for the store.
......@@ -1629,7 +1566,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
}
// Call the selector function.
ADD_CODE(code, kExprCallFunction, static_cast<byte>(index));
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in memory.
ADD_CODE(code,
......@@ -1643,14 +1580,14 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Run the code.
for (int t = 0; t < 10; t++) {
module.RandomizeMemory();
r.module().RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
for (int i = 0; i < size; i++) {
int base = (which + 1) * kElemSize;
byte expected = module.raw_mem_at<byte>(base + i);
byte result = module.raw_mem_at<byte>(i);
byte expected = r.module().raw_mem_at<byte>(base + i);
byte result = r.module().raw_mem_at<byte>(i);
CHECK_EQ(expected, result);
}
}
......
......@@ -38,9 +38,8 @@ uint32_t GetMatchingRelocInfoCount(Handle<Code> code, RelocInfo::Mode rmode) {
}
WASM_EXEC_TEST(Int32AsmjsDivS) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
......@@ -51,9 +50,8 @@ WASM_EXEC_TEST(Int32AsmjsDivS) {
}
WASM_EXEC_TEST(Int32AsmjsRemS) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprI32AsmjsRemS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(33, r.Call(133, 100));
......@@ -64,9 +62,8 @@ WASM_EXEC_TEST(Int32AsmjsRemS) {
}
WASM_EXEC_TEST(Int32AsmjsDivU) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprI32AsmjsDivU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
......@@ -77,9 +74,8 @@ WASM_EXEC_TEST(Int32AsmjsDivU) {
}
WASM_EXEC_TEST(Int32AsmjsRemU) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprI32AsmjsRemU, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(17, r.Call(217, 100));
......@@ -90,9 +86,8 @@ WASM_EXEC_TEST(Int32AsmjsRemU) {
}
WASM_EXEC_TEST(I32AsmjsSConvertF32) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Float32());
WasmRunner<int32_t, float> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -102,9 +97,8 @@ WASM_EXEC_TEST(I32AsmjsSConvertF32) {
}
WASM_EXEC_TEST(I32AsmjsSConvertF64) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Float64());
WasmRunner<int32_t, double> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprI32AsmjsSConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -114,9 +108,8 @@ WASM_EXEC_TEST(I32AsmjsSConvertF64) {
}
WASM_EXEC_TEST(I32AsmjsUConvertF32) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<uint32_t> r(&module, MachineType::Float32());
WasmRunner<uint32_t, float> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF32, WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -126,9 +119,8 @@ WASM_EXEC_TEST(I32AsmjsUConvertF32) {
}
WASM_EXEC_TEST(I32AsmjsUConvertF64) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<uint32_t> r(&module, MachineType::Float64());
WasmRunner<uint32_t, double> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprI32AsmjsUConvertF64, WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -138,11 +130,10 @@ WASM_EXEC_TEST(I32AsmjsUConvertF64) {
}
WASM_EXEC_TEST(LoadMemI32_oob_asm) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
WasmRunner<int32_t, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0)));
......@@ -159,11 +150,10 @@ WASM_EXEC_TEST(LoadMemI32_oob_asm) {
}
WASM_EXEC_TEST(LoadMemF32_oob_asm) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
float* memory = module.AddMemoryElems<float>(8);
WasmRunner<float> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
WasmRunner<float, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
float* memory = r.module().AddMemoryElems<float>(8);
r.module().RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0)));
......@@ -180,11 +170,10 @@ WASM_EXEC_TEST(LoadMemF32_oob_asm) {
}
WASM_EXEC_TEST(LoadMemF64_oob_asm) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
double* memory = module.AddMemoryElems<double>(8);
WasmRunner<double> r(&module, MachineType::Uint32());
module.RandomizeMemory(1112);
WasmRunner<double, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
double* memory = r.module().AddMemoryElems<double>(8);
r.module().RandomizeMemory(1112);
BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0)));
......@@ -203,11 +192,10 @@ WASM_EXEC_TEST(LoadMemF64_oob_asm) {
}
WASM_EXEC_TEST(StoreMemI32_oob_asm) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32());
module.RandomizeMemory(1112);
WasmRunner<int32_t, uint32_t, uint32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1112);
BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
......@@ -237,87 +225,78 @@ WASM_EXEC_TEST(StoreMemI32_oob_asm) {
TEST_BODY(kExprI32AsmjsStoreMem16) \
TEST_BODY(kExprI32AsmjsStoreMem)
#define INT_LOAD_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
TestingModule module(kExecuteCompiled); \
module.ChangeOriginToAsmjs(); \
WasmRunner<int32_t> r(&module, MachineType::Uint32()); \
BUILD(r, WASM_UNOP(OP_TYPE, WASM_GET_LOCAL(0))); \
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
#define INT_LOAD_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
WasmRunner<int32_t, uint32_t> r(kExecuteCompiled); \
r.module().ChangeOriginToAsmjs(); \
BUILD(r, WASM_UNOP(OP_TYPE, WASM_GET_LOCAL(0))); \
CHECK_EQ(1, \
GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0, GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
}
FOREACH_INT_CHECKED_LOAD_OP(INT_LOAD_TEST)
#define INT_STORE_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
TestingModule module(kExecuteCompiled); \
module.ChangeOriginToAsmjs(); \
WasmRunner<int32_t> r(&module, MachineType::Uint32(), \
MachineType::Uint32()); \
BUILD(r, WASM_BINOP(OP_TYPE, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); \
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0u, GetMatchingRelocInfoCount(module.instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
#define INT_STORE_TEST(OP_TYPE) \
TEST(RunWasm_AsmCheckedRelocInfo##OP_TYPE) { \
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteCompiled); \
r.module().ChangeOriginToAsmjs(); \
BUILD(r, WASM_BINOP(OP_TYPE, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); \
CHECK_EQ(1, \
GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
RelocInfo::WASM_MEMORY_REFERENCE)); \
CHECK_NE( \
0, GetMatchingRelocInfoCount(r.module().instance->function_code[0], \
RelocInfo::WASM_MEMORY_SIZE_REFERENCE)); \
}
FOREACH_INT_CHECKED_STORE_OP(INT_STORE_TEST)
TEST(RunWasm_AsmCheckedLoadFloat32RelocInfo) {
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<float> r(&module, MachineType::Uint32());
WasmRunner<float, uint32_t> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0)));
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedStoreFloat32RelocInfo) {
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<float> r(&module, MachineType::Uint32(), MachineType::Float32());
WasmRunner<float, uint32_t, float> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprF32AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedLoadFloat64RelocInfo) {
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<double> r(&module, MachineType::Uint32());
WasmRunner<double, uint32_t> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0)));
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
TEST(RunWasm_AsmCheckedStoreFloat64RelocInfo) {
TestingModule module(kExecuteCompiled);
module.ChangeOriginToAsmjs();
WasmRunner<double> r(&module, MachineType::Uint32(), MachineType::Float64());
WasmRunner<double, uint32_t, double> r(kExecuteCompiled);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_BINOP(kExprF64AsmjsStoreMem, WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
CHECK_EQ(1u, GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0u,
GetMatchingRelocInfoCount(module.instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
CHECK_EQ(1, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_REFERENCE));
CHECK_NE(0, GetMatchingRelocInfoCount(r.module().instance->function_code[0],
RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
}
......@@ -35,14 +35,14 @@ TEST(Run_WasmInt8Const_i) {
}
TEST(Run_WasmIfElse) {
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
CHECK_EQ(10, r.Call(0));
CHECK_EQ(9, r.Call(1));
}
TEST(Run_WasmIfReturn) {
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
CHECK_EQ(65, r.Call(0));
CHECK_EQ(77, r.Call(1));
......@@ -131,8 +131,7 @@ TEST(Run_WasmBlockBreakN) {
}
TEST(Run_Wasm_nested_ifs_i) {
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
......@@ -180,8 +179,7 @@ TEST(Breakpoint_I32Add) {
Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
kExprI32Add);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
r.Build(code, code + arraysize(code));
......@@ -220,8 +218,7 @@ TEST(Step_I32Mul) {
static const int kTraceLength = 4;
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
r.Build(code, code + arraysize(code));
......@@ -259,8 +256,7 @@ TEST(Breakpoint_I32And_disable) {
std::unique_ptr<int[]> offsets =
Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted);
r.Build(code, code + arraysize(code));
......@@ -297,9 +293,8 @@ TEST(Breakpoint_I32And_disable) {
}
TEST(GrowMemory) {
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(1, r.Call(1));
}
......@@ -307,9 +302,8 @@ TEST(GrowMemory) {
TEST(GrowMemoryPreservesData) {
int32_t index = 16;
int32_t value = 2335;
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value)),
WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
......@@ -320,16 +314,14 @@ TEST(GrowMemoryPreservesData) {
TEST(GrowMemoryInvalidSize) {
{
// Grow memory by an invalid amount without initial memory.
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575));
}
{
// Grow memory by an invalid amount without initial memory.
TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575));
}
......@@ -338,9 +330,7 @@ TEST(GrowMemoryInvalidSize) {
TEST(TestPossibleNondeterminism) {
{
// F32Div may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
WasmRunner<float, float, float> r(kExecuteInterpreted);
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism());
......@@ -349,8 +339,7 @@ TEST(TestPossibleNondeterminism) {
}
{
// F32Sqrt may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32());
WasmRunner<float, float> r(kExecuteInterpreted);
BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0)));
r.Call(16.0f);
CHECK(!r.possible_nondeterminism());
......@@ -359,9 +348,7 @@ TEST(TestPossibleNondeterminism) {
}
{
// F32Mul may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
WasmRunner<float, float, float> r(kExecuteInterpreted);
BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism());
......@@ -370,9 +357,7 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Div may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
WasmRunner<double, double, double> r(kExecuteInterpreted);
BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism());
......@@ -381,8 +366,7 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Sqrt may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64());
WasmRunner<double, double> r(kExecuteInterpreted);
BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0)));
r.Call(1048575.5);
CHECK(!r.possible_nondeterminism());
......@@ -391,9 +375,7 @@ TEST(TestPossibleNondeterminism) {
}
{
// F64Mul may produced NaN
TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
WasmRunner<double, double, double> r(kExecuteInterpreted);
BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism());
......
......@@ -97,48 +97,36 @@ void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
} // namespace
TEST(Run_Int32Sub_jswrapped) {
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_ii(), &module);
BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
WasmRunner<int, int, int> r(kExecuteCompiled);
BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
EXPECT_CALL(33, jsfunc, 44, 11);
EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
}
TEST(Run_Float32Div_jswrapped) {
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.f_ff(), &module);
BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
WasmRunner<float, float, float> r(kExecuteCompiled);
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
EXPECT_CALL(92, jsfunc, 46, 0.5);
EXPECT_CALL(64, jsfunc, -16, -0.25);
}
TEST(Run_Float64Add_jswrapped) {
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.d_dd(), &module);
BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
WasmRunner<double, double, double> r(kExecuteCompiled);
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
EXPECT_CALL(3, jsfunc, 2, 1);
EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
}
TEST(Run_I32Popcount_jswrapped) {
CcTest::InitializeVM();
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
WasmRunner<int, int> r(kExecuteCompiled);
BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
EXPECT_CALL(2, jsfunc, 9, 0);
EXPECT_CALL(3, jsfunc, 11, 0);
......@@ -146,15 +134,13 @@ TEST(Run_I32Popcount_jswrapped) {
}
TEST(Run_CallJS_Add_jswrapped) {
CcTest::InitializeVM();
WasmRunner<int, int> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
uint32_t js_index =
module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
r.module().AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index);
EXPECT_CALL(101, jsfunc, 2, -8);
EXPECT_CALL(199, jsfunc, 100, -1);
......@@ -171,9 +157,9 @@ void RunJSSelectTest(int which) {
HandleScope scope(CcTest::InitIsolateOnce());
FunctionSig sig(1, num_params, types);
TestingModule module;
uint32_t js_index = AddJSSelector(&module, &sig, which);
WasmFunctionCompiler t(&sig, &module);
WasmRunner<void> r(kExecuteCompiled);
uint32_t js_index = AddJSSelector(&r.module(), &sig, which);
WasmFunctionCompiler& t = r.NewFunction(&sig);
{
std::vector<byte> code;
......@@ -189,7 +175,7 @@ void RunJSSelectTest(int which) {
t.Build(&code[0], &code[end]);
}
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
}
......@@ -245,10 +231,10 @@ void RunWASMSelectTest(int which) {
type, type, type, type};
FunctionSig sig(1, num_params, types);
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
WasmRunner<void> r(kExecuteCompiled);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<Object> args[] = {
isolate->factory()->NewNumber(inputs.arg_d(0)),
......@@ -317,10 +303,10 @@ void RunWASMSelectAlignTest(int num_args, int num_params) {
FunctionSig sig(1, num_params, types);
for (int which = 0; which < num_params; which++) {
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
WasmRunner<void> r(kExecuteCompiled);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
isolate->factory()->NewNumber(inputs.arg_d(1)),
......@@ -411,6 +397,8 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
LocalType types[kMaxParams + 1] = {type, type, type, type, type, type,
type, type, type, type, type};
FunctionSig sig(1, num_params, types);
i::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
// Build the calling code.
std::vector<byte> code;
......@@ -419,21 +407,21 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
ADD_CODE(code, WASM_GET_LOCAL(i));
}
ADD_CODE(code, kExprCallFunction, 0);
uint8_t predicted_js_index = 1;
ADD_CODE(code, kExprCallFunction, predicted_js_index);
size_t end = code.size();
code.push_back(0);
// Call different select JS functions.
for (int which = 0; which < num_params; which++) {
HandleScope scope(isolate);
TestingModule module;
uint32_t js_index = AddJSSelector(&module, &sig, which);
CHECK_EQ(0u, js_index);
WasmFunctionCompiler t(&sig, &module);
WasmRunner<void> r(kExecuteCompiled);
uint32_t js_index = AddJSSelector(&r.module(), &sig, which);
CHECK_EQ(predicted_js_index, js_index);
WasmFunctionCompiler& t = r.NewFunction(&sig);
t.Build(&code[0], &code[end]);
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index());
Handle<Object> args[] = {
factory->NewNumber(inputs.arg_d(0)),
......
......@@ -13,31 +13,29 @@
using namespace v8::internal;
using namespace v8::internal::compiler;
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, I32, WASM_I32_ADD) \
TEST_BODY(int64_t, I64, WASM_I64_ADD) \
TEST_BODY(float, F32, WASM_F32_ADD) \
TEST_BODY(double, F64, WASM_F64_ADD)
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, WASM_I32_ADD) \
TEST_BODY(int64_t, WASM_I64_ADD) \
TEST_BODY(float, WASM_F32_ADD) \
TEST_BODY(double, WASM_F64_ADD)
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
TestingModule module(kExecuteCompiled); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \
TEST(WasmRelocateGlobal_##C_TYPE) { \
WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \
\
WasmRunner<C_TYPE> r(&module, \
WasmOpcodes::MachineTypeFor(kAst##MACHINE_TYPE)); \
r.module().AddGlobal<C_TYPE>(); \
r.module().AddGlobal<C_TYPE>(); \
\
/* global = global + p0 */ \
BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \
WASM_GET_GLOBAL(0)); \
CHECK_EQ(1u, module.instance->function_code.size()); \
CHECK_EQ(1, r.module().instance->function_code.size()); \
\
int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
\
Handle<Code> code = module.instance->function_code[0]; \
Handle<Code> code = r.module().instance->function_code[0]; \
\
Address old_start = module.instance->globals_start; \
Address old_start = r.module().instance->globals_start; \
Address new_start = old_start + 1; \
\
Address old_addresses[4]; \
......
......@@ -17,7 +17,7 @@ using namespace v8::internal::wasm;
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(5))));
FOR_INT32_INPUTS(i) { CHECK_EQ(5, r.Call()); }
......@@ -25,7 +25,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_ADD(WASM_SIMD_I32x4_SPLAT(WASM_I32V(5)),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(6)))));
......@@ -34,7 +34,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(9.5))),
......@@ -45,7 +45,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Splat) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_F32x4_SPLAT(WASM_F32(30.5))),
......@@ -56,7 +56,7 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Extract_With_F32x4) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(15))),
......@@ -67,7 +67,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Extract_With_I32x4) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(
WASM_F32_EQ(WASM_SIMD_F32x4_EXTRACT_LANE(
......@@ -82,7 +82,7 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Add_With_I32x4) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
BUILD(r,
WASM_IF_ELSE(
WASM_I32_EQ(WASM_SIMD_I32x4_EXTRACT_LANE(
......@@ -97,39 +97,39 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Add_With_F32x4) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Local) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_RETURN1(
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)))));
WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(0)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(31, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Replace_Lane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(0),
WASM_I32V(53))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)))));
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(0)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(53, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstF32);
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(2), WASM_F32(65.25))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(23.5))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(65.25))),
WASM_SET_LOCAL(
1, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(1), WASM_F32(65.25)),
0, WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1))),
WASM_IF(WASM_F32_EQ(WASM_GET_LOCAL(0), WASM_F32(65.25)),
WASM_RETURN1(WASM_I32V(1))),
WASM_RETURN1(WASM_I32V(0))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
......@@ -137,27 +137,26 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Replace_Lane) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Splat_From_Extract) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(r,
WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_EXTRACT_LANE(
WASM_SET_LOCAL(0, WASM_SIMD_I32x4_EXTRACT_LANE(
0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(76)))),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(1))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2)))));
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_GET_LOCAL(0))),
WASM_RETURN1(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(76, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
FLAG_wasm_simd_prototype = true;
TestingModule module(kExecuteCompiled);
int32_t* global = module.AddGlobal<int32_t>(kAstS128);
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
int32_t* global = r.module().AddGlobal<int32_t>(kAstS128);
*(global) = 0;
*(global + 1) = 1;
*(global + 2) = 2;
*(global + 3) = 3;
WasmRunner<int32_t> r(&module, MachineType::Int32());
r.AllocateLocal(kAstI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
......@@ -179,9 +178,8 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Get_Global) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
TestingModule module(kExecuteCompiled);
int32_t* global = module.AddGlobal<int32_t>(kAstS128);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
int32_t* global = r.module().AddGlobal<int32_t>(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_SPLAT(WASM_I32V(23))),
WASM_SET_GLOBAL(0, WASM_SIMD_I32x4_REPLACE_LANE(
......@@ -200,13 +198,12 @@ WASM_EXEC_COMPILED_TEST(Simd_I32x4_Set_Global) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
FLAG_wasm_simd_prototype = true;
TestingModule module(kExecuteCompiled);
float* global = module.AddGlobal<float>(kAstS128);
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
float* global = r.module().AddGlobal<float>(kAstS128);
*(global) = 0.0;
*(global + 1) = 1.5;
*(global + 2) = 2.25;
*(global + 3) = 3.5;
WasmRunner<int32_t> r(&module, MachineType::Int32());
r.AllocateLocal(kAstI32);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(1, WASM_I32V(1)),
......@@ -228,9 +225,8 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Get_Global) {
WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
FLAG_wasm_simd_prototype = true;
TestingModule module(kExecuteCompiled);
float* global = module.AddGlobal<float>(kAstS128);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
float* global = r.module().AddGlobal<float>(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_SPLAT(WASM_F32(13.5))),
WASM_SET_GLOBAL(0, WASM_SIMD_F32x4_REPLACE_LANE(
......@@ -249,69 +245,69 @@ WASM_EXEC_COMPILED_TEST(Simd_F32x4_Set_Global) {
WASM_EXEC_COMPILED_TEST(Simd_I32x4_For) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(
r,
WASM_BLOCK(
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(2),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_SPLAT(WASM_I32V(31))),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(1, WASM_GET_LOCAL(1),
WASM_I32V(53))),
WASM_SET_LOCAL(2, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(2),
WASM_SET_LOCAL(1, WASM_SIMD_I32x4_REPLACE_LANE(2, WASM_GET_LOCAL(1),
WASM_I32V(23))),
WASM_SET_LOCAL(1, WASM_I32V(0)),
WASM_LOOP(WASM_SET_LOCAL(2, WASM_SIMD_I32x4_ADD(
WASM_GET_LOCAL(2),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(WASM_SET_LOCAL(1, WASM_SIMD_I32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SIMD_I32x4_SPLAT(WASM_I32V(1)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(5)),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(5)),
WASM_BR(1))),
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(2)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(1, WASM_GET_LOCAL(1)),
WASM_I32V(58)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(2)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(2, WASM_GET_LOCAL(1)),
WASM_I32V(28)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)),
WASM_I32_NE(WASM_SIMD_I32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_I32V(36)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
WASM_EXEC_COMPILED_TEST(Simd_F32x4_For) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t> r(kExecuteCompiled);
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(2), WASM_F32(19.5))),
WASM_SET_LOCAL(1, WASM_I32V(0)),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_SPLAT(WASM_F32(21.25))),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_REPLACE_LANE(
3, WASM_GET_LOCAL(1), WASM_F32(19.5))),
WASM_SET_LOCAL(0, WASM_I32V(0)),
WASM_LOOP(
WASM_SET_LOCAL(2, WASM_SIMD_F32x4_ADD(
WASM_GET_LOCAL(2),
WASM_SET_LOCAL(1, WASM_SIMD_F32x4_ADD(
WASM_GET_LOCAL(1),
WASM_SIMD_F32x4_SPLAT(WASM_F32(2.0)))),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(1), WASM_I32V(3)),
WASM_IF(WASM_I32_NE(WASM_INC_LOCAL(0), WASM_I32V(3)),
WASM_BR(1))),
WASM_SET_LOCAL(1, WASM_I32V(1)),
WASM_SET_LOCAL(0, WASM_I32V(1)),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(2)),
WASM_SIMD_F32x4_EXTRACT_LANE(0, WASM_GET_LOCAL(1)),
WASM_F32(27.25)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_IF(WASM_F32_NE(
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(2)),
WASM_SIMD_F32x4_EXTRACT_LANE(3, WASM_GET_LOCAL(1)),
WASM_F32(25.5)),
WASM_SET_LOCAL(1, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(1))));
WASM_SET_LOCAL(0, WASM_I32V(0))),
WASM_RETURN1(WASM_GET_LOCAL(0))));
FOR_INT32_INPUTS(i) { CHECK_EQ(1, r.Call()); }
}
......@@ -45,7 +45,7 @@ WASM_EXEC_TEST(I32x4Splat) {
// return 0
//
// return 1
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
byte lane_val = 0;
byte simd = r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(
......@@ -58,8 +58,7 @@ WASM_EXEC_TEST(I32x4Splat) {
WASM_EXEC_TEST(I32x4ReplaceLane) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled);
byte old_val = 0;
byte new_val = 1;
byte simd = r.AllocateLocal(kAstS128);
......@@ -92,8 +91,7 @@ WASM_EXEC_TEST(I32x4ReplaceLane) {
WASM_EXEC_TEST(I32x4Add) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
byte a = 0;
byte b = 1;
byte expected = 2;
......@@ -115,8 +113,7 @@ WASM_EXEC_TEST(I32x4Add) {
WASM_EXEC_TEST(I32x4Sub) {
FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled);
byte a = 0;
byte b = 1;
byte expected = 2;
......
......@@ -81,29 +81,28 @@ WASM_EXEC_TEST(Int32Const_many) {
WASM_EXEC_TEST(GraphTrimming) {
// This WebAssembly code requires graph trimming in the TurboFan compiler.
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0, kExprI32RemS,
kExprI32Eq, kExprGetLocal, 0, kExprI32DivS, kExprUnreachable);
r.Call(1);
}
WASM_EXEC_TEST(Int32Param0) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// return(local[0])
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Param0_fallthru) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// local[0]
BUILD(r, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Param1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
// local[1]
BUILD(r, WASM_GET_LOCAL(1));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(-111, *i)); }
......@@ -117,14 +116,14 @@ WASM_EXEC_TEST(Int32Add) {
}
WASM_EXEC_TEST(Int32Add_P) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
}
WASM_EXEC_TEST(Int32Add_P_fallthru) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
......@@ -132,8 +131,7 @@ WASM_EXEC_TEST(Int32Add_P_fallthru) {
static void RunInt32AddTest(WasmExecutionMode execution_mode, const byte* code,
size_t size) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.Build(code, code + size);
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
......@@ -202,8 +200,7 @@ void TestInt32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
// a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
......@@ -252,7 +249,7 @@ void TestInt32Unop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// return op a
BUILD(r, WASM_UNOP(opcode, WASM_GET_LOCAL(0)));
CHECK_EQ(expected, r.Call(a));
......@@ -348,8 +345,7 @@ WASM_EXEC_TEST(I32Eqz) {
}
WASM_EXEC_TEST(I32Shl) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
......@@ -361,8 +357,7 @@ WASM_EXEC_TEST(I32Shl) {
}
WASM_EXEC_TEST(I32Shr) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_UINT32_INPUTS(i) {
......@@ -374,8 +369,7 @@ WASM_EXEC_TEST(I32Shr) {
}
WASM_EXEC_TEST(I32Sar) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
......@@ -387,8 +381,7 @@ WASM_EXEC_TEST(I32Sar) {
}
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
......@@ -399,8 +392,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) {
}
WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(33, r.Call(133, 100));
......@@ -411,8 +403,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) {
}
WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(0, 100));
......@@ -423,8 +414,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) {
}
WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(17, r.Call(217, 100));
const int32_t kMin = std::numeric_limits<int32_t>::min();
......@@ -436,7 +426,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) {
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
for (int32_t val = -7; val < 8; ++val) {
if (denom == 0) {
......@@ -450,9 +440,8 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) {
WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
FOR_INT32_INPUTS(i) {
if (denom == 0) {
......@@ -468,9 +457,8 @@ WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) {
WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) {
TestingModule module(execution_mode);
module.ChangeOriginToAsmjs();
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I8(denom)));
FOR_INT32_INPUTS(i) {
if (denom == 0) {
......@@ -486,7 +474,7 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) {
WASM_EXEC_TEST_WITH_TRAP(Int32DivU_byzero_const) {
for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32());
WasmRunner<uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
for (uint32_t val = 0xfffffff0; val < 8; ++val) {
......@@ -500,9 +488,8 @@ WASM_EXEC_TEST_WITH_TRAP(Int32DivU_byzero_const) {
}
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap_effect) {
TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8);
BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
......@@ -531,8 +518,7 @@ void TestFloat32Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float32(),
MachineType::Float32());
WasmRunner<int32_t, float, float> r(execution_mode);
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
......@@ -550,8 +536,7 @@ void TestFloat32BinopWithConvert(WasmExecutionMode execution_mode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float32(),
MachineType::Float32());
WasmRunner<int32_t, float, float> r(execution_mode);
// return int(a op b)
BUILD(r, WASM_I32_SCONVERT_F32(
WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
......@@ -568,7 +553,7 @@ void TestFloat32UnopWithConvert(WasmExecutionMode execution_mode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float32());
WasmRunner<int32_t, float> r(execution_mode);
// return int(op(a))
BUILD(r, WASM_I32_SCONVERT_F32(WASM_UNOP(opcode, WASM_GET_LOCAL(0))));
CHECK_EQ(expected, r.Call(a));
......@@ -584,8 +569,7 @@ void TestFloat64Binop(WasmExecutionMode execution_mode, WasmOpcode opcode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float64(),
MachineType::Float64());
WasmRunner<int32_t, double, double> r(execution_mode);
// return a op b
BUILD(r, WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
CHECK_EQ(expected, r.Call(a, b));
......@@ -603,8 +587,7 @@ void TestFloat64BinopWithConvert(WasmExecutionMode execution_mode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float64(),
MachineType::Float64());
WasmRunner<int32_t, double, double> r(execution_mode);
BUILD(r, WASM_I32_SCONVERT_F64(
WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
CHECK_EQ(expected, r.Call(a, b));
......@@ -620,7 +603,7 @@ void TestFloat64UnopWithConvert(WasmExecutionMode execution_mode,
CHECK_EQ(expected, r.Call());
}
{
WasmRunner<int32_t> r(execution_mode, MachineType::Float64());
WasmRunner<int32_t, double> r(execution_mode);
// return int(op(a))
BUILD(r, WASM_I32_SCONVERT_F64(WASM_UNOP(opcode, WASM_GET_LOCAL(0))));
CHECK_EQ(expected, r.Call(a));
......@@ -671,7 +654,7 @@ WASM_EXEC_TEST(Float64Unops) {
}
WASM_EXEC_TEST(Float32Neg) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_F32_NEG(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) {
......@@ -681,7 +664,7 @@ WASM_EXEC_TEST(Float32Neg) {
}
WASM_EXEC_TEST(Float64Neg) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_F64_NEG(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) {
......@@ -691,7 +674,7 @@ WASM_EXEC_TEST(Float64Neg) {
}
WASM_EXEC_TEST(IfElse_P) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// if (p0) return 11; else return 22;
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // --
WASM_I8(11), // --
......@@ -704,38 +687,34 @@ WASM_EXEC_TEST(IfElse_P) {
#define EMPTY
WASM_EXEC_TEST(If_empty1) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprEnd, WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 9, *i)); }
}
WASM_EXEC_TEST(IfElse_empty1) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, kExprEnd,
WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 8, *i)); }
}
WASM_EXEC_TEST(IfElse_empty2) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, WASM_NOP, kExprElse,
kExprEnd, WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 7, *i)); }
}
WASM_EXEC_TEST(IfElse_empty3) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_GET_LOCAL(0), kExprIf, kLocalVoid, kExprElse, WASM_NOP,
kExprEnd, WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i - 6, *i)); }
}
WASM_EXEC_TEST(If_chain1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// if (p0) 13; if (p0) 14; 15
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP),
WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I8(15));
......@@ -743,8 +722,7 @@ WASM_EXEC_TEST(If_chain1) {
}
WASM_EXEC_TEST(If_chain_set) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
// if (p0) p1 = 73; if (p0) p1 = 74; p1
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))),
WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))),
......@@ -788,7 +766,7 @@ WASM_EXEC_TEST(Return17) {
}
WASM_EXEC_TEST(Return_I32) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, RET(WASM_GET_LOCAL(0)));
......@@ -796,7 +774,7 @@ WASM_EXEC_TEST(Return_I32) {
}
WASM_EXEC_TEST(Return_F32) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, RET(WASM_GET_LOCAL(0)));
......@@ -812,7 +790,7 @@ WASM_EXEC_TEST(Return_F32) {
}
WASM_EXEC_TEST(Return_F64) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, RET(WASM_GET_LOCAL(0)));
......@@ -828,8 +806,7 @@ WASM_EXEC_TEST(Return_F64) {
}
WASM_EXEC_TEST(Select_float_parameters) {
WasmRunner<float> r(execution_mode, MachineType::Float32(),
MachineType::Float32(), MachineType::Int32());
WasmRunner<float, float, float, int32_t> r(execution_mode);
// return select(11, 22, a);
BUILD(r,
WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)));
......@@ -837,7 +814,7 @@ WASM_EXEC_TEST(Select_float_parameters) {
}
WASM_EXEC_TEST(Select) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// return select(11, 22, a);
BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) {
......@@ -847,7 +824,7 @@ WASM_EXEC_TEST(Select) {
}
WASM_EXEC_TEST(Select_strict1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// select(a=0, a=1, a=2); return a
BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)),
WASM_TEE_LOCAL(0, WASM_I8(1)),
......@@ -857,7 +834,7 @@ WASM_EXEC_TEST(Select_strict1) {
}
WASM_EXEC_TEST(Select_strict2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstI32);
// select(b=5, c=6, a)
......@@ -870,7 +847,7 @@ WASM_EXEC_TEST(Select_strict2) {
}
WASM_EXEC_TEST(Select_strict3) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.AllocateLocal(kAstI32);
r.AllocateLocal(kAstI32);
// select(b=5, c=6, a=b)
......@@ -884,7 +861,7 @@ WASM_EXEC_TEST(Select_strict3) {
}
WASM_EXEC_TEST(BrIf_strict) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0),
WASM_TEE_LOCAL(0, WASM_I8(99)))));
......@@ -892,7 +869,7 @@ WASM_EXEC_TEST(BrIf_strict) {
}
WASM_EXEC_TEST(Br_height) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(
WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)),
......@@ -906,23 +883,22 @@ WASM_EXEC_TEST(Br_height) {
}
WASM_EXEC_TEST(Regression_660262) {
TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8);
BUILD(r, kExprI8Const, 0x00, kExprI8Const, 0x00, kExprI32LoadMem, 0x00, 0x0f,
kExprBrTable, 0x00, 0x80, 0x00); // entries=0
r.Call();
}
WASM_EXEC_TEST(BrTable0a) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))),
WASM_I8(91));
FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); }
}
WASM_EXEC_TEST(BrTable0b) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))),
WASM_I8(92));
......@@ -930,7 +906,7 @@ WASM_EXEC_TEST(BrTable0b) {
}
WASM_EXEC_TEST(BrTable0c) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(
r,
B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
......@@ -943,13 +919,13 @@ WASM_EXEC_TEST(BrTable0c) {
}
WASM_EXEC_TEST(BrTable1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0))), RET_I8(93));
FOR_INT32_INPUTS(i) { CHECK_EQ(93, r.Call(*i)); }
}
WASM_EXEC_TEST(BrTable_loop) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2),
BR_TARGET(1), BR_TARGET(0)))),
......@@ -963,7 +939,7 @@ WASM_EXEC_TEST(BrTable_loop) {
}
WASM_EXEC_TEST(BrTable_br) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))),
RET_I8(91)),
......@@ -975,7 +951,7 @@ WASM_EXEC_TEST(BrTable_br) {
}
WASM_EXEC_TEST(BrTable_br2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B2(B2(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 3, BR_TARGET(1),
BR_TARGET(2), BR_TARGET(3), BR_TARGET(0))),
......@@ -1006,7 +982,7 @@ WASM_EXEC_TEST(BrTable4) {
RET_I8(73)),
WASM_I8(75)};
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.Build(code, code + arraysize(code));
for (int x = -3; x < 50; ++x) {
......@@ -1036,7 +1012,7 @@ WASM_EXEC_TEST(BrTable4x4) {
RET_I8(53)),
WASM_I8(55)};
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.Build(code, code + arraysize(code));
for (int x = -6; x < 47; ++x) {
......@@ -1061,8 +1037,7 @@ WASM_EXEC_TEST(BrTable4_fallthru) {
WASM_INC_LOCAL_BY(1, 8)),
WASM_GET_LOCAL(1)};
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
r.Build(code, code + arraysize(code));
CHECK_EQ(15, r.Call(0, 0));
......@@ -1079,24 +1054,22 @@ WASM_EXEC_TEST(BrTable4_fallthru) {
}
WASM_EXEC_TEST(F32ReinterpretI32) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
WasmRunner<int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
BUILD(r, WASM_I32_REINTERPRET_F32(
WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)));
FOR_INT32_INPUTS(i) {
int32_t expected = *i;
module.WriteMemory(&memory[0], expected);
r.module().WriteMemory(&memory[0], expected);
CHECK_EQ(expected, r.Call());
}
}
WASM_EXEC_TEST(I32ReinterpretF32) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))),
......@@ -1105,14 +1078,13 @@ WASM_EXEC_TEST(I32ReinterpretF32) {
FOR_INT32_INPUTS(i) {
int32_t expected = *i;
CHECK_EQ(107, r.Call(expected));
CHECK_EQ(expected, module.ReadMemory(&memory[0]));
CHECK_EQ(expected, r.module().ReadMemory(&memory[0]));
}
}
WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) {
TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8);
BUILD(r, kExprI8Const, 0, // index
static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(
......@@ -1124,9 +1096,8 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) {
}
WASM_EXEC_TEST(LoadStoreLoad) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module);
WasmRunner<int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
......@@ -1134,111 +1105,107 @@ WASM_EXEC_TEST(LoadStoreLoad) {
FOR_INT32_INPUTS(i) {
int32_t expected = *i;
module.WriteMemory(&memory[0], expected);
r.module().WriteMemory(&memory[0], expected);
CHECK_EQ(expected, r.Call());
}
}
WASM_EXEC_TEST(VoidReturn1) {
// We use a wrapper function because WasmRunner<void> does not exist.
const int32_t kExpected = -414444;
WasmRunner<int32_t> r(execution_mode);
// Build the test function.
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.v_v(), &module);
BUILD(t, kExprNop);
uint32_t index = t.CompileAndAdd();
WasmFunctionCompiler& test_func = r.NewFunction<void>();
BUILD(test_func, kExprNop);
const int32_t kExpected = -414444;
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(r, WASM_CALL_FUNCTION0(index), WASM_I32V_3(kExpected));
BUILD(r, WASM_CALL_FUNCTION0(test_func.function_index()),
WASM_I32V_3(kExpected));
// Call and check.
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
}
WASM_EXEC_TEST(VoidReturn2) {
// We use a wrapper function because WasmRunner<void> does not exist.
const int32_t kExpected = -414444;
WasmRunner<int32_t> r(execution_mode);
// Build the test function.
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.v_v(), &module);
BUILD(t, WASM_RETURN0);
uint32_t index = t.CompileAndAdd();
WasmFunctionCompiler& test_func = r.NewFunction<void>();
BUILD(test_func, WASM_RETURN0);
const int32_t kExpected = -414444;
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(r, B1(WASM_CALL_FUNCTION0(index)), WASM_I32V_3(kExpected));
BUILD(r, WASM_CALL_FUNCTION0(test_func.function_index()),
WASM_I32V_3(kExpected));
// Call and check.
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
}
WASM_EXEC_TEST(BrEmpty) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BRV(0, WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(BrIfEmpty) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, kExprBlock, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_br1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_BR(0)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_brif1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK(WASM_BR_IF(0, WASM_ZERO)), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_empty_brif2) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_BLOCK(WASM_BR_IF(0, WASM_GET_LOCAL(1))), WASM_GET_LOCAL(0));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
}
WASM_EXEC_TEST(Block_i) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_f) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_BLOCK_F(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_d) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_BLOCK_D(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Block_br2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0))));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, static_cast<uint32_t>(r.Call(*i))); }
}
WASM_EXEC_TEST(Block_If_P) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// block { if (p0) break 51; 52; }
BUILD(r, WASM_BLOCK_I( // --
WASM_IF(WASM_GET_LOCAL(0), // --
......@@ -1251,51 +1218,49 @@ WASM_EXEC_TEST(Block_If_P) {
}
WASM_EXEC_TEST(Loop_empty) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, kExprLoop, kLocalVoid, kExprEnd, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_i) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP_I(WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_f) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_LOOP_F(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_d) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_LOOP_D(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_FLOAT_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_br1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_LOOP(WASM_BR(1))), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_brif1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_LOOP(WASM_BR_IF(1, WASM_ZERO))), WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
}
WASM_EXEC_TEST(Loop_empty_brif2) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_LOOP_I(WASM_BRV_IF(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))));
FOR_UINT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i, *i + 1)); }
}
WASM_EXEC_TEST(Loop_empty_brif3) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32(),
MachineType::Uint32(), MachineType::Uint32());
WasmRunner<uint32_t, uint32_t, uint32_t, uint32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_BRV_IFD(1, WASM_GET_LOCAL(2), WASM_GET_LOCAL(0))),
WASM_GET_LOCAL(1));
FOR_UINT32_INPUTS(i) {
......@@ -1307,7 +1272,7 @@ WASM_EXEC_TEST(Loop_empty_brif3) {
}
WASM_EXEC_TEST(Block_BrIf_P) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(51), WASM_GET_LOCAL(0)),
WASM_I8(52)));
FOR_INT32_INPUTS(i) {
......@@ -1317,7 +1282,7 @@ WASM_EXEC_TEST(Block_BrIf_P) {
}
WASM_EXEC_TEST(Block_IfElse_P_assign) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// { if (p0) p0 = 71; else p0 = 72; return p0; }
BUILD(r, // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
......@@ -1331,7 +1296,7 @@ WASM_EXEC_TEST(Block_IfElse_P_assign) {
}
WASM_EXEC_TEST(Block_IfElse_P_return) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// if (p0) return 81; else return 82;
BUILD(r, // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
......@@ -1344,7 +1309,7 @@ WASM_EXEC_TEST(Block_IfElse_P_return) {
}
WASM_EXEC_TEST(Block_If_P_assign) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// { if (p0) p0 = 61; p0; }
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))),
WASM_GET_LOCAL(0));
......@@ -1355,14 +1320,14 @@ WASM_EXEC_TEST(Block_If_P_assign) {
}
WASM_EXEC_TEST(DanglingAssign) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// { return 0; p0 = 0; }
BUILD(r, B2(RET_I8(99), WASM_SET_LOCAL(0, WASM_ZERO)));
CHECK_EQ(99, r.Call(1));
}
WASM_EXEC_TEST(ExprIf_P) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 ? 11 : 22;
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // --
WASM_I8(11), // --
......@@ -1374,7 +1339,7 @@ WASM_EXEC_TEST(ExprIf_P) {
}
WASM_EXEC_TEST(CountDown) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_IFB(
WASM_GET_LOCAL(0),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))),
......@@ -1386,7 +1351,7 @@ WASM_EXEC_TEST(CountDown) {
}
WASM_EXEC_TEST(CountDown_fallthru) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(
WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)),
WASM_BRV(2, WASM_GET_LOCAL(0))),
......@@ -1399,7 +1364,7 @@ WASM_EXEC_TEST(CountDown_fallthru) {
}
WASM_EXEC_TEST(WhileCountDown) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_WHILE(
WASM_GET_LOCAL(0),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))),
......@@ -1410,8 +1375,7 @@ WASM_EXEC_TEST(WhileCountDown) {
}
WASM_EXEC_TEST(Loop_if_break1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))),
WASM_SET_LOCAL(0, WASM_I8(99))),
WASM_GET_LOCAL(0));
......@@ -1422,8 +1386,7 @@ WASM_EXEC_TEST(Loop_if_break1) {
}
WASM_EXEC_TEST(Loop_if_break2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)),
WASM_DROP, WASM_SET_LOCAL(0, WASM_I8(99))),
WASM_GET_LOCAL(0));
......@@ -1434,7 +1397,7 @@ WASM_EXEC_TEST(Loop_if_break2) {
}
WASM_EXEC_TEST(Loop_if_break_fallthru) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)),
WASM_SET_LOCAL(0, WASM_I8(93)))),
WASM_GET_LOCAL(0));
......@@ -1445,7 +1408,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru) {
}
WASM_EXEC_TEST(Loop_if_break_fallthru2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)),
WASM_SET_LOCAL(0, WASM_I8(93))))),
WASM_GET_LOCAL(0));
......@@ -1456,7 +1419,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru2) {
}
WASM_EXEC_TEST(IfBreak1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)),
WASM_I8(91));
CHECK_EQ(91, r.Call(0));
......@@ -1465,7 +1428,7 @@ WASM_EXEC_TEST(IfBreak1) {
}
WASM_EXEC_TEST(IfBreak2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))),
WASM_I8(81));
CHECK_EQ(81, r.Call(0));
......@@ -1474,53 +1437,50 @@ WASM_EXEC_TEST(IfBreak2) {
}
WASM_EXEC_TEST(LoadMemI32) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0)));
module.WriteMemory(&memory[0], 99999999);
r.module().WriteMemory(&memory[0], 99999999);
CHECK_EQ(99999999, r.Call(0));
module.WriteMemory(&memory[0], 88888888);
r.module().WriteMemory(&memory[0], 88888888);
CHECK_EQ(88888888, r.Call(0));
module.WriteMemory(&memory[0], 77777777);
r.module().WriteMemory(&memory[0], 77777777);
CHECK_EQ(77777777, r.Call(0));
}
WASM_EXEC_TEST(LoadMemI32_alignment) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
for (byte alignment = 0; alignment <= 2; ++alignment) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment));
module.WriteMemory(&memory[0], 0x1a2b3c4d);
r.module().WriteMemory(&memory[0], 0x1a2b3c4d);
CHECK_EQ(0x1a2b3c4d, r.Call(0));
module.WriteMemory(&memory[0], 0x5e6f7a8b);
r.module().WriteMemory(&memory[0], 0x5e6f7a8b);
CHECK_EQ(0x5e6f7a8b, r.Call(0));
module.WriteMemory(&memory[0], 0x7ca0b1c2);
r.module().WriteMemory(&memory[0], 0x7ca0b1c2);
CHECK_EQ(0x7ca0b1c2, r.Call(0));
}
}
WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.RandomizeMemory(1111);
WasmRunner<int32_t, uint32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
module.WriteMemory(&memory[0], 88888888);
r.module().WriteMemory(&memory[0], 88888888);
CHECK_EQ(88888888, r.Call(0u));
for (uint32_t offset = 29; offset < 40; ++offset) {
CHECK_TRAP(r.Call(offset));
......@@ -1532,9 +1492,6 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) {
}
WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) {
TestingModule module(execution_mode);
module.AddMemoryElems<int32_t>(8);
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
......@@ -1542,8 +1499,10 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) {
MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1116 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
WasmRunner<int32_t, uint32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1116 + static_cast<int>(m));
uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]);
BUILD(r, WASM_LOAD_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0)),
......@@ -1558,25 +1517,24 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) {
}
WASM_EXEC_TEST(LoadMemI32_offset) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(4);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(4);
r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0)));
module.WriteMemory(&memory[0], 66666666);
module.WriteMemory(&memory[1], 77777777);
module.WriteMemory(&memory[2], 88888888);
module.WriteMemory(&memory[3], 99999999);
r.module().WriteMemory(&memory[0], 66666666);
r.module().WriteMemory(&memory[1], 77777777);
r.module().WriteMemory(&memory[2], 88888888);
r.module().WriteMemory(&memory[3], 99999999);
CHECK_EQ(77777777, r.Call(0));
CHECK_EQ(88888888, r.Call(4));
CHECK_EQ(99999999, r.Call(8));
module.WriteMemory(&memory[0], 11111111);
module.WriteMemory(&memory[1], 22222222);
module.WriteMemory(&memory[2], 33333333);
module.WriteMemory(&memory[3], 44444444);
r.module().WriteMemory(&memory[0], 11111111);
r.module().WriteMemory(&memory[1], 22222222);
r.module().WriteMemory(&memory[2], 33333333);
r.module().WriteMemory(&memory[3], 44444444);
CHECK_EQ(22222222, r.Call(0));
CHECK_EQ(33333333, r.Call(4));
CHECK_EQ(44444444, r.Call(8));
......@@ -1587,17 +1545,15 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) {
// TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
for (int offset = 0; offset < kMemSize + 5; ++offset) {
for (int index = 0; index < kMemSize + 5; ++index) {
TestingModule module(execution_mode);
module.AddMemoryElems<byte>(kMemSize);
WasmRunner<int32_t> r(&module);
module.RandomizeMemory();
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory();
BUILD(r,
WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) {
CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
} else {
CHECK_TRAP(r.Call());
}
......@@ -1609,17 +1565,15 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) {
const int kMemSize = 24;
for (int offset = 0; offset < kMemSize + 5; offset += 4) {
for (int index = 0; index < kMemSize + 5; index += 4) {
TestingModule module(execution_mode);
module.AddMemoryElems<byte>(kMemSize);
WasmRunner<int32_t> r(&module);
module.RandomizeMemory();
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory();
BUILD(r,
WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) {
CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
} else {
CHECK_TRAP(r.Call());
}
......@@ -1628,27 +1582,25 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) {
}
WASM_EXEC_TEST(StoreMemI32_alignment) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(4);
const int32_t kWritten = 0x12345678;
for (byte i = 0; i <= 2; ++i) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(4);
BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
WASM_GET_LOCAL(0)),
WASM_GET_LOCAL(0));
module.RandomizeMemory(1111);
r.module().RandomizeMemory(1111);
memory[0] = 0;
CHECK_EQ(kWritten, r.Call(kWritten));
CHECK_EQ(kWritten, module.ReadMemory(&memory[0]));
CHECK_EQ(kWritten, r.module().ReadMemory(&memory[0]));
}
}
WASM_EXEC_TEST(StoreMemI32_offset) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(4);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(4);
const int32_t kWritten = 0xaabbccdd;
BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
......@@ -1656,23 +1608,20 @@ WASM_EXEC_TEST(StoreMemI32_offset) {
WASM_I32V_5(kWritten));
for (int i = 0; i < 2; ++i) {
module.RandomizeMemory(1111);
module.WriteMemory(&memory[0], 66666666);
module.WriteMemory(&memory[1], 77777777);
module.WriteMemory(&memory[2], 88888888);
module.WriteMemory(&memory[3], 99999999);
r.module().RandomizeMemory(1111);
r.module().WriteMemory(&memory[0], 66666666);
r.module().WriteMemory(&memory[1], 77777777);
r.module().WriteMemory(&memory[2], 88888888);
r.module().WriteMemory(&memory[3], 99999999);
CHECK_EQ(kWritten, r.Call(i * 4));
CHECK_EQ(66666666, module.ReadMemory(&memory[0]));
CHECK_EQ(i == 0 ? kWritten : 77777777, module.ReadMemory(&memory[1]));
CHECK_EQ(i == 1 ? kWritten : 88888888, module.ReadMemory(&memory[2]));
CHECK_EQ(i == 2 ? kWritten : 99999999, module.ReadMemory(&memory[3]));
CHECK_EQ(66666666, r.module().ReadMemory(&memory[0]));
CHECK_EQ(i == 0 ? kWritten : 77777777, r.module().ReadMemory(&memory[1]));
CHECK_EQ(i == 1 ? kWritten : 88888888, r.module().ReadMemory(&memory[2]));
CHECK_EQ(i == 2 ? kWritten : 99999999, r.module().ReadMemory(&memory[3]));
}
}
WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) {
TestingModule module(execution_mode);
byte* memory = module.AddMemoryElems<byte>(32);
// 64-bit cases are handled in test-run-wasm-64.cc
static const MachineType machineTypes[] = {
MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
......@@ -1680,8 +1629,10 @@ WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) {
MachineType::Float32(), MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1119 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
WasmRunner<int32_t, uint32_t> r(execution_mode);
byte* memory = r.module().AddMemoryElems<byte>(32);
r.module().RandomizeMemory(1119 + static_cast<int>(m));
BUILD(r, WASM_STORE_MEM_OFFSET(machineTypes[m], 8, WASM_GET_LOCAL(0),
WASM_LOAD_MEM(machineTypes[m], WASM_ZERO)),
......@@ -1700,23 +1651,21 @@ WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) {
WASM_EXEC_TEST(LoadMemI32_P) {
const int kNumElems = 8;
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(kNumElems);
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(2222);
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* memory = r.module().AddMemoryElems<int32_t>(kNumElems);
r.module().RandomizeMemory(2222);
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumElems; ++i) {
CHECK_EQ(module.ReadMemory(&memory[i]), r.Call(i * 4));
CHECK_EQ(r.module().ReadMemory(&memory[i]), r.Call(i * 4));
}
}
WASM_EXEC_TEST(MemI32_Sum) {
const int kNumElems = 20;
TestingModule module(execution_mode);
uint32_t* memory = module.AddMemoryElems<uint32_t>(kNumElems);
WasmRunner<uint32_t> r(&module, MachineType::Int32());
WasmRunner<uint32_t, int32_t> r(execution_mode);
uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems);
const byte kSum = r.AllocateLocal(kAstI32);
BUILD(
......@@ -1733,10 +1682,10 @@ WASM_EXEC_TEST(MemI32_Sum) {
// Run 4 trials.
for (int i = 0; i < 3; ++i) {
module.RandomizeMemory(i * 33);
r.module().RandomizeMemory(i * 33);
uint32_t expected = 0;
for (size_t j = kNumElems - 1; j > 0; --j) {
expected += module.ReadMemory(&memory[j]);
expected += r.module().ReadMemory(&memory[j]);
}
uint32_t result = r.Call(4 * (kNumElems - 1));
CHECK_EQ(expected, result);
......@@ -1745,9 +1694,8 @@ WASM_EXEC_TEST(MemI32_Sum) {
WASM_EXEC_TEST(CheckMachIntsZero) {
const int kNumElems = 55;
TestingModule module(execution_mode);
module.AddMemoryElems<uint32_t>(kNumElems);
WasmRunner<uint32_t> r(&module, MachineType::Int32());
WasmRunner<uint32_t, int32_t> r(execution_mode);
r.module().AddMemoryElems<uint32_t>(kNumElems);
BUILD(r, // --
/**/ kExprLoop, kLocalVoid, // --
......@@ -1768,21 +1716,20 @@ WASM_EXEC_TEST(CheckMachIntsZero) {
/**/ kExprEnd, // --
/**/ kExprI8Const, 0); // --
module.BlankMemory();
CHECK_EQ(0u, r.Call((kNumElems - 1) * 4));
r.module().BlankMemory();
CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
}
WASM_EXEC_TEST(MemF32_Sum) {
const int kSize = 5;
TestingModule module(execution_mode);
module.AddMemoryElems<float>(kSize);
float* buffer = module.raw_mem_start<float>();
module.WriteMemory(&buffer[0], -99.25f);
module.WriteMemory(&buffer[1], -888.25f);
module.WriteMemory(&buffer[2], -77.25f);
module.WriteMemory(&buffer[3], 66666.25f);
module.WriteMemory(&buffer[4], 5555.25f);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().AddMemoryElems<float>(kSize);
float* buffer = r.module().raw_mem_start<float>();
r.module().WriteMemory(&buffer[0], -99.25f);
r.module().WriteMemory(&buffer[1], -888.25f);
r.module().WriteMemory(&buffer[2], -77.25f);
r.module().WriteMemory(&buffer[3], 66666.25f);
r.module().WriteMemory(&buffer[4], 5555.25f);
const byte kSum = r.AllocateLocal(kAstF32);
BUILD(
......@@ -1799,20 +1746,19 @@ WASM_EXEC_TEST(MemF32_Sum) {
WASM_GET_LOCAL(0));
CHECK_EQ(0, r.Call(4 * (kSize - 1)));
CHECK_NE(-99.25f, module.ReadMemory(&buffer[0]));
CHECK_EQ(71256.0f, module.ReadMemory(&buffer[0]));
CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0]));
CHECK_EQ(71256.0f, r.module().ReadMemory(&buffer[0]));
}
template <typename T>
T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
T* buffer, uint32_t size, LocalType astType,
MachineType memType) {
TestingModule module(execution_mode);
T* memory = module.AddMemoryElems<T>(size);
WasmRunner<int32_t, int32_t> r(execution_mode);
T* memory = r.module().AddMemoryElems<T>(size);
for (uint32_t i = 0; i < size; ++i) {
module.WriteMemory(&memory[i], buffer[i]);
r.module().WriteMemory(&memory[i], buffer[i]);
}
WasmRunner<int32_t> r(&module, MachineType::Int32());
const byte kAccum = r.AllocateLocal(astType);
BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
......@@ -1827,7 +1773,7 @@ T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
WASM_GET_LOCAL(0));
r.Call(static_cast<int>(sizeof(T) * (size - 1)));
return module.ReadMemory(&memory[0]);
return r.module().ReadMemory(&memory[0]);
}
WASM_EXEC_TEST(MemF64_Mul) {
......@@ -1840,15 +1786,14 @@ WASM_EXEC_TEST(MemF64_Mul) {
}
WASM_EXEC_TEST(Build_Wasm_Infinite_Loop) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
// Only build the graph and compile, don't run.
BUILD(r, WASM_INFINITE_LOOP);
}
WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
TestingModule module(execution_mode);
module.AddMemoryElems<int8_t>(16);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().AddMemoryElems<int8_t>(16);
// Only build the graph and compile, don't run.
BUILD(r, WASM_LOOP(WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO), WASM_DROP),
......@@ -1856,47 +1801,47 @@ WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
}
WASM_EXEC_TEST(Unreachable0a) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0))));
CHECK_EQ(9, r.Call(0));
CHECK_EQ(9, r.Call(1));
}
WASM_EXEC_TEST(Unreachable0b) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE));
CHECK_EQ(7, r.Call(0));
CHECK_EQ(7, r.Call(1));
}
TEST(Build_Wasm_Unreachable1) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE);
}
TEST(Build_Wasm_Unreachable2) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE);
}
TEST(Build_Wasm_Unreachable3) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE, WASM_UNREACHABLE, WASM_UNREACHABLE);
}
TEST(Build_Wasm_UnreachableIf1) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
}
TEST(Build_Wasm_UnreachableIf2) {
WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
BUILD(r, WASM_UNREACHABLE,
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
}
WASM_EXEC_TEST(Unreachable_Load) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)),
WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0))));
CHECK_EQ(11, r.Call(11));
......@@ -1904,14 +1849,14 @@ WASM_EXEC_TEST(Unreachable_Load) {
}
WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45));
// Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(0));
}
WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)),
WASM_INFINITE_LOOP)));
......@@ -1920,7 +1865,7 @@ WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
}
WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)),
WASM_INFINITE_LOOP));
// Run the code, but don't go into the infinite loop.
......@@ -1944,7 +1889,7 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) {
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
code + arraysize(code));
} else {
CHECK_EQ(2u, sig->parameter_count());
CHECK_EQ(2, sig->parameter_count());
byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, kExprGetLocal, 1,
static_cast<byte>(opcode)};
TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code,
......@@ -1963,12 +1908,11 @@ TEST(Build_Wasm_SimpleExprs) {
}
WASM_EXEC_TEST(Int32LoadInt8_signext) {
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
const int kNumElems = 16;
int8_t* memory = module.AddMemoryElems<int8_t>(kNumElems);
module.RandomizeMemory();
int8_t* memory = r.module().AddMemoryElems<int8_t>(kNumElems);
r.module().RandomizeMemory();
memory[0] = -1;
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumElems; ++i) {
......@@ -1977,12 +1921,11 @@ WASM_EXEC_TEST(Int32LoadInt8_signext) {
}
WASM_EXEC_TEST(Int32LoadInt8_zeroext) {
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
const int kNumElems = 16;
byte* memory = module.AddMemory(kNumElems);
module.RandomizeMemory(77);
byte* memory = r.module().AddMemory(kNumElems);
r.module().RandomizeMemory(77);
memory[0] = 255;
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumElems; ++i) {
......@@ -1991,12 +1934,11 @@ WASM_EXEC_TEST(Int32LoadInt8_zeroext) {
}
WASM_EXEC_TEST(Int32LoadInt16_signext) {
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
const int kNumBytes = 16;
byte* memory = module.AddMemory(kNumBytes);
module.RandomizeMemory(888);
byte* memory = r.module().AddMemory(kNumBytes);
r.module().RandomizeMemory(888);
memory[1] = 200;
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumBytes; i += 2) {
......@@ -2006,12 +1948,11 @@ WASM_EXEC_TEST(Int32LoadInt16_signext) {
}
WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
const int kNumBytes = 16;
byte* memory = module.AddMemory(kNumBytes);
module.RandomizeMemory(9999);
byte* memory = r.module().AddMemory(kNumBytes);
r.module().RandomizeMemory(9999);
memory[1] = 204;
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumBytes; i += 2) {
......@@ -2021,9 +1962,8 @@ WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
}
WASM_EXEC_TEST(Int32Global) {
TestingModule module(execution_mode);
int32_t* global = module.AddGlobal<int32_t>(kAstI32);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* global = r.module().AddGlobal<int32_t>();
// global = global + p0
BUILD(r,
WASM_SET_GLOBAL(0, WASM_I32_ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))),
......@@ -2039,14 +1979,13 @@ WASM_EXEC_TEST(Int32Global) {
WASM_EXEC_TEST(Int32Globals_DontAlias) {
const int kNumGlobals = 3;
TestingModule module(execution_mode);
int32_t* globals[] = {module.AddGlobal<int32_t>(kAstI32),
module.AddGlobal<int32_t>(kAstI32),
module.AddGlobal<int32_t>(kAstI32)};
for (int g = 0; g < kNumGlobals; ++g) {
// global = global + p0
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* globals[] = {r.module().AddGlobal<int32_t>(),
r.module().AddGlobal<int32_t>(),
r.module().AddGlobal<int32_t>()};
BUILD(r, WASM_SET_GLOBAL(
g, WASM_I32_ADD(WASM_GET_GLOBAL(g), WASM_GET_LOCAL(0))),
WASM_GET_GLOBAL(g));
......@@ -2068,9 +2007,8 @@ WASM_EXEC_TEST(Int32Globals_DontAlias) {
}
WASM_EXEC_TEST(Float32Global) {
TestingModule module(execution_mode);
float* global = module.AddGlobal<float>(kAstF32);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
float* global = r.module().AddGlobal<float>();
// global = global + p0
BUILD(r, WASM_SET_GLOBAL(
0, WASM_F32_ADD(WASM_GET_GLOBAL(0),
......@@ -2086,9 +2024,8 @@ WASM_EXEC_TEST(Float32Global) {
}
WASM_EXEC_TEST(Float64Global) {
TestingModule module(execution_mode);
double* global = module.AddGlobal<double>(kAstF64);
WasmRunner<int32_t> r(&module, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
double* global = r.module().AddGlobal<double>();
// global = global + p0
BUILD(r, WASM_SET_GLOBAL(
0, WASM_F64_ADD(WASM_GET_GLOBAL(0),
......@@ -2104,16 +2041,15 @@ WASM_EXEC_TEST(Float64Global) {
}
WASM_EXEC_TEST(MixedGlobals) {
TestingModule module(execution_mode);
int32_t* unused = module.AddGlobal<int32_t>(kAstI32);
byte* memory = module.AddMemory(32);
WasmRunner<int32_t, int32_t> r(execution_mode);
int32_t* var_int32 = module.AddGlobal<int32_t>(kAstI32);
uint32_t* var_uint32 = module.AddGlobal<uint32_t>(kAstI32);
float* var_float = module.AddGlobal<float>(kAstF32);
double* var_double = module.AddGlobal<double>(kAstF64);
int32_t* unused = r.module().AddGlobal<int32_t>();
byte* memory = r.module().AddMemory(32);
WasmRunner<int32_t> r(&module, MachineType::Int32());
int32_t* var_int32 = r.module().AddGlobal<int32_t>();
uint32_t* var_uint32 = r.module().AddGlobal<uint32_t>();
float* var_float = r.module().AddGlobal<float>();
double* var_double = r.module().AddGlobal<double>();
BUILD(r, WASM_SET_GLOBAL(1, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
WASM_SET_GLOBAL(2, WASM_LOAD_MEM(MachineType::Uint32(), WASM_ZERO)),
......@@ -2141,36 +2077,33 @@ WASM_EXEC_TEST(MixedGlobals) {
WASM_EXEC_TEST(CallEmpty) {
const int32_t kExpected = -414444;
WasmRunner<int32_t> r(execution_mode);
// Build the target function.
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.i_v(), &module);
BUILD(t, WASM_I32V_3(kExpected));
uint32_t index = t.CompileAndAdd();
WasmFunctionCompiler& target_func = r.NewFunction<int>();
BUILD(target_func, WASM_I32V_3(kExpected));
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(r, WASM_CALL_FUNCTION0(index));
BUILD(r, WASM_CALL_FUNCTION0(target_func.function_index()));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
}
WASM_EXEC_TEST(CallF32StackParameter) {
WasmRunner<float> r(execution_mode);
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; ++i) param_types[i] = kAstF32;
FunctionSig sig(1, 19, param_types);
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(17));
uint32_t index = t.CompileAndAdd();
// Build the calling function.
WasmRunner<float> r(&module);
BUILD(r, WASM_CALL_FUNCTION(
index, WASM_F32(1.0f), WASM_F32(2.0f), WASM_F32(4.0f),
WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
t.function_index(), WASM_F32(1.0f), WASM_F32(2.0f),
WASM_F32(4.0f), WASM_F32(8.0f), WASM_F32(16.0f), WASM_F32(32.0f),
WASM_F32(64.0f), WASM_F32(128.0f), WASM_F32(256.0f),
WASM_F32(1.5f), WASM_F32(2.5f), WASM_F32(4.5f), WASM_F32(8.5f),
WASM_F32(16.5f), WASM_F32(32.5f), WASM_F32(64.5f),
......@@ -2181,18 +2114,17 @@ WASM_EXEC_TEST(CallF32StackParameter) {
}
WASM_EXEC_TEST(CallF64StackParameter) {
WasmRunner<double> r(execution_mode);
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; ++i) param_types[i] = kAstF64;
FunctionSig sig(1, 19, param_types);
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
WasmFunctionCompiler& t = r.NewFunction(&sig);
BUILD(t, WASM_GET_LOCAL(17));
uint32_t index = t.CompileAndAdd();
// Build the calling function.
WasmRunner<double> r(&module);
BUILD(r, WASM_CALL_FUNCTION(index, WASM_F64(1.0), WASM_F64(2.0),
BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_F64(1.0), WASM_F64(2.0),
WASM_F64(4.0), WASM_F64(8.0), WASM_F64(16.0),
WASM_F64(32.0), WASM_F64(64.0), WASM_F64(128.0),
WASM_F64(256.0), WASM_F64(1.5), WASM_F64(2.5),
......@@ -2205,41 +2137,39 @@ WASM_EXEC_TEST(CallF64StackParameter) {
}
WASM_EXEC_TEST(CallVoid) {
WasmRunner<int32_t> r(execution_mode);
const byte kMemOffset = 8;
const int32_t kElemNum = kMemOffset / sizeof(int32_t);
const int32_t kExpected = 414444;
// Build the target function.
TestSignatures sigs;
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(16 / sizeof(int32_t));
module.RandomizeMemory();
WasmFunctionCompiler t(sigs.v_v(), &module);
int32_t* memory = r.module().AddMemoryElems<int32_t>(16 / sizeof(int32_t));
r.module().RandomizeMemory();
WasmFunctionCompiler& t = r.NewFunction(sigs.v_v());
BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset),
WASM_I32V_3(kExpected)));
uint32_t index = t.CompileAndAdd();
// Build the calling function.
WasmRunner<int32_t> r(&module);
BUILD(r, WASM_CALL_FUNCTION0(index),
BUILD(r, WASM_CALL_FUNCTION0(t.function_index()),
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset)));
int32_t result = r.Call();
CHECK_EQ(kExpected, result);
CHECK_EQ(static_cast<int64_t>(kExpected),
static_cast<int64_t>(module.ReadMemory(&memory[kElemNum])));
static_cast<int64_t>(r.module().ReadMemory(&memory[kElemNum])));
}
WASM_EXEC_TEST(Call_Int32Add) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
// Build the target function.
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.i_ii(), &module);
WasmFunctionCompiler& t = r.NewFunction<int32_t, int32_t, int32_t>();
BUILD(t, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
uint32_t index = t.CompileAndAdd();
// Build the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
BUILD(r, WASM_CALL_FUNCTION(t.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
......@@ -2251,17 +2181,15 @@ WASM_EXEC_TEST(Call_Int32Add) {
}
WASM_EXEC_TEST(Call_Float32Sub) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t(sigs.f_ff(), &module);
WasmRunner<float, float, float> r(execution_mode);
// Build the target function.
BUILD(t, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
uint32_t index = t.CompileAndAdd();
WasmFunctionCompiler& target_func = r.NewFunction<float, float, float>();
BUILD(target_func, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
// Builder the caller function.
WasmRunner<float> r(&module, MachineType::Float32(), MachineType::Float32());
BUILD(r, WASM_CALL_FUNCTION(index, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
// Build the caller function.
BUILD(r, WASM_CALL_FUNCTION(target_func.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
FOR_FLOAT32_INPUTS(j) { CHECK_FLOAT_EQ(*i - *j, r.Call(*i, *j)); }
......@@ -2269,9 +2197,8 @@ WASM_EXEC_TEST(Call_Float32Sub) {
}
WASM_EXEC_TEST(Call_Float64Sub) {
TestingModule module(execution_mode);
double* memory = module.AddMemoryElems<double>(16);
WasmRunner<int32_t> r(&module);
WasmRunner<int32_t> r(execution_mode);
double* memory = r.module().AddMemoryElems<double>(16);
BUILD(r, WASM_STORE_MEM(
MachineType::Float64(), WASM_ZERO,
......@@ -2281,15 +2208,16 @@ WASM_EXEC_TEST(Call_Float64Sub) {
FOR_FLOAT64_INPUTS(i) {
FOR_FLOAT64_INPUTS(j) {
module.WriteMemory(&memory[0], *i);
module.WriteMemory(&memory[1], *j);
r.module().WriteMemory(&memory[0], *i);
r.module().WriteMemory(&memory[1], *j);
double expected = *i - *j;
CHECK_EQ(107, r.Call());
if (expected != expected) {
CHECK(module.ReadMemory(&memory[0]) != module.ReadMemory(&memory[0]));
CHECK(r.module().ReadMemory(&memory[0]) !=
r.module().ReadMemory(&memory[0]));
} else {
CHECK_EQ(expected, module.ReadMemory(&memory[0]));
CHECK_EQ(expected, r.module().ReadMemory(&memory[0]));
}
}
}
......@@ -2317,28 +2245,25 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
for (int which = 0; which < num_params; ++which) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
TestingModule module(execution_mode);
module.AddMemory(1024);
WasmRunner<int32_t> r(execution_mode);
r.module().AddMemory(1024);
MachineType* memtypes = &mixed[start];
MachineType result = memtypes[which];
// =========================================================================
// Build the selector function.
// =========================================================================
uint32_t index;
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::LocalTypeFor(result));
for (int i = 0; i < num_params; ++i) {
b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
}
WasmFunctionCompiler t(b.Build(), &module);
WasmFunctionCompiler& t = r.NewFunction(b.Build());
BUILD(t, WASM_GET_LOCAL(which));
index = t.CompileAndAdd();
// =========================================================================
// Build the calling function.
// =========================================================================
WasmRunner<int32_t> r(&module);
std::vector<byte> code;
// Load the offset for the store.
......@@ -2351,7 +2276,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
}
// Call the selector function.
ADD_CODE(code, kExprCallFunction, static_cast<byte>(index));
ADD_CODE(code, WASM_CALL_FUNCTION0(t.function_index()));
// Store the result in memory.
ADD_CODE(code,
......@@ -2365,14 +2290,14 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Run the code.
for (int t = 0; t < 10; ++t) {
module.RandomizeMemory();
r.module().RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
for (int i = 0; i < size; ++i) {
int base = (which + 1) * kElemSize;
byte expected = module.raw_mem_at<byte>(base + i);
byte result = module.raw_mem_at<byte>(i);
byte expected = r.module().raw_mem_at<byte>(base + i);
byte result = r.module().raw_mem_at<byte>(i);
CHECK_EQ(expected, result);
}
}
......@@ -2385,13 +2310,10 @@ WASM_EXEC_TEST(MixedCall_2) { Run_WasmMixedCall_N(execution_mode, 2); }
WASM_EXEC_TEST(MixedCall_3) { Run_WasmMixedCall_N(execution_mode, 3); }
WASM_EXEC_TEST(AddCall) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
WasmRunner<int32_t, int32_t> r(kExecuteCompiled);
WasmFunctionCompiler& t1 = r.NewFunction<int32_t, int32_t, int32_t>();
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd();
WasmRunner<int32_t> r(&module, MachineType::Int32());
byte local = r.AllocateLocal(kAstI32);
BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)),
WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0),
......@@ -2406,16 +2328,15 @@ WASM_EXEC_TEST(AddCall) {
WASM_EXEC_TEST(MultiReturnSub) {
FLAG_wasm_mv_prototype = true;
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
LocalType storage[] = {kAstI32, kAstI32, kAstI32, kAstI32};
FunctionSig sig_ii_ii(2, 2, storage);
TestingModule module(execution_mode);
WasmFunctionCompiler t1(&sig_ii_ii, &module);
WasmFunctionCompiler& t1 = r.NewFunction(&sig_ii_ii);
BUILD(t1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0));
t1.CompileAndAdd();
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), kExprCallFunction, 0,
kExprI32Sub);
BUILD(r, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
WASM_CALL_FUNCTION0(t1.function_index()), kExprI32Sub);
FOR_INT32_INPUTS(i) {
FOR_INT32_INPUTS(j) {
......@@ -2427,9 +2348,9 @@ WASM_EXEC_TEST(MultiReturnSub) {
}
template <typename T>
void RunMultiReturnSelect(WasmExecutionMode execution_mode, LocalType type,
const T* inputs) {
void RunMultiReturnSelect(WasmExecutionMode execution_mode, const T* inputs) {
FLAG_wasm_mv_prototype = true;
LocalType type = WasmOpcodes::LocalTypeFor(MachineTypeForC<T>());
LocalType storage[] = {type, type, type, type, type, type};
const size_t kNumReturns = 2;
const size_t kNumParams = arraysize(storage) - kNumReturns;
......@@ -2438,30 +2359,25 @@ void RunMultiReturnSelect(WasmExecutionMode execution_mode, LocalType type,
for (size_t i = 0; i < kNumParams; i++) {
for (size_t j = 0; j < kNumParams; j++) {
for (int k = 0; k < 2; k++) {
TestingModule module(execution_mode);
WasmFunctionCompiler r1(&sig, &module);
WasmRunner<T, T, T, T, T> r(execution_mode);
WasmFunctionCompiler& r1 = r.NewFunction(&sig);
BUILD(r1, WASM_GET_LOCAL(i), WASM_GET_LOCAL(j));
r1.CompileAndAdd();
MachineType machine_type = WasmOpcodes::MachineTypeFor(type);
WasmRunner<T> r2(&module, machine_type, machine_type, machine_type,
machine_type);
if (k == 0) {
BUILD(r2, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
WASM_GET_LOCAL(3)),
BUILD(r, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
WASM_GET_LOCAL(3)),
WASM_DROP);
} else {
BUILD(r2, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
WASM_GET_LOCAL(3)),
BUILD(r, WASM_CALL_FUNCTION(r1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
WASM_GET_LOCAL(3)),
kExprSetLocal, 0, WASM_DROP, WASM_GET_LOCAL(0));
}
T expected = inputs[k == 0 ? i : j];
CHECK_EQ(expected, r2.Call(inputs[0], inputs[1], inputs[2], inputs[3]));
CHECK_EQ(expected, r.Call(inputs[0], inputs[1], inputs[2], inputs[3]));
}
}
}
......@@ -2469,12 +2385,12 @@ void RunMultiReturnSelect(WasmExecutionMode execution_mode, LocalType type,
WASM_EXEC_TEST(MultiReturnSelect_i32) {
static const int32_t inputs[] = {3333333, 4444444, -55555555, -7777777};
RunMultiReturnSelect<int32_t>(execution_mode, kAstI32, inputs);
RunMultiReturnSelect<int32_t>(execution_mode, inputs);
}
WASM_EXEC_TEST(MultiReturnSelect_f32) {
static const float inputs[] = {33.33333f, 444.4444f, -55555.555f, -77777.77f};
RunMultiReturnSelect<float>(execution_mode, kAstF32, inputs);
RunMultiReturnSelect<float>(execution_mode, inputs);
}
WASM_EXEC_TEST(MultiReturnSelect_i64) {
......@@ -2482,17 +2398,17 @@ WASM_EXEC_TEST(MultiReturnSelect_i64) {
// TODO(titzer): implement int64-lowering for multiple return values
static const int64_t inputs[] = {33333338888, 44444446666, -555555553333,
-77777771111};
RunMultiReturnSelect<int64_t>(execution_mode, kAstI64, inputs);
RunMultiReturnSelect<int64_t>(execution_mode, inputs);
#endif
}
WASM_EXEC_TEST(MultiReturnSelect_f64) {
static const double inputs[] = {3.333333, 44444.44, -55.555555, -7777.777};
RunMultiReturnSelect<double>(execution_mode, kAstF64, inputs);
RunMultiReturnSelect<double>(execution_mode, inputs);
}
WASM_EXEC_TEST(ExprBlock2a) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))),
WASM_I8(1)));
CHECK_EQ(1, r.Call(0));
......@@ -2500,7 +2416,7 @@ WASM_EXEC_TEST(ExprBlock2a) {
}
WASM_EXEC_TEST(ExprBlock2b) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))),
WASM_I8(2)));
CHECK_EQ(2, r.Call(0));
......@@ -2508,7 +2424,7 @@ WASM_EXEC_TEST(ExprBlock2b) {
}
WASM_EXEC_TEST(ExprBlock2c) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)),
WASM_I8(1)));
CHECK_EQ(1, r.Call(0));
......@@ -2516,7 +2432,7 @@ WASM_EXEC_TEST(ExprBlock2c) {
}
WASM_EXEC_TEST(ExprBlock2d) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)),
WASM_I8(2)));
CHECK_EQ(2, r.Call(0));
......@@ -2524,7 +2440,7 @@ WASM_EXEC_TEST(ExprBlock2d) {
}
WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)),
WASM_BRV(1, WASM_I8(11))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)),
......@@ -2546,7 +2462,7 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
}
WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(11),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))),
......@@ -2569,8 +2485,7 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
}
WASM_EXEC_TEST(If_nested) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
......@@ -2584,7 +2499,7 @@ WASM_EXEC_TEST(If_nested) {
}
WASM_EXEC_TEST(ExprBlock_if) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r,
WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)),
......@@ -2595,8 +2510,7 @@ WASM_EXEC_TEST(ExprBlock_if) {
}
WASM_EXEC_TEST(ExprBlock_nested_ifs) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I(
WASM_GET_LOCAL(0),
......@@ -2613,29 +2527,30 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) {
WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii());
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd(/*sig_index*/ 1);
t1.SetSigIndex(1);
WasmFunctionCompiler t2(sigs.i_ii(), &module);
WasmFunctionCompiler& t2 = r.NewFunction(sigs.i_ii());
BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t2.CompileAndAdd(/*sig_index*/ 1);
t2.SetSigIndex(1);
// Signature table.
module.AddSignature(sigs.f_ff());
module.AddSignature(sigs.i_ii());
module.AddSignature(sigs.d_dd());
r.module().AddSignature(sigs.f_ff());
r.module().AddSignature(sigs.i_ii());
r.module().AddSignature(sigs.d_dd());
// Function table.
uint16_t indirect_function_table[] = {0, 1};
module.AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
module.PopulateIndirectFunctionTable();
uint16_t indirect_function_table[] = {
static_cast<uint16_t>(t1.function_index()),
static_cast<uint16_t>(t2.function_index())};
r.module().AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
r.module().PopulateIndirectFunctionTable();
// Builder the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32());
// Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22)));
CHECK_EQ(88, r.Call(0));
......@@ -2645,30 +2560,30 @@ WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) {
WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii());
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd(/*sig_index*/ 1);
t1.SetSigIndex(1);
WasmFunctionCompiler t2(sigs.i_ii(), &module);
WasmFunctionCompiler& t2 = r.NewFunction(sigs.i_ii());
BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t2.CompileAndAdd(/*sig_index*/ 1);
t2.SetSigIndex(1);
// Signature table.
module.AddSignature(sigs.f_ff());
module.AddSignature(sigs.i_ii());
module.AddSignature(sigs.d_dd());
r.module().AddSignature(sigs.f_ff());
r.module().AddSignature(sigs.i_ii());
r.module().AddSignature(sigs.d_dd());
// Function table.
uint16_t indirect_function_table[] = {0, 1};
module.AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
module.PopulateIndirectFunctionTable();
// Builder the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32(),
MachineType::Int32());
uint16_t indirect_function_table[] = {
static_cast<uint16_t>(t1.function_index()),
static_cast<uint16_t>(t2.function_index())};
r.module().AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
r.module().PopulateIndirectFunctionTable();
// Build the caller function.
BUILD(r, WASM_I32_ADD(
WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
WASM_GET_LOCAL(2)),
......@@ -2688,20 +2603,19 @@ WASM_EXEC_TEST_WITH_TRAP(MultipleCallIndirect) {
WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
// One function.
WasmFunctionCompiler t1(sigs.i_ii(), &module);
WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii());
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd(/*sig_index*/ 1);
t1.SetSigIndex(1);
// Signature table.
module.AddSignature(sigs.f_ff());
module.AddSignature(sigs.i_ii());
module.AddIndirectFunctionTable(nullptr, 0);
r.module().AddSignature(sigs.f_ff());
r.module().AddSignature(sigs.i_ii());
r.module().AddIndirectFunctionTable(nullptr, 0);
// Builder the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32());
// Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22)));
CHECK_TRAP(r.Call(0));
......@@ -2711,24 +2625,24 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) {
WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) {
TestSignatures sigs;
TestingModule module(execution_mode);
WasmRunner<int32_t, int32_t> r(execution_mode);
WasmFunctionCompiler t1(sigs.i_ii(), &module);
WasmFunctionCompiler& t1 = r.NewFunction(sigs.i_ii());
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t1.CompileAndAdd(/*sig_index*/ 0);
t1.SetSigIndex(0);
WasmFunctionCompiler t2(sigs.i_ii(), &module);
WasmFunctionCompiler& t2 = r.NewFunction(sigs.i_ii());
BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t2.CompileAndAdd(/*sig_index*/ 1);
t2.SetSigIndex(1);
WasmFunctionCompiler t3(sigs.f_ff(), &module);
WasmFunctionCompiler& t3 = r.NewFunction(sigs.f_ff());
BUILD(t3, WASM_F32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
t3.CompileAndAdd(/*sig_index*/ 2);
t3.SetSigIndex(2);
// Signature table.
module.AddSignature(sigs.i_ii());
module.AddSignature(sigs.i_ii());
module.AddSignature(sigs.f_ff());
r.module().AddSignature(sigs.i_ii());
r.module().AddSignature(sigs.i_ii());
r.module().AddSignature(sigs.f_ff());
// Function table.
uint16_t i1 = static_cast<uint16_t>(t1.function_index());
......@@ -2736,12 +2650,11 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) {
uint16_t i3 = static_cast<uint16_t>(t3.function_index());
uint16_t indirect_function_table[] = {i1, i2, i3, i1, i2};
module.AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
module.PopulateIndirectFunctionTable();
r.module().AddIndirectFunctionTable(indirect_function_table,
arraysize(indirect_function_table));
r.module().PopulateIndirectFunctionTable();
// Builder the caller function.
WasmRunner<int32_t> r(&module, MachineType::Int32());
// Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11)));
CHECK_EQ(88, r.Call(0));
......@@ -2753,64 +2666,63 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) {
}
WASM_EXEC_TEST(F32Floor) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_F32_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(floorf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Ceil) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_F32_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(ceilf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Trunc) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_F32_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(truncf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32NearestInt) {
WasmRunner<float> r(execution_mode, MachineType::Float32());
WasmRunner<float, float> r(execution_mode);
BUILD(r, WASM_F32_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT32_INPUTS(i) { CHECK_FLOAT_EQ(nearbyintf(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Floor) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_F64_FLOOR(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(floor(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Ceil) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_F64_CEIL(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(ceil(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64Trunc) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_F64_TRUNC(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(trunc(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F64NearestInt) {
WasmRunner<double> r(execution_mode, MachineType::Float64());
WasmRunner<double, double> r(execution_mode);
BUILD(r, WASM_F64_NEARESTINT(WASM_GET_LOCAL(0)));
FOR_FLOAT64_INPUTS(i) { CHECK_DOUBLE_EQ(nearbyint(*i), r.Call(*i)); }
}
WASM_EXEC_TEST(F32Min) {
WasmRunner<float> r(execution_mode, MachineType::Float32(),
MachineType::Float32());
WasmRunner<float, float, float> r(execution_mode);
BUILD(r, WASM_F32_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
......@@ -2819,8 +2731,7 @@ WASM_EXEC_TEST(F32Min) {
}
WASM_EXEC_TEST(F64Min) {
WasmRunner<double> r(execution_mode, MachineType::Float64(),
MachineType::Float64());
WasmRunner<double, double, double> r(execution_mode);
BUILD(r, WASM_F64_MIN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
......@@ -2829,8 +2740,7 @@ WASM_EXEC_TEST(F64Min) {
}
WASM_EXEC_TEST(F32Max) {
WasmRunner<float> r(execution_mode, MachineType::Float32(),
MachineType::Float32());
WasmRunner<float, float, float> r(execution_mode);
BUILD(r, WASM_F32_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
......@@ -2839,8 +2749,7 @@ WASM_EXEC_TEST(F32Max) {
}
WASM_EXEC_TEST(F64Max) {
WasmRunner<double> r(execution_mode, MachineType::Float64(),
MachineType::Float64());
WasmRunner<double, double, double> r(execution_mode);
BUILD(r, WASM_F64_MAX(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
......@@ -2852,7 +2761,7 @@ WASM_EXEC_TEST(F64Max) {
}
WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) {
WasmRunner<int32_t> r(execution_mode, MachineType::Float32());
WasmRunner<int32_t, float> r(execution_mode);
BUILD(r, WASM_I32_SCONVERT_F32(WASM_GET_LOCAL(0)));
// The upper bound is (INT32_MAX + 1), which is the lowest float-representable
......@@ -2872,7 +2781,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) {
}
WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) {
WasmRunner<int32_t> r(execution_mode, MachineType::Float64());
WasmRunner<int32_t, double> r(execution_mode);
BUILD(r, WASM_I32_SCONVERT_F64(WASM_GET_LOCAL(0)));
// The upper bound is (INT32_MAX + 1), which is the lowest double-
......@@ -2891,7 +2800,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) {
}
WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Float32());
WasmRunner<uint32_t, float> r(execution_mode);
BUILD(r, WASM_I32_UCONVERT_F32(WASM_GET_LOCAL(0)));
// The upper bound is (UINT32_MAX + 1), which is the lowest
// float-representable number above UINT32_MAX which cannot be represented as
......@@ -2908,7 +2817,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) {
}
WASM_EXEC_TEST_WITH_TRAP(I32UConvertF64) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Float64());
WasmRunner<uint32_t, double> r(execution_mode);
BUILD(r, WASM_I32_UCONVERT_F64(WASM_GET_LOCAL(0)));
// The upper bound is (UINT32_MAX + 1), which is the lowest
// double-representable number above UINT32_MAX which cannot be represented as
......@@ -2925,8 +2834,7 @@ WASM_EXEC_TEST_WITH_TRAP(I32UConvertF64) {
}
WASM_EXEC_TEST(F64CopySign) {
WasmRunner<double> r(execution_mode, MachineType::Float64(),
MachineType::Float64());
WasmRunner<double, double, double> r(execution_mode);
BUILD(r, WASM_F64_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT64_INPUTS(i) {
......@@ -2935,8 +2843,7 @@ WASM_EXEC_TEST(F64CopySign) {
}
WASM_EXEC_TEST(F32CopySign) {
WasmRunner<float> r(execution_mode, MachineType::Float32(),
MachineType::Float32());
WasmRunner<float, float, float> r(execution_mode);
BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
FOR_FLOAT32_INPUTS(i) {
......@@ -2949,17 +2856,14 @@ static void CompileCallIndirectMany(LocalType param) {
// with many many parameters.
TestSignatures sigs;
for (byte num_params = 0; num_params < 40; ++num_params) {
v8::internal::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
HandleScope scope(CcTest::InitIsolateOnce());
TestingModule module(kExecuteCompiled);
FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
WasmRunner<void> r(kExecuteCompiled);
FunctionSig* sig = sigs.many(r.zone(), kAstStmt, param, num_params);
module.AddSignature(sig);
module.AddSignature(sig);
module.AddIndirectFunctionTable(nullptr, 0);
r.module().AddSignature(sig);
r.module().AddSignature(sig);
r.module().AddIndirectFunctionTable(nullptr, 0);
WasmFunctionCompiler t(sig, &module);
WasmFunctionCompiler& t = r.NewFunction(sig);
std::vector<byte> code;
for (byte p = 0; p < num_params; ++p) {
......@@ -2969,7 +2873,6 @@ static void CompileCallIndirectMany(LocalType param) {
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size());
t.Compile();
}
}
......@@ -2980,8 +2883,7 @@ TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32(),
MachineType::Int32());
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
WASM_ZERO);
const int32_t kMin = std::numeric_limits<int32_t>::min();
......
......@@ -76,25 +76,22 @@ void CheckExceptionInfos(Handle<Object> exc,
// Call from JS to WASM to JS and throw an Error from JS.
TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
// Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
WasmFunctionCompiler comp1(sigs.v_v(), &module);
uint32_t js_throwing_index = module.AddJsFunction(
uint32_t js_throwing_index = r.module().AddJsFunction(
sigs.v_v(),
"(function js() {\n function a() {\n throw new Error(); };\n a(); })");
// Add a nop such that we don't always get position 1.
BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
uint32_t wasm_index = comp1.CompileAndAdd();
BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
uint32_t wasm_index_1 = r.function()->func_index;
WasmFunctionCompiler comp2(sigs.v_v(), &module);
BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<void>();
BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1));
uint32_t wasm_index_2 = f2.function_index();
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
......@@ -114,7 +111,7 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
ExceptionInfo expected_exceptions[] = {
{"a", 3, 8}, // -
{"js", 4, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} // -
};
......@@ -124,21 +121,18 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
TEST(CollectDetailedWasmStack_WasmError) {
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler comp1(sigs.i_v(), &module,
ArrayVector("exec_unreachable"));
WasmRunner<int> r(kExecuteCompiled);
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
r.SetModuleContext();
BUILD(r, WASM_UNREACHABLE);
uint32_t wasm_index_1 = r.function()->func_index;
WasmFunctionCompiler comp2(sigs.i_v(), &module,
ArrayVector("call_exec_unreachable"));
BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<int>();
BUILD(f2, WASM_CALL_FUNCTION0(0));
uint32_t wasm_index_2 = f2.function_index();
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
......@@ -156,7 +150,7 @@ TEST(CollectDetailedWasmStack_WasmError) {
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} //-
};
......
......@@ -62,17 +62,15 @@ void CheckExceptionInfos(Handle<Object> exc,
// Trigger a trap for executing unreachable.
TEST(Unreachable) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler comp1(sigs.v_v(), &module,
ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
r.SetModuleContext();
BUILD(r, WASM_UNREACHABLE);
uint32_t wasm_index = r.function()->func_index;
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index);
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
......@@ -98,23 +96,22 @@ TEST(Unreachable) {
// Trigger a trap for loading from out-of-bounds.
TEST(IllegalLoad) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
WASM_I32V_1(-3)),
WASM_DROP)));
uint32_t wasm_index = comp1.CompileAndAdd();
r.SetModuleContext();
BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
WASM_I32V_1(-3)),
WASM_DROP)));
uint32_t wasm_index_1 = r.function()->func_index;
WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob"));
WasmFunctionCompiler& f2 = r.NewFunction<void>();
// Insert a NOP such that the position of the call is not one.
BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1));
uint32_t wasm_index_2 = f2.function_index();
Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
......@@ -132,7 +129,7 @@ TEST(IllegalLoad) {
// Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // --
{"callFn", 1, 24} // --
};
......
......@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <array>
#include <memory>
#include "src/base/utils/random-number-generator.h"
......@@ -51,7 +52,6 @@ enum WasmExecutionMode { kExecuteInterpreted, kExecuteCompiled };
CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
#define CHECK_TRAP(x) CHECK_TRAP32(x)
#define WASM_RUNNER_MAX_NUM_PARAMETERS 4
#define WASM_WRAPPER_RETURN_VALUE 8754
#define BUILD(r, ...) \
......@@ -73,7 +73,7 @@ const uint32_t kMaxGlobalsSize = 128;
// {WasmInstance}.
class TestingModule : public ModuleEnv {
public:
explicit TestingModule(WasmExecutionMode mode = kExecuteCompiled)
explicit TestingModule(Zone* zone, WasmExecutionMode mode = kExecuteCompiled)
: ModuleEnv(&module_, &instance_),
execution_mode_(mode),
instance_(&module_),
......@@ -83,7 +83,7 @@ class TestingModule : public ModuleEnv {
? new WasmInterpreter(
ModuleBytesEnv(&module_, &instance_,
Vector<const byte>::empty()),
&allocator_)
zone->allocator())
: nullptr) {
instance->module = &module_;
instance->globals_start = global_data;
......@@ -104,7 +104,7 @@ class TestingModule : public ModuleEnv {
byte* AddMemory(uint32_t size) {
CHECK_NULL(instance->mem_start);
CHECK_EQ(0u, instance->mem_size);
CHECK_EQ(0, instance->mem_size);
instance->mem_start = reinterpret_cast<byte*>(malloc(size));
CHECK(instance->mem_start);
memset(instance->mem_start, 0, size);
......@@ -119,7 +119,8 @@ class TestingModule : public ModuleEnv {
}
template <typename T>
T* AddGlobal(LocalType type) {
T* AddGlobal(
LocalType type = WasmOpcodes::LocalTypeFor(MachineTypeForC<T>())) {
const WasmGlobal* global = AddGlobal(type);
return reinterpret_cast<T*>(instance->globals_start + global->offset);
}
......@@ -244,6 +245,7 @@ class TestingModule : public ModuleEnv {
}
void PopulateIndirectFunctionTable() {
if (execution_mode_ == kExecuteInterpreted) return;
// Initialize the fixed arrays in instance->function_tables.
for (uint32_t i = 0; i < instance->function_tables.size(); i++) {
WasmIndirectFunctionTable& table = module_.function_tables[i];
......@@ -262,13 +264,13 @@ class TestingModule : public ModuleEnv {
WasmInterpreter* interpreter() { return interpreter_; }
WasmExecutionMode execution_mode() { return execution_mode_; }
Isolate* isolate() { return isolate_; }
private:
WasmExecutionMode execution_mode_;
WasmModule module_;
WasmInstance instance_;
Isolate* isolate_;
v8::internal::AccountingAllocator allocator_;
uint32_t global_offset;
V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
WasmInterpreter* interpreter_;
......@@ -314,36 +316,29 @@ inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
}
}
template <typename ReturnType>
class WasmFunctionWrapper : public HandleAndZoneScope,
private GraphAndBuilders {
class WasmFunctionWrapper : private GraphAndBuilders {
public:
WasmFunctionWrapper()
: GraphAndBuilders(main_zone()),
inner_code_node_(nullptr),
signature_(nullptr) {
explicit WasmFunctionWrapper(Zone* zone, int num_params)
: GraphAndBuilders(zone), inner_code_node_(nullptr), signature_(nullptr) {
// One additional parameter for the pointer to the return value memory.
Signature<MachineType>::Builder sig_builder(
zone(), 1, WASM_RUNNER_MAX_NUM_PARAMETERS + 1);
Signature<MachineType>::Builder sig_builder(zone, 1, num_params + 1);
sig_builder.AddReturn(MachineType::Int32());
for (int i = 0; i < WASM_RUNNER_MAX_NUM_PARAMETERS + 1; i++) {
for (int i = 0; i < num_params + 1; i++) {
sig_builder.AddParam(MachineType::Pointer());
}
signature_ = sig_builder.Build();
}
void Init(CallDescriptor* descriptor, MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None()) {
// Create the TF graph for the wrapper. The wrapper always takes four
// pointers as parameters, but may not pass the values of all pointers to
// the actual test function.
void Init(CallDescriptor* descriptor, MachineType return_type,
Vector<MachineType> param_types) {
DCHECK_NOT_NULL(descriptor);
DCHECK_EQ(signature_->parameter_count(), param_types.length() + 1);
// Create the TF graph for the wrapper.
// Function, effect, and control.
Node** parameters =
zone()->template NewArray<Node*>(WASM_RUNNER_MAX_NUM_PARAMETERS + 3);
Node** parameters = zone()->NewArray<Node*>(param_types.length() + 3);
graph()->SetStart(graph()->NewNode(common()->Start(6)));
Node* effect = graph()->start();
int parameter_count = 0;
......@@ -352,34 +347,12 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
inner_code_node_ = graph()->NewNode(common()->Int32Constant(0));
parameters[parameter_count++] = inner_code_node_;
if (p0 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p0),
graph()->NewNode(common()->Parameter(0), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p1 != MachineType::None()) {
int param_idx = 0;
for (MachineType t : param_types) {
DCHECK_NE(MachineType::None(), t);
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p1),
graph()->NewNode(common()->Parameter(1), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p2 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p2),
graph()->NewNode(common()->Parameter(2), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
}
if (p3 != MachineType::None()) {
parameters[parameter_count] = graph()->NewNode(
machine()->Load(p3),
graph()->NewNode(common()->Parameter(3), graph()->start()),
machine()->Load(t),
graph()->NewNode(common()->Parameter(param_idx++), graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), effect,
graph()->start());
effect = parameters[parameter_count++];
......@@ -390,14 +363,15 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
Node* call = graph()->NewNode(common()->Call(descriptor), parameter_count,
parameters);
effect = graph()->NewNode(
machine()->Store(
StoreRepresentation(MachineTypeForC<ReturnType>().representation(),
WriteBarrierKind::kNoWriteBarrier)),
graph()->NewNode(common()->Parameter(WASM_RUNNER_MAX_NUM_PARAMETERS),
graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), call, effect,
graph()->start());
if (!return_type.IsNone()) {
effect = graph()->NewNode(
machine()->Store(StoreRepresentation(
return_type.representation(), WriteBarrierKind::kNoWriteBarrier)),
graph()->NewNode(common()->Parameter(param_types.length()),
graph()->start()),
graph()->NewNode(common()->Int32Constant(0)), call, effect,
graph()->start());
}
Node* zero = graph()->NewNode(common()->Int32Constant(0));
Node* r = graph()->NewNode(
common()->Return(), zero,
......@@ -406,6 +380,15 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
graph()->SetEnd(graph()->NewNode(common()->End(2), r, graph()->start()));
}
template <typename ReturnType, typename... ParamTypes>
void Init(CallDescriptor* descriptor) {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
Init(descriptor, MachineTypeForC<ReturnType>(), param_vec);
}
void SetInnerCode(Handle<Code> code_handle) {
NodeProperties::ChangeOp(inner_code_node_,
common()->HeapConstant(code_handle));
......@@ -419,12 +402,13 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
Linkage::GetSimplifiedCDescriptor(zone(), signature_, true);
if (kPointerSize == 4) {
size_t num_params = signature_->parameter_count();
// One additional parameter for the pointer of the return value.
Signature<MachineRepresentation>::Builder rep_builder(
zone(), 1, WASM_RUNNER_MAX_NUM_PARAMETERS + 1);
Signature<MachineRepresentation>::Builder rep_builder(zone(), 1,
num_params + 1);
rep_builder.AddReturn(MachineRepresentation::kWord32);
for (int i = 0; i < WASM_RUNNER_MAX_NUM_PARAMETERS + 1; i++) {
for (size_t i = 0; i < num_params + 1; i++) {
rep_builder.AddParam(MachineRepresentation::kWord32);
}
Int64Lowering r(graph(), machine(), common(), zone(),
......@@ -456,99 +440,37 @@ class WasmFunctionWrapper : public HandleAndZoneScope,
Signature<MachineType>* signature_;
};
// A helper for compiling WASM functions for testing. This class can create a
// standalone function if {module} is NULL or a function within a
// {TestingModule}. It contains the internal state for compilation (i.e.
// TurboFan graph) and interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : public HandleAndZoneScope,
private GraphAndBuilders {
// A helper for compiling WASM functions for testing.
// It contains the internal state for compilation (i.e. TurboFan graph) and
// interpretation (by adding to the interpreter manually).
class WasmFunctionCompiler : private GraphAndBuilders {
public:
explicit WasmFunctionCompiler(
FunctionSig* sig, WasmExecutionMode mode,
Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
: GraphAndBuilders(main_zone()),
execution_mode_(mode),
jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(nullptr),
debug_name_(debug_name),
local_decls(main_zone(), sig),
source_position_table_(this->graph()),
interpreter_(nullptr) {
// Create our own function.
function_ = new WasmFunction();
function_->sig = sig;
function_->func_index = 0;
function_->sig_index = 0;
if (mode == kExecuteInterpreted) {
ModuleBytesEnv empty_env(nullptr, nullptr, Vector<const byte>::empty());
interpreter_ = new WasmInterpreter(empty_env, zone()->allocator());
int index = interpreter_->AddFunctionForTesting(function_);
CHECK_EQ(0, index);
}
}
explicit WasmFunctionCompiler(
FunctionSig* sig, TestingModule* module,
Vector<const char> debug_name = ArrayVector("<WASM UNNAMED>"))
: GraphAndBuilders(main_zone()),
execution_mode_(module->execution_mode()),
jsgraph(this->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(module),
debug_name_(debug_name),
local_decls(main_zone(), sig),
source_position_table_(this->graph()),
interpreter_(module->interpreter()) {
// Get a new function from the testing module.
int index = module->AddFunction(sig, Handle<Code>::null());
function_ = testing_module_->GetFunctionAt(index);
}
~WasmFunctionCompiler() {
if (testing_module_) return; // testing module owns the below things.
delete function_;
if (interpreter_) delete interpreter_;
}
WasmExecutionMode execution_mode_;
JSGraph jsgraph;
FunctionSig* sig;
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
TestingModule* testing_module_;
Vector<const char> debug_name_;
WasmFunction* function_;
LocalDeclEncoder local_decls;
SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
Isolate* isolate() { return main_isolate(); }
Isolate* isolate() { return testing_module_->isolate(); }
Graph* graph() const { return main_graph_; }
Zone* zone() const { return graph()->zone(); }
CommonOperatorBuilder* common() { return &main_common_; }
MachineOperatorBuilder* machine() { return &main_machine_; }
void InitializeDescriptor() {
CallDescriptor* descriptor() {
if (descriptor_ == nullptr) {
descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig);
descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig);
}
return descriptor_;
}
CallDescriptor* descriptor() { return descriptor_; }
uint32_t function_index() { return function_->func_index; }
void Build(const byte* start, const byte* end) {
// Build the TurboFan graph.
local_decls.Prepend(main_zone(), &start, &end);
TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
local_decls.Prepend(zone(), &start, &end);
if (interpreter_) {
// Add the code to the interpreter.
CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end));
return;
}
// Build the TurboFan graph.
TestBuildingGraph(zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
Handle<Code> code = Compile();
testing_module_->SetFunctionCode(function_index(), code);
}
byte AllocateLocal(LocalType type) {
......@@ -558,13 +480,33 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
return result;
}
void SetSigIndex(int sig_index) { function_->sig_index = sig_index; }
private:
friend class WasmRunnerBase;
explicit WasmFunctionCompiler(Zone* zone, FunctionSig* sig,
TestingModule* module)
: GraphAndBuilders(zone),
jsgraph(module->isolate(), this->graph(), this->common(), nullptr,
nullptr, this->machine()),
sig(sig),
descriptor_(nullptr),
testing_module_(module),
local_decls(zone, sig),
source_position_table_(this->graph()),
interpreter_(module->interpreter()) {
// Get a new function from the testing module.
int index = module->AddFunction(sig, Handle<Code>::null());
function_ = testing_module_->GetFunctionAt(index);
}
Handle<Code> Compile() {
InitializeDescriptor();
CallDescriptor* desc = descriptor_;
CallDescriptor* desc = descriptor();
if (kPointerSize == 4) {
desc = testing_module_->GetI32WasmCallDescriptor(this->zone(), desc);
}
CompilationInfo info(debug_name_, this->isolate(), this->zone(),
CompilationInfo info(CStrVector("wasm"), this->isolate(), this->zone(),
Code::ComputeFlags(Code::WASM_FUNCTION));
std::unique_ptr<CompilationJob> job(Pipeline::NewWasmCompilationJob(
&info, &jsgraph, desc, &source_position_table_, nullptr));
......@@ -594,82 +536,26 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
return code;
}
uint32_t CompileAndAdd(uint16_t sig_index = 0) {
CHECK(testing_module_);
function_->sig_index = sig_index;
Handle<Code> code = Compile();
testing_module_->SetFunctionCode(function_index(), code);
return function_index();
}
// Set the context, such that e.g. runtime functions can be called.
void SetModuleContext() {
if (!testing_module_->instance->context.is_null()) {
CHECK(testing_module_->instance->context.is_identical_to(
main_isolate()->native_context()));
return;
}
testing_module_->instance->context = main_isolate()->native_context();
}
};
template <typename ReturnType>
union ReturnTypeUnion {
ReturnType value;
uint64_t trap;
JSGraph jsgraph;
FunctionSig* sig;
// The call descriptor is initialized when the function is compiled.
CallDescriptor* descriptor_;
TestingModule* testing_module_;
Vector<const char> debug_name_;
WasmFunction* function_;
LocalDeclEncoder local_decls;
SourcePositionTable source_position_table_;
WasmInterpreter* interpreter_;
};
// A helper class to build graphs from Wasm bytecode, generate machine
// A helper class to build a module around Wasm bytecode, generate machine
// code, and run that code.
template <typename ReturnType>
class WasmRunner {
class WasmRunnerBase : public HandleAndZoneScope {
public:
WasmRunner(WasmExecutionMode execution_mode,
MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None())
: zone(&allocator_, ZONE_NAME),
compiled_(false),
signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1,
GetParameterCount(p0, p1, p2, p3), storage_),
compiler_(&signature_, execution_mode) {
InitSigStorage(p0, p1, p2, p3);
}
WasmRunner(TestingModule* module, MachineType p0 = MachineType::None(),
MachineType p1 = MachineType::None(),
MachineType p2 = MachineType::None(),
MachineType p3 = MachineType::None())
: zone(&allocator_, ZONE_NAME),
compiled_(false),
signature_(MachineTypeForC<ReturnType>() == MachineType::None() ? 0 : 1,
GetParameterCount(p0, p1, p2, p3), storage_),
compiler_(&signature_, module),
possible_nondeterminism_(false) {
DCHECK(module);
InitSigStorage(p0, p1, p2, p3);
}
void InitSigStorage(MachineType p0, MachineType p1, MachineType p2,
MachineType p3) {
int index = 0;
MachineType ret = MachineTypeForC<ReturnType>();
if (ret != MachineType::None()) {
storage_[index++] = WasmOpcodes::LocalTypeFor(ret);
}
if (p0 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p0);
if (p1 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p1);
if (p2 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p2);
if (p3 != MachineType::None())
storage_[index++] = WasmOpcodes::LocalTypeFor(p3);
compiler_.InitializeDescriptor();
wrapper_.Init(compiler_.descriptor(), p0, p1, p2, p3);
}
explicit WasmRunnerBase(WasmExecutionMode execution_mode, int num_params)
: zone_(&allocator_, ZONE_NAME),
module_(&zone_, execution_mode),
wrapper_(&zone_, num_params) {}
// Builds a graph from the given Wasm code and generates the machine
// code and call wrapper for that graph. This method must not be called
......@@ -677,102 +563,122 @@ class WasmRunner {
void Build(const byte* start, const byte* end) {
CHECK(!compiled_);
compiled_ = true;
compiler_.Build(start, end);
if (!interpret()) {
// Compile machine code and install it into the module.
Handle<Code> code = compiler_.Compile();
functions_[0]->Build(start, end);
}
if (compiler_.testing_module_) {
// Update the table of function code in the module.
compiler_.testing_module_->SetFunctionCode(
compiler_.function_->func_index, code);
}
// Resets the state for building the next function.
// The main function called will always be the first function.
template <typename ReturnType, typename... ParamTypes>
WasmFunctionCompiler& NewFunction() {
return NewFunction(CreateSig<ReturnType, ParamTypes...>());
}
wrapper_.SetInnerCode(code);
}
// Resets the state for building the next function.
// The main function called will be the last generated function.
// Returns the index of the previously built function.
WasmFunctionCompiler& NewFunction(FunctionSig* sig) {
functions_.emplace_back(new WasmFunctionCompiler(&zone_, sig, &module_));
return *functions_.back();
}
ReturnType Call() {
if (interpret()) {
return CallInterpreter(Vector<WasmVal>(nullptr, 0));
} else {
return Call(0, 0, 0, 0);
}
byte AllocateLocal(LocalType type) {
return functions_[0]->AllocateLocal(type);
}
template <typename P0>
ReturnType Call(P0 p0) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, 0, 0, 0);
WasmFunction* function() { return functions_[0]->function_; }
WasmInterpreter* interpreter() { return functions_[0]->interpreter_; }
bool possible_nondeterminism() { return possible_nondeterminism_; }
TestingModule& module() { return module_; }
Zone* zone() { return &zone_; }
// Set the context, such that e.g. runtime functions can be called.
void SetModuleContext() {
if (!module_.instance->context.is_null()) {
CHECK(module_.instance->context.is_identical_to(
main_isolate()->native_context()));
return;
}
module_.instance->context = main_isolate()->native_context();
}
template <typename P0, typename P1>
ReturnType Call(P0 p0, P1 p1) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, p1, 0, 0);
private:
FunctionSig* CreateSig(MachineType return_type,
Vector<MachineType> param_types) {
int return_count = return_type.IsNone() ? 0 : 1;
int param_count = param_types.length();
// Allocate storage array in zone.
LocalType* sig_types =
zone_.NewArray<LocalType>(return_count + param_count);
// Convert machine types to local types, and check that there are no
// MachineType::None()'s in the parameters.
int idx = 0;
if (return_count) sig_types[idx++] = WasmOpcodes::LocalTypeFor(return_type);
for (MachineType param : param_types) {
CHECK_NE(MachineType::None(), param);
sig_types[idx++] = WasmOpcodes::LocalTypeFor(param);
}
return new (&zone_) FunctionSig(return_count, param_count, sig_types);
}
template <typename P0, typename P1, typename P2>
ReturnType Call(P0 p0, P1 p1, P2 p2) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2)};
return CallInterpreter(ArrayVector(args));
} else {
return Call(p0, p1, p2, 0);
}
template <typename ReturnType, typename... ParamTypes>
FunctionSig* CreateSig() {
std::array<MachineType, sizeof...(ParamTypes)> param_machine_types{
{MachineTypeForC<ParamTypes>()...}};
Vector<MachineType> param_vec(param_machine_types.data(),
param_machine_types.size());
return CreateSig(MachineTypeForC<ReturnType>(), param_vec);
}
protected:
v8::internal::AccountingAllocator allocator_;
Zone zone_;
TestingModule module_;
std::vector<std::unique_ptr<WasmFunctionCompiler>> functions_;
WasmFunctionWrapper wrapper_;
bool compiled_ = false;
bool possible_nondeterminism_ = false;
bool interpret() { return module_.execution_mode() == kExecuteInterpreted; }
public:
// This field has to be static. Otherwise, gcc complains about the using in
// the lambda context below.
static jmp_buf jump_buffer;
static int jump_value;
static ReturnTypeUnion<ReturnType> return_value;
template <typename P0, typename P1, typename P2, typename P3>
void DoCall(P0 p0, P1 p1, P2 p2, P3 p3) {
auto trap_callback = []() {
WasmRunner<ReturnType>::return_value.trap = 0xdeadbeefdeadbeef;
longjmp(WasmRunner<ReturnType>::jump_buffer, 1);
};
set_trap_callback_for_testing(trap_callback);
CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_.GetWrapperCode(), wrapper_.signature());
};
int32_t result = runner.Call<void*, void*, void*, void*, void*>(
&p0, &p1, &p2, &p3, &WasmRunner<ReturnType>::return_value.value);
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
template <typename ReturnType, typename... ParamTypes>
class WasmRunner : public WasmRunnerBase {
public:
explicit WasmRunner(WasmExecutionMode execution_mode)
: WasmRunnerBase(execution_mode, sizeof...(ParamTypes)) {
NewFunction<ReturnType, ParamTypes...>();
if (!interpret()) {
wrapper_.Init<ReturnType, ParamTypes...>(functions_[0]->descriptor());
}
}
template <typename P0, typename P1, typename P2, typename P3>
ReturnType Call(P0 p0, P1 p1, P2 p2, P3 p3) {
if (interpret()) {
WasmVal args[] = {WasmVal(p0), WasmVal(p1), WasmVal(p2), WasmVal(p3)};
return CallInterpreter(ArrayVector(args));
} else {
// Use setjmp/longjmp to deal with traps in WebAssembly code.
WasmRunner<ReturnType>::jump_value =
setjmp(WasmRunner<ReturnType>::jump_buffer);
if (!WasmRunner<ReturnType>::jump_value) {
DoCall(p0, p1, p2, p3);
}
set_trap_callback_for_testing(nullptr);
return WasmRunner<ReturnType>::return_value.value;
}
ReturnType Call(ParamTypes... p) {
DCHECK(compiled_);
if (interpret()) return CallInterpreter(p...);
// Use setjmp/longjmp to deal with traps in WebAssembly code.
// Make the return value volatile, to give defined semantics if accessed
// after setjmp.
volatile ReturnType return_value =
static_cast<ReturnType>(0xdeadbeefdeadbeef);
int jump_value = setjmp(WasmRunnerBase::jump_buffer);
// jump_value == 0 --> first return; jump_value == 1 --> longjmp happened.
if (!jump_value) DoCall(&return_value, p...);
return return_value;
}
ReturnType CallInterpreter(Vector<WasmVal> args) {
CHECK_EQ(args.length(),
static_cast<int>(compiler_.function_->sig->parameter_count()));
ReturnType CallInterpreter(ParamTypes... p) {
WasmInterpreter::Thread* thread = interpreter()->GetThread(0);
thread->Reset();
thread->PushFrame(compiler_.function_, args.start());
std::array<WasmVal, sizeof...(p)> args{{WasmVal(p)...}};
thread->PushFrame(function(), args.data());
if (thread->Run() == WasmInterpreter::FINISHED) {
WasmVal val = thread->GetReturnValue();
possible_nondeterminism_ |= thread->PossibleNondeterminism();
......@@ -783,45 +689,35 @@ class WasmRunner {
return static_cast<ReturnType>(result);
} else {
// TODO(titzer): falling off end
ReturnType val = 0;
return val;
return ReturnType{0};
}
}
byte AllocateLocal(LocalType type) { return compiler_.AllocateLocal(type); }
WasmFunction* function() { return compiler_.function_; }
WasmInterpreter* interpreter() { return compiler_.interpreter_; }
bool possible_nondeterminism() { return possible_nondeterminism_; }
private:
// Don't inline this function. The setjmp above should be followed immediately
// by a call.
V8_NOINLINE void DoCall(volatile ReturnType* return_value, ParamTypes... p) {
auto trap_callback = []() -> void {
set_trap_callback_for_testing(nullptr);
longjmp(WasmRunnerBase::jump_buffer, 1);
};
set_trap_callback_for_testing(trap_callback);
protected:
v8::internal::AccountingAllocator allocator_;
Zone zone;
bool compiled_;
LocalType storage_[WASM_RUNNER_MAX_NUM_PARAMETERS];
FunctionSig signature_;
WasmFunctionCompiler compiler_;
WasmFunctionWrapper<ReturnType> wrapper_;
bool possible_nondeterminism_;
bool interpret() { return compiler_.execution_mode_ == kExecuteInterpreted; }
static size_t GetParameterCount(MachineType p0, MachineType p1,
MachineType p2, MachineType p3) {
if (p0 == MachineType::None()) return 0;
if (p1 == MachineType::None()) return 1;
if (p2 == MachineType::None()) return 2;
if (p3 == MachineType::None()) return 3;
return 4;
wrapper_.SetInnerCode(
module_.GetFunctionCode(functions_[0]->function_index()));
CodeRunner<int32_t> runner(CcTest::InitIsolateOnce(),
wrapper_.GetWrapperCode(), wrapper_.signature());
ReturnType return_value_local;
int32_t result = runner.Call(static_cast<void*>(&p)...,
static_cast<void*>(&return_value_local));
*return_value = return_value_local;
// If we arrive here, no trap happened.
CHECK_EQ(WASM_WRAPPER_RETURN_VALUE, result);
}
};
template <typename ReturnType>
jmp_buf WasmRunner<ReturnType>::jump_buffer;
template <typename ReturnType>
int WasmRunner<ReturnType>::jump_value;
template <typename ReturnType>
ReturnTypeUnion<ReturnType> WasmRunner<ReturnType>::return_value;
// Declare static variable.
jmp_buf WasmRunnerBase::jump_buffer;
// A macro to define tests that run in different engine configurations.
#define WASM_EXEC_TEST(name) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment