;; Test `if` operator (module ;; Auxiliary definition (memory 1) (func $dummy) (func (export "empty") (param i32) (if (local.get 0) (then)) (if (local.get 0) (then) (else)) (if $l (local.get 0) (then)) (if $l (local.get 0) (then) (else)) ) (func (export "singular") (param i32) (result i32) (if (local.get 0) (then (nop))) (if (local.get 0) (then (nop)) (else (nop))) (if (result i32) (local.get 0) (then (i32.const 7)) (else (i32.const 8))) ) (func (export "nested") (param i32 i32) (result i32) (if (result i32) (local.get 0) (then (if (local.get 1) (then (call $dummy) (block) (nop))) (if (local.get 1) (then) (else (call $dummy) (block) (nop))) (if (result i32) (local.get 1) (then (call $dummy) (i32.const 9)) (else (call $dummy) (i32.const 10)) ) ) (else (if (local.get 1) (then (call $dummy) (block) (nop))) (if (local.get 1) (then) (else (call $dummy) (block) (nop))) (if (result i32) (local.get 1) (then (call $dummy) (i32.const 10)) (else (call $dummy) (i32.const 11)) ) ) ) ) (func (export "as-loop-first") (param i32) (result i32) (loop (result i32) (if (result i32) (local.get 0) (then (call $dummy) (i32.const 1)) (else (call $dummy) (i32.const 0)) ) (call $dummy) (call $dummy) ) ) (func (export "as-loop-mid") (param i32) (result i32) (loop (result i32) (call $dummy) (if (result i32) (local.get 0) (then (call $dummy) (i32.const 1)) (else (call $dummy) (i32.const 0)) ) (call $dummy) ) ) (func (export "as-loop-last") (param i32) (result i32) (loop (result i32) (call $dummy) (call $dummy) (if (result i32) (local.get 0) (then (call $dummy) (i32.const 1)) (else (call $dummy) (i32.const 0)) ) ) ) (func (export "as-if-condition") (param i32) (result i32) (if (result i32) (if (result i32) (local.get 0) (then (i32.const 1)) (else (i32.const 0)) ) (then (call $dummy) (i32.const 2)) (else (call $dummy) (i32.const 3)) ) ) (func (export "as-br_if-first") (param i32) (result i32) (block (result i32) (br_if 0 (if (result i32) (local.get 0) (then (call $dummy) (i32.const 1)) (else (call $dummy) (i32.const 0)) ) (i32.const 2) ) (return (i32.const 3)) ) ) (func (export "as-br_if-last") (param i32) (result i32) (block (result i32) (br_if 0 (i32.const 2) (if (result i32) (local.get 0) (then (call $dummy) (i32.const 1)) (else (call $dummy) (i32.const 0)) ) ) (return (i32.const 3)) ) ) (func $f (param i32) (result i32) (local.get 0)) (func (export "as-call-value") (param i32) (result i32) (call $f (if (result i32) (local.get 0) (then (i32.const 1)) (else (i32.const 0)) ) ) ) (func (export "as-return-value") (param i32) (result i32) (if (result i32) (local.get 0) (then (i32.const 1)) (else (i32.const 0))) (return) ) (func (export "as-br-value") (param i32) (result i32) (block (result i32) (br 0 (if (result i32) (local.get 0) (then (i32.const 1)) (else (i32.const 0)) ) ) ) ) (func (export "as-local.set-value") (param i32) (result i32) (local i32) (local.set 0 (if (result i32) (local.get 0) (then (i32.const 1)) (else (i32.const 0)) ) ) (local.get 0) ) (func (export "as-unary-operand") (param i32) (result i32) (i32.ctz (if (result i32) (local.get 0) (then (call $dummy) (i32.const 13)) (else (call $dummy) (i32.const -13)) ) ) ) (func (export "as-binary-operand") (param i32 i32) (result i32) (i32.mul (if (result i32) (local.get 0) (then (call $dummy) (i32.const 3)) (else (call $dummy) (i32.const -3)) ) (if (result i32) (local.get 1) (then (call $dummy) (i32.const 4)) (else (call $dummy) (i32.const -5)) ) ) ) (func (export "as-test-operand") (param i32) (result i32) (i32.eqz (if (result i32) (local.get 0) (then (call $dummy) (i32.const 13)) (else (call $dummy) (i32.const 0)) ) ) ) (func (export "break-value") (param i32) (result i32) (if (result i32) (local.get 0) (then (br 0 (i32.const 18)) (i32.const 19)) (else (br 0 (i32.const 21)) (i32.const 20)) ) ) (func (export "effects") (param i32) (result i32) (local i32) (if (block (result i32) (local.set 1 (i32.const 1)) (local.get 0)) (then (local.set 1 (i32.mul (local.get 1) (i32.const 3))) (local.set 1 (i32.sub (local.get 1) (i32.const 5))) (local.set 1 (i32.mul (local.get 1) (i32.const 7))) (br 0) (local.set 1 (i32.mul (local.get 1) (i32.const 100))) ) (else (local.set 1 (i32.mul (local.get 1) (i32.const 5))) (local.set 1 (i32.sub (local.get 1) (i32.const 7))) (local.set 1 (i32.mul (local.get 1) (i32.const 3))) (br 0) (local.set 1 (i32.mul (local.get 1) (i32.const 1000))) ) ) (local.get 1) ) ) (assert_return (invoke "empty" (i32.const 0))) (assert_return (invoke "empty" (i32.const 1))) (assert_return (invoke "empty" (i32.const 100))) (assert_return (invoke "empty" (i32.const -2))) (assert_return (invoke "singular" (i32.const 0)) (i32.const 8)) (assert_return (invoke "singular" (i32.const 1)) (i32.const 7)) (assert_return (invoke "singular" (i32.const 10)) (i32.const 7)) (assert_return (invoke "singular" (i32.const -10)) (i32.const 7)) (assert_return (invoke "nested" (i32.const 0) (i32.const 0)) (i32.const 11)) (assert_return (invoke "nested" (i32.const 1) (i32.const 0)) (i32.const 10)) (assert_return (invoke "nested" (i32.const 0) (i32.const 1)) (i32.const 10)) (assert_return (invoke "nested" (i32.const 3) (i32.const 2)) (i32.const 9)) (assert_return (invoke "nested" (i32.const 0) (i32.const -100)) (i32.const 10)) (assert_return (invoke "nested" (i32.const 10) (i32.const 10)) (i32.const 9)) (assert_return (invoke "nested" (i32.const 0) (i32.const -1)) (i32.const 10)) (assert_return (invoke "nested" (i32.const -111) (i32.const -2)) (i32.const 9)) (assert_return (invoke "as-loop-first" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-loop-first" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-loop-mid" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-loop-mid" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-loop-last" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-loop-last" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-if-condition" (i32.const 0)) (i32.const 3)) (assert_return (invoke "as-if-condition" (i32.const 1)) (i32.const 2)) (assert_return (invoke "as-br_if-first" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-br_if-first" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-br_if-last" (i32.const 0)) (i32.const 3)) (assert_return (invoke "as-br_if-last" (i32.const 1)) (i32.const 2)) (assert_return (invoke "as-call-value" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-call-value" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-return-value" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-return-value" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-br-value" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-br-value" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-local.set-value" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-local.set-value" (i32.const 1)) (i32.const 1)) (assert_return (invoke "as-unary-operand" (i32.const 0)) (i32.const 0)) (assert_return (invoke "as-unary-operand" (i32.const 1)) (i32.const 0)) (assert_return (invoke "as-unary-operand" (i32.const -1)) (i32.const 0)) (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 0)) (i32.const 15)) (assert_return (invoke "as-binary-operand" (i32.const 0) (i32.const 1)) (i32.const -12)) (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 0)) (i32.const -15)) (assert_return (invoke "as-binary-operand" (i32.const 1) (i32.const 1)) (i32.const 12)) (assert_return (invoke "as-test-operand" (i32.const 0)) (i32.const 1)) (assert_return (invoke "as-test-operand" (i32.const 1)) (i32.const 0)) (assert_return (invoke "break-value" (i32.const 1)) (i32.const 18)) (assert_return (invoke "break-value" (i32.const 0)) (i32.const 21)) (assert_return (invoke "effects" (i32.const 1)) (i32.const -14)) (assert_return (invoke "effects" (i32.const 0)) (i32.const -6))