Skip to content

Commit de71f3a

Browse files
danlliuConstellation
authored andcommitted
Implement saturating truncation, remaining memory and table operations, and update call to pass stack parameters
https://bugs.webkit.org/show_bug.cgi?id=259665 rdar://113166666 Reviewed by Yusuke Suzuki. Added implementations for all saturating truncation instructions, as well as the remaining memory and table operations. Fixed bugs with regards to handling call parameter ordering, and allowed calls to pass arguments on stack. * JSTests/wasm/ipint-tests/ipint-test-branch-table.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.block.block.block.block.local.0.br_table.0.1.2.3.i32.const.2.return.i32.const.3.return.i32.const.5.return.i32.const.7.return.async test): * JSTests/wasm/ipint-tests/ipint-test-call-add12.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.add.export.string_appeared_here.param.i32.i32.i32.i32.i32.i32.i32.i32.i32.i32.i32.i32.result.i32.local.0.local.1.i32.add.local.2.i32.add.local.3.i32.add.local.4.i32.add.local.5.i32.add.local.6.i32.add.local.7.i32.add.local.8.i32.add.local.9.i32.add.local.10.i32.add.local.11.i32.add.return.func.export.string_appeared_here.param.i32.result.i32.local.0.local.0.local.0.local.0.local.0.local.0.local.0.local.0.local.0.local.0.local.0.local.0.call.add.return.async test): * JSTests/wasm/ipint-tests/ipint-test-call-arg-order.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.r2.param.i32.i32.result.i32.local.0.return.func.export.string_appeared_here.result.i32.i32.const.1.i32.const.2.call.r2.return.async test): * JSTests/wasm/ipint-tests/ipint-test-call-stack-arg.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.r9.param.i32.i32.i32.i32.i32.i32.i32.i32.i32.i32.result.i32.local.8.return.func.export.string_appeared_here.result.i32.i32.const.1.i32.const.2.i32.const.3.i32.const.4.i32.const.5.i32.const.6.i32.const.7.i32.const.8.i32.const.9.i32.const.10.call.r9.return.async test): * JSTests/wasm/ipint-tests/ipint-test-data-drop.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.memory.export.string_appeared_here.1.10.data.string_appeared_here.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.memory.init.0.func.export.string_appeared_here.data.drop.0.decodeString): (async test): * JSTests/wasm/ipint-tests/ipint-test-elem-drop.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.type.i2i.func.param.i32.result.i32.table.table.export.string_appeared_here.3.funcref.elem.3.3.3.elem.elems.4.4.4.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.table.init.0.elems.func.export.string_appeared_here.result.i32.i32.const.0.table.table.ref.is_null.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.0.call_indirect.table.type.i2i.func.null.param.i32.result.i32.local.0.func.inc.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.1.i32.add.func.drop.export.string_appeared_here.elem.drop.elems.async test): * JSTests/wasm/ipint-tests/ipint-test-i32-ops.js: (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.clz.return.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.ctz.return.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.popcnt.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.add.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.sub.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.mul.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.div_s.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.div_u.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.rem_s.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.rem_u.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.and.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.or.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.xor.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shl.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shr_s.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shr_u.return.async test): (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.clz.return.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.ctz.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.add.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.sub.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.mul.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.div_s.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.div_u.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.and.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.or.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.xor.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shl.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shr_s.return.func.export.string_appeared_here.param.i32.i32.result.i32.local.0.local.1.i32.shr_u.return.async test): Deleted. * JSTests/wasm/ipint-tests/ipint-test-i64-ops.js: (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i64.result.i64.local.0.i64.clz.return.func.export.string_appeared_here.param.i64.result.i64.local.0.i64.ctz.return.func.export.string_appeared_here.param.i64.result.i64.local.0.i64.popcnt.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.add.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.sub.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.mul.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.div_s.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.div_u.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.rem_s.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.rem_u.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.and.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.or.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.xor.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shl.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shr_s.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shr_u.return.async test): (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i64.result.i64.local.0.i64.clz.return.func.export.string_appeared_here.param.i64.result.i64.local.0.i64.ctz.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.add.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.sub.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.mul.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.div_s.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.div_u.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.and.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.or.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.xor.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shl.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shr_s.return.func.export.string_appeared_here.param.i64.i64.result.i64.local.0.local.1.i64.shr_u.return.async test): Deleted. * JSTests/wasm/ipint-tests/ipint-test-if.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.i32.i32.result.i32.local.0.then.local.1.return.local.2.return.async test): * JSTests/wasm/ipint-tests/ipint-test-loop.js: (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.local.0.loop.param.i32.result.i32.i32.const.1.i32.add.local.tee.0.local.0.i32.const.5.i32.sub.br_if.1.return.async test): Deleted. * JSTests/wasm/ipint-tests/ipint-test-memory-copy.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.memory.export.string_appeared_here.1.10.data.i32.const.0x0.string_appeared_here.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.memory.copy.decodeString): (async test): * JSTests/wasm/ipint-tests/ipint-test-memory-fill.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.memory.export.string_appeared_here.1.10.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.memory.fill.decodeString): (async test): * JSTests/wasm/ipint-tests/ipint-test-memory-init.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.memory.export.string_appeared_here.1.10.data.string_appeared_here.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.memory.init.0.decodeString): (async test): * JSTests/wasm/ipint-tests/ipint-test-memory-size.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.memory.export.string_appeared_here.1.10.func.export.string_appeared_here.result.i32.memory.size.func.export.string_appeared_here.param.i32.result.i32.local.0.memory.grow.async test): * JSTests/wasm/ipint-tests/ipint-test-select.js: Copied from JSTests/wasm/ipint-tests/ipint-test-loop.js. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.i32.const.2.i32.const.1.local.0.select.async test): * JSTests/wasm/ipint-tests/ipint-test-table-copy.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.type.i2i.func.param.i32.result.i32.table.table.3.funcref.table.table2.3.funcref.elem.3.3.3.elem.elems.4.4.4.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.table.init.table.elems.func.export.string_appeared_here.result.i32.i32.const.0.table.table.ref.is_null.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.0.call_indirect.table2.type.i2i.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.table.copy.table2.table.func.inc.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.1.i32.add.async test): * JSTests/wasm/ipint-tests/ipint-test-table-fill.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.type.i2i.func.param.i32.result.i32.table.table.5.funcref.elem.i32.const.0.0.0.0.0.0.func.export.string_appeared_here.result.i32.table.size.table.func.export.string_appeared_here.param.i32.i32.local.0.ref.null.func.local.1.table.fill.table.func.export.string_appeared_here.param.i32.result.i32.local.0.table.table.ref.is_null.async test): * JSTests/wasm/ipint-tests/ipint-test-table-grow.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.type.i2i.func.param.i32.result.i32.table.table.3.funcref.elem.i32.const.0.0.0.0.func.export.string_appeared_here.result.i32.table.size.table.func.export.string_appeared_here.param.i32.result.i32.ref.null.func.local.0.table.grow.table.async test): * JSTests/wasm/ipint-tests/ipint-test-table-init.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.type.i2i.func.param.i32.result.i32.table.table.export.string_appeared_here.3.funcref.elem.3.3.3.elem.elems.4.4.4.func.export.string_appeared_here.param.i32.i32.i32.local.0.local.1.local.2.table.init.0.elems.func.export.string_appeared_here.result.i32.i32.const.0.table.table.ref.is_null.func.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.0.call_indirect.table.type.i2i.func.null.param.i32.result.i32.local.0.func.inc.export.string_appeared_here.param.i32.result.i32.local.0.i32.const.1.i32.add.async test): * JSTests/wasm/ipint-tests/ipint-test-trunc-sat.js: Added. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.f32.result.i32.local.0.i32.trunc_sat_f32_s.func.export.string_appeared_here.param.f32.result.i32.local.0.i32.trunc_sat_f32_u.func.export.string_appeared_here.param.f64.result.i32.local.0.i32.trunc_sat_f64_s.func.export.string_appeared_here.param.f64.result.i32.local.0.i32.trunc_sat_f64_u.func.export.string_appeared_here.param.f32.result.i64.local.0.i64.trunc_sat_f32_s.func.export.string_appeared_here.param.f32.result.i64.local.0.i64.trunc_sat_f32_u.func.export.string_appeared_here.param.f64.result.i64.local.0.i64.trunc_sat_f64_s.func.export.string_appeared_here.param.f64.result.i64.local.0.i64.trunc_sat_f64_u.async test): * JSTests/wasm/ipint-tests/ipint-test-typed-select.js: Copied from JSTests/wasm/ipint-tests/ipint-test-loop.js. (from.string_appeared_here.import.as.assert.from.string_appeared_here.let.wat.module.func.export.string_appeared_here.param.i32.result.i32.i32.const.2.i32.const.1.local.0.select.result.i32.async test): * Source/JavaScriptCore/llint/InPlaceInterpreter.asm: * Source/JavaScriptCore/llint/InPlaceInterpreter.cpp: (JSC::IPInt::initialize): * Source/JavaScriptCore/llint/InPlaceInterpreter.h: * Source/JavaScriptCore/wasm/WasmCallee.cpp: (JSC::Wasm::IPIntCallee::IPIntCallee): * Source/JavaScriptCore/wasm/WasmCallee.h: * Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp: (JSC::Wasm::FunctionIPIntMetadataGenerator::addReturnData): * Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.h: * Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp: (JSC::Wasm::IPIntGenerator::addTableInit): (JSC::Wasm::IPIntGenerator::addElemDrop): (JSC::Wasm::IPIntGenerator::addTableSize): (JSC::Wasm::IPIntGenerator::addTableGrow): (JSC::Wasm::IPIntGenerator::addTableFill): (JSC::Wasm::IPIntGenerator::addTableCopy): (JSC::Wasm::IPIntGenerator::addMemoryInit): (JSC::Wasm::IPIntGenerator::addDataDrop): (JSC::Wasm::IPIntGenerator::addSelect): (JSC::Wasm::IPIntGenerator::addElse): (JSC::Wasm::IPIntGenerator::addElseToUnreachable): (JSC::Wasm::IPIntGenerator::addSwitch): (JSC::Wasm::IPIntGenerator::addEndToUnreachable): (JSC::Wasm::IPIntGenerator::addCallCommonData): * Source/JavaScriptCore/wasm/WasmModule.cpp: (JSC::Wasm::makeValidationCallback): * Source/JavaScriptCore/wasm/WasmSlowPaths.cpp: (JSC::LLInt::WASM_IPINT_EXTERN_CPP_DECL): (JSC::LLInt::WASM_IPINT_EXTERN_CPP_DECL_1P): * Source/JavaScriptCore/wasm/WasmSlowPaths.h: Canonical link: https://commits.webkit.org/266545@main
1 parent 6ee1cc8 commit de71f3a

