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 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1164 | 1164 |
1165 int DoBreak(InterpreterCode* code, pc_t pc, size_t depth) { | 1165 int DoBreak(InterpreterCode* code, pc_t pc, size_t depth) { |
1166 size_t bp = blocks_.size() - depth - 1; | 1166 size_t bp = blocks_.size() - depth - 1; |
1167 Block* target = &blocks_[bp]; | 1167 Block* target = &blocks_[bp]; |
1168 DoStackTransfer(target->sp, target->arity); | 1168 DoStackTransfer(target->sp, target->arity); |
1169 blocks_.resize(bp); | 1169 blocks_.resize(bp); |
1170 return LookupTarget(code, pc); | 1170 return LookupTarget(code, pc); |
1171 } | 1171 } |
1172 | 1172 |
1173 bool DoReturn(InterpreterCode** code, pc_t* pc, pc_t* limit, size_t arity) { | 1173 bool DoReturn(InterpreterCode** code, pc_t* pc, pc_t* limit, size_t arity) { |
1174 DCHECK_GT(frames_.size(), 0u); | 1174 DCHECK_GT(frames_.size(), 0); |
1175 // Pop all blocks for this frame. | 1175 // Pop all blocks for this frame. |
1176 while (!blocks_.empty() && blocks_.back().fp == frames_.size()) { | 1176 while (!blocks_.empty() && blocks_.back().fp == frames_.size()) { |
1177 blocks_.pop_back(); | 1177 blocks_.pop_back(); |
1178 } | 1178 } |
1179 | 1179 |
1180 sp_t dest = frames_.back().sp; | 1180 sp_t dest = frames_.back().sp; |
1181 frames_.pop_back(); | 1181 frames_.pop_back(); |
1182 if (frames_.size() == 0) { | 1182 if (frames_.size() == 0) { |
1183 // A return from the last frame terminates the execution. | 1183 // A return from the last frame terminates the execution. |
1184 state_ = WasmInterpreter::FINISHED; | 1184 state_ = WasmInterpreter::FINISHED; |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1671 code->start[pc], OpcodeName(code->start[pc])); | 1671 code->start[pc], OpcodeName(code->start[pc])); |
1672 UNREACHABLE(); | 1672 UNREACHABLE(); |
1673 } | 1673 } |
1674 | 1674 |
1675 pc += len; | 1675 pc += len; |
1676 } | 1676 } |
1677 UNREACHABLE(); // above decoding loop should run forever. | 1677 UNREACHABLE(); // above decoding loop should run forever. |
1678 } | 1678 } |
1679 | 1679 |
1680 WasmVal Pop() { | 1680 WasmVal Pop() { |
1681 DCHECK_GT(stack_.size(), 0u); | 1681 DCHECK_GT(stack_.size(), 0); |
1682 DCHECK_GT(frames_.size(), 0u); | 1682 DCHECK_GT(frames_.size(), 0); |
1683 DCHECK_GT(stack_.size(), frames_.back().llimit()); // can't pop into locals | 1683 DCHECK_GT(stack_.size(), frames_.back().llimit()); // can't pop into locals |
1684 WasmVal val = stack_.back(); | 1684 WasmVal val = stack_.back(); |
1685 stack_.pop_back(); | 1685 stack_.pop_back(); |
1686 return val; | 1686 return val; |
1687 } | 1687 } |
1688 | 1688 |
1689 void PopN(int n) { | 1689 void PopN(int n) { |
1690 DCHECK_GE(stack_.size(), static_cast<size_t>(n)); | 1690 DCHECK_GE(stack_.size(), n); |
1691 DCHECK_GT(frames_.size(), 0u); | 1691 DCHECK_GT(frames_.size(), 0); |
1692 size_t nsize = stack_.size() - n; | 1692 size_t nsize = stack_.size() - n; |
1693 DCHECK_GE(nsize, frames_.back().llimit()); // can't pop into locals | 1693 DCHECK_GE(nsize, frames_.back().llimit()); // can't pop into locals |
1694 stack_.resize(nsize); | 1694 stack_.resize(nsize); |
1695 } | 1695 } |
1696 | 1696 |
1697 WasmVal PopArity(size_t arity) { | 1697 WasmVal PopArity(size_t arity) { |
1698 if (arity == 0) return WasmVal(); | 1698 if (arity == 0) return WasmVal(); |
1699 CHECK_EQ(1u, arity); | 1699 CHECK_EQ(1, arity); |
1700 return Pop(); | 1700 return Pop(); |
1701 } | 1701 } |
1702 | 1702 |
1703 void Push(pc_t pc, WasmVal val) { | 1703 void Push(pc_t pc, WasmVal val) { |
1704 // TODO(titzer): store PC as well? | 1704 // TODO(titzer): store PC as well? |
1705 if (val.type != kAstStmt) stack_.push_back(val); | 1705 if (val.type != kAstStmt) stack_.push_back(val); |
1706 } | 1706 } |
1707 | 1707 |
1708 void TraceStack(const char* phase, pc_t pc) { | 1708 void TraceStack(const char* phase, pc_t pc) { |
1709 if (FLAG_trace_wasm_interpreter) { | 1709 if (FLAG_trace_wasm_interpreter) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 | 1888 |
1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1890 Zone* zone, const byte* start, const byte* end) { | 1890 Zone* zone, const byte* start, const byte* end) { |
1891 ControlTransfers targets(zone, nullptr, start, end); | 1891 ControlTransfers targets(zone, nullptr, start, end); |
1892 return targets.map_; | 1892 return targets.map_; |
1893 } | 1893 } |
1894 | 1894 |
1895 } // namespace wasm | 1895 } // namespace wasm |
1896 } // namespace internal | 1896 } // namespace internal |
1897 } // namespace v8 | 1897 } // namespace v8 |
OLD | NEW |