Commit 172ecd61 authored by mbrandy's avatar mbrandy Committed by Commit bot

PPC: [es6] Super call in arrows and eval

Port 4b8051a0

Original commit message:
This splits the SuperReference AST node into SuperPropertyReference and
SuperCallReference. The super call reference node consists of three
unresolved vars to this, new.target and this_function. These gets
declared when the right function is entered and if it is in use. The
variables gets assigned in FullCodeGenerator::Generate.

This is a revert of the revert 88b1c917

R=arv@chromium.org, dstence@us.ibm.com, michael_dawson@ca.ibm.com
BUG=

Review URL: https://codereview.chromium.org/1146403010

Cr-Commit-Position: refs/heads/master@{#28791}
parent 405844b5
......@@ -252,6 +252,24 @@ void FullCodeGenerator::Generate() {
__ Push(r4);
}
// Possibly set up a local binding to the this function which is used in
// derived constructors with super calls.
Variable* this_function_var = scope()->this_function_var();
if (this_function_var != nullptr) {
Comment cmnt(masm_, "[ This function");
SetVar(this_function_var, r4, r3, r5);
}
Variable* new_target_var = scope()->new_target_var();
if (new_target_var != nullptr) {
Comment cmnt(masm_, "[ new.target");
// new.target is parameter -2.
int offset = 2 * kPointerSize +
(info_->scope()->num_parameters() + 1) * kPointerSize;
__ LoadP(r3, MemOperand(fp, offset));
SetVar(new_target_var, r3, r5, r6);
}
ArgumentsAccessStub::HasNewTarget has_new_target =
IsSubclassConstructor(info->function()->kind())
? ArgumentsAccessStub::HAS_NEW_TARGET
......@@ -1955,9 +1973,10 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
}
break;
case NAMED_SUPER_PROPERTY:
VisitForStackValue(property->obj()->AsSuperReference()->this_var());
VisitForStackValue(
property->obj()->AsSuperPropertyReference()->this_var());
VisitForAccumulatorValue(
property->obj()->AsSuperReference()->home_object_var());
property->obj()->AsSuperPropertyReference()->home_object_var());
__ Push(result_register());
if (expr->is_compound()) {
const Register scratch = r4;
......@@ -1967,9 +1986,10 @@ void FullCodeGenerator::VisitAssignment(Assignment* expr) {
break;
case KEYED_SUPER_PROPERTY: {
const Register scratch = r4;
VisitForStackValue(property->obj()->AsSuperReference()->this_var());
VisitForStackValue(
property->obj()->AsSuperPropertyReference()->this_var());
VisitForAccumulatorValue(
property->obj()->AsSuperReference()->home_object_var());
property->obj()->AsSuperPropertyReference()->home_object_var());
__ mr(scratch, result_register());
VisitForAccumulatorValue(property->key());
__ Push(scratch, result_register());
......@@ -2648,9 +2668,9 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
}
case NAMED_SUPER_PROPERTY: {
__ Push(r3);
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
VisitForAccumulatorValue(
prop->obj()->AsSuperReference()->home_object_var());
prop->obj()->AsSuperPropertyReference()->home_object_var());
// stack: value, this; r3: home_object
Register scratch = r5;
Register scratch2 = r6;
......@@ -2665,8 +2685,9 @@ void FullCodeGenerator::EmitAssignment(Expression* expr,
}
case KEYED_SUPER_PROPERTY: {
__ Push(r3);
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
VisitForStackValue(prop->obj()->AsSuperReference()->home_object_var());
VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
VisitForStackValue(
prop->obj()->AsSuperPropertyReference()->home_object_var());
VisitForAccumulatorValue(prop->key());
Register scratch = r5;
Register scratch2 = r6;
......@@ -2889,8 +2910,9 @@ void FullCodeGenerator::VisitProperty(Property* expr) {
__ Move(LoadDescriptor::ReceiverRegister(), r3);
EmitNamedPropertyLoad(expr);
} else {
VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
VisitForStackValue(expr->obj()->AsSuperReference()->home_object_var());
VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
VisitForStackValue(
expr->obj()->AsSuperPropertyReference()->home_object_var());
EmitNamedSuperPropertyLoad(expr);
}
} else {
......@@ -2901,8 +2923,9 @@ void FullCodeGenerator::VisitProperty(Property* expr) {
__ pop(LoadDescriptor::ReceiverRegister());
EmitKeyedPropertyLoad(expr);
} else {
VisitForStackValue(expr->obj()->AsSuperReference()->this_var());
VisitForStackValue(expr->obj()->AsSuperReference()->home_object_var());
VisitForStackValue(expr->obj()->AsSuperPropertyReference()->this_var());
VisitForStackValue(
expr->obj()->AsSuperPropertyReference()->home_object_var());
VisitForStackValue(expr->key());
EmitKeyedSuperPropertyLoad(expr);
}
......@@ -2964,7 +2987,7 @@ void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) {
DCHECK(!key->value()->IsSmi());
// Load the function from the receiver.
const Register scratch = r4;
SuperReference* super_ref = prop->obj()->AsSuperReference();
SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference();
VisitForAccumulatorValue(super_ref->home_object_var());
__ mr(scratch, r3);
VisitForAccumulatorValue(super_ref->this_var());
......@@ -3021,7 +3044,7 @@ void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) {
SetSourcePosition(prop->position());
// Load the function from the receiver.
const Register scratch = r4;
SuperReference* super_ref = prop->obj()->AsSuperReference();
SuperPropertyReference* super_ref = prop->obj()->AsSuperPropertyReference();
VisitForAccumulatorValue(super_ref->home_object_var());
__ mr(scratch, r3);
VisitForAccumulatorValue(super_ref->this_var());
......@@ -3101,15 +3124,8 @@ void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) {
}
void FullCodeGenerator::EmitLoadSuperConstructor() {
__ LoadP(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ Push(r3);
__ CallRuntime(Runtime::kGetPrototype, 1);
}
void FullCodeGenerator::EmitInitializeThisAfterSuper(
SuperReference* super_ref, FeedbackVectorICSlot slot) {
SuperCallReference* super_ref, FeedbackVectorICSlot slot) {
Variable* this_var = super_ref->this_var()->var();
GetVar(r4, this_var);
__ CompareRoot(r4, Heap::kTheHoleValueRootIndex);
......@@ -3272,7 +3288,7 @@ void FullCodeGenerator::VisitCallNew(CallNew* expr) {
// Push constructor on the stack. If it's not a function it's used as
// receiver for CALL_NON_FUNCTION, otherwise the value on the stack is
// ignored.
DCHECK(!expr->expression()->IsSuperReference());
DCHECK(!expr->expression()->IsSuperPropertyReference());
VisitForStackValue(expr->expression());
// Push the arguments ("left-to-right") on the stack.
......@@ -3308,11 +3324,14 @@ void FullCodeGenerator::VisitCallNew(CallNew* expr) {
void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
GetVar(result_register(), new_target_var);
__ Push(result_register());
SuperCallReference* super_call_ref =
expr->expression()->AsSuperCallReference();
DCHECK_NOT_NULL(super_call_ref);
VariableProxy* new_target_proxy = super_call_ref->new_target_var();
VisitForStackValue(new_target_proxy);
EmitLoadSuperConstructor();
EmitLoadSuperConstructor(super_call_ref);
__ push(result_register());
// Push the arguments ("left-to-right") on the stack.
......@@ -3350,8 +3369,7 @@ void FullCodeGenerator::EmitSuperConstructorCall(Call* expr) {
RecordJSReturnSite(expr);
EmitInitializeThisAfterSuper(expr->expression()->AsSuperReference(),
expr->CallFeedbackICSlot());
EmitInitializeThisAfterSuper(super_call_ref, expr->CallFeedbackICSlot());
context()->Plug(r3);
}
......@@ -4221,11 +4239,15 @@ void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) {
void FullCodeGenerator::EmitDefaultConstructorCallSuper(CallRuntime* expr) {
Variable* new_target_var = scope()->DeclarationScope()->new_target_var();
GetVar(result_register(), new_target_var);
__ Push(result_register());
ZoneList<Expression*>* args = expr->arguments();
DCHECK(args->length() == 2);
EmitLoadSuperConstructor();
// new.target
VisitForStackValue(args->at(0));
// .this_function
VisitForStackValue(args->at(1));
__ CallRuntime(Runtime::kGetPrototype, 1);
__ mr(r4, result_register());
__ Push(r4);
......@@ -4639,11 +4661,14 @@ void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) {
void FullCodeGenerator::EmitCallSuperWithSpread(CallRuntime* expr) {
// Assert: expr === CallRuntime("ReflectConstruct")
DCHECK_EQ(1, expr->arguments()->length());
CallRuntime* call = expr->arguments()->at(0)->AsCallRuntime();
ZoneList<Expression*>* args = call->arguments();
DCHECK_EQ(3, args->length());
SuperReference* super_reference = args->at(0)->AsSuperReference();
SuperCallReference* super_call_ref = args->at(0)->AsSuperCallReference();
DCHECK_NOT_NULL(super_call_ref);
// Load ReflectConstruct function
EmitLoadJSRuntimeFunction(call);
......@@ -4653,8 +4678,8 @@ void FullCodeGenerator::EmitCallSuperWithSpread(CallRuntime* expr) {
__ push(r0);
__ StoreP(r3, MemOperand(sp, kPointerSize));
// Push super
EmitLoadSuperConstructor();
// Push super constructor
EmitLoadSuperConstructor(super_call_ref);
__ Push(result_register());
// Push arguments array
......@@ -4671,7 +4696,7 @@ void FullCodeGenerator::EmitCallSuperWithSpread(CallRuntime* expr) {
context()->DropAndPlug(1, r3);
// TODO(mvstanton): with FLAG_vector_stores this needs a slot id.
EmitInitializeThisAfterSuper(super_reference);
EmitInitializeThisAfterSuper(super_call_ref);
}
......@@ -4892,9 +4917,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
case NAMED_SUPER_PROPERTY: {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
VisitForAccumulatorValue(
prop->obj()->AsSuperReference()->home_object_var());
prop->obj()->AsSuperPropertyReference()->home_object_var());
__ Push(result_register());
const Register scratch = r4;
__ LoadP(scratch, MemOperand(sp, kPointerSize));
......@@ -4904,9 +4929,9 @@ void FullCodeGenerator::VisitCountOperation(CountOperation* expr) {
}
case KEYED_SUPER_PROPERTY: {
VisitForStackValue(prop->obj()->AsSuperReference()->this_var());
VisitForStackValue(prop->obj()->AsSuperPropertyReference()->this_var());
VisitForAccumulatorValue(
prop->obj()->AsSuperReference()->home_object_var());
prop->obj()->AsSuperPropertyReference()->home_object_var());
const Register scratch = r4;
const Register scratch1 = r5;
__ mr(scratch, result_register());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment