summaryrefslogtreecommitdiff
path: root/test/let.wasm.fromBinary
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-01-15 18:13:05 +0000
committerGitHub <noreply@github.com>2021-01-15 10:13:05 -0800
commite2dc4c338476aedff8d95c7549ab0f39d1aaf6d1 (patch)
treefa6fc4184c5ee762ccdc861a1f1c52188a7a3dc5 /test/let.wasm.fromBinary
parentd808e900b8b8a0bc99d77fd38e94426df73c3afa (diff)
downloadbinaryen-e2dc4c338476aedff8d95c7549ab0f39d1aaf6d1.tar.gz
binaryen-e2dc4c338476aedff8d95c7549ab0f39d1aaf6d1.tar.bz2
binaryen-e2dc4c338476aedff8d95c7549ab0f39d1aaf6d1.zip
[GC] Read and lower Let instructions (#3485)
For now we don't support non-nullability, and can therefore lower a let into simpler things. That is, (let $x = ... ;; ) => (block $x = ... ;; ) This lets us handle wasm binaries with let, so that we can optimize them (with the current downside of losing non-nullability). This is still not trivial to do, sadly, because the indexing of lets is somewhat odd in the binary. A let modifies the indexes of other things declared before it, which means that index "0" means different things at different times. And this is trickier for us because we add more locals as needed for tuples and stacky code. So this PR makes us track the absolute local indexes from which each let started to allocate its locals. The binary testcase was created from this wat using wasp: (module (type $vector (array (field (mut f64)))) (func $main (local $x i32) (local $y i32) (drop (local.get $x)) ;; 0 is the index appearing in the binary ;; first let (array.new_with_rtt $vector (f64.const 3.14159) (i32.const 1) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ;; another one, nested (array.new_with_rtt $vector (f64.const 1234) (i32.const 2) (rtt.canon $vector) ) (let (local $w (ref $vector)) (drop (local.get $v)) ;; 1 (drop (local.get $w)) ;; 0 (drop (local.get $x)) ;; 2 ) ) ;; another one, later (array.new_with_rtt $vector (f64.const 2.1828) (i32.const 3) (rtt.canon $vector) ) (let (local $v (ref $vector)) (drop (local.get $v)) ;; 0 (drop (local.get $x)) ;; 1 ) (drop (local.get $x)) ;; 0 ) )
Diffstat (limited to 'test/let.wasm.fromBinary')
-rw-r--r--test/let.wasm.fromBinary72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/let.wasm.fromBinary b/test/let.wasm.fromBinary
new file mode 100644
index 000000000..1de54a96d
--- /dev/null
+++ b/test/let.wasm.fromBinary
@@ -0,0 +1,72 @@
+(module
+ (type $[mut:f64] (array (mut f64)))
+ (type $none_=>_none (func))
+ (func $0
+ (local $0 i32)
+ (local $1 i32)
+ (local $2 (ref null $[mut:f64]))
+ (local $3 (ref null $[mut:f64]))
+ (local $4 (ref null $[mut:f64]))
+ (drop
+ (local.get $0)
+ )
+ (block
+ (local.set $2
+ (array.new_with_rtt $[mut:f64]
+ (rtt.canon $[mut:f64])
+ (i32.const 1)
+ (f64.const 3.14159)
+ )
+ )
+ (block
+ (drop
+ (local.get $2)
+ )
+ (drop
+ (local.get $0)
+ )
+ (block
+ (local.set $3
+ (array.new_with_rtt $[mut:f64]
+ (rtt.canon $[mut:f64])
+ (i32.const 2)
+ (f64.const 1234)
+ )
+ )
+ (block
+ (drop
+ (local.get $2)
+ )
+ (drop
+ (local.get $3)
+ )
+ (drop
+ (local.get $0)
+ )
+ )
+ )
+ )
+ )
+ (block
+ (local.set $4
+ (array.new_with_rtt $[mut:f64]
+ (rtt.canon $[mut:f64])
+ (i32.const 3)
+ (f64.const 2.1828)
+ )
+ )
+ (block
+ (drop
+ (local.get $4)
+ )
+ (drop
+ (local.get $0)
+ )
+ )
+ )
+ (drop
+ (local.get $0)
+ )
+ )
+)
+