;; Test `br_if` operator (module (func $dummy) (func (export "type-i32-value") (result i32) (block (result i32) (i32.ctz (br_if 0 (i32.const 1) (i32.const 1)))) ) (func (export "type-i64-value") (result i64) (block (result i64) (i64.ctz (br_if 0 (i64.const 2) (i32.const 1)))) ) (func (export "as-block-first") (param i32) (result i32) (block (br_if 0 (local.get 0)) (return (i32.const 2))) (i32.const 3) ) (func (export "as-block-mid") (param i32) (result i32) (block (call $dummy) (br_if 0 (local.get 0)) (return (i32.const 2))) (i32.const 3) ) (func (export "as-block-last") (param i32) (block (call $dummy) (call $dummy) (br_if 0 (local.get 0))) ) (func (export "as-block-last-value") (param i32) (result i32) (block (result i32) (call $dummy) (call $dummy) (br_if 0 (i32.const 11) (local.get 0)) ) ) (func (export "as-loop-first") (param i32) (result i32) (block (loop (br_if 1 (local.get 0)) (return (i32.const 2)))) (i32.const 3) ) (func (export "as-loop-mid") (param i32) (result i32) (block (loop (call $dummy) (br_if 1 (local.get 0)) (return (i32.const 2)))) (i32.const 4) ) (func (export "as-loop-last") (param i32) (loop (call $dummy) (br_if 1 (local.get 0))) ) (func (export "as-br-value") (result i32) (block (result i32) (br 0 (br_if 0 (i32.const 1) (i32.const 2)))) ) (func (export "as-br_if-cond") (block (br_if 0 (br_if 0 (i32.const 1) (i32.const 1)))) ) (func (export "as-return-value") (result i64) (block (result i64) (return (br_if 0 (i64.const 1) (i32.const 2)))) ) (func (export "as-if-cond") (param i32) (result i32) (block (result i32) (if (result i32) (br_if 0 (i32.const 1) (local.get 0)) (then (i32.const 2)) (else (i32.const 3)) ) ) ) (func (export "as-if-then") (param i32 i32) (block (if (local.get 0) (then (br_if 1 (local.get 1))) (else (call $dummy))) ) ) (func (export "as-if-else") (param i32 i32) (block (if (local.get 0) (then (call $dummy)) (else (br_if 1 (local.get 1)))) ) ) (func $f (param i32 i32 i32) (result i32) (i32.const -1)) (func (export "as-call-first") (result i32) (block (result i32) (call $f (br_if 0 (i32.const 12) (i32.const 1)) (i32.const 2) (i32.const 3) ) ) ) (func (export "as-call-mid") (result i32) (block (result i32) (call $f (i32.const 1) (br_if 0 (i32.const 13) (i32.const 1)) (i32.const 3) ) ) ) (func (export "as-call-last") (result i32) (block (result i32) (call $f (i32.const 1) (i32.const 2) (br_if 0 (i32.const 14) (i32.const 1)) ) ) ) (func (export "as-local.set-value") (param i32) (result i32) (local i32) (block (result i32) (local.set 0 (br_if 0 (i32.const 17) (local.get 0))) (i32.const -1) ) ) (func (export "as-binary-left") (result i32) (block (result i32) (i32.add (br_if 0 (i32.const 1) (i32.const 1)) (i32.const 10))) ) (func (export "as-binary-right") (result i32) (block (result i32) (i32.sub (i32.const 10) (br_if 0 (i32.const 1) (i32.const 1)))) ) (func (export "as-test-operand") (result i32) (block (result i32) (i32.eqz (br_if 0 (i32.const 0) (i32.const 1)))) ) (func (export "as-compare-left") (result i32) (block (result i32) (i32.le_u (br_if 0 (i32.const 1) (i32.const 1)) (i32.const 10))) ) (func (export "as-compare-right") (result i32) (block (result i32) (i32.ne (i32.const 10) (br_if 0 (i32.const 1) (i32.const 42)))) ) ) (assert_return (invoke "type-i32-value") (i32.const 1)) (assert_return (invoke "type-i64-value") (i64.const 2)) (assert_return (invoke "as-block-first" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-block-first" (i32.const 1)) (i32.const 3)) (assert_return (invoke "as-block-mid" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-block-mid" (i32.const 1)) (i32.const 3)) (assert_return (invoke "as-block-last" (i32.const 0))) (assert_return (invoke "as-block-last" (i32.const 1))) (assert_return (invoke "as-block-last-value" (i32.const 0)) (i32.const 11)) (assert_return (invoke "as-block-last-value" (i32.const 1)) (i32.const 11)) (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 3)) (assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 4)) (assert_return (invoke "as-loop-last" (i32.const 0))) (assert_return (invoke "as-loop-last" (i32.const 1))) (assert_return (invoke "as-br-value") (i32.const 1)) (assert_return (invoke "as-br_if-cond")) (assert_return (invoke "as-return-value") (i64.const 1)) (assert_return (invoke "as-if-cond" (i32.const 0)) (i32.const 2)) (assert_return (invoke "as-if-cond" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-if-then" (i32.const 0) (i32.const 0))) (assert_return (invoke "as-if-then" (i32.const 4) (i32.const 0))) (assert_return (invoke "as-if-then" (i32.const 0) (i32.const 1))) (assert_return (invoke "as-if-then" (i32.const 4) (i32.const 1))) (assert_return (invoke "as-if-else" (i32.const 0) (i32.const 0))) (assert_return (invoke "as-if-else" (i32.const 3) (i32.const 0))) (assert_return (invoke "as-if-else" (i32.const 0) (i32.const 1))) (assert_return (invoke "as-if-else" (i32.const 3) (i32.const 1))) (assert_return (invoke "as-call-first") (i32.const 12)) (assert_return (invoke "as-call-mid") (i32.const 13)) (assert_return (invoke "as-call-last") (i32.const 14)) (assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const -1)) (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 17)) (assert_return (invoke "as-binary-left") (i32.const 1)) (assert_return (invoke "as-binary-right") (i32.const 1)) (assert_return (invoke "as-test-operand") (i32.const 0)) (assert_return (invoke "as-compare-left") (i32.const 1)) (assert_return (invoke "as-compare-right") (i32.const 1))