Index: test/cctest/wasm/test-run-wasm-module.cc |
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc |
index 54f851bab5da914f004063287dced3d9352e3d51..8feda785c5dcd647b9cb0b4086efcd2e6108402c 100644 |
--- a/test/cctest/wasm/test-run-wasm-module.cc |
+++ b/test/cctest/wasm/test-run-wasm-module.cc |
@@ -63,6 +63,12 @@ |
void ExportAsMain(WasmFunctionBuilder* f) { f->ExportAs(CStrVector("main")); } |
+#define EMIT_CODE_WITH_END(f, code) \ |
+ do { \ |
+ f->EmitCode(code, sizeof(code)); \ |
+ f->Emit(kExprEnd); \ |
+ } while (false) |
+ |
} // namespace |
TEST(Run_WasmModule_Return114) { |
@@ -76,7 +82,7 @@ |
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
ExportAsMain(f); |
byte code[] = {WASM_I32V_2(kReturnValue)}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, kReturnValue); |
} |
Cleanup(); |
@@ -95,14 +101,14 @@ |
uint16_t param2 = 1; |
byte code1[] = { |
WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; |
- f1->EmitCode(code1, sizeof(code1)); |
+ EMIT_CODE_WITH_END(f1, code1); |
WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
ExportAsMain(f2); |
byte code2[] = { |
WASM_CALL_FUNCTION(f1->func_index(), WASM_I32V_2(77), WASM_I32V_1(22))}; |
- f2->EmitCode(code2, sizeof(code2)); |
+ EMIT_CODE_WITH_END(f2, code2); |
TestModule(&zone, builder, 99); |
} |
Cleanup(); |
@@ -121,7 +127,7 @@ |
ExportAsMain(f); |
byte code[] = { |
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V_1(kDataSegmentDest0))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
builder->AddDataSegment(data, sizeof(data), kDataSegmentDest0); |
TestModule(&zone, builder, 0xddccbbaa); |
@@ -149,7 +155,7 @@ |
WASM_BRV(3, WASM_I32V_1(-1)), |
WASM_INC_LOCAL_BY(localIndex, 4))), |
WASM_I32V_1(11))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, 11); |
} |
Cleanup(); |
@@ -174,7 +180,7 @@ |
WASM_INC_LOCAL(localIndex)), |
WASM_CALL_FUNCTION0(0)), |
WASM_I32V_1(55))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, 55); |
} |
Cleanup(); |
@@ -192,13 +198,13 @@ |
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
byte code1[] = { |
WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
- f1->EmitCode(code1, sizeof(code1)); |
+ EMIT_CODE_WITH_END(f1, code1); |
WasmFunctionBuilder* f2 = builder->AddFunction(sigs.i_v()); |
ExportAsMain(f2); |
byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), |
WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), |
WASM_RETURN1(WASM_CALL_FUNCTION0(f1->func_index()))}; |
- f2->EmitCode(code2, sizeof(code2)); |
+ EMIT_CODE_WITH_END(f2, code2); |
TestModule(&zone, builder, 97); |
} |
Cleanup(); |
@@ -293,7 +299,7 @@ |
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_i()); |
byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
f->ExportAs(CStrVector(kFunctionName)); |
ZoneBuffer buffer(&zone_); |
@@ -425,7 +431,7 @@ |
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
ExportAsMain(f); |
byte code[] = {WASM_MEMORY_SIZE}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, kExpectedValue); |
} |
Cleanup(); |
@@ -444,7 +450,7 @@ |
ExportAsMain(f); |
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(10)), WASM_DROP, |
WASM_MEMORY_SIZE}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, kExpectedValue); |
} |
Cleanup(); |
@@ -462,7 +468,7 @@ |
WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
ExportAsMain(f); |
byte code[] = {WASM_GROW_MEMORY(WASM_I32V(0))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, kExpectedValue); |
} |
Cleanup(); |
@@ -533,7 +539,7 @@ |
WASM_I32V(InterruptThread::signal_value_)), |
WASM_BR(1))), |
WASM_I32V(121)}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
ZoneBuffer buffer(&zone); |
builder->WriteTo(buffer); |
@@ -572,7 +578,7 @@ |
ExportAsMain(f); |
byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
WASM_I32V(12))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModule(&zone, builder, 12); |
} |
Cleanup(); |
@@ -594,7 +600,7 @@ |
byte code[] = {WASM_GROW_MEMORY(WASM_I32V_1(1)), |
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), |
WASM_I32V(value))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
TestModuleException(&zone, builder); |
} |
Cleanup(); |
@@ -617,7 +623,7 @@ |
WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), |
WASM_I32V(value)), |
WASM_LOAD_MEM(MachineType::Int32(), WASM_I32V(index))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
HandleScope scope(isolate); |
ZoneBuffer buffer(&zone); |
@@ -665,7 +671,7 @@ |
WASM_STORE_MEM(MachineType::Int32(), WASM_GET_LOCAL(0), |
WASM_I32V(value)), |
WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))}; |
- f->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f, code); |
HandleScope scope(isolate); |
ZoneBuffer buffer(&zone); |
@@ -724,7 +730,7 @@ |
WasmFunctionBuilder* f1 = builder->AddFunction(sigs.i_v()); |
byte code[] = { |
WASM_I32_ADD(WASM_GET_GLOBAL(global1), WASM_GET_GLOBAL(global2))}; |
- f1->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f1, code); |
ExportAsMain(f1); |
TestModule(&zone, builder, 999999); |
} |
@@ -756,7 +762,7 @@ |
WasmFunctionBuilder* f1 = builder->AddFunction(&sig); |
byte code[] = {WASM_GET_GLOBAL(global)}; |
- f1->EmitCode(code, sizeof(code)); |
+ EMIT_CODE_WITH_END(f1, code); |
ExportAsMain(f1); |
TestModule(&zone, builder, expected); |
} |