Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: src/wasm/wasm-interpreter.cc

Issue 2415533003: [wasm] Rename WasmModuleInstance to WasmInstance. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-interpreter.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
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, 657 static inline int32_t ExecuteGrowMemory(uint32_t delta_pages,
658 WasmModuleInstance* instance) { 658 WasmInstance* instance) {
659 // TODO(ahaas): Move memory allocation to wasm-module.cc for better 659 // TODO(ahaas): Move memory allocation to wasm-module.cc for better
660 // encapsulation. 660 // encapsulation.
661 if (delta_pages > wasm::WasmModule::kMaxMemPages) { 661 if (delta_pages > wasm::WasmModule::kMaxMemPages) {
662 return -1; 662 return -1;
663 } 663 }
664 uint32_t old_size = instance->mem_size; 664 uint32_t old_size = instance->mem_size;
665 uint32_t new_size; 665 uint32_t new_size;
666 byte* new_mem_start; 666 byte* new_mem_start;
667 if (instance->mem_size == 0) { 667 if (instance->mem_size == 0) {
668 if (delta_pages > wasm::WasmModule::kMaxMemPages) { 668 if (delta_pages > wasm::WasmModule::kMaxMemPages) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 code->start = const_cast<byte*>(start); 960 code->start = const_cast<byte*>(start);
961 code->end = const_cast<byte*>(end); 961 code->end = const_cast<byte*>(end);
962 Preprocess(code); 962 Preprocess(code);
963 return true; 963 return true;
964 } 964 }
965 }; 965 };
966 966
967 // Responsible for executing code directly. 967 // Responsible for executing code directly.
968 class ThreadImpl : public WasmInterpreter::Thread { 968 class ThreadImpl : public WasmInterpreter::Thread {
969 public: 969 public:
970 ThreadImpl(Zone* zone, CodeMap* codemap, WasmModuleInstance* instance) 970 ThreadImpl(Zone* zone, CodeMap* codemap, WasmInstance* instance)
971 : codemap_(codemap), 971 : codemap_(codemap),
972 instance_(instance), 972 instance_(instance),
973 stack_(zone), 973 stack_(zone),
974 frames_(zone), 974 frames_(zone),
975 blocks_(zone), 975 blocks_(zone),
976 state_(WasmInterpreter::STOPPED), 976 state_(WasmInterpreter::STOPPED),
977 break_pc_(kInvalidPc), 977 break_pc_(kInvalidPc),
978 trap_reason_(kTrapCount) {} 978 trap_reason_(kTrapCount) {}
979 979
980 virtual ~ThreadImpl() {} 980 virtual ~ThreadImpl() {}
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 }; 1073 };
1074 1074
1075 struct Block { 1075 struct Block {
1076 pc_t pc; 1076 pc_t pc;
1077 sp_t sp; 1077 sp_t sp;
1078 size_t fp; 1078 size_t fp;
1079 unsigned arity; 1079 unsigned arity;
1080 }; 1080 };
1081 1081
1082 CodeMap* codemap_; 1082 CodeMap* codemap_;
1083 WasmModuleInstance* instance_; 1083 WasmInstance* instance_;
1084 ZoneVector<WasmVal> stack_; 1084 ZoneVector<WasmVal> stack_;
1085 ZoneVector<Frame> frames_; 1085 ZoneVector<Frame> frames_;
1086 ZoneVector<Block> blocks_; 1086 ZoneVector<Block> blocks_;
1087 WasmInterpreter::State state_; 1087 WasmInterpreter::State state_;
1088 pc_t break_pc_; 1088 pc_t break_pc_;
1089 TrapReason trap_reason_; 1089 TrapReason trap_reason_;
1090 1090
1091 CodeMap* codemap() { return codemap_; } 1091 CodeMap* codemap() { return codemap_; }
1092 WasmModuleInstance* instance() { return instance_; } 1092 WasmInstance* instance() { return instance_; }
1093 const WasmModule* module() { return instance_->module; } 1093 const WasmModule* module() { return instance_->module; }
1094 1094
1095 void DoTrap(TrapReason trap, pc_t pc) { 1095 void DoTrap(TrapReason trap, pc_t pc) {
1096 state_ = WasmInterpreter::TRAPPED; 1096 state_ = WasmInterpreter::TRAPPED;
1097 trap_reason_ = trap; 1097 trap_reason_ = trap;
1098 CommitPc(pc); 1098 CommitPc(pc);
1099 } 1099 }
1100 1100
1101 // Push a frame with arguments already on the stack. 1101 // Push a frame with arguments already on the stack.
1102 void PushFrame(InterpreterCode* code, pc_t call_pc, pc_t ret_pc) { 1102 void PushFrame(InterpreterCode* code, pc_t call_pc, pc_t ret_pc) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 } 1711 }
1712 } 1712 }
1713 } 1713 }
1714 }; 1714 };
1715 1715
1716 //============================================================================ 1716 //============================================================================
1717 // The implementation details of the interpreter. 1717 // The implementation details of the interpreter.
1718 //============================================================================ 1718 //============================================================================
1719 class WasmInterpreterInternals : public ZoneObject { 1719 class WasmInterpreterInternals : public ZoneObject {
1720 public: 1720 public:
1721 WasmModuleInstance* instance_; 1721 WasmInstance* instance_;
1722 CodeMap codemap_; 1722 CodeMap codemap_;
1723 ZoneVector<ThreadImpl*> threads_; 1723 ZoneVector<ThreadImpl*> threads_;
1724 1724
1725 WasmInterpreterInternals(Zone* zone, WasmModuleInstance* instance) 1725 WasmInterpreterInternals(Zone* zone, WasmInstance* instance)
1726 : instance_(instance), 1726 : instance_(instance),
1727 codemap_(instance_ ? instance_->module : nullptr, zone), 1727 codemap_(instance_ ? instance_->module : nullptr, zone),
1728 threads_(zone) { 1728 threads_(zone) {
1729 threads_.push_back(new ThreadImpl(zone, &codemap_, instance)); 1729 threads_.push_back(new ThreadImpl(zone, &codemap_, instance));
1730 } 1730 }
1731 1731
1732 void Delete() { 1732 void Delete() {
1733 // TODO(titzer): CFI doesn't like threads in the ZoneVector. 1733 // TODO(titzer): CFI doesn't like threads in the ZoneVector.
1734 for (auto t : threads_) delete t; 1734 for (auto t : threads_) delete t;
1735 threads_.resize(0); 1735 threads_.resize(0);
1736 } 1736 }
1737 }; 1737 };
1738 1738
1739 //============================================================================ 1739 //============================================================================
1740 // Implementation of the public interface of the interpreter. 1740 // Implementation of the public interface of the interpreter.
1741 //============================================================================ 1741 //============================================================================
1742 WasmInterpreter::WasmInterpreter(WasmModuleInstance* instance, 1742 WasmInterpreter::WasmInterpreter(WasmInstance* instance,
1743 AccountingAllocator* allocator) 1743 AccountingAllocator* allocator)
1744 : zone_(allocator), 1744 : zone_(allocator),
1745 internals_(new (&zone_) WasmInterpreterInternals(&zone_, instance)) {} 1745 internals_(new (&zone_) WasmInterpreterInternals(&zone_, instance)) {}
1746 1746
1747 WasmInterpreter::~WasmInterpreter() { internals_->Delete(); } 1747 WasmInterpreter::~WasmInterpreter() { internals_->Delete(); }
1748 1748
1749 void WasmInterpreter::Run() { internals_->threads_[0]->Run(); } 1749 void WasmInterpreter::Run() { internals_->threads_[0]->Run(); }
1750 1750
1751 void WasmInterpreter::Pause() { internals_->threads_[0]->Pause(); } 1751 void WasmInterpreter::Pause() { internals_->threads_[0]->Pause(); }
1752 1752
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 1844
1845 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( 1845 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting(
1846 Zone* zone, const byte* start, const byte* end) { 1846 Zone* zone, const byte* start, const byte* end) {
1847 ControlTransfers targets(zone, nullptr, nullptr, start, end); 1847 ControlTransfers targets(zone, nullptr, nullptr, start, end);
1848 return targets.map_; 1848 return targets.map_;
1849 } 1849 }
1850 1850
1851 } // namespace wasm 1851 } // namespace wasm
1852 } // namespace internal 1852 } // namespace internal
1853 } // namespace v8 1853 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-interpreter.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698