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))};
......
This diff is collapsed.
...@@ -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});
} }
......
...@@ -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