OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/wasm/wasm-interpreter.h" | 5 #include "src/wasm/wasm-interpreter.h" |
6 | 6 |
7 #include "src/utils.h" | 7 #include "src/utils.h" |
8 #include "src/wasm/ast-decoder.h" | 8 #include "src/wasm/ast-decoder.h" |
9 #include "src/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
10 #include "src/wasm/wasm-external-refs.h" | 10 #include "src/wasm/wasm-external-refs.h" |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1435 } else if (type == kAstF64) { | 1435 } else if (type == kAstF64) { |
1436 *reinterpret_cast<double*>(ptr) = val.to<double>(); | 1436 *reinterpret_cast<double*>(ptr) = val.to<double>(); |
1437 } else { | 1437 } else { |
1438 UNREACHABLE(); | 1438 UNREACHABLE(); |
1439 } | 1439 } |
1440 Push(pc, val); | 1440 Push(pc, val); |
1441 len = 1 + operand.length; | 1441 len = 1 + operand.length; |
1442 break; | 1442 break; |
1443 } | 1443 } |
1444 | 1444 |
1445 #define LOAD_CASE(name, ctype, mtype) \ | 1445 #define LOAD_CASE(name, ctype, mtype, machine_type) \ |
1446 case kExpr##name: { \ | 1446 case kExpr##name: { \ |
1447 MemoryAccessOperand operand(&decoder, code->at(pc)); \ | 1447 MemoryAccessOperand operand(&decoder, code->at(pc), machine_type); \ |
1448 uint32_t index = Pop().to<uint32_t>(); \ | 1448 uint32_t index = Pop().to<uint32_t>(); \ |
1449 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ | 1449 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ |
1450 if (operand.offset > effective_mem_size || \ | 1450 if (operand.offset > effective_mem_size || \ |
1451 index > (effective_mem_size - operand.offset)) { \ | 1451 index > (effective_mem_size - operand.offset)) { \ |
1452 return DoTrap(kTrapMemOutOfBounds, pc); \ | 1452 return DoTrap(kTrapMemOutOfBounds, pc); \ |
1453 } \ | 1453 } \ |
1454 byte* addr = instance()->mem_start + operand.offset + index; \ | 1454 byte* addr = instance()->mem_start + operand.offset + index; \ |
1455 WasmVal result(static_cast<ctype>(ReadLittleEndianValue<mtype>(addr))); \ | 1455 WasmVal result(static_cast<ctype>(ReadLittleEndianValue<mtype>(addr))); \ |
1456 Push(pc, result); \ | 1456 Push(pc, result); \ |
1457 len = 1 + operand.length; \ | 1457 len = 1 + operand.length; \ |
1458 break; \ | 1458 break; \ |
1459 } | 1459 } |
1460 | 1460 |
1461 LOAD_CASE(I32LoadMem8S, int32_t, int8_t); | 1461 LOAD_CASE(I32LoadMem8S, int32_t, int8_t, MachineType::Int8()); |
1462 LOAD_CASE(I32LoadMem8U, int32_t, uint8_t); | 1462 LOAD_CASE(I32LoadMem8U, int32_t, uint8_t, MachineType::Uint8()); |
1463 LOAD_CASE(I32LoadMem16S, int32_t, int16_t); | 1463 LOAD_CASE(I32LoadMem16S, int32_t, int16_t, MachineType::Int16()); |
1464 LOAD_CASE(I32LoadMem16U, int32_t, uint16_t); | 1464 LOAD_CASE(I32LoadMem16U, int32_t, uint16_t, MachineType::Uint16()); |
1465 LOAD_CASE(I64LoadMem8S, int64_t, int8_t); | 1465 LOAD_CASE(I64LoadMem8S, int64_t, int8_t, MachineType::Int8()); |
1466 LOAD_CASE(I64LoadMem8U, int64_t, uint8_t); | 1466 LOAD_CASE(I64LoadMem8U, int64_t, uint8_t, MachineType::Uint8()); |
1467 LOAD_CASE(I64LoadMem16S, int64_t, int16_t); | 1467 LOAD_CASE(I64LoadMem16S, int64_t, int16_t, MachineType::Int16()); |
1468 LOAD_CASE(I64LoadMem16U, int64_t, uint16_t); | 1468 LOAD_CASE(I64LoadMem16U, int64_t, uint16_t, MachineType::Uint16()); |
1469 LOAD_CASE(I64LoadMem32S, int64_t, int32_t); | 1469 LOAD_CASE(I64LoadMem32S, int64_t, int32_t, MachineType::Int32()); |
1470 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t); | 1470 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t, MachineType::Uint32()); |
1471 LOAD_CASE(I32LoadMem, int32_t, int32_t); | 1471 LOAD_CASE(I32LoadMem, int32_t, int32_t, MachineType::Int32()); |
1472 LOAD_CASE(I64LoadMem, int64_t, int64_t); | 1472 LOAD_CASE(I64LoadMem, int64_t, int64_t, MachineType::Int64()); |
1473 LOAD_CASE(F32LoadMem, float, float); | 1473 LOAD_CASE(F32LoadMem, float, float, MachineType::Float32()); |
1474 LOAD_CASE(F64LoadMem, double, double); | 1474 LOAD_CASE(F64LoadMem, double, double, MachineType::Float64()); |
1475 #undef LOAD_CASE | 1475 #undef LOAD_CASE |
1476 | 1476 |
1477 #define STORE_CASE(name, ctype, mtype) \ | 1477 #define STORE_CASE(name, ctype, mtype, machine_type) \ |
1478 case kExpr##name: { \ | 1478 case kExpr##name: { \ |
1479 MemoryAccessOperand operand(&decoder, code->at(pc)); \ | 1479 MemoryAccessOperand operand(&decoder, code->at(pc), machine_type); \ |
1480 WasmVal val = Pop(); \ | 1480 WasmVal val = Pop(); \ |
1481 uint32_t index = Pop().to<uint32_t>(); \ | 1481 uint32_t index = Pop().to<uint32_t>(); \ |
1482 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ | 1482 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ |
1483 if (operand.offset > effective_mem_size || \ | 1483 if (operand.offset > effective_mem_size || \ |
1484 index > (effective_mem_size - operand.offset)) { \ | 1484 index > (effective_mem_size - operand.offset)) { \ |
1485 return DoTrap(kTrapMemOutOfBounds, pc); \ | 1485 return DoTrap(kTrapMemOutOfBounds, pc); \ |
1486 } \ | 1486 } \ |
1487 byte* addr = instance()->mem_start + operand.offset + index; \ | 1487 byte* addr = instance()->mem_start + operand.offset + index; \ |
1488 WriteLittleEndianValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \ | 1488 WriteLittleEndianValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \ |
1489 Push(pc, val); \ | 1489 Push(pc, val); \ |
1490 len = 1 + operand.length; \ | 1490 len = 1 + operand.length; \ |
1491 break; \ | 1491 break; \ |
1492 } | 1492 } |
1493 | 1493 |
1494 STORE_CASE(I32StoreMem8, int32_t, int8_t); | 1494 STORE_CASE(I32StoreMem8, int32_t, int8_t, MachineType::Int8()); |
1495 STORE_CASE(I32StoreMem16, int32_t, int16_t); | 1495 STORE_CASE(I32StoreMem16, int32_t, int16_t, MachineType::Int16()); |
1496 STORE_CASE(I64StoreMem8, int64_t, int8_t); | 1496 STORE_CASE(I64StoreMem8, int64_t, int8_t, MachineType::Int8()); |
1497 STORE_CASE(I64StoreMem16, int64_t, int16_t); | 1497 STORE_CASE(I64StoreMem16, int64_t, int16_t, MachineType::Int16()); |
1498 STORE_CASE(I64StoreMem32, int64_t, int32_t); | 1498 STORE_CASE(I64StoreMem32, int64_t, int32_t, MachineType::Int32()); |
1499 STORE_CASE(I32StoreMem, int32_t, int32_t); | 1499 STORE_CASE(I32StoreMem, int32_t, int32_t, MachineType::Int32()); |
1500 STORE_CASE(I64StoreMem, int64_t, int64_t); | 1500 STORE_CASE(I64StoreMem, int64_t, int64_t, MachineType::Int64()); |
1501 STORE_CASE(F32StoreMem, float, float); | 1501 STORE_CASE(F32StoreMem, float, float, MachineType::Float32()); |
1502 STORE_CASE(F64StoreMem, double, double); | 1502 STORE_CASE(F64StoreMem, double, double, MachineType::Float64()); |
1503 #undef STORE_CASE | 1503 #undef STORE_CASE |
1504 | 1504 |
1505 #define ASMJS_LOAD_CASE(name, ctype, mtype, defval) \ | 1505 #define ASMJS_LOAD_CASE(name, ctype, mtype, defval) \ |
1506 case kExpr##name: { \ | 1506 case kExpr##name: { \ |
1507 uint32_t index = Pop().to<uint32_t>(); \ | 1507 uint32_t index = Pop().to<uint32_t>(); \ |
1508 ctype result; \ | 1508 ctype result; \ |
1509 if (index >= (instance()->mem_size - sizeof(mtype))) { \ | 1509 if (index >= (instance()->mem_size - sizeof(mtype))) { \ |
1510 result = defval; \ | 1510 result = defval; \ |
1511 } else { \ | 1511 } else { \ |
1512 byte* addr = instance()->mem_start + index; \ | 1512 byte* addr = instance()->mem_start + index; \ |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 | 1804 |
1805 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1805 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1806 Zone* zone, const byte* start, const byte* end) { | 1806 Zone* zone, const byte* start, const byte* end) { |
1807 ControlTransfers targets(zone, 0, start, end); | 1807 ControlTransfers targets(zone, 0, start, end); |
1808 return targets.map_; | 1808 return targets.map_; |
1809 } | 1809 } |
1810 | 1810 |
1811 } // namespace wasm | 1811 } // namespace wasm |
1812 } // namespace internal | 1812 } // namespace internal |
1813 } // namespace v8 | 1813 } // namespace v8 |
OLD | NEW |