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 24 namespace compiler { 25 class InterpreterAssembler; 26 } 27 28 namespace interpreter { 29 30 class Interpreter { 31 public: 32 explicit Interpreter(Isolate* isolate); ~Interpreter()33 virtual ~Interpreter() {} 34 35 // Creates an uninitialized interpreter handler table, where each handler 36 // points to the Illegal builtin. 37 static Handle<FixedArray> CreateUninitializedInterpreterTable( 38 Isolate* isolate); 39 40 // Initializes the interpreter. 41 void Initialize(); 42 43 // 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, ...) \ 49 void Do##Name(compiler::InterpreterAssembler* assembler); 50 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, 55 compiler::InterpreterAssembler* assembler); 56 57 // Generates code to perform the count operations via |function_id|. 58 void DoCountOp(Runtime::FunctionId function_id, 59 compiler::InterpreterAssembler* assembler); 60 61 // Generates code to perform the comparison operation associated with 62 // |compare_op|. 63 void DoCompareOp(Token::Value compare_op, 64 compiler::InterpreterAssembler* assembler); 65 66 // Generates code to load a constant from the constant pool. 67 void DoLoadConstant(compiler::InterpreterAssembler* assembler); 68 69 // Generates code to perform a global load via |ic|. 70 void DoLoadGlobal(Callable ic, compiler::InterpreterAssembler* assembler); 71 72 // Generates code to perform a global store via |ic|. 73 void DoStoreGlobal(Callable ic, compiler::InterpreterAssembler* assembler); 74 75 // Generates code to perform a named property load via |ic|. 76 void DoLoadIC(Callable ic, compiler::InterpreterAssembler* assembler); 77 78 // Generates code to perform a keyed property load via |ic|. 79 void DoKeyedLoadIC(Callable ic, compiler::InterpreterAssembler* assembler); 80 81 // Generates code to perform a namedproperty store via |ic|. 82 void DoStoreIC(Callable ic, compiler::InterpreterAssembler* assembler); 83 84 // Generates code to perform a keyed property store via |ic|. 85 void DoKeyedStoreIC(Callable ic, compiler::InterpreterAssembler* assembler); 86 87 // Generates code to perform a JS call. 88 void DoJSCall(compiler::InterpreterAssembler* assembler); 89 90 // Generates code ro create a literal via |function_id|. 91 void DoCreateLiteral(Runtime::FunctionId function_id, 92 compiler::InterpreterAssembler* assembler); 93 94 // Generates code to perform delete via function_id. 95 void DoDelete(Runtime::FunctionId function_id, 96 compiler::InterpreterAssembler* assembler); 97 98 // Generates code to perform a lookup slot load via |function_id|. 99 void DoLoadLookupSlot(Runtime::FunctionId function_id, 100 compiler::InterpreterAssembler* assembler); 101 102 // Generates code to perform a lookup slot store depending on |language_mode|. 103 void DoStoreLookupSlot(LanguageMode language_mode, 104 compiler::InterpreterAssembler* assembler); 105 106 bool IsInterpreterTableInitialized(Handle<FixedArray> handler_table); 107 108 Isolate* isolate_; 109 110 DISALLOW_COPY_AND_ASSIGN(Interpreter); 111 }; 112 113 } // namespace interpreter 114 } // namespace internal 115 } // namespace v8 116 117 #endif // V8_INTERPRETER_INTERPRETER_H_ 118