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 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2042 EXPECT_LENGTH(1, kExprF64ConvertF32); | 2042 EXPECT_LENGTH(1, kExprF64ConvertF32); |
2043 EXPECT_LENGTH(1, kExprF64ReinterpretI64); | 2043 EXPECT_LENGTH(1, kExprF64ReinterpretI64); |
2044 EXPECT_LENGTH(1, kExprI32ReinterpretF32); | 2044 EXPECT_LENGTH(1, kExprI32ReinterpretF32); |
2045 EXPECT_LENGTH(1, kExprI64ReinterpretF64); | 2045 EXPECT_LENGTH(1, kExprI64ReinterpretF64); |
2046 } | 2046 } |
2047 | 2047 |
2048 | 2048 |
2049 class WasmOpcodeArityTest : public TestWithZone { | 2049 class WasmOpcodeArityTest : public TestWithZone { |
2050 public: | 2050 public: |
2051 WasmOpcodeArityTest() : TestWithZone() {} | 2051 WasmOpcodeArityTest() : TestWithZone() {} |
2052 TestModuleEnv module; | |
2053 TestSignatures sigs; | |
2054 }; | 2052 }; |
2055 | 2053 |
2056 #define EXPECT_ARITY(expected, ...) \ | 2054 #define EXPECT_ARITY(expected, ...) \ |
2057 { \ | 2055 { \ |
2058 static const byte code[] = {__VA_ARGS__}; \ | 2056 static const byte code[] = {__VA_ARGS__}; \ |
2059 EXPECT_EQ(expected, OpcodeArity(&module, sig, code, code + sizeof(code))); \ | 2057 EXPECT_EQ(expected, OpcodeArity(code, code + sizeof(code))); \ |
2060 } | 2058 } |
2061 | 2059 |
2062 TEST_F(WasmOpcodeArityTest, Control) { | 2060 TEST_F(WasmOpcodeArityTest, Control) { |
2063 FunctionSig* sig = sigs.v_v(); | |
2064 EXPECT_ARITY(0, kExprNop); | 2061 EXPECT_ARITY(0, kExprNop); |
2065 | 2062 |
2066 EXPECT_ARITY(0, kExprBlock, 0); | 2063 EXPECT_ARITY(0, kExprBlock, 0); |
2067 EXPECT_ARITY(0, kExprBlock, 1); | 2064 EXPECT_ARITY(0, kExprBlock, 1); |
2068 EXPECT_ARITY(0, kExprBlock, 2); | 2065 EXPECT_ARITY(0, kExprBlock, 2); |
2069 EXPECT_ARITY(0, kExprBlock, 5); | 2066 EXPECT_ARITY(0, kExprBlock, 5); |
2070 EXPECT_ARITY(0, kExprBlock, 10); | 2067 EXPECT_ARITY(0, kExprBlock, 10); |
2071 | 2068 |
2072 EXPECT_ARITY(0, kExprLoop, 0); | 2069 EXPECT_ARITY(0, kExprLoop, 0); |
2073 EXPECT_ARITY(0, kExprLoop, 1); | 2070 EXPECT_ARITY(0, kExprLoop, 1); |
2074 EXPECT_ARITY(0, kExprLoop, 2); | 2071 EXPECT_ARITY(0, kExprLoop, 2); |
2075 EXPECT_ARITY(0, kExprLoop, 7); | 2072 EXPECT_ARITY(0, kExprLoop, 7); |
2076 EXPECT_ARITY(0, kExprLoop, 11); | 2073 EXPECT_ARITY(0, kExprLoop, 11); |
2077 | 2074 |
2078 EXPECT_ARITY(3, kExprSelect); | 2075 EXPECT_ARITY(3, kExprSelect); |
2079 | 2076 |
2080 EXPECT_ARITY(0, kExprBr); | 2077 EXPECT_ARITY(0, kExprBr); |
2081 EXPECT_ARITY(1, kExprBrIf); | 2078 EXPECT_ARITY(1, kExprBrIf); |
2082 EXPECT_ARITY(1, kExprBrTable); | 2079 EXPECT_ARITY(1, kExprBrTable); |
2083 | 2080 |
2084 EXPECT_ARITY(1, kExprBr, ARITY_1); | 2081 EXPECT_ARITY(1, kExprBr, ARITY_1); |
2085 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | 2082 EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
2086 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | 2083 EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
2087 | 2084 |
2088 { | 2085 { |
2089 sig = sigs.v_v(); | |
2090 EXPECT_ARITY(0, kExprReturn, ARITY_0); | 2086 EXPECT_ARITY(0, kExprReturn, ARITY_0); |
2091 sig = sigs.i_i(); | |
2092 EXPECT_ARITY(1, kExprReturn, ARITY_1); | 2087 EXPECT_ARITY(1, kExprReturn, ARITY_1); |
2093 } | 2088 } |
2094 } | 2089 } |
2095 | 2090 |
2096 | 2091 |
2097 TEST_F(WasmOpcodeArityTest, Misc) { | 2092 TEST_F(WasmOpcodeArityTest, Misc) { |
2098 FunctionSig* sig = sigs.v_v(); | |
2099 EXPECT_ARITY(0, kExprI8Const); | 2093 EXPECT_ARITY(0, kExprI8Const); |
2100 EXPECT_ARITY(0, kExprI32Const); | 2094 EXPECT_ARITY(0, kExprI32Const); |
2101 EXPECT_ARITY(0, kExprF32Const); | 2095 EXPECT_ARITY(0, kExprF32Const); |
2102 EXPECT_ARITY(0, kExprI64Const); | 2096 EXPECT_ARITY(0, kExprI64Const); |
2103 EXPECT_ARITY(0, kExprF64Const); | 2097 EXPECT_ARITY(0, kExprF64Const); |
2104 EXPECT_ARITY(0, kExprGetLocal); | 2098 EXPECT_ARITY(0, kExprGetLocal); |
2105 EXPECT_ARITY(1, kExprSetLocal); | 2099 EXPECT_ARITY(1, kExprSetLocal); |
2106 EXPECT_ARITY(0, kExprLoadGlobal); | 2100 EXPECT_ARITY(0, kExprLoadGlobal); |
2107 EXPECT_ARITY(1, kExprStoreGlobal); | 2101 EXPECT_ARITY(1, kExprStoreGlobal); |
2108 } | 2102 } |
2109 | 2103 |
2110 | 2104 |
2111 TEST_F(WasmOpcodeArityTest, Calls) { | 2105 TEST_F(WasmOpcodeArityTest, Calls) { |
2112 module.AddFunction(sigs.i_ii()); | |
2113 module.AddFunction(sigs.i_i()); | |
2114 | |
2115 module.AddSignature(sigs.f_ff()); | |
2116 module.AddSignature(sigs.i_d()); | |
2117 | |
2118 module.AddImport(sigs.f_ff()); | |
2119 module.AddImport(sigs.i_d()); | |
2120 | |
2121 { | 2106 { |
2122 FunctionSig* sig = sigs.i_ii(); | |
2123 | |
2124 EXPECT_ARITY(2, kExprCallFunction, 2, 0); | 2107 EXPECT_ARITY(2, kExprCallFunction, 2, 0); |
2125 EXPECT_ARITY(2, kExprCallImport, 2, 0); | 2108 EXPECT_ARITY(2, kExprCallImport, 2, 0); |
2126 EXPECT_ARITY(3, kExprCallIndirect, 2, 0); | 2109 EXPECT_ARITY(3, kExprCallIndirect, 2, 0); |
2127 | 2110 |
2128 EXPECT_ARITY(1, kExprBr, ARITY_1); | 2111 EXPECT_ARITY(1, kExprBr, ARITY_1); |
2129 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | 2112 EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
2130 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | 2113 EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
2131 | 2114 |
2132 EXPECT_ARITY(0, kExprBr, ARITY_0); | 2115 EXPECT_ARITY(0, kExprBr, ARITY_0); |
2133 EXPECT_ARITY(1, kExprBrIf, ARITY_0); | 2116 EXPECT_ARITY(1, kExprBrIf, ARITY_0); |
2134 EXPECT_ARITY(1, kExprBrTable, ARITY_0); | 2117 EXPECT_ARITY(1, kExprBrTable, ARITY_0); |
2135 } | 2118 } |
2136 | 2119 |
2137 { | 2120 { |
2138 FunctionSig* sig = sigs.v_v(); | |
2139 | |
2140 EXPECT_ARITY(1, kExprCallFunction, ARITY_1, 1); | 2121 EXPECT_ARITY(1, kExprCallFunction, ARITY_1, 1); |
2141 EXPECT_ARITY(1, kExprCallImport, ARITY_1, 1); | 2122 EXPECT_ARITY(1, kExprCallImport, ARITY_1, 1); |
2142 EXPECT_ARITY(2, kExprCallIndirect, ARITY_1, 1); | 2123 EXPECT_ARITY(2, kExprCallIndirect, ARITY_1, 1); |
2143 | 2124 |
2144 EXPECT_ARITY(1, kExprBr, ARITY_1); | 2125 EXPECT_ARITY(1, kExprBr, ARITY_1); |
2145 EXPECT_ARITY(2, kExprBrIf, ARITY_1); | 2126 EXPECT_ARITY(2, kExprBrIf, ARITY_1); |
2146 EXPECT_ARITY(2, kExprBrTable, ARITY_1); | 2127 EXPECT_ARITY(2, kExprBrTable, ARITY_1); |
2147 | 2128 |
2148 EXPECT_ARITY(0, kExprBr, ARITY_0); | 2129 EXPECT_ARITY(0, kExprBr, ARITY_0); |
2149 EXPECT_ARITY(1, kExprBrIf, ARITY_0); | 2130 EXPECT_ARITY(1, kExprBrIf, ARITY_0); |
2150 EXPECT_ARITY(1, kExprBrTable, ARITY_0); | 2131 EXPECT_ARITY(1, kExprBrTable, ARITY_0); |
2151 } | 2132 } |
2152 } | 2133 } |
2153 | 2134 |
2154 | 2135 |
2155 TEST_F(WasmOpcodeArityTest, LoadsAndStores) { | 2136 TEST_F(WasmOpcodeArityTest, LoadsAndStores) { |
2156 FunctionSig* sig = sigs.v_v(); | |
2157 EXPECT_ARITY(1, kExprI32LoadMem8S); | 2137 EXPECT_ARITY(1, kExprI32LoadMem8S); |
2158 EXPECT_ARITY(1, kExprI32LoadMem8U); | 2138 EXPECT_ARITY(1, kExprI32LoadMem8U); |
2159 EXPECT_ARITY(1, kExprI32LoadMem16S); | 2139 EXPECT_ARITY(1, kExprI32LoadMem16S); |
2160 EXPECT_ARITY(1, kExprI32LoadMem16U); | 2140 EXPECT_ARITY(1, kExprI32LoadMem16U); |
2161 EXPECT_ARITY(1, kExprI32LoadMem); | 2141 EXPECT_ARITY(1, kExprI32LoadMem); |
2162 | 2142 |
2163 EXPECT_ARITY(1, kExprI64LoadMem8S); | 2143 EXPECT_ARITY(1, kExprI64LoadMem8S); |
2164 EXPECT_ARITY(1, kExprI64LoadMem8U); | 2144 EXPECT_ARITY(1, kExprI64LoadMem8U); |
2165 EXPECT_ARITY(1, kExprI64LoadMem16S); | 2145 EXPECT_ARITY(1, kExprI64LoadMem16S); |
2166 EXPECT_ARITY(1, kExprI64LoadMem16U); | 2146 EXPECT_ARITY(1, kExprI64LoadMem16U); |
2167 EXPECT_ARITY(1, kExprI64LoadMem32S); | 2147 EXPECT_ARITY(1, kExprI64LoadMem32S); |
2168 EXPECT_ARITY(1, kExprI64LoadMem32U); | 2148 EXPECT_ARITY(1, kExprI64LoadMem32U); |
2169 EXPECT_ARITY(1, kExprI64LoadMem); | 2149 EXPECT_ARITY(1, kExprI64LoadMem); |
2170 EXPECT_ARITY(1, kExprF32LoadMem); | 2150 EXPECT_ARITY(1, kExprF32LoadMem); |
2171 EXPECT_ARITY(1, kExprF64LoadMem); | 2151 EXPECT_ARITY(1, kExprF64LoadMem); |
2172 | 2152 |
2173 EXPECT_ARITY(2, kExprI32StoreMem8); | 2153 EXPECT_ARITY(2, kExprI32StoreMem8); |
2174 EXPECT_ARITY(2, kExprI32StoreMem16); | 2154 EXPECT_ARITY(2, kExprI32StoreMem16); |
2175 EXPECT_ARITY(2, kExprI32StoreMem); | 2155 EXPECT_ARITY(2, kExprI32StoreMem); |
2176 EXPECT_ARITY(2, kExprI64StoreMem8); | 2156 EXPECT_ARITY(2, kExprI64StoreMem8); |
2177 EXPECT_ARITY(2, kExprI64StoreMem16); | 2157 EXPECT_ARITY(2, kExprI64StoreMem16); |
2178 EXPECT_ARITY(2, kExprI64StoreMem32); | 2158 EXPECT_ARITY(2, kExprI64StoreMem32); |
2179 EXPECT_ARITY(2, kExprI64StoreMem); | 2159 EXPECT_ARITY(2, kExprI64StoreMem); |
2180 EXPECT_ARITY(2, kExprF32StoreMem); | 2160 EXPECT_ARITY(2, kExprF32StoreMem); |
2181 EXPECT_ARITY(2, kExprF64StoreMem); | 2161 EXPECT_ARITY(2, kExprF64StoreMem); |
2182 } | 2162 } |
2183 | 2163 |
2184 | 2164 |
2185 TEST_F(WasmOpcodeArityTest, MiscMemExpressions) { | 2165 TEST_F(WasmOpcodeArityTest, MiscMemExpressions) { |
2186 FunctionSig* sig = sigs.v_v(); | |
2187 EXPECT_ARITY(0, kExprMemorySize); | 2166 EXPECT_ARITY(0, kExprMemorySize); |
2188 EXPECT_ARITY(1, kExprGrowMemory); | 2167 EXPECT_ARITY(1, kExprGrowMemory); |
2189 } | 2168 } |
2190 | 2169 |
2191 | 2170 |
2192 TEST_F(WasmOpcodeArityTest, SimpleExpressions) { | 2171 TEST_F(WasmOpcodeArityTest, SimpleExpressions) { |
2193 FunctionSig* sig = sigs.v_v(); | |
2194 EXPECT_ARITY(2, kExprI32Add); | 2172 EXPECT_ARITY(2, kExprI32Add); |
2195 EXPECT_ARITY(2, kExprI32Sub); | 2173 EXPECT_ARITY(2, kExprI32Sub); |
2196 EXPECT_ARITY(2, kExprI32Mul); | 2174 EXPECT_ARITY(2, kExprI32Mul); |
2197 EXPECT_ARITY(2, kExprI32DivS); | 2175 EXPECT_ARITY(2, kExprI32DivS); |
2198 EXPECT_ARITY(2, kExprI32DivU); | 2176 EXPECT_ARITY(2, kExprI32DivU); |
2199 EXPECT_ARITY(2, kExprI32RemS); | 2177 EXPECT_ARITY(2, kExprI32RemS); |
2200 EXPECT_ARITY(2, kExprI32RemU); | 2178 EXPECT_ARITY(2, kExprI32RemU); |
2201 EXPECT_ARITY(2, kExprI32And); | 2179 EXPECT_ARITY(2, kExprI32And); |
2202 EXPECT_ARITY(2, kExprI32Ior); | 2180 EXPECT_ARITY(2, kExprI32Ior); |
2203 EXPECT_ARITY(2, kExprI32Xor); | 2181 EXPECT_ARITY(2, kExprI32Xor); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 size_t pos = 0; | 2405 size_t pos = 0; |
2428 pos = ExpectRun(map, pos, kAstF32, 5); | 2406 pos = ExpectRun(map, pos, kAstF32, 5); |
2429 pos = ExpectRun(map, pos, kAstI32, 1337); | 2407 pos = ExpectRun(map, pos, kAstI32, 1337); |
2430 pos = ExpectRun(map, pos, kAstI64, 212); | 2408 pos = ExpectRun(map, pos, kAstI64, 212); |
2431 delete[] data; | 2409 delete[] data; |
2432 } | 2410 } |
2433 | 2411 |
2434 } // namespace wasm | 2412 } // namespace wasm |
2435 } // namespace internal | 2413 } // namespace internal |
2436 } // namespace v8 | 2414 } // namespace v8 |
OLD | NEW |