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 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1885 } | 1885 } |
1886 | 1886 |
1887 case Yield::kFinal: { | 1887 case Yield::kFinal: { |
1888 // Pop value from top-of-stack slot, box result into result register. | 1888 // Pop value from top-of-stack slot, box result into result register. |
1889 EmitCreateIteratorResult(true); | 1889 EmitCreateIteratorResult(true); |
1890 EmitUnwindBeforeReturn(); | 1890 EmitUnwindBeforeReturn(); |
1891 EmitReturnSequence(); | 1891 EmitReturnSequence(); |
1892 break; | 1892 break; |
1893 } | 1893 } |
1894 | 1894 |
1895 case Yield::kDelegating: { | 1895 case Yield::kDelegating: |
1896 VisitForStackValue(expr->generator_object()); | 1896 UNREACHABLE(); |
1897 | |
1898 // Initial stack layout is as follows: | |
1899 // [sp + 1 * kPointerSize] iter | |
1900 // [sp + 0 * kPointerSize] g | |
1901 | |
1902 Label l_catch, l_try, l_suspend, l_continuation, l_resume; | |
1903 Label l_next, l_call, l_loop; | |
1904 Register load_receiver = LoadDescriptor::ReceiverRegister(); | |
1905 Register load_name = LoadDescriptor::NameRegister(); | |
1906 | |
1907 // Initial send value is undefined. | |
1908 __ mov(eax, isolate()->factory()->undefined_value()); | |
1909 __ jmp(&l_next); | |
1910 | |
1911 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | |
1912 __ bind(&l_catch); | |
1913 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" | |
1914 __ push(load_name); // "throw" | |
1915 __ push(Operand(esp, 2 * kPointerSize)); // iter | |
1916 __ push(eax); // exception | |
1917 __ jmp(&l_call); | |
1918 | |
1919 // try { received = %yield result } | |
1920 // Shuffle the received result above a try handler and yield it without | |
1921 // re-boxing. | |
1922 __ bind(&l_try); | |
1923 __ pop(eax); // result | |
1924 int handler_index = NewHandlerTableEntry(); | |
1925 EnterTryBlock(handler_index, &l_catch); | |
1926 const int try_block_size = TryCatch::kElementCount * kPointerSize; | |
1927 __ push(eax); // result | |
1928 | |
1929 __ jmp(&l_suspend); | |
1930 __ bind(&l_continuation); | |
1931 __ RecordGeneratorContinuation(); | |
1932 __ jmp(&l_resume); | |
1933 | |
1934 __ bind(&l_suspend); | |
1935 const int generator_object_depth = kPointerSize + try_block_size; | |
1936 __ mov(eax, Operand(esp, generator_object_depth)); | |
1937 __ push(eax); // g | |
1938 __ push(Immediate(Smi::FromInt(handler_index))); // handler-index | |
1939 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | |
1940 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | |
1941 Immediate(Smi::FromInt(l_continuation.pos()))); | |
1942 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | |
1943 __ mov(ecx, esi); | |
1944 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | |
1945 kDontSaveFPRegs); | |
1946 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); | |
1947 __ mov(context_register(), | |
1948 Operand(ebp, StandardFrameConstants::kContextOffset)); | |
1949 __ pop(eax); // result | |
1950 EmitReturnSequence(); | |
1951 __ bind(&l_resume); // received in eax | |
1952 ExitTryBlock(handler_index); | |
1953 | |
1954 // receiver = iter; f = iter.next; arg = received; | |
1955 __ bind(&l_next); | |
1956 | |
1957 __ mov(load_name, isolate()->factory()->next_string()); | |
1958 __ push(load_name); // "next" | |
1959 __ push(Operand(esp, 2 * kPointerSize)); // iter | |
1960 __ push(eax); // received | |
1961 | |
1962 // result = receiver[f](arg); | |
1963 __ bind(&l_call); | |
1964 __ mov(load_receiver, Operand(esp, kPointerSize)); | |
1965 __ mov(LoadDescriptor::SlotRegister(), | |
1966 Immediate(SmiFromSlot(expr->KeyedLoadFeedbackSlot()))); | |
1967 Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate(), SLOPPY).code(); | |
1968 CallIC(ic, TypeFeedbackId::None()); | |
1969 __ mov(edi, eax); | |
1970 __ mov(Operand(esp, 2 * kPointerSize), edi); | |
1971 SetCallPosition(expr); | |
1972 __ Set(eax, 1); | |
1973 __ Call( | |
1974 isolate()->builtins()->Call(ConvertReceiverMode::kNotNullOrUndefined), | |
1975 RelocInfo::CODE_TARGET); | |
1976 | |
1977 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
1978 __ Drop(1); // The function is still on the stack; drop it. | |
1979 | |
1980 // if (!result.done) goto l_try; | |
1981 __ bind(&l_loop); | |
1982 __ push(eax); // save result | |
1983 __ Move(load_receiver, eax); // result | |
1984 __ mov(load_name, | |
1985 isolate()->factory()->done_string()); // "done" | |
1986 __ mov(LoadDescriptor::SlotRegister(), | |
1987 Immediate(SmiFromSlot(expr->DoneFeedbackSlot()))); | |
1988 CallLoadIC(NOT_INSIDE_TYPEOF); // result.done in eax | |
1989 Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); | |
1990 CallIC(bool_ic); | |
1991 __ CompareRoot(result_register(), Heap::kTrueValueRootIndex); | |
1992 __ j(not_equal, &l_try); | |
1993 | |
1994 // result.value | |
1995 __ pop(load_receiver); // result | |
1996 __ mov(load_name, | |
1997 isolate()->factory()->value_string()); // "value" | |
1998 __ mov(LoadDescriptor::SlotRegister(), | |
1999 Immediate(SmiFromSlot(expr->ValueFeedbackSlot()))); | |
2000 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in eax | |
2001 context()->DropAndPlug(2, eax); // drop iter and g | |
2002 break; | |
2003 } | |
2004 } | 1897 } |
2005 } | 1898 } |
2006 | 1899 |
2007 | 1900 |
2008 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 1901 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
2009 Expression *value, | 1902 Expression *value, |
2010 JSGeneratorObject::ResumeMode resume_mode) { | 1903 JSGeneratorObject::ResumeMode resume_mode) { |
2011 // The value stays in eax, and is ultimately read by the resumed generator, as | 1904 // The value stays in eax, and is ultimately read by the resumed generator, as |
2012 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it | 1905 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
2013 // is read to throw the value when the resumed generator is already closed. | 1906 // is read to throw the value when the resumed generator is already closed. |
(...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4721 Assembler::target_address_at(call_target_address, | 4614 Assembler::target_address_at(call_target_address, |
4722 unoptimized_code)); | 4615 unoptimized_code)); |
4723 return OSR_AFTER_STACK_CHECK; | 4616 return OSR_AFTER_STACK_CHECK; |
4724 } | 4617 } |
4725 | 4618 |
4726 | 4619 |
4727 } // namespace internal | 4620 } // namespace internal |
4728 } // namespace v8 | 4621 } // namespace v8 |
4729 | 4622 |
4730 #endif // V8_TARGET_ARCH_IA32 | 4623 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |