blob: ea50faa02d882c91bee2cdd2912a2cd6e7486db7 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
17namespace v8 {
18namespace internal {
19
20class Isolate;
21class Callable;
22class CompilationInfo;
23
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000024namespace interpreter {
25
Ben Murdoch097c5b22016-05-18 11:27:45 +010026class InterpreterAssembler;
27
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028class Interpreter {
29 public:
30 explicit Interpreter(Isolate* isolate);
31 virtual ~Interpreter() {}
32
Ben Murdoch097c5b22016-05-18 11:27:45 +010033 // Initializes the interpreter dispatch table.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034 void Initialize();
35
Ben Murdoch097c5b22016-05-18 11:27:45 +010036 // Returns the interrupt budget which should be used for the profiler counter.
37 static int InterruptBudget();
38
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039 // Generate bytecode for |info|.
40 static bool MakeBytecode(CompilationInfo* info);
41
Ben Murdoch097c5b22016-05-18 11:27:45 +010042 // Return bytecode handler for |bytecode|.
Ben Murdochda12d292016-06-02 14:46:10 +010043 Code* GetBytecodeHandler(Bytecode bytecode, OperandScale operand_scale);
Ben Murdoch097c5b22016-05-18 11:27:45 +010044
45 // GC support.
46 void IterateDispatchTable(ObjectVisitor* v);
47
Ben Murdochda12d292016-06-02 14:46:10 +010048 // Disassembler support (only useful with ENABLE_DISASSEMBLER defined).
49 void TraceCodegen(Handle<Code> code);
50 const char* LookupNameOfBytecodeHandler(Code* code);
Ben Murdoch097c5b22016-05-18 11:27:45 +010051
52 Address dispatch_table_address() {
53 return reinterpret_cast<Address>(&dispatch_table_[0]);
54 }
55
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 private:
57// Bytecode handler generator functions.
58#define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010059 void Do##Name(InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
61#undef DECLARE_BYTECODE_HANDLER_GENERATOR
62
Ben Murdochda12d292016-06-02 14:46:10 +010063 // Generates code to perform the binary operations via |callable|.
64 void DoBinaryOp(Callable callable, InterpreterAssembler* assembler);
65
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000066 // Generates code to perform the binary operations via |function_id|.
67 void DoBinaryOp(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +010068 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069
70 // Generates code to perform the count operations via |function_id|.
71 void DoCountOp(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +010072 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000073
74 // Generates code to perform the comparison operation associated with
75 // |compare_op|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010076 void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077
78 // Generates code to load a constant from the constant pool.
Ben Murdoch097c5b22016-05-18 11:27:45 +010079 void DoLoadConstant(InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000080
81 // Generates code to perform a global load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010082 void DoLoadGlobal(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000083
84 // Generates code to perform a global store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010085 void DoStoreGlobal(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000086
87 // Generates code to perform a named property load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010088 void DoLoadIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089
90 // Generates code to perform a keyed property load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010091 void DoKeyedLoadIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000092
93 // Generates code to perform a namedproperty store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010094 void DoStoreIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095
96 // Generates code to perform a keyed property store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010097 void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000098
99 // Generates code to perform a JS call.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100100 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 Murdochda12d292016-06-02 14:46:10 +0100111 // Generates code to perform a constructor call.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100112 void DoCallConstruct(InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113
Ben Murdochda12d292016-06-02 14:46:10 +0100114 // Generates code to perform a type conversion.
115 void DoTypeConversionOp(Callable callable, InterpreterAssembler* assembler);
116
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117 // Generates code ro create a literal via |function_id|.
118 void DoCreateLiteral(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100119 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120
121 // Generates code to perform delete via function_id.
122 void DoDelete(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100123 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124
125 // Generates code to perform a lookup slot load via |function_id|.
126 void DoLoadLookupSlot(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100127 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128
129 // Generates code to perform a lookup slot store depending on |language_mode|.
130 void DoStoreLookupSlot(LanguageMode language_mode,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100131 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000132
Ben Murdochda12d292016-06-02 14:46:10 +0100133 // Get dispatch table index of bytecode.
134 static size_t GetDispatchTableIndex(Bytecode bytecode,
135 OperandScale operand_scale);
136
Ben Murdoch097c5b22016-05-18 11:27:45 +0100137 bool IsDispatchTableInitialized();
138
Ben Murdochda12d292016-06-02 14:46:10 +0100139 static const int kNumberOfWideVariants = 3;
140 static const int kDispatchTableSize = kNumberOfWideVariants * (kMaxUInt8 + 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141
142 Isolate* isolate_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100143 Code* dispatch_table_[kDispatchTableSize];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144
145 DISALLOW_COPY_AND_ASSIGN(Interpreter);
146};
147
148} // namespace interpreter
149} // namespace internal
150} // namespace v8
151
152#endif // V8_INTERPRETER_INTERPRETER_H_