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::GetHandler(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 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1794 | 1799 |
1795 // Debugger | 1800 // Debugger |
1796 // | 1801 // |
1797 // Call runtime to handle debugger statement. | 1802 // Call runtime to handle debugger statement. |
1798 void Interpreter::DoDebugger(InterpreterAssembler* assembler) { | 1803 void Interpreter::DoDebugger(InterpreterAssembler* assembler) { |
1799 Node* context = __ GetContext(); | 1804 Node* context = __ GetContext(); |
1800 __ CallRuntime(Runtime::kHandleDebuggerStatement, context); | 1805 __ CallRuntime(Runtime::kHandleDebuggerStatement, context); |
1801 __ Dispatch(); | 1806 __ Dispatch(); |
1802 } | 1807 } |
1803 | 1808 |
| 1809 // DebugBreak |
| 1810 // |
| 1811 // Call runtime to handle a debug break. |
| 1812 #define DEBUG_BREAK(Name, ...) \ |
| 1813 void Interpreter::Do##Name(InterpreterAssembler* assembler) { \ |
| 1814 Node* context = __ GetContext(); \ |
| 1815 Node* original_handler = __ CallRuntime(Runtime::kDebugBreak, context); \ |
| 1816 __ DispatchToHandler(original_handler); \ |
| 1817 } |
| 1818 DEBUG_BREAK_BYTECODE_LIST(DEBUG_BREAK); |
| 1819 #undef DEBUG_BREAK |
| 1820 |
1804 // ForInPrepare <cache_info_triple> | 1821 // ForInPrepare <cache_info_triple> |
1805 // | 1822 // |
1806 // Returns state for for..in loop execution based on the object in the | 1823 // Returns state for for..in loop execution based on the object in the |
1807 // accumulator. The result is output in registers |cache_info_triple| to | 1824 // accumulator. The result is output in registers |cache_info_triple| to |
1808 // |cache_info_triple + 2|, with the registers holding cache_type, cache_array, | 1825 // |cache_info_triple + 2|, with the registers holding cache_type, cache_array, |
1809 // and cache_length respectively. | 1826 // and cache_length respectively. |
1810 void Interpreter::DoForInPrepare(InterpreterAssembler* assembler) { | 1827 void Interpreter::DoForInPrepare(InterpreterAssembler* assembler) { |
1811 Node* object = __ GetAccumulator(); | 1828 Node* object = __ GetAccumulator(); |
1812 Node* context = __ GetContext(); | 1829 Node* context = __ GetContext(); |
1813 Node* result_triple = __ CallRuntime(Runtime::kForInPrepare, context, object); | 1830 Node* result_triple = __ CallRuntime(Runtime::kForInPrepare, context, object); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 Node* index = __ LoadRegister(index_reg); | 1907 Node* index = __ LoadRegister(index_reg); |
1891 Node* context = __ GetContext(); | 1908 Node* context = __ GetContext(); |
1892 Node* result = __ CallRuntime(Runtime::kForInStep, context, index); | 1909 Node* result = __ CallRuntime(Runtime::kForInStep, context, index); |
1893 __ SetAccumulator(result); | 1910 __ SetAccumulator(result); |
1894 __ Dispatch(); | 1911 __ Dispatch(); |
1895 } | 1912 } |
1896 | 1913 |
1897 } // namespace interpreter | 1914 } // namespace interpreter |
1898 } // namespace internal | 1915 } // namespace internal |
1899 } // namespace v8 | 1916 } // namespace v8 |
OLD | NEW |