Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_INTERPRETER_INTERPRETER_H_ |
| 6 | #define V8_INTERPRETER_INTERPRETER_H_ |
| 7 | |
| 8 | // Clients of this interface shouldn't depend on lots of interpreter internals. |
| 9 | // Do not include anything from src/interpreter other than |
| 10 | // src/interpreter/bytecodes.h here! |
| 11 | #include "src/base/macros.h" |
| 12 | #include "src/builtins.h" |
| 13 | #include "src/interpreter/bytecodes.h" |
| 14 | #include "src/parsing/token.h" |
| 15 | #include "src/runtime/runtime.h" |
| 16 | |
| 17 | namespace v8 { |
| 18 | namespace internal { |
| 19 | |
| 20 | class Isolate; |
| 21 | class Callable; |
| 22 | class CompilationInfo; |
| 23 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 24 | namespace compiler { |
| 25 | class Node; |
| 26 | } // namespace compiler |
| 27 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | namespace interpreter { |
| 29 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 30 | class InterpreterAssembler; |
| 31 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 32 | class Interpreter { |
| 33 | public: |
| 34 | explicit Interpreter(Isolate* isolate); |
| 35 | virtual ~Interpreter() {} |
| 36 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 37 | // Initializes the interpreter dispatch table. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 38 | void Initialize(); |
| 39 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 40 | // Returns the interrupt budget which should be used for the profiler counter. |
| 41 | static int InterruptBudget(); |
| 42 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | // Generate bytecode for |info|. |
| 44 | static bool MakeBytecode(CompilationInfo* info); |
| 45 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 46 | // Return bytecode handler for |bytecode|. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 47 | Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 48 | |
| 49 | // GC support. |
| 50 | void IterateDispatchTable(ObjectVisitor* v); |
| 51 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 52 | // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). |
| 53 | void TraceCodegen(Handle<Code> code); |
| 54 | const char* LookupNameOfBytecodeHandler(Code* code); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 55 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 56 | Local<v8::Object> GetDispatchCountersObject(); |
| 57 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 58 | Address dispatch_table_address() { |
| 59 | return reinterpret_cast<Address>(&dispatch_table_[0]); |
| 60 | } |
| 61 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 62 | Address bytecode_dispatch_counters_table() { |
| 63 | return reinterpret_cast<Address>(bytecode_dispatch_counters_table_.get()); |
| 64 | } |
| 65 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | private: |
| 67 | // Bytecode handler generator functions. |
| 68 | #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 69 | void Do##Name(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 70 | BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR) |
| 71 | #undef DECLARE_BYTECODE_HANDLER_GENERATOR |
| 72 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 73 | // Generates code to perform the binary operation via |callable|. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 74 | void DoBinaryOp(Callable callable, InterpreterAssembler* assembler); |
| 75 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 76 | // Generates code to perform the binary operation via |function_id|. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 77 | void DoBinaryOp(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 78 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 79 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 80 | // Generates code to perform the binary operation via |Generator|. |
| 81 | template <class Generator> |
| 82 | void DoBinaryOp(InterpreterAssembler* assembler); |
| 83 | |
| 84 | // Generates code to perform the unary operation via |Generator|. |
| 85 | template <class Generator> |
| 86 | void DoUnaryOp(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 87 | |
| 88 | // Generates code to perform the comparison operation associated with |
| 89 | // |compare_op|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 90 | void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | |
| 92 | // Generates code to load a constant from the constant pool. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 93 | void DoLoadConstant(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 94 | |
| 95 | // Generates code to perform a global load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 96 | void DoLoadGlobal(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 97 | |
| 98 | // Generates code to perform a global store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 99 | void DoStoreGlobal(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 100 | |
| 101 | // Generates code to perform a named property load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 102 | void DoLoadIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 103 | |
| 104 | // Generates code to perform a keyed property load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 105 | void DoKeyedLoadIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 106 | |
| 107 | // Generates code to perform a namedproperty store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 108 | void DoStoreIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 109 | |
| 110 | // Generates code to perform a keyed property store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 111 | void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | |
| 113 | // Generates code to perform a JS call. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 114 | void DoJSCall(InterpreterAssembler* assembler, TailCallMode tail_call_mode); |
| 115 | |
| 116 | // Generates code to perform a runtime call. |
| 117 | void DoCallRuntimeCommon(InterpreterAssembler* assembler); |
| 118 | |
| 119 | // Generates code to perform a runtime call returning a pair. |
| 120 | void DoCallRuntimeForPairCommon(InterpreterAssembler* assembler); |
| 121 | |
| 122 | // Generates code to perform a JS runtime call. |
| 123 | void DoCallJSRuntimeCommon(InterpreterAssembler* assembler); |
| 124 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 125 | // Generates code to perform a constructor call. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 126 | void DoCallConstruct(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 127 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 128 | // Generates code to perform a type conversion. |
| 129 | void DoTypeConversionOp(Callable callable, InterpreterAssembler* assembler); |
| 130 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 131 | // Generates code to perform logical-not on boolean |value|. |
| 132 | void DoLogicalNotOp(compiler::Node* value, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 133 | |
| 134 | // Generates code to perform delete via function_id. |
| 135 | void DoDelete(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 136 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 137 | |
| 138 | // Generates code to perform a lookup slot load via |function_id|. |
| 139 | void DoLoadLookupSlot(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 140 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 | |
| 142 | // Generates code to perform a lookup slot store depending on |language_mode|. |
| 143 | void DoStoreLookupSlot(LanguageMode language_mode, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 144 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 145 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 146 | uintptr_t GetDispatchCounter(Bytecode from, Bytecode to) const; |
| 147 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 148 | // Get dispatch table index of bytecode. |
| 149 | static size_t GetDispatchTableIndex(Bytecode bytecode, |
| 150 | OperandScale operand_scale); |
| 151 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 152 | bool IsDispatchTableInitialized(); |
| 153 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 154 | static const int kNumberOfWideVariants = 3; |
| 155 | static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 156 | static const int kNumberOfBytecodes = static_cast<int>(Bytecode::kLast) + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 157 | |
| 158 | Isolate* isolate_; |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 159 | Address dispatch_table_[kDispatchTableSize]; |
| 160 | v8::base::SmartArrayPointer<uintptr_t> bytecode_dispatch_counters_table_; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 161 | |
| 162 | DISALLOW_COPY_AND_ASSIGN(Interpreter); |
| 163 | }; |
| 164 | |
| 165 | } // namespace interpreter |
| 166 | } // namespace internal |
| 167 | } // namespace v8 |
| 168 | |
| 169 | #endif // V8_INTERPRETER_INTERPRETER_H_ |