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

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

Issue 2170773003: [wasm] Remove the explicit count from WASM_BLOCK and WASM_LOOP macros. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 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/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 462
463 TEST_F(AstDecoderTest, Block5) { 463 TEST_F(AstDecoderTest, Block5) {
464 EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0))); 464 EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0)));
465 465
466 EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 466 EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
467 467
468 EXPECT_VERIFIES_INLINE( 468 EXPECT_VERIFIES_INLINE(
469 sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 469 sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
470 470
471 EXPECT_VERIFIES_INLINE(sigs.v_i(), 471 EXPECT_VERIFIES_INLINE(sigs.v_i(),
472 WASM_BLOCK(4, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), 472 WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
473 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 473 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
474 474
475 EXPECT_VERIFIES_INLINE( 475 EXPECT_VERIFIES_INLINE(
476 sigs.v_i(), 476 sigs.v_i(),
477 WASM_BLOCK(5, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), 477 WASM_BLOCK(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
478 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); 478 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
479 } 479 }
480 480
481 TEST_F(AstDecoderTest, BlockF32) { 481 TEST_F(AstDecoderTest, BlockF32) {
482 static const byte code[] = {kExprBlock, kExprF32Const, 0, 0, 0, 0, kExprEnd}; 482 static const byte code[] = {kExprBlock, kExprF32Const, 0, 0, 0, 0, kExprEnd};
483 EXPECT_VERIFIES(sigs.f_ff(), code); 483 EXPECT_VERIFIES(sigs.f_ff(), code);
484 EXPECT_FAILURE(sigs.i_i(), code); 484 EXPECT_FAILURE(sigs.i_i(), code);
485 EXPECT_FAILURE(sigs.d_dd(), code); 485 EXPECT_FAILURE(sigs.d_dd(), code);
486 } 486 }
487 487
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), 676 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
677 WASM_SET_LOCAL(0, WASM_I8(1)))); 677 WASM_SET_LOCAL(0, WASM_I8(1))));
678 } 678 }
679 679
680 TEST_F(AstDecoderTest, Loop0) { 680 TEST_F(AstDecoderTest, Loop0) {
681 static const byte code[] = {kExprLoop, kExprEnd}; 681 static const byte code[] = {kExprLoop, kExprEnd};
682 EXPECT_VERIFIES(sigs.v_v(), code); 682 EXPECT_VERIFIES(sigs.v_v(), code);
683 } 683 }
684 684
685 TEST_F(AstDecoderTest, Loop1) { 685 TEST_F(AstDecoderTest, Loop1) {
686 static const byte code[] = {WASM_LOOP(1, WASM_SET_LOCAL(0, WASM_ZERO))}; 686 static const byte code[] = {WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO))};
687 EXPECT_VERIFIES(sigs.v_i(), code); 687 EXPECT_VERIFIES(sigs.v_i(), code);
688 EXPECT_FAILURE(sigs.v_v(), code); 688 EXPECT_FAILURE(sigs.v_v(), code);
689 EXPECT_FAILURE(sigs.f_ff(), code); 689 EXPECT_FAILURE(sigs.f_ff(), code);
690 } 690 }
691 691
692 TEST_F(AstDecoderTest, Loop2) { 692 TEST_F(AstDecoderTest, Loop2) {
693 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), 693 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO),
694 WASM_SET_LOCAL(0, WASM_ZERO))); 694 WASM_SET_LOCAL(0, WASM_ZERO)));
695 } 695 }
696 696
697 TEST_F(AstDecoderTest, Loop1_continue) { 697 TEST_F(AstDecoderTest, Loop1_continue) {
698 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0))); 698 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0)));
699 } 699 }
700 700
701 TEST_F(AstDecoderTest, Loop1_break) { 701 TEST_F(AstDecoderTest, Loop1_break) {
702 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1))); 702 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1)));
703 } 703 }
704 704
705 TEST_F(AstDecoderTest, Loop2_continue) { 705 TEST_F(AstDecoderTest, Loop2_continue) {
706 EXPECT_VERIFIES_INLINE( 706 EXPECT_VERIFIES_INLINE(sigs.v_i(),
707 sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0))); 707 WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0)));
708 } 708 }
709 709
710 TEST_F(AstDecoderTest, Loop2_break) { 710 TEST_F(AstDecoderTest, Loop2_break) {
711 EXPECT_VERIFIES_INLINE( 711 EXPECT_VERIFIES_INLINE(sigs.v_i(),
712 sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1))); 712 WASM_LOOP(WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1)));
713 } 713 }
714 714
715 TEST_F(AstDecoderTest, ExprLoop0) { 715 TEST_F(AstDecoderTest, ExprLoop0) {
716 static const byte code[] = {kExprLoop, kExprEnd}; 716 static const byte code[] = {kExprLoop, kExprEnd};
717 EXPECT_VERIFIES(sigs.v_v(), code); 717 EXPECT_VERIFIES(sigs.v_v(), code);
718 } 718 }
719 719
720 TEST_F(AstDecoderTest, ExprLoop1a) { 720 TEST_F(AstDecoderTest, ExprLoop1a) {
721 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 721 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(0, WASM_ZERO)));
722 } 722 }
723 723
724 TEST_F(AstDecoderTest, ExprLoop1b) { 724 TEST_F(AstDecoderTest, ExprLoop1b) {
725 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 725 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BRV(1, WASM_ZERO)));
726 EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 726 EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BRV(1, WASM_ZERO)));
727 } 727 }
728 728
729 TEST_F(AstDecoderTest, ExprLoop2_unreachable) { 729 TEST_F(AstDecoderTest, ExprLoop2_unreachable) {
730 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(2, WASM_BR(0), WASM_NOP)); 730 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BR(0), WASM_NOP));
731 } 731 }
732 732
733 TEST_F(AstDecoderTest, ReturnVoid1) { 733 TEST_F(AstDecoderTest, ReturnVoid1) {
734 static const byte code[] = {kExprNop}; 734 static const byte code[] = {kExprNop};
735 EXPECT_VERIFIES(sigs.v_v(), code); 735 EXPECT_VERIFIES(sigs.v_v(), code);
736 EXPECT_FAILURE(sigs.i_i(), code); 736 EXPECT_FAILURE(sigs.i_i(), code);
737 EXPECT_FAILURE(sigs.i_f(), code); 737 EXPECT_FAILURE(sigs.i_f(), code);
738 } 738 }
739 739
740 TEST_F(AstDecoderTest, ReturnVoid2) { 740 TEST_F(AstDecoderTest, ReturnVoid2) {
(...skipping 11 matching lines...) Expand all
752 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 752 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
753 753
754 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0); 754 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0);
755 } 755 }
756 756
757 TEST_F(AstDecoderTest, Unreachable1) { 757 TEST_F(AstDecoderTest, Unreachable1) {
758 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable); 758 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable);
759 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable); 759 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable);
760 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_UNREACHABLE, WASM_ZERO)); 760 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_UNREACHABLE, WASM_ZERO));
761 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_ZERO)); 761 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_ZERO));
762 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO)); 762 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_UNREACHABLE, WASM_ZERO));
763 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_BR(0), WASM_ZERO)); 763 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0), WASM_ZERO));
764 } 764 }
765 765
766 TEST_F(AstDecoderTest, Unreachable_binop) { 766 TEST_F(AstDecoderTest, Unreachable_binop) {
767 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE)); 767 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
768 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO)); 768 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
769 } 769 }
770 770
771 TEST_F(AstDecoderTest, Unreachable_select) { 771 TEST_F(AstDecoderTest, Unreachable_select) {
772 EXPECT_VERIFIES_INLINE(sigs.i_i(), 772 EXPECT_VERIFIES_INLINE(sigs.i_i(),
773 WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO)); 773 WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); 907 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64);
908 } 908 }
909 909
910 TEST_F(AstDecoderTest, MacrosStmt) { 910 TEST_F(AstDecoderTest, MacrosStmt) {
911 VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348))); 911 VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
912 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); 912 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
913 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 913 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
914 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 914 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
915 VERIFY(WASM_NOP); 915 VERIFY(WASM_NOP);
916 VERIFY(B1(WASM_NOP)); 916 VERIFY(B1(WASM_NOP));
917 VERIFY(WASM_LOOP(1, WASM_NOP)); 917 VERIFY(WASM_LOOP(WASM_NOP));
918 VERIFY(WASM_LOOP(1, WASM_BREAK(0))); 918 VERIFY(WASM_LOOP(WASM_BREAK(0)));
919 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0))); 919 VERIFY(WASM_LOOP(WASM_CONTINUE(0)));
920 } 920 }
921 921
922 TEST_F(AstDecoderTest, MacrosBreak) { 922 TEST_F(AstDecoderTest, MacrosBreak) {
923 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BREAK(0))); 923 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BREAK(0)));
924 924
925 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO))); 925 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(WASM_BREAKV(0, WASM_ZERO)));
926 EXPECT_VERIFIES_INLINE(sigs.l_l(), 926 EXPECT_VERIFIES_INLINE(sigs.l_l(), WASM_LOOP(WASM_BREAKV(0, WASM_I64V_1(0))));
927 WASM_LOOP(1, WASM_BREAKV(0, WASM_I64V_1(0)))); 927 EXPECT_VERIFIES_INLINE(sigs.f_ff(), WASM_LOOP(WASM_BREAKV(0, WASM_F32(0.0))));
928 EXPECT_VERIFIES_INLINE(sigs.f_ff(), 928 EXPECT_VERIFIES_INLINE(sigs.d_dd(), WASM_LOOP(WASM_BREAKV(0, WASM_F64(0.0))));
929 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
930 EXPECT_VERIFIES_INLINE(sigs.d_dd(),
931 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0))));
932 } 929 }
933 930
934 TEST_F(AstDecoderTest, MacrosContinue) { 931 TEST_F(AstDecoderTest, MacrosContinue) {
935 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_CONTINUE(0))); 932 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_CONTINUE(0)));
936 } 933 }
937 934
938 TEST_F(AstDecoderTest, MacrosVariadic) { 935 TEST_F(AstDecoderTest, MacrosVariadic) {
939 VERIFY(B2(WASM_NOP, WASM_NOP)); 936 VERIFY(B2(WASM_NOP, WASM_NOP));
940 VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP)); 937 VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP));
941 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP)); 938 VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP));
942 VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP)); 939 VERIFY(WASM_LOOP(WASM_NOP, WASM_NOP, WASM_NOP));
943 } 940 }
944 941
945 TEST_F(AstDecoderTest, MacrosNestedBlocks) { 942 TEST_F(AstDecoderTest, MacrosNestedBlocks) {
946 VERIFY(B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); 943 VERIFY(B2(WASM_NOP, B2(WASM_NOP, WASM_NOP)));
947 VERIFY(B3(WASM_NOP, // -- 944 VERIFY(B3(WASM_NOP, // --
948 B2(WASM_NOP, WASM_NOP), // -- 945 B2(WASM_NOP, WASM_NOP), // --
949 B2(WASM_NOP, WASM_NOP))); // -- 946 B2(WASM_NOP, WASM_NOP))); // --
950 VERIFY(B1(B1(B2(WASM_NOP, WASM_NOP)))); 947 VERIFY(B1(B1(B2(WASM_NOP, WASM_NOP))));
951 } 948 }
952 949
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 1463
1467 TEST_F(AstDecoderTest, BreakEnd) { 1464 TEST_F(AstDecoderTest, BreakEnd) {
1468 EXPECT_VERIFIES_INLINE(sigs.i_i(), 1465 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1469 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); 1466 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO)));
1470 EXPECT_VERIFIES_INLINE(sigs.i_i(), 1467 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1471 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); 1468 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO))));
1472 } 1469 }
1473 1470
1474 TEST_F(AstDecoderTest, BreakIfBinop) { 1471 TEST_F(AstDecoderTest, BreakIfBinop) {
1475 EXPECT_FAILURE_INLINE( 1472 EXPECT_FAILURE_INLINE(
1476 sigs.i_i(), 1473 sigs.i_i(), WASM_BLOCK(WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO),
1477 WASM_BLOCK( 1474 WASM_ZERO)));
1478 1, WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO))); 1475 EXPECT_FAILURE_INLINE(sigs.i_i(),
1479 EXPECT_FAILURE_INLINE( 1476 WASM_BLOCK(WASM_I32_ADD(
1480 sigs.i_i(), 1477 WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))));
1481 WASM_BLOCK(
1482 1, WASM_I32_ADD(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))));
1483 } 1478 }
1484 1479
1485 TEST_F(AstDecoderTest, BreakNesting1) { 1480 TEST_F(AstDecoderTest, BreakNesting1) {
1486 for (int i = 0; i < 5; i++) { 1481 for (int i = 0; i < 5; i++) {
1487 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) 1482 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
1488 byte code[] = {WASM_BLOCK( 1483 byte code[] = {WASM_BLOCK(
1489 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)), 1484 WASM_LOOP(WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)),
1490 WASM_SET_LOCAL(0, WASM_I8(1))), 1485 WASM_SET_LOCAL(0, WASM_I8(1))),
1491 WASM_GET_LOCAL(0))}; 1486 WASM_GET_LOCAL(0))};
1492 if (i < 3) { 1487 if (i < 3) {
1493 EXPECT_VERIFIES(sigs.i_i(), code); 1488 EXPECT_VERIFIES(sigs.i_i(), code);
1494 } else { 1489 } else {
1495 EXPECT_FAILURE(sigs.i_i(), code); 1490 EXPECT_FAILURE(sigs.i_i(), code);
1496 } 1491 }
1497 } 1492 }
1498 } 1493 }
1499 1494
1500 TEST_F(AstDecoderTest, BreakNesting2) { 1495 TEST_F(AstDecoderTest, BreakNesting2) {
1501 AddLocals(kAstI32, 1); 1496 AddLocals(kAstI32, 1);
1502 for (int i = 0; i < 5; i++) { 1497 for (int i = 0; i < 5; i++) {
1503 // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11) 1498 // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11)
1504 byte code[] = {B1(WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)), 1499 byte code[] = {B1(WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)),
1505 WASM_SET_LOCAL(0, WASM_I8(1)))), 1500 WASM_SET_LOCAL(0, WASM_I8(1)))),
1506 WASM_I8(11)}; 1501 WASM_I8(11)};
1507 if (i < 2) { 1502 if (i < 2) {
1508 EXPECT_VERIFIES(sigs.v_v(), code); 1503 EXPECT_VERIFIES(sigs.v_v(), code);
1509 } else { 1504 } else {
1510 EXPECT_FAILURE(sigs.v_v(), code); 1505 EXPECT_FAILURE(sigs.v_v(), code);
1511 } 1506 }
1512 } 1507 }
1513 } 1508 }
1514 1509
1515 TEST_F(AstDecoderTest, BreakNesting3) { 1510 TEST_F(AstDecoderTest, BreakNesting3) {
1516 for (int i = 0; i < 5; i++) { 1511 for (int i = 0; i < 5; i++) {
1517 // (block[1] (loop[1] (block[1] (if 0 break[N]) 1512 // (block[1] (loop[1] (block[1] (if 0 break[N])
1518 byte code[] = { 1513 byte code[] = {
1519 WASM_BLOCK(1, WASM_LOOP(1, B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))}; 1514 WASM_BLOCK(WASM_LOOP(B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))};
1520 if (i < 3) { 1515 if (i < 3) {
1521 EXPECT_VERIFIES(sigs.v_v(), code); 1516 EXPECT_VERIFIES(sigs.v_v(), code);
1522 } else { 1517 } else {
1523 EXPECT_FAILURE(sigs.v_v(), code); 1518 EXPECT_FAILURE(sigs.v_v(), code);
1524 } 1519 }
1525 } 1520 }
1526 } 1521 }
1527 1522
1528 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { 1523 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) {
1529 EXPECT_FAILURE_INLINE(sigs.i_i(), 1524 EXPECT_FAILURE_INLINE(sigs.i_i(),
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 sigs.i_i(), 1585 sigs.i_i(),
1591 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); 1586 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2)));
1592 1587
1593 // unify f64 and f64 => OK 1588 // unify f64 and f64 => OK
1594 EXPECT_VERIFIES_INLINE( 1589 EXPECT_VERIFIES_INLINE(
1595 sigs.d_dd(), 1590 sigs.d_dd(),
1596 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2))); 1591 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2)));
1597 } 1592 }
1598 1593
1599 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) { 1594 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) {
1600 byte code1[] = {WASM_BLOCK(2, 1595 byte code1[] = {WASM_BLOCK(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1601 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1602 WASM_GET_LOCAL(1))}; 1596 WASM_GET_LOCAL(1))};
1603 byte code2[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), 1597 byte code2[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))),
1604 WASM_GET_LOCAL(1))}; 1598 WASM_GET_LOCAL(1))};
1605 1599
1606 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1600 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1607 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1601 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1608 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; 1602 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]};
1609 FunctionSig sig(1, 2, storage); 1603 FunctionSig sig(1, 2, storage);
1610 1604
1611 if (i == j) { 1605 if (i == j) {
(...skipping 10 matching lines...) Expand all
1622 TEST_F(AstDecoderTest, ExprBr_Unify) { 1616 TEST_F(AstDecoderTest, ExprBr_Unify) {
1623 for (int which = 0; which < 2; which++) { 1617 for (int which = 0; which < 2; which++) {
1624 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1618 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1625 LocalType type = kLocalTypes[i]; 1619 LocalType type = kLocalTypes[i];
1626 LocalType storage[] = {kAstI32, kAstI32, type}; 1620 LocalType storage[] = {kAstI32, kAstI32, type};
1627 FunctionSig sig(1, 2, storage); 1621 FunctionSig sig(1, 2, storage);
1628 1622
1629 byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), 1623 byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))),
1630 WASM_GET_LOCAL(which ^ 1))}; 1624 WASM_GET_LOCAL(which ^ 1))};
1631 byte code2[] = { 1625 byte code2[] = {
1632 WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))), 1626 WASM_LOOP(WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))),
1633 WASM_GET_LOCAL(which ^ 1))}; 1627 WASM_GET_LOCAL(which ^ 1))};
1634 1628
1635 if (type == kAstI32) { 1629 if (type == kAstI32) {
1636 EXPECT_VERIFIES(&sig, code1); 1630 EXPECT_VERIFIES(&sig, code1);
1637 EXPECT_VERIFIES(&sig, code2); 1631 EXPECT_VERIFIES(&sig, code2);
1638 } else { 1632 } else {
1639 EXPECT_FAILURE(&sig, code1); 1633 EXPECT_FAILURE(&sig, code1);
1640 EXPECT_FAILURE(&sig, code2); 1634 EXPECT_FAILURE(&sig, code2);
1641 } 1635 }
1642 } 1636 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 1673
1680 TEST_F(AstDecoderTest, ExprBrIf_Unify) { 1674 TEST_F(AstDecoderTest, ExprBrIf_Unify) {
1681 for (int which = 0; which < 2; which++) { 1675 for (int which = 0; which < 2; which++) {
1682 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1676 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1683 LocalType type = kLocalTypes[i]; 1677 LocalType type = kLocalTypes[i];
1684 LocalType storage[] = {kAstI32, kAstI32, type}; 1678 LocalType storage[] = {kAstI32, kAstI32, type};
1685 FunctionSig sig(1, 2, storage); 1679 FunctionSig sig(1, 2, storage);
1686 1680
1687 byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), 1681 byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
1688 WASM_GET_LOCAL(which ^ 1))}; 1682 WASM_GET_LOCAL(which ^ 1))};
1689 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), 1683 byte code2[] = {WASM_LOOP(WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)),
1690 WASM_GET_LOCAL(which ^ 1))}; 1684 WASM_GET_LOCAL(which ^ 1))};
1691 1685
1692 if (type == kAstI32) { 1686 if (type == kAstI32) {
1693 EXPECT_VERIFIES(&sig, code1); 1687 EXPECT_VERIFIES(&sig, code1);
1694 EXPECT_VERIFIES(&sig, code2); 1688 EXPECT_VERIFIES(&sig, code2);
1695 } else { 1689 } else {
1696 EXPECT_FAILURE(&sig, code1); 1690 EXPECT_FAILURE(&sig, code1);
1697 EXPECT_FAILURE(&sig, code2); 1691 EXPECT_FAILURE(&sig, code2);
1698 } 1692 }
1699 } 1693 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1731 } 1725 }
1732 1726
1733 TEST_F(AstDecoderTest, BrTable2a) { 1727 TEST_F(AstDecoderTest, BrTable2a) {
1734 static byte code[] = { 1728 static byte code[] = {
1735 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; 1729 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))};
1736 EXPECT_VERIFIES(sigs.v_v(), code); 1730 EXPECT_VERIFIES(sigs.v_v(), code);
1737 } 1731 }
1738 1732
1739 TEST_F(AstDecoderTest, BrTable2b) { 1733 TEST_F(AstDecoderTest, BrTable2b) {
1740 static byte code[] = {WASM_BLOCK( 1734 static byte code[] = {WASM_BLOCK(
1741 1, WASM_BLOCK( 1735 WASM_BLOCK(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
1742 1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
1743 EXPECT_VERIFIES(sigs.v_v(), code); 1736 EXPECT_VERIFIES(sigs.v_v(), code);
1744 } 1737 }
1745 1738
1746 TEST_F(AstDecoderTest, BrTable_off_end) { 1739 TEST_F(AstDecoderTest, BrTable_off_end) {
1747 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))}; 1740 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
1748 for (size_t len = 1; len < sizeof(code); len++) { 1741 for (size_t len = 1; len < sizeof(code); len++) {
1749 Verify(kError, sigs.i_i(), code, code + len); 1742 Verify(kError, sigs.i_i(), code, code + len);
1750 } 1743 }
1751 } 1744 }
1752 1745
1753 TEST_F(AstDecoderTest, BrTable_invalid_br1) { 1746 TEST_F(AstDecoderTest, BrTable_invalid_br1) {
1754 for (int depth = 0; depth < 4; depth++) { 1747 for (int depth = 0; depth < 4; depth++) {
1755 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; 1748 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1756 if (depth == 0) { 1749 if (depth == 0) {
1757 EXPECT_VERIFIES(sigs.v_i(), code); 1750 EXPECT_VERIFIES(sigs.v_i(), code);
1758 } else { 1751 } else {
1759 EXPECT_FAILURE(sigs.v_i(), code); 1752 EXPECT_FAILURE(sigs.v_i(), code);
1760 } 1753 }
1761 } 1754 }
1762 } 1755 }
1763 1756
1764 TEST_F(AstDecoderTest, BrTable_invalid_br2) { 1757 TEST_F(AstDecoderTest, BrTable_invalid_br2) {
1765 for (int depth = 0; depth < 4; depth++) { 1758 for (int depth = 0; depth < 4; depth++) {
1766 byte code[] = { 1759 byte code[] = {
1767 WASM_LOOP(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; 1760 WASM_LOOP(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1768 if (depth <= 1) { 1761 if (depth <= 1) {
1769 EXPECT_VERIFIES(sigs.v_i(), code); 1762 EXPECT_VERIFIES(sigs.v_i(), code);
1770 } else { 1763 } else {
1771 EXPECT_FAILURE(sigs.v_i(), code); 1764 EXPECT_FAILURE(sigs.v_i(), code);
1772 } 1765 }
1773 } 1766 }
1774 } 1767 }
1775 1768
1776 TEST_F(AstDecoderTest, ExprBreakNesting1) { 1769 TEST_F(AstDecoderTest, ExprBreakNesting1) {
1777 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV(0, WASM_ZERO))); 1770 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV(0, WASM_ZERO)));
1778 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0))); 1771 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0)));
1779 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1772 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1780 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR_IF(0, WASM_ZERO))); 1773 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR_IF(0, WASM_ZERO)));
1781 1774
1782 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 1775 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(0, WASM_ZERO)));
1783 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0))); 1776 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(0)));
1784 EXPECT_VERIFIES_INLINE(sigs.v_v(), 1777 EXPECT_VERIFIES_INLINE(sigs.v_v(),
1785 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1778 WASM_LOOP(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1786 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO))); 1779 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR_IF(0, WASM_ZERO)));
1787 1780
1788 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 1781 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BRV(1, WASM_ZERO)));
1789 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1))); 1782 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(WASM_BR(1)));
1790 } 1783 }
1791 1784
1792 TEST_F(AstDecoderTest, Select) { 1785 TEST_F(AstDecoderTest, Select) {
1793 EXPECT_VERIFIES_INLINE( 1786 EXPECT_VERIFIES_INLINE(
1794 sigs.i_i(), WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO)); 1787 sigs.i_i(), WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_ZERO));
1795 EXPECT_VERIFIES_INLINE(sigs.f_ff(), 1788 EXPECT_VERIFIES_INLINE(sigs.f_ff(),
1796 WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO)); 1789 WASM_SELECT(WASM_F32(0.0), WASM_F32(0.0), WASM_ZERO));
1797 EXPECT_VERIFIES_INLINE(sigs.d_dd(), 1790 EXPECT_VERIFIES_INLINE(sigs.d_dd(),
1798 WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO)); 1791 WASM_SELECT(WASM_F64(0.0), WASM_F64(0.0), WASM_ZERO));
1799 EXPECT_VERIFIES_INLINE( 1792 EXPECT_VERIFIES_INLINE(
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 iter.next(); 2480 iter.next();
2488 EXPECT_TRUE(iter.has_next()); 2481 EXPECT_TRUE(iter.has_next());
2489 EXPECT_EQ(kExprI8Const, iter.current()); 2482 EXPECT_EQ(kExprI8Const, iter.current());
2490 iter.next(); 2483 iter.next();
2491 EXPECT_FALSE(iter.has_next()); 2484 EXPECT_FALSE(iter.has_next());
2492 } 2485 }
2493 2486
2494 } // namespace wasm 2487 } // namespace wasm
2495 } // namespace internal 2488 } // namespace internal
2496 } // namespace v8 2489 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm-module.cc ('k') | test/unittests/wasm/loop-assignment-analysis-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698