diff options
author | Thomas Lively <tlively@google.com> | 2023-01-03 15:02:54 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 15:02:54 -0600 |
commit | 938bf992f79257e938d37629e4859b1e09dbbe65 (patch) | |
tree | bed97cb717cb792404e1cbd2c5ea7bf4461ec669 /test | |
parent | 657431cdc36272a64b6b77465b68eaed2c7dfe31 (diff) | |
download | binaryen-938bf992f79257e938d37629e4859b1e09dbbe65.tar.gz binaryen-938bf992f79257e938d37629e4859b1e09dbbe65.tar.bz2 binaryen-938bf992f79257e938d37629e4859b1e09dbbe65.zip |
[Parser] Parse array creation and data segment instructions (#5374)
* [NFC][Parser] Track definition indices
For each definition in a module, record that definition's index in the relevant
index space. Previously the index was inferred from its position in a list of
module definitions, but that scheme does not scale to data segments defined
inline inside memory definitions because these data segments occupy a slot in
the data segment index space but do not have their own independent definitions.
* clarify comment
* [Parser] Parse data segments
Parse active and passive data segments, including all their variations and
abbreviations as well as data segments declared inline in memory declarations.
Switch to parsing data strings, memory limits, and memory types during the
ParseDecls phase so that the inline data segments can be completely parsed
during that phase and never revisited. Parsing the inline data segments in a
later phase would not work because they would be incorrectly inserted at the end
of the data segment index space.
Also update the printer to print a memory use on active data segments that are
initialized in a non-default memory.
* [Parser] Parse array creation and data segment instructions
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/wat-kitchen-sink.wast | 98 |
1 files changed, 90 insertions, 8 deletions
diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast index 124600e63..976be4401 100644 --- a/test/lit/wat-kitchen-sink.wast +++ b/test/lit/wat-kitchen-sink.wast @@ -5,10 +5,10 @@ (module $parse ;; types - ;; CHECK: (type $pair (struct (field (mut i32)) (field (mut i64)))) - ;; CHECK: (type $void (func)) + ;; CHECK: (type $pair (struct (field (mut i32)) (field (mut i64)))) + ;; CHECK: (type $none_=>_i32 (func (result i32))) ;; CHECK: (type $ret2 (func (result i32 i32))) @@ -17,8 +17,12 @@ (rec ;; CHECK: (type $i32_i64_=>_none (func (param i32 i64))) + ;; CHECK: (type $a1 (array i64)) + ;; CHECK: (type $i32_=>_none (func (param i32))) + ;; CHECK: (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) + ;; CHECK: (type $v128_i32_=>_v128 (func (param v128 i32) (result v128))) ;; CHECK: (type $many (func (param i32 i64 f32 f64) (result anyref (ref func)))) @@ -29,8 +33,6 @@ ;; CHECK: (type $i64_=>_none (func (param i64))) - ;; CHECK: (type $i32_i32_i32_=>_none (func (param i32 i32 i32))) - ;; CHECK: (type $v128_=>_i32 (func (param v128) (result i32))) ;; CHECK: (type $v128_v128_=>_v128 (func (param v128 v128) (result v128))) @@ -71,6 +73,12 @@ ;; CHECK: (type $ref|$pair|_i64_=>_none (func (param (ref $pair) i64))) + ;; CHECK: (type $i64_i32_=>_ref|$a1| (func (param i64 i32) (result (ref $a1)))) + + ;; CHECK: (type $i32_=>_ref|$a1| (func (param i32) (result (ref $a1)))) + + ;; CHECK: (type $i32_i32_=>_ref|$a1| (func (param i32 i32) (result (ref $a1)))) + ;; CHECK: (rec ;; CHECK-NEXT: (type $s0 (struct )) (type $s0 (sub (struct))) @@ -97,7 +105,6 @@ ;; CHECK: (type $a0 (array i32)) (type $a0 (array i32)) - ;; CHECK: (type $a1 (array i64)) (type $a1 (array (field i64))) ;; CHECK: (type $a2 (array (mut f32))) (type $a2 (array (mut f32))) @@ -1097,6 +1104,47 @@ v128.store64_lane 3 align=4 0 ) + ;; CHECK: (func $memory-init (type $i32_i32_i32_=>_none) (param $0 i32) (param $1 i32) (param $2 i32) + ;; CHECK-NEXT: (memory.init $mem-i32 2 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (memory.init $mem-i64 1 + ;; CHECK-NEXT: (i64.const 0) + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (memory.init $mem 0 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: (local.get $2) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $memory-init (param i32 i32 i32) + local.get 0 + local.get 1 + local.get 2 + memory.init $mem-i32 $passive + i64.const 0 + local.get 1 + local.get 2 + memory.init 3 1 + local.get 0 + local.get 1 + local.get 2 + memory.init 0 + ) + + ;; CHECK: (func $data-drop (type $void) + ;; CHECK-NEXT: (data.drop 0) + ;; CHECK-NEXT: (data.drop 2) + ;; CHECK-NEXT: ) + (func $data-drop + data.drop 0 + data.drop $passive + ) + ;; CHECK: (func $memory-copy (type $i32_i32_i64_i64_=>_none) (param $0 i32) (param $1 i32) (param $2 i64) (param $3 i64) ;; CHECK-NEXT: (memory.copy $mem $mem ;; CHECK-NEXT: (local.get $0) @@ -1319,7 +1367,7 @@ ;; CHECK-NEXT: (struct.new_default $pair) ;; CHECK-NEXT: ) (func $struct-new-default (result (ref $pair)) - struct.new_default $pair + struct.new_default 14 ) ;; CHECK: (func $struct-get-0 (type $ref|$pair|_=>_i32) (param $0 (ref $pair)) (result i32) @@ -1329,7 +1377,7 @@ ;; CHECK-NEXT: ) (func $struct-get-0 (param (ref $pair)) (result i32) local.get 0 - struct.get $pair 0 + struct.get 14 0 ) ;; CHECK: (func $struct-get-1 (type $ref|$pair|_=>_i64) (param $0 (ref $pair)) (result i64) @@ -1363,7 +1411,41 @@ (func $struct-set-1 (param (ref $pair) i64) local.get 0 local.get 1 - struct.set $pair 1 + struct.set 14 1 + ) + + ;; CHECK: (func $array-new (type $i64_i32_=>_ref|$a1|) (param $0 i64) (param $1 i32) (result (ref $a1)) + ;; CHECK-NEXT: (array.new $a1 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $array-new (param i64 i32) (result (ref 11)) + local.get 0 + local.get 1 + array.new $a1 + ) + + ;; CHECK: (func $array-new-default (type $i32_=>_ref|$a1|) (param $0 i32) (result (ref $a1)) + ;; CHECK-NEXT: (array.new_default $a1 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $array-new-default (param i32) (result (ref $a1)) + local.get 0 + array.new_default 11 + ) + + ;; CHECK: (func $array-new-data (type $i32_i32_=>_ref|$a1|) (param $0 i32) (param $1 i32) (result (ref $a1)) + ;; CHECK-NEXT: (array.new_data $a1 0 + ;; CHECK-NEXT: (local.get $0) + ;; CHECK-NEXT: (local.get $1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $array-new-data (param i32 i32) (result (ref $a1)) + local.get 0 + local.get 1 + array.new_data $a1 0 ) ;; CHECK: (func $use-types (type $ref|$s0|_ref|$s1|_ref|$s2|_ref|$s3|_ref|$s4|_ref|$s5|_ref|$s6|_ref|$s7|_ref|$s8|_ref|$a0|_ref|$a1|_ref|$a2|_ref|$a3|_ref|$subvoid|_ref|$submany|_=>_none) (param $0 (ref $s0)) (param $1 (ref $s1)) (param $2 (ref $s2)) (param $3 (ref $s3)) (param $4 (ref $s4)) (param $5 (ref $s5)) (param $6 (ref $s6)) (param $7 (ref $s7)) (param $8 (ref $s8)) (param $9 (ref $a0)) (param $10 (ref $a1)) (param $11 (ref $a2)) (param $12 (ref $a3)) (param $13 (ref $subvoid)) (param $14 (ref $submany)) |