blob: e02e9142b3a5522557c832a12f7ea88f48c772c9 [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|.
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 Murdoch4a90d5f2016-03-22 12:00:34 +000054 private:
55// Bytecode handler generator functions.
56#define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \
Ben Murdoch097c5b22016-05-18 11:27:45 +010057 void Do##Name(InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058 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 Murdoch097c5b22016-05-18 11:27:45 +010063 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000064
65 // Generates code to perform the count operations via |function_id|.
66 void DoCountOp(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +010067 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068
69 // Generates code to perform the comparison operation associated with
70 // |compare_op|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010071 void DoCompareOp(Token::Value compare_op, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072
73 // Generates code to load a constant from the constant pool.
Ben Murdoch097c5b22016-05-18 11:27:45 +010074 void DoLoadConstant(InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000075
76 // Generates code to perform a global load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010077 void DoLoadGlobal(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078
79 // Generates code to perform a global store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010080 void DoStoreGlobal(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081
82 // Generates code to perform a named property load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010083 void DoLoadIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000084
85 // Generates code to perform a keyed property load via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010086 void DoKeyedLoadIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000087
88 // Generates code to perform a namedproperty store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010089 void DoStoreIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090
91 // Generates code to perform a keyed property store via |ic|.
Ben Murdoch097c5b22016-05-18 11:27:45 +010092 void DoKeyedStoreIC(Callable ic, InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093
94 // Generates code to perform a JS call.
Ben Murdoch097c5b22016-05-18 11:27:45 +010095 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000108
109 // Generates code ro create a literal via |function_id|.
110 void DoCreateLiteral(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100111 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112
113 // Generates code to perform delete via function_id.
114 void DoDelete(Runtime::FunctionId function_id,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100115 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000116
117 // Generates code to perform a lookup slot load via |function_id|.
118 void DoLoadLookupSlot(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 a lookup slot store depending on |language_mode|.
122 void DoStoreLookupSlot(LanguageMode language_mode,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100123 InterpreterAssembler* assembler);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124
Ben Murdoch097c5b22016-05-18 11:27:45 +0100125 bool IsDispatchTableInitialized();
126
127 static const int kDispatchTableSize = static_cast<int>(Bytecode::kLast) + 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128
129 Isolate* isolate_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100130 Code* dispatch_table_[kDispatchTableSize];
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131
132 DISALLOW_COPY_AND_ASSIGN(Interpreter);
133};
134
135} // namespace interpreter
136} // namespace internal
137} // namespace v8
138
139#endif // V8_INTERPRETER_INTERPRETER_H_