| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/interpreter.h" | 5 #include "src/interpreter/interpreter.h" |
| 6 | 6 |
| 7 #include "src/ast/prettyprinter.h" | 7 #include "src/ast/prettyprinter.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/factory.h" | 10 #include "src/factory.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 if (IsDispatchTableInitialized()) return; | 30 if (IsDispatchTableInitialized()) return; |
| 31 Zone zone; | 31 Zone zone; |
| 32 HandleScope scope(isolate_); | 32 HandleScope scope(isolate_); |
| 33 | 33 |
| 34 #define GENERATE_CODE(Name, ...) \ | 34 #define GENERATE_CODE(Name, ...) \ |
| 35 { \ | 35 { \ |
| 36 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name); \ | 36 InterpreterAssembler assembler(isolate_, &zone, Bytecode::k##Name); \ |
| 37 Do##Name(&assembler); \ | 37 Do##Name(&assembler); \ |
| 38 Handle<Code> code = assembler.GenerateCode(); \ | 38 Handle<Code> code = assembler.GenerateCode(); \ |
| 39 TraceCodegen(code, #Name); \ | 39 TraceCodegen(code, #Name); \ |
| 40 int index = static_cast<int>(Bytecode::k##Name); \ | 40 dispatch_table_[Bytecodes::ToByte(Bytecode::k##Name)] = *code; \ |
| 41 dispatch_table_[index] = *code; \ | |
| 42 } | 41 } |
| 43 BYTECODE_LIST(GENERATE_CODE) | 42 BYTECODE_LIST(GENERATE_CODE) |
| 44 #undef GENERATE_CODE | 43 #undef GENERATE_CODE |
| 45 } | 44 } |
| 46 | 45 |
| 46 Code* Interpreter::GetBytecodeHandler(Bytecode bytecode) { |
| 47 DCHECK(IsDispatchTableInitialized()); |
| 48 return dispatch_table_[Bytecodes::ToByte(bytecode)]; |
| 49 } |
| 50 |
| 47 void Interpreter::IterateDispatchTable(ObjectVisitor* v) { | 51 void Interpreter::IterateDispatchTable(ObjectVisitor* v) { |
| 48 v->VisitPointers(&dispatch_table_[0], | 52 v->VisitPointers( |
| 49 &dispatch_table_[0] + kDispatchTableSize); | 53 reinterpret_cast<Object**>(&dispatch_table_[0]), |
| 54 reinterpret_cast<Object**>(&dispatch_table_[0] + kDispatchTableSize)); |
| 50 } | 55 } |
| 51 | 56 |
| 52 bool Interpreter::MakeBytecode(CompilationInfo* info) { | 57 bool Interpreter::MakeBytecode(CompilationInfo* info) { |
| 53 if (FLAG_print_bytecode || FLAG_print_source || FLAG_print_ast) { | 58 if (FLAG_print_bytecode || FLAG_print_source || FLAG_print_ast) { |
| 54 OFStream os(stdout); | 59 OFStream os(stdout); |
| 55 base::SmartArrayPointer<char> name = info->GetDebugName(); | 60 base::SmartArrayPointer<char> name = info->GetDebugName(); |
| 56 os << "[generating bytecode for function: " << info->GetDebugName().get() | 61 os << "[generating bytecode for function: " << info->GetDebugName().get() |
| 57 << "]" << std::endl | 62 << "]" << std::endl |
| 58 << std::flush; | 63 << std::flush; |
| 59 } | 64 } |
| (...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1715 | 1720 |
| 1716 // Debugger | 1721 // Debugger |
| 1717 // | 1722 // |
| 1718 // Call runtime to handle debugger statement. | 1723 // Call runtime to handle debugger statement. |
| 1719 void Interpreter::DoDebugger(InterpreterAssembler* assembler) { | 1724 void Interpreter::DoDebugger(InterpreterAssembler* assembler) { |
| 1720 Node* context = __ GetContext(); | 1725 Node* context = __ GetContext(); |
| 1721 __ CallRuntime(Runtime::kHandleDebuggerStatement, context); | 1726 __ CallRuntime(Runtime::kHandleDebuggerStatement, context); |
| 1722 __ Dispatch(); | 1727 __ Dispatch(); |
| 1723 } | 1728 } |
| 1724 | 1729 |
| 1730 // DebugBreak |
| 1731 // |
| 1732 // Call runtime to handle a debug break. |
| 1733 #define DEBUG_BREAK(Name, ...) \ |
| 1734 void Interpreter::Do##Name(InterpreterAssembler* assembler) { \ |
| 1735 Node* context = __ GetContext(); \ |
| 1736 Node* original_handler = __ CallRuntime(Runtime::kDebugBreak, context); \ |
| 1737 __ DispatchToBytecodeHandler(original_handler); \ |
| 1738 } |
| 1739 DEBUG_BREAK_BYTECODE_LIST(DEBUG_BREAK); |
| 1740 #undef DEBUG_BREAK |
| 1741 |
| 1725 // ForInPrepare <cache_info_triple> | 1742 // ForInPrepare <cache_info_triple> |
| 1726 // | 1743 // |
| 1727 // Returns state for for..in loop execution based on the object in the | 1744 // Returns state for for..in loop execution based on the object in the |
| 1728 // accumulator. The result is output in registers |cache_info_triple| to | 1745 // accumulator. The result is output in registers |cache_info_triple| to |
| 1729 // |cache_info_triple + 2|, with the registers holding cache_type, cache_array, | 1746 // |cache_info_triple + 2|, with the registers holding cache_type, cache_array, |
| 1730 // and cache_length respectively. | 1747 // and cache_length respectively. |
| 1731 void Interpreter::DoForInPrepare(InterpreterAssembler* assembler) { | 1748 void Interpreter::DoForInPrepare(InterpreterAssembler* assembler) { |
| 1732 Node* object = __ GetAccumulator(); | 1749 Node* object = __ GetAccumulator(); |
| 1733 Node* context = __ GetContext(); | 1750 Node* context = __ GetContext(); |
| 1734 Node* result_triple = __ CallRuntime(Runtime::kForInPrepare, context, object); | 1751 Node* result_triple = __ CallRuntime(Runtime::kForInPrepare, context, object); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 Node* index = __ LoadRegister(index_reg); | 1828 Node* index = __ LoadRegister(index_reg); |
| 1812 Node* context = __ GetContext(); | 1829 Node* context = __ GetContext(); |
| 1813 Node* result = __ CallRuntime(Runtime::kForInStep, context, index); | 1830 Node* result = __ CallRuntime(Runtime::kForInStep, context, index); |
| 1814 __ SetAccumulator(result); | 1831 __ SetAccumulator(result); |
| 1815 __ Dispatch(); | 1832 __ Dispatch(); |
| 1816 } | 1833 } |
| 1817 | 1834 |
| 1818 } // namespace interpreter | 1835 } // namespace interpreter |
| 1819 } // namespace internal | 1836 } // namespace internal |
| 1820 } // namespace v8 | 1837 } // namespace v8 |
| OLD | NEW |