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 #include "src/wasm/ast-decoder.h" | 6 #include "src/wasm/ast-decoder.h" |
7 #include "src/wasm/decoder.h" | 7 #include "src/wasm/decoder.h" |
8 #include "src/wasm/wasm-external-refs.h" | 8 #include "src/wasm/wasm-external-refs.h" |
9 #include "src/wasm/wasm-module.h" | 9 #include "src/wasm/wasm-module.h" |
10 | 10 |
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1430 } else if (type == MachineType::Float64()) { | 1430 } else if (type == MachineType::Float64()) { |
1431 *reinterpret_cast<double*>(ptr) = val.to<double>(); | 1431 *reinterpret_cast<double*>(ptr) = val.to<double>(); |
1432 } else { | 1432 } else { |
1433 UNREACHABLE(); | 1433 UNREACHABLE(); |
1434 } | 1434 } |
1435 Push(pc, val); | 1435 Push(pc, val); |
1436 len = 1 + operand.length; | 1436 len = 1 + operand.length; |
1437 break; | 1437 break; |
1438 } | 1438 } |
1439 | 1439 |
1440 #define LOAD_CASE(name, ctype, mtype) \ | 1440 #define LOAD_CASE(name, ctype, mtype) \ |
1441 case kExpr##name: { \ | 1441 case kExpr##name: { \ |
1442 MemoryAccessOperand operand(&decoder, code->at(pc)); \ | 1442 MemoryAccessOperand operand(&decoder, code->at(pc)); \ |
1443 uint32_t index = Pop().to<uint32_t>(); \ | 1443 uint32_t index = Pop().to<uint32_t>(); \ |
1444 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ | 1444 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ |
1445 if (operand.offset > effective_mem_size || \ | 1445 if (operand.offset > effective_mem_size || \ |
1446 index > (effective_mem_size - operand.offset)) { \ | 1446 index > (effective_mem_size - operand.offset)) { \ |
1447 return DoTrap(kTrapMemOutOfBounds, pc); \ | 1447 return DoTrap(kTrapMemOutOfBounds, pc); \ |
1448 } \ | 1448 } \ |
1449 byte* addr = instance()->mem_start + operand.offset + index; \ | 1449 byte* addr = instance()->mem_start + operand.offset + index; \ |
1450 WasmVal result(static_cast<ctype>(ReadUnalignedValue<mtype>(addr))); \ | 1450 WasmVal result(static_cast<ctype>(ReadLittleEndianValue<mtype>(addr))); \ |
titzer
2016/06/06 07:44:00
I think you can use the routines in decoder.h for
ivica.bogosavljevic
2016/06/13 14:59:02
I would like to leave this method as it is, becaus
| |
1451 Push(pc, result); \ | 1451 Push(pc, result); \ |
1452 len = 1 + operand.length; \ | 1452 len = 1 + operand.length; \ |
1453 break; \ | 1453 break; \ |
1454 } | 1454 } |
1455 | 1455 |
1456 LOAD_CASE(I32LoadMem8S, int32_t, int8_t); | 1456 LOAD_CASE(I32LoadMem8S, int32_t, int8_t); |
1457 LOAD_CASE(I32LoadMem8U, int32_t, uint8_t); | 1457 LOAD_CASE(I32LoadMem8U, int32_t, uint8_t); |
1458 LOAD_CASE(I32LoadMem16S, int32_t, int16_t); | 1458 LOAD_CASE(I32LoadMem16S, int32_t, int16_t); |
1459 LOAD_CASE(I32LoadMem16U, int32_t, uint16_t); | 1459 LOAD_CASE(I32LoadMem16U, int32_t, uint16_t); |
1460 LOAD_CASE(I64LoadMem8S, int64_t, int8_t); | 1460 LOAD_CASE(I64LoadMem8S, int64_t, int8_t); |
1461 LOAD_CASE(I64LoadMem8U, int64_t, uint8_t); | 1461 LOAD_CASE(I64LoadMem8U, int64_t, uint8_t); |
1462 LOAD_CASE(I64LoadMem16S, int64_t, int16_t); | 1462 LOAD_CASE(I64LoadMem16S, int64_t, int16_t); |
1463 LOAD_CASE(I64LoadMem16U, int64_t, uint16_t); | 1463 LOAD_CASE(I64LoadMem16U, int64_t, uint16_t); |
1464 LOAD_CASE(I64LoadMem32S, int64_t, int32_t); | 1464 LOAD_CASE(I64LoadMem32S, int64_t, int32_t); |
1465 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t); | 1465 LOAD_CASE(I64LoadMem32U, int64_t, uint32_t); |
1466 LOAD_CASE(I32LoadMem, int32_t, int32_t); | 1466 LOAD_CASE(I32LoadMem, int32_t, int32_t); |
1467 LOAD_CASE(I64LoadMem, int64_t, int64_t); | 1467 LOAD_CASE(I64LoadMem, int64_t, int64_t); |
1468 LOAD_CASE(F32LoadMem, float, float); | 1468 LOAD_CASE(F32LoadMem, float, float); |
1469 LOAD_CASE(F64LoadMem, double, double); | 1469 LOAD_CASE(F64LoadMem, double, double); |
1470 #undef LOAD_CASE | 1470 #undef LOAD_CASE |
1471 | 1471 |
1472 #define STORE_CASE(name, ctype, mtype) \ | 1472 #define STORE_CASE(name, ctype, mtype) \ |
1473 case kExpr##name: { \ | 1473 case kExpr##name: { \ |
1474 MemoryAccessOperand operand(&decoder, code->at(pc)); \ | 1474 MemoryAccessOperand operand(&decoder, code->at(pc)); \ |
1475 WasmVal val = Pop(); \ | 1475 WasmVal val = Pop(); \ |
1476 uint32_t index = Pop().to<uint32_t>(); \ | 1476 uint32_t index = Pop().to<uint32_t>(); \ |
1477 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ | 1477 size_t effective_mem_size = instance()->mem_size - sizeof(mtype); \ |
1478 if (operand.offset > effective_mem_size || \ | 1478 if (operand.offset > effective_mem_size || \ |
1479 index > (effective_mem_size - operand.offset)) { \ | 1479 index > (effective_mem_size - operand.offset)) { \ |
1480 return DoTrap(kTrapMemOutOfBounds, pc); \ | 1480 return DoTrap(kTrapMemOutOfBounds, pc); \ |
1481 } \ | 1481 } \ |
1482 byte* addr = instance()->mem_start + operand.offset + index; \ | 1482 byte* addr = instance()->mem_start + operand.offset + index; \ |
1483 WriteUnalignedValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \ | 1483 WriteLittleEndianValue<mtype>(addr, static_cast<mtype>(val.to<ctype>())); \ |
1484 Push(pc, val); \ | 1484 Push(pc, val); \ |
1485 len = 1 + operand.length; \ | 1485 len = 1 + operand.length; \ |
1486 break; \ | 1486 break; \ |
1487 } | 1487 } |
1488 | 1488 |
1489 STORE_CASE(I32StoreMem8, int32_t, int8_t); | 1489 STORE_CASE(I32StoreMem8, int32_t, int8_t); |
1490 STORE_CASE(I32StoreMem16, int32_t, int16_t); | 1490 STORE_CASE(I32StoreMem16, int32_t, int16_t); |
1491 STORE_CASE(I64StoreMem8, int64_t, int8_t); | 1491 STORE_CASE(I64StoreMem8, int64_t, int8_t); |
1492 STORE_CASE(I64StoreMem16, int64_t, int16_t); | 1492 STORE_CASE(I64StoreMem16, int64_t, int16_t); |
1493 STORE_CASE(I64StoreMem32, int64_t, int32_t); | 1493 STORE_CASE(I64StoreMem32, int64_t, int32_t); |
1494 STORE_CASE(I32StoreMem, int32_t, int32_t); | 1494 STORE_CASE(I32StoreMem, int32_t, int32_t); |
1495 STORE_CASE(I64StoreMem, int64_t, int64_t); | 1495 STORE_CASE(I64StoreMem, int64_t, int64_t); |
1496 STORE_CASE(F32StoreMem, float, float); | 1496 STORE_CASE(F32StoreMem, float, float); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1793 | 1793 |
1794 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1794 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1795 Zone* zone, const byte* start, const byte* end) { | 1795 Zone* zone, const byte* start, const byte* end) { |
1796 ControlTransfers targets(zone, 0, start, end); | 1796 ControlTransfers targets(zone, 0, start, end); |
1797 return targets.map_; | 1797 return targets.map_; |
1798 } | 1798 } |
1799 | 1799 |
1800 } // namespace wasm | 1800 } // namespace wasm |
1801 } // namespace internal | 1801 } // namespace internal |
1802 } // namespace v8 | 1802 } // namespace v8 |
OLD | NEW |