| 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 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
| (...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1808 __ CallStub(&stub); | 1808 __ CallStub(&stub); |
| 1809 } | 1809 } |
| 1810 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); | 1810 PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
| 1811 | 1811 |
| 1812 bool result_saved = false; // Is the result saved to the stack? | 1812 bool result_saved = false; // Is the result saved to the stack? |
| 1813 ZoneList<Expression*>* subexprs = expr->values(); | 1813 ZoneList<Expression*>* subexprs = expr->values(); |
| 1814 int length = subexprs->length(); | 1814 int length = subexprs->length(); |
| 1815 | 1815 |
| 1816 // Emit code to evaluate all the non-constant subexpressions and to store | 1816 // Emit code to evaluate all the non-constant subexpressions and to store |
| 1817 // them into the newly cloned array. | 1817 // them into the newly cloned array. |
| 1818 for (int i = 0; i < length; i++) { | 1818 int array_index = 0; |
| 1819 Expression* subexpr = subexprs->at(i); | 1819 for (; array_index < length; array_index++) { |
| 1820 Expression* subexpr = subexprs->at(array_index); |
| 1821 if (subexpr->IsSpread()) break; |
| 1822 |
| 1820 // If the subexpression is a literal or a simple materialized literal it | 1823 // If the subexpression is a literal or a simple materialized literal it |
| 1821 // is already set in the cloned array. | 1824 // is already set in the cloned array. |
| 1822 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; | 1825 if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
| 1823 | 1826 |
| 1824 if (!result_saved) { | 1827 if (!result_saved) { |
| 1825 __ push(eax); // array literal. | 1828 __ push(eax); // array literal. |
| 1826 __ push(Immediate(Smi::FromInt(expr->literal_index()))); | 1829 __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1827 result_saved = true; | 1830 result_saved = true; |
| 1828 } | 1831 } |
| 1829 VisitForAccumulatorValue(subexpr); | 1832 VisitForAccumulatorValue(subexpr); |
| 1830 | 1833 |
| 1831 if (has_constant_fast_elements) { | 1834 if (has_constant_fast_elements) { |
| 1832 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they | 1835 // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1833 // cannot transition and don't need to call the runtime stub. | 1836 // cannot transition and don't need to call the runtime stub. |
| 1834 int offset = FixedArray::kHeaderSize + (i * kPointerSize); | 1837 int offset = FixedArray::kHeaderSize + (array_index * kPointerSize); |
| 1835 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. | 1838 __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
| 1836 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); | 1839 __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1837 // Store the subexpression value in the array's elements. | 1840 // Store the subexpression value in the array's elements. |
| 1838 __ mov(FieldOperand(ebx, offset), result_register()); | 1841 __ mov(FieldOperand(ebx, offset), result_register()); |
| 1839 // Update the write barrier for the array store. | 1842 // Update the write barrier for the array store. |
| 1840 __ RecordWriteField(ebx, offset, result_register(), ecx, | 1843 __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1841 kDontSaveFPRegs, | 1844 kDontSaveFPRegs, |
| 1842 EMIT_REMEMBERED_SET, | 1845 EMIT_REMEMBERED_SET, |
| 1843 INLINE_SMI_CHECK); | 1846 INLINE_SMI_CHECK); |
| 1844 } else { | 1847 } else { |
| 1845 // Store the subexpression value in the array's elements. | 1848 // Store the subexpression value in the array's elements. |
| 1846 __ mov(ecx, Immediate(Smi::FromInt(i))); | 1849 __ mov(ecx, Immediate(Smi::FromInt(array_index))); |
| 1847 StoreArrayLiteralElementStub stub(isolate()); | 1850 StoreArrayLiteralElementStub stub(isolate()); |
| 1848 __ CallStub(&stub); | 1851 __ CallStub(&stub); |
| 1849 } | 1852 } |
| 1850 | 1853 |
| 1851 PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); | 1854 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); |
| 1855 } |
| 1856 |
| 1857 // In case the array literal contains spread expressions it has two parts. The |
| 1858 // first part is the "static" array which has a literal index is handled |
| 1859 // above. The second part is the part after the first spread expression |
| 1860 // (inclusive) and these elements gets appended to the array. Note that the |
| 1861 // number elements an iterable produces is unknown ahead of time. |
| 1862 if (array_index < length && result_saved) { |
| 1863 __ Drop(1); // literal index |
| 1864 __ Pop(eax); |
| 1865 result_saved = false; |
| 1866 } |
| 1867 for (; array_index < length; array_index++) { |
| 1868 Expression* subexpr = subexprs->at(array_index); |
| 1869 |
| 1870 __ Push(eax); |
| 1871 if (subexpr->IsSpread()) { |
| 1872 VisitForStackValue(subexpr->AsSpread()->expression()); |
| 1873 __ InvokeBuiltin(Builtins::CONCAT_ITERABLE_TO_ARRAY, CALL_FUNCTION); |
| 1874 } else { |
| 1875 VisitForStackValue(subexpr); |
| 1876 __ CallRuntime(Runtime::kAppendElement, 2); |
| 1877 } |
| 1878 |
| 1879 PrepareForBailoutForId(expr->GetIdForElement(array_index), NO_REGISTERS); |
| 1852 } | 1880 } |
| 1853 | 1881 |
| 1854 if (result_saved) { | 1882 if (result_saved) { |
| 1855 __ add(esp, Immediate(kPointerSize)); // literal index | 1883 __ Drop(1); // literal index |
| 1856 context()->PlugTOS(); | 1884 context()->PlugTOS(); |
| 1857 } else { | 1885 } else { |
| 1858 context()->Plug(eax); | 1886 context()->Plug(eax); |
| 1859 } | 1887 } |
| 1860 } | 1888 } |
| 1861 | 1889 |
| 1862 | 1890 |
| 1863 void FullCodeGenerator::VisitAssignment(Assignment* expr) { | 1891 void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1864 DCHECK(expr->target()->IsValidReferenceExpression()); | 1892 DCHECK(expr->target()->IsValidReferenceExpression()); |
| 1865 | 1893 |
| (...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5349 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5377 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5350 Assembler::target_address_at(call_target_address, | 5378 Assembler::target_address_at(call_target_address, |
| 5351 unoptimized_code)); | 5379 unoptimized_code)); |
| 5352 return OSR_AFTER_STACK_CHECK; | 5380 return OSR_AFTER_STACK_CHECK; |
| 5353 } | 5381 } |
| 5354 | 5382 |
| 5355 | 5383 |
| 5356 } } // namespace v8::internal | 5384 } } // namespace v8::internal |
| 5357 | 5385 |
| 5358 #endif // V8_TARGET_ARCH_IA32 | 5386 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |