OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/common/wasm/test-signatures.h" | 9 #include "test/common/wasm/test-signatures.h" |
10 | 10 |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 | 12 |
13 #include "src/wasm/ast-decoder.h" | 13 #include "src/wasm/function-body-decoder.h" |
14 #include "src/wasm/signature-map.h" | 14 #include "src/wasm/signature-map.h" |
15 #include "src/wasm/wasm-macro-gen.h" | 15 #include "src/wasm/wasm-macro-gen.h" |
16 #include "src/wasm/wasm-module.h" | 16 #include "src/wasm/wasm-module.h" |
17 #include "src/wasm/wasm-opcodes.h" | 17 #include "src/wasm/wasm-opcodes.h" |
18 | 18 |
19 namespace v8 { | 19 namespace v8 { |
20 namespace internal { | 20 namespace internal { |
21 namespace wasm { | 21 namespace wasm { |
22 | 22 |
23 #define B1(a) WASM_BLOCK(a) | 23 #define B1(a) WASM_BLOCK(a) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } while (false) | 76 } while (false) |
77 | 77 |
78 #define EXPECT_FAILURE(sig, ...) \ | 78 #define EXPECT_FAILURE(sig, ...) \ |
79 do { \ | 79 do { \ |
80 static const byte code[] = {__VA_ARGS__}; \ | 80 static const byte code[] = {__VA_ARGS__}; \ |
81 Verify(kError, sigs.sig(), code, code + sizeof(code)); \ | 81 Verify(kError, sigs.sig(), code, code + sizeof(code)); \ |
82 } while (false) | 82 } while (false) |
83 | 83 |
84 static bool old_eh_flag; | 84 static bool old_eh_flag; |
85 | 85 |
86 class AstDecoderTest : public TestWithZone { | 86 class FunctionBodyDecoderTest : public TestWithZone { |
87 public: | 87 public: |
88 typedef std::pair<uint32_t, LocalType> LocalsDecl; | 88 typedef std::pair<uint32_t, LocalType> LocalsDecl; |
89 | 89 |
90 AstDecoderTest() : module(nullptr), local_decls(zone()) {} | 90 FunctionBodyDecoderTest() : module(nullptr), local_decls(zone()) {} |
91 | 91 |
92 static void SetUpTestCase() { old_eh_flag = FLAG_wasm_eh_prototype; } | 92 static void SetUpTestCase() { old_eh_flag = FLAG_wasm_eh_prototype; } |
93 | 93 |
94 static void TearDownTestCase() { | 94 static void TearDownTestCase() { |
95 // Reset the wasm_eh_prototype flag | 95 // Reset the wasm_eh_prototype flag |
96 FLAG_wasm_eh_prototype = old_eh_flag; | 96 FLAG_wasm_eh_prototype = old_eh_flag; |
97 } | 97 } |
98 | 98 |
99 TestSignatures sigs; | 99 TestSignatures sigs; |
100 ModuleEnv* module; | 100 ModuleEnv* module; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (types[0] != ret_type || types[1] != param_type) { | 175 if (types[0] != ret_type || types[1] != param_type) { |
176 // Test signature mismatch. | 176 // Test signature mismatch. |
177 FunctionSig sig(1, 1, types); | 177 FunctionSig sig(1, 1, types); |
178 EXPECT_FAILURE_SC(&sig, code); | 178 EXPECT_FAILURE_SC(&sig, code); |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 }; | 183 }; |
184 | 184 |
185 TEST_F(AstDecoderTest, Int8Const) { | 185 TEST_F(FunctionBodyDecoderTest, Int8Const) { |
186 byte code[] = {kExprI8Const, 0}; | 186 byte code[] = {kExprI8Const, 0}; |
187 for (int i = -128; i < 128; i++) { | 187 for (int i = -128; i < 128; i++) { |
188 code[1] = static_cast<byte>(i); | 188 code[1] = static_cast<byte>(i); |
189 EXPECT_VERIFIES_C(i_i, code); | 189 EXPECT_VERIFIES_C(i_i, code); |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 TEST_F(AstDecoderTest, EmptyFunction) { | 193 TEST_F(FunctionBodyDecoderTest, EmptyFunction) { |
194 byte code[] = {0}; | 194 byte code[] = {0}; |
195 Verify(kSuccess, sigs.v_v(), code, code); | 195 Verify(kSuccess, sigs.v_v(), code, code); |
196 Verify(kError, sigs.i_i(), code, code); | 196 Verify(kError, sigs.i_i(), code, code); |
197 } | 197 } |
198 | 198 |
199 TEST_F(AstDecoderTest, IncompleteIf1) { | 199 TEST_F(FunctionBodyDecoderTest, IncompleteIf1) { |
200 byte code[] = {kExprIf}; | 200 byte code[] = {kExprIf}; |
201 EXPECT_FAILURE_C(v_v, code); | 201 EXPECT_FAILURE_C(v_v, code); |
202 EXPECT_FAILURE_C(i_i, code); | 202 EXPECT_FAILURE_C(i_i, code); |
203 } | 203 } |
204 | 204 |
205 TEST_F(AstDecoderTest, Int8Const_fallthru) { | 205 TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru) { |
206 EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); | 206 EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); |
207 } | 207 } |
208 | 208 |
209 TEST_F(AstDecoderTest, Int8Const_fallthru2) { | 209 TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru2) { |
210 EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); | 210 EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); |
211 } | 211 } |
212 | 212 |
213 TEST_F(AstDecoderTest, Int32Const) { | 213 TEST_F(FunctionBodyDecoderTest, Int32Const) { |
214 const int kInc = 4498211; | 214 const int kInc = 4498211; |
215 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { | 215 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
216 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. | 216 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. |
217 byte code[] = {WASM_I32V(i)}; | 217 byte code[] = {WASM_I32V(i)}; |
218 EXPECT_VERIFIES_C(i_i, code); | 218 EXPECT_VERIFIES_C(i_i, code); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 TEST_F(AstDecoderTest, Int64Const) { | 222 TEST_F(FunctionBodyDecoderTest, Int64Const) { |
223 const int kInc = 4498211; | 223 const int kInc = 4498211; |
224 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { | 224 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { |
225 byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; | 225 byte code[] = {WASM_I64V((static_cast<int64_t>(i) << 32) | i)}; |
226 EXPECT_VERIFIES_C(l_l, code); | 226 EXPECT_VERIFIES_C(l_l, code); |
227 } | 227 } |
228 } | 228 } |
229 | 229 |
230 TEST_F(AstDecoderTest, Float32Const) { | 230 TEST_F(FunctionBodyDecoderTest, Float32Const) { |
231 byte code[] = {kExprF32Const, 0, 0, 0, 0}; | 231 byte code[] = {kExprF32Const, 0, 0, 0, 0}; |
232 float* ptr = reinterpret_cast<float*>(code + 1); | 232 float* ptr = reinterpret_cast<float*>(code + 1); |
233 for (int i = 0; i < 30; i++) { | 233 for (int i = 0; i < 30; i++) { |
234 WriteLittleEndianValue<float>(ptr, i * -7.75f); | 234 WriteLittleEndianValue<float>(ptr, i * -7.75f); |
235 EXPECT_VERIFIES_C(f_ff, code); | 235 EXPECT_VERIFIES_C(f_ff, code); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 TEST_F(AstDecoderTest, Float64Const) { | 239 TEST_F(FunctionBodyDecoderTest, Float64Const) { |
240 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; | 240 byte code[] = {kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0}; |
241 double* ptr = reinterpret_cast<double*>(code + 1); | 241 double* ptr = reinterpret_cast<double*>(code + 1); |
242 for (int i = 0; i < 30; i++) { | 242 for (int i = 0; i < 30; i++) { |
243 WriteLittleEndianValue<double>(ptr, i * 33.45); | 243 WriteLittleEndianValue<double>(ptr, i * 33.45); |
244 EXPECT_VERIFIES_C(d_dd, code); | 244 EXPECT_VERIFIES_C(d_dd, code); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 TEST_F(AstDecoderTest, Int32Const_off_end) { | 248 TEST_F(FunctionBodyDecoderTest, Int32Const_off_end) { |
249 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; | 249 byte code[] = {kExprI32Const, 0xaa, 0xbb, 0xcc, 0x44}; |
250 | 250 |
251 for (int size = 1; size <= 4; size++) { | 251 for (int size = 1; size <= 4; size++) { |
252 Verify(kError, sigs.i_i(), code, code + size); | 252 Verify(kError, sigs.i_i(), code, code + size); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 TEST_F(AstDecoderTest, GetLocal0_param) { | 256 TEST_F(FunctionBodyDecoderTest, GetLocal0_param) { |
257 EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); | 257 EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); |
258 } | 258 } |
259 | 259 |
260 TEST_F(AstDecoderTest, GetLocal0_local) { | 260 TEST_F(FunctionBodyDecoderTest, GetLocal0_local) { |
261 AddLocals(kAstI32, 1); | 261 AddLocals(kAstI32, 1); |
262 EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); | 262 EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); |
263 } | 263 } |
264 | 264 |
265 TEST_F(AstDecoderTest, TooManyLocals) { | 265 TEST_F(FunctionBodyDecoderTest, TooManyLocals) { |
266 AddLocals(kAstI32, 4034986500); | 266 AddLocals(kAstI32, 4034986500); |
267 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); | 267 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
268 } | 268 } |
269 | 269 |
270 TEST_F(AstDecoderTest, GetLocal0_param_n) { | 270 TEST_F(FunctionBodyDecoderTest, GetLocal0_param_n) { |
271 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; | 271 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; |
272 | 272 |
273 for (size_t i = 0; i < arraysize(array); i++) { | 273 for (size_t i = 0; i < arraysize(array); i++) { |
274 EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); | 274 EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 TEST_F(AstDecoderTest, GetLocalN_local) { | 278 TEST_F(FunctionBodyDecoderTest, GetLocalN_local) { |
279 for (byte i = 1; i < 8; i++) { | 279 for (byte i = 1; i < 8; i++) { |
280 AddLocals(kAstI32, 1); | 280 AddLocals(kAstI32, 1); |
281 for (byte j = 0; j < i; j++) { | 281 for (byte j = 0; j < i; j++) { |
282 byte code[] = {kExprGetLocal, j}; | 282 byte code[] = {kExprGetLocal, j}; |
283 EXPECT_VERIFIES_C(i_v, code); | 283 EXPECT_VERIFIES_C(i_v, code); |
284 } | 284 } |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 TEST_F(AstDecoderTest, GetLocal0_fail_no_params) { | 288 TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) { |
289 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); | 289 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
290 } | 290 } |
291 | 291 |
292 TEST_F(AstDecoderTest, GetLocal1_fail_no_locals) { | 292 TEST_F(FunctionBodyDecoderTest, GetLocal1_fail_no_locals) { |
293 EXPECT_FAILURE_C(i_i, kCodeGetLocal1); | 293 EXPECT_FAILURE_C(i_i, kCodeGetLocal1); |
294 } | 294 } |
295 | 295 |
296 TEST_F(AstDecoderTest, GetLocal_off_end) { | 296 TEST_F(FunctionBodyDecoderTest, GetLocal_off_end) { |
297 static const byte code[] = {kExprGetLocal}; | 297 static const byte code[] = {kExprGetLocal}; |
298 EXPECT_FAILURE_C(i_i, code); | 298 EXPECT_FAILURE_C(i_i, code); |
299 } | 299 } |
300 | 300 |
301 TEST_F(AstDecoderTest, NumLocalBelowLimit) { | 301 TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) { |
302 AddLocals(kAstI32, kMaxNumWasmLocals - 1); | 302 AddLocals(kAstI32, kMaxNumWasmLocals - 1); |
303 EXPECT_VERIFIES(v_v, WASM_NOP); | 303 EXPECT_VERIFIES(v_v, WASM_NOP); |
304 } | 304 } |
305 | 305 |
306 TEST_F(AstDecoderTest, NumLocalAtLimit) { | 306 TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) { |
307 AddLocals(kAstI32, kMaxNumWasmLocals); | 307 AddLocals(kAstI32, kMaxNumWasmLocals); |
308 EXPECT_VERIFIES(v_v, WASM_NOP); | 308 EXPECT_VERIFIES(v_v, WASM_NOP); |
309 } | 309 } |
310 | 310 |
311 TEST_F(AstDecoderTest, NumLocalAboveLimit) { | 311 TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) { |
312 AddLocals(kAstI32, kMaxNumWasmLocals + 1); | 312 AddLocals(kAstI32, kMaxNumWasmLocals + 1); |
313 EXPECT_FAILURE(v_v, WASM_NOP); | 313 EXPECT_FAILURE(v_v, WASM_NOP); |
314 } | 314 } |
315 | 315 |
316 TEST_F(AstDecoderTest, GetLocal_varint) { | 316 TEST_F(FunctionBodyDecoderTest, GetLocal_varint) { |
317 const int kMaxLocals = kMaxNumWasmLocals - 1; | 317 const int kMaxLocals = kMaxNumWasmLocals - 1; |
318 AddLocals(kAstI32, kMaxLocals); | 318 AddLocals(kAstI32, kMaxLocals); |
319 | 319 |
320 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); | 320 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); |
321 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); | 321 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); |
322 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888)); | 322 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888)); |
323 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999)); | 323 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999)); |
324 | 324 |
325 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); | 325 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); |
326 | 326 |
327 EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); | 327 EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
328 | 328 |
329 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); | 329 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); |
330 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); | 330 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); |
331 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); | 331 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
332 | 332 |
333 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); | 333 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); |
334 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); | 334 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
335 } | 335 } |
336 | 336 |
337 TEST_F(AstDecoderTest, GetLocal_toomany) { | 337 TEST_F(FunctionBodyDecoderTest, GetLocal_toomany) { |
338 AddLocals(kAstI32, kMaxNumWasmLocals - 100); | 338 AddLocals(kAstI32, kMaxNumWasmLocals - 100); |
339 AddLocals(kAstI32, 100); | 339 AddLocals(kAstI32, 100); |
340 | 340 |
341 EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66)); | 341 EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66)); |
342 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66)); | 342 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66)); |
343 } | 343 } |
344 | 344 |
345 TEST_F(AstDecoderTest, Binops_off_end) { | 345 TEST_F(FunctionBodyDecoderTest, Binops_off_end) { |
346 byte code1[] = {0}; // [opcode] | 346 byte code1[] = {0}; // [opcode] |
347 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 347 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
348 code1[0] = kInt32BinopOpcodes[i]; | 348 code1[0] = kInt32BinopOpcodes[i]; |
349 EXPECT_FAILURE_C(i_i, code1); | 349 EXPECT_FAILURE_C(i_i, code1); |
350 } | 350 } |
351 | 351 |
352 byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] | 352 byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode] |
353 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 353 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
354 code3[2] = kInt32BinopOpcodes[i]; | 354 code3[2] = kInt32BinopOpcodes[i]; |
355 EXPECT_FAILURE_C(i_i, code3); | 355 EXPECT_FAILURE_C(i_i, code3); |
356 } | 356 } |
357 | 357 |
358 byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] | 358 byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode] |
359 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 359 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
360 code4[2] = kInt32BinopOpcodes[i]; | 360 code4[2] = kInt32BinopOpcodes[i]; |
361 code4[3] = kInt32BinopOpcodes[i]; | 361 code4[3] = kInt32BinopOpcodes[i]; |
362 EXPECT_FAILURE_C(i_i, code4); | 362 EXPECT_FAILURE_C(i_i, code4); |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 TEST_F(AstDecoderTest, BinopsAcrossBlock1) { | 366 TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock1) { |
367 static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add, | 367 static const byte code[] = {WASM_ZERO, kExprBlock, WASM_ZERO, kExprI32Add, |
368 kExprEnd}; | 368 kExprEnd}; |
369 EXPECT_FAILURE_C(i_i, code); | 369 EXPECT_FAILURE_C(i_i, code); |
370 } | 370 } |
371 | 371 |
372 TEST_F(AstDecoderTest, BinopsAcrossBlock2) { | 372 TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock2) { |
373 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add, | 373 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprBlock, kExprI32Add, |
374 kExprEnd}; | 374 kExprEnd}; |
375 EXPECT_FAILURE_C(i_i, code); | 375 EXPECT_FAILURE_C(i_i, code); |
376 } | 376 } |
377 | 377 |
378 TEST_F(AstDecoderTest, BinopsAcrossBlock3) { | 378 TEST_F(FunctionBodyDecoderTest, BinopsAcrossBlock3) { |
379 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add, | 379 static const byte code[] = {WASM_ZERO, WASM_ZERO, kExprIf, kExprI32Add, |
380 kExprElse, kExprI32Add, kExprEnd}; | 380 kExprElse, kExprI32Add, kExprEnd}; |
381 EXPECT_FAILURE_C(i_i, code); | 381 EXPECT_FAILURE_C(i_i, code); |
382 } | 382 } |
383 | 383 |
384 TEST_F(AstDecoderTest, Nop) { | 384 TEST_F(FunctionBodyDecoderTest, Nop) { |
385 static const byte code[] = {kExprNop}; | 385 static const byte code[] = {kExprNop}; |
386 EXPECT_VERIFIES_C(v_v, code); | 386 EXPECT_VERIFIES_C(v_v, code); |
387 } | 387 } |
388 | 388 |
389 TEST_F(AstDecoderTest, SetLocal0_void) { | 389 TEST_F(FunctionBodyDecoderTest, SetLocal0_void) { |
390 EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO)); | 390 EXPECT_FAILURE(i_i, WASM_SET_LOCAL(0, WASM_ZERO)); |
391 } | 391 } |
392 | 392 |
393 TEST_F(AstDecoderTest, SetLocal0_param) { | 393 TEST_F(FunctionBodyDecoderTest, SetLocal0_param) { |
394 EXPECT_FAILURE_C(i_i, kCodeSetLocal0); | 394 EXPECT_FAILURE_C(i_i, kCodeSetLocal0); |
395 EXPECT_FAILURE_C(f_ff, kCodeSetLocal0); | 395 EXPECT_FAILURE_C(f_ff, kCodeSetLocal0); |
396 EXPECT_FAILURE_C(d_dd, kCodeSetLocal0); | 396 EXPECT_FAILURE_C(d_dd, kCodeSetLocal0); |
397 } | 397 } |
398 | 398 |
399 TEST_F(AstDecoderTest, TeeLocal0_param) { | 399 TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) { |
400 EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); | 400 EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); |
401 EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); | 401 EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); |
402 EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); | 402 EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); |
403 } | 403 } |
404 | 404 |
405 TEST_F(AstDecoderTest, SetLocal0_local) { | 405 TEST_F(FunctionBodyDecoderTest, SetLocal0_local) { |
406 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); | 406 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
407 EXPECT_FAILURE_C(v_v, kCodeSetLocal0); | 407 EXPECT_FAILURE_C(v_v, kCodeSetLocal0); |
408 AddLocals(kAstI32, 1); | 408 AddLocals(kAstI32, 1); |
409 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); | 409 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
410 EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); | 410 EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); |
411 } | 411 } |
412 | 412 |
413 TEST_F(AstDecoderTest, TeeLocal0_local) { | 413 TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) { |
414 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); | 414 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); |
415 AddLocals(kAstI32, 1); | 415 AddLocals(kAstI32, 1); |
416 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); | 416 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); |
417 } | 417 } |
418 | 418 |
419 TEST_F(AstDecoderTest, TeeLocalN_local) { | 419 TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { |
420 for (byte i = 1; i < 8; i++) { | 420 for (byte i = 1; i < 8; i++) { |
421 AddLocals(kAstI32, 1); | 421 AddLocals(kAstI32, 1); |
422 for (byte j = 0; j < i; j++) { | 422 for (byte j = 0; j < i; j++) { |
423 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); | 423 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); |
424 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); | 424 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); |
425 } | 425 } |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 TEST_F(AstDecoderTest, BlockN) { | 429 TEST_F(FunctionBodyDecoderTest, BlockN) { |
430 const int kMaxSize = 200; | 430 const int kMaxSize = 200; |
431 byte buffer[kMaxSize + 3]; | 431 byte buffer[kMaxSize + 3]; |
432 | 432 |
433 for (int i = 0; i <= kMaxSize; i++) { | 433 for (int i = 0; i <= kMaxSize; i++) { |
434 memset(buffer, kExprNop, sizeof(buffer)); | 434 memset(buffer, kExprNop, sizeof(buffer)); |
435 buffer[0] = kExprBlock; | 435 buffer[0] = kExprBlock; |
436 buffer[1] = kLocalVoid; | 436 buffer[1] = kLocalVoid; |
437 buffer[i + 2] = kExprEnd; | 437 buffer[i + 2] = kExprEnd; |
438 Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 3); | 438 Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 3); |
439 } | 439 } |
440 } | 440 } |
441 | 441 |
442 #define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd | 442 #define WASM_EMPTY_BLOCK kExprBlock, kLocalVoid, kExprEnd |
443 | 443 |
444 TEST_F(AstDecoderTest, Block0) { | 444 TEST_F(FunctionBodyDecoderTest, Block0) { |
445 static const byte code[] = {WASM_EMPTY_BLOCK}; | 445 static const byte code[] = {WASM_EMPTY_BLOCK}; |
446 EXPECT_VERIFIES_C(v_v, code); | 446 EXPECT_VERIFIES_C(v_v, code); |
447 EXPECT_FAILURE_C(i_i, code); | 447 EXPECT_FAILURE_C(i_i, code); |
448 } | 448 } |
449 | 449 |
450 TEST_F(AstDecoderTest, Block0_fallthru1) { | 450 TEST_F(FunctionBodyDecoderTest, Block0_fallthru1) { |
451 static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)}; | 451 static const byte code[] = {WASM_BLOCK(WASM_EMPTY_BLOCK)}; |
452 EXPECT_VERIFIES_C(v_v, code); | 452 EXPECT_VERIFIES_C(v_v, code); |
453 EXPECT_FAILURE_C(i_i, code); | 453 EXPECT_FAILURE_C(i_i, code); |
454 } | 454 } |
455 | 455 |
456 TEST_F(AstDecoderTest, Block0Block0) { | 456 TEST_F(FunctionBodyDecoderTest, Block0Block0) { |
457 static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; | 457 static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; |
458 EXPECT_VERIFIES_C(v_v, code); | 458 EXPECT_VERIFIES_C(v_v, code); |
459 EXPECT_FAILURE_C(i_i, code); | 459 EXPECT_FAILURE_C(i_i, code); |
460 } | 460 } |
461 | 461 |
462 TEST_F(AstDecoderTest, Block0_end) { | 462 TEST_F(FunctionBodyDecoderTest, Block0_end) { |
463 EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd); | 463 EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd); |
464 } | 464 } |
465 | 465 |
466 TEST_F(AstDecoderTest, Block0_end_end) { | 466 TEST_F(FunctionBodyDecoderTest, Block0_end_end) { |
467 EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd); | 467 EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd); |
468 } | 468 } |
469 | 469 |
470 TEST_F(AstDecoderTest, Block1) { | 470 TEST_F(FunctionBodyDecoderTest, Block1) { |
471 byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; | 471 byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; |
472 EXPECT_VERIFIES_C(i_i, code); | 472 EXPECT_VERIFIES_C(i_i, code); |
473 EXPECT_FAILURE_C(v_i, code); | 473 EXPECT_FAILURE_C(v_i, code); |
474 EXPECT_FAILURE_C(d_dd, code); | 474 EXPECT_FAILURE_C(d_dd, code); |
475 EXPECT_FAILURE_C(i_f, code); | 475 EXPECT_FAILURE_C(i_f, code); |
476 EXPECT_FAILURE_C(i_d, code); | 476 EXPECT_FAILURE_C(i_d, code); |
477 } | 477 } |
478 | 478 |
479 TEST_F(AstDecoderTest, Block1_i) { | 479 TEST_F(FunctionBodyDecoderTest, Block1_i) { |
480 byte code[] = {WASM_BLOCK_I(WASM_ZERO)}; | 480 byte code[] = {WASM_BLOCK_I(WASM_ZERO)}; |
481 EXPECT_VERIFIES_C(i_i, code); | 481 EXPECT_VERIFIES_C(i_i, code); |
482 EXPECT_FAILURE_C(f_ff, code); | 482 EXPECT_FAILURE_C(f_ff, code); |
483 EXPECT_FAILURE_C(d_dd, code); | 483 EXPECT_FAILURE_C(d_dd, code); |
484 EXPECT_FAILURE_C(l_ll, code); | 484 EXPECT_FAILURE_C(l_ll, code); |
485 } | 485 } |
486 | 486 |
487 TEST_F(AstDecoderTest, Block1_f) { | 487 TEST_F(FunctionBodyDecoderTest, Block1_f) { |
488 byte code[] = {WASM_BLOCK_F(WASM_F32(0))}; | 488 byte code[] = {WASM_BLOCK_F(WASM_F32(0))}; |
489 EXPECT_FAILURE_C(i_i, code); | 489 EXPECT_FAILURE_C(i_i, code); |
490 EXPECT_VERIFIES_C(f_ff, code); | 490 EXPECT_VERIFIES_C(f_ff, code); |
491 EXPECT_FAILURE_C(d_dd, code); | 491 EXPECT_FAILURE_C(d_dd, code); |
492 EXPECT_FAILURE_C(l_ll, code); | 492 EXPECT_FAILURE_C(l_ll, code); |
493 } | 493 } |
494 | 494 |
495 TEST_F(AstDecoderTest, Block1_continue) { | 495 TEST_F(FunctionBodyDecoderTest, Block1_continue) { |
496 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); | 496 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
497 } | 497 } |
498 | 498 |
499 TEST_F(AstDecoderTest, Block1_br) { | 499 TEST_F(FunctionBodyDecoderTest, Block1_br) { |
500 EXPECT_VERIFIES(v_v, B1(WASM_BR(0))); | 500 EXPECT_VERIFIES(v_v, B1(WASM_BR(0))); |
501 EXPECT_VERIFIES(v_v, B1(WASM_BR(1))); | 501 EXPECT_VERIFIES(v_v, B1(WASM_BR(1))); |
502 EXPECT_FAILURE(v_v, B1(WASM_BR(2))); | 502 EXPECT_FAILURE(v_v, B1(WASM_BR(2))); |
503 } | 503 } |
504 | 504 |
505 TEST_F(AstDecoderTest, Block2_br) { | 505 TEST_F(FunctionBodyDecoderTest, Block2_br) { |
506 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0))); | 506 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_BR(0))); |
507 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP)); | 507 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_NOP)); |
508 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0))); | 508 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_BR(0))); |
509 } | 509 } |
510 | 510 |
511 TEST_F(AstDecoderTest, Block2) { | 511 TEST_F(FunctionBodyDecoderTest, Block2) { |
512 EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP)); | 512 EXPECT_FAILURE(i_i, WASM_BLOCK(WASM_NOP, WASM_NOP)); |
513 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP)); | 513 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_NOP, WASM_NOP)); |
514 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO)); | 514 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_NOP, WASM_ZERO)); |
515 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP)); | 515 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_NOP)); |
516 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)); | 516 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_ZERO, WASM_ZERO)); |
517 } | 517 } |
518 | 518 |
519 TEST_F(AstDecoderTest, Block2b) { | 519 TEST_F(FunctionBodyDecoderTest, Block2b) { |
520 byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; | 520 byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; |
521 EXPECT_VERIFIES_C(i_i, code); | 521 EXPECT_VERIFIES_C(i_i, code); |
522 EXPECT_FAILURE_C(v_v, code); | 522 EXPECT_FAILURE_C(v_v, code); |
523 EXPECT_FAILURE_C(f_ff, code); | 523 EXPECT_FAILURE_C(f_ff, code); |
524 } | 524 } |
525 | 525 |
526 TEST_F(AstDecoderTest, Block2_fallthru) { | 526 TEST_F(FunctionBodyDecoderTest, Block2_fallthru) { |
527 EXPECT_VERIFIES( | 527 EXPECT_VERIFIES( |
528 i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), | 528 i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), |
529 WASM_I8(23)); | 529 WASM_I8(23)); |
530 } | 530 } |
531 | 531 |
532 TEST_F(AstDecoderTest, Block3) { | 532 TEST_F(FunctionBodyDecoderTest, Block3) { |
533 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), | 533 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), |
534 WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); | 534 WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); |
535 } | 535 } |
536 | 536 |
537 TEST_F(AstDecoderTest, Block5) { | 537 TEST_F(FunctionBodyDecoderTest, Block5) { |
538 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); | 538 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); |
539 | 539 |
540 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); | 540 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); |
541 | 541 |
542 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); | 542 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
543 | 543 |
544 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); | 544 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
545 | 545 |
546 EXPECT_FAILURE( | 546 EXPECT_FAILURE( |
547 v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); | 547 v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
548 } | 548 } |
549 | 549 |
550 TEST_F(AstDecoderTest, BlockType) { | 550 TEST_F(FunctionBodyDecoderTest, BlockType) { |
551 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0))); | 551 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_GET_LOCAL(0))); |
552 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0))); | 552 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_GET_LOCAL(0))); |
553 EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0))); | 553 EXPECT_VERIFIES(f_f, WASM_BLOCK_F(WASM_GET_LOCAL(0))); |
554 EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0))); | 554 EXPECT_VERIFIES(d_d, WASM_BLOCK_D(WASM_GET_LOCAL(0))); |
555 } | 555 } |
556 | 556 |
557 TEST_F(AstDecoderTest, BlockType_fail) { | 557 TEST_F(FunctionBodyDecoderTest, BlockType_fail) { |
558 EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0))); | 558 EXPECT_FAILURE(i_i, WASM_BLOCK_L(WASM_I64V_1(0))); |
559 EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0))); | 559 EXPECT_FAILURE(i_i, WASM_BLOCK_F(WASM_F32(0.0))); |
560 EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1))); | 560 EXPECT_FAILURE(i_i, WASM_BLOCK_D(WASM_F64(1.1))); |
561 | 561 |
562 EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO)); | 562 EXPECT_FAILURE(l_l, WASM_BLOCK_I(WASM_ZERO)); |
563 EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0))); | 563 EXPECT_FAILURE(l_l, WASM_BLOCK_F(WASM_F32(0.0))); |
564 EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1))); | 564 EXPECT_FAILURE(l_l, WASM_BLOCK_D(WASM_F64(1.1))); |
565 | 565 |
566 EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO)); | 566 EXPECT_FAILURE(f_ff, WASM_BLOCK_I(WASM_ZERO)); |
567 EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0))); | 567 EXPECT_FAILURE(f_ff, WASM_BLOCK_L(WASM_I64V_1(0))); |
568 EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1))); | 568 EXPECT_FAILURE(f_ff, WASM_BLOCK_D(WASM_F64(1.1))); |
569 | 569 |
570 EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO)); | 570 EXPECT_FAILURE(d_dd, WASM_BLOCK_I(WASM_ZERO)); |
571 EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0))); | 571 EXPECT_FAILURE(d_dd, WASM_BLOCK_L(WASM_I64V_1(0))); |
572 EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0))); | 572 EXPECT_FAILURE(d_dd, WASM_BLOCK_F(WASM_F32(0.0))); |
573 } | 573 } |
574 | 574 |
575 TEST_F(AstDecoderTest, BlockF32) { | 575 TEST_F(FunctionBodyDecoderTest, BlockF32) { |
576 static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)}; | 576 static const byte code[] = {WASM_BLOCK_F(kExprF32Const, 0, 0, 0, 0)}; |
577 EXPECT_VERIFIES_C(f_ff, code); | 577 EXPECT_VERIFIES_C(f_ff, code); |
578 EXPECT_FAILURE_C(i_i, code); | 578 EXPECT_FAILURE_C(i_i, code); |
579 EXPECT_FAILURE_C(d_dd, code); | 579 EXPECT_FAILURE_C(d_dd, code); |
580 } | 580 } |
581 | 581 |
582 TEST_F(AstDecoderTest, BlockN_off_end) { | 582 TEST_F(FunctionBodyDecoderTest, BlockN_off_end) { |
583 byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)}; | 583 byte code[] = {WASM_BLOCK(kExprNop, kExprNop, kExprNop, kExprNop)}; |
584 EXPECT_VERIFIES_C(v_v, code); | 584 EXPECT_VERIFIES_C(v_v, code); |
585 for (size_t i = 1; i < arraysize(code); i++) { | 585 for (size_t i = 1; i < arraysize(code); i++) { |
586 Verify(kError, sigs.v_v(), code, code + i); | 586 Verify(kError, sigs.v_v(), code, code + i); |
587 } | 587 } |
588 } | 588 } |
589 | 589 |
590 TEST_F(AstDecoderTest, Block2_continue) { | 590 TEST_F(FunctionBodyDecoderTest, Block2_continue) { |
591 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0))); | 591 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(0))); |
592 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1))); | 592 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_BR(1))); |
593 EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2))); | 593 EXPECT_FAILURE(v_v, WASM_LOOP(WASM_NOP, WASM_BR(2))); |
594 } | 594 } |
595 | 595 |
596 TEST_F(AstDecoderTest, Block3_continue) { | 596 TEST_F(FunctionBodyDecoderTest, Block3_continue) { |
597 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); | 597 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(0)))); |
598 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); | 598 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); |
599 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); | 599 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); |
600 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); | 600 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); |
601 } | 601 } |
602 | 602 |
603 TEST_F(AstDecoderTest, NestedBlock_return) { | 603 TEST_F(FunctionBodyDecoderTest, NestedBlock_return) { |
604 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); | 604 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); |
605 } | 605 } |
606 | 606 |
607 TEST_F(AstDecoderTest, BlockBrBinop) { | 607 TEST_F(FunctionBodyDecoderTest, BlockBrBinop) { |
608 EXPECT_VERIFIES( | 608 EXPECT_VERIFIES( |
609 i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); | 609 i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); |
610 } | 610 } |
611 | 611 |
612 TEST_F(AstDecoderTest, If_empty1) { | 612 TEST_F(FunctionBodyDecoderTest, If_empty1) { |
613 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); | 613 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); |
614 } | 614 } |
615 | 615 |
616 TEST_F(AstDecoderTest, If_empty2) { | 616 TEST_F(FunctionBodyDecoderTest, If_empty2) { |
617 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); | 617 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); |
618 } | 618 } |
619 | 619 |
620 TEST_F(AstDecoderTest, If_empty3) { | 620 TEST_F(FunctionBodyDecoderTest, If_empty3) { |
621 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); | 621 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); |
622 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); | 622 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); |
623 } | 623 } |
624 | 624 |
625 TEST_F(AstDecoderTest, If_empty4) { | 625 TEST_F(FunctionBodyDecoderTest, If_empty4) { |
626 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); | 626 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); |
627 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); | 627 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); |
628 } | 628 } |
629 | 629 |
630 TEST_F(AstDecoderTest, If_empty_stack) { | 630 TEST_F(FunctionBodyDecoderTest, If_empty_stack) { |
631 byte code[] = {kExprIf}; | 631 byte code[] = {kExprIf}; |
632 EXPECT_FAILURE_C(v_v, code); | 632 EXPECT_FAILURE_C(v_v, code); |
633 EXPECT_FAILURE_C(i_i, code); | 633 EXPECT_FAILURE_C(i_i, code); |
634 } | 634 } |
635 | 635 |
636 TEST_F(AstDecoderTest, If_incomplete1) { | 636 TEST_F(FunctionBodyDecoderTest, If_incomplete1) { |
637 byte code[] = {kExprI8Const, 0, kExprIf}; | 637 byte code[] = {kExprI8Const, 0, kExprIf}; |
638 EXPECT_FAILURE_C(v_v, code); | 638 EXPECT_FAILURE_C(v_v, code); |
639 EXPECT_FAILURE_C(i_i, code); | 639 EXPECT_FAILURE_C(i_i, code); |
640 } | 640 } |
641 | 641 |
642 TEST_F(AstDecoderTest, If_incomplete2) { | 642 TEST_F(FunctionBodyDecoderTest, If_incomplete2) { |
643 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; | 643 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; |
644 EXPECT_FAILURE_C(v_v, code); | 644 EXPECT_FAILURE_C(v_v, code); |
645 EXPECT_FAILURE_C(i_i, code); | 645 EXPECT_FAILURE_C(i_i, code); |
646 } | 646 } |
647 | 647 |
648 TEST_F(AstDecoderTest, If_else_else) { | 648 TEST_F(FunctionBodyDecoderTest, If_else_else) { |
649 byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; | 649 byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; |
650 EXPECT_FAILURE_C(v_v, code); | 650 EXPECT_FAILURE_C(v_v, code); |
651 EXPECT_FAILURE_C(i_i, code); | 651 EXPECT_FAILURE_C(i_i, code); |
652 } | 652 } |
653 | 653 |
654 TEST_F(AstDecoderTest, IfEmpty) { | 654 TEST_F(FunctionBodyDecoderTest, IfEmpty) { |
655 EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); | 655 EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); |
656 } | 656 } |
657 | 657 |
658 TEST_F(AstDecoderTest, IfSet) { | 658 TEST_F(FunctionBodyDecoderTest, IfSet) { |
659 EXPECT_VERIFIES(v_i, | 659 EXPECT_VERIFIES(v_i, |
660 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); | 660 WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO))); |
661 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), | 661 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), |
662 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); | 662 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
663 } | 663 } |
664 | 664 |
665 TEST_F(AstDecoderTest, IfElseEmpty) { | 665 TEST_F(FunctionBodyDecoderTest, IfElseEmpty) { |
666 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd); | 666 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), WASM_IF_OP, kExprElse, kExprEnd); |
667 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 667 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
668 } | 668 } |
669 | 669 |
670 TEST_F(AstDecoderTest, IfElseUnreachable1) { | 670 TEST_F(FunctionBodyDecoderTest, IfElseUnreachable1) { |
671 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, | 671 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, |
672 WASM_GET_LOCAL(0))); | 672 WASM_GET_LOCAL(0))); |
673 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), | 673 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
674 WASM_UNREACHABLE)); | 674 WASM_UNREACHABLE)); |
675 } | 675 } |
676 | 676 |
677 TEST_F(AstDecoderTest, IfElseUnreachable2) { | 677 TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) { |
678 static const byte code[] = { | 678 static const byte code[] = { |
679 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; | 679 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
680 | 680 |
681 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 681 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
682 LocalType types[] = {kAstI32, kLocalTypes[i]}; | 682 LocalType types[] = {kAstI32, kLocalTypes[i]}; |
683 FunctionSig sig(1, 1, types); | 683 FunctionSig sig(1, 1, types); |
684 | 684 |
685 if (kLocalTypes[i] == kAstI32) { | 685 if (kLocalTypes[i] == kAstI32) { |
686 EXPECT_VERIFIES_SC(&sig, code); | 686 EXPECT_VERIFIES_SC(&sig, code); |
687 } else { | 687 } else { |
688 EXPECT_FAILURE_SC(&sig, code); | 688 EXPECT_FAILURE_SC(&sig, code); |
689 } | 689 } |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 TEST_F(AstDecoderTest, IfBreak) { | 693 TEST_F(FunctionBodyDecoderTest, IfBreak) { |
694 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); | 694 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); |
695 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); | 695 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); |
696 EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); | 696 EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); |
697 } | 697 } |
698 | 698 |
699 TEST_F(AstDecoderTest, IfElseBreak) { | 699 TEST_F(FunctionBodyDecoderTest, IfElseBreak) { |
700 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); | 700 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); |
701 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); | 701 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); |
702 EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); | 702 EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); |
703 } | 703 } |
704 | 704 |
705 TEST_F(AstDecoderTest, Block_else) { | 705 TEST_F(FunctionBodyDecoderTest, Block_else) { |
706 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; | 706 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; |
707 EXPECT_FAILURE_C(v_v, code); | 707 EXPECT_FAILURE_C(v_v, code); |
708 EXPECT_FAILURE_C(i_i, code); | 708 EXPECT_FAILURE_C(i_i, code); |
709 } | 709 } |
710 | 710 |
711 TEST_F(AstDecoderTest, IfNop) { | 711 TEST_F(FunctionBodyDecoderTest, IfNop) { |
712 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 712 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
713 } | 713 } |
714 | 714 |
715 TEST_F(AstDecoderTest, IfNopElseNop) { | 715 TEST_F(FunctionBodyDecoderTest, IfNopElseNop) { |
716 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 716 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
717 } | 717 } |
718 | 718 |
719 TEST_F(AstDecoderTest, If_end_end) { | 719 TEST_F(FunctionBodyDecoderTest, If_end_end) { |
720 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; | 720 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; |
721 EXPECT_VERIFIES_C(v_i, code); | 721 EXPECT_VERIFIES_C(v_i, code); |
722 } | 722 } |
723 | 723 |
724 TEST_F(AstDecoderTest, If_end_end_end) { | 724 TEST_F(FunctionBodyDecoderTest, If_end_end_end) { |
725 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, | 725 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, |
726 kExprEnd, kExprEnd, kExprEnd}; | 726 kExprEnd, kExprEnd, kExprEnd}; |
727 EXPECT_FAILURE_C(v_i, code); | 727 EXPECT_FAILURE_C(v_i, code); |
728 } | 728 } |
729 | 729 |
730 TEST_F(AstDecoderTest, If_falloff1) { | 730 TEST_F(FunctionBodyDecoderTest, If_falloff1) { |
731 static const byte code[] = {kExprGetLocal, 0, kExprIf}; | 731 static const byte code[] = {kExprGetLocal, 0, kExprIf}; |
732 EXPECT_FAILURE_C(v_i, code); | 732 EXPECT_FAILURE_C(v_i, code); |
733 } | 733 } |
734 | 734 |
735 TEST_F(AstDecoderTest, If_falloff2) { | 735 TEST_F(FunctionBodyDecoderTest, If_falloff2) { |
736 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP}; | 736 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP}; |
737 EXPECT_FAILURE_C(v_i, code); | 737 EXPECT_FAILURE_C(v_i, code); |
738 } | 738 } |
739 | 739 |
740 TEST_F(AstDecoderTest, IfElse_falloff) { | 740 TEST_F(FunctionBodyDecoderTest, IfElse_falloff) { |
741 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop, | 741 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop, |
742 kExprElse}; | 742 kExprElse}; |
743 EXPECT_FAILURE_C(v_i, code); | 743 EXPECT_FAILURE_C(v_i, code); |
744 } | 744 } |
745 | 745 |
746 TEST_F(AstDecoderTest, IfElseNop) { | 746 TEST_F(FunctionBodyDecoderTest, IfElseNop) { |
747 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), | 747 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), |
748 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); | 748 WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP)); |
749 } | 749 } |
750 | 750 |
751 TEST_F(AstDecoderTest, IfBlock1) { | 751 TEST_F(FunctionBodyDecoderTest, IfBlock1) { |
752 EXPECT_VERIFIES( | 752 EXPECT_VERIFIES( |
753 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)), | 753 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)), |
754 WASM_NOP)); | 754 WASM_NOP)); |
755 } | 755 } |
756 | 756 |
757 TEST_F(AstDecoderTest, IfBlock1b) { | 757 TEST_F(FunctionBodyDecoderTest, IfBlock1b) { |
758 EXPECT_VERIFIES(v_i, | 758 EXPECT_VERIFIES(v_i, |
759 WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); | 759 WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO)))); |
760 } | 760 } |
761 | 761 |
762 TEST_F(AstDecoderTest, IfBlock2a) { | 762 TEST_F(FunctionBodyDecoderTest, IfBlock2a) { |
763 EXPECT_VERIFIES(v_i, | 763 EXPECT_VERIFIES(v_i, |
764 WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 764 WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
765 WASM_SET_LOCAL(0, WASM_ZERO)))); | 765 WASM_SET_LOCAL(0, WASM_ZERO)))); |
766 } | 766 } |
767 | 767 |
768 TEST_F(AstDecoderTest, IfBlock2b) { | 768 TEST_F(FunctionBodyDecoderTest, IfBlock2b) { |
769 EXPECT_VERIFIES( | 769 EXPECT_VERIFIES( |
770 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), | 770 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), |
771 WASM_SET_LOCAL(0, WASM_ZERO)), | 771 WASM_SET_LOCAL(0, WASM_ZERO)), |
772 WASM_NOP)); | 772 WASM_NOP)); |
773 } | 773 } |
774 | 774 |
775 TEST_F(AstDecoderTest, IfElseSet) { | 775 TEST_F(FunctionBodyDecoderTest, IfElseSet) { |
776 EXPECT_VERIFIES(v_i, | 776 EXPECT_VERIFIES(v_i, |
777 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), | 777 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), |
778 WASM_SET_LOCAL(0, WASM_I8(1)))); | 778 WASM_SET_LOCAL(0, WASM_I8(1)))); |
779 } | 779 } |
780 | 780 |
781 TEST_F(AstDecoderTest, Loop0) { EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); } | 781 TEST_F(FunctionBodyDecoderTest, Loop0) { |
| 782 EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); |
| 783 } |
782 | 784 |
783 TEST_F(AstDecoderTest, Loop1) { | 785 TEST_F(FunctionBodyDecoderTest, Loop1) { |
784 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; | 786 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; |
785 EXPECT_VERIFIES_C(v_i, code); | 787 EXPECT_VERIFIES_C(v_i, code); |
786 EXPECT_FAILURE_C(v_v, code); | 788 EXPECT_FAILURE_C(v_v, code); |
787 EXPECT_FAILURE_C(f_ff, code); | 789 EXPECT_FAILURE_C(f_ff, code); |
788 } | 790 } |
789 | 791 |
790 TEST_F(AstDecoderTest, Loop2) { | 792 TEST_F(FunctionBodyDecoderTest, Loop2) { |
791 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), | 793 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), |
792 WASM_SET_LOCAL(0, WASM_ZERO))); | 794 WASM_SET_LOCAL(0, WASM_ZERO))); |
793 } | 795 } |
794 | 796 |
795 TEST_F(AstDecoderTest, Loop1_continue) { | 797 TEST_F(FunctionBodyDecoderTest, Loop1_continue) { |
796 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); | 798 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
797 } | 799 } |
798 | 800 |
799 TEST_F(AstDecoderTest, Loop1_break) { | 801 TEST_F(FunctionBodyDecoderTest, Loop1_break) { |
800 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1))); | 802 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(1))); |
801 } | 803 } |
802 | 804 |
803 TEST_F(AstDecoderTest, Loop2_continue) { | 805 TEST_F(FunctionBodyDecoderTest, Loop2_continue) { |
804 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); | 806 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); |
805 } | 807 } |
806 | 808 |
807 TEST_F(AstDecoderTest, Loop2_break) { | 809 TEST_F(FunctionBodyDecoderTest, Loop2_break) { |
808 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); | 810 EXPECT_VERIFIES(v_i, WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); |
809 } | 811 } |
810 | 812 |
811 TEST_F(AstDecoderTest, InfiniteLoop) { | 813 TEST_F(FunctionBodyDecoderTest, InfiniteLoop) { |
812 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0))); | 814 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0))); |
813 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO))); | 815 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BRV(1, WASM_ZERO))); |
814 } | 816 } |
815 | 817 |
816 TEST_F(AstDecoderTest, Loop2_unreachable) { | 818 TEST_F(FunctionBodyDecoderTest, Loop2_unreachable) { |
817 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP)); | 819 EXPECT_VERIFIES(i_i, WASM_LOOP(WASM_BR(0), WASM_NOP)); |
818 } | 820 } |
819 | 821 |
820 TEST_F(AstDecoderTest, LoopType) { | 822 TEST_F(FunctionBodyDecoderTest, LoopType) { |
821 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); | 823 EXPECT_VERIFIES(i_i, WASM_LOOP_I(WASM_GET_LOCAL(0))); |
822 EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); | 824 EXPECT_VERIFIES(l_l, WASM_LOOP_L(WASM_GET_LOCAL(0))); |
823 EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); | 825 EXPECT_VERIFIES(f_f, WASM_LOOP_F(WASM_GET_LOCAL(0))); |
824 EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); | 826 EXPECT_VERIFIES(d_d, WASM_LOOP_D(WASM_GET_LOCAL(0))); |
825 } | 827 } |
826 | 828 |
827 TEST_F(AstDecoderTest, LoopType_void) { | 829 TEST_F(FunctionBodyDecoderTest, LoopType_void) { |
828 EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO)); | 830 EXPECT_FAILURE(v_v, WASM_LOOP_I(WASM_ZERO)); |
829 EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0))); | 831 EXPECT_FAILURE(v_v, WASM_LOOP_L(WASM_I64V_1(0))); |
830 EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0))); | 832 EXPECT_FAILURE(v_v, WASM_LOOP_F(WASM_F32(0.0))); |
831 EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1))); | 833 EXPECT_FAILURE(v_v, WASM_LOOP_D(WASM_F64(1.1))); |
832 } | 834 } |
833 | 835 |
834 TEST_F(AstDecoderTest, LoopType_fail) { | 836 TEST_F(FunctionBodyDecoderTest, LoopType_fail) { |
835 EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0))); | 837 EXPECT_FAILURE(i_i, WASM_LOOP_L(WASM_I64V_1(0))); |
836 EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0))); | 838 EXPECT_FAILURE(i_i, WASM_LOOP_F(WASM_F32(0.0))); |
837 EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1))); | 839 EXPECT_FAILURE(i_i, WASM_LOOP_D(WASM_F64(1.1))); |
838 | 840 |
839 EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO)); | 841 EXPECT_FAILURE(l_l, WASM_LOOP_I(WASM_ZERO)); |
840 EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0))); | 842 EXPECT_FAILURE(l_l, WASM_LOOP_F(WASM_F32(0.0))); |
841 EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1))); | 843 EXPECT_FAILURE(l_l, WASM_LOOP_D(WASM_F64(1.1))); |
842 | 844 |
843 EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO)); | 845 EXPECT_FAILURE(f_ff, WASM_LOOP_I(WASM_ZERO)); |
844 EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0))); | 846 EXPECT_FAILURE(f_ff, WASM_LOOP_L(WASM_I64V_1(0))); |
845 EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1))); | 847 EXPECT_FAILURE(f_ff, WASM_LOOP_D(WASM_F64(1.1))); |
846 | 848 |
847 EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO)); | 849 EXPECT_FAILURE(d_dd, WASM_LOOP_I(WASM_ZERO)); |
848 EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0))); | 850 EXPECT_FAILURE(d_dd, WASM_LOOP_L(WASM_I64V_1(0))); |
849 EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0))); | 851 EXPECT_FAILURE(d_dd, WASM_LOOP_F(WASM_F32(0.0))); |
850 } | 852 } |
851 | 853 |
852 TEST_F(AstDecoderTest, ReturnVoid1) { | 854 TEST_F(FunctionBodyDecoderTest, ReturnVoid1) { |
853 static const byte code[] = {kExprNop}; | 855 static const byte code[] = {kExprNop}; |
854 EXPECT_VERIFIES_C(v_v, code); | 856 EXPECT_VERIFIES_C(v_v, code); |
855 EXPECT_FAILURE_C(i_i, code); | 857 EXPECT_FAILURE_C(i_i, code); |
856 EXPECT_FAILURE_C(i_f, code); | 858 EXPECT_FAILURE_C(i_f, code); |
857 } | 859 } |
858 | 860 |
859 TEST_F(AstDecoderTest, ReturnVoid2) { | 861 TEST_F(FunctionBodyDecoderTest, ReturnVoid2) { |
860 static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; | 862 static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; |
861 EXPECT_VERIFIES_C(v_v, code); | 863 EXPECT_VERIFIES_C(v_v, code); |
862 EXPECT_FAILURE_C(i_i, code); | 864 EXPECT_FAILURE_C(i_i, code); |
863 EXPECT_FAILURE_C(i_f, code); | 865 EXPECT_FAILURE_C(i_f, code); |
864 } | 866 } |
865 | 867 |
866 TEST_F(AstDecoderTest, ReturnVoid3) { | 868 TEST_F(FunctionBodyDecoderTest, ReturnVoid3) { |
867 EXPECT_FAILURE(v_v, kExprI8Const, 0); | 869 EXPECT_FAILURE(v_v, kExprI8Const, 0); |
868 EXPECT_FAILURE(v_v, kExprI32Const, 0); | 870 EXPECT_FAILURE(v_v, kExprI32Const, 0); |
869 EXPECT_FAILURE(v_v, kExprI64Const, 0); | 871 EXPECT_FAILURE(v_v, kExprI64Const, 0); |
870 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); | 872 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); |
871 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); | 873 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); |
872 | 874 |
873 EXPECT_FAILURE(v_i, kExprGetLocal, 0); | 875 EXPECT_FAILURE(v_i, kExprGetLocal, 0); |
874 } | 876 } |
875 | 877 |
876 TEST_F(AstDecoderTest, Unreachable1) { | 878 TEST_F(FunctionBodyDecoderTest, Unreachable1) { |
877 EXPECT_VERIFIES(v_v, kExprUnreachable); | 879 EXPECT_VERIFIES(v_v, kExprUnreachable); |
878 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); | 880 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); |
879 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); | 881 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); |
880 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO)); | 882 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO)); |
881 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); | 883 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); |
882 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); | 884 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); |
883 } | 885 } |
884 | 886 |
885 TEST_F(AstDecoderTest, Unreachable_binop) { | 887 TEST_F(FunctionBodyDecoderTest, Unreachable_binop) { |
886 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); | 888 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); |
887 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); | 889 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); |
888 } | 890 } |
889 | 891 |
890 TEST_F(AstDecoderTest, Unreachable_select) { | 892 TEST_F(FunctionBodyDecoderTest, Unreachable_select) { |
891 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); | 893 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); |
892 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); | 894 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); |
893 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); | 895 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); |
894 } | 896 } |
895 | 897 |
896 TEST_F(AstDecoderTest, If1) { | 898 TEST_F(FunctionBodyDecoderTest, If1) { |
897 EXPECT_VERIFIES(i_i, | 899 EXPECT_VERIFIES(i_i, |
898 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); | 900 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8))); |
899 EXPECT_VERIFIES( | 901 EXPECT_VERIFIES( |
900 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); | 902 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); |
901 EXPECT_VERIFIES( | 903 EXPECT_VERIFIES( |
902 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); | 904 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); |
903 } | 905 } |
904 | 906 |
905 TEST_F(AstDecoderTest, If_off_end) { | 907 TEST_F(FunctionBodyDecoderTest, If_off_end) { |
906 static const byte kCode[] = { | 908 static const byte kCode[] = { |
907 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; | 909 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; |
908 for (size_t len = 3; len < arraysize(kCode); len++) { | 910 for (size_t len = 3; len < arraysize(kCode); len++) { |
909 Verify(kError, sigs.i_i(), kCode, kCode + len); | 911 Verify(kError, sigs.i_i(), kCode, kCode + len); |
910 } | 912 } |
911 } | 913 } |
912 | 914 |
913 TEST_F(AstDecoderTest, If_type1) { | 915 TEST_F(FunctionBodyDecoderTest, If_type1) { |
914 // float|double ? 1 : 2 | 916 // float|double ? 1 : 2 |
915 static const byte kCode[] = { | 917 static const byte kCode[] = { |
916 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; | 918 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; |
917 EXPECT_VERIFIES_C(i_i, kCode); | 919 EXPECT_VERIFIES_C(i_i, kCode); |
918 EXPECT_FAILURE_C(i_f, kCode); | 920 EXPECT_FAILURE_C(i_f, kCode); |
919 EXPECT_FAILURE_C(i_d, kCode); | 921 EXPECT_FAILURE_C(i_d, kCode); |
920 } | 922 } |
921 | 923 |
922 TEST_F(AstDecoderTest, If_type2) { | 924 TEST_F(FunctionBodyDecoderTest, If_type2) { |
923 // 1 ? float|double : 2 | 925 // 1 ? float|double : 2 |
924 static const byte kCode[] = { | 926 static const byte kCode[] = { |
925 WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; | 927 WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; |
926 EXPECT_VERIFIES_C(i_i, kCode); | 928 EXPECT_VERIFIES_C(i_i, kCode); |
927 EXPECT_FAILURE_C(i_f, kCode); | 929 EXPECT_FAILURE_C(i_f, kCode); |
928 EXPECT_FAILURE_C(i_d, kCode); | 930 EXPECT_FAILURE_C(i_d, kCode); |
929 } | 931 } |
930 | 932 |
931 TEST_F(AstDecoderTest, If_type3) { | 933 TEST_F(FunctionBodyDecoderTest, If_type3) { |
932 // stmt ? 0 : 1 | 934 // stmt ? 0 : 1 |
933 static const byte kCode[] = { | 935 static const byte kCode[] = { |
934 WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; | 936 WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; |
935 EXPECT_FAILURE_C(i_i, kCode); | 937 EXPECT_FAILURE_C(i_i, kCode); |
936 EXPECT_FAILURE_C(i_f, kCode); | 938 EXPECT_FAILURE_C(i_f, kCode); |
937 EXPECT_FAILURE_C(i_d, kCode); | 939 EXPECT_FAILURE_C(i_d, kCode); |
938 } | 940 } |
939 | 941 |
940 TEST_F(AstDecoderTest, If_type4) { | 942 TEST_F(FunctionBodyDecoderTest, If_type4) { |
941 // 0 ? stmt : 1 | 943 // 0 ? stmt : 1 |
942 static const byte kCode[] = { | 944 static const byte kCode[] = { |
943 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; | 945 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; |
944 EXPECT_FAILURE_C(i_i, kCode); | 946 EXPECT_FAILURE_C(i_i, kCode); |
945 EXPECT_FAILURE_C(i_f, kCode); | 947 EXPECT_FAILURE_C(i_f, kCode); |
946 EXPECT_FAILURE_C(i_d, kCode); | 948 EXPECT_FAILURE_C(i_d, kCode); |
947 } | 949 } |
948 | 950 |
949 TEST_F(AstDecoderTest, If_type5) { | 951 TEST_F(FunctionBodyDecoderTest, If_type5) { |
950 // 0 ? 1 : stmt | 952 // 0 ? 1 : stmt |
951 static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; | 953 static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; |
952 EXPECT_FAILURE_C(i_i, kCode); | 954 EXPECT_FAILURE_C(i_i, kCode); |
953 EXPECT_FAILURE_C(i_f, kCode); | 955 EXPECT_FAILURE_C(i_f, kCode); |
954 EXPECT_FAILURE_C(i_d, kCode); | 956 EXPECT_FAILURE_C(i_d, kCode); |
955 } | 957 } |
956 | 958 |
957 TEST_F(AstDecoderTest, Int64Local_param) { | 959 TEST_F(FunctionBodyDecoderTest, Int64Local_param) { |
958 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); | 960 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); |
959 } | 961 } |
960 | 962 |
961 TEST_F(AstDecoderTest, Int64Locals) { | 963 TEST_F(FunctionBodyDecoderTest, Int64Locals) { |
962 for (byte i = 1; i < 8; i++) { | 964 for (byte i = 1; i < 8; i++) { |
963 AddLocals(kAstI64, 1); | 965 AddLocals(kAstI64, 1); |
964 for (byte j = 0; j < i; j++) { | 966 for (byte j = 0; j < i; j++) { |
965 EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); | 967 EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); |
966 } | 968 } |
967 } | 969 } |
968 } | 970 } |
969 | 971 |
970 TEST_F(AstDecoderTest, Int32Binops) { | 972 TEST_F(FunctionBodyDecoderTest, Int32Binops) { |
971 TestBinop(kExprI32Add, sigs.i_ii()); | 973 TestBinop(kExprI32Add, sigs.i_ii()); |
972 TestBinop(kExprI32Sub, sigs.i_ii()); | 974 TestBinop(kExprI32Sub, sigs.i_ii()); |
973 TestBinop(kExprI32Mul, sigs.i_ii()); | 975 TestBinop(kExprI32Mul, sigs.i_ii()); |
974 TestBinop(kExprI32DivS, sigs.i_ii()); | 976 TestBinop(kExprI32DivS, sigs.i_ii()); |
975 TestBinop(kExprI32DivU, sigs.i_ii()); | 977 TestBinop(kExprI32DivU, sigs.i_ii()); |
976 TestBinop(kExprI32RemS, sigs.i_ii()); | 978 TestBinop(kExprI32RemS, sigs.i_ii()); |
977 TestBinop(kExprI32RemU, sigs.i_ii()); | 979 TestBinop(kExprI32RemU, sigs.i_ii()); |
978 TestBinop(kExprI32And, sigs.i_ii()); | 980 TestBinop(kExprI32And, sigs.i_ii()); |
979 TestBinop(kExprI32Ior, sigs.i_ii()); | 981 TestBinop(kExprI32Ior, sigs.i_ii()); |
980 TestBinop(kExprI32Xor, sigs.i_ii()); | 982 TestBinop(kExprI32Xor, sigs.i_ii()); |
981 TestBinop(kExprI32Shl, sigs.i_ii()); | 983 TestBinop(kExprI32Shl, sigs.i_ii()); |
982 TestBinop(kExprI32ShrU, sigs.i_ii()); | 984 TestBinop(kExprI32ShrU, sigs.i_ii()); |
983 TestBinop(kExprI32ShrS, sigs.i_ii()); | 985 TestBinop(kExprI32ShrS, sigs.i_ii()); |
984 TestBinop(kExprI32Eq, sigs.i_ii()); | 986 TestBinop(kExprI32Eq, sigs.i_ii()); |
985 TestBinop(kExprI32LtS, sigs.i_ii()); | 987 TestBinop(kExprI32LtS, sigs.i_ii()); |
986 TestBinop(kExprI32LeS, sigs.i_ii()); | 988 TestBinop(kExprI32LeS, sigs.i_ii()); |
987 TestBinop(kExprI32LtU, sigs.i_ii()); | 989 TestBinop(kExprI32LtU, sigs.i_ii()); |
988 TestBinop(kExprI32LeU, sigs.i_ii()); | 990 TestBinop(kExprI32LeU, sigs.i_ii()); |
989 } | 991 } |
990 | 992 |
991 TEST_F(AstDecoderTest, DoubleBinops) { | 993 TEST_F(FunctionBodyDecoderTest, DoubleBinops) { |
992 TestBinop(kExprF64Add, sigs.d_dd()); | 994 TestBinop(kExprF64Add, sigs.d_dd()); |
993 TestBinop(kExprF64Sub, sigs.d_dd()); | 995 TestBinop(kExprF64Sub, sigs.d_dd()); |
994 TestBinop(kExprF64Mul, sigs.d_dd()); | 996 TestBinop(kExprF64Mul, sigs.d_dd()); |
995 TestBinop(kExprF64Div, sigs.d_dd()); | 997 TestBinop(kExprF64Div, sigs.d_dd()); |
996 | 998 |
997 TestBinop(kExprF64Eq, sigs.i_dd()); | 999 TestBinop(kExprF64Eq, sigs.i_dd()); |
998 TestBinop(kExprF64Lt, sigs.i_dd()); | 1000 TestBinop(kExprF64Lt, sigs.i_dd()); |
999 TestBinop(kExprF64Le, sigs.i_dd()); | 1001 TestBinop(kExprF64Le, sigs.i_dd()); |
1000 } | 1002 } |
1001 | 1003 |
1002 TEST_F(AstDecoderTest, FloatBinops) { | 1004 TEST_F(FunctionBodyDecoderTest, FloatBinops) { |
1003 TestBinop(kExprF32Add, sigs.f_ff()); | 1005 TestBinop(kExprF32Add, sigs.f_ff()); |
1004 TestBinop(kExprF32Sub, sigs.f_ff()); | 1006 TestBinop(kExprF32Sub, sigs.f_ff()); |
1005 TestBinop(kExprF32Mul, sigs.f_ff()); | 1007 TestBinop(kExprF32Mul, sigs.f_ff()); |
1006 TestBinop(kExprF32Div, sigs.f_ff()); | 1008 TestBinop(kExprF32Div, sigs.f_ff()); |
1007 | 1009 |
1008 TestBinop(kExprF32Eq, sigs.i_ff()); | 1010 TestBinop(kExprF32Eq, sigs.i_ff()); |
1009 TestBinop(kExprF32Lt, sigs.i_ff()); | 1011 TestBinop(kExprF32Lt, sigs.i_ff()); |
1010 TestBinop(kExprF32Le, sigs.i_ff()); | 1012 TestBinop(kExprF32Le, sigs.i_ff()); |
1011 } | 1013 } |
1012 | 1014 |
1013 TEST_F(AstDecoderTest, TypeConversions) { | 1015 TEST_F(FunctionBodyDecoderTest, TypeConversions) { |
1014 TestUnop(kExprI32SConvertF32, kAstI32, kAstF32); | 1016 TestUnop(kExprI32SConvertF32, kAstI32, kAstF32); |
1015 TestUnop(kExprI32SConvertF64, kAstI32, kAstF64); | 1017 TestUnop(kExprI32SConvertF64, kAstI32, kAstF64); |
1016 TestUnop(kExprI32UConvertF32, kAstI32, kAstF32); | 1018 TestUnop(kExprI32UConvertF32, kAstI32, kAstF32); |
1017 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); | 1019 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); |
1018 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); | 1020 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); |
1019 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); | 1021 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); |
1020 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); | 1022 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); |
1021 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); | 1023 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); |
1022 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); | 1024 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); |
1023 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); | 1025 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); |
1024 } | 1026 } |
1025 | 1027 |
1026 TEST_F(AstDecoderTest, MacrosStmt) { | 1028 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { |
1027 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); | 1029 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
1028 EXPECT_VERIFIES( | 1030 EXPECT_VERIFIES( |
1029 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); | 1031 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); |
1030 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 1032 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
1031 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 1033 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
1032 EXPECT_VERIFIES(v_v, WASM_NOP); | 1034 EXPECT_VERIFIES(v_v, WASM_NOP); |
1033 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); | 1035 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); |
1034 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); | 1036 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); |
1035 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); | 1037 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
1036 } | 1038 } |
1037 | 1039 |
1038 TEST_F(AstDecoderTest, MacrosContinue) { | 1040 TEST_F(FunctionBodyDecoderTest, MacrosContinue) { |
1039 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); | 1041 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); |
1040 } | 1042 } |
1041 | 1043 |
1042 TEST_F(AstDecoderTest, MacrosVariadic) { | 1044 TEST_F(FunctionBodyDecoderTest, MacrosVariadic) { |
1043 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP)); | 1045 EXPECT_VERIFIES(v_v, B2(WASM_NOP, WASM_NOP)); |
1044 EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP)); | 1046 EXPECT_VERIFIES(v_v, B3(WASM_NOP, WASM_NOP, WASM_NOP)); |
1045 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP)); | 1047 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP)); |
1046 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); | 1048 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP)); |
1047 } | 1049 } |
1048 | 1050 |
1049 TEST_F(AstDecoderTest, MacrosNestedBlocks) { | 1051 TEST_F(FunctionBodyDecoderTest, MacrosNestedBlocks) { |
1050 EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); | 1052 EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); |
1051 EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- | 1053 EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- |
1052 B2(WASM_NOP, WASM_NOP), // -- | 1054 B2(WASM_NOP, WASM_NOP), // -- |
1053 B2(WASM_NOP, WASM_NOP))); // -- | 1055 B2(WASM_NOP, WASM_NOP))); // -- |
1054 EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); | 1056 EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); |
1055 } | 1057 } |
1056 | 1058 |
1057 TEST_F(AstDecoderTest, MultipleReturn) { | 1059 TEST_F(FunctionBodyDecoderTest, MultipleReturn) { |
1058 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1060 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
1059 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1061 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
1060 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1062 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
1061 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); | 1063 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
1062 | 1064 |
1063 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1065 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
1064 EXPECT_VERIFIES_S(&sig_iii_v, | 1066 EXPECT_VERIFIES_S(&sig_iii_v, |
1065 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); | 1067 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
1066 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1068 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
1067 } | 1069 } |
1068 | 1070 |
1069 TEST_F(AstDecoderTest, MultipleReturn_fallthru) { | 1071 TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { |
1070 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1072 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; |
1071 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1073 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
1072 | 1074 |
1073 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); | 1075 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); |
1074 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); | 1076 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); |
1075 | 1077 |
1076 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1078 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
1077 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); | 1079 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); |
1078 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); | 1080 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); |
1079 } | 1081 } |
1080 | 1082 |
1081 TEST_F(AstDecoderTest, MacrosInt32) { | 1083 TEST_F(FunctionBodyDecoderTest, MacrosInt32) { |
1082 EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); | 1084 EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); |
1083 EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); | 1085 EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); |
1084 EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); | 1086 EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); |
1085 EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); | 1087 EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); |
1086 EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); | 1088 EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); |
1087 EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); | 1089 EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); |
1088 EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); | 1090 EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); |
1089 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); | 1091 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); |
1090 EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); | 1092 EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); |
1091 EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); | 1093 EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); |
1092 EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); | 1094 EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); |
1093 EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); | 1095 EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); |
1094 EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); | 1096 EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); |
1095 EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); | 1097 EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); |
1096 EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); | 1098 EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); |
1097 EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); | 1099 EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); |
1098 EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); | 1100 EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); |
1099 | 1101 |
1100 EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); | 1102 EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
1101 EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); | 1103 EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); |
1102 EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); | 1104 EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
1103 EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); | 1105 EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
1104 | 1106 |
1105 EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); | 1107 EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); |
1106 EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); | 1108 EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); |
1107 EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); | 1109 EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); |
1108 EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); | 1110 EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); |
1109 } | 1111 } |
1110 | 1112 |
1111 TEST_F(AstDecoderTest, MacrosInt64) { | 1113 TEST_F(FunctionBodyDecoderTest, MacrosInt64) { |
1112 EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); | 1114 EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); |
1113 EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); | 1115 EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); |
1114 EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); | 1116 EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); |
1115 EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); | 1117 EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); |
1116 EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); | 1118 EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); |
1117 EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); | 1119 EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); |
1118 EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); | 1120 EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); |
1119 EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); | 1121 EXPECT_VERIFIES(l_ll, WASM_I64_AND(WASM_GET_LOCAL(0), WASM_I64V_1(19))); |
1120 EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); | 1122 EXPECT_VERIFIES(l_ll, WASM_I64_IOR(WASM_GET_LOCAL(0), WASM_I64V_1(20))); |
1121 EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); | 1123 EXPECT_VERIFIES(l_ll, WASM_I64_XOR(WASM_GET_LOCAL(0), WASM_I64V_1(21))); |
(...skipping 11 matching lines...) Expand all Loading... |
1133 | 1135 |
1134 EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); | 1136 EXPECT_VERIFIES(i_ll, WASM_I64_GTS(WASM_GET_LOCAL(0), WASM_I64V_1(26))); |
1135 EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); | 1137 EXPECT_VERIFIES(i_ll, WASM_I64_GES(WASM_GET_LOCAL(0), WASM_I64V_1(27))); |
1136 EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); | 1138 EXPECT_VERIFIES(i_ll, WASM_I64_GTU(WASM_GET_LOCAL(0), WASM_I64V_1(28))); |
1137 EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); | 1139 EXPECT_VERIFIES(i_ll, WASM_I64_GEU(WASM_GET_LOCAL(0), WASM_I64V_1(29))); |
1138 | 1140 |
1139 EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); | 1141 EXPECT_VERIFIES(i_ll, WASM_I64_EQ(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
1140 EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); | 1142 EXPECT_VERIFIES(i_ll, WASM_I64_NE(WASM_GET_LOCAL(0), WASM_I64V_1(25))); |
1141 } | 1143 } |
1142 | 1144 |
1143 TEST_F(AstDecoderTest, AllSimpleExpressions) { | 1145 TEST_F(FunctionBodyDecoderTest, AllSimpleExpressions) { |
1144 // Test all simple expressions which are described by a signature. | 1146 // Test all simple expressions which are described by a signature. |
1145 #define DECODE_TEST(name, opcode, sig) \ | 1147 #define DECODE_TEST(name, opcode, sig) \ |
1146 { \ | 1148 { \ |
1147 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \ | 1149 FunctionSig* sig = WasmOpcodes::Signature(kExpr##name); \ |
1148 if (sig->parameter_count() == 1) { \ | 1150 if (sig->parameter_count() == 1) { \ |
1149 TestUnop(kExpr##name, sig); \ | 1151 TestUnop(kExpr##name, sig); \ |
1150 } else { \ | 1152 } else { \ |
1151 TestBinop(kExpr##name, sig); \ | 1153 TestBinop(kExpr##name, sig); \ |
1152 } \ | 1154 } \ |
1153 } | 1155 } |
1154 | 1156 |
1155 FOREACH_SIMPLE_OPCODE(DECODE_TEST); | 1157 FOREACH_SIMPLE_OPCODE(DECODE_TEST); |
1156 | 1158 |
1157 #undef DECODE_TEST | 1159 #undef DECODE_TEST |
1158 } | 1160 } |
1159 | 1161 |
1160 TEST_F(AstDecoderTest, MemorySize) { | 1162 TEST_F(FunctionBodyDecoderTest, MemorySize) { |
1161 byte code[] = {kExprMemorySize, 0}; | 1163 byte code[] = {kExprMemorySize, 0}; |
1162 EXPECT_VERIFIES_C(i_i, code); | 1164 EXPECT_VERIFIES_C(i_i, code); |
1163 EXPECT_FAILURE_C(f_ff, code); | 1165 EXPECT_FAILURE_C(f_ff, code); |
1164 } | 1166 } |
1165 | 1167 |
1166 TEST_F(AstDecoderTest, LoadMemOffset) { | 1168 TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { |
1167 for (int offset = 0; offset < 128; offset += 7) { | 1169 for (int offset = 0; offset < 128; offset += 7) { |
1168 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, | 1170 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, |
1169 static_cast<byte>(offset)}; | 1171 static_cast<byte>(offset)}; |
1170 EXPECT_VERIFIES_C(i_i, code); | 1172 EXPECT_VERIFIES_C(i_i, code); |
1171 } | 1173 } |
1172 } | 1174 } |
1173 | 1175 |
1174 TEST_F(AstDecoderTest, LoadMemAlignment) { | 1176 TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) { |
1175 struct { | 1177 struct { |
1176 WasmOpcode instruction; | 1178 WasmOpcode instruction; |
1177 uint32_t maximum_aligment; | 1179 uint32_t maximum_aligment; |
1178 } values[] = { | 1180 } values[] = { |
1179 {kExprI32LoadMem8U, 0}, // -- | 1181 {kExprI32LoadMem8U, 0}, // -- |
1180 {kExprI32LoadMem8S, 0}, // -- | 1182 {kExprI32LoadMem8S, 0}, // -- |
1181 {kExprI32LoadMem16U, 1}, // -- | 1183 {kExprI32LoadMem16U, 1}, // -- |
1182 {kExprI32LoadMem16S, 1}, // -- | 1184 {kExprI32LoadMem16S, 1}, // -- |
1183 {kExprI64LoadMem8U, 0}, // -- | 1185 {kExprI64LoadMem8U, 0}, // -- |
1184 {kExprI64LoadMem8S, 0}, // -- | 1186 {kExprI64LoadMem8S, 0}, // -- |
(...skipping 13 matching lines...) Expand all Loading... |
1198 alignment, ZERO_OFFSET, WASM_DROP}; | 1200 alignment, ZERO_OFFSET, WASM_DROP}; |
1199 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { | 1201 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { |
1200 EXPECT_VERIFIES_C(v_i, code); | 1202 EXPECT_VERIFIES_C(v_i, code); |
1201 } else { | 1203 } else { |
1202 EXPECT_FAILURE_C(v_i, code); | 1204 EXPECT_FAILURE_C(v_i, code); |
1203 } | 1205 } |
1204 } | 1206 } |
1205 } | 1207 } |
1206 } | 1208 } |
1207 | 1209 |
1208 TEST_F(AstDecoderTest, StoreMemOffset) { | 1210 TEST_F(FunctionBodyDecoderTest, StoreMemOffset) { |
1209 for (int offset = 0; offset < 128; offset += 7) { | 1211 for (int offset = 0; offset < 128; offset += 7) { |
1210 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, | 1212 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, |
1211 WASM_ZERO, WASM_ZERO)}; | 1213 WASM_ZERO, WASM_ZERO)}; |
1212 EXPECT_VERIFIES_C(v_i, code); | 1214 EXPECT_VERIFIES_C(v_i, code); |
1213 } | 1215 } |
1214 } | 1216 } |
1215 | 1217 |
1216 TEST_F(AstDecoderTest, StoreMemOffset_void) { | 1218 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) { |
1217 EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, | 1219 EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, |
1218 WASM_ZERO)); | 1220 WASM_ZERO)); |
1219 } | 1221 } |
1220 | 1222 |
1221 #define BYTE0(x) ((x)&0x7F) | 1223 #define BYTE0(x) ((x)&0x7F) |
1222 #define BYTE1(x) ((x >> 7) & 0x7F) | 1224 #define BYTE1(x) ((x >> 7) & 0x7F) |
1223 #define BYTE2(x) ((x >> 14) & 0x7F) | 1225 #define BYTE2(x) ((x >> 14) & 0x7F) |
1224 #define BYTE3(x) ((x >> 21) & 0x7F) | 1226 #define BYTE3(x) ((x >> 21) & 0x7F) |
1225 | 1227 |
1226 #define VARINT1(x) BYTE0(x) | 1228 #define VARINT1(x) BYTE0(x) |
1227 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) | 1229 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) |
1228 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 1230 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) |
1229 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) | 1231 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) |
1230 | 1232 |
1231 TEST_F(AstDecoderTest, LoadMemOffset_varint) { | 1233 TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) { |
1232 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1234 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1233 VARINT1(0x45)); | 1235 VARINT1(0x45)); |
1234 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1236 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1235 VARINT2(0x3999)); | 1237 VARINT2(0x3999)); |
1236 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1238 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1237 VARINT3(0x344445)); | 1239 VARINT3(0x344445)); |
1238 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1240 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1239 VARINT4(0x36666667)); | 1241 VARINT4(0x36666667)); |
1240 } | 1242 } |
1241 | 1243 |
1242 TEST_F(AstDecoderTest, StoreMemOffset_varint) { | 1244 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) { |
1243 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1245 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1244 VARINT1(0x33)); | 1246 VARINT1(0x33)); |
1245 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1247 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1246 VARINT2(0x1111)); | 1248 VARINT2(0x1111)); |
1247 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1249 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1248 VARINT3(0x222222)); | 1250 VARINT3(0x222222)); |
1249 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1251 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1250 VARINT4(0x44444444)); | 1252 VARINT4(0x44444444)); |
1251 } | 1253 } |
1252 | 1254 |
1253 TEST_F(AstDecoderTest, AllLoadMemCombinations) { | 1255 TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { |
1254 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1256 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1255 LocalType local_type = kLocalTypes[i]; | 1257 LocalType local_type = kLocalTypes[i]; |
1256 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1258 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1257 MachineType mem_type = machineTypes[j]; | 1259 MachineType mem_type = machineTypes[j]; |
1258 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; | 1260 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; |
1259 FunctionSig sig(1, 0, &local_type); | 1261 FunctionSig sig(1, 0, &local_type); |
1260 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1262 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
1261 EXPECT_VERIFIES_SC(&sig, code); | 1263 EXPECT_VERIFIES_SC(&sig, code); |
1262 } else { | 1264 } else { |
1263 EXPECT_FAILURE_SC(&sig, code); | 1265 EXPECT_FAILURE_SC(&sig, code); |
1264 } | 1266 } |
1265 } | 1267 } |
1266 } | 1268 } |
1267 } | 1269 } |
1268 | 1270 |
1269 TEST_F(AstDecoderTest, AllStoreMemCombinations) { | 1271 TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { |
1270 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1272 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1271 LocalType local_type = kLocalTypes[i]; | 1273 LocalType local_type = kLocalTypes[i]; |
1272 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1274 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1273 MachineType mem_type = machineTypes[j]; | 1275 MachineType mem_type = machineTypes[j]; |
1274 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; | 1276 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; |
1275 FunctionSig sig(0, 1, &local_type); | 1277 FunctionSig sig(0, 1, &local_type); |
1276 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1278 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { |
1277 EXPECT_VERIFIES_SC(&sig, code); | 1279 EXPECT_VERIFIES_SC(&sig, code); |
1278 } else { | 1280 } else { |
1279 EXPECT_FAILURE_SC(&sig, code); | 1281 EXPECT_FAILURE_SC(&sig, code); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 void InitializeFunctionTable() { | 1325 void InitializeFunctionTable() { |
1324 mod.function_tables.push_back( | 1326 mod.function_tables.push_back( |
1325 {0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()}); | 1327 {0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()}); |
1326 } | 1328 } |
1327 | 1329 |
1328 private: | 1330 private: |
1329 WasmModule mod; | 1331 WasmModule mod; |
1330 }; | 1332 }; |
1331 } // namespace | 1333 } // namespace |
1332 | 1334 |
1333 TEST_F(AstDecoderTest, SimpleCalls) { | 1335 TEST_F(FunctionBodyDecoderTest, SimpleCalls) { |
1334 FunctionSig* sig = sigs.i_i(); | 1336 FunctionSig* sig = sigs.i_i(); |
1335 TestModuleEnv module_env; | 1337 TestModuleEnv module_env; |
1336 module = &module_env; | 1338 module = &module_env; |
1337 | 1339 |
1338 module_env.AddFunction(sigs.i_v()); | 1340 module_env.AddFunction(sigs.i_v()); |
1339 module_env.AddFunction(sigs.i_i()); | 1341 module_env.AddFunction(sigs.i_i()); |
1340 module_env.AddFunction(sigs.i_ii()); | 1342 module_env.AddFunction(sigs.i_ii()); |
1341 | 1343 |
1342 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); | 1344 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); |
1343 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); | 1345 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); |
1344 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); | 1346 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); |
1345 } | 1347 } |
1346 | 1348 |
1347 TEST_F(AstDecoderTest, CallsWithTooFewArguments) { | 1349 TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) { |
1348 FunctionSig* sig = sigs.i_i(); | 1350 FunctionSig* sig = sigs.i_i(); |
1349 TestModuleEnv module_env; | 1351 TestModuleEnv module_env; |
1350 module = &module_env; | 1352 module = &module_env; |
1351 | 1353 |
1352 module_env.AddFunction(sigs.i_i()); | 1354 module_env.AddFunction(sigs.i_i()); |
1353 module_env.AddFunction(sigs.i_ii()); | 1355 module_env.AddFunction(sigs.i_ii()); |
1354 module_env.AddFunction(sigs.f_ff()); | 1356 module_env.AddFunction(sigs.f_ff()); |
1355 | 1357 |
1356 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0)); | 1358 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(0)); |
1357 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); | 1359 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); |
1358 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); | 1360 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); |
1359 } | 1361 } |
1360 | 1362 |
1361 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { | 1363 TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs2) { |
1362 FunctionSig* sig = sigs.i_i(); | 1364 FunctionSig* sig = sigs.i_i(); |
1363 TestModuleEnv module_env; | 1365 TestModuleEnv module_env; |
1364 module = &module_env; | 1366 module = &module_env; |
1365 | 1367 |
1366 module_env.AddFunction(sigs.i_i()); | 1368 module_env.AddFunction(sigs.i_i()); |
1367 | 1369 |
1368 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); | 1370 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); |
1369 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); | 1371 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); |
1370 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); | 1372 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); |
1371 } | 1373 } |
1372 | 1374 |
1373 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { | 1375 TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { |
1374 FunctionSig* sig = sigs.i_i(); | 1376 FunctionSig* sig = sigs.i_i(); |
1375 TestModuleEnv module_env; | 1377 TestModuleEnv module_env; |
1376 module = &module_env; | 1378 module = &module_env; |
1377 | 1379 |
1378 module_env.AddFunction(sigs.i_f()); | 1380 module_env.AddFunction(sigs.i_f()); |
1379 | 1381 |
1380 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); | 1382 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); |
1381 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); | 1383 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); |
1382 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); | 1384 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); |
1383 | 1385 |
1384 module_env.AddFunction(sigs.i_d()); | 1386 module_env.AddFunction(sigs.i_d()); |
1385 | 1387 |
1386 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); | 1388 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); |
1387 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); | 1389 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); |
1388 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); | 1390 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); |
1389 } | 1391 } |
1390 | 1392 |
1391 TEST_F(AstDecoderTest, MultiReturn) { | 1393 TEST_F(FunctionBodyDecoderTest, MultiReturn) { |
1392 FLAG_wasm_mv_prototype = true; | 1394 FLAG_wasm_mv_prototype = true; |
1393 LocalType storage[] = {kAstI32, kAstI32}; | 1395 LocalType storage[] = {kAstI32, kAstI32}; |
1394 FunctionSig sig_ii_v(2, 0, storage); | 1396 FunctionSig sig_ii_v(2, 0, storage); |
1395 FunctionSig sig_v_ii(0, 2, storage); | 1397 FunctionSig sig_v_ii(0, 2, storage); |
1396 TestModuleEnv module_env; | 1398 TestModuleEnv module_env; |
1397 module = &module_env; | 1399 module = &module_env; |
1398 | 1400 |
1399 module_env.AddFunction(&sig_v_ii); | 1401 module_env.AddFunction(&sig_v_ii); |
1400 module_env.AddFunction(&sig_ii_v); | 1402 module_env.AddFunction(&sig_ii_v); |
1401 | 1403 |
1402 EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); | 1404 EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); |
1403 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); | 1405 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); |
1404 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); | 1406 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); |
1405 } | 1407 } |
1406 | 1408 |
1407 TEST_F(AstDecoderTest, MultiReturnType) { | 1409 TEST_F(FunctionBodyDecoderTest, MultiReturnType) { |
1408 FLAG_wasm_mv_prototype = true; | 1410 FLAG_wasm_mv_prototype = true; |
1409 for (size_t a = 0; a < arraysize(kLocalTypes); a++) { | 1411 for (size_t a = 0; a < arraysize(kLocalTypes); a++) { |
1410 for (size_t b = 0; b < arraysize(kLocalTypes); b++) { | 1412 for (size_t b = 0; b < arraysize(kLocalTypes); b++) { |
1411 for (size_t c = 0; c < arraysize(kLocalTypes); c++) { | 1413 for (size_t c = 0; c < arraysize(kLocalTypes); c++) { |
1412 for (size_t d = 0; d < arraysize(kLocalTypes); d++) { | 1414 for (size_t d = 0; d < arraysize(kLocalTypes); d++) { |
1413 LocalType storage_ab[] = {kLocalTypes[a], kLocalTypes[b]}; | 1415 LocalType storage_ab[] = {kLocalTypes[a], kLocalTypes[b]}; |
1414 FunctionSig sig_ab_v(2, 0, storage_ab); | 1416 FunctionSig sig_ab_v(2, 0, storage_ab); |
1415 LocalType storage_cd[] = {kLocalTypes[c], kLocalTypes[d]}; | 1417 LocalType storage_cd[] = {kLocalTypes[c], kLocalTypes[d]}; |
1416 FunctionSig sig_cd_v(2, 0, storage_cd); | 1418 FunctionSig sig_cd_v(2, 0, storage_cd); |
1417 | 1419 |
1418 TestModuleEnv module_env; | 1420 TestModuleEnv module_env; |
1419 module = &module_env; | 1421 module = &module_env; |
1420 module_env.AddFunction(&sig_cd_v); | 1422 module_env.AddFunction(&sig_cd_v); |
1421 | 1423 |
1422 EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); | 1424 EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); |
1423 | 1425 |
1424 if (a == c && b == d) { | 1426 if (a == c && b == d) { |
1425 EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); | 1427 EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
1426 } else { | 1428 } else { |
1427 EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); | 1429 EXPECT_FAILURE_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
1428 } | 1430 } |
1429 } | 1431 } |
1430 } | 1432 } |
1431 } | 1433 } |
1432 } | 1434 } |
1433 } | 1435 } |
1434 | 1436 |
1435 TEST_F(AstDecoderTest, SimpleIndirectCalls) { | 1437 TEST_F(FunctionBodyDecoderTest, SimpleIndirectCalls) { |
1436 FunctionSig* sig = sigs.i_i(); | 1438 FunctionSig* sig = sigs.i_i(); |
1437 TestModuleEnv module_env; | 1439 TestModuleEnv module_env; |
1438 module_env.InitializeFunctionTable(); | 1440 module_env.InitializeFunctionTable(); |
1439 module = &module_env; | 1441 module = &module_env; |
1440 | 1442 |
1441 byte f0 = module_env.AddSignature(sigs.i_v()); | 1443 byte f0 = module_env.AddSignature(sigs.i_v()); |
1442 byte f1 = module_env.AddSignature(sigs.i_i()); | 1444 byte f1 = module_env.AddSignature(sigs.i_i()); |
1443 byte f2 = module_env.AddSignature(sigs.i_ii()); | 1445 byte f2 = module_env.AddSignature(sigs.i_ii()); |
1444 | 1446 |
1445 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); | 1447 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
1446 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); | 1448 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
1447 EXPECT_VERIFIES_S( | 1449 EXPECT_VERIFIES_S( |
1448 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); | 1450 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
1449 } | 1451 } |
1450 | 1452 |
1451 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { | 1453 TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { |
1452 FunctionSig* sig = sigs.i_i(); | 1454 FunctionSig* sig = sigs.i_i(); |
1453 TestModuleEnv module_env; | 1455 TestModuleEnv module_env; |
1454 module_env.InitializeFunctionTable(); | 1456 module_env.InitializeFunctionTable(); |
1455 module = &module_env; | 1457 module = &module_env; |
1456 | 1458 |
1457 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1459 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1458 module_env.AddSignature(sigs.i_v()); | 1460 module_env.AddSignature(sigs.i_v()); |
1459 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1461 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1460 | 1462 |
1461 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); | 1463 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
1462 module_env.AddSignature(sigs.i_i()); | 1464 module_env.AddSignature(sigs.i_i()); |
1463 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); | 1465 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
1464 | 1466 |
1465 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); | 1467 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
1466 } | 1468 } |
1467 | 1469 |
1468 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { | 1470 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { |
1469 FunctionSig* sig = sigs.i_i(); | 1471 FunctionSig* sig = sigs.i_i(); |
1470 TestModuleEnv module_env; | 1472 TestModuleEnv module_env; |
1471 module_env.InitializeFunctionTable(); | 1473 module_env.InitializeFunctionTable(); |
1472 module = &module_env; | 1474 module = &module_env; |
1473 | 1475 |
1474 byte f0 = module_env.AddFunction(sigs.i_f()); | 1476 byte f0 = module_env.AddFunction(sigs.i_f()); |
1475 | 1477 |
1476 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); | 1478 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); |
1477 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); | 1479 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); |
1478 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); | 1480 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); |
1479 | 1481 |
1480 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); | 1482 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); |
1481 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); | 1483 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); |
1482 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); | 1484 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); |
1483 | 1485 |
1484 byte f1 = module_env.AddFunction(sigs.i_d()); | 1486 byte f1 = module_env.AddFunction(sigs.i_d()); |
1485 | 1487 |
1486 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); | 1488 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); |
1487 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); | 1489 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); |
1488 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); | 1490 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
1489 } | 1491 } |
1490 | 1492 |
1491 TEST_F(AstDecoderTest, IndirectCallsWithoutTableCrash) { | 1493 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) { |
1492 FunctionSig* sig = sigs.i_i(); | 1494 FunctionSig* sig = sigs.i_i(); |
1493 TestModuleEnv module_env; | 1495 TestModuleEnv module_env; |
1494 module = &module_env; | 1496 module = &module_env; |
1495 | 1497 |
1496 byte f0 = module_env.AddSignature(sigs.i_v()); | 1498 byte f0 = module_env.AddSignature(sigs.i_v()); |
1497 byte f1 = module_env.AddSignature(sigs.i_i()); | 1499 byte f1 = module_env.AddSignature(sigs.i_i()); |
1498 byte f2 = module_env.AddSignature(sigs.i_ii()); | 1500 byte f2 = module_env.AddSignature(sigs.i_ii()); |
1499 | 1501 |
1500 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); | 1502 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
1501 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); | 1503 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
1502 EXPECT_FAILURE_S( | 1504 EXPECT_FAILURE_S( |
1503 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); | 1505 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
1504 } | 1506 } |
1505 | 1507 |
1506 TEST_F(AstDecoderTest, SimpleImportCalls) { | 1508 TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { |
1507 FunctionSig* sig = sigs.i_i(); | 1509 FunctionSig* sig = sigs.i_i(); |
1508 TestModuleEnv module_env; | 1510 TestModuleEnv module_env; |
1509 module = &module_env; | 1511 module = &module_env; |
1510 | 1512 |
1511 byte f0 = module_env.AddImport(sigs.i_v()); | 1513 byte f0 = module_env.AddImport(sigs.i_v()); |
1512 byte f1 = module_env.AddImport(sigs.i_i()); | 1514 byte f1 = module_env.AddImport(sigs.i_i()); |
1513 byte f2 = module_env.AddImport(sigs.i_ii()); | 1515 byte f2 = module_env.AddImport(sigs.i_ii()); |
1514 | 1516 |
1515 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); | 1517 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); |
1516 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22))); | 1518 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22))); |
1517 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); | 1519 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); |
1518 } | 1520 } |
1519 | 1521 |
1520 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { | 1522 TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { |
1521 FunctionSig* sig = sigs.i_i(); | 1523 FunctionSig* sig = sigs.i_i(); |
1522 TestModuleEnv module_env; | 1524 TestModuleEnv module_env; |
1523 module = &module_env; | 1525 module = &module_env; |
1524 | 1526 |
1525 byte f0 = module_env.AddImport(sigs.i_f()); | 1527 byte f0 = module_env.AddImport(sigs.i_f()); |
1526 | 1528 |
1527 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); | 1529 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); |
1528 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17))); | 1530 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17))); |
1529 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); | 1531 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); |
1530 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); | 1532 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); |
1531 | 1533 |
1532 byte f1 = module_env.AddImport(sigs.i_d()); | 1534 byte f1 = module_env.AddImport(sigs.i_d()); |
1533 | 1535 |
1534 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); | 1536 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); |
1535 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); | 1537 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); |
1536 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); | 1538 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); |
1537 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); | 1539 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); |
1538 } | 1540 } |
1539 | 1541 |
1540 TEST_F(AstDecoderTest, Int32Globals) { | 1542 TEST_F(FunctionBodyDecoderTest, Int32Globals) { |
1541 FunctionSig* sig = sigs.i_i(); | 1543 FunctionSig* sig = sigs.i_i(); |
1542 TestModuleEnv module_env; | 1544 TestModuleEnv module_env; |
1543 module = &module_env; | 1545 module = &module_env; |
1544 | 1546 |
1545 module_env.AddGlobal(kAstI32); | 1547 module_env.AddGlobal(kAstI32); |
1546 | 1548 |
1547 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1549 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1548 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1550 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1549 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); | 1551 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
1550 } | 1552 } |
1551 | 1553 |
1552 TEST_F(AstDecoderTest, ImmutableGlobal) { | 1554 TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) { |
1553 FunctionSig* sig = sigs.v_v(); | 1555 FunctionSig* sig = sigs.v_v(); |
1554 TestModuleEnv module_env; | 1556 TestModuleEnv module_env; |
1555 module = &module_env; | 1557 module = &module_env; |
1556 | 1558 |
1557 uint32_t g0 = module_env.AddGlobal(kAstI32, true); | 1559 uint32_t g0 = module_env.AddGlobal(kAstI32, true); |
1558 uint32_t g1 = module_env.AddGlobal(kAstI32, false); | 1560 uint32_t g1 = module_env.AddGlobal(kAstI32, false); |
1559 | 1561 |
1560 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); | 1562 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); |
1561 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); | 1563 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); |
1562 } | 1564 } |
1563 | 1565 |
1564 TEST_F(AstDecoderTest, Int32Globals_fail) { | 1566 TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) { |
1565 FunctionSig* sig = sigs.i_i(); | 1567 FunctionSig* sig = sigs.i_i(); |
1566 TestModuleEnv module_env; | 1568 TestModuleEnv module_env; |
1567 module = &module_env; | 1569 module = &module_env; |
1568 | 1570 |
1569 module_env.AddGlobal(kAstI64); | 1571 module_env.AddGlobal(kAstI64); |
1570 module_env.AddGlobal(kAstI64); | 1572 module_env.AddGlobal(kAstI64); |
1571 module_env.AddGlobal(kAstF32); | 1573 module_env.AddGlobal(kAstF32); |
1572 module_env.AddGlobal(kAstF64); | 1574 module_env.AddGlobal(kAstF64); |
1573 | 1575 |
1574 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); | 1576 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); |
1575 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); | 1577 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); |
1576 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); | 1578 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); |
1577 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); | 1579 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); |
1578 | 1580 |
1579 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); | 1581 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
1580 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); | 1582 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); |
1581 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); | 1583 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); |
1582 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); | 1584 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); |
1583 } | 1585 } |
1584 | 1586 |
1585 TEST_F(AstDecoderTest, Int64Globals) { | 1587 TEST_F(FunctionBodyDecoderTest, Int64Globals) { |
1586 FunctionSig* sig = sigs.l_l(); | 1588 FunctionSig* sig = sigs.l_l(); |
1587 TestModuleEnv module_env; | 1589 TestModuleEnv module_env; |
1588 module = &module_env; | 1590 module = &module_env; |
1589 | 1591 |
1590 module_env.AddGlobal(kAstI64); | 1592 module_env.AddGlobal(kAstI64); |
1591 module_env.AddGlobal(kAstI64); | 1593 module_env.AddGlobal(kAstI64); |
1592 | 1594 |
1593 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1595 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1594 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); | 1596 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); |
1595 | 1597 |
1596 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1598 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1597 WASM_GET_LOCAL(0)); | 1599 WASM_GET_LOCAL(0)); |
1598 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), | 1600 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), |
1599 WASM_GET_LOCAL(0)); | 1601 WASM_GET_LOCAL(0)); |
1600 } | 1602 } |
1601 | 1603 |
1602 TEST_F(AstDecoderTest, Float32Globals) { | 1604 TEST_F(FunctionBodyDecoderTest, Float32Globals) { |
1603 FunctionSig* sig = sigs.f_ff(); | 1605 FunctionSig* sig = sigs.f_ff(); |
1604 TestModuleEnv module_env; | 1606 TestModuleEnv module_env; |
1605 module = &module_env; | 1607 module = &module_env; |
1606 | 1608 |
1607 module_env.AddGlobal(kAstF32); | 1609 module_env.AddGlobal(kAstF32); |
1608 | 1610 |
1609 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1611 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1610 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1612 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1611 WASM_GET_LOCAL(0)); | 1613 WASM_GET_LOCAL(0)); |
1612 } | 1614 } |
1613 | 1615 |
1614 TEST_F(AstDecoderTest, Float64Globals) { | 1616 TEST_F(FunctionBodyDecoderTest, Float64Globals) { |
1615 FunctionSig* sig = sigs.d_dd(); | 1617 FunctionSig* sig = sigs.d_dd(); |
1616 TestModuleEnv module_env; | 1618 TestModuleEnv module_env; |
1617 module = &module_env; | 1619 module = &module_env; |
1618 | 1620 |
1619 module_env.AddGlobal(kAstF64); | 1621 module_env.AddGlobal(kAstF64); |
1620 | 1622 |
1621 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1623 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1622 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1624 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1623 WASM_GET_LOCAL(0)); | 1625 WASM_GET_LOCAL(0)); |
1624 } | 1626 } |
1625 | 1627 |
1626 TEST_F(AstDecoderTest, AllGetGlobalCombinations) { | 1628 TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) { |
1627 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1629 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1628 LocalType local_type = kLocalTypes[i]; | 1630 LocalType local_type = kLocalTypes[i]; |
1629 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1631 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1630 LocalType global_type = kLocalTypes[j]; | 1632 LocalType global_type = kLocalTypes[j]; |
1631 FunctionSig sig(1, 0, &local_type); | 1633 FunctionSig sig(1, 0, &local_type); |
1632 TestModuleEnv module_env; | 1634 TestModuleEnv module_env; |
1633 module = &module_env; | 1635 module = &module_env; |
1634 module_env.AddGlobal(global_type); | 1636 module_env.AddGlobal(global_type); |
1635 if (local_type == global_type) { | 1637 if (local_type == global_type) { |
1636 EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); | 1638 EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); |
1637 } else { | 1639 } else { |
1638 EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); | 1640 EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); |
1639 } | 1641 } |
1640 } | 1642 } |
1641 } | 1643 } |
1642 } | 1644 } |
1643 | 1645 |
1644 TEST_F(AstDecoderTest, AllSetGlobalCombinations) { | 1646 TEST_F(FunctionBodyDecoderTest, AllSetGlobalCombinations) { |
1645 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1647 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1646 LocalType local_type = kLocalTypes[i]; | 1648 LocalType local_type = kLocalTypes[i]; |
1647 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1649 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1648 LocalType global_type = kLocalTypes[j]; | 1650 LocalType global_type = kLocalTypes[j]; |
1649 FunctionSig sig(0, 1, &local_type); | 1651 FunctionSig sig(0, 1, &local_type); |
1650 TestModuleEnv module_env; | 1652 TestModuleEnv module_env; |
1651 module = &module_env; | 1653 module = &module_env; |
1652 module_env.AddGlobal(global_type); | 1654 module_env.AddGlobal(global_type); |
1653 if (local_type == global_type) { | 1655 if (local_type == global_type) { |
1654 EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1656 EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1655 } else { | 1657 } else { |
1656 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1658 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1657 } | 1659 } |
1658 } | 1660 } |
1659 } | 1661 } |
1660 } | 1662 } |
1661 | 1663 |
1662 TEST_F(AstDecoderTest, WasmGrowMemory) { | 1664 TEST_F(FunctionBodyDecoderTest, WasmGrowMemory) { |
1663 TestModuleEnv module_env; | 1665 TestModuleEnv module_env; |
1664 module = &module_env; | 1666 module = &module_env; |
1665 | 1667 |
1666 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; | 1668 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; |
1667 EXPECT_VERIFIES_C(i_i, code); | 1669 EXPECT_VERIFIES_C(i_i, code); |
1668 EXPECT_FAILURE_C(i_d, code); | 1670 EXPECT_FAILURE_C(i_d, code); |
1669 } | 1671 } |
1670 | 1672 |
1671 TEST_F(AstDecoderTest, AsmJsGrowMemory) { | 1673 TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) { |
1672 TestModuleEnv module_env(kAsmJsOrigin); | 1674 TestModuleEnv module_env(kAsmJsOrigin); |
1673 module = &module_env; | 1675 module = &module_env; |
1674 | 1676 |
1675 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; | 1677 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; |
1676 EXPECT_FAILURE_C(i_i, code); | 1678 EXPECT_FAILURE_C(i_i, code); |
1677 } | 1679 } |
1678 | 1680 |
1679 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { | 1681 TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { |
1680 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; | 1682 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; |
1681 FunctionSig sig_f_if(1, 2, float32int32float32); | 1683 FunctionSig sig_f_if(1, 2, float32int32float32); |
1682 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; | 1684 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; |
1683 FunctionSig sig_d_id(1, 2, float64int32float64); | 1685 FunctionSig sig_d_id(1, 2, float64int32float64); |
1684 struct { | 1686 struct { |
1685 WasmOpcode op; | 1687 WasmOpcode op; |
1686 FunctionSig* sig; | 1688 FunctionSig* sig; |
1687 } AsmJsBinOps[] = { | 1689 } AsmJsBinOps[] = { |
1688 {kExprF64Atan2, sigs.d_dd()}, | 1690 {kExprF64Atan2, sigs.d_dd()}, |
1689 {kExprF64Pow, sigs.d_dd()}, | 1691 {kExprF64Pow, sigs.d_dd()}, |
(...skipping 21 matching lines...) Expand all Loading... |
1711 TestModuleEnv module_env; | 1713 TestModuleEnv module_env; |
1712 module = &module_env; | 1714 module = &module_env; |
1713 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { | 1715 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { |
1714 byte code[] = { | 1716 byte code[] = { |
1715 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 1717 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
1716 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); | 1718 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); |
1717 } | 1719 } |
1718 } | 1720 } |
1719 } | 1721 } |
1720 | 1722 |
1721 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) { | 1723 TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { |
1722 LocalType float32int32[] = {kAstF32, kAstI32}; | 1724 LocalType float32int32[] = {kAstF32, kAstI32}; |
1723 FunctionSig sig_f_i(1, 1, float32int32); | 1725 FunctionSig sig_f_i(1, 1, float32int32); |
1724 LocalType float64int32[] = {kAstF64, kAstI32}; | 1726 LocalType float64int32[] = {kAstF64, kAstI32}; |
1725 FunctionSig sig_d_i(1, 1, float64int32); | 1727 FunctionSig sig_d_i(1, 1, float64int32); |
1726 struct { | 1728 struct { |
1727 WasmOpcode op; | 1729 WasmOpcode op; |
1728 FunctionSig* sig; | 1730 FunctionSig* sig; |
1729 } AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()}, | 1731 } AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()}, |
1730 {kExprF64Asin, sigs.d_d()}, | 1732 {kExprF64Asin, sigs.d_d()}, |
1731 {kExprF64Atan, sigs.d_d()}, | 1733 {kExprF64Atan, sigs.d_d()}, |
(...skipping 24 matching lines...) Expand all Loading... |
1756 { | 1758 { |
1757 TestModuleEnv module_env; | 1759 TestModuleEnv module_env; |
1758 module = &module_env; | 1760 module = &module_env; |
1759 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { | 1761 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { |
1760 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; | 1762 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; |
1761 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); | 1763 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); |
1762 } | 1764 } |
1763 } | 1765 } |
1764 } | 1766 } |
1765 | 1767 |
1766 TEST_F(AstDecoderTest, BreakEnd) { | 1768 TEST_F(FunctionBodyDecoderTest, BreakEnd) { |
1767 EXPECT_VERIFIES( | 1769 EXPECT_VERIFIES( |
1768 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); | 1770 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
1769 EXPECT_VERIFIES( | 1771 EXPECT_VERIFIES( |
1770 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); | 1772 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); |
1771 } | 1773 } |
1772 | 1774 |
1773 TEST_F(AstDecoderTest, BreakIfBinop) { | 1775 TEST_F(FunctionBodyDecoderTest, BreakIfBinop) { |
1774 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( | 1776 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
1775 WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); | 1777 WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); |
1776 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( | 1778 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_I32_ADD( |
1777 WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); | 1779 WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
1778 EXPECT_VERIFIES_S( | 1780 EXPECT_VERIFIES_S( |
1779 sigs.f_ff(), | 1781 sigs.f_ff(), |
1780 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); | 1782 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); |
1781 } | 1783 } |
1782 | 1784 |
1783 TEST_F(AstDecoderTest, BreakIfBinop_fail) { | 1785 TEST_F(FunctionBodyDecoderTest, BreakIfBinop_fail) { |
1784 EXPECT_FAILURE_S( | 1786 EXPECT_FAILURE_S( |
1785 sigs.f_ff(), | 1787 sigs.f_ff(), |
1786 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); | 1788 WASM_BLOCK_F(WASM_F32_ABS(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)))); |
1787 EXPECT_FAILURE_S( | 1789 EXPECT_FAILURE_S( |
1788 sigs.i_i(), | 1790 sigs.i_i(), |
1789 WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); | 1791 WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); |
1790 } | 1792 } |
1791 | 1793 |
1792 TEST_F(AstDecoderTest, BreakNesting1) { | 1794 TEST_F(FunctionBodyDecoderTest, BreakNesting1) { |
1793 for (int i = 0; i < 5; i++) { | 1795 for (int i = 0; i < 5; i++) { |
1794 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) | 1796 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) |
1795 byte code[] = {WASM_BLOCK_I( | 1797 byte code[] = {WASM_BLOCK_I( |
1796 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), | 1798 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), |
1797 WASM_SET_LOCAL(0, WASM_I8(1))), | 1799 WASM_SET_LOCAL(0, WASM_I8(1))), |
1798 WASM_ZERO)}; | 1800 WASM_ZERO)}; |
1799 if (i < 3) { | 1801 if (i < 3) { |
1800 EXPECT_VERIFIES_C(i_i, code); | 1802 EXPECT_VERIFIES_C(i_i, code); |
1801 } else { | 1803 } else { |
1802 EXPECT_FAILURE_C(i_i, code); | 1804 EXPECT_FAILURE_C(i_i, code); |
1803 } | 1805 } |
1804 } | 1806 } |
1805 } | 1807 } |
1806 | 1808 |
1807 TEST_F(AstDecoderTest, BreakNesting2) { | 1809 TEST_F(FunctionBodyDecoderTest, BreakNesting2) { |
1808 for (int i = 0; i < 7; i++) { | 1810 for (int i = 0; i < 7; i++) { |
1809 byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))}; | 1811 byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BR(i)), WASM_NOP))}; |
1810 if (i <= 3) { | 1812 if (i <= 3) { |
1811 EXPECT_VERIFIES_C(v_v, code); | 1813 EXPECT_VERIFIES_C(v_v, code); |
1812 } else { | 1814 } else { |
1813 EXPECT_FAILURE_C(v_v, code); | 1815 EXPECT_FAILURE_C(v_v, code); |
1814 } | 1816 } |
1815 } | 1817 } |
1816 } | 1818 } |
1817 | 1819 |
1818 TEST_F(AstDecoderTest, BreakNesting3) { | 1820 TEST_F(FunctionBodyDecoderTest, BreakNesting3) { |
1819 for (int i = 0; i < 7; i++) { | 1821 for (int i = 0; i < 7; i++) { |
1820 // (block[1] (loop[1] (block[1] (if 0 break[N]) | 1822 // (block[1] (loop[1] (block[1] (if 0 break[N]) |
1821 byte code[] = { | 1823 byte code[] = { |
1822 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; | 1824 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; |
1823 if (i < 4) { | 1825 if (i < 4) { |
1824 EXPECT_VERIFIES_C(v_v, code); | 1826 EXPECT_VERIFIES_C(v_v, code); |
1825 } else { | 1827 } else { |
1826 EXPECT_FAILURE_C(v_v, code); | 1828 EXPECT_FAILURE_C(v_v, code); |
1827 } | 1829 } |
1828 } | 1830 } |
1829 } | 1831 } |
1830 | 1832 |
1831 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { | 1833 TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) { |
1832 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); | 1834 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); |
1833 | 1835 |
1834 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), | 1836 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), |
1835 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); | 1837 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
1836 EXPECT_FAILURE( | 1838 EXPECT_FAILURE( |
1837 i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), WASM_BRV_IF_ZERO(0, WASM_I8(0)), | 1839 i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), WASM_BRV_IF_ZERO(0, WASM_I8(0)), |
1838 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); | 1840 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); |
1839 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), | 1841 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), |
1840 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), | 1842 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), |
1841 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); | 1843 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); |
1842 } | 1844 } |
1843 | 1845 |
1844 TEST_F(AstDecoderTest, BreakNesting_6_levels) { | 1846 TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) { |
1845 for (int mask = 0; mask < 64; mask++) { | 1847 for (int mask = 0; mask < 64; mask++) { |
1846 for (int i = 0; i < 14; i++) { | 1848 for (int i = 0; i < 14; i++) { |
1847 byte code[] = {WASM_BLOCK(WASM_BLOCK( | 1849 byte code[] = {WASM_BLOCK(WASM_BLOCK( |
1848 WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))}; | 1850 WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))}; |
1849 | 1851 |
1850 int depth = 6; | 1852 int depth = 6; |
1851 int m = mask; | 1853 int m = mask; |
1852 for (size_t pos = 0; pos < sizeof(code); pos++) { | 1854 for (size_t pos = 0; pos < sizeof(code); pos++) { |
1853 if (code[pos] != kExprBlock) continue; | 1855 if (code[pos] != kExprBlock) continue; |
1854 if (m & 1) { | 1856 if (m & 1) { |
1855 code[pos] = kExprLoop; | 1857 code[pos] = kExprLoop; |
1856 code[pos + 1] = kLocalVoid; | 1858 code[pos + 1] = kLocalVoid; |
1857 } | 1859 } |
1858 m >>= 1; | 1860 m >>= 1; |
1859 } | 1861 } |
1860 | 1862 |
1861 if (i <= depth) { | 1863 if (i <= depth) { |
1862 EXPECT_VERIFIES_C(v_v, code); | 1864 EXPECT_VERIFIES_C(v_v, code); |
1863 } else { | 1865 } else { |
1864 EXPECT_FAILURE_C(v_v, code); | 1866 EXPECT_FAILURE_C(v_v, code); |
1865 } | 1867 } |
1866 } | 1868 } |
1867 } | 1869 } |
1868 } | 1870 } |
1869 | 1871 |
1870 TEST_F(AstDecoderTest, Break_TypeCheck) { | 1872 TEST_F(FunctionBodyDecoderTest, Break_TypeCheck) { |
1871 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; | 1873 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; |
1872 for (size_t i = 0; i < arraysize(sigarray); i++) { | 1874 for (size_t i = 0; i < arraysize(sigarray); i++) { |
1873 FunctionSig* sig = sigarray[i]; | 1875 FunctionSig* sig = sigarray[i]; |
1874 // unify X and X => OK | 1876 // unify X and X => OK |
1875 byte code[] = {WASM_BLOCK_T( | 1877 byte code[] = {WASM_BLOCK_T( |
1876 sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1878 sig->GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1877 WASM_GET_LOCAL(0))}; | 1879 WASM_GET_LOCAL(0))}; |
1878 EXPECT_VERIFIES_SC(sig, code); | 1880 EXPECT_VERIFIES_SC(sig, code); |
1879 } | 1881 } |
1880 | 1882 |
1881 // unify i32 and f32 => fail | 1883 // unify i32 and f32 => fail |
1882 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), | 1884 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), |
1883 WASM_F32(1.2))); | 1885 WASM_F32(1.2))); |
1884 | 1886 |
1885 // unify f64 and f64 => OK | 1887 // unify f64 and f64 => OK |
1886 EXPECT_VERIFIES( | 1888 EXPECT_VERIFIES( |
1887 d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1889 d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1888 WASM_F64(1.2))); | 1890 WASM_F64(1.2))); |
1889 } | 1891 } |
1890 | 1892 |
1891 TEST_F(AstDecoderTest, Break_TypeCheckAll1) { | 1893 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { |
1892 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1894 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1893 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1895 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1894 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1896 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1895 FunctionSig sig(1, 2, storage); | 1897 FunctionSig sig(1, 2, storage); |
1896 byte code[] = {WASM_BLOCK_T( | 1898 byte code[] = {WASM_BLOCK_T( |
1897 sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1899 sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1898 WASM_GET_LOCAL(1))}; | 1900 WASM_GET_LOCAL(1))}; |
1899 | 1901 |
1900 if (i == j) { | 1902 if (i == j) { |
1901 EXPECT_VERIFIES_SC(&sig, code); | 1903 EXPECT_VERIFIES_SC(&sig, code); |
1902 } else { | 1904 } else { |
1903 EXPECT_FAILURE_SC(&sig, code); | 1905 EXPECT_FAILURE_SC(&sig, code); |
1904 } | 1906 } |
1905 } | 1907 } |
1906 } | 1908 } |
1907 } | 1909 } |
1908 | 1910 |
1909 TEST_F(AstDecoderTest, Break_TypeCheckAll2) { | 1911 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { |
1910 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1912 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1911 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1913 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1912 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1914 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1913 FunctionSig sig(1, 2, storage); | 1915 FunctionSig sig(1, 2, storage); |
1914 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, | 1916 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, |
1915 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), | 1917 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), |
1916 WASM_GET_LOCAL(1))}; | 1918 WASM_GET_LOCAL(1))}; |
1917 | 1919 |
1918 if (i == j) { | 1920 if (i == j) { |
1919 EXPECT_VERIFIES_SC(&sig, code); | 1921 EXPECT_VERIFIES_SC(&sig, code); |
1920 } else { | 1922 } else { |
1921 EXPECT_FAILURE_SC(&sig, code); | 1923 EXPECT_FAILURE_SC(&sig, code); |
1922 } | 1924 } |
1923 } | 1925 } |
1924 } | 1926 } |
1925 } | 1927 } |
1926 | 1928 |
1927 TEST_F(AstDecoderTest, Break_TypeCheckAll3) { | 1929 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) { |
1928 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1930 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1929 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1931 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1930 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1932 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1931 FunctionSig sig(1, 2, storage); | 1933 FunctionSig sig(1, 2, storage); |
1932 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, | 1934 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, |
1933 WASM_GET_LOCAL(1), | 1935 WASM_GET_LOCAL(1), |
1934 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; | 1936 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; |
1935 | 1937 |
1936 if (i == j) { | 1938 if (i == j) { |
1937 EXPECT_VERIFIES_SC(&sig, code); | 1939 EXPECT_VERIFIES_SC(&sig, code); |
1938 } else { | 1940 } else { |
1939 EXPECT_FAILURE_SC(&sig, code); | 1941 EXPECT_FAILURE_SC(&sig, code); |
1940 } | 1942 } |
1941 } | 1943 } |
1942 } | 1944 } |
1943 } | 1945 } |
1944 | 1946 |
1945 TEST_F(AstDecoderTest, Break_Unify) { | 1947 TEST_F(FunctionBodyDecoderTest, Break_Unify) { |
1946 for (int which = 0; which < 2; which++) { | 1948 for (int which = 0; which < 2; which++) { |
1947 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1949 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1948 LocalType type = kLocalTypes[i]; | 1950 LocalType type = kLocalTypes[i]; |
1949 LocalType storage[] = {kAstI32, kAstI32, type}; | 1951 LocalType storage[] = {kAstI32, kAstI32, type}; |
1950 FunctionSig sig(1, 2, storage); | 1952 FunctionSig sig(1, 2, storage); |
1951 | 1953 |
1952 byte code1[] = {WASM_BLOCK_T( | 1954 byte code1[] = {WASM_BLOCK_T( |
1953 type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), | 1955 type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
1954 WASM_GET_LOCAL(which ^ 1))}; | 1956 WASM_GET_LOCAL(which ^ 1))}; |
1955 | 1957 |
1956 if (type == kAstI32) { | 1958 if (type == kAstI32) { |
1957 EXPECT_VERIFIES_SC(&sig, code1); | 1959 EXPECT_VERIFIES_SC(&sig, code1); |
1958 } else { | 1960 } else { |
1959 EXPECT_FAILURE_SC(&sig, code1); | 1961 EXPECT_FAILURE_SC(&sig, code1); |
1960 } | 1962 } |
1961 } | 1963 } |
1962 } | 1964 } |
1963 } | 1965 } |
1964 | 1966 |
1965 TEST_F(AstDecoderTest, BreakIf_cond_type) { | 1967 TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { |
1966 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1968 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1967 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1969 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1968 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1970 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; |
1969 FunctionSig sig(1, 2, types); | 1971 FunctionSig sig(1, 2, types); |
1970 byte code[] = {WASM_BLOCK_T( | 1972 byte code[] = {WASM_BLOCK_T( |
1971 types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; | 1973 types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
1972 | 1974 |
1973 if (types[2] == kAstI32) { | 1975 if (types[2] == kAstI32) { |
1974 EXPECT_VERIFIES_SC(&sig, code); | 1976 EXPECT_VERIFIES_SC(&sig, code); |
1975 } else { | 1977 } else { |
1976 EXPECT_FAILURE_SC(&sig, code); | 1978 EXPECT_FAILURE_SC(&sig, code); |
1977 } | 1979 } |
1978 } | 1980 } |
1979 } | 1981 } |
1980 } | 1982 } |
1981 | 1983 |
1982 TEST_F(AstDecoderTest, BreakIf_val_type) { | 1984 TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) { |
1983 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1985 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
1984 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1986 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { |
1985 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], | 1987 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], |
1986 kAstI32}; | 1988 kAstI32}; |
1987 FunctionSig sig(1, 3, types); | 1989 FunctionSig sig(1, 3, types); |
1988 byte code[] = {WASM_BLOCK_T( | 1990 byte code[] = {WASM_BLOCK_T( |
1989 types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), | 1991 types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
1990 WASM_DROP, WASM_GET_LOCAL(0))}; | 1992 WASM_DROP, WASM_GET_LOCAL(0))}; |
1991 | 1993 |
1992 if (i == j) { | 1994 if (i == j) { |
1993 EXPECT_VERIFIES_SC(&sig, code); | 1995 EXPECT_VERIFIES_SC(&sig, code); |
1994 } else { | 1996 } else { |
1995 EXPECT_FAILURE_SC(&sig, code); | 1997 EXPECT_FAILURE_SC(&sig, code); |
1996 } | 1998 } |
1997 } | 1999 } |
1998 } | 2000 } |
1999 } | 2001 } |
2000 | 2002 |
2001 TEST_F(AstDecoderTest, BreakIf_Unify) { | 2003 TEST_F(FunctionBodyDecoderTest, BreakIf_Unify) { |
2002 for (int which = 0; which < 2; which++) { | 2004 for (int which = 0; which < 2; which++) { |
2003 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2005 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
2004 LocalType type = kLocalTypes[i]; | 2006 LocalType type = kLocalTypes[i]; |
2005 LocalType storage[] = {kAstI32, kAstI32, type}; | 2007 LocalType storage[] = {kAstI32, kAstI32, type}; |
2006 FunctionSig sig(1, 2, storage); | 2008 FunctionSig sig(1, 2, storage); |
2007 byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), | 2009 byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
2008 WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; | 2010 WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; |
2009 | 2011 |
2010 if (type == kAstI32) { | 2012 if (type == kAstI32) { |
2011 EXPECT_VERIFIES_SC(&sig, code); | 2013 EXPECT_VERIFIES_SC(&sig, code); |
2012 } else { | 2014 } else { |
2013 EXPECT_FAILURE_SC(&sig, code); | 2015 EXPECT_FAILURE_SC(&sig, code); |
2014 } | 2016 } |
2015 } | 2017 } |
2016 } | 2018 } |
2017 } | 2019 } |
2018 | 2020 |
2019 TEST_F(AstDecoderTest, BrTable0) { | 2021 TEST_F(FunctionBodyDecoderTest, BrTable0) { |
2020 static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; | 2022 static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; |
2021 EXPECT_FAILURE_C(v_v, code); | 2023 EXPECT_FAILURE_C(v_v, code); |
2022 } | 2024 } |
2023 | 2025 |
2024 TEST_F(AstDecoderTest, BrTable0b) { | 2026 TEST_F(FunctionBodyDecoderTest, BrTable0b) { |
2025 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)}; | 2027 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(0)}; |
2026 EXPECT_VERIFIES_C(v_v, code); | 2028 EXPECT_VERIFIES_C(v_v, code); |
2027 EXPECT_FAILURE_C(i_i, code); | 2029 EXPECT_FAILURE_C(i_i, code); |
2028 } | 2030 } |
2029 | 2031 |
2030 TEST_F(AstDecoderTest, BrTable0c) { | 2032 TEST_F(FunctionBodyDecoderTest, BrTable0c) { |
2031 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; | 2033 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; |
2032 EXPECT_FAILURE_C(v_v, code); | 2034 EXPECT_FAILURE_C(v_v, code); |
2033 EXPECT_FAILURE_C(i_i, code); | 2035 EXPECT_FAILURE_C(i_i, code); |
2034 } | 2036 } |
2035 | 2037 |
2036 TEST_F(AstDecoderTest, BrTable1a) { | 2038 TEST_F(FunctionBodyDecoderTest, BrTable1a) { |
2037 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; | 2039 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; |
2038 EXPECT_VERIFIES_C(v_v, code); | 2040 EXPECT_VERIFIES_C(v_v, code); |
2039 } | 2041 } |
2040 | 2042 |
2041 TEST_F(AstDecoderTest, BrTable1b) { | 2043 TEST_F(FunctionBodyDecoderTest, BrTable1b) { |
2042 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; | 2044 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; |
2043 EXPECT_VERIFIES_C(v_v, code); | 2045 EXPECT_VERIFIES_C(v_v, code); |
2044 EXPECT_FAILURE_C(i_i, code); | 2046 EXPECT_FAILURE_C(i_i, code); |
2045 EXPECT_FAILURE_C(f_ff, code); | 2047 EXPECT_FAILURE_C(f_ff, code); |
2046 EXPECT_FAILURE_C(d_dd, code); | 2048 EXPECT_FAILURE_C(d_dd, code); |
2047 } | 2049 } |
2048 | 2050 |
2049 TEST_F(AstDecoderTest, BrTable2a) { | 2051 TEST_F(FunctionBodyDecoderTest, BrTable2a) { |
2050 static byte code[] = { | 2052 static byte code[] = { |
2051 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; | 2053 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; |
2052 EXPECT_VERIFIES_C(v_v, code); | 2054 EXPECT_VERIFIES_C(v_v, code); |
2053 } | 2055 } |
2054 | 2056 |
2055 TEST_F(AstDecoderTest, BrTable2b) { | 2057 TEST_F(FunctionBodyDecoderTest, BrTable2b) { |
2056 static byte code[] = {WASM_BLOCK( | 2058 static byte code[] = {WASM_BLOCK( |
2057 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; | 2059 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; |
2058 EXPECT_VERIFIES_C(v_v, code); | 2060 EXPECT_VERIFIES_C(v_v, code); |
2059 } | 2061 } |
2060 | 2062 |
2061 TEST_F(AstDecoderTest, BrTable_off_end) { | 2063 TEST_F(FunctionBodyDecoderTest, BrTable_off_end) { |
2062 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; | 2064 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; |
2063 for (size_t len = 1; len < sizeof(code); len++) { | 2065 for (size_t len = 1; len < sizeof(code); len++) { |
2064 Verify(kError, sigs.i_i(), code, code + len); | 2066 Verify(kError, sigs.i_i(), code, code + len); |
2065 } | 2067 } |
2066 } | 2068 } |
2067 | 2069 |
2068 TEST_F(AstDecoderTest, BrTable_invalid_br1) { | 2070 TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br1) { |
2069 for (int depth = 0; depth < 4; depth++) { | 2071 for (int depth = 0; depth < 4; depth++) { |
2070 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; | 2072 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
2071 if (depth <= 1) { | 2073 if (depth <= 1) { |
2072 EXPECT_VERIFIES_C(v_i, code); | 2074 EXPECT_VERIFIES_C(v_i, code); |
2073 } else { | 2075 } else { |
2074 EXPECT_FAILURE_C(v_i, code); | 2076 EXPECT_FAILURE_C(v_i, code); |
2075 } | 2077 } |
2076 } | 2078 } |
2077 } | 2079 } |
2078 | 2080 |
2079 TEST_F(AstDecoderTest, BrTable_invalid_br2) { | 2081 TEST_F(FunctionBodyDecoderTest, BrTable_invalid_br2) { |
2080 for (int depth = 0; depth < 7; depth++) { | 2082 for (int depth = 0; depth < 7; depth++) { |
2081 byte code[] = { | 2083 byte code[] = { |
2082 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; | 2084 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; |
2083 if (depth < 2) { | 2085 if (depth < 2) { |
2084 EXPECT_VERIFIES_C(v_i, code); | 2086 EXPECT_VERIFIES_C(v_i, code); |
2085 } else { | 2087 } else { |
2086 EXPECT_FAILURE_C(v_i, code); | 2088 EXPECT_FAILURE_C(v_i, code); |
2087 } | 2089 } |
2088 } | 2090 } |
2089 } | 2091 } |
2090 | 2092 |
2091 TEST_F(AstDecoderTest, Brv1) { | 2093 TEST_F(FunctionBodyDecoderTest, Brv1) { |
2092 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); | 2094 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV(0, WASM_ZERO))); |
2093 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO)))); | 2095 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_LOOP(WASM_BRV(2, WASM_ZERO)))); |
2094 } | 2096 } |
2095 | 2097 |
2096 TEST_F(AstDecoderTest, Brv1_type) { | 2098 TEST_F(FunctionBodyDecoderTest, Brv1_type) { |
2097 EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2099 EXPECT_VERIFIES(i_ii, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2098 EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2100 EXPECT_VERIFIES(l_ll, WASM_BLOCK_L(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2099 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2101 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2100 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2102 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2101 } | 2103 } |
2102 | 2104 |
2103 TEST_F(AstDecoderTest, Brv1_type_n) { | 2105 TEST_F(FunctionBodyDecoderTest, Brv1_type_n) { |
2104 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2106 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2105 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); | 2107 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV(0, WASM_GET_LOCAL(0)))); |
2106 } | 2108 } |
2107 | 2109 |
2108 TEST_F(AstDecoderTest, BrvIf1) { | 2110 TEST_F(FunctionBodyDecoderTest, BrvIf1) { |
2109 EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))); | 2111 EXPECT_VERIFIES(i_v, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_ZERO))); |
2110 } | 2112 } |
2111 | 2113 |
2112 TEST_F(AstDecoderTest, BrvIf1_type) { | 2114 TEST_F(FunctionBodyDecoderTest, BrvIf1_type) { |
2113 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2115 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2114 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2116 EXPECT_VERIFIES(l_l, WASM_BLOCK_L(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2115 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2117 EXPECT_VERIFIES(f_ff, WASM_BLOCK_F(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2116 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2118 EXPECT_VERIFIES(d_dd, WASM_BLOCK_D(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2117 } | 2119 } |
2118 | 2120 |
2119 TEST_F(AstDecoderTest, BrvIf1_type_n) { | 2121 TEST_F(FunctionBodyDecoderTest, BrvIf1_type_n) { |
2120 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2122 EXPECT_FAILURE(i_f, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2121 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); | 2123 EXPECT_FAILURE(i_d, WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))); |
2122 } | 2124 } |
2123 | 2125 |
2124 TEST_F(AstDecoderTest, Select) { | 2126 TEST_F(FunctionBodyDecoderTest, Select) { |
2125 EXPECT_VERIFIES(i_i, | 2127 EXPECT_VERIFIES(i_i, |
2126 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); | 2128 WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); |
2127 EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); | 2129 EXPECT_VERIFIES(f_ff, WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); |
2128 EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); | 2130 EXPECT_VERIFIES(d_dd, WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); |
2129 EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); | 2131 EXPECT_VERIFIES(l_l, WASM_SELECT(WASM_I64V_1(0), WASM_I64V_1(0), WASM_ZERO)); |
2130 } | 2132 } |
2131 | 2133 |
2132 TEST_F(AstDecoderTest, Select_fail1) { | 2134 TEST_F(FunctionBodyDecoderTest, Select_fail1) { |
2133 EXPECT_FAILURE( | 2135 EXPECT_FAILURE( |
2134 i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 2136 i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
2135 EXPECT_FAILURE( | 2137 EXPECT_FAILURE( |
2136 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); | 2138 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); |
2137 EXPECT_FAILURE( | 2139 EXPECT_FAILURE( |
2138 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); | 2140 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); |
2139 } | 2141 } |
2140 | 2142 |
2141 TEST_F(AstDecoderTest, Select_fail2) { | 2143 TEST_F(FunctionBodyDecoderTest, Select_fail2) { |
2142 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2144 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
2143 LocalType type = kLocalTypes[i]; | 2145 LocalType type = kLocalTypes[i]; |
2144 if (type == kAstI32) continue; | 2146 if (type == kAstI32) continue; |
2145 | 2147 |
2146 LocalType types[] = {type, kAstI32, type}; | 2148 LocalType types[] = {type, kAstI32, type}; |
2147 FunctionSig sig(1, 2, types); | 2149 FunctionSig sig(1, 2, types); |
2148 | 2150 |
2149 EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), | 2151 EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), |
2150 WASM_GET_LOCAL(0))); | 2152 WASM_GET_LOCAL(0))); |
2151 | 2153 |
2152 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), | 2154 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), |
2153 WASM_GET_LOCAL(0))); | 2155 WASM_GET_LOCAL(0))); |
2154 | 2156 |
2155 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), | 2157 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
2156 WASM_GET_LOCAL(0))); | 2158 WASM_GET_LOCAL(0))); |
2157 | 2159 |
2158 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), | 2160 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
2159 WASM_GET_LOCAL(1))); | 2161 WASM_GET_LOCAL(1))); |
2160 } | 2162 } |
2161 } | 2163 } |
2162 | 2164 |
2163 TEST_F(AstDecoderTest, Select_TypeCheck) { | 2165 TEST_F(FunctionBodyDecoderTest, Select_TypeCheck) { |
2164 EXPECT_FAILURE( | 2166 EXPECT_FAILURE( |
2165 i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 2167 i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
2166 | 2168 |
2167 EXPECT_FAILURE( | 2169 EXPECT_FAILURE( |
2168 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); | 2170 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F64(0.25), WASM_GET_LOCAL(0))); |
2169 | 2171 |
2170 EXPECT_FAILURE(i_i, | 2172 EXPECT_FAILURE(i_i, |
2171 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); | 2173 WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64V_1(0))); |
2172 } | 2174 } |
2173 | 2175 |
2174 TEST_F(AstDecoderTest, Throw) { | 2176 TEST_F(FunctionBodyDecoderTest, Throw) { |
2175 FLAG_wasm_eh_prototype = true; | 2177 FLAG_wasm_eh_prototype = true; |
2176 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow); | 2178 EXPECT_VERIFIES(v_i, WASM_GET_LOCAL(0), kExprThrow); |
2177 | 2179 |
2178 EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); | 2180 EXPECT_FAILURE(i_d, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
2179 EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); | 2181 EXPECT_FAILURE(i_f, WASM_GET_LOCAL(0), kExprThrow, WASM_I32V(0)); |
2180 EXPECT_FAILURE(l_l, WASM_GET_LOCAL(0), kExprThrow, WASM_I64V(0)); | 2182 EXPECT_FAILURE(l_l, WASM_GET_LOCAL(0), kExprThrow, WASM_I64V(0)); |
2181 } | 2183 } |
2182 | 2184 |
2183 #define WASM_TRY_OP kExprTry, kLocalVoid | 2185 #define WASM_TRY_OP kExprTry, kLocalVoid |
2184 | 2186 |
2185 #define WASM_CATCH(local) kExprCatch, static_cast<byte>(local) | 2187 #define WASM_CATCH(local) kExprCatch, static_cast<byte>(local) |
2186 | 2188 |
2187 TEST_F(AstDecoderTest, TryCatch) { | 2189 TEST_F(FunctionBodyDecoderTest, TryCatch) { |
2188 FLAG_wasm_eh_prototype = true; | 2190 FLAG_wasm_eh_prototype = true; |
2189 EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd); | 2191 EXPECT_VERIFIES(v_i, WASM_TRY_OP, WASM_CATCH(0), kExprEnd); |
2190 | 2192 |
2191 // Missing catch. | 2193 // Missing catch. |
2192 EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd); | 2194 EXPECT_FAILURE(v_v, WASM_TRY_OP, kExprEnd); |
2193 | 2195 |
2194 // Missing end. | 2196 // Missing end. |
2195 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); | 2197 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); |
2196 | 2198 |
2197 // Double catch. | 2199 // Double catch. |
2198 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); | 2200 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); |
2199 } | 2201 } |
2200 | 2202 |
2201 TEST_F(AstDecoderTest, MultiValBlock1) { | 2203 TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { |
2202 FLAG_wasm_mv_prototype = true; | 2204 FLAG_wasm_mv_prototype = true; |
2203 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2205 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
2204 WASM_GET_LOCAL(1)), | 2206 WASM_GET_LOCAL(1)), |
2205 kExprI32Add); | 2207 kExprI32Add); |
2206 } | 2208 } |
2207 | 2209 |
2208 TEST_F(AstDecoderTest, MultiValBlock2) { | 2210 TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { |
2209 FLAG_wasm_mv_prototype = true; | 2211 FLAG_wasm_mv_prototype = true; |
2210 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2212 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
2211 WASM_GET_LOCAL(1)), | 2213 WASM_GET_LOCAL(1)), |
2212 WASM_I32_ADD(WASM_NOP, WASM_NOP)); | 2214 WASM_I32_ADD(WASM_NOP, WASM_NOP)); |
2213 } | 2215 } |
2214 | 2216 |
2215 TEST_F(AstDecoderTest, MultiValBlockBr1) { | 2217 TEST_F(FunctionBodyDecoderTest, MultiValBlockBr1) { |
2216 FLAG_wasm_mv_prototype = true; | 2218 FLAG_wasm_mv_prototype = true; |
2217 EXPECT_FAILURE(i_ii, | 2219 EXPECT_FAILURE(i_ii, |
2218 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_BR(0)), | 2220 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_BR(0)), |
2219 kExprI32Add); | 2221 kExprI32Add); |
2220 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2222 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
2221 WASM_GET_LOCAL(1), WASM_BR(0)), | 2223 WASM_GET_LOCAL(1), WASM_BR(0)), |
2222 kExprI32Add); | 2224 kExprI32Add); |
2223 } | 2225 } |
2224 | 2226 |
2225 TEST_F(AstDecoderTest, MultiValIf1) { | 2227 TEST_F(FunctionBodyDecoderTest, MultiValIf1) { |
2226 FLAG_wasm_mv_prototype = true; | 2228 FLAG_wasm_mv_prototype = true; |
2227 EXPECT_FAILURE( | 2229 EXPECT_FAILURE( |
2228 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2230 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
2229 WASM_SEQ(WASM_GET_LOCAL(0)), | 2231 WASM_SEQ(WASM_GET_LOCAL(0)), |
2230 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), | 2232 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
2231 kExprI32Add); | 2233 kExprI32Add); |
2232 EXPECT_FAILURE(i_ii, | 2234 EXPECT_FAILURE(i_ii, |
2233 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2235 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), |
2234 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), | 2236 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
2235 WASM_SEQ(WASM_GET_LOCAL(1))), | 2237 WASM_SEQ(WASM_GET_LOCAL(1))), |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2548 v8::internal::AccountingAllocator allocator; | 2550 v8::internal::AccountingAllocator allocator; |
2549 | 2551 |
2550 size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected, | 2552 size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected, |
2551 size_t count) { | 2553 size_t count) { |
2552 for (size_t i = 0; i < count; i++) { | 2554 for (size_t i = 0; i < count; i++) { |
2553 EXPECT_EQ(expected, map[pos++]); | 2555 EXPECT_EQ(expected, map[pos++]); |
2554 } | 2556 } |
2555 return pos; | 2557 return pos; |
2556 } | 2558 } |
2557 | 2559 |
2558 LocalTypeMap Expand(AstLocalDecls& decls) { | 2560 LocalTypeMap Expand(BodyLocalDecls& decls) { |
2559 ZoneVector<LocalType> map(zone()); | 2561 ZoneVector<LocalType> map(zone()); |
2560 for (auto p : decls.local_types) { | 2562 for (auto p : decls.local_types) { |
2561 map.insert(map.end(), p.second, p.first); | 2563 map.insert(map.end(), p.second, p.first); |
2562 } | 2564 } |
2563 return map; | 2565 return map; |
2564 } | 2566 } |
2565 }; | 2567 }; |
2566 | 2568 |
2567 TEST_F(LocalDeclDecoderTest, EmptyLocals) { | 2569 TEST_F(LocalDeclDecoderTest, EmptyLocals) { |
2568 AstLocalDecls decls(zone()); | 2570 BodyLocalDecls decls(zone()); |
2569 bool result = DecodeLocalDecls(decls, nullptr, nullptr); | 2571 bool result = DecodeLocalDecls(decls, nullptr, nullptr); |
2570 EXPECT_FALSE(result); | 2572 EXPECT_FALSE(result); |
2571 } | 2573 } |
2572 | 2574 |
2573 TEST_F(LocalDeclDecoderTest, NoLocals) { | 2575 TEST_F(LocalDeclDecoderTest, NoLocals) { |
2574 static const byte data[] = {0}; | 2576 static const byte data[] = {0}; |
2575 AstLocalDecls decls(zone()); | 2577 BodyLocalDecls decls(zone()); |
2576 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2578 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2577 EXPECT_TRUE(result); | 2579 EXPECT_TRUE(result); |
2578 EXPECT_EQ(0u, decls.total_local_count); | 2580 EXPECT_EQ(0u, decls.total_local_count); |
2579 } | 2581 } |
2580 | 2582 |
2581 TEST_F(LocalDeclDecoderTest, OneLocal) { | 2583 TEST_F(LocalDeclDecoderTest, OneLocal) { |
2582 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2584 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
2583 LocalType type = kLocalTypes[i]; | 2585 LocalType type = kLocalTypes[i]; |
2584 const byte data[] = { | 2586 const byte data[] = { |
2585 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; | 2587 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; |
2586 AstLocalDecls decls(zone()); | 2588 BodyLocalDecls decls(zone()); |
2587 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2589 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2588 EXPECT_TRUE(result); | 2590 EXPECT_TRUE(result); |
2589 EXPECT_EQ(1u, decls.total_local_count); | 2591 EXPECT_EQ(1u, decls.total_local_count); |
2590 | 2592 |
2591 LocalTypeMap map = Expand(decls); | 2593 LocalTypeMap map = Expand(decls); |
2592 EXPECT_EQ(1u, map.size()); | 2594 EXPECT_EQ(1u, map.size()); |
2593 EXPECT_EQ(type, map[0]); | 2595 EXPECT_EQ(type, map[0]); |
2594 } | 2596 } |
2595 } | 2597 } |
2596 | 2598 |
2597 TEST_F(LocalDeclDecoderTest, FiveLocals) { | 2599 TEST_F(LocalDeclDecoderTest, FiveLocals) { |
2598 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2600 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { |
2599 LocalType type = kLocalTypes[i]; | 2601 LocalType type = kLocalTypes[i]; |
2600 const byte data[] = { | 2602 const byte data[] = { |
2601 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; | 2603 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; |
2602 AstLocalDecls decls(zone()); | 2604 BodyLocalDecls decls(zone()); |
2603 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2605 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2604 EXPECT_TRUE(result); | 2606 EXPECT_TRUE(result); |
2605 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); | 2607 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); |
2606 EXPECT_EQ(5u, decls.total_local_count); | 2608 EXPECT_EQ(5u, decls.total_local_count); |
2607 | 2609 |
2608 LocalTypeMap map = Expand(decls); | 2610 LocalTypeMap map = Expand(decls); |
2609 EXPECT_EQ(5u, map.size()); | 2611 EXPECT_EQ(5u, map.size()); |
2610 ExpectRun(map, 0, type, 5); | 2612 ExpectRun(map, 0, type, 5); |
2611 } | 2613 } |
2612 } | 2614 } |
2613 | 2615 |
2614 TEST_F(LocalDeclDecoderTest, MixedLocals) { | 2616 TEST_F(LocalDeclDecoderTest, MixedLocals) { |
2615 for (byte a = 0; a < 3; a++) { | 2617 for (byte a = 0; a < 3; a++) { |
2616 for (byte b = 0; b < 3; b++) { | 2618 for (byte b = 0; b < 3; b++) { |
2617 for (byte c = 0; c < 3; c++) { | 2619 for (byte c = 0; c < 3; c++) { |
2618 for (byte d = 0; d < 3; d++) { | 2620 for (byte d = 0; d < 3; d++) { |
2619 const byte data[] = {4, a, kLocalI32, b, kLocalI64, | 2621 const byte data[] = {4, a, kLocalI32, b, kLocalI64, |
2620 c, kLocalF32, d, kLocalF64}; | 2622 c, kLocalF32, d, kLocalF64}; |
2621 AstLocalDecls decls(zone()); | 2623 BodyLocalDecls decls(zone()); |
2622 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2624 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2623 EXPECT_TRUE(result); | 2625 EXPECT_TRUE(result); |
2624 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); | 2626 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); |
2625 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), | 2627 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), |
2626 decls.total_local_count); | 2628 decls.total_local_count); |
2627 | 2629 |
2628 LocalTypeMap map = Expand(decls); | 2630 LocalTypeMap map = Expand(decls); |
2629 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), map.size()); | 2631 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), map.size()); |
2630 | 2632 |
2631 size_t pos = 0; | 2633 size_t pos = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
2642 TEST_F(LocalDeclDecoderTest, UseEncoder) { | 2644 TEST_F(LocalDeclDecoderTest, UseEncoder) { |
2643 const byte* data = nullptr; | 2645 const byte* data = nullptr; |
2644 const byte* end = nullptr; | 2646 const byte* end = nullptr; |
2645 LocalDeclEncoder local_decls(zone()); | 2647 LocalDeclEncoder local_decls(zone()); |
2646 | 2648 |
2647 local_decls.AddLocals(5, kAstF32); | 2649 local_decls.AddLocals(5, kAstF32); |
2648 local_decls.AddLocals(1337, kAstI32); | 2650 local_decls.AddLocals(1337, kAstI32); |
2649 local_decls.AddLocals(212, kAstI64); | 2651 local_decls.AddLocals(212, kAstI64); |
2650 local_decls.Prepend(zone(), &data, &end); | 2652 local_decls.Prepend(zone(), &data, &end); |
2651 | 2653 |
2652 AstLocalDecls decls(zone()); | 2654 BodyLocalDecls decls(zone()); |
2653 bool result = DecodeLocalDecls(decls, data, end); | 2655 bool result = DecodeLocalDecls(decls, data, end); |
2654 EXPECT_TRUE(result); | 2656 EXPECT_TRUE(result); |
2655 EXPECT_EQ(5u + 1337u + 212u, decls.total_local_count); | 2657 EXPECT_EQ(5u + 1337u + 212u, decls.total_local_count); |
2656 | 2658 |
2657 LocalTypeMap map = Expand(decls); | 2659 LocalTypeMap map = Expand(decls); |
2658 size_t pos = 0; | 2660 size_t pos = 0; |
2659 pos = ExpectRun(map, pos, kAstF32, 5); | 2661 pos = ExpectRun(map, pos, kAstF32, 5); |
2660 pos = ExpectRun(map, pos, kAstI32, 1337); | 2662 pos = ExpectRun(map, pos, kAstI32, 1337); |
2661 pos = ExpectRun(map, pos, kAstI64, 212); | 2663 pos = ExpectRun(map, pos, kAstI64, 212); |
2662 } | 2664 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 EXPECT_EQ(6, count); | 2714 EXPECT_EQ(6, count); |
2713 | 2715 |
2714 count = 0; | 2716 count = 0; |
2715 for (auto offset : iter.offsets()) { | 2717 for (auto offset : iter.offsets()) { |
2716 USE(offset); | 2718 USE(offset); |
2717 count++; | 2719 count++; |
2718 } | 2720 } |
2719 EXPECT_EQ(6, count); | 2721 EXPECT_EQ(6, count); |
2720 } | 2722 } |
2721 | 2723 |
2722 TEST_F(BytecodeIteratorTest, WithAstDecls) { | 2724 TEST_F(BytecodeIteratorTest, WithLocalDecls) { |
2723 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; | 2725 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; |
2724 AstLocalDecls decls(zone()); | 2726 BodyLocalDecls decls(zone()); |
2725 BytecodeIterator iter(code, code + sizeof(code), &decls); | 2727 BytecodeIterator iter(code, code + sizeof(code), &decls); |
2726 | 2728 |
2727 EXPECT_EQ(3u, decls.decls_encoded_size); | 2729 EXPECT_EQ(3u, decls.decls_encoded_size); |
2728 EXPECT_EQ(3u, iter.pc_offset()); | 2730 EXPECT_EQ(3u, iter.pc_offset()); |
2729 EXPECT_TRUE(iter.has_next()); | 2731 EXPECT_TRUE(iter.has_next()); |
2730 EXPECT_EQ(kExprI8Const, iter.current()); | 2732 EXPECT_EQ(kExprI8Const, iter.current()); |
2731 iter.next(); | 2733 iter.next(); |
2732 EXPECT_TRUE(iter.has_next()); | 2734 EXPECT_TRUE(iter.has_next()); |
2733 EXPECT_EQ(kExprI8Const, iter.current()); | 2735 EXPECT_EQ(kExprI8Const, iter.current()); |
2734 iter.next(); | 2736 iter.next(); |
2735 EXPECT_FALSE(iter.has_next()); | 2737 EXPECT_FALSE(iter.has_next()); |
2736 } | 2738 } |
2737 | 2739 |
2738 } // namespace wasm | 2740 } // namespace wasm |
2739 } // namespace internal | 2741 } // namespace internal |
2740 } // namespace v8 | 2742 } // namespace v8 |
OLD | NEW |