diff options
Diffstat (limited to 'deps/v8/test/cctest/wasm/test-run-wasm.cc')
-rw-r--r-- | deps/v8/test/cctest/wasm/test-run-wasm.cc | 1431 |
1 files changed, 666 insertions, 765 deletions
diff --git a/deps/v8/test/cctest/wasm/test-run-wasm.cc b/deps/v8/test/cctest/wasm/test-run-wasm.cc index a42a81ba27..05370b5775 100644 --- a/deps/v8/test/cctest/wasm/test-run-wasm.cc +++ b/deps/v8/test/cctest/wasm/test-run-wasm.cc @@ -25,41 +25,7 @@ using namespace v8::internal::wasm; #define B2(a, b) WASM_BLOCK(a, b) #define B3(a, b, c) WASM_BLOCK(a, b, c) #define RET(x) x, kExprReturn -#define RET_I8(x) kExprI8Const, x, kExprReturn - -WASM_EXEC_TEST(Int8Const) { - WasmRunner<int32_t> r(execution_mode); - const byte kExpectedValue = 121; - // return(kExpectedValue) - BUILD(r, WASM_I8(kExpectedValue)); - CHECK_EQ(kExpectedValue, r.Call()); -} - -WASM_EXEC_TEST(Int8Const_end) { - WasmRunner<int32_t> r(execution_mode); - const byte kExpectedValue = 121; - // return(kExpectedValue) - BUILD(r, WASM_I8(kExpectedValue), kExprEnd); - CHECK_EQ(kExpectedValue, r.Call()); -} - -WASM_EXEC_TEST(Int8Const_fallthru2) { - WasmRunner<int32_t> r(execution_mode); - const byte kExpectedValue = 123; - // -99 kExpectedValue - BUILD(r, WASM_I8(-99), WASM_DROP, WASM_I8(kExpectedValue)); - CHECK_EQ(kExpectedValue, r.Call()); -} - -WASM_EXEC_TEST(Int8Const_all) { - for (int value = -128; value <= 127; ++value) { - WasmRunner<int32_t> r(execution_mode); - // return(value) - BUILD(r, WASM_I8(value)); - int32_t result = r.Call(); - CHECK_EQ(value, result); - } -} +#define RET_I8(x) WASM_I32V_2(x), kExprReturn WASM_EXEC_TEST(Int32Const) { WasmRunner<int32_t> r(execution_mode); @@ -81,29 +47,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)); } @@ -112,28 +77,27 @@ WASM_EXEC_TEST(Int32Param1) { WASM_EXEC_TEST(Int32Add) { WasmRunner<int32_t> r(execution_mode); // 11 + 44 - BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); + BUILD(r, WASM_I32_ADD(WASM_I32V_1(11), WASM_I32V_1(44))); CHECK_EQ(55, r.Call()); } 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))); + BUILD(r, WASM_I32_ADD(WASM_I32V_1(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))); + BUILD(r, WASM_I32_ADD(WASM_I32V_1(13), WASM_GET_LOCAL(0))); FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } } 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) { @@ -154,7 +118,7 @@ WASM_EXEC_TEST(Int32Add_P2) { WASM_EXEC_TEST(Int32Add_block1) { FLAG_wasm_mv_prototype = true; static const byte code[] = { - WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), + WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), kExprI32Add}; RunInt32AddTest(execution_mode, code, sizeof(code)); } @@ -162,7 +126,7 @@ WASM_EXEC_TEST(Int32Add_block1) { WASM_EXEC_TEST(Int32Add_block2) { FLAG_wasm_mv_prototype = true; static const byte code[] = { - WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), + WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), kExprBr, DEPTH_0), kExprI32Add}; RunInt32AddTest(execution_mode, code, sizeof(code)); @@ -171,7 +135,7 @@ WASM_EXEC_TEST(Int32Add_block2) { WASM_EXEC_TEST(Int32Add_multi_if) { FLAG_wasm_mv_prototype = true; static const byte code[] = { - WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), + WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), kExprI32Add}; @@ -202,8 +166,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 +215,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 +311,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 +323,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 +335,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) { @@ -386,9 +346,8 @@ WASM_EXEC_TEST(I32Sar) { } } -WASM_EXEC_TEST(Int32DivS_trap) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), - MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap) { + 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)); @@ -398,9 +357,8 @@ WASM_EXEC_TEST(Int32DivS_trap) { CHECK_TRAP(r.Call(kMin, 0)); } -WASM_EXEC_TEST(Int32RemS_trap) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), - MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32RemS_trap) { + 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)); @@ -410,9 +368,8 @@ WASM_EXEC_TEST(Int32RemS_trap) { CHECK_TRAP(r.Call(kMin, 0)); } -WASM_EXEC_TEST(Int32DivU_trap) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), - MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32DivU_trap) { + 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)); @@ -422,9 +379,8 @@ WASM_EXEC_TEST(Int32DivU_trap) { CHECK_TRAP(r.Call(kMin, 0)); } -WASM_EXEC_TEST(Int32RemU_trap) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), - MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) { + 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(); @@ -434,10 +390,10 @@ WASM_EXEC_TEST(Int32RemU_trap) { CHECK_EQ(kMin, r.Call(kMin, -1)); } -WASM_EXEC_TEST(Int32DivS_byzero_const) { +WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) { for (int8_t denom = -2; denom < 8; ++denom) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); for (int32_t val = -7; val < 8; ++val) { if (denom == 0) { CHECK_TRAP(r.Call(val)); @@ -450,10 +406,9 @@ WASM_EXEC_TEST(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()); - BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); + WasmRunner<int32_t, int32_t> r(execution_mode); + r.module().ChangeOriginToAsmjs(); + BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); FOR_INT32_INPUTS(i) { if (denom == 0) { CHECK_EQ(0, r.Call(*i)); @@ -468,10 +423,9 @@ 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()); - BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I8(denom))); + WasmRunner<int32_t, int32_t> r(execution_mode); + r.module().ChangeOriginToAsmjs(); + BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(denom))); FOR_INT32_INPUTS(i) { if (denom == 0) { CHECK_EQ(0, r.Call(*i)); @@ -484,9 +438,9 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) { } } -WASM_EXEC_TEST(Int32DivU_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) { @@ -499,10 +453,9 @@ WASM_EXEC_TEST(Int32DivU_byzero_const) { } } -WASM_EXEC_TEST(Int32DivS_trap_effect) { - TestingModule module(execution_mode); - module.AddMemoryElems<int32_t>(8); - WasmRunner<int32_t> r(&module, MachineType::Int32(), MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32DivS_trap_effect) { + 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 +484,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 +502,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 +519,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 +535,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 +553,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 +569,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 +620,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 +630,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,11 +640,11 @@ 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), // -- - WASM_I8(22))); // -- + WASM_I32V_1(11), // -- + WASM_I32V_1(22))); // -- FOR_INT32_INPUTS(i) { int32_t expected = *i ? 11 : 22; CHECK_EQ(expected, r.Call(*i)); @@ -704,50 +653,45 @@ 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)); + WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I32V_1(15)); FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } } 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))), + BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(73))), + WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(74))), WASM_GET_LOCAL(1)); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 74 : *i; @@ -758,17 +702,17 @@ WASM_EXEC_TEST(If_chain_set) { WASM_EXEC_TEST(IfElse_Unreachable1) { WasmRunner<int32_t> r(execution_mode); // 0 ? unreachable : 27 - BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- - WASM_UNREACHABLE, // -- - WASM_I8(27))); // -- + BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- + WASM_UNREACHABLE, // -- + WASM_I32V_1(27))); // -- CHECK_EQ(27, r.Call()); } WASM_EXEC_TEST(IfElse_Unreachable2) { WasmRunner<int32_t> r(execution_mode); // 1 ? 28 : unreachable - BUILD(r, WASM_IF_ELSE_I(WASM_I8(1), // -- - WASM_I8(28), // -- + BUILD(r, WASM_IF_ELSE_I(WASM_I32V_1(1), // -- + WASM_I32V_1(28), // -- WASM_UNREACHABLE)); // -- CHECK_EQ(28, r.Call()); } @@ -783,12 +727,12 @@ WASM_EXEC_TEST(Return12) { WASM_EXEC_TEST(Return17) { WasmRunner<int32_t> r(execution_mode); - BUILD(r, WASM_BLOCK(RET_I8(17))); + BUILD(r, WASM_BLOCK(RET_I8(17)), WASM_ZERO); CHECK_EQ(17, r.Call()); } 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 +740,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 +756,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 +772,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,9 +780,9 @@ 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))); + BUILD(r, WASM_SELECT(WASM_I32V_1(11), WASM_I32V_1(22), WASM_GET_LOCAL(0))); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 11 : 22; CHECK_EQ(expected, r.Call(*i)); @@ -847,22 +790,22 @@ 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)), - WASM_TEE_LOCAL(0, WASM_I8(2))), + BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_ZERO), + WASM_TEE_LOCAL(0, WASM_I32V_1(1)), + WASM_TEE_LOCAL(0, WASM_I32V_1(2))), WASM_DROP, WASM_GET_LOCAL(0)); FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } } WASM_EXEC_TEST(Select_strict2) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - r.AllocateLocal(kAstI32); - r.AllocateLocal(kAstI32); + WasmRunner<int32_t, int32_t> r(execution_mode); + r.AllocateLocal(kWasmI32); + r.AllocateLocal(kWasmI32); // select(b=5, c=6, a) - BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), - WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); + BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)), + WASM_TEE_LOCAL(2, WASM_I32V_1(6)), WASM_GET_LOCAL(0))); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 5 : 6; CHECK_EQ(expected, r.Call(*i)); @@ -870,12 +813,12 @@ WASM_EXEC_TEST(Select_strict2) { } WASM_EXEC_TEST(Select_strict3) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - r.AllocateLocal(kAstI32); - r.AllocateLocal(kAstI32); + WasmRunner<int32_t, int32_t> r(execution_mode); + r.AllocateLocal(kWasmI32); + r.AllocateLocal(kWasmI32); // select(b=5, c=6, a=b) - BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), - WASM_TEE_LOCAL(2, WASM_I8(6)), + BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)), + WASM_TEE_LOCAL(2, WASM_I32V_1(6)), WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); FOR_INT32_INPUTS(i) { int32_t expected = 5; @@ -884,20 +827,19 @@ 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))))); + WASM_TEE_LOCAL(0, WASM_I32V_2(99))))); FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } } WASM_EXEC_TEST(Br_height) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, - WASM_BLOCK_I( - WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), - WASM_RETURN1(WASM_I8(9)), WASM_I8(7), WASM_I8(7)), - WASM_BRV(0, WASM_I8(8)))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I( + WASM_BLOCK(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), + WASM_RETURN1(WASM_I32V_1(9))), + WASM_BRV(0, WASM_I32V_1(8)))); for (int32_t i = 0; i < 5; i++) { int32_t expected = i != 0 ? 8 : 9; @@ -906,36 +848,35 @@ WASM_EXEC_TEST(Br_height) { } WASM_EXEC_TEST(Regression_660262) { - TestingModule module(execution_mode); - module.AddMemoryElems<int32_t>(8); - WasmRunner<int32_t> r(&module); - BUILD(r, kExprI8Const, 0x00, kExprI8Const, 0x00, kExprI32LoadMem, 0x00, 0x0f, - kExprBrTable, 0x00, 0x80, 0x00); // entries=0 + WasmRunner<int32_t> r(execution_mode); + r.module().AddMemoryElems<int32_t>(8); + BUILD(r, kExprI32Const, 0x00, kExprI32Const, 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)); + WASM_I32V_2(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)); + WASM_I32V_2(92)); FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } } 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))), RET_I8(76))), - WASM_I8(77)); + WASM_I32V_2(77)); FOR_INT32_INPUTS(i) { int32_t expected = *i == 0 ? 76 : 77; CHECK_EQ(expected, r.Call(*i)); @@ -943,18 +884,18 @@ 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)))), RET_I8(99)), - WASM_I8(98)); + WASM_I32V_2(98)); CHECK_EQ(99, r.Call(0)); CHECK_EQ(98, r.Call(-1)); CHECK_EQ(98, r.Call(-2)); @@ -963,11 +904,11 @@ 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)), - WASM_I8(99)); + WASM_I32V_2(99)); CHECK_EQ(99, r.Call(0)); CHECK_EQ(91, r.Call(1)); CHECK_EQ(91, r.Call(2)); @@ -975,14 +916,14 @@ 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))), RET_I8(85)), RET_I8(86)), RET_I8(87)), - WASM_I8(88)); + WASM_I32V_2(88)); CHECK_EQ(86, r.Call(0)); CHECK_EQ(87, r.Call(1)); CHECK_EQ(88, r.Call(2)); @@ -1004,9 +945,9 @@ WASM_EXEC_TEST(BrTable4) { RET_I8(71)), RET_I8(72)), RET_I8(73)), - WASM_I8(75)}; + WASM_I32V_2(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) { @@ -1034,9 +975,9 @@ WASM_EXEC_TEST(BrTable4x4) { RET_I8(51)), RET_I8(52)), RET_I8(53)), - WASM_I8(55)}; + WASM_I32V_2(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 +1002,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,42 +1019,49 @@ 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))), - WASM_I8(107)); + WASM_I32V_2(107)); 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(LoadMaxUint32Offset) { - TestingModule module(execution_mode); - module.AddMemoryElems<int32_t>(8); - WasmRunner<int32_t> r(&module); +WASM_EXEC_TEST(SignallingNanSurvivesI32ReinterpretF32) { + WasmRunner<int32_t> r(execution_mode); + + BUILD(r, WASM_I32_REINTERPRET_F32( + WASM_SEQ(kExprF32Const, 0x00, 0x00, 0xa0, 0x7f))); + + // This is a signalling nan. + CHECK_EQ(0x7fa00000, r.Call()); +} + +WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { + WasmRunner<int32_t> r(execution_mode); + r.module().AddMemoryElems<int32_t>(8); - BUILD(r, kExprI8Const, 0, // index + BUILD(r, kExprI32Const, 0, // index static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf( MachineType::Int32(), false)), // -- 0, // alignment @@ -1124,9 +1071,8 @@ WASM_EXEC_TEST(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,116 +1080,112 @@ 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), // -- - WASM_BRV(1, WASM_I8(51))), // -- - WASM_I8(52))); // -- + BUILD(r, WASM_BLOCK_I( // -- + WASM_IF(WASM_GET_LOCAL(0), // -- + WASM_BRV(1, WASM_I32V_1(51))), // -- + WASM_I32V_1(52))); // -- FOR_INT32_INPUTS(i) { int32_t expected = *i ? 51 : 52; CHECK_EQ(expected, r.Call(*i)); @@ -1251,51 +1193,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,9 +1247,9 @@ WASM_EXEC_TEST(Loop_empty_brif3) { } WASM_EXEC_TEST(Block_BrIf_P) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(51), WASM_GET_LOCAL(0)), - WASM_I8(52))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(51), WASM_GET_LOCAL(0)), + WASM_I32V_1(52))); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 51 : 52; CHECK_EQ(expected, r.Call(*i)); @@ -1317,12 +1257,12 @@ 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), // -- - WASM_SET_LOCAL(0, WASM_I8(71)), // -- - WASM_SET_LOCAL(0, WASM_I8(72))), // -- + BUILD(r, // -- + WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- + WASM_SET_LOCAL(0, WASM_I32V_2(71)), // -- + WASM_SET_LOCAL(0, WASM_I32V_2(72))), // -- WASM_GET_LOCAL(0)); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 71 : 72; @@ -1331,12 +1271,13 @@ 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), // -- RET_I8(81), // -- - RET_I8(82))); // -- + RET_I8(82)), // -- + WASM_ZERO); // -- FOR_INT32_INPUTS(i) { int32_t expected = *i ? 81 : 82; CHECK_EQ(expected, r.Call(*i)); @@ -1344,9 +1285,9 @@ 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))), + BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I32V_1(61))), WASM_GET_LOCAL(0)); FOR_INT32_INPUTS(i) { int32_t expected = *i ? 61 : *i; @@ -1355,18 +1296,18 @@ 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))); + BUILD(r, WASM_BLOCK_I(RET_I8(99), WASM_TEE_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), // -- - WASM_I8(22))); // -- + WASM_I32V_1(11), // -- + WASM_I32V_1(22))); // -- FOR_INT32_INPUTS(i) { int32_t expected = *i ? 11 : 22; CHECK_EQ(expected, r.Call(*i)); @@ -1374,11 +1315,11 @@ WASM_EXEC_TEST(ExprIf_P) { } WASM_EXEC_TEST(CountDown) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_LOOP(WASM_IFB( - WASM_GET_LOCAL(0), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), - WASM_BR(1))), + 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_I32V_1(1))), + WASM_BR(1))), WASM_GET_LOCAL(0)); CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(10)); @@ -1386,23 +1327,24 @@ WASM_EXEC_TEST(CountDown) { } WASM_EXEC_TEST(CountDown_fallthru) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_LOOP( - WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), - WASM_BRV(2, WASM_GET_LOCAL(0))), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), - WASM_CONTINUE(0)), - WASM_GET_LOCAL(0)); + 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))), + WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(1))), + WASM_CONTINUE(0)), + WASM_GET_LOCAL(0)); CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(10)); CHECK_EQ(0, r.Call(100)); } WASM_EXEC_TEST(WhileCountDown) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_WHILE( - WASM_GET_LOCAL(0), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))), + 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_I32V_1(1)))), WASM_GET_LOCAL(0)); CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(10)); @@ -1410,10 +1352,9 @@ 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_SET_LOCAL(0, WASM_I32V_2(99))), WASM_GET_LOCAL(0)); CHECK_EQ(99, r.Call(0, 11)); CHECK_EQ(65, r.Call(3, 65)); @@ -1422,10 +1363,9 @@ 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_DROP, WASM_SET_LOCAL(0, WASM_I32V_2(99))), WASM_GET_LOCAL(0)); CHECK_EQ(99, r.Call(0, 33)); CHECK_EQ(3, r.Call(1, 3)); @@ -1434,9 +1374,9 @@ 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_SET_LOCAL(0, WASM_I32V_2(93)))), WASM_GET_LOCAL(0)); CHECK_EQ(93, r.Call(0)); CHECK_EQ(3, r.Call(3)); @@ -1445,9 +1385,9 @@ 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_SET_LOCAL(0, WASM_I32V_2(93))))), WASM_GET_LOCAL(0)); CHECK_EQ(93, r.Call(0)); CHECK_EQ(3, r.Call(3)); @@ -1456,71 +1396,68 @@ 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)); + WASM_I32V_2(91)); CHECK_EQ(91, r.Call(0)); CHECK_EQ(91, r.Call(1)); CHECK_EQ(91, r.Call(-8734)); } 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)); + WASM_I32V_2(81)); CHECK_EQ(81, r.Call(0)); CHECK_EQ(81, r.Call(1)); CHECK_EQ(81, r.Call(-8734)); } 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))); + BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)); - 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)); + WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, 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(LoadMemI32_oob) { - TestingModule module(execution_mode); - int32_t* memory = module.AddMemoryElems<int32_t>(8); - WasmRunner<int32_t> r(&module, MachineType::Uint32()); - module.RandomizeMemory(1111); +WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) { + 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)); @@ -1531,10 +1468,7 @@ WASM_EXEC_TEST(LoadMemI32_oob) { } } -WASM_EXEC_TEST(LoadMem_offset_oob) { - TestingModule module(execution_mode); - module.AddMemoryElems<int32_t>(8); - +WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) { static const MachineType machineTypes[] = { MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), @@ -1542,8 +1476,10 @@ WASM_EXEC_TEST(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,46 +1494,43 @@ WASM_EXEC_TEST(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)); } -WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { +WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { const int kMemSize = 12; // 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))); + BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, + WASM_I32V_2(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()); } @@ -1605,21 +1538,19 @@ WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) { } } -WASM_EXEC_TEST(LoadMemI32_const_oob) { +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))); + BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, + WASM_I32V_2(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 +1559,25 @@ WASM_EXEC_TEST(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 +1585,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(StoreMem_offset_oob) { - TestingModule module(execution_mode); - byte* memory = module.AddMemoryElems<byte>(32); - +WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) { // 64-bit cases are handled in test-run-wasm-64.cc static const MachineType machineTypes[] = { MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), @@ -1680,8 +1606,10 @@ WASM_EXEC_TEST(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,43 +1628,40 @@ WASM_EXEC_TEST(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()); - const byte kSum = r.AllocateLocal(kAstI32); + WasmRunner<uint32_t, int32_t> r(execution_mode); + uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems); + const byte kSum = r.AllocateLocal(kWasmI32); - BUILD( - r, - WASM_WHILE( - WASM_GET_LOCAL(0), - WASM_BLOCK( - WASM_SET_LOCAL(kSum, - WASM_I32_ADD(WASM_GET_LOCAL(kSum), + BUILD(r, WASM_WHILE( + WASM_GET_LOCAL(0), + WASM_BLOCK( + WASM_SET_LOCAL( + kSum, WASM_I32_ADD(WASM_GET_LOCAL(kSum), WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)))), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), - WASM_GET_LOCAL(1)); + WASM_SET_LOCAL( + 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))), + WASM_GET_LOCAL(1)); // 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 +1670,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, // -- @@ -1756,78 +1680,76 @@ WASM_EXEC_TEST(CheckMachIntsZero) { /* */ kExprGetLocal, 0, // -- /* */ kExprI32LoadMem, 0, 0, // -- /* */ kExprIf, kLocalVoid, // -- - /* */ kExprI8Const, 255, // -- + /* */ kExprI32Const, 127, // -- /* */ kExprReturn, // -- /* */ kExprEnd, // -- /* */ kExprGetLocal, 0, // -- - /* */ kExprI8Const, 4, // -- + /* */ kExprI32Const, 4, // -- /* */ kExprI32Sub, // -- /* */ kExprTeeLocal, 0, // -- /* */ kExprBr, DEPTH_0, // -- /* */ kExprEnd, // -- /**/ kExprEnd, // -- - /**/ kExprI8Const, 0); // -- + /**/ kExprI32Const, 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()); - const byte kSum = r.AllocateLocal(kAstF32); + 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(kWasmF32); - BUILD( - r, - WASM_WHILE( - WASM_GET_LOCAL(0), - WASM_BLOCK( - WASM_SET_LOCAL(kSum, - WASM_F32_ADD(WASM_GET_LOCAL(kSum), + BUILD(r, WASM_WHILE( + WASM_GET_LOCAL(0), + WASM_BLOCK( + WASM_SET_LOCAL( + kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), WASM_LOAD_MEM(MachineType::Float32(), WASM_GET_LOCAL(0)))), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), - WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), - WASM_GET_LOCAL(0)); + WASM_SET_LOCAL( + 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))), + WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), + 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, + T* buffer, uint32_t size, ValueType 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)), - WASM_WHILE( - WASM_GET_LOCAL(0), - WASM_BLOCK(WASM_SET_LOCAL( - kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), - WASM_LOAD_MEM( - memType, WASM_GET_LOCAL(0)))), - WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), - WASM_I8(sizeof(T)))))), - WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), - WASM_GET_LOCAL(0)); + BUILD( + r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), + WASM_WHILE( + WASM_GET_LOCAL(0), + WASM_BLOCK(WASM_SET_LOCAL( + kAccum, + WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), + WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))), + WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), + WASM_I32V_1(sizeof(T)))))), + 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) { @@ -1835,20 +1757,19 @@ WASM_EXEC_TEST(MemF64_Mul) { double buffer[kSize] = {1, 2, 2, 2, 2, 2}; double result = GenerateAndRunFold<double>(execution_mode, kExprF64Mul, buffer, kSize, - kAstF64, MachineType::Float64()); + kWasmF64, MachineType::Float64()); CHECK_EQ(32, result); } 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); + BUILD(r, WASM_INFINITE_LOOP, WASM_ZERO); } 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,72 +1777,83 @@ WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) { } WASM_EXEC_TEST(Unreachable0a) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(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()); - BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(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()); - BUILD(r, WASM_UNREACHABLE, WASM_IF(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); + WasmRunner<int32_t, int32_t> r(kExecuteCompiled); + BUILD(r, WASM_UNREACHABLE, + WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_GET_LOCAL(0), WASM_DROP)), + WASM_ZERO); } 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_IF_ELSE_I(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); + r.module().AddMemory(8); 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)); CHECK_EQ(21, r.Call(21)); } +WASM_EXEC_TEST(BrV_Fallthrough) { + WasmRunner<int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BLOCK(WASM_BRV(1, WASM_I32V_1(42))), + WASM_I32V_1(22))); + CHECK_EQ(42, r.Call()); +} + WASM_EXEC_TEST(Infinite_Loop_not_taken1) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I32V_1(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()); - BUILD(r, - WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), - WASM_INFINITE_LOOP))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I( + WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(45)), + WASM_INFINITE_LOOP), + WASM_ZERO)); // Run the code, but don't go into the infinite loop. CHECK_EQ(45, r.Call(1)); } WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I32V_1(45), WASM_GET_LOCAL(0)), WASM_INFINITE_LOOP)); // Run the code, but don't go into the infinite loop. CHECK_EQ(45, r.Call(1)); @@ -1940,13 +1872,19 @@ static void TestBuildGraphForSimpleExpression(WasmOpcode opcode) { FunctionSig* sig = WasmOpcodes::Signature(opcode); if (sig->parameter_count() == 1) { - byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode)}; + byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, static_cast<byte>(opcode), + WASM_END}; TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, code + arraysize(code)); } else { - CHECK_EQ(2u, sig->parameter_count()); - byte code[] = {WASM_NO_LOCALS, kExprGetLocal, 0, kExprGetLocal, 1, - static_cast<byte>(opcode)}; + CHECK_EQ(2, sig->parameter_count()); + byte code[] = {WASM_NO_LOCALS, + kExprGetLocal, + 0, + kExprGetLocal, + 1, + static_cast<byte>(opcode), + WASM_END}; TestBuildingGraph(&zone, &jsgraph, nullptr, sig, nullptr, code, code + arraysize(code)); } @@ -1963,12 +1901,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 +1914,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 +1927,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 +1941,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 +1955,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 +1972,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 +2000,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 +2017,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 +2034,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 +2070,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; + ValueType param_types[20]; + for (int i = 0; i < 20; ++i) param_types[i] = kWasmF32; 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 +2107,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; + ValueType param_types[20]; + for (int i = 0; i < 20; ++i) param_types[i] = kWasmF64; 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 +2130,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); - BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), + 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_I32V_1(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), - WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); + BUILD(r, WASM_CALL_FUNCTION0(t.function_index()), + WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(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 +2174,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,27 +2190,28 @@ 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, - WASM_F64_SUB(WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), - WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), - WASM_I8(107)); + WASM_F64_SUB( + WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), + WASM_LOAD_MEM(MachineType::Float64(), WASM_I32V_1(8)))), + WASM_I32V_2(107)); 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 +2239,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)); + b.AddReturn(WasmOpcodes::ValueTypeFor(result)); for (int i = 0; i < num_params; ++i) { - b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i])); + b.AddParam(WasmOpcodes::ValueTypeFor(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. @@ -2347,11 +2266,11 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { // Load the arguments. for (int i = 0; i < num_params; ++i) { int offset = (i + 1) * kElemSize; - ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); + ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I32V_2(offset))); } // 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 +2284,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,15 +2304,12 @@ 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)), + byte local = r.AllocateLocal(kWasmI32); + BUILD(r, WASM_SET_LOCAL(local, WASM_I32V_2(99)), WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), @@ -2406,16 +2322,15 @@ WASM_EXEC_TEST(AddCall) { WASM_EXEC_TEST(MultiReturnSub) { FLAG_wasm_mv_prototype = true; - LocalType storage[] = {kAstI32, kAstI32, kAstI32, kAstI32}; + WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); + + ValueType storage[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32}; 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,10 +2342,10 @@ 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 storage[] = {type, type, type, type, type, type}; + ValueType type = WasmOpcodes::ValueTypeFor(MachineTypeForC<T>()); + ValueType storage[] = {type, type, type, type, type, type}; const size_t kNumReturns = 2; const size_t kNumParams = arraysize(storage) - kNumReturns; FunctionSig sig(kNumReturns, kNumParams, storage); @@ -2438,30 +2353,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 +2379,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,60 +2392,60 @@ 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()); - BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), - WASM_I8(1))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))), + WASM_I32V_1(1))); CHECK_EQ(1, r.Call(0)); CHECK_EQ(1, r.Call(1)); } WASM_EXEC_TEST(ExprBlock2b) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), - WASM_I8(2))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))), + WASM_I32V_1(2))); CHECK_EQ(2, r.Call(0)); CHECK_EQ(1, r.Call(1)); } WASM_EXEC_TEST(ExprBlock2c) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), - WASM_I8(1))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)), + WASM_I32V_1(1))); CHECK_EQ(1, r.Call(0)); CHECK_EQ(1, r.Call(1)); } WASM_EXEC_TEST(ExprBlock2d) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), - WASM_I8(2))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)), + WASM_I32V_1(2))); CHECK_EQ(2, r.Call(0)); CHECK_EQ(1, r.Call(1)); } WASM_EXEC_TEST(ExprBlock_ManualSwitch) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - 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)), - WASM_BRV(1, WASM_I8(12))), - WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), - WASM_BRV(1, WASM_I8(13))), - WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), - WASM_BRV(1, WASM_I8(14))), - WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), - WASM_BRV(1, WASM_I8(15))), - WASM_I8(99))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1)), + WASM_BRV(1, WASM_I32V_1(11))), + WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2)), + WASM_BRV(1, WASM_I32V_1(12))), + WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3)), + WASM_BRV(1, WASM_I32V_1(13))), + WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4)), + WASM_BRV(1, WASM_I32V_1(14))), + WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5)), + WASM_BRV(1, WASM_I32V_1(15))), + WASM_I32V_2(99))); CHECK_EQ(99, r.Call(0)); CHECK_EQ(11, r.Call(1)); CHECK_EQ(12, r.Call(2)); @@ -2546,19 +2456,19 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch) { } WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32()); - BUILD(r, - WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(11), - WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), - WASM_BRV_IFD(0, WASM_I8(12), - WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), - WASM_BRV_IFD(0, WASM_I8(13), - WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), - WASM_BRV_IFD(0, WASM_I8(14), - WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), - WASM_BRV_IFD(0, WASM_I8(15), - WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), - WASM_I8(99))); + WasmRunner<int32_t, int32_t> r(execution_mode); + BUILD(r, WASM_BLOCK_I( + WASM_BRV_IFD(0, WASM_I32V_1(11), + WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1))), + WASM_BRV_IFD(0, WASM_I32V_1(12), + WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2))), + WASM_BRV_IFD(0, WASM_I32V_1(13), + WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3))), + WASM_BRV_IFD(0, WASM_I32V_1(14), + WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4))), + WASM_BRV_IFD(0, WASM_I32V_1(15), + WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5))), + WASM_I32V_2(99))); CHECK_EQ(99, r.Call(0)); CHECK_EQ(11, r.Call(1)); CHECK_EQ(12, r.Call(2)); @@ -2569,13 +2479,14 @@ 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), - WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), - WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); + BUILD( + r, + WASM_IF_ELSE_I( + WASM_GET_LOCAL(0), + WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)), + WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14)))); CHECK_EQ(11, r.Call(1, 1)); CHECK_EQ(12, r.Call(1, 0)); @@ -2584,26 +2495,25 @@ 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)), - WASM_BRV(1, WASM_I8(14))))); + BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), + WASM_BRV(0, WASM_I32V_1(11)), + WASM_BRV(1, WASM_I32V_1(14))))); CHECK_EQ(11, r.Call(1)); CHECK_EQ(14, r.Call(0)); } 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), - WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), - WASM_BRV(1, WASM_I8(12))), - WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), - WASM_BRV(1, WASM_I8(14)))))); + WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(11)), + WASM_BRV(1, WASM_I32V_1(12))), + WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(13)), + WASM_BRV(1, WASM_I32V_1(14)))))); CHECK_EQ(11, r.Call(1, 1)); CHECK_EQ(12, r.Call(1, 0)); @@ -2611,64 +2521,66 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) { CHECK_EQ(14, r.Call(0, 0)); } -WASM_EXEC_TEST(SimpleCallIndirect) { +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(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); + // Build the caller function. + BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66), + WASM_I32V_1(22))); CHECK_EQ(88, r.Call(0)); CHECK_EQ(44, r.Call(1)); CHECK_TRAP(r.Call(2)); } -WASM_EXEC_TEST(MultipleCallIndirect) { +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)), @@ -2686,49 +2598,49 @@ WASM_EXEC_TEST(MultipleCallIndirect) { CHECK_TRAP(r.Call(2, 1, 0)); } -WASM_EXEC_TEST(CallIndirect_EmptyTable) { +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(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); + // Build the caller function. + BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66), + WASM_I32V_1(22))); CHECK_TRAP(r.Call(0)); CHECK_TRAP(r.Call(1)); CHECK_TRAP(r.Call(2)); } -WASM_EXEC_TEST(CallIndirect_canonical) { +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,13 +2648,13 @@ WASM_EXEC_TEST(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(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11))); + // Build the caller function. + BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(77), + WASM_I32V_1(11))); CHECK_EQ(88, r.Call(0)); CHECK_EQ(66, r.Call(1)); @@ -2753,64 +2665,63 @@ WASM_EXEC_TEST(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 +2730,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 +2739,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 +2748,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) { @@ -2851,8 +2759,8 @@ WASM_EXEC_TEST(F64Max) { } } -WASM_EXEC_TEST(I32SConvertF32) { - WasmRunner<int32_t> r(execution_mode, MachineType::Float32()); +WASM_EXEC_TEST_WITH_TRAP(I32SConvertF32) { + 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 @@ -2871,8 +2779,8 @@ WASM_EXEC_TEST(I32SConvertF32) { } } -WASM_EXEC_TEST(I32SConvertF64) { - WasmRunner<int32_t> r(execution_mode, MachineType::Float64()); +WASM_EXEC_TEST_WITH_TRAP(I32SConvertF64) { + 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- @@ -2890,8 +2798,8 @@ WASM_EXEC_TEST(I32SConvertF64) { } } -WASM_EXEC_TEST(I32UConvertF32) { - WasmRunner<uint32_t> r(execution_mode, MachineType::Float32()); +WASM_EXEC_TEST_WITH_TRAP(I32UConvertF32) { + 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 @@ -2907,8 +2815,8 @@ WASM_EXEC_TEST(I32UConvertF32) { } } -WASM_EXEC_TEST(I32UConvertF64) { - WasmRunner<uint32_t> r(execution_mode, MachineType::Float64()); +WASM_EXEC_TEST_WITH_TRAP(I32UConvertF64) { + 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 +2833,7 @@ WASM_EXEC_TEST(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 +2842,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) { @@ -2944,44 +2850,39 @@ WASM_EXEC_TEST(F32CopySign) { } } -static void CompileCallIndirectMany(LocalType param) { +static void CompileCallIndirectMany(ValueType param) { // Make sure we don't run out of registers when compiling indirect calls // 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(), kWasmStmt, 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) { ADD_CODE(code, kExprGetLocal, p); } - ADD_CODE(code, kExprI8Const, 0); + ADD_CODE(code, kExprI32Const, 0); ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); t.Build(&code[0], &code[0] + code.size()); - t.Compile(); } } -TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); } +TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kWasmI32); } -TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } +TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kWasmF32); } -TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } +TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kWasmF64); } -WASM_EXEC_TEST(Int32RemS_dead) { - WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), - MachineType::Int32()); +WASM_EXEC_TEST_WITH_TRAP(Int32RemS_dead) { + 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(); |