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 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1668 } | 1668 } |
1669 }; | 1669 }; |
1670 | 1670 |
1671 //============================================================================ | 1671 //============================================================================ |
1672 // The implementation details of the interpreter. | 1672 // The implementation details of the interpreter. |
1673 //============================================================================ | 1673 //============================================================================ |
1674 class WasmInterpreterInternals : public ZoneObject { | 1674 class WasmInterpreterInternals : public ZoneObject { |
1675 public: | 1675 public: |
1676 WasmModuleInstance* instance_; | 1676 WasmModuleInstance* instance_; |
1677 CodeMap codemap_; | 1677 CodeMap codemap_; |
1678 ZoneVector<ThreadImpl> threads_; | 1678 ZoneVector<ThreadImpl*> threads_; |
1679 | 1679 |
1680 WasmInterpreterInternals(Zone* zone, WasmModuleInstance* instance) | 1680 WasmInterpreterInternals(Zone* zone, WasmModuleInstance* instance) |
1681 : instance_(instance), | 1681 : instance_(instance), |
1682 codemap_(instance_ ? instance_->module : nullptr, zone), | 1682 codemap_(instance_ ? instance_->module : nullptr, zone), |
1683 threads_(zone) { | 1683 threads_(zone) { |
1684 threads_.push_back(ThreadImpl(zone, &codemap_, instance)); | 1684 threads_.push_back(new ThreadImpl(zone, &codemap_, instance)); |
1685 } | |
1686 | |
1687 void Delete() { | |
1688 // TODO(titzer): CFI doesn't like threads in the ZoneVector. | |
1689 for (auto t : threads_) delete t; | |
1690 threads_.resize(0); | |
1685 } | 1691 } |
1686 }; | 1692 }; |
1687 | 1693 |
1688 //============================================================================ | 1694 //============================================================================ |
1689 // Implementation of the public interface of the interpreter. | 1695 // Implementation of the public interface of the interpreter. |
1690 //============================================================================ | 1696 //============================================================================ |
1691 WasmInterpreter::WasmInterpreter(WasmModuleInstance* instance, | 1697 WasmInterpreter::WasmInterpreter(WasmModuleInstance* instance, |
1692 base::AccountingAllocator* allocator) | 1698 base::AccountingAllocator* allocator) |
1693 : zone_(allocator), | 1699 : zone_(allocator), |
1694 internals_(new (&zone_) WasmInterpreterInternals(&zone_, instance)) {} | 1700 internals_(new (&zone_) WasmInterpreterInternals(&zone_, instance)) {} |
1695 | 1701 |
1696 WasmInterpreter::~WasmInterpreter() {} | 1702 WasmInterpreter::~WasmInterpreter() { internals_->Delete(); } |
ahaas
2016/06/09 14:07:17
I wonder if it would be useful to use a SmartPoint
| |
1697 | 1703 |
1698 void WasmInterpreter::Run() { internals_->threads_[0].Run(); } | 1704 void WasmInterpreter::Run() { internals_->threads_[0]->Run(); } |
1699 | 1705 |
1700 void WasmInterpreter::Pause() { internals_->threads_[0].Pause(); } | 1706 void WasmInterpreter::Pause() { internals_->threads_[0]->Pause(); } |
1701 | 1707 |
1702 bool WasmInterpreter::SetBreakpoint(const WasmFunction* function, pc_t pc, | 1708 bool WasmInterpreter::SetBreakpoint(const WasmFunction* function, pc_t pc, |
1703 bool enabled) { | 1709 bool enabled) { |
1704 InterpreterCode* code = internals_->codemap_.FindCode(function); | 1710 InterpreterCode* code = internals_->codemap_.FindCode(function); |
1705 if (!code) return false; | 1711 if (!code) return false; |
1706 size_t size = static_cast<size_t>(code->end - code->start); | 1712 size_t size = static_cast<size_t>(code->end - code->start); |
1707 // Check bounds for {pc}. | 1713 // Check bounds for {pc}. |
1708 if (pc < code->locals.decls_encoded_size || pc >= size) return false; | 1714 if (pc < code->locals.decls_encoded_size || pc >= size) return false; |
1709 // Make a copy of the code before enabling a breakpoint. | 1715 // Make a copy of the code before enabling a breakpoint. |
1710 if (enabled && code->orig_start == code->start) { | 1716 if (enabled && code->orig_start == code->start) { |
(...skipping 22 matching lines...) Expand all Loading... | |
1733 | 1739 |
1734 bool WasmInterpreter::SetTracing(const WasmFunction* function, bool enabled) { | 1740 bool WasmInterpreter::SetTracing(const WasmFunction* function, bool enabled) { |
1735 UNIMPLEMENTED(); | 1741 UNIMPLEMENTED(); |
1736 return false; | 1742 return false; |
1737 } | 1743 } |
1738 | 1744 |
1739 int WasmInterpreter::GetThreadCount() { | 1745 int WasmInterpreter::GetThreadCount() { |
1740 return 1; // only one thread for now. | 1746 return 1; // only one thread for now. |
1741 } | 1747 } |
1742 | 1748 |
1743 WasmInterpreter::Thread& WasmInterpreter::GetThread(int id) { | 1749 WasmInterpreter::Thread* WasmInterpreter::GetThread(int id) { |
1744 CHECK_EQ(0, id); // only one thread for now. | 1750 CHECK_EQ(0, id); // only one thread for now. |
1745 return internals_->threads_[id]; | 1751 return internals_->threads_[id]; |
1746 } | 1752 } |
1747 | 1753 |
1748 WasmVal WasmInterpreter::GetLocalVal(const WasmFrame* frame, int index) { | 1754 WasmVal WasmInterpreter::GetLocalVal(const WasmFrame* frame, int index) { |
1749 CHECK_GE(index, 0); | 1755 CHECK_GE(index, 0); |
1750 UNIMPLEMENTED(); | 1756 UNIMPLEMENTED(); |
1751 WasmVal none; | 1757 WasmVal none; |
1752 none.type = kAstStmt; | 1758 none.type = kAstStmt; |
1753 return none; | 1759 return none; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1793 | 1799 |
1794 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1800 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1795 Zone* zone, const byte* start, const byte* end) { | 1801 Zone* zone, const byte* start, const byte* end) { |
1796 ControlTransfers targets(zone, 0, start, end); | 1802 ControlTransfers targets(zone, 0, start, end); |
1797 return targets.map_; | 1803 return targets.map_; |
1798 } | 1804 } |
1799 | 1805 |
1800 } // namespace wasm | 1806 } // namespace wasm |
1801 } // namespace internal | 1807 } // namespace internal |
1802 } // namespace v8 | 1808 } // namespace v8 |
OLD | NEW |