Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winch: Add support for br_table #6951

Merged
merged 4 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/differential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ fn winch_supports_module(module: &[u8]) -> bool {
| Loop { .. }
| Br { .. }
| BrIf { .. }
| BrTable { .. }
| Unreachable { .. }
| Return { .. }
| F32Const { .. }
Expand Down
33 changes: 33 additions & 0 deletions tests/misc_testsuite/winch/block.wast
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
)
)

(func (export "as-br_table-first") (result i32)
(block (result i32) (block (result i32) (i32.const 1)) (i32.const 2) (br_table 0 0))
)
(func (export "as-br_table-last") (result i32)
(block (result i32) (i32.const 2) (block (result i32) (i32.const 1)) (br_table 0 0))
)

(func (export "break-bare") (result i32)
(block (br 0) (unreachable))
(block (br_if 0 (i32.const 1)) (unreachable))
(block (br_table 0 (i32.const 0)) (unreachable))
(block (br_table 0 0 0 (i32.const 1)) (unreachable))
(i32.const 19)
)

(func (export "break-repeated") (result i32)
(block (result i32)
(br 0 (i32.const 18))
(br 0 (i32.const 19))
(drop (br_if 0 (i32.const 20) (i32.const 0)))
(drop (br_if 0 (i32.const 20) (i32.const 1)))
(br 0 (i32.const 21))
(br_table 0 (i32.const 22) (i32.const 4))
(br_table 0 0 0 (i32.const 23) (i32.const 1))
(i32.const 21)
)
)

(func (export "deep") (result i32)
(block (result i32) (block (result i32)
(block (result i32) (block (result i32)
Expand Down Expand Up @@ -163,3 +191,8 @@
(assert_return (invoke "as-test-operand") (i32.const 0))
(assert_return (invoke "break-inner") (i32.const 0xf))
(assert_return (invoke "effects") (i32.const 1))

(assert_return (invoke "as-br_table-first") (i32.const 1))
(assert_return (invoke "as-br_table-last") (i32.const 2))
(assert_return (invoke "break-bare") (i32.const 19))
(assert_return (invoke "break-repeated") (i32.const 18))
47 changes: 47 additions & 0 deletions tests/misc_testsuite/winch/br.wast
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,47 @@
)
)
)

(func (export "as-br_table-index")
(block (br_table 0 0 0 (br 0)))
)
(func (export "as-br_table-value") (result i32)
(block (result i32)
(br_table 0 0 0 (br 0 (i32.const 10)) (i32.const 1)) (i32.const 7)
)
)
(func (export "as-br_table-value-index") (result i32)
(block (result i32)
(br_table 0 0 (i32.const 6) (br 0 (i32.const 11))) (i32.const 7)
)
)

(func (export "nested-br_table-value") (result i32)
(i32.add
(i32.const 1)
(block (result i32)
(drop (i32.const 2))
(drop
(block (result i32)
(drop (i32.const 4))
(br_table 0 (br 1 (i32.const 8)) (i32.const 1))
)
)
(i32.const 16)
)
)
)

(func (export "nested-br_table-value-index") (result i32)
(i32.add
(i32.const 1)
(block (result i32)
(drop (i32.const 2))
(br_table 0 (i32.const 4) (br 0 (i32.const 8)))
(i32.const 16)
)
)
)
)

(assert_return (invoke "type-i32-value") (i32.const 1))
Expand Down Expand Up @@ -213,3 +254,9 @@
(assert_return (invoke "nested-br-value") (i32.const 9))
(assert_return (invoke "nested-br_if-value") (i32.const 9))
(assert_return (invoke "nested-br_if-value-cond") (i32.const 9))

(assert_return (invoke "as-br_table-index"))
(assert_return (invoke "as-br_table-value") (i32.const 10))
(assert_return (invoke "as-br_table-value-index") (i32.const 11))
(assert_return (invoke "nested-br_table-value") (i32.const 9))
(assert_return (invoke "nested-br_table-value-index") (i32.const 9))
55 changes: 55 additions & 0 deletions tests/misc_testsuite/winch/br_if.wast
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,52 @@
)
)
)

(func (export "as-br_table-index")
(block (br_table 0 0 0 (br_if 0 (i32.const 1) (i32.const 2))))
)
(func (export "as-br_table-value") (result i32)
(block (result i32)
(br_table 0 0 0 (br_if 0 (i32.const 1) (i32.const 2)) (i32.const 3)) (i32.const 4)
)
)
(func (export "as-br_table-value-index") (result i32)
(block (result i32)
(br_table 0 0 (i32.const 2) (br_if 0 (i32.const 1) (i32.const 3))) (i32.const 4)
)
)

(func (export "nested-br_table-value") (param i32) (result i32)
(i32.add
(i32.const 1)
(block (result i32)
(drop (i32.const 2))
(br_table 0
(block (result i32)
(drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 4)
)
(i32.const 1)
)
(i32.const 16)
)
)
)

(func (export "nested-br_table-value-index") (param i32) (result i32)
(i32.add
(i32.const 1)
(block (result i32)
(drop (i32.const 2))
(br_table 0
(i32.const 4)
(block (result i32)
(drop (br_if 1 (i32.const 8) (local.get 0))) (i32.const 1)
)
)
(i32.const 16)
)
)
)
)


Expand Down Expand Up @@ -260,3 +306,12 @@
(assert_return (invoke "nested-br_if-value" (i32.const 1)) (i32.const 9))
(assert_return (invoke "nested-br_if-value-cond" (i32.const 0)) (i32.const 5))
(assert_return (invoke "nested-br_if-value-cond" (i32.const 1)) (i32.const 9))

(assert_return (invoke "as-br_table-index"))
(assert_return (invoke "as-br_table-value") (i32.const 1))
(assert_return (invoke "as-br_table-value-index") (i32.const 1))

(assert_return (invoke "nested-br_table-value" (i32.const 0)) (i32.const 5))
(assert_return (invoke "nested-br_table-value" (i32.const 1)) (i32.const 9))
(assert_return (invoke "nested-br_table-value-index" (i32.const 0)) (i32.const 5))
(assert_return (invoke "nested-br_table-value-index" (i32.const 1)) (i32.const 9))
Loading