Commit 7ed3c4d7 authored by titzer's avatar titzer Committed by Commit bot

[wasm] Remove non-standard kExprI8Const bytecode

R=clemensh@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2595733003
Cr-Commit-Position: refs/heads/master@{#42141}
parent 9c7b8726
...@@ -1067,7 +1067,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -1067,7 +1067,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
void VisitPropertyAndEmitIndex(Property* expr, AsmType** atype) { void VisitPropertyAndEmitIndex(Property* expr, AsmType** atype) {
Expression* obj = expr->obj(); Expression* obj = expr->obj();
*atype = typer_->TypeOf(obj); *atype = typer_->TypeOf(obj);
int size = (*atype)->ElementSizeInBytes(); int32_t size = (*atype)->ElementSizeInBytes();
if (size == 1) { if (size == 1) {
// Allow more general expression in byte arrays than the spec // Allow more general expression in byte arrays than the spec
// strictly permits. // strictly permits.
...@@ -1095,9 +1095,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -1095,9 +1095,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
1 << static_cast<int>( 1 << static_cast<int>(
binop->right()->AsLiteral()->raw_value()->AsNumber())); binop->right()->AsLiteral()->raw_value()->AsNumber()));
// Mask bottom bits to match asm.js behavior. // Mask bottom bits to match asm.js behavior.
byte mask = static_cast<byte>(~(size - 1));
RECURSE(Visit(binop->left())); RECURSE(Visit(binop->left()));
current_function_builder_->EmitWithU8(kExprI8Const, mask); current_function_builder_->EmitI32Const(~(size - 1));
current_function_builder_->Emit(kExprI32And); current_function_builder_->Emit(kExprI32And);
return; return;
} }
...@@ -1236,7 +1235,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> { ...@@ -1236,7 +1235,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
// if set_local(tmp, x) < 0 // if set_local(tmp, x) < 0
Visit(call->arguments()->at(0)); Visit(call->arguments()->at(0));
current_function_builder_->EmitTeeLocal(tmp.index()); current_function_builder_->EmitTeeLocal(tmp.index());
byte code[] = {WASM_I8(0)}; byte code[] = {WASM_ZERO};
current_function_builder_->EmitCode(code, sizeof(code)); current_function_builder_->EmitCode(code, sizeof(code));
current_function_builder_->Emit(kExprI32LtS); current_function_builder_->Emit(kExprI32LtS);
current_function_builder_->EmitWithU8(kExprIf, kLocalI32); current_function_builder_->EmitWithU8(kExprIf, kLocalI32);
......
...@@ -422,8 +422,6 @@ class WasmDecoder : public Decoder { ...@@ -422,8 +422,6 @@ class WasmDecoder : public Decoder {
MemoryIndexOperand operand(decoder, pc); MemoryIndexOperand operand(decoder, pc);
return 1 + operand.length; return 1 + operand.length;
} }
case kExprI8Const:
return 2;
case kExprF32Const: case kExprF32Const:
return 5; return 5;
case kExprF64Const: case kExprF64Const:
...@@ -993,12 +991,6 @@ class WasmFullDecoder : public WasmDecoder { ...@@ -993,12 +991,6 @@ class WasmFullDecoder : public WasmDecoder {
EndControl(); EndControl();
break; break;
} }
case kExprI8Const: {
ImmI8Operand operand(this, pc_);
Push(kWasmI32, BUILD(Int32Constant, operand.value));
len = 1 + operand.length;
break;
}
case kExprI32Const: { case kExprI32Const: {
ImmI32Operand operand(this, pc_); ImmI32Operand operand(this, pc_);
Push(kWasmI32, BUILD(Int32Constant, operand.value)); Push(kWasmI32, BUILD(Int32Constant, operand.value));
......
...@@ -1355,12 +1355,6 @@ class ThreadImpl : public WasmInterpreter::Thread { ...@@ -1355,12 +1355,6 @@ class ThreadImpl : public WasmInterpreter::Thread {
blocks_.pop_back(); blocks_.pop_back();
break; break;
} }
case kExprI8Const: {
ImmI8Operand operand(&decoder, code->at(pc));
Push(pc, WasmVal(operand.value));
len = 1 + operand.length;
break;
}
case kExprI32Const: { case kExprI32Const: {
ImmI32Operand operand(&decoder, code->at(pc)); ImmI32Operand operand(&decoder, code->at(pc));
Push(pc, WasmVal(operand.value)); Push(pc, WasmVal(operand.value));
......
...@@ -140,9 +140,8 @@ ...@@ -140,9 +140,8 @@
// Misc expressions. // Misc expressions.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#define WASM_ID(...) __VA_ARGS__ #define WASM_ID(...) __VA_ARGS__
#define WASM_ZERO kExprI8Const, 0 #define WASM_ZERO kExprI32Const, 0
#define WASM_ONE kExprI8Const, 1 #define WASM_ONE kExprI32Const, 1
#define WASM_I8(val) kExprI8Const, static_cast<byte>(val)
#define I32V_MIN(length) -(1 << (6 + (7 * ((length) - 1)))) #define I32V_MIN(length) -(1 << (6 + (7 * ((length) - 1))))
#define I32V_MAX(length) ((1 << (6 + (7 * ((length) - 1)))) - 1) #define I32V_MAX(length) ((1 << (6 + (7 * ((length) - 1)))) - 1)
...@@ -447,15 +446,15 @@ class LocalDeclEncoder { ...@@ -447,15 +446,15 @@ class LocalDeclEncoder {
#define WASM_WHILE(x, y) \ #define WASM_WHILE(x, y) \
kExprLoop, kLocalVoid, x, kExprIf, kLocalVoid, y, kExprBr, DEPTH_1, \ kExprLoop, kLocalVoid, x, kExprIf, kLocalVoid, y, kExprBr, DEPTH_1, \
kExprEnd, kExprEnd kExprEnd, kExprEnd
#define WASM_INC_LOCAL(index) \ #define WASM_INC_LOCAL(index) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, 1, kExprI32Add, \ kExprGetLocal, static_cast<byte>(index), kExprI32Const, 1, kExprI32Add, \
kExprTeeLocal, static_cast<byte>(index) kExprTeeLocal, static_cast<byte>(index)
#define WASM_INC_LOCAL_BYV(index, count) \ #define WASM_INC_LOCAL_BYV(index, count) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, \ kExprGetLocal, static_cast<byte>(index), kExprI32Const, \
static_cast<byte>(count), kExprI32Add, kExprTeeLocal, \ static_cast<byte>(count), kExprI32Add, kExprTeeLocal, \
static_cast<byte>(index) static_cast<byte>(index)
#define WASM_INC_LOCAL_BY(index, count) \ #define WASM_INC_LOCAL_BY(index, count) \
kExprGetLocal, static_cast<byte>(index), kExprI8Const, \ kExprGetLocal, static_cast<byte>(index), kExprI32Const, \
static_cast<byte>(count), kExprI32Add, kExprSetLocal, \ static_cast<byte>(count), kExprI32Add, kExprSetLocal, \
static_cast<byte>(index) static_cast<byte>(index)
#define WASM_UNOP(opcode, x) x, static_cast<byte>(opcode) #define WASM_UNOP(opcode, x) x, static_cast<byte>(opcode)
......
...@@ -122,10 +122,10 @@ void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode, ...@@ -122,10 +122,10 @@ void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode,
} }
void WasmFunctionBuilder::EmitI32Const(int32_t value) { void WasmFunctionBuilder::EmitI32Const(int32_t value) {
// TODO(titzer): variable-length signed and unsigned i32 constants. if (-64 <= value && value <= 63) {
if (-128 <= value && value <= 127) { EmitWithU8(kExprI32Const, static_cast<byte>(value & 0x7F));
EmitWithU8(kExprI8Const, static_cast<byte>(value));
} else { } else {
// TODO(titzer): variable-length signed and unsigned i32 constants.
byte code[] = {WASM_I32V_5(value)}; byte code[] = {WASM_I32V_5(value)};
EmitCode(code, sizeof(code)); EmitCode(code, sizeof(code));
} }
......
...@@ -78,8 +78,7 @@ const WasmCodePosition kNoCodePosition = -1; ...@@ -78,8 +78,7 @@ const WasmCodePosition kNoCodePosition = -1;
V(I32Const, 0x41, _) \ V(I32Const, 0x41, _) \
V(I64Const, 0x42, _) \ V(I64Const, 0x42, _) \
V(F32Const, 0x43, _) \ V(F32Const, 0x43, _) \
V(F64Const, 0x44, _) \ V(F64Const, 0x44, _)
V(I8Const, 0xcb, _ /* TODO(titzer): V8 specific, remove */)
// Load memory expressions. // Load memory expressions.
#define FOREACH_LOAD_MEM_OPCODE(V) \ #define FOREACH_LOAD_MEM_OPCODE(V) \
......
...@@ -263,7 +263,6 @@ void wasm::PrintWasmText(const WasmModule *module, ...@@ -263,7 +263,6 @@ void wasm::PrintWasmText(const WasmModule *module,
os << #str ".const " << static_cast<cast_type>(operand.value); \ os << #str ".const " << static_cast<cast_type>(operand.value); \
break; \ break; \
} }
CASE_CONST(I8, i8, int32_t)
CASE_CONST(I32, i32, int32_t) CASE_CONST(I32, i32, int32_t)
CASE_CONST(I64, i64, int64_t) CASE_CONST(I64, i64, int64_t)
CASE_CONST(F32, f32, float) CASE_CONST(F32, f32, float)
......
...@@ -1188,15 +1188,15 @@ WASM_EXEC_TEST(LoadStoreI64_sx) { ...@@ -1188,15 +1188,15 @@ WASM_EXEC_TEST(LoadStoreI64_sx) {
byte* memory = r.module().AddMemoryElems<byte>(16); byte* memory = r.module().AddMemoryElems<byte>(16);
byte code[] = { byte code[] = {
kExprI8Const, 8, // -- kExprI32Const, 8, // --
kExprI8Const, 0, // -- kExprI32Const, 0, // --
loads[m], // -- loads[m], // --
ZERO_ALIGNMENT, // -- ZERO_ALIGNMENT, // --
ZERO_OFFSET, // -- ZERO_OFFSET, // --
kExprI64StoreMem, // -- kExprI64StoreMem, // --
ZERO_ALIGNMENT, // -- ZERO_ALIGNMENT, // --
ZERO_OFFSET, // -- ZERO_OFFSET, // --
kExprI8Const, 0, // -- kExprI32Const, 0, // --
loads[m], // -- loads[m], // --
ZERO_ALIGNMENT, // -- ZERO_ALIGNMENT, // --
ZERO_OFFSET, // -- ZERO_OFFSET, // --
...@@ -1316,7 +1316,7 @@ WASM_EXEC_TEST(LoadMemI64) { ...@@ -1316,7 +1316,7 @@ WASM_EXEC_TEST(LoadMemI64) {
int64_t* memory = r.module().AddMemoryElems<int64_t>(8); int64_t* memory = r.module().AddMemoryElems<int64_t>(8);
r.module().RandomizeMemory(1111); r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_I8(0))); BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call()); CHECK_EQ(0x1abbccdd00112233LL, r.Call());
...@@ -1336,7 +1336,7 @@ WASM_EXEC_TEST(LoadMemI64_alignment) { ...@@ -1336,7 +1336,7 @@ WASM_EXEC_TEST(LoadMemI64_alignment) {
r.module().RandomizeMemory(1111); r.module().RandomizeMemory(1111);
BUILD(r, BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_I8(0), alignment)); WASM_LOAD_MEM_ALIGNMENT(MachineType::Int64(), WASM_ZERO, alignment));
r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL); r.module().WriteMemory<int64_t>(&memory[0], 0x1abbccdd00112233LL);
CHECK_EQ(0x1abbccdd00112233LL, r.Call()); CHECK_EQ(0x1abbccdd00112233LL, r.Call());
...@@ -1359,17 +1359,16 @@ WASM_EXEC_TEST(MemI64_Sum) { ...@@ -1359,17 +1359,16 @@ WASM_EXEC_TEST(MemI64_Sum) {
uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems); uint64_t* memory = r.module().AddMemoryElems<uint64_t>(kNumElems);
const byte kSum = r.AllocateLocal(kWasmI64); const byte kSum = r.AllocateLocal(kWasmI64);
BUILD( BUILD(r, WASM_WHILE(
r, WASM_GET_LOCAL(0),
WASM_WHILE( WASM_BLOCK(
WASM_GET_LOCAL(0), WASM_SET_LOCAL(
WASM_BLOCK( kSum, WASM_I64_ADD(WASM_GET_LOCAL(kSum),
WASM_SET_LOCAL(kSum,
WASM_I64_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Int64(), WASM_LOAD_MEM(MachineType::Int64(),
WASM_GET_LOCAL(0)))), WASM_GET_LOCAL(0)))),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(8))))), WASM_SET_LOCAL(
WASM_GET_LOCAL(1)); 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(8))))),
WASM_GET_LOCAL(1));
// Run 4 trials. // Run 4 trials.
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
...@@ -1510,7 +1509,7 @@ static void CompileCallIndirectMany(ValueType param) { ...@@ -1510,7 +1509,7 @@ static void CompileCallIndirectMany(ValueType param) {
for (byte p = 0; p < num_params; p++) { for (byte p = 0; p < num_params; p++) {
ADD_CODE(code, kExprGetLocal, p); ADD_CODE(code, kExprGetLocal, p);
} }
ADD_CODE(code, kExprI8Const, 0); ADD_CODE(code, kExprI32Const, 0);
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size()); t.Build(&code[0], &code[0] + code.size());
...@@ -1562,7 +1561,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -1562,7 +1561,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Load the arguments. // Load the arguments.
for (int i = 0; i < num_params; i++) { for (int i = 0; i < num_params; i++) {
int offset = (i + 1) * kElemSize; int offset = (i + 1) * kElemSize;
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I32V_2(offset)));
} }
// Call the selector function. // Call the selector function.
......
...@@ -30,20 +30,21 @@ TEST(Run_WasmInt8Const_i) { ...@@ -30,20 +30,21 @@ TEST(Run_WasmInt8Const_i) {
WasmRunner<int32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted);
const byte kExpectedValue = 109; const byte kExpectedValue = 109;
// return(kExpectedValue) // return(kExpectedValue)
BUILD(r, WASM_I8(kExpectedValue)); BUILD(r, WASM_I32V_2(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call()); CHECK_EQ(kExpectedValue, r.Call());
} }
TEST(Run_WasmIfElse) { TEST(Run_WasmIfElse) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10))); BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(10)));
CHECK_EQ(10, r.Call(0)); CHECK_EQ(10, r.Call(0));
CHECK_EQ(9, r.Call(1)); CHECK_EQ(9, r.Call(1));
} }
TEST(Run_WasmIfReturn) { TEST(Run_WasmIfReturn) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65)); BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I32V_2(77))),
WASM_I32V_2(65));
CHECK_EQ(65, r.Call(0)); CHECK_EQ(65, r.Call(0));
CHECK_EQ(77, r.Call(1)); CHECK_EQ(77, r.Call(1));
} }
...@@ -54,7 +55,7 @@ TEST(Run_WasmNopsN) { ...@@ -54,7 +55,7 @@ TEST(Run_WasmNopsN) {
for (int nops = 0; nops < kMaxNops; nops++) { for (int nops = 0; nops < kMaxNops; nops++) {
byte expected = static_cast<byte>(20 + nops); byte expected = static_cast<byte>(20 + nops);
memset(code, kExprNop, sizeof(code)); memset(code, kExprNop, sizeof(code));
code[nops] = kExprI8Const; code[nops] = kExprI32Const;
code[nops + 1] = expected; code[nops + 1] = expected;
WasmRunner<int32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted);
...@@ -64,13 +65,13 @@ TEST(Run_WasmNopsN) { ...@@ -64,13 +65,13 @@ TEST(Run_WasmNopsN) {
} }
TEST(Run_WasmConstsN) { TEST(Run_WasmConstsN) {
const int kMaxConsts = 10; const int kMaxConsts = 5;
byte code[kMaxConsts * 3]; byte code[kMaxConsts * 3];
int32_t expected = 0; int32_t expected = 0;
for (int count = 1; count < kMaxConsts; count++) { for (int count = 1; count < kMaxConsts; count++) {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
byte val = static_cast<byte>(count * 10 + i); byte val = static_cast<byte>(count * 10 + i);
code[i * 3] = kExprI8Const; code[i * 3] = kExprI32Const;
code[i * 3 + 1] = val; code[i * 3 + 1] = val;
if (i == (count - 1)) { if (i == (count - 1)) {
code[i * 3 + 2] = kExprNop; code[i * 3 + 2] = kExprNop;
...@@ -95,7 +96,7 @@ TEST(Run_WasmBlocksN) { ...@@ -95,7 +96,7 @@ TEST(Run_WasmBlocksN) {
memset(code, kExprNop, sizeof(code)); memset(code, kExprNop, sizeof(code));
code[0] = kExprBlock; code[0] = kExprBlock;
code[1] = kLocalI32; code[1] = kLocalI32;
code[2 + nops] = kExprI8Const; code[2 + nops] = kExprI32Const;
code[2 + nops + 1] = expected; code[2 + nops + 1] = expected;
code[2 + nops + 2] = kExprEnd; code[2 + nops + 2] = kExprEnd;
...@@ -108,6 +109,7 @@ TEST(Run_WasmBlocksN) { ...@@ -108,6 +109,7 @@ TEST(Run_WasmBlocksN) {
TEST(Run_WasmBlockBreakN) { TEST(Run_WasmBlockBreakN) {
const int kMaxNops = 10; const int kMaxNops = 10;
const int kExtra = 6; const int kExtra = 6;
int run = 0;
byte code[kMaxNops + kExtra]; byte code[kMaxNops + kExtra];
for (int nops = 0; nops < kMaxNops; nops++) { for (int nops = 0; nops < kMaxNops; nops++) {
// Place the break anywhere within the block. // Place the break anywhere within the block.
...@@ -117,8 +119,8 @@ TEST(Run_WasmBlockBreakN) { ...@@ -117,8 +119,8 @@ TEST(Run_WasmBlockBreakN) {
code[1] = kLocalI32; code[1] = kLocalI32;
code[sizeof(code) - 1] = kExprEnd; code[sizeof(code) - 1] = kExprEnd;
int expected = nops * 11 + index; int expected = run++;
code[2 + index + 0] = kExprI8Const; code[2 + index + 0] = kExprI32Const;
code[2 + index + 1] = static_cast<byte>(expected); code[2 + index + 1] = static_cast<byte>(expected);
code[2 + index + 2] = kExprBr; code[2 + index + 2] = kExprBr;
code[2 + index + 3] = 0; code[2 + index + 3] = 0;
...@@ -133,10 +135,12 @@ TEST(Run_WasmBlockBreakN) { ...@@ -133,10 +135,12 @@ TEST(Run_WasmBlockBreakN) {
TEST(Run_Wasm_nested_ifs_i) { TEST(Run_Wasm_nested_ifs_i) {
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted);
BUILD(r, WASM_IF_ELSE_I( BUILD(
WASM_GET_LOCAL(0), r,
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), WASM_IF_ELSE_I(
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); WASM_GET_LOCAL(0),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14))));
CHECK_EQ(11, r.Call(1, 1)); CHECK_EQ(11, r.Call(1, 1));
CHECK_EQ(12, r.Call(1, 0)); CHECK_EQ(12, r.Call(1, 0));
......
...@@ -75,7 +75,7 @@ TEST(Run_WasmModule_Return114) { ...@@ -75,7 +75,7 @@ TEST(Run_WasmModule_Return114) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_I8(kReturnValue)}; byte code[] = {WASM_I32V_2(kReturnValue)};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kReturnValue); TestModule(&zone, builder, kReturnValue);
} }
...@@ -101,7 +101,7 @@ TEST(Run_WasmModule_CallAdd) { ...@@ -101,7 +101,7 @@ TEST(Run_WasmModule_CallAdd) {
ExportAsMain(f2); ExportAsMain(f2);
byte code2[] = { byte code2[] = {
WASM_CALL_FUNCTION(f1->func_index(), WASM_I8(77), WASM_I8(22))}; WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))};
f2->EmitCode(code2, sizeof(code2)); f2->EmitCode(code2, sizeof(code2));
TestModule(&zone, builder, 99); TestModule(&zone, builder, 99);
} }
...@@ -120,7 +120,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) { ...@@ -120,7 +120,7 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) {
ExportAsMain(f); ExportAsMain(f);
byte code[] = { byte code[] = {
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; byte data[] = {0xaa, 0xbb, 0xcc, 0xdd};
builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0);
...@@ -146,8 +146,9 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { ...@@ -146,8 +146,9 @@ TEST(Run_WasmModule_CheckMemoryIsZero) {
WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)),
WASM_IF_ELSE( WASM_IF_ELSE(
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)),
WASM_BRV(3, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), WASM_BRV(3, WASM_I32V_1(-1)),
WASM_I8(11))}; WASM_INC_LOCAL_BY(localIndex, 4))),
WASM_I32V_1(11))};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 11); TestModule(&zone, builder, 11);
} }
...@@ -168,11 +169,11 @@ TEST(Run_WasmModule_CallMain_recursive) { ...@@ -168,11 +169,11 @@ TEST(Run_WasmModule_CallMain_recursive) {
byte code[] = { byte code[] = {
WASM_SET_LOCAL(localIndex, WASM_SET_LOCAL(localIndex,
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)),
WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I8(5)), WASM_IF_ELSE_I(WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_1(5)),
WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_SEQ(WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO,
WASM_INC_LOCAL(localIndex)), WASM_INC_LOCAL(localIndex)),
WASM_CALL_FUNCTION0(0)), WASM_CALL_FUNCTION0(0)),
WASM_I8(55))}; WASM_I32V_1(55))};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, 55); TestModule(&zone, builder, 55);
} }
...@@ -441,7 +442,8 @@ TEST(Run_WasmModule_MemSize_GrowMem) { ...@@ -441,7 +442,8 @@ TEST(Run_WasmModule_MemSize_GrowMem) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(10)), WASM_DROP, WASM_MEMORY_SIZE}; byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP,
WASM_MEMORY_SIZE};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
TestModule(&zone, builder, kExpectedValue); TestModule(&zone, builder, kExpectedValue);
} }
...@@ -589,7 +591,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) { ...@@ -589,7 +591,7 @@ TEST(Run_WasmModule_GrowMemOobOffset) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)), byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)),
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value))}; WASM_I32V(value))};
f->EmitCode(code, sizeof(code)); f->EmitCode(code, sizeof(code));
...@@ -659,7 +661,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) { ...@@ -659,7 +661,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone);
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i());
ExportAsMain(f); ExportAsMain(f);
byte code[] = {WASM_GROW_MEMORY(WASM_I8(1)), WASM_DROP, byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), WASM_DROP,
WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0),
WASM_I32V(value)), WASM_I32V(value)),
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))};
......
...@@ -25,41 +25,7 @@ using namespace v8::internal::wasm; ...@@ -25,41 +25,7 @@ using namespace v8::internal::wasm;
#define B2(a, b) WASM_BLOCK(a, b) #define B2(a, b) WASM_BLOCK(a, b)
#define B3(a, b, c) WASM_BLOCK(a, b, c) #define B3(a, b, c) WASM_BLOCK(a, b, c)
#define RET(x) x, kExprReturn #define RET(x) x, kExprReturn
#define RET_I8(x) kExprI8Const, x, kExprReturn #define RET_I8(x) WASM_I32V_2(x), kExprReturn
WASM_EXEC_TEST(Int8Const) {
WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 121;
// return(kExpectedValue)
BUILD(r, WASM_I8(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
WASM_EXEC_TEST(Int8Const_end) {
WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 121;
// return(kExpectedValue)
BUILD(r, WASM_I8(kExpectedValue), kExprEnd);
CHECK_EQ(kExpectedValue, r.Call());
}
WASM_EXEC_TEST(Int8Const_fallthru2) {
WasmRunner<int32_t> r(execution_mode);
const byte kExpectedValue = 123;
// -99 kExpectedValue
BUILD(r, WASM_I8(-99), WASM_DROP, WASM_I8(kExpectedValue));
CHECK_EQ(kExpectedValue, r.Call());
}
WASM_EXEC_TEST(Int8Const_all) {
for (int value = -128; value <= 127; ++value) {
WasmRunner<int32_t> r(execution_mode);
// return(value)
BUILD(r, WASM_I8(value));
int32_t result = r.Call();
CHECK_EQ(value, result);
}
}
WASM_EXEC_TEST(Int32Const) { WASM_EXEC_TEST(Int32Const) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
...@@ -111,21 +77,21 @@ WASM_EXEC_TEST(Int32Param1) { ...@@ -111,21 +77,21 @@ WASM_EXEC_TEST(Int32Param1) {
WASM_EXEC_TEST(Int32Add) { WASM_EXEC_TEST(Int32Add) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
// 11 + 44 // 11 + 44
BUILD(r, WASM_I32_ADD(WASM_I8(11), WASM_I8(44))); BUILD(r, WASM_I32_ADD(WASM_I32V_1(11), WASM_I32V_1(44)));
CHECK_EQ(55, r.Call()); CHECK_EQ(55, r.Call());
} }
WASM_EXEC_TEST(Int32Add_P) { WASM_EXEC_TEST(Int32Add_P) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 + 13 // p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_ADD(WASM_I32V_1(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
} }
WASM_EXEC_TEST(Int32Add_P_fallthru) { WASM_EXEC_TEST(Int32Add_P_fallthru) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 + 13 // p0 + 13
BUILD(r, WASM_I32_ADD(WASM_I8(13), WASM_GET_LOCAL(0))); BUILD(r, WASM_I32_ADD(WASM_I32V_1(13), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(*i + 13, r.Call(*i)); }
} }
...@@ -427,7 +393,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) { ...@@ -427,7 +393,7 @@ WASM_EXEC_TEST_WITH_TRAP(Int32RemU_trap) {
WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) { WASM_EXEC_TEST_WITH_TRAP(Int32DivS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) { for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
for (int32_t val = -7; val < 8; ++val) { for (int32_t val = -7; val < 8; ++val) {
if (denom == 0) { if (denom == 0) {
CHECK_TRAP(r.Call(val)); CHECK_TRAP(r.Call(val));
...@@ -442,7 +408,7 @@ WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) { ...@@ -442,7 +408,7 @@ WASM_EXEC_TEST(Int32AsmjsDivS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) { for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs(); r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom))); BUILD(r, WASM_I32_ASMJS_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
if (denom == 0) { if (denom == 0) {
CHECK_EQ(0, r.Call(*i)); CHECK_EQ(0, r.Call(*i));
...@@ -459,7 +425,7 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) { ...@@ -459,7 +425,7 @@ WASM_EXEC_TEST(Int32AsmjsRemS_byzero_const) {
for (int8_t denom = -2; denom < 8; ++denom) { for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
r.module().ChangeOriginToAsmjs(); r.module().ChangeOriginToAsmjs();
BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I8(denom))); BUILD(r, WASM_I32_ASMJS_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
if (denom == 0) { if (denom == 0) {
CHECK_EQ(0, r.Call(*i)); CHECK_EQ(0, r.Call(*i));
...@@ -677,8 +643,8 @@ WASM_EXEC_TEST(IfElse_P) { ...@@ -677,8 +643,8 @@ WASM_EXEC_TEST(IfElse_P) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// if (p0) return 11; else return 22; // if (p0) return 11; else return 22;
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // --
WASM_I8(11), // -- WASM_I32V_1(11), // --
WASM_I8(22))); // -- WASM_I32V_1(22))); // --
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 11 : 22; int32_t expected = *i ? 11 : 22;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -717,15 +683,15 @@ WASM_EXEC_TEST(If_chain1) { ...@@ -717,15 +683,15 @@ WASM_EXEC_TEST(If_chain1) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// if (p0) 13; if (p0) 14; 15 // if (p0) 13; if (p0) 14; 15
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP),
WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I8(15)); WASM_IF(WASM_GET_LOCAL(0), WASM_NOP), WASM_I32V_1(15));
FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(15, r.Call(*i)); }
} }
WASM_EXEC_TEST(If_chain_set) { WASM_EXEC_TEST(If_chain_set) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
// if (p0) p1 = 73; if (p0) p1 = 74; p1 // if (p0) p1 = 73; if (p0) p1 = 74; p1
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(73))), BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(73))),
WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I8(74))), WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(1, WASM_I32V_2(74))),
WASM_GET_LOCAL(1)); WASM_GET_LOCAL(1));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 74 : *i; int32_t expected = *i ? 74 : *i;
...@@ -736,17 +702,17 @@ WASM_EXEC_TEST(If_chain_set) { ...@@ -736,17 +702,17 @@ WASM_EXEC_TEST(If_chain_set) {
WASM_EXEC_TEST(IfElse_Unreachable1) { WASM_EXEC_TEST(IfElse_Unreachable1) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
// 0 ? unreachable : 27 // 0 ? unreachable : 27
BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // -- BUILD(r, WASM_IF_ELSE_I(WASM_ZERO, // --
WASM_UNREACHABLE, // -- WASM_UNREACHABLE, // --
WASM_I8(27))); // -- WASM_I32V_1(27))); // --
CHECK_EQ(27, r.Call()); CHECK_EQ(27, r.Call());
} }
WASM_EXEC_TEST(IfElse_Unreachable2) { WASM_EXEC_TEST(IfElse_Unreachable2) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
// 1 ? 28 : unreachable // 1 ? 28 : unreachable
BUILD(r, WASM_IF_ELSE_I(WASM_I8(1), // -- BUILD(r, WASM_IF_ELSE_I(WASM_I32V_1(1), // --
WASM_I8(28), // -- WASM_I32V_1(28), // --
WASM_UNREACHABLE)); // -- WASM_UNREACHABLE)); // --
CHECK_EQ(28, r.Call()); CHECK_EQ(28, r.Call());
} }
...@@ -816,7 +782,7 @@ WASM_EXEC_TEST(Select_float_parameters) { ...@@ -816,7 +782,7 @@ WASM_EXEC_TEST(Select_float_parameters) {
WASM_EXEC_TEST(Select) { WASM_EXEC_TEST(Select) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// return select(11, 22, a); // return select(11, 22, a);
BUILD(r, WASM_SELECT(WASM_I8(11), WASM_I8(22), WASM_GET_LOCAL(0))); BUILD(r, WASM_SELECT(WASM_I32V_1(11), WASM_I32V_1(22), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 11 : 22; int32_t expected = *i ? 11 : 22;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -826,9 +792,9 @@ WASM_EXEC_TEST(Select) { ...@@ -826,9 +792,9 @@ WASM_EXEC_TEST(Select) {
WASM_EXEC_TEST(Select_strict1) { WASM_EXEC_TEST(Select_strict1) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// select(a=0, a=1, a=2); return a // select(a=0, a=1, a=2); return a
BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_I8(0)), BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(0, WASM_ZERO),
WASM_TEE_LOCAL(0, WASM_I8(1)), WASM_TEE_LOCAL(0, WASM_I32V_1(1)),
WASM_TEE_LOCAL(0, WASM_I8(2))), WASM_TEE_LOCAL(0, WASM_I32V_1(2))),
WASM_DROP, WASM_GET_LOCAL(0)); WASM_DROP, WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); }
} }
...@@ -838,8 +804,8 @@ WASM_EXEC_TEST(Select_strict2) { ...@@ -838,8 +804,8 @@ WASM_EXEC_TEST(Select_strict2) {
r.AllocateLocal(kWasmI32); r.AllocateLocal(kWasmI32);
r.AllocateLocal(kWasmI32); r.AllocateLocal(kWasmI32);
// select(b=5, c=6, a) // select(b=5, c=6, a)
BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)),
WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); WASM_TEE_LOCAL(2, WASM_I32V_1(6)), WASM_GET_LOCAL(0)));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 5 : 6; int32_t expected = *i ? 5 : 6;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -851,8 +817,8 @@ WASM_EXEC_TEST(Select_strict3) { ...@@ -851,8 +817,8 @@ WASM_EXEC_TEST(Select_strict3) {
r.AllocateLocal(kWasmI32); r.AllocateLocal(kWasmI32);
r.AllocateLocal(kWasmI32); r.AllocateLocal(kWasmI32);
// select(b=5, c=6, a=b) // select(b=5, c=6, a=b)
BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I8(5)), BUILD(r, WASM_SELECT(WASM_TEE_LOCAL(1, WASM_I32V_1(5)),
WASM_TEE_LOCAL(2, WASM_I8(6)), WASM_TEE_LOCAL(2, WASM_I32V_1(6)),
WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1)))); WASM_TEE_LOCAL(0, WASM_GET_LOCAL(1))));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = 5; int32_t expected = 5;
...@@ -863,18 +829,18 @@ WASM_EXEC_TEST(Select_strict3) { ...@@ -863,18 +829,18 @@ WASM_EXEC_TEST(Select_strict3) {
WASM_EXEC_TEST(BrIf_strict) { WASM_EXEC_TEST(BrIf_strict) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0), BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_GET_LOCAL(0),
WASM_TEE_LOCAL(0, WASM_I8(99))))); WASM_TEE_LOCAL(0, WASM_I32V_2(99)))));
FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(*i, r.Call(*i)); }
} }
WASM_EXEC_TEST(Br_height) { WASM_EXEC_TEST(Br_height) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, BUILD(r, WASM_BLOCK_I(WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0),
WASM_BLOCK_I( WASM_GET_LOCAL(0)),
WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)), WASM_RETURN1(WASM_I32V_1(9)),
WASM_RETURN1(WASM_I8(9)), WASM_I8(7), WASM_I8(7)), WASM_I32V_1(7), WASM_I32V_1(7)),
WASM_BRV(0, WASM_I8(8)))); WASM_BRV(0, WASM_I32V_1(8))));
for (int32_t i = 0; i < 5; i++) { for (int32_t i = 0; i < 5; i++) {
int32_t expected = i != 0 ? 8 : 9; int32_t expected = i != 0 ? 8 : 9;
...@@ -885,15 +851,15 @@ WASM_EXEC_TEST(Br_height) { ...@@ -885,15 +851,15 @@ WASM_EXEC_TEST(Br_height) {
WASM_EXEC_TEST(Regression_660262) { WASM_EXEC_TEST(Regression_660262) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8); r.module().AddMemoryElems<int32_t>(8);
BUILD(r, kExprI8Const, 0x00, kExprI8Const, 0x00, kExprI32LoadMem, 0x00, 0x0f, BUILD(r, kExprI32Const, 0x00, kExprI32Const, 0x00, kExprI32LoadMem, 0x00,
kExprBrTable, 0x00, 0x80, 0x00); // entries=0 0x0f, kExprBrTable, 0x00, 0x80, 0x00); // entries=0
r.Call(); r.Call();
} }
WASM_EXEC_TEST(BrTable0a) { WASM_EXEC_TEST(BrTable0a) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))), BUILD(r, B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))),
WASM_I8(91)); WASM_I32V_2(91));
FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(91, r.Call(*i)); }
} }
...@@ -901,7 +867,7 @@ WASM_EXEC_TEST(BrTable0b) { ...@@ -901,7 +867,7 @@ WASM_EXEC_TEST(BrTable0b) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, BUILD(r,
B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))), B1(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(0)))),
WASM_I8(92)); WASM_I32V_2(92));
FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); } FOR_INT32_INPUTS(i) { CHECK_EQ(92, r.Call(*i)); }
} }
...@@ -911,7 +877,7 @@ WASM_EXEC_TEST(BrTable0c) { ...@@ -911,7 +877,7 @@ WASM_EXEC_TEST(BrTable0c) {
r, r,
B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))), B1(B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(0), BR_TARGET(1))),
RET_I8(76))), RET_I8(76))),
WASM_I8(77)); WASM_I32V_2(77));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i == 0 ? 76 : 77; int32_t expected = *i == 0 ? 76 : 77;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -930,7 +896,7 @@ WASM_EXEC_TEST(BrTable_loop) { ...@@ -930,7 +896,7 @@ WASM_EXEC_TEST(BrTable_loop) {
B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2), B2(B1(WASM_LOOP(WASM_BR_TABLE(WASM_INC_LOCAL_BYV(0, 1), 2, BR_TARGET(2),
BR_TARGET(1), BR_TARGET(0)))), BR_TARGET(1), BR_TARGET(0)))),
RET_I8(99)), RET_I8(99)),
WASM_I8(98)); WASM_I32V_2(98));
CHECK_EQ(99, r.Call(0)); CHECK_EQ(99, r.Call(0));
CHECK_EQ(98, r.Call(-1)); CHECK_EQ(98, r.Call(-1));
CHECK_EQ(98, r.Call(-2)); CHECK_EQ(98, r.Call(-2));
...@@ -943,7 +909,7 @@ WASM_EXEC_TEST(BrTable_br) { ...@@ -943,7 +909,7 @@ WASM_EXEC_TEST(BrTable_br) {
BUILD(r, BUILD(r,
B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))), B2(B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 1, BR_TARGET(1), BR_TARGET(0))),
RET_I8(91)), RET_I8(91)),
WASM_I8(99)); WASM_I32V_2(99));
CHECK_EQ(99, r.Call(0)); CHECK_EQ(99, r.Call(0));
CHECK_EQ(91, r.Call(1)); CHECK_EQ(91, r.Call(1));
CHECK_EQ(91, r.Call(2)); CHECK_EQ(91, r.Call(2));
...@@ -958,7 +924,7 @@ WASM_EXEC_TEST(BrTable_br2) { ...@@ -958,7 +924,7 @@ WASM_EXEC_TEST(BrTable_br2) {
RET_I8(85)), RET_I8(85)),
RET_I8(86)), RET_I8(86)),
RET_I8(87)), RET_I8(87)),
WASM_I8(88)); WASM_I32V_2(88));
CHECK_EQ(86, r.Call(0)); CHECK_EQ(86, r.Call(0));
CHECK_EQ(87, r.Call(1)); CHECK_EQ(87, r.Call(1));
CHECK_EQ(88, r.Call(2)); CHECK_EQ(88, r.Call(2));
...@@ -980,7 +946,7 @@ WASM_EXEC_TEST(BrTable4) { ...@@ -980,7 +946,7 @@ WASM_EXEC_TEST(BrTable4) {
RET_I8(71)), RET_I8(71)),
RET_I8(72)), RET_I8(72)),
RET_I8(73)), RET_I8(73)),
WASM_I8(75)}; WASM_I32V_2(75)};
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
r.Build(code, code + arraysize(code)); r.Build(code, code + arraysize(code));
...@@ -1010,7 +976,7 @@ WASM_EXEC_TEST(BrTable4x4) { ...@@ -1010,7 +976,7 @@ WASM_EXEC_TEST(BrTable4x4) {
RET_I8(51)), RET_I8(51)),
RET_I8(52)), RET_I8(52)),
RET_I8(53)), RET_I8(53)),
WASM_I8(55)}; WASM_I32V_2(55)};
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
r.Build(code, code + arraysize(code)); r.Build(code, code + arraysize(code));
...@@ -1073,7 +1039,7 @@ WASM_EXEC_TEST(I32ReinterpretF32) { ...@@ -1073,7 +1039,7 @@ WASM_EXEC_TEST(I32ReinterpretF32) {
BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, BUILD(r, WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO,
WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))), WASM_F32_REINTERPRET_I32(WASM_GET_LOCAL(0))),
WASM_I8(107)); WASM_I32V_2(107));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i; int32_t expected = *i;
...@@ -1086,7 +1052,7 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { ...@@ -1086,7 +1052,7 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) {
WasmRunner<int32_t> r(execution_mode); WasmRunner<int32_t> r(execution_mode);
r.module().AddMemoryElems<int32_t>(8); r.module().AddMemoryElems<int32_t>(8);
BUILD(r, kExprI8Const, 0, // index BUILD(r, kExprI32Const, 0, // index
static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf( static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(
MachineType::Int32(), false)), // -- MachineType::Int32(), false)), // --
0, // alignment 0, // alignment
...@@ -1207,10 +1173,10 @@ WASM_EXEC_TEST(Block_br2) { ...@@ -1207,10 +1173,10 @@ WASM_EXEC_TEST(Block_br2) {
WASM_EXEC_TEST(Block_If_P) { WASM_EXEC_TEST(Block_If_P) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// block { if (p0) break 51; 52; } // block { if (p0) break 51; 52; }
BUILD(r, WASM_BLOCK_I( // -- BUILD(r, WASM_BLOCK_I( // --
WASM_IF(WASM_GET_LOCAL(0), // -- WASM_IF(WASM_GET_LOCAL(0), // --
WASM_BRV(1, WASM_I8(51))), // -- WASM_BRV(1, WASM_I32V_1(51))), // --
WASM_I8(52))); // -- WASM_I32V_1(52))); // --
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 51 : 52; int32_t expected = *i ? 51 : 52;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -1273,8 +1239,8 @@ WASM_EXEC_TEST(Loop_empty_brif3) { ...@@ -1273,8 +1239,8 @@ WASM_EXEC_TEST(Loop_empty_brif3) {
WASM_EXEC_TEST(Block_BrIf_P) { WASM_EXEC_TEST(Block_BrIf_P) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(51), WASM_GET_LOCAL(0)), BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(51), WASM_GET_LOCAL(0)),
WASM_I8(52))); WASM_I32V_1(52)));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 51 : 52; int32_t expected = *i ? 51 : 52;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -1284,10 +1250,10 @@ WASM_EXEC_TEST(Block_BrIf_P) { ...@@ -1284,10 +1250,10 @@ WASM_EXEC_TEST(Block_BrIf_P) {
WASM_EXEC_TEST(Block_IfElse_P_assign) { WASM_EXEC_TEST(Block_IfElse_P_assign) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// { if (p0) p0 = 71; else p0 = 72; return p0; } // { if (p0) p0 = 71; else p0 = 72; return p0; }
BUILD(r, // -- BUILD(r, // --
WASM_IF_ELSE(WASM_GET_LOCAL(0), // -- WASM_IF_ELSE(WASM_GET_LOCAL(0), // --
WASM_SET_LOCAL(0, WASM_I8(71)), // -- WASM_SET_LOCAL(0, WASM_I32V_2(71)), // --
WASM_SET_LOCAL(0, WASM_I8(72))), // -- WASM_SET_LOCAL(0, WASM_I32V_2(72))), // --
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 71 : 72; int32_t expected = *i ? 71 : 72;
...@@ -1311,7 +1277,7 @@ WASM_EXEC_TEST(Block_IfElse_P_return) { ...@@ -1311,7 +1277,7 @@ WASM_EXEC_TEST(Block_IfElse_P_return) {
WASM_EXEC_TEST(Block_If_P_assign) { WASM_EXEC_TEST(Block_If_P_assign) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// { if (p0) p0 = 61; p0; } // { if (p0) p0 = 61; p0; }
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I8(61))), BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I32V_1(61))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 61 : *i; int32_t expected = *i ? 61 : *i;
...@@ -1330,8 +1296,8 @@ WASM_EXEC_TEST(ExprIf_P) { ...@@ -1330,8 +1296,8 @@ WASM_EXEC_TEST(ExprIf_P) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
// p0 ? 11 : 22; // p0 ? 11 : 22;
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // -- BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), // --
WASM_I8(11), // -- WASM_I32V_1(11), // --
WASM_I8(22))); // -- WASM_I32V_1(22))); // --
FOR_INT32_INPUTS(i) { FOR_INT32_INPUTS(i) {
int32_t expected = *i ? 11 : 22; int32_t expected = *i ? 11 : 22;
CHECK_EQ(expected, r.Call(*i)); CHECK_EQ(expected, r.Call(*i));
...@@ -1340,10 +1306,10 @@ WASM_EXEC_TEST(ExprIf_P) { ...@@ -1340,10 +1306,10 @@ WASM_EXEC_TEST(ExprIf_P) {
WASM_EXEC_TEST(CountDown) { WASM_EXEC_TEST(CountDown) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_IFB( BUILD(r, WASM_LOOP(WASM_IFB(WASM_GET_LOCAL(0),
WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), WASM_I32V_1(1))),
WASM_BR(1))), WASM_BR(1))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(1));
CHECK_EQ(0, r.Call(10)); CHECK_EQ(0, r.Call(10));
...@@ -1352,12 +1318,13 @@ WASM_EXEC_TEST(CountDown) { ...@@ -1352,12 +1318,13 @@ WASM_EXEC_TEST(CountDown) {
WASM_EXEC_TEST(CountDown_fallthru) { WASM_EXEC_TEST(CountDown_fallthru) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP( BUILD(
WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), r,
WASM_BRV(2, WASM_GET_LOCAL(0))), WASM_LOOP(
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1))), WASM_IF(WASM_NOT(WASM_GET_LOCAL(0)), WASM_BRV(2, WASM_GET_LOCAL(0))),
WASM_CONTINUE(0)), WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(1))),
WASM_GET_LOCAL(0)); WASM_CONTINUE(0)),
WASM_GET_LOCAL(0));
CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(1));
CHECK_EQ(0, r.Call(10)); CHECK_EQ(0, r.Call(10));
CHECK_EQ(0, r.Call(100)); CHECK_EQ(0, r.Call(100));
...@@ -1365,9 +1332,9 @@ WASM_EXEC_TEST(CountDown_fallthru) { ...@@ -1365,9 +1332,9 @@ WASM_EXEC_TEST(CountDown_fallthru) {
WASM_EXEC_TEST(WhileCountDown) { WASM_EXEC_TEST(WhileCountDown) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_WHILE( BUILD(r, WASM_WHILE(WASM_GET_LOCAL(0),
WASM_GET_LOCAL(0), WASM_SET_LOCAL(
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))), 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(1)))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(0, r.Call(1)); CHECK_EQ(0, r.Call(1));
CHECK_EQ(0, r.Call(10)); CHECK_EQ(0, r.Call(10));
...@@ -1377,7 +1344,7 @@ WASM_EXEC_TEST(WhileCountDown) { ...@@ -1377,7 +1344,7 @@ WASM_EXEC_TEST(WhileCountDown) {
WASM_EXEC_TEST(Loop_if_break1) { WASM_EXEC_TEST(Loop_if_break1) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))), BUILD(r, WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(2, WASM_GET_LOCAL(1))),
WASM_SET_LOCAL(0, WASM_I8(99))), WASM_SET_LOCAL(0, WASM_I32V_2(99))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(99, r.Call(0, 11)); CHECK_EQ(99, r.Call(0, 11));
CHECK_EQ(65, r.Call(3, 65)); CHECK_EQ(65, r.Call(3, 65));
...@@ -1388,7 +1355,7 @@ WASM_EXEC_TEST(Loop_if_break1) { ...@@ -1388,7 +1355,7 @@ WASM_EXEC_TEST(Loop_if_break1) {
WASM_EXEC_TEST(Loop_if_break2) { WASM_EXEC_TEST(Loop_if_break2) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)), BUILD(r, WASM_LOOP(WASM_BRV_IF(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(0)),
WASM_DROP, WASM_SET_LOCAL(0, WASM_I8(99))), WASM_DROP, WASM_SET_LOCAL(0, WASM_I32V_2(99))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(99, r.Call(0, 33)); CHECK_EQ(99, r.Call(0, 33));
CHECK_EQ(3, r.Call(1, 3)); CHECK_EQ(3, r.Call(1, 3));
...@@ -1399,7 +1366,7 @@ WASM_EXEC_TEST(Loop_if_break2) { ...@@ -1399,7 +1366,7 @@ WASM_EXEC_TEST(Loop_if_break2) {
WASM_EXEC_TEST(Loop_if_break_fallthru) { WASM_EXEC_TEST(Loop_if_break_fallthru) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), BUILD(r, B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)),
WASM_SET_LOCAL(0, WASM_I8(93)))), WASM_SET_LOCAL(0, WASM_I32V_2(93)))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(93, r.Call(0)); CHECK_EQ(93, r.Call(0));
CHECK_EQ(3, r.Call(3)); CHECK_EQ(3, r.Call(3));
...@@ -1410,7 +1377,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru) { ...@@ -1410,7 +1377,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru) {
WASM_EXEC_TEST(Loop_if_break_fallthru2) { WASM_EXEC_TEST(Loop_if_break_fallthru2) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)), BUILD(r, B1(B1(WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)),
WASM_SET_LOCAL(0, WASM_I8(93))))), WASM_SET_LOCAL(0, WASM_I32V_2(93))))),
WASM_GET_LOCAL(0)); WASM_GET_LOCAL(0));
CHECK_EQ(93, r.Call(0)); CHECK_EQ(93, r.Call(0));
CHECK_EQ(3, r.Call(3)); CHECK_EQ(3, r.Call(3));
...@@ -1421,7 +1388,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru2) { ...@@ -1421,7 +1388,7 @@ WASM_EXEC_TEST(Loop_if_break_fallthru2) {
WASM_EXEC_TEST(IfBreak1) { WASM_EXEC_TEST(IfBreak1) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)), BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), WASM_UNREACHABLE)),
WASM_I8(91)); WASM_I32V_2(91));
CHECK_EQ(91, r.Call(0)); CHECK_EQ(91, r.Call(0));
CHECK_EQ(91, r.Call(1)); CHECK_EQ(91, r.Call(1));
CHECK_EQ(91, r.Call(-8734)); CHECK_EQ(91, r.Call(-8734));
...@@ -1430,7 +1397,7 @@ WASM_EXEC_TEST(IfBreak1) { ...@@ -1430,7 +1397,7 @@ WASM_EXEC_TEST(IfBreak1) {
WASM_EXEC_TEST(IfBreak2) { WASM_EXEC_TEST(IfBreak2) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))), BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_SEQ(WASM_BR(0), RET_I8(77))),
WASM_I8(81)); WASM_I32V_2(81));
CHECK_EQ(81, r.Call(0)); CHECK_EQ(81, r.Call(0));
CHECK_EQ(81, r.Call(1)); CHECK_EQ(81, r.Call(1));
CHECK_EQ(81, r.Call(-8734)); CHECK_EQ(81, r.Call(-8734));
...@@ -1441,7 +1408,7 @@ WASM_EXEC_TEST(LoadMemI32) { ...@@ -1441,7 +1408,7 @@ WASM_EXEC_TEST(LoadMemI32) {
int32_t* memory = r.module().AddMemoryElems<int32_t>(8); int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
r.module().RandomizeMemory(1111); r.module().RandomizeMemory(1111);
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(0))); BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO));
r.module().WriteMemory(&memory[0], 99999999); r.module().WriteMemory(&memory[0], 99999999);
CHECK_EQ(99999999, r.Call(0)); CHECK_EQ(99999999, r.Call(0));
...@@ -1460,7 +1427,7 @@ WASM_EXEC_TEST(LoadMemI32_alignment) { ...@@ -1460,7 +1427,7 @@ WASM_EXEC_TEST(LoadMemI32_alignment) {
r.module().RandomizeMemory(1111); r.module().RandomizeMemory(1111);
BUILD(r, BUILD(r,
WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_I8(0), alignment)); WASM_LOAD_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, alignment));
r.module().WriteMemory(&memory[0], 0x1a2b3c4d); r.module().WriteMemory(&memory[0], 0x1a2b3c4d);
CHECK_EQ(0x1a2b3c4d, r.Call(0)); CHECK_EQ(0x1a2b3c4d, r.Call(0));
...@@ -1549,8 +1516,8 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { ...@@ -1549,8 +1516,8 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) {
r.module().AddMemoryElems<byte>(kMemSize); r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory(); r.module().RandomizeMemory();
BUILD(r, BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset,
WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); WASM_I32V_2(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) {
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
...@@ -1569,8 +1536,8 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) { ...@@ -1569,8 +1536,8 @@ WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) {
r.module().AddMemoryElems<byte>(kMemSize); r.module().AddMemoryElems<byte>(kMemSize);
r.module().RandomizeMemory(); r.module().RandomizeMemory();
BUILD(r, BUILD(r, WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset,
WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); WASM_I32V_2(index)));
if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) {
CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
...@@ -1668,17 +1635,16 @@ WASM_EXEC_TEST(MemI32_Sum) { ...@@ -1668,17 +1635,16 @@ WASM_EXEC_TEST(MemI32_Sum) {
uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems); uint32_t* memory = r.module().AddMemoryElems<uint32_t>(kNumElems);
const byte kSum = r.AllocateLocal(kWasmI32); const byte kSum = r.AllocateLocal(kWasmI32);
BUILD( BUILD(r, WASM_WHILE(
r, WASM_GET_LOCAL(0),
WASM_WHILE( WASM_BLOCK(
WASM_GET_LOCAL(0), WASM_SET_LOCAL(
WASM_BLOCK( kSum, WASM_I32_ADD(WASM_GET_LOCAL(kSum),
WASM_SET_LOCAL(kSum,
WASM_I32_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Int32(), WASM_LOAD_MEM(MachineType::Int32(),
WASM_GET_LOCAL(0)))), WASM_GET_LOCAL(0)))),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), WASM_SET_LOCAL(
WASM_GET_LOCAL(1)); 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))),
WASM_GET_LOCAL(1));
// Run 4 trials. // Run 4 trials.
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
...@@ -1704,17 +1670,17 @@ WASM_EXEC_TEST(CheckMachIntsZero) { ...@@ -1704,17 +1670,17 @@ WASM_EXEC_TEST(CheckMachIntsZero) {
/* */ kExprGetLocal, 0, // -- /* */ kExprGetLocal, 0, // --
/* */ kExprI32LoadMem, 0, 0, // -- /* */ kExprI32LoadMem, 0, 0, // --
/* */ kExprIf, kLocalVoid, // -- /* */ kExprIf, kLocalVoid, // --
/* */ kExprI8Const, 255, // -- /* */ kExprI32Const, 127, // --
/* */ kExprReturn, // -- /* */ kExprReturn, // --
/* */ kExprEnd, // -- /* */ kExprEnd, // --
/* */ kExprGetLocal, 0, // -- /* */ kExprGetLocal, 0, // --
/* */ kExprI8Const, 4, // -- /* */ kExprI32Const, 4, // --
/* */ kExprI32Sub, // -- /* */ kExprI32Sub, // --
/* */ kExprTeeLocal, 0, // -- /* */ kExprTeeLocal, 0, // --
/* */ kExprBr, DEPTH_0, // -- /* */ kExprBr, DEPTH_0, // --
/* */ kExprEnd, // -- /* */ kExprEnd, // --
/**/ kExprEnd, // -- /**/ kExprEnd, // --
/**/ kExprI8Const, 0); // -- /**/ kExprI32Const, 0); // --
r.module().BlankMemory(); r.module().BlankMemory();
CHECK_EQ(0, r.Call((kNumElems - 1) * 4)); CHECK_EQ(0, r.Call((kNumElems - 1) * 4));
...@@ -1732,18 +1698,17 @@ WASM_EXEC_TEST(MemF32_Sum) { ...@@ -1732,18 +1698,17 @@ WASM_EXEC_TEST(MemF32_Sum) {
r.module().WriteMemory(&buffer[4], 5555.25f); r.module().WriteMemory(&buffer[4], 5555.25f);
const byte kSum = r.AllocateLocal(kWasmF32); const byte kSum = r.AllocateLocal(kWasmF32);
BUILD( BUILD(r, WASM_WHILE(
r, WASM_GET_LOCAL(0),
WASM_WHILE( WASM_BLOCK(
WASM_GET_LOCAL(0), WASM_SET_LOCAL(
WASM_BLOCK( kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum),
WASM_SET_LOCAL(kSum,
WASM_F32_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Float32(), WASM_LOAD_MEM(MachineType::Float32(),
WASM_GET_LOCAL(0)))), WASM_GET_LOCAL(0)))),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(4))))), WASM_SET_LOCAL(
WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), 0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(4))))),
WASM_GET_LOCAL(0)); WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)),
WASM_GET_LOCAL(0));
CHECK_EQ(0, r.Call(4 * (kSize - 1))); CHECK_EQ(0, r.Call(4 * (kSize - 1)));
CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0])); CHECK_NE(-99.25f, r.module().ReadMemory(&buffer[0]));
...@@ -1761,17 +1726,18 @@ T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop, ...@@ -1761,17 +1726,18 @@ T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
} }
const byte kAccum = r.AllocateLocal(astType); const byte kAccum = r.AllocateLocal(astType);
BUILD(r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)), BUILD(
WASM_WHILE( r, WASM_SET_LOCAL(kAccum, WASM_LOAD_MEM(memType, WASM_ZERO)),
WASM_GET_LOCAL(0), WASM_WHILE(
WASM_BLOCK(WASM_SET_LOCAL( WASM_GET_LOCAL(0),
kAccum, WASM_BINOP(binop, WASM_GET_LOCAL(kAccum), WASM_BLOCK(WASM_SET_LOCAL(
WASM_LOAD_MEM( kAccum,
memType, WASM_GET_LOCAL(0)))), WASM_BINOP(binop, WASM_GET_LOCAL(kAccum),
WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_LOAD_MEM(memType, WASM_GET_LOCAL(0)))),
WASM_I8(sizeof(T)))))), WASM_SET_LOCAL(0, WASM_I32_SUB(WASM_GET_LOCAL(0),
WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)), WASM_I32V_1(sizeof(T)))))),
WASM_GET_LOCAL(0)); WASM_STORE_MEM(memType, WASM_ZERO, WASM_GET_LOCAL(kAccum)),
WASM_GET_LOCAL(0));
r.Call(static_cast<int>(sizeof(T) * (size - 1))); r.Call(static_cast<int>(sizeof(T) * (size - 1)));
return r.module().ReadMemory(&memory[0]); return r.module().ReadMemory(&memory[0]);
} }
...@@ -1802,14 +1768,14 @@ WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) { ...@@ -1802,14 +1768,14 @@ WASM_EXEC_TEST(Build_Wasm_Infinite_Loop_effect) {
WASM_EXEC_TEST(Unreachable0a) { WASM_EXEC_TEST(Unreachable0a) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(9)), RET(WASM_GET_LOCAL(0)))); BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(9)), RET(WASM_GET_LOCAL(0))));
CHECK_EQ(9, r.Call(0)); CHECK_EQ(9, r.Call(0));
CHECK_EQ(9, r.Call(1)); CHECK_EQ(9, r.Call(1));
} }
WASM_EXEC_TEST(Unreachable0b) { WASM_EXEC_TEST(Unreachable0b) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I8(7)), WASM_UNREACHABLE)); BUILD(r, WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(7)), WASM_UNREACHABLE));
CHECK_EQ(7, r.Call(0)); CHECK_EQ(7, r.Call(0));
CHECK_EQ(7, r.Call(1)); CHECK_EQ(7, r.Call(1));
} }
...@@ -1850,23 +1816,23 @@ WASM_EXEC_TEST(Unreachable_Load) { ...@@ -1850,23 +1816,23 @@ WASM_EXEC_TEST(Unreachable_Load) {
WASM_EXEC_TEST(Infinite_Loop_not_taken1) { WASM_EXEC_TEST(Infinite_Loop_not_taken1) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I8(45)); BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_INFINITE_LOOP), WASM_I32V_1(45));
// Run the code, but don't go into the infinite loop. // Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(0)); CHECK_EQ(45, r.Call(0));
} }
WASM_EXEC_TEST(Infinite_Loop_not_taken2) { WASM_EXEC_TEST(Infinite_Loop_not_taken2) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0),
WASM_BLOCK_I(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(45)), WASM_BRV(1, WASM_I32V_1(45)),
WASM_INFINITE_LOOP))); WASM_INFINITE_LOOP)));
// Run the code, but don't go into the infinite loop. // Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(1)); CHECK_EQ(45, r.Call(1));
} }
WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) { WASM_EXEC_TEST(Infinite_Loop_not_taken2_brif) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I8(45), WASM_GET_LOCAL(0)), BUILD(r, WASM_BLOCK_I(WASM_BRV_IF(0, WASM_I32V_1(45), WASM_GET_LOCAL(0)),
WASM_INFINITE_LOOP)); WASM_INFINITE_LOOP));
// Run the code, but don't go into the infinite loop. // Run the code, but don't go into the infinite loop.
CHECK_EQ(45, r.Call(1)); CHECK_EQ(45, r.Call(1));
...@@ -2147,12 +2113,12 @@ WASM_EXEC_TEST(CallVoid) { ...@@ -2147,12 +2113,12 @@ WASM_EXEC_TEST(CallVoid) {
int32_t* memory = r.module().AddMemoryElems<int32_t>(16 / sizeof(int32_t)); int32_t* memory = r.module().AddMemoryElems<int32_t>(16 / sizeof(int32_t));
r.module().RandomizeMemory(); r.module().RandomizeMemory();
WasmFunctionCompiler& t = r.NewFunction(sigs.v_v()); WasmFunctionCompiler& t = r.NewFunction(sigs.v_v());
BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(kMemOffset), BUILD(t, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(kMemOffset),
WASM_I32V_3(kExpected))); WASM_I32V_3(kExpected)));
// Build the calling function. // Build the calling function.
BUILD(r, WASM_CALL_FUNCTION0(t.function_index()), BUILD(r, WASM_CALL_FUNCTION0(t.function_index()),
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kMemOffset))); WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kMemOffset)));
int32_t result = r.Call(); int32_t result = r.Call();
CHECK_EQ(kExpected, result); CHECK_EQ(kExpected, result);
...@@ -2202,9 +2168,10 @@ WASM_EXEC_TEST(Call_Float64Sub) { ...@@ -2202,9 +2168,10 @@ WASM_EXEC_TEST(Call_Float64Sub) {
BUILD(r, WASM_STORE_MEM( BUILD(r, WASM_STORE_MEM(
MachineType::Float64(), WASM_ZERO, MachineType::Float64(), WASM_ZERO,
WASM_F64_SUB(WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO), WASM_F64_SUB(
WASM_LOAD_MEM(MachineType::Float64(), WASM_I8(8)))), WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO),
WASM_I8(107)); WASM_LOAD_MEM(MachineType::Float64(), WASM_I32V_1(8)))),
WASM_I32V_2(107));
FOR_FLOAT64_INPUTS(i) { FOR_FLOAT64_INPUTS(i) {
FOR_FLOAT64_INPUTS(j) { FOR_FLOAT64_INPUTS(j) {
...@@ -2272,7 +2239,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) { ...@@ -2272,7 +2239,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
// Load the arguments. // Load the arguments.
for (int i = 0; i < num_params; ++i) { for (int i = 0; i < num_params; ++i) {
int offset = (i + 1) * kElemSize; int offset = (i + 1) * kElemSize;
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset))); ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I32V_2(offset)));
} }
// Call the selector function. // Call the selector function.
...@@ -2315,7 +2282,7 @@ WASM_EXEC_TEST(AddCall) { ...@@ -2315,7 +2282,7 @@ WASM_EXEC_TEST(AddCall) {
BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
byte local = r.AllocateLocal(kWasmI32); byte local = r.AllocateLocal(kWasmI32);
BUILD(r, WASM_SET_LOCAL(local, WASM_I8(99)), BUILD(r, WASM_SET_LOCAL(local, WASM_I32V_2(99)),
WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0), WASM_I32_ADD(WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(0),
WASM_GET_LOCAL(0)), WASM_GET_LOCAL(0)),
WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1), WASM_CALL_FUNCTION(t1.function_index(), WASM_GET_LOCAL(1),
...@@ -2409,49 +2376,49 @@ WASM_EXEC_TEST(MultiReturnSelect_f64) { ...@@ -2409,49 +2376,49 @@ WASM_EXEC_TEST(MultiReturnSelect_f64) {
WASM_EXEC_TEST(ExprBlock2a) { WASM_EXEC_TEST(ExprBlock2a) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))),
WASM_I8(1))); WASM_I32V_1(1)));
CHECK_EQ(1, r.Call(0)); CHECK_EQ(1, r.Call(0));
CHECK_EQ(1, r.Call(1)); CHECK_EQ(1, r.Call(1));
} }
WASM_EXEC_TEST(ExprBlock2b) { WASM_EXEC_TEST(ExprBlock2b) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I8(1))), BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(1, WASM_I32V_1(1))),
WASM_I8(2))); WASM_I32V_1(2)));
CHECK_EQ(2, r.Call(0)); CHECK_EQ(2, r.Call(0));
CHECK_EQ(1, r.Call(1)); CHECK_EQ(1, r.Call(1));
} }
WASM_EXEC_TEST(ExprBlock2c) { WASM_EXEC_TEST(ExprBlock2c) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)),
WASM_I8(1))); WASM_I32V_1(1)));
CHECK_EQ(1, r.Call(0)); CHECK_EQ(1, r.Call(0));
CHECK_EQ(1, r.Call(1)); CHECK_EQ(1, r.Call(1));
} }
WASM_EXEC_TEST(ExprBlock2d) { WASM_EXEC_TEST(ExprBlock2d) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(1), WASM_GET_LOCAL(0)), BUILD(r, WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I32V_1(1), WASM_GET_LOCAL(0)),
WASM_I8(2))); WASM_I32V_1(2)));
CHECK_EQ(2, r.Call(0)); CHECK_EQ(2, r.Call(0));
CHECK_EQ(1, r.Call(1)); CHECK_EQ(1, r.Call(1));
} }
WASM_EXEC_TEST(ExprBlock_ManualSwitch) { WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1)), BUILD(r, WASM_BLOCK_I(WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1)),
WASM_BRV(1, WASM_I8(11))), WASM_BRV(1, WASM_I32V_1(11))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2)), WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2)),
WASM_BRV(1, WASM_I8(12))), WASM_BRV(1, WASM_I32V_1(12))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3)), WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3)),
WASM_BRV(1, WASM_I8(13))), WASM_BRV(1, WASM_I32V_1(13))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4)), WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4)),
WASM_BRV(1, WASM_I8(14))), WASM_BRV(1, WASM_I32V_1(14))),
WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5)), WASM_IF(WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5)),
WASM_BRV(1, WASM_I8(15))), WASM_BRV(1, WASM_I32V_1(15))),
WASM_I8(99))); WASM_I32V_2(99)));
CHECK_EQ(99, r.Call(0)); CHECK_EQ(99, r.Call(0));
CHECK_EQ(11, r.Call(1)); CHECK_EQ(11, r.Call(1));
CHECK_EQ(12, r.Call(2)); CHECK_EQ(12, r.Call(2));
...@@ -2463,18 +2430,18 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch) { ...@@ -2463,18 +2430,18 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch) {
WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, BUILD(r, WASM_BLOCK_I(
WASM_BLOCK_I(WASM_BRV_IFD(0, WASM_I8(11), WASM_BRV_IFD(0, WASM_I32V_1(11),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(1))), WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(1))),
WASM_BRV_IFD(0, WASM_I8(12), WASM_BRV_IFD(0, WASM_I32V_1(12),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(2))), WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(2))),
WASM_BRV_IFD(0, WASM_I8(13), WASM_BRV_IFD(0, WASM_I32V_1(13),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(3))), WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(3))),
WASM_BRV_IFD(0, WASM_I8(14), WASM_BRV_IFD(0, WASM_I32V_1(14),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(4))), WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(4))),
WASM_BRV_IFD(0, WASM_I8(15), WASM_BRV_IFD(0, WASM_I32V_1(15),
WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(5))), WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(5))),
WASM_I8(99))); WASM_I32V_2(99)));
CHECK_EQ(99, r.Call(0)); CHECK_EQ(99, r.Call(0));
CHECK_EQ(11, r.Call(1)); CHECK_EQ(11, r.Call(1));
CHECK_EQ(12, r.Call(2)); CHECK_EQ(12, r.Call(2));
...@@ -2487,10 +2454,12 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) { ...@@ -2487,10 +2454,12 @@ WASM_EXEC_TEST(ExprBlock_ManualSwitch_brif) {
WASM_EXEC_TEST(If_nested) { WASM_EXEC_TEST(If_nested) {
WasmRunner<int32_t, int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t, int32_t> r(execution_mode);
BUILD(r, WASM_IF_ELSE_I( BUILD(
WASM_GET_LOCAL(0), r,
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(11), WASM_I8(12)), WASM_IF_ELSE_I(
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I8(13), WASM_I8(14)))); WASM_GET_LOCAL(0),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(11), WASM_I32V_1(12)),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_I32V_1(13), WASM_I32V_1(14))));
CHECK_EQ(11, r.Call(1, 1)); CHECK_EQ(11, r.Call(1, 1));
CHECK_EQ(12, r.Call(1, 0)); CHECK_EQ(12, r.Call(1, 0));
...@@ -2501,9 +2470,9 @@ WASM_EXEC_TEST(If_nested) { ...@@ -2501,9 +2470,9 @@ WASM_EXEC_TEST(If_nested) {
WASM_EXEC_TEST(ExprBlock_if) { WASM_EXEC_TEST(ExprBlock_if) {
WasmRunner<int32_t, int32_t> r(execution_mode); WasmRunner<int32_t, int32_t> r(execution_mode);
BUILD(r, BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0),
WASM_BLOCK_I(WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(11)), WASM_BRV(0, WASM_I32V_1(11)),
WASM_BRV(1, WASM_I8(14))))); WASM_BRV(1, WASM_I32V_1(14)))));
CHECK_EQ(11, r.Call(1)); CHECK_EQ(11, r.Call(1));
CHECK_EQ(14, r.Call(0)); CHECK_EQ(14, r.Call(0));
...@@ -2514,10 +2483,10 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) { ...@@ -2514,10 +2483,10 @@ WASM_EXEC_TEST(ExprBlock_nested_ifs) {
BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I( BUILD(r, WASM_BLOCK_I(WASM_IF_ELSE_I(
WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(11)), WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(11)),
WASM_BRV(1, WASM_I8(12))), WASM_BRV(1, WASM_I32V_1(12))),
WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I8(13)), WASM_IF_ELSE_I(WASM_GET_LOCAL(1), WASM_BRV(0, WASM_I32V_1(13)),
WASM_BRV(1, WASM_I8(14)))))); WASM_BRV(1, WASM_I32V_1(14))))));
CHECK_EQ(11, r.Call(1, 1)); CHECK_EQ(11, r.Call(1, 1));
CHECK_EQ(12, r.Call(1, 0)); CHECK_EQ(12, r.Call(1, 0));
...@@ -2551,7 +2520,8 @@ WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) { ...@@ -2551,7 +2520,8 @@ WASM_EXEC_TEST_WITH_TRAP(SimpleCallIndirect) {
r.module().PopulateIndirectFunctionTable(); r.module().PopulateIndirectFunctionTable();
// Build the caller function. // Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66),
WASM_I32V_1(22)));
CHECK_EQ(88, r.Call(0)); CHECK_EQ(88, r.Call(0));
CHECK_EQ(44, r.Call(1)); CHECK_EQ(44, r.Call(1));
...@@ -2616,7 +2586,8 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) { ...@@ -2616,7 +2586,8 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_EmptyTable) {
r.module().AddIndirectFunctionTable(nullptr, 0); r.module().AddIndirectFunctionTable(nullptr, 0);
// Build the caller function. // Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(66),
WASM_I32V_1(22)));
CHECK_TRAP(r.Call(0)); CHECK_TRAP(r.Call(0));
CHECK_TRAP(r.Call(1)); CHECK_TRAP(r.Call(1));
...@@ -2655,7 +2626,8 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) { ...@@ -2655,7 +2626,8 @@ WASM_EXEC_TEST_WITH_TRAP(CallIndirect_canonical) {
r.module().PopulateIndirectFunctionTable(); r.module().PopulateIndirectFunctionTable();
// Build the caller function. // Build the caller function.
BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I8(77), WASM_I8(11))); BUILD(r, WASM_CALL_INDIRECT2(1, WASM_GET_LOCAL(0), WASM_I32V_2(77),
WASM_I32V_1(11)));
CHECK_EQ(88, r.Call(0)); CHECK_EQ(88, r.Call(0));
CHECK_EQ(66, r.Call(1)); CHECK_EQ(66, r.Call(1));
...@@ -2869,7 +2841,7 @@ static void CompileCallIndirectMany(ValueType param) { ...@@ -2869,7 +2841,7 @@ static void CompileCallIndirectMany(ValueType param) {
for (byte p = 0; p < num_params; ++p) { for (byte p = 0; p < num_params; ++p) {
ADD_CODE(code, kExprGetLocal, p); ADD_CODE(code, kExprGetLocal, p);
} }
ADD_CODE(code, kExprI8Const, 0); ADD_CODE(code, kExprI32Const, 0);
ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO); ADD_CODE(code, kExprCallIndirect, 1, TABLE_ZERO);
t.Build(&code[0], &code[0] + code.size()); t.Build(&code[0], &code[0] + code.size());
......
...@@ -13,8 +13,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -13,8 +13,8 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
builder.addFunction("foo", kSig_i_v) builder.addFunction("foo", kSig_i_v)
.addBody([ .addBody([
kExprI32Const, 0x00, kExprI32Const, 0x00,
kExprI8Const, 0xcb, kExprI32Const, 0x0b,
kExprI8Const, 0xff, kExprI32Const, 0x0f,
kExprBrTable, 0xcb, 0xcb, 0xcb, 0x00, 0x00, 0xcb, 0x00 // entries=1238475 kExprBrTable, 0xcb, 0xcb, 0xcb, 0x00, 0x00, 0xcb, 0x00 // entries=1238475
]) ])
.exportFunc(); .exportFunc();
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --expose-wasm
load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js");
var wire_bytes = readbuffer("test/mjsunit/regress/wasm/665402.wasm");
var module = new WebAssembly.Module(wire_bytes);
assertTrue(module != undefined);
...@@ -11,12 +11,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -11,12 +11,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("test", kSig_i_iii) builder.addFunction("test", kSig_i_iii)
.addBody([ .addBody([
kExprI8Const, 0xcb, kExprI32Const, 0x0b,
kExprI32Clz, kExprI32Clz,
kExprI32Clz, kExprI32Clz,
kExprI32Clz, kExprI32Clz,
kExprI32Const, 0x67, kExprI32Const, 0x67,
kExprI8Const, 0x67, kExprI32Const, 0x07,
kExprI32Clz, kExprI32Clz,
kExprI32Clz, kExprI32Clz,
kExprI32Clz, kExprI32Clz,
...@@ -407,7 +407,7 @@ kExprNop, ...@@ -407,7 +407,7 @@ kExprNop,
kExprI64DivU, kExprI64DivU,
kExprUnreachable, kExprUnreachable,
kExprI32GeS, kExprI32GeS,
kExprI8Const, 0xcb, kExprI32Const, 0x0b,
]) ])
.exportFunc(); .exportFunc();
var module = builder.instantiate(); var module = builder.instantiate();
......
...@@ -66,7 +66,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -66,7 +66,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function RelationBetweenModuleAndClone() { (function RelationBetweenModuleAndClone() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, 42]) .addBody([kExprI32Const, 42])
.exportFunc(); .exportFunc();
var wire_bytes = builder.toBuffer(); var wire_bytes = builder.toBuffer();
...@@ -83,7 +83,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -83,7 +83,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function SerializeAfterInstantiation() { (function SerializeAfterInstantiation() {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, 42]) .addBody([kExprI32Const, 42])
.exportFunc(); .exportFunc();
var wire_bytes = builder.toBuffer() var wire_bytes = builder.toBuffer()
......
...@@ -9,12 +9,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -9,12 +9,12 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testExportedMain() { (function testExportedMain() {
print("TestExportedMain..."); print("TestExportedMain...");
var kReturnValue = 88; var kReturnValue = 44;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprI8Const, kExprI32Const,
kReturnValue, kReturnValue,
kExprReturn kExprReturn
]) ])
...@@ -30,13 +30,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -30,13 +30,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testExportedTwice() { (function testExportedTwice() {
print("TestExportedTwice..."); print("TestExportedTwice...");
var kReturnValue = 99; var kReturnValue = 45;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprI8Const, kExprI32Const,
kReturnValue, kReturnValue,
kExprReturn kExprReturn
]) ])
...@@ -56,13 +56,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -56,13 +56,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testEmptyName() { (function testEmptyName() {
print("TestEmptyName..."); print("TestEmptyName...");
var kReturnValue = 93; var kReturnValue = 46;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprI8Const, kExprI32Const,
kReturnValue, kReturnValue,
kExprReturn kExprReturn
]) ])
...@@ -78,13 +78,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -78,13 +78,13 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
(function testNumericName() { (function testNumericName() {
print("TestNumericName..."); print("TestNumericName...");
var kReturnValue = 93; var kReturnValue = 47;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([ .addBody([
kExprI8Const, kExprI32Const,
kReturnValue, kReturnValue,
kExprReturn kExprReturn
]) ])
......
...@@ -247,7 +247,7 @@ function testCallBinopVoid(type, func, check) { ...@@ -247,7 +247,7 @@ function testCallBinopVoid(type, func, check) {
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
kExprGetLocal, 1, // -- kExprGetLocal, 1, // --
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
kExprI8Const, 99 // -- kExprI32Const, 33 // --
]) // -- ]) // --
.exportFunc() .exportFunc()
...@@ -258,7 +258,7 @@ function testCallBinopVoid(type, func, check) { ...@@ -258,7 +258,7 @@ function testCallBinopVoid(type, func, check) {
for (var i = 0; i < 100000; i += 10003.1) { for (var i = 0; i < 100000; i += 10003.1) {
var a = 22.5 + i, b = 10.5 + i; var a = 22.5 + i, b = 10.5 + i;
var r = main(a, b); var r = main(a, b);
assertEquals(99, r); assertEquals(33, r);
assertEquals(2, passed_length); assertEquals(2, passed_length);
var expected_a, expected_b; var expected_a, expected_b;
switch (type) { switch (type) {
...@@ -299,7 +299,7 @@ testCallBinopVoid(kWasmF64); ...@@ -299,7 +299,7 @@ testCallBinopVoid(kWasmF64);
builder.addImport("", "print", makeSig_v_x(kWasmF64)); builder.addImport("", "print", makeSig_v_x(kWasmF64));
builder.addFunction("main", makeSig_v_x(kWasmF64)) builder.addFunction("main", makeSig_v_x(kWasmF64))
.addBody([ .addBody([
kExprI8Const, 97, // -- kExprI32Const, 37, // --
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
kExprCallFunction, 1 // -- kExprCallFunction, 1 // --
......
...@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js"); ...@@ -11,7 +11,7 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
var f = builder.addFunction("nine", kSig_i_v) var f = builder.addFunction("nine", kSig_i_v)
.addBody([kExprI8Const, 9]) .addBody([kExprI32Const, 9])
.exportFunc(); .exportFunc();
var func = builder.instantiate().exports.nine; var func = builder.instantiate().exports.nine;
......
...@@ -190,7 +190,7 @@ function testCallBinopVoid(type, func, check) { ...@@ -190,7 +190,7 @@ function testCallBinopVoid(type, func, check) {
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
kExprGetLocal, 1, // -- kExprGetLocal, 1, // --
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
kExprI8Const, 99, // -- kExprI32Const, 39, // --
]) ])
.exportFunc("main"); .exportFunc("main");
...@@ -201,7 +201,7 @@ function testCallBinopVoid(type, func, check) { ...@@ -201,7 +201,7 @@ function testCallBinopVoid(type, func, check) {
for (var i = 0; i < 100000; i += 10003.1) { for (var i = 0; i < 100000; i += 10003.1) {
var a = 22.5 + i, b = 10.5 + i; var a = 22.5 + i, b = 10.5 + i;
var r = main(a, b); var r = main(a, b);
assertEquals(99, r); assertEquals(39, r);
assertEquals(2, passed_length); assertEquals(2, passed_length);
var expected_a, expected_b; var expected_a, expected_b;
switch (type) { switch (type) {
...@@ -243,9 +243,9 @@ function testCallPrint() { ...@@ -243,9 +243,9 @@ function testCallPrint() {
builder.addImport("q", "print", makeSig_r_x(kWasmF64, kWasmF64)); builder.addImport("q", "print", makeSig_r_x(kWasmF64, kWasmF64));
builder.addFunction("main", makeSig_r_x(kWasmF64, kWasmF64)) builder.addFunction("main", makeSig_r_x(kWasmF64, kWasmF64))
.addBody([ .addBody([
kExprI8Const, 97, // -- kExprI32Const, 27, // --
kExprCallFunction, 0, // -- kExprCallFunction, 0, // --
kExprGetLocal, 0, // -- kExprGetLocal, 0, // --
kExprCallFunction, 1 // -- kExprCallFunction, 1 // --
]) ])
.exportFunc(); .exportFunc();
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/wasm-module-builder.js");
let kReturnValue = 117; let kReturnValue = 17;
let buffer = (() => { let buffer = (() => {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 1, true); builder.addMemory(1, 1, true);
builder.addFunction("main", kSig_i_v) builder.addFunction("main", kSig_i_v)
.addBody([kExprI8Const, kReturnValue]) .addBody([kExprI32Const, kReturnValue])
.exportFunc(); .exportFunc();
return builder.toBuffer(); return builder.toBuffer();
......
...@@ -8,11 +8,11 @@ load("test/mjsunit/wasm/wasm-constants.js"); ...@@ -8,11 +8,11 @@ load("test/mjsunit/wasm/wasm-constants.js");
load("test/mjsunit/wasm/wasm-module-builder.js"); load("test/mjsunit/wasm/wasm-module-builder.js");
(function BasicTest() { (function BasicTest() {
var kReturnValue = 107; var kReturnValue = 15;
var builder = new WasmModuleBuilder(); var builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_i) builder.addFunction("main", kSig_i_i)
.addBody([kExprI8Const, kReturnValue]) .addBody([kExprI32Const, kReturnValue])
.exportFunc(); .exportFunc();
var main = builder.instantiate().exports.main; var main = builder.instantiate().exports.main;
......
...@@ -17,23 +17,23 @@ function genModule(memory) { ...@@ -17,23 +17,23 @@ function genModule(memory) {
.addBody([ .addBody([
// main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0; // main body: while(i) { if(mem[i]) return -1; i -= 4; } return 0;
// TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc // TODO(titzer): this manual bytecode has a copy of test-run-wasm.cc
/**/ kExprLoop, kWasmStmt, // -- /**/ kExprLoop, kWasmStmt, // --
/* */ kExprGetLocal, 0, // -- /* */ kExprGetLocal, 0, // --
/* */ kExprIf, kWasmStmt, // -- /* */ kExprIf, kWasmStmt, // --
/* */ kExprGetLocal, 0, // -- /* */ kExprGetLocal, 0, // --
/* */ kExprI32LoadMem, 0, 0, // -- /* */ kExprI32LoadMem, 0, 0, // --
/* */ kExprIf, kWasmStmt, // -- /* */ kExprIf, kWasmStmt, // --
/* */ kExprI8Const, 255, // -- /* */ kExprI32Const, 127, // --
/* */ kExprReturn, // -- /* */ kExprReturn, // --
/* */ kExprEnd, // -- /* */ kExprEnd, // --
/* */ kExprGetLocal, 0, // -- /* */ kExprGetLocal, 0, // --
/* */ kExprI8Const, 4, // -- /* */ kExprI32Const, 4, // --
/* */ kExprI32Sub, // -- /* */ kExprI32Sub, // --
/* */ kExprSetLocal, 0, // -- /* */ kExprSetLocal, 0, // --
/* */ kExprBr, 1, // -- /* */ kExprBr, 1, // --
/* */ kExprEnd, // -- /* */ kExprEnd, // --
/* */ kExprEnd, // -- /* */ kExprEnd, // --
/**/ kExprI8Const, 0 // -- /**/ kExprI32Const, 0 // --
]) ])
.exportFunc(); .exportFunc();
var module = builder.instantiate(null, memory); var module = builder.instantiate(null, memory);
......
...@@ -33,7 +33,7 @@ assertVerifies(kSig_v_v, [kExprNop]); ...@@ -33,7 +33,7 @@ assertVerifies(kSig_v_v, [kExprNop]);
assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);}); assertThrows(() => {instantiate(kSig_i_i, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);}); assertThrows(() => {instantiate(kSig_i_ii, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);}); assertThrows(() => {instantiate(kSig_i_dd, [kExprGetLocal, 0]);});
assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); assertThrows(() => {instantiate(kSig_i_v, [kExprI32Const, 0]);});
(function testInvalidIndex() { (function testInvalidIndex() {
print("testInvalidIndex"); print("testInvalidIndex");
...@@ -69,14 +69,14 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); ...@@ -69,14 +69,14 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
builder.addMemory(12, 12, true); builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v) var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 66, kExprI32StoreMem, 0, 0]); .addBody([kExprI32Const, 0, kExprI32Const, 55, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index); builder.addStart(func.index);
var module = builder.instantiate(); var module = builder.instantiate();
var memory = module.exports.memory.buffer; var memory = module.exports.memory.buffer;
var view = new Int8Array(memory); var view = new Int8Array(memory);
assertEquals(66, view[0]); assertEquals(55, view[0]);
})(); })();
(function testRun2() { (function testRun2() {
...@@ -86,7 +86,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);}); ...@@ -86,7 +86,7 @@ assertThrows(() => {instantiate(kSig_i_v, [kExprI8Const, 0]);});
builder.addMemory(12, 12, true); builder.addMemory(12, 12, true);
var func = builder.addFunction("", kSig_v_v) var func = builder.addFunction("", kSig_v_v)
.addBody([kExprI8Const, 0, kExprI8Const, 22, kExprI8Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]); .addBody([kExprI32Const, 0, kExprI32Const, 22, kExprI32Const, 55, kExprI32Add, kExprI32StoreMem, 0, 0]);
builder.addStart(func.index); builder.addStart(func.index);
......
...@@ -17,7 +17,7 @@ function instantiate(buffer, ffi) { ...@@ -17,7 +17,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 2, false); builder.addMemory(1, 2, false);
builder.addFunction("foo", kSig_i_v) builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 11]) .addBody([kExprI32Const, 11])
.exportAs("blarg"); .exportAs("blarg");
var buffer = builder.toBuffer(debug); var buffer = builder.toBuffer(debug);
...@@ -29,7 +29,7 @@ function instantiate(buffer, ffi) { ...@@ -29,7 +29,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
var index = builder.addImport("", "print", makeSig_v_x(kWasmI32)); var index = builder.addImport("", "print", makeSig_v_x(kWasmI32));
builder.addFunction("foo", kSig_v_v) builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 13, kExprCallFunction, index]) .addBody([kExprI32Const, 13, kExprCallFunction, index])
.exportAs("main"); .exportAs("main");
var buffer = builder.toBuffer(debug); var buffer = builder.toBuffer(debug);
...@@ -121,7 +121,7 @@ function instantiate(buffer, ffi) { ...@@ -121,7 +121,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
builder.addMemory(1, 2, false); builder.addMemory(1, 2, false);
builder.addFunction("foo", kSig_i_v) builder.addFunction("foo", kSig_i_v)
.addBody([kExprI8Const, 17]) .addBody([kExprI32Const, 17])
.exportAs("blarg"); .exportAs("blarg");
var buffer = builder.toBuffer(debug); var buffer = builder.toBuffer(debug);
...@@ -147,7 +147,7 @@ function instantiate(buffer, ffi) { ...@@ -147,7 +147,7 @@ function instantiate(buffer, ffi) {
let builder = new WasmModuleBuilder(); let builder = new WasmModuleBuilder();
var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32)); var index = builder.addImport("mod", "print", makeSig_v_x(kWasmI32));
builder.addFunction("foo", kSig_v_v) builder.addFunction("foo", kSig_v_v)
.addBody([kExprI8Const, 19, kExprCallFunction, index]) .addBody([kExprI32Const, 19, kExprCallFunction, index])
.exportAs("main"); .exportAs("main");
var buffer = builder.toBuffer(debug); var buffer = builder.toBuffer(debug);
......
...@@ -167,7 +167,6 @@ let kExprI32Const = 0x41; ...@@ -167,7 +167,6 @@ let kExprI32Const = 0x41;
let kExprI64Const = 0x42; let kExprI64Const = 0x42;
let kExprF32Const = 0x43; let kExprF32Const = 0x43;
let kExprF64Const = 0x44; let kExprF64Const = 0x44;
let kExprI8Const = 0xcb;
let kExprI32LoadMem = 0x28; let kExprI32LoadMem = 0x28;
let kExprI64LoadMem = 0x29; let kExprI64LoadMem = 0x29;
let kExprF32LoadMem = 0x2a; let kExprF32LoadMem = 0x2a;
......
...@@ -163,10 +163,10 @@ TEST_F(ControlTransferTest, SimpleIfElse_v1) { ...@@ -163,10 +163,10 @@ TEST_F(ControlTransferTest, SimpleIfElse_v1) {
0, // @1 0, // @1
kExprIf, // @2 kExprIf, // @2
kLocalVoid, // @3 kLocalVoid, // @3
kExprI8Const, // @4 kExprI32Const, // @4
0, // @5 0, // @5
kExprElse, // @6 kExprElse, // @6
kExprI8Const, // @7 kExprI32Const, // @7
0, // @8 0, // @8
kExprEnd // @9 kExprEnd // @9
}; };
...@@ -260,39 +260,39 @@ TEST_F(ControlTransferTest, Br1) { ...@@ -260,39 +260,39 @@ TEST_F(ControlTransferTest, Br1) {
TEST_F(ControlTransferTest, Br_v1a) { TEST_F(ControlTransferTest, Br_v1a) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprBr, // @4 kExprBr, // @4
0, // @5 0, // @5
kExprEnd // @6 kExprEnd // @6
}; };
EXPECT_PC_DELTAS({4, 3}); EXPECT_PC_DELTAS({4, 3});
} }
TEST_F(ControlTransferTest, Br_v1b) { TEST_F(ControlTransferTest, Br_v1b) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprBr, // @4 kExprBr, // @4
0, // @5 0, // @5
kExprEnd // @6 kExprEnd // @6
}; };
EXPECT_PC_DELTAS({4, 3}); EXPECT_PC_DELTAS({4, 3});
} }
TEST_F(ControlTransferTest, Br_v1c) { TEST_F(ControlTransferTest, Br_v1c) {
byte code[] = { byte code[] = {
kExprI8Const, // @0 kExprI32Const, // @0
0, // @1 0, // @1
kExprBlock, // @2 kExprBlock, // @2
kLocalVoid, // @3 kLocalVoid, // @3
kExprBr, // @4 kExprBr, // @4
0, // @5 0, // @5
kExprEnd // @6 kExprEnd // @6
}; };
EXPECT_PC_DELTAS({4, 3}); EXPECT_PC_DELTAS({4, 3});
} }
...@@ -383,80 +383,80 @@ TEST_F(ControlTransferTest, SimpleLoopExit2) { ...@@ -383,80 +383,80 @@ TEST_F(ControlTransferTest, SimpleLoopExit2) {
TEST_F(ControlTransferTest, BrTable0) { TEST_F(ControlTransferTest, BrTable0) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprBrTable, // @4 kExprBrTable, // @4
0, // @5 0, // @5
U32V_1(0), // @6 U32V_1(0), // @6
kExprEnd // @7 kExprEnd // @7
}; };
EXPECT_PC_DELTAS({4, 4}); EXPECT_PC_DELTAS({4, 4});
} }
TEST_F(ControlTransferTest, BrTable0_v1a) { TEST_F(ControlTransferTest, BrTable0_v1a) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprI8Const, // @4 kExprI32Const, // @4
0, // @5 0, // @5
kExprBrTable, // @6 kExprBrTable, // @6
0, // @7 0, // @7
U32V_1(0), // @8 U32V_1(0), // @8
kExprEnd // @9 kExprEnd // @9
}; };
EXPECT_PC_DELTAS({6, 4}); EXPECT_PC_DELTAS({6, 4});
} }
TEST_F(ControlTransferTest, BrTable0_v1b) { TEST_F(ControlTransferTest, BrTable0_v1b) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprI8Const, // @4 kExprI32Const, // @4
0, // @5 0, // @5
kExprBrTable, // @6 kExprBrTable, // @6
0, // @7 0, // @7
U32V_1(0), // @8 U32V_1(0), // @8
kExprEnd // @9 kExprEnd // @9
}; };
EXPECT_PC_DELTAS({6, 4}); EXPECT_PC_DELTAS({6, 4});
} }
TEST_F(ControlTransferTest, BrTable1) { TEST_F(ControlTransferTest, BrTable1) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprI8Const, // @2 kExprI32Const, // @2
0, // @3 0, // @3
kExprBrTable, // @4 kExprBrTable, // @4
1, // @5 1, // @5
U32V_1(0), // @6 U32V_1(0), // @6
U32V_1(0), // @7 U32V_1(0), // @7
kExprEnd // @8 kExprEnd // @8
}; };
EXPECT_PC_DELTAS({4, 5}, {5, 4}); EXPECT_PC_DELTAS({4, 5}, {5, 4});
} }
TEST_F(ControlTransferTest, BrTable2) { TEST_F(ControlTransferTest, BrTable2) {
byte code[] = { byte code[] = {
kExprBlock, // @0 kExprBlock, // @0
kLocalVoid, // @1 kLocalVoid, // @1
kExprBlock, // @2 kExprBlock, // @2
kLocalVoid, // @3 kLocalVoid, // @3
kExprI8Const, // @4 kExprI32Const, // @4
0, // @5 0, // @5
kExprBrTable, // @6 kExprBrTable, // @6
2, // @7 2, // @7
U32V_1(0), // @8 U32V_1(0), // @8
U32V_1(0), // @9 U32V_1(0), // @9
U32V_1(1), // @10 U32V_1(1), // @10
kExprEnd, // @11 kExprEnd, // @11
kExprEnd // @12 kExprEnd // @12
}; };
EXPECT_PC_DELTAS({6, 6}, {7, 5}, {8, 5}); EXPECT_PC_DELTAS({6, 6}, {7, 5}, {8, 5});
} }
......
...@@ -183,10 +183,10 @@ class FunctionBodyDecoderTest : public TestWithZone { ...@@ -183,10 +183,10 @@ class FunctionBodyDecoderTest : public TestWithZone {
} }
}; };
TEST_F(FunctionBodyDecoderTest, Int8Const) { TEST_F(FunctionBodyDecoderTest, Int32Const1) {
byte code[] = {kExprI8Const, 0}; byte code[] = {kExprI32Const, 0};
for (int i = -128; i < 128; i++) { for (int i = -64; i <= 63; i++) {
code[1] = static_cast<byte>(i); code[1] = static_cast<byte>(i & 0x7F);
EXPECT_VERIFIES_C(i_i, code); EXPECT_VERIFIES_C(i_i, code);
} }
} }
...@@ -203,11 +203,11 @@ TEST_F(FunctionBodyDecoderTest, IncompleteIf1) { ...@@ -203,11 +203,11 @@ TEST_F(FunctionBodyDecoderTest, IncompleteIf1) {
EXPECT_FAILURE_C(i_i, code); EXPECT_FAILURE_C(i_i, code);
} }
TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru) { TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru) {
EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); EXPECT_VERIFIES(i_i, WASM_I32V_1(0));
} }
TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru2) { TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru2) {
EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1));
} }
...@@ -421,8 +421,8 @@ TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { ...@@ -421,8 +421,8 @@ TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) {
for (byte i = 1; i < 8; i++) { for (byte i = 1; i < 8; i++) {
AddLocals(kWasmI32, 1); AddLocals(kWasmI32, 1);
for (byte j = 0; j < i; j++) { for (byte j = 0; j < i; j++) {
EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I32V_1(i)));
EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I32V_1(i)));
} }
} }
} }
...@@ -527,12 +527,13 @@ TEST_F(FunctionBodyDecoderTest, Block2b) { ...@@ -527,12 +527,13 @@ TEST_F(FunctionBodyDecoderTest, Block2b) {
TEST_F(FunctionBodyDecoderTest, Block2_fallthru) { TEST_F(FunctionBodyDecoderTest, Block2_fallthru) {
EXPECT_VERIFIES( EXPECT_VERIFIES(
i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)),
WASM_I8(23)); WASM_I32V_1(23));
} }
TEST_F(FunctionBodyDecoderTest, Block3) { TEST_F(FunctionBodyDecoderTest, Block3) {
EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), EXPECT_VERIFIES(i_i,
WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO),
WASM_SET_LOCAL(0, WASM_ZERO), WASM_I32V_1(11)));
} }
TEST_F(FunctionBodyDecoderTest, Block5) { TEST_F(FunctionBodyDecoderTest, Block5) {
...@@ -606,8 +607,8 @@ TEST_F(FunctionBodyDecoderTest, NestedBlock_return) { ...@@ -606,8 +607,8 @@ TEST_F(FunctionBodyDecoderTest, NestedBlock_return) {
} }
TEST_F(FunctionBodyDecoderTest, BlockBrBinop) { TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
EXPECT_VERIFIES( EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))),
i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); WASM_I32V_1(2)));
} }
TEST_F(FunctionBodyDecoderTest, If_empty1) { TEST_F(FunctionBodyDecoderTest, If_empty1) {
...@@ -635,19 +636,19 @@ TEST_F(FunctionBodyDecoderTest, If_empty_stack) { ...@@ -635,19 +636,19 @@ TEST_F(FunctionBodyDecoderTest, If_empty_stack) {
} }
TEST_F(FunctionBodyDecoderTest, If_incomplete1) { TEST_F(FunctionBodyDecoderTest, If_incomplete1) {
byte code[] = {kExprI8Const, 0, kExprIf}; byte code[] = {kExprI32Const, 0, kExprIf};
EXPECT_FAILURE_C(v_v, code); EXPECT_FAILURE_C(v_v, code);
EXPECT_FAILURE_C(i_i, code); EXPECT_FAILURE_C(i_i, code);
} }
TEST_F(FunctionBodyDecoderTest, If_incomplete2) { TEST_F(FunctionBodyDecoderTest, If_incomplete2) {
byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; byte code[] = {kExprI32Const, 0, kExprIf, kExprNop};
EXPECT_FAILURE_C(v_v, code); EXPECT_FAILURE_C(v_v, code);
EXPECT_FAILURE_C(i_i, code); EXPECT_FAILURE_C(i_i, code);
} }
TEST_F(FunctionBodyDecoderTest, If_else_else) { TEST_F(FunctionBodyDecoderTest, If_else_else) {
byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; byte code[] = {kExprI32Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd};
EXPECT_FAILURE_C(v_v, code); EXPECT_FAILURE_C(v_v, code);
EXPECT_FAILURE_C(i_i, code); EXPECT_FAILURE_C(i_i, code);
} }
...@@ -704,7 +705,7 @@ TEST_F(FunctionBodyDecoderTest, IfElseBreak) { ...@@ -704,7 +705,7 @@ TEST_F(FunctionBodyDecoderTest, IfElseBreak) {
} }
TEST_F(FunctionBodyDecoderTest, Block_else) { TEST_F(FunctionBodyDecoderTest, Block_else) {
byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; byte code[] = {kExprI32Const, 0, kExprBlock, kExprElse, kExprEnd};
EXPECT_FAILURE_C(v_v, code); EXPECT_FAILURE_C(v_v, code);
EXPECT_FAILURE_C(i_i, code); EXPECT_FAILURE_C(i_i, code);
} }
...@@ -776,7 +777,7 @@ TEST_F(FunctionBodyDecoderTest, IfBlock2b) { ...@@ -776,7 +777,7 @@ TEST_F(FunctionBodyDecoderTest, IfBlock2b) {
TEST_F(FunctionBodyDecoderTest, IfElseSet) { TEST_F(FunctionBodyDecoderTest, IfElseSet) {
EXPECT_VERIFIES(v_i, EXPECT_VERIFIES(v_i,
WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
WASM_SET_LOCAL(0, WASM_I8(1)))); WASM_SET_LOCAL(0, WASM_I32V_1(1))));
} }
TEST_F(FunctionBodyDecoderTest, Loop0) { TEST_F(FunctionBodyDecoderTest, Loop0) {
...@@ -867,7 +868,6 @@ TEST_F(FunctionBodyDecoderTest, ReturnVoid2) { ...@@ -867,7 +868,6 @@ TEST_F(FunctionBodyDecoderTest, ReturnVoid2) {
} }
TEST_F(FunctionBodyDecoderTest, ReturnVoid3) { TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
EXPECT_FAILURE(v_v, kExprI8Const, 0);
EXPECT_FAILURE(v_v, kExprI32Const, 0); EXPECT_FAILURE(v_v, kExprI32Const, 0);
EXPECT_FAILURE(v_v, kExprI64Const, 0); EXPECT_FAILURE(v_v, kExprI64Const, 0);
EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0);
...@@ -897,12 +897,12 @@ TEST_F(FunctionBodyDecoderTest, Unreachable_select) { ...@@ -897,12 +897,12 @@ TEST_F(FunctionBodyDecoderTest, Unreachable_select) {
} }
TEST_F(FunctionBodyDecoderTest, If1) { TEST_F(FunctionBodyDecoderTest, If1) {
EXPECT_VERIFIES(i_i,
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8)));
EXPECT_VERIFIES( EXPECT_VERIFIES(
i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8)));
EXPECT_VERIFIES( EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9),
i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); WASM_GET_LOCAL(0)));
EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
WASM_I32V_1(8)));
} }
TEST_F(FunctionBodyDecoderTest, If_off_end) { TEST_F(FunctionBodyDecoderTest, If_off_end) {
...@@ -916,7 +916,7 @@ TEST_F(FunctionBodyDecoderTest, If_off_end) { ...@@ -916,7 +916,7 @@ TEST_F(FunctionBodyDecoderTest, If_off_end) {
TEST_F(FunctionBodyDecoderTest, If_type1) { TEST_F(FunctionBodyDecoderTest, If_type1) {
// float|double ? 1 : 2 // float|double ? 1 : 2
static const byte kCode[] = { static const byte kCode[] = {
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(0), WASM_I32V_1(2))};
EXPECT_VERIFIES_C(i_i, kCode); EXPECT_VERIFIES_C(i_i, kCode);
EXPECT_FAILURE_C(i_f, kCode); EXPECT_FAILURE_C(i_f, kCode);
EXPECT_FAILURE_C(i_d, kCode); EXPECT_FAILURE_C(i_d, kCode);
...@@ -925,7 +925,7 @@ TEST_F(FunctionBodyDecoderTest, If_type1) { ...@@ -925,7 +925,7 @@ TEST_F(FunctionBodyDecoderTest, If_type1) {
TEST_F(FunctionBodyDecoderTest, If_type2) { TEST_F(FunctionBodyDecoderTest, If_type2) {
// 1 ? float|double : 2 // 1 ? float|double : 2
static const byte kCode[] = { static const byte kCode[] = {
WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; WASM_IF_ELSE_I(WASM_I32V_1(1), WASM_GET_LOCAL(0), WASM_I32V_1(1))};
EXPECT_VERIFIES_C(i_i, kCode); EXPECT_VERIFIES_C(i_i, kCode);
EXPECT_FAILURE_C(i_f, kCode); EXPECT_FAILURE_C(i_f, kCode);
EXPECT_FAILURE_C(i_d, kCode); EXPECT_FAILURE_C(i_d, kCode);
...@@ -934,7 +934,7 @@ TEST_F(FunctionBodyDecoderTest, If_type2) { ...@@ -934,7 +934,7 @@ TEST_F(FunctionBodyDecoderTest, If_type2) {
TEST_F(FunctionBodyDecoderTest, If_type3) { TEST_F(FunctionBodyDecoderTest, If_type3) {
// stmt ? 0 : 1 // stmt ? 0 : 1
static const byte kCode[] = { static const byte kCode[] = {
WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; WASM_IF_ELSE_I(WASM_NOP, WASM_I32V_1(0), WASM_I32V_1(1))};
EXPECT_FAILURE_C(i_i, kCode); EXPECT_FAILURE_C(i_i, kCode);
EXPECT_FAILURE_C(i_f, kCode); EXPECT_FAILURE_C(i_f, kCode);
EXPECT_FAILURE_C(i_d, kCode); EXPECT_FAILURE_C(i_d, kCode);
...@@ -943,7 +943,7 @@ TEST_F(FunctionBodyDecoderTest, If_type3) { ...@@ -943,7 +943,7 @@ TEST_F(FunctionBodyDecoderTest, If_type3) {
TEST_F(FunctionBodyDecoderTest, If_type4) { TEST_F(FunctionBodyDecoderTest, If_type4) {
// 0 ? stmt : 1 // 0 ? stmt : 1
static const byte kCode[] = { static const byte kCode[] = {
WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I32V_1(1))};
EXPECT_FAILURE_C(i_i, kCode); EXPECT_FAILURE_C(i_i, kCode);
EXPECT_FAILURE_C(i_f, kCode); EXPECT_FAILURE_C(i_f, kCode);
EXPECT_FAILURE_C(i_d, kCode); EXPECT_FAILURE_C(i_d, kCode);
...@@ -951,7 +951,8 @@ TEST_F(FunctionBodyDecoderTest, If_type4) { ...@@ -951,7 +951,8 @@ TEST_F(FunctionBodyDecoderTest, If_type4) {
TEST_F(FunctionBodyDecoderTest, If_type5) { TEST_F(FunctionBodyDecoderTest, If_type5) {
// 0 ? 1 : stmt // 0 ? 1 : stmt
static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; static const byte kCode[] = {
WASM_IF_ELSE_I(WASM_ZERO, WASM_I32V_1(1), WASM_NOP)};
EXPECT_FAILURE_C(i_i, kCode); EXPECT_FAILURE_C(i_i, kCode);
EXPECT_FAILURE_C(i_f, kCode); EXPECT_FAILURE_C(i_f, kCode);
EXPECT_FAILURE_C(i_d, kCode); EXPECT_FAILURE_C(i_d, kCode);
...@@ -1028,8 +1029,8 @@ TEST_F(FunctionBodyDecoderTest, TypeConversions) { ...@@ -1028,8 +1029,8 @@ TEST_F(FunctionBodyDecoderTest, TypeConversions) {
TEST_F(FunctionBodyDecoderTest, MacrosStmt) { TEST_F(FunctionBodyDecoderTest, MacrosStmt) {
EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
EXPECT_VERIFIES( EXPECT_VERIFIES(v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24),
v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); WASM_I32V_1(40)));
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 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_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
EXPECT_VERIFIES(v_v, WASM_NOP); EXPECT_VERIFIES(v_v, WASM_NOP);
...@@ -1066,7 +1067,7 @@ TEST_F(FunctionBodyDecoderTest, MultipleReturn) { ...@@ -1066,7 +1067,7 @@ TEST_F(FunctionBodyDecoderTest, MultipleReturn) {
FunctionSig sig_iii_v(3, 0, kIntTypes5); FunctionSig sig_iii_v(3, 0, kIntTypes5);
EXPECT_VERIFIES_S(&sig_iii_v, EXPECT_VERIFIES_S(&sig_iii_v,
WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I32V_1(44)));
EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
} }
...@@ -1079,38 +1080,38 @@ TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { ...@@ -1079,38 +1080,38 @@ TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) {
EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO);
FunctionSig sig_iii_v(3, 0, kIntTypes5); FunctionSig sig_iii_v(3, 0, kIntTypes5);
EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I32V_1(44));
EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE);
} }
TEST_F(FunctionBodyDecoderTest, MacrosInt32) { TEST_F(FunctionBodyDecoderTest, MacrosInt32) {
EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(12)));
EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(13)));
EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I32V_1(14)));
EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(15)));
EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(16)));
EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(17)));
EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I32V_1(18)));
EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I32V_1(19)));
EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I32V_1(20)));
EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I32V_1(21)));
EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I32V_1(22)));
EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I32V_1(23)));
EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(25)));
EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I32V_1(25)));
EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I32V_1(26)));
EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I32V_1(27)));
EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I32V_1(28)));
EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I32V_1(29)));
EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I32V_1(26)));
EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I32V_1(27)));
EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I32V_1(28)));
EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I32V_1(29)));
} }
TEST_F(FunctionBodyDecoderTest, MacrosInt64) { TEST_F(FunctionBodyDecoderTest, MacrosInt64) {
...@@ -1170,7 +1171,7 @@ TEST_F(FunctionBodyDecoderTest, MemorySize) { ...@@ -1170,7 +1171,7 @@ TEST_F(FunctionBodyDecoderTest, MemorySize) {
TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { TEST_F(FunctionBodyDecoderTest, LoadMemOffset) {
for (int offset = 0; offset < 128; offset += 7) { for (int offset = 0; offset < 128; offset += 7) {
byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
static_cast<byte>(offset)}; static_cast<byte>(offset)};
EXPECT_VERIFIES_C(i_i, code); EXPECT_VERIFIES_C(i_i, code);
} }
...@@ -1345,8 +1346,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleCalls) { ...@@ -1345,8 +1346,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleCalls) {
module_env.AddFunction(sigs.i_ii()); module_env.AddFunction(sigs.i_ii());
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); 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(1, WASM_I32V_1(27)));
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); EXPECT_VERIFIES_S(sig,
WASM_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77)));
} }
TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) { TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) {
...@@ -1382,13 +1384,13 @@ TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { ...@@ -1382,13 +1384,13 @@ TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) {
module_env.AddFunction(sigs.i_f()); module_env.AddFunction(sigs.i_f());
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I32V_1(17)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
module_env.AddFunction(sigs.i_d()); module_env.AddFunction(sigs.i_d());
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I32V_1(16)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(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))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
} }
...@@ -1448,9 +1450,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) { ...@@ -1448,9 +1450,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) {
byte f2 = module_env.AddSignature(sigs.i_ii()); byte f2 = module_env.AddSignature(sigs.i_ii());
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); 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_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22)));
EXPECT_VERIFIES_S( EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32),
sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); WASM_I32V_2(72)));
} }
TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) {
...@@ -1463,11 +1465,11 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { ...@@ -1463,11 +1465,11 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) {
module_env.AddSignature(sigs.i_v()); module_env.AddSignature(sigs.i_v());
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(22)));
module_env.AddSignature(sigs.i_i()); module_env.AddSignature(sigs.i_i());
EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(27)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I32V_1(27)));
} }
TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) {
...@@ -1478,17 +1480,17 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { ...@@ -1478,17 +1480,17 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) {
byte f0 = module_env.AddFunction(sigs.i_f()); byte f0 = module_env.AddFunction(sigs.i_f());
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I32V_1(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_I64V_1(27)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I32V_1(17)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
byte f1 = module_env.AddFunction(sigs.i_d()); byte f1 = module_env.AddFunction(sigs.i_d());
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(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_I64V_1(16)));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6)));
} }
...@@ -1503,9 +1505,9 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) { ...@@ -1503,9 +1505,9 @@ TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) {
byte f2 = module_env.AddSignature(sigs.i_ii()); byte f2 = module_env.AddSignature(sigs.i_ii());
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22)));
EXPECT_FAILURE_S( EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32),
sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); WASM_I32V_2(72)));
} }
TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) {
...@@ -1518,8 +1520,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { ...@@ -1518,8 +1520,9 @@ TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) {
byte f2 = module_env.AddImport(sigs.i_ii()); byte f2 = module_env.AddImport(sigs.i_ii());
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); 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(f1, WASM_I32V_1(22)));
EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); EXPECT_VERIFIES_S(sig,
WASM_CALL_FUNCTION(f2, WASM_I32V_1(32), WASM_I32V_2(72)));
} }
TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) {
...@@ -1530,14 +1533,14 @@ TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { ...@@ -1530,14 +1533,14 @@ TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) {
byte f0 = module_env.AddImport(sigs.i_f()); byte f0 = module_env.AddImport(sigs.i_f());
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); 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_I32V_1(17)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2)));
byte f1 = module_env.AddImport(sigs.i_d()); byte f1 = module_env.AddImport(sigs.i_d());
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); 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_I32V_1(16)));
EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(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))); EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6)));
} }
...@@ -1799,7 +1802,7 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting1) { ...@@ -1799,7 +1802,7 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting1) {
// (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
byte code[] = {WASM_BLOCK_I( byte code[] = {WASM_BLOCK_I(
WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)),
WASM_SET_LOCAL(0, WASM_I8(1))), WASM_SET_LOCAL(0, WASM_I32V_1(1))),
WASM_ZERO)}; WASM_ZERO)};
if (i < 3) { if (i < 3) {
EXPECT_VERIFIES_C(i_i, code); EXPECT_VERIFIES_C(i_i, code);
...@@ -1834,16 +1837,16 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting3) { ...@@ -1834,16 +1837,16 @@ TEST_F(FunctionBodyDecoderTest, BreakNesting3) {
} }
TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) { TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) {
EXPECT_FAILURE(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_I32V_1(7)), WASM_F32(7.7)));
EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)),
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
EXPECT_FAILURE( EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(8)),
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_I32V_1(0)),
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(9)),
WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
WASM_BRV_IF_ZERO(0, WASM_I8(11)))); WASM_BRV_IF_ZERO(0, WASM_I32V_1(11))));
} }
TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) { TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) {
...@@ -2039,7 +2042,7 @@ TEST_F(FunctionBodyDecoderTest, BrTable0c) { ...@@ -2039,7 +2042,7 @@ TEST_F(FunctionBodyDecoderTest, BrTable0c) {
} }
TEST_F(FunctionBodyDecoderTest, BrTable1a) { TEST_F(FunctionBodyDecoderTest, BrTable1a) {
static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; static byte code[] = {B1(WASM_BR_TABLE(WASM_I32V_2(67), 0, BR_TARGET(0)))};
EXPECT_VERIFIES_C(v_v, code); EXPECT_VERIFIES_C(v_v, code);
} }
...@@ -2053,13 +2056,13 @@ TEST_F(FunctionBodyDecoderTest, BrTable1b) { ...@@ -2053,13 +2056,13 @@ TEST_F(FunctionBodyDecoderTest, BrTable1b) {
TEST_F(FunctionBodyDecoderTest, BrTable2a) { TEST_F(FunctionBodyDecoderTest, BrTable2a) {
static byte code[] = { static byte code[] = {
B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; B1(WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(0)))};
EXPECT_VERIFIES_C(v_v, code); EXPECT_VERIFIES_C(v_v, code);
} }
TEST_F(FunctionBodyDecoderTest, BrTable2b) { TEST_F(FunctionBodyDecoderTest, BrTable2b) {
static byte code[] = {WASM_BLOCK( static byte code[] = {WASM_BLOCK(WASM_BLOCK(
WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))};
EXPECT_VERIFIES_C(v_v, code); EXPECT_VERIFIES_C(v_v, code);
} }
...@@ -2341,7 +2344,6 @@ TEST_F(WasmOpcodeLengthTest, Statements) { ...@@ -2341,7 +2344,6 @@ TEST_F(WasmOpcodeLengthTest, Statements) {
} }
TEST_F(WasmOpcodeLengthTest, MiscExpressions) { TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
EXPECT_LENGTH(2, kExprI8Const);
EXPECT_LENGTH(5, kExprF32Const); EXPECT_LENGTH(5, kExprF32Const);
EXPECT_LENGTH(9, kExprF64Const); EXPECT_LENGTH(9, kExprF64Const);
EXPECT_LENGTH(2, kExprGetLocal); EXPECT_LENGTH(2, kExprGetLocal);
...@@ -2661,8 +2663,8 @@ class BytecodeIteratorTest : public TestWithZone {}; ...@@ -2661,8 +2663,8 @@ class BytecodeIteratorTest : public TestWithZone {};
TEST_F(BytecodeIteratorTest, SimpleForeach) { TEST_F(BytecodeIteratorTest, SimpleForeach) {
byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
BytecodeIterator iter(code, code + sizeof(code)); BytecodeIterator iter(code, code + sizeof(code));
WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, WasmOpcode expected[] = {kExprI32Const, kExprIf, kExprI32Const,
kExprElse, kExprI8Const, kExprEnd}; kExprElse, kExprI32Const, kExprEnd};
size_t pos = 0; size_t pos = 0;
for (WasmOpcode opcode : iter.opcodes()) { for (WasmOpcode opcode : iter.opcodes()) {
if (pos >= arraysize(expected)) { if (pos >= arraysize(expected)) {
...@@ -2715,17 +2717,17 @@ TEST_F(BytecodeIteratorTest, ForeachOffset) { ...@@ -2715,17 +2717,17 @@ TEST_F(BytecodeIteratorTest, ForeachOffset) {
} }
TEST_F(BytecodeIteratorTest, WithLocalDecls) { TEST_F(BytecodeIteratorTest, WithLocalDecls) {
byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; byte code[] = {1, 1, kLocalI32, WASM_I32V_1(9), WASM_I32V_1(11)};
BodyLocalDecls decls(zone()); BodyLocalDecls decls(zone());
BytecodeIterator iter(code, code + sizeof(code), &decls); BytecodeIterator iter(code, code + sizeof(code), &decls);
EXPECT_EQ(3u, decls.encoded_size); EXPECT_EQ(3u, decls.encoded_size);
EXPECT_EQ(3u, iter.pc_offset()); EXPECT_EQ(3u, iter.pc_offset());
EXPECT_TRUE(iter.has_next()); EXPECT_TRUE(iter.has_next());
EXPECT_EQ(kExprI8Const, iter.current()); EXPECT_EQ(kExprI32Const, iter.current());
iter.next(); iter.next();
EXPECT_TRUE(iter.has_next()); EXPECT_TRUE(iter.has_next());
EXPECT_EQ(kExprI8Const, iter.current()); EXPECT_EQ(kExprI32Const, iter.current());
iter.next(); iter.next();
EXPECT_FALSE(iter.has_next()); EXPECT_FALSE(iter.has_next());
} }
......
...@@ -112,7 +112,7 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) { ...@@ -112,7 +112,7 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, NestedIf) {
TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) { TEST_F(WasmLoopAssignmentAnalyzerTest, BigLocal) {
num_locals = 65000; num_locals = 65000;
for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) { for (int i = 13; i < 65000; i = static_cast<int>(i * 1.5)) {
byte code[] = {WASM_LOOP(WASM_I8(11), kExprSetLocal, U32V_3(i))}; byte code[] = {WASM_LOOP(WASM_I32V_1(11), kExprSetLocal, U32V_3(i))};
BitVector* assigned = Analyze(code, code + arraysize(code)); BitVector* assigned = Analyze(code, code + arraysize(code));
for (int j = 0; j < assigned->length(); j++) { for (int j = 0; j < assigned->length(); j++) {
...@@ -140,8 +140,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) { ...@@ -140,8 +140,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop1) {
byte code[] = { byte code[] = {
WASM_LOOP(WASM_IF( WASM_LOOP(WASM_IF(
WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
WASM_BRV(0, WASM_SET_LOCAL( WASM_BRV(0, WASM_SET_LOCAL(3, WASM_I32_SUB(WASM_GET_LOCAL(0),
3, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(1)))))), WASM_I32V_1(1)))))),
WASM_GET_LOCAL(0)}; WASM_GET_LOCAL(0)};
BitVector* assigned = Analyze(code, code + arraysize(code)); BitVector* assigned = Analyze(code, code + arraysize(code));
...@@ -164,8 +164,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) { ...@@ -164,8 +164,8 @@ TEST_F(WasmLoopAssignmentAnalyzerTest, Loop2) {
kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum), kSum, WASM_F32_ADD(WASM_GET_LOCAL(kSum),
WASM_LOAD_MEM(MachineType::Float32(), WASM_LOAD_MEM(MachineType::Float32(),
WASM_GET_LOCAL(kIter)))), WASM_GET_LOCAL(kIter)))),
WASM_SET_LOCAL(kIter, WASM_SET_LOCAL(
WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I8(4))))), kIter, WASM_I32_SUB(WASM_GET_LOCAL(kIter), WASM_I32V_1(4))))),
WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)), WASM_STORE_MEM(MachineType::Float32(), WASM_ZERO, WASM_GET_LOCAL(kSum)),
WASM_GET_LOCAL(kIter))}; WASM_GET_LOCAL(kIter))};
......
...@@ -22,8 +22,8 @@ TEST_F(WasmMacroGenTest, Constants) { ...@@ -22,8 +22,8 @@ TEST_F(WasmMacroGenTest, Constants) {
EXPECT_SIZE(2, WASM_ONE); EXPECT_SIZE(2, WASM_ONE);
EXPECT_SIZE(2, WASM_ZERO); EXPECT_SIZE(2, WASM_ZERO);
EXPECT_SIZE(2, WASM_I8(122)); EXPECT_SIZE(2, WASM_I32V_1(-22));
EXPECT_SIZE(2, WASM_I8(254)); EXPECT_SIZE(2, WASM_I32V_1(54));
EXPECT_SIZE(2, WASM_I32V_1(1)); EXPECT_SIZE(2, WASM_I32V_1(1));
EXPECT_SIZE(3, WASM_I32V_2(200)); EXPECT_SIZE(3, WASM_I32V_2(200));
...@@ -84,7 +84,7 @@ TEST_F(WasmMacroGenTest, Statements) { ...@@ -84,7 +84,7 @@ TEST_F(WasmMacroGenTest, Statements) {
} }
TEST_F(WasmMacroGenTest, MacroStatements) { TEST_F(WasmMacroGenTest, MacroStatements) {
EXPECT_SIZE(11, WASM_WHILE(WASM_I8(0), WASM_NOP)); EXPECT_SIZE(11, WASM_WHILE(WASM_ZERO, WASM_NOP));
EXPECT_SIZE(7, WASM_INC_LOCAL(0)); EXPECT_SIZE(7, WASM_INC_LOCAL(0));
EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3)); EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment