blob: ef9b5d1fe3e7326c8ca711be667dc12863dc38f4 [file] [log] [blame]
Ben Murdoch014dc512016-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 Murdochf2e39942016-05-18 10:25:55 +000024namespace compiler {
Ben Murdoch83897452016-05-17 11:12:09 +010025class InterpreterAssembler;
Ben Murdochf2e39942016-05-18 10:25:55 +000026}
27
28namespace interpreter {
Ben Murdoch83897452016-05-17 11:12:09 +010029
Ben Murdoch014dc512016-03-22 12:00:34 +000030class Interpreter {
31 public:
32 explicit Interpreter(Isolate* isolate);
33 virtual ~Interpreter() {}
34
Ben Murdochf2e39942016-05-18 10:25:55 +000035 // Creates an uninitialized interpreter handler table, where each handler
36 // points to the Illegal builtin.
37 static Handle<FixedArray> CreateUninitializedInterpreterTable(
38 Isolate* isolate);
Ben Murdoch014dc512016-03-22 12:00:34 +000039
Ben Murdochf2e39942016-05-18 10:25:55 +000040 // Initializes the interpreter.
41 void Initialize();
Ben Murdoch83897452016-05-17 11:12:09 +010042
Ben Murdoch014dc512016-03-22 12:00:34 +000043 // Generate bytecode for |info|.
44 static bool MakeBytecode(CompilationInfo* info);
45
46 private:
47// Bytecode handler generator functions.
48#define DECLARE_BYTECODE_HANDLER_GENERATOR(Name, ...) \
Ben Murdochf2e39942016-05-18 10:25:55 +000049 void Do##Name(compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000050 BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
51#undef DECLARE_BYTECODE_HANDLER_GENERATOR
52
53 // Generates code to perform the binary operations via |function_id|.
54 void DoBinaryOp(Runtime::FunctionId function_id,
Ben Murdochf2e39942016-05-18 10:25:55 +000055 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000056
57 // Generates code to perform the count operations via |function_id|.
58 void DoCountOp(Runtime::FunctionId function_id,
Ben Murdochf2e39942016-05-18 10:25:55 +000059 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000060
61 // Generates code to perform the comparison operation associated with
62 // |compare_op|.
Ben Murdochf2e39942016-05-18 10:25:55 +000063 void DoCompareOp(Token::Value compare_op,
64 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000065
66 // Generates code to load a constant from the constant pool.
Ben Murdochf2e39942016-05-18 10:25:55 +000067 void DoLoadConstant(compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000068
69 // Generates code to perform a global load via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000070 void DoLoadGlobal(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000071
72 // Generates code to perform a global store via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000073 void DoStoreGlobal(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000074
75 // Generates code to perform a named property load via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000076 void DoLoadIC(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000077
78 // Generates code to perform a keyed property load via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000079 void DoKeyedLoadIC(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000080
81 // Generates code to perform a namedproperty store via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000082 void DoStoreIC(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000083
84 // Generates code to perform a keyed property store via |ic|.
Ben Murdochf2e39942016-05-18 10:25:55 +000085 void DoKeyedStoreIC(Callable ic, compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000086
87 // Generates code to perform a JS call.
Ben Murdochf2e39942016-05-18 10:25:55 +000088 void DoJSCall(compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000089
90 // Generates code ro create a literal via |function_id|.
91 void DoCreateLiteral(Runtime::FunctionId function_id,
Ben Murdochf2e39942016-05-18 10:25:55 +000092 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000093
94 // Generates code to perform delete via function_id.
95 void DoDelete(Runtime::FunctionId function_id,
Ben Murdochf2e39942016-05-18 10:25:55 +000096 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +000097
98 // Generates code to perform a lookup slot load via |function_id|.
99 void DoLoadLookupSlot(Runtime::FunctionId function_id,
Ben Murdochf2e39942016-05-18 10:25:55 +0000100 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +0000101
102 // Generates code to perform a lookup slot store depending on |language_mode|.
103 void DoStoreLookupSlot(LanguageMode language_mode,
Ben Murdochf2e39942016-05-18 10:25:55 +0000104 compiler::InterpreterAssembler* assembler);
Ben Murdoch014dc512016-03-22 12:00:34 +0000105
Ben Murdochf2e39942016-05-18 10:25:55 +0000106 bool IsInterpreterTableInitialized(Handle<FixedArray> handler_table);
Ben Murdoch014dc512016-03-22 12:00:34 +0000107
108 Isolate* isolate_;
Ben Murdoch014dc512016-03-22 12:00:34 +0000109
110 DISALLOW_COPY_AND_ASSIGN(Interpreter);
111};
112
113} // namespace interpreter
114} // namespace internal
115} // namespace v8
116
117#endif // V8_INTERPRETER_INTERPRETER_H_