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/common/wasm/test-signatures.h" | 9 #include "test/common/wasm/test-signatures.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 #define B3(a, b, c) WASM_BLOCK(a, b, c) | 25 #define B3(a, b, c) WASM_BLOCK(a, b, c) |
26 | 26 |
27 #define WASM_IF_OP kExprIf, kLocalVoid | 27 #define WASM_IF_OP kExprIf, kLocalVoid |
28 #define WASM_LOOP_OP kExprLoop, kLocalVoid | 28 #define WASM_LOOP_OP kExprLoop, kLocalVoid |
29 | 29 |
30 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; | 30 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; |
31 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; | 31 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; |
32 static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; | 32 static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)}; |
33 static const byte kCodeTeeLocal0[] = {WASM_TEE_LOCAL(0, WASM_ZERO)}; | 33 static const byte kCodeTeeLocal0[] = {WASM_TEE_LOCAL(0, WASM_ZERO)}; |
34 | 34 |
35 static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; | 35 static const ValueType kValueTypes[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64}; |
36 static const MachineType machineTypes[] = { | 36 static const MachineType machineTypes[] = { |
37 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), | 37 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
38 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), | 38 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
39 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), | 39 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
40 MachineType::Float64()}; | 40 MachineType::Float64()}; |
41 | 41 |
42 static const WasmOpcode kInt32BinopOpcodes[] = { | 42 static const WasmOpcode kInt32BinopOpcodes[] = { |
43 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, | 43 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, |
44 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, | 44 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, |
45 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, | 45 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 #define EXPECT_FAILURE(sig, ...) \ | 78 #define EXPECT_FAILURE(sig, ...) \ |
79 do { \ | 79 do { \ |
80 static const byte code[] = {__VA_ARGS__}; \ | 80 static const byte code[] = {__VA_ARGS__}; \ |
81 Verify(kError, sigs.sig(), code, code + sizeof(code)); \ | 81 Verify(kError, sigs.sig(), code, code + sizeof(code)); \ |
82 } while (false) | 82 } while (false) |
83 | 83 |
84 static bool old_eh_flag; | 84 static bool old_eh_flag; |
85 | 85 |
86 class FunctionBodyDecoderTest : public TestWithZone { | 86 class FunctionBodyDecoderTest : public TestWithZone { |
87 public: | 87 public: |
88 typedef std::pair<uint32_t, LocalType> LocalsDecl; | 88 typedef std::pair<uint32_t, ValueType> LocalsDecl; |
89 | 89 |
90 FunctionBodyDecoderTest() : module(nullptr), local_decls(zone()) {} | 90 FunctionBodyDecoderTest() : module(nullptr), local_decls(zone()) {} |
91 | 91 |
92 static void SetUpTestCase() { old_eh_flag = FLAG_wasm_eh_prototype; } | 92 static void SetUpTestCase() { old_eh_flag = FLAG_wasm_eh_prototype; } |
93 | 93 |
94 static void TearDownTestCase() { | 94 static void TearDownTestCase() { |
95 // Reset the wasm_eh_prototype flag | 95 // Reset the wasm_eh_prototype flag |
96 FLAG_wasm_eh_prototype = old_eh_flag; | 96 FLAG_wasm_eh_prototype = old_eh_flag; |
97 } | 97 } |
98 | 98 |
99 TestSignatures sigs; | 99 TestSignatures sigs; |
100 ModuleEnv* module; | 100 ModuleEnv* module; |
101 LocalDeclEncoder local_decls; | 101 LocalDeclEncoder local_decls; |
102 | 102 |
103 void AddLocals(LocalType type, uint32_t count) { | 103 void AddLocals(ValueType type, uint32_t count) { |
104 local_decls.AddLocals(count, type); | 104 local_decls.AddLocals(count, type); |
105 } | 105 } |
106 | 106 |
107 // Prepends local variable declarations and renders nice error messages for | 107 // Prepends local variable declarations and renders nice error messages for |
108 // verification failures. | 108 // verification failures. |
109 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, | 109 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, |
110 const byte* end) { | 110 const byte* end) { |
111 local_decls.Prepend(zone(), &start, &end); | 111 local_decls.Prepend(zone(), &start, &end); |
112 // Verify the code. | 112 // Verify the code. |
113 DecodeResult result = | 113 DecodeResult result = |
(...skipping 18 matching lines...) Expand all Loading... |
132 EXPECT_TRUE(false) << str.str().c_str(); | 132 EXPECT_TRUE(false) << str.str().c_str(); |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 void TestBinop(WasmOpcode opcode, FunctionSig* success) { | 136 void TestBinop(WasmOpcode opcode, FunctionSig* success) { |
137 // op(local[0], local[1]) | 137 // op(local[0], local[1]) |
138 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 138 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
139 EXPECT_VERIFIES_SC(success, code); | 139 EXPECT_VERIFIES_SC(success, code); |
140 | 140 |
141 // Try all combinations of return and parameter types. | 141 // Try all combinations of return and parameter types. |
142 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 142 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
143 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 143 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
144 for (size_t k = 0; k < arraysize(kLocalTypes); k++) { | 144 for (size_t k = 0; k < arraysize(kValueTypes); k++) { |
145 LocalType types[] = {kLocalTypes[i], kLocalTypes[j], kLocalTypes[k]}; | 145 ValueType types[] = {kValueTypes[i], kValueTypes[j], kValueTypes[k]}; |
146 if (types[0] != success->GetReturn(0) || | 146 if (types[0] != success->GetReturn(0) || |
147 types[1] != success->GetParam(0) || | 147 types[1] != success->GetParam(0) || |
148 types[2] != success->GetParam(1)) { | 148 types[2] != success->GetParam(1)) { |
149 // Test signature mismatch. | 149 // Test signature mismatch. |
150 FunctionSig sig(1, 2, types); | 150 FunctionSig sig(1, 2, types); |
151 EXPECT_FAILURE_SC(&sig, code); | 151 EXPECT_FAILURE_SC(&sig, code); |
152 } | 152 } |
153 } | 153 } |
154 } | 154 } |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 void TestUnop(WasmOpcode opcode, FunctionSig* success) { | 158 void TestUnop(WasmOpcode opcode, FunctionSig* success) { |
159 TestUnop(opcode, success->GetReturn(), success->GetParam(0)); | 159 TestUnop(opcode, success->GetReturn(), success->GetParam(0)); |
160 } | 160 } |
161 | 161 |
162 void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) { | 162 void TestUnop(WasmOpcode opcode, ValueType ret_type, ValueType param_type) { |
163 // Return(op(local[0])) | 163 // Return(op(local[0])) |
164 byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))}; | 164 byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))}; |
165 { | 165 { |
166 LocalType types[] = {ret_type, param_type}; | 166 ValueType types[] = {ret_type, param_type}; |
167 FunctionSig sig(1, 1, types); | 167 FunctionSig sig(1, 1, types); |
168 EXPECT_VERIFIES_SC(&sig, code); | 168 EXPECT_VERIFIES_SC(&sig, code); |
169 } | 169 } |
170 | 170 |
171 // Try all combinations of return and parameter types. | 171 // Try all combinations of return and parameter types. |
172 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 172 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
173 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 173 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
174 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; | 174 ValueType types[] = {kValueTypes[i], kValueTypes[j]}; |
175 if (types[0] != ret_type || types[1] != param_type) { | 175 if (types[0] != ret_type || types[1] != param_type) { |
176 // Test signature mismatch. | 176 // Test signature mismatch. |
177 FunctionSig sig(1, 1, types); | 177 FunctionSig sig(1, 1, types); |
178 EXPECT_FAILURE_SC(&sig, code); | 178 EXPECT_FAILURE_SC(&sig, code); |
179 } | 179 } |
180 } | 180 } |
181 } | 181 } |
182 } | 182 } |
183 }; | 183 }; |
184 | 184 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 for (int size = 1; size <= 4; size++) { | 251 for (int size = 1; size <= 4; size++) { |
252 Verify(kError, sigs.i_i(), code, code + size); | 252 Verify(kError, sigs.i_i(), code, code + size); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 TEST_F(FunctionBodyDecoderTest, GetLocal0_param) { | 256 TEST_F(FunctionBodyDecoderTest, GetLocal0_param) { |
257 EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); | 257 EXPECT_VERIFIES_C(i_i, kCodeGetLocal0); |
258 } | 258 } |
259 | 259 |
260 TEST_F(FunctionBodyDecoderTest, GetLocal0_local) { | 260 TEST_F(FunctionBodyDecoderTest, GetLocal0_local) { |
261 AddLocals(kAstI32, 1); | 261 AddLocals(kWasmI32, 1); |
262 EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); | 262 EXPECT_VERIFIES_C(i_v, kCodeGetLocal0); |
263 } | 263 } |
264 | 264 |
265 TEST_F(FunctionBodyDecoderTest, TooManyLocals) { | 265 TEST_F(FunctionBodyDecoderTest, TooManyLocals) { |
266 AddLocals(kAstI32, 4034986500); | 266 AddLocals(kWasmI32, 4034986500); |
267 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); | 267 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
268 } | 268 } |
269 | 269 |
270 TEST_F(FunctionBodyDecoderTest, GetLocal0_param_n) { | 270 TEST_F(FunctionBodyDecoderTest, GetLocal0_param_n) { |
271 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; | 271 FunctionSig* array[] = {sigs.i_i(), sigs.i_ii(), sigs.i_iii()}; |
272 | 272 |
273 for (size_t i = 0; i < arraysize(array); i++) { | 273 for (size_t i = 0; i < arraysize(array); i++) { |
274 EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); | 274 EXPECT_VERIFIES_SC(array[i], kCodeGetLocal0); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 TEST_F(FunctionBodyDecoderTest, GetLocalN_local) { | 278 TEST_F(FunctionBodyDecoderTest, GetLocalN_local) { |
279 for (byte i = 1; i < 8; i++) { | 279 for (byte i = 1; i < 8; i++) { |
280 AddLocals(kAstI32, 1); | 280 AddLocals(kWasmI32, 1); |
281 for (byte j = 0; j < i; j++) { | 281 for (byte j = 0; j < i; j++) { |
282 byte code[] = {kExprGetLocal, j}; | 282 byte code[] = {kExprGetLocal, j}; |
283 EXPECT_VERIFIES_C(i_v, code); | 283 EXPECT_VERIFIES_C(i_v, code); |
284 } | 284 } |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) { | 288 TEST_F(FunctionBodyDecoderTest, GetLocal0_fail_no_params) { |
289 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); | 289 EXPECT_FAILURE_C(i_v, kCodeGetLocal0); |
290 } | 290 } |
291 | 291 |
292 TEST_F(FunctionBodyDecoderTest, GetLocal1_fail_no_locals) { | 292 TEST_F(FunctionBodyDecoderTest, GetLocal1_fail_no_locals) { |
293 EXPECT_FAILURE_C(i_i, kCodeGetLocal1); | 293 EXPECT_FAILURE_C(i_i, kCodeGetLocal1); |
294 } | 294 } |
295 | 295 |
296 TEST_F(FunctionBodyDecoderTest, GetLocal_off_end) { | 296 TEST_F(FunctionBodyDecoderTest, GetLocal_off_end) { |
297 static const byte code[] = {kExprGetLocal}; | 297 static const byte code[] = {kExprGetLocal}; |
298 EXPECT_FAILURE_C(i_i, code); | 298 EXPECT_FAILURE_C(i_i, code); |
299 } | 299 } |
300 | 300 |
301 TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) { | 301 TEST_F(FunctionBodyDecoderTest, NumLocalBelowLimit) { |
302 AddLocals(kAstI32, kMaxNumWasmLocals - 1); | 302 AddLocals(kWasmI32, kMaxNumWasmLocals - 1); |
303 EXPECT_VERIFIES(v_v, WASM_NOP); | 303 EXPECT_VERIFIES(v_v, WASM_NOP); |
304 } | 304 } |
305 | 305 |
306 TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) { | 306 TEST_F(FunctionBodyDecoderTest, NumLocalAtLimit) { |
307 AddLocals(kAstI32, kMaxNumWasmLocals); | 307 AddLocals(kWasmI32, kMaxNumWasmLocals); |
308 EXPECT_VERIFIES(v_v, WASM_NOP); | 308 EXPECT_VERIFIES(v_v, WASM_NOP); |
309 } | 309 } |
310 | 310 |
311 TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) { | 311 TEST_F(FunctionBodyDecoderTest, NumLocalAboveLimit) { |
312 AddLocals(kAstI32, kMaxNumWasmLocals + 1); | 312 AddLocals(kWasmI32, kMaxNumWasmLocals + 1); |
313 EXPECT_FAILURE(v_v, WASM_NOP); | 313 EXPECT_FAILURE(v_v, WASM_NOP); |
314 } | 314 } |
315 | 315 |
316 TEST_F(FunctionBodyDecoderTest, GetLocal_varint) { | 316 TEST_F(FunctionBodyDecoderTest, GetLocal_varint) { |
317 const int kMaxLocals = kMaxNumWasmLocals - 1; | 317 const int kMaxLocals = kMaxNumWasmLocals - 1; |
318 AddLocals(kAstI32, kMaxLocals); | 318 AddLocals(kWasmI32, kMaxLocals); |
319 | 319 |
320 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); | 320 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_1(66)); |
321 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); | 321 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_2(7777)); |
322 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888)); | 322 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_3(8888)); |
323 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999)); | 323 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(9999)); |
324 | 324 |
325 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); | 325 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_5(kMaxLocals - 1)); |
326 | 326 |
327 EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); | 327 EXPECT_FAILURE(i_i, kExprGetLocal, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
328 | 328 |
329 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); | 329 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals - 1)); |
330 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); | 330 EXPECT_VERIFIES(i_i, kExprGetLocal, U32V_4(kMaxLocals)); |
331 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); | 331 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
332 | 332 |
333 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); | 333 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals)); |
334 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); | 334 EXPECT_FAILURE(i_v, kExprGetLocal, U32V_4(kMaxLocals + 1)); |
335 } | 335 } |
336 | 336 |
337 TEST_F(FunctionBodyDecoderTest, GetLocal_toomany) { | 337 TEST_F(FunctionBodyDecoderTest, GetLocal_toomany) { |
338 AddLocals(kAstI32, kMaxNumWasmLocals - 100); | 338 AddLocals(kWasmI32, kMaxNumWasmLocals - 100); |
339 AddLocals(kAstI32, 100); | 339 AddLocals(kWasmI32, 100); |
340 | 340 |
341 EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66)); | 341 EXPECT_VERIFIES(i_v, kExprGetLocal, U32V_1(66)); |
342 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66)); | 342 EXPECT_FAILURE(i_i, kExprGetLocal, U32V_1(66)); |
343 } | 343 } |
344 | 344 |
345 TEST_F(FunctionBodyDecoderTest, Binops_off_end) { | 345 TEST_F(FunctionBodyDecoderTest, Binops_off_end) { |
346 byte code1[] = {0}; // [opcode] | 346 byte code1[] = {0}; // [opcode] |
347 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { | 347 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { |
348 code1[0] = kInt32BinopOpcodes[i]; | 348 code1[0] = kInt32BinopOpcodes[i]; |
349 EXPECT_FAILURE_C(i_i, code1); | 349 EXPECT_FAILURE_C(i_i, code1); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 398 |
399 TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) { | 399 TEST_F(FunctionBodyDecoderTest, TeeLocal0_param) { |
400 EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); | 400 EXPECT_VERIFIES_C(i_i, kCodeTeeLocal0); |
401 EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); | 401 EXPECT_FAILURE_C(f_ff, kCodeTeeLocal0); |
402 EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); | 402 EXPECT_FAILURE_C(d_dd, kCodeTeeLocal0); |
403 } | 403 } |
404 | 404 |
405 TEST_F(FunctionBodyDecoderTest, SetLocal0_local) { | 405 TEST_F(FunctionBodyDecoderTest, SetLocal0_local) { |
406 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); | 406 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
407 EXPECT_FAILURE_C(v_v, kCodeSetLocal0); | 407 EXPECT_FAILURE_C(v_v, kCodeSetLocal0); |
408 AddLocals(kAstI32, 1); | 408 AddLocals(kWasmI32, 1); |
409 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); | 409 EXPECT_FAILURE_C(i_v, kCodeSetLocal0); |
410 EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); | 410 EXPECT_VERIFIES_C(v_v, kCodeSetLocal0); |
411 } | 411 } |
412 | 412 |
413 TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) { | 413 TEST_F(FunctionBodyDecoderTest, TeeLocal0_local) { |
414 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); | 414 EXPECT_FAILURE_C(i_v, kCodeTeeLocal0); |
415 AddLocals(kAstI32, 1); | 415 AddLocals(kWasmI32, 1); |
416 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); | 416 EXPECT_VERIFIES_C(i_v, kCodeTeeLocal0); |
417 } | 417 } |
418 | 418 |
419 TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { | 419 TEST_F(FunctionBodyDecoderTest, TeeLocalN_local) { |
420 for (byte i = 1; i < 8; i++) { | 420 for (byte i = 1; i < 8; i++) { |
421 AddLocals(kAstI32, 1); | 421 AddLocals(kWasmI32, 1); |
422 for (byte j = 0; j < i; j++) { | 422 for (byte j = 0; j < i; j++) { |
423 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); | 423 EXPECT_FAILURE(v_v, WASM_TEE_LOCAL(j, WASM_I8(i))); |
424 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); | 424 EXPECT_VERIFIES(i_i, WASM_TEE_LOCAL(j, WASM_I8(i))); |
425 } | 425 } |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 TEST_F(FunctionBodyDecoderTest, BlockN) { | 429 TEST_F(FunctionBodyDecoderTest, BlockN) { |
430 const int kMaxSize = 200; | 430 const int kMaxSize = 200; |
431 byte buffer[kMaxSize + 3]; | 431 byte buffer[kMaxSize + 3]; |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, | 671 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, |
672 WASM_GET_LOCAL(0))); | 672 WASM_GET_LOCAL(0))); |
673 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), | 673 EXPECT_VERIFIES(i_i, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), |
674 WASM_UNREACHABLE)); | 674 WASM_UNREACHABLE)); |
675 } | 675 } |
676 | 676 |
677 TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) { | 677 TEST_F(FunctionBodyDecoderTest, IfElseUnreachable2) { |
678 static const byte code[] = { | 678 static const byte code[] = { |
679 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; | 679 WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))}; |
680 | 680 |
681 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 681 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
682 LocalType types[] = {kAstI32, kLocalTypes[i]}; | 682 ValueType types[] = {kWasmI32, kValueTypes[i]}; |
683 FunctionSig sig(1, 1, types); | 683 FunctionSig sig(1, 1, types); |
684 | 684 |
685 if (kLocalTypes[i] == kAstI32) { | 685 if (kValueTypes[i] == kWasmI32) { |
686 EXPECT_VERIFIES_SC(&sig, code); | 686 EXPECT_VERIFIES_SC(&sig, code); |
687 } else { | 687 } else { |
688 EXPECT_FAILURE_SC(&sig, code); | 688 EXPECT_FAILURE_SC(&sig, code); |
689 } | 689 } |
690 } | 690 } |
691 } | 691 } |
692 | 692 |
693 TEST_F(FunctionBodyDecoderTest, IfBreak) { | 693 TEST_F(FunctionBodyDecoderTest, IfBreak) { |
694 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); | 694 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0))); |
695 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); | 695 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1))); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 EXPECT_FAILURE_C(i_f, kCode); | 955 EXPECT_FAILURE_C(i_f, kCode); |
956 EXPECT_FAILURE_C(i_d, kCode); | 956 EXPECT_FAILURE_C(i_d, kCode); |
957 } | 957 } |
958 | 958 |
959 TEST_F(FunctionBodyDecoderTest, Int64Local_param) { | 959 TEST_F(FunctionBodyDecoderTest, Int64Local_param) { |
960 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); | 960 EXPECT_VERIFIES_C(l_l, kCodeGetLocal0); |
961 } | 961 } |
962 | 962 |
963 TEST_F(FunctionBodyDecoderTest, Int64Locals) { | 963 TEST_F(FunctionBodyDecoderTest, Int64Locals) { |
964 for (byte i = 1; i < 8; i++) { | 964 for (byte i = 1; i < 8; i++) { |
965 AddLocals(kAstI64, 1); | 965 AddLocals(kWasmI64, 1); |
966 for (byte j = 0; j < i; j++) { | 966 for (byte j = 0; j < i; j++) { |
967 EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); | 967 EXPECT_VERIFIES(l_v, WASM_GET_LOCAL(j)); |
968 } | 968 } |
969 } | 969 } |
970 } | 970 } |
971 | 971 |
972 TEST_F(FunctionBodyDecoderTest, Int32Binops) { | 972 TEST_F(FunctionBodyDecoderTest, Int32Binops) { |
973 TestBinop(kExprI32Add, sigs.i_ii()); | 973 TestBinop(kExprI32Add, sigs.i_ii()); |
974 TestBinop(kExprI32Sub, sigs.i_ii()); | 974 TestBinop(kExprI32Sub, sigs.i_ii()); |
975 TestBinop(kExprI32Mul, sigs.i_ii()); | 975 TestBinop(kExprI32Mul, sigs.i_ii()); |
(...skipping 30 matching lines...) Expand all Loading... |
1006 TestBinop(kExprF32Sub, sigs.f_ff()); | 1006 TestBinop(kExprF32Sub, sigs.f_ff()); |
1007 TestBinop(kExprF32Mul, sigs.f_ff()); | 1007 TestBinop(kExprF32Mul, sigs.f_ff()); |
1008 TestBinop(kExprF32Div, sigs.f_ff()); | 1008 TestBinop(kExprF32Div, sigs.f_ff()); |
1009 | 1009 |
1010 TestBinop(kExprF32Eq, sigs.i_ff()); | 1010 TestBinop(kExprF32Eq, sigs.i_ff()); |
1011 TestBinop(kExprF32Lt, sigs.i_ff()); | 1011 TestBinop(kExprF32Lt, sigs.i_ff()); |
1012 TestBinop(kExprF32Le, sigs.i_ff()); | 1012 TestBinop(kExprF32Le, sigs.i_ff()); |
1013 } | 1013 } |
1014 | 1014 |
1015 TEST_F(FunctionBodyDecoderTest, TypeConversions) { | 1015 TEST_F(FunctionBodyDecoderTest, TypeConversions) { |
1016 TestUnop(kExprI32SConvertF32, kAstI32, kAstF32); | 1016 TestUnop(kExprI32SConvertF32, kWasmI32, kWasmF32); |
1017 TestUnop(kExprI32SConvertF64, kAstI32, kAstF64); | 1017 TestUnop(kExprI32SConvertF64, kWasmI32, kWasmF64); |
1018 TestUnop(kExprI32UConvertF32, kAstI32, kAstF32); | 1018 TestUnop(kExprI32UConvertF32, kWasmI32, kWasmF32); |
1019 TestUnop(kExprI32UConvertF64, kAstI32, kAstF64); | 1019 TestUnop(kExprI32UConvertF64, kWasmI32, kWasmF64); |
1020 TestUnop(kExprF64SConvertI32, kAstF64, kAstI32); | 1020 TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32); |
1021 TestUnop(kExprF64UConvertI32, kAstF64, kAstI32); | 1021 TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32); |
1022 TestUnop(kExprF64ConvertF32, kAstF64, kAstF32); | 1022 TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32); |
1023 TestUnop(kExprF32SConvertI32, kAstF32, kAstI32); | 1023 TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32); |
1024 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); | 1024 TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32); |
1025 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); | 1025 TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64); |
1026 } | 1026 } |
1027 | 1027 |
1028 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { | 1028 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { |
1029 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); | 1029 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
1030 EXPECT_VERIFIES( | 1030 EXPECT_VERIFIES( |
1031 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); | 1031 v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); |
1032 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 1032 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
1033 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 1033 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
1034 EXPECT_VERIFIES(v_v, WASM_NOP); | 1034 EXPECT_VERIFIES(v_v, WASM_NOP); |
1035 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); | 1035 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); |
(...skipping 14 matching lines...) Expand all Loading... |
1050 | 1050 |
1051 TEST_F(FunctionBodyDecoderTest, MacrosNestedBlocks) { | 1051 TEST_F(FunctionBodyDecoderTest, MacrosNestedBlocks) { |
1052 EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); | 1052 EXPECT_VERIFIES(v_v, B2(WASM_NOP, B2(WASM_NOP, WASM_NOP))); |
1053 EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- | 1053 EXPECT_VERIFIES(v_v, B3(WASM_NOP, // -- |
1054 B2(WASM_NOP, WASM_NOP), // -- | 1054 B2(WASM_NOP, WASM_NOP), // -- |
1055 B2(WASM_NOP, WASM_NOP))); // -- | 1055 B2(WASM_NOP, WASM_NOP))); // -- |
1056 EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); | 1056 EXPECT_VERIFIES(v_v, B1(B1(B2(WASM_NOP, WASM_NOP)))); |
1057 } | 1057 } |
1058 | 1058 |
1059 TEST_F(FunctionBodyDecoderTest, MultipleReturn) { | 1059 TEST_F(FunctionBodyDecoderTest, MultipleReturn) { |
1060 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1060 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32, |
| 1061 kWasmI32}; |
1061 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1062 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
1062 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1063 EXPECT_VERIFIES_S(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
1063 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); | 1064 EXPECT_FAILURE_S(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO)); |
1064 | 1065 |
1065 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1066 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
1066 EXPECT_VERIFIES_S(&sig_iii_v, | 1067 EXPECT_VERIFIES_S(&sig_iii_v, |
1067 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); | 1068 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44))); |
1068 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); | 1069 EXPECT_FAILURE_S(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE)); |
1069 } | 1070 } |
1070 | 1071 |
1071 TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { | 1072 TEST_F(FunctionBodyDecoderTest, MultipleReturn_fallthru) { |
1072 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; | 1073 static ValueType kIntTypes5[] = {kWasmI32, kWasmI32, kWasmI32, kWasmI32, |
| 1074 kWasmI32}; |
1073 FunctionSig sig_ii_v(2, 0, kIntTypes5); | 1075 FunctionSig sig_ii_v(2, 0, kIntTypes5); |
1074 | 1076 |
1075 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); | 1077 EXPECT_VERIFIES_S(&sig_ii_v, WASM_ZERO, WASM_ONE); |
1076 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); | 1078 EXPECT_FAILURE_S(&sig_ii_v, WASM_ZERO); |
1077 | 1079 |
1078 FunctionSig sig_iii_v(3, 0, kIntTypes5); | 1080 FunctionSig sig_iii_v(3, 0, kIntTypes5); |
1079 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); | 1081 EXPECT_VERIFIES_S(&sig_iii_v, WASM_ZERO, WASM_ONE, WASM_I8(44)); |
1080 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); | 1082 EXPECT_FAILURE_S(&sig_iii_v, WASM_ZERO, WASM_ONE); |
1081 } | 1083 } |
1082 | 1084 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 VARINT1(0x33)); | 1248 VARINT1(0x33)); |
1247 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1249 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1248 VARINT2(0x1111)); | 1250 VARINT2(0x1111)); |
1249 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1251 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1250 VARINT3(0x222222)); | 1252 VARINT3(0x222222)); |
1251 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1253 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1252 VARINT4(0x44444444)); | 1254 VARINT4(0x44444444)); |
1253 } | 1255 } |
1254 | 1256 |
1255 TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { | 1257 TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { |
1256 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1258 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1257 LocalType local_type = kLocalTypes[i]; | 1259 ValueType local_type = kValueTypes[i]; |
1258 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1260 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1259 MachineType mem_type = machineTypes[j]; | 1261 MachineType mem_type = machineTypes[j]; |
1260 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; | 1262 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; |
1261 FunctionSig sig(1, 0, &local_type); | 1263 FunctionSig sig(1, 0, &local_type); |
1262 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1264 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { |
1263 EXPECT_VERIFIES_SC(&sig, code); | 1265 EXPECT_VERIFIES_SC(&sig, code); |
1264 } else { | 1266 } else { |
1265 EXPECT_FAILURE_SC(&sig, code); | 1267 EXPECT_FAILURE_SC(&sig, code); |
1266 } | 1268 } |
1267 } | 1269 } |
1268 } | 1270 } |
1269 } | 1271 } |
1270 | 1272 |
1271 TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { | 1273 TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { |
1272 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1274 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1273 LocalType local_type = kLocalTypes[i]; | 1275 ValueType local_type = kValueTypes[i]; |
1274 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1276 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1275 MachineType mem_type = machineTypes[j]; | 1277 MachineType mem_type = machineTypes[j]; |
1276 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; | 1278 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; |
1277 FunctionSig sig(0, 1, &local_type); | 1279 FunctionSig sig(0, 1, &local_type); |
1278 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { | 1280 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { |
1279 EXPECT_VERIFIES_SC(&sig, code); | 1281 EXPECT_VERIFIES_SC(&sig, code); |
1280 } else { | 1282 } else { |
1281 EXPECT_FAILURE_SC(&sig, code); | 1283 EXPECT_FAILURE_SC(&sig, code); |
1282 } | 1284 } |
1283 } | 1285 } |
1284 } | 1286 } |
1285 } | 1287 } |
1286 | 1288 |
1287 namespace { | 1289 namespace { |
1288 // A helper for tests that require a module environment for functions and | 1290 // A helper for tests that require a module environment for functions and |
1289 // globals. | 1291 // globals. |
1290 class TestModuleEnv : public ModuleEnv { | 1292 class TestModuleEnv : public ModuleEnv { |
1291 public: | 1293 public: |
1292 explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin) | 1294 explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin) |
1293 : ModuleEnv(&mod, nullptr) { | 1295 : ModuleEnv(&mod, nullptr) { |
1294 mod.origin = origin; | 1296 mod.origin = origin; |
1295 } | 1297 } |
1296 byte AddGlobal(LocalType type, bool mutability = true) { | 1298 byte AddGlobal(ValueType type, bool mutability = true) { |
1297 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); | 1299 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); |
1298 CHECK(mod.globals.size() <= 127); | 1300 CHECK(mod.globals.size() <= 127); |
1299 return static_cast<byte>(mod.globals.size() - 1); | 1301 return static_cast<byte>(mod.globals.size() - 1); |
1300 } | 1302 } |
1301 byte AddSignature(FunctionSig* sig) { | 1303 byte AddSignature(FunctionSig* sig) { |
1302 mod.signatures.push_back(sig); | 1304 mod.signatures.push_back(sig); |
1303 CHECK(mod.signatures.size() <= 127); | 1305 CHECK(mod.signatures.size() <= 127); |
1304 return static_cast<byte>(mod.signatures.size() - 1); | 1306 return static_cast<byte>(mod.signatures.size() - 1); |
1305 } | 1307 } |
1306 byte AddFunction(FunctionSig* sig) { | 1308 byte AddFunction(FunctionSig* sig) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 | 1387 |
1386 module_env.AddFunction(sigs.i_d()); | 1388 module_env.AddFunction(sigs.i_d()); |
1387 | 1389 |
1388 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); | 1390 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); |
1389 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); | 1391 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); |
1390 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); | 1392 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); |
1391 } | 1393 } |
1392 | 1394 |
1393 TEST_F(FunctionBodyDecoderTest, MultiReturn) { | 1395 TEST_F(FunctionBodyDecoderTest, MultiReturn) { |
1394 FLAG_wasm_mv_prototype = true; | 1396 FLAG_wasm_mv_prototype = true; |
1395 LocalType storage[] = {kAstI32, kAstI32}; | 1397 ValueType storage[] = {kWasmI32, kWasmI32}; |
1396 FunctionSig sig_ii_v(2, 0, storage); | 1398 FunctionSig sig_ii_v(2, 0, storage); |
1397 FunctionSig sig_v_ii(0, 2, storage); | 1399 FunctionSig sig_v_ii(0, 2, storage); |
1398 TestModuleEnv module_env; | 1400 TestModuleEnv module_env; |
1399 module = &module_env; | 1401 module = &module_env; |
1400 | 1402 |
1401 module_env.AddFunction(&sig_v_ii); | 1403 module_env.AddFunction(&sig_v_ii); |
1402 module_env.AddFunction(&sig_ii_v); | 1404 module_env.AddFunction(&sig_ii_v); |
1403 | 1405 |
1404 EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); | 1406 EXPECT_VERIFIES_S(&sig_ii_v, WASM_CALL_FUNCTION0(1)); |
1405 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); | 1407 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), WASM_DROP, WASM_DROP); |
1406 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); | 1408 EXPECT_VERIFIES(v_v, WASM_CALL_FUNCTION0(1), kExprCallFunction, 0); |
1407 } | 1409 } |
1408 | 1410 |
1409 TEST_F(FunctionBodyDecoderTest, MultiReturnType) { | 1411 TEST_F(FunctionBodyDecoderTest, MultiReturnType) { |
1410 FLAG_wasm_mv_prototype = true; | 1412 FLAG_wasm_mv_prototype = true; |
1411 for (size_t a = 0; a < arraysize(kLocalTypes); a++) { | 1413 for (size_t a = 0; a < arraysize(kValueTypes); a++) { |
1412 for (size_t b = 0; b < arraysize(kLocalTypes); b++) { | 1414 for (size_t b = 0; b < arraysize(kValueTypes); b++) { |
1413 for (size_t c = 0; c < arraysize(kLocalTypes); c++) { | 1415 for (size_t c = 0; c < arraysize(kValueTypes); c++) { |
1414 for (size_t d = 0; d < arraysize(kLocalTypes); d++) { | 1416 for (size_t d = 0; d < arraysize(kValueTypes); d++) { |
1415 LocalType storage_ab[] = {kLocalTypes[a], kLocalTypes[b]}; | 1417 ValueType storage_ab[] = {kValueTypes[a], kValueTypes[b]}; |
1416 FunctionSig sig_ab_v(2, 0, storage_ab); | 1418 FunctionSig sig_ab_v(2, 0, storage_ab); |
1417 LocalType storage_cd[] = {kLocalTypes[c], kLocalTypes[d]}; | 1419 ValueType storage_cd[] = {kValueTypes[c], kValueTypes[d]}; |
1418 FunctionSig sig_cd_v(2, 0, storage_cd); | 1420 FunctionSig sig_cd_v(2, 0, storage_cd); |
1419 | 1421 |
1420 TestModuleEnv module_env; | 1422 TestModuleEnv module_env; |
1421 module = &module_env; | 1423 module = &module_env; |
1422 module_env.AddFunction(&sig_cd_v); | 1424 module_env.AddFunction(&sig_cd_v); |
1423 | 1425 |
1424 EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); | 1426 EXPECT_VERIFIES_S(&sig_cd_v, WASM_CALL_FUNCTION0(0)); |
1425 | 1427 |
1426 if (a == c && b == d) { | 1428 if (a == c && b == d) { |
1427 EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); | 1429 EXPECT_VERIFIES_S(&sig_ab_v, WASM_CALL_FUNCTION0(0)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); | 1539 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I8(16))); |
1538 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); | 1540 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_I64V_1(16))); |
1539 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); | 1541 EXPECT_FAILURE_S(sig, WASM_CALL_FUNCTION(f1, WASM_F32(17.6))); |
1540 } | 1542 } |
1541 | 1543 |
1542 TEST_F(FunctionBodyDecoderTest, Int32Globals) { | 1544 TEST_F(FunctionBodyDecoderTest, Int32Globals) { |
1543 FunctionSig* sig = sigs.i_i(); | 1545 FunctionSig* sig = sigs.i_i(); |
1544 TestModuleEnv module_env; | 1546 TestModuleEnv module_env; |
1545 module = &module_env; | 1547 module = &module_env; |
1546 | 1548 |
1547 module_env.AddGlobal(kAstI32); | 1549 module_env.AddGlobal(kWasmI32); |
1548 | 1550 |
1549 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1551 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1550 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1552 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1551 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); | 1553 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
1552 } | 1554 } |
1553 | 1555 |
1554 TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) { | 1556 TEST_F(FunctionBodyDecoderTest, ImmutableGlobal) { |
1555 FunctionSig* sig = sigs.v_v(); | 1557 FunctionSig* sig = sigs.v_v(); |
1556 TestModuleEnv module_env; | 1558 TestModuleEnv module_env; |
1557 module = &module_env; | 1559 module = &module_env; |
1558 | 1560 |
1559 uint32_t g0 = module_env.AddGlobal(kAstI32, true); | 1561 uint32_t g0 = module_env.AddGlobal(kWasmI32, true); |
1560 uint32_t g1 = module_env.AddGlobal(kAstI32, false); | 1562 uint32_t g1 = module_env.AddGlobal(kWasmI32, false); |
1561 | 1563 |
1562 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); | 1564 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(g0, WASM_ZERO)); |
1563 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); | 1565 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(g1, WASM_ZERO)); |
1564 } | 1566 } |
1565 | 1567 |
1566 TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) { | 1568 TEST_F(FunctionBodyDecoderTest, Int32Globals_fail) { |
1567 FunctionSig* sig = sigs.i_i(); | 1569 FunctionSig* sig = sigs.i_i(); |
1568 TestModuleEnv module_env; | 1570 TestModuleEnv module_env; |
1569 module = &module_env; | 1571 module = &module_env; |
1570 | 1572 |
1571 module_env.AddGlobal(kAstI64); | 1573 module_env.AddGlobal(kWasmI64); |
1572 module_env.AddGlobal(kAstI64); | 1574 module_env.AddGlobal(kWasmI64); |
1573 module_env.AddGlobal(kAstF32); | 1575 module_env.AddGlobal(kWasmF32); |
1574 module_env.AddGlobal(kAstF64); | 1576 module_env.AddGlobal(kWasmF64); |
1575 | 1577 |
1576 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); | 1578 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(0)); |
1577 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); | 1579 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(1)); |
1578 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); | 1580 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(2)); |
1579 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); | 1581 EXPECT_FAILURE_S(sig, WASM_GET_GLOBAL(3)); |
1580 | 1582 |
1581 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); | 1583 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), WASM_ZERO); |
1582 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); | 1584 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), WASM_ZERO); |
1583 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); | 1585 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(2, WASM_GET_LOCAL(0)), WASM_ZERO); |
1584 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); | 1586 EXPECT_FAILURE_S(sig, WASM_SET_GLOBAL(3, WASM_GET_LOCAL(0)), WASM_ZERO); |
1585 } | 1587 } |
1586 | 1588 |
1587 TEST_F(FunctionBodyDecoderTest, Int64Globals) { | 1589 TEST_F(FunctionBodyDecoderTest, Int64Globals) { |
1588 FunctionSig* sig = sigs.l_l(); | 1590 FunctionSig* sig = sigs.l_l(); |
1589 TestModuleEnv module_env; | 1591 TestModuleEnv module_env; |
1590 module = &module_env; | 1592 module = &module_env; |
1591 | 1593 |
1592 module_env.AddGlobal(kAstI64); | 1594 module_env.AddGlobal(kWasmI64); |
1593 module_env.AddGlobal(kAstI64); | 1595 module_env.AddGlobal(kWasmI64); |
1594 | 1596 |
1595 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1597 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1596 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); | 1598 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(1)); |
1597 | 1599 |
1598 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1600 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1599 WASM_GET_LOCAL(0)); | 1601 WASM_GET_LOCAL(0)); |
1600 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), | 1602 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(1, WASM_GET_LOCAL(0)), |
1601 WASM_GET_LOCAL(0)); | 1603 WASM_GET_LOCAL(0)); |
1602 } | 1604 } |
1603 | 1605 |
1604 TEST_F(FunctionBodyDecoderTest, Float32Globals) { | 1606 TEST_F(FunctionBodyDecoderTest, Float32Globals) { |
1605 FunctionSig* sig = sigs.f_ff(); | 1607 FunctionSig* sig = sigs.f_ff(); |
1606 TestModuleEnv module_env; | 1608 TestModuleEnv module_env; |
1607 module = &module_env; | 1609 module = &module_env; |
1608 | 1610 |
1609 module_env.AddGlobal(kAstF32); | 1611 module_env.AddGlobal(kWasmF32); |
1610 | 1612 |
1611 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1613 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1612 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1614 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1613 WASM_GET_LOCAL(0)); | 1615 WASM_GET_LOCAL(0)); |
1614 } | 1616 } |
1615 | 1617 |
1616 TEST_F(FunctionBodyDecoderTest, Float64Globals) { | 1618 TEST_F(FunctionBodyDecoderTest, Float64Globals) { |
1617 FunctionSig* sig = sigs.d_dd(); | 1619 FunctionSig* sig = sigs.d_dd(); |
1618 TestModuleEnv module_env; | 1620 TestModuleEnv module_env; |
1619 module = &module_env; | 1621 module = &module_env; |
1620 | 1622 |
1621 module_env.AddGlobal(kAstF64); | 1623 module_env.AddGlobal(kWasmF64); |
1622 | 1624 |
1623 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); | 1625 EXPECT_VERIFIES_S(sig, WASM_GET_GLOBAL(0)); |
1624 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), | 1626 EXPECT_VERIFIES_S(sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)), |
1625 WASM_GET_LOCAL(0)); | 1627 WASM_GET_LOCAL(0)); |
1626 } | 1628 } |
1627 | 1629 |
1628 TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) { | 1630 TEST_F(FunctionBodyDecoderTest, AllGetGlobalCombinations) { |
1629 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1631 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1630 LocalType local_type = kLocalTypes[i]; | 1632 ValueType local_type = kValueTypes[i]; |
1631 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1633 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1632 LocalType global_type = kLocalTypes[j]; | 1634 ValueType global_type = kValueTypes[j]; |
1633 FunctionSig sig(1, 0, &local_type); | 1635 FunctionSig sig(1, 0, &local_type); |
1634 TestModuleEnv module_env; | 1636 TestModuleEnv module_env; |
1635 module = &module_env; | 1637 module = &module_env; |
1636 module_env.AddGlobal(global_type); | 1638 module_env.AddGlobal(global_type); |
1637 if (local_type == global_type) { | 1639 if (local_type == global_type) { |
1638 EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); | 1640 EXPECT_VERIFIES_S(&sig, WASM_GET_GLOBAL(0)); |
1639 } else { | 1641 } else { |
1640 EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); | 1642 EXPECT_FAILURE_S(&sig, WASM_GET_GLOBAL(0)); |
1641 } | 1643 } |
1642 } | 1644 } |
1643 } | 1645 } |
1644 } | 1646 } |
1645 | 1647 |
1646 TEST_F(FunctionBodyDecoderTest, AllSetGlobalCombinations) { | 1648 TEST_F(FunctionBodyDecoderTest, AllSetGlobalCombinations) { |
1647 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1649 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1648 LocalType local_type = kLocalTypes[i]; | 1650 ValueType local_type = kValueTypes[i]; |
1649 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1651 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1650 LocalType global_type = kLocalTypes[j]; | 1652 ValueType global_type = kValueTypes[j]; |
1651 FunctionSig sig(0, 1, &local_type); | 1653 FunctionSig sig(0, 1, &local_type); |
1652 TestModuleEnv module_env; | 1654 TestModuleEnv module_env; |
1653 module = &module_env; | 1655 module = &module_env; |
1654 module_env.AddGlobal(global_type); | 1656 module_env.AddGlobal(global_type); |
1655 if (local_type == global_type) { | 1657 if (local_type == global_type) { |
1656 EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1658 EXPECT_VERIFIES_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1657 } else { | 1659 } else { |
1658 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1660 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1659 } | 1661 } |
1660 } | 1662 } |
(...skipping 11 matching lines...) Expand all Loading... |
1672 | 1674 |
1673 TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) { | 1675 TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) { |
1674 TestModuleEnv module_env(kAsmJsOrigin); | 1676 TestModuleEnv module_env(kAsmJsOrigin); |
1675 module = &module_env; | 1677 module = &module_env; |
1676 | 1678 |
1677 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; | 1679 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; |
1678 EXPECT_FAILURE_C(i_i, code); | 1680 EXPECT_FAILURE_C(i_i, code); |
1679 } | 1681 } |
1680 | 1682 |
1681 TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { | 1683 TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { |
1682 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; | 1684 ValueType float32int32float32[] = {kWasmF32, kWasmI32, kWasmF32}; |
1683 FunctionSig sig_f_if(1, 2, float32int32float32); | 1685 FunctionSig sig_f_if(1, 2, float32int32float32); |
1684 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; | 1686 ValueType float64int32float64[] = {kWasmF64, kWasmI32, kWasmF64}; |
1685 FunctionSig sig_d_id(1, 2, float64int32float64); | 1687 FunctionSig sig_d_id(1, 2, float64int32float64); |
1686 struct { | 1688 struct { |
1687 WasmOpcode op; | 1689 WasmOpcode op; |
1688 FunctionSig* sig; | 1690 FunctionSig* sig; |
1689 } AsmJsBinOps[] = { | 1691 } AsmJsBinOps[] = { |
1690 {kExprF64Atan2, sigs.d_dd()}, | 1692 {kExprF64Atan2, sigs.d_dd()}, |
1691 {kExprF64Pow, sigs.d_dd()}, | 1693 {kExprF64Pow, sigs.d_dd()}, |
1692 {kExprF64Mod, sigs.d_dd()}, | 1694 {kExprF64Mod, sigs.d_dd()}, |
1693 {kExprI32AsmjsDivS, sigs.i_ii()}, | 1695 {kExprI32AsmjsDivS, sigs.i_ii()}, |
1694 {kExprI32AsmjsDivU, sigs.i_ii()}, | 1696 {kExprI32AsmjsDivU, sigs.i_ii()}, |
(...skipping 19 matching lines...) Expand all Loading... |
1714 module = &module_env; | 1716 module = &module_env; |
1715 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { | 1717 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { |
1716 byte code[] = { | 1718 byte code[] = { |
1717 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 1719 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
1718 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); | 1720 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); |
1719 } | 1721 } |
1720 } | 1722 } |
1721 } | 1723 } |
1722 | 1724 |
1723 TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { | 1725 TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { |
1724 LocalType float32int32[] = {kAstF32, kAstI32}; | 1726 ValueType float32int32[] = {kWasmF32, kWasmI32}; |
1725 FunctionSig sig_f_i(1, 1, float32int32); | 1727 FunctionSig sig_f_i(1, 1, float32int32); |
1726 LocalType float64int32[] = {kAstF64, kAstI32}; | 1728 ValueType float64int32[] = {kWasmF64, kWasmI32}; |
1727 FunctionSig sig_d_i(1, 1, float64int32); | 1729 FunctionSig sig_d_i(1, 1, float64int32); |
1728 struct { | 1730 struct { |
1729 WasmOpcode op; | 1731 WasmOpcode op; |
1730 FunctionSig* sig; | 1732 FunctionSig* sig; |
1731 } AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()}, | 1733 } AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()}, |
1732 {kExprF64Asin, sigs.d_d()}, | 1734 {kExprF64Asin, sigs.d_d()}, |
1733 {kExprF64Atan, sigs.d_d()}, | 1735 {kExprF64Atan, sigs.d_d()}, |
1734 {kExprF64Cos, sigs.d_d()}, | 1736 {kExprF64Cos, sigs.d_d()}, |
1735 {kExprF64Sin, sigs.d_d()}, | 1737 {kExprF64Sin, sigs.d_d()}, |
1736 {kExprF64Tan, sigs.d_d()}, | 1738 {kExprF64Tan, sigs.d_d()}, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), | 1886 EXPECT_FAILURE(i_i, WASM_BLOCK_I(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), |
1885 WASM_F32(1.2))); | 1887 WASM_F32(1.2))); |
1886 | 1888 |
1887 // unify f64 and f64 => OK | 1889 // unify f64 and f64 => OK |
1888 EXPECT_VERIFIES( | 1890 EXPECT_VERIFIES( |
1889 d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1891 d_dd, WASM_BLOCK_D(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1890 WASM_F64(1.2))); | 1892 WASM_F64(1.2))); |
1891 } | 1893 } |
1892 | 1894 |
1893 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { | 1895 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll1) { |
1894 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1896 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1895 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1897 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1896 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1898 ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; |
1897 FunctionSig sig(1, 2, storage); | 1899 FunctionSig sig(1, 2, storage); |
1898 byte code[] = {WASM_BLOCK_T( | 1900 byte code[] = {WASM_BLOCK_T( |
1899 sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), | 1901 sig.GetReturn(), WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), |
1900 WASM_GET_LOCAL(1))}; | 1902 WASM_GET_LOCAL(1))}; |
1901 | 1903 |
1902 if (i == j) { | 1904 if (i == j) { |
1903 EXPECT_VERIFIES_SC(&sig, code); | 1905 EXPECT_VERIFIES_SC(&sig, code); |
1904 } else { | 1906 } else { |
1905 EXPECT_FAILURE_SC(&sig, code); | 1907 EXPECT_FAILURE_SC(&sig, code); |
1906 } | 1908 } |
1907 } | 1909 } |
1908 } | 1910 } |
1909 } | 1911 } |
1910 | 1912 |
1911 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { | 1913 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll2) { |
1912 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1914 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1913 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1915 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1914 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1916 ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; |
1915 FunctionSig sig(1, 2, storage); | 1917 FunctionSig sig(1, 2, storage); |
1916 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, | 1918 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(0), WASM_ZERO, |
1917 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), | 1919 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)), |
1918 WASM_GET_LOCAL(1))}; | 1920 WASM_GET_LOCAL(1))}; |
1919 | 1921 |
1920 if (i == j) { | 1922 if (i == j) { |
1921 EXPECT_VERIFIES_SC(&sig, code); | 1923 EXPECT_VERIFIES_SC(&sig, code); |
1922 } else { | 1924 } else { |
1923 EXPECT_FAILURE_SC(&sig, code); | 1925 EXPECT_FAILURE_SC(&sig, code); |
1924 } | 1926 } |
1925 } | 1927 } |
1926 } | 1928 } |
1927 } | 1929 } |
1928 | 1930 |
1929 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) { | 1931 TEST_F(FunctionBodyDecoderTest, Break_TypeCheckAll3) { |
1930 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1932 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1931 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1933 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1932 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1934 ValueType storage[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; |
1933 FunctionSig sig(1, 2, storage); | 1935 FunctionSig sig(1, 2, storage); |
1934 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, | 1936 byte code[] = {WASM_IF_ELSE_T(sig.GetReturn(), WASM_ZERO, |
1935 WASM_GET_LOCAL(1), | 1937 WASM_GET_LOCAL(1), |
1936 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; | 1938 WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0)))}; |
1937 | 1939 |
1938 if (i == j) { | 1940 if (i == j) { |
1939 EXPECT_VERIFIES_SC(&sig, code); | 1941 EXPECT_VERIFIES_SC(&sig, code); |
1940 } else { | 1942 } else { |
1941 EXPECT_FAILURE_SC(&sig, code); | 1943 EXPECT_FAILURE_SC(&sig, code); |
1942 } | 1944 } |
1943 } | 1945 } |
1944 } | 1946 } |
1945 } | 1947 } |
1946 | 1948 |
1947 TEST_F(FunctionBodyDecoderTest, Break_Unify) { | 1949 TEST_F(FunctionBodyDecoderTest, Break_Unify) { |
1948 for (int which = 0; which < 2; which++) { | 1950 for (int which = 0; which < 2; which++) { |
1949 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1951 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1950 LocalType type = kLocalTypes[i]; | 1952 ValueType type = kValueTypes[i]; |
1951 LocalType storage[] = {kAstI32, kAstI32, type}; | 1953 ValueType storage[] = {kWasmI32, kWasmI32, type}; |
1952 FunctionSig sig(1, 2, storage); | 1954 FunctionSig sig(1, 2, storage); |
1953 | 1955 |
1954 byte code1[] = {WASM_BLOCK_T( | 1956 byte code1[] = {WASM_BLOCK_T( |
1955 type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), | 1957 type, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), |
1956 WASM_GET_LOCAL(which ^ 1))}; | 1958 WASM_GET_LOCAL(which ^ 1))}; |
1957 | 1959 |
1958 if (type == kAstI32) { | 1960 if (type == kWasmI32) { |
1959 EXPECT_VERIFIES_SC(&sig, code1); | 1961 EXPECT_VERIFIES_SC(&sig, code1); |
1960 } else { | 1962 } else { |
1961 EXPECT_FAILURE_SC(&sig, code1); | 1963 EXPECT_FAILURE_SC(&sig, code1); |
1962 } | 1964 } |
1963 } | 1965 } |
1964 } | 1966 } |
1965 } | 1967 } |
1966 | 1968 |
1967 TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { | 1969 TEST_F(FunctionBodyDecoderTest, BreakIf_cond_type) { |
1968 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1970 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1969 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1971 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1970 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; | 1972 ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j]}; |
1971 FunctionSig sig(1, 2, types); | 1973 FunctionSig sig(1, 2, types); |
1972 byte code[] = {WASM_BLOCK_T( | 1974 byte code[] = {WASM_BLOCK_T( |
1973 types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; | 1975 types[0], WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))}; |
1974 | 1976 |
1975 if (types[2] == kAstI32) { | 1977 if (types[2] == kWasmI32) { |
1976 EXPECT_VERIFIES_SC(&sig, code); | 1978 EXPECT_VERIFIES_SC(&sig, code); |
1977 } else { | 1979 } else { |
1978 EXPECT_FAILURE_SC(&sig, code); | 1980 EXPECT_FAILURE_SC(&sig, code); |
1979 } | 1981 } |
1980 } | 1982 } |
1981 } | 1983 } |
1982 } | 1984 } |
1983 | 1985 |
1984 TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) { | 1986 TEST_F(FunctionBodyDecoderTest, BreakIf_val_type) { |
1985 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 1987 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1986 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { | 1988 for (size_t j = 0; j < arraysize(kValueTypes); j++) { |
1987 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], | 1989 ValueType types[] = {kValueTypes[i], kValueTypes[i], kValueTypes[j], |
1988 kAstI32}; | 1990 kWasmI32}; |
1989 FunctionSig sig(1, 3, types); | 1991 FunctionSig sig(1, 3, types); |
1990 byte code[] = {WASM_BLOCK_T( | 1992 byte code[] = {WASM_BLOCK_T( |
1991 types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), | 1993 types[1], WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), |
1992 WASM_DROP, WASM_GET_LOCAL(0))}; | 1994 WASM_DROP, WASM_GET_LOCAL(0))}; |
1993 | 1995 |
1994 if (i == j) { | 1996 if (i == j) { |
1995 EXPECT_VERIFIES_SC(&sig, code); | 1997 EXPECT_VERIFIES_SC(&sig, code); |
1996 } else { | 1998 } else { |
1997 EXPECT_FAILURE_SC(&sig, code); | 1999 EXPECT_FAILURE_SC(&sig, code); |
1998 } | 2000 } |
1999 } | 2001 } |
2000 } | 2002 } |
2001 } | 2003 } |
2002 | 2004 |
2003 TEST_F(FunctionBodyDecoderTest, BreakIf_Unify) { | 2005 TEST_F(FunctionBodyDecoderTest, BreakIf_Unify) { |
2004 for (int which = 0; which < 2; which++) { | 2006 for (int which = 0; which < 2; which++) { |
2005 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2007 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
2006 LocalType type = kLocalTypes[i]; | 2008 ValueType type = kValueTypes[i]; |
2007 LocalType storage[] = {kAstI32, kAstI32, type}; | 2009 ValueType storage[] = {kWasmI32, kWasmI32, type}; |
2008 FunctionSig sig(1, 2, storage); | 2010 FunctionSig sig(1, 2, storage); |
2009 byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), | 2011 byte code[] = {WASM_BLOCK_I(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), |
2010 WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; | 2012 WASM_DROP, WASM_GET_LOCAL(which ^ 1))}; |
2011 | 2013 |
2012 if (type == kAstI32) { | 2014 if (type == kWasmI32) { |
2013 EXPECT_VERIFIES_SC(&sig, code); | 2015 EXPECT_VERIFIES_SC(&sig, code); |
2014 } else { | 2016 } else { |
2015 EXPECT_FAILURE_SC(&sig, code); | 2017 EXPECT_FAILURE_SC(&sig, code); |
2016 } | 2018 } |
2017 } | 2019 } |
2018 } | 2020 } |
2019 } | 2021 } |
2020 | 2022 |
2021 TEST_F(FunctionBodyDecoderTest, BrTable0) { | 2023 TEST_F(FunctionBodyDecoderTest, BrTable0) { |
2022 static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; | 2024 static byte code[] = {kExprBrTable, 0, BR_TARGET(0)}; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2134 TEST_F(FunctionBodyDecoderTest, Select_fail1) { | 2136 TEST_F(FunctionBodyDecoderTest, Select_fail1) { |
2135 EXPECT_FAILURE( | 2137 EXPECT_FAILURE( |
2136 i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); | 2138 i_i, WASM_SELECT(WASM_F32(0.0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))); |
2137 EXPECT_FAILURE( | 2139 EXPECT_FAILURE( |
2138 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); | 2140 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_F32(0.0), WASM_GET_LOCAL(0))); |
2139 EXPECT_FAILURE( | 2141 EXPECT_FAILURE( |
2140 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); | 2142 i_i, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_F32(0.0))); |
2141 } | 2143 } |
2142 | 2144 |
2143 TEST_F(FunctionBodyDecoderTest, Select_fail2) { | 2145 TEST_F(FunctionBodyDecoderTest, Select_fail2) { |
2144 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2146 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
2145 LocalType type = kLocalTypes[i]; | 2147 ValueType type = kValueTypes[i]; |
2146 if (type == kAstI32) continue; | 2148 if (type == kWasmI32) continue; |
2147 | 2149 |
2148 LocalType types[] = {type, kAstI32, type}; | 2150 ValueType types[] = {type, kWasmI32, type}; |
2149 FunctionSig sig(1, 2, types); | 2151 FunctionSig sig(1, 2, types); |
2150 | 2152 |
2151 EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), | 2153 EXPECT_VERIFIES_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(1), |
2152 WASM_GET_LOCAL(0))); | 2154 WASM_GET_LOCAL(0))); |
2153 | 2155 |
2154 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), | 2156 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0), |
2155 WASM_GET_LOCAL(0))); | 2157 WASM_GET_LOCAL(0))); |
2156 | 2158 |
2157 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), | 2159 EXPECT_FAILURE_S(&sig, WASM_SELECT(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), |
2158 WASM_GET_LOCAL(0))); | 2160 WASM_GET_LOCAL(0))); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 | 2197 |
2196 // Missing end. | 2198 // Missing end. |
2197 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); | 2199 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0)); |
2198 | 2200 |
2199 // Double catch. | 2201 // Double catch. |
2200 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); | 2202 EXPECT_FAILURE(v_i, WASM_TRY_OP, WASM_CATCH(0), WASM_CATCH(0), kExprEnd); |
2201 } | 2203 } |
2202 | 2204 |
2203 TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { | 2205 TEST_F(FunctionBodyDecoderTest, MultiValBlock1) { |
2204 FLAG_wasm_mv_prototype = true; | 2206 FLAG_wasm_mv_prototype = true; |
2205 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2207 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2206 WASM_GET_LOCAL(1)), | 2208 WASM_GET_LOCAL(1)), |
2207 kExprI32Add); | 2209 kExprI32Add); |
2208 } | 2210 } |
2209 | 2211 |
2210 TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { | 2212 TEST_F(FunctionBodyDecoderTest, MultiValBlock2) { |
2211 FLAG_wasm_mv_prototype = true; | 2213 FLAG_wasm_mv_prototype = true; |
2212 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2214 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2213 WASM_GET_LOCAL(1)), | 2215 WASM_GET_LOCAL(1)), |
2214 WASM_I32_ADD(WASM_NOP, WASM_NOP)); | 2216 WASM_I32_ADD(WASM_NOP, WASM_NOP)); |
2215 } | 2217 } |
2216 | 2218 |
2217 TEST_F(FunctionBodyDecoderTest, MultiValBlockBr1) { | 2219 TEST_F(FunctionBodyDecoderTest, MultiValBlockBr1) { |
2218 FLAG_wasm_mv_prototype = true; | 2220 FLAG_wasm_mv_prototype = true; |
2219 EXPECT_FAILURE(i_ii, | 2221 EXPECT_FAILURE( |
2220 WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), WASM_BR(0)), | 2222 i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), WASM_BR(0)), |
2221 kExprI32Add); | 2223 kExprI32Add); |
2222 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2224 EXPECT_VERIFIES(i_ii, WASM_BLOCK_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2223 WASM_GET_LOCAL(1), WASM_BR(0)), | 2225 WASM_GET_LOCAL(1), WASM_BR(0)), |
2224 kExprI32Add); | 2226 kExprI32Add); |
2225 } | 2227 } |
2226 | 2228 |
2227 TEST_F(FunctionBodyDecoderTest, MultiValIf1) { | 2229 TEST_F(FunctionBodyDecoderTest, MultiValIf1) { |
2228 FLAG_wasm_mv_prototype = true; | 2230 FLAG_wasm_mv_prototype = true; |
2229 EXPECT_FAILURE( | 2231 EXPECT_FAILURE( |
2230 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2232 i_ii, WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2231 WASM_SEQ(WASM_GET_LOCAL(0)), | 2233 WASM_SEQ(WASM_GET_LOCAL(0)), |
2232 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), | 2234 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
2233 kExprI32Add); | 2235 kExprI32Add); |
2234 EXPECT_FAILURE(i_ii, | 2236 EXPECT_FAILURE(i_ii, |
2235 WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2237 WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2236 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), | 2238 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
2237 WASM_SEQ(WASM_GET_LOCAL(1))), | 2239 WASM_SEQ(WASM_GET_LOCAL(1))), |
2238 kExprI32Add); | 2240 kExprI32Add); |
2239 EXPECT_VERIFIES( | 2241 EXPECT_VERIFIES( |
2240 i_ii, WASM_IF_ELSE_TT(kAstI32, kAstI32, WASM_GET_LOCAL(0), | 2242 i_ii, WASM_IF_ELSE_TT(kWasmI32, kWasmI32, WASM_GET_LOCAL(0), |
2241 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), | 2243 WASM_SEQ(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), |
2242 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), | 2244 WASM_SEQ(WASM_GET_LOCAL(1), WASM_GET_LOCAL(0))), |
2243 kExprI32Add); | 2245 kExprI32Add); |
2244 } | 2246 } |
2245 | 2247 |
2246 class BranchTableIteratorTest : public TestWithZone { | 2248 class BranchTableIteratorTest : public TestWithZone { |
2247 public: | 2249 public: |
2248 BranchTableIteratorTest() : TestWithZone() {} | 2250 BranchTableIteratorTest() : TestWithZone() {} |
2249 void CheckBrTableSize(const byte* start, const byte* end) { | 2251 void CheckBrTableSize(const byte* start, const byte* end) { |
2250 Decoder decoder(start, end); | 2252 Decoder decoder(start, end); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD) | 2538 FOREACH_SIMD_0_OPERAND_OPCODE(TEST_SIMD) |
2537 #undef TEST_SIMD | 2539 #undef TEST_SIMD |
2538 #define TEST_SIMD(name, opcode, sig) \ | 2540 #define TEST_SIMD(name, opcode, sig) \ |
2539 EXPECT_LENGTH_N(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff)); | 2541 EXPECT_LENGTH_N(3, kSimdPrefix, static_cast<byte>(kExpr##name & 0xff)); |
2540 FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD) | 2542 FOREACH_SIMD_1_OPERAND_OPCODE(TEST_SIMD) |
2541 #undef TEST_SIMD | 2543 #undef TEST_SIMD |
2542 // test for bad simd opcode | 2544 // test for bad simd opcode |
2543 EXPECT_LENGTH_N(2, kSimdPrefix, 0xff); | 2545 EXPECT_LENGTH_N(2, kSimdPrefix, 0xff); |
2544 } | 2546 } |
2545 | 2547 |
2546 typedef ZoneVector<LocalType> LocalTypeMap; | 2548 typedef ZoneVector<ValueType> ValueTypeMap; |
2547 | 2549 |
2548 class LocalDeclDecoderTest : public TestWithZone { | 2550 class LocalDeclDecoderTest : public TestWithZone { |
2549 public: | 2551 public: |
2550 v8::internal::AccountingAllocator allocator; | 2552 v8::internal::AccountingAllocator allocator; |
2551 | 2553 |
2552 size_t ExpectRun(LocalTypeMap map, size_t pos, LocalType expected, | 2554 size_t ExpectRun(ValueTypeMap map, size_t pos, ValueType expected, |
2553 size_t count) { | 2555 size_t count) { |
2554 for (size_t i = 0; i < count; i++) { | 2556 for (size_t i = 0; i < count; i++) { |
2555 EXPECT_EQ(expected, map[pos++]); | 2557 EXPECT_EQ(expected, map[pos++]); |
2556 } | 2558 } |
2557 return pos; | 2559 return pos; |
2558 } | 2560 } |
2559 | 2561 |
2560 LocalTypeMap Expand(BodyLocalDecls& decls) { | 2562 ValueTypeMap Expand(BodyLocalDecls& decls) { |
2561 ZoneVector<LocalType> map(zone()); | 2563 ZoneVector<ValueType> map(zone()); |
2562 for (auto p : decls.local_types) { | 2564 for (auto p : decls.local_types) { |
2563 map.insert(map.end(), p.second, p.first); | 2565 map.insert(map.end(), p.second, p.first); |
2564 } | 2566 } |
2565 return map; | 2567 return map; |
2566 } | 2568 } |
2567 }; | 2569 }; |
2568 | 2570 |
2569 TEST_F(LocalDeclDecoderTest, EmptyLocals) { | 2571 TEST_F(LocalDeclDecoderTest, EmptyLocals) { |
2570 BodyLocalDecls decls(zone()); | 2572 BodyLocalDecls decls(zone()); |
2571 bool result = DecodeLocalDecls(decls, nullptr, nullptr); | 2573 bool result = DecodeLocalDecls(decls, nullptr, nullptr); |
2572 EXPECT_FALSE(result); | 2574 EXPECT_FALSE(result); |
2573 } | 2575 } |
2574 | 2576 |
2575 TEST_F(LocalDeclDecoderTest, NoLocals) { | 2577 TEST_F(LocalDeclDecoderTest, NoLocals) { |
2576 static const byte data[] = {0}; | 2578 static const byte data[] = {0}; |
2577 BodyLocalDecls decls(zone()); | 2579 BodyLocalDecls decls(zone()); |
2578 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2580 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2579 EXPECT_TRUE(result); | 2581 EXPECT_TRUE(result); |
2580 EXPECT_EQ(0u, decls.total_local_count); | 2582 EXPECT_EQ(0u, decls.total_local_count); |
2581 } | 2583 } |
2582 | 2584 |
2583 TEST_F(LocalDeclDecoderTest, OneLocal) { | 2585 TEST_F(LocalDeclDecoderTest, OneLocal) { |
2584 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2586 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
2585 LocalType type = kLocalTypes[i]; | 2587 ValueType type = kValueTypes[i]; |
2586 const byte data[] = { | 2588 const byte data[] = { |
2587 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; | 2589 1, 1, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))}; |
2588 BodyLocalDecls decls(zone()); | 2590 BodyLocalDecls decls(zone()); |
2589 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2591 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2590 EXPECT_TRUE(result); | 2592 EXPECT_TRUE(result); |
2591 EXPECT_EQ(1u, decls.total_local_count); | 2593 EXPECT_EQ(1u, decls.total_local_count); |
2592 | 2594 |
2593 LocalTypeMap map = Expand(decls); | 2595 ValueTypeMap map = Expand(decls); |
2594 EXPECT_EQ(1u, map.size()); | 2596 EXPECT_EQ(1u, map.size()); |
2595 EXPECT_EQ(type, map[0]); | 2597 EXPECT_EQ(type, map[0]); |
2596 } | 2598 } |
2597 } | 2599 } |
2598 | 2600 |
2599 TEST_F(LocalDeclDecoderTest, FiveLocals) { | 2601 TEST_F(LocalDeclDecoderTest, FiveLocals) { |
2600 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { | 2602 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
2601 LocalType type = kLocalTypes[i]; | 2603 ValueType type = kValueTypes[i]; |
2602 const byte data[] = { | 2604 const byte data[] = { |
2603 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; | 2605 1, 5, static_cast<byte>(WasmOpcodes::ValueTypeCodeFor(type))}; |
2604 BodyLocalDecls decls(zone()); | 2606 BodyLocalDecls decls(zone()); |
2605 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2607 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2606 EXPECT_TRUE(result); | 2608 EXPECT_TRUE(result); |
2607 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); | 2609 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); |
2608 EXPECT_EQ(5u, decls.total_local_count); | 2610 EXPECT_EQ(5u, decls.total_local_count); |
2609 | 2611 |
2610 LocalTypeMap map = Expand(decls); | 2612 ValueTypeMap map = Expand(decls); |
2611 EXPECT_EQ(5u, map.size()); | 2613 EXPECT_EQ(5u, map.size()); |
2612 ExpectRun(map, 0, type, 5); | 2614 ExpectRun(map, 0, type, 5); |
2613 } | 2615 } |
2614 } | 2616 } |
2615 | 2617 |
2616 TEST_F(LocalDeclDecoderTest, MixedLocals) { | 2618 TEST_F(LocalDeclDecoderTest, MixedLocals) { |
2617 for (byte a = 0; a < 3; a++) { | 2619 for (byte a = 0; a < 3; a++) { |
2618 for (byte b = 0; b < 3; b++) { | 2620 for (byte b = 0; b < 3; b++) { |
2619 for (byte c = 0; c < 3; c++) { | 2621 for (byte c = 0; c < 3; c++) { |
2620 for (byte d = 0; d < 3; d++) { | 2622 for (byte d = 0; d < 3; d++) { |
2621 const byte data[] = {4, a, kLocalI32, b, kLocalI64, | 2623 const byte data[] = {4, a, kLocalI32, b, kLocalI64, |
2622 c, kLocalF32, d, kLocalF64}; | 2624 c, kLocalF32, d, kLocalF64}; |
2623 BodyLocalDecls decls(zone()); | 2625 BodyLocalDecls decls(zone()); |
2624 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); | 2626 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); |
2625 EXPECT_TRUE(result); | 2627 EXPECT_TRUE(result); |
2626 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); | 2628 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); |
2627 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), | 2629 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), |
2628 decls.total_local_count); | 2630 decls.total_local_count); |
2629 | 2631 |
2630 LocalTypeMap map = Expand(decls); | 2632 ValueTypeMap map = Expand(decls); |
2631 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), map.size()); | 2633 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), map.size()); |
2632 | 2634 |
2633 size_t pos = 0; | 2635 size_t pos = 0; |
2634 pos = ExpectRun(map, pos, kAstI32, a); | 2636 pos = ExpectRun(map, pos, kWasmI32, a); |
2635 pos = ExpectRun(map, pos, kAstI64, b); | 2637 pos = ExpectRun(map, pos, kWasmI64, b); |
2636 pos = ExpectRun(map, pos, kAstF32, c); | 2638 pos = ExpectRun(map, pos, kWasmF32, c); |
2637 pos = ExpectRun(map, pos, kAstF64, d); | 2639 pos = ExpectRun(map, pos, kWasmF64, d); |
2638 } | 2640 } |
2639 } | 2641 } |
2640 } | 2642 } |
2641 } | 2643 } |
2642 } | 2644 } |
2643 | 2645 |
2644 TEST_F(LocalDeclDecoderTest, UseEncoder) { | 2646 TEST_F(LocalDeclDecoderTest, UseEncoder) { |
2645 const byte* data = nullptr; | 2647 const byte* data = nullptr; |
2646 const byte* end = nullptr; | 2648 const byte* end = nullptr; |
2647 LocalDeclEncoder local_decls(zone()); | 2649 LocalDeclEncoder local_decls(zone()); |
2648 | 2650 |
2649 local_decls.AddLocals(5, kAstF32); | 2651 local_decls.AddLocals(5, kWasmF32); |
2650 local_decls.AddLocals(1337, kAstI32); | 2652 local_decls.AddLocals(1337, kWasmI32); |
2651 local_decls.AddLocals(212, kAstI64); | 2653 local_decls.AddLocals(212, kWasmI64); |
2652 local_decls.Prepend(zone(), &data, &end); | 2654 local_decls.Prepend(zone(), &data, &end); |
2653 | 2655 |
2654 BodyLocalDecls decls(zone()); | 2656 BodyLocalDecls decls(zone()); |
2655 bool result = DecodeLocalDecls(decls, data, end); | 2657 bool result = DecodeLocalDecls(decls, data, end); |
2656 EXPECT_TRUE(result); | 2658 EXPECT_TRUE(result); |
2657 EXPECT_EQ(5u + 1337u + 212u, decls.total_local_count); | 2659 EXPECT_EQ(5u + 1337u + 212u, decls.total_local_count); |
2658 | 2660 |
2659 LocalTypeMap map = Expand(decls); | 2661 ValueTypeMap map = Expand(decls); |
2660 size_t pos = 0; | 2662 size_t pos = 0; |
2661 pos = ExpectRun(map, pos, kAstF32, 5); | 2663 pos = ExpectRun(map, pos, kWasmF32, 5); |
2662 pos = ExpectRun(map, pos, kAstI32, 1337); | 2664 pos = ExpectRun(map, pos, kWasmI32, 1337); |
2663 pos = ExpectRun(map, pos, kAstI64, 212); | 2665 pos = ExpectRun(map, pos, kWasmI64, 212); |
2664 } | 2666 } |
2665 | 2667 |
2666 class BytecodeIteratorTest : public TestWithZone {}; | 2668 class BytecodeIteratorTest : public TestWithZone {}; |
2667 | 2669 |
2668 TEST_F(BytecodeIteratorTest, SimpleForeach) { | 2670 TEST_F(BytecodeIteratorTest, SimpleForeach) { |
2669 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; | 2671 byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)}; |
2670 BytecodeIterator iter(code, code + sizeof(code)); | 2672 BytecodeIterator iter(code, code + sizeof(code)); |
2671 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, | 2673 WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const, |
2672 kExprElse, kExprI8Const, kExprEnd}; | 2674 kExprElse, kExprI8Const, kExprEnd}; |
2673 size_t pos = 0; | 2675 size_t pos = 0; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2733 iter.next(); | 2735 iter.next(); |
2734 EXPECT_TRUE(iter.has_next()); | 2736 EXPECT_TRUE(iter.has_next()); |
2735 EXPECT_EQ(kExprI8Const, iter.current()); | 2737 EXPECT_EQ(kExprI8Const, iter.current()); |
2736 iter.next(); | 2738 iter.next(); |
2737 EXPECT_FALSE(iter.has_next()); | 2739 EXPECT_FALSE(iter.has_next()); |
2738 } | 2740 } |
2739 | 2741 |
2740 } // namespace wasm | 2742 } // namespace wasm |
2741 } // namespace internal | 2743 } // namespace internal |
2742 } // namespace v8 | 2744 } // namespace v8 |
OLD | NEW |