5 #ifndef V8_INTERPRETER_BYTECODE_GENERATOR_H_ 6 #define V8_INTERPRETER_BYTECODE_GENERATOR_H_ 8 #include "src/ast/ast.h" 9 #include "src/feedback-vector.h" 10 #include "src/interpreter/bytecode-array-builder.h" 11 #include "src/interpreter/bytecode-label.h" 12 #include "src/interpreter/bytecode-register.h" 13 #include "src/interpreter/bytecodes.h" 18 class AstNodeSourceRanges;
19 class AstStringConstants;
20 class UnoptimizedCompilationInfo;
21 enum class SourceRangeKind;
23 namespace interpreter {
25 class GlobalDeclarationsBuilder;
27 class BlockCoverageBuilder;
28 class BytecodeJumpTable;
35 std::vector<FunctionLiteral*>* eager_inner_literals);
37 void GenerateBytecode(
uintptr_t stack_limit);
41 #define DECLARE_VISIT(type) void Visit##type(type* node); 42 AST_NODE_LIST(DECLARE_VISIT)
68 using ToBooleanMode = BytecodeArrayBuilder::ToBooleanMode;
70 enum class TestFallthrough { kThen, kElse,
kNone };
71 enum class TypeHint { kAny, kBoolean, kString };
73 void GenerateBytecodeBody();
76 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
111 void VisitKeyedSuperPropertyLoad(
Property* property,
118 void VisitNamedSuperPropertyLoad(
Property* property,
130 void BuildVariableLoad(
Variable* variable, HoleCheckMode hole_check_mode,
131 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);
132 void BuildVariableLoadForAccumulatorValue(
133 Variable* variable, HoleCheckMode hole_check_mode,
134 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);
135 void BuildVariableAssignment(
136 Variable* variable, Token::Value op, HoleCheckMode hole_check_mode,
137 LookupHoistingMode lookup_hoisting_mode = LookupHoistingMode::kNormal);
138 void BuildLiteralCompareNil(Token::Value compare_op,
139 BytecodeArrayBuilder::NilValue nil);
140 void BuildReturn(
int source_position = kNoSourcePosition);
141 void BuildAsyncReturn(
int source_position = kNoSourcePosition);
142 void BuildAsyncGeneratorReturn();
144 void BuildHoleCheckForVariableAssignment(
Variable* variable, Token::Value op);
145 void BuildThrowIfHole(
Variable* variable);
149 void BuildIndexedJump(
Register value,
size_t start_index,
size_t size,
152 void BuildNewLocalActivationContext();
153 void BuildLocalActivationContextInitialization();
154 void BuildNewLocalBlockContext(
Scope* scope);
155 void BuildNewLocalCatchContext(
Scope* scope);
156 void BuildNewLocalWithContext(
Scope* scope);
158 void BuildGeneratorPrologue();
159 void BuildSuspendPoint(
Expression* suspend_expr);
163 void BuildGetIterator(
Expression* iterable, IteratorType hint);
192 void BuildCreateObjectLiteral(
Register literal, uint8_t flags,
size_t entry);
193 void AllocateTopLevelRegisters();
194 void VisitArgumentsObject(
Variable* variable);
195 void VisitRestArgumentsArray(
Variable* rest);
196 void VisitCallSuper(
Call* call);
199 void VisitNewTargetVariable(
Variable* variable);
200 void VisitThisFunctionVariable(
Variable* variable);
201 void BuildInstanceMemberInitialization(
Register constructor,
203 void BuildGeneratorObjectVariableInitialization();
204 void VisitBlockDeclarationsAndStatements(
Block* stmt);
207 void VisitObjectLiteralAccessor(
Register home_object,
211 void VisitModuleNamespaceImports();
216 int right_coverage_slot);
217 void VisitNaryLogicalTest(Token::Value token,
NaryOperation* expr,
221 void VisitLogicalTestSubExpression(Token::Value token,
Expression* expr,
229 bool VisitLogicalAndSubExpression(
Expression* expr,
239 void BuildPushUndefinedIntoRegisterList(
RegisterList* reg_list);
243 int AllocateBlockCoverageSlotIfEnabled(
AstNode* node, SourceRangeKind kind);
244 int AllocateNaryBlockCoverageSlotIfEnabled(
NaryOperation* node,
size_t index);
246 void BuildIncrementBlockCoverageCounterIfEnabled(
AstNode* node,
247 SourceRangeKind kind);
248 void BuildIncrementBlockCoverageCounterIfEnabled(
int coverage_array_slot);
256 TypeHint VisitForAccumulatorValue(
Expression* expr);
257 void VisitForAccumulatorValueOrTheHole(
Expression* expr);
265 void VisitInSameTestExecutionScope(
Expression* expr);
271 inline Runtime::FunctionId StoreToSuperRuntimeId();
272 inline Runtime::FunctionId StoreKeyedToSuperRuntimeId();
276 FeedbackSlot GetCachedLoadGlobalICSlot(TypeofMode typeof_mode,
278 FeedbackSlot GetCachedStoreGlobalICSlot(LanguageMode language_mode,
292 inline bool ShouldOptimizeAsOneShot()
const;
294 static constexpr ToBooleanMode ToBooleanModeFromTypeHint(TypeHint type_hint) {
295 return type_hint == TypeHint::kBoolean ? ToBooleanMode::kAlreadyBoolean
296 : ToBooleanMode::kConvertToBoolean;
299 inline Register generator_object()
const;
302 inline Zone* zone()
const {
return zone_; }
306 return ast_string_constants_;
309 inline Scope* current_scope()
const {
return current_scope_; }
310 inline void set_current_scope(
Scope* scope) { current_scope_ = scope; }
312 inline ControlScope* execution_control()
const {
return execution_control_; }
313 inline void set_execution_control(
ControlScope* scope) {
314 execution_control_ = scope;
316 inline ContextScope* execution_context()
const {
return execution_context_; }
317 inline void set_execution_context(
ContextScope* context) {
318 execution_context_ = context;
321 execution_result_ = execution_result;
325 return builder()->register_allocator();
329 DCHECK_NOT_NULL(globals_builder_);
330 return globals_builder_;
332 inline LanguageMode language_mode()
const;
333 inline FunctionKind function_kind()
const;
338 return feedback_slot_cache_;
341 inline HandlerTable::CatchPrediction catch_prediction()
const {
342 return catch_prediction_;
344 inline void set_catch_prediction(HandlerTable::CatchPrediction value) {
345 catch_prediction_ = value;
353 Scope* current_scope_;
356 std::vector<FunctionLiteral*>* eager_inner_literals_;
365 native_function_literals_;
375 Register incoming_new_target_or_generator_;
385 HandlerTable::CatchPrediction catch_prediction_;
392 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_