OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/signature.h" | 5 #include "src/signature.h" |
6 | 6 |
7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
8 #include "src/flags.h" | 8 #include "src/flags.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ | 379 #define DECLARE_OPCODE_CASE(name, opcode, sig) \ |
380 case kExpr##name: \ | 380 case kExpr##name: \ |
381 return kArity_##sig; | 381 return kArity_##sig; |
382 | 382 |
383 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 383 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
384 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 384 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
385 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) | 385 FOREACH_MISC_MEM_OPCODE(DECLARE_OPCODE_CASE) |
386 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) | 386 FOREACH_SIMPLE_OPCODE(DECLARE_OPCODE_CASE) |
387 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 387 FOREACH_SIMPLE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
388 FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE) | 388 FOREACH_ASMJS_COMPAT_OPCODE(DECLARE_OPCODE_CASE) |
389 FOREACH_SIMD_OPCODE(DECLARE_OPCODE_CASE) | 389 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) |
390 #undef DECLARE_OPCODE_CASE | 390 #undef DECLARE_OPCODE_CASE |
| 391 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
| 392 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) |
| 393 #undef DECLARE_OPCODE_CASE |
| 394 return 1; |
391 default: | 395 default: |
392 UNREACHABLE(); | 396 UNREACHABLE(); |
393 return 0; | 397 return 0; |
394 } | 398 } |
395 } | 399 } |
396 | 400 |
397 unsigned OpcodeLength(const byte* pc) { | 401 unsigned OpcodeLength(const byte* pc) { |
398 switch (static_cast<WasmOpcode>(*pc)) { | 402 switch (static_cast<WasmOpcode>(*pc)) { |
399 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: | 403 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
400 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 404 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 case kExprI8Const: | 453 case kExprI8Const: |
450 return 2; | 454 return 2; |
451 case kExprF32Const: | 455 case kExprF32Const: |
452 return 5; | 456 return 5; |
453 case kExprF64Const: | 457 case kExprF64Const: |
454 return 9; | 458 return 9; |
455 case kExprReturn: { | 459 case kExprReturn: { |
456 ReturnArityOperand operand(this, pc); | 460 ReturnArityOperand operand(this, pc); |
457 return 1 + operand.length; | 461 return 1 + operand.length; |
458 } | 462 } |
459 | 463 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
| 464 FOREACH_SIMD_0_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 2; } |
| 465 FOREACH_SIMD_1_OPERAND_OPCODE(DECLARE_OPCODE_CASE) { return 3; } |
| 466 #undef DECLARE_OPCODE_CASE |
460 default: | 467 default: |
461 return 1; | 468 return 1; |
462 } | 469 } |
463 } | 470 } |
464 }; | 471 }; |
465 | 472 |
466 static const int32_t kFirstFinallyToken = 1; | 473 static const int32_t kFirstFinallyToken = 1; |
467 static const int32_t kFallthroughToken = 0; | 474 static const int32_t kFallthroughToken = 0; |
468 static const int32_t kNullFinallyToken = -1; | 475 static const int32_t kNullFinallyToken = -1; |
469 | 476 |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 len = 1 + operand.length; | 1275 len = 1 + operand.length; |
1269 break; | 1276 break; |
1270 } | 1277 } |
1271 case kSimdPrefix: { | 1278 case kSimdPrefix: { |
1272 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); | 1279 CHECK_PROTOTYPE_OPCODE(wasm_simd_prototype); |
1273 len++; | 1280 len++; |
1274 byte simd_index = *(pc_ + 1); | 1281 byte simd_index = *(pc_ + 1); |
1275 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); | 1282 opcode = static_cast<WasmOpcode>(opcode << 8 | simd_index); |
1276 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, | 1283 TRACE(" @%-4d #%02x #%02x:%-20s|", startrel(pc_), kSimdPrefix, |
1277 simd_index, WasmOpcodes::ShortOpcodeName(opcode)); | 1284 simd_index, WasmOpcodes::ShortOpcodeName(opcode)); |
1278 DecodeSimdOpcode(opcode); | 1285 len += DecodeSimdOpcode(opcode); |
1279 break; | 1286 break; |
1280 } | 1287 } |
1281 default: | 1288 default: |
1282 error("Invalid opcode"); | 1289 error("Invalid opcode"); |
1283 return; | 1290 return; |
1284 } | 1291 } |
1285 } // end complex bytecode | 1292 } // end complex bytecode |
1286 | 1293 |
1287 #if DEBUG | 1294 #if DEBUG |
1288 if (FLAG_trace_wasm_decoder) { | 1295 if (FLAG_trace_wasm_decoder) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 MemoryAccessOperand operand(this, pc_, | 1406 MemoryAccessOperand operand(this, pc_, |
1400 ElementSizeLog2Of(mem_type.representation())); | 1407 ElementSizeLog2Of(mem_type.representation())); |
1401 Value val = Pop(1, type); | 1408 Value val = Pop(1, type); |
1402 Value index = Pop(0, kAstI32); | 1409 Value index = Pop(0, kAstI32); |
1403 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, | 1410 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, |
1404 val.node, position()); | 1411 val.node, position()); |
1405 Push(type, val.node); | 1412 Push(type, val.node); |
1406 return 1 + operand.length; | 1413 return 1 + operand.length; |
1407 } | 1414 } |
1408 | 1415 |
1409 void DecodeSimdOpcode(WasmOpcode opcode) { | 1416 unsigned DecodeSimdOpcode(WasmOpcode opcode) { |
1410 FunctionSig* sig = WasmOpcodes::Signature(opcode); | 1417 unsigned len = 0; |
1411 compiler::NodeVector inputs(sig->parameter_count(), zone_); | 1418 switch (opcode) { |
1412 for (size_t i = sig->parameter_count(); i > 0; i--) { | 1419 case kExprI32x4ExtractLane: { |
1413 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); | 1420 uint8_t lane = this->checked_read_u8(pc_, 2, "lane number"); |
1414 inputs[i - 1] = val.node; | 1421 if (lane < 0 || lane > 3) { |
| 1422 error(pc_, pc_ + 2, "invalid extract lane value"); |
| 1423 } |
| 1424 TFNode* input = Pop(0, LocalType::kSimd128).node; |
| 1425 TFNode* node = BUILD(SimdExtractLane, opcode, lane, input); |
| 1426 Push(LocalType::kWord32, node); |
| 1427 len++; |
| 1428 break; |
| 1429 } |
| 1430 default: { |
| 1431 FunctionSig* sig = WasmOpcodes::Signature(opcode); |
| 1432 if (sig != nullptr) { |
| 1433 compiler::NodeVector inputs(sig->parameter_count(), zone_); |
| 1434 for (size_t i = sig->parameter_count(); i > 0; i--) { |
| 1435 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); |
| 1436 inputs[i - 1] = val.node; |
| 1437 } |
| 1438 TFNode* node = BUILD(SimdOp, opcode, inputs); |
| 1439 Push(GetReturnType(sig), node); |
| 1440 } else { |
| 1441 error(pc_, pc_, "invalid simd opcode"); |
| 1442 } |
| 1443 } |
1415 } | 1444 } |
1416 TFNode* node = BUILD(SimdOp, opcode, inputs); | 1445 return len; |
1417 Push(GetReturnType(sig), node); | |
1418 } | 1446 } |
1419 | 1447 |
1420 void DispatchToTargets(Control* next_block, const Value& val) { | 1448 void DispatchToTargets(Control* next_block, const Value& val) { |
1421 const ZoneVector<IncomingBranch>& incoming_branches = | 1449 const ZoneVector<IncomingBranch>& incoming_branches = |
1422 next_block->try_info->incoming_branches; | 1450 next_block->try_info->incoming_branches; |
1423 // Counts how many successors are not current control block. | 1451 // Counts how many successors are not current control block. |
1424 uint32_t targets = 0; | 1452 uint32_t targets = 0; |
1425 for (const auto& path_token : incoming_branches) { | 1453 for (const auto& path_token : incoming_branches) { |
1426 if (path_token.target != next_block) ++targets; | 1454 if (path_token.target != next_block) ++targets; |
1427 } | 1455 } |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 2102 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
2075 const byte* start, const byte* end) { | 2103 const byte* start, const byte* end) { |
2076 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 2104 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
2077 WasmFullDecoder decoder(zone, nullptr, body); | 2105 WasmFullDecoder decoder(zone, nullptr, body); |
2078 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 2106 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
2079 } | 2107 } |
2080 | 2108 |
2081 } // namespace wasm | 2109 } // namespace wasm |
2082 } // namespace internal | 2110 } // namespace internal |
2083 } // namespace v8 | 2111 } // namespace v8 |
OLD | NEW |