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

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

Issue 1830663002: [wasm] Binary 11: AST changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
11 #include "src/objects.h" 11 #include "src/objects.h"
12 12
13 #include "src/wasm/ast-decoder.h" 13 #include "src/wasm/ast-decoder.h"
14 #include "src/wasm/wasm-macro-gen.h" 14 #include "src/wasm/wasm-macro-gen.h"
15 #include "src/wasm/wasm-module.h" 15 #include "src/wasm/wasm-module.h"
16 16
17 namespace v8 { 17 namespace v8 {
18 namespace internal { 18 namespace internal {
19 namespace wasm { 19 namespace wasm {
20 20
21 #define B1(a) kExprBlock, a, kExprEnd
22 #define B2(a, b) kExprBlock, a, b, kExprEnd
23 #define B3(a, b, c) kExprBlock, a, b, c, kExprEnd
24
21 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; 25 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0};
22 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1}; 26 static const byte kCodeGetLocal1[] = {kExprGetLocal, 1};
23 static const byte kCodeSetLocal0[] = {kExprSetLocal, 0, kExprI8Const, 0}; 27 static const byte kCodeSetLocal0[] = {WASM_SET_LOCAL(0, WASM_ZERO)};
24 28
25 static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64}; 29 static const LocalType kLocalTypes[] = {kAstI32, kAstI64, kAstF32, kAstF64};
26 static const MachineType machineTypes[] = { 30 static const MachineType machineTypes[] = {
27 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), 31 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
28 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 32 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
29 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), 33 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
30 MachineType::Float64()}; 34 MachineType::Float64()};
31 35
32 static const WasmOpcode kInt32BinopOpcodes[] = { 36 static const WasmOpcode kInt32BinopOpcodes[] = {
33 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU, 37 kExprI32Add, kExprI32Sub, kExprI32Mul, kExprI32DivS, kExprI32DivU,
34 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor, 38 kExprI32RemS, kExprI32RemU, kExprI32And, kExprI32Ior, kExprI32Xor,
35 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS, 39 kExprI32Shl, kExprI32ShrU, kExprI32ShrS, kExprI32Eq, kExprI32LtS,
36 kExprI32LeS, kExprI32LtU, kExprI32LeU}; 40 kExprI32LeS, kExprI32LtU, kExprI32LeU};
37 41
38 #define WASM_BRV_IF_ZERO(depth, val) \ 42 #define WASM_BRV_IF_ZERO(depth, val) \
39 kExprBrIf, static_cast<byte>(depth), val, WASM_ZERO 43 val, WASM_ZERO, kExprBrIf, ARITY_1, static_cast<byte>(depth)
40 44
41 #define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x)) 45 #define EXPECT_VERIFIES(env, x) Verify(kSuccess, env, x, x + arraysize(x))
42 46
43 #define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x)) 47 #define EXPECT_FAILURE(env, x) Verify(kError, env, x, x + arraysize(x))
44 48
45 #define EXPECT_VERIFIES_INLINE(env, ...) \ 49 #define EXPECT_VERIFIES_INLINE(env, ...) \
46 do { \ 50 do { \
47 static byte code[] = {__VA_ARGS__}; \ 51 static byte code[] = {__VA_ARGS__}; \
48 Verify(kSuccess, env, code, code + arraysize(code)); \ 52 Verify(kSuccess, env, code, code + arraysize(code)); \
49 } while (false) 53 } while (false)
(...skipping 17 matching lines...) Expand all
67 71
68 AstDecoderTest() : module(nullptr) {} 72 AstDecoderTest() : module(nullptr) {}
69 TestSignatures sigs; 73 TestSignatures sigs;
70 ModuleEnv* module; 74 ModuleEnv* module;
71 LocalDeclEncoder local_decls; 75 LocalDeclEncoder local_decls;
72 76
73 void AddLocals(LocalType type, uint32_t count) { 77 void AddLocals(LocalType type, uint32_t count) {
74 local_decls.AddLocals(count, type); 78 local_decls.AddLocals(count, type);
75 } 79 }
76 80
77 // Preprends local variable declarations and renders nice error messages for 81 // Prepends local variable declarations and renders nice error messages for
78 // verification failures. 82 // verification failures.
79 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, 83 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
80 const byte* end) { 84 const byte* end) {
81 local_decls.Prepend(&start, &end); 85 local_decls.Prepend(&start, &end);
82 // Verify the code. 86 // Verify the code.
83 TreeResult result = 87 TreeResult result =
84 VerifyWasmCode(zone()->allocator(), module, sig, start, end); 88 VerifyWasmCode(zone()->allocator(), module, sig, start, end);
85 89
86 if (result.error_code != expected) { 90 if (result.error_code != expected) {
87 ptrdiff_t pc = result.error_pc - result.start; 91 ptrdiff_t pc = result.error_pc - result.start;
(...skipping 12 matching lines...) Expand all
100 } 104 }
101 } 105 }
102 FATAL(str.str().c_str()); 106 FATAL(str.str().c_str());
103 } 107 }
104 108
105 delete[] start; // local_decls.Prepend() allocated a new buffer. 109 delete[] start; // local_decls.Prepend() allocated a new buffer.
106 } 110 }
107 111
108 void TestBinop(WasmOpcode opcode, FunctionSig* success) { 112 void TestBinop(WasmOpcode opcode, FunctionSig* success) {
109 // op(local[0], local[1]) 113 // op(local[0], local[1])
110 byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0, kExprGetLocal, 114 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
111 1};
112 EXPECT_VERIFIES(success, code); 115 EXPECT_VERIFIES(success, code);
113 116
114 // Try all combinations of return and parameter types. 117 // Try all combinations of return and parameter types.
115 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 118 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
116 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 119 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
117 for (size_t k = 0; k < arraysize(kLocalTypes); k++) { 120 for (size_t k = 0; k < arraysize(kLocalTypes); k++) {
118 LocalType types[] = {kLocalTypes[i], kLocalTypes[j], kLocalTypes[k]}; 121 LocalType types[] = {kLocalTypes[i], kLocalTypes[j], kLocalTypes[k]};
119 if (types[0] != success->GetReturn(0) || 122 if (types[0] != success->GetReturn(0) ||
120 types[1] != success->GetParam(0) || 123 types[1] != success->GetParam(0) ||
121 types[2] != success->GetParam(1)) { 124 types[2] != success->GetParam(1)) {
122 // Test signature mismatch. 125 // Test signature mismatch.
123 FunctionSig sig(1, 2, types); 126 FunctionSig sig(1, 2, types);
124 EXPECT_FAILURE(&sig, code); 127 EXPECT_FAILURE(&sig, code);
125 } 128 }
126 } 129 }
127 } 130 }
128 } 131 }
129 } 132 }
130 133
131 void TestUnop(WasmOpcode opcode, FunctionSig* success) { 134 void TestUnop(WasmOpcode opcode, FunctionSig* success) {
132 TestUnop(opcode, success->GetReturn(), success->GetParam(0)); 135 TestUnop(opcode, success->GetReturn(), success->GetParam(0));
133 } 136 }
134 137
135 void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) { 138 void TestUnop(WasmOpcode opcode, LocalType ret_type, LocalType param_type) {
136 // Return(op(local[0])) 139 // Return(op(local[0]))
137 byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0}; 140 byte code[] = {WASM_UNOP(opcode, WASM_GET_LOCAL(0))};
138 { 141 {
139 LocalType types[] = {ret_type, param_type}; 142 LocalType types[] = {ret_type, param_type};
140 FunctionSig sig(1, 1, types); 143 FunctionSig sig(1, 1, types);
141 EXPECT_VERIFIES(&sig, code); 144 EXPECT_VERIFIES(&sig, code);
142 } 145 }
143 146
144 // Try all combinations of return and parameter types. 147 // Try all combinations of return and parameter types.
145 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 148 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
146 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 149 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
147 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; 150 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]};
148 if (types[0] != ret_type || types[1] != param_type) { 151 if (types[0] != ret_type || types[1] != param_type) {
149 // Test signature mismatch. 152 // Test signature mismatch.
150 FunctionSig sig(1, 1, types); 153 FunctionSig sig(1, 1, types);
151 EXPECT_FAILURE(&sig, code); 154 EXPECT_FAILURE(&sig, code);
152 } 155 }
153 } 156 }
154 } 157 }
155 } 158 }
156 }; 159 };
157 160
158
159 TEST_F(AstDecoderTest, Int8Const) { 161 TEST_F(AstDecoderTest, Int8Const) {
160 byte code[] = {kExprI8Const, 0}; 162 byte code[] = {kExprI8Const, 0};
161 for (int i = -128; i < 128; i++) { 163 for (int i = -128; i < 128; i++) {
162 code[1] = static_cast<byte>(i); 164 code[1] = static_cast<byte>(i);
163 EXPECT_VERIFIES(sigs.i_i(), code); 165 EXPECT_VERIFIES(sigs.i_i(), code);
164 } 166 }
165 } 167 }
166 168
167 TEST_F(AstDecoderTest, EmptyFunction) { 169 TEST_F(AstDecoderTest, EmptyFunction) {
168 byte code[] = {0}; 170 byte code[] = {0};
169 Verify(kSuccess, sigs.v_v(), code, code); 171 Verify(kSuccess, sigs.v_v(), code, code);
170 Verify(kError, sigs.i_i(), code, code); 172 Verify(kError, sigs.i_i(), code, code);
171 } 173 }
172 174
173 TEST_F(AstDecoderTest, IncompleteIf1) { 175 TEST_F(AstDecoderTest, IncompleteIf1) {
174 byte code[] = {kExprIf}; 176 byte code[] = {kExprIf};
175 EXPECT_FAILURE(sigs.v_v(), code); 177 EXPECT_FAILURE(sigs.v_v(), code);
176 EXPECT_FAILURE(sigs.i_i(), code); 178 EXPECT_FAILURE(sigs.i_i(), code);
177 } 179 }
178 180
179 TEST_F(AstDecoderTest, IncompleteIf2) {
180 byte code[] = {kExprIf, kExprI8Const, 0};
181 EXPECT_FAILURE(sigs.v_v(), code);
182 EXPECT_FAILURE(sigs.i_i(), code);
183 }
184
185 TEST_F(AstDecoderTest, Int8Const_fallthru) { 181 TEST_F(AstDecoderTest, Int8Const_fallthru) {
186 byte code[] = {kExprI8Const, 0, kExprI8Const, 1}; 182 byte code[] = {kExprI8Const, 0, kExprI8Const, 1};
187 EXPECT_VERIFIES(sigs.i_i(), code); 183 EXPECT_VERIFIES(sigs.i_i(), code);
188 } 184 }
189 185
190 TEST_F(AstDecoderTest, Int32Const) { 186 TEST_F(AstDecoderTest, Int32Const) {
191 const int kInc = 4498211; 187 const int kInc = 4498211;
192 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) { 188 for (int32_t i = kMinInt; i < kMaxInt - kInc; i = i + kInc) {
193 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes. 189 // TODO(binji): expand test for other sized int32s; 1 through 5 bytes.
194 byte code[] = {WASM_I32V(i)}; 190 byte code[] = {WASM_I32V(i)};
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals + 1)); 292 EXPECT_FAILURE_INLINE(sigs.i_v(), kExprGetLocal, U32V_4(kMaxLocals + 1));
297 } 293 }
298 294
299 TEST_F(AstDecoderTest, Binops_off_end) { 295 TEST_F(AstDecoderTest, Binops_off_end) {
300 byte code1[] = {0}; // [opcode] 296 byte code1[] = {0}; // [opcode]
301 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 297 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
302 code1[0] = kInt32BinopOpcodes[i]; 298 code1[0] = kInt32BinopOpcodes[i];
303 EXPECT_FAILURE(sigs.i_i(), code1); 299 EXPECT_FAILURE(sigs.i_i(), code1);
304 } 300 }
305 301
306 byte code3[] = {0, kExprGetLocal, 0}; // [opcode] [expr] 302 byte code3[] = {kExprGetLocal, 0, 0}; // [expr] [opcode]
307 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 303 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
308 code3[0] = kInt32BinopOpcodes[i]; 304 code3[2] = kInt32BinopOpcodes[i];
309 EXPECT_FAILURE(sigs.i_i(), code3); 305 EXPECT_FAILURE(sigs.i_i(), code3);
310 } 306 }
311 307
312 byte code4[] = {0, kExprGetLocal, 0, 0}; // [opcode] [expr] [opcode] 308 byte code4[] = {kExprGetLocal, 0, 0, 0}; // [expr] [opcode] [opcode]
313 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) { 309 for (size_t i = 0; i < arraysize(kInt32BinopOpcodes); i++) {
314 code4[0] = kInt32BinopOpcodes[i]; 310 code4[1] = kInt32BinopOpcodes[i];
315 code4[3] = kInt32BinopOpcodes[i]; 311 code4[3] = kInt32BinopOpcodes[i];
316 EXPECT_FAILURE(sigs.i_i(), code4); 312 EXPECT_FAILURE(sigs.i_i(), code4);
317 } 313 }
318 } 314 }
319 315
320 316
321 //=================================================================== 317 //===================================================================
322 //== Statements 318 //== Statements
323 //=================================================================== 319 //===================================================================
324 TEST_F(AstDecoderTest, Nop) { 320 TEST_F(AstDecoderTest, Nop) {
325 static const byte code[] = {kExprNop}; 321 static const byte code[] = {kExprNop};
326 EXPECT_VERIFIES(sigs.v_v(), code); 322 EXPECT_VERIFIES(sigs.v_v(), code);
327 } 323 }
328 324
329 TEST_F(AstDecoderTest, SetLocal0_param) { 325 TEST_F(AstDecoderTest, SetLocal0_param) {
330 static const byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; 326 EXPECT_VERIFIES(sigs.i_i(), kCodeSetLocal0);
331 EXPECT_VERIFIES(sigs.i_i(), code); 327 EXPECT_FAILURE(sigs.f_ff(), kCodeSetLocal0);
328 EXPECT_FAILURE(sigs.d_dd(), kCodeSetLocal0);
332 } 329 }
333 330
334 TEST_F(AstDecoderTest, SetLocal0_local) { 331 TEST_F(AstDecoderTest, SetLocal0_local) {
335 byte code[] = {kExprSetLocal, 0, kExprI8Const, 0}; 332 EXPECT_FAILURE(sigs.i_v(), kCodeSetLocal0);
336 AddLocals(kAstI32, 1); 333 AddLocals(kAstI32, 1);
337 EXPECT_VERIFIES(sigs.i_v(), code); 334 EXPECT_VERIFIES(sigs.i_v(), kCodeSetLocal0);
338 } 335 }
339 336
340 TEST_F(AstDecoderTest, SetLocalN_local) { 337 TEST_F(AstDecoderTest, SetLocalN_local) {
341 for (byte i = 1; i < 8; i++) { 338 for (byte i = 1; i < 8; i++) {
342 AddLocals(kAstI32, 1); 339 AddLocals(kAstI32, 1);
343 for (byte j = 0; j < i; j++) { 340 for (byte j = 0; j < i; j++) {
344 byte code[] = {kExprSetLocal, j, kExprI8Const, i}; 341 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_SET_LOCAL(j, WASM_I8(i)));
345 EXPECT_VERIFIES(sigs.v_v(), code);
346 } 342 }
347 } 343 }
348 } 344 }
349 345
346 TEST_F(AstDecoderTest, BlockN) {
347 const int kMaxSize = 200;
348 byte buffer[kMaxSize + 2];
349
350 for (int i = 0; i <= kMaxSize; i++) {
351 memset(buffer, kExprNop, sizeof(buffer));
352 buffer[0] = kExprBlock;
353 buffer[i + 1] = kExprEnd;
354 Verify(kSuccess, sigs.v_i(), buffer, buffer + i + 2);
355 }
356 }
357
350 TEST_F(AstDecoderTest, Block0) { 358 TEST_F(AstDecoderTest, Block0) {
351 static const byte code[] = {kExprBlock, 0}; 359 static const byte code[] = {kExprBlock, kExprEnd};
352 EXPECT_VERIFIES(sigs.v_v(), code); 360 EXPECT_VERIFIES(sigs.v_v(), code);
361 EXPECT_FAILURE(sigs.i_i(), code);
353 } 362 }
354 363
355 TEST_F(AstDecoderTest, Block0_fallthru1) { 364 TEST_F(AstDecoderTest, Block0_fallthru1) {
356 static const byte code[] = {kExprBlock, 0, kExprBlock, 0}; 365 static const byte code[] = {kExprBlock, kExprBlock, kExprEnd, kExprEnd};
357 EXPECT_VERIFIES(sigs.v_v(), code); 366 EXPECT_VERIFIES(sigs.v_v(), code);
367 EXPECT_FAILURE(sigs.i_i(), code);
368 }
369
370 TEST_F(AstDecoderTest, Block0Block0) {
371 static const byte code[] = {kExprBlock, kExprEnd, kExprBlock, kExprEnd};
372 EXPECT_VERIFIES(sigs.v_v(), code);
373 EXPECT_FAILURE(sigs.i_i(), code);
374 }
375
376 TEST_F(AstDecoderTest, Block0_end_end) {
377 static const byte code[] = {kExprBlock, kExprEnd, kExprEnd};
378 EXPECT_FAILURE(sigs.v_v(), code);
358 } 379 }
359 380
360 TEST_F(AstDecoderTest, Block1) { 381 TEST_F(AstDecoderTest, Block1) {
361 static const byte code[] = {kExprBlock, 1, kExprSetLocal, 0, kExprI8Const, 0}; 382 byte code[] = {B1(WASM_SET_LOCAL(0, WASM_ZERO))};
362 EXPECT_VERIFIES(sigs.i_i(), code); 383 EXPECT_VERIFIES(sigs.i_i(), code);
363 } 384 EXPECT_VERIFIES(sigs.v_i(), code);
364 385 EXPECT_FAILURE(sigs.d_dd(), code);
365 TEST_F(AstDecoderTest, Block0_fallthru2) { 386 }
366 static const byte code[] = {kExprBlock, 0, kExprSetLocal, 0, kExprI8Const, 0}; 387
388 TEST_F(AstDecoderTest, Block1_i) {
389 byte code[] = {B1(WASM_ZERO)};
367 EXPECT_VERIFIES(sigs.i_i(), code); 390 EXPECT_VERIFIES(sigs.i_i(), code);
391 EXPECT_FAILURE(sigs.f_ff(), code);
392 EXPECT_FAILURE(sigs.d_dd(), code);
393 EXPECT_FAILURE(sigs.l_ll(), code);
394 }
395
396 TEST_F(AstDecoderTest, Block1_f) {
397 byte code[] = {B1(WASM_F32(0))};
398 EXPECT_FAILURE(sigs.i_i(), code);
399 EXPECT_VERIFIES(sigs.f_ff(), code);
400 EXPECT_FAILURE(sigs.d_dd(), code);
401 EXPECT_FAILURE(sigs.l_ll(), code);
402 }
403
404 TEST_F(AstDecoderTest, Block1_continue) {
405 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0)));
406 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(1)));
407 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(2)));
408 EXPECT_FAILURE_INLINE(sigs.v_v(), B1(WASM_BR(3)));
409 }
410
411 TEST_F(AstDecoderTest, Block1_br) {
412 EXPECT_FAILURE_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_1, DEPTH_0,
413 kExprEnd);
414 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprBlock, kExprBr, ARITY_0, DEPTH_0,
415 kExprEnd);
416 }
417
418 TEST_F(AstDecoderTest, Block2_br) {
419 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_NOP, WASM_BR(0)));
420 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_NOP));
421 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_BR(0)));
368 } 422 }
369 423
370 TEST_F(AstDecoderTest, Block2) { 424 TEST_F(AstDecoderTest, Block2) {
371 static const byte code[] = {kExprBlock, 2, // -- 425 EXPECT_VERIFIES_INLINE(sigs.i_i(),
372 kExprSetLocal, 0, kExprI8Const, 0, // -- 426 B2(WASM_NOP, WASM_SET_LOCAL(0, WASM_ZERO)));
373 kExprSetLocal, 0, kExprI8Const, 0}; // -- 427 EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP));
428 EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO),
429 WASM_SET_LOCAL(0, WASM_ZERO)));
430 }
431
432 TEST_F(AstDecoderTest, Block2b) {
433 byte code[] = {B2(WASM_SET_LOCAL(0, WASM_ZERO), WASM_ZERO)};
374 EXPECT_VERIFIES(sigs.i_i(), code); 434 EXPECT_VERIFIES(sigs.i_i(), code);
435 EXPECT_FAILURE(sigs.v_v(), code);
436 EXPECT_FAILURE(sigs.f_ff(), code);
375 } 437 }
376 438
377 TEST_F(AstDecoderTest, Block2_fallthru) { 439 TEST_F(AstDecoderTest, Block2_fallthru) {
378 static const byte code[] = {kExprBlock, 2, // -- 440 EXPECT_VERIFIES_INLINE(sigs.i_i(), B2(WASM_SET_LOCAL(0, WASM_ZERO),
379 kExprSetLocal, 0, kExprI8Const, 0, // -- 441 WASM_SET_LOCAL(0, WASM_ZERO)),
380 kExprSetLocal, 0, kExprI8Const, 0, // -- 442 WASM_I8(23));
381 kExprI8Const, 11}; // -- 443 }
382 EXPECT_VERIFIES(sigs.i_i(), code); 444
383 } 445 TEST_F(AstDecoderTest, Block3) {
384 446 EXPECT_VERIFIES_INLINE(
385 TEST_F(AstDecoderTest, BlockN) { 447 sigs.i_i(), B3(WASM_SET_LOCAL(0, WASM_ZERO), WASM_SET_LOCAL(0, WASM_ZERO),
386 byte block[] = {kExprBlock, 2}; 448 WASM_I8(11)));
387 449 }
388 for (size_t i = 0; i < 10; i++) { 450
389 size_t total = sizeof(block) + sizeof(kCodeSetLocal0) * i; 451 TEST_F(AstDecoderTest, Block5) {
390 byte* code = reinterpret_cast<byte*>(malloc(total)); 452 EXPECT_VERIFIES_INLINE(sigs.v_i(), B1(WASM_GET_LOCAL(0)));
391 memcpy(code, block, sizeof(block)); 453
392 code[1] = static_cast<byte>(i); 454 EXPECT_VERIFIES_INLINE(sigs.v_i(), B2(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
393 for (size_t j = 0; j < i; j++) { 455
394 memcpy(code + sizeof(block) + j * sizeof(kCodeSetLocal0), kCodeSetLocal0, 456 EXPECT_VERIFIES_INLINE(
395 sizeof(kCodeSetLocal0)); 457 sigs.v_i(), B3(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
396 } 458
397 Verify(kSuccess, sigs.v_i(), code, code + total); 459 EXPECT_VERIFIES_INLINE(sigs.v_i(),
398 free(code); 460 WASM_BLOCK(4, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
461 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
462
463 EXPECT_VERIFIES_INLINE(
464 sigs.v_i(),
465 WASM_BLOCK(5, WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
466 WASM_GET_LOCAL(0), WASM_GET_LOCAL(0)));
467 }
468
469 TEST_F(AstDecoderTest, BlockF32) {
470 static const byte code[] = {kExprBlock, kExprF32Const, 0, 0, 0, 0, kExprEnd};
471 EXPECT_VERIFIES(sigs.f_ff(), code);
472 EXPECT_FAILURE(sigs.i_i(), code);
473 EXPECT_FAILURE(sigs.d_dd(), code);
474 }
475
476 TEST_F(AstDecoderTest, BlockN_off_end) {
477 byte code[] = {kExprBlock, kExprNop, kExprNop, kExprNop, kExprNop, kExprEnd};
478 EXPECT_VERIFIES(sigs.v_v(), code);
479 for (size_t i = 1; i < arraysize(code); i++) {
480 Verify(kError, sigs.v_v(), code, code + i);
399 } 481 }
400 } 482 }
401 483
402 TEST_F(AstDecoderTest, BlockN_off_end) {
403 for (byte i = 2; i < 10; i++) {
404 byte code[] = {kExprBlock, i, kExprNop};
405 EXPECT_FAILURE(sigs.v_v(), code);
406 }
407 }
408
409 TEST_F(AstDecoderTest, Block1_break) {
410 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop};
411 EXPECT_VERIFIES(sigs.v_v(), code);
412 }
413
414 TEST_F(AstDecoderTest, Block2_break) {
415 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 0, kExprNop};
416 EXPECT_VERIFIES(sigs.v_v(), code);
417 }
418
419 TEST_F(AstDecoderTest, Block1_continue) {
420 static const byte code[] = {kExprBlock, 1, kExprBr, 1, kExprNop};
421 EXPECT_FAILURE(sigs.v_v(), code);
422 }
423
424 TEST_F(AstDecoderTest, Block2_continue) { 484 TEST_F(AstDecoderTest, Block2_continue) {
425 static const byte code[] = {kExprBlock, 2, kExprNop, kExprBr, 1, kExprNop}; 485 static const byte code[] = {kExprBlock, kExprBr, ARITY_0,
426 EXPECT_FAILURE(sigs.v_v(), code); 486 DEPTH_1, kExprNop, kExprEnd};
427 } 487 EXPECT_FAILURE(sigs.v_v(), code);
428 488 }
429 TEST_F(AstDecoderTest, ExprBlock0) { 489
430 static const byte code[] = {kExprBlock, 0}; 490 TEST_F(AstDecoderTest, NestedBlock_return) {
431 EXPECT_VERIFIES(sigs.v_v(), code); 491 EXPECT_VERIFIES_INLINE(sigs.i_i(), B1(B1(WASM_RETURN1(WASM_ZERO))));
432 } 492 }
433 493
434 TEST_F(AstDecoderTest, ExprBlock1a) { 494 TEST_F(AstDecoderTest, BlockBinop) {
435 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; 495 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(B1(WASM_I8(1)), WASM_I8(2)));
436 EXPECT_VERIFIES(sigs.i_i(), code); 496 }
437 } 497
438 498 TEST_F(AstDecoderTest, BlockBrBinop) {
439 TEST_F(AstDecoderTest, ExprBlock1b) { 499 EXPECT_VERIFIES_INLINE(sigs.i_i(),
440 static const byte code[] = {kExprBlock, 1, kExprI8Const, 0}; 500 WASM_I32_AND(B1(WASM_BRV(0, WASM_I8(1))), WASM_I8(2)));
441 EXPECT_FAILURE(sigs.f_ff(), code); 501 }
442 } 502
443 503 TEST_F(AstDecoderTest, If_empty_stack) {
444 TEST_F(AstDecoderTest, ExprBlock1c) { 504 byte code[] = {kExprIf};
445 static const byte code[] = {kExprBlock, 1, kExprF32Const, 0, 0, 0, 0}; 505 EXPECT_FAILURE(sigs.v_v(), code);
446 EXPECT_VERIFIES(sigs.f_ff(), code); 506 EXPECT_FAILURE(sigs.i_i(), code);
507 }
508
509 TEST_F(AstDecoderTest, If_incomplete1) {
510 byte code[] = {kExprI8Const, 0, kExprIf};
511 EXPECT_FAILURE(sigs.v_v(), code);
512 EXPECT_FAILURE(sigs.i_i(), code);
513 }
514
515 TEST_F(AstDecoderTest, If_incomplete2) {
516 byte code[] = {kExprI8Const, 0, kExprIf, kExprNop};
517 EXPECT_FAILURE(sigs.v_v(), code);
518 EXPECT_FAILURE(sigs.i_i(), code);
519 }
520
521 TEST_F(AstDecoderTest, If_else_else) {
522 byte code[] = {kExprI8Const, 0, kExprIf, kExprElse, kExprElse, kExprEnd};
523 EXPECT_FAILURE(sigs.v_v(), code);
524 EXPECT_FAILURE(sigs.i_i(), code);
447 } 525 }
448 526
449 TEST_F(AstDecoderTest, IfEmpty) { 527 TEST_F(AstDecoderTest, IfEmpty) {
450 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprNop}; 528 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0, kExprIf, kExprEnd);
451 EXPECT_VERIFIES(sigs.v_i(), code);
452 } 529 }
453 530
454 TEST_F(AstDecoderTest, IfSet) { 531 TEST_F(AstDecoderTest, IfSet) {
455 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprSetLocal, 532 EXPECT_VERIFIES_INLINE(
456 0, kExprI8Const, 0, kExprNop}; 533 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO)));
457 EXPECT_VERIFIES(sigs.v_i(), code); 534 EXPECT_VERIFIES_INLINE(
458 } 535 sigs.v_i(),
459 536 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP));
460 TEST_F(AstDecoderTest, IfBlock1) {
461 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprBlock,
462 1, kExprSetLocal, 0, kExprI8Const,
463 0, kExprNop};
464 EXPECT_VERIFIES(sigs.v_i(), code);
465 }
466
467 TEST_F(AstDecoderTest, IfBlock2) {
468 static const byte code[] = {kExprIf, kExprGetLocal, 0, kExprBlock,
469 2, kExprSetLocal, 0, kExprI8Const,
470 0, kExprSetLocal, 0, kExprI8Const,
471 0};
472 EXPECT_VERIFIES(sigs.v_i(), code);
473 } 537 }
474 538
475 TEST_F(AstDecoderTest, IfElseEmpty) { 539 TEST_F(AstDecoderTest, IfElseEmpty) {
476 static const byte code[] = {kExprIfElse, kExprGetLocal, 0, kExprNop, 540 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_GET_LOCAL(0), kExprIf, kExprElse,
477 kExprNop}; 541 kExprEnd);
478 EXPECT_VERIFIES(sigs.v_i(), code); 542 EXPECT_VERIFIES_INLINE(sigs.v_i(),
479 } 543 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
480 544 }
481 TEST_F(AstDecoderTest, IfElseSet) { 545
482 static const byte code[] = {kExprIfElse, 546 TEST_F(AstDecoderTest, IfElseUnreachable1) {
483 kExprGetLocal, 547 EXPECT_VERIFIES_INLINE(
484 0, // -- 548 sigs.i_i(),
485 kExprSetLocal, 549 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0)));
486 0, 550 EXPECT_VERIFIES_INLINE(
487 kExprI8Const, 551 sigs.i_i(),
488 0, // -- 552 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_UNREACHABLE));
489 kExprSetLocal, 553 }
490 0, 554
491 kExprI8Const, 555 TEST_F(AstDecoderTest, IfElseUnreachable2) {
492 1}; // -- 556 static const byte code[] = {
493 EXPECT_VERIFIES(sigs.v_i(), code); 557 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_UNREACHABLE, WASM_GET_LOCAL(0))};
494 }
495
496 TEST_F(AstDecoderTest, IfElseUnreachable) {
497 static const byte code[] = {kExprIfElse, kExprI8Const, 0,
498 kExprUnreachable, kExprGetLocal, 0};
499 558
500 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 559 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
501 LocalType types[] = {kAstI32, kLocalTypes[i]}; 560 LocalType types[] = {kAstI32, kLocalTypes[i]};
502 FunctionSig sig(1, 1, types); 561 FunctionSig sig(1, 1, types);
503 562
504 if (kLocalTypes[i] == kAstI32) { 563 if (kLocalTypes[i] == kAstI32) {
505 EXPECT_VERIFIES(&sig, code); 564 EXPECT_VERIFIES(&sig, code);
506 } else { 565 } else {
507 EXPECT_FAILURE(&sig, code); 566 EXPECT_FAILURE(&sig, code);
508 } 567 }
509 } 568 }
510 } 569 }
511 570
571 TEST_F(AstDecoderTest, IfBreak) {
572 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(0)));
573 EXPECT_FAILURE_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_BR(1)));
574 }
575
576 TEST_F(AstDecoderTest, IfElseBreak) {
577 EXPECT_VERIFIES_INLINE(sigs.v_i(),
578 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(0)));
579 EXPECT_FAILURE_INLINE(sigs.v_i(),
580 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_BR(1)));
581 }
582
583 TEST_F(AstDecoderTest, Block_else) {
584 byte code[] = {kExprI8Const, 0, kExprBlock, kExprElse, kExprEnd};
585 EXPECT_FAILURE(sigs.v_v(), code);
586 EXPECT_FAILURE(sigs.i_i(), code);
587 }
588
589 TEST_F(AstDecoderTest, IfNop) {
590 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
591 }
592
593 TEST_F(AstDecoderTest, IfNopElseNop) {
594 EXPECT_VERIFIES_INLINE(sigs.v_i(),
595 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
596 }
597
598 TEST_F(AstDecoderTest, If_end_end) {
599 static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprEnd, kExprEnd};
600 EXPECT_FAILURE(sigs.v_i(), code);
601 }
602
603 TEST_F(AstDecoderTest, If_falloff) {
604 static const byte code[] = {kExprGetLocal, 0, kExprIf};
605 EXPECT_FAILURE(sigs.v_i(), code);
606 }
607
608 TEST_F(AstDecoderTest, IfElse_falloff) {
609 static const byte code[] = {kExprGetLocal, 0, kExprIf, kExprNop, kExprElse};
610 EXPECT_FAILURE(sigs.v_i(), code);
611 }
612
613 TEST_F(AstDecoderTest, IfElseNop) {
614 EXPECT_VERIFIES_INLINE(
615 sigs.v_i(),
616 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO), WASM_NOP));
617 }
618
619 TEST_F(AstDecoderTest, IfBlock1) {
620 EXPECT_VERIFIES_INLINE(
621 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0),
622 B1(WASM_SET_LOCAL(0, WASM_ZERO)), WASM_NOP));
623 }
624
625 TEST_F(AstDecoderTest, IfBlock1b) {
626 EXPECT_VERIFIES_INLINE(
627 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B1(WASM_SET_LOCAL(0, WASM_ZERO))));
628 }
629
630 TEST_F(AstDecoderTest, IfBlock2a) {
631 EXPECT_VERIFIES_INLINE(
632 sigs.v_i(), WASM_IF(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO),
633 WASM_SET_LOCAL(0, WASM_ZERO))));
634 }
635
636 TEST_F(AstDecoderTest, IfBlock2b) {
637 EXPECT_VERIFIES_INLINE(
638 sigs.v_i(),
639 WASM_IF_ELSE(WASM_GET_LOCAL(0), B2(WASM_SET_LOCAL(0, WASM_ZERO),
640 WASM_SET_LOCAL(0, WASM_ZERO)),
641 WASM_NOP));
642 }
643
644 TEST_F(AstDecoderTest, IfElseSet) {
645 EXPECT_VERIFIES_INLINE(
646 sigs.v_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_SET_LOCAL(0, WASM_ZERO),
647 WASM_SET_LOCAL(0, WASM_I8(1))));
648 }
649
512 TEST_F(AstDecoderTest, Loop0) { 650 TEST_F(AstDecoderTest, Loop0) {
513 static const byte code[] = {kExprLoop, 0}; 651 static const byte code[] = {kExprLoop, kExprEnd};
514 EXPECT_VERIFIES(sigs.v_v(), code); 652 EXPECT_VERIFIES(sigs.v_v(), code);
515 } 653 }
516 654
517 TEST_F(AstDecoderTest, Loop1) { 655 TEST_F(AstDecoderTest, Loop1) {
518 static const byte code[] = {kExprLoop, 1, kExprSetLocal, 0, kExprI8Const, 0}; 656 static const byte code[] = {WASM_LOOP(1, WASM_SET_LOCAL(0, WASM_ZERO))};
519 EXPECT_VERIFIES(sigs.v_i(), code); 657 EXPECT_VERIFIES(sigs.v_i(), code);
658 EXPECT_FAILURE(sigs.v_v(), code);
659 EXPECT_FAILURE(sigs.f_ff(), code);
520 } 660 }
521 661
522 TEST_F(AstDecoderTest, Loop2) { 662 TEST_F(AstDecoderTest, Loop2) {
523 static const byte code[] = {kExprLoop, 2, // -- 663 EXPECT_VERIFIES_INLINE(sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO),
524 kExprSetLocal, 0, kExprI8Const, 0, // -- 664 WASM_SET_LOCAL(0, WASM_ZERO)));
525 kExprSetLocal, 0, kExprI8Const, 0}; // --
526 EXPECT_VERIFIES(sigs.v_i(), code);
527 } 665 }
528 666
529 TEST_F(AstDecoderTest, Loop1_continue) { 667 TEST_F(AstDecoderTest, Loop1_continue) {
530 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprNop}; 668 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0)));
531 EXPECT_VERIFIES(sigs.v_v(), code);
532 } 669 }
533 670
534 TEST_F(AstDecoderTest, Loop1_break) { 671 TEST_F(AstDecoderTest, Loop1_break) {
535 static const byte code[] = {kExprLoop, 1, kExprBr, 1, kExprNop}; 672 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1)));
536 EXPECT_VERIFIES(sigs.v_v(), code);
537 } 673 }
538 674
539 TEST_F(AstDecoderTest, Loop2_continue) { 675 TEST_F(AstDecoderTest, Loop2_continue) {
540 static const byte code[] = {kExprLoop, 2, // -- 676 EXPECT_VERIFIES_INLINE(
541 kExprSetLocal, 0, kExprI8Const, 0, // -- 677 sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(0)));
542 kExprBr, 0, kExprNop}; // --
543 EXPECT_VERIFIES(sigs.v_i(), code);
544 } 678 }
545 679
546 TEST_F(AstDecoderTest, Loop2_break) { 680 TEST_F(AstDecoderTest, Loop2_break) {
547 static const byte code[] = {kExprLoop, 2, // -- 681 EXPECT_VERIFIES_INLINE(
548 kExprSetLocal, 0, kExprI8Const, 0, // -- 682 sigs.v_i(), WASM_LOOP(2, WASM_SET_LOCAL(0, WASM_ZERO), WASM_BR(1)));
549 kExprBr, 1, kExprNop}; // --
550 EXPECT_VERIFIES(sigs.v_i(), code);
551 } 683 }
552 684
553 TEST_F(AstDecoderTest, ExprLoop0) { 685 TEST_F(AstDecoderTest, ExprLoop0) {
554 static const byte code[] = {kExprLoop, 0}; 686 static const byte code[] = {kExprLoop, kExprEnd};
555 EXPECT_VERIFIES(sigs.v_v(), code); 687 EXPECT_VERIFIES(sigs.v_v(), code);
556 } 688 }
557 689
558 TEST_F(AstDecoderTest, ExprLoop1a) { 690 TEST_F(AstDecoderTest, ExprLoop1a) {
559 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; 691 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
560 EXPECT_VERIFIES(sigs.i_i(), code);
561 } 692 }
562 693
563 TEST_F(AstDecoderTest, ExprLoop1b) { 694 TEST_F(AstDecoderTest, ExprLoop1b) {
564 static const byte code[] = {kExprLoop, 1, kExprBr, 0, kExprI8Const, 0}; 695 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
565 EXPECT_VERIFIES(sigs.i_i(), code); 696 EXPECT_FAILURE_INLINE(sigs.f_ff(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
566 } 697 }
567 698
568 TEST_F(AstDecoderTest, ExprLoop2_unreachable) { 699 TEST_F(AstDecoderTest, ExprLoop2_unreachable) {
569 static const byte code[] = {kExprLoop, 2, kExprBr, 0, 700 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(2, WASM_BR(0), WASM_NOP));
570 kExprI8Const, 0, kExprNop};
571 EXPECT_VERIFIES(sigs.i_i(), code);
572 } 701 }
573 702
574 TEST_F(AstDecoderTest, ReturnVoid1) { 703 TEST_F(AstDecoderTest, ReturnVoid1) {
575 static const byte code[] = {kExprNop}; 704 static const byte code[] = {kExprNop};
576 EXPECT_VERIFIES(sigs.v_v(), code); 705 EXPECT_VERIFIES(sigs.v_v(), code);
577 EXPECT_FAILURE(sigs.i_i(), code); 706 EXPECT_FAILURE(sigs.i_i(), code);
578 EXPECT_FAILURE(sigs.i_f(), code); 707 EXPECT_FAILURE(sigs.i_f(), code);
579 } 708 }
580 709
581 TEST_F(AstDecoderTest, ReturnVoid2) { 710 TEST_F(AstDecoderTest, ReturnVoid2) {
582 static const byte code[] = {kExprBlock, 1, kExprBr, 0, kExprNop}; 711 static const byte code[] = {kExprBlock, kExprBr, ARITY_0, DEPTH_0, kExprEnd};
583 EXPECT_VERIFIES(sigs.v_v(), code); 712 EXPECT_VERIFIES(sigs.v_v(), code);
584 EXPECT_FAILURE(sigs.i_i(), code); 713 EXPECT_FAILURE(sigs.i_i(), code);
585 EXPECT_FAILURE(sigs.i_f(), code); 714 EXPECT_FAILURE(sigs.i_f(), code);
586 } 715 }
587 716
588 TEST_F(AstDecoderTest, ReturnVoid3) { 717 TEST_F(AstDecoderTest, ReturnVoid3) {
589 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI8Const, 0); 718 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI8Const, 0);
590 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI32Const, 0, 0, 0, 0); 719 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI32Const, 0, 0, 0, 0);
591 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0); 720 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprI64Const, 0, 0, 0, 0, 0, 0, 0, 0);
592 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF32Const, 0, 0, 0, 0); 721 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF32Const, 0, 0, 0, 0);
593 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0); 722 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprF64Const, 0, 0, 0, 0, 0, 0, 0, 0);
594 723
595 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0); 724 EXPECT_VERIFIES_INLINE(sigs.v_i(), kExprGetLocal, 0);
596 } 725 }
597 726
598 TEST_F(AstDecoderTest, Unreachable1) { 727 TEST_F(AstDecoderTest, Unreachable1) {
599 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable); 728 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable);
600 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable); 729 EXPECT_VERIFIES_INLINE(sigs.v_v(), kExprUnreachable, kExprUnreachable);
601 EXPECT_VERIFIES_INLINE(sigs.v_v(), 730 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_UNREACHABLE, WASM_ZERO));
602 WASM_BLOCK(2, WASM_UNREACHABLE, WASM_ZERO)); 731 EXPECT_VERIFIES_INLINE(sigs.v_v(), B2(WASM_BR(0), WASM_ZERO));
603 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(2, WASM_BR(0), WASM_ZERO));
604 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO)); 732 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_UNREACHABLE, WASM_ZERO));
605 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_BR(0), WASM_ZERO)); 733 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(2, WASM_BR(0), WASM_ZERO));
606 } 734 }
607 735
608 TEST_F(AstDecoderTest, Codeiness) { 736 TEST_F(AstDecoderTest, Unreachable_binop) {
609 VERIFY(kExprLoop, 2, // -- 737 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_ZERO, WASM_UNREACHABLE));
610 kExprSetLocal, 0, kExprI8Const, 0, // -- 738 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_I32_AND(WASM_UNREACHABLE, WASM_ZERO));
611 kExprBr, 0, kExprNop); // --
612 } 739 }
613 740
614 TEST_F(AstDecoderTest, ExprIf1) { 741 TEST_F(AstDecoderTest, Unreachable_select) {
615 VERIFY(kExprIf, kExprGetLocal, 0, kExprI8Const, 0, kExprI8Const, 1); 742 EXPECT_VERIFIES_INLINE(sigs.i_i(),
616 VERIFY(kExprIf, kExprGetLocal, 0, kExprGetLocal, 0, kExprGetLocal, 0); 743 WASM_SELECT(WASM_UNREACHABLE, WASM_ZERO, WASM_ZERO));
617 VERIFY(kExprIf, kExprGetLocal, 0, kExprI32Add, kExprGetLocal, 0, 744 EXPECT_VERIFIES_INLINE(sigs.i_i(),
618 kExprGetLocal, 0, kExprI8Const, 1); 745 WASM_SELECT(WASM_ZERO, WASM_UNREACHABLE, WASM_ZERO));
746 EXPECT_VERIFIES_INLINE(sigs.i_i(),
747 WASM_SELECT(WASM_ZERO, WASM_ZERO, WASM_UNREACHABLE));
619 } 748 }
620 749
621 TEST_F(AstDecoderTest, ExprIf_off_end) { 750 TEST_F(AstDecoderTest, If1) {
622 static const byte kCode[] = {kExprIf, kExprGetLocal, 0, kExprGetLocal, 751 EXPECT_VERIFIES_INLINE(
623 0, kExprGetLocal, 0}; 752 sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(8)));
624 for (size_t len = 1; len < arraysize(kCode); len++) { 753 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(9),
754 WASM_GET_LOCAL(0)));
755 EXPECT_VERIFIES_INLINE(
756 sigs.i_i(),
757 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_I8(8)));
758 }
759
760 TEST_F(AstDecoderTest, If_off_end) {
761 static const byte kCode[] = {
762 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_GET_LOCAL(0), WASM_GET_LOCAL(0))};
763 for (size_t len = 3; len < arraysize(kCode); len++) {
625 Verify(kError, sigs.i_i(), kCode, kCode + len); 764 Verify(kError, sigs.i_i(), kCode, kCode + len);
626 } 765 }
627 } 766 }
628 767
629 TEST_F(AstDecoderTest, ExprIf_type) { 768 TEST_F(AstDecoderTest, If_type1) {
630 { 769 // float|double ? 1 : 2
631 // float|double ? 1 : 2 770 static const byte kCode[] = {
632 static const byte kCode[] = {kExprIfElse, kExprGetLocal, 0, kExprI8Const, 771 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_I8(0), WASM_I8(2))};
633 1, kExprI8Const, 2}; 772 EXPECT_VERIFIES(sigs.i_i(), kCode);
634 EXPECT_FAILURE(sigs.i_f(), kCode); 773 EXPECT_FAILURE(sigs.i_f(), kCode);
635 EXPECT_FAILURE(sigs.i_d(), kCode); 774 EXPECT_FAILURE(sigs.i_d(), kCode);
636 } 775 }
637 { 776
638 // 1 ? float|double : 2 777 TEST_F(AstDecoderTest, If_type2) {
639 static const byte kCode[] = {kExprIfElse, kExprI8Const, 1, kExprGetLocal, 778 // 1 ? float|double : 2
640 0, kExprI8Const, 2}; 779 static const byte kCode[] = {
641 EXPECT_FAILURE(sigs.i_f(), kCode); 780 WASM_IF_ELSE(WASM_I8(1), WASM_GET_LOCAL(0), WASM_I8(1))};
642 EXPECT_FAILURE(sigs.i_d(), kCode); 781 EXPECT_VERIFIES(sigs.i_i(), kCode);
643 } 782 EXPECT_FAILURE(sigs.i_f(), kCode);
644 { 783 EXPECT_FAILURE(sigs.i_d(), kCode);
645 // stmt ? 0 : 1 784 }
646 static const byte kCode[] = {kExprIfElse, kExprNop, kExprI8Const, 785
647 0, kExprI8Const, 1}; 786 TEST_F(AstDecoderTest, If_type3) {
648 EXPECT_FAILURE(sigs.i_i(), kCode); 787 // stmt ? 0 : 1
649 } 788 static const byte kCode[] = {WASM_IF_ELSE(WASM_NOP, WASM_I8(0), WASM_I8(1))};
650 { 789 EXPECT_FAILURE(sigs.i_i(), kCode);
651 // 0 ? stmt : 1 790 EXPECT_FAILURE(sigs.i_f(), kCode);
652 static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, 791 EXPECT_FAILURE(sigs.i_d(), kCode);
653 kExprNop, kExprI8Const, 1}; 792 }
654 EXPECT_FAILURE(sigs.i_i(), kCode); 793
655 } 794 TEST_F(AstDecoderTest, If_type4) {
656 { 795 // 0 ? stmt : 1
657 // 0 ? 1 : stmt 796 static const byte kCode[] = {
658 static const byte kCode[] = {kExprIfElse, kExprI8Const, 0, kExprI8Const, 1, 797 WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_I8(1))};
659 0, kExprBlock}; 798 EXPECT_FAILURE(sigs.i_i(), kCode);
660 EXPECT_FAILURE(sigs.i_i(), kCode); 799 EXPECT_FAILURE(sigs.i_f(), kCode);
661 } 800 EXPECT_FAILURE(sigs.i_d(), kCode);
801 }
802
803 TEST_F(AstDecoderTest, If_type5) {
804 // 0 ? 1 : stmt
805 static const byte kCode[] = {WASM_IF_ELSE(WASM_ZERO, WASM_I8(1), WASM_NOP)};
806 EXPECT_FAILURE(sigs.i_i(), kCode);
807 EXPECT_FAILURE(sigs.i_f(), kCode);
808 EXPECT_FAILURE(sigs.i_d(), kCode);
662 } 809 }
663 810
664 TEST_F(AstDecoderTest, Int64Local_param) { 811 TEST_F(AstDecoderTest, Int64Local_param) {
665 EXPECT_VERIFIES(sigs.l_l(), kCodeGetLocal0); 812 EXPECT_VERIFIES(sigs.l_l(), kCodeGetLocal0);
666 } 813 }
667 814
668 TEST_F(AstDecoderTest, Int64Locals) { 815 TEST_F(AstDecoderTest, Int64Locals) {
669 for (byte i = 1; i < 8; i++) { 816 for (byte i = 1; i < 8; i++) {
670 AddLocals(kAstI64, 1); 817 AddLocals(kAstI64, 1);
671 for (byte j = 0; j < i; j++) { 818 for (byte j = 0; j < i; j++) {
672 byte code[] = {kExprGetLocal, j}; 819 EXPECT_VERIFIES_INLINE(sigs.l_v(), WASM_GET_LOCAL(j));
673 EXPECT_VERIFIES(sigs.l_v(), code);
674 } 820 }
675 } 821 }
676 } 822 }
677 823
678 TEST_F(AstDecoderTest, Int32Binops) { 824 TEST_F(AstDecoderTest, Int32Binops) {
679 TestBinop(kExprI32Add, sigs.i_ii()); 825 TestBinop(kExprI32Add, sigs.i_ii());
680 TestBinop(kExprI32Sub, sigs.i_ii()); 826 TestBinop(kExprI32Sub, sigs.i_ii());
681 TestBinop(kExprI32Mul, sigs.i_ii()); 827 TestBinop(kExprI32Mul, sigs.i_ii());
682 TestBinop(kExprI32DivS, sigs.i_ii()); 828 TestBinop(kExprI32DivS, sigs.i_ii());
683 TestBinop(kExprI32DivU, sigs.i_ii()); 829 TestBinop(kExprI32DivU, sigs.i_ii());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32); 876 TestUnop(kExprF32UConvertI32, kAstF32, kAstI32);
731 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64); 877 TestUnop(kExprF32ConvertF64, kAstF32, kAstF64);
732 } 878 }
733 879
734 TEST_F(AstDecoderTest, MacrosStmt) { 880 TEST_F(AstDecoderTest, MacrosStmt) {
735 VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348))); 881 VERIFY(WASM_SET_LOCAL(0, WASM_I32V_3(87348)));
736 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40))); 882 VERIFY(WASM_STORE_MEM(MachineType::Int32(), WASM_I8(24), WASM_I8(40)));
737 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 883 VERIFY(WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
738 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 884 VERIFY(WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
739 VERIFY(WASM_NOP); 885 VERIFY(WASM_NOP);
740 VERIFY(WASM_BLOCK(1, WASM_NOP)); 886 VERIFY(B1(WASM_NOP));
741 VERIFY(WASM_LOOP(1, WASM_NOP)); 887 VERIFY(WASM_LOOP(1, WASM_NOP));
742 VERIFY(WASM_LOOP(1, WASM_BREAK(0))); 888 VERIFY(WASM_LOOP(1, WASM_BREAK(0)));
743 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0))); 889 VERIFY(WASM_LOOP(1, WASM_CONTINUE(0)));
744 } 890 }
745 891
746 TEST_F(AstDecoderTest, MacrosBreak) { 892 TEST_F(AstDecoderTest, MacrosBreak) {
747 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BREAK(0))); 893 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BREAK(0)));
748 894
749 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO))); 895 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_LOOP(1, WASM_BREAKV(0, WASM_ZERO)));
750 EXPECT_VERIFIES_INLINE(sigs.l_l(), 896 EXPECT_VERIFIES_INLINE(sigs.l_l(),
751 WASM_LOOP(1, WASM_BREAKV(0, WASM_I64V_1(0)))); 897 WASM_LOOP(1, WASM_BREAKV(0, WASM_I64V_1(0))));
752 EXPECT_VERIFIES_INLINE(sigs.f_ff(), 898 EXPECT_VERIFIES_INLINE(sigs.f_ff(),
753 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0)))); 899 WASM_LOOP(1, WASM_BREAKV(0, WASM_F32(0.0))));
754 EXPECT_VERIFIES_INLINE(sigs.d_dd(), 900 EXPECT_VERIFIES_INLINE(sigs.d_dd(),
755 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0)))); 901 WASM_LOOP(1, WASM_BREAKV(0, WASM_F64(0.0))));
756 } 902 }
757 903
758 TEST_F(AstDecoderTest, MacrosContinue) { 904 TEST_F(AstDecoderTest, MacrosContinue) {
759 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_CONTINUE(0))); 905 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_CONTINUE(0)));
760 } 906 }
761 907
762 TEST_F(AstDecoderTest, MacrosVariadic) { 908 TEST_F(AstDecoderTest, MacrosVariadic) {
763 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_NOP)); 909 VERIFY(B2(WASM_NOP, WASM_NOP));
764 VERIFY(WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP)); 910 VERIFY(B3(WASM_NOP, WASM_NOP, WASM_NOP));
765 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP)); 911 VERIFY(WASM_LOOP(2, WASM_NOP, WASM_NOP));
766 VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP)); 912 VERIFY(WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP));
767 } 913 }
768 914
769 TEST_F(AstDecoderTest, MacrosNestedBlocks) { 915 TEST_F(AstDecoderTest, MacrosNestedBlocks) {
770 VERIFY(WASM_BLOCK(2, WASM_NOP, WASM_BLOCK(2, WASM_NOP, WASM_NOP))); 916 VERIFY(B2(WASM_NOP, B2(WASM_NOP, WASM_NOP)));
771 VERIFY(WASM_BLOCK(3, WASM_NOP, // -- 917 VERIFY(B3(WASM_NOP, // --
772 WASM_BLOCK(2, WASM_NOP, WASM_NOP), // -- 918 B2(WASM_NOP, WASM_NOP), // --
773 WASM_BLOCK(2, WASM_NOP, WASM_NOP))); // -- 919 B2(WASM_NOP, WASM_NOP))); // --
774 VERIFY(WASM_BLOCK(1, WASM_BLOCK(1, WASM_BLOCK(2, WASM_NOP, WASM_NOP)))); 920 VERIFY(B1(B1(B2(WASM_NOP, WASM_NOP))));
775 } 921 }
776 922
777 TEST_F(AstDecoderTest, MultipleReturn) { 923 TEST_F(AstDecoderTest, MultipleReturn) {
778 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; 924 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
779 FunctionSig sig_ii_v(2, 0, kIntTypes5); 925 FunctionSig sig_ii_v(2, 0, kIntTypes5);
780 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); 926 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
781 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURN(WASM_ZERO)); 927 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_RETURNN(1, WASM_ZERO));
782 928
783 FunctionSig sig_iii_v(3, 0, kIntTypes5); 929 FunctionSig sig_iii_v(3, 0, kIntTypes5);
784 EXPECT_VERIFIES_INLINE(&sig_iii_v, 930 EXPECT_VERIFIES_INLINE(&sig_iii_v,
785 WASM_RETURN(WASM_ZERO, WASM_ONE, WASM_I8(44))); 931 WASM_RETURNN(3, WASM_ZERO, WASM_ONE, WASM_I8(44)));
786 EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURN(WASM_ZERO, WASM_ONE)); 932 EXPECT_FAILURE_INLINE(&sig_iii_v, WASM_RETURNN(2, WASM_ZERO, WASM_ONE));
787 } 933 }
788 934
789 TEST_F(AstDecoderTest, MultipleReturn_fallthru) { 935 TEST_F(AstDecoderTest, MultipleReturn_fallthru) {
790 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32}; 936 static LocalType kIntTypes5[] = {kAstI32, kAstI32, kAstI32, kAstI32, kAstI32};
791 FunctionSig sig_ii_v(2, 0, kIntTypes5); 937 FunctionSig sig_ii_v(2, 0, kIntTypes5);
792 938
793 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_ZERO, WASM_ONE); 939 EXPECT_VERIFIES_INLINE(&sig_ii_v, WASM_ZERO, WASM_ONE);
794 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_ZERO); 940 EXPECT_FAILURE_INLINE(&sig_ii_v, WASM_ZERO);
795 941
796 FunctionSig sig_iii_v(3, 0, kIntTypes5); 942 FunctionSig sig_iii_v(3, 0, kIntTypes5);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 #undef DECODE_TEST 1026 #undef DECODE_TEST
881 } 1027 }
882 1028
883 TEST_F(AstDecoderTest, MemorySize) { 1029 TEST_F(AstDecoderTest, MemorySize) {
884 byte code[] = {kExprMemorySize}; 1030 byte code[] = {kExprMemorySize};
885 EXPECT_VERIFIES(sigs.i_i(), code); 1031 EXPECT_VERIFIES(sigs.i_i(), code);
886 EXPECT_FAILURE(sigs.f_ff(), code); 1032 EXPECT_FAILURE(sigs.f_ff(), code);
887 } 1033 }
888 1034
889 TEST_F(AstDecoderTest, GrowMemory) { 1035 TEST_F(AstDecoderTest, GrowMemory) {
890 byte code[] = {kExprGrowMemory, kExprGetLocal, 0}; 1036 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
891 EXPECT_VERIFIES(sigs.i_i(), code); 1037 EXPECT_VERIFIES(sigs.i_i(), code);
892 EXPECT_FAILURE(sigs.i_d(), code); 1038 EXPECT_FAILURE(sigs.i_d(), code);
893 } 1039 }
894 1040
895 TEST_F(AstDecoderTest, LoadMemOffset) { 1041 TEST_F(AstDecoderTest, LoadMemOffset) {
896 for (int offset = 0; offset < 128; offset += 7) { 1042 for (int offset = 0; offset < 128; offset += 7) {
897 byte code[] = {kExprI32LoadMem, ZERO_ALIGNMENT, static_cast<byte>(offset), 1043 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
898 kExprI8Const, 0}; 1044 static_cast<byte>(offset)};
899 EXPECT_VERIFIES(sigs.i_i(), code); 1045 EXPECT_VERIFIES(sigs.i_i(), code);
900 } 1046 }
901 } 1047 }
902 1048
903 TEST_F(AstDecoderTest, StoreMemOffset) { 1049 TEST_F(AstDecoderTest, StoreMemOffset) {
904 for (int offset = 0; offset < 128; offset += 7) { 1050 for (int offset = 0; offset < 128; offset += 7) {
905 byte code[] = { 1051 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset,
906 kExprI32StoreMem, 0, static_cast<byte>(offset), kExprI8Const, 0, 1052 WASM_ZERO, WASM_ZERO)};
907 kExprI8Const, 0};
908 EXPECT_VERIFIES(sigs.i_i(), code); 1053 EXPECT_VERIFIES(sigs.i_i(), code);
909 } 1054 }
910 } 1055 }
911 1056
1057 #define BYTE0(x) ((x)&0x7F)
1058 #define BYTE1(x) ((x >> 7) & 0x7F)
1059 #define BYTE2(x) ((x >> 14) & 0x7F)
1060 #define BYTE3(x) ((x >> 21) & 0x7F)
1061
1062 #define VARINT1(x) BYTE0(x)
1063 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x)
1064 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x)
1065 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x)
1066
912 TEST_F(AstDecoderTest, LoadMemOffset_varint) { 1067 TEST_F(AstDecoderTest, LoadMemOffset_varint) {
913 byte code1[] = {kExprI32LoadMem, ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, 1068 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
914 0}; 1069 VARINT1(0x45));
915 byte code2[] = {kExprI32LoadMem, ZERO_ALIGNMENT, 0x80, 1, kExprI8Const, 0}; 1070 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
916 byte code3[] = { 1071 VARINT2(0x3999));
917 kExprI32LoadMem, ZERO_ALIGNMENT, 0x81, 0x82, 5, kExprI8Const, 0}; 1072 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
918 byte code4[] = { 1073 VARINT3(0x344445));
919 kExprI32LoadMem, ZERO_ALIGNMENT, 0x83, 0x84, 0x85, 7, kExprI8Const, 0}; 1074 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT,
920 1075 VARINT4(0x36666667));
921 EXPECT_VERIFIES(sigs.i_i(), code1);
922 EXPECT_VERIFIES(sigs.i_i(), code2);
923 EXPECT_VERIFIES(sigs.i_i(), code3);
924 EXPECT_VERIFIES(sigs.i_i(), code4);
925 } 1076 }
926 1077
927 TEST_F(AstDecoderTest, StoreMemOffset_varint) { 1078 TEST_F(AstDecoderTest, StoreMemOffset_varint) {
928 byte code1[] = { 1079 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
929 kExprI32StoreMem, ZERO_ALIGNMENT, 0, kExprI8Const, 0, kExprI8Const, 0}; 1080 ZERO_ALIGNMENT, VARINT1(0x33));
930 byte code2[] = {kExprI32StoreMem, 1081 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
931 ZERO_ALIGNMENT, 1082 ZERO_ALIGNMENT, VARINT2(0x1111));
932 0x80, 1083 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
933 1, 1084 ZERO_ALIGNMENT, VARINT3(0x222222));
934 kExprI8Const, 1085 EXPECT_VERIFIES_INLINE(sigs.i_i(), WASM_ZERO, WASM_ZERO, kExprI32StoreMem,
935 0, 1086 ZERO_ALIGNMENT, VARINT4(0x44444444));
936 kExprI8Const,
937 0};
938 byte code3[] = {kExprI32StoreMem,
939 ZERO_ALIGNMENT,
940 0x81,
941 0x82,
942 5,
943 kExprI8Const,
944 0,
945 kExprI8Const,
946 0};
947 byte code4[] = {kExprI32StoreMem,
948 ZERO_ALIGNMENT,
949 0x83,
950 0x84,
951 0x85,
952 7,
953 kExprI8Const,
954 0,
955 kExprI8Const,
956 0};
957
958 EXPECT_VERIFIES(sigs.i_i(), code1);
959 EXPECT_VERIFIES(sigs.i_i(), code2);
960 EXPECT_VERIFIES(sigs.i_i(), code3);
961 EXPECT_VERIFIES(sigs.i_i(), code4);
962 } 1087 }
963 1088
964 TEST_F(AstDecoderTest, AllLoadMemCombinations) { 1089 TEST_F(AstDecoderTest, AllLoadMemCombinations) {
965 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1090 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
966 LocalType local_type = kLocalTypes[i]; 1091 LocalType local_type = kLocalTypes[i];
967 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1092 for (size_t j = 0; j < arraysize(machineTypes); j++) {
968 MachineType mem_type = machineTypes[j]; 1093 MachineType mem_type = machineTypes[j];
969 byte code[] = { 1094 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)};
970 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, false)),
971 ZERO_ALIGNMENT, ZERO_OFFSET, kExprI8Const, 0};
972 FunctionSig sig(1, 0, &local_type); 1095 FunctionSig sig(1, 0, &local_type);
973 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1096 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
974 EXPECT_VERIFIES(&sig, code); 1097 EXPECT_VERIFIES(&sig, code);
975 } else { 1098 } else {
976 EXPECT_FAILURE(&sig, code); 1099 EXPECT_FAILURE(&sig, code);
977 } 1100 }
978 } 1101 }
979 } 1102 }
980 } 1103 }
981 1104
982 TEST_F(AstDecoderTest, AllStoreMemCombinations) { 1105 TEST_F(AstDecoderTest, AllStoreMemCombinations) {
983 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1106 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
984 LocalType local_type = kLocalTypes[i]; 1107 LocalType local_type = kLocalTypes[i];
985 for (size_t j = 0; j < arraysize(machineTypes); j++) { 1108 for (size_t j = 0; j < arraysize(machineTypes); j++) {
986 MachineType mem_type = machineTypes[j]; 1109 MachineType mem_type = machineTypes[j];
987 byte code[] = { 1110 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))};
988 static_cast<byte>(WasmOpcodes::LoadStoreOpcodeOf(mem_type, true)),
989 ZERO_ALIGNMENT,
990 ZERO_OFFSET,
991 kExprI8Const,
992 0,
993 kExprGetLocal,
994 0};
995 FunctionSig sig(0, 1, &local_type); 1111 FunctionSig sig(0, 1, &local_type);
996 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1112 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
997 EXPECT_VERIFIES(&sig, code); 1113 EXPECT_VERIFIES(&sig, code);
998 } else { 1114 } else {
999 EXPECT_FAILURE(&sig, code); 1115 EXPECT_FAILURE(&sig, code);
1000 } 1116 }
1001 } 1117 }
1002 } 1118 }
1003 } 1119 }
1004 1120
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1157
1042 TEST_F(AstDecoderTest, SimpleCalls) { 1158 TEST_F(AstDecoderTest, SimpleCalls) {
1043 FunctionSig* sig = sigs.i_i(); 1159 FunctionSig* sig = sigs.i_i();
1044 TestModuleEnv module_env; 1160 TestModuleEnv module_env;
1045 module = &module_env; 1161 module = &module_env;
1046 1162
1047 module_env.AddFunction(sigs.i_v()); 1163 module_env.AddFunction(sigs.i_v());
1048 module_env.AddFunction(sigs.i_i()); 1164 module_env.AddFunction(sigs.i_i());
1049 module_env.AddFunction(sigs.i_ii()); 1165 module_env.AddFunction(sigs.i_ii());
1050 1166
1051 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(0)); 1167 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION0(0));
1052 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(27))); 1168 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(27)));
1053 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_I8(37), WASM_I8(77))); 1169 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_FUNCTION2(2, WASM_I8(37), WASM_I8(77)));
1054 } 1170 }
1055 1171
1056 TEST_F(AstDecoderTest, CallsWithTooFewArguments) { 1172 TEST_F(AstDecoderTest, CallsWithTooFewArguments) {
1057 FunctionSig* sig = sigs.i_i(); 1173 FunctionSig* sig = sigs.i_i();
1058 TestModuleEnv module_env; 1174 TestModuleEnv module_env;
1059 module = &module_env; 1175 module = &module_env;
1060 1176
1061 module_env.AddFunction(sigs.i_i()); 1177 module_env.AddFunction(sigs.i_i());
1062 module_env.AddFunction(sigs.i_ii()); 1178 module_env.AddFunction(sigs.i_ii());
1063 module_env.AddFunction(sigs.f_ff()); 1179 module_env.AddFunction(sigs.f_ff());
1064 1180
1065 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0)); 1181 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION0(0));
1066 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_ZERO)); 1182 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_ZERO));
1067 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(2, WASM_GET_LOCAL(0))); 1183 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(2, WASM_GET_LOCAL(0)));
1068 }
1069
1070 TEST_F(AstDecoderTest, CallsWithSpilloverArgs) {
1071 static LocalType a_i_ff[] = {kAstI32, kAstF32, kAstF32};
1072 FunctionSig sig_i_ff(1, 2, a_i_ff);
1073
1074 TestModuleEnv module_env;
1075 module = &module_env;
1076
1077 module_env.AddFunction(&sig_i_ff);
1078
1079 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1080 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
1081
1082 EXPECT_VERIFIES_INLINE(sigs.i_ff(),
1083 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
1084
1085 EXPECT_FAILURE_INLINE(sigs.f_ff(),
1086 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1)));
1087
1088 EXPECT_FAILURE_INLINE(
1089 sigs.i_i(),
1090 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(0.2)));
1091
1092 EXPECT_VERIFIES_INLINE(
1093 sigs.f_ff(),
1094 WASM_CALL_FUNCTION(0, WASM_F32(0.1), WASM_F32(0.1), WASM_F32(11)));
1095 } 1184 }
1096 1185
1097 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) { 1186 TEST_F(AstDecoderTest, CallsWithMismatchedSigs2) {
1098 FunctionSig* sig = sigs.i_i(); 1187 FunctionSig* sig = sigs.i_i();
1099 TestModuleEnv module_env; 1188 TestModuleEnv module_env;
1100 module = &module_env; 1189 module = &module_env;
1101 1190
1102 module_env.AddFunction(sigs.i_i()); 1191 module_env.AddFunction(sigs.i_i());
1103 1192
1104 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(17))); 1193 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(17)));
1105 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F32(17.1))); 1194 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F32(17.1)));
1106 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(17.1))); 1195 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(17.1)));
1107 } 1196 }
1108 1197
1109 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) { 1198 TEST_F(AstDecoderTest, CallsWithMismatchedSigs3) {
1110 FunctionSig* sig = sigs.i_i(); 1199 FunctionSig* sig = sigs.i_i();
1111 TestModuleEnv module_env; 1200 TestModuleEnv module_env;
1112 module = &module_env; 1201 module = &module_env;
1113 1202
1114 module_env.AddFunction(sigs.i_f()); 1203 module_env.AddFunction(sigs.i_f());
1115 1204
1116 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I8(17))); 1205 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I8(17)));
1117 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_I64V_1(27))); 1206 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_I64V_1(27)));
1118 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(0, WASM_F64(37.2))); 1207 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(0, WASM_F64(37.2)));
1119 1208
1120 module_env.AddFunction(sigs.i_d()); 1209 module_env.AddFunction(sigs.i_d());
1121 1210
1122 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I8(16))); 1211 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I8(16)));
1123 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_I64V_1(16))); 1212 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_I64V_1(16)));
1124 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION(1, WASM_F32(17.6))); 1213 EXPECT_FAILURE_INLINE(sig, WASM_CALL_FUNCTION1(1, WASM_F32(17.6)));
1125 } 1214 }
1126 1215
1127 TEST_F(AstDecoderTest, SimpleIndirectCalls) { 1216 TEST_F(AstDecoderTest, SimpleIndirectCalls) {
1128 FunctionSig* sig = sigs.i_i(); 1217 FunctionSig* sig = sigs.i_i();
1129 TestModuleEnv module_env; 1218 TestModuleEnv module_env;
1130 module = &module_env; 1219 module = &module_env;
1131 1220
1132 byte f0 = module_env.AddSignature(sigs.i_v()); 1221 byte f0 = module_env.AddSignature(sigs.i_v());
1133 byte f1 = module_env.AddSignature(sigs.i_i()); 1222 byte f1 = module_env.AddSignature(sigs.i_i());
1134 byte f2 = module_env.AddSignature(sigs.i_ii()); 1223 byte f2 = module_env.AddSignature(sigs.i_ii());
1135 1224
1136 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); 1225 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO));
1137 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(22))); 1226 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22)));
1138 EXPECT_VERIFIES_INLINE( 1227 EXPECT_VERIFIES_INLINE(
1139 sig, WASM_CALL_INDIRECT(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); 1228 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72)));
1140 } 1229 }
1141 1230
1142 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { 1231 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) {
1143 FunctionSig* sig = sigs.i_i(); 1232 FunctionSig* sig = sigs.i_i();
1144 TestModuleEnv module_env; 1233 TestModuleEnv module_env;
1145 module = &module_env; 1234 module = &module_env;
1146 1235
1147 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1236 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1148 module_env.AddSignature(sigs.i_v()); 1237 module_env.AddSignature(sigs.i_v());
1149 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); 1238 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO));
1150 1239
1151 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(22))); 1240 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22)));
1152 module_env.AddSignature(sigs.i_i()); 1241 module_env.AddSignature(sigs.i_i());
1153 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT(1, WASM_ZERO, WASM_I8(27))); 1242 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27)));
1154 1243
1155 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(2, WASM_ZERO, WASM_I8(27))); 1244 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27)));
1156 } 1245 }
1157 1246
1158 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { 1247 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) {
1159 FunctionSig* sig = sigs.i_i(); 1248 FunctionSig* sig = sigs.i_i();
1160 TestModuleEnv module_env; 1249 TestModuleEnv module_env;
1161 module = &module_env; 1250 module = &module_env;
1162 1251
1163 byte f0 = module_env.AddFunction(sigs.i_f()); 1252 byte f0 = module_env.AddFunction(sigs.i_f());
1164 1253
1165 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I8(17))); 1254 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17)));
1166 EXPECT_FAILURE_INLINE(sig, 1255 EXPECT_FAILURE_INLINE(sig,
1167 WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_I64V_1(27))); 1256 WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27)));
1168 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f0, WASM_ZERO, WASM_F64(37.2))); 1257 EXPECT_FAILURE_INLINE(sig,
1258 WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2)));
1169 1259
1170 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); 1260 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17)));
1171 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); 1261 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27)));
1172 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); 1262 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
1173 1263
1174 byte f1 = module_env.AddFunction(sigs.i_d()); 1264 byte f1 = module_env.AddFunction(sigs.i_d());
1175 1265
1176 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16))); 1266 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16)));
1177 EXPECT_FAILURE_INLINE(sig, 1267 EXPECT_FAILURE_INLINE(sig,
1178 WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64V_1(16))); 1268 WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16)));
1179 EXPECT_FAILURE_INLINE(sig, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6))); 1269 EXPECT_FAILURE_INLINE(sig,
1270 WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6)));
1180 } 1271 }
1181 1272
1182 TEST_F(AstDecoderTest, SimpleImportCalls) { 1273 TEST_F(AstDecoderTest, SimpleImportCalls) {
1183 FunctionSig* sig = sigs.i_i(); 1274 FunctionSig* sig = sigs.i_i();
1184 TestModuleEnv module_env; 1275 TestModuleEnv module_env;
1185 module = &module_env; 1276 module = &module_env;
1186 1277
1187 byte f0 = module_env.AddImport(sigs.i_v()); 1278 byte f0 = module_env.AddImport(sigs.i_v());
1188 byte f1 = module_env.AddImport(sigs.i_i()); 1279 byte f1 = module_env.AddImport(sigs.i_i());
1189 byte f2 = module_env.AddImport(sigs.i_ii()); 1280 byte f2 = module_env.AddImport(sigs.i_ii());
1190 1281
1191 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0)); 1282 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT0(f0));
1192 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(22))); 1283 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(22)));
1193 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72))); 1284 EXPECT_VERIFIES_INLINE(sig, WASM_CALL_IMPORT2(f2, WASM_I8(32), WASM_I8(72)));
1194 } 1285 }
1195 1286
1196 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) { 1287 TEST_F(AstDecoderTest, ImportCallsWithMismatchedSigs3) {
1197 FunctionSig* sig = sigs.i_i(); 1288 FunctionSig* sig = sigs.i_i();
1198 TestModuleEnv module_env; 1289 TestModuleEnv module_env;
1199 module = &module_env; 1290 module = &module_env;
1200 1291
1201 byte f0 = module_env.AddImport(sigs.i_f()); 1292 byte f0 = module_env.AddImport(sigs.i_f());
1202 1293
1203 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f0)); 1294 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f0));
1204 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I8(17))); 1295 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I8(17)));
1205 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_I64V_1(27))); 1296 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_I64V_1(27)));
1206 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f0, WASM_F64(37.2))); 1297 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f0, WASM_F64(37.2)));
1207 1298
1208 byte f1 = module_env.AddImport(sigs.i_d()); 1299 byte f1 = module_env.AddImport(sigs.i_d());
1209 1300
1210 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f1)); 1301 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT0(f1));
1211 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I8(16))); 1302 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I8(16)));
1212 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_I64V_1(16))); 1303 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_I64V_1(16)));
1213 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT(f1, WASM_F32(17.6))); 1304 EXPECT_FAILURE_INLINE(sig, WASM_CALL_IMPORT1(f1, WASM_F32(17.6)));
1214 } 1305 }
1215 1306
1216 TEST_F(AstDecoderTest, Int32Globals) { 1307 TEST_F(AstDecoderTest, Int32Globals) {
1217 FunctionSig* sig = sigs.i_i(); 1308 FunctionSig* sig = sigs.i_i();
1218 TestModuleEnv module_env; 1309 TestModuleEnv module_env;
1219 module = &module_env; 1310 module = &module_env;
1220 1311
1221 module_env.AddGlobal(MachineType::Int8()); 1312 module_env.AddGlobal(MachineType::Int8());
1222 module_env.AddGlobal(MachineType::Uint8()); 1313 module_env.AddGlobal(MachineType::Uint8());
1223 module_env.AddGlobal(MachineType::Int16()); 1314 module_env.AddGlobal(MachineType::Int16());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 module_env.AddGlobal(mem_type); 1418 module_env.AddGlobal(mem_type);
1328 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) { 1419 if (local_type == WasmOpcodes::LocalTypeFor(mem_type)) {
1329 EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1420 EXPECT_VERIFIES_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1330 } else { 1421 } else {
1331 EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0))); 1422 EXPECT_FAILURE_INLINE(&sig, WASM_STORE_GLOBAL(0, WASM_GET_LOCAL(0)));
1332 } 1423 }
1333 } 1424 }
1334 } 1425 }
1335 } 1426 }
1336 1427
1428 TEST_F(AstDecoderTest, BreakEnd) {
1429 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1430 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO)));
1431 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1432 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO))));
1433 }
1434
1435 TEST_F(AstDecoderTest, BreakIfBinop) {
1436 EXPECT_FAILURE_INLINE(
1437 sigs.i_i(),
1438 WASM_BLOCK(
1439 1, WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), WASM_ZERO)));
1440 EXPECT_FAILURE_INLINE(
1441 sigs.i_i(),
1442 WASM_BLOCK(
1443 1, WASM_I32_ADD(WASM_ZERO, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))));
1444 }
1445
1337 TEST_F(AstDecoderTest, BreakNesting1) { 1446 TEST_F(AstDecoderTest, BreakNesting1) {
1338 for (int i = 0; i < 5; i++) { 1447 for (int i = 0; i < 5; i++) {
1339 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p) 1448 // (block[2] (loop[2] (if (get p) break[N]) (set p 1)) p)
1340 byte code[] = {WASM_BLOCK( 1449 byte code[] = {WASM_BLOCK(
1341 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i, WASM_ZERO)), 1450 2, WASM_LOOP(2, WASM_IF(WASM_GET_LOCAL(0), WASM_BRV(i + 1, WASM_ZERO)),
1342 WASM_SET_LOCAL(0, WASM_I8(1))), 1451 WASM_SET_LOCAL(0, WASM_I8(1))),
1343 WASM_GET_LOCAL(0))}; 1452 WASM_GET_LOCAL(0))};
1344 if (i < 3) { 1453 if (i < 3) {
1345 EXPECT_VERIFIES(sigs.i_i(), code); 1454 EXPECT_VERIFIES(sigs.i_i(), code);
1346 } else { 1455 } else {
1347 EXPECT_FAILURE(sigs.i_i(), code); 1456 EXPECT_FAILURE(sigs.i_i(), code);
1348 } 1457 }
1349 } 1458 }
1350 } 1459 }
1351 1460
1352 TEST_F(AstDecoderTest, BreakNesting2) { 1461 TEST_F(AstDecoderTest, BreakNesting2) {
1353 AddLocals(kAstI32, 1); 1462 AddLocals(kAstI32, 1);
1354 for (int i = 0; i < 5; i++) { 1463 for (int i = 0; i < 5; i++) {
1355 // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11) 1464 // (block[2] (loop[2] (if 0 break[N]) (set p 1)) (return p)) (11)
1356 byte code[] = {WASM_BLOCK(1, WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i)), 1465 byte code[] = {B1(WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)),
1357 WASM_SET_LOCAL(0, WASM_I8(1)))), 1466 WASM_SET_LOCAL(0, WASM_I8(1)))),
1358 WASM_I8(11)}; 1467 WASM_I8(11)};
1359 if (i < 2) { 1468 if (i < 2) {
1360 EXPECT_VERIFIES(sigs.v_v(), code); 1469 EXPECT_VERIFIES(sigs.v_v(), code);
1361 } else { 1470 } else {
1362 EXPECT_FAILURE(sigs.v_v(), code); 1471 EXPECT_FAILURE(sigs.v_v(), code);
1363 } 1472 }
1364 } 1473 }
1365 } 1474 }
1366 1475
1367 TEST_F(AstDecoderTest, BreakNesting3) { 1476 TEST_F(AstDecoderTest, BreakNesting3) {
1368 for (int i = 0; i < 5; i++) { 1477 for (int i = 0; i < 5; i++) {
1369 // (block[1] (loop[1] (block[1] (if 0 break[N]) 1478 // (block[1] (loop[1] (block[1] (if 0 break[N])
1370 byte code[] = {WASM_BLOCK( 1479 byte code[] = {
1371 1, WASM_LOOP(1, WASM_BLOCK(1, WASM_IF(WASM_ZERO, WASM_BREAK(i)))))}; 1480 WASM_BLOCK(1, WASM_LOOP(1, B1(WASM_IF(WASM_ZERO, WASM_BREAK(i + 1)))))};
1372 if (i < 3) { 1481 if (i < 3) {
1373 EXPECT_VERIFIES(sigs.v_v(), code); 1482 EXPECT_VERIFIES(sigs.v_v(), code);
1374 } else { 1483 } else {
1375 EXPECT_FAILURE(sigs.v_v(), code); 1484 EXPECT_FAILURE(sigs.v_v(), code);
1376 } 1485 }
1377 } 1486 }
1378 } 1487 }
1379 1488
1380 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) { 1489 TEST_F(AstDecoderTest, BreaksWithMultipleTypes) {
1381 EXPECT_FAILURE_INLINE( 1490 EXPECT_FAILURE_INLINE(sigs.i_i(),
1382 sigs.i_i(), 1491 B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
1383 WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), WASM_F32(7.7)));
1384 1492
1385 EXPECT_FAILURE_INLINE(sigs.i_i(), 1493 EXPECT_FAILURE_INLINE(sigs.i_i(), B2(WASM_BRV_IF_ZERO(0, WASM_I8(7)),
1386 WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_I8(7)), 1494 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1387 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1495 EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(8)),
1388 EXPECT_FAILURE_INLINE(sigs.i_i(), 1496 WASM_BRV_IF_ZERO(0, WASM_I8(0)),
1389 WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(8)), 1497 WASM_BRV_IF_ZERO(0, WASM_F32(7.7))));
1390 WASM_BRV_IF_ZERO(0, WASM_I8(0)), 1498 EXPECT_FAILURE_INLINE(sigs.i_i(), B3(WASM_BRV_IF_ZERO(0, WASM_I8(9)),
1391 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)))); 1499 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
1392 EXPECT_FAILURE_INLINE(sigs.i_i(), 1500 WASM_BRV_IF_ZERO(0, WASM_I8(11))));
1393 WASM_BLOCK(3, WASM_BRV_IF_ZERO(0, WASM_I8(9)),
1394 WASM_BRV_IF_ZERO(0, WASM_F32(7.7)),
1395 WASM_BRV_IF_ZERO(0, WASM_I8(11))));
1396 } 1501 }
1397 1502
1398 TEST_F(AstDecoderTest, BreakNesting_6_levels) { 1503 TEST_F(AstDecoderTest, BreakNesting_6_levels) {
1399 for (int mask = 0; mask < 64; mask++) { 1504 for (int mask = 0; mask < 64; mask++) {
1400 for (int i = 0; i < 14; i++) { 1505 for (int i = 0; i < 14; i++) {
1401 byte code[] = { 1506 byte code[] = {
1402 kExprBlock, 1, // -- 1507 kExprBlock, // --
1403 kExprBlock, 1, // -- 1508 kExprBlock, // --
1404 kExprBlock, 1, // -- 1509 kExprBlock, // --
1405 kExprBlock, 1, // -- 1510 kExprBlock, // --
1406 kExprBlock, 1, // -- 1511 kExprBlock, // --
1407 kExprBlock, 1, // -- 1512 kExprBlock, // --
1408 kExprBr, static_cast<byte>(i), 1513 kExprBr, ARITY_0, static_cast<byte>(i), // --
1409 kExprNop // -- 1514 kExprEnd, // --
1515 kExprEnd, // --
1516 kExprEnd, // --
1517 kExprEnd, // --
1518 kExprEnd, // --
1519 kExprEnd // --
1410 }; 1520 };
1411 1521
1412 int depth = 6; 1522 int depth = 6;
1413 for (int l = 0; l < 6; l++) { 1523 for (int l = 0; l < 6; l++) {
1414 if (mask & (1 << l)) { 1524 if (mask & (1 << l)) {
1415 code[l * 2] = kExprLoop; 1525 code[l] = kExprLoop;
1416 depth++; 1526 depth++;
1417 } 1527 }
1418 } 1528 }
1419 1529
1420 if (i < depth) { 1530 if (i < depth) {
1421 EXPECT_VERIFIES(sigs.v_v(), code); 1531 EXPECT_VERIFIES(sigs.v_v(), code);
1422 } else { 1532 } else {
1423 EXPECT_FAILURE(sigs.v_v(), code); 1533 EXPECT_FAILURE(sigs.v_v(), code);
1424 } 1534 }
1425 } 1535 }
1426 } 1536 }
1427 } 1537 }
1428 1538
1429 TEST_F(AstDecoderTest, ExprBreak_TypeCheck) { 1539 TEST_F(AstDecoderTest, ExprBreak_TypeCheck) {
1430 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()}; 1540 FunctionSig* sigarray[] = {sigs.i_i(), sigs.l_l(), sigs.f_ff(), sigs.d_dd()};
1431 for (size_t i = 0; i < arraysize(sigarray); i++) { 1541 for (size_t i = 0; i < arraysize(sigarray); i++) {
1432 FunctionSig* sig = sigarray[i]; 1542 FunctionSig* sig = sigarray[i];
1433 // unify X and X => OK 1543 // unify X and X => OK
1434 EXPECT_VERIFIES_INLINE( 1544 EXPECT_VERIFIES_INLINE(
1435 sig, WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1545 sig, B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1436 WASM_GET_LOCAL(0))); 1546 WASM_GET_LOCAL(0)));
1437 } 1547 }
1438 1548
1439 // unify i32 and f32 => fail 1549 // unify i32 and f32 => fail
1440 EXPECT_FAILURE_INLINE( 1550 EXPECT_FAILURE_INLINE(
1441 sigs.i_i(), 1551 sigs.i_i(),
1442 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2))); 1552 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_ZERO)), WASM_F32(1.2)));
1443 1553
1444 // unify f64 and f64 => OK 1554 // unify f64 and f64 => OK
1445 EXPECT_VERIFIES_INLINE( 1555 EXPECT_VERIFIES_INLINE(
1446 sigs.d_dd(), 1556 sigs.d_dd(),
1447 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1557 B2(WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), WASM_F64(1.2)));
1448 WASM_F64(1.2)));
1449 } 1558 }
1450 1559
1451 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) { 1560 TEST_F(AstDecoderTest, ExprBreak_TypeCheckAll) {
1452 byte code1[] = {WASM_BLOCK(2, 1561 byte code1[] = {WASM_BLOCK(2,
1453 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))), 1562 WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(0))),
1454 WASM_GET_LOCAL(1))}; 1563 WASM_GET_LOCAL(1))};
1455 byte code2[] = { 1564 byte code2[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))),
1456 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(0))), 1565 WASM_GET_LOCAL(1))};
1457 WASM_GET_LOCAL(1))};
1458 1566
1459 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1567 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1460 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1568 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1461 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]}; 1569 LocalType storage[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j]};
1462 FunctionSig sig(1, 2, storage); 1570 FunctionSig sig(1, 2, storage);
1463 1571
1464 if (i == j) { 1572 if (i == j) {
1465 EXPECT_VERIFIES(&sig, code1); 1573 EXPECT_VERIFIES(&sig, code1);
1466 EXPECT_VERIFIES(&sig, code2); 1574 EXPECT_VERIFIES(&sig, code2);
1467 } else { 1575 } else {
1468 EXPECT_FAILURE(&sig, code1); 1576 EXPECT_FAILURE(&sig, code1);
1469 EXPECT_FAILURE(&sig, code2); 1577 EXPECT_FAILURE(&sig, code2);
1470 } 1578 }
1471 } 1579 }
1472 } 1580 }
1473 } 1581 }
1474 1582
1475 TEST_F(AstDecoderTest, ExprBr_Unify) { 1583 TEST_F(AstDecoderTest, ExprBr_Unify) {
1476 for (int which = 0; which < 2; which++) { 1584 for (int which = 0; which < 2; which++) {
1477 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1585 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1478 LocalType type = kLocalTypes[i]; 1586 LocalType type = kLocalTypes[i];
1479 LocalType storage[] = {kAstI32, kAstI32, type}; 1587 LocalType storage[] = {kAstI32, kAstI32, type};
1480 FunctionSig sig(1, 2, storage); 1588 FunctionSig sig(1, 2, storage);
1481 1589
1482 byte code1[] = { 1590 byte code1[] = {B2(WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))),
1483 WASM_BLOCK(2, WASM_IF(WASM_ZERO, WASM_BRV(0, WASM_GET_LOCAL(which))), 1591 WASM_GET_LOCAL(which ^ 1))};
1484 WASM_GET_LOCAL(which ^ 1))};
1485 byte code2[] = { 1592 byte code2[] = {
1486 WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(1, WASM_GET_LOCAL(which))), 1593 WASM_LOOP(2, WASM_IF(WASM_ZERO, WASM_BRV(2, WASM_GET_LOCAL(which))),
1487 WASM_GET_LOCAL(which ^ 1))}; 1594 WASM_GET_LOCAL(which ^ 1))};
1488 1595
1489
1490 if (type == kAstI32) { 1596 if (type == kAstI32) {
1491 EXPECT_VERIFIES(&sig, code1); 1597 EXPECT_VERIFIES(&sig, code1);
1492 EXPECT_VERIFIES(&sig, code2); 1598 EXPECT_VERIFIES(&sig, code2);
1493 } else { 1599 } else {
1494 EXPECT_FAILURE(&sig, code1); 1600 EXPECT_FAILURE(&sig, code1);
1495 EXPECT_FAILURE(&sig, code2); 1601 EXPECT_FAILURE(&sig, code2);
1496 } 1602 }
1497 } 1603 }
1498 } 1604 }
1499 } 1605 }
1500 1606
1501 TEST_F(AstDecoderTest, ExprBrIf_cond_type) { 1607 TEST_F(AstDecoderTest, ExprBrIf_cond_type) {
1502 byte code[] = { 1608 byte code[] = {B1(WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
1503 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)))};
1504 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1609 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1505 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1610 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1506 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]}; 1611 LocalType types[] = {kLocalTypes[i], kLocalTypes[j]};
1507 FunctionSig sig(0, 2, types); 1612 FunctionSig sig(0, 2, types);
1508 1613
1509 if (types[1] == kAstI32) { 1614 if (types[1] == kAstI32) {
1510 EXPECT_VERIFIES(&sig, code); 1615 EXPECT_VERIFIES(&sig, code);
1511 } else { 1616 } else {
1512 EXPECT_FAILURE(&sig, code); 1617 EXPECT_FAILURE(&sig, code);
1513 } 1618 }
1514 } 1619 }
1515 } 1620 }
1516 } 1621 }
1517 1622
1518 TEST_F(AstDecoderTest, ExprBrIf_val_type) { 1623 TEST_F(AstDecoderTest, ExprBrIf_val_type) {
1519 byte code[] = { 1624 byte code[] = {B2(WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)),
1520 WASM_BLOCK(2, WASM_BRV_IF(0, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2)), 1625 WASM_GET_LOCAL(0))};
1521 WASM_GET_LOCAL(0))};
1522 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1626 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1523 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 1627 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
1524 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j], 1628 LocalType types[] = {kLocalTypes[i], kLocalTypes[i], kLocalTypes[j],
1525 kAstI32}; 1629 kAstI32};
1526 FunctionSig sig(1, 3, types); 1630 FunctionSig sig(1, 3, types);
1527 1631
1528 if (i == j) { 1632 if (i == j) {
1529 EXPECT_VERIFIES(&sig, code); 1633 EXPECT_VERIFIES(&sig, code);
1530 } else { 1634 } else {
1531 EXPECT_FAILURE(&sig, code); 1635 EXPECT_FAILURE(&sig, code);
1532 } 1636 }
1533 } 1637 }
1534 } 1638 }
1535 } 1639 }
1536 1640
1537 TEST_F(AstDecoderTest, ExprBrIf_Unify) { 1641 TEST_F(AstDecoderTest, ExprBrIf_Unify) {
1538 for (int which = 0; which < 2; which++) { 1642 for (int which = 0; which < 2; which++) {
1539 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 1643 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
1540 LocalType type = kLocalTypes[i]; 1644 LocalType type = kLocalTypes[i];
1541 LocalType storage[] = {kAstI32, kAstI32, type}; 1645 LocalType storage[] = {kAstI32, kAstI32, type};
1542 FunctionSig sig(1, 2, storage); 1646 FunctionSig sig(1, 2, storage);
1543 1647
1544 byte code1[] = {WASM_BLOCK(2, WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)), 1648 byte code1[] = {B2(WASM_BRV_IF_ZERO(0, WASM_GET_LOCAL(which)),
1545 WASM_GET_LOCAL(which ^ 1))}; 1649 WASM_GET_LOCAL(which ^ 1))};
1546 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)), 1650 byte code2[] = {WASM_LOOP(2, WASM_BRV_IF_ZERO(1, WASM_GET_LOCAL(which)),
1547 WASM_GET_LOCAL(which ^ 1))}; 1651 WASM_GET_LOCAL(which ^ 1))};
1548 1652
1549 if (type == kAstI32) { 1653 if (type == kAstI32) {
1550 EXPECT_VERIFIES(&sig, code1); 1654 EXPECT_VERIFIES(&sig, code1);
1551 EXPECT_VERIFIES(&sig, code2); 1655 EXPECT_VERIFIES(&sig, code2);
1552 } else { 1656 } else {
1553 EXPECT_FAILURE(&sig, code1); 1657 EXPECT_FAILURE(&sig, code1);
1554 EXPECT_FAILURE(&sig, code2); 1658 EXPECT_FAILURE(&sig, code2);
1555 } 1659 }
1556 } 1660 }
1557 } 1661 }
1558 } 1662 }
1559 1663
1560 TEST_F(AstDecoderTest, BrTable0) { 1664 TEST_F(AstDecoderTest, BrTable0) {
1561 static byte code[] = {kExprBrTable, 0, 0}; 1665 static byte code[] = {kExprNop, kExprBrTable, 0, 0};
1562 EXPECT_FAILURE(sigs.v_v(), code); 1666 EXPECT_FAILURE(sigs.v_v(), code);
1563 } 1667 }
1564 1668
1565 TEST_F(AstDecoderTest, BrTable0b) { 1669 TEST_F(AstDecoderTest, BrTable0b) {
1566 static byte code[] = {kExprBrTable, 0, 0, kExprI32Const, 11}; 1670 static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 0};
1567 EXPECT_FAILURE(sigs.v_v(), code); 1671 EXPECT_FAILURE(sigs.v_v(), code);
1568 EXPECT_FAILURE(sigs.i_i(), code); 1672 EXPECT_FAILURE(sigs.i_i(), code);
1569 } 1673 }
1570 1674
1571 TEST_F(AstDecoderTest, BrTable0c) { 1675 TEST_F(AstDecoderTest, BrTable0c) {
1572 static byte code[] = {kExprBrTable, 0, 1, 0, 0, kExprI32Const, 11}; 1676 static byte code[] = {kExprNop, kExprI32Const, 11, kExprBrTable, 0, 1, 0, 0};
1573 EXPECT_FAILURE(sigs.v_v(), code); 1677 EXPECT_FAILURE(sigs.v_v(), code);
1574 EXPECT_FAILURE(sigs.i_i(), code); 1678 EXPECT_FAILURE(sigs.i_i(), code);
1575 } 1679 }
1576 1680
1577 TEST_F(AstDecoderTest, BrTable1a) { 1681 TEST_F(AstDecoderTest, BrTable1a) {
1578 static byte code[] = { 1682 static byte code[] = {B1(WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))};
1579 WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 0, BR_TARGET(0)))};
1580 EXPECT_VERIFIES(sigs.v_v(), code); 1683 EXPECT_VERIFIES(sigs.v_v(), code);
1581 } 1684 }
1582 1685
1583 TEST_F(AstDecoderTest, BrTable1b) { 1686 TEST_F(AstDecoderTest, BrTable1b) {
1584 static byte code[] = { 1687 static byte code[] = {B1(WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
1585 WASM_BLOCK(1, WASM_BR_TABLE(WASM_ZERO, 0, BR_TARGET(0)))};
1586 EXPECT_VERIFIES(sigs.v_v(), code); 1688 EXPECT_VERIFIES(sigs.v_v(), code);
1587 EXPECT_FAILURE(sigs.i_i(), code); 1689 EXPECT_FAILURE(sigs.i_i(), code);
1588 EXPECT_FAILURE(sigs.f_ff(), code); 1690 EXPECT_FAILURE(sigs.f_ff(), code);
1589 EXPECT_FAILURE(sigs.d_dd(), code); 1691 EXPECT_FAILURE(sigs.d_dd(), code);
1590 } 1692 }
1591 1693
1592 TEST_F(AstDecoderTest, BrTable2a) { 1694 TEST_F(AstDecoderTest, BrTable2a) {
1593 static byte code[] = { 1695 static byte code[] = {
1594 WASM_BLOCK(1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))}; 1696 B1(WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(0)))};
1595 EXPECT_VERIFIES(sigs.v_v(), code); 1697 EXPECT_VERIFIES(sigs.v_v(), code);
1596 } 1698 }
1597 1699
1598 TEST_F(AstDecoderTest, BrTable2b) { 1700 TEST_F(AstDecoderTest, BrTable2b) {
1599 static byte code[] = {WASM_BLOCK( 1701 static byte code[] = {WASM_BLOCK(
1600 1, WASM_BLOCK( 1702 1, WASM_BLOCK(
1601 1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))}; 1703 1, WASM_BR_TABLE(WASM_I8(67), 1, BR_TARGET(0), BR_TARGET(1))))};
1602 EXPECT_VERIFIES(sigs.v_v(), code); 1704 EXPECT_VERIFIES(sigs.v_v(), code);
1603 } 1705 }
1604 1706
1605 TEST_F(AstDecoderTest, BrTable_off_end) { 1707 TEST_F(AstDecoderTest, BrTable_off_end) {
1606 static byte code[] = { 1708 static byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
1607 WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(0)))};
1608 for (size_t len = 1; len < sizeof(code); len++) { 1709 for (size_t len = 1; len < sizeof(code); len++) {
1609 Verify(kError, sigs.i_i(), code, code + len); 1710 Verify(kError, sigs.i_i(), code, code + len);
1610 } 1711 }
1611 } 1712 }
1612 1713
1613 TEST_F(AstDecoderTest, BrTable_invalid_br1) { 1714 TEST_F(AstDecoderTest, BrTable_invalid_br1) {
1614 for (int depth = 0; depth < 4; depth++) { 1715 for (int depth = 0; depth < 4; depth++) {
1615 byte code[] = { 1716 byte code[] = {B1(WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1616 WASM_BLOCK(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1617 if (depth == 0) { 1717 if (depth == 0) {
1618 EXPECT_VERIFIES(sigs.v_i(), code); 1718 EXPECT_VERIFIES(sigs.v_i(), code);
1619 } else { 1719 } else {
1620 EXPECT_FAILURE(sigs.v_i(), code); 1720 EXPECT_FAILURE(sigs.v_i(), code);
1621 } 1721 }
1622 } 1722 }
1623 } 1723 }
1624 1724
1625 TEST_F(AstDecoderTest, BrTable_invalid_br2) { 1725 TEST_F(AstDecoderTest, BrTable_invalid_br2) {
1626 for (int depth = 0; depth < 4; depth++) { 1726 for (int depth = 0; depth < 4; depth++) {
1627 byte code[] = { 1727 byte code[] = {
1628 WASM_LOOP(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))}; 1728 WASM_LOOP(1, WASM_BR_TABLE(WASM_GET_LOCAL(0), 0, BR_TARGET(depth)))};
1629 if (depth <= 1) { 1729 if (depth <= 1) {
1630 EXPECT_VERIFIES(sigs.v_i(), code); 1730 EXPECT_VERIFIES(sigs.v_i(), code);
1631 } else { 1731 } else {
1632 EXPECT_FAILURE(sigs.v_i(), code); 1732 EXPECT_FAILURE(sigs.v_i(), code);
1633 } 1733 }
1634 } 1734 }
1635 } 1735 }
1636 1736
1637 TEST_F(AstDecoderTest, ExprBreakNesting1) { 1737 TEST_F(AstDecoderTest, ExprBreakNesting1) {
1638 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BRV(0, WASM_ZERO))); 1738 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV(0, WASM_ZERO)));
1639 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR(0))); 1739 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR(0)));
1640 EXPECT_VERIFIES_INLINE(sigs.v_v(), 1740 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1641 WASM_BLOCK(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1741 EXPECT_VERIFIES_INLINE(sigs.v_v(), B1(WASM_BR_IF(0, WASM_ZERO)));
1642 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_BLOCK(1, WASM_BR_IF(0, WASM_ZERO)));
1643 1742
1644 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO))); 1743 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(0, WASM_ZERO)));
1645 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0))); 1744 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(0)));
1646 EXPECT_VERIFIES_INLINE(sigs.v_v(), 1745 EXPECT_VERIFIES_INLINE(sigs.v_v(),
1647 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO))); 1746 WASM_LOOP(1, WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO)));
1648 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO))); 1747 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO)));
1649 1748
1650 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO))); 1749 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BRV(1, WASM_ZERO)));
1651 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1))); 1750 EXPECT_VERIFIES_INLINE(sigs.v_v(), WASM_LOOP(1, WASM_BR(1)));
1652 } 1751 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 } 1826 }
1728 1827
1729 #define EXPECT_LENGTH_N(expected, ...) \ 1828 #define EXPECT_LENGTH_N(expected, ...) \
1730 { \ 1829 { \
1731 static const byte code[] = {__VA_ARGS__}; \ 1830 static const byte code[] = {__VA_ARGS__}; \
1732 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 1831 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
1733 } 1832 }
1734 1833
1735 TEST_F(WasmOpcodeLengthTest, Statements) { 1834 TEST_F(WasmOpcodeLengthTest, Statements) {
1736 EXPECT_LENGTH(1, kExprNop); 1835 EXPECT_LENGTH(1, kExprNop);
1737 EXPECT_LENGTH(2, kExprBlock); 1836 EXPECT_LENGTH(1, kExprBlock);
1738 EXPECT_LENGTH(2, kExprLoop); 1837 EXPECT_LENGTH(1, kExprLoop);
1739 EXPECT_LENGTH(1, kExprIf); 1838 EXPECT_LENGTH(1, kExprIf);
1740 EXPECT_LENGTH(1, kExprIfElse); 1839 EXPECT_LENGTH(1, kExprElse);
1840 EXPECT_LENGTH(1, kExprEnd);
1741 EXPECT_LENGTH(1, kExprSelect); 1841 EXPECT_LENGTH(1, kExprSelect);
1742 EXPECT_LENGTH(2, kExprBr); 1842 EXPECT_LENGTH(3, kExprBr);
1743 EXPECT_LENGTH(2, kExprBrIf); 1843 EXPECT_LENGTH(3, kExprBrIf);
1744 } 1844 }
1745 1845
1746 1846
1747 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { 1847 TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
1748 EXPECT_LENGTH(2, kExprI8Const); 1848 EXPECT_LENGTH(2, kExprI8Const);
1749 EXPECT_LENGTH(5, kExprF32Const); 1849 EXPECT_LENGTH(5, kExprF32Const);
1750 EXPECT_LENGTH(9, kExprF64Const); 1850 EXPECT_LENGTH(9, kExprF64Const);
1751 EXPECT_LENGTH(2, kExprGetLocal); 1851 EXPECT_LENGTH(2, kExprGetLocal);
1752 EXPECT_LENGTH(2, kExprSetLocal); 1852 EXPECT_LENGTH(2, kExprSetLocal);
1753 EXPECT_LENGTH(2, kExprLoadGlobal); 1853 EXPECT_LENGTH(2, kExprLoadGlobal);
1754 EXPECT_LENGTH(2, kExprStoreGlobal); 1854 EXPECT_LENGTH(2, kExprStoreGlobal);
1755 EXPECT_LENGTH(2, kExprCallFunction); 1855 EXPECT_LENGTH(3, kExprCallFunction);
1756 EXPECT_LENGTH(2, kExprCallImport); 1856 EXPECT_LENGTH(3, kExprCallImport);
1757 EXPECT_LENGTH(2, kExprCallIndirect); 1857 EXPECT_LENGTH(3, kExprCallIndirect);
1758 EXPECT_LENGTH(1, kExprIf); 1858 EXPECT_LENGTH(1, kExprIf);
1759 EXPECT_LENGTH(1, kExprIfElse); 1859 EXPECT_LENGTH(1, kExprBlock);
1760 EXPECT_LENGTH(2, kExprBlock); 1860 EXPECT_LENGTH(1, kExprLoop);
1761 EXPECT_LENGTH(2, kExprLoop); 1861 EXPECT_LENGTH(3, kExprBr);
1762 EXPECT_LENGTH(2, kExprBr); 1862 EXPECT_LENGTH(3, kExprBrIf);
1763 EXPECT_LENGTH(2, kExprBrIf);
1764 } 1863 }
1765 1864
1766 TEST_F(WasmOpcodeLengthTest, I32Const) { 1865 TEST_F(WasmOpcodeLengthTest, I32Const) {
1767 EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1)); 1866 EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1));
1768 EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999)); 1867 EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999));
1769 EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999)); 1868 EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999));
1770 EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999)); 1869 EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999));
1771 EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999)); 1870 EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999));
1772 } 1871 }
1773 1872
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 { \ 2057 { \
1959 static const byte code[] = {__VA_ARGS__}; \ 2058 static const byte code[] = {__VA_ARGS__}; \
1960 EXPECT_EQ(expected, OpcodeArity(&module, sig, code, code + sizeof(code))); \ 2059 EXPECT_EQ(expected, OpcodeArity(&module, sig, code, code + sizeof(code))); \
1961 } 2060 }
1962 2061
1963 TEST_F(WasmOpcodeArityTest, Control) { 2062 TEST_F(WasmOpcodeArityTest, Control) {
1964 FunctionSig* sig = sigs.v_v(); 2063 FunctionSig* sig = sigs.v_v();
1965 EXPECT_ARITY(0, kExprNop); 2064 EXPECT_ARITY(0, kExprNop);
1966 2065
1967 EXPECT_ARITY(0, kExprBlock, 0); 2066 EXPECT_ARITY(0, kExprBlock, 0);
1968 EXPECT_ARITY(1, kExprBlock, 1); 2067 EXPECT_ARITY(0, kExprBlock, 1);
1969 EXPECT_ARITY(2, kExprBlock, 2); 2068 EXPECT_ARITY(0, kExprBlock, 2);
1970 EXPECT_ARITY(5, kExprBlock, 5); 2069 EXPECT_ARITY(0, kExprBlock, 5);
1971 EXPECT_ARITY(10, kExprBlock, 10); 2070 EXPECT_ARITY(0, kExprBlock, 10);
1972 2071
1973 EXPECT_ARITY(0, kExprLoop, 0); 2072 EXPECT_ARITY(0, kExprLoop, 0);
1974 EXPECT_ARITY(1, kExprLoop, 1); 2073 EXPECT_ARITY(0, kExprLoop, 1);
1975 EXPECT_ARITY(2, kExprLoop, 2); 2074 EXPECT_ARITY(0, kExprLoop, 2);
1976 EXPECT_ARITY(7, kExprLoop, 7); 2075 EXPECT_ARITY(0, kExprLoop, 7);
1977 EXPECT_ARITY(11, kExprLoop, 11); 2076 EXPECT_ARITY(0, kExprLoop, 11);
1978 2077
1979 EXPECT_ARITY(2, kExprIf);
1980 EXPECT_ARITY(3, kExprIfElse);
1981 EXPECT_ARITY(3, kExprSelect); 2078 EXPECT_ARITY(3, kExprSelect);
1982 2079
1983 EXPECT_ARITY(1, kExprBr); 2080 EXPECT_ARITY(0, kExprBr);
1984 EXPECT_ARITY(2, kExprBrIf); 2081 EXPECT_ARITY(1, kExprBrIf);
2082 EXPECT_ARITY(1, kExprBrTable);
2083
2084 EXPECT_ARITY(1, kExprBr, ARITY_1);
2085 EXPECT_ARITY(2, kExprBrIf, ARITY_1);
2086 EXPECT_ARITY(2, kExprBrTable, ARITY_1);
1985 2087
1986 { 2088 {
1987 sig = sigs.v_v(); 2089 sig = sigs.v_v();
1988 EXPECT_ARITY(0, kExprReturn); 2090 EXPECT_ARITY(0, kExprReturn, ARITY_0);
1989 sig = sigs.i_i(); 2091 sig = sigs.i_i();
1990 EXPECT_ARITY(1, kExprReturn); 2092 EXPECT_ARITY(1, kExprReturn, ARITY_1);
1991 } 2093 }
1992 } 2094 }
1993 2095
1994 2096
1995 TEST_F(WasmOpcodeArityTest, Misc) { 2097 TEST_F(WasmOpcodeArityTest, Misc) {
1996 FunctionSig* sig = sigs.v_v(); 2098 FunctionSig* sig = sigs.v_v();
1997 EXPECT_ARITY(0, kExprI8Const); 2099 EXPECT_ARITY(0, kExprI8Const);
1998 EXPECT_ARITY(0, kExprI32Const); 2100 EXPECT_ARITY(0, kExprI32Const);
1999 EXPECT_ARITY(0, kExprF32Const); 2101 EXPECT_ARITY(0, kExprF32Const);
2000 EXPECT_ARITY(0, kExprI64Const); 2102 EXPECT_ARITY(0, kExprI64Const);
(...skipping 11 matching lines...) Expand all
2012 2114
2013 module.AddSignature(sigs.f_ff()); 2115 module.AddSignature(sigs.f_ff());
2014 module.AddSignature(sigs.i_d()); 2116 module.AddSignature(sigs.i_d());
2015 2117
2016 module.AddImport(sigs.f_ff()); 2118 module.AddImport(sigs.f_ff());
2017 module.AddImport(sigs.i_d()); 2119 module.AddImport(sigs.i_d());
2018 2120
2019 { 2121 {
2020 FunctionSig* sig = sigs.i_ii(); 2122 FunctionSig* sig = sigs.i_ii();
2021 2123
2022 EXPECT_ARITY(2, kExprCallFunction, 0); 2124 EXPECT_ARITY(2, kExprCallFunction, 2, 0);
2023 EXPECT_ARITY(2, kExprCallImport, 0); 2125 EXPECT_ARITY(2, kExprCallImport, 2, 0);
2024 EXPECT_ARITY(3, kExprCallIndirect, 0); 2126 EXPECT_ARITY(3, kExprCallIndirect, 2, 0);
2025 EXPECT_ARITY(1, kExprBr); 2127
2026 EXPECT_ARITY(2, kExprBrIf); 2128 EXPECT_ARITY(1, kExprBr, ARITY_1);
2129 EXPECT_ARITY(2, kExprBrIf, ARITY_1);
2130 EXPECT_ARITY(2, kExprBrTable, ARITY_1);
2131
2132 EXPECT_ARITY(0, kExprBr, ARITY_0);
2133 EXPECT_ARITY(1, kExprBrIf, ARITY_0);
2134 EXPECT_ARITY(1, kExprBrTable, ARITY_0);
2027 } 2135 }
2028 2136
2029 { 2137 {
2030 FunctionSig* sig = sigs.v_v(); 2138 FunctionSig* sig = sigs.v_v();
2031 2139
2032 EXPECT_ARITY(1, kExprCallFunction, 1); 2140 EXPECT_ARITY(1, kExprCallFunction, ARITY_1, 1);
2033 EXPECT_ARITY(1, kExprCallImport, 1); 2141 EXPECT_ARITY(1, kExprCallImport, ARITY_1, 1);
2034 EXPECT_ARITY(2, kExprCallIndirect, 1); 2142 EXPECT_ARITY(2, kExprCallIndirect, ARITY_1, 1);
2035 EXPECT_ARITY(1, kExprBr); 2143
2036 EXPECT_ARITY(2, kExprBrIf); 2144 EXPECT_ARITY(1, kExprBr, ARITY_1);
2145 EXPECT_ARITY(2, kExprBrIf, ARITY_1);
2146 EXPECT_ARITY(2, kExprBrTable, ARITY_1);
2147
2148 EXPECT_ARITY(0, kExprBr, ARITY_0);
2149 EXPECT_ARITY(1, kExprBrIf, ARITY_0);
2150 EXPECT_ARITY(1, kExprBrTable, ARITY_0);
2037 } 2151 }
2038 } 2152 }
2039 2153
2040 2154
2041 TEST_F(WasmOpcodeArityTest, LoadsAndStores) { 2155 TEST_F(WasmOpcodeArityTest, LoadsAndStores) {
2042 FunctionSig* sig = sigs.v_v(); 2156 FunctionSig* sig = sigs.v_v();
2043 EXPECT_ARITY(1, kExprI32LoadMem8S); 2157 EXPECT_ARITY(1, kExprI32LoadMem8S);
2044 EXPECT_ARITY(1, kExprI32LoadMem8U); 2158 EXPECT_ARITY(1, kExprI32LoadMem8U);
2045 EXPECT_ARITY(1, kExprI32LoadMem16S); 2159 EXPECT_ARITY(1, kExprI32LoadMem16S);
2046 EXPECT_ARITY(1, kExprI32LoadMem16U); 2160 EXPECT_ARITY(1, kExprI32LoadMem16U);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2313 size_t pos = 0; 2427 size_t pos = 0;
2314 pos = ExpectRun(map, pos, kAstF32, 5); 2428 pos = ExpectRun(map, pos, kAstF32, 5);
2315 pos = ExpectRun(map, pos, kAstI32, 1337); 2429 pos = ExpectRun(map, pos, kAstI32, 1337);
2316 pos = ExpectRun(map, pos, kAstI64, 212); 2430 pos = ExpectRun(map, pos, kAstI64, 212);
2317 delete[] data; 2431 delete[] data;
2318 } 2432 }
2319 2433
2320 } // namespace wasm 2434 } // namespace wasm
2321 } // namespace internal 2435 } // namespace internal
2322 } // namespace v8 2436 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/wasm-object-api.js ('k') | test/unittests/wasm/loop-assignment-analysis-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698