| 1 |
wasmValidateText(` |
| 2 |
(module |
| 3 |
(func (result i32) |
| 4 |
(i32.add |
| 5 |
(block (result i32 i32) |
| 6 |
(i32.const 32) |
| 7 |
(i32.const 10)))))`); |
| 8 |
|
| 9 |
wasmValidateText(` |
| 10 |
(module |
| 11 |
(func (result i32) |
| 12 |
(i32.const 32) (i32.const 10) |
| 13 |
(block (param i32 i32) (result i32 i32)) |
| 14 |
(i32.add)))`); |
| 15 |
|
| 16 |
wasmValidateText(` |
| 17 |
(module |
| 18 |
(func (result i32) |
| 19 |
(i32.const 32) |
| 20 |
(block (param i32) (result i32 i32) |
| 21 |
(i32.const 10)) |
| 22 |
(i32.add)))`); |
| 23 |
|
| 24 |
wasmValidateText(` |
| 25 |
(module |
| 26 |
(func (result i32) |
| 27 |
(i32.add |
| 28 |
(loop (result i32 i32) |
| 29 |
(i32.const 32) |
| 30 |
(i32.const 10)))))`); |
| 31 |
|
| 32 |
wasmValidateText(` |
| 33 |
(module |
| 34 |
(func (result i32) |
| 35 |
(i32.const 32) (i32.const 10) |
| 36 |
(loop (param i32 i32) (result i32 i32)) |
| 37 |
(i32.add)))`); |
| 38 |
|
| 39 |
wasmValidateText(` |
| 40 |
(module |
| 41 |
(func (result i32) |
| 42 |
(i32.const 32) |
| 43 |
(loop (param i32) (result i32 i32) |
| 44 |
(i32.const 10)) |
| 45 |
(i32.add)))`); |
| 46 |
|
| 47 |
wasmValidateText(` |
| 48 |
(module |
| 49 |
(func (result i32) |
| 50 |
(i32.add |
| 51 |
(block (result i32 i32) |
| 52 |
(i32.const 32) |
| 53 |
(i32.const 10) |
| 54 |
(br 0)))))`); |
| 55 |
|
| 56 |
wasmValidateText(` |
| 57 |
(module |
| 58 |
(func (result i32) |
| 59 |
(i32.const 32) |
| 60 |
(i32.const 10) |
| 61 |
(block (param i32 i32) (result i32 i32) |
| 62 |
(br 0)) |
| 63 |
(i32.add)))`); |
| 64 |
|
| 65 |
wasmValidateText(` |
| 66 |
(module |
| 67 |
(func (result i32) |
| 68 |
(i32.const 32) |
| 69 |
(block (param i32) (result i32 i32) |
| 70 |
(i32.const 10) |
| 71 |
(br 0)) |
| 72 |
(i32.add)))`); |
| 73 |
|
| 74 |
wasmValidateText(` |
| 75 |
(module |
| 76 |
(func (result i32) |
| 77 |
(i32.add |
| 78 |
(block (result i32 i32) |
| 79 |
(i32.const 32) |
| 80 |
(i32.const 10) |
| 81 |
(block (param i32 i32) (result i32 i32) |
| 82 |
(br 1))))))`); |
| 83 |
|
| 84 |
wasmValidateText(` |
| 85 |
(module |
| 86 |
(func (result i32) |
| 87 |
(i32.const 32) |
| 88 |
(i32.const 10) |
| 89 |
(block (param i32 i32) (result i32 i32) |
| 90 |
(block (param i32 i32) (result i32 i32) |
| 91 |
(br 1))) |
| 92 |
(i32.add)))`); |
| 93 |
|
| 94 |
wasmValidateText(` |
| 95 |
(module |
| 96 |
(func (result i32) |
| 97 |
(i32.const 32) |
| 98 |
(i32.const 10) |
| 99 |
(block (param i32 i32) (result i32 i32) |
| 100 |
(block (param i32 i32) (result i32 i32) |
| 101 |
(br 0))) |
| 102 |
(i32.add)))`); |
| 103 |
|
| 104 |
wasmValidateText(` |
| 105 |
(module |
| 106 |
(func (result i32) |
| 107 |
(i32.const 32) |
| 108 |
(block (param i32) (result i32 i32) |
| 109 |
(i32.const 10) |
| 110 |
(block (param i32 i32) (result i32 i32) |
| 111 |
(br 1))) |
| 112 |
(i32.add)))`); |
| 113 |
|
| 114 |
wasmValidateText(` |
| 115 |
(module |
| 116 |
(func (result i32) |
| 117 |
(i32.const 32) |
| 118 |
(i32.const 10) |
| 119 |
(i32.const 1) |
| 120 |
(if (param i32 i32) (result i32) |
| 121 |
(then (i32.add)) |
| 122 |
(else (i32.sub)))))`); |
| 123 |
|
| 124 |
wasmValidateText(` |
| 125 |
(module |
| 126 |
(func (result i32) |
| 127 |
(i32.const 32) |
| 128 |
(i32.const 10) |
| 129 |
(i32.const 1) |
| 130 |
(if (param i32 i32) (result i32 i32) |
| 131 |
(then |
| 132 |
(drop) |
| 133 |
(drop) |
| 134 |
(i32.const 10) |
| 135 |
(i32.const 32))) |
| 136 |
(i32.sub)))`); |
| 137 |
|
| 138 |
wasmValidateText(` |
| 139 |
(module |
| 140 |
(func (result i32) |
| 141 |
(i32.const 32) |
| 142 |
(i32.const 10) |
| 143 |
(i32.const 1) |
| 144 |
(if (param i32 i32) (result i32 i32) |
| 145 |
(then (return))) |
| 146 |
(i32.sub)))`); |
| 147 |
|
| 148 |
wasmValidateText(` |
| 149 |
(module |
| 150 |
(func (result i32) |
| 151 |
(i32.const 32) |
| 152 |
(i32.const 10) |
| 153 |
(i32.const 1) |
| 154 |
(if (param i32 i32) (result i32 i32) |
| 155 |
(then) |
| 156 |
(else (return))) |
| 157 |
(i32.sub)))`); |
| 158 |
|
| 159 |
wasmValidateText(` |
| 160 |
(module |
| 161 |
(func (result i32) |
| 162 |
(local $i i32) |
| 163 |
(i32.const 0) ;; sum |
| 164 |
(i32.const 10) ;; i |
| 165 |
(loop $loop (param i32 i32) (result i32) |
| 166 |
(local.tee $i) |
| 167 |
(i32.add) ;; sum = i + sum |
| 168 |
(i32.sub (local.get $i) (i32.const 1)) |
| 169 |
(local.tee $i) |
| 170 |
(local.get $i) |
| 171 |
(br_if $loop (i32.eqz)) |
| 172 |
(drop))))`); |
| 173 |
|
| 174 |
// Tests the encoding: with more than 64 function types, the block type encoded |
| 175 |
// as an uleb will create a confusion with the valtype; an sleb is required. |
| 176 |
|
| 177 |
wasmValidateText(` |
| 178 |
(module |
| 179 |
${(function () { |
| 180 |
s = ""; |
| 181 |
for ( let i=0; i < 64; i++ ) { |
| 182 |
let t = []; |
| 183 |
for ( let j=0; j < 6; j++ ) |
| 184 |
t.push(i & (1 << j) ? "i32" : "f32"); |
| 185 |
s += "(func (param " + t.join(" ") + "))\n"; |
| 186 |
} |
| 187 |
return s; |
| 188 |
})()} |
| 189 |
(func (result i32) |
| 190 |
(i32.add |
| 191 |
(block (result i32 i32) |
| 192 |
(i32.const 32) |
| 193 |
(i32.const 10)))))`); |
| 194 |
|
| 195 |
wasmValidateText(` |
| 196 |
(module |
| 197 |
(func (result i32) |
| 198 |
(block $B (result i32 i32) |
| 199 |
(br $B (i32.const 1) (i32.const 2)) |
| 200 |
(i32.const 0x1337)) |
| 201 |
(drop)))`); |
| 202 |
|
| 203 |
wasmValidateText(` |
| 204 |
(module |
| 205 |
(func (result i32) |
| 206 |
(block $B (result i32 i32) |
| 207 |
(i32.const 1) |
| 208 |
(br $B (i32.const 2)) |
| 209 |
(i32.const 0x1337)) |
| 210 |
(drop)))`); |
| 211 |
|
| 212 |
wasmValidateText(` |
| 213 |
(module |
| 214 |
(func (result i32) |
| 215 |
(block $B (result i32 i32) |
| 216 |
(i32.const 1) |
| 217 |
(i32.const 2) |
| 218 |
(br $B) |
| 219 |
(i32.const 0x1337)) |
| 220 |
(drop)))`); |
| 221 |
|
| 222 |
wasmValidateText(` |
| 223 |
(module |
| 224 |
(func (param $cond i32) (result i32) |
| 225 |
(block $B (result i32 i32) |
| 226 |
(br_if $B (i32.const 1) (i32.const 2) (local.get $cond))) |
| 227 |
(drop)))`); |
| 228 |
|
| 229 |
wasmValidateText(` |
| 230 |
(module |
| 231 |
(func (param $cond i32) (result i32) |
| 232 |
(block $B (result i32 i32) |
| 233 |
(i32.const 1) |
| 234 |
(br_if $B (i32.const 2) (local.get $cond))) |
| 235 |
(drop)))`); |
| 236 |
|
| 237 |
wasmValidateText(` |
| 238 |
(module |
| 239 |
(func (param $cond i32) (result i32) |
| 240 |
(block $B (result i32 i32) |
| 241 |
(i32.const 1) |
| 242 |
(i32.const 2) |
| 243 |
(br_if $B (local.get $cond))) |
| 244 |
(drop)))`); |
| 245 |
|
| 246 |
wasmValidateText(` |
| 247 |
(module |
| 248 |
(func (param $cond i32) (result i32) |
| 249 |
(block $B (result i32 i32) |
| 250 |
(i32.const 1) |
| 251 |
(i32.const 2) |
| 252 |
(local.get $cond) |
| 253 |
(br_if $B)) |
| 254 |
(drop)))`); |
| 255 |
|
| 256 |
wasmValidateText(` |
| 257 |
(module |
| 258 |
(func (param $index i32) (result i32) |
| 259 |
(block $OUT (result i32) |
| 260 |
(block $B1 (result i32 i32) |
| 261 |
(block $B2 (result i32 i32) |
| 262 |
(block $B3 (result i32 i32) |
| 263 |
(br_table $B1 $B2 $B3 (i32.const 1) (i32.const 2) (local.get $index))) |
| 264 |
(br $OUT (i32.add))) |
| 265 |
(br $OUT (i32.sub))) |
| 266 |
(br $OUT (i32.mul)))))`); |