OLD | NEW |
1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 #include "src/interpreter/interpreter-generator.h" | 5 #include "src/interpreter/interpreter-generator.h" |
6 | 6 |
7 #include <array> | 7 #include <array> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "src/builtins/builtins-arguments-gen.h" | 10 #include "src/builtins/builtins-arguments-gen.h" |
(...skipping 3594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3605 // Illegal | 3605 // Illegal |
3606 // | 3606 // |
3607 // An invalid bytecode aborting execution if dispatched. | 3607 // An invalid bytecode aborting execution if dispatched. |
3608 IGNITION_HANDLER(Illegal, InterpreterAssembler) { Abort(kInvalidBytecode); } | 3608 IGNITION_HANDLER(Illegal, InterpreterAssembler) { Abort(kInvalidBytecode); } |
3609 | 3609 |
3610 // Nop | 3610 // Nop |
3611 // | 3611 // |
3612 // No operation. | 3612 // No operation. |
3613 IGNITION_HANDLER(Nop, InterpreterAssembler) { Dispatch(); } | 3613 IGNITION_HANDLER(Nop, InterpreterAssembler) { Dispatch(); } |
3614 | 3614 |
3615 // SuspendGenerator <generator> | 3615 // SuspendGenerator <generator> <first input register> <register count> <flags> |
3616 // | 3616 // |
3617 // Exports the register file and stores it into the generator. Also stores the | 3617 // Exports the register file and stores it into the generator. Also stores the |
3618 // current context, the state given in the accumulator, and the current bytecode | 3618 // current context, the state given in the accumulator, and the current bytecode |
3619 // offset (for debugging purposes) into the generator. | 3619 // offset (for debugging purposes) into the generator. |
3620 IGNITION_HANDLER(SuspendGenerator, InterpreterAssembler) { | 3620 IGNITION_HANDLER(SuspendGenerator, InterpreterAssembler) { |
3621 Node* generator_reg = BytecodeOperandReg(0); | 3621 Node* generator_reg = BytecodeOperandReg(0); |
3622 Node* flags = BytecodeOperandFlag(1); | 3622 Node* flags = BytecodeOperandFlag(3); |
| 3623 |
3623 Node* generator = LoadRegister(generator_reg); | 3624 Node* generator = LoadRegister(generator_reg); |
3624 | 3625 |
3625 Label if_stepping(this, Label::kDeferred), ok(this); | 3626 Label if_stepping(this, Label::kDeferred), ok(this); |
3626 Node* step_action_address = ExternalConstant( | 3627 Node* step_action_address = ExternalConstant( |
3627 ExternalReference::debug_last_step_action_address(isolate())); | 3628 ExternalReference::debug_last_step_action_address(isolate())); |
3628 Node* step_action = Load(MachineType::Int8(), step_action_address); | 3629 Node* step_action = Load(MachineType::Int8(), step_action_address); |
3629 STATIC_ASSERT(StepIn > StepNext); | 3630 STATIC_ASSERT(StepIn > StepNext); |
3630 STATIC_ASSERT(LastStepAction == StepIn); | 3631 STATIC_ASSERT(LastStepAction == StepIn); |
3631 Node* step_next = Int32Constant(StepNext); | 3632 Node* step_next = Int32Constant(StepNext); |
3632 Branch(Int32LessThanOrEqual(step_next, step_action), &if_stepping, &ok); | 3633 Branch(Int32LessThanOrEqual(step_next, step_action), &if_stepping, &ok); |
3633 BIND(&ok); | 3634 BIND(&ok); |
3634 | 3635 |
3635 Node* array = | 3636 Node* array = |
3636 LoadObjectField(generator, JSGeneratorObject::kRegisterFileOffset); | 3637 LoadObjectField(generator, JSGeneratorObject::kRegisterFileOffset); |
3637 Node* context = GetContext(); | 3638 Node* context = GetContext(); |
3638 Node* state = GetAccumulator(); | 3639 Node* state = GetAccumulator(); |
3639 | 3640 |
3640 ExportRegisterFile(array); | 3641 // Bytecode operand 1 should be always 0 (we are always store registers |
| 3642 // from the beginning). |
| 3643 CSA_ASSERT(this, WordEqual(BytecodeOperandReg(1), |
| 3644 IntPtrConstant(Register(0).ToOperand()))); |
| 3645 // Bytecode operand 2 is the number of registers to store to the generator. |
| 3646 Node* register_count = ChangeUint32ToWord(BytecodeOperandCount(2)); |
| 3647 ExportRegisterFile(array, register_count); |
3641 StoreObjectField(generator, JSGeneratorObject::kContextOffset, context); | 3648 StoreObjectField(generator, JSGeneratorObject::kContextOffset, context); |
3642 StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, state); | 3649 StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, state); |
3643 | 3650 |
3644 Label if_asyncgeneratorawait(this), if_notasyncgeneratorawait(this), | 3651 Label if_asyncgeneratorawait(this), if_notasyncgeneratorawait(this), |
3645 merge(this); | 3652 merge(this); |
3646 | 3653 |
3647 // Calculate bytecode offset to store in the [input_or_debug_pos] or | 3654 // Calculate bytecode offset to store in the [input_or_debug_pos] or |
3648 // [await_input_or_debug_pos] fields, to be used by the inspector. | 3655 // [await_input_or_debug_pos] fields, to be used by the inspector. |
3649 Node* offset = SmiTag(BytecodeOffset()); | 3656 Node* offset = SmiTag(BytecodeOffset()); |
3650 | 3657 |
(...skipping 28 matching lines...) Expand all Loading... |
3679 Dispatch(); | 3686 Dispatch(); |
3680 | 3687 |
3681 BIND(&if_stepping); | 3688 BIND(&if_stepping); |
3682 { | 3689 { |
3683 Node* context = GetContext(); | 3690 Node* context = GetContext(); |
3684 CallRuntime(Runtime::kDebugRecordGenerator, context, generator); | 3691 CallRuntime(Runtime::kDebugRecordGenerator, context, generator); |
3685 Goto(&ok); | 3692 Goto(&ok); |
3686 } | 3693 } |
3687 } | 3694 } |
3688 | 3695 |
3689 // ResumeGenerator <generator> | 3696 // RestoreGeneratorState <generator> |
3690 // | 3697 // |
3691 // Imports the register file stored in the generator. Also loads the | 3698 // Loads the generator's state and stores it in the accumulator, |
3692 // generator's state and stores it in the accumulator, before overwriting it | 3699 // before overwriting it with kGeneratorExecuting. |
3693 // with kGeneratorExecuting. | 3700 IGNITION_HANDLER(RestoreGeneratorState, InterpreterAssembler) { |
3694 IGNITION_HANDLER(ResumeGenerator, InterpreterAssembler) { | |
3695 Node* generator_reg = BytecodeOperandReg(0); | 3701 Node* generator_reg = BytecodeOperandReg(0); |
3696 Node* generator = LoadRegister(generator_reg); | 3702 Node* generator = LoadRegister(generator_reg); |
3697 | 3703 |
3698 ImportRegisterFile( | |
3699 LoadObjectField(generator, JSGeneratorObject::kRegisterFileOffset)); | |
3700 | |
3701 Node* old_state = | 3704 Node* old_state = |
3702 LoadObjectField(generator, JSGeneratorObject::kContinuationOffset); | 3705 LoadObjectField(generator, JSGeneratorObject::kContinuationOffset); |
3703 Node* new_state = Int32Constant(JSGeneratorObject::kGeneratorExecuting); | 3706 Node* new_state = Int32Constant(JSGeneratorObject::kGeneratorExecuting); |
3704 StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, | 3707 StoreObjectField(generator, JSGeneratorObject::kContinuationOffset, |
3705 SmiTag(new_state)); | 3708 SmiTag(new_state)); |
3706 SetAccumulator(old_state); | 3709 SetAccumulator(old_state); |
3707 | 3710 |
3708 Dispatch(); | 3711 Dispatch(); |
3709 } | 3712 } |
3710 | 3713 |
| 3714 // RestoreGeneratorRegisters <generator> <first output register> <register |
| 3715 // count> |
| 3716 // |
| 3717 // Imports the register file stored in the generator. |
| 3718 IGNITION_HANDLER(RestoreGeneratorRegisters, InterpreterAssembler) { |
| 3719 Node* generator_reg = BytecodeOperandReg(0); |
| 3720 // Bytecode operand 1 is the start register. It should always be 0, so let's |
| 3721 // ignore it. |
| 3722 CSA_ASSERT(this, WordEqual(BytecodeOperandReg(1), |
| 3723 IntPtrConstant(Register(0).ToOperand()))); |
| 3724 // Bytecode operand 2 is the number of registers to store to the generator. |
| 3725 Node* register_count = ChangeUint32ToWord(BytecodeOperandCount(2)); |
| 3726 |
| 3727 Node* generator = LoadRegister(generator_reg); |
| 3728 |
| 3729 ImportRegisterFile( |
| 3730 LoadObjectField(generator, JSGeneratorObject::kRegisterFileOffset), |
| 3731 register_count); |
| 3732 |
| 3733 Dispatch(); |
| 3734 } |
| 3735 |
3711 } // namespace | 3736 } // namespace |
3712 | 3737 |
3713 Handle<Code> GenerateBytecodeHandler(Isolate* isolate, Bytecode bytecode, | 3738 Handle<Code> GenerateBytecodeHandler(Isolate* isolate, Bytecode bytecode, |
3714 OperandScale operand_scale) { | 3739 OperandScale operand_scale) { |
3715 Zone zone(isolate->allocator(), ZONE_NAME); | 3740 Zone zone(isolate->allocator(), ZONE_NAME); |
3716 InterpreterDispatchDescriptor descriptor(isolate); | 3741 InterpreterDispatchDescriptor descriptor(isolate); |
3717 compiler::CodeAssemblerState state( | 3742 compiler::CodeAssemblerState state( |
3718 isolate, &zone, descriptor, Code::ComputeFlags(Code::BYTECODE_HANDLER), | 3743 isolate, &zone, descriptor, Code::ComputeFlags(Code::BYTECODE_HANDLER), |
3719 Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode)); | 3744 Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode)); |
3720 | 3745 |
(...skipping 17 matching lines...) Expand all Loading... |
3738 code->Disassemble(Bytecodes::ToString(bytecode), os); | 3763 code->Disassemble(Bytecodes::ToString(bytecode), os); |
3739 os << std::flush; | 3764 os << std::flush; |
3740 } | 3765 } |
3741 #endif // ENABLE_DISASSEMBLER | 3766 #endif // ENABLE_DISASSEMBLER |
3742 return code; | 3767 return code; |
3743 } | 3768 } |
3744 | 3769 |
3745 } // namespace interpreter | 3770 } // namespace interpreter |
3746 } // namespace internal | 3771 } // namespace internal |
3747 } // namespace v8 | 3772 } // namespace v8 |
OLD | NEW |