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 9109dbf3320a019b00f0267812e1012ad44704ee..c1468ab29f6e436d5af748841ba8d7ac74e45a14 100644 |
--- a/test/unittests/wasm/ast-decoder-unittest.cc |
+++ b/test/unittests/wasm/ast-decoder-unittest.cc |
@@ -19,13 +19,17 @@ 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 |
+#define B1(a) WASM_BLOCK(a) |
+#define B2(a, b) WASM_BLOCK(a, b) |
+#define B3(a, b, c) WASM_BLOCK(a, b, c) |
+ |
+#define WASM_IF_OP kExprIf, kLocalVoid |
+#define WASM_LOOP_OP kExprLoop, kLocalVoid |
static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; |
static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; |
static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; |
+static const byte kCodeTeeLocal0[] = {WASM_TEE_LOCAL(0, WASM_ZERO)}; |
static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; |
static const MachineType machineTypes[] = { |
@@ -41,28 +45,39 @@ static const WasmOpcode kInt32BinopOpcodes[] = { |
kExprI32LeS, kExprI32LtU, kExprI32LeU}; |
#define WASM_BRV_IF_ZERO(depth, val) \ |
- val, WASM_ZERO, kExprBrIf, ARITY_1, static_cast<byte>(depth) |
+ val, WASM_ZERO, kExprBrIf, static_cast<byte>(depth) |
+ |
+#define EXPECT_VERIFIES_C(sig, x) \ |
+ Verify(kSuccess, sigs.sig(), x, x + arraysize(x)) |
+ |
+#define EXPECT_FAILURE_C(sig, x) Verify(kError, sigs.sig(), x, x + arraysize(x)) |
-#define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x)) |
+#define EXPECT_VERIFIES_SC(sig, x) Verify(kSuccess, sig, x, x + arraysize(x)) |
-#define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x)) |
+#define EXPECT_FAILURE_SC(sig, x) Verify(kError, sig, x, x + arraysize(x)) |
-#define EXPECT_VERIFIES_INLINE(env, ...) \ |
+#define EXPECT_VERIFIES_S(env, ...) \ |
do { \ |
static byte code[] = {__VA_ARGS__}; \ |
Verify(kSuccess, env, code, code + arraysize(code)); \ |
} while (false) |
-#define EXPECT_FAILURE_INLINE(env, ...) \ |
+#define EXPECT_FAILURE_S(env, ...) \ |
do { \ |
static byte code[] = {__VA_ARGS__}; \ |
Verify(kError, env, code, code + arraysize(code)); \ |
} while (false) |
-#define VERIFY(...) \ |
+#define EXPECT_VERIFIES(sig, ...) \ |
do { \ |
static const byte code[] = {__VA_ARGS__}; \ |
- Verify(kSuccess, sigs.v_i(), code, code + sizeof(code)); \ |
+ Verify(kSuccess, sigs.sig(), code, code + sizeof(code)); \ |
+ } while (false) |
+ |
+#define EXPECT_FAILURE(sig, ...) \ |
+ do { \ |
+ static const byte code[] = {__VA_ARGS__}; \ |
+ Verify(kError, sigs.sig(), code, code + sizeof(code)); \ |
} while (false) |
static bool old_eh_flag; |
@@ -113,14 +128,14 @@ class AstDecoderTest : public TestWithZone { |
if (result.error_pt) str << ", pt = +" << pt; |
} |
} |
- FATAL(str.str().c_str()); |
+ EXPECT_TRUE(false) << str.str().c_str(); |
} |
} |
void TestBinop(WasmOpcode opcode, FunctionSig* success) { |
// op(local[0], local[1]) |
byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
- EXPECT_VERIFIES(success, code); |
+ EXPECT_VERIFIES_SC(success, code); |
// Try all combinations of return and parameter types. |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
@@ -132,7 +147,7 @@ class AstDecoderTest : public TestWithZone { |
types[2] != success->GetParam(1)) { |
// Test signature mismatch. |
FunctionSig sig(1, 2, types); |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
@@ -149,7 +164,7 @@ class AstDecoderTest : public TestWithZone { |
{ |
LocalType types[] = {ret_type, param_type}; |
FunctionSig sig(1, 1, types); |
- EXPECT_VERIFIES(&sig, code); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} |
// Try all combinations of return and parameter types. |
@@ -159,7 +174,7 @@ class AstDecoderTest : public TestWithZone { |
if (types[0] != ret_type || types[1] != param_type) { |
// Test signature mismatch. |
FunctionSig sig(1, 1, types); |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
@@ -170,7 +185,7 @@ TEST_F(AstDecoderTest, Int8Const) { |
byte code[] = {kExprI8Const, 0}; |
for (int i = -128; i < 128; i++) { |
code[1] = static_cast<byte>(i); |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
} |
} |
@@ -182,13 +197,16 @@ TEST_F(AstDecoderTest, EmptyFunction) { |
TEST_F(AstDecoderTest, IncompleteIf1) { |
byte code[] = {kExprIf}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, Int8Const_fallthru) { |
- byte code[] = {kExprI8Const, 0, kExprI8Const, 1}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); |
+} |
+ |
+TEST_F(AstDecoderTest, Int8Const_fallthru2) { |
+ EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); |
} |
TEST_F(AstDecoderTest, Int32Const) { |
@@ -196,20 +214,15 @@ TEST_F(AstDecoderTest, Int32Const) { |
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
// TODO(binji): expand test for other sized int32s; 1 through 5 bytes. |
byte code[] = {WASM_I32V(i)}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
} |
} |
-TEST_F(AstDecoderTest, Int8Const_fallthru2) { |
- byte code[] = {WASM_I8(0), WASM_I32V_4(0x1122334)}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
-} |
- |
TEST_F(AstDecoderTest, Int64Const) { |
const int kInc = 4498211; |
for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; |
- EXPECT_VERIFIES(sigs.l_l(), code); |
+ EXPECT_VERIFIES_C(l_l, code); |
} |
} |
@@ -218,7 +231,7 @@ TEST_F(AstDecoderTest, Float32Const) { |
float* ptr = reinterpret_cast<float*>(code + 1); |
for (int i = 0; i < 30; i++) { |
WriteLittleEndianValue<float>(ptr, i * -7.75f); |
- EXPECT_VERIFIES(sigs.f_ff(), code); |
+ EXPECT_VERIFIES_C(f_ff, code); |
} |
} |
@@ -227,7 +240,7 @@ TEST_F(AstDecoderTest, Float64Const) { |
double* ptr = reinterpret_cast<double*>(code + 1); |
for (int i = 0; i < 30; i++) { |
WriteLittleEndianValue<double>(ptr, i * 33.45); |
- EXPECT_VERIFIES(sigs.d_dd(), code); |
+ EXPECT_VERIFIES_C(d_dd, code); |
} |
} |
@@ -240,24 +253,24 @@ TEST_F(AstDecoderTest, Int32Const_off_end) { |
} |
TEST_F(AstDecoderTest, GetLocal0_param) { |
- EXPECT_VERIFIES(sigs.i_i(), kCodeGetLocal0); |
+ EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); |
} |
TEST_F(AstDecoderTest, GetLocal0_local) { |
AddLocals(kAstI32, 1); |
- EXPECT_VERIFIES(sigs.i_v(), kCodeGetLocal0); |
+ EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); |
} |
TEST_F(AstDecoderTest, TooManyLocals) { |
AddLocals(kAstI32, 4034986500); |
- EXPECT_FAILURE(sigs.i_v(), kCodeGetLocal0); |
+ EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
} |
TEST_F(AstDecoderTest, GetLocal0_param_n) { |
FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; |
for (size_t i = 0; i < arraysize(array); i++) { |
- EXPECT_VERIFIES(array[i], kCodeGetLocal0); |
+ EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); |
} |
} |
@@ -266,555 +279,618 @@ TEST_F(AstDecoderTest, GetLocalN_local) { |
AddLocals(kAstI32, 1); |
for (byte j = 0; j < i; j++) { |
byte code[] = {kExprGetLocal, j}; |
- EXPECT_VERIFIES(sigs.i_v(), code); |
+ EXPECT_VERIFIES_C(i_v, code); |
} |
} |
} |
TEST_F(AstDecoderTest, GetLocal0_fail_no_params) { |
- EXPECT_FAILURE(sigs.i_v(), kCodeGetLocal0); |
+ EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
} |
TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) { |
- EXPECT_FAILURE(sigs.i_i(), kCodeGetLocal1); |
+ EXPECT_FAILURE_C(i_i, kCodeGetLocal1); |
} |
TEST_F(AstDecoderTest, GetLocal_off_end) { |
static const byte code[] = {kExprGetLocal}; |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, NumLocalBelowLimit) { |
AddLocals(kAstI32, kMaxNumWasmLocals - 1); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_NOP); |
+ EXPECT_VERIFIES(v_v, WASM_NOP); |
} |
TEST_F(AstDecoderTest, NumLocalAtLimit) { |
AddLocals(kAstI32, kMaxNumWasmLocals); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_NOP); |
+ EXPECT_VERIFIES(v_v, WASM_NOP); |
} |
TEST_F(AstDecoderTest, NumLocalAboveLimit) { |
AddLocals(kAstI32, kMaxNumWasmLocals + 1); |
- EXPECT_FAILURE_INLINE(sigs.v_v(), WASM_NOP); |
+ EXPECT_FAILURE(v_v, WASM_NOP); |
} |
TEST_F(AstDecoderTest, GetLocal_varint) { |
const int kMaxLocals = kMaxNumWasmLocals; |
AddLocals(kAstI32, kMaxLocals); |
- for (int index = 0; index < kMaxLocals; index = index * 11 + 5) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_1(index)); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_2(index)); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_3(index)); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(index)); |
- } |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(888888)); |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(3999999)); |
+ |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_5(kMaxLocals - 1)); |
+ EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals - 1)); |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals)); |
- EXPECT_FAILURE_INLINE(sigs.i_i(), kExprGetLocal, U32V_4(kMaxLocals + 1)); |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); |
+ EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); |
+ EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
- EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals)); |
- EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals + 1)); |
+ EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); |
+ EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
} |
TEST_F(AstDecoderTest, Binops_off_end) { |
byte code1[] = {0}; // [opcode] |
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
code1[0] = kInt32BinopOpcodes[i]; |
- EXPECT_FAILURE(sigs.i_i(), code1); |
+ EXPECT_FAILURE_C(i_i, code1); |
} |
byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] |
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
code3[2] = kInt32BinopOpcodes[i]; |
- EXPECT_FAILURE(sigs.i_i(), code3); |
+ EXPECT_FAILURE_C(i_i, code3); |
} |
byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] |
for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
code4[2] = kInt32BinopOpcodes[i]; |
code4[3] = kInt32BinopOpcodes[i]; |
- EXPECT_FAILURE(sigs.i_i(), code4); |
+ EXPECT_FAILURE_C(i_i, code4); |
} |
} |
TEST_F(AstDecoderTest, BinopsAcrossBlock1) { |
static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add, |
kExprEnd}; |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, BinopsAcrossBlock2) { |
static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add, |
kExprEnd}; |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, BinopsAcrossBlock3) { |
static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add, |
kExprElse, kExprI32Add, kExprEnd}; |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, Nop) { |
static const byte code[] = {kExprNop}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
+} |
+ |
+TEST_F(AstDecoderTest, SetLocal0_void) { |
+ EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO)); |
} |
TEST_F(AstDecoderTest, SetLocal0_param) { |
- EXPECT_VERIFIES(sigs.i_i(), kCodeSetLocal0); |
- EXPECT_FAILURE(sigs.f_ff(), kCodeSetLocal0); |
- EXPECT_FAILURE(sigs.d_dd(), kCodeSetLocal0); |
+ EXPECT_FAILURE_C(i_i, kCodeSetLocal0); |
+ EXPECT_FAILURE_C(f_ff, kCodeSetLocal0); |
+ EXPECT_FAILURE_C(d_dd, kCodeSetLocal0); |
+} |
+ |
+TEST_F(AstDecoderTest, TeeLocal0_param) { |
+ EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); |
+ EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); |
+ EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); |
} |
TEST_F(AstDecoderTest, SetLocal0_local) { |
- EXPECT_FAILURE(sigs.i_v(), kCodeSetLocal0); |
+ EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
+ EXPECT_FAILURE_C(v_v, kCodeSetLocal0); |
AddLocals(kAstI32, 1); |
- EXPECT_VERIFIES(sigs.i_v(), kCodeSetLocal0); |
+ EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
+ EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); |
} |
-TEST_F(AstDecoderTest, SetLocalN_local) { |
+TEST_F(AstDecoderTest, TeeLocal0_local) { |
+ EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); |
+ AddLocals(kAstI32, 1); |
+ EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); |
+} |
+ |
+TEST_F(AstDecoderTest, TeeLocalN_local) { |
for (byte i = 1; i < 8; i++) { |
AddLocals(kAstI32, 1); |
for (byte j = 0; j < i; j++) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_SET_LOCAL(j, WASM_I8(i))); |
+ EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); |
+ EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); |
} |
} |
} |
TEST_F(AstDecoderTest, BlockN) { |
const int kMaxSize = 200; |
- byte buffer[kMaxSize + 2]; |
+ byte buffer[kMaxSize + 3]; |
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); |
+ buffer[1] = kLocalVoid; |
+ buffer[i + 2] = kExprEnd; |
+ Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 3); |
} |
} |
+#define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd |
+ |
TEST_F(AstDecoderTest, Block0) { |
- static const byte code[] = {kExprBlock, kExprEnd}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ static const byte code[] = {WASM_EMPTY_BLOCK}; |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, Block0_fallthru1) { |
- static const byte code[] = {kExprBlock, kExprBlock, kExprEnd, kExprEnd}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)}; |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(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); |
+ static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
+} |
+ |
+TEST_F(AstDecoderTest, Block0_end) { |
+ EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd); |
} |
TEST_F(AstDecoderTest, Block0_end_end) { |
- static const byte code[] = {kExprBlock, kExprEnd, kExprEnd}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd); |
} |
TEST_F(AstDecoderTest, Block1) { |
- 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); |
+ byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; |
+ EXPECT_VERIFIES_C(i_i, code); |
+ EXPECT_FAILURE_C(v_i, code); |
+ EXPECT_FAILURE_C(d_dd, code); |
+ EXPECT_FAILURE_C(i_f, code); |
+ EXPECT_FAILURE_C(i_d, code); |
} |
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); |
+ byte code[] = {WASM_BLOCK_I(WASM_ZERO)}; |
+ EXPECT_VERIFIES_C(i_i, code); |
+ EXPECT_FAILURE_C(f_ff, code); |
+ EXPECT_FAILURE_C(d_dd, code); |
+ EXPECT_FAILURE_C(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); |
+ byte code[] = {WASM_BLOCK_F(WASM_F32(0))}; |
+ EXPECT_FAILURE_C(i_i, code); |
+ EXPECT_VERIFIES_C(f_ff, code); |
+ EXPECT_FAILURE_C(d_dd, code); |
+ EXPECT_FAILURE_C(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))); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
} |
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); |
+ EXPECT_VERIFIES(v_v, B1(WASM_BR(0))); |
+ EXPECT_VERIFIES(v_v, B1(WASM_BR(1))); |
+ EXPECT_FAILURE(v_v, B1(WASM_BR(2))); |
} |
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))); |
+ EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0))); |
+ EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Block2) { |
- 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))); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP)); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO)); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP)); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)); |
} |
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); |
+ byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; |
+ EXPECT_VERIFIES_C(i_i, code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(f_ff, code); |
} |
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)); |
+ EXPECT_VERIFIES( |
+ i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), |
+ WASM_I8(23)); |
} |
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))); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); |
} |
TEST_F(AstDecoderTest, Block5) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); |
+ |
+ EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE( |
- sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), |
- WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
- WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE( |
+ v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
+} |
- EXPECT_VERIFIES_INLINE( |
- sigs.v_i(), |
- WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
- WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+TEST_F(AstDecoderTest, BlockType) { |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0))); |
+} |
+ |
+TEST_F(AstDecoderTest, BlockType_fail) { |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0))); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO)); |
+ EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0))); |
+ EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO)); |
+ EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO)); |
+ EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0))); |
} |
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); |
+ static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)}; |
+ EXPECT_VERIFIES_C(f_ff, code); |
+ EXPECT_FAILURE_C(i_i, code); |
+ EXPECT_FAILURE_C(d_dd, code); |
} |
TEST_F(AstDecoderTest, BlockN_off_end) { |
- byte code[] = {kExprBlock, kExprNop, kExprNop, kExprNop, kExprNop, kExprEnd}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)}; |
+ EXPECT_VERIFIES_C(v_v, code); |
for (size_t i = 1; i < arraysize(code); i++) { |
Verify(kError, sigs.v_v(), code, code + i); |
} |
} |
TEST_F(AstDecoderTest, Block2_continue) { |
- static const byte code[] = {kExprBlock, kExprBr, ARITY_0, |
- DEPTH_1, kExprNop, kExprEnd}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0))); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1))); |
+ EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2))); |
} |
-TEST_F(AstDecoderTest, NestedBlock_return) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), B1(B1(WASM_RETURN1(WASM_ZERO)))); |
+TEST_F(AstDecoderTest, Block3_continue) { |
+ EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); |
+ EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); |
+ EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); |
+ EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); |
} |
-TEST_F(AstDecoderTest, BlockBinop) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(B1(WASM_I8(1)), WASM_I8(2))); |
+TEST_F(AstDecoderTest, NestedBlock_return) { |
+ EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); |
} |
TEST_F(AstDecoderTest, BlockBrBinop) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), |
- WASM_I32_AND(B1(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); |
+ EXPECT_VERIFIES( |
+ i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); |
} |
TEST_F(AstDecoderTest, If_empty1) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprEnd); |
+ EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); |
} |
TEST_F(AstDecoderTest, If_empty2) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprElse, kExprEnd); |
+ EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); |
} |
TEST_F(AstDecoderTest, If_empty3) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, WASM_ZERO, kExprElse, |
- kExprEnd); |
+ EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); |
+ EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); |
} |
TEST_F(AstDecoderTest, If_empty4) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_ZERO, kExprIf, kExprElse, WASM_ZERO, |
- kExprEnd); |
+ EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); |
+ EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); |
} |
TEST_F(AstDecoderTest, If_empty_stack) { |
byte code[] = {kExprIf}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, If_incomplete1) { |
byte code[] = {kExprI8Const, 0, kExprIf}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_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); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_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); |
+ byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, IfEmpty) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0, kExprIf, kExprEnd); |
+ EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); |
} |
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)); |
+ EXPECT_VERIFIES(v_i, |
+ WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); |
+ EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), |
+ WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
} |
TEST_F(AstDecoderTest, IfElseEmpty) { |
- 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)); |
+ EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd); |
+ EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
} |
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)); |
+ EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, |
+ WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
+ WASM_UNREACHABLE)); |
} |
TEST_F(AstDecoderTest, IfElseUnreachable2) { |
static const byte code[] = { |
- WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
+ WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
LocalType types[] = {kAstI32, kLocalTypes[i]}; |
FunctionSig sig(1, 1, types); |
if (kLocalTypes[i] == kAstI32) { |
- EXPECT_VERIFIES(&sig, code); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
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))); |
+ EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); |
+ EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); |
+ EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); |
} |
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))); |
+ EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); |
+ EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); |
+ EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); |
} |
TEST_F(AstDecoderTest, Block_else) { |
byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, IfNop) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
+ EXPECT_VERIFIES(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)); |
+ EXPECT_VERIFIES(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); |
+ static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; |
+ EXPECT_VERIFIES_C(v_i, code); |
} |
-TEST_F(AstDecoderTest, If_falloff) { |
+TEST_F(AstDecoderTest, If_end_end_end) { |
+ static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, |
+ kExprEnd, kExprEnd, kExprEnd}; |
+ EXPECT_FAILURE_C(v_i, code); |
+} |
+ |
+TEST_F(AstDecoderTest, If_falloff1) { |
static const byte code[] = {kExprGetLocal, 0, kExprIf}; |
- EXPECT_FAILURE(sigs.v_i(), code); |
+ EXPECT_FAILURE_C(v_i, code); |
+} |
+ |
+TEST_F(AstDecoderTest, If_falloff2) { |
+ static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP}; |
+ EXPECT_FAILURE_C(v_i, code); |
} |
TEST_F(AstDecoderTest, IfElse_falloff) { |
- static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprNop, kExprElse}; |
- EXPECT_FAILURE(sigs.v_i(), code); |
+ static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop, |
+ kExprElse}; |
+ EXPECT_FAILURE_C(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)); |
+ EXPECT_VERIFIES(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)); |
+ EXPECT_VERIFIES( |
+ 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)))); |
+ EXPECT_VERIFIES(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), |
+ EXPECT_VERIFIES(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)); |
+ EXPECT_VERIFIES( |
+ 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), |
+ EXPECT_VERIFIES(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, kExprEnd}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
-} |
+TEST_F(AstDecoderTest, Loop0) { EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); } |
TEST_F(AstDecoderTest, Loop1) { |
static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; |
- EXPECT_VERIFIES(sigs.v_i(), code); |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.f_ff(), code); |
+ EXPECT_VERIFIES_C(v_i, code); |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(f_ff, code); |
} |
TEST_F(AstDecoderTest, Loop2) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), |
- WASM_SET_LOCAL(0, WASM_ZERO))); |
+ EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), |
+ WASM_SET_LOCAL(0, WASM_ZERO))); |
} |
TEST_F(AstDecoderTest, Loop1_continue) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0))); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Loop1_break) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1))); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1))); |
} |
TEST_F(AstDecoderTest, Loop2_continue) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), |
- WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); |
+ EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, Loop2_break) { |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), |
- WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); |
+ EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); |
} |
-TEST_F(AstDecoderTest, ExprLoop0) { |
- static const byte code[] = {kExprLoop, kExprEnd}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+TEST_F(AstDecoderTest, InfiniteLoop) { |
+ EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0))); |
+ EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
} |
-TEST_F(AstDecoderTest, ExprLoop1a) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(0, WASM_ZERO))); |
+TEST_F(AstDecoderTest, Loop2_unreachable) { |
+ EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP)); |
} |
-TEST_F(AstDecoderTest, ExprLoop1b) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
- EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
+TEST_F(AstDecoderTest, LoopType) { |
+ EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); |
} |
-TEST_F(AstDecoderTest, ExprLoop2_unreachable) { |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BR(0), WASM_NOP)); |
+TEST_F(AstDecoderTest, LoopType_void) { |
+ EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO)); |
+ EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0))); |
+ EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1))); |
+} |
+ |
+TEST_F(AstDecoderTest, LoopType_fail) { |
+ EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0))); |
+ EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO)); |
+ EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0))); |
+ EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO)); |
+ EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1))); |
+ |
+ EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO)); |
+ EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0))); |
+ EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0))); |
} |
TEST_F(AstDecoderTest, ReturnVoid1) { |
static const byte code[] = {kExprNop}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
- EXPECT_FAILURE(sigs.i_f(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
+ EXPECT_FAILURE_C(i_f, code); |
} |
TEST_F(AstDecoderTest, ReturnVoid2) { |
- 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); |
+ static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
+ EXPECT_FAILURE_C(i_f, code); |
} |
TEST_F(AstDecoderTest, ReturnVoid3) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI8Const, 0); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI32Const, 0, 0, 0, 0); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF32Const, 0, 0, 0, 0); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); |
+ EXPECT_FAILURE(v_v, kExprI8Const, 0); |
+ EXPECT_FAILURE(v_v, kExprI32Const, 0); |
+ EXPECT_FAILURE(v_v, kExprI64Const, 0); |
+ EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); |
+ EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0); |
+ EXPECT_FAILURE(v_i, kExprGetLocal, 0); |
} |
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(), 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(WASM_UNREACHABLE, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0), WASM_ZERO)); |
+ EXPECT_VERIFIES(v_v, kExprUnreachable); |
+ EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); |
+ EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); |
+ EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); |
} |
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)); |
+ EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); |
+ EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); |
} |
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)); |
+ EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); |
+ EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); |
+ EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); |
} |
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))); |
+ EXPECT_VERIFIES(i_i, |
+ WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); |
+ EXPECT_VERIFIES( |
+ i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES( |
+ i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); |
} |
TEST_F(AstDecoderTest, If_off_end) { |
@@ -828,55 +904,56 @@ TEST_F(AstDecoderTest, If_off_end) { |
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); |
+ WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; |
+ EXPECT_VERIFIES_C(i_i, kCode); |
+ EXPECT_FAILURE_C(i_f, kCode); |
+ EXPECT_FAILURE_C(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); |
+ WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; |
+ EXPECT_VERIFIES_C(i_i, kCode); |
+ EXPECT_FAILURE_C(i_f, kCode); |
+ EXPECT_FAILURE_C(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); |
+ static const byte kCode[] = { |
+ WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; |
+ EXPECT_FAILURE_C(i_i, kCode); |
+ EXPECT_FAILURE_C(i_f, kCode); |
+ EXPECT_FAILURE_C(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); |
+ WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; |
+ EXPECT_FAILURE_C(i_i, kCode); |
+ EXPECT_FAILURE_C(i_f, kCode); |
+ EXPECT_FAILURE_C(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); |
+ static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; |
+ EXPECT_FAILURE_C(i_i, kCode); |
+ EXPECT_FAILURE_C(i_f, kCode); |
+ EXPECT_FAILURE_C(i_d, kCode); |
} |
TEST_F(AstDecoderTest, Int64Local_param) { |
- EXPECT_VERIFIES(sigs.l_l(), kCodeGetLocal0); |
+ EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); |
} |
TEST_F(AstDecoderTest, Int64Locals) { |
for (byte i = 1; i < 8; i++) { |
AddLocals(kAstI64, 1); |
for (byte j = 0; j < i; j++) { |
- EXPECT_VERIFIES_INLINE(sigs.l_v(), WASM_GET_LOCAL(j)); |
+ EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); |
} |
} |
} |
@@ -938,132 +1015,120 @@ TEST_F(AstDecoderTest, TypeConversions) { |
} |
TEST_F(AstDecoderTest, MacrosStmt) { |
- VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
- VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); |
- 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(B1(WASM_NOP)); |
- VERIFY(WASM_LOOP(WASM_NOP)); |
- VERIFY(WASM_LOOP(WASM_BREAK(0))); |
- VERIFY(WASM_LOOP(WASM_CONTINUE(0))); |
-} |
- |
-TEST_F(AstDecoderTest, MacrosBreak) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BREAK(0))); |
- |
- EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BREAKV(0, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.l_l(), WASM_LOOP(WASM_BREAKV(0, WASM_I64V_1(0)))); |
- EXPECT_VERIFIES_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BREAKV(0, WASM_F32(0.0)))); |
- EXPECT_VERIFIES_INLINE(sigs.d_dd(), WASM_LOOP(WASM_BREAKV(0, WASM_F64(0.0)))); |
+ EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
+ EXPECT_VERIFIES( |
+ v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); |
+ EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
+ EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, WASM_NOP); |
+ EXPECT_VERIFIES(v_v, B1(WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
} |
TEST_F(AstDecoderTest, MacrosContinue) { |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_CONTINUE(0))); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); |
} |
TEST_F(AstDecoderTest, MacrosVariadic) { |
- VERIFY(B2(WASM_NOP, WASM_NOP)); |
- VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP)); |
- VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP)); |
- VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP)); |
+ EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); |
} |
TEST_F(AstDecoderTest, MacrosNestedBlocks) { |
- 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)))); |
+ EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); |
+ EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- |
+ B2(WASM_NOP, WASM_NOP), // -- |
+ B2(WASM_NOP, WASM_NOP))); // -- |
+ EXPECT_VERIFIES(v_v, 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_RETURNN(2, WASM_ZERO, WASM_ONE)); |
- EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
+ EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
+ EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
FunctionSig sig_iii_v(3, 0, kIntTypes5); |
- EXPECT_VERIFIES_INLINE(&sig_iii_v, |
- WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
- EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
+ EXPECT_VERIFIES_S(&sig_iii_v, |
+ WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
+ EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
} |
TEST_F(AstDecoderTest, MultipleReturn_fallthru) { |
static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
FunctionSig sig_ii_v(2, 0, kIntTypes5); |
- EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_ZERO, WASM_ONE); |
- EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_ZERO); |
+ EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); |
+ EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); |
FunctionSig sig_iii_v(3, 0, kIntTypes5); |
- EXPECT_VERIFIES_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); |
- EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_ZERO, WASM_ONE); |
+ EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); |
+ EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); |
} |
TEST_F(AstDecoderTest, MacrosInt32) { |
- VERIFY(WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); |
- VERIFY(WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); |
- VERIFY(WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); |
- VERIFY(WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); |
- VERIFY(WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); |
- VERIFY(WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); |
- VERIFY(WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); |
- VERIFY(WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); |
- VERIFY(WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); |
- VERIFY(WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); |
- VERIFY(WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); |
- VERIFY(WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); |
- VERIFY(WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); |
- VERIFY(WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); |
- VERIFY(WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); |
- VERIFY(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); |
- VERIFY(WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); |
- |
- VERIFY(WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
- VERIFY(WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); |
- VERIFY(WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
- VERIFY(WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
- |
- VERIFY(WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
- VERIFY(WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); |
- VERIFY(WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
- VERIFY(WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); |
+ |
+ EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
+ |
+ EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
+ EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
} |
TEST_F(AstDecoderTest, MacrosInt64) { |
-#define VERIFY_L_LL(...) EXPECT_VERIFIES_INLINE(sigs.l_ll(), __VA_ARGS__) |
-#define VERIFY_I_LL(...) EXPECT_VERIFIES_INLINE(sigs.i_ll(), __VA_ARGS__) |
- |
- VERIFY_L_LL(WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); |
- VERIFY_L_LL(WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); |
- VERIFY_L_LL(WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); |
- VERIFY_L_LL(WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); |
- VERIFY_L_LL(WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); |
- VERIFY_L_LL(WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); |
- VERIFY_L_LL(WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); |
- VERIFY_L_LL(WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); |
- VERIFY_L_LL(WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
- VERIFY_L_LL(WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); |
- |
- VERIFY_L_LL(WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))); |
- VERIFY_L_LL(WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))); |
- VERIFY_L_LL(WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
- VERIFY_L_LL(WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
- VERIFY_L_LL(WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
- |
- VERIFY_I_LL(WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
- VERIFY_I_LL(WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
- VERIFY_I_LL(WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
- VERIFY_I_LL(WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
- |
- VERIFY_I_LL(WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
- VERIFY_I_LL(WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
- VERIFY_I_LL(WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
- VERIFY_I_LL(WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
- |
- VERIFY_I_LL(WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
- VERIFY_I_LL(WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); |
+ |
+ EXPECT_VERIFIES(l_ll, WASM_I64_SHL(WASM_GET_LOCAL(0), WASM_I64V_1(22))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_SHR(WASM_GET_LOCAL(0), WASM_I64V_1(23))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_SAR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_ROR(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
+ EXPECT_VERIFIES(l_ll, WASM_I64_ROL(WASM_GET_LOCAL(0), WASM_I64V_1(24))); |
+ |
+ EXPECT_VERIFIES(i_ll, WASM_I64_LTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_LES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_LTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_LEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
+ |
+ EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
+ |
+ EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
+ EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
} |
TEST_F(AstDecoderTest, AllSimpleExpressions) { |
@@ -1085,15 +1150,15 @@ TEST_F(AstDecoderTest, AllSimpleExpressions) { |
TEST_F(AstDecoderTest, MemorySize) { |
byte code[] = {kExprMemorySize}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
- EXPECT_FAILURE(sigs.f_ff(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
+ EXPECT_FAILURE_C(f_ff, code); |
} |
TEST_F(AstDecoderTest, LoadMemOffset) { |
for (int offset = 0; offset < 128; offset += 7) { |
byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, |
static_cast<byte>(offset)}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
} |
} |
@@ -1120,12 +1185,12 @@ TEST_F(AstDecoderTest, LoadMemAlignment) { |
for (int i = 0; i < arraysize(values); i++) { |
for (byte alignment = 0; alignment <= 4; alignment++) { |
- byte code[] = {kExprI8Const, 0, static_cast<byte>(values[i].instruction), |
- alignment, ZERO_OFFSET}; |
+ byte code[] = {WASM_ZERO, static_cast<byte>(values[i].instruction), |
+ alignment, ZERO_OFFSET, WASM_DROP}; |
if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ EXPECT_VERIFIES_C(v_i, code); |
} else { |
- EXPECT_FAILURE(sigs.v_i(), code); |
+ EXPECT_FAILURE_C(v_i, code); |
} |
} |
} |
@@ -1135,10 +1200,15 @@ TEST_F(AstDecoderTest, StoreMemOffset) { |
for (int offset = 0; offset < 128; offset += 7) { |
byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, |
WASM_ZERO, WASM_ZERO)}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_C(v_i, code); |
} |
} |
+TEST_F(AstDecoderTest, StoreMemOffset_void) { |
+ EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, |
+ WASM_ZERO)); |
+} |
+ |
#define BYTE0(x) ((x)&0x7F) |
#define BYTE1(x) ((x >> 7) & 0x7F) |
#define BYTE2(x) ((x >> 14) & 0x7F) |
@@ -1150,25 +1220,25 @@ TEST_F(AstDecoderTest, StoreMemOffset) { |
#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)); |
+ EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT1(0x45)); |
+ EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT2(0x3999)); |
+ EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT3(0x344445)); |
+ EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
+ VARINT4(0x36666667)); |
} |
TEST_F(AstDecoderTest, StoreMemOffset_varint) { |
- 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)); |
+ EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
+ VARINT1(0x33)); |
+ EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
+ VARINT2(0x1111)); |
+ EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
+ VARINT3(0x222222)); |
+ EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
+ VARINT4(0x44444444)); |
} |
TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
@@ -1179,9 +1249,9 @@ TEST_F(AstDecoderTest, AllLoadMemCombinations) { |
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); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
@@ -1195,9 +1265,9 @@ TEST_F(AstDecoderTest, AllStoreMemCombinations) { |
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); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
@@ -1212,8 +1282,8 @@ class TestModuleEnv : public ModuleEnv { |
instance = nullptr; |
module = &mod; |
} |
- byte AddGlobal(LocalType type) { |
- mod.globals.push_back({0, 0, type, 0, false}); |
+ byte AddGlobal(LocalType type, bool mutability = true) { |
+ mod.globals.push_back({type, mutability, NO_INIT, 0, false, false}); |
CHECK(mod.globals.size() <= 127); |
return static_cast<byte>(mod.globals.size() - 1); |
} |
@@ -1223,25 +1293,22 @@ class TestModuleEnv : public ModuleEnv { |
return static_cast<byte>(mod.signatures.size() - 1); |
} |
byte AddFunction(FunctionSig* sig) { |
- mod.functions.push_back({sig, // sig |
- 0, // func_index |
- 0, // sig_index |
- 0, // name_offset |
- 0, // name_length |
- 0, // code_start_offset |
- 0}); // code_end_offset |
+ mod.functions.push_back({sig, // sig |
+ 0, // func_index |
+ 0, // sig_index |
+ 0, // name_offset |
+ 0, // name_length |
+ 0, // code_start_offset |
+ 0, // code_end_offset |
+ false, // import |
+ false}); // export |
CHECK(mod.functions.size() <= 127); |
return static_cast<byte>(mod.functions.size() - 1); |
} |
byte AddImport(FunctionSig* sig) { |
- mod.import_table.push_back({sig, // sig |
- 0, // sig_index |
- 0, // module_name_offset |
- 0, // module_name_length |
- 0, // function_name_offset |
- 0}); // function_name_length |
- CHECK(mod.import_table.size() <= 127); |
- return static_cast<byte>(mod.import_table.size() - 1); |
+ byte result = AddFunction(sig); |
+ mod.functions[result].imported = true; |
+ return result; |
} |
private: |
@@ -1258,9 +1325,9 @@ TEST_F(AstDecoderTest, SimpleCalls) { |
module_env.AddFunction(sigs.i_i()); |
module_env.AddFunction(sigs.i_ii()); |
- 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))); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); |
} |
TEST_F(AstDecoderTest, CallsWithTooFewArguments) { |
@@ -1272,9 +1339,9 @@ TEST_F(AstDecoderTest, CallsWithTooFewArguments) { |
module_env.AddFunction(sigs.i_ii()); |
module_env.AddFunction(sigs.f_ff()); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_ZERO)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(2, WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0)); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); |
} |
TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { |
@@ -1284,9 +1351,9 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { |
module_env.AddFunction(sigs.i_i()); |
- 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))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); |
} |
TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { |
@@ -1296,15 +1363,59 @@ TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { |
module_env.AddFunction(sigs.i_f()); |
- 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))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); |
module_env.AddFunction(sigs.i_d()); |
- 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))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiReturn) { |
+ FLAG_wasm_mv_prototype = true; |
+ LocalType storage[] = {kAstI32, kAstI32}; |
+ FunctionSig sig_ii_v(2, 0, storage); |
+ FunctionSig sig_v_ii(0, 2, storage); |
+ TestModuleEnv module_env; |
+ module = &module_env; |
+ |
+ module_env.AddFunction(&sig_v_ii); |
+ module_env.AddFunction(&sig_ii_v); |
+ |
+ EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); |
+ EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); |
+ EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiReturnType) { |
+ FLAG_wasm_mv_prototype = true; |
+ for (size_t a = 0; a < arraysize(kLocalTypes); a++) { |
+ for (size_t b = 0; b < arraysize(kLocalTypes); b++) { |
+ for (size_t c = 0; c < arraysize(kLocalTypes); c++) { |
+ for (size_t d = 0; d < arraysize(kLocalTypes); d++) { |
+ LocalType storage_ab[] = {kLocalTypes[a], kLocalTypes[b]}; |
+ FunctionSig sig_ab_v(2, 0, storage_ab); |
+ LocalType storage_cd[] = {kLocalTypes[c], kLocalTypes[d]}; |
+ FunctionSig sig_cd_v(2, 0, storage_cd); |
+ |
+ TestModuleEnv module_env; |
+ module = &module_env; |
+ module_env.AddFunction(&sig_cd_v); |
+ |
+ EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); |
+ |
+ if (a == c && b == d) { |
+ EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
+ } else { |
+ EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
+ } |
+ } |
+ } |
+ } |
+ } |
} |
TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
@@ -1316,9 +1427,9 @@ TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
byte f1 = module_env.AddSignature(sigs.i_i()); |
byte f2 = module_env.AddSignature(sigs.i_ii()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
- EXPECT_VERIFIES_INLINE( |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
+ EXPECT_VERIFIES_S( |
sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
} |
@@ -1327,15 +1438,15 @@ TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { |
TestModuleEnv module_env; |
module = &module_env; |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
module_env.AddSignature(sigs.i_v()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
module_env.AddSignature(sigs.i_i()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
} |
TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
@@ -1345,23 +1456,19 @@ TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
byte f0 = module_env.AddFunction(sigs.i_f()); |
- 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_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_S(sig, 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))); |
- EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); |
byte f1 = module_env.AddFunction(sigs.i_d()); |
- 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_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
} |
TEST_F(AstDecoderTest, SimpleImportCalls) { |
@@ -1373,9 +1480,9 @@ TEST_F(AstDecoderTest, SimpleImportCalls) { |
byte f1 = module_env.AddImport(sigs.i_i()); |
byte f2 = module_env.AddImport(sigs.i_ii()); |
- EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0)); |
- 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))); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22))); |
+ EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); |
} |
TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { |
@@ -1385,17 +1492,17 @@ 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_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))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(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_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))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); |
+ EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); |
} |
TEST_F(AstDecoderTest, Int32Globals) { |
@@ -1405,8 +1512,21 @@ TEST_F(AstDecoderTest, Int32Globals) { |
module_env.AddGlobal(kAstI32); |
- EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
+} |
+ |
+TEST_F(AstDecoderTest, ImmutableGlobal) { |
+ FunctionSig* sig = sigs.v_v(); |
+ TestModuleEnv module_env; |
+ module = &module_env; |
+ |
+ uint32_t g0 = module_env.AddGlobal(kAstI32, true); |
+ uint32_t g1 = module_env.AddGlobal(kAstI32, false); |
+ |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); |
} |
TEST_F(AstDecoderTest, Int32Globals_fail) { |
@@ -1419,15 +1539,15 @@ TEST_F(AstDecoderTest, Int32Globals_fail) { |
module_env.AddGlobal(kAstF32); |
module_env.AddGlobal(kAstF64); |
- EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(0)); |
- EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(1)); |
- EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(2)); |
- EXPECT_FAILURE_INLINE(sig, WASM_GET_GLOBAL(3)); |
+ EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); |
+ EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); |
+ EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); |
- EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); |
+ EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); |
} |
TEST_F(AstDecoderTest, Int64Globals) { |
@@ -1438,11 +1558,13 @@ TEST_F(AstDecoderTest, Int64Globals) { |
module_env.AddGlobal(kAstI64); |
module_env.AddGlobal(kAstI64); |
- EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(1)); |
+ EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
- EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
+ WASM_GET_LOCAL(0)); |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), |
+ WASM_GET_LOCAL(0)); |
} |
TEST_F(AstDecoderTest, Float32Globals) { |
@@ -1452,8 +1574,9 @@ TEST_F(AstDecoderTest, Float32Globals) { |
module_env.AddGlobal(kAstF32); |
- EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
+ WASM_GET_LOCAL(0)); |
} |
TEST_F(AstDecoderTest, Float64Globals) { |
@@ -1463,8 +1586,9 @@ TEST_F(AstDecoderTest, Float64Globals) { |
module_env.AddGlobal(kAstF64); |
- EXPECT_VERIFIES_INLINE(sig, WASM_GET_GLOBAL(0)); |
- EXPECT_VERIFIES_INLINE(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
+ WASM_GET_LOCAL(0)); |
} |
TEST_F(AstDecoderTest, AllGetGlobalCombinations) { |
@@ -1477,9 +1601,9 @@ TEST_F(AstDecoderTest, AllGetGlobalCombinations) { |
module = &module_env; |
module_env.AddGlobal(global_type); |
if (local_type == global_type) { |
- EXPECT_VERIFIES_INLINE(&sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); |
} else { |
- EXPECT_FAILURE_INLINE(&sig, WASM_GET_GLOBAL(0)); |
+ EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); |
} |
} |
} |
@@ -1495,9 +1619,9 @@ TEST_F(AstDecoderTest, AllSetGlobalCombinations) { |
module = &module_env; |
module_env.AddGlobal(global_type); |
if (local_type == global_type) { |
- EXPECT_VERIFIES_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
} else { |
- EXPECT_FAILURE_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
} |
} |
} |
@@ -1509,8 +1633,8 @@ TEST_F(AstDecoderTest, WasmGrowMemory) { |
module->origin = kWasmOrigin; |
byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; |
- EXPECT_VERIFIES(sigs.i_i(), code); |
- EXPECT_FAILURE(sigs.i_d(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
+ EXPECT_FAILURE_C(i_d, code); |
} |
TEST_F(AstDecoderTest, AsmJsGrowMemory) { |
@@ -1519,7 +1643,7 @@ TEST_F(AstDecoderTest, AsmJsGrowMemory) { |
module->origin = kAsmJsOrigin; |
byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))}; |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { |
@@ -1561,7 +1685,7 @@ TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { |
for (int i = 0; i < arraysize(AsmJsBinOps); i++) { |
byte code[] = { |
WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
- EXPECT_FAILURE(AsmJsBinOps[i].sig, code); |
+ EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); |
} |
} |
} |
@@ -1608,284 +1732,304 @@ TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) { |
module->origin = kWasmOrigin; |
for (int i = 0; i < arraysize(AsmJsUnOps); i++) { |
byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; |
- EXPECT_FAILURE(AsmJsUnOps[i].sig, code); |
+ EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); |
} |
} |
} |
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)))); |
+ EXPECT_VERIFIES( |
+ i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
+ EXPECT_VERIFIES( |
+ i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); |
} |
TEST_F(AstDecoderTest, BreakIfBinop) { |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), WASM_BLOCK(WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), |
- WASM_ZERO))); |
- EXPECT_FAILURE_INLINE(sigs.i_i(), |
- WASM_BLOCK(WASM_I32_ADD( |
- WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
+ WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
+ WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
+ EXPECT_VERIFIES_S( |
+ sigs.f_ff(), |
+ WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); |
+} |
+ |
+TEST_F(AstDecoderTest, BreakIfBinop_fail) { |
+ EXPECT_FAILURE_S( |
+ sigs.f_ff(), |
+ WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
+ EXPECT_FAILURE_S( |
+ sigs.i_i(), |
+ WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), 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( |
+ byte code[] = {WASM_BLOCK_I( |
WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), |
WASM_SET_LOCAL(0, WASM_I8(1))), |
- WASM_GET_LOCAL(0))}; |
+ WASM_ZERO)}; |
if (i < 3) { |
- EXPECT_VERIFIES(sigs.i_i(), code); |
+ EXPECT_VERIFIES_C(i_i, code); |
} else { |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
} |
} |
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[] = {B1(WASM_LOOP(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); |
+ for (int i = 0; i < 7; i++) { |
+ byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))}; |
+ if (i <= 3) { |
+ EXPECT_VERIFIES_C(v_v, code); |
} else { |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
} |
} |
} |
TEST_F(AstDecoderTest, BreakNesting3) { |
- for (int i = 0; i < 5; i++) { |
+ for (int i = 0; i < 7; i++) { |
// (block[1] (loop[1] (block[1] (if 0 break[N]) |
byte code[] = { |
- WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))}; |
- if (i < 3) { |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; |
+ if (i < 4) { |
+ EXPECT_VERIFIES_C(v_v, code); |
} else { |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
} |
} |
} |
TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { |
- EXPECT_FAILURE_INLINE(sigs.i_i(), |
- B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); |
+ EXPECT_FAILURE(i_i, 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)))); |
+ EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), |
+ WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
+ EXPECT_FAILURE( |
+ 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(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, // -- |
- kExprBlock, // -- |
- kExprBlock, // -- |
- kExprBlock, // -- |
- kExprBlock, // -- |
- kExprBlock, // -- |
- kExprBr, ARITY_0, static_cast<byte>(i), // -- |
- kExprEnd, // -- |
- kExprEnd, // -- |
- kExprEnd, // -- |
- kExprEnd, // -- |
- kExprEnd, // -- |
- kExprEnd // -- |
- }; |
+ byte code[] = {WASM_BLOCK(WASM_BLOCK( |
+ WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))}; |
int depth = 6; |
- for (int l = 0; l < 6; l++) { |
- if (mask & (1 << l)) { |
- code[l] = kExprLoop; |
- depth++; |
+ int m = mask; |
+ for (size_t pos = 0; pos < sizeof(code); pos++) { |
+ if (code[pos] != kExprBlock) continue; |
+ if (m & 1) { |
+ code[pos] = kExprLoop; |
+ code[pos + 1] = kLocalVoid; |
} |
+ m >>= 1; |
} |
- if (i < depth) { |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ if (i <= depth) { |
+ EXPECT_VERIFIES_C(v_v, code); |
} else { |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ EXPECT_FAILURE_C(v_v, code); |
} |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBreak_TypeCheck) { |
+TEST_F(AstDecoderTest, Break_TypeCheck) { |
FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; |
for (size_t i = 0; i < arraysize(sigarray); i++) { |
FunctionSig* sig = sigarray[i]; |
// unify X and X => OK |
- EXPECT_VERIFIES_INLINE( |
- sig, B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
- WASM_GET_LOCAL(0))); |
+ byte code[] = {WASM_BLOCK_T( |
+ sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
+ WASM_GET_LOCAL(0))}; |
+ EXPECT_VERIFIES_SC(sig, code); |
} |
// unify i32 and f32 => fail |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); |
+ EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), |
+ WASM_F32(1.2))); |
// unify f64 and f64 => OK |
- EXPECT_VERIFIES_INLINE( |
- sigs.d_dd(), |
- B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2))); |
+ EXPECT_VERIFIES( |
+ d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
+ WASM_F64(1.2))); |
} |
-TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) { |
- byte code1[] = {WASM_BLOCK(WASM_IF(WASM_ZERO, WASM_BRV(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))}; |
+TEST_F(AstDecoderTest, Break_TypeCheckAll1) { |
+ for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
+ for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
+ LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
+ FunctionSig sig(1, 2, storage); |
+ byte code[] = {WASM_BLOCK_T( |
+ sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
+ WASM_GET_LOCAL(1))}; |
+ if (i == j) { |
+ EXPECT_VERIFIES_SC(&sig, code); |
+ } else { |
+ EXPECT_FAILURE_SC(&sig, code); |
+ } |
+ } |
+ } |
+} |
+ |
+TEST_F(AstDecoderTest, Break_TypeCheckAll2) { |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
FunctionSig sig(1, 2, storage); |
+ byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, |
+ WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), |
+ WASM_GET_LOCAL(1))}; |
if (i == j) { |
- EXPECT_VERIFIES(&sig, code1); |
- EXPECT_VERIFIES(&sig, code2); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code1); |
- EXPECT_FAILURE(&sig, code2); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBr_Unify) { |
+TEST_F(AstDecoderTest, Break_TypeCheckAll3) { |
+ for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
+ for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
+ LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
+ FunctionSig sig(1, 2, storage); |
+ byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, |
+ WASM_GET_LOCAL(1), |
+ WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; |
+ |
+ if (i == j) { |
+ EXPECT_VERIFIES_SC(&sig, code); |
+ } else { |
+ EXPECT_FAILURE_SC(&sig, code); |
+ } |
+ } |
+ } |
+} |
+ |
+TEST_F(AstDecoderTest, Break_Unify) { |
for (int which = 0; which < 2; which++) { |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
LocalType type = kLocalTypes[i]; |
LocalType storage[] = {kAstI32, kAstI32, type}; |
FunctionSig sig(1, 2, storage); |
- byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
- WASM_GET_LOCAL(which ^ 1))}; |
- byte code2[] = { |
- WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))), |
- WASM_GET_LOCAL(which ^ 1))}; |
+ byte code1[] = {WASM_BLOCK_T( |
+ type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
+ WASM_GET_LOCAL(which ^ 1))}; |
if (type == kAstI32) { |
- EXPECT_VERIFIES(&sig, code1); |
- EXPECT_VERIFIES(&sig, code2); |
+ EXPECT_VERIFIES_SC(&sig, code1); |
} else { |
- EXPECT_FAILURE(&sig, code1); |
- EXPECT_FAILURE(&sig, code2); |
+ EXPECT_FAILURE_SC(&sig, code1); |
} |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBrIf_cond_type) { |
- byte code[] = {B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
+TEST_F(AstDecoderTest, BreakIf_cond_type) { |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
- LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; |
- FunctionSig sig(0, 2, types); |
+ LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
+ FunctionSig sig(1, 2, types); |
+ byte code[] = {WASM_BLOCK_T( |
+ types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
- if (types[1] == kAstI32) { |
- EXPECT_VERIFIES(&sig, code); |
+ if (types[2] == kAstI32) { |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBrIf_val_type) { |
- byte code[] = {B2(WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
- WASM_GET_LOCAL(0))}; |
+TEST_F(AstDecoderTest, BreakIf_val_type) { |
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], |
kAstI32}; |
FunctionSig sig(1, 3, types); |
+ byte code[] = {WASM_BLOCK_T( |
+ types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
+ WASM_DROP, WASM_GET_LOCAL(0))}; |
if (i == j) { |
- EXPECT_VERIFIES(&sig, code); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBrIf_Unify) { |
+TEST_F(AstDecoderTest, BreakIf_Unify) { |
for (int which = 0; which < 2; which++) { |
for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
LocalType type = kLocalTypes[i]; |
LocalType storage[] = {kAstI32, kAstI32, type}; |
FunctionSig sig(1, 2, storage); |
- |
- byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
- WASM_GET_LOCAL(which ^ 1))}; |
- byte code2[] = {WASM_LOOP(WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), |
- WASM_GET_LOCAL(which ^ 1))}; |
+ byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
+ WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; |
if (type == kAstI32) { |
- EXPECT_VERIFIES(&sig, code1); |
- EXPECT_VERIFIES(&sig, code2); |
+ EXPECT_VERIFIES_SC(&sig, code); |
} else { |
- EXPECT_FAILURE(&sig, code1); |
- EXPECT_FAILURE(&sig, code2); |
+ EXPECT_FAILURE_SC(&sig, code); |
} |
} |
} |
} |
TEST_F(AstDecoderTest, BrTable0) { |
- static byte code[] = {kExprNop, kExprBrTable, 0, 0}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
+ static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; |
+ EXPECT_FAILURE_C(v_v, code); |
} |
TEST_F(AstDecoderTest, BrTable0b) { |
- static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 0}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)}; |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, BrTable0c) { |
- static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 1, 0, 0}; |
- EXPECT_FAILURE(sigs.v_v(), code); |
- EXPECT_FAILURE(sigs.i_i(), code); |
+ static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; |
+ EXPECT_FAILURE_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
} |
TEST_F(AstDecoderTest, BrTable1a) { |
static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
} |
TEST_F(AstDecoderTest, BrTable1b) { |
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); |
- EXPECT_FAILURE(sigs.d_dd(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
+ EXPECT_FAILURE_C(i_i, code); |
+ EXPECT_FAILURE_C(f_ff, code); |
+ EXPECT_FAILURE_C(d_dd, code); |
} |
TEST_F(AstDecoderTest, BrTable2a) { |
static byte code[] = { |
B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
} |
TEST_F(AstDecoderTest, BrTable2b) { |
static byte code[] = {WASM_BLOCK( |
WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; |
- EXPECT_VERIFIES(sigs.v_v(), code); |
+ EXPECT_VERIFIES_C(v_v, code); |
} |
TEST_F(AstDecoderTest, BrTable_off_end) { |
@@ -1898,63 +2042,74 @@ TEST_F(AstDecoderTest, BrTable_off_end) { |
TEST_F(AstDecoderTest, BrTable_invalid_br1) { |
for (int depth = 0; depth < 4; depth++) { |
byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
- if (depth == 0) { |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ if (depth <= 1) { |
+ EXPECT_VERIFIES_C(v_i, code); |
} else { |
- EXPECT_FAILURE(sigs.v_i(), code); |
+ EXPECT_FAILURE_C(v_i, code); |
} |
} |
} |
TEST_F(AstDecoderTest, BrTable_invalid_br2) { |
- for (int depth = 0; depth < 4; depth++) { |
+ for (int depth = 0; depth < 7; depth++) { |
byte code[] = { |
WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
- if (depth <= 1) { |
- EXPECT_VERIFIES(sigs.v_i(), code); |
+ if (depth < 2) { |
+ EXPECT_VERIFIES_C(v_i, code); |
} else { |
- EXPECT_FAILURE(sigs.v_i(), code); |
+ EXPECT_FAILURE_C(v_i, code); |
} |
} |
} |
-TEST_F(AstDecoderTest, ExprBreakNesting1) { |
- 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))); |
+TEST_F(AstDecoderTest, Brv1) { |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO)))); |
+} |
+ |
+TEST_F(AstDecoderTest, Brv1_type) { |
+ EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+} |
+ |
+TEST_F(AstDecoderTest, Brv1_type_n) { |
+ EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
+} |
+ |
+TEST_F(AstDecoderTest, BrvIf1) { |
+ EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))); |
+} |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(0, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), |
- WASM_LOOP(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR_IF(0, WASM_ZERO))); |
+TEST_F(AstDecoderTest, BrvIf1_type) { |
+ EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
+} |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
- EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1))); |
+TEST_F(AstDecoderTest, BrvIf1_type_n) { |
+ EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
+ EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
} |
TEST_F(AstDecoderTest, Select) { |
- EXPECT_VERIFIES_INLINE( |
- sigs.i_i(), WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.f_ff(), |
- WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE(sigs.d_dd(), |
- WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); |
- EXPECT_VERIFIES_INLINE( |
- sigs.l_l(), WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); |
+ EXPECT_VERIFIES(i_i, |
+ WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); |
+ EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); |
+ EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); |
+ EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); |
} |
TEST_F(AstDecoderTest, Select_fail1) { |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); |
+ EXPECT_FAILURE( |
+ i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE( |
+ i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE( |
+ i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); |
} |
TEST_F(AstDecoderTest, Select_fail2) { |
@@ -1965,64 +2120,159 @@ TEST_F(AstDecoderTest, Select_fail2) { |
LocalType types[] = {type, kAstI32, type}; |
FunctionSig sig(1, 2, types); |
- EXPECT_VERIFIES_INLINE( |
- &sig, |
- WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); |
+ EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), |
+ WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- &sig, |
- WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- &sig, |
- WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
+ WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- &sig, |
- WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
+ EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(1))); |
} |
} |
TEST_F(AstDecoderTest, Select_TypeCheck) { |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE( |
+ i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); |
+ EXPECT_FAILURE( |
+ i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); |
- EXPECT_FAILURE_INLINE( |
- sigs.i_i(), |
- WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
+ EXPECT_FAILURE(i_i, |
+ WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
} |
TEST_F(AstDecoderTest, Throw) { |
FLAG_wasm_eh_prototype = true; |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprThrow); |
+ EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow); |
- EXPECT_FAILURE_INLINE(sigs.i_d(), WASM_GET_LOCAL(0), kExprThrow, |
- WASM_I32V(0)); |
- EXPECT_FAILURE_INLINE(sigs.i_f(), WASM_GET_LOCAL(0), kExprThrow, |
- WASM_I32V(0)); |
- EXPECT_FAILURE_INLINE(sigs.l_l(), WASM_GET_LOCAL(0), kExprThrow, |
- WASM_I64V(0)); |
+ EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
+ EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
+ EXPECT_FAILURE(l_l, WASM_GET_LOCAL(0), kExprThrow, WASM_I64V(0)); |
} |
+#define WASM_TRY_OP kExprTry, kLocalVoid |
+ |
#define WASM_CATCH(local) kExprCatch, static_cast<byte>(local) |
+ |
TEST_F(AstDecoderTest, TryCatch) { |
FLAG_wasm_eh_prototype = true; |
- EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0), kExprEnd); |
+ EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd); |
// Missing catch. |
- EXPECT_FAILURE_INLINE(sigs.v_v(), kExprTry, kExprEnd); |
+ EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd); |
// Missing end. |
- EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0)); |
+ EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); |
// Double catch. |
- EXPECT_FAILURE_INLINE(sigs.v_i(), kExprTry, WASM_CATCH(0), WASM_CATCH(0), |
- kExprEnd); |
+ EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiValBlock1) { |
+ FLAG_wasm_mv_prototype = true; |
+ EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(1)), |
+ kExprI32Add); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiValBlock2) { |
+ FLAG_wasm_mv_prototype = true; |
+ EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(1)), |
+ WASM_I32_ADD(WASM_NOP, WASM_NOP)); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiValBlockBr1) { |
+ FLAG_wasm_mv_prototype = true; |
+ EXPECT_FAILURE(i_ii, |
+ WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_BR(0)), |
+ kExprI32Add); |
+ EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
+ WASM_GET_LOCAL(1), WASM_BR(0)), |
+ kExprI32Add); |
+} |
+ |
+TEST_F(AstDecoderTest, MultiValIf1) { |
+ FLAG_wasm_mv_prototype = true; |
+ EXPECT_FAILURE( |
+ i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
+ WASM_SEQ(WASM_GET_LOCAL(0)), |
+ WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
+ kExprI32Add); |
+ EXPECT_FAILURE(i_ii, |
+ WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
+ WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
+ WASM_SEQ(WASM_GET_LOCAL(1))), |
+ kExprI32Add); |
+ EXPECT_VERIFIES( |
+ i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, 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); |
+} |
+ |
+class BranchTableIteratorTest : public TestWithZone { |
+ public: |
+ BranchTableIteratorTest() : TestWithZone() {} |
+ void CheckBrTableSize(const byte* start, const byte* end) { |
+ Decoder decoder(start, end); |
+ BranchTableOperand operand(&decoder, start); |
+ BranchTableIterator iterator(&decoder, operand); |
+ EXPECT_EQ(end - start - 1, iterator.length()); |
+ EXPECT_TRUE(decoder.ok()); |
+ } |
+ void CheckBrTableError(const byte* start, const byte* end) { |
+ Decoder decoder(start, end); |
+ BranchTableOperand operand(&decoder, start); |
+ BranchTableIterator iterator(&decoder, operand); |
+ iterator.length(); |
+ EXPECT_FALSE(decoder.ok()); |
+ } |
+}; |
+ |
+#define CHECK_BR_TABLE_LENGTH(...) \ |
+ { \ |
+ static byte code[] = {kExprBrTable, __VA_ARGS__}; \ |
+ CheckBrTableSize(code, code + sizeof(code)); \ |
+ } |
+ |
+#define CHECK_BR_TABLE_ERROR(...) \ |
+ { \ |
+ static byte code[] = {kExprBrTable, __VA_ARGS__}; \ |
+ CheckBrTableError(code, code + sizeof(code)); \ |
+ } |
+ |
+TEST_F(BranchTableIteratorTest, count0) { |
+ CHECK_BR_TABLE_LENGTH(0, U32V_1(1)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_2(200)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_3(30000)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_4(400000)); |
+ |
+ CHECK_BR_TABLE_LENGTH(0, U32V_1(2)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_2(300)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_3(40000)); |
+ CHECK_BR_TABLE_LENGTH(0, U32V_4(500000)); |
+} |
+ |
+TEST_F(BranchTableIteratorTest, count1) { |
+ CHECK_BR_TABLE_LENGTH(1, U32V_1(1), U32V_1(6)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_2(200), U32V_1(8)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_3(30000), U32V_1(9)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_4(400000), U32V_1(11)); |
+ |
+ CHECK_BR_TABLE_LENGTH(1, U32V_1(2), U32V_2(6)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_2(300), U32V_2(7)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_3(40000), U32V_2(8)); |
+ CHECK_BR_TABLE_LENGTH(1, U32V_4(500000), U32V_2(9)); |
+} |
+ |
+TEST_F(BranchTableIteratorTest, error0) { |
+ CHECK_BR_TABLE_ERROR(0); |
+ CHECK_BR_TABLE_ERROR(1, U32V_1(33)); |
} |
class WasmOpcodeLengthTest : public TestWithZone { |
@@ -2044,16 +2294,16 @@ class WasmOpcodeLengthTest : public TestWithZone { |
TEST_F(WasmOpcodeLengthTest, Statements) { |
EXPECT_LENGTH(1, kExprNop); |
- EXPECT_LENGTH(1, kExprBlock); |
- EXPECT_LENGTH(1, kExprLoop); |
- EXPECT_LENGTH(1, kExprIf); |
+ EXPECT_LENGTH(2, kExprBlock); |
+ EXPECT_LENGTH(2, kExprLoop); |
+ EXPECT_LENGTH(2, kExprIf); |
EXPECT_LENGTH(1, kExprElse); |
EXPECT_LENGTH(1, kExprEnd); |
EXPECT_LENGTH(1, kExprSelect); |
- EXPECT_LENGTH(3, kExprBr); |
- EXPECT_LENGTH(3, kExprBrIf); |
+ EXPECT_LENGTH(2, kExprBr); |
+ EXPECT_LENGTH(2, kExprBrIf); |
EXPECT_LENGTH(1, kExprThrow); |
- EXPECT_LENGTH(1, kExprTry); |
+ EXPECT_LENGTH(2, kExprTry); |
EXPECT_LENGTH(2, kExprCatch); |
} |
@@ -2065,14 +2315,8 @@ TEST_F(WasmOpcodeLengthTest, MiscExpressions) { |
EXPECT_LENGTH(2, kExprSetLocal); |
EXPECT_LENGTH(2, kExprGetGlobal); |
EXPECT_LENGTH(2, kExprSetGlobal); |
- EXPECT_LENGTH(3, kExprCallFunction); |
- EXPECT_LENGTH(3, kExprCallImport); |
- EXPECT_LENGTH(3, kExprCallIndirect); |
- EXPECT_LENGTH(1, kExprIf); |
- EXPECT_LENGTH(1, kExprBlock); |
- EXPECT_LENGTH(1, kExprLoop); |
- EXPECT_LENGTH(3, kExprBr); |
- EXPECT_LENGTH(3, kExprBrIf); |
+ EXPECT_LENGTH(2, kExprCallFunction); |
+ EXPECT_LENGTH(2, kExprCallIndirect); |
} |
TEST_F(WasmOpcodeLengthTest, I32Const) { |
@@ -2256,248 +2500,6 @@ TEST_F(WasmOpcodeLengthTest, SimpleExpressions) { |
EXPECT_LENGTH(1, kExprI64ReinterpretF64); |
} |
-class WasmOpcodeArityTest : public TestWithZone { |
- public: |
- WasmOpcodeArityTest() : TestWithZone() {} |
-}; |
- |
-#define EXPECT_ARITY(expected, ...) \ |
- { \ |
- static const byte code[] = {__VA_ARGS__}; \ |
- EXPECT_EQ(expected, OpcodeArity(code, code + sizeof(code))); \ |
- } |
- |
-TEST_F(WasmOpcodeArityTest, Control) { |
- EXPECT_ARITY(0, kExprNop); |
- |
- EXPECT_ARITY(0, kExprBlock, 0); |
- 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(0, kExprLoop, 1); |
- EXPECT_ARITY(0, kExprLoop, 2); |
- EXPECT_ARITY(0, kExprLoop, 7); |
- EXPECT_ARITY(0, kExprLoop, 11); |
- |
- EXPECT_ARITY(3, kExprSelect); |
- |
- 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); |
- |
- { |
- EXPECT_ARITY(0, kExprReturn, ARITY_0); |
- EXPECT_ARITY(1, kExprReturn, ARITY_1); |
- } |
- |
- EXPECT_ARITY(0, kExprThrow); |
- EXPECT_ARITY(0, kExprTry); |
- EXPECT_ARITY(1, kExprCatch, 2); |
-} |
- |
-TEST_F(WasmOpcodeArityTest, Misc) { |
- EXPECT_ARITY(0, kExprI8Const); |
- EXPECT_ARITY(0, kExprI32Const); |
- EXPECT_ARITY(0, kExprF32Const); |
- EXPECT_ARITY(0, kExprI64Const); |
- EXPECT_ARITY(0, kExprF64Const); |
- EXPECT_ARITY(0, kExprGetLocal); |
- EXPECT_ARITY(1, kExprSetLocal); |
- EXPECT_ARITY(0, kExprGetGlobal); |
- EXPECT_ARITY(1, kExprSetGlobal); |
-} |
- |
-TEST_F(WasmOpcodeArityTest, Calls) { |
- { |
- 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); |
- } |
- |
- { |
- 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); |
- } |
-} |
- |
-TEST_F(WasmOpcodeArityTest, LoadsAndStores) { |
- EXPECT_ARITY(1, kExprI32LoadMem8S); |
- EXPECT_ARITY(1, kExprI32LoadMem8U); |
- EXPECT_ARITY(1, kExprI32LoadMem16S); |
- EXPECT_ARITY(1, kExprI32LoadMem16U); |
- EXPECT_ARITY(1, kExprI32LoadMem); |
- |
- EXPECT_ARITY(1, kExprI64LoadMem8S); |
- EXPECT_ARITY(1, kExprI64LoadMem8U); |
- EXPECT_ARITY(1, kExprI64LoadMem16S); |
- EXPECT_ARITY(1, kExprI64LoadMem16U); |
- EXPECT_ARITY(1, kExprI64LoadMem32S); |
- EXPECT_ARITY(1, kExprI64LoadMem32U); |
- EXPECT_ARITY(1, kExprI64LoadMem); |
- EXPECT_ARITY(1, kExprF32LoadMem); |
- EXPECT_ARITY(1, kExprF64LoadMem); |
- |
- EXPECT_ARITY(2, kExprI32StoreMem8); |
- EXPECT_ARITY(2, kExprI32StoreMem16); |
- EXPECT_ARITY(2, kExprI32StoreMem); |
- EXPECT_ARITY(2, kExprI64StoreMem8); |
- EXPECT_ARITY(2, kExprI64StoreMem16); |
- EXPECT_ARITY(2, kExprI64StoreMem32); |
- EXPECT_ARITY(2, kExprI64StoreMem); |
- EXPECT_ARITY(2, kExprF32StoreMem); |
- EXPECT_ARITY(2, kExprF64StoreMem); |
-} |
- |
-TEST_F(WasmOpcodeArityTest, MiscMemExpressions) { |
- EXPECT_ARITY(0, kExprMemorySize); |
- EXPECT_ARITY(1, kExprGrowMemory); |
-} |
- |
-TEST_F(WasmOpcodeArityTest, SimpleExpressions) { |
- EXPECT_ARITY(2, kExprI32Add); |
- EXPECT_ARITY(2, kExprI32Sub); |
- EXPECT_ARITY(2, kExprI32Mul); |
- EXPECT_ARITY(2, kExprI32DivS); |
- EXPECT_ARITY(2, kExprI32DivU); |
- EXPECT_ARITY(2, kExprI32RemS); |
- EXPECT_ARITY(2, kExprI32RemU); |
- EXPECT_ARITY(2, kExprI32And); |
- EXPECT_ARITY(2, kExprI32Ior); |
- EXPECT_ARITY(2, kExprI32Xor); |
- EXPECT_ARITY(2, kExprI32Shl); |
- EXPECT_ARITY(2, kExprI32ShrU); |
- EXPECT_ARITY(2, kExprI32ShrS); |
- EXPECT_ARITY(2, kExprI32Eq); |
- EXPECT_ARITY(2, kExprI32Ne); |
- EXPECT_ARITY(2, kExprI32LtS); |
- EXPECT_ARITY(2, kExprI32LeS); |
- EXPECT_ARITY(2, kExprI32LtU); |
- EXPECT_ARITY(2, kExprI32LeU); |
- EXPECT_ARITY(2, kExprI32GtS); |
- EXPECT_ARITY(2, kExprI32GeS); |
- EXPECT_ARITY(2, kExprI32GtU); |
- EXPECT_ARITY(2, kExprI32GeU); |
- EXPECT_ARITY(1, kExprI32Clz); |
- EXPECT_ARITY(1, kExprI32Ctz); |
- EXPECT_ARITY(1, kExprI32Popcnt); |
- EXPECT_ARITY(1, kExprI32Eqz); |
- EXPECT_ARITY(2, kExprI64Add); |
- EXPECT_ARITY(2, kExprI64Sub); |
- EXPECT_ARITY(2, kExprI64Mul); |
- EXPECT_ARITY(2, kExprI64DivS); |
- EXPECT_ARITY(2, kExprI64DivU); |
- EXPECT_ARITY(2, kExprI64RemS); |
- EXPECT_ARITY(2, kExprI64RemU); |
- EXPECT_ARITY(2, kExprI64And); |
- EXPECT_ARITY(2, kExprI64Ior); |
- EXPECT_ARITY(2, kExprI64Xor); |
- EXPECT_ARITY(2, kExprI64Shl); |
- EXPECT_ARITY(2, kExprI64ShrU); |
- EXPECT_ARITY(2, kExprI64ShrS); |
- EXPECT_ARITY(2, kExprI64Eq); |
- EXPECT_ARITY(2, kExprI64Ne); |
- EXPECT_ARITY(2, kExprI64LtS); |
- EXPECT_ARITY(2, kExprI64LeS); |
- EXPECT_ARITY(2, kExprI64LtU); |
- EXPECT_ARITY(2, kExprI64LeU); |
- EXPECT_ARITY(2, kExprI64GtS); |
- EXPECT_ARITY(2, kExprI64GeS); |
- EXPECT_ARITY(2, kExprI64GtU); |
- EXPECT_ARITY(2, kExprI64GeU); |
- EXPECT_ARITY(1, kExprI64Clz); |
- EXPECT_ARITY(1, kExprI64Ctz); |
- EXPECT_ARITY(1, kExprI64Popcnt); |
- EXPECT_ARITY(2, kExprF32Add); |
- EXPECT_ARITY(2, kExprF32Sub); |
- EXPECT_ARITY(2, kExprF32Mul); |
- EXPECT_ARITY(2, kExprF32Div); |
- EXPECT_ARITY(2, kExprF32Min); |
- EXPECT_ARITY(2, kExprF32Max); |
- EXPECT_ARITY(1, kExprF32Abs); |
- EXPECT_ARITY(1, kExprF32Neg); |
- EXPECT_ARITY(2, kExprF32CopySign); |
- EXPECT_ARITY(1, kExprF32Ceil); |
- EXPECT_ARITY(1, kExprF32Floor); |
- EXPECT_ARITY(1, kExprF32Trunc); |
- EXPECT_ARITY(1, kExprF32NearestInt); |
- EXPECT_ARITY(1, kExprF32Sqrt); |
- EXPECT_ARITY(2, kExprF32Eq); |
- EXPECT_ARITY(2, kExprF32Ne); |
- EXPECT_ARITY(2, kExprF32Lt); |
- EXPECT_ARITY(2, kExprF32Le); |
- EXPECT_ARITY(2, kExprF32Gt); |
- EXPECT_ARITY(2, kExprF32Ge); |
- EXPECT_ARITY(2, kExprF64Add); |
- EXPECT_ARITY(2, kExprF64Sub); |
- EXPECT_ARITY(2, kExprF64Mul); |
- EXPECT_ARITY(2, kExprF64Div); |
- EXPECT_ARITY(2, kExprF64Min); |
- EXPECT_ARITY(2, kExprF64Max); |
- EXPECT_ARITY(1, kExprF64Abs); |
- EXPECT_ARITY(1, kExprF64Neg); |
- EXPECT_ARITY(2, kExprF64CopySign); |
- EXPECT_ARITY(1, kExprF64Ceil); |
- EXPECT_ARITY(1, kExprF64Floor); |
- EXPECT_ARITY(1, kExprF64Trunc); |
- EXPECT_ARITY(1, kExprF64NearestInt); |
- EXPECT_ARITY(1, kExprF64Sqrt); |
- EXPECT_ARITY(2, kExprF64Eq); |
- EXPECT_ARITY(2, kExprF64Ne); |
- EXPECT_ARITY(2, kExprF64Lt); |
- EXPECT_ARITY(2, kExprF64Le); |
- EXPECT_ARITY(2, kExprF64Gt); |
- EXPECT_ARITY(2, kExprF64Ge); |
- EXPECT_ARITY(1, kExprI32SConvertF32); |
- EXPECT_ARITY(1, kExprI32SConvertF64); |
- EXPECT_ARITY(1, kExprI32UConvertF32); |
- EXPECT_ARITY(1, kExprI32UConvertF64); |
- EXPECT_ARITY(1, kExprI32ConvertI64); |
- EXPECT_ARITY(1, kExprI64SConvertF32); |
- EXPECT_ARITY(1, kExprI64SConvertF64); |
- EXPECT_ARITY(1, kExprI64UConvertF32); |
- EXPECT_ARITY(1, kExprI64UConvertF64); |
- EXPECT_ARITY(1, kExprI64SConvertI32); |
- EXPECT_ARITY(1, kExprI64UConvertI32); |
- EXPECT_ARITY(1, kExprF32SConvertI32); |
- EXPECT_ARITY(1, kExprF32UConvertI32); |
- EXPECT_ARITY(1, kExprF32SConvertI64); |
- EXPECT_ARITY(1, kExprF32UConvertI64); |
- EXPECT_ARITY(1, kExprF32ConvertF64); |
- EXPECT_ARITY(1, kExprF32ReinterpretI32); |
- EXPECT_ARITY(1, kExprF64SConvertI32); |
- EXPECT_ARITY(1, kExprF64UConvertI32); |
- EXPECT_ARITY(1, kExprF64SConvertI64); |
- EXPECT_ARITY(1, kExprF64UConvertI64); |
- EXPECT_ARITY(1, kExprF64ConvertF32); |
- EXPECT_ARITY(1, kExprF64ReinterpretI64); |
- EXPECT_ARITY(1, kExprI32ReinterpretF32); |
- EXPECT_ARITY(1, kExprI64ReinterpretF64); |
-} |
- |
typedef ZoneVector<LocalType> LocalTypeMap; |
class LocalDeclDecoderTest : public TestWithZone { |