diff options
author | Alon Zakai <azakai@google.com> | 2024-06-10 16:02:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 16:02:00 -0700 |
commit | 0a1a59af573414a20fe457fd77b732729aa92fb2 (patch) | |
tree | 9639e7d7946f6d63737703d5c032ff85d4d2be79 /test/wasm2js | |
parent | 76d1ac3e9c5abfe589bcdfc84b89f263bac7c574 (diff) | |
download | binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.tar.gz binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.tar.bz2 binaryen-0a1a59af573414a20fe457fd77b732729aa92fb2.zip |
wasm2js: Add basic reference operations (#6648)
This adds ref.eq, ref.null, ref.is_null, ref.func.
Diffstat (limited to 'test/wasm2js')
-rw-r--r-- | test/wasm2js/refs.2asm.js | 44 | ||||
-rw-r--r-- | test/wasm2js/refs.2asm.js.opt | 42 | ||||
-rw-r--r-- | test/wasm2js/refs.wast | 33 |
3 files changed, 119 insertions, 0 deletions
diff --git a/test/wasm2js/refs.2asm.js b/test/wasm2js/refs.2asm.js new file mode 100644 index 000000000..0133159b9 --- /dev/null +++ b/test/wasm2js/refs.2asm.js @@ -0,0 +1,44 @@ + +function asmFunc(imports) { + 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 null_() { + return null; + } + + function is_null(ref) { + return ref == null | 0; + } + + function ref_func() { + var ref_func_1 = 0; + ref_func_1 = ref_func_1 + 1 | 0; + return ref_func; + } + + function ref_eq(x, y) { + return x == y | 0; + } + + return { + "null_": null_, + "is_null": is_null, + "ref_func": ref_func, + "ref_eq": ref_eq + }; +} + +var retasmFunc = asmFunc({ +}); +export var null_ = retasmFunc.null_; +export var is_null = retasmFunc.is_null; +export var ref_func = retasmFunc.ref_func; +export var ref_eq = retasmFunc.ref_eq; diff --git a/test/wasm2js/refs.2asm.js.opt b/test/wasm2js/refs.2asm.js.opt new file mode 100644 index 000000000..e38afe1cf --- /dev/null +++ b/test/wasm2js/refs.2asm.js.opt @@ -0,0 +1,42 @@ + +function asmFunc(imports) { + 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 null_() { + return null; + } + + function is_null($0) { + return $0 == null | 0; + } + + function ref_func() { + return ref_func; + } + + function ref_eq($0, $1) { + return $0 == $1 | 0; + } + + return { + "null_": null_, + "is_null": is_null, + "ref_func": ref_func, + "ref_eq": ref_eq + }; +} + +var retasmFunc = asmFunc({ +}); +export var null_ = retasmFunc.null_; +export var is_null = retasmFunc.is_null; +export var ref_func = retasmFunc.ref_func; +export var ref_eq = retasmFunc.ref_eq; diff --git a/test/wasm2js/refs.wast b/test/wasm2js/refs.wast new file mode 100644 index 000000000..4e133c03e --- /dev/null +++ b/test/wasm2js/refs.wast @@ -0,0 +1,33 @@ +(module + (func $null (export "null") (result anyref) + (ref.null any) + ) + + (func $is_null (export "is_null") (param $ref anyref) (result i32) + (ref.is_null + (local.get $ref) + ) + ) + + (func $ref.func (export "ref.func") (result funcref) + ;; Test that we are aware that "$ref.func" below refers to the function and + ;; not the local. This code will keep the local around (at least in an + ;; unoptimized build), and it should use a different name than the function. + (local $ref.func i32) + (local.set $ref.func + (i32.add + (local.get $ref.func) + (i32.const 1) + ) + ) + + (ref.func $ref.func) + ) + + (func $ref.eq (export "ref.eq") (param $x eqref) (param $y eqref) (result i32) + (ref.eq + (local.get $x) + (local.get $y) + ) + ) +) |