Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Unified Diff: src/full-codegen/ia32/full-codegen-ia32.cc

Issue 1865833002: [generators] Decouple generator resume from fullcodegen. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/full-codegen/ia32/full-codegen-ia32.cc
diff --git a/src/full-codegen/ia32/full-codegen-ia32.cc b/src/full-codegen/ia32/full-codegen-ia32.cc
index 4dfe902386654a2a3267de1d9f0b59a9e0f0a43b..101e0c336a0335cb7ee8dd23455dc77718ccd076 100644
--- a/src/full-codegen/ia32/full-codegen-ia32.cc
+++ b/src/full-codegen/ia32/full-codegen-ia32.cc
@@ -1756,7 +1756,7 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
// this. It stays on the stack while we update the iterator.
VisitForStackValue(expr->expression());
- Label suspend, continuation, post_runtime, resume;
+ Label suspend, continuation, post_runtime, resume, exception;
__ jmp(&suspend);
__ bind(&continuation);
@@ -1765,12 +1765,18 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
// respective resume operation).
__ RecordGeneratorContinuation();
__ pop(ebx);
- __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::RETURN)));
- __ j(not_equal, &resume);
- __ push(result_register());
+ STATIC_ASSERT(JSGeneratorObject::kNext < JSGeneratorObject::kReturn);
+ STATIC_ASSERT(JSGeneratorObject::kThrow > JSGeneratorObject::kReturn);
+ __ cmp(ebx, Immediate(Smi::FromInt(JSGeneratorObject::kReturn)));
+ __ j(less, &resume);
+ __ Push(result_register());
+ __ j(greater, &exception);
EmitCreateIteratorResult(true);
EmitUnwindAndReturn();
+ __ bind(&exception);
+ __ CallRuntime(Runtime::kThrow);
+
__ bind(&suspend);
OperandStackDepthIncrement(1); // Not popped on this path.
VisitForAccumulatorValue(expr->generator_object());
@@ -1796,101 +1802,6 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
context()->Plug(result_register());
}
-
-void FullCodeGenerator::EmitGeneratorResume(Expression *generator,
- Expression *value,
- JSGeneratorObject::ResumeMode resume_mode) {
- // The value stays in eax, and is ultimately read by the resumed generator, as
- // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
- // is read to throw the value when the resumed generator is already closed.
- // ebx will hold the generator object until the activation has been resumed.
- VisitForStackValue(generator);
- VisitForAccumulatorValue(value);
- PopOperand(ebx);
-
- // Store input value into generator object.
- __ mov(FieldOperand(ebx, JSGeneratorObject::kInputOffset), result_register());
- __ mov(ecx, result_register());
- __ RecordWriteField(ebx, JSGeneratorObject::kInputOffset, ecx, edx,
- kDontSaveFPRegs);
-
- // Load suspended function and context.
- __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset));
- __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset));
-
- // Push receiver.
- __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset));
-
- // Push holes for arguments to generator function. Since the parser forced
- // context allocation for any variables in generators, the actual argument
- // values have already been copied into the context and these dummy values
- // will never be used.
- __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
- __ mov(edx,
- FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset));
- __ mov(ecx, isolate()->factory()->the_hole_value());
- Label push_argument_holes, push_frame;
- __ bind(&push_argument_holes);
- __ sub(edx, Immediate(Smi::FromInt(1)));
- __ j(carry, &push_frame);
- __ push(ecx);
- __ jmp(&push_argument_holes);
-
- // Enter a new JavaScript frame, and initialize its slots as they were when
- // the generator was suspended.
- Label resume_frame, done;
- __ bind(&push_frame);
- __ call(&resume_frame);
- __ jmp(&done);
- __ bind(&resume_frame);
- __ push(ebp); // Caller's frame pointer.
- __ mov(ebp, esp);
- __ push(esi); // Callee's context.
- __ push(edi); // Callee's JS Function.
-
- // Load the operand stack size.
- __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset));
- __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset));
- __ SmiUntag(edx);
-
- // If we are sending a value and there is no operand stack, we can jump back
- // in directly.
- if (resume_mode == JSGeneratorObject::NEXT) {
- Label slow_resume;
- __ cmp(edx, Immediate(0));
- __ j(not_zero, &slow_resume);
- __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset));
- __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset));
- __ SmiUntag(ecx);
- __ add(edx, ecx);
- __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset),
- Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)));
- __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
- __ jmp(edx);
- __ bind(&slow_resume);
- }
-
- // Otherwise, we push holes for the operand stack and call the runtime to fix
- // up the stack and the handlers.
- Label push_operand_holes, call_resume;
- __ bind(&push_operand_holes);
- __ sub(edx, Immediate(1));
- __ j(carry, &call_resume);
- __ push(ecx);
- __ jmp(&push_operand_holes);
- __ bind(&call_resume);
- __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
- __ push(ebx);
- __ push(result_register());
- __ Push(Smi::FromInt(resume_mode));
- __ CallRuntime(Runtime::kResumeJSGeneratorObject);
- // Not reached: the runtime call returns elsewhere.
- __ Abort(kGeneratorFailedToResume);
-
- __ bind(&done);
- context()->Plug(result_register());
-}
-
void FullCodeGenerator::PushOperand(MemOperand operand) {
OperandStackDepthIncrement(1);
__ Push(operand);

Powered by Google App Engine
This is Rietveld 408576698