43 files changed

Lines changed: 2080 additions & 134 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

JSTests/wasm/ipint-tests/ipint-error-check-call-null.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let wat = `
2121
async function test() {
2222
const instance = await instantiate(wat, {});
2323
const { table, read, write_null, write_inc, call, inc } = instance.exports
24-
assert.eq(call(5), 6);
24+
assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a null table entry (evaluating 'call(5)')");
2525
}
2626

2727
assert.asyncTest(test())

JSTests/wasm/ipint-tests/ipint-error-check-call-sig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function test() {
2828
const instance = await instantiate(wat, {});
2929
const { table, read, write_null, write_inc, call, inc } = instance.exports
3030
write_inc();
31-
assert.eq(call(5), 6);
31+
assert.throws(() => {call(5)}, WebAssembly.RuntimeError, "call_indirect to a signature that does not match (evaluating 'call(5)')");
3232
}
3333

3434
assert.asyncTest(test())
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func (export "test") (param i32 i32) (result i32)
7+
(local.get 0)
8+
(local.get 1)
9+
(i32.div_u)
10+
(return)
11+
)
12+
)
13+
`
14+
15+
async function test() {
16+
const instance = await instantiate(wat, {});
17+
const { test } = instance.exports
18+
assert.throws(() => {test(1, 0)}, WebAssembly.RuntimeError, "Division by zero (evaluating 'test(1, 0)')");
19+
}
20+
21+
assert.asyncTest(test())

