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 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 | 1749 |
1750 | 1750 |
1751 void FullCodeGenerator::VisitYield(Yield* expr) { | 1751 void FullCodeGenerator::VisitYield(Yield* expr) { |
1752 Comment cmnt(masm_, "[ Yield"); | 1752 Comment cmnt(masm_, "[ Yield"); |
1753 SetExpressionPosition(expr); | 1753 SetExpressionPosition(expr); |
1754 | 1754 |
1755 // Evaluate yielded value first; the initial iterator definition depends on | 1755 // Evaluate yielded value first; the initial iterator definition depends on |
1756 // this. It stays on the stack while we update the iterator. | 1756 // this. It stays on the stack while we update the iterator. |
1757 VisitForStackValue(expr->expression()); | 1757 VisitForStackValue(expr->expression()); |
1758 | 1758 |
1759 Label suspend, continuation, post_runtime, resume; | 1759 Label suspend, continuation, post_runtime, resume, exception; |
1760 | 1760 |
1761 __ jmp(&suspend); | 1761 __ jmp(&suspend); |
1762 __ bind(&continuation); | 1762 __ bind(&continuation); |
1763 // When we arrive here, the stack top is the resume mode and | 1763 // When we arrive here, the stack top is the resume mode and |
1764 // result_register() holds the input value (the argument given to the | 1764 // result_register() holds the input value (the argument given to the |
1765 // respective resume operation). | 1765 // respective resume operation). |
1766 __ RecordGeneratorContinuation(); | 1766 __ RecordGeneratorContinuation(); |
1767 __ pop(ebx); | 1767 __ pop(ebx); |
1768 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN))); | 1768 STATIC_ASSERT(JSGeneratorObject::kNext < JSGeneratorObject::kReturn); |
1769 __ j(not_equal, &resume); | 1769 STATIC_ASSERT(JSGeneratorObject::kThrow > JSGeneratorObject::kReturn); |
1770 __ push(result_register()); | 1770 __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::kReturn))); |
| 1771 __ j(less, &resume); |
| 1772 __ Push(result_register()); |
| 1773 __ j(greater, &exception); |
1771 EmitCreateIteratorResult(true); | 1774 EmitCreateIteratorResult(true); |
1772 EmitUnwindAndReturn(); | 1775 EmitUnwindAndReturn(); |
1773 | 1776 |
| 1777 __ bind(&exception); |
| 1778 __ CallRuntime(Runtime::kThrow); |
| 1779 |
1774 __ bind(&suspend); | 1780 __ bind(&suspend); |
1775 OperandStackDepthIncrement(1); // Not popped on this path. | 1781 OperandStackDepthIncrement(1); // Not popped on this path. |
1776 VisitForAccumulatorValue(expr->generator_object()); | 1782 VisitForAccumulatorValue(expr->generator_object()); |
1777 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); | 1783 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
1778 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | 1784 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
1779 Immediate(Smi::FromInt(continuation.pos()))); | 1785 Immediate(Smi::FromInt(continuation.pos()))); |
1780 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | 1786 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
1781 __ mov(ecx, esi); | 1787 __ mov(ecx, esi); |
1782 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | 1788 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
1783 kDontSaveFPRegs); | 1789 kDontSaveFPRegs); |
1784 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); | 1790 __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
1785 __ cmp(esp, ebx); | 1791 __ cmp(esp, ebx); |
1786 __ j(equal, &post_runtime); | 1792 __ j(equal, &post_runtime); |
1787 __ push(eax); // generator object | 1793 __ push(eax); // generator object |
1788 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1794 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1789 __ mov(context_register(), | 1795 __ mov(context_register(), |
1790 Operand(ebp, StandardFrameConstants::kContextOffset)); | 1796 Operand(ebp, StandardFrameConstants::kContextOffset)); |
1791 __ bind(&post_runtime); | 1797 __ bind(&post_runtime); |
1792 PopOperand(result_register()); | 1798 PopOperand(result_register()); |
1793 EmitReturnSequence(); | 1799 EmitReturnSequence(); |
1794 | 1800 |
1795 __ bind(&resume); | 1801 __ bind(&resume); |
1796 context()->Plug(result_register()); | 1802 context()->Plug(result_register()); |
1797 } | 1803 } |
1798 | 1804 |
1799 | |
1800 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | |
1801 Expression *value, | |
1802 JSGeneratorObject::ResumeMode resume_mode) { | |
1803 // The value stays in eax, and is ultimately read by the resumed generator, as | |
1804 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | |
1805 // is read to throw the value when the resumed generator is already closed. | |
1806 // ebx will hold the generator object until the activation has been resumed. | |
1807 VisitForStackValue(generator); | |
1808 VisitForAccumulatorValue(value); | |
1809 PopOperand(ebx); | |
1810 | |
1811 // Store input value into generator object. | |
1812 __ mov(FieldOperand(ebx, JSGeneratorObject::kInputOffset), result_register()); | |
1813 __ mov(ecx, result_register()); | |
1814 __ RecordWriteField(ebx, JSGeneratorObject::kInputOffset, ecx, edx, | |
1815 kDontSaveFPRegs); | |
1816 | |
1817 // Load suspended function and context. | |
1818 __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); | |
1819 __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); | |
1820 | |
1821 // Push receiver. | |
1822 __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); | |
1823 | |
1824 // Push holes for arguments to generator function. Since the parser forced | |
1825 // context allocation for any variables in generators, the actual argument | |
1826 // values have already been copied into the context and these dummy values | |
1827 // will never be used. | |
1828 __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | |
1829 __ mov(edx, | |
1830 FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); | |
1831 __ mov(ecx, isolate()->factory()->the_hole_value()); | |
1832 Label push_argument_holes, push_frame; | |
1833 __ bind(&push_argument_holes); | |
1834 __ sub(edx, Immediate(Smi::FromInt(1))); | |
1835 __ j(carry, &push_frame); | |
1836 __ push(ecx); | |
1837 __ jmp(&push_argument_holes); | |
1838 | |
1839 // Enter a new JavaScript frame, and initialize its slots as they were when | |
1840 // the generator was suspended. | |
1841 Label resume_frame, done; | |
1842 __ bind(&push_frame); | |
1843 __ call(&resume_frame); | |
1844 __ jmp(&done); | |
1845 __ bind(&resume_frame); | |
1846 __ push(ebp); // Caller's frame pointer. | |
1847 __ mov(ebp, esp); | |
1848 __ push(esi); // Callee's context. | |
1849 __ push(edi); // Callee's JS Function. | |
1850 | |
1851 // Load the operand stack size. | |
1852 __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); | |
1853 __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); | |
1854 __ SmiUntag(edx); | |
1855 | |
1856 // If we are sending a value and there is no operand stack, we can jump back | |
1857 // in directly. | |
1858 if (resume_mode == JSGeneratorObject::NEXT) { | |
1859 Label slow_resume; | |
1860 __ cmp(edx, Immediate(0)); | |
1861 __ j(not_zero, &slow_resume); | |
1862 __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); | |
1863 __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); | |
1864 __ SmiUntag(ecx); | |
1865 __ add(edx, ecx); | |
1866 __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), | |
1867 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); | |
1868 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. | |
1869 __ jmp(edx); | |
1870 __ bind(&slow_resume); | |
1871 } | |
1872 | |
1873 // Otherwise, we push holes for the operand stack and call the runtime to fix | |
1874 // up the stack and the handlers. | |
1875 Label push_operand_holes, call_resume; | |
1876 __ bind(&push_operand_holes); | |
1877 __ sub(edx, Immediate(1)); | |
1878 __ j(carry, &call_resume); | |
1879 __ push(ecx); | |
1880 __ jmp(&push_operand_holes); | |
1881 __ bind(&call_resume); | |
1882 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation. | |
1883 __ push(ebx); | |
1884 __ push(result_register()); | |
1885 __ Push(Smi::FromInt(resume_mode)); | |
1886 __ CallRuntime(Runtime::kResumeJSGeneratorObject); | |
1887 // Not reached: the runtime call returns elsewhere. | |
1888 __ Abort(kGeneratorFailedToResume); | |
1889 | |
1890 __ bind(&done); | |
1891 context()->Plug(result_register()); | |
1892 } | |
1893 | |
1894 void FullCodeGenerator::PushOperand(MemOperand operand) { | 1805 void FullCodeGenerator::PushOperand(MemOperand operand) { |
1895 OperandStackDepthIncrement(1); | 1806 OperandStackDepthIncrement(1); |
1896 __ Push(operand); | 1807 __ Push(operand); |
1897 } | 1808 } |
1898 | 1809 |
1899 void FullCodeGenerator::EmitOperandStackDepthCheck() { | 1810 void FullCodeGenerator::EmitOperandStackDepthCheck() { |
1900 if (FLAG_debug_code) { | 1811 if (FLAG_debug_code) { |
1901 int expected_diff = StandardFrameConstants::kFixedFrameSizeFromFp + | 1812 int expected_diff = StandardFrameConstants::kFixedFrameSizeFromFp + |
1902 operand_stack_depth_ * kPointerSize; | 1813 operand_stack_depth_ * kPointerSize; |
1903 __ mov(eax, ebp); | 1814 __ mov(eax, ebp); |
(...skipping 2081 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3985 isolate->builtins()->OnStackReplacement()->entry(), | 3896 isolate->builtins()->OnStackReplacement()->entry(), |
3986 Assembler::target_address_at(call_target_address, unoptimized_code)); | 3897 Assembler::target_address_at(call_target_address, unoptimized_code)); |
3987 return ON_STACK_REPLACEMENT; | 3898 return ON_STACK_REPLACEMENT; |
3988 } | 3899 } |
3989 | 3900 |
3990 | 3901 |
3991 } // namespace internal | 3902 } // namespace internal |
3992 } // namespace v8 | 3903 } // namespace v8 |
3993 | 3904 |
3994 #endif // V8_TARGET_ARCH_IA32 | 3905 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |