Commit 3f6e5b30 authored by chunyang.dai's avatar chunyang.dai Committed by Commit bot

X87: [runtime] Add %ToString and %_ToString and remove the TO_STRING builtin.

port 09de997b (r30442).

original commit message:

    This adds a new ToString runtime function and a fast-path ToStringStub
    (which is just a simple dispatcher for existing functionality), and also
    implements %_ToName using the ToStringStub.

R=weiliang.lin@intel.com
BUG=

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

Cr-Commit-Position: refs/heads/master@{#30460}
parent 5f2d6ef6
......@@ -3833,6 +3833,40 @@ void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
}
void FullCodeGenerator::EmitToString(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
DCHECK_EQ(1, args->length());
// Load the argument into eax and convert it.
VisitForAccumulatorValue(args->at(0));
ToStringStub stub(isolate());
__ CallStub(&stub);
context()->Plug(eax);
}
void FullCodeGenerator::EmitToName(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
DCHECK_EQ(1, args->length());
// Load the argument into eax and convert it.
VisitForAccumulatorValue(args->at(0));
// Convert the object to a name.
Label convert, done_convert;
__ JumpIfSmi(eax, &convert, Label::kNear);
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
__ CmpObjectType(eax, LAST_NAME_TYPE, ecx);
__ j(below_equal, &done_convert, Label::kNear);
__ bind(&convert);
ToStringStub stub(isolate());
__ CallStub(&stub);
__ bind(&done_convert);
context()->Plug(eax);
}
void FullCodeGenerator::EmitToObject(CallRuntime* expr) {
ZoneList<Expression*>* args = expr->arguments();
DCHECK_EQ(1, args->length());
......
......@@ -1527,8 +1527,8 @@ void Builtins::Generate_StringConstructCode(MacroAssembler* masm) {
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ push(edi); // Preserve the function.
__ push(eax);
__ InvokeBuiltin(Context::TO_STRING_BUILTIN_INDEX, CALL_FUNCTION);
ToStringStub stub(masm->isolate());
__ CallStub(&stub);
__ pop(edi);
}
__ mov(ebx, eax);
......
......@@ -2985,6 +2985,41 @@ void ToNumberStub::Generate(MacroAssembler* masm) {
}
void ToStringStub::Generate(MacroAssembler* masm) {
// The ToString stub takes one argument in eax.
Label is_number;
__ JumpIfSmi(eax, &is_number, Label::kNear);
Label not_string;
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edi);
// eax: receiver
// edi: receiver map
__ j(above_equal, &not_string, Label::kNear);
__ Ret();
__ bind(&not_string);
Label not_heap_number;
__ CompareMap(eax, masm->isolate()->factory()->heap_number_map());
__ j(not_equal, &not_heap_number, Label::kNear);
__ bind(&is_number);
NumberToStringStub stub(isolate());
__ TailCallStub(&stub);
__ bind(&not_heap_number);
Label not_oddball;
__ CmpInstanceType(edi, ODDBALL_TYPE);
__ j(not_equal, &not_oddball, Label::kNear);
__ mov(eax, FieldOperand(eax, Oddball::kToStringOffset));
__ Ret();
__ bind(&not_oddball);
__ pop(ecx); // Pop return address.
__ push(eax); // Push argument.
__ push(ecx); // Push return address.
__ TailCallRuntime(Runtime::kToString, 1, 1);
}
void StringHelper::GenerateFlatOneByteStringEquals(MacroAssembler* masm,
Register left,
Register right,
......
......@@ -106,6 +106,10 @@ void ToNumberDescriptor::InitializePlatformSpecific(
}
// static
const Register ToStringDescriptor::ReceiverRegister() { return eax; }
// static
const Register ToObjectDescriptor::ReceiverRegister() { return eax; }
......
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