5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 8 #include "src/ast/ast.h" 9 #include "src/base/compiler-specific.h" 10 #include "src/globals.h" 11 #include "src/interpreter/bytecode-array-writer.h" 12 #include "src/interpreter/bytecode-flags.h" 13 #include "src/interpreter/bytecode-register-allocator.h" 14 #include "src/interpreter/bytecode-register.h" 15 #include "src/interpreter/bytecode-source-info.h" 16 #include "src/interpreter/bytecodes.h" 17 #include "src/interpreter/constant-array-builder.h" 18 #include "src/interpreter/handler-table-builder.h" 19 #include "src/zone/zone-containers.h" 24 class FeedbackVectorSpec;
27 namespace interpreter {
31 class BytecodeRegisterOptimizer;
32 class BytecodeJumpTable;
38 Zone* zone,
int parameter_count,
int locals_count,
40 SourcePositionTableBuilder::RecordingMode source_position_mode =
41 SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS);
46 int parameter_count()
const {
47 DCHECK_GE(parameter_count_, 0);
48 return parameter_count_;
52 int locals_count()
const {
53 DCHECK_GE(local_register_count_, 0);
54 return local_register_count_;
58 int fixed_register_count()
const {
return locals_count(); }
61 int total_register_count()
const {
62 DCHECK_LE(fixed_register_count(),
63 register_allocator()->maximum_register_count());
64 return register_allocator()->maximum_register_count();
68 Register Parameter(
int parameter_index)
const;
88 TypeofMode typeof_mode);
94 enum ContextSlotMutability { kImmutableSlot, kMutableSlot };
97 ContextSlotMutability immutable);
151 LanguageMode language_mode);
161 size_t constant_pool_entry,
163 LanguageMode language_mode);
173 LanguageMode language_mode);
182 LanguageMode language_mode);
195 TypeofMode typeof_mode);
201 TypeofMode typeof_mode,
202 int slot_index,
int depth);
208 TypeofMode typeof_mode,
209 int feedback_slot,
int depth);
214 LookupHoistingMode lookup_hoisting_mode);
219 int slot,
int flags);
243 int literal_index,
int flags);
245 int literal_index,
int flags);
249 int literal_index,
int flags);
257 size_t template_object_description_entry,
int feedback_slot);
358 enum class ToBooleanMode {
377 enum NilValue { kNullValue, kUndefinedValue };
389 TestTypeOfFlags::LiteralFlag literal_flag);
464 HandlerTable::CatchPrediction will_catch);
470 int NewHandlerEntry() {
return handler_table_builder()->NewHandlerEntry(); }
477 size_t GetConstantPoolEntry(
const AstRawString* raw_string);
478 size_t GetConstantPoolEntry(
AstBigInt bigint);
479 size_t GetConstantPoolEntry(
const Scope* scope);
480 size_t GetConstantPoolEntry(
double number);
481 #define ENTRY_GETTER(NAME, ...) size_t NAME##ConstantPoolEntry(); 482 SINGLETON_CONSTANT_ENTRY_TYPES(ENTRY_GETTER)
486 size_t AllocateDeferredConstantPoolEntry();
488 void SetDeferredConstantPoolEntry(
size_t entry,
Handle<Object> object);
492 void SetStatementPosition(
Statement* stmt) {
493 if (stmt->position() == kNoSourcePosition)
return;
494 latest_source_info_.MakeStatementPosition(stmt->position());
497 void SetExpressionPosition(
Expression* expr) {
498 SetExpressionPosition(expr->position());
501 void SetExpressionPosition(
int position) {
502 if (position == kNoSourcePosition)
return;
503 if (!latest_source_info_.is_statement()) {
506 latest_source_info_.MakeExpressionPosition(position);
510 void SetExpressionAsStatementPosition(
Expression* expr) {
511 if (expr->position() == kNoSourcePosition)
return;
512 latest_source_info_.MakeStatementPosition(expr->position());
515 void SetReturnPosition(
int source_position,
FunctionLiteral* literal) {
516 if (source_position != kNoSourcePosition) {
517 latest_source_info_.MakeStatementPosition(source_position);
518 }
else if (literal->return_position() != kNoSourcePosition) {
519 latest_source_info_.MakeStatementPosition(literal->return_position());
523 bool RequiresImplicitReturn()
const {
return !return_seen_in_block_; }
524 bool RemainderOfBlockIsDead()
const {
525 return bytecode_array_writer_.RemainderOfBlockIsDead();
542 return ®ister_allocator_;
545 return ®ister_allocator_;
547 Zone* zone()
const {
return zone_; }
551 template <Bytecode bytecode, AccumulatorUse accumulator_use,
552 OperandType... operand_types>
556 return feedback_vector_spec_;
562 #define DECLARE_BYTECODE_OUTPUT(Name, ...) \ 563 template <typename... Operands> \ 564 V8_INLINE BytecodeNode Create##Name##Node(Operands... operands); \ 565 template <typename... Operands> \ 566 V8_INLINE void Output##Name(Operands... operands); \ 567 template <typename... Operands> \ 568 V8_INLINE void Output##Name(BytecodeLabel* label, Operands... operands); 569 BYTECODE_LIST(DECLARE_BYTECODE_OUTPUT)
570 #undef DECLARE_OPERAND_TYPE_INFO 574 bool RegisterIsValid(
Register reg)
const;
582 void AttachOrEmitDeferredSourceInfo(
BytecodeNode* node);
594 template <Bytecode bytecode, AccumulatorUse accumulator_use>
595 void PrepareToOutputBytecode();
597 void LeaveBasicBlock() { return_seen_in_block_ =
false; }
600 return &bytecode_array_writer_;
603 return &constant_array_builder_;
606 return &constant_array_builder_;
609 return &handler_table_builder_;
614 bool bytecode_generated_;
617 bool return_seen_in_block_;
618 int parameter_count_;
619 int local_register_count_;
629 V8_EXPORT_PRIVATE std::ostream& operator<<(
630 std::ostream& os,
const BytecodeArrayBuilder::ToBooleanMode& mode);
636 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_