diff options
Diffstat (limited to 'test/wasm2js')
-rw-r--r-- | test/wasm2js/tables.2asm.js | 89 | ||||
-rw-r--r-- | test/wasm2js/tables.2asm.js.opt | 89 | ||||
-rw-r--r-- | test/wasm2js/tables.wast | 46 |
3 files changed, 224 insertions, 0 deletions
diff --git a/test/wasm2js/tables.2asm.js b/test/wasm2js/tables.2asm.js new file mode 100644 index 000000000..a7dd8fdd5 --- /dev/null +++ b/test/wasm2js/tables.2asm.js @@ -0,0 +1,89 @@ +import * as env from 'env'; + + + function wasm2js_table_grow(value, delta) { + // TODO: traps on invalid things + var oldSize = FUNCTION_TABLE.length; + FUNCTION_TABLE.length = oldSize + delta; + if (newSize > oldSize) { + __wasm_table_fill(oldSize, value, delta) + } + return oldSize; + } + + function __wasm_table_fill(dest, value, size) { + // TODO: traps on invalid things + for (var i = 0; i < size; i++) { + FUNCTION_TABLE[dest + i] = value; + } + } + + function __wasm_table_copy(dest, source, size) { + // TODO: traps on invalid things + for (var i = 0; i < size; i++) { + FUNCTION_TABLE[dest + i] = FUNCTION_TABLE[source + i]; + } + } + +function asmFunc(imports) { + var env = imports.env; + var FUNCTION_TABLE = env.table; + var Math_imul = Math.imul; + var Math_fround = Math.fround; + var Math_abs = Math.abs; + var Math_clz32 = Math.clz32; + var Math_min = Math.min; + var Math_max = Math.max; + var Math_floor = Math.floor; + var Math_ceil = Math.ceil; + var Math_trunc = Math.trunc; + var Math_sqrt = Math.sqrt; + function table_get() { + return FUNCTION_TABLE[1]; + } + + function table_set() { + FUNCTION_TABLE[1] = table_set; + } + + function table_size() { + return FUNCTION_TABLE.length | 0; + } + + function table_grow() { + return wasm2js_table_grow(table_grow, 42) | 0; + } + + function table_fill(dest, value, size) { + dest = dest | 0; + size = size | 0; + wasm2js_table_fill(dest, value, size); + } + + function table_copy(dest, source, size) { + dest = dest | 0; + source = source | 0; + size = size | 0; + wasm2js_table_copy(dest, source, size); + } + + FUNCTION_TABLE[1] = table_get; + return { + "table_get": table_get, + "table_set": table_set, + "table_size": table_size, + "table_grow": table_grow, + "table_fill": table_fill, + "table_copy": table_copy + }; +} + +var retasmFunc = asmFunc({ + "env": env, +}); +export var table_get = retasmFunc.table_get; +export var table_set = retasmFunc.table_set; +export var table_size = retasmFunc.table_size; +export var table_grow = retasmFunc.table_grow; +export var table_fill = retasmFunc.table_fill; +export var table_copy = retasmFunc.table_copy; diff --git a/test/wasm2js/tables.2asm.js.opt b/test/wasm2js/tables.2asm.js.opt new file mode 100644 index 000000000..f15b0cb11 --- /dev/null +++ b/test/wasm2js/tables.2asm.js.opt @@ -0,0 +1,89 @@ +import * as env from 'env'; + + + function wasm2js_table_grow(value, delta) { + // TODO: traps on invalid things + var oldSize = FUNCTION_TABLE.length; + FUNCTION_TABLE.length = oldSize + delta; + if (newSize > oldSize) { + __wasm_table_fill(oldSize, value, delta) + } + return oldSize; + } + + function __wasm_table_fill(dest, value, size) { + // TODO: traps on invalid things + for (var i = 0; i < size; i++) { + FUNCTION_TABLE[dest + i] = value; + } + } + + function __wasm_table_copy(dest, source, size) { + // TODO: traps on invalid things + for (var i = 0; i < size; i++) { + FUNCTION_TABLE[dest + i] = FUNCTION_TABLE[source + i]; + } + } + +function asmFunc(imports) { + var env = imports.env; + var FUNCTION_TABLE = env.table; + var Math_imul = Math.imul; + var Math_fround = Math.fround; + var Math_abs = Math.abs; + var Math_clz32 = Math.clz32; + var Math_min = Math.min; + var Math_max = Math.max; + var Math_floor = Math.floor; + var Math_ceil = Math.ceil; + var Math_trunc = Math.trunc; + var Math_sqrt = Math.sqrt; + function table_get() { + return FUNCTION_TABLE[1]; + } + + function table_set() { + FUNCTION_TABLE[1] = table_set; + } + + function table_size() { + return FUNCTION_TABLE.length | 0; + } + + function table_grow() { + return wasm2js_table_grow(table_grow, 42) | 0; + } + + function table_fill($0, $1, $2) { + $0 = $0 | 0; + $2 = $2 | 0; + wasm2js_table_fill($0, $1, $2); + } + + function table_copy($0, $1, $2) { + $0 = $0 | 0; + $1 = $1 | 0; + $2 = $2 | 0; + wasm2js_table_copy($0, $1, $2); + } + + FUNCTION_TABLE[1] = table_get; + return { + "table_get": table_get, + "table_set": table_set, + "table_size": table_size, + "table_grow": table_grow, + "table_fill": table_fill, + "table_copy": table_copy + }; +} + +var retasmFunc = asmFunc({ + "env": env, +}); +export var table_get = retasmFunc.table_get; +export var table_set = retasmFunc.table_set; +export var table_size = retasmFunc.table_size; +export var table_grow = retasmFunc.table_grow; +export var table_fill = retasmFunc.table_fill; +export var table_copy = retasmFunc.table_copy; diff --git a/test/wasm2js/tables.wast b/test/wasm2js/tables.wast new file mode 100644 index 000000000..56e85e40d --- /dev/null +++ b/test/wasm2js/tables.wast @@ -0,0 +1,46 @@ +(module + (import "env" "table" (table $table 7 funcref)) + + (elem (i32.const 1) $table.get) + + (func $table.get (export "table.get") (result funcref) + (table.get $table + (i32.const 1) + ) + ) + + (func $table.set (export "table.set") + (table.set $table + (i32.const 1) + (ref.func $table.set) + ) + ) + + (func $table.size (export "table.size") (result i32) + (table.size $table) + ) + + (func $table.grow (export "table.grow") (result i32) + (table.grow $table + (ref.func $table.grow) + (i32.const 42) + ) + ) + + (func $table.fill (export "table.fill") (param $dest i32) (param $value funcref) (param $size i32) + (table.fill $table + (local.get $dest) + (local.get $value) + (local.get $size) + ) + ) + + (func $table.copy (export "table.copy") (param $dest i32) (param $source i32) (param $size i32) + (table.copy $table $table + (local.get $dest) + (local.get $source) + (local.get $size) + ) + ) +) + |