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 #include "src/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 // functions are non-constructable. | 974 // functions are non-constructable. |
975 builder()->MoveRegister(Register::new_target(), generator_object_); | 975 builder()->MoveRegister(Register::new_target(), generator_object_); |
976 | 976 |
977 BytecodeLabel regular_call; | 977 BytecodeLabel regular_call; |
978 builder() | 978 builder() |
979 ->LoadAccumulatorWithRegister(generator_object_) | 979 ->LoadAccumulatorWithRegister(generator_object_) |
980 .JumpIfUndefined(®ular_call); | 980 .JumpIfUndefined(®ular_call); |
981 | 981 |
982 // This is a resume call. Restore the current context and the registers, | 982 // This is a resume call. Restore the current context and the registers, |
983 // then perform state dispatch. | 983 // then perform state dispatch. |
984 Register generator_context = register_allocator()->NewRegister(); | 984 { |
985 builder() | 985 RegisterAllocationScope register_scope(this); |
986 ->CallRuntime(Runtime::kInlineGeneratorGetContext, generator_object_) | 986 Register generator_context = register_allocator()->NewRegister(); |
987 .PushContext(generator_context) | 987 builder() |
988 .RestoreGeneratorState(generator_object_) | 988 ->CallRuntime(Runtime::kInlineGeneratorGetContext, generator_object_) |
989 .StoreAccumulatorInRegister(generator_state_) | 989 .PushContext(generator_context) |
990 .SwitchOnSmiNoFeedback(generator_jump_table_); | 990 .RestoreGeneratorState(generator_object_) |
991 .StoreAccumulatorInRegister(generator_state_) | |
992 .SwitchOnSmiNoFeedback(generator_jump_table_); | |
993 } | |
991 // We fall through when the generator state is not in the jump table. | 994 // We fall through when the generator state is not in the jump table. |
992 // TODO(leszeks): Only generate this for debug builds. | 995 // TODO(leszeks): Only generate this for debug builds. |
993 BuildAbort(BailoutReason::kInvalidJumpTableIndex); | 996 BuildAbort(BailoutReason::kInvalidJumpTableIndex); |
994 | 997 |
995 // This is a regular call. | 998 // This is a regular call. |
996 builder() | 999 builder() |
997 ->Bind(®ular_call) | 1000 ->Bind(®ular_call) |
998 .LoadLiteral(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)) | 1001 .LoadLiteral(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)) |
999 .StoreAccumulatorInRegister(generator_state_); | 1002 .StoreAccumulatorInRegister(generator_state_); |
1000 // Now fall through to the ordinary function prologue, after which we will run | 1003 // Now fall through to the ordinary function prologue, after which we will run |
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2176 if (FLAG_trace) { | 2179 if (FLAG_trace) { |
2177 RegisterAllocationScope register_scope(this); | 2180 RegisterAllocationScope register_scope(this); |
2178 Register result = register_allocator()->NewRegister(); | 2181 Register result = register_allocator()->NewRegister(); |
2179 // Runtime returns {result} value, preserving accumulator. | 2182 // Runtime returns {result} value, preserving accumulator. |
2180 builder()->StoreAccumulatorInRegister(result).CallRuntime( | 2183 builder()->StoreAccumulatorInRegister(result).CallRuntime( |
2181 Runtime::kTraceExit, result); | 2184 Runtime::kTraceExit, result); |
2182 } | 2185 } |
2183 if (info()->literal()->feedback_vector_spec()->HasTypeProfileSlot()) { | 2186 if (info()->literal()->feedback_vector_spec()->HasTypeProfileSlot()) { |
2184 builder()->CollectTypeProfile(info()->literal()->return_position()); | 2187 builder()->CollectTypeProfile(info()->literal()->return_position()); |
2185 } | 2188 } |
2189 if (IsGeneratorFunction(info()->literal()->kind())) { | |
2190 Register result = register_allocator()->NewRegister(); | |
rmcilroy
2017/06/05 10:02:58
nit - add a comment that we need to close the gene
Jarin
2017/06/05 16:03:25
Done.
| |
2191 builder() | |
2192 ->StoreAccumulatorInRegister(result) | |
2193 .CallRuntime(Runtime::kInlineGeneratorClose, generator_object_) | |
2194 .LoadAccumulatorWithRegister(result); | |
2195 } | |
2186 builder()->Return(); | 2196 builder()->Return(); |
2187 } | 2197 } |
2188 | 2198 |
2189 void BytecodeGenerator::BuildAsyncReturn() { | 2199 void BytecodeGenerator::BuildAsyncReturn() { |
2190 RegisterAllocationScope register_scope(this); | 2200 RegisterAllocationScope register_scope(this); |
2191 | 2201 |
2192 if (IsAsyncGeneratorFunction(info()->literal()->kind())) { | 2202 if (IsAsyncGeneratorFunction(info()->literal()->kind())) { |
2193 RegisterList args = register_allocator()->NewRegisterList(3); | 2203 RegisterList args = register_allocator()->NewRegisterList(3); |
2194 Register generator = args[0]; | 2204 Register generator = args[0]; |
2195 Register result = args[1]; | 2205 Register result = args[1]; |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2539 RegisterList args = register_allocator()->NewRegisterList(3); | 2549 RegisterList args = register_allocator()->NewRegisterList(3); |
2540 | 2550 |
2541 // AsyncGeneratorYield: | 2551 // AsyncGeneratorYield: |
2542 // perform AsyncGeneratorResolve(<generator>, <value>, false). | 2552 // perform AsyncGeneratorResolve(<generator>, <value>, false). |
2543 builder() | 2553 builder() |
2544 ->MoveRegister(generator, args[0]) | 2554 ->MoveRegister(generator, args[0]) |
2545 .MoveRegister(value, args[1]) | 2555 .MoveRegister(value, args[1]) |
2546 .LoadFalse() | 2556 .LoadFalse() |
2547 .StoreAccumulatorInRegister(args[2]) | 2557 .StoreAccumulatorInRegister(args[2]) |
2548 .CallRuntime(Runtime::kInlineAsyncGeneratorResolve, args); | 2558 .CallRuntime(Runtime::kInlineAsyncGeneratorResolve, args); |
2559 } else if (expr->IsNonInitialGeneratorYield()) { | |
rmcilroy
2017/06/05 10:02:58
nit - let's put this above expr->IsNonInitialAsync
Jarin
2017/06/05 16:03:24
Done.
| |
2560 // GeneratorYield: Wrap the value into IteratorResult. | |
2561 RegisterList args = register_allocator()->NewRegisterList(2); | |
2562 builder() | |
2563 ->MoveRegister(value, args[0]) | |
2564 .LoadFalse() | |
2565 .StoreAccumulatorInRegister(args[1]) | |
2566 .CallRuntime(Runtime::kInlineCreateIterResultObject, args); | |
2549 } else { | 2567 } else { |
2550 builder()->LoadAccumulatorWithRegister(value); | 2568 builder()->LoadAccumulatorWithRegister(value); |
2551 } | 2569 } |
2552 builder()->Return(); // Hard return (ignore any finally blocks). | 2570 builder()->Return(); // Hard return (ignore any finally blocks). |
2553 } | 2571 } |
2554 | 2572 |
2555 void BytecodeGenerator::BuildGeneratorResume( | 2573 void BytecodeGenerator::BuildGeneratorResume( |
2556 Suspend* expr, Register generator, RegisterList registers_to_restore) { | 2574 Suspend* expr, Register generator, RegisterList registers_to_restore) { |
2557 RegisterAllocationScope register_scope(this); | 2575 RegisterAllocationScope register_scope(this); |
2558 | 2576 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2592 | 2610 |
2593 builder() | 2611 builder() |
2594 ->LoadLiteral(Smi::FromInt(JSGeneratorObject::kNext)) | 2612 ->LoadLiteral(Smi::FromInt(JSGeneratorObject::kNext)) |
2595 .CompareOperation(Token::EQ_STRICT, resume_mode) | 2613 .CompareOperation(Token::EQ_STRICT, resume_mode) |
2596 .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &resume_with_next) | 2614 .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &resume_with_next) |
2597 .LoadLiteral(Smi::FromInt(JSGeneratorObject::kThrow)) | 2615 .LoadLiteral(Smi::FromInt(JSGeneratorObject::kThrow)) |
2598 .CompareOperation(Token::EQ_STRICT, resume_mode) | 2616 .CompareOperation(Token::EQ_STRICT, resume_mode) |
2599 .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &resume_with_throw); | 2617 .JumpIfTrue(ToBooleanMode::kAlreadyBoolean, &resume_with_throw); |
2600 // Fall through for resuming with return. | 2618 // Fall through for resuming with return. |
2601 | 2619 |
2620 builder()->LoadAccumulatorWithRegister(input); | |
2602 if (expr->is_async_generator()) { | 2621 if (expr->is_async_generator()) { |
2603 // Async generator methods will produce the iter result object. | 2622 // Async generator methods will produce the iter result object. |
2604 builder()->LoadAccumulatorWithRegister(input); | |
2605 execution_control()->AsyncReturnAccumulator(); | 2623 execution_control()->AsyncReturnAccumulator(); |
2606 } else { | 2624 } else { |
2607 RegisterList args = register_allocator()->NewRegisterList(2); | |
2608 builder() | |
2609 ->MoveRegister(input, args[0]) | |
2610 .LoadTrue() | |
2611 .StoreAccumulatorInRegister(args[1]) | |
2612 .CallRuntime(Runtime::kInlineCreateIterResultObject, args); | |
2613 execution_control()->ReturnAccumulator(); | 2625 execution_control()->ReturnAccumulator(); |
2614 } | 2626 } |
2615 | 2627 |
2616 builder()->Bind(&resume_with_throw); | 2628 builder()->Bind(&resume_with_throw); |
2617 builder()->SetExpressionPosition(expr); | 2629 builder()->SetExpressionPosition(expr); |
2618 builder()->LoadAccumulatorWithRegister(input); | 2630 builder()->LoadAccumulatorWithRegister(input); |
2619 if (expr->rethrow_on_exception()) { | 2631 if (expr->rethrow_on_exception()) { |
2620 builder()->ReThrow(); | 2632 builder()->ReThrow(); |
2621 } else { | 2633 } else { |
2622 builder()->Throw(); | 2634 builder()->Throw(); |
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3913 } | 3925 } |
3914 | 3926 |
3915 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3927 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3916 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3928 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3917 : Runtime::kStoreKeyedToSuper_Sloppy; | 3929 : Runtime::kStoreKeyedToSuper_Sloppy; |
3918 } | 3930 } |
3919 | 3931 |
3920 } // namespace interpreter | 3932 } // namespace interpreter |
3921 } // namespace internal | 3933 } // namespace internal |
3922 } // namespace v8 | 3934 } // namespace v8 |
OLD | NEW |