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 4938408a1d924d39651eaff946e1f75016c87225..269a47c8fafa1245f51220a9b0c1b747d60d0cfc 100644 |
--- a/test/cctest/wasm/test-run-wasm-module.cc |
+++ b/test/cctest/wasm/test-run-wasm-module.cc |
@@ -63,6 +63,12 @@ void TestModuleException(Zone* zone, WasmModuleBuilder* builder) { |
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 @@ TEST(Run_WasmModule_Return114) { |
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 @@ TEST(Run_WasmModule_CallAdd) { |
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 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) { |
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 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { |
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 @@ TEST(Run_WasmModule_CallMain_recursive) { |
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 @@ TEST(Run_WasmModule_Global) { |
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 @@ class WasmSerializationTest { |
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 @@ TEST(MemorySize) { |
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 @@ TEST(Run_WasmModule_MemSize_GrowMem) { |
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 @@ TEST(GrowMemoryZero) { |
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 @@ TEST(TestInterruptLoop) { |
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 @@ TEST(Run_WasmModule_GrowMemoryInIf) { |
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 @@ TEST(Run_WasmModule_GrowMemOobOffset) { |
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 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) { |
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 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) { |
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 @@ TEST(Run_WasmModule_Global_init) { |
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 @@ static void RunWasmModuleGlobalInitTest(ValueType type, CType expected) { |
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); |
} |