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|. |
| 43 | Code* GetBytecodeHandler(Bytecode bytecode); |
| 44 | |
| 45 | // GC support. |
| 46 | void IterateDispatchTable(ObjectVisitor* v); |
| 47 | |
| 48 | void TraceCodegen(Handle<Code> code, const char* name); |
| 49 | |
| 50 | Address dispatch_table_address() { |
| 51 | return reinterpret_cast<Address>(&dispatch_table_[0]); |
| 52 | } |
| 53 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 54 | private: |
| 55 | // Bytecode handler generator functions. |
| 56 | #define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \ |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 57 | void Do##Name(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR) |
| 59 | #undef DECLARE_BYTECODE_HANDLER_GENERATOR |
| 60 | |
| 61 | // Generates code to perform the binary operations via |function_id|. |
| 62 | void DoBinaryOp(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 63 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 64 | |
| 65 | // Generates code to perform the count operations via |function_id|. |
| 66 | void DoCountOp(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 67 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | |
| 69 | // Generates code to perform the comparison operation associated with |
| 70 | // |compare_op|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 71 | void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 72 | |
| 73 | // Generates code to load a constant from the constant pool. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 74 | void DoLoadConstant(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 75 | |
| 76 | // Generates code to perform a global load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 77 | void DoLoadGlobal(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 78 | |
| 79 | // Generates code to perform a global store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 80 | void DoStoreGlobal(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 81 | |
| 82 | // Generates code to perform a named property load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 83 | void DoLoadIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 84 | |
| 85 | // Generates code to perform a keyed property load via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 86 | void DoKeyedLoadIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 87 | |
| 88 | // Generates code to perform a namedproperty store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 89 | void DoStoreIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 90 | |
| 91 | // Generates code to perform a keyed property store via |ic|. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 92 | void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 93 | |
| 94 | // Generates code to perform a JS call. |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 95 | void DoJSCall(InterpreterAssembler* assembler, TailCallMode tail_call_mode); |
| 96 | |
| 97 | // Generates code to perform a runtime call. |
| 98 | void DoCallRuntimeCommon(InterpreterAssembler* assembler); |
| 99 | |
| 100 | // Generates code to perform a runtime call returning a pair. |
| 101 | void DoCallRuntimeForPairCommon(InterpreterAssembler* assembler); |
| 102 | |
| 103 | // Generates code to perform a JS runtime call. |
| 104 | void DoCallJSRuntimeCommon(InterpreterAssembler* assembler); |
| 105 | |
| 106 | // Generates code to perform a constructor call.. |
| 107 | void DoCallConstruct(InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 108 | |
| 109 | // Generates code ro create a literal via |function_id|. |
| 110 | void DoCreateLiteral(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 111 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 112 | |
| 113 | // Generates code to perform delete via function_id. |
| 114 | void DoDelete(Runtime::FunctionId function_id, |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 115 | InterpreterAssembler* assembler); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 116 | |
| 117 | // Generates code to perform a lookup slot load via |function_id|. |
| 118 | void DoLoadLookupSlot(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 a lookup slot store depending on |language_mode|. |
| 122 | void DoStoreLookupSlot(LanguageMode language_mode, |
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 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 125 | bool IsDispatchTableInitialized(); |
| 126 | |
| 127 | static const int kDispatchTableSize = static_cast<int>(Bytecode::kLast) + 1; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 128 | |
| 129 | Isolate* isolate_; |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 130 | Code* dispatch_table_[kDispatchTableSize]; |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 131 | |
| 132 | DISALLOW_COPY_AND_ASSIGN(Interpreter); |
| 133 | }; |
| 134 | |
| 135 | } // namespace interpreter |
| 136 | } // namespace internal |
| 137 | } // namespace v8 |
| 138 | |
| 139 | #endif // V8_INTERPRETER_INTERPRETER_H_ |