| 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 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 control_stack[control_stack.size() - operand.depth - 1].Ref( | 815 control_stack[control_stack.size() - operand.depth - 1].Ref( |
| 816 &map_, start, pc, value_depth, operand.arity > 0); | 816 &map_, start, pc, value_depth, operand.arity > 0); |
| 817 value_depth++; | 817 value_depth++; |
| 818 break; | 818 break; |
| 819 } | 819 } |
| 820 case kExprBrTable: { | 820 case kExprBrTable: { |
| 821 BranchTableOperand operand(&decoder, pc); | 821 BranchTableOperand operand(&decoder, pc); |
| 822 TRACE("control @%td $%zu: BrTable[arity=%u count=%u]\n", (pc - start), | 822 TRACE("control @%td $%zu: BrTable[arity=%u count=%u]\n", (pc - start), |
| 823 value_depth, operand.arity, operand.table_count); | 823 value_depth, operand.arity, operand.table_count); |
| 824 value_depth -= (operand.arity + 1); | 824 value_depth -= (operand.arity + 1); |
| 825 for (uint32_t i = 0; i < operand.table_count + 1; i++) { | 825 for (uint32_t i = 0; i < operand.table_count + 1; ++i) { |
| 826 uint32_t target = operand.read_entry(&decoder, i); | 826 uint32_t target = operand.read_entry(&decoder, i); |
| 827 control_stack[control_stack.size() - target - 1].Ref( | 827 control_stack[control_stack.size() - target - 1].Ref( |
| 828 &map_, start, pc + i, value_depth, operand.arity > 0); | 828 &map_, start, pc + i, value_depth, operand.arity > 0); |
| 829 } | 829 } |
| 830 value_depth++; | 830 value_depth++; |
| 831 break; | 831 break; |
| 832 } | 832 } |
| 833 default: { | 833 default: { |
| 834 value_depth = value_depth - OpcodeArity(pc, end) + 1; | 834 value_depth = value_depth - OpcodeArity(pc, end) + 1; |
| 835 break; | 835 break; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 866 // metadata needed to execute each function. | 866 // metadata needed to execute each function. |
| 867 class CodeMap { | 867 class CodeMap { |
| 868 public: | 868 public: |
| 869 Zone* zone_; | 869 Zone* zone_; |
| 870 const WasmModule* module_; | 870 const WasmModule* module_; |
| 871 ZoneVector<InterpreterCode> interpreter_code_; | 871 ZoneVector<InterpreterCode> interpreter_code_; |
| 872 | 872 |
| 873 CodeMap(const WasmModule* module, Zone* zone) | 873 CodeMap(const WasmModule* module, Zone* zone) |
| 874 : zone_(zone), module_(module), interpreter_code_(zone) { | 874 : zone_(zone), module_(module), interpreter_code_(zone) { |
| 875 if (module == nullptr) return; | 875 if (module == nullptr) return; |
| 876 for (size_t i = 0; i < module->functions.size(); i++) { | 876 for (size_t i = 0; i < module->functions.size(); ++i) { |
| 877 const WasmFunction* function = &module->functions[i]; | 877 const WasmFunction* function = &module->functions[i]; |
| 878 const byte* code_start = | 878 const byte* code_start = |
| 879 module->module_start + function->code_start_offset; | 879 module->module_start + function->code_start_offset; |
| 880 const byte* code_end = module->module_start + function->code_end_offset; | 880 const byte* code_end = module->module_start + function->code_end_offset; |
| 881 AddFunction(function, code_start, code_end); | 881 AddFunction(function, code_start, code_end); |
| 882 } | 882 } |
| 883 } | 883 } |
| 884 | 884 |
| 885 InterpreterCode* FindCode(const WasmFunction* function) { | 885 InterpreterCode* FindCode(const WasmFunction* function) { |
| 886 if (function->func_index < interpreter_code_.size()) { | 886 if (function->func_index < interpreter_code_.size()) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 //========================================================================== | 957 //========================================================================== |
| 958 // Implementation of public interface for WasmInterpreter::Thread. | 958 // Implementation of public interface for WasmInterpreter::Thread. |
| 959 //========================================================================== | 959 //========================================================================== |
| 960 | 960 |
| 961 virtual WasmInterpreter::State state() { return state_; } | 961 virtual WasmInterpreter::State state() { return state_; } |
| 962 | 962 |
| 963 virtual void PushFrame(const WasmFunction* function, WasmVal* args) { | 963 virtual void PushFrame(const WasmFunction* function, WasmVal* args) { |
| 964 InterpreterCode* code = codemap()->FindCode(function); | 964 InterpreterCode* code = codemap()->FindCode(function); |
| 965 CHECK_NOT_NULL(code); | 965 CHECK_NOT_NULL(code); |
| 966 frames_.push_back({code, 0, 0, stack_.size()}); | 966 frames_.push_back({code, 0, 0, stack_.size()}); |
| 967 for (size_t i = 0; i < function->sig->parameter_count(); i++) { | 967 for (size_t i = 0; i < function->sig->parameter_count(); ++i) { |
| 968 stack_.push_back(args[i]); | 968 stack_.push_back(args[i]); |
| 969 } | 969 } |
| 970 frames_.back().ret_pc = InitLocals(code); | 970 frames_.back().ret_pc = InitLocals(code); |
| 971 TRACE(" => PushFrame(#%u @%zu)\n", code->function->func_index, | 971 TRACE(" => PushFrame(#%u @%zu)\n", code->function->func_index, |
| 972 frames_.back().ret_pc); | 972 frames_.back().ret_pc); |
| 973 } | 973 } |
| 974 | 974 |
| 975 virtual WasmInterpreter::State Run() { | 975 virtual WasmInterpreter::State Run() { |
| 976 do { | 976 do { |
| 977 TRACE(" => Run()\n"); | 977 TRACE(" => Run()\n"); |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 PrintF("\n"); | 1650 PrintF("\n"); |
| 1651 } | 1651 } |
| 1652 } | 1652 } |
| 1653 | 1653 |
| 1654 void TraceValueStack() { | 1654 void TraceValueStack() { |
| 1655 Frame* top = frames_.size() > 0 ? &frames_.back() : nullptr; | 1655 Frame* top = frames_.size() > 0 ? &frames_.back() : nullptr; |
| 1656 sp_t sp = top ? top->sp : 0; | 1656 sp_t sp = top ? top->sp : 0; |
| 1657 sp_t plimit = top ? top->plimit() : 0; | 1657 sp_t plimit = top ? top->plimit() : 0; |
| 1658 sp_t llimit = top ? top->llimit() : 0; | 1658 sp_t llimit = top ? top->llimit() : 0; |
| 1659 if (FLAG_trace_wasm_interpreter) { | 1659 if (FLAG_trace_wasm_interpreter) { |
| 1660 for (size_t i = sp; i < stack_.size(); i++) { | 1660 for (size_t i = sp; i < stack_.size(); ++i) { |
| 1661 if (i < plimit) | 1661 if (i < plimit) |
| 1662 PrintF(" p%zu:", i); | 1662 PrintF(" p%zu:", i); |
| 1663 else if (i < llimit) | 1663 else if (i < llimit) |
| 1664 PrintF(" l%zu:", i); | 1664 PrintF(" l%zu:", i); |
| 1665 else | 1665 else |
| 1666 PrintF(" s%zu:", i); | 1666 PrintF(" s%zu:", i); |
| 1667 WasmVal val = stack_[i]; | 1667 WasmVal val = stack_[i]; |
| 1668 switch (val.type) { | 1668 switch (val.type) { |
| 1669 case kAstI32: | 1669 case kAstI32: |
| 1670 PrintF("i32:%d", val.to<int32_t>()); | 1670 PrintF("i32:%d", val.to<int32_t>()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 | 1821 |
| 1822 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1822 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
| 1823 Zone* zone, const byte* start, const byte* end) { | 1823 Zone* zone, const byte* start, const byte* end) { |
| 1824 ControlTransfers targets(zone, 0, start, end); | 1824 ControlTransfers targets(zone, 0, start, end); |
| 1825 return targets.map_; | 1825 return targets.map_; |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 } // namespace wasm | 1828 } // namespace wasm |
| 1829 } // namespace internal | 1829 } // namespace internal |
| 1830 } // namespace v8 | 1830 } // namespace v8 |
| OLD | NEW |