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