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_X64 | 5 #if V8_TARGET_ARCH_X64 |
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 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 | 1782 |
1783 | 1783 |
1784 void FullCodeGenerator::VisitYield(Yield* expr) { | 1784 void FullCodeGenerator::VisitYield(Yield* expr) { |
1785 Comment cmnt(masm_, "[ Yield"); | 1785 Comment cmnt(masm_, "[ Yield"); |
1786 SetExpressionPosition(expr); | 1786 SetExpressionPosition(expr); |
1787 | 1787 |
1788 // Evaluate yielded value first; the initial iterator definition depends on | 1788 // Evaluate yielded value first; the initial iterator definition depends on |
1789 // this. It stays on the stack while we update the iterator. | 1789 // this. It stays on the stack while we update the iterator. |
1790 VisitForStackValue(expr->expression()); | 1790 VisitForStackValue(expr->expression()); |
1791 | 1791 |
1792 switch (expr->yield_kind()) { | 1792 Label suspend, continuation, post_runtime, resume; |
1793 case Yield::kSuspend: | |
1794 // Pop value from top-of-stack slot; box result into result register. | |
1795 EmitCreateIteratorResult(false); | |
1796 PushOperand(result_register()); | |
1797 // Fall through. | |
1798 case Yield::kInitial: { | |
1799 Label suspend, continuation, post_runtime, resume; | |
1800 | 1793 |
1801 __ jmp(&suspend); | 1794 __ jmp(&suspend); |
1802 __ bind(&continuation); | 1795 __ bind(&continuation); |
1803 // When we arrive here, the stack top is the resume mode and | 1796 // When we arrive here, the stack top is the resume mode and |
1804 // result_register() holds the input value (the argument given to the | 1797 // result_register() holds the input value (the argument given to the |
1805 // respective resume operation). | 1798 // respective resume operation). |
1806 __ RecordGeneratorContinuation(); | 1799 __ RecordGeneratorContinuation(); |
1807 __ Pop(rbx); | 1800 __ Pop(rbx); |
1808 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN)); | 1801 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN)); |
1809 __ j(not_equal, &resume); | 1802 __ j(not_equal, &resume); |
1810 __ Push(result_register()); | 1803 __ Push(result_register()); |
1811 EmitCreateIteratorResult(true); | 1804 EmitCreateIteratorResult(true); |
1812 EmitUnwindAndReturn(); | 1805 EmitUnwindAndReturn(); |
1813 | 1806 |
1814 __ bind(&suspend); | 1807 __ bind(&suspend); |
1815 OperandStackDepthIncrement(1); // Not popped on this path. | 1808 OperandStackDepthIncrement(1); // Not popped on this path. |
1816 VisitForAccumulatorValue(expr->generator_object()); | 1809 VisitForAccumulatorValue(expr->generator_object()); |
1817 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | 1810 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
1818 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), | 1811 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
1819 Smi::FromInt(continuation.pos())); | 1812 Smi::FromInt(continuation.pos())); |
1820 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); | 1813 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
1821 __ movp(rcx, rsi); | 1814 __ movp(rcx, rsi); |
1822 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, | 1815 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
1823 kDontSaveFPRegs); | 1816 kDontSaveFPRegs); |
1824 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); | 1817 __ leap(rbx, Operand(rbp, StandardFrameConstants::kExpressionsOffset)); |
1825 __ cmpp(rsp, rbx); | 1818 __ cmpp(rsp, rbx); |
1826 __ j(equal, &post_runtime); | 1819 __ j(equal, &post_runtime); |
1827 __ Push(rax); // generator object | 1820 __ Push(rax); // generator object |
1828 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1821 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1829 __ movp(context_register(), | 1822 __ movp(context_register(), |
1830 Operand(rbp, StandardFrameConstants::kContextOffset)); | 1823 Operand(rbp, StandardFrameConstants::kContextOffset)); |
1831 __ bind(&post_runtime); | 1824 __ bind(&post_runtime); |
1832 | 1825 |
1833 PopOperand(result_register()); | 1826 PopOperand(result_register()); |
1834 EmitReturnSequence(); | 1827 EmitReturnSequence(); |
1835 | 1828 |
1836 __ bind(&resume); | 1829 __ bind(&resume); |
1837 context()->Plug(result_register()); | 1830 context()->Plug(result_register()); |
1838 break; | |
1839 } | |
1840 | |
1841 case Yield::kFinal: { | |
1842 // Pop value from top-of-stack slot, box result into result register. | |
1843 EmitCreateIteratorResult(true); | |
1844 EmitUnwindAndReturn(); | |
1845 break; | |
1846 } | |
1847 | |
1848 case Yield::kDelegating: | |
1849 UNREACHABLE(); | |
1850 } | |
1851 } | 1831 } |
1852 | 1832 |
1853 | 1833 |
1854 void FullCodeGenerator::EmitGeneratorResume( | 1834 void FullCodeGenerator::EmitGeneratorResume( |
1855 Expression* generator, Expression* value, | 1835 Expression* generator, Expression* value, |
1856 JSGeneratorObject::ResumeMode resume_mode) { | 1836 JSGeneratorObject::ResumeMode resume_mode) { |
1857 // The value stays in rax, and is ultimately read by the resumed generator, as | 1837 // The value stays in rax, and is ultimately read by the resumed generator, as |
1858 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 1838 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
1859 // is read to throw the value when the resumed generator is already closed. | 1839 // is read to throw the value when the resumed generator is already closed. |
1860 // rbx will hold the generator object until the activation has been resumed. | 1840 // rbx will hold the generator object until the activation has been resumed. |
(...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4070 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 4050 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
4071 Assembler::target_address_at(call_target_address, | 4051 Assembler::target_address_at(call_target_address, |
4072 unoptimized_code)); | 4052 unoptimized_code)); |
4073 return OSR_AFTER_STACK_CHECK; | 4053 return OSR_AFTER_STACK_CHECK; |
4074 } | 4054 } |
4075 | 4055 |
4076 } // namespace internal | 4056 } // namespace internal |
4077 } // namespace v8 | 4057 } // namespace v8 |
4078 | 4058 |
4079 #endif // V8_TARGET_ARCH_X64 | 4059 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |