OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1759 | 1759 |
1760 | 1760 |
1761 void FullCodeGenerator::VisitYield(Yield* expr) { | 1761 void FullCodeGenerator::VisitYield(Yield* expr) { |
1762 Comment cmnt(masm_, "[ Yield"); | 1762 Comment cmnt(masm_, "[ Yield"); |
1763 SetExpressionPosition(expr); | 1763 SetExpressionPosition(expr); |
1764 | 1764 |
1765 // Evaluate yielded value first; the initial iterator definition depends on | 1765 // Evaluate yielded value first; the initial iterator definition depends on |
1766 // this. It stays on the stack while we update the iterator. | 1766 // this. It stays on the stack while we update the iterator. |
1767 VisitForStackValue(expr->expression()); | 1767 VisitForStackValue(expr->expression()); |
1768 | 1768 |
1769 switch (expr->yield_kind()) { | 1769 Label suspend, continuation, post_runtime, resume; |
1770 case Yield::kSuspend: | |
1771 // Pop value from top-of-stack slot; box result into result register. | |
1772 EmitCreateIteratorResult(false); | |
1773 PushOperand(result_register()); | |
1774 // Fall through. | |
1775 case Yield::kInitial: { | |
1776 Label suspend, continuation, post_runtime, resume; | |
1777 | 1770 |
1778 __ jmp(&suspend); | 1771 __ jmp(&suspend); |
1779 __ bind(&continuation); | 1772 __ bind(&continuation); |
1780 // When we arrive here, the stack top is the resume mode and | 1773 // When we arrive here, the stack top is the resume mode and |
1781 // result_register() holds the input value (the argument given to the | 1774 // result_register() holds the input value (the argument given to the |
1782 // respective resume operation). | 1775 // respective resume operation). |
1783 __ RecordGeneratorContinuation(); | 1776 __ RecordGeneratorContinuation(); |
1784 __ pop(ebx); | 1777 __ pop(ebx); |
1785 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); | 1778 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); |
1786 __ j(not_equal, &resume); | 1779 __ j(not_equal, &resume); |
1787 __ push(result_register()); | 1780 __ push(result_register()); |
1788 EmitCreateIteratorResult(true); | 1781 EmitCreateIteratorResult(true); |
1789 EmitUnwindAndReturn(); | 1782 EmitUnwindAndReturn(); |
1790 | 1783 |
1791 __ bind(&suspend); | 1784 __ bind(&suspend); |
1792 OperandStackDepthIncrement(1); // Not popped on this path. | 1785 OperandStackDepthIncrement(1); // Not popped on this path. |
1793 VisitForAccumulatorValue(expr->generator_object()); | 1786 VisitForAccumulatorValue(expr->generator_object()); |
1794 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | 1787 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
1795 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | 1788 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
1796 Immediate(Smi::FromInt(continuation.pos()))); | 1789 Immediate(Smi::FromInt(continuation.pos()))); |
1797 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | 1790 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
1798 __ mov(ecx, esi); | 1791 __ mov(ecx, esi); |
1799 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | 1792 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
1800 kDontSaveFPRegs); | 1793 kDontSaveFPRegs); |
1801 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); | 1794 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
1802 __ cmp(esp, ebx); | 1795 __ cmp(esp, ebx); |
1803 __ j(equal, &post_runtime); | 1796 __ j(equal, &post_runtime); |
1804 __ push(eax); // generator object | 1797 __ push(eax); // generator object |
1805 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1798 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1806 __ mov(context_register(), | 1799 __ mov(context_register(), |
1807 Operand(ebp, StandardFrameConstants::kContextOffset)); | 1800 Operand(ebp, StandardFrameConstants::kContextOffset)); |
1808 __ bind(&post_runtime); | 1801 __ bind(&post_runtime); |
1809 PopOperand(result_register()); | 1802 PopOperand(result_register()); |
1810 EmitReturnSequence(); | 1803 EmitReturnSequence(); |
1811 | 1804 |
1812 __ bind(&resume); | 1805 __ bind(&resume); |
1813 context()->Plug(result_register()); | 1806 context()->Plug(result_register()); |
1814 break; | |
1815 } | |
1816 | |
1817 case Yield::kFinal: { | |
1818 // Pop value from top-of-stack slot, box result into result register. | |
1819 EmitCreateIteratorResult(true); | |
1820 EmitUnwindAndReturn(); | |
1821 break; | |
1822 } | |
1823 | |
1824 case Yield::kDelegating: | |
1825 UNREACHABLE(); | |
1826 } | |
1827 } | 1807 } |
1828 | 1808 |
1829 | 1809 |
1830 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 1810 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
1831 Expression *value, | 1811 Expression *value, |
1832 JSGeneratorObject::ResumeMode resume_mode) { | 1812 JSGeneratorObject::ResumeMode resume_mode) { |
1833 // The value stays in eax, and is ultimately read by the resumed generator, as | 1813 // The value stays in eax, and is ultimately read by the resumed generator, as |
1834 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 1814 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
1835 // is read to throw the value when the resumed generator is already closed. | 1815 // is read to throw the value when the resumed generator is already closed. |
1836 // ebx will hold the generator object until the activation has been resumed. | 1816 // ebx will hold the generator object until the activation has been resumed. |
(...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4084 Assembler::target_address_at(call_target_address, | 4064 Assembler::target_address_at(call_target_address, |
4085 unoptimized_code)); | 4065 unoptimized_code)); |
4086 return OSR_AFTER_STACK_CHECK; | 4066 return OSR_AFTER_STACK_CHECK; |
4087 } | 4067 } |
4088 | 4068 |
4089 | 4069 |
4090 } // namespace internal | 4070 } // namespace internal |
4091 } // namespace v8 | 4071 } // namespace v8 |
4092 | 4072 |
4093 #endif // V8_TARGET_ARCH_IA32 | 4073 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |