| 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 | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 24 | namespace interpreter { | 
|  | 25 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 26 | class InterpreterAssembler; | 
|  | 27 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | class Interpreter { | 
|  | 29 | public: | 
|  | 30 | explicit Interpreter(Isolate* isolate); | 
|  | 31 | virtual ~Interpreter() {} | 
|  | 32 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 33 | // Initializes the interpreter dispatch table. | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 34 | void Initialize(); | 
|  | 35 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 36 | // Returns the interrupt budget which should be used for the profiler counter. | 
|  | 37 | static int InterruptBudget(); | 
|  | 38 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | // Generate bytecode for |info|. | 
|  | 40 | static bool MakeBytecode(CompilationInfo* info); | 
|  | 41 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 42 | // Return bytecode handler for |bytecode|. | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 43 | Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale); | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 44 |  | 
|  | 45 | // GC support. | 
|  | 46 | void IterateDispatchTable(ObjectVisitor* v); | 
|  | 47 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 48 | // Disassembler support (only useful with ENABLE_DISASSEMBLER defined). | 
|  | 49 | void TraceCodegen(Handle<Code> code); | 
|  | 50 | const char* LookupNameOfBytecodeHandler(Code* code); | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 51 |  | 
|  | 52 | Address dispatch_table_address() { | 
|  | 53 | return reinterpret_cast<Address>(&dispatch_table_[0]); | 
|  | 54 | } | 
|  | 55 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | private: | 
|  | 57 | // Bytecode handler generator functions. | 
|  | 58 | #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \ | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 59 | void Do##Name(InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR) | 
|  | 61 | #undef DECLARE_BYTECODE_HANDLER_GENERATOR | 
|  | 62 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 63 | // Generates code to perform the binary operations via |callable|. | 
|  | 64 | void DoBinaryOp(Callable callable, InterpreterAssembler* assembler); | 
|  | 65 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 66 | // Generates code to perform the binary operations via |function_id|. | 
|  | 67 | void DoBinaryOp(Runtime::FunctionId function_id, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 68 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 69 |  | 
|  | 70 | // Generates code to perform the count operations via |function_id|. | 
|  | 71 | void DoCountOp(Runtime::FunctionId function_id, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 72 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 73 |  | 
|  | 74 | // Generates code to perform the comparison operation associated with | 
|  | 75 | // |compare_op|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 76 | void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 77 |  | 
|  | 78 | // Generates code to load a constant from the constant pool. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 79 | void DoLoadConstant(InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 80 |  | 
|  | 81 | // Generates code to perform a global load via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 82 | void DoLoadGlobal(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 83 |  | 
|  | 84 | // Generates code to perform a global store via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 85 | void DoStoreGlobal(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 86 |  | 
|  | 87 | // Generates code to perform a named property load via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 88 | void DoLoadIC(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 89 |  | 
|  | 90 | // Generates code to perform a keyed property load via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 91 | void DoKeyedLoadIC(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 92 |  | 
|  | 93 | // Generates code to perform a namedproperty store via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 94 | void DoStoreIC(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 |  | 
|  | 96 | // Generates code to perform a keyed property store via |ic|. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 97 | void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 |  | 
|  | 99 | // Generates code to perform a JS call. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 100 | void DoJSCall(InterpreterAssembler* assembler, TailCallMode tail_call_mode); | 
|  | 101 |  | 
|  | 102 | // Generates code to perform a runtime call. | 
|  | 103 | void DoCallRuntimeCommon(InterpreterAssembler* assembler); | 
|  | 104 |  | 
|  | 105 | // Generates code to perform a runtime call returning a pair. | 
|  | 106 | void DoCallRuntimeForPairCommon(InterpreterAssembler* assembler); | 
|  | 107 |  | 
|  | 108 | // Generates code to perform a JS runtime call. | 
|  | 109 | void DoCallJSRuntimeCommon(InterpreterAssembler* assembler); | 
|  | 110 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 111 | // Generates code to perform a constructor call. | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 112 | void DoCallConstruct(InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 113 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 114 | // Generates code to perform a type conversion. | 
|  | 115 | void DoTypeConversionOp(Callable callable, InterpreterAssembler* assembler); | 
|  | 116 |  | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 117 | // Generates code ro create a literal via |function_id|. | 
|  | 118 | void DoCreateLiteral(Runtime::FunctionId function_id, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 119 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 120 |  | 
|  | 121 | // Generates code to perform delete via function_id. | 
|  | 122 | void DoDelete(Runtime::FunctionId function_id, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 123 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 124 |  | 
|  | 125 | // Generates code to perform a lookup slot load via |function_id|. | 
|  | 126 | void DoLoadLookupSlot(Runtime::FunctionId function_id, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 127 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 128 |  | 
|  | 129 | // Generates code to perform a lookup slot store depending on |language_mode|. | 
|  | 130 | void DoStoreLookupSlot(LanguageMode language_mode, | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 131 | InterpreterAssembler* assembler); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 132 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 133 | // Get dispatch table index of bytecode. | 
|  | 134 | static size_t GetDispatchTableIndex(Bytecode bytecode, | 
|  | 135 | OperandScale operand_scale); | 
|  | 136 |  | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 137 | bool IsDispatchTableInitialized(); | 
|  | 138 |  | 
| Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 139 | static const int kNumberOfWideVariants = 3; | 
|  | 140 | static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1); | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 141 |  | 
|  | 142 | Isolate* isolate_; | 
| Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 143 | Code* dispatch_table_[kDispatchTableSize]; | 
| Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 144 |  | 
|  | 145 | DISALLOW_COPY_AND_ASSIGN(Interpreter); | 
|  | 146 | }; | 
|  | 147 |  | 
|  | 148 | }  // namespace interpreter | 
|  | 149 | }  // namespace internal | 
|  | 150 | }  // namespace v8 | 
|  | 151 |  | 
|  | 152 | #endif  // V8_INTERPRETER_INTERPRETER_H_ |