Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 6 #define V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
| 10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
| 11 #include "src/interpreter/bytecode-register.h" | 11 #include "src/interpreter/bytecode-register.h" |
| 12 #include "src/interpreter/bytecodes.h" | 12 #include "src/interpreter/bytecodes.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 class CompilationInfo; | 17 class CompilationInfo; |
| 18 | 18 |
| 19 namespace interpreter { | 19 namespace interpreter { |
| 20 | 20 |
| 21 class LoopBuilder; | 21 class LoopBuilder; |
| 22 | 22 |
| 23 class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { | 23 class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> { |
| 24 public: | 24 public: |
| 25 explicit BytecodeGenerator(CompilationInfo* info); | 25 explicit BytecodeGenerator(CompilationInfo* info); |
| 26 | 26 |
| 27 Handle<BytecodeArray> MakeBytecode(); | 27 Handle<BytecodeArray> MakeBytecode(Isolate* isolate); |
| 28 | 28 |
| 29 #define DECLARE_VISIT(type) void Visit##type(type* node); | 29 #define DECLARE_VISIT(type) void Visit##type(type* node); |
| 30 AST_NODE_LIST(DECLARE_VISIT) | 30 AST_NODE_LIST(DECLARE_VISIT) |
| 31 #undef DECLARE_VISIT | 31 #undef DECLARE_VISIT |
| 32 | 32 |
| 33 // Visiting function for declarations list and statements are overridden. | 33 // Visiting function for declarations list and statements are overridden. |
| 34 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 34 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
| 35 void VisitStatements(ZoneList<Statement*>* statments); | 35 void VisitStatements(ZoneList<Statement*>* statments); |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 class AccumulatorResultScope; | 38 class AccumulatorResultScope; |
| 39 class ContextScope; | 39 class ContextScope; |
| 40 class ControlScope; | 40 class ControlScope; |
| 41 class ControlScopeForBreakable; | 41 class ControlScopeForBreakable; |
| 42 class ControlScopeForIteration; | 42 class ControlScopeForIteration; |
| 43 class ControlScopeForTopLevel; | 43 class ControlScopeForTopLevel; |
| 44 class ControlScopeForTryCatch; | 44 class ControlScopeForTryCatch; |
| 45 class ControlScopeForTryFinally; | 45 class ControlScopeForTryFinally; |
| 46 class ExpressionResultScope; | 46 class ExpressionResultScope; |
| 47 class EffectResultScope; | 47 class EffectResultScope; |
| 48 class GlobalDeclarationsBuilder; | 48 class GlobalDeclarationsBuilder; |
| 49 class RegisterResultScope; | 49 class RegisterResultScope; |
| 50 class RegisterAllocationScope; | 50 class RegisterAllocationScope; |
| 51 class TestResultScope; | 51 class TestResultScope; |
| 52 | 52 |
| 53 enum class TestFallthrough { kThen, kElse, kNone }; | 53 enum class TestFallthrough { kThen, kElse, kNone }; |
| 54 | 54 |
| 55 void GenerateBytecode(); | 55 void GenerateBytecode(); |
| 56 void GenerateBytecodeBody(); | 56 void GenerateBytecodeBody(); |
| 57 void FinalizeBytecode(); | 57 void FinalizeBytecode(Isolate* isolate); |
| 58 | 58 |
| 59 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 59 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
| 60 | 60 |
| 61 // Dispatched from VisitBinaryOperation. | 61 // Dispatched from VisitBinaryOperation. |
| 62 void VisitArithmeticExpression(BinaryOperation* binop); | 62 void VisitArithmeticExpression(BinaryOperation* binop); |
| 63 void VisitCommaExpression(BinaryOperation* binop); | 63 void VisitCommaExpression(BinaryOperation* binop); |
| 64 void VisitLogicalOrExpression(BinaryOperation* binop); | 64 void VisitLogicalOrExpression(BinaryOperation* binop); |
| 65 void VisitLogicalAndExpression(BinaryOperation* binop); | 65 void VisitLogicalAndExpression(BinaryOperation* binop); |
| 66 | 66 |
| 67 // Dispatched from VisitUnaryOperation. | 67 // Dispatched from VisitUnaryOperation. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 170 |
| 171 // Methods for tracking and remapping register. | 171 // Methods for tracking and remapping register. |
| 172 void RecordStoreToRegister(Register reg); | 172 void RecordStoreToRegister(Register reg); |
| 173 Register LoadFromAliasedRegister(Register reg); | 173 Register LoadFromAliasedRegister(Register reg); |
| 174 | 174 |
| 175 // Initialize an array of temporary registers with consecutive registers. | 175 // Initialize an array of temporary registers with consecutive registers. |
| 176 template <size_t N> | 176 template <size_t N> |
| 177 void InitializeWithConsecutiveRegisters(Register (®isters)[N]); | 177 void InitializeWithConsecutiveRegisters(Register (®isters)[N]); |
| 178 | 178 |
| 179 inline BytecodeArrayBuilder* builder() const { return builder_; } | 179 inline BytecodeArrayBuilder* builder() const { return builder_; } |
| 180 inline Isolate* isolate() const { return isolate_; } | |
| 181 inline Zone* zone() const { return zone_; } | 180 inline Zone* zone() const { return zone_; } |
| 182 inline DeclarationScope* scope() const { return scope_; } | 181 inline DeclarationScope* scope() const { return scope_; } |
| 183 inline CompilationInfo* info() const { return info_; } | 182 inline CompilationInfo* info() const { return info_; } |
| 184 | 183 |
| 185 inline ControlScope* execution_control() const { return execution_control_; } | 184 inline ControlScope* execution_control() const { return execution_control_; } |
| 186 inline void set_execution_control(ControlScope* scope) { | 185 inline void set_execution_control(ControlScope* scope) { |
| 187 execution_control_ = scope; | 186 execution_control_ = scope; |
| 188 } | 187 } |
| 189 inline ContextScope* execution_context() const { return execution_context_; } | 188 inline ContextScope* execution_context() const { return execution_context_; } |
| 190 inline void set_execution_context(ContextScope* context) { | 189 inline void set_execution_context(ContextScope* context) { |
| 191 execution_context_ = context; | 190 execution_context_ = context; |
| 192 } | 191 } |
| 193 inline void set_execution_result(ExpressionResultScope* execution_result) { | 192 inline void set_execution_result(ExpressionResultScope* execution_result) { |
| 194 execution_result_ = execution_result; | 193 execution_result_ = execution_result; |
| 195 } | 194 } |
| 196 ExpressionResultScope* execution_result() const { return execution_result_; } | 195 ExpressionResultScope* execution_result() const { return execution_result_; } |
| 197 inline void set_register_allocator( | 196 inline void set_register_allocator( |
| 198 RegisterAllocationScope* register_allocator) { | 197 RegisterAllocationScope* register_allocator) { |
| 199 register_allocator_ = register_allocator; | 198 register_allocator_ = register_allocator; |
| 200 } | 199 } |
| 201 RegisterAllocationScope* register_allocator() const { | 200 RegisterAllocationScope* register_allocator() const { |
| 202 return register_allocator_; | 201 return register_allocator_; |
| 203 } | 202 } |
| 204 | 203 |
| 205 GlobalDeclarationsBuilder* globals_builder() { return globals_builder_; } | 204 GlobalDeclarationsBuilder* globals_builder() { return globals_builder_; } |
| 206 inline LanguageMode language_mode() const; | 205 inline LanguageMode language_mode() const; |
| 207 int feedback_index(FeedbackVectorSlot slot) const; | 206 int feedback_index(FeedbackVectorSlot slot) const; |
| 208 | 207 |
| 209 Isolate* isolate_; | 208 Handle<Name> home_object_symbol() const { return home_object_symbol_; } |
| 209 Handle<Name> prototype_string() const { return prototype_string_; } | |
| 210 | |
| 210 Zone* zone_; | 211 Zone* zone_; |
| 211 BytecodeArrayBuilder* builder_; | 212 BytecodeArrayBuilder* builder_; |
| 212 CompilationInfo* info_; | 213 CompilationInfo* info_; |
| 213 DeclarationScope* scope_; | 214 DeclarationScope* scope_; |
| 215 bool isolate_access_allowed_; | |
|
Michael Starzinger
2016/08/16 12:26:50
nit: Field should no longer be required. Lets drop
rmcilroy
2016/08/16 14:22:30
Done.
| |
| 216 | |
| 214 GlobalDeclarationsBuilder* globals_builder_; | 217 GlobalDeclarationsBuilder* globals_builder_; |
| 215 ZoneVector<GlobalDeclarationsBuilder*> global_declarations_; | 218 ZoneVector<GlobalDeclarationsBuilder*> global_declarations_; |
| 216 ZoneVector<std::pair<FunctionLiteral*, size_t>> function_literals_; | 219 ZoneVector<std::pair<FunctionLiteral*, size_t>> function_literals_; |
| 217 ZoneVector<std::pair<NativeFunctionLiteral*, size_t>> | 220 ZoneVector<std::pair<NativeFunctionLiteral*, size_t>> |
| 218 native_function_literals_; | 221 native_function_literals_; |
| 222 | |
| 219 ControlScope* execution_control_; | 223 ControlScope* execution_control_; |
| 220 ContextScope* execution_context_; | 224 ContextScope* execution_context_; |
| 221 ExpressionResultScope* execution_result_; | 225 ExpressionResultScope* execution_result_; |
| 222 RegisterAllocationScope* register_allocator_; | 226 RegisterAllocationScope* register_allocator_; |
| 227 | |
| 223 ZoneVector<BytecodeLabel> generator_resume_points_; | 228 ZoneVector<BytecodeLabel> generator_resume_points_; |
| 224 Register generator_state_; | 229 Register generator_state_; |
| 225 int loop_depth_; | 230 int loop_depth_; |
| 231 | |
| 232 Handle<Name> home_object_symbol_; | |
| 233 Handle<Name> prototype_string_; | |
| 226 }; | 234 }; |
| 227 | 235 |
| 228 } // namespace interpreter | 236 } // namespace interpreter |
| 229 } // namespace internal | 237 } // namespace internal |
| 230 } // namespace v8 | 238 } // namespace v8 |
| 231 | 239 |
| 232 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 240 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
| OLD | NEW |