OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
6 | 6 |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
10 | 10 |
(...skipping 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 EXPECT_FAILURE_INLINE( | 1906 EXPECT_FAILURE_INLINE( |
1907 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0))); | 1907 &env_i_i, WASM_SELECT(WASM_F32(9.9), WASM_GET_LOCAL(0), WASM_I64(0))); |
1908 } | 1908 } |
1909 | 1909 |
1910 | 1910 |
1911 class WasmOpcodeLengthTest : public TestWithZone { | 1911 class WasmOpcodeLengthTest : public TestWithZone { |
1912 public: | 1912 public: |
1913 WasmOpcodeLengthTest() : TestWithZone() {} | 1913 WasmOpcodeLengthTest() : TestWithZone() {} |
1914 }; | 1914 }; |
1915 | 1915 |
1916 | 1916 #define EXPECT_LENGTH(expected, opcode) \ |
1917 #define EXPECT_LENGTH(expected, opcode) \ | 1917 { \ |
1918 { \ | 1918 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ |
1919 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ | 1919 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ |
1920 EXPECT_EQ(expected, OpcodeLength(code)); \ | |
1921 } | 1920 } |
1922 | 1921 |
1923 | |
1924 TEST_F(WasmOpcodeLengthTest, Statements) { | 1922 TEST_F(WasmOpcodeLengthTest, Statements) { |
1925 EXPECT_LENGTH(1, kExprNop); | 1923 EXPECT_LENGTH(1, kExprNop); |
1926 EXPECT_LENGTH(2, kExprBlock); | 1924 EXPECT_LENGTH(2, kExprBlock); |
1927 EXPECT_LENGTH(2, kExprLoop); | 1925 EXPECT_LENGTH(2, kExprLoop); |
1928 EXPECT_LENGTH(1, kExprIf); | 1926 EXPECT_LENGTH(1, kExprIf); |
1929 EXPECT_LENGTH(1, kExprIfElse); | 1927 EXPECT_LENGTH(1, kExprIfElse); |
1930 EXPECT_LENGTH(1, kExprSelect); | 1928 EXPECT_LENGTH(1, kExprSelect); |
1931 EXPECT_LENGTH(2, kExprBr); | 1929 EXPECT_LENGTH(2, kExprBr); |
1932 EXPECT_LENGTH(2, kExprBrIf); | 1930 EXPECT_LENGTH(2, kExprBrIf); |
1933 } | 1931 } |
(...skipping 20 matching lines...) Expand all Loading... |
1954 } | 1952 } |
1955 | 1953 |
1956 | 1954 |
1957 TEST_F(WasmOpcodeLengthTest, VariableLength) { | 1955 TEST_F(WasmOpcodeLengthTest, VariableLength) { |
1958 byte size2[] = {kExprLoadGlobal, 1}; | 1956 byte size2[] = {kExprLoadGlobal, 1}; |
1959 byte size3[] = {kExprLoadGlobal, 1 | 0x80, 2}; | 1957 byte size3[] = {kExprLoadGlobal, 1 | 0x80, 2}; |
1960 byte size4[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3}; | 1958 byte size4[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3}; |
1961 byte size5[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4}; | 1959 byte size5[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4}; |
1962 byte size6[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4 | 0x80, 5}; | 1960 byte size6[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4 | 0x80, 5}; |
1963 | 1961 |
1964 EXPECT_EQ(2, OpcodeLength(size2)); | 1962 EXPECT_EQ(2, OpcodeLength(size2, size2 + sizeof(size2))); |
1965 EXPECT_EQ(3, OpcodeLength(size3)); | 1963 EXPECT_EQ(3, OpcodeLength(size3, size3 + sizeof(size3))); |
1966 EXPECT_EQ(4, OpcodeLength(size4)); | 1964 EXPECT_EQ(4, OpcodeLength(size4, size4 + sizeof(size4))); |
1967 EXPECT_EQ(5, OpcodeLength(size5)); | 1965 EXPECT_EQ(5, OpcodeLength(size5, size5 + sizeof(size5))); |
1968 EXPECT_EQ(6, OpcodeLength(size6)); | 1966 EXPECT_EQ(6, OpcodeLength(size6, size6 + sizeof(size6))); |
1969 } | 1967 } |
1970 | 1968 |
1971 | 1969 |
1972 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { | 1970 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { |
1973 EXPECT_LENGTH(2, kExprI32LoadMem8S); | 1971 EXPECT_LENGTH(2, kExprI32LoadMem8S); |
1974 EXPECT_LENGTH(2, kExprI32LoadMem8U); | 1972 EXPECT_LENGTH(2, kExprI32LoadMem8U); |
1975 EXPECT_LENGTH(2, kExprI32LoadMem16S); | 1973 EXPECT_LENGTH(2, kExprI32LoadMem16S); |
1976 EXPECT_LENGTH(2, kExprI32LoadMem16U); | 1974 EXPECT_LENGTH(2, kExprI32LoadMem16U); |
1977 EXPECT_LENGTH(2, kExprI32LoadMem); | 1975 EXPECT_LENGTH(2, kExprI32LoadMem); |
1978 EXPECT_LENGTH(2, kExprI64LoadMem8S); | 1976 EXPECT_LENGTH(2, kExprI64LoadMem8S); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 EXPECT_LENGTH(1, kExprI32ReinterpretF32); | 2121 EXPECT_LENGTH(1, kExprI32ReinterpretF32); |
2124 EXPECT_LENGTH(1, kExprI64ReinterpretF64); | 2122 EXPECT_LENGTH(1, kExprI64ReinterpretF64); |
2125 } | 2123 } |
2126 | 2124 |
2127 | 2125 |
2128 class WasmOpcodeArityTest : public TestWithZone { | 2126 class WasmOpcodeArityTest : public TestWithZone { |
2129 public: | 2127 public: |
2130 WasmOpcodeArityTest() : TestWithZone() {} | 2128 WasmOpcodeArityTest() : TestWithZone() {} |
2131 }; | 2129 }; |
2132 | 2130 |
2133 | 2131 #define EXPECT_ARITY(expected, ...) \ |
2134 #define EXPECT_ARITY(expected, ...) \ | 2132 { \ |
2135 { \ | 2133 static const byte code[] = {__VA_ARGS__}; \ |
2136 static const byte code[] = {__VA_ARGS__}; \ | 2134 EXPECT_EQ(expected, OpcodeArity(&env, code, code + sizeof(code))); \ |
2137 EXPECT_EQ(expected, OpcodeArity(&env, code)); \ | |
2138 } | 2135 } |
2139 | 2136 |
2140 | |
2141 TEST_F(WasmOpcodeArityTest, Control) { | 2137 TEST_F(WasmOpcodeArityTest, Control) { |
2142 FunctionEnv env; | 2138 FunctionEnv env; |
2143 EXPECT_ARITY(0, kExprNop); | 2139 EXPECT_ARITY(0, kExprNop); |
2144 | 2140 |
2145 EXPECT_ARITY(0, kExprBlock, 0); | 2141 EXPECT_ARITY(0, kExprBlock, 0); |
2146 EXPECT_ARITY(1, kExprBlock, 1); | 2142 EXPECT_ARITY(1, kExprBlock, 1); |
2147 EXPECT_ARITY(2, kExprBlock, 2); | 2143 EXPECT_ARITY(2, kExprBlock, 2); |
2148 EXPECT_ARITY(5, kExprBlock, 5); | 2144 EXPECT_ARITY(5, kExprBlock, 5); |
2149 EXPECT_ARITY(10, kExprBlock, 10); | 2145 EXPECT_ARITY(10, kExprBlock, 10); |
2150 | 2146 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 EXPECT_ARITY(1, kExprF64SConvertI64); | 2373 EXPECT_ARITY(1, kExprF64SConvertI64); |
2378 EXPECT_ARITY(1, kExprF64UConvertI64); | 2374 EXPECT_ARITY(1, kExprF64UConvertI64); |
2379 EXPECT_ARITY(1, kExprF64ConvertF32); | 2375 EXPECT_ARITY(1, kExprF64ConvertF32); |
2380 EXPECT_ARITY(1, kExprF64ReinterpretI64); | 2376 EXPECT_ARITY(1, kExprF64ReinterpretI64); |
2381 EXPECT_ARITY(1, kExprI32ReinterpretF32); | 2377 EXPECT_ARITY(1, kExprI32ReinterpretF32); |
2382 EXPECT_ARITY(1, kExprI64ReinterpretF64); | 2378 EXPECT_ARITY(1, kExprI64ReinterpretF64); |
2383 } | 2379 } |
2384 } // namespace wasm | 2380 } // namespace wasm |
2385 } // namespace internal | 2381 } // namespace internal |
2386 } // namespace v8 | 2382 } // namespace v8 |
OLD | NEW |