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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 } | 647 } |
648 | 648 |
649 static inline int32_t ExecuteI32ReinterpretF32(float a, TrapReason* trap) { | 649 static inline int32_t ExecuteI32ReinterpretF32(float a, TrapReason* trap) { |
650 return bit_cast<int32_t>(a); | 650 return bit_cast<int32_t>(a); |
651 } | 651 } |
652 | 652 |
653 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { | 653 static inline int64_t ExecuteI64ReinterpretF64(double a, TrapReason* trap) { |
654 return bit_cast<int64_t>(a); | 654 return bit_cast<int64_t>(a); |
655 } | 655 } |
656 | 656 |
657 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages, | |
658 WasmModuleInstance* instance) { | |
659 uint32_t old_size = instance->mem_size; | |
660 uint32_t new_size; | |
661 byte* new_mem_start; | |
662 if (instance->mem_size == 0) { | |
663 if (delta_pages > wasm::WasmModule::kMaxMemPages) { | |
664 return -1; | |
665 } | |
666 // TODO(gdeepti): Fix bounds check to take into account size of memtype. | |
667 new_size = delta_pages * wasm::WasmModule::kPageSize; | |
668 new_mem_start = static_cast<byte*>(calloc(new_size, sizeof(byte))); | |
669 if (!new_mem_start) { | |
670 return -1; | |
671 } | |
672 } else { | |
673 DCHECK_NOT_NULL(instance->mem_start); | |
674 new_size = old_size + delta_pages * wasm::WasmModule::kPageSize; | |
675 if (new_size > | |
676 wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) { | |
677 return -1; | |
678 } | |
679 new_mem_start = static_cast<byte*>(realloc(instance->mem_start, new_size)); | |
titzer
2016/09/14 07:57:08
Can you put a TODO here to call back into somethin
ahaas
2016/09/14 08:47:18
Done.
| |
680 if (!new_mem_start) { | |
681 return -1; | |
682 } | |
683 // Zero initializing uninitialized memory from realloc | |
684 memset(new_mem_start + old_size, 0, new_size - old_size); | |
685 } | |
686 instance->mem_start = new_mem_start; | |
687 instance->mem_size = new_size; | |
688 // realloc | |
689 // update mem_start | |
690 // update mem_size | |
691 return static_cast<int32_t>(old_size / WasmModule::kPageSize); | |
692 } | |
693 | |
657 enum InternalOpcode { | 694 enum InternalOpcode { |
658 #define DECL_INTERNAL_ENUM(name, value) kInternal##name = value, | 695 #define DECL_INTERNAL_ENUM(name, value) kInternal##name = value, |
659 FOREACH_INTERNAL_OPCODE(DECL_INTERNAL_ENUM) | 696 FOREACH_INTERNAL_OPCODE(DECL_INTERNAL_ENUM) |
660 #undef DECL_INTERNAL_ENUM | 697 #undef DECL_INTERNAL_ENUM |
661 }; | 698 }; |
662 | 699 |
663 static const char* OpcodeName(uint32_t val) { | 700 static const char* OpcodeName(uint32_t val) { |
664 switch (val) { | 701 switch (val) { |
665 #define DECL_INTERNAL_CASE(name, value) \ | 702 #define DECL_INTERNAL_CASE(name, value) \ |
666 case kInternal##name: \ | 703 case kInternal##name: \ |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1539 Push(pc, val); \ | 1576 Push(pc, val); \ |
1540 break; \ | 1577 break; \ |
1541 } | 1578 } |
1542 | 1579 |
1543 ASMJS_STORE_CASE(I32AsmjsStoreMem8, int32_t, int8_t); | 1580 ASMJS_STORE_CASE(I32AsmjsStoreMem8, int32_t, int8_t); |
1544 ASMJS_STORE_CASE(I32AsmjsStoreMem16, int32_t, int16_t); | 1581 ASMJS_STORE_CASE(I32AsmjsStoreMem16, int32_t, int16_t); |
1545 ASMJS_STORE_CASE(I32AsmjsStoreMem, int32_t, int32_t); | 1582 ASMJS_STORE_CASE(I32AsmjsStoreMem, int32_t, int32_t); |
1546 ASMJS_STORE_CASE(F32AsmjsStoreMem, float, float); | 1583 ASMJS_STORE_CASE(F32AsmjsStoreMem, float, float); |
1547 ASMJS_STORE_CASE(F64AsmjsStoreMem, double, double); | 1584 ASMJS_STORE_CASE(F64AsmjsStoreMem, double, double); |
1548 #undef ASMJS_STORE_CASE | 1585 #undef ASMJS_STORE_CASE |
1549 | 1586 case kExprGrowMemory: { |
1587 uint32_t delta_pages = Pop().to<uint32_t>(); | |
1588 Push(pc, WasmVal(ExecuteGrowMemory(delta_pages, instance()))); | |
1589 break; | |
1590 } | |
1550 case kExprMemorySize: { | 1591 case kExprMemorySize: { |
1551 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size))); | 1592 Push(pc, WasmVal(static_cast<uint32_t>(instance()->mem_size))); |
1552 break; | 1593 break; |
1553 } | 1594 } |
1554 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \ | 1595 #define EXECUTE_SIMPLE_BINOP(name, ctype, op) \ |
1555 case kExpr##name: { \ | 1596 case kExpr##name: { \ |
1556 WasmVal rval = Pop(); \ | 1597 WasmVal rval = Pop(); \ |
1557 WasmVal lval = Pop(); \ | 1598 WasmVal lval = Pop(); \ |
1558 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \ | 1599 WasmVal result(lval.to<ctype>() op rval.to<ctype>()); \ |
1559 Push(pc, result); \ | 1600 Push(pc, result); \ |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1804 | 1845 |
1805 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1846 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1806 Zone* zone, const byte* start, const byte* end) { | 1847 Zone* zone, const byte* start, const byte* end) { |
1807 ControlTransfers targets(zone, 0, start, end); | 1848 ControlTransfers targets(zone, 0, start, end); |
1808 return targets.map_; | 1849 return targets.map_; |
1809 } | 1850 } |
1810 | 1851 |
1811 } // namespace wasm | 1852 } // namespace wasm |
1812 } // namespace internal | 1853 } // namespace internal |
1813 } // namespace v8 | 1854 } // namespace v8 |
OLD | NEW |