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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 #define DECLARE_VISIT(type) void Visit##type(type* node); | 30 #define DECLARE_VISIT(type) void Visit##type(type* node); |
31 AST_NODE_LIST(DECLARE_VISIT) | 31 AST_NODE_LIST(DECLARE_VISIT) |
32 #undef DECLARE_VISIT | 32 #undef DECLARE_VISIT |
33 | 33 |
34 // Visiting function for declarations list and statements are overridden. | 34 // Visiting function for declarations list and statements are overridden. |
35 void VisitDeclarations(ZoneList<Declaration*>* declarations); | 35 void VisitDeclarations(ZoneList<Declaration*>* declarations); |
36 void VisitStatements(ZoneList<Statement*>* statments); | 36 void VisitStatements(ZoneList<Statement*>* statments); |
37 | 37 |
38 private: | 38 private: |
39 class AccumulatorResultScope; | |
40 class ContextScope; | 39 class ContextScope; |
41 class ControlScope; | 40 class ControlScope; |
42 class ControlScopeForBreakable; | 41 class ControlScopeForBreakable; |
43 class ControlScopeForIteration; | 42 class ControlScopeForIteration; |
44 class ControlScopeForTopLevel; | 43 class ControlScopeForTopLevel; |
45 class ControlScopeForTryCatch; | 44 class ControlScopeForTryCatch; |
46 class ControlScopeForTryFinally; | 45 class ControlScopeForTryFinally; |
47 class ExpressionResultScope; | 46 class ExpressionResultScope; |
48 class EffectResultScope; | 47 class EffectResultScope; |
49 class GlobalDeclarationsBuilder; | 48 class GlobalDeclarationsBuilder; |
50 class RegisterResultScope; | |
51 class RegisterAllocationScope; | 49 class RegisterAllocationScope; |
52 class TestResultScope; | 50 class TestResultScope; |
| 51 class ValueResultScope; |
53 | 52 |
54 enum class TestFallthrough { kThen, kElse, kNone }; | 53 enum class TestFallthrough { kThen, kElse, kNone }; |
55 | 54 |
56 void GenerateBytecodeBody(); | 55 void GenerateBytecodeBody(); |
57 void AllocateDeferredConstants(); | 56 void AllocateDeferredConstants(); |
58 | 57 |
59 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 58 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
60 | 59 |
61 // Dispatched from VisitBinaryOperation. | 60 // Dispatched from VisitBinaryOperation. |
62 void VisitArithmeticExpression(BinaryOperation* binop); | 61 void VisitArithmeticExpression(BinaryOperation* binop); |
63 void VisitCommaExpression(BinaryOperation* binop); | 62 void VisitCommaExpression(BinaryOperation* binop); |
64 void VisitLogicalOrExpression(BinaryOperation* binop); | 63 void VisitLogicalOrExpression(BinaryOperation* binop); |
65 void VisitLogicalAndExpression(BinaryOperation* binop); | 64 void VisitLogicalAndExpression(BinaryOperation* binop); |
66 | 65 |
67 // Dispatched from VisitUnaryOperation. | 66 // Dispatched from VisitUnaryOperation. |
68 void VisitVoid(UnaryOperation* expr); | 67 void VisitVoid(UnaryOperation* expr); |
69 void VisitTypeOf(UnaryOperation* expr); | 68 void VisitTypeOf(UnaryOperation* expr); |
70 void VisitNot(UnaryOperation* expr); | 69 void VisitNot(UnaryOperation* expr); |
71 void VisitDelete(UnaryOperation* expr); | 70 void VisitDelete(UnaryOperation* expr); |
72 | 71 |
73 // Used by flow control routines to evaluate loop condition. | 72 // Used by flow control routines to evaluate loop condition. |
74 void VisitCondition(Expression* expr); | 73 void VisitCondition(Expression* expr); |
75 | 74 |
76 // Helper visitors which perform common operations. | 75 // Visit the arguments expressions in |args| and store them in |args_regs| |
77 Register VisitArguments(ZoneList<Expression*>* arguments); | 76 // starting at register |first_argument_register| in the list. |
| 77 void VisitArguments(ZoneList<Expression*>* args, RegisterList arg_regs, |
| 78 size_t first_argument_register = 0); |
78 | 79 |
79 // Visit a keyed super property load. The optional | 80 // Visit a keyed super property load. The optional |
80 // |opt_receiver_out| register will have the receiver stored to it | 81 // |opt_receiver_out| register will have the receiver stored to it |
81 // if it's a valid register. The loaded value is placed in the | 82 // if it's a valid register. The loaded value is placed in the |
82 // accumulator. | 83 // accumulator. |
83 void VisitKeyedSuperPropertyLoad(Property* property, | 84 void VisitKeyedSuperPropertyLoad(Property* property, |
84 Register opt_receiver_out); | 85 Register opt_receiver_out); |
85 | 86 |
86 // Visit a named super property load. The optional | 87 // Visit a named super property load. The optional |
87 // |opt_receiver_out| register will have the receiver stored to it | 88 // |opt_receiver_out| register will have the receiver stored to it |
88 // if it's a valid register. The loaded value is placed in the | 89 // if it's a valid register. The loaded value is placed in the |
89 // accumulator. | 90 // accumulator. |
90 void VisitNamedSuperPropertyLoad(Property* property, | 91 void VisitNamedSuperPropertyLoad(Property* property, |
91 Register opt_receiver_out); | 92 Register opt_receiver_out); |
92 | 93 |
93 void VisitPropertyLoad(Register obj, Property* expr); | 94 void VisitPropertyLoad(Register obj, Property* expr); |
94 void VisitPropertyLoadForAccumulator(Register obj, Property* expr); | 95 void VisitPropertyLoadForAccumulator(Register obj, Property* expr); |
95 | 96 |
96 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot, | 97 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot, |
97 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); | 98 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); |
98 void VisitVariableLoadForAccumulatorValue( | 99 void VisitVariableLoadForAccumulatorValue( |
99 Variable* variable, FeedbackVectorSlot slot, | 100 Variable* variable, FeedbackVectorSlot slot, |
100 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); | 101 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); |
101 MUST_USE_RESULT Register | 102 MUST_USE_RESULT Register |
102 VisitVariableLoadForRegisterValue(Variable* variable, FeedbackVectorSlot slot, | 103 VisitVariableLoadForRegisterValue(Variable* variable, FeedbackVectorSlot slot, |
103 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); | 104 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); |
104 void VisitVariableAssignment(Variable* variable, Token::Value op, | 105 void VisitVariableAssignment(Variable* variable, Token::Value op, |
105 FeedbackVectorSlot slot); | 106 FeedbackVectorSlot slot); |
106 | 107 |
107 void BuildNamedSuperPropertyStore(Register receiver, Register home_object, | |
108 Register name, Register value); | |
109 void BuildKeyedSuperPropertyStore(Register receiver, Register home_object, | |
110 Register key, Register value); | |
111 void BuildNamedSuperPropertyLoad(Register receiver, Register home_object, | |
112 Register name); | |
113 void BuildKeyedSuperPropertyLoad(Register receiver, Register home_object, | |
114 Register key); | |
115 | |
116 void BuildAbort(BailoutReason bailout_reason); | 108 void BuildAbort(BailoutReason bailout_reason); |
117 void BuildThrowIfHole(Handle<String> name); | 109 void BuildThrowIfHole(Handle<String> name); |
118 void BuildThrowIfNotHole(Handle<String> name); | 110 void BuildThrowIfNotHole(Handle<String> name); |
119 void BuildThrowReferenceError(Handle<String> name); | 111 void BuildThrowReferenceError(Handle<String> name); |
120 void BuildHoleCheckForVariableLoad(Variable* variable); | 112 void BuildHoleCheckForVariableLoad(Variable* variable); |
121 void BuildHoleCheckForVariableAssignment(Variable* variable, Token::Value op); | 113 void BuildHoleCheckForVariableAssignment(Variable* variable, Token::Value op); |
122 | 114 |
123 // Build jump to targets[value], where | 115 // Build jump to targets[value], where |
124 // start_index <= value < start_index + size. | 116 // start_index <= value < start_index + size. |
125 void BuildIndexedJump(Register value, size_t start_index, size_t size, | 117 void BuildIndexedJump(Register value, size_t start_index, size_t size, |
126 ZoneVector<BytecodeLabel>& targets); | 118 ZoneVector<BytecodeLabel>& targets); |
127 | 119 |
128 void BuildNewLocalActivationContext(); | 120 void BuildNewLocalActivationContext(); |
129 void BuildLocalActivationContextInitialization(); | 121 void BuildLocalActivationContextInitialization(); |
130 void BuildNewLocalBlockContext(Scope* scope); | 122 void BuildNewLocalBlockContext(Scope* scope); |
131 void BuildNewLocalCatchContext(Variable* variable, Scope* scope); | 123 void BuildNewLocalCatchContext(Variable* variable, Scope* scope); |
132 void BuildNewLocalWithContext(Scope* scope); | 124 void BuildNewLocalWithContext(Scope* scope); |
133 | 125 |
134 void VisitGeneratorPrologue(); | 126 void VisitGeneratorPrologue(); |
135 | 127 |
136 void VisitArgumentsObject(Variable* variable); | 128 void VisitArgumentsObject(Variable* variable); |
137 void VisitRestArgumentsArray(Variable* rest); | 129 void VisitRestArgumentsArray(Variable* rest); |
138 void VisitCallSuper(Call* call); | 130 void VisitCallSuper(Call* call); |
139 void VisitClassLiteralForRuntimeDefinition(ClassLiteral* expr); | 131 void VisitClassLiteralForRuntimeDefinition(ClassLiteral* expr); |
140 void VisitClassLiteralProperties(ClassLiteral* expr, Register literal, | 132 void VisitClassLiteralProperties(ClassLiteral* expr, Register literal, |
141 Register prototype); | 133 Register prototype); |
142 void VisitClassLiteralStaticPrototypeWithComputedName(Register name); | |
143 void VisitThisFunctionVariable(Variable* variable); | 134 void VisitThisFunctionVariable(Variable* variable); |
144 void VisitNewTargetVariable(Variable* variable); | 135 void VisitNewTargetVariable(Variable* variable); |
145 void VisitBlockDeclarationsAndStatements(Block* stmt); | 136 void VisitBlockDeclarationsAndStatements(Block* stmt); |
146 void VisitFunctionClosureForContext(); | 137 void VisitFunctionClosureForContext(); |
147 void VisitSetHomeObject(Register value, Register home_object, | 138 void VisitSetHomeObject(Register value, Register home_object, |
148 LiteralProperty* property, int slot_number = 0); | 139 LiteralProperty* property, int slot_number = 0); |
149 void VisitObjectLiteralAccessor(Register home_object, | 140 void VisitObjectLiteralAccessor(Register home_object, |
150 ObjectLiteralProperty* property, | 141 ObjectLiteralProperty* property, |
151 Register value_out); | 142 Register value_out); |
152 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot); | 143 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot); |
153 | 144 |
154 // Visit the header/body of a loop iteration. | 145 // Visit the header/body of a loop iteration. |
155 void VisitIterationHeader(IterationStatement* stmt, | 146 void VisitIterationHeader(IterationStatement* stmt, |
156 LoopBuilder* loop_builder); | 147 LoopBuilder* loop_builder); |
157 void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop_builder); | 148 void VisitIterationBody(IterationStatement* stmt, LoopBuilder* loop_builder); |
158 | 149 |
159 // Visit a statement and switch scopes, the context is in the accumulator. | 150 // Visit a statement and switch scopes, the context is in the accumulator. |
160 void VisitInScope(Statement* stmt, Scope* scope); | 151 void VisitInScope(Statement* stmt, Scope* scope); |
161 | 152 |
162 // Visitors for obtaining expression result in the accumulator, in a | 153 // Visitors for obtaining expression result in the accumulator, in a |
163 // register, or just getting the effect. | 154 // register, or just getting the effect. |
164 void VisitForAccumulatorValue(Expression* expr); | 155 void VisitForAccumulatorValue(Expression* expr); |
165 void VisitForAccumulatorValueOrTheHole(Expression* expr); | 156 void VisitForAccumulatorValueOrTheHole(Expression* expr); |
166 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expr); | 157 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expr); |
167 void VisitForRegisterValue(Expression* expr, Register destination); | 158 void VisitForRegisterValue(Expression* expr, Register destination); |
168 void VisitForEffect(Expression* expr); | 159 void VisitForEffect(Expression* expr); |
169 void VisitForTest(Expression* expr, BytecodeLabels* then_labels, | 160 void VisitForTest(Expression* expr, BytecodeLabels* then_labels, |
170 BytecodeLabels* else_labels, TestFallthrough fallthrough); | 161 BytecodeLabels* else_labels, TestFallthrough fallthrough); |
171 | 162 |
172 // Methods for tracking and remapping register. | 163 // Returns the runtime function id for a store to super for the function's |
173 void RecordStoreToRegister(Register reg); | 164 // language mode. |
174 Register LoadFromAliasedRegister(Register reg); | 165 inline Runtime::FunctionId StoreToSuperRuntimeId(); |
175 | 166 inline Runtime::FunctionId StoreKeyedToSuperRuntimeId(); |
176 // Initialize an array of temporary registers with consecutive registers. | |
177 template <size_t N> | |
178 void InitializeWithConsecutiveRegisters(Register (®isters)[N]); | |
179 | 167 |
180 inline BytecodeArrayBuilder* builder() const { return builder_; } | 168 inline BytecodeArrayBuilder* builder() const { return builder_; } |
181 inline Zone* zone() const { return zone_; } | 169 inline Zone* zone() const { return zone_; } |
182 inline DeclarationScope* scope() const { return scope_; } | 170 inline DeclarationScope* scope() const { return scope_; } |
183 inline CompilationInfo* info() const { return info_; } | 171 inline CompilationInfo* info() const { return info_; } |
184 | 172 |
185 inline ControlScope* execution_control() const { return execution_control_; } | 173 inline ControlScope* execution_control() const { return execution_control_; } |
186 inline void set_execution_control(ControlScope* scope) { | 174 inline void set_execution_control(ControlScope* scope) { |
187 execution_control_ = scope; | 175 execution_control_ = scope; |
188 } | 176 } |
189 inline ContextScope* execution_context() const { return execution_context_; } | 177 inline ContextScope* execution_context() const { return execution_context_; } |
190 inline void set_execution_context(ContextScope* context) { | 178 inline void set_execution_context(ContextScope* context) { |
191 execution_context_ = context; | 179 execution_context_ = context; |
192 } | 180 } |
193 inline void set_execution_result(ExpressionResultScope* execution_result) { | 181 inline void set_execution_result(ExpressionResultScope* execution_result) { |
194 execution_result_ = execution_result; | 182 execution_result_ = execution_result; |
195 } | 183 } |
196 ExpressionResultScope* execution_result() const { return execution_result_; } | 184 ExpressionResultScope* execution_result() const { return execution_result_; } |
197 inline void set_register_allocator( | 185 BytecodeRegisterAllocator* register_allocator() const { |
198 RegisterAllocationScope* register_allocator) { | 186 return builder()->register_allocator(); |
199 register_allocator_ = register_allocator; | |
200 } | |
201 RegisterAllocationScope* register_allocator() const { | |
202 return register_allocator_; | |
203 } | 187 } |
204 | 188 |
205 GlobalDeclarationsBuilder* globals_builder() { return globals_builder_; } | 189 GlobalDeclarationsBuilder* globals_builder() { return globals_builder_; } |
206 inline LanguageMode language_mode() const; | 190 inline LanguageMode language_mode() const; |
207 int feedback_index(FeedbackVectorSlot slot) const; | 191 int feedback_index(FeedbackVectorSlot slot) const; |
208 | 192 |
209 Handle<Name> home_object_symbol() const { return home_object_symbol_; } | 193 Handle<Name> home_object_symbol() const { return home_object_symbol_; } |
210 Handle<Name> prototype_string() const { return prototype_string_; } | 194 Handle<Name> prototype_string() const { return prototype_string_; } |
211 | 195 |
212 Zone* zone_; | 196 Zone* zone_; |
213 BytecodeArrayBuilder* builder_; | 197 BytecodeArrayBuilder* builder_; |
214 CompilationInfo* info_; | 198 CompilationInfo* info_; |
215 DeclarationScope* scope_; | 199 DeclarationScope* scope_; |
216 | 200 |
217 GlobalDeclarationsBuilder* globals_builder_; | 201 GlobalDeclarationsBuilder* globals_builder_; |
218 ZoneVector<GlobalDeclarationsBuilder*> global_declarations_; | 202 ZoneVector<GlobalDeclarationsBuilder*> global_declarations_; |
219 ZoneVector<std::pair<FunctionLiteral*, size_t>> function_literals_; | 203 ZoneVector<std::pair<FunctionLiteral*, size_t>> function_literals_; |
220 ZoneVector<std::pair<NativeFunctionLiteral*, size_t>> | 204 ZoneVector<std::pair<NativeFunctionLiteral*, size_t>> |
221 native_function_literals_; | 205 native_function_literals_; |
222 | 206 |
223 ControlScope* execution_control_; | 207 ControlScope* execution_control_; |
224 ContextScope* execution_context_; | 208 ContextScope* execution_context_; |
225 ExpressionResultScope* execution_result_; | 209 ExpressionResultScope* execution_result_; |
226 RegisterAllocationScope* register_allocator_; | |
227 | 210 |
228 ZoneVector<BytecodeLabel> generator_resume_points_; | 211 ZoneVector<BytecodeLabel> generator_resume_points_; |
229 Register generator_state_; | 212 Register generator_state_; |
230 int loop_depth_; | 213 int loop_depth_; |
231 | 214 |
232 Handle<Name> home_object_symbol_; | 215 Handle<Name> home_object_symbol_; |
233 Handle<Name> prototype_string_; | 216 Handle<Name> prototype_string_; |
234 }; | 217 }; |
235 | 218 |
236 } // namespace interpreter | 219 } // namespace interpreter |
237 } // namespace internal | 220 } // namespace internal |
238 } // namespace v8 | 221 } // namespace v8 |
239 | 222 |
240 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 223 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
OLD | NEW |