|
| 1 | +(module |
| 2 | + ;; We define this module to check if Wasmi's expected test module setup was successful. |
| 3 | + (import "wasmitest" "identity-0" (func $identity-0)) |
| 4 | + (import "wasmitest" "identity-1" (func $identity-1 (param i64) (result i64))) |
| 5 | + (import "wasmitest" "identity-2" (func $identity-2 (param i64 i64) (result i64 i64))) |
| 6 | + (import "wasmitest" "offset-1" (func $offset-1 (param i64) (result i64))) |
| 7 | + (import "wasmitest" "offset-2" (func $offset-2 (param i64 i64) (result i64 i64))) |
| 8 | + (import "wasmitest" "sum-3" (func $sum-3 (param i64 i64 i64) (result i64))) |
| 9 | + (import "wasmitest" "iota-3" (func $iota-3 (param i64) (result i64 i64 i64))) |
| 10 | + |
| 11 | + (table funcref |
| 12 | + (elem |
| 13 | + $identity-0 ;; 0 |
| 14 | + $identity-1 ;; 1 |
| 15 | + $identity-2 ;; 2 |
| 16 | + $offset-1 ;; 3 |
| 17 | + $offset-2 ;; 4 |
| 18 | + $sum-3 ;; 5 |
| 19 | + $iota-3 ;; 6 |
| 20 | + ) |
| 21 | + ) |
| 22 | +) |
| 23 | + |
| 24 | +(module |
| 25 | + (type $ty (func)) |
| 26 | + (import "wasmitest" "identity-0" (func $identity-0)) |
| 27 | + (table $t funcref (elem $identity-0)) |
| 28 | + (func (export "call-identity-0") (type $ty) |
| 29 | + (call_indirect $t (type $ty) |
| 30 | + (i32.const 0) ;; index |
| 31 | + ) |
| 32 | + ) |
| 33 | +) |
| 34 | +(assert_return |
| 35 | + (invoke "call-identity-0") |
| 36 | +) |
| 37 | + |
| 38 | +(module |
| 39 | + (type $ty (func (param i64) (result i64))) |
| 40 | + (import "wasmitest" "identity-1" (func $identity-1 (type $ty))) |
| 41 | + (table $t funcref (elem $identity-1)) |
| 42 | + (func (export "call-identity-1") (type $ty) |
| 43 | + (call_indirect $t (type $ty) |
| 44 | + (local.get 0) |
| 45 | + (i32.const 0) ;; index |
| 46 | + ) |
| 47 | + ) |
| 48 | +) |
| 49 | +(assert_return |
| 50 | + (invoke "call-identity-1" (i64.const 0)) |
| 51 | + (i64.const 0) |
| 52 | +) |
| 53 | +(assert_return |
| 54 | + (invoke "call-identity-1" (i64.const 1)) |
| 55 | + (i64.const 1) |
| 56 | +) |
| 57 | +(assert_return |
| 58 | + (invoke "call-identity-1" (i64.const -1)) |
| 59 | + (i64.const -1) |
| 60 | +) |
| 61 | + |
| 62 | +(module |
| 63 | + (type $ty (func (param i64 i64) (result i64 i64))) |
| 64 | + (import "wasmitest" "identity-2" (func $identity-2 (type $ty))) |
| 65 | + (table $t funcref (elem $identity-2)) |
| 66 | + (func (export "call-identity-2") (type $ty) |
| 67 | + (call_indirect $t (type $ty) |
| 68 | + (local.get 0) |
| 69 | + (local.get 1) |
| 70 | + (i32.const 0) ;; index |
| 71 | + ) |
| 72 | + ) |
| 73 | +) |
| 74 | +(assert_return |
| 75 | + (invoke "call-identity-2" (i64.const 0) (i64.const 0)) |
| 76 | + (i64.const 0) (i64.const 0) |
| 77 | +) |
| 78 | +(assert_return |
| 79 | + (invoke "call-identity-2" (i64.const 0) (i64.const 1)) |
| 80 | + (i64.const 0) (i64.const 1) |
| 81 | +) |
| 82 | +(assert_return |
| 83 | + (invoke "call-identity-2" (i64.const 1) (i64.const 0)) |
| 84 | + (i64.const 1) (i64.const 0) |
| 85 | +) |
| 86 | +(assert_return |
| 87 | + (invoke "call-identity-2" (i64.const 1) (i64.const 1)) |
| 88 | + (i64.const 1) (i64.const 1) |
| 89 | +) |
| 90 | + |
| 91 | +(module |
| 92 | + (type $ty (func (param i64) (result i64))) |
| 93 | + (import "wasmitest" "offset-1" (func $offset-1 (type $ty))) |
| 94 | + (table $t funcref (elem $offset-1)) |
| 95 | + (func (export "call-offset-1") (type $ty) |
| 96 | + (call_indirect $t (type $ty) |
| 97 | + (local.get 0) |
| 98 | + (i32.const 0) ;; index |
| 99 | + ) |
| 100 | + ) |
| 101 | +) |
| 102 | +(assert_return |
| 103 | + (invoke "call-offset-1" (i64.const 0)) |
| 104 | + (i64.const 1) |
| 105 | +) |
| 106 | +(assert_return |
| 107 | + (invoke "call-offset-1" (i64.const 1)) |
| 108 | + (i64.const 2) |
| 109 | +) |
| 110 | +(assert_return |
| 111 | + (invoke "call-offset-1" (i64.const -1)) |
| 112 | + (i64.const 0) |
| 113 | +) |
| 114 | + |
| 115 | +(module |
| 116 | + (type $ty (func (param i64 i64) (result i64 i64))) |
| 117 | + (import "wasmitest" "offset-2" (func $offset-2 (type $ty))) |
| 118 | + (table $t funcref (elem $offset-2)) |
| 119 | + (func (export "call-offset-2") (type $ty) |
| 120 | + (call_indirect $t (type $ty) |
| 121 | + (local.get 0) |
| 122 | + (local.get 1) |
| 123 | + (i32.const 0) ;; index |
| 124 | + ) |
| 125 | + ) |
| 126 | +) |
| 127 | +(assert_return |
| 128 | + (invoke "call-offset-2" (i64.const 0) (i64.const 0)) |
| 129 | + (i64.const 1) (i64.const 2) |
| 130 | +) |
| 131 | +(assert_return |
| 132 | + (invoke "call-offset-2" (i64.const 0) (i64.const 1)) |
| 133 | + (i64.const 1) (i64.const 3) |
| 134 | +) |
| 135 | +(assert_return |
| 136 | + (invoke "call-offset-2" (i64.const 1) (i64.const 0)) |
| 137 | + (i64.const 2) (i64.const 2) |
| 138 | +) |
| 139 | +(assert_return |
| 140 | + (invoke "call-offset-2" (i64.const 1) (i64.const 1)) |
| 141 | + (i64.const 2) (i64.const 3) |
| 142 | +) |
| 143 | + |
| 144 | +(module |
| 145 | + (type $ty (func (param i64 i64 i64) (result i64))) |
| 146 | + (import "wasmitest" "sum-3" (func $sum-3 (type $ty))) |
| 147 | + (table $t funcref (elem $sum-3)) |
| 148 | + (func (export "call-sum-3") (type $ty) |
| 149 | + (call_indirect $t (type $ty) |
| 150 | + (local.get 0) |
| 151 | + (local.get 1) |
| 152 | + (local.get 2) |
| 153 | + (i32.const 0) ;; index |
| 154 | + ) |
| 155 | + ) |
| 156 | +) |
| 157 | +(assert_return |
| 158 | + (invoke "call-sum-3" (i64.const 0) (i64.const 0) (i64.const 0)) |
| 159 | + (i64.const 0) |
| 160 | +) |
| 161 | +(assert_return |
| 162 | + (invoke "call-sum-3" (i64.const 1) (i64.const 2) (i64.const 3)) |
| 163 | + (i64.const 6) |
| 164 | +) |
| 165 | +(assert_return |
| 166 | + (invoke "call-sum-3" (i64.const -1) (i64.const 0) (i64.const 1)) |
| 167 | + (i64.const 0) |
| 168 | +) |
| 169 | +(assert_return |
| 170 | + (invoke "call-sum-3" (i64.const -1) (i64.const -1) (i64.const -1)) |
| 171 | + (i64.const -3) |
| 172 | +) |
| 173 | + |
| 174 | +(module |
| 175 | + (type $ty (func (param i64) (result i64 i64 i64))) |
| 176 | + (import "wasmitest" "iota-3" (func $iota-3 (type $ty))) |
| 177 | + (table $t funcref (elem $iota-3)) |
| 178 | + (func (export "call-iota-3") (type $ty) |
| 179 | + (call_indirect $t (type $ty) |
| 180 | + (local.get 0) |
| 181 | + (i32.const 0) ;; index |
| 182 | + ) |
| 183 | + ) |
| 184 | +) |
| 185 | +(assert_return |
| 186 | + (invoke "call-iota-3" (i64.const 0)) |
| 187 | + (i64.const 1) (i64.const 2) (i64.const 3) |
| 188 | +) |
| 189 | +(assert_return |
| 190 | + (invoke "call-iota-3" (i64.const 100)) |
| 191 | + (i64.const 101) (i64.const 102) (i64.const 103) |
| 192 | +) |
| 193 | +(assert_return |
| 194 | + (invoke "call-iota-3" (i64.const -3)) |
| 195 | + (i64.const -2) (i64.const -1) (i64.const 0) |
| 196 | +) |
0 commit comments