JSTests/wasm/ipint-tests/ipint-error-check-mem-outofbounds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let wat = `
1616
async function test() {
1717
const instance = await instantiate(wat, {});
1818
const { memory, test } = instance.exports
19-
test(65536);
19+
assert.throws(() => {test(65536)}, WebAssembly.RuntimeError, "Out of bounds memory access (evaluating 'test(65536)')")
2020
}
2121

2222
assert.asyncTest(test())

JSTests/wasm/ipint-tests/ipint-error-check-trunc-outofbounds.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let wat = `
1313
async function test() {
1414
const instance = await instantiate(wat, {});
1515
const { memory, test } = instance.exports
16-
test(4294967296)
16+
assert.throws(() => {test(4294967296)}, WebAssembly.RuntimeError, "Out of bounds Trunc operation (evaluating 'test(4294967296)')");
1717
}
1818

1919
assert.asyncTest(test())
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func (export "test")
7+
(unreachable)
8+
(return)
9+
)
10+
)
11+
`
12+
13+
async function test() {
14+
const instance = await instantiate(wat, {});
15+
const { test } = instance.exports
16+
assert.throws(() => {test()}, WebAssembly.RuntimeError, "Unreachable code should not be executed (evaluating 'test()')");
17+
}
18+
19+
assert.asyncTest(test())
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func (export "test") (result i32)
7+
(block (result i32 i32 i32 i32)
8+
(block (result i32 i32)
9+
(i32.const 1)
10+
(i32.const 2)
11+
)
12+
(i32.const 2)
13+
(i32.const 3)
14+
)
15+
(i32.add)
16+
(i32.add)
17+
(i32.add)
18+
(return)
19+
)
20+
)
21+
`
22+
23+
async function test() {
24+
const instance = await instantiate(wat, {});
25+
const { test } = instance.exports
26+
assert.eq(test(), 8)
27+
}
28+
29+
assert.asyncTest(test())
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func (export "test") (param i32) (result i32)
7+
(block
8+
(block
9+
(block
10+
(block
11+
(local.get 0)
12+
(br_table 0 1 2 3)
13+
)
14+
(i32.const 2)
15+
(return)
16+
)
17+
(i32.const 3)
18+
(return)
19+
)
20+
(i32.const 5)
21+
(return)
22+
)
23+
(i32.const 7)
24+
(return)
25+
)
26+
)
27+
`
28+
29+
async function test() {
30+
const instance = await instantiate(wat, {});
31+
const { test } = instance.exports
32+
assert.eq(test(0), 2);
33+
assert.eq(test(1), 3);
34+
assert.eq(test(2), 5);
35+
assert.eq(test(3), 7);
36+
assert.eq(test(4), 7);
37+
}
38+
39+
assert.asyncTest(test())
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func $add (export "add") (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result i32)
7+
(local.get 0)
8+
(local.get 1)
9+
(i32.add)
10+
(local.get 2)
11+
(i32.add)
12+
(local.get 3)
13+
(i32.add)
14+
(local.get 4)
15+
(i32.add)
16+
(local.get 5)
17+
(i32.add)
18+
(local.get 6)
19+
(i32.add)
20+
(local.get 7)
21+
(i32.add)
22+
(local.get 8)
23+
(i32.add)
24+
(local.get 9)
25+
(i32.add)
26+
(local.get 10)
27+
(i32.add)
28+
(local.get 11)
29+
(i32.add)
30+
(return)
31+
)
32+
(func (export "test") (param i32) (result i32)
33+
(local.get 0)
34+
(local.get 0)
35+
(local.get 0)
36+
(local.get 0)
37+
(local.get 0)
38+
(local.get 0)
39+
(local.get 0)
40+
(local.get 0)
41+
(local.get 0)
42+
(local.get 0)
43+
(local.get 0)
44+
(local.get 0)
45+
(call $add)
46+
(return)
47+
)
48+
)
49+
`
50+
51+
async function test() {
52+
const instance = await instantiate(wat, {});
53+
const { test, add } = instance.exports
54+
// assert.eq(add(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 12);
55+
assert.eq(test(1), 12)
56+
}
57+
58+
assert.asyncTest(test())
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { instantiate } from "../wabt-wrapper.js"
2+
import * as assert from "../assert.js"
3+
4+
let wat = `
5+
(module
6+
(func $r2 (param i32 i32) (result i32)
7+
(local.get 0)
8+
(return)
9+
)
10+
(func (export "test") (result i32)
11+
(i32.const 1)
12+
(i32.const 2)
13+
(call $r2)
14+
(return)
15+
)
16+
)
17+
`
18+
19+
async function test() {
20+
const instance = await instantiate(wat, {});
21+
const { test } = instance.exports
22+
assert.eq(test(), 1)
23+
}
24+
25+
assert.asyncTest(test())

0 commit comments

Comments
 (0)