diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-09-24 12:02:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-24 12:02:09 +0200 |
commit | e9e1b2ff00aeb05aaeb57af3811add267dc25323 (patch) | |
tree | 4e19032813858b2e650f0cda46fe9fa227aa0a7f /test/binaryen.js | |
parent | a42423fafa8cf731c69303ddc0acbe80c890e0ab (diff) | |
download | binaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.tar.gz binaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.tar.bz2 binaryen-e9e1b2ff00aeb05aaeb57af3811add267dc25323.zip |
GC: Add i31 instructions (#3154)
Adds the `i31.new` and `i31.get_s/u` instructions for creating and working with `i31ref` typed values. Does not include fuzzer integration just yet because the fuzzer expects that trivial values it creates are suitable in global initializers, which is not the case for trivial `i31ref` expressions.
Diffstat (limited to 'test/binaryen.js')
-rw-r--r-- | test/binaryen.js/expressions.js | 57 | ||||
-rw-r--r-- | test/binaryen.js/expressions.js.txt | 10 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js | 19 | ||||
-rw-r--r-- | test/binaryen.js/kitchen-sink.js.txt | 42 |
4 files changed, 128 insertions, 0 deletions
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index a97097afe..0d48e5551 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1649,3 +1649,60 @@ console.log("# TupleExtract"); module.dispose(); })(); + +console.log("# I31New"); +(function testI31New() { + const module = new binaryen.Module(); + + var value = module.local.get(1, binaryen.i32); + const theI31New = binaryen.I31New(module.i31.new(value)); + assert(theI31New instanceof binaryen.I31New); + assert(theI31New instanceof binaryen.Expression); + assert(theI31New.value === value); + assert(theI31New.type === binaryen.i31ref); + + theI31New.value = value = module.local.get(2, binaryen.i32); + assert(theI31New.value === value); + theI31New.type = binaryen.f64; + theI31New.finalize(); + assert(theI31New.type === binaryen.i31ref); + + console.log(theI31New.toText()); + assert( + theI31New.toText() + == + "(i31.new\n (local.get $2)\n)\n" + ); + + module.dispose(); +})(); + +console.log("# I31Get"); +(function testI31Get() { + const module = new binaryen.Module(); + + var i31 = module.local.get(1, binaryen.i31ref); + const theI31Get = binaryen.I31Get(module.i31.get_s(i31)); + assert(theI31Get instanceof binaryen.I31Get); + assert(theI31Get instanceof binaryen.Expression); + assert(theI31Get.i31 === i31); + assert(theI31Get.signed === true); + assert(theI31Get.type === binaryen.i32); + + theI31Get.i31 = i31 = module.local.get(2, binaryen.i31ref); + assert(theI31Get.i31 === i31); + theI31Get.signed = false; + assert(theI31Get.signed === false); + theI31Get.type = binaryen.f64; + theI31Get.finalize(); + assert(theI31Get.type === binaryen.i32); + + console.log(theI31Get.toText()); + assert( + theI31Get.toText() + == + "(i31.get_u\n (local.get $2)\n)\n" + ); + + module.dispose(); +})(); diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt index 22c4f2747..e2b34e501 100644 --- a/test/binaryen.js/expressions.js.txt +++ b/test/binaryen.js/expressions.js.txt @@ -256,3 +256,13 @@ ) ) +# I31New +(i31.new + (local.get $2) +) + +# I31Get +(i31.get_u + (local.get $2) +) + diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index f699e96e0..051f53c54 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -165,6 +165,10 @@ function test_ids() { console.log("ThrowId: " + binaryen.ThrowId); console.log("RethrowId: " + binaryen.RethrowId); console.log("BrOnExnId: " + binaryen.BrOnExnId); + console.log("TupleMakeId: " + binaryen.TupleMakeId); + console.log("TupleExtractId: " + binaryen.TupleExtractId); + console.log("I31NewId: " + binaryen.I31NewId); + console.log("I31GetId: " + binaryen.I31GetId); } function test_core() { @@ -595,6 +599,21 @@ function test_core() { module.memory.size(), module.memory.grow(makeInt32(0)), + // GC + module.i31.new( + module.i32.const(0) + ), + module.i31.get_s( + module.i31.new( + module.i32.const(1) + ) + ), + module.i31.get_u( + module.i31.new( + module.i32.const(2) + ) + ), + // Other module.nop(), module.unreachable(), diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 1c11e787e..9fca3ae53 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -89,6 +89,10 @@ TryId: 44 ThrowId: 45 RethrowId: 46 BrOnExnId: 47 +TupleMakeId: 48 +TupleExtractId: 49 +I31NewId: 50 +I31GetId: 51 getExpressionInfo={"id":15,"type":4,"op":6} (f32.neg (f32.const -33.61199951171875) @@ -1952,6 +1956,25 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) + (drop + (i31.new + (i32.const 0) + ) + ) + (drop + (i31.get_s + (i31.new + (i32.const 1) + ) + ) + ) + (drop + (i31.get_u + (i31.new + (i32.const 2) + ) + ) + ) (nop) (unreachable) ) @@ -3815,6 +3838,25 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) + (drop + (i31.new + (i32.const 0) + ) + ) + (drop + (i31.get_s + (i31.new + (i32.const 1) + ) + ) + ) + (drop + (i31.get_u + (i31.new + (i32.const 2) + ) + ) + ) (nop) (unreachable) ) |