Index: test/unittests/wasm/ast-decoder-unittest.cc |
diff --git a/test/unittests/wasm/ast-decoder-unittest.cc b/test/unittests/wasm/ast-decoder-unittest.cc |
index 9b54c5af140452f3414eb1d0bd10c3981da15d3e..d4141eea104ac3022835a38fb08c94e59dffea15 100644 |
--- a/test/unittests/wasm/ast-decoder-unittest.cc |
+++ b/test/unittests/wasm/ast-decoder-unittest.cc |
@@ -18,9 +18,13 @@ namespace v8 { |
namespace internal { |
namespace wasm { |
+#define B1(a) kExprBlock, a, kExprEnd |
+#define B2(a, b) kExprBlock, a, b, kExprEnd |
+#define B3(a, b, c) kExprBlock, a, b, c, kExprEnd |
+ |
static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; |
static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; |
-static const byte kCodeSetLocal0[] = {kExprSetLocal, 0, kExprI8Const, 0}; |
+static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; |
static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; |
static const MachineType machineTypes[] = { |
@@ -36,7 +40,7 @@ static const WasmOpcode kInt32BinopOpcodes[] = { |
kExprI32LeS, kExprI32LtU, kExprI32LeU}; |
#define WASM_BRV_IF_ZERO(depth, val) \ |
- kExprBrIf, static_cast<byte>(depth), val, WASM_ZERO |
+ val, WASM_ZERO, kExprBrIf, ARITY_1, static_cast<byte>(depth) |
#define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x)) |
@@ -74,7 +78,7 @@ class AstDecoderTest : public TestWithZone { |
local_decls.AddLocals(count, type); |
} |
- // Preprends local variable declarations and renders nice error messages for |
+ // Prepends local variable declarations and renders nice error messages for |
// verification failures. |
void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, |
const byte* end) { |
@@ -107,8 +111,7 @@ class AstDecoderTest : public TestWithZone { |
void TestBinop(WasmOpcode opcode, FunctionSig* success) { |
// op(local[0], local[1]) |
- byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0, kExprGetLocal, |
- 1}; |
+ byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
EXPECT_VERIFIES(success, code); |
// Try all combinations of return and parameter types. |
@@ -134,7 +137,7 @@ class AstDecoderTest : public TestWithZone { |
void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) { |
// Return(op(local[0])) |
- byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0}; |
+ byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))}; |
{ |
LocalType types[] = {ret_type, param_type}; |
FunctionSig sig(1, 1, types); |
@@ -155,7 +158,6 @@ class AstDecoderTest : public TestWithZone { |
} |
}; |
- |
TEST_F(AstDecoderTest, Int8Const) { |
byte code[] = {kExprI8Const, 0}; |
for (int i = -128; i < 128; i++) { |
@@ -176,12 +178,6 @@ TEST_F(AstDecoderTest, IncompleteIf1) { |
EXPECT_FAILURE(sigs.i_i(), code); |
} |
-TEST_F(AstDecoderTest, IncompleteIf2) { |
- byte code[] = {kExprIf, kExprI8Const, 0}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
-} |
- |
TEST_F(AstDecoderTest, Int8Const_fallthru) { |
byte code[] = {kExprI8Const, 0, kExprI8Const, 1}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
@@ -303,15 +299,15 @@ TEST_F(AstDecoderTest, Binops_off_end) { |
EXPECT_FAILURE(sigs.i_i(), code1); |
} |
- byte code3[] = {0, kExprGetLocal, 0}; // [opcode] [expr] |
+ byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] |
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
- code3[0] = kInt32BinopOpcodes[i]; |
+ code3[2] = kInt32BinopOpcodes[i]; |
EXPECT_FAILURE(sigs.i_i(), code3); |
} |
- byte code4[] = {0, kExprGetLocal, 0, 0}; // [opcode] [expr] [opcode] |
+ byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] |
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
- code4[0] = kInt32BinopOpcodes[i]; |
+ code4[1] = kInt32BinopOpcodes[i]; |
code4[3] = kInt32BinopOpcodes[i]; |
EXPECT_FAILURE(sigs.i_i(), code4); |
} |
@@ -327,175 +323,238 @@ TEST_F(AstDecoderTest, Nop) { |
} |
TEST_F(AstDecoderTest, SetLocal0_param) { |
- static const byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES(sigs.i_i(), kCodeSetLocal0); |
+ EXPECT_FAILURE(sigs.f_ff(), kCodeSetLocal0); |
+ EXPECT_FAILURE(sigs.d_dd(), kCodeSetLocal0); |
} |
TEST_F(AstDecoderTest, SetLocal0_local) { |
- byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; |
+ EXPECT_FAILURE(sigs.i_v(), kCodeSetLocal0); |
AddLocals(kAstI32, 1); |
- EXPECT_VERIFIES(sigs.i_v(), code); |
+ EXPECT_VERIFIES(sigs.i_v(), kCodeSetLocal0); |
} |
TEST_F(AstDecoderTest, SetLocalN_local) { |
for (byte i = 1; i < 8; i++) { |
AddLocals(kAstI32, 1); |
for (byte j = 0; j < i; j++) { |
- byte code[] = {kExprSetLocal, j, kExprI8Const, i}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_SET_LOCAL(j, WASM_I8(i))); |
} |
} |
} |
+TEST_F(AstDecoderTest, BlockN) { |
+ const int kMaxSize = 200; |
+ byte buffer[kMaxSize + 2]; |
+ |
+ for (int i = 0; i <= kMaxSize; i++) { |
+ memset(buffer, kExprNop, sizeof(buffer)); |
+ buffer[0] = kExprBlock; |
+ buffer[i + 1] = kExprEnd; |
+ Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 2); |
+ } |
+} |
+ |
TEST_F(AstDecoderTest, Block0) { |
- static const byte code[] = {kExprBlock, 0}; |
+ static const byte code[] = {kExprBlock, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
} |
TEST_F(AstDecoderTest, Block0_fallthru1) { |
- static const byte code[] = {kExprBlock, 0, kExprBlock, 0}; |
+ static const byte code[] = {kExprBlock, kExprBlock, kExprEnd, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, Block0Block0) { |
+ static const byte code[] = {kExprBlock, kExprEnd, kExprBlock, kExprEnd}; |
+ EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, Block0_end_end) { |
+ static const byte code[] = {kExprBlock, kExprEnd, kExprEnd}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
} |
TEST_F(AstDecoderTest, Block1) { |
- static const byte code[] = {kExprBlock, 1, kExprSetLocal, 0, kExprI8Const, 0}; |
+ byte code[] = {B1(WASM_SET_LOCAL(0, WASM_ZERO))}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_FAILURE(sigs.d_dd(), code); |
} |
-TEST_F(AstDecoderTest, Block0_fallthru2) { |
- static const byte code[] = {kExprBlock, 0, kExprSetLocal, 0, kExprI8Const, 0}; |
+TEST_F(AstDecoderTest, Block1_i) { |
+ byte code[] = {B1(WASM_ZERO)}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_FAILURE(sigs.f_ff(), code); |
+ EXPECT_FAILURE(sigs.d_dd(), code); |
+ EXPECT_FAILURE(sigs.l_ll(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, Block1_f) { |
+ byte code[] = {B1(WASM_F32(0))}; |
+ EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_VERIFIES(sigs.f_ff(), code); |
+ EXPECT_FAILURE(sigs.d_dd(), code); |
+ EXPECT_FAILURE(sigs.l_ll(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, Block1_continue) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0))); |
+ EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(1))); |
+ EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(2))); |
+ EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(3))); |
+} |
+ |
+TEST_F(AstDecoderTest, Block1_br) { |
+ EXPECT_FAILURE_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_1, DEPTH_0, |
+ kExprEnd); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_0, DEPTH_0, |
+ kExprEnd); |
+} |
+ |
+TEST_F(AstDecoderTest, Block2_br) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_NOP, WASM_BR(0))); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_NOP)); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Block2) { |
- static const byte code[] = {kExprBlock, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprSetLocal, 0, kExprI8Const, 0}; // -- |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ B2(WASM_NOP, WASM_SET_LOCAL(0, WASM_ZERO))); |
+ EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO))); |
} |
-TEST_F(AstDecoderTest, Block2_fallthru) { |
- static const byte code[] = {kExprBlock, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprI8Const, 11}; // -- |
+TEST_F(AstDecoderTest, Block2b) { |
+ byte code[] = {B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.f_ff(), code); |
} |
-TEST_F(AstDecoderTest, BlockN) { |
- byte block[] = {kExprBlock, 2}; |
+TEST_F(AstDecoderTest, Block2_fallthru) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO)), |
+ WASM_I8(23)); |
+} |
- for (size_t i = 0; i < 10; i++) { |
- size_t total = sizeof(block) + sizeof(kCodeSetLocal0) * i; |
- byte* code = reinterpret_cast<byte*>(malloc(total)); |
- memcpy(code, block, sizeof(block)); |
- code[1] = static_cast<byte>(i); |
- for (size_t j = 0; j < i; j++) { |
- memcpy(code + sizeof(block) + j * sizeof(kCodeSetLocal0), kCodeSetLocal0, |
- sizeof(kCodeSetLocal0)); |
- } |
- Verify(kSuccess, sigs.v_i(), code, code + total); |
- free(code); |
- } |
+TEST_F(AstDecoderTest, Block3) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.i_i(), B3(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_I8(11))); |
} |
-TEST_F(AstDecoderTest, BlockN_off_end) { |
- for (byte i = 2; i < 10; i++) { |
- byte code[] = {kExprBlock, i, kExprNop}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- } |
+TEST_F(AstDecoderTest, Block5) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0))); |
+ |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), |
+ WASM_BLOCK(4, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), |
+ WASM_BLOCK(5, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
} |
-TEST_F(AstDecoderTest, Block1_break) { |
- static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+TEST_F(AstDecoderTest, BlockF32) { |
+ static const byte code[] = {kExprBlock, kExprF32Const, 0, 0, 0, 0, kExprEnd}; |
+ EXPECT_VERIFIES(sigs.f_ff(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE(sigs.d_dd(), code); |
} |
-TEST_F(AstDecoderTest, Block2_break) { |
- static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 0, kExprNop}; |
+TEST_F(AstDecoderTest, BlockN_off_end) { |
+ byte code[] = {kExprBlock, kExprNop, kExprNop, kExprNop, kExprNop, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
+ for (size_t i = 1; i < arraysize(code); i++) { |
+ Verify(kError, sigs.v_v(), code, code + i); |
+ } |
} |
-TEST_F(AstDecoderTest, Block1_continue) { |
- static const byte code[] = {kExprBlock, 1, kExprBr, 1, kExprNop}; |
+TEST_F(AstDecoderTest, Block2_continue) { |
+ static const byte code[] = {kExprBlock, kExprBr, ARITY_0, |
+ DEPTH_1, kExprNop, kExprEnd}; |
EXPECT_FAILURE(sigs.v_v(), code); |
} |
-TEST_F(AstDecoderTest, Block2_continue) { |
- static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 1, kExprNop}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
+TEST_F(AstDecoderTest, NestedBlock_return) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), B1(B1(WASM_RETURN1(WASM_ZERO)))); |
} |
-TEST_F(AstDecoderTest, ExprBlock0) { |
- static const byte code[] = {kExprBlock, 0}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+TEST_F(AstDecoderTest, BlockBinop) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(B1(WASM_I8(1)), WASM_I8(2))); |
} |
-TEST_F(AstDecoderTest, ExprBlock1a) { |
- static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+TEST_F(AstDecoderTest, BlockBrBinop) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ WASM_I32_AND(B1(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); |
} |
-TEST_F(AstDecoderTest, ExprBlock1b) { |
- static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; |
- EXPECT_FAILURE(sigs.f_ff(), code); |
+TEST_F(AstDecoderTest, If_empty_stack) { |
+ byte code[] = {kExprIf}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
} |
-TEST_F(AstDecoderTest, ExprBlock1c) { |
- static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0}; |
- EXPECT_VERIFIES(sigs.f_ff(), code); |
+TEST_F(AstDecoderTest, If_incomplete1) { |
+ byte code[] = {kExprI8Const, 0, kExprIf}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
} |
-TEST_F(AstDecoderTest, IfEmpty) { |
- static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+TEST_F(AstDecoderTest, If_incomplete2) { |
+ byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
} |
-TEST_F(AstDecoderTest, IfSet) { |
- static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal, |
- 0, kExprI8Const, 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+TEST_F(AstDecoderTest, If_else_else) { |
+ byte code[] = {kExprI8Const, 0, kExprIf, kExprElse, kExprElse, kExprEnd}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
} |
-TEST_F(AstDecoderTest, IfBlock1) { |
- static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprBlock, |
- 1, kExprSetLocal, 0, kExprI8Const, |
- 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+TEST_F(AstDecoderTest, IfEmpty) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0, kExprIf, kExprEnd); |
} |
-TEST_F(AstDecoderTest, IfBlock2) { |
- static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprBlock, |
- 2, kExprSetLocal, 0, kExprI8Const, |
- 0, kExprSetLocal, 0, kExprI8Const, |
- 0}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+TEST_F(AstDecoderTest, IfSet) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
} |
TEST_F(AstDecoderTest, IfElseEmpty) { |
- static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprNop, |
- kExprNop}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprIf, kExprElse, |
+ kExprEnd); |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
} |
-TEST_F(AstDecoderTest, IfElseSet) { |
- static const byte code[] = {kExprIfElse, |
- kExprGetLocal, |
- 0, // -- |
- kExprSetLocal, |
- 0, |
- kExprI8Const, |
- 0, // -- |
- kExprSetLocal, |
- 0, |
- kExprI8Const, |
- 1}; // -- |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+TEST_F(AstDecoderTest, IfElseUnreachable1) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.i_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.i_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE)); |
} |
-TEST_F(AstDecoderTest, IfElseUnreachable) { |
- static const byte code[] = {kExprIfElse, kExprI8Const, 0, |
- kExprUnreachable, kExprGetLocal, 0}; |
+TEST_F(AstDecoderTest, IfElseUnreachable2) { |
+ static const byte code[] = { |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
LocalType types[] = {kAstI32, kLocalTypes[i]}; |
@@ -509,66 +568,136 @@ TEST_F(AstDecoderTest, IfElseUnreachable) { |
} |
} |
+TEST_F(AstDecoderTest, IfBreak) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); |
+ EXPECT_FAILURE_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); |
+} |
+ |
+TEST_F(AstDecoderTest, IfElseBreak) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); |
+ EXPECT_FAILURE_INLINE(sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); |
+} |
+ |
+TEST_F(AstDecoderTest, Block_else) { |
+ byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.i_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, IfNop) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, IfNopElseNop) { |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, If_end_end) { |
+ static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprEnd, kExprEnd}; |
+ EXPECT_FAILURE(sigs.v_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, If_falloff) { |
+ static const byte code[] = {kExprGetLocal, 0, kExprIf}; |
+ EXPECT_FAILURE(sigs.v_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, IfElse_falloff) { |
+ static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprNop, kExprElse}; |
+ EXPECT_FAILURE(sigs.v_i(), code); |
+} |
+ |
+TEST_F(AstDecoderTest, IfElseNop) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, IfBlock1) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), |
+ B1(WASM_SET_LOCAL(0, WASM_ZERO)), WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, IfBlock1b) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); |
+} |
+ |
+TEST_F(AstDecoderTest, IfBlock2a) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO)))); |
+} |
+ |
+TEST_F(AstDecoderTest, IfBlock2b) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO)), |
+ WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, IfElseSet) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_I8(1)))); |
+} |
+ |
TEST_F(AstDecoderTest, Loop0) { |
- static const byte code[] = {kExprLoop, 0}; |
+ static const byte code[] = {kExprLoop, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
} |
TEST_F(AstDecoderTest, Loop1) { |
- static const byte code[] = {kExprLoop, 1, kExprSetLocal, 0, kExprI8Const, 0}; |
+ static const byte code[] = {WASM_LOOP(1, WASM_SET_LOCAL(0, WASM_ZERO))}; |
EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(sigs.f_ff(), code); |
} |
TEST_F(AstDecoderTest, Loop2) { |
- static const byte code[] = {kExprLoop, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprSetLocal, 0, kExprI8Const, 0}; // -- |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO))); |
} |
TEST_F(AstDecoderTest, Loop1_continue) { |
- static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Loop1_break) { |
- static const byte code[] = {kExprLoop, 1, kExprBr, 1, kExprNop}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1))); |
} |
TEST_F(AstDecoderTest, Loop2_continue) { |
- static const byte code[] = {kExprLoop, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprBr, 0, kExprNop}; // -- |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Loop2_break) { |
- static const byte code[] = {kExprLoop, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprBr, 1, kExprNop}; // -- |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); |
} |
TEST_F(AstDecoderTest, ExprLoop0) { |
- static const byte code[] = {kExprLoop, 0}; |
+ static const byte code[] = {kExprLoop, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
} |
TEST_F(AstDecoderTest, ExprLoop1a) { |
- static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); |
} |
TEST_F(AstDecoderTest, ExprLoop1b) { |
- static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); |
+ EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); |
} |
TEST_F(AstDecoderTest, ExprLoop2_unreachable) { |
- static const byte code[] = {kExprLoop, 2, kExprBr, 0, |
- kExprI8Const, 0, kExprNop}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(2, WASM_BR(0), WASM_NOP)); |
} |
TEST_F(AstDecoderTest, ReturnVoid1) { |
@@ -579,7 +708,7 @@ TEST_F(AstDecoderTest, ReturnVoid1) { |
} |
TEST_F(AstDecoderTest, ReturnVoid2) { |
- static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; |
+ static const byte code[] = {kExprBlock, kExprBr, ARITY_0, DEPTH_0, kExprEnd}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
EXPECT_FAILURE(sigs.i_i(), code); |
EXPECT_FAILURE(sigs.i_f(), code); |
@@ -598,67 +727,85 @@ TEST_F(AstDecoderTest, ReturnVoid3) { |
TEST_F(AstDecoderTest, Unreachable1) { |
EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable); |
EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), |
- WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(2, WASM_BR(0), WASM_ZERO)); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_UNREACHABLE, WASM_ZERO)); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_ZERO)); |
EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO)); |
EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_BR(0), WASM_ZERO)); |
} |
-TEST_F(AstDecoderTest, Codeiness) { |
- VERIFY(kExprLoop, 2, // -- |
- kExprSetLocal, 0, kExprI8Const, 0, // -- |
- kExprBr, 0, kExprNop); // -- |
+TEST_F(AstDecoderTest, Unreachable_binop) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); |
} |
-TEST_F(AstDecoderTest, ExprIf1) { |
- VERIFY(kExprIf, kExprGetLocal, 0, kExprI8Const, 0, kExprI8Const, 1); |
- VERIFY(kExprIf, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0); |
- VERIFY(kExprIf, kExprGetLocal, 0, kExprI32Add, kExprGetLocal, 0, |
- kExprGetLocal, 0, kExprI8Const, 1); |
+TEST_F(AstDecoderTest, Unreachable_select) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); |
} |
-TEST_F(AstDecoderTest, ExprIf_off_end) { |
- static const byte kCode[] = {kExprIf, kExprGetLocal, 0, kExprGetLocal, |
- 0, kExprGetLocal, 0}; |
- for (size_t len = 1; len < arraysize(kCode); len++) { |
+TEST_F(AstDecoderTest, If1) { |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), |
+ WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_INLINE( |
+ sigs.i_i(), |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); |
+} |
+ |
+TEST_F(AstDecoderTest, If_off_end) { |
+ static const byte kCode[] = { |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; |
+ for (size_t len = 3; len < arraysize(kCode); len++) { |
Verify(kError, sigs.i_i(), kCode, kCode + len); |
} |
} |
-TEST_F(AstDecoderTest, ExprIf_type) { |
- { |
- // float|double ? 1 : 2 |
- static const byte kCode[] = {kExprIfElse, kExprGetLocal, 0, kExprI8Const, |
- 1, kExprI8Const, 2}; |
- EXPECT_FAILURE(sigs.i_f(), kCode); |
- EXPECT_FAILURE(sigs.i_d(), kCode); |
- } |
- { |
- // 1 ? float|double : 2 |
- static const byte kCode[] = {kExprIfElse, kExprI8Const, 1, kExprGetLocal, |
- 0, kExprI8Const, 2}; |
- EXPECT_FAILURE(sigs.i_f(), kCode); |
- EXPECT_FAILURE(sigs.i_d(), kCode); |
- } |
- { |
- // stmt ? 0 : 1 |
- static const byte kCode[] = {kExprIfElse, kExprNop, kExprI8Const, |
- 0, kExprI8Const, 1}; |
- EXPECT_FAILURE(sigs.i_i(), kCode); |
- } |
- { |
- // 0 ? stmt : 1 |
- static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, |
- kExprNop, kExprI8Const, 1}; |
- EXPECT_FAILURE(sigs.i_i(), kCode); |
- } |
- { |
- // 0 ? 1 : stmt |
- static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, kExprI8Const, 1, |
- 0, kExprBlock}; |
- EXPECT_FAILURE(sigs.i_i(), kCode); |
- } |
+TEST_F(AstDecoderTest, If_type1) { |
+ // float|double ? 1 : 2 |
+ static const byte kCode[] = { |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; |
+ EXPECT_VERIFIES(sigs.i_i(), kCode); |
+ EXPECT_FAILURE(sigs.i_f(), kCode); |
+ EXPECT_FAILURE(sigs.i_d(), kCode); |
+} |
+ |
+TEST_F(AstDecoderTest, If_type2) { |
+ // 1 ? float|double : 2 |
+ static const byte kCode[] = { |
+ WASM_IF_ELSE(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; |
+ EXPECT_VERIFIES(sigs.i_i(), kCode); |
+ EXPECT_FAILURE(sigs.i_f(), kCode); |
+ EXPECT_FAILURE(sigs.i_d(), kCode); |
+} |
+ |
+TEST_F(AstDecoderTest, If_type3) { |
+ // stmt ? 0 : 1 |
+ static const byte kCode[] = {WASM_IF_ELSE(WASM_NOP, WASM_I8(0), WASM_I8(1))}; |
+ EXPECT_FAILURE(sigs.i_i(), kCode); |
+ EXPECT_FAILURE(sigs.i_f(), kCode); |
+ EXPECT_FAILURE(sigs.i_d(), kCode); |
+} |
+ |
+TEST_F(AstDecoderTest, If_type4) { |
+ // 0 ? stmt : 1 |
+ static const byte kCode[] = { |
+ WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; |
+ EXPECT_FAILURE(sigs.i_i(), kCode); |
+ EXPECT_FAILURE(sigs.i_f(), kCode); |
+ EXPECT_FAILURE(sigs.i_d(), kCode); |
+} |
+ |
+TEST_F(AstDecoderTest, If_type5) { |
+ // 0 ? 1 : stmt |
+ static const byte kCode[] = {WASM_IF_ELSE(WASM_ZERO, WASM_I8(1), WASM_NOP)}; |
+ EXPECT_FAILURE(sigs.i_i(), kCode); |
+ EXPECT_FAILURE(sigs.i_f(), kCode); |
+ EXPECT_FAILURE(sigs.i_d(), kCode); |
} |
TEST_F(AstDecoderTest, Int64Local_param) { |
@@ -669,8 +816,7 @@ TEST_F(AstDecoderTest, Int64Locals) { |
for (byte i = 1; i < 8; i++) { |
AddLocals(kAstI64, 1); |
for (byte j = 0; j < i; j++) { |
- byte code[] = {kExprGetLocal, j}; |
- EXPECT_VERIFIES(sigs.l_v(), code); |
+ EXPECT_VERIFIES_INLINE(sigs.l_v(), WASM_GET_LOCAL(j)); |
} |
} |
} |
@@ -737,7 +883,7 @@ TEST_F(AstDecoderTest, MacrosStmt) { |
VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
VERIFY(WASM_NOP); |
- VERIFY(WASM_BLOCK(1, WASM_NOP)); |
+ VERIFY(B1(WASM_NOP)); |
VERIFY(WASM_LOOP(1, WASM_NOP)); |
VERIFY(WASM_LOOP(1, WASM_BREAK(0))); |
VERIFY(WASM_LOOP(1, WASM_CONTINUE(0))); |
@@ -760,30 +906,30 @@ TEST_F(AstDecoderTest, MacrosContinue) { |
} |
TEST_F(AstDecoderTest, MacrosVariadic) { |
- VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP)); |
- VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP)); |
+ VERIFY(B2(WASM_NOP, WASM_NOP)); |
+ VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP)); |
VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP)); |
VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP)); |
} |
TEST_F(AstDecoderTest, MacrosNestedBlocks) { |
- VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_BLOCK(2, WASM_NOP, WASM_NOP))); |
- VERIFY(WASM_BLOCK(3, WASM_NOP, // -- |
- WASM_BLOCK(2, WASM_NOP, WASM_NOP), // -- |
- WASM_BLOCK(2, WASM_NOP, WASM_NOP))); // -- |
- VERIFY(WASM_BLOCK(1, WASM_BLOCK(1, WASM_BLOCK(2, WASM_NOP, WASM_NOP)))); |
+ VERIFY(B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); |
+ VERIFY(B3(WASM_NOP, // -- |
+ B2(WASM_NOP, WASM_NOP), // -- |
+ B2(WASM_NOP, WASM_NOP))); // -- |
+ VERIFY(B1(B1(B2(WASM_NOP, WASM_NOP)))); |
} |
TEST_F(AstDecoderTest, MultipleReturn) { |
static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
FunctionSig sig_ii_v(2, 0, kIntTypes5); |
- EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); |
- EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO)); |
+ EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
+ EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
FunctionSig sig_iii_v(3, 0, kIntTypes5); |
EXPECT_VERIFIES_INLINE(&sig_iii_v, |
- WASM_RETURN(WASM_ZERO, WASM_ONE, WASM_I8(44))); |
- EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); |
+ WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
+ EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
} |
TEST_F(AstDecoderTest, MultipleReturn_fallthru) { |
@@ -887,78 +1033,57 @@ TEST_F(AstDecoderTest, MemorySize) { |
} |
TEST_F(AstDecoderTest, GrowMemory) { |
- byte code[] = {kExprGrowMemory, kExprGetLocal, 0}; |
+ byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
EXPECT_FAILURE(sigs.i_d(), code); |
} |
TEST_F(AstDecoderTest, LoadMemOffset) { |
for (int offset = 0; offset < 128; offset += 7) { |
- byte code[] = {kExprI32LoadMem, ZERO_ALIGNMENT, static_cast<byte>(offset), |
- kExprI8Const, 0}; |
+ byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ static_cast<byte>(offset)}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
} |
} |
TEST_F(AstDecoderTest, StoreMemOffset) { |
for (int offset = 0; offset < 128; offset += 7) { |
- byte code[] = { |
- kExprI32StoreMem, 0, static_cast<byte>(offset), kExprI8Const, 0, |
- kExprI8Const, 0}; |
+ byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, |
+ WASM_ZERO, WASM_ZERO)}; |
EXPECT_VERIFIES(sigs.i_i(), code); |
} |
} |
-TEST_F(AstDecoderTest, LoadMemOffset_varint) { |
- byte code1[] = {kExprI32LoadMem, ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, |
- 0}; |
- byte code2[] = {kExprI32LoadMem, ZERO_ALIGNMENT, 0x80, 1, kExprI8Const, 0}; |
- byte code3[] = { |
- kExprI32LoadMem, ZERO_ALIGNMENT, 0x81, 0x82, 5, kExprI8Const, 0}; |
- byte code4[] = { |
- kExprI32LoadMem, ZERO_ALIGNMENT, 0x83, 0x84, 0x85, 7, kExprI8Const, 0}; |
+#define BYTE0(x) ((x)&0x7F) |
+#define BYTE1(x) ((x >> 7) & 0x7F) |
+#define BYTE2(x) ((x >> 14) & 0x7F) |
+#define BYTE3(x) ((x >> 21) & 0x7F) |
- EXPECT_VERIFIES(sigs.i_i(), code1); |
- EXPECT_VERIFIES(sigs.i_i(), code2); |
- EXPECT_VERIFIES(sigs.i_i(), code3); |
- EXPECT_VERIFIES(sigs.i_i(), code4); |
+#define VARINT1(x) BYTE0(x) |
+#define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) |
+#define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) |
+#define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) |
+ |
+TEST_F(AstDecoderTest, LoadMemOffset_varint) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT1(0x45)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT2(0x3999)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT3(0x344445)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT4(0x36666667)); |
} |
TEST_F(AstDecoderTest, StoreMemOffset_varint) { |
- byte code1[] = { |
- kExprI32StoreMem, ZERO_ALIGNMENT, 0, kExprI8Const, 0, kExprI8Const, 0}; |
- byte code2[] = {kExprI32StoreMem, |
- ZERO_ALIGNMENT, |
- 0x80, |
- 1, |
- kExprI8Const, |
- 0, |
- kExprI8Const, |
- 0}; |
- byte code3[] = {kExprI32StoreMem, |
- ZERO_ALIGNMENT, |
- 0x81, |
- 0x82, |
- 5, |
- kExprI8Const, |
- 0, |
- kExprI8Const, |
- 0}; |
- byte code4[] = {kExprI32StoreMem, |
- ZERO_ALIGNMENT, |
- 0x83, |
- 0x84, |
- 0x85, |
- 7, |
- kExprI8Const, |
- 0, |
- kExprI8Const, |
- 0}; |
- |
- EXPECT_VERIFIES(sigs.i_i(), code1); |
- EXPECT_VERIFIES(sigs.i_i(), code2); |
- EXPECT_VERIFIES(sigs.i_i(), code3); |
- EXPECT_VERIFIES(sigs.i_i(), code4); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, |
+ ZERO_ALIGNMENT, VARINT1(0x33)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, |
+ ZERO_ALIGNMENT, VARINT2(0x1111)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, |
+ ZERO_ALIGNMENT, VARINT3(0x222222)); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem, |
+ ZERO_ALIGNMENT, VARINT4(0x44444444)); |
} |
TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
@@ -966,9 +1091,7 @@ TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
LocalType local_type = kLocalTypes[i]; |
for (size_t j = 0; j < arraysize(machineTypes); j++) { |
MachineType mem_type = machineTypes[j]; |
- byte code[] = { |
- static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)), |
- ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, 0}; |
+ byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; |
FunctionSig sig(1, 0, &local_type); |
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
EXPECT_VERIFIES(&sig, code); |
@@ -984,14 +1107,7 @@ TEST_F(AstDecoderTest, AllStoreMemCombinations) { |
LocalType local_type = kLocalTypes[i]; |
for (size_t j = 0; j < arraysize(machineTypes); j++) { |
MachineType mem_type = machineTypes[j]; |
- byte code[] = { |
- static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)), |
- ZERO_ALIGNMENT, |
- ZERO_OFFSET, |
- kExprI8Const, |
- 0, |
- kExprGetLocal, |
- 0}; |
+ byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; |
FunctionSig sig(0, 1, &local_type); |
if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
EXPECT_VERIFIES(&sig, code); |
@@ -1048,9 +1164,9 @@ TEST_F(AstDecoderTest, SimpleCalls) { |
module_env.AddFunction(sigs.i_i()); |
module_env.AddFunction(sigs.i_ii()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION0(0)); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(27))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION2(2, WASM_I8(37), WASM_I8(77))); |
} |
TEST_F(AstDecoderTest, CallsWithTooFewArguments) { |
@@ -1063,35 +1179,8 @@ TEST_F(AstDecoderTest, CallsWithTooFewArguments) { |
module_env.AddFunction(sigs.f_ff()); |
EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); |
-} |
- |
-TEST_F(AstDecoderTest, CallsWithSpilloverArgs) { |
- static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32}; |
- FunctionSig sig_i_ff(1, 2, a_i_ff); |
- |
- TestModuleEnv module_env; |
- module = &module_env; |
- |
- module_env.AddFunction(&sig_i_ff); |
- |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), |
- WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1))); |
- |
- EXPECT_VERIFIES_INLINE(sigs.i_ff(), |
- WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1))); |
- |
- EXPECT_FAILURE_INLINE(sigs.f_ff(), |
- WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1))); |
- |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(0.2))); |
- |
- EXPECT_VERIFIES_INLINE( |
- sigs.f_ff(), |
- WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(11))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_ZERO)); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(2, WASM_GET_LOCAL(0))); |
} |
TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { |
@@ -1101,9 +1190,9 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { |
module_env.AddFunction(sigs.i_i()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(17))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F32(17.1))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(17.1))); |
} |
TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { |
@@ -1113,15 +1202,15 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { |
module_env.AddFunction(sigs.i_f()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I8(17))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(37.2))); |
module_env.AddFunction(sigs.i_d()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(16))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I64V_1(16))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_F32(17.6))); |
} |
TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
@@ -1134,9 +1223,9 @@ TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
byte f2 = module_env.AddSignature(sigs.i_ii()); |
EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
EXPECT_VERIFIES_INLINE( |
- sig, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
+ sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
} |
TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { |
@@ -1148,11 +1237,11 @@ TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { |
module_env.AddSignature(sigs.i_v()); |
EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
module_env.AddSignature(sigs.i_i()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
} |
TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
@@ -1162,10 +1251,11 @@ TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
byte f0 = module_env.AddFunction(sigs.i_f()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); |
+ EXPECT_FAILURE_INLINE(sig, |
+ WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); |
EXPECT_FAILURE_INLINE(sig, |
- WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64V_1(27))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2))); |
+ WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); |
EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); |
EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); |
@@ -1173,10 +1263,11 @@ TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
byte f1 = module_env.AddFunction(sigs.i_d()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); |
+ EXPECT_FAILURE_INLINE(sig, |
+ WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); |
EXPECT_FAILURE_INLINE(sig, |
- WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64V_1(16))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6))); |
+ WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
} |
TEST_F(AstDecoderTest, SimpleImportCalls) { |
@@ -1189,8 +1280,8 @@ TEST_F(AstDecoderTest, SimpleImportCalls) { |
byte f2 = module_env.AddImport(sigs.i_ii()); |
EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(22))); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(22))); |
+ EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT2(f2, WASM_I8(32), WASM_I8(72))); |
} |
TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { |
@@ -1201,16 +1292,16 @@ TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { |
byte f0 = module_env.AddImport(sigs.i_f()); |
EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f0)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I8(17))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I64V_1(27))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_F64(37.2))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I8(17))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_F64(37.2))); |
byte f1 = module_env.AddImport(sigs.i_d()); |
EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f1)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(16))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I64V_1(16))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_F32(17.6))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(16))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I64V_1(16))); |
+ EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_F32(17.6))); |
} |
TEST_F(AstDecoderTest, Int32Globals) { |
@@ -1334,11 +1425,29 @@ TEST_F(AstDecoderTest, AllStoreGlobalCombinations) { |
} |
} |
+TEST_F(AstDecoderTest, BreakEnd) { |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
+ EXPECT_VERIFIES_INLINE(sigs.i_i(), |
+ B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); |
+} |
+ |
+TEST_F(AstDecoderTest, BreakIfBinop) { |
+ EXPECT_FAILURE_INLINE( |
+ sigs.i_i(), |
+ WASM_BLOCK( |
+ 1, WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); |
+ EXPECT_FAILURE_INLINE( |
+ sigs.i_i(), |
+ WASM_BLOCK( |
+ 1, WASM_I32_ADD(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
+} |
+ |
TEST_F(AstDecoderTest, BreakNesting1) { |
for (int i = 0; i < 5; i++) { |
// (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) |
byte code[] = {WASM_BLOCK( |
- 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i, WASM_ZERO)), |
+ 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), |
WASM_SET_LOCAL(0, WASM_I8(1))), |
WASM_GET_LOCAL(0))}; |
if (i < 3) { |
@@ -1353,8 +1462,8 @@ TEST_F(AstDecoderTest, BreakNesting2) { |
AddLocals(kAstI32, 1); |
for (int i = 0; i < 5; i++) { |
// (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11) |
- byte code[] = {WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i)), |
- WASM_SET_LOCAL(0, WASM_I8(1)))), |
+ byte code[] = {B1(WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)), |
+ WASM_SET_LOCAL(0, WASM_I8(1)))), |
WASM_I8(11)}; |
if (i < 2) { |
EXPECT_VERIFIES(sigs.v_v(), code); |
@@ -1367,8 +1476,8 @@ TEST_F(AstDecoderTest, BreakNesting2) { |
TEST_F(AstDecoderTest, BreakNesting3) { |
for (int i = 0; i < 5; i++) { |
// (block[1] (loop[1] (block[1] (if 0 break[N]) |
- byte code[] = {WASM_BLOCK( |
- 1, WASM_LOOP(1, WASM_BLOCK(1, WASM_IF(WASM_ZERO, WASM_BREAK(i)))))}; |
+ byte code[] = { |
+ WASM_BLOCK(1, WASM_LOOP(1, B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))}; |
if (i < 3) { |
EXPECT_VERIFIES(sigs.v_v(), code); |
} else { |
@@ -1378,41 +1487,42 @@ TEST_F(AstDecoderTest, BreakNesting3) { |
} |
TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); |
- |
EXPECT_FAILURE_INLINE(sigs.i_i(), |
- WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), |
- WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
- EXPECT_FAILURE_INLINE(sigs.i_i(), |
- WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)), |
- WASM_BRV_IF_ZERO(0, WASM_I8(0)), |
- WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
- EXPECT_FAILURE_INLINE(sigs.i_i(), |
- WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)), |
- WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), |
- WASM_BRV_IF_ZERO(0, WASM_I8(11)))); |
+ B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); |
+ |
+ EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), |
+ WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
+ EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), |
+ WASM_BRV_IF_ZERO(0, WASM_I8(0)), |
+ WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
+ EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), |
+ WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), |
+ WASM_BRV_IF_ZERO(0, WASM_I8(11)))); |
} |
TEST_F(AstDecoderTest, BreakNesting_6_levels) { |
for (int mask = 0; mask < 64; mask++) { |
for (int i = 0; i < 14; i++) { |
byte code[] = { |
- kExprBlock, 1, // -- |
- kExprBlock, 1, // -- |
- kExprBlock, 1, // -- |
- kExprBlock, 1, // -- |
- kExprBlock, 1, // -- |
- kExprBlock, 1, // -- |
- kExprBr, static_cast<byte>(i), |
- kExprNop // -- |
+ kExprBlock, // -- |
+ kExprBlock, // -- |
+ kExprBlock, // -- |
+ kExprBlock, // -- |
+ kExprBlock, // -- |
+ kExprBlock, // -- |
+ kExprBr, ARITY_0, static_cast<byte>(i), // -- |
+ kExprEnd, // -- |
+ kExprEnd, // -- |
+ kExprEnd, // -- |
+ kExprEnd, // -- |
+ kExprEnd, // -- |
+ kExprEnd // -- |
}; |
int depth = 6; |
for (int l = 0; l < 6; l++) { |
if (mask & (1 << l)) { |
- code[l * 2] = kExprLoop; |
+ code[l] = kExprLoop; |
depth++; |
} |
} |
@@ -1432,29 +1542,27 @@ TEST_F(AstDecoderTest, ExprBreak_TypeCheck) { |
FunctionSig* sig = sigarray[i]; |
// unify X and X => OK |
EXPECT_VERIFIES_INLINE( |
- sig, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
- WASM_GET_LOCAL(0))); |
+ sig, B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
+ WASM_GET_LOCAL(0))); |
} |
// unify i32 and f32 => fail |
EXPECT_FAILURE_INLINE( |
sigs.i_i(), |
- WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); |
+ B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); |
// unify f64 and f64 => OK |
EXPECT_VERIFIES_INLINE( |
sigs.d_dd(), |
- WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
- WASM_F64(1.2))); |
+ B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2))); |
} |
TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) { |
byte code1[] = {WASM_BLOCK(2, |
WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
WASM_GET_LOCAL(1))}; |
- byte code2[] = { |
- WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), |
- WASM_GET_LOCAL(1))}; |
+ byte code2[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), |
+ WASM_GET_LOCAL(1))}; |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
@@ -1479,14 +1587,12 @@ TEST_F(AstDecoderTest, ExprBr_Unify) { |
LocalType storage[] = {kAstI32, kAstI32, type}; |
FunctionSig sig(1, 2, storage); |
- byte code1[] = { |
- WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(which))), |
- WASM_GET_LOCAL(which ^ 1))}; |
+ byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
+ WASM_GET_LOCAL(which ^ 1))}; |
byte code2[] = { |
- WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
+ WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))), |
WASM_GET_LOCAL(which ^ 1))}; |
- |
if (type == kAstI32) { |
EXPECT_VERIFIES(&sig, code1); |
EXPECT_VERIFIES(&sig, code2); |
@@ -1499,8 +1605,7 @@ TEST_F(AstDecoderTest, ExprBr_Unify) { |
} |
TEST_F(AstDecoderTest, ExprBrIf_cond_type) { |
- byte code[] = { |
- WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
+ byte code[] = {B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; |
@@ -1516,9 +1621,8 @@ TEST_F(AstDecoderTest, ExprBrIf_cond_type) { |
} |
TEST_F(AstDecoderTest, ExprBrIf_val_type) { |
- byte code[] = { |
- WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
- WASM_GET_LOCAL(0))}; |
+ byte code[] = {B2(WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
+ WASM_GET_LOCAL(0))}; |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], |
@@ -1541,8 +1645,8 @@ TEST_F(AstDecoderTest, ExprBrIf_Unify) { |
LocalType storage[] = {kAstI32, kAstI32, type}; |
FunctionSig sig(1, 2, storage); |
- byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
- WASM_GET_LOCAL(which ^ 1))}; |
+ byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
+ WASM_GET_LOCAL(which ^ 1))}; |
byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), |
WASM_GET_LOCAL(which ^ 1))}; |
@@ -1558,31 +1662,29 @@ TEST_F(AstDecoderTest, ExprBrIf_Unify) { |
} |
TEST_F(AstDecoderTest, BrTable0) { |
- static byte code[] = {kExprBrTable, 0, 0}; |
+ static byte code[] = {kExprNop, kExprBrTable, 0, 0}; |
EXPECT_FAILURE(sigs.v_v(), code); |
} |
TEST_F(AstDecoderTest, BrTable0b) { |
- static byte code[] = {kExprBrTable, 0, 0, kExprI32Const, 11}; |
+ static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 0}; |
EXPECT_FAILURE(sigs.v_v(), code); |
EXPECT_FAILURE(sigs.i_i(), code); |
} |
TEST_F(AstDecoderTest, BrTable0c) { |
- static byte code[] = {kExprBrTable, 0, 1, 0, 0, kExprI32Const, 11}; |
+ static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 1, 0, 0}; |
EXPECT_FAILURE(sigs.v_v(), code); |
EXPECT_FAILURE(sigs.i_i(), code); |
} |
TEST_F(AstDecoderTest, BrTable1a) { |
- static byte code[] = { |
- WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; |
+ static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
} |
TEST_F(AstDecoderTest, BrTable1b) { |
- static byte code[] = { |
- WASM_BLOCK(1, WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; |
+ static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
EXPECT_FAILURE(sigs.i_i(), code); |
EXPECT_FAILURE(sigs.f_ff(), code); |
@@ -1591,7 +1693,7 @@ TEST_F(AstDecoderTest, BrTable1b) { |
TEST_F(AstDecoderTest, BrTable2a) { |
static byte code[] = { |
- WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; |
+ B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; |
EXPECT_VERIFIES(sigs.v_v(), code); |
} |
@@ -1603,8 +1705,7 @@ TEST_F(AstDecoderTest, BrTable2b) { |
} |
TEST_F(AstDecoderTest, BrTable_off_end) { |
- static byte code[] = { |
- WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; |
+ static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; |
for (size_t len = 1; len < sizeof(code); len++) { |
Verify(kError, sigs.i_i(), code, code + len); |
} |
@@ -1612,8 +1713,7 @@ TEST_F(AstDecoderTest, BrTable_off_end) { |
TEST_F(AstDecoderTest, BrTable_invalid_br1) { |
for (int depth = 0; depth < 4; depth++) { |
- byte code[] = { |
- WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
+ byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
if (depth == 0) { |
EXPECT_VERIFIES(sigs.v_i(), code); |
} else { |
@@ -1635,11 +1735,10 @@ TEST_F(AstDecoderTest, BrTable_invalid_br2) { |
} |
TEST_F(AstDecoderTest, ExprBreakNesting1) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR(0))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), |
- WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO))); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV(0, WASM_ZERO))); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0))); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); |
+ EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR_IF(0, WASM_ZERO))); |
EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); |
EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0))); |
@@ -1734,13 +1833,14 @@ class WasmOpcodeLengthTest : public TestWithZone { |
TEST_F(WasmOpcodeLengthTest, Statements) { |
EXPECT_LENGTH(1, kExprNop); |
- EXPECT_LENGTH(2, kExprBlock); |
- EXPECT_LENGTH(2, kExprLoop); |
+ EXPECT_LENGTH(1, kExprBlock); |
+ EXPECT_LENGTH(1, kExprLoop); |
EXPECT_LENGTH(1, kExprIf); |
- EXPECT_LENGTH(1, kExprIfElse); |
+ EXPECT_LENGTH(1, kExprElse); |
+ EXPECT_LENGTH(1, kExprEnd); |
EXPECT_LENGTH(1, kExprSelect); |
- EXPECT_LENGTH(2, kExprBr); |
- EXPECT_LENGTH(2, kExprBrIf); |
+ EXPECT_LENGTH(3, kExprBr); |
+ EXPECT_LENGTH(3, kExprBrIf); |
} |
@@ -1752,15 +1852,14 @@ TEST_F(WasmOpcodeLengthTest, MiscExpressions) { |
EXPECT_LENGTH(2, kExprSetLocal); |
EXPECT_LENGTH(2, kExprLoadGlobal); |
EXPECT_LENGTH(2, kExprStoreGlobal); |
- EXPECT_LENGTH(2, kExprCallFunction); |
- EXPECT_LENGTH(2, kExprCallImport); |
- EXPECT_LENGTH(2, kExprCallIndirect); |
+ EXPECT_LENGTH(3, kExprCallFunction); |
+ EXPECT_LENGTH(3, kExprCallImport); |
+ EXPECT_LENGTH(3, kExprCallIndirect); |
EXPECT_LENGTH(1, kExprIf); |
- EXPECT_LENGTH(1, kExprIfElse); |
- EXPECT_LENGTH(2, kExprBlock); |
- EXPECT_LENGTH(2, kExprLoop); |
- EXPECT_LENGTH(2, kExprBr); |
- EXPECT_LENGTH(2, kExprBrIf); |
+ EXPECT_LENGTH(1, kExprBlock); |
+ EXPECT_LENGTH(1, kExprLoop); |
+ EXPECT_LENGTH(3, kExprBr); |
+ EXPECT_LENGTH(3, kExprBrIf); |
} |
TEST_F(WasmOpcodeLengthTest, I32Const) { |
@@ -1965,29 +2064,32 @@ TEST_F(WasmOpcodeArityTest, Control) { |
EXPECT_ARITY(0, kExprNop); |
EXPECT_ARITY(0, kExprBlock, 0); |
- EXPECT_ARITY(1, kExprBlock, 1); |
- EXPECT_ARITY(2, kExprBlock, 2); |
- EXPECT_ARITY(5, kExprBlock, 5); |
- EXPECT_ARITY(10, kExprBlock, 10); |
+ EXPECT_ARITY(0, kExprBlock, 1); |
+ EXPECT_ARITY(0, kExprBlock, 2); |
+ EXPECT_ARITY(0, kExprBlock, 5); |
+ EXPECT_ARITY(0, kExprBlock, 10); |
EXPECT_ARITY(0, kExprLoop, 0); |
- EXPECT_ARITY(1, kExprLoop, 1); |
- EXPECT_ARITY(2, kExprLoop, 2); |
- EXPECT_ARITY(7, kExprLoop, 7); |
- EXPECT_ARITY(11, kExprLoop, 11); |
+ EXPECT_ARITY(0, kExprLoop, 1); |
+ EXPECT_ARITY(0, kExprLoop, 2); |
+ EXPECT_ARITY(0, kExprLoop, 7); |
+ EXPECT_ARITY(0, kExprLoop, 11); |
- EXPECT_ARITY(2, kExprIf); |
- EXPECT_ARITY(3, kExprIfElse); |
EXPECT_ARITY(3, kExprSelect); |
- EXPECT_ARITY(1, kExprBr); |
- EXPECT_ARITY(2, kExprBrIf); |
+ EXPECT_ARITY(0, kExprBr); |
+ EXPECT_ARITY(1, kExprBrIf); |
+ EXPECT_ARITY(1, kExprBrTable); |
+ |
+ EXPECT_ARITY(1, kExprBr, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
{ |
sig = sigs.v_v(); |
- EXPECT_ARITY(0, kExprReturn); |
+ EXPECT_ARITY(0, kExprReturn, ARITY_0); |
sig = sigs.i_i(); |
- EXPECT_ARITY(1, kExprReturn); |
+ EXPECT_ARITY(1, kExprReturn, ARITY_1); |
} |
} |
@@ -2019,21 +2121,33 @@ TEST_F(WasmOpcodeArityTest, Calls) { |
{ |
FunctionSig* sig = sigs.i_ii(); |
- EXPECT_ARITY(2, kExprCallFunction, 0); |
- EXPECT_ARITY(2, kExprCallImport, 0); |
- EXPECT_ARITY(3, kExprCallIndirect, 0); |
- EXPECT_ARITY(1, kExprBr); |
- EXPECT_ARITY(2, kExprBrIf); |
+ EXPECT_ARITY(2, kExprCallFunction, 2, 0); |
+ EXPECT_ARITY(2, kExprCallImport, 2, 0); |
+ EXPECT_ARITY(3, kExprCallIndirect, 2, 0); |
+ |
+ EXPECT_ARITY(1, kExprBr, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
+ |
+ EXPECT_ARITY(0, kExprBr, ARITY_0); |
+ EXPECT_ARITY(1, kExprBrIf, ARITY_0); |
+ EXPECT_ARITY(1, kExprBrTable, ARITY_0); |
} |
{ |
FunctionSig* sig = sigs.v_v(); |
- EXPECT_ARITY(1, kExprCallFunction, 1); |
- EXPECT_ARITY(1, kExprCallImport, 1); |
- EXPECT_ARITY(2, kExprCallIndirect, 1); |
- EXPECT_ARITY(1, kExprBr); |
- EXPECT_ARITY(2, kExprBrIf); |
+ EXPECT_ARITY(1, kExprCallFunction, ARITY_1, 1); |
+ EXPECT_ARITY(1, kExprCallImport, ARITY_1, 1); |
+ EXPECT_ARITY(2, kExprCallIndirect, ARITY_1, 1); |
+ |
+ EXPECT_ARITY(1, kExprBr, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
+ EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
+ |
+ EXPECT_ARITY(0, kExprBr, ARITY_0); |
+ EXPECT_ARITY(1, kExprBrIf, ARITY_0); |
+ EXPECT_ARITY(1, kExprBrTable, ARITY_0); |
} |
} |