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

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

Issue 1764723002: [wasm] Remove TableSwitch and replace with br_table. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 EXPECT_VERIFIES(&env, code1); 1664 EXPECT_VERIFIES(&env, code1);
1665 EXPECT_VERIFIES(&env, code2); 1665 EXPECT_VERIFIES(&env, code2);
1666 } else { 1666 } else {
1667 EXPECT_FAILURE(&env, code1); 1667 EXPECT_FAILURE(&env, code1);
1668 EXPECT_FAILURE(&env, code2); 1668 EXPECT_FAILURE(&env, code2);
1669 } 1669 }
1670 } 1670 }
1671 } 1671 }
1672 } 1672 }
1673 1673
1674 TEST_F(AstDecoderTest, TableSwitch0) { 1674 TEST_F(AstDecoderTest, BrTable0) {
1675 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0}; 1675 static byte code[] = {kExprBrTable, 0, 0};
1676 EXPECT_FAILURE(&env_v_v, code); 1676 EXPECT_FAILURE(&env_v_v, code);
1677 } 1677 }
1678 1678
1679 TEST_F(AstDecoderTest, TableSwitch0b) { 1679 TEST_F(AstDecoderTest, BrTable0b) {
1680 static byte code[] = {kExprTableSwitch, 0, 0, 0, 0, kExprI8Const, 11}; 1680 static byte code[] = {kExprBrTable, 0, 0, kExprI8Const, 11};
1681 EXPECT_FAILURE(&env_v_v, code); 1681 EXPECT_FAILURE(&env_v_v, code);
1682 EXPECT_FAILURE(&env_i_i, code); 1682 EXPECT_FAILURE(&env_i_i, code);
1683 } 1683 }
1684 1684
1685 TEST_F(AstDecoderTest, TableSwitch0c) { 1685 TEST_F(AstDecoderTest, BrTable0c) {
1686 static byte code[] = {kExprBrTable, 0, 1, 0, 0, kExprI8Const, 11};
1687 EXPECT_FAILURE(&env_v_v, code);
1688 EXPECT_FAILURE(&env_i_i, code);
1689 }
1690
1691 TEST_F(AstDecoderTest, BrTable1a) {
1686 static byte code[] = { 1692 static byte code[] = {
1687 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(0)), WASM_I8(67))}; 1693 WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))};
1688 EXPECT_VERIFIES(&env_v_v, code); 1694 EXPECT_VERIFIES(&env_v_v, code);
1689 } 1695 }
1690 1696
1691 TEST_F(AstDecoderTest, TableSwitch0d) { 1697 TEST_F(AstDecoderTest, BrTable1b) {
1692 static byte code[] = { 1698 static byte code[] = {
1693 WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(0), WASM_CASE_BR(1)), 1699 WASM_BLOCK(1, WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
1694 WASM_I8(67))};
1695 EXPECT_VERIFIES(&env_v_v, code); 1700 EXPECT_VERIFIES(&env_v_v, code);
1696 } 1701 EXPECT_FAILURE(&env_i_i, code);
1697
1698 TEST_F(AstDecoderTest, TableSwitch1) {
1699 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1700 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))};
1701 EXPECT_VERIFIES(&env_i_i, code);
1702 EXPECT_VERIFIES(&env_v_v, code);
1703 EXPECT_FAILURE(&env_f_ff, code); 1702 EXPECT_FAILURE(&env_f_ff, code);
1704 EXPECT_FAILURE(&env_d_dd, code); 1703 EXPECT_FAILURE(&env_d_dd, code);
1705 } 1704 }
1706 1705
1707 TEST_F(AstDecoderTest, TableSwitch_off_end) { 1706 TEST_F(AstDecoderTest, BrTable2a) {
1708 static byte code[] = {WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)), 1707 static byte code[] = {
1709 WASM_TABLESWITCH_BODY(WASM_I8(0), WASM_I8(9))}; 1708 WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))};
1710 for (size_t len = arraysize(code) - 1; len > 0; len--) { 1709 EXPECT_VERIFIES(&env_v_v, code);
1711 Verify(kError, &env_v_v, code, code + len); 1710 }
1711
1712 TEST_F(AstDecoderTest, BrTable2b) {
1713 static byte code[] = {WASM_BLOCK(
1714 1, WASM_BLOCK(
1715 1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
1716 EXPECT_VERIFIES(&env_v_v, code);
1717 }
1718
1719 TEST_F(AstDecoderTest, BrTable_off_end) {
1720 static byte code[] = {
1721 WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
1722 for (size_t len = 1; len < sizeof(code); len++) {
1723 Verify(kError, &env_i_i, code, code + len);
1712 } 1724 }
1713 } 1725 }
1714 1726
1715 TEST_F(AstDecoderTest, TableSwitch2) { 1727 TEST_F(AstDecoderTest, BrTable_invalid_br1) {
1716 static byte code[] = { 1728 for (int depth = 0; depth < 4; depth++) {
1717 WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)), 1729 byte code[] = {
1718 WASM_TABLESWITCH_BODY(WASM_I8(3), WASM_I8(10), WASM_I8(11))}; 1730 WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1719 EXPECT_VERIFIES(&env_i_i, code); 1731 if (depth == 0) {
1720 EXPECT_VERIFIES(&env_v_v, code); 1732 EXPECT_VERIFIES(&env_v_i, code);
1721 EXPECT_FAILURE(&env_f_ff, code); 1733 } else {
1722 EXPECT_FAILURE(&env_d_dd, code); 1734 EXPECT_FAILURE(&env_v_i, code);
1723 } 1735 }
1724
1725 TEST_F(AstDecoderTest, TableSwitch1b) {
1726 EXPECT_VERIFIES_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1727 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1728
1729 EXPECT_VERIFIES_INLINE(&env_f_ff, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1730 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F32(0.0)));
1731
1732 EXPECT_VERIFIES_INLINE(&env_d_dd, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1733 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_F64(0.0)));
1734 }
1735
1736 TEST_F(AstDecoderTest, TableSwitch_br1) {
1737 for (int depth = 0; depth < 2; depth++) {
1738 byte code[] = {WASM_BLOCK(1, WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)),
1739 WASM_GET_LOCAL(0))};
1740 EXPECT_VERIFIES(&env_v_i, code);
1741 EXPECT_FAILURE(&env_i_i, code);
1742 } 1736 }
1743 } 1737 }
1744 1738
1745 TEST_F(AstDecoderTest, TableSwitch_invalid_br) { 1739 TEST_F(AstDecoderTest, BrTable_invalid_br2) {
1746 for (int depth = 1; depth < 4; depth++) { 1740 for (int depth = 0; depth < 4; depth++) {
1747 EXPECT_FAILURE_INLINE(&env_v_i, 1741 byte code[] = {
1748 WASM_TABLESWITCH_OP(0, 1, WASM_CASE_BR(depth)), 1742 WASM_LOOP(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1749 WASM_GET_LOCAL(0)); 1743 if (depth <= 1) {
1750 EXPECT_FAILURE_INLINE( 1744 EXPECT_VERIFIES(&env_v_i, code);
1751 &env_v_i, 1745 } else {
1752 WASM_TABLESWITCH_OP(0, 2, WASM_CASE_BR(depth), WASM_CASE_BR(depth)), 1746 EXPECT_FAILURE(&env_v_i, code);
1753 WASM_GET_LOCAL(0)); 1747 }
1754 } 1748 }
1755 } 1749 }
1756 1750
1757 TEST_F(AstDecoderTest, TableSwitch_invalid_case_ref) {
1758 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(0, 1, WASM_CASE(0)),
1759 WASM_GET_LOCAL(0));
1760 EXPECT_FAILURE_INLINE(&env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(1)),
1761 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_ZERO));
1762 }
1763
1764 TEST_F(AstDecoderTest, TableSwitch1_br) {
1765 EXPECT_VERIFIES_INLINE(
1766 &env_i_i, WASM_TABLESWITCH_OP(1, 1, WASM_CASE(0)),
1767 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_ZERO)));
1768 }
1769
1770 TEST_F(AstDecoderTest, TableSwitch2_br) {
1771 EXPECT_VERIFIES_INLINE(
1772 &env_i_i, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1773 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(0)),
1774 WASM_BRV(0, WASM_I8(1))));
1775
1776 EXPECT_FAILURE_INLINE(
1777 &env_f_ff, WASM_TABLESWITCH_OP(2, 2, WASM_CASE(0), WASM_CASE(1)),
1778 WASM_TABLESWITCH_BODY(WASM_ZERO, WASM_BRV(0, WASM_I8(3)),
1779 WASM_BRV(0, WASM_I8(4))));
1780 }
1781
1782 TEST_F(AstDecoderTest, TableSwitch2x2) {
1783 EXPECT_VERIFIES_INLINE(
1784 &env_i_i, WASM_TABLESWITCH_OP(2, 4, WASM_CASE(0), WASM_CASE(1),
1785 WASM_CASE(0), WASM_CASE(1)),
1786 WASM_TABLESWITCH_BODY(WASM_GET_LOCAL(0), WASM_BRV(0, WASM_I8(3)),
1787 WASM_BRV(0, WASM_I8(4))));
1788 }
1789
1790 TEST_F(AstDecoderTest, ExprBreakNesting1) { 1751 TEST_F(AstDecoderTest, ExprBreakNesting1) {
1791 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO))); 1752 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO)));
1792 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0))); 1753 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR(0)));
1793 EXPECT_VERIFIES_INLINE(&env_v_v, 1754 EXPECT_VERIFIES_INLINE(&env_v_v,
1794 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1755 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1795 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO))); 1756 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
1796 1757
1797 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 1758 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
1798 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0))); 1759 EXPECT_VERIFIES_INLINE(&env_v_v, WASM_LOOP(1, WASM_BR(0)));
1799 EXPECT_VERIFIES_INLINE(&env_v_v, 1760 EXPECT_VERIFIES_INLINE(&env_v_v,
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 EXPECT_ARITY(1, kExprF64SConvertI64); 2297 EXPECT_ARITY(1, kExprF64SConvertI64);
2337 EXPECT_ARITY(1, kExprF64UConvertI64); 2298 EXPECT_ARITY(1, kExprF64UConvertI64);
2338 EXPECT_ARITY(1, kExprF64ConvertF32); 2299 EXPECT_ARITY(1, kExprF64ConvertF32);
2339 EXPECT_ARITY(1, kExprF64ReinterpretI64); 2300 EXPECT_ARITY(1, kExprF64ReinterpretI64);
2340 EXPECT_ARITY(1, kExprI32ReinterpretF32); 2301 EXPECT_ARITY(1, kExprI32ReinterpretF32);
2341 EXPECT_ARITY(1, kExprI64ReinterpretF64); 2302 EXPECT_ARITY(1, kExprI64ReinterpretF64);
2342 } 2303 }
2343 } // namespace wasm 2304 } // namespace wasm
2344 } // namespace internal 2305 } // namespace internal
2345 } // namespace v8 2306 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-run-wasm.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698