Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: test/unittests/wasm/function-body-decoder-unittest.cc

Issue 2595733003: [wasm] Remove non-standard kExprI8Const bytecode (Closed)
Patch Set: Remove regression test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (types[0] != ret_type || types[1] != param_type) { 176 if (types[0] != ret_type || types[1] != param_type) {
177 // Test signature mismatch. 177 // Test signature mismatch.
178 FunctionSig sig(1, 1, types); 178 FunctionSig sig(1, 1, types);
179 EXPECT_FAILURE_SC(&sig, code); 179 EXPECT_FAILURE_SC(&sig, code);
180 } 180 }
181 } 181 }
182 } 182 }
183 } 183 }
184 }; 184 };
185 185
186 TEST_F(FunctionBodyDecoderTest, Int8Const) { 186 TEST_F(FunctionBodyDecoderTest, Int32Const1) {
187 byte code[] = {kExprI8Const, 0}; 187 byte code[] = {kExprI32Const, 0};
188 for (int i = -128; i < 128; i++) { 188 for (int i = -64; i <= 63; i++) {
189 code[1] = static_cast<byte>(i); 189 code[1] = static_cast<byte>(i & 0x7F);
190 EXPECT_VERIFIES_C(i_i, code); 190 EXPECT_VERIFIES_C(i_i, code);
191 } 191 }
192 } 192 }
193 193
194 TEST_F(FunctionBodyDecoderTest, EmptyFunction) { 194 TEST_F(FunctionBodyDecoderTest, EmptyFunction) {
195 byte code[] = {0}; 195 byte code[] = {0};
196 Verify(kSuccess, sigs.v_v(), code, code); 196 Verify(kSuccess, sigs.v_v(), code, code);
197 Verify(kError, sigs.i_i(), code, code); 197 Verify(kError, sigs.i_i(), code, code);
198 } 198 }
199 199
200 TEST_F(FunctionBodyDecoderTest, IncompleteIf1) { 200 TEST_F(FunctionBodyDecoderTest, IncompleteIf1) {
201 byte code[] = {kExprIf}; 201 byte code[] = {kExprIf};
202 EXPECT_FAILURE_C(v_v, code); 202 EXPECT_FAILURE_C(v_v, code);
203 EXPECT_FAILURE_C(i_i, code); 203 EXPECT_FAILURE_C(i_i, code);
204 } 204 }
205 205
206 TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru) { 206 TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru) {
207 EXPECT_VERIFIES(i_i, WASM_I32V_1(0)); 207 EXPECT_VERIFIES(i_i, WASM_I32V_1(0));
208 } 208 }
209 209
210 TEST_F(FunctionBodyDecoderTest, Int8Const_fallthru2) { 210 TEST_F(FunctionBodyDecoderTest, Int32Const_fallthru2) {
211 EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1)); 211 EXPECT_FAILURE(i_i, WASM_I32V_1(0), WASM_I32V_1(1));
212 } 212 }
213 213
214 TEST_F(FunctionBodyDecoderTest, Int32Const) { 214 TEST_F(FunctionBodyDecoderTest, Int32Const) {
215 const int kInc = 4498211; 215 const int kInc = 4498211;
216 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { 216 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
217 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. 217 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes.
218 byte code[] = {WASM_I32V(i)}; 218 byte code[] = {WASM_I32V(i)};
219 EXPECT_VERIFIES_C(i_i, code); 219 EXPECT_VERIFIES_C(i_i, code);
220 } 220 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) { 414 TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) {
415 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); 415 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0);
416 AddLocals(kWasmI32, 1); 416 AddLocals(kWasmI32, 1);
417 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); 417 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0);
418 } 418 }
419 419
420 TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { 420 TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) {
421 for (byte i = 1; i < 8; i++) { 421 for (byte i = 1; i < 8; i++) {
422 AddLocals(kWasmI32, 1); 422 AddLocals(kWasmI32, 1);
423 for (byte j = 0; j < i; j++) { 423 for (byte j = 0; j < i; j++) {
424 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); 424 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I32V_1(i)));
425 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); 425 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I32V_1(i)));
426 } 426 }
427 } 427 }
428 } 428 }
429 429
430 TEST_F(FunctionBodyDecoderTest, BlockN) { 430 TEST_F(FunctionBodyDecoderTest, BlockN) {
431 const int kMaxSize = 200; 431 const int kMaxSize = 200;
432 byte buffer[kMaxSize + 3]; 432 byte buffer[kMaxSize + 3];
433 433
434 for (int i = 0; i <= kMaxSize; i++) { 434 for (int i = 0; i <= kMaxSize; i++) {
435 memset(buffer, kExprNop, sizeof(buffer)); 435 memset(buffer, kExprNop, sizeof(buffer));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 TEST_F(FunctionBodyDecoderTest, Block2b) { 520 TEST_F(FunctionBodyDecoderTest, Block2b) {
521 byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)}; 521 byte code[] = {WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)};
522 EXPECT_VERIFIES_C(i_i, code); 522 EXPECT_VERIFIES_C(i_i, code);
523 EXPECT_FAILURE_C(v_v, code); 523 EXPECT_FAILURE_C(v_v, code);
524 EXPECT_FAILURE_C(f_ff, code); 524 EXPECT_FAILURE_C(f_ff, code);
525 } 525 }
526 526
527 TEST_F(FunctionBodyDecoderTest, Block2_fallthru) { 527 TEST_F(FunctionBodyDecoderTest, Block2_fallthru) {
528 EXPECT_VERIFIES( 528 EXPECT_VERIFIES(
529 i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)), 529 i_i, B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO)),
530 WASM_I8(23)); 530 WASM_I32V_1(23));
531 } 531 }
532 532
533 TEST_F(FunctionBodyDecoderTest, Block3) { 533 TEST_F(FunctionBodyDecoderTest, Block3) {
534 EXPECT_VERIFIES(i_i, WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO), 534 EXPECT_VERIFIES(i_i,
535 WASM_SET_LOCAL(0, WASM_ZERO), WASM_I8(11))); 535 WASM_BLOCK_I(WASM_SET_LOCAL(0, WASM_ZERO),
536 WASM_SET_LOCAL(0, WASM_ZERO), WASM_I32V_1(11)));
536 } 537 }
537 538
538 TEST_F(FunctionBodyDecoderTest, Block5) { 539 TEST_F(FunctionBodyDecoderTest, Block5) {
539 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO)); 540 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO));
540 541
541 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO)); 542 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO));
542 543
543 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO)); 544 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO));
544 545
545 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO)); 546 EXPECT_FAILURE(v_i, WASM_BLOCK(WASM_ZERO, WASM_ZERO, WASM_ZERO, WASM_ZERO));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1)))); 600 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(1))));
600 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2)))); 601 EXPECT_VERIFIES(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(2))));
601 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3)))); 602 EXPECT_FAILURE(v_v, B1(WASM_LOOP(WASM_NOP, WASM_BR(3))));
602 } 603 }
603 604
604 TEST_F(FunctionBodyDecoderTest, NestedBlock_return) { 605 TEST_F(FunctionBodyDecoderTest, NestedBlock_return) {
605 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO)))); 606 EXPECT_VERIFIES(i_i, B1(B1(WASM_RETURN1(WASM_ZERO))));
606 } 607 }
607 608
608 TEST_F(FunctionBodyDecoderTest, BlockBrBinop) { 609 TEST_F(FunctionBodyDecoderTest, BlockBrBinop) {
609 EXPECT_VERIFIES( 610 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I32V_1(1))),
610 i_i, WASM_I32_AND(WASM_BLOCK_I(WASM_BRV(0, WASM_I8(1))), WASM_I8(2))); 611 WASM_I32V_1(2)));
611 } 612 }
612 613
613 TEST_F(FunctionBodyDecoderTest, If_empty1) { 614 TEST_F(FunctionBodyDecoderTest, If_empty1) {
614 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd); 615 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprEnd);
615 } 616 }
616 617
617 TEST_F(FunctionBodyDecoderTest, If_empty2) { 618 TEST_F(FunctionBodyDecoderTest, If_empty2) {
618 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd); 619 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, kExprEnd);
619 } 620 }
620 621
621 TEST_F(FunctionBodyDecoderTest, If_empty3) { 622 TEST_F(FunctionBodyDecoderTest, If_empty3) {
622 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd); 623 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, WASM_NOP, kExprElse, kExprEnd);
623 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd); 624 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, WASM_ZERO, kExprElse, kExprEnd);
624 } 625 }
625 626
626 TEST_F(FunctionBodyDecoderTest, If_empty4) { 627 TEST_F(FunctionBodyDecoderTest, If_empty4) {
627 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd); 628 EXPECT_VERIFIES(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_NOP, kExprEnd);
628 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd); 629 EXPECT_FAILURE(v_v, WASM_ZERO, WASM_IF_OP, kExprElse, WASM_ZERO, kExprEnd);
629 } 630 }
630 631
631 TEST_F(FunctionBodyDecoderTest, If_empty_stack) { 632 TEST_F(FunctionBodyDecoderTest, If_empty_stack) {
632 byte code[] = {kExprIf}; 633 byte code[] = {kExprIf};
633 EXPECT_FAILURE_C(v_v, code); 634 EXPECT_FAILURE_C(v_v, code);
634 EXPECT_FAILURE_C(i_i, code); 635 EXPECT_FAILURE_C(i_i, code);
635 } 636 }
636 637
637 TEST_F(FunctionBodyDecoderTest, If_incomplete1) { 638 TEST_F(FunctionBodyDecoderTest, If_incomplete1) {
638 byte code[] = {kExprI8Const, 0, kExprIf}; 639 byte code[] = {kExprI32Const, 0, kExprIf};
639 EXPECT_FAILURE_C(v_v, code); 640 EXPECT_FAILURE_C(v_v, code);
640 EXPECT_FAILURE_C(i_i, code); 641 EXPECT_FAILURE_C(i_i, code);
641 } 642 }
642 643
643 TEST_F(FunctionBodyDecoderTest, If_incomplete2) { 644 TEST_F(FunctionBodyDecoderTest, If_incomplete2) {
644 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop}; 645 byte code[] = {kExprI32Const, 0, kExprIf, kExprNop};
645 EXPECT_FAILURE_C(v_v, code); 646 EXPECT_FAILURE_C(v_v, code);
646 EXPECT_FAILURE_C(i_i, code); 647 EXPECT_FAILURE_C(i_i, code);
647 } 648 }
648 649
649 TEST_F(FunctionBodyDecoderTest, If_else_else) { 650 TEST_F(FunctionBodyDecoderTest, If_else_else) {
650 byte code[] = {kExprI8Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd}; 651 byte code[] = {kExprI32Const, 0, WASM_IF_OP, kExprElse, kExprElse, kExprEnd};
651 EXPECT_FAILURE_C(v_v, code); 652 EXPECT_FAILURE_C(v_v, code);
652 EXPECT_FAILURE_C(i_i, code); 653 EXPECT_FAILURE_C(i_i, code);
653 } 654 }
654 655
655 TEST_F(FunctionBodyDecoderTest, IfEmpty) { 656 TEST_F(FunctionBodyDecoderTest, IfEmpty) {
656 EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd); 657 EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd);
657 } 658 }
658 659
659 TEST_F(FunctionBodyDecoderTest, IfSet) { 660 TEST_F(FunctionBodyDecoderTest, IfSet) {
660 EXPECT_VERIFIES(v_i, 661 EXPECT_VERIFIES(v_i,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2))); 698 EXPECT_FAILURE(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(2)));
698 } 699 }
699 700
700 TEST_F(FunctionBodyDecoderTest, IfElseBreak) { 701 TEST_F(FunctionBodyDecoderTest, IfElseBreak) {
701 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0))); 702 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0)));
702 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1))); 703 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1)));
703 EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2))); 704 EXPECT_FAILURE(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(2)));
704 } 705 }
705 706
706 TEST_F(FunctionBodyDecoderTest, Block_else) { 707 TEST_F(FunctionBodyDecoderTest, Block_else) {
707 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd}; 708 byte code[] = {kExprI32Const, 0, kExprBlock, kExprElse, kExprEnd};
708 EXPECT_FAILURE_C(v_v, code); 709 EXPECT_FAILURE_C(v_v, code);
709 EXPECT_FAILURE_C(i_i, code); 710 EXPECT_FAILURE_C(i_i, code);
710 } 711 }
711 712
712 TEST_F(FunctionBodyDecoderTest, IfNop) { 713 TEST_F(FunctionBodyDecoderTest, IfNop) {
713 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 714 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
714 } 715 }
715 716
716 TEST_F(FunctionBodyDecoderTest, IfNopElseNop) { 717 TEST_F(FunctionBodyDecoderTest, IfNopElseNop) {
717 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 718 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 TEST_F(FunctionBodyDecoderTest, IfBlock2b) { 770 TEST_F(FunctionBodyDecoderTest, IfBlock2b) {
770 EXPECT_VERIFIES( 771 EXPECT_VERIFIES(
771 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO), 772 v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO),
772 WASM_SET_LOCAL(0, WASM_ZERO)), 773 WASM_SET_LOCAL(0, WASM_ZERO)),
773 WASM_NOP)); 774 WASM_NOP));
774 } 775 }
775 776
776 TEST_F(FunctionBodyDecoderTest, IfElseSet) { 777 TEST_F(FunctionBodyDecoderTest, IfElseSet) {
777 EXPECT_VERIFIES(v_i, 778 EXPECT_VERIFIES(v_i,
778 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), 779 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
779 WASM_SET_LOCAL(0, WASM_I8(1)))); 780 WASM_SET_LOCAL(0, WASM_I32V_1(1))));
780 } 781 }
781 782
782 TEST_F(FunctionBodyDecoderTest, Loop0) { 783 TEST_F(FunctionBodyDecoderTest, Loop0) {
783 EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd); 784 EXPECT_VERIFIES(v_v, WASM_LOOP_OP, kExprEnd);
784 } 785 }
785 786
786 TEST_F(FunctionBodyDecoderTest, Loop1) { 787 TEST_F(FunctionBodyDecoderTest, Loop1) {
787 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))}; 788 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))};
788 EXPECT_VERIFIES_C(v_i, code); 789 EXPECT_VERIFIES_C(v_i, code);
789 EXPECT_FAILURE_C(v_v, code); 790 EXPECT_FAILURE_C(v_v, code);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 } 861 }
861 862
862 TEST_F(FunctionBodyDecoderTest, ReturnVoid2) { 863 TEST_F(FunctionBodyDecoderTest, ReturnVoid2) {
863 static const byte code[] = {WASM_BLOCK(WASM_BR(0))}; 864 static const byte code[] = {WASM_BLOCK(WASM_BR(0))};
864 EXPECT_VERIFIES_C(v_v, code); 865 EXPECT_VERIFIES_C(v_v, code);
865 EXPECT_FAILURE_C(i_i, code); 866 EXPECT_FAILURE_C(i_i, code);
866 EXPECT_FAILURE_C(i_f, code); 867 EXPECT_FAILURE_C(i_f, code);
867 } 868 }
868 869
869 TEST_F(FunctionBodyDecoderTest, ReturnVoid3) { 870 TEST_F(FunctionBodyDecoderTest, ReturnVoid3) {
870 EXPECT_FAILURE(v_v, kExprI8Const, 0);
871 EXPECT_FAILURE(v_v, kExprI32Const, 0); 871 EXPECT_FAILURE(v_v, kExprI32Const, 0);
872 EXPECT_FAILURE(v_v, kExprI64Const, 0); 872 EXPECT_FAILURE(v_v, kExprI64Const, 0);
873 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0); 873 EXPECT_FAILURE(v_v, kExprF32Const, 0, 0, 0, 0);
874 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 874 EXPECT_FAILURE(v_v, kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
875 875
876 EXPECT_FAILURE(v_i, kExprGetLocal, 0); 876 EXPECT_FAILURE(v_i, kExprGetLocal, 0);
877 } 877 }
878 878
879 TEST_F(FunctionBodyDecoderTest, Unreachable1) { 879 TEST_F(FunctionBodyDecoderTest, Unreachable1) {
880 EXPECT_VERIFIES(v_v, kExprUnreachable); 880 EXPECT_VERIFIES(v_v, kExprUnreachable);
881 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable); 881 EXPECT_VERIFIES(v_v, kExprUnreachable, kExprUnreachable);
882 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO)); 882 EXPECT_VERIFIES(v_v, B2(WASM_UNREACHABLE, WASM_ZERO));
883 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO)); 883 EXPECT_VERIFIES(v_v, B2(WASM_BR(0), WASM_ZERO));
884 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO)); 884 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
885 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO)); 885 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0), WASM_ZERO));
886 } 886 }
887 887
888 TEST_F(FunctionBodyDecoderTest, Unreachable_binop) { 888 TEST_F(FunctionBodyDecoderTest, Unreachable_binop) {
889 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); 889 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
890 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); 890 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
891 } 891 }
892 892
893 TEST_F(FunctionBodyDecoderTest, Unreachable_select) { 893 TEST_F(FunctionBodyDecoderTest, Unreachable_select) {
894 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); 894 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
895 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO)); 895 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO));
896 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE)); 896 EXPECT_VERIFIES(i_i, WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE));
897 } 897 }
898 898
899 TEST_F(FunctionBodyDecoderTest, If1) { 899 TEST_F(FunctionBodyDecoderTest, If1) {
900 EXPECT_VERIFIES(i_i,
901 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8)));
902 EXPECT_VERIFIES( 900 EXPECT_VERIFIES(
903 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_GET_LOCAL(0))); 901 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9), WASM_I32V_1(8)));
904 EXPECT_VERIFIES( 902 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(9),
905 i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8))); 903 WASM_GET_LOCAL(0)));
904 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
905 WASM_I32V_1(8)));
906 } 906 }
907 907
908 TEST_F(FunctionBodyDecoderTest, If_off_end) { 908 TEST_F(FunctionBodyDecoderTest, If_off_end) {
909 static const byte kCode[] = { 909 static const byte kCode[] = {
910 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))}; 910 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))};
911 for (size_t len = 3; len < arraysize(kCode); len++) { 911 for (size_t len = 3; len < arraysize(kCode); len++) {
912 Verify(kError, sigs.i_i(), kCode, kCode + len); 912 Verify(kError, sigs.i_i(), kCode, kCode + len);
913 } 913 }
914 } 914 }
915 915
916 TEST_F(FunctionBodyDecoderTest, If_type1) { 916 TEST_F(FunctionBodyDecoderTest, If_type1) {
917 // float|double ? 1 : 2 917 // float|double ? 1 : 2
918 static const byte kCode[] = { 918 static const byte kCode[] = {
919 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))}; 919 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I32V_1(0), WASM_I32V_1(2))};
920 EXPECT_VERIFIES_C(i_i, kCode); 920 EXPECT_VERIFIES_C(i_i, kCode);
921 EXPECT_FAILURE_C(i_f, kCode); 921 EXPECT_FAILURE_C(i_f, kCode);
922 EXPECT_FAILURE_C(i_d, kCode); 922 EXPECT_FAILURE_C(i_d, kCode);
923 } 923 }
924 924
925 TEST_F(FunctionBodyDecoderTest, If_type2) { 925 TEST_F(FunctionBodyDecoderTest, If_type2) {
926 // 1 ? float|double : 2 926 // 1 ? float|double : 2
927 static const byte kCode[] = { 927 static const byte kCode[] = {
928 WASM_IF_ELSE_I(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))}; 928 WASM_IF_ELSE_I(WASM_I32V_1(1), WASM_GET_LOCAL(0), WASM_I32V_1(1))};
929 EXPECT_VERIFIES_C(i_i, kCode); 929 EXPECT_VERIFIES_C(i_i, kCode);
930 EXPECT_FAILURE_C(i_f, kCode); 930 EXPECT_FAILURE_C(i_f, kCode);
931 EXPECT_FAILURE_C(i_d, kCode); 931 EXPECT_FAILURE_C(i_d, kCode);
932 } 932 }
933 933
934 TEST_F(FunctionBodyDecoderTest, If_type3) { 934 TEST_F(FunctionBodyDecoderTest, If_type3) {
935 // stmt ? 0 : 1 935 // stmt ? 0 : 1
936 static const byte kCode[] = { 936 static const byte kCode[] = {
937 WASM_IF_ELSE_I(WASM_NOP, WASM_I8(0), WASM_I8(1))}; 937 WASM_IF_ELSE_I(WASM_NOP, WASM_I32V_1(0), WASM_I32V_1(1))};
938 EXPECT_FAILURE_C(i_i, kCode); 938 EXPECT_FAILURE_C(i_i, kCode);
939 EXPECT_FAILURE_C(i_f, kCode); 939 EXPECT_FAILURE_C(i_f, kCode);
940 EXPECT_FAILURE_C(i_d, kCode); 940 EXPECT_FAILURE_C(i_d, kCode);
941 } 941 }
942 942
943 TEST_F(FunctionBodyDecoderTest, If_type4) { 943 TEST_F(FunctionBodyDecoderTest, If_type4) {
944 // 0 ? stmt : 1 944 // 0 ? stmt : 1
945 static const byte kCode[] = { 945 static const byte kCode[] = {
946 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))}; 946 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_NOP, WASM_I32V_1(1))};
947 EXPECT_FAILURE_C(i_i, kCode); 947 EXPECT_FAILURE_C(i_i, kCode);
948 EXPECT_FAILURE_C(i_f, kCode); 948 EXPECT_FAILURE_C(i_f, kCode);
949 EXPECT_FAILURE_C(i_d, kCode); 949 EXPECT_FAILURE_C(i_d, kCode);
950 } 950 }
951 951
952 TEST_F(FunctionBodyDecoderTest, If_type5) { 952 TEST_F(FunctionBodyDecoderTest, If_type5) {
953 // 0 ? 1 : stmt 953 // 0 ? 1 : stmt
954 static const byte kCode[] = {WASM_IF_ELSE_I(WASM_ZERO, WASM_I8(1), WASM_NOP)}; 954 static const byte kCode[] = {
955 WASM_IF_ELSE_I(WASM_ZERO, WASM_I32V_1(1), WASM_NOP)};
955 EXPECT_FAILURE_C(i_i, kCode); 956 EXPECT_FAILURE_C(i_i, kCode);
956 EXPECT_FAILURE_C(i_f, kCode); 957 EXPECT_FAILURE_C(i_f, kCode);
957 EXPECT_FAILURE_C(i_d, kCode); 958 EXPECT_FAILURE_C(i_d, kCode);
958 } 959 }
959 960
960 TEST_F(FunctionBodyDecoderTest, Int64Local_param) { 961 TEST_F(FunctionBodyDecoderTest, Int64Local_param) {
961 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); 962 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0);
962 } 963 }
963 964
964 TEST_F(FunctionBodyDecoderTest, Int64Locals) { 965 TEST_F(FunctionBodyDecoderTest, Int64Locals) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32); 1022 TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32);
1022 TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32); 1023 TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32);
1023 TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32); 1024 TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32);
1024 TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32); 1025 TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32);
1025 TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32); 1026 TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32);
1026 TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64); 1027 TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64);
1027 } 1028 }
1028 1029
1029 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { 1030 TEST_F(FunctionBodyDecoderTest, MacrosStmt) {
1030 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); 1031 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
1031 EXPECT_VERIFIES( 1032 EXPECT_VERIFIES(v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24),
1032 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); 1033 WASM_I32V_1(40)));
1033 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 1034 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
1034 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 1035 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
1035 EXPECT_VERIFIES(v_v, WASM_NOP); 1036 EXPECT_VERIFIES(v_v, WASM_NOP);
1036 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); 1037 EXPECT_VERIFIES(v_v, B1(WASM_NOP));
1037 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); 1038 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP));
1038 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); 1039 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0)));
1039 } 1040 }
1040 1041
1041 TEST_F(FunctionBodyDecoderTest, MacrosContinue) { 1042 TEST_F(FunctionBodyDecoderTest, MacrosContinue) {
1042 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0))); 1043 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_CONTINUE(0)));
(...skipping 16 matching lines...) Expand all
1059 1060
1060 TEST_F(FunctionBodyDecoderTest, MultipleReturn) { 1061 TEST_F(FunctionBodyDecoderTest, MultipleReturn) {
1061 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32, 1062 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32,
1062 kWasmI32}; 1063 kWasmI32};
1063 FunctionSig sig_ii_v(2, 0, kIntTypes5); 1064 FunctionSig sig_ii_v(2, 0, kIntTypes5);
1064 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); 1065 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
1065 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); 1066 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO));
1066 1067
1067 FunctionSig sig_iii_v(3, 0, kIntTypes5); 1068 FunctionSig sig_iii_v(3, 0, kIntTypes5);
1068 EXPECT_VERIFIES_S(&sig_iii_v, 1069 EXPECT_VERIFIES_S(&sig_iii_v,
1069 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); 1070 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I32V_1(44)));
1070 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); 1071 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
1071 } 1072 }
1072 1073
1073 TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { 1074 TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) {
1074 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32, 1075 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32,
1075 kWasmI32}; 1076 kWasmI32};
1076 FunctionSig sig_ii_v(2, 0, kIntTypes5); 1077 FunctionSig sig_ii_v(2, 0, kIntTypes5);
1077 1078
1078 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); 1079 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE);
1079 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); 1080 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO);
1080 1081
1081 FunctionSig sig_iii_v(3, 0, kIntTypes5); 1082 FunctionSig sig_iii_v(3, 0, kIntTypes5);
1082 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); 1083 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I32V_1(44));
1083 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); 1084 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE);
1084 } 1085 }
1085 1086
1086 TEST_F(FunctionBodyDecoderTest, MacrosInt32) { 1087 TEST_F(FunctionBodyDecoderTest, MacrosInt32) {
1087 EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I8(12))); 1088 EXPECT_VERIFIES(i_i, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_I32V_1(12)));
1088 EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I8(13))); 1089 EXPECT_VERIFIES(i_i, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_I32V_1(13)));
1089 EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I8(14))); 1090 EXPECT_VERIFIES(i_i, WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_I32V_1(14)));
1090 EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(15))); 1091 EXPECT_VERIFIES(i_i, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I32V_1(15)));
1091 EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I8(16))); 1092 EXPECT_VERIFIES(i_i, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(16)));
1092 EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I8(17))); 1093 EXPECT_VERIFIES(i_i, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_I32V_1(17)));
1093 EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I8(18))); 1094 EXPECT_VERIFIES(i_i, WASM_I32_REMU(WASM_GET_LOCAL(0), WASM_I32V_1(18)));
1094 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I8(19))); 1095 EXPECT_VERIFIES(i_i, WASM_I32_AND(WASM_GET_LOCAL(0), WASM_I32V_1(19)));
1095 EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I8(20))); 1096 EXPECT_VERIFIES(i_i, WASM_I32_IOR(WASM_GET_LOCAL(0), WASM_I32V_1(20)));
1096 EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I8(21))); 1097 EXPECT_VERIFIES(i_i, WASM_I32_XOR(WASM_GET_LOCAL(0), WASM_I32V_1(21)));
1097 EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I8(22))); 1098 EXPECT_VERIFIES(i_i, WASM_I32_SHL(WASM_GET_LOCAL(0), WASM_I32V_1(22)));
1098 EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I8(23))); 1099 EXPECT_VERIFIES(i_i, WASM_I32_SHR(WASM_GET_LOCAL(0), WASM_I32V_1(23)));
1099 EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I8(24))); 1100 EXPECT_VERIFIES(i_i, WASM_I32_SAR(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
1100 EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I8(24))); 1101 EXPECT_VERIFIES(i_i, WASM_I32_ROR(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
1101 EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I8(24))); 1102 EXPECT_VERIFIES(i_i, WASM_I32_ROL(WASM_GET_LOCAL(0), WASM_I32V_1(24)));
1102 EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I8(25))); 1103 EXPECT_VERIFIES(i_i, WASM_I32_EQ(WASM_GET_LOCAL(0), WASM_I32V_1(25)));
1103 EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I8(25))); 1104 EXPECT_VERIFIES(i_i, WASM_I32_NE(WASM_GET_LOCAL(0), WASM_I32V_1(25)));
1104 1105
1105 EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I8(26))); 1106 EXPECT_VERIFIES(i_i, WASM_I32_LTS(WASM_GET_LOCAL(0), WASM_I32V_1(26)));
1106 EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I8(27))); 1107 EXPECT_VERIFIES(i_i, WASM_I32_LES(WASM_GET_LOCAL(0), WASM_I32V_1(27)));
1107 EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I8(28))); 1108 EXPECT_VERIFIES(i_i, WASM_I32_LTU(WASM_GET_LOCAL(0), WASM_I32V_1(28)));
1108 EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I8(29))); 1109 EXPECT_VERIFIES(i_i, WASM_I32_LEU(WASM_GET_LOCAL(0), WASM_I32V_1(29)));
1109 1110
1110 EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I8(26))); 1111 EXPECT_VERIFIES(i_i, WASM_I32_GTS(WASM_GET_LOCAL(0), WASM_I32V_1(26)));
1111 EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I8(27))); 1112 EXPECT_VERIFIES(i_i, WASM_I32_GES(WASM_GET_LOCAL(0), WASM_I32V_1(27)));
1112 EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I8(28))); 1113 EXPECT_VERIFIES(i_i, WASM_I32_GTU(WASM_GET_LOCAL(0), WASM_I32V_1(28)));
1113 EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I8(29))); 1114 EXPECT_VERIFIES(i_i, WASM_I32_GEU(WASM_GET_LOCAL(0), WASM_I32V_1(29)));
1114 } 1115 }
1115 1116
1116 TEST_F(FunctionBodyDecoderTest, MacrosInt64) { 1117 TEST_F(FunctionBodyDecoderTest, MacrosInt64) {
1117 EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12))); 1118 EXPECT_VERIFIES(l_ll, WASM_I64_ADD(WASM_GET_LOCAL(0), WASM_I64V_1(12)));
1118 EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13))); 1119 EXPECT_VERIFIES(l_ll, WASM_I64_SUB(WASM_GET_LOCAL(0), WASM_I64V_1(13)));
1119 EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14))); 1120 EXPECT_VERIFIES(l_ll, WASM_I64_MUL(WASM_GET_LOCAL(0), WASM_I64V_1(14)));
1120 EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15))); 1121 EXPECT_VERIFIES(l_ll, WASM_I64_DIVS(WASM_GET_LOCAL(0), WASM_I64V_1(15)));
1121 EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16))); 1122 EXPECT_VERIFIES(l_ll, WASM_I64_DIVU(WASM_GET_LOCAL(0), WASM_I64V_1(16)));
1122 EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17))); 1123 EXPECT_VERIFIES(l_ll, WASM_I64_REMS(WASM_GET_LOCAL(0), WASM_I64V_1(17)));
1123 EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18))); 1124 EXPECT_VERIFIES(l_ll, WASM_I64_REMU(WASM_GET_LOCAL(0), WASM_I64V_1(18)));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 } 1164 }
1164 1165
1165 TEST_F(FunctionBodyDecoderTest, MemorySize) { 1166 TEST_F(FunctionBodyDecoderTest, MemorySize) {
1166 byte code[] = {kExprMemorySize, 0}; 1167 byte code[] = {kExprMemorySize, 0};
1167 EXPECT_VERIFIES_C(i_i, code); 1168 EXPECT_VERIFIES_C(i_i, code);
1168 EXPECT_FAILURE_C(f_ff, code); 1169 EXPECT_FAILURE_C(f_ff, code);
1169 } 1170 }
1170 1171
1171 TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { 1172 TEST_F(FunctionBodyDecoderTest, LoadMemOffset) {
1172 for (int offset = 0; offset < 128; offset += 7) { 1173 for (int offset = 0; offset < 128; offset += 7) {
1173 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, 1174 byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
1174 static_cast<byte>(offset)}; 1175 static_cast<byte>(offset)};
1175 EXPECT_VERIFIES_C(i_i, code); 1176 EXPECT_VERIFIES_C(i_i, code);
1176 } 1177 }
1177 } 1178 }
1178 1179
1179 TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) { 1180 TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) {
1180 struct { 1181 struct {
1181 WasmOpcode instruction; 1182 WasmOpcode instruction;
1182 uint32_t maximum_aligment; 1183 uint32_t maximum_aligment;
1183 } values[] = { 1184 } values[] = {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 TEST_F(FunctionBodyDecoderTest, SimpleCalls) { 1339 TEST_F(FunctionBodyDecoderTest, SimpleCalls) {
1339 FunctionSig* sig = sigs.i_i(); 1340 FunctionSig* sig = sigs.i_i();
1340 TestModuleEnv module_env; 1341 TestModuleEnv module_env;
1341 module = &module_env; 1342 module = &module_env;
1342 1343
1343 module_env.AddFunction(sigs.i_v()); 1344 module_env.AddFunction(sigs.i_v());
1344 module_env.AddFunction(sigs.i_i()); 1345 module_env.AddFunction(sigs.i_i());
1345 module_env.AddFunction(sigs.i_ii()); 1346 module_env.AddFunction(sigs.i_ii());
1346 1347
1347 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); 1348 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0));
1348 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); 1349 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(1, WASM_I32V_1(27)));
1349 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); 1350 EXPECT_VERIFIES_S(sig,
1351 WASM_CALL_FUNCTION(2, WASM_I32V_1(37), WASM_I32V_2(77)));
1350 } 1352 }
1351 1353
1352 TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) { 1354 TEST_F(FunctionBodyDecoderTest, CallsWithTooFewArguments) {
1353 FunctionSig* sig = sigs.i_i(); 1355 FunctionSig* sig = sigs.i_i();
1354 TestModuleEnv module_env; 1356 TestModuleEnv module_env;
1355 module = &module_env; 1357 module = &module_env;
1356 1358
1357 module_env.AddFunction(sigs.i_i()); 1359 module_env.AddFunction(sigs.i_i());
1358 module_env.AddFunction(sigs.i_ii()); 1360 module_env.AddFunction(sigs.i_ii());
1359 module_env.AddFunction(sigs.f_ff()); 1361 module_env.AddFunction(sigs.f_ff());
(...skipping 15 matching lines...) Expand all
1375 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); 1377 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1)));
1376 } 1378 }
1377 1379
1378 TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) { 1380 TEST_F(FunctionBodyDecoderTest, CallsWithMismatchedSigs3) {
1379 FunctionSig* sig = sigs.i_i(); 1381 FunctionSig* sig = sigs.i_i();
1380 TestModuleEnv module_env; 1382 TestModuleEnv module_env;
1381 module = &module_env; 1383 module = &module_env;
1382 1384
1383 module_env.AddFunction(sigs.i_f()); 1385 module_env.AddFunction(sigs.i_f());
1384 1386
1385 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); 1387 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I32V_1(17)));
1386 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); 1388 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27)));
1387 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); 1389 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2)));
1388 1390
1389 module_env.AddFunction(sigs.i_d()); 1391 module_env.AddFunction(sigs.i_d());
1390 1392
1391 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); 1393 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I32V_1(16)));
1392 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); 1394 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16)));
1393 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); 1395 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6)));
1394 } 1396 }
1395 1397
1396 TEST_F(FunctionBodyDecoderTest, MultiReturn) { 1398 TEST_F(FunctionBodyDecoderTest, MultiReturn) {
1397 FLAG_wasm_mv_prototype = true; 1399 FLAG_wasm_mv_prototype = true;
1398 ValueType storage[] = {kWasmI32, kWasmI32}; 1400 ValueType storage[] = {kWasmI32, kWasmI32};
1399 FunctionSig sig_ii_v(2, 0, storage); 1401 FunctionSig sig_ii_v(2, 0, storage);
1400 FunctionSig sig_v_ii(0, 2, storage); 1402 FunctionSig sig_v_ii(0, 2, storage);
1401 TestModuleEnv module_env; 1403 TestModuleEnv module_env;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 FunctionSig* sig = sigs.i_i(); 1443 FunctionSig* sig = sigs.i_i();
1442 TestModuleEnv module_env; 1444 TestModuleEnv module_env;
1443 module_env.InitializeFunctionTable(); 1445 module_env.InitializeFunctionTable();
1444 module = &module_env; 1446 module = &module_env;
1445 1447
1446 byte f0 = module_env.AddSignature(sigs.i_v()); 1448 byte f0 = module_env.AddSignature(sigs.i_v());
1447 byte f1 = module_env.AddSignature(sigs.i_i()); 1449 byte f1 = module_env.AddSignature(sigs.i_i());
1448 byte f2 = module_env.AddSignature(sigs.i_ii()); 1450 byte f2 = module_env.AddSignature(sigs.i_ii());
1449 1451
1450 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); 1452 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
1451 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); 1453 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22)));
1452 EXPECT_VERIFIES_S( 1454 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32),
1453 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); 1455 WASM_I32V_2(72)));
1454 } 1456 }
1455 1457
1456 TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) { 1458 TEST_F(FunctionBodyDecoderTest, IndirectCallsOutOfBounds) {
1457 FunctionSig* sig = sigs.i_i(); 1459 FunctionSig* sig = sigs.i_i();
1458 TestModuleEnv module_env; 1460 TestModuleEnv module_env;
1459 module_env.InitializeFunctionTable(); 1461 module_env.InitializeFunctionTable();
1460 module = &module_env; 1462 module = &module_env;
1461 1463
1462 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1464 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1463 module_env.AddSignature(sigs.i_v()); 1465 module_env.AddSignature(sigs.i_v());
1464 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1466 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1465 1467
1466 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); 1468 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(22)));
1467 module_env.AddSignature(sigs.i_i()); 1469 module_env.AddSignature(sigs.i_i());
1468 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); 1470 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I32V_1(27)));
1469 1471
1470 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); 1472 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I32V_1(27)));
1471 } 1473 }
1472 1474
1473 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) { 1475 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithMismatchedSigs3) {
1474 FunctionSig* sig = sigs.i_i(); 1476 FunctionSig* sig = sigs.i_i();
1475 TestModuleEnv module_env; 1477 TestModuleEnv module_env;
1476 module_env.InitializeFunctionTable(); 1478 module_env.InitializeFunctionTable();
1477 module = &module_env; 1479 module = &module_env;
1478 1480
1479 byte f0 = module_env.AddFunction(sigs.i_f()); 1481 byte f0 = module_env.AddFunction(sigs.i_f());
1480 1482
1481 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); 1483 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I32V_1(17)));
1482 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); 1484 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27)));
1483 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); 1485 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2)));
1484 1486
1485 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); 1487 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I32V_1(17)));
1486 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); 1488 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
1487 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); 1489 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
1488 1490
1489 byte f1 = module_env.AddFunction(sigs.i_d()); 1491 byte f1 = module_env.AddFunction(sigs.i_d());
1490 1492
1491 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); 1493 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(16)));
1492 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); 1494 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16)));
1493 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); 1495 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6)));
1494 } 1496 }
1495 1497
1496 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) { 1498 TEST_F(FunctionBodyDecoderTest, IndirectCallsWithoutTableCrash) {
1497 FunctionSig* sig = sigs.i_i(); 1499 FunctionSig* sig = sigs.i_i();
1498 TestModuleEnv module_env; 1500 TestModuleEnv module_env;
1499 module = &module_env; 1501 module = &module_env;
1500 1502
1501 byte f0 = module_env.AddSignature(sigs.i_v()); 1503 byte f0 = module_env.AddSignature(sigs.i_v());
1502 byte f1 = module_env.AddSignature(sigs.i_i()); 1504 byte f1 = module_env.AddSignature(sigs.i_i());
1503 byte f2 = module_env.AddSignature(sigs.i_ii()); 1505 byte f2 = module_env.AddSignature(sigs.i_ii());
1504 1506
1505 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); 1507 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
1506 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); 1508 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I32V_1(22)));
1507 EXPECT_FAILURE_S( 1509 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I32V_1(32),
1508 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); 1510 WASM_I32V_2(72)));
1509 } 1511 }
1510 1512
1511 TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) { 1513 TEST_F(FunctionBodyDecoderTest, SimpleImportCalls) {
1512 FunctionSig* sig = sigs.i_i(); 1514 FunctionSig* sig = sigs.i_i();
1513 TestModuleEnv module_env; 1515 TestModuleEnv module_env;
1514 module = &module_env; 1516 module = &module_env;
1515 1517
1516 byte f0 = module_env.AddImport(sigs.i_v()); 1518 byte f0 = module_env.AddImport(sigs.i_v());
1517 byte f1 = module_env.AddImport(sigs.i_i()); 1519 byte f1 = module_env.AddImport(sigs.i_i());
1518 byte f2 = module_env.AddImport(sigs.i_ii()); 1520 byte f2 = module_env.AddImport(sigs.i_ii());
1519 1521
1520 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); 1522 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0));
1521 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(22))); 1523 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f1, WASM_I32V_1(22)));
1522 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION(f2, WASM_I8(32), WASM_I8(72))); 1524 EXPECT_VERIFIES_S(sig,
1525 WASM_CALL_FUNCTION(f2, WASM_I32V_1(32), WASM_I32V_2(72)));
1523 } 1526 }
1524 1527
1525 TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) { 1528 TEST_F(FunctionBodyDecoderTest, ImportCallsWithMismatchedSigs3) {
1526 FunctionSig* sig = sigs.i_i(); 1529 FunctionSig* sig = sigs.i_i();
1527 TestModuleEnv module_env; 1530 TestModuleEnv module_env;
1528 module = &module_env; 1531 module = &module_env;
1529 1532
1530 byte f0 = module_env.AddImport(sigs.i_f()); 1533 byte f0 = module_env.AddImport(sigs.i_f());
1531 1534
1532 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0)); 1535 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f0));
1533 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I8(17))); 1536 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I32V_1(17)));
1534 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27))); 1537 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_I64V_1(27)));
1535 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2))); 1538 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f0, WASM_F64(37.2)));
1536 1539
1537 byte f1 = module_env.AddImport(sigs.i_d()); 1540 byte f1 = module_env.AddImport(sigs.i_d());
1538 1541
1539 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1)); 1542 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION0(f1));
1540 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); 1543 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I32V_1(16)));
1541 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); 1544 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16)));
1542 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); 1545 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6)));
1543 } 1546 }
1544 1547
1545 TEST_F(FunctionBodyDecoderTest, Int32Globals) { 1548 TEST_F(FunctionBodyDecoderTest, Int32Globals) {
1546 FunctionSig* sig = sigs.i_i(); 1549 FunctionSig* sig = sigs.i_i();
1547 TestModuleEnv module_env; 1550 TestModuleEnv module_env;
1548 module = &module_env; 1551 module = &module_env;
1549 1552
1550 module_env.AddGlobal(kWasmI32); 1553 module_env.AddGlobal(kWasmI32);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1792 EXPECT_FAILURE_S( 1795 EXPECT_FAILURE_S(
1793 sigs.i_i(), 1796 sigs.i_i(),
1794 WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO)))); 1797 WASM_BLOCK_I(WASM_F32_ABS(WASM_BRV_IF(0, WASM_F32(0.0f), WASM_ZERO))));
1795 } 1798 }
1796 1799
1797 TEST_F(FunctionBodyDecoderTest, BreakNesting1) { 1800 TEST_F(FunctionBodyDecoderTest, BreakNesting1) {
1798 for (int i = 0; i < 5; i++) { 1801 for (int i = 0; i < 5; i++) {
1799 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) 1802 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
1800 byte code[] = {WASM_BLOCK_I( 1803 byte code[] = {WASM_BLOCK_I(
1801 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), 1804 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)),
1802 WASM_SET_LOCAL(0, WASM_I8(1))), 1805 WASM_SET_LOCAL(0, WASM_I32V_1(1))),
1803 WASM_ZERO)}; 1806 WASM_ZERO)};
1804 if (i < 3) { 1807 if (i < 3) {
1805 EXPECT_VERIFIES_C(i_i, code); 1808 EXPECT_VERIFIES_C(i_i, code);
1806 } else { 1809 } else {
1807 EXPECT_FAILURE_C(i_i, code); 1810 EXPECT_FAILURE_C(i_i, code);
1808 } 1811 }
1809 } 1812 }
1810 } 1813 }
1811 1814
1812 TEST_F(FunctionBodyDecoderTest, BreakNesting2) { 1815 TEST_F(FunctionBodyDecoderTest, BreakNesting2) {
(...skipping 14 matching lines...) Expand all
1827 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))}; 1830 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BR(i + 1)))))};
1828 if (i < 4) { 1831 if (i < 4) {
1829 EXPECT_VERIFIES_C(v_v, code); 1832 EXPECT_VERIFIES_C(v_v, code);
1830 } else { 1833 } else {
1831 EXPECT_FAILURE_C(v_v, code); 1834 EXPECT_FAILURE_C(v_v, code);
1832 } 1835 }
1833 } 1836 }
1834 } 1837 }
1835 1838
1836 TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) { 1839 TEST_F(FunctionBodyDecoderTest, BreaksWithMultipleTypes) {
1837 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7))); 1840 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)), WASM_F32(7.7)));
1838 1841
1839 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), 1842 EXPECT_FAILURE(i_i, B2(WASM_BRV_IF_ZERO(0, WASM_I32V_1(7)),
1840 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1843 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1841 EXPECT_FAILURE( 1844 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(8)),
1842 i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)), WASM_BRV_IF_ZERO(0, WASM_I8(0)), 1845 WASM_BRV_IF_ZERO(0, WASM_I32V_1(0)),
1843 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1846 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1844 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)), 1847 EXPECT_FAILURE(i_i, B3(WASM_BRV_IF_ZERO(0, WASM_I32V_1(9)),
1845 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)), 1848 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
1846 WASM_BRV_IF_ZERO(0, WASM_I8(11)))); 1849 WASM_BRV_IF_ZERO(0, WASM_I32V_1(11))));
1847 } 1850 }
1848 1851
1849 TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) { 1852 TEST_F(FunctionBodyDecoderTest, BreakNesting_6_levels) {
1850 for (int mask = 0; mask < 64; mask++) { 1853 for (int mask = 0; mask < 64; mask++) {
1851 for (int i = 0; i < 14; i++) { 1854 for (int i = 0; i < 14; i++) {
1852 byte code[] = {WASM_BLOCK(WASM_BLOCK( 1855 byte code[] = {WASM_BLOCK(WASM_BLOCK(
1853 WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))}; 1856 WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BLOCK(WASM_BR(i)))))))};
1854 1857
1855 int depth = 6; 1858 int depth = 6;
1856 int m = mask; 1859 int m = mask;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 EXPECT_FAILURE_C(i_i, code); 2035 EXPECT_FAILURE_C(i_i, code);
2033 } 2036 }
2034 2037
2035 TEST_F(FunctionBodyDecoderTest, BrTable0c) { 2038 TEST_F(FunctionBodyDecoderTest, BrTable0c) {
2036 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)}; 2039 static byte code[] = {kExprI32Const, 11, kExprBrTable, 0, BR_TARGET(1)};
2037 EXPECT_FAILURE_C(v_v, code); 2040 EXPECT_FAILURE_C(v_v, code);
2038 EXPECT_FAILURE_C(i_i, code); 2041 EXPECT_FAILURE_C(i_i, code);
2039 } 2042 }
2040 2043
2041 TEST_F(FunctionBodyDecoderTest, BrTable1a) { 2044 TEST_F(FunctionBodyDecoderTest, BrTable1a) {
2042 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))}; 2045 static byte code[] = {B1(WASM_BR_TABLE(WASM_I32V_2(67), 0, BR_TARGET(0)))};
2043 EXPECT_VERIFIES_C(v_v, code); 2046 EXPECT_VERIFIES_C(v_v, code);
2044 } 2047 }
2045 2048
2046 TEST_F(FunctionBodyDecoderTest, BrTable1b) { 2049 TEST_F(FunctionBodyDecoderTest, BrTable1b) {
2047 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))}; 2050 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
2048 EXPECT_VERIFIES_C(v_v, code); 2051 EXPECT_VERIFIES_C(v_v, code);
2049 EXPECT_FAILURE_C(i_i, code); 2052 EXPECT_FAILURE_C(i_i, code);
2050 EXPECT_FAILURE_C(f_ff, code); 2053 EXPECT_FAILURE_C(f_ff, code);
2051 EXPECT_FAILURE_C(d_dd, code); 2054 EXPECT_FAILURE_C(d_dd, code);
2052 } 2055 }
2053 2056
2054 TEST_F(FunctionBodyDecoderTest, BrTable2a) { 2057 TEST_F(FunctionBodyDecoderTest, BrTable2a) {
2055 static byte code[] = { 2058 static byte code[] = {
2056 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; 2059 B1(WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(0)))};
2057 EXPECT_VERIFIES_C(v_v, code); 2060 EXPECT_VERIFIES_C(v_v, code);
2058 } 2061 }
2059 2062
2060 TEST_F(FunctionBodyDecoderTest, BrTable2b) { 2063 TEST_F(FunctionBodyDecoderTest, BrTable2b) {
2061 static byte code[] = {WASM_BLOCK( 2064 static byte code[] = {WASM_BLOCK(WASM_BLOCK(
2062 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; 2065 WASM_BR_TABLE(WASM_I32V_2(67), 1, BR_TARGET(0), BR_TARGET(1))))};
2063 EXPECT_VERIFIES_C(v_v, code); 2066 EXPECT_VERIFIES_C(v_v, code);
2064 } 2067 }
2065 2068
2066 TEST_F(FunctionBodyDecoderTest, BrTable_off_end) { 2069 TEST_F(FunctionBodyDecoderTest, BrTable_off_end) {
2067 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; 2070 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
2068 for (size_t len = 1; len < sizeof(code); len++) { 2071 for (size_t len = 1; len < sizeof(code); len++) {
2069 Verify(kError, sigs.i_i(), code, code + len); 2072 Verify(kError, sigs.i_i(), code, code + len);
2070 } 2073 }
2071 } 2074 }
2072 2075
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 EXPECT_LENGTH(1, kExprEnd); 2337 EXPECT_LENGTH(1, kExprEnd);
2335 EXPECT_LENGTH(1, kExprSelect); 2338 EXPECT_LENGTH(1, kExprSelect);
2336 EXPECT_LENGTH(2, kExprBr); 2339 EXPECT_LENGTH(2, kExprBr);
2337 EXPECT_LENGTH(2, kExprBrIf); 2340 EXPECT_LENGTH(2, kExprBrIf);
2338 EXPECT_LENGTH(1, kExprThrow); 2341 EXPECT_LENGTH(1, kExprThrow);
2339 EXPECT_LENGTH(2, kExprTry); 2342 EXPECT_LENGTH(2, kExprTry);
2340 EXPECT_LENGTH(2, kExprCatch); 2343 EXPECT_LENGTH(2, kExprCatch);
2341 } 2344 }
2342 2345
2343 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { 2346 TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
2344 EXPECT_LENGTH(2, kExprI8Const);
2345 EXPECT_LENGTH(5, kExprF32Const); 2347 EXPECT_LENGTH(5, kExprF32Const);
2346 EXPECT_LENGTH(9, kExprF64Const); 2348 EXPECT_LENGTH(9, kExprF64Const);
2347 EXPECT_LENGTH(2, kExprGetLocal); 2349 EXPECT_LENGTH(2, kExprGetLocal);
2348 EXPECT_LENGTH(2, kExprSetLocal); 2350 EXPECT_LENGTH(2, kExprSetLocal);
2349 EXPECT_LENGTH(2, kExprGetGlobal); 2351 EXPECT_LENGTH(2, kExprGetGlobal);
2350 EXPECT_LENGTH(2, kExprSetGlobal); 2352 EXPECT_LENGTH(2, kExprSetGlobal);
2351 EXPECT_LENGTH(2, kExprCallFunction); 2353 EXPECT_LENGTH(2, kExprCallFunction);
2352 EXPECT_LENGTH(3, kExprCallIndirect); 2354 EXPECT_LENGTH(3, kExprCallIndirect);
2353 } 2355 }
2354 2356
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 pos = ExpectRun(map, pos, kWasmF32, 5); 2656 pos = ExpectRun(map, pos, kWasmF32, 5);
2655 pos = ExpectRun(map, pos, kWasmI32, 1337); 2657 pos = ExpectRun(map, pos, kWasmI32, 1337);
2656 pos = ExpectRun(map, pos, kWasmI64, 212); 2658 pos = ExpectRun(map, pos, kWasmI64, 212);
2657 } 2659 }
2658 2660
2659 class BytecodeIteratorTest : public TestWithZone {}; 2661 class BytecodeIteratorTest : public TestWithZone {};
2660 2662
2661 TEST_F(BytecodeIteratorTest, SimpleForeach) { 2663 TEST_F(BytecodeIteratorTest, SimpleForeach) {
2662 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; 2664 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
2663 BytecodeIterator iter(code, code + sizeof(code)); 2665 BytecodeIterator iter(code, code + sizeof(code));
2664 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, 2666 WasmOpcode expected[] = {kExprI32Const, kExprIf, kExprI32Const,
2665 kExprElse, kExprI8Const, kExprEnd}; 2667 kExprElse, kExprI32Const, kExprEnd};
2666 size_t pos = 0; 2668 size_t pos = 0;
2667 for (WasmOpcode opcode : iter.opcodes()) { 2669 for (WasmOpcode opcode : iter.opcodes()) {
2668 if (pos >= arraysize(expected)) { 2670 if (pos >= arraysize(expected)) {
2669 EXPECT_TRUE(false); 2671 EXPECT_TRUE(false);
2670 break; 2672 break;
2671 } 2673 }
2672 EXPECT_EQ(expected[pos++], opcode); 2674 EXPECT_EQ(expected[pos++], opcode);
2673 } 2675 }
2674 EXPECT_EQ(arraysize(expected), pos); 2676 EXPECT_EQ(arraysize(expected), pos);
2675 } 2677 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2708 2710
2709 count = 0; 2711 count = 0;
2710 for (auto offset : iter.offsets()) { 2712 for (auto offset : iter.offsets()) {
2711 USE(offset); 2713 USE(offset);
2712 count++; 2714 count++;
2713 } 2715 }
2714 EXPECT_EQ(6, count); 2716 EXPECT_EQ(6, count);
2715 } 2717 }
2716 2718
2717 TEST_F(BytecodeIteratorTest, WithLocalDecls) { 2719 TEST_F(BytecodeIteratorTest, WithLocalDecls) {
2718 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; 2720 byte code[] = {1, 1, kLocalI32, WASM_I32V_1(9), WASM_I32V_1(11)};
2719 BodyLocalDecls decls(zone()); 2721 BodyLocalDecls decls(zone());
2720 BytecodeIterator iter(code, code + sizeof(code), &decls); 2722 BytecodeIterator iter(code, code + sizeof(code), &decls);
2721 2723
2722 EXPECT_EQ(3u, decls.encoded_size); 2724 EXPECT_EQ(3u, decls.encoded_size);
2723 EXPECT_EQ(3u, iter.pc_offset()); 2725 EXPECT_EQ(3u, iter.pc_offset());
2724 EXPECT_TRUE(iter.has_next()); 2726 EXPECT_TRUE(iter.has_next());
2725 EXPECT_EQ(kExprI8Const, iter.current()); 2727 EXPECT_EQ(kExprI32Const, iter.current());
2726 iter.next(); 2728 iter.next();
2727 EXPECT_TRUE(iter.has_next()); 2729 EXPECT_TRUE(iter.has_next());
2728 EXPECT_EQ(kExprI8Const, iter.current()); 2730 EXPECT_EQ(kExprI32Const, iter.current());
2729 iter.next(); 2731 iter.next();
2730 EXPECT_FALSE(iter.has_next()); 2732 EXPECT_FALSE(iter.has_next());
2731 } 2733 }
2732 2734
2733 } // namespace wasm 2735 } // namespace wasm
2734 } // namespace internal 2736 } // namespace internal
2735 } // namespace v8 2737 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698