2010-01-27 14:07:12 +00:00
|
|
|
// Copyright 2010 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2010-05-17 15:41:35 +00:00
|
|
|
#if defined(V8_TARGET_ARCH_ARM)
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "bootstrapper.h"
|
2010-08-30 11:48:07 +00:00
|
|
|
#include "code-stubs.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "codegen-inl.h"
|
2009-11-04 17:59:24 +00:00
|
|
|
#include "compiler.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "debug.h"
|
2010-03-01 16:24:05 +00:00
|
|
|
#include "ic-inl.h"
|
2010-04-14 09:25:33 +00:00
|
|
|
#include "jsregexp.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "jump-target-inl.h"
|
2009-03-24 08:55:11 +00:00
|
|
|
#include "parser.h"
|
2010-04-14 09:25:33 +00:00
|
|
|
#include "regexp-macro-assembler.h"
|
|
|
|
#include "regexp-stack.h"
|
2009-03-20 12:58:14 +00:00
|
|
|
#include "register-allocator-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
#include "runtime.h"
|
2009-03-20 09:35:31 +00:00
|
|
|
#include "scopes.h"
|
2010-11-11 10:33:51 +00:00
|
|
|
#include "stub-cache.h"
|
2010-02-26 09:32:48 +00:00
|
|
|
#include "virtual-frame-inl.h"
|
2010-05-10 11:32:25 +00:00
|
|
|
#include "virtual-frame-arm-inl.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-10 11:32:25 +00:00
|
|
|
|
2010-05-26 14:23:19 +00:00
|
|
|
#define __ ACCESS_MASM(masm_)
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Platform-specific DeferredCode functions.
|
|
|
|
|
|
|
|
void DeferredCode::SaveRegisters() {
|
2010-05-27 13:57:55 +00:00
|
|
|
// On ARM you either have a completely spilled frame or you
|
2010-05-27 13:48:52 +00:00
|
|
|
// handle it yourself, but at the moment there's no automation
|
|
|
|
// of registers and deferred code.
|
2010-05-26 14:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredCode::RestoreRegisters() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// Platform-specific RuntimeCallHelper functions.
|
|
|
|
|
|
|
|
void VirtualFrameRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const {
|
2010-05-27 13:48:52 +00:00
|
|
|
frame_state_->frame()->AssertIsSpilled();
|
2010-05-26 14:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void VirtualFrameRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void StubRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const {
|
2010-05-26 14:23:19 +00:00
|
|
|
masm->EnterInternalFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void StubRuntimeCallHelper::AfterCall(MacroAssembler* masm) const {
|
2010-05-26 14:23:19 +00:00
|
|
|
masm->LeaveInternalFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-12 08:24:57 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// CodeGenState implementation.
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
CodeGenState::CodeGenState(CodeGenerator* owner)
|
2008-09-12 08:24:57 +00:00
|
|
|
: owner_(owner),
|
2010-06-02 09:37:02 +00:00
|
|
|
previous_(owner->state()) {
|
|
|
|
owner->set_state(this);
|
2008-09-12 08:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
ConditionCodeGenState::ConditionCodeGenState(CodeGenerator* owner,
|
|
|
|
JumpTarget* true_target,
|
|
|
|
JumpTarget* false_target)
|
|
|
|
: CodeGenState(owner),
|
2008-09-12 08:24:57 +00:00
|
|
|
true_target_(true_target),
|
2010-06-02 09:37:02 +00:00
|
|
|
false_target_(false_target) {
|
|
|
|
owner->set_state(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TypeInfoCodeGenState::TypeInfoCodeGenState(CodeGenerator* owner,
|
|
|
|
Slot* slot,
|
|
|
|
TypeInfo type_info)
|
|
|
|
: CodeGenState(owner),
|
|
|
|
slot_(slot) {
|
|
|
|
owner->set_state(this);
|
|
|
|
old_type_info_ = owner->set_type_info(slot, type_info);
|
2008-09-12 08:24:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CodeGenState::~CodeGenState() {
|
|
|
|
ASSERT(owner_->state() == this);
|
|
|
|
owner_->set_state(previous_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
TypeInfoCodeGenState::~TypeInfoCodeGenState() {
|
|
|
|
owner()->set_type_info(slot_, old_type_info_);
|
|
|
|
}
|
|
|
|
|
2008-11-05 08:44:54 +00:00
|
|
|
// -------------------------------------------------------------------------
|
2008-10-10 00:00:52 +00:00
|
|
|
// CodeGenerator implementation
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-02-03 16:12:55 +00:00
|
|
|
CodeGenerator::CodeGenerator(MacroAssembler* masm)
|
|
|
|
: deferred_(8),
|
2010-02-01 13:07:53 +00:00
|
|
|
masm_(masm),
|
2010-02-03 16:12:55 +00:00
|
|
|
info_(NULL),
|
2008-11-05 08:44:54 +00:00
|
|
|
frame_(NULL),
|
2009-02-27 13:00:32 +00:00
|
|
|
allocator_(NULL),
|
2008-07-03 15:10:15 +00:00
|
|
|
cc_reg_(al),
|
|
|
|
state_(NULL),
|
2010-04-15 14:06:57 +00:00
|
|
|
loop_nesting_(0),
|
2010-06-02 09:37:02 +00:00
|
|
|
type_info_(NULL),
|
2010-06-24 07:54:48 +00:00
|
|
|
function_return_(JumpTarget::BIDIRECTIONAL),
|
2009-08-07 08:18:31 +00:00
|
|
|
function_return_is_shadowed_(false) {
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Calling conventions:
|
2009-02-27 13:00:32 +00:00
|
|
|
// fp: caller's frame pointer
|
2008-07-03 15:10:15 +00:00
|
|
|
// sp: stack pointer
|
2009-02-27 13:00:32 +00:00
|
|
|
// r1: called JS function
|
2008-07-03 15:10:15 +00:00
|
|
|
// cp: callee's context
|
|
|
|
|
2010-02-19 14:52:39 +00:00
|
|
|
void CodeGenerator::Generate(CompilationInfo* info) {
|
2009-11-03 16:08:35 +00:00
|
|
|
// Record the position for debugging purposes.
|
2010-02-03 16:12:55 +00:00
|
|
|
CodeForFunctionPosition(info->function());
|
2010-02-23 12:40:36 +00:00
|
|
|
Comment cmnt(masm_, "[ function compiled by virtual frame code generator");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Initialize state.
|
2010-02-03 16:12:55 +00:00
|
|
|
info_ = info;
|
2010-06-02 09:37:02 +00:00
|
|
|
|
|
|
|
int slots = scope()->num_parameters() + scope()->num_stack_slots();
|
|
|
|
ScopedVector<TypeInfo> type_info_array(slots);
|
2010-12-07 11:31:57 +00:00
|
|
|
for (int i = 0; i < slots; i++) {
|
|
|
|
type_info_array[i] = TypeInfo::Unknown();
|
|
|
|
}
|
2010-06-02 09:37:02 +00:00
|
|
|
type_info_ = &type_info_array;
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(allocator_ == NULL);
|
|
|
|
RegisterAllocator register_allocator(this);
|
|
|
|
allocator_ = ®ister_allocator;
|
2008-11-05 08:44:54 +00:00
|
|
|
ASSERT(frame_ == NULL);
|
2009-05-20 11:14:18 +00:00
|
|
|
frame_ = new VirtualFrame();
|
2008-11-05 08:44:54 +00:00
|
|
|
cc_reg_ = al;
|
2010-04-15 14:06:57 +00:00
|
|
|
|
|
|
|
// Adjust for function-level loop nesting.
|
|
|
|
ASSERT_EQ(0, loop_nesting_);
|
2010-10-04 11:35:46 +00:00
|
|
|
loop_nesting_ = info->is_in_loop() ? 1 : 0;
|
2010-04-15 14:06:57 +00:00
|
|
|
|
2008-11-05 08:44:54 +00:00
|
|
|
{
|
|
|
|
CodeGenState state(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Entry:
|
|
|
|
// Stack: receiver, arguments
|
|
|
|
// lr: return address
|
|
|
|
// fp: caller's frame pointer
|
2008-07-03 15:10:15 +00:00
|
|
|
// sp: stack pointer
|
2009-02-27 13:00:32 +00:00
|
|
|
// r1: called JS function
|
2008-07-03 15:10:15 +00:00
|
|
|
// cp: callee's context
|
2009-02-27 13:00:32 +00:00
|
|
|
allocator_->Initialize();
|
2010-02-03 07:58:47 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (strlen(FLAG_stop_at) > 0 &&
|
2010-02-03 16:12:55 +00:00
|
|
|
info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->SpillAll();
|
2008-07-30 08:49:36 +00:00
|
|
|
__ stop("stop-at");
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-13 09:07:09 +00:00
|
|
|
frame_->Enter();
|
|
|
|
// tos: code slot
|
|
|
|
|
|
|
|
// Allocate space for locals and initialize them. This also checks
|
|
|
|
// for stack overflow.
|
|
|
|
frame_->AllocateStackSlots();
|
|
|
|
|
|
|
|
frame_->AssertIsSpilled();
|
2011-01-25 13:01:45 +00:00
|
|
|
int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS;
|
2010-08-13 09:07:09 +00:00
|
|
|
if (heap_slots > 0) {
|
|
|
|
// Allocate local context.
|
|
|
|
// Get outer context and create a new context based on it.
|
|
|
|
__ ldr(r0, frame_->Function());
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
if (heap_slots <= FastNewContextStub::kMaximumSlots) {
|
|
|
|
FastNewContextStub stub(heap_slots);
|
|
|
|
frame_->CallStub(&stub, 1);
|
|
|
|
} else {
|
|
|
|
frame_->CallRuntime(Runtime::kNewContext, 1);
|
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
2010-08-13 09:07:09 +00:00
|
|
|
JumpTarget verified_true;
|
|
|
|
__ cmp(r0, cp);
|
|
|
|
verified_true.Branch(eq);
|
|
|
|
__ stop("NewContext: r0 is expected to be the same as cp");
|
|
|
|
verified_true.Bind();
|
2009-04-22 09:25:41 +00:00
|
|
|
#endif
|
2010-08-13 09:07:09 +00:00
|
|
|
// Update context local.
|
|
|
|
__ str(cp, frame_->Context());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-13 09:07:09 +00:00
|
|
|
// TODO(1241774): Improve this code:
|
|
|
|
// 1) only needed if we have a context
|
|
|
|
// 2) no need to recompute context ptr every single time
|
|
|
|
// 3) don't copy parameter operand code from SlotOperand!
|
|
|
|
{
|
|
|
|
Comment cmnt2(masm_, "[ copy context parameters into .context");
|
|
|
|
// Note that iteration order is relevant here! If we have the same
|
|
|
|
// parameter twice (e.g., function (x, y, x)), and that parameter
|
|
|
|
// needs to be copied into the context, it must be the last argument
|
|
|
|
// passed to the parameter that needs to be copied. This is a rare
|
|
|
|
// case so we don't check for it, instead we rely on the copying
|
|
|
|
// order: such a parameter is copied repeatedly into the same
|
|
|
|
// context location and thus the last value is what is seen inside
|
|
|
|
// the function.
|
|
|
|
frame_->AssertIsSpilled();
|
|
|
|
for (int i = 0; i < scope()->num_parameters(); i++) {
|
|
|
|
Variable* par = scope()->parameter(i);
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = par->AsSlot();
|
2010-08-13 09:07:09 +00:00
|
|
|
if (slot != NULL && slot->type() == Slot::CONTEXT) {
|
|
|
|
ASSERT(!scope()->is_global_scope()); // No params in global scope.
|
|
|
|
__ ldr(r1, frame_->ParameterAt(i));
|
|
|
|
// Loads r2 with context; used below in RecordWrite.
|
|
|
|
__ str(r1, SlotOperand(slot, r2));
|
|
|
|
// Load the offset into r3.
|
|
|
|
int slot_offset =
|
|
|
|
FixedArray::kHeaderSize + slot->index() * kPointerSize;
|
|
|
|
__ RecordWrite(r2, Operand(slot_offset), r3, r1);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-13 09:07:09 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-13 09:07:09 +00:00
|
|
|
// Store the arguments object. This must happen after context
|
|
|
|
// initialization because the arguments object may be stored in
|
|
|
|
// the context.
|
|
|
|
if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) {
|
|
|
|
StoreArgumentsObject(true);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-13 09:07:09 +00:00
|
|
|
// Initialize ThisFunction reference if present.
|
|
|
|
if (scope()->is_function_scope() && scope()->function() != NULL) {
|
|
|
|
frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex);
|
2010-09-24 07:53:59 +00:00
|
|
|
StoreToSlot(scope()->function()->AsSlot(), NOT_CONST_INIT);
|
2010-01-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 07:58:47 +00:00
|
|
|
// Initialize the function return target after the locals are set
|
|
|
|
// up, because it needs the expected frame height from the frame.
|
2010-05-10 11:32:25 +00:00
|
|
|
function_return_.SetExpectedHeight();
|
2010-02-03 07:58:47 +00:00
|
|
|
function_return_is_shadowed_ = false;
|
|
|
|
|
2008-11-07 08:21:07 +00:00
|
|
|
// Generate code to 'execute' declarations and initialize functions
|
|
|
|
// (source elements). In case of an illegal redeclaration we need to
|
|
|
|
// handle that instead of processing the declarations.
|
2010-02-03 16:12:55 +00:00
|
|
|
if (scope()->HasIllegalRedeclaration()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Comment cmnt(masm_, "[ illegal redeclarations");
|
2010-02-03 16:12:55 +00:00
|
|
|
scope()->VisitIllegalRedeclaration(this);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
Comment cmnt(masm_, "[ declarations");
|
2010-02-03 16:12:55 +00:00
|
|
|
ProcessDeclarations(scope()->declarations());
|
2008-11-07 08:21:07 +00:00
|
|
|
// Bail out if a stack-overflow exception occurred when processing
|
|
|
|
// declarations.
|
2008-07-16 07:07:30 +00:00
|
|
|
if (HasStackOverflow()) return;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
if (FLAG_trace) {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kTraceEnter, 0);
|
2008-11-07 08:21:07 +00:00
|
|
|
// Ignore the return value.
|
2008-08-13 09:32:07 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Compile the body of the function in a vanilla state. Don't
|
|
|
|
// bother compiling all the code if the scope has an illegal
|
|
|
|
// redeclaration.
|
2010-02-03 16:12:55 +00:00
|
|
|
if (!scope()->HasIllegalRedeclaration()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
Comment cmnt(masm_, "[ function body");
|
|
|
|
#ifdef DEBUG
|
2011-03-18 20:35:07 +00:00
|
|
|
bool is_builtin = Isolate::Current()->bootstrapper()->IsActive();
|
2008-07-03 15:10:15 +00:00
|
|
|
bool should_trace =
|
|
|
|
is_builtin ? FLAG_trace_builtin_calls : FLAG_trace_calls;
|
2008-08-13 09:32:07 +00:00
|
|
|
if (should_trace) {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDebugTrace, 0);
|
2008-11-07 08:21:07 +00:00
|
|
|
// Ignore the return value.
|
2008-08-13 09:32:07 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
2010-05-31 08:52:57 +00:00
|
|
|
VisitStatements(info->function()->body());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-14 11:37:05 +00:00
|
|
|
// Handle the return from the function.
|
|
|
|
if (has_valid_frame()) {
|
|
|
|
// If there is a valid frame, control flow can fall off the end of
|
|
|
|
// the body. In that case there is an implicit return statement.
|
|
|
|
ASSERT(!function_return_is_shadowed_);
|
|
|
|
frame_->PrepareForReturn();
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
|
2010-06-14 11:37:05 +00:00
|
|
|
if (function_return_.is_bound()) {
|
|
|
|
function_return_.Jump();
|
|
|
|
} else {
|
|
|
|
function_return_.Bind();
|
|
|
|
GenerateReturnSequence();
|
2010-04-27 09:09:51 +00:00
|
|
|
}
|
2010-06-14 11:37:05 +00:00
|
|
|
} else if (function_return_.is_linked()) {
|
|
|
|
// If the return target has dangling jumps to it, then we have not
|
|
|
|
// yet generated the return sequence. This can happen when (a)
|
|
|
|
// control does not flow off the end of the body so we did not
|
|
|
|
// compile an artificial return statement just above, and (b) there
|
|
|
|
// are return statements in the body but (c) they are all shadowed.
|
|
|
|
function_return_.Bind();
|
|
|
|
GenerateReturnSequence();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
|
2010-04-15 14:06:57 +00:00
|
|
|
// Adjust for function-level loop nesting.
|
2010-10-04 11:35:46 +00:00
|
|
|
ASSERT(loop_nesting_ == info->is_in_loop()? 1 : 0);
|
2010-04-15 14:06:57 +00:00
|
|
|
loop_nesting_ = 0;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Code generation state must be reset.
|
|
|
|
ASSERT(!has_cc());
|
|
|
|
ASSERT(state_ == NULL);
|
2010-04-22 07:18:30 +00:00
|
|
|
ASSERT(loop_nesting() == 0);
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!function_return_is_shadowed_);
|
|
|
|
function_return_.Unuse();
|
|
|
|
DeleteFrame();
|
|
|
|
|
|
|
|
// Process any deferred code using the register allocator.
|
2009-05-27 15:13:00 +00:00
|
|
|
if (!HasStackOverflow()) {
|
2009-03-11 10:25:48 +00:00
|
|
|
ProcessDeferred();
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
|
|
|
allocator_ = NULL;
|
2010-06-02 09:37:02 +00:00
|
|
|
type_info_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CodeGenerator::NumberOfSlot(Slot* slot) {
|
|
|
|
if (slot == NULL) return kInvalidSlotNumber;
|
|
|
|
switch (slot->type()) {
|
|
|
|
case Slot::PARAMETER:
|
|
|
|
return slot->index();
|
|
|
|
case Slot::LOCAL:
|
|
|
|
return slot->index() + scope()->num_parameters();
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return kInvalidSlotNumber;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) {
|
2008-10-07 11:19:44 +00:00
|
|
|
// Currently, this assertion will fail if we try to assign to
|
|
|
|
// a constant variable that is constant because it is read-only
|
|
|
|
// (such as the variable referring to a named function expression).
|
|
|
|
// We need to implement assignments to read-only variables.
|
|
|
|
// Ideally, we should do this during AST generation (by converting
|
|
|
|
// such assignments into expression statements); however, in general
|
|
|
|
// we may not be able to make the decision until past AST generation,
|
|
|
|
// that is when the entire program is known.
|
|
|
|
ASSERT(slot != NULL);
|
|
|
|
int index = slot->index();
|
|
|
|
switch (slot->type()) {
|
|
|
|
case Slot::PARAMETER:
|
2009-02-27 13:00:32 +00:00
|
|
|
return frame_->ParameterAt(index);
|
2008-10-07 11:19:44 +00:00
|
|
|
|
2008-11-05 08:44:54 +00:00
|
|
|
case Slot::LOCAL:
|
2009-02-27 13:00:32 +00:00
|
|
|
return frame_->LocalAt(index);
|
2008-10-07 11:19:44 +00:00
|
|
|
|
|
|
|
case Slot::CONTEXT: {
|
|
|
|
// Follow the context chain if necessary.
|
|
|
|
ASSERT(!tmp.is(cp)); // do not overwrite context register
|
|
|
|
Register context = cp;
|
|
|
|
int chain_length = scope()->ContextChainLength(slot->var()->scope());
|
2009-02-18 13:54:13 +00:00
|
|
|
for (int i = 0; i < chain_length; i++) {
|
2008-10-07 11:19:44 +00:00
|
|
|
// Load the closure.
|
|
|
|
// (All contexts, even 'with' contexts, have a closure,
|
|
|
|
// and it is the same for all contexts inside a function.
|
|
|
|
// There is no need to go to the function context first.)
|
|
|
|
__ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
|
|
|
|
// Load the function context (which is the incoming, outer context).
|
|
|
|
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
|
|
|
|
context = tmp;
|
|
|
|
}
|
|
|
|
// We may have a 'with' context now. Get the function context.
|
|
|
|
// (In fact this mov may never be the needed, since the scope analysis
|
|
|
|
// may not permit a direct context access in this case and thus we are
|
|
|
|
// always at a function context. However it is safe to dereference be-
|
|
|
|
// cause the function context of a function context is itself. Before
|
|
|
|
// deleting this mov we should try to create a counter-example first,
|
|
|
|
// though...)
|
|
|
|
__ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX));
|
|
|
|
return ContextOperand(tmp, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
return MemOperand(r0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
MemOperand CodeGenerator::ContextSlotOperandCheckExtensions(
|
|
|
|
Slot* slot,
|
|
|
|
Register tmp,
|
|
|
|
Register tmp2,
|
|
|
|
JumpTarget* slow) {
|
2009-02-18 13:54:13 +00:00
|
|
|
ASSERT(slot->type() == Slot::CONTEXT);
|
|
|
|
Register context = cp;
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-02-18 13:54:13 +00:00
|
|
|
for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) {
|
|
|
|
if (s->num_heap_slots() > 0) {
|
|
|
|
if (s->calls_eval()) {
|
|
|
|
// Check that extension is NULL.
|
|
|
|
__ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX));
|
|
|
|
__ tst(tmp2, tmp2);
|
2009-02-27 13:00:32 +00:00
|
|
|
slow->Branch(ne);
|
2009-02-18 13:54:13 +00:00
|
|
|
}
|
|
|
|
__ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
|
|
|
|
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
|
|
|
|
context = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check that last extension is NULL.
|
2009-02-19 07:22:53 +00:00
|
|
|
__ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX));
|
2009-02-18 13:54:13 +00:00
|
|
|
__ tst(tmp2, tmp2);
|
2009-02-27 13:00:32 +00:00
|
|
|
slow->Branch(ne);
|
2009-02-19 07:22:53 +00:00
|
|
|
__ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX));
|
2009-02-27 13:00:32 +00:00
|
|
|
return ContextOperand(tmp, slot->index());
|
2009-02-18 13:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 08:21:07 +00:00
|
|
|
// Loads a value on TOS. If it is a boolean value, the result may have been
|
|
|
|
// (partially) translated into branches, or it may have set the condition
|
|
|
|
// code register. If force_cc is set, the value is forced to set the
|
|
|
|
// condition code register and no value is pushed. If the condition code
|
|
|
|
// register was set, has_cc() is true and cc_reg_ contains the condition to
|
|
|
|
// test for 'true'.
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::LoadCondition(Expression* x,
|
2009-02-27 13:00:32 +00:00
|
|
|
JumpTarget* true_target,
|
|
|
|
JumpTarget* false_target,
|
2008-11-07 08:21:07 +00:00
|
|
|
bool force_cc) {
|
2008-10-08 07:24:06 +00:00
|
|
|
ASSERT(!has_cc());
|
2009-02-27 13:00:32 +00:00
|
|
|
int original_height = frame_->height();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
{ ConditionCodeGenState new_state(this, true_target, false_target);
|
2008-09-12 08:24:57 +00:00
|
|
|
Visit(x);
|
2009-02-27 13:00:32 +00:00
|
|
|
|
|
|
|
// If we hit a stack overflow, we may not have actually visited
|
|
|
|
// the expression. In that case, we ensure that we have a
|
|
|
|
// valid-looking frame state because we will continue to generate
|
|
|
|
// code as we unwind the C++ stack.
|
|
|
|
//
|
|
|
|
// It's possible to have both a stack overflow and a valid frame
|
|
|
|
// state (eg, a subexpression overflowed, visiting it returned
|
|
|
|
// with a dummied frame state, and visiting this expression
|
|
|
|
// returned with a normal-looking state).
|
|
|
|
if (HasStackOverflow() &&
|
|
|
|
has_valid_frame() &&
|
|
|
|
!has_cc() &&
|
|
|
|
frame_->height() == original_height) {
|
|
|
|
true_target->Jump();
|
|
|
|
}
|
2008-09-12 08:24:57 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
if (force_cc && frame_ != NULL && !has_cc()) {
|
2008-08-13 09:32:07 +00:00
|
|
|
// Convert the TOS value to a boolean in the condition code register.
|
|
|
|
ToBoolean(true_target, false_target);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!force_cc || !has_valid_frame() || has_cc());
|
|
|
|
ASSERT(!has_valid_frame() ||
|
|
|
|
(has_cc() && frame_->height() == original_height) ||
|
|
|
|
(!has_cc() && frame_->height() == original_height + 1));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 13:56:41 +00:00
|
|
|
void CodeGenerator::Load(Expression* expr) {
|
2010-08-16 11:43:30 +00:00
|
|
|
// We generally assume that we are not in a spilled scope for most
|
|
|
|
// of the code generator. A failure to ensure this caused issue 815
|
|
|
|
// and this assert is designed to catch similar issues.
|
|
|
|
frame_->AssertIsNotSpilled();
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget true_target;
|
|
|
|
JumpTarget false_target;
|
2009-11-04 13:56:41 +00:00
|
|
|
LoadCondition(expr, &true_target, &false_target, false);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
if (has_cc()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
// Convert cc_reg_ into a boolean value.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget loaded;
|
|
|
|
JumpTarget materialize_true;
|
2009-02-27 13:00:32 +00:00
|
|
|
materialize_true.Branch(cc_reg_);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kFalseValueRootIndex);
|
2009-02-27 13:00:32 +00:00
|
|
|
loaded.Jump();
|
|
|
|
materialize_true.Bind();
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kTrueValueRootIndex);
|
2009-02-27 13:00:32 +00:00
|
|
|
loaded.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
cc_reg_ = al;
|
2008-10-31 13:18:52 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-31 13:18:52 +00:00
|
|
|
if (true_target.is_linked() || false_target.is_linked()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
// We have at least one condition value that has been "translated"
|
|
|
|
// into a branch, thus it needs to be loaded explicitly.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget loaded;
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
loaded.Jump(); // Don't lose the current TOS.
|
|
|
|
}
|
2008-10-31 13:18:52 +00:00
|
|
|
bool both = true_target.is_linked() && false_target.is_linked();
|
2009-02-27 13:00:32 +00:00
|
|
|
// Load "true" if necessary.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (true_target.is_linked()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
true_target.Bind();
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kTrueValueRootIndex);
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
// If both "true" and "false" need to be loaded jump across the code for
|
|
|
|
// "false".
|
|
|
|
if (both) {
|
|
|
|
loaded.Jump();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
// Load "false" if necessary.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (false_target.is_linked()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target.Bind();
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kFalseValueRootIndex);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
// A value is loaded on all paths reaching this point.
|
|
|
|
loaded.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(has_valid_frame());
|
2008-10-31 13:18:52 +00:00
|
|
|
ASSERT(!has_cc());
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::LoadGlobal() {
|
2010-04-27 19:24:36 +00:00
|
|
|
Register reg = frame_->GetTOSRegister();
|
2010-11-10 17:00:20 +00:00
|
|
|
__ ldr(reg, GlobalObjectOperand());
|
2010-04-27 19:24:36 +00:00
|
|
|
frame_->EmitPush(reg);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-07 08:21:07 +00:00
|
|
|
void CodeGenerator::LoadGlobalReceiver(Register scratch) {
|
2010-06-24 07:54:48 +00:00
|
|
|
Register reg = frame_->GetTOSRegister();
|
|
|
|
__ ldr(reg, ContextOperand(cp, Context::GLOBAL_INDEX));
|
|
|
|
__ ldr(reg,
|
|
|
|
FieldMemOperand(reg, GlobalObject::kGlobalReceiverOffset));
|
|
|
|
frame_->EmitPush(reg);
|
2008-10-21 20:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
ArgumentsAllocationMode CodeGenerator::ArgumentsMode() {
|
|
|
|
if (scope()->arguments() == NULL) return NO_ARGUMENTS_ALLOCATION;
|
2011-03-07 19:23:46 +00:00
|
|
|
|
|
|
|
// In strict mode there is no need for shadow arguments.
|
|
|
|
ASSERT(scope()->arguments_shadow() != NULL || scope()->is_strict_mode());
|
2010-04-22 12:20:36 +00:00
|
|
|
// We don't want to do lazy arguments allocation for functions that
|
|
|
|
// have heap-allocated contexts, because it interfers with the
|
|
|
|
// uninitialized const tracking in the context objects.
|
2011-03-07 19:23:46 +00:00
|
|
|
return (scope()->num_heap_slots() > 0 || scope()->is_strict_mode())
|
2010-04-22 12:20:36 +00:00
|
|
|
? EAGER_ARGUMENTS_ALLOCATION
|
|
|
|
: LAZY_ARGUMENTS_ALLOCATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::StoreArgumentsObject(bool initial) {
|
|
|
|
ArgumentsAllocationMode mode = ArgumentsMode();
|
|
|
|
ASSERT(mode != NO_ARGUMENTS_ALLOCATION);
|
|
|
|
|
|
|
|
Comment cmnt(masm_, "[ store arguments object");
|
|
|
|
if (mode == LAZY_ARGUMENTS_ALLOCATION && initial) {
|
|
|
|
// When using lazy arguments allocation, we store the hole value
|
|
|
|
// as a sentinel indicating that the arguments object hasn't been
|
|
|
|
// allocated yet.
|
2011-01-06 15:53:56 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kArgumentsMarkerRootIndex);
|
2010-04-22 12:20:36 +00:00
|
|
|
} else {
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->SpillAll();
|
2011-03-17 20:28:41 +00:00
|
|
|
ArgumentsAccessStub stub(is_strict_mode()
|
|
|
|
? ArgumentsAccessStub::NEW_STRICT
|
|
|
|
: ArgumentsAccessStub::NEW_NON_STRICT);
|
2010-04-22 12:20:36 +00:00
|
|
|
__ ldr(r2, frame_->Function());
|
|
|
|
// The receiver is below the arguments, the return address, and the
|
|
|
|
// frame pointer on the stack.
|
|
|
|
const int kReceiverDisplacement = 2 + scope()->num_parameters();
|
|
|
|
__ add(r1, fp, Operand(kReceiverDisplacement * kPointerSize));
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(scope()->num_parameters())));
|
|
|
|
frame_->Adjust(3);
|
2010-04-26 14:25:29 +00:00
|
|
|
__ Push(r2, r1, r0);
|
2010-04-22 12:20:36 +00:00
|
|
|
frame_->CallStub(&stub, 3);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
2010-09-24 07:53:59 +00:00
|
|
|
Variable* arguments = scope()->arguments();
|
|
|
|
Variable* shadow = scope()->arguments_shadow();
|
|
|
|
ASSERT(arguments != NULL && arguments->AsSlot() != NULL);
|
2011-03-07 19:23:46 +00:00
|
|
|
ASSERT((shadow != NULL && shadow->AsSlot() != NULL) ||
|
|
|
|
scope()->is_strict_mode());
|
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
JumpTarget done;
|
|
|
|
if (mode == LAZY_ARGUMENTS_ALLOCATION && !initial) {
|
|
|
|
// We have to skip storing into the arguments slot if it has
|
|
|
|
// already been written to. This can happen if the a function
|
|
|
|
// has a local variable named 'arguments'.
|
2010-09-24 07:53:59 +00:00
|
|
|
LoadFromSlot(scope()->arguments()->AsSlot(), NOT_INSIDE_TYPEOF);
|
2010-06-24 07:54:48 +00:00
|
|
|
Register arguments = frame_->PopToRegister();
|
2011-01-06 15:53:56 +00:00
|
|
|
__ LoadRoot(ip, Heap::kArgumentsMarkerRootIndex);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(arguments, ip);
|
2010-04-22 12:20:36 +00:00
|
|
|
done.Branch(ne);
|
|
|
|
}
|
2010-09-24 07:53:59 +00:00
|
|
|
StoreToSlot(arguments->AsSlot(), NOT_CONST_INIT);
|
2010-04-22 12:20:36 +00:00
|
|
|
if (mode == LAZY_ARGUMENTS_ALLOCATION) done.Bind();
|
2011-03-07 19:23:46 +00:00
|
|
|
if (shadow != NULL) {
|
|
|
|
StoreToSlot(shadow->AsSlot(), NOT_CONST_INIT);
|
|
|
|
}
|
2010-04-22 12:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 13:56:41 +00:00
|
|
|
void CodeGenerator::LoadTypeofExpression(Expression* expr) {
|
|
|
|
// Special handling of identifiers as subexpressions of typeof.
|
|
|
|
Variable* variable = expr->AsVariableProxy()->AsVariable();
|
2008-07-03 15:10:15 +00:00
|
|
|
if (variable != NULL && !variable->is_this() && variable->is_global()) {
|
2009-11-04 13:56:41 +00:00
|
|
|
// For a global variable we build the property reference
|
|
|
|
// <global>.<variable> and perform a (regular non-contextual) property
|
|
|
|
// load to make sure we do not get reference errors.
|
2008-07-03 15:10:15 +00:00
|
|
|
Slot global(variable, Slot::CONTEXT, Context::GLOBAL_INDEX);
|
|
|
|
Literal key(variable->name());
|
2008-09-22 13:57:03 +00:00
|
|
|
Property property(&global, &key, RelocInfo::kNoPosition);
|
2009-11-04 13:56:41 +00:00
|
|
|
Reference ref(this, &property);
|
2010-04-08 22:30:30 +00:00
|
|
|
ref.GetValue();
|
2010-09-24 07:53:59 +00:00
|
|
|
} else if (variable != NULL && variable->AsSlot() != NULL) {
|
2009-11-04 13:56:41 +00:00
|
|
|
// For a variable that rewrites to a slot, we signal it is the immediate
|
|
|
|
// subexpression of a typeof.
|
2010-09-24 07:53:59 +00:00
|
|
|
LoadFromSlotCheckForArguments(variable->AsSlot(), INSIDE_TYPEOF);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-11-04 13:56:41 +00:00
|
|
|
// Anything else can be handled normally.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(expr);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-27 14:07:12 +00:00
|
|
|
Reference::Reference(CodeGenerator* cgen,
|
|
|
|
Expression* expression,
|
|
|
|
bool persist_after_get)
|
|
|
|
: cgen_(cgen),
|
|
|
|
expression_(expression),
|
|
|
|
type_(ILLEGAL),
|
|
|
|
persist_after_get_(persist_after_get) {
|
2010-08-16 11:43:30 +00:00
|
|
|
// We generally assume that we are not in a spilled scope for most
|
|
|
|
// of the code generator. A failure to ensure this caused issue 815
|
|
|
|
// and this assert is designed to catch similar issues.
|
|
|
|
cgen->frame()->AssertIsNotSpilled();
|
2008-07-03 15:10:15 +00:00
|
|
|
cgen->LoadReference(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Reference::~Reference() {
|
2010-01-27 14:07:12 +00:00
|
|
|
ASSERT(is_unloaded() || is_illegal());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::LoadReference(Reference* ref) {
|
2008-10-08 07:24:06 +00:00
|
|
|
Comment cmnt(masm_, "[ LoadReference");
|
2008-07-03 15:10:15 +00:00
|
|
|
Expression* e = ref->expression();
|
|
|
|
Property* property = e->AsProperty();
|
|
|
|
Variable* var = e->AsVariableProxy()->AsVariable();
|
|
|
|
|
|
|
|
if (property != NULL) {
|
2008-10-07 08:47:15 +00:00
|
|
|
// The expression is either a property or a variable proxy that rewrites
|
|
|
|
// to a property.
|
2010-04-27 19:24:36 +00:00
|
|
|
Load(property->obj());
|
2010-01-12 08:48:26 +00:00
|
|
|
if (property->key()->IsPropertyName()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
ref->set_type(Reference::NAMED);
|
|
|
|
} else {
|
2010-04-27 19:24:36 +00:00
|
|
|
Load(property->key());
|
2008-07-03 15:10:15 +00:00
|
|
|
ref->set_type(Reference::KEYED);
|
|
|
|
}
|
|
|
|
} else if (var != NULL) {
|
2008-10-07 08:47:15 +00:00
|
|
|
// The expression is a variable proxy that does not rewrite to a
|
|
|
|
// property. Global variables are treated as named property references.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (var->is_global()) {
|
|
|
|
LoadGlobal();
|
|
|
|
ref->set_type(Reference::NAMED);
|
|
|
|
} else {
|
2010-09-24 07:53:59 +00:00
|
|
|
ASSERT(var->AsSlot() != NULL);
|
2008-10-07 08:47:15 +00:00
|
|
|
ref->set_type(Reference::SLOT);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-10-07 08:47:15 +00:00
|
|
|
// Anything else is a runtime error.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(e);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kThrowReferenceError, 1);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::UnloadReference(Reference* ref) {
|
2010-04-08 22:30:30 +00:00
|
|
|
int size = ref->size();
|
|
|
|
ref->set_unloaded();
|
|
|
|
if (size == 0) return;
|
|
|
|
|
2008-11-07 08:21:07 +00:00
|
|
|
// Pop a reference from the stack while preserving TOS.
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
2008-10-08 07:24:06 +00:00
|
|
|
Comment cmnt(masm_, "[ UnloadReference");
|
2008-11-07 08:58:23 +00:00
|
|
|
if (size > 0) {
|
2010-04-08 22:30:30 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
2008-11-07 08:21:07 +00:00
|
|
|
frame_->Drop(size);
|
2010-04-08 22:30:30 +00:00
|
|
|
frame_->EmitPush(tos);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ECMA-262, section 9.2, page 30: ToBoolean(). Convert the given
|
|
|
|
// register to a boolean in the condition code register. The code
|
|
|
|
// may jump to 'false_target' in case the register converts to 'false'.
|
2009-02-27 13:00:32 +00:00
|
|
|
void CodeGenerator::ToBoolean(JumpTarget* true_target,
|
|
|
|
JumpTarget* false_target) {
|
2008-08-13 09:32:07 +00:00
|
|
|
// Note: The generated code snippet does not change stack variables.
|
2008-07-03 15:10:15 +00:00
|
|
|
// Only the condition code should be set.
|
2010-07-02 08:42:22 +00:00
|
|
|
bool known_smi = frame_->KnownSmiAt(0);
|
2010-06-24 07:54:48 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Fast case checks
|
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
// Check if the value is 'false'.
|
2010-07-02 08:42:22 +00:00
|
|
|
if (!known_smi) {
|
|
|
|
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
|
|
|
__ cmp(tos, ip);
|
|
|
|
false_target->Branch(eq);
|
|
|
|
|
|
|
|
// Check if the value is 'true'.
|
|
|
|
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
|
|
|
|
__ cmp(tos, ip);
|
|
|
|
true_target->Branch(eq);
|
|
|
|
|
|
|
|
// Check if the value is 'undefined'.
|
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ cmp(tos, ip);
|
|
|
|
false_target->Branch(eq);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-08-13 09:32:07 +00:00
|
|
|
// Check if the value is a smi.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(tos, Operand(Smi::FromInt(0)));
|
2010-07-02 08:42:22 +00:00
|
|
|
|
|
|
|
if (!known_smi) {
|
|
|
|
false_target->Branch(eq);
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
true_target->Branch(eq);
|
|
|
|
|
2010-08-16 07:52:49 +00:00
|
|
|
// Slow case.
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-08-16 07:52:49 +00:00
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
// Implements the slow case by using ToBooleanStub.
|
|
|
|
// The ToBooleanStub takes a single argument, and
|
|
|
|
// returns a non-zero value for true, or zero for false.
|
|
|
|
// Both the argument value and the return value use the
|
|
|
|
// register assigned to tos_
|
|
|
|
ToBooleanStub stub(tos);
|
|
|
|
frame_->CallStub(&stub, 0);
|
|
|
|
// Convert the result in "tos" to a condition code.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(tos, Operand(0, RelocInfo::NONE));
|
2010-08-16 07:52:49 +00:00
|
|
|
} else {
|
|
|
|
// Implements slow case by calling the runtime.
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
frame_->CallRuntime(Runtime::kToBool, 1);
|
|
|
|
// Convert the result (r0) to a condition code.
|
|
|
|
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
|
|
|
__ cmp(r0, ip);
|
|
|
|
}
|
2010-07-02 08:42:22 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
cc_reg_ = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:30:23 +00:00
|
|
|
void CodeGenerator::GenericBinaryOperation(Token::Value op,
|
2009-07-03 12:44:31 +00:00
|
|
|
OverwriteMode overwrite_mode,
|
2010-06-02 09:37:02 +00:00
|
|
|
GenerateInlineSmi inline_smi,
|
2009-07-03 12:44:31 +00:00
|
|
|
int constant_rhs) {
|
2010-06-02 09:37:02 +00:00
|
|
|
// top of virtual frame: y
|
|
|
|
// 2nd elt. on virtual frame : x
|
|
|
|
// result : top of virtual frame
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
// Stub is entered with a call: 'return address' is in lr.
|
|
|
|
switch (op) {
|
2010-04-08 22:30:30 +00:00
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
2010-06-02 09:37:02 +00:00
|
|
|
if (inline_smi) {
|
|
|
|
JumpTarget done;
|
|
|
|
Register rhs = frame_->PopToRegister();
|
|
|
|
Register lhs = frame_->PopToRegister(rhs);
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
__ orr(scratch, rhs, Operand(lhs));
|
|
|
|
// Check they are both small and positive.
|
|
|
|
__ tst(scratch, Operand(kSmiTagMask | 0xc0000000));
|
|
|
|
ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-06-02 09:37:02 +00:00
|
|
|
if (op == Token::ADD) {
|
|
|
|
__ add(r0, lhs, Operand(rhs), LeaveCC, eq);
|
|
|
|
} else {
|
|
|
|
__ sub(r0, lhs, Operand(rhs), LeaveCC, eq);
|
|
|
|
}
|
|
|
|
done.Branch(eq);
|
|
|
|
GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs);
|
|
|
|
frame_->SpillAll();
|
|
|
|
frame_->CallStub(&stub, 0);
|
|
|
|
done.Bind();
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Fall through!
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_XOR:
|
2010-06-02 09:37:02 +00:00
|
|
|
if (inline_smi) {
|
|
|
|
bool rhs_is_smi = frame_->KnownSmiAt(0);
|
|
|
|
bool lhs_is_smi = frame_->KnownSmiAt(1);
|
|
|
|
Register rhs = frame_->PopToRegister();
|
|
|
|
Register lhs = frame_->PopToRegister(rhs);
|
|
|
|
Register smi_test_reg;
|
|
|
|
Condition cond;
|
|
|
|
if (!rhs_is_smi || !lhs_is_smi) {
|
2010-06-02 10:47:50 +00:00
|
|
|
if (rhs_is_smi) {
|
2010-06-02 09:37:02 +00:00
|
|
|
smi_test_reg = lhs;
|
2010-06-02 10:47:50 +00:00
|
|
|
} else if (lhs_is_smi) {
|
|
|
|
smi_test_reg = rhs;
|
2010-06-02 09:37:02 +00:00
|
|
|
} else {
|
|
|
|
smi_test_reg = VirtualFrame::scratch0();
|
|
|
|
__ orr(smi_test_reg, rhs, Operand(lhs));
|
|
|
|
}
|
|
|
|
// Check they are both Smis.
|
|
|
|
__ tst(smi_test_reg, Operand(kSmiTagMask));
|
|
|
|
cond = eq;
|
|
|
|
} else {
|
|
|
|
cond = al;
|
|
|
|
}
|
|
|
|
ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now.
|
|
|
|
if (op == Token::BIT_OR) {
|
|
|
|
__ orr(r0, lhs, Operand(rhs), LeaveCC, cond);
|
|
|
|
} else if (op == Token::BIT_AND) {
|
|
|
|
__ and_(r0, lhs, Operand(rhs), LeaveCC, cond);
|
|
|
|
} else {
|
|
|
|
ASSERT(op == Token::BIT_XOR);
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
2010-06-02 09:37:02 +00:00
|
|
|
__ eor(r0, lhs, Operand(rhs), LeaveCC, cond);
|
|
|
|
}
|
|
|
|
if (cond != al) {
|
|
|
|
JumpTarget done;
|
|
|
|
done.Branch(cond);
|
|
|
|
GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs);
|
|
|
|
frame_->SpillAll();
|
|
|
|
frame_->CallStub(&stub, 0);
|
|
|
|
done.Bind();
|
|
|
|
}
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
// Fall through!
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
case Token::MUL:
|
|
|
|
case Token::DIV:
|
|
|
|
case Token::MOD:
|
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
case Token::SAR: {
|
2010-04-09 18:25:51 +00:00
|
|
|
Register rhs = frame_->PopToRegister();
|
|
|
|
Register lhs = frame_->PopToRegister(rhs); // Don't pop to rhs register.
|
2010-05-28 11:23:07 +00:00
|
|
|
GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs);
|
|
|
|
frame_->SpillAll();
|
|
|
|
frame_->CallStub(&stub, 0);
|
2010-04-08 22:30:30 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::COMMA: {
|
|
|
|
Register scratch = frame_->PopToRegister();
|
|
|
|
// Simply discard left value.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop();
|
2010-04-08 22:30:30 +00:00
|
|
|
frame_->EmitPush(scratch);
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
default:
|
|
|
|
// Other cases should have been handled before this point.
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
class DeferredInlineSmiOperation: public DeferredCode {
|
2008-10-02 11:54:32 +00:00
|
|
|
public:
|
2009-05-27 15:13:00 +00:00
|
|
|
DeferredInlineSmiOperation(Token::Value op,
|
2009-02-27 13:00:32 +00:00
|
|
|
int value,
|
2009-04-16 09:30:23 +00:00
|
|
|
bool reversed,
|
2010-04-08 22:30:30 +00:00
|
|
|
OverwriteMode overwrite_mode,
|
|
|
|
Register tos)
|
2009-05-27 15:13:00 +00:00
|
|
|
: op_(op),
|
2009-02-27 13:00:32 +00:00
|
|
|
value_(value),
|
2009-04-16 09:30:23 +00:00
|
|
|
reversed_(reversed),
|
2010-04-08 22:30:30 +00:00
|
|
|
overwrite_mode_(overwrite_mode),
|
|
|
|
tos_register_(tos) {
|
2008-10-02 11:54:32 +00:00
|
|
|
set_comment("[ DeferredInlinedSmiOperation");
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
virtual void Generate();
|
2010-09-02 08:30:52 +00:00
|
|
|
// This stub makes explicit calls to SaveRegisters(), RestoreRegisters() and
|
|
|
|
// Exit(). Currently on ARM SaveRegisters() and RestoreRegisters() are empty
|
|
|
|
// methods, it is the responsibility of the deferred code to save and restore
|
|
|
|
// registers.
|
|
|
|
virtual bool AutoSaveAndRestore() { return false; }
|
|
|
|
|
|
|
|
void JumpToNonSmiInput(Condition cond);
|
|
|
|
void JumpToAnswerOutOfRange(Condition cond);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
private:
|
2010-09-02 08:30:52 +00:00
|
|
|
void GenerateNonSmiInput();
|
|
|
|
void GenerateAnswerOutOfRange();
|
|
|
|
void WriteNonSmiAnswer(Register answer,
|
|
|
|
Register heap_number,
|
|
|
|
Register scratch);
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
Token::Value op_;
|
|
|
|
int value_;
|
|
|
|
bool reversed_;
|
2009-04-16 09:30:23 +00:00
|
|
|
OverwriteMode overwrite_mode_;
|
2010-04-08 22:30:30 +00:00
|
|
|
Register tos_register_;
|
2010-09-02 08:30:52 +00:00
|
|
|
Label non_smi_input_;
|
|
|
|
Label answer_out_of_range_;
|
2009-02-27 13:00:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-02 08:30:52 +00:00
|
|
|
// For bit operations we try harder and handle the case where the input is not
|
|
|
|
// a Smi but a 32bits integer without calling the generic stub.
|
|
|
|
void DeferredInlineSmiOperation::JumpToNonSmiInput(Condition cond) {
|
|
|
|
ASSERT(Token::IsBitOp(op_));
|
|
|
|
|
|
|
|
__ b(cond, &non_smi_input_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For bit operations the result is always 32bits so we handle the case where
|
|
|
|
// the result does not fit in a Smi without calling the generic stub.
|
|
|
|
void DeferredInlineSmiOperation::JumpToAnswerOutOfRange(Condition cond) {
|
|
|
|
ASSERT(Token::IsBitOp(op_));
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
if ((op_ == Token::SHR) &&
|
|
|
|
!Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-09-02 08:30:52 +00:00
|
|
|
// >>> requires an unsigned to double conversion and the non VFP code
|
|
|
|
// does not support this conversion.
|
|
|
|
__ b(cond, entry_label());
|
|
|
|
} else {
|
|
|
|
__ b(cond, &answer_out_of_range_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
|
|
|
|
// On entry the non-constant side of the binary operation is in tos_register_
|
|
|
|
// and the constant smi side is nowhere. The tos_register_ is not used by the
|
|
|
|
// virtual frame. On exit the answer is in the tos_register_ and the virtual
|
|
|
|
// frame is unchanged.
|
2009-02-27 13:00:32 +00:00
|
|
|
void DeferredInlineSmiOperation::Generate() {
|
2010-06-24 07:54:48 +00:00
|
|
|
VirtualFrame copied_frame(*frame_state()->frame());
|
|
|
|
copied_frame.SpillAll();
|
|
|
|
|
2010-04-09 18:25:51 +00:00
|
|
|
Register lhs = r1;
|
|
|
|
Register rhs = r0;
|
2009-02-27 13:00:32 +00:00
|
|
|
switch (op_) {
|
|
|
|
case Token::ADD: {
|
2009-06-05 14:16:32 +00:00
|
|
|
// Revert optimistic add.
|
2009-02-27 13:00:32 +00:00
|
|
|
if (reversed_) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ sub(r0, tos_register_, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
__ mov(r1, Operand(Smi::FromInt(value_)));
|
|
|
|
} else {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ sub(r1, tos_register_, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(value_)));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
case Token::SUB: {
|
2009-06-05 14:16:32 +00:00
|
|
|
// Revert optimistic sub.
|
2009-02-27 13:00:32 +00:00
|
|
|
if (reversed_) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ rsb(r0, tos_register_, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
__ mov(r1, Operand(Smi::FromInt(value_)));
|
|
|
|
} else {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ add(r1, tos_register_, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(value_)));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-07-03 12:44:31 +00:00
|
|
|
// For these operations there is no optimistic operation that needs to be
|
|
|
|
// reverted.
|
|
|
|
case Token::MUL:
|
|
|
|
case Token::MOD:
|
2009-02-27 13:00:32 +00:00
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR:
|
2010-06-23 13:44:11 +00:00
|
|
|
case Token::BIT_AND:
|
2009-02-27 13:00:32 +00:00
|
|
|
case Token::SHL:
|
|
|
|
case Token::SHR:
|
|
|
|
case Token::SAR: {
|
2010-06-23 13:44:11 +00:00
|
|
|
if (tos_register_.is(r1)) {
|
|
|
|
__ mov(r0, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
} else {
|
2010-06-23 13:44:11 +00:00
|
|
|
ASSERT(tos_register_.is(r0));
|
2010-06-02 09:37:02 +00:00
|
|
|
__ mov(r1, Operand(Smi::FromInt(value_)));
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2010-06-23 13:44:11 +00:00
|
|
|
if (reversed_ == tos_register_.is(r1)) {
|
|
|
|
lhs = r0;
|
|
|
|
rhs = r1;
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
default:
|
2009-06-05 14:16:32 +00:00
|
|
|
// Other cases should have been handled before this point.
|
2009-02-27 13:00:32 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-09 18:25:51 +00:00
|
|
|
GenericBinaryOpStub stub(op_, overwrite_mode_, lhs, rhs, value_);
|
2009-06-05 14:16:32 +00:00
|
|
|
__ CallStub(&stub);
|
2010-06-24 07:54:48 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
// The generic stub returns its value in r0, but that's not
|
|
|
|
// necessarily what we want. We want whatever the inlined code
|
|
|
|
// expected, which is that the answer is in the same register as
|
|
|
|
// the operand was.
|
|
|
|
__ Move(tos_register_, r0);
|
2010-06-24 07:54:48 +00:00
|
|
|
|
|
|
|
// The tos register was not in use for the virtual frame that we
|
|
|
|
// came into this function with, so we can merge back to that frame
|
|
|
|
// without trashing it.
|
|
|
|
copied_frame.MergeTo(frame_state()->frame());
|
2010-09-02 08:30:52 +00:00
|
|
|
|
|
|
|
Exit();
|
|
|
|
|
|
|
|
if (non_smi_input_.is_linked()) {
|
|
|
|
GenerateNonSmiInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answer_out_of_range_.is_linked()) {
|
|
|
|
GenerateAnswerOutOfRange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Convert and write the integer answer into heap_number.
|
|
|
|
void DeferredInlineSmiOperation::WriteNonSmiAnswer(Register answer,
|
|
|
|
Register heap_number,
|
|
|
|
Register scratch) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-09-02 08:30:52 +00:00
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
__ vmov(s0, answer);
|
|
|
|
if (op_ == Token::SHR) {
|
|
|
|
__ vcvt_f64_u32(d0, s0);
|
|
|
|
} else {
|
|
|
|
__ vcvt_f64_s32(d0, s0);
|
|
|
|
}
|
|
|
|
__ sub(scratch, heap_number, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(d0, scratch, HeapNumber::kValueOffset);
|
|
|
|
} else {
|
|
|
|
WriteInt32ToHeapNumberStub stub(answer, heap_number, scratch);
|
|
|
|
__ CallStub(&stub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredInlineSmiOperation::GenerateNonSmiInput() {
|
|
|
|
// We know the left hand side is not a Smi and the right hand side is an
|
|
|
|
// immediate value (value_) which can be represented as a Smi. We only
|
|
|
|
// handle bit operations.
|
|
|
|
ASSERT(Token::IsBitOp(op_));
|
|
|
|
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ Abort("Should not fall through!");
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&non_smi_input_);
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ AbortIfSmi(tos_register_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This routine uses the registers from r2 to r6. At the moment they are
|
|
|
|
// not used by the register allocator, but when they are it should use
|
|
|
|
// SpillAll and MergeTo like DeferredInlineSmiOperation::Generate() above.
|
|
|
|
|
|
|
|
Register heap_number_map = r7;
|
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ ldr(r3, FieldMemOperand(tos_register_, HeapNumber::kMapOffset));
|
|
|
|
__ cmp(r3, heap_number_map);
|
|
|
|
// Not a number, fall back to the GenericBinaryOpStub.
|
|
|
|
__ b(ne, entry_label());
|
|
|
|
|
|
|
|
Register int32 = r2;
|
|
|
|
// Not a 32bits signed int, fall back to the GenericBinaryOpStub.
|
2011-02-04 10:52:19 +00:00
|
|
|
__ ConvertToInt32(tos_register_, int32, r4, r5, d0, entry_label());
|
2010-09-02 08:30:52 +00:00
|
|
|
|
|
|
|
// tos_register_ (r0 or r1): Original heap number.
|
|
|
|
// int32: signed 32bits int.
|
|
|
|
|
|
|
|
Label result_not_a_smi;
|
|
|
|
int shift_value = value_ & 0x1f;
|
|
|
|
switch (op_) {
|
|
|
|
case Token::BIT_OR: __ orr(int32, int32, Operand(value_)); break;
|
|
|
|
case Token::BIT_XOR: __ eor(int32, int32, Operand(value_)); break;
|
|
|
|
case Token::BIT_AND: __ and_(int32, int32, Operand(value_)); break;
|
|
|
|
case Token::SAR:
|
|
|
|
ASSERT(!reversed_);
|
|
|
|
if (shift_value != 0) {
|
|
|
|
__ mov(int32, Operand(int32, ASR, shift_value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Token::SHR:
|
|
|
|
ASSERT(!reversed_);
|
|
|
|
if (shift_value != 0) {
|
|
|
|
__ mov(int32, Operand(int32, LSR, shift_value), SetCC);
|
|
|
|
} else {
|
|
|
|
// SHR is special because it is required to produce a positive answer.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(int32, Operand(0, RelocInfo::NONE));
|
2010-09-02 08:30:52 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-09-02 08:30:52 +00:00
|
|
|
__ b(mi, &result_not_a_smi);
|
|
|
|
} else {
|
|
|
|
// Non VFP code cannot convert from unsigned to double, so fall back
|
|
|
|
// to GenericBinaryOpStub.
|
|
|
|
__ b(mi, entry_label());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Token::SHL:
|
|
|
|
ASSERT(!reversed_);
|
|
|
|
if (shift_value != 0) {
|
|
|
|
__ mov(int32, Operand(int32, LSL, shift_value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
// Check that the *signed* result fits in a smi. Not necessary for AND, SAR
|
|
|
|
// if the shift if more than 0 or SHR if the shit is more than 1.
|
2011-03-15 21:56:12 +00:00
|
|
|
if (!( (op_ == Token::AND && value_ >= 0) ||
|
2010-09-02 08:30:52 +00:00
|
|
|
((op_ == Token::SAR) && (shift_value > 0)) ||
|
|
|
|
((op_ == Token::SHR) && (shift_value > 1)))) {
|
|
|
|
__ add(r3, int32, Operand(0x40000000), SetCC);
|
|
|
|
__ b(mi, &result_not_a_smi);
|
|
|
|
}
|
|
|
|
__ mov(tos_register_, Operand(int32, LSL, kSmiTagSize));
|
|
|
|
Exit();
|
|
|
|
|
|
|
|
if (result_not_a_smi.is_linked()) {
|
|
|
|
__ bind(&result_not_a_smi);
|
|
|
|
if (overwrite_mode_ != OVERWRITE_LEFT) {
|
|
|
|
ASSERT((overwrite_mode_ == NO_OVERWRITE) ||
|
|
|
|
(overwrite_mode_ == OVERWRITE_RIGHT));
|
|
|
|
// If the allocation fails, fall back to the GenericBinaryOpStub.
|
|
|
|
__ AllocateHeapNumber(r4, r5, r6, heap_number_map, entry_label());
|
|
|
|
// Nothing can go wrong now, so overwrite tos.
|
|
|
|
__ mov(tos_register_, Operand(r4));
|
|
|
|
}
|
|
|
|
|
|
|
|
// int32: answer as signed 32bits integer.
|
|
|
|
// tos_register_: Heap number to write the answer into.
|
|
|
|
WriteNonSmiAnswer(int32, tos_register_, r3);
|
|
|
|
|
|
|
|
Exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredInlineSmiOperation::GenerateAnswerOutOfRange() {
|
|
|
|
// The input from a bitwise operation were Smis but the result cannot fit
|
2010-10-20 12:01:17 +00:00
|
|
|
// into a Smi, so we store it into a heap number. VirtualFrame::scratch0()
|
|
|
|
// holds the untagged result to be converted. tos_register_ contains the
|
|
|
|
// input. See the calls to JumpToAnswerOutOfRange to see how we got here.
|
2010-09-02 08:30:52 +00:00
|
|
|
ASSERT(Token::IsBitOp(op_));
|
|
|
|
ASSERT(!reversed_);
|
|
|
|
|
2010-10-20 12:01:17 +00:00
|
|
|
Register untagged_result = VirtualFrame::scratch0();
|
|
|
|
|
2010-09-02 08:30:52 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ Abort("Should not fall through!");
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&answer_out_of_range_);
|
|
|
|
if (((value_ & 0x1f) == 0) && (op_ == Token::SHR)) {
|
2010-10-20 12:01:17 +00:00
|
|
|
// >>> 0 is a special case where the untagged_result register is not set up
|
|
|
|
// yet. We untag the input to get it.
|
|
|
|
__ mov(untagged_result, Operand(tos_register_, ASR, kSmiTagSize));
|
2010-09-02 08:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This routine uses the registers from r2 to r6. At the moment they are
|
|
|
|
// not used by the register allocator, but when they are it should use
|
|
|
|
// SpillAll and MergeTo like DeferredInlineSmiOperation::Generate() above.
|
|
|
|
|
|
|
|
// Allocate the result heap number.
|
2010-10-20 12:01:17 +00:00
|
|
|
Register heap_number_map = VirtualFrame::scratch1();
|
2010-09-02 08:30:52 +00:00
|
|
|
Register heap_number = r4;
|
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
// If the allocation fails, fall back to the GenericBinaryOpStub.
|
|
|
|
__ AllocateHeapNumber(heap_number, r5, r6, heap_number_map, entry_label());
|
2010-10-20 12:01:17 +00:00
|
|
|
WriteNonSmiAnswer(untagged_result, heap_number, r3);
|
2010-09-02 08:30:52 +00:00
|
|
|
__ mov(tos_register_, Operand(heap_number));
|
|
|
|
|
|
|
|
Exit();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-07-03 12:44:31 +00:00
|
|
|
static bool PopCountLessThanEqual2(unsigned int x) {
|
|
|
|
x &= x - 1;
|
|
|
|
return (x & (x - 1)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the index of the lowest bit set.
|
|
|
|
static int BitPosition(unsigned x) {
|
|
|
|
int bit_posn = 0;
|
|
|
|
while ((x & 0xf) == 0) {
|
|
|
|
bit_posn += 4;
|
|
|
|
x >>= 4;
|
|
|
|
}
|
|
|
|
while ((x & 1) == 0) {
|
|
|
|
bit_posn++;
|
|
|
|
x >>= 1;
|
|
|
|
}
|
|
|
|
return bit_posn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Can we multiply by x with max two shifts and an add.
|
|
|
|
// This answers yes to all integers from 2 to 10.
|
|
|
|
static bool IsEasyToMultiplyBy(int x) {
|
|
|
|
if (x < 2) return false; // Avoid special cases.
|
|
|
|
if (x > (Smi::kMaxValue + 1) >> 2) return false; // Almost always overflows.
|
|
|
|
if (IsPowerOf2(x)) return true; // Simple shift.
|
|
|
|
if (PopCountLessThanEqual2(x)) return true; // Shift and add and shift.
|
|
|
|
if (IsPowerOf2(x + 1)) return true; // Patterns like 11111.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Can multiply by anything that IsEasyToMultiplyBy returns true for.
|
|
|
|
// Source and destination may be the same register. This routine does
|
|
|
|
// not set carry and overflow the way a mul instruction would.
|
|
|
|
static void InlineMultiplyByKnownInt(MacroAssembler* masm,
|
|
|
|
Register source,
|
|
|
|
Register destination,
|
|
|
|
int known_int) {
|
|
|
|
if (IsPowerOf2(known_int)) {
|
|
|
|
masm->mov(destination, Operand(source, LSL, BitPosition(known_int)));
|
|
|
|
} else if (PopCountLessThanEqual2(known_int)) {
|
|
|
|
int first_bit = BitPosition(known_int);
|
|
|
|
int second_bit = BitPosition(known_int ^ (1 << first_bit));
|
|
|
|
masm->add(destination, source,
|
|
|
|
Operand(source, LSL, second_bit - first_bit));
|
|
|
|
if (first_bit != 0) {
|
|
|
|
masm->mov(destination, Operand(destination, LSL, first_bit));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ASSERT(IsPowerOf2(known_int + 1)); // Patterns like 1111.
|
|
|
|
int the_bit = BitPosition(known_int + 1);
|
|
|
|
masm->rsb(destination, source, Operand(source, LSL, the_bit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-29 13:09:31 +00:00
|
|
|
void CodeGenerator::SmiOperation(Token::Value op,
|
|
|
|
Handle<Object> value,
|
|
|
|
bool reversed,
|
|
|
|
OverwriteMode mode) {
|
2010-04-08 22:30:30 +00:00
|
|
|
int int_value = Smi::cast(*value)->value();
|
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
bool both_sides_are_smi = frame_->KnownSmiAt(0);
|
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
bool something_to_inline;
|
|
|
|
switch (op) {
|
|
|
|
case Token::ADD:
|
|
|
|
case Token::SUB:
|
|
|
|
case Token::BIT_AND:
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR: {
|
|
|
|
something_to_inline = true;
|
|
|
|
break;
|
|
|
|
}
|
2010-06-02 09:37:02 +00:00
|
|
|
case Token::SHL: {
|
|
|
|
something_to_inline = (both_sides_are_smi || !reversed);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
case Token::SHR:
|
|
|
|
case Token::SAR: {
|
|
|
|
if (reversed) {
|
|
|
|
something_to_inline = false;
|
|
|
|
} else {
|
|
|
|
something_to_inline = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::MOD: {
|
|
|
|
if (reversed || int_value < 2 || !IsPowerOf2(int_value)) {
|
|
|
|
something_to_inline = false;
|
|
|
|
} else {
|
|
|
|
something_to_inline = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::MUL: {
|
|
|
|
if (!IsEasyToMultiplyBy(int_value)) {
|
|
|
|
something_to_inline = false;
|
|
|
|
} else {
|
|
|
|
something_to_inline = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
something_to_inline = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!something_to_inline) {
|
|
|
|
if (!reversed) {
|
2010-04-09 18:25:51 +00:00
|
|
|
// Push the rhs onto the virtual frame by putting it in a TOS register.
|
|
|
|
Register rhs = frame_->GetTOSRegister();
|
|
|
|
__ mov(rhs, Operand(value));
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->EmitPush(rhs, TypeInfo::Smi());
|
|
|
|
GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, int_value);
|
2010-04-08 22:30:30 +00:00
|
|
|
} else {
|
2010-04-09 18:25:51 +00:00
|
|
|
// Pop the rhs, then push lhs and rhs in the right order. Only performs
|
|
|
|
// at most one pop, the rest takes place in TOS registers.
|
|
|
|
Register lhs = frame_->GetTOSRegister(); // Get reg for pushing.
|
|
|
|
Register rhs = frame_->PopToRegister(lhs); // Don't use lhs for this.
|
|
|
|
__ mov(lhs, Operand(value));
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->EmitPush(lhs, TypeInfo::Smi());
|
|
|
|
TypeInfo t = both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Unknown();
|
|
|
|
frame_->EmitPush(rhs, t);
|
2010-08-30 11:48:07 +00:00
|
|
|
GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI,
|
|
|
|
GenericBinaryOpStub::kUnknownIntValue);
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We move the top of stack to a register (normally no move is invoved).
|
|
|
|
Register tos = frame_->PopToRegister();
|
|
|
|
switch (op) {
|
|
|
|
case Token::ADD: {
|
|
|
|
DeferredCode* deferred =
|
|
|
|
new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos);
|
|
|
|
|
|
|
|
__ add(tos, tos, Operand(value), SetCC);
|
|
|
|
deferred->Branch(vs);
|
2010-06-02 09:37:02 +00:00
|
|
|
if (!both_sides_are_smi) {
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(ne);
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
deferred->BindExit();
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::SUB: {
|
|
|
|
DeferredCode* deferred =
|
|
|
|
new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos);
|
|
|
|
|
|
|
|
if (reversed) {
|
|
|
|
__ rsb(tos, tos, Operand(value), SetCC);
|
|
|
|
} else {
|
|
|
|
__ sub(tos, tos, Operand(value), SetCC);
|
|
|
|
}
|
|
|
|
deferred->Branch(vs);
|
2010-06-02 09:37:02 +00:00
|
|
|
if (!both_sides_are_smi) {
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(ne);
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
deferred->BindExit();
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case Token::BIT_OR:
|
|
|
|
case Token::BIT_XOR:
|
|
|
|
case Token::BIT_AND: {
|
2010-06-02 09:37:02 +00:00
|
|
|
if (both_sides_are_smi) {
|
|
|
|
switch (op) {
|
|
|
|
case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break;
|
|
|
|
case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break;
|
2010-06-14 11:20:36 +00:00
|
|
|
case Token::BIT_AND: __ And(tos, tos, Operand(value)); break;
|
2010-06-02 09:37:02 +00:00
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
frame_->EmitPush(tos, TypeInfo::Smi());
|
|
|
|
} else {
|
2010-09-02 08:30:52 +00:00
|
|
|
DeferredInlineSmiOperation* deferred =
|
2010-06-02 09:37:02 +00:00
|
|
|
new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos);
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2010-09-02 08:30:52 +00:00
|
|
|
deferred->JumpToNonSmiInput(ne);
|
2010-06-02 09:37:02 +00:00
|
|
|
switch (op) {
|
|
|
|
case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break;
|
|
|
|
case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break;
|
2010-06-14 11:20:36 +00:00
|
|
|
case Token::BIT_AND: __ And(tos, tos, Operand(value)); break;
|
2010-06-02 09:37:02 +00:00
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
deferred->BindExit();
|
2011-03-15 21:56:12 +00:00
|
|
|
TypeInfo result_type = TypeInfo::Integer32();
|
|
|
|
if (op == Token::BIT_AND && int_value >= 0) {
|
|
|
|
result_type = TypeInfo::Smi();
|
|
|
|
}
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->EmitPush(tos, result_type);
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::SHL:
|
2010-06-02 09:37:02 +00:00
|
|
|
if (reversed) {
|
|
|
|
ASSERT(both_sides_are_smi);
|
|
|
|
int max_shift = 0;
|
|
|
|
int max_result = int_value == 0 ? 1 : int_value;
|
|
|
|
while (Smi::IsValid(max_result << 1)) {
|
|
|
|
max_shift++;
|
|
|
|
max_result <<= 1;
|
|
|
|
}
|
|
|
|
DeferredCode* deferred =
|
|
|
|
new DeferredInlineSmiOperation(op, int_value, true, mode, tos);
|
|
|
|
// Mask off the last 5 bits of the shift operand (rhs). This is part
|
|
|
|
// of the definition of shift in JS and we know we have a Smi so we
|
|
|
|
// can safely do this. The masked version gets passed to the
|
|
|
|
// deferred code, but that makes no difference.
|
|
|
|
__ and_(tos, tos, Operand(Smi::FromInt(0x1f)));
|
|
|
|
__ cmp(tos, Operand(Smi::FromInt(max_shift)));
|
|
|
|
deferred->Branch(ge);
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
__ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Untag.
|
|
|
|
__ mov(tos, Operand(Smi::FromInt(int_value))); // Load constant.
|
|
|
|
__ mov(tos, Operand(tos, LSL, scratch)); // Shift constant.
|
|
|
|
deferred->BindExit();
|
|
|
|
TypeInfo result = TypeInfo::Integer32();
|
|
|
|
frame_->EmitPush(tos, result);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fall through!
|
2010-04-08 22:30:30 +00:00
|
|
|
case Token::SHR:
|
|
|
|
case Token::SAR: {
|
|
|
|
ASSERT(!reversed);
|
2010-09-02 08:30:52 +00:00
|
|
|
int shift_value = int_value & 0x1f;
|
2010-08-23 07:53:03 +00:00
|
|
|
TypeInfo result = TypeInfo::Number();
|
|
|
|
|
|
|
|
if (op == Token::SHR) {
|
2010-09-02 08:30:52 +00:00
|
|
|
if (shift_value > 1) {
|
2010-08-23 07:53:03 +00:00
|
|
|
result = TypeInfo::Smi();
|
2010-09-02 08:30:52 +00:00
|
|
|
} else if (shift_value > 0) {
|
2010-08-23 07:53:03 +00:00
|
|
|
result = TypeInfo::Integer32();
|
|
|
|
}
|
|
|
|
} else if (op == Token::SAR) {
|
2010-09-02 08:30:52 +00:00
|
|
|
if (shift_value > 0) {
|
2010-08-23 07:53:03 +00:00
|
|
|
result = TypeInfo::Smi();
|
2010-08-16 15:08:32 +00:00
|
|
|
} else {
|
2010-08-23 07:53:03 +00:00
|
|
|
result = TypeInfo::Integer32();
|
2010-08-16 15:08:32 +00:00
|
|
|
}
|
2010-08-23 07:53:03 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(op == Token::SHL);
|
|
|
|
result = TypeInfo::Integer32();
|
2010-08-16 15:08:32 +00:00
|
|
|
}
|
2010-08-23 07:53:03 +00:00
|
|
|
|
2010-09-02 08:30:52 +00:00
|
|
|
DeferredInlineSmiOperation* deferred =
|
2010-04-08 22:30:30 +00:00
|
|
|
new DeferredInlineSmiOperation(op, shift_value, false, mode, tos);
|
2010-09-02 08:30:52 +00:00
|
|
|
if (!both_sides_are_smi) {
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
deferred->JumpToNonSmiInput(ne);
|
2010-06-02 09:37:02 +00:00
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
switch (op) {
|
|
|
|
case Token::SHL: {
|
|
|
|
if (shift_value != 0) {
|
2010-10-20 12:01:17 +00:00
|
|
|
Register untagged_result = VirtualFrame::scratch0();
|
|
|
|
Register scratch = VirtualFrame::scratch1();
|
2010-05-11 08:27:56 +00:00
|
|
|
int adjusted_shift = shift_value - kSmiTagSize;
|
|
|
|
ASSERT(adjusted_shift >= 0);
|
2010-09-02 08:30:52 +00:00
|
|
|
|
2010-05-11 08:27:56 +00:00
|
|
|
if (adjusted_shift != 0) {
|
2010-10-20 12:01:17 +00:00
|
|
|
__ mov(untagged_result, Operand(tos, LSL, adjusted_shift));
|
|
|
|
} else {
|
|
|
|
__ mov(untagged_result, Operand(tos));
|
2010-05-11 08:27:56 +00:00
|
|
|
}
|
2010-09-02 08:30:52 +00:00
|
|
|
// Check that the *signed* result fits in a smi.
|
2010-10-20 12:01:17 +00:00
|
|
|
__ add(scratch, untagged_result, Operand(0x40000000), SetCC);
|
2010-09-02 08:30:52 +00:00
|
|
|
deferred->JumpToAnswerOutOfRange(mi);
|
2010-10-20 12:01:17 +00:00
|
|
|
__ mov(tos, Operand(untagged_result, LSL, kSmiTagSize));
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::SHR: {
|
|
|
|
if (shift_value != 0) {
|
2010-10-20 12:01:17 +00:00
|
|
|
Register untagged_result = VirtualFrame::scratch0();
|
|
|
|
// Remove tag.
|
|
|
|
__ mov(untagged_result, Operand(tos, ASR, kSmiTagSize));
|
|
|
|
__ mov(untagged_result, Operand(untagged_result, LSR, shift_value));
|
2010-05-11 08:27:56 +00:00
|
|
|
if (shift_value == 1) {
|
2010-09-02 08:30:52 +00:00
|
|
|
// Check that the *unsigned* result fits in a smi.
|
|
|
|
// Neither of the two high-order bits can be set:
|
2010-05-11 08:27:56 +00:00
|
|
|
// - 0x80000000: high bit would be lost when smi tagging
|
2010-09-02 08:30:52 +00:00
|
|
|
// - 0x40000000: this number would convert to negative when Smi
|
|
|
|
// tagging.
|
|
|
|
// These two cases can only happen with shifts by 0 or 1 when
|
|
|
|
// handed a valid smi.
|
2010-10-20 12:01:17 +00:00
|
|
|
__ tst(untagged_result, Operand(0xc0000000));
|
2010-09-02 08:30:52 +00:00
|
|
|
deferred->JumpToAnswerOutOfRange(ne);
|
2010-05-11 08:27:56 +00:00
|
|
|
}
|
2010-10-20 12:01:17 +00:00
|
|
|
__ mov(tos, Operand(untagged_result, LSL, kSmiTagSize));
|
2010-09-02 08:30:52 +00:00
|
|
|
} else {
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(tos, Operand(0, RelocInfo::NONE));
|
2010-09-02 08:30:52 +00:00
|
|
|
deferred->JumpToAnswerOutOfRange(mi);
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Token::SAR: {
|
|
|
|
if (shift_value != 0) {
|
2010-09-02 08:30:52 +00:00
|
|
|
// Do the shift and the tag removal in one operation. If the shift
|
2010-05-11 08:27:56 +00:00
|
|
|
// is 31 bits (the highest possible value) then we emit the
|
2010-09-02 08:30:52 +00:00
|
|
|
// instruction as a shift by 0 which in the ARM ISA means shift
|
|
|
|
// arithmetically by 32.
|
2010-05-11 08:27:56 +00:00
|
|
|
__ mov(tos, Operand(tos, ASR, (kSmiTagSize + shift_value) & 0x1f));
|
|
|
|
__ mov(tos, Operand(tos, LSL, kSmiTagSize));
|
2010-04-08 22:30:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: UNREACHABLE();
|
|
|
|
}
|
|
|
|
deferred->BindExit();
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->EmitPush(tos, result);
|
2010-04-08 22:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::MOD: {
|
|
|
|
ASSERT(!reversed);
|
|
|
|
ASSERT(int_value >= 2);
|
|
|
|
ASSERT(IsPowerOf2(int_value));
|
|
|
|
DeferredCode* deferred =
|
2010-06-02 09:37:02 +00:00
|
|
|
new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos);
|
2010-04-08 22:30:30 +00:00
|
|
|
unsigned mask = (0x80000000u | kSmiTagMask);
|
|
|
|
__ tst(tos, Operand(mask));
|
|
|
|
deferred->Branch(ne); // Go to deferred code on non-Smis and negative.
|
|
|
|
mask = (int_value << kSmiTagSize) - 1;
|
|
|
|
__ and_(tos, tos, Operand(mask));
|
|
|
|
deferred->BindExit();
|
2010-06-02 09:37:02 +00:00
|
|
|
// Mod of positive power of 2 Smi gives a Smi if the lhs is an integer.
|
|
|
|
frame_->EmitPush(
|
|
|
|
tos,
|
|
|
|
both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Number());
|
2010-04-08 22:30:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Token::MUL: {
|
|
|
|
ASSERT(IsEasyToMultiplyBy(int_value));
|
|
|
|
DeferredCode* deferred =
|
2010-06-02 09:37:02 +00:00
|
|
|
new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos);
|
2010-04-08 22:30:30 +00:00
|
|
|
unsigned max_smi_that_wont_overflow = Smi::kMaxValue / int_value;
|
|
|
|
max_smi_that_wont_overflow <<= kSmiTagSize;
|
|
|
|
unsigned mask = 0x80000000u;
|
|
|
|
while ((mask & max_smi_that_wont_overflow) == 0) {
|
|
|
|
mask |= mask >> 1;
|
|
|
|
}
|
|
|
|
mask |= kSmiTagMask;
|
|
|
|
// This does a single mask that checks for a too high value in a
|
|
|
|
// conservative way and for a non-Smi. It also filters out negative
|
|
|
|
// numbers, unfortunately, but since this code is inline we prefer
|
|
|
|
// brevity to comprehensiveness.
|
|
|
|
__ tst(tos, Operand(mask));
|
|
|
|
deferred->Branch(ne);
|
2010-08-25 09:44:44 +00:00
|
|
|
InlineMultiplyByKnownInt(masm_, tos, tos, int_value);
|
2010-04-08 22:30:30 +00:00
|
|
|
deferred->BindExit();
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 08:32:54 +00:00
|
|
|
void CodeGenerator::Comparison(Condition cond,
|
2009-06-29 13:52:13 +00:00
|
|
|
Expression* left,
|
|
|
|
Expression* right,
|
|
|
|
bool strict) {
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
|
|
|
|
if (left != NULL) Load(left);
|
|
|
|
if (right != NULL) Load(right);
|
2009-06-29 13:52:13 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// sp[0] : y
|
|
|
|
// sp[1] : x
|
|
|
|
// result : cc register
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Strict only makes sense for equality comparisons.
|
2011-01-26 08:32:54 +00:00
|
|
|
ASSERT(!strict || cond == eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
Register lhs;
|
|
|
|
Register rhs;
|
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
bool lhs_is_smi;
|
|
|
|
bool rhs_is_smi;
|
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
// We load the top two stack positions into registers chosen by the virtual
|
|
|
|
// frame. This should keep the register shuffling to a minimum.
|
2008-10-02 11:54:32 +00:00
|
|
|
// Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order.
|
2011-01-26 08:32:54 +00:00
|
|
|
if (cond == gt || cond == le) {
|
|
|
|
cond = ReverseCondition(cond);
|
2010-06-02 09:37:02 +00:00
|
|
|
lhs_is_smi = frame_->KnownSmiAt(0);
|
|
|
|
rhs_is_smi = frame_->KnownSmiAt(1);
|
2010-04-08 22:30:30 +00:00
|
|
|
lhs = frame_->PopToRegister();
|
|
|
|
rhs = frame_->PopToRegister(lhs); // Don't pop to the same register again!
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2010-06-02 09:37:02 +00:00
|
|
|
rhs_is_smi = frame_->KnownSmiAt(0);
|
|
|
|
lhs_is_smi = frame_->KnownSmiAt(1);
|
2010-04-08 22:30:30 +00:00
|
|
|
rhs = frame_->PopToRegister();
|
|
|
|
lhs = frame_->PopToRegister(rhs); // Don't pop to the same register again!
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
bool both_sides_are_smi = (lhs_is_smi && rhs_is_smi);
|
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
ASSERT(rhs.is(r0) || rhs.is(r1));
|
|
|
|
ASSERT(lhs.is(r0) || lhs.is(r1));
|
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
JumpTarget exit;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
if (!both_sides_are_smi) {
|
|
|
|
// Now we have the two sides in r0 and r1. We flush any other registers
|
|
|
|
// because the stub doesn't know about register allocation.
|
|
|
|
frame_->SpillAll();
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
Register smi_test_reg;
|
|
|
|
if (lhs_is_smi) {
|
|
|
|
smi_test_reg = rhs;
|
|
|
|
} else if (rhs_is_smi) {
|
|
|
|
smi_test_reg = lhs;
|
|
|
|
} else {
|
|
|
|
__ orr(scratch, lhs, Operand(rhs));
|
|
|
|
smi_test_reg = scratch;
|
|
|
|
}
|
|
|
|
__ tst(smi_test_reg, Operand(kSmiTagMask));
|
|
|
|
JumpTarget smi;
|
|
|
|
smi.Branch(eq);
|
|
|
|
|
|
|
|
// Perform non-smi comparison by stub.
|
|
|
|
// CompareStub takes arguments in r0 and r1, returns <0, >0 or 0 in r0.
|
|
|
|
// We call with 0 args because there are 0 on the stack.
|
2011-01-26 08:32:54 +00:00
|
|
|
CompareStub stub(cond, strict, NO_SMI_COMPARE_IN_STUB, lhs, rhs);
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->CallStub(&stub, 0);
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(r0, Operand(0, RelocInfo::NONE));
|
2010-06-02 09:37:02 +00:00
|
|
|
exit.Jump();
|
|
|
|
|
|
|
|
smi.Bind();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-29 13:52:13 +00:00
|
|
|
// Do smi comparisons by pointer comparison.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(lhs, Operand(rhs));
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Bind();
|
2011-01-26 08:32:54 +00:00
|
|
|
cc_reg_ = cond;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Call the function on the stack with the given arguments.
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args,
|
2010-01-15 13:42:32 +00:00
|
|
|
CallFunctionFlags flags,
|
|
|
|
int position) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// Push the arguments ("left-to-right") on the stack.
|
2009-02-27 13:00:32 +00:00
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Record the position for debugging purposes.
|
2008-12-17 08:45:42 +00:00
|
|
|
CodeForSourcePosition(position);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Use the shared code stub to call the function.
|
2009-05-25 18:29:02 +00:00
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2010-01-15 13:42:32 +00:00
|
|
|
CallFunctionStub call_function(arg_count, in_loop, flags);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallStub(&call_function, arg_count + 1);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Restore context and pop function from the stack.
|
2008-11-05 08:44:54 +00:00
|
|
|
__ ldr(cp, frame_->Context());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop(); // discard the TOS
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
void CodeGenerator::CallApplyLazy(Expression* applicand,
|
|
|
|
Expression* receiver,
|
|
|
|
VariableProxy* arguments,
|
|
|
|
int position) {
|
|
|
|
// An optimized implementation of expressions of the form
|
|
|
|
// x.apply(y, arguments).
|
|
|
|
// If the arguments object of the scope has not been allocated,
|
|
|
|
// and x.apply is Function.prototype.apply, this optimization
|
|
|
|
// just copies y and the arguments of the current function on the
|
|
|
|
// stack, as receiver and arguments, and calls x.
|
|
|
|
// In the implementation comments, we call x the applicand
|
|
|
|
// and y the receiver.
|
|
|
|
|
|
|
|
ASSERT(ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION);
|
|
|
|
ASSERT(arguments->IsArguments());
|
|
|
|
|
|
|
|
// Load applicand.apply onto the stack. This will usually
|
|
|
|
// give us a megamorphic load site. Not super, but it works.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(applicand);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<String> name = FACTORY->LookupAsciiSymbol("apply");
|
2010-05-19 10:29:19 +00:00
|
|
|
frame_->Dup();
|
2010-05-05 06:50:15 +00:00
|
|
|
frame_->CallLoadIC(name, RelocInfo::CODE_TARGET);
|
2010-04-22 12:20:36 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
// Load the receiver and the existing arguments object onto the
|
|
|
|
// expression stack. Avoid allocating the arguments object here.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(receiver);
|
2010-09-24 07:53:59 +00:00
|
|
|
LoadFromSlot(scope()->arguments()->AsSlot(), NOT_INSIDE_TYPEOF);
|
2010-04-22 12:20:36 +00:00
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
// At this point the top two stack elements are probably in registers
|
|
|
|
// since they were just loaded. Ensure they are in regs and get the
|
|
|
|
// regs.
|
|
|
|
Register receiver_reg = frame_->Peek2();
|
|
|
|
Register arguments_reg = frame_->Peek();
|
|
|
|
|
|
|
|
// From now on the frame is spilled.
|
|
|
|
frame_->SpillAll();
|
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
// Emit the source position information after having loaded the
|
|
|
|
// receiver and the arguments.
|
|
|
|
CodeForSourcePosition(position);
|
|
|
|
// Contents of the stack at this point:
|
|
|
|
// sp[0]: arguments object of the current function or the hole.
|
|
|
|
// sp[1]: receiver
|
|
|
|
// sp[2]: applicand.apply
|
|
|
|
// sp[3]: applicand.
|
|
|
|
|
|
|
|
// Check if the arguments object has been lazily allocated
|
|
|
|
// already. If so, just use that instead of copying the arguments
|
|
|
|
// from the stack. This also deals with cases where a local variable
|
|
|
|
// named 'arguments' has been introduced.
|
2010-06-24 07:54:48 +00:00
|
|
|
JumpTarget slow;
|
|
|
|
Label done;
|
2011-01-06 15:53:56 +00:00
|
|
|
__ LoadRoot(ip, Heap::kArgumentsMarkerRootIndex);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(ip, arguments_reg);
|
|
|
|
slow.Branch(ne);
|
2010-04-22 12:20:36 +00:00
|
|
|
|
|
|
|
Label build_args;
|
|
|
|
// Get rid of the arguments object probe.
|
|
|
|
frame_->Drop();
|
|
|
|
// Stack now has 3 elements on it.
|
|
|
|
// Contents of stack at this point:
|
2010-06-24 07:54:48 +00:00
|
|
|
// sp[0]: receiver - in the receiver_reg register.
|
2010-04-22 12:20:36 +00:00
|
|
|
// sp[1]: applicand.apply
|
|
|
|
// sp[2]: applicand.
|
|
|
|
|
|
|
|
// Check that the receiver really is a JavaScript object.
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(receiver_reg, &build_args);
|
2010-04-22 12:20:36 +00:00
|
|
|
// We allow all JSObjects including JSFunctions. As long as
|
|
|
|
// JS_FUNCTION_TYPE is the last instance type and it is right
|
|
|
|
// after LAST_JS_OBJECT_TYPE, we do not have to check the upper
|
|
|
|
// bound.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
|
|
|
|
STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ CompareObjectType(receiver_reg, r2, r3, FIRST_JS_OBJECT_TYPE);
|
2010-04-22 12:20:36 +00:00
|
|
|
__ b(lt, &build_args);
|
|
|
|
|
|
|
|
// Check that applicand.apply is Function.prototype.apply.
|
|
|
|
__ ldr(r0, MemOperand(sp, kPointerSize));
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(r0, &build_args);
|
2010-04-22 12:20:36 +00:00
|
|
|
__ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE);
|
|
|
|
__ b(ne, &build_args);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> apply_code(
|
2011-03-23 13:40:07 +00:00
|
|
|
Isolate::Current()->builtins()->builtin(Builtins::kFunctionApply));
|
2010-08-20 07:10:18 +00:00
|
|
|
__ ldr(r1, FieldMemOperand(r0, JSFunction::kCodeEntryOffset));
|
|
|
|
__ sub(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag));
|
2010-04-22 12:20:36 +00:00
|
|
|
__ cmp(r1, Operand(apply_code));
|
|
|
|
__ b(ne, &build_args);
|
|
|
|
|
|
|
|
// Check that applicand is a function.
|
|
|
|
__ ldr(r1, MemOperand(sp, 2 * kPointerSize));
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfSmi(r1, &build_args);
|
2010-04-22 12:20:36 +00:00
|
|
|
__ CompareObjectType(r1, r2, r3, JS_FUNCTION_TYPE);
|
|
|
|
__ b(ne, &build_args);
|
|
|
|
|
|
|
|
// Copy the arguments to this function possibly from the
|
|
|
|
// adaptor frame below it.
|
|
|
|
Label invoke, adapted;
|
|
|
|
__ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ b(eq, &adapted);
|
|
|
|
|
|
|
|
// No arguments adaptor frame. Copy fixed number of arguments.
|
|
|
|
__ mov(r0, Operand(scope()->num_parameters()));
|
|
|
|
for (int i = 0; i < scope()->num_parameters(); i++) {
|
|
|
|
__ ldr(r2, frame_->ParameterAt(i));
|
|
|
|
__ push(r2);
|
|
|
|
}
|
|
|
|
__ jmp(&invoke);
|
|
|
|
|
|
|
|
// Arguments adaptor frame present. Copy arguments from there, but
|
|
|
|
// avoid copying too many arguments to avoid stack overflows.
|
|
|
|
__ bind(&adapted);
|
|
|
|
static const uint32_t kArgumentsLimit = 1 * KB;
|
|
|
|
__ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ mov(r0, Operand(r0, LSR, kSmiTagSize));
|
|
|
|
__ mov(r3, r0);
|
|
|
|
__ cmp(r0, Operand(kArgumentsLimit));
|
|
|
|
__ b(gt, &build_args);
|
|
|
|
|
|
|
|
// Loop through the arguments pushing them onto the execution
|
|
|
|
// stack. We don't inform the virtual frame of the push, so we don't
|
|
|
|
// have to worry about getting rid of the elements from the virtual
|
|
|
|
// frame.
|
|
|
|
Label loop;
|
|
|
|
// r3 is a small non-negative integer, due to the test above.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(r3, Operand(0, RelocInfo::NONE));
|
2010-04-22 12:20:36 +00:00
|
|
|
__ b(eq, &invoke);
|
|
|
|
// Compute the address of the first argument.
|
|
|
|
__ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2));
|
|
|
|
__ add(r2, r2, Operand(kPointerSize));
|
|
|
|
__ bind(&loop);
|
|
|
|
// Post-decrement argument address by kPointerSize on each iteration.
|
|
|
|
__ ldr(r4, MemOperand(r2, kPointerSize, NegPostIndex));
|
|
|
|
__ push(r4);
|
|
|
|
__ sub(r3, r3, Operand(1), SetCC);
|
|
|
|
__ b(gt, &loop);
|
|
|
|
|
|
|
|
// Invoke the function.
|
|
|
|
__ bind(&invoke);
|
|
|
|
ParameterCount actual(r0);
|
|
|
|
__ InvokeFunction(r1, actual, CALL_FUNCTION);
|
|
|
|
// Drop applicand.apply and applicand from the stack, and push
|
|
|
|
// the result of the function call, but leave the spilled frame
|
|
|
|
// unchanged, with 3 elements, so it is correct when we compile the
|
|
|
|
// slow-case code.
|
|
|
|
__ add(sp, sp, Operand(2 * kPointerSize));
|
|
|
|
__ push(r0);
|
|
|
|
// Stack now has 1 element:
|
|
|
|
// sp[0]: result
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Slow-case: Allocate the arguments object since we know it isn't
|
|
|
|
// there, and fall-through to the slow-case where we call
|
|
|
|
// applicand.apply.
|
|
|
|
__ bind(&build_args);
|
|
|
|
// Stack now has 3 elements, because we have jumped from where:
|
|
|
|
// sp[0]: receiver
|
|
|
|
// sp[1]: applicand.apply
|
|
|
|
// sp[2]: applicand.
|
|
|
|
StoreArgumentsObject(false);
|
|
|
|
|
|
|
|
// Stack and frame now have 4 elements.
|
2010-06-24 07:54:48 +00:00
|
|
|
slow.Bind();
|
2010-04-22 12:20:36 +00:00
|
|
|
|
|
|
|
// Generic computation of x.apply(y, args) with no special optimization.
|
|
|
|
// Flip applicand.apply and applicand on the stack, so
|
|
|
|
// applicand looks like the receiver of the applicand.apply call.
|
|
|
|
// Then process it as a normal function call.
|
|
|
|
__ ldr(r0, MemOperand(sp, 3 * kPointerSize));
|
|
|
|
__ ldr(r1, MemOperand(sp, 2 * kPointerSize));
|
2010-05-26 11:19:39 +00:00
|
|
|
__ Strd(r0, r1, MemOperand(sp, 2 * kPointerSize));
|
2010-04-22 12:20:36 +00:00
|
|
|
|
|
|
|
CallFunctionStub call_function(2, NOT_IN_LOOP, NO_CALL_FUNCTION_FLAGS);
|
|
|
|
frame_->CallStub(&call_function, 3);
|
|
|
|
// The function and its two arguments have been dropped.
|
|
|
|
frame_->Drop(); // Drop the receiver as well.
|
|
|
|
frame_->EmitPush(r0);
|
2010-07-28 12:50:27 +00:00
|
|
|
frame_->SpillAll(); // A spilled frame is also jumping to label done.
|
2010-04-22 12:20:36 +00:00
|
|
|
// Stack now has 1 element:
|
|
|
|
// sp[0]: result
|
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
// Restore the context register after a call.
|
|
|
|
__ ldr(cp, frame_->Context());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
void CodeGenerator::Branch(bool if_true, JumpTarget* target) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(has_cc());
|
2011-01-26 08:32:54 +00:00
|
|
|
Condition cond = if_true ? cc_reg_ : NegateCondition(cc_reg_);
|
|
|
|
target->Branch(cond);
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = al;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::CheckStack() {
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->SpillAll();
|
2009-10-27 14:56:50 +00:00
|
|
|
Comment cmnt(masm_, "[ check stack");
|
|
|
|
__ LoadRoot(ip, Heap::kStackLimitRootIndex);
|
|
|
|
masm_->cmp(sp, Operand(ip));
|
|
|
|
StackCheckStub stub;
|
|
|
|
// Call the stub if lower.
|
2010-11-17 14:48:43 +00:00
|
|
|
masm_->mov(ip,
|
2009-10-27 14:56:50 +00:00
|
|
|
Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()),
|
|
|
|
RelocInfo::CODE_TARGET),
|
|
|
|
LeaveCC,
|
|
|
|
lo);
|
2010-11-17 14:48:43 +00:00
|
|
|
masm_->Call(ip, lo);
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
for (int i = 0; frame_ != NULL && i < statements->length(); i++) {
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(statements->at(i));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitBlock(Block* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Block");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
2010-05-31 08:52:57 +00:00
|
|
|
VisitStatements(node->statements());
|
2009-02-27 13:00:32 +00:00
|
|
|
if (node->break_target()->is_linked()) {
|
|
|
|
node->break_target()->Bind();
|
|
|
|
}
|
2009-03-11 10:25:48 +00:00
|
|
|
node->break_target()->Unuse();
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
|
2009-10-22 10:07:45 +00:00
|
|
|
frame_->EmitPush(cp);
|
2010-05-03 10:22:25 +00:00
|
|
|
frame_->EmitPush(Operand(pairs));
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0)));
|
2011-03-02 04:53:43 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(strict_mode_flag())));
|
2010-05-03 10:22:25 +00:00
|
|
|
|
2011-03-02 04:53:43 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDeclareGlobals, 4);
|
2008-10-02 11:54:32 +00:00
|
|
|
// The result is discarded.
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitDeclaration(Declaration* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Declaration");
|
|
|
|
Variable* var = node->proxy()->var();
|
|
|
|
ASSERT(var != NULL); // must have been resolved
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = var->AsSlot();
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
// If it was not possible to allocate the variable at compile time,
|
|
|
|
// we need to "declare" it at runtime to make sure it actually
|
|
|
|
// exists in the local context.
|
|
|
|
if (slot != NULL && slot->type() == Slot::LOOKUP) {
|
|
|
|
// Variables with a "LOOKUP" slot were introduced as non-locals
|
|
|
|
// during variable resolution and must have mode DYNAMIC.
|
2009-02-18 13:04:28 +00:00
|
|
|
ASSERT(var->is_dynamic());
|
2008-10-02 11:54:32 +00:00
|
|
|
// For now, just do a runtime call.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(cp);
|
2010-05-03 10:22:25 +00:00
|
|
|
frame_->EmitPush(Operand(var->name()));
|
2008-10-02 11:54:32 +00:00
|
|
|
// Declaration nodes are always declared in only two modes.
|
|
|
|
ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST);
|
|
|
|
PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY;
|
2010-05-03 10:22:25 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(attr)));
|
2008-10-02 11:54:32 +00:00
|
|
|
// Push initial value, if any.
|
|
|
|
// Note: For variables we must not push an initial value (such as
|
|
|
|
// 'undefined') because we may have a (legal) redeclaration and we
|
|
|
|
// must not destroy the current value.
|
|
|
|
if (node->mode() == Variable::CONST) {
|
2010-05-03 10:22:25 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (node->fun() != NULL) {
|
2010-05-03 10:22:25 +00:00
|
|
|
Load(node->fun());
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2010-09-07 11:09:45 +00:00
|
|
|
frame_->EmitPush(Operand(0, RelocInfo::NONE));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-05-03 10:22:25 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDeclareContextSlot, 4);
|
2008-10-06 16:57:38 +00:00
|
|
|
// Ignore the return value (declarations are statements).
|
2010-05-03 10:22:25 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
return;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(!var->is_global());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// If we have a function or a constant, we need to initialize the variable.
|
|
|
|
Expression* val = NULL;
|
|
|
|
if (node->mode() == Variable::CONST) {
|
2011-03-18 20:35:07 +00:00
|
|
|
val = new Literal(FACTORY->the_hole_value());
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
val = node->fun(); // NULL if we don't have a function
|
|
|
|
}
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
if (val != NULL) {
|
2010-07-01 15:06:24 +00:00
|
|
|
WriteBarrierCharacter wb_info =
|
|
|
|
val->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI;
|
|
|
|
if (val->AsLiteral() != NULL) wb_info = NEVER_NEWSPACE;
|
2010-05-03 10:22:25 +00:00
|
|
|
// Set initial value.
|
|
|
|
Reference target(this, node->proxy());
|
|
|
|
Load(val);
|
2010-07-01 15:06:24 +00:00
|
|
|
target.SetValue(NOT_CONST_INIT, wb_info);
|
2010-05-03 10:22:25 +00:00
|
|
|
|
2009-02-02 12:05:13 +00:00
|
|
|
// Get rid of the assigned value (declarations are statements).
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ExpressionStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-10-02 11:54:32 +00:00
|
|
|
Expression* expression = node->expression();
|
|
|
|
expression->MarkAsStatement();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(expression);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop();
|
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "// EmptyStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-10-02 11:54:32 +00:00
|
|
|
// nothing to do
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitIfStatement(IfStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ IfStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
// Generate different code depending on which parts of the if statement
|
|
|
|
// are present or not.
|
2008-10-02 11:54:32 +00:00
|
|
|
bool has_then_stm = node->HasThenStatement();
|
|
|
|
bool has_else_stm = node->HasElseStatement();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget exit;
|
2008-10-02 11:54:32 +00:00
|
|
|
if (has_then_stm && has_else_stm) {
|
|
|
|
Comment cmnt(masm_, "[ IfThenElse");
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget then;
|
|
|
|
JumpTarget else_;
|
2008-10-02 11:54:32 +00:00
|
|
|
// if (cond)
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->condition(), &then, &else_, true);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
Branch(false, &else_);
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
// then
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL || then.is_linked()) {
|
|
|
|
then.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->then_statement());
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
if (frame_ != NULL) {
|
|
|
|
exit.Jump();
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
// else
|
2009-02-27 13:00:32 +00:00
|
|
|
if (else_.is_linked()) {
|
|
|
|
else_.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->else_statement());
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (has_then_stm) {
|
|
|
|
Comment cmnt(masm_, "[ IfThen");
|
|
|
|
ASSERT(!has_else_stm);
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget then;
|
2008-10-02 11:54:32 +00:00
|
|
|
// if (cond)
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->condition(), &then, &exit, true);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
Branch(false, &exit);
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
// then
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL || then.is_linked()) {
|
|
|
|
then.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->then_statement());
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (has_else_stm) {
|
|
|
|
Comment cmnt(masm_, "[ IfElse");
|
|
|
|
ASSERT(!has_then_stm);
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget else_;
|
2008-10-02 11:54:32 +00:00
|
|
|
// if (!cond)
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->condition(), &exit, &else_, true);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
Branch(true, &exit);
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
// else
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL || else_.is_linked()) {
|
|
|
|
else_.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->else_statement());
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
} else {
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ If");
|
|
|
|
ASSERT(!has_then_stm && !has_else_stm);
|
|
|
|
// if (cond)
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->condition(), &exit, &exit, false);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
if (has_cc()) {
|
|
|
|
cc_reg_ = al;
|
|
|
|
} else {
|
|
|
|
frame_->Drop();
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// end
|
2009-02-27 13:00:32 +00:00
|
|
|
if (exit.is_linked()) {
|
|
|
|
exit.Bind();
|
|
|
|
}
|
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitContinueStatement(ContinueStatement* node) {
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ContinueStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
|
|
|
node->target()->continue_target()->Jump();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitBreakStatement(BreakStatement* node) {
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ BreakStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
|
|
|
node->target()->break_target()->Jump();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitReturnStatement(ReturnStatement* node) {
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ReturnStatement");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-14 06:57:24 +00:00
|
|
|
CodeForStatementPosition(node);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->expression());
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->PopToR0();
|
|
|
|
frame_->PrepareForReturn();
|
2009-02-27 13:00:32 +00:00
|
|
|
if (function_return_is_shadowed_) {
|
|
|
|
function_return_.Jump();
|
|
|
|
} else {
|
|
|
|
// Pop the result from the frame and prepare the frame for
|
|
|
|
// returning thus making it easier to merge.
|
2010-06-14 11:37:05 +00:00
|
|
|
if (function_return_.is_bound()) {
|
|
|
|
// If the function return label is already bound we reuse the
|
|
|
|
// code by jumping to the return site.
|
|
|
|
function_return_.Jump();
|
|
|
|
} else {
|
|
|
|
function_return_.Bind();
|
|
|
|
GenerateReturnSequence();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2010-06-14 11:37:05 +00:00
|
|
|
|
|
|
|
void CodeGenerator::GenerateReturnSequence() {
|
|
|
|
if (FLAG_trace) {
|
|
|
|
// Push the return value on the stack as the parameter.
|
|
|
|
// Runtime::TraceExit returns the parameter as it is.
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
frame_->CallRuntime(Runtime::kTraceExit, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Add a label for checking the size of the code used for returning.
|
|
|
|
Label check_exit_codesize;
|
|
|
|
masm_->bind(&check_exit_codesize);
|
|
|
|
#endif
|
|
|
|
// Make sure that the constant pool is not emitted inside of the return
|
|
|
|
// sequence.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
|
|
|
// Tear down the frame which will restore the caller's frame pointer and
|
|
|
|
// the link register.
|
|
|
|
frame_->Exit();
|
|
|
|
|
|
|
|
// Here we use masm_-> instead of the __ macro to avoid the code coverage
|
|
|
|
// tool from instrumenting as we rely on the code size here.
|
|
|
|
int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize;
|
|
|
|
masm_->add(sp, sp, Operand(sp_delta));
|
|
|
|
masm_->Jump(lr);
|
|
|
|
DeleteFrame();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-02-09 13:56:35 +00:00
|
|
|
// Check that the size of the code used for returning is large enough
|
|
|
|
// for the debugger's requirements.
|
|
|
|
ASSERT(Assembler::kJSReturnSequenceInstructions <=
|
|
|
|
masm_->InstructionsGeneratedSince(&check_exit_codesize));
|
2010-06-14 11:37:05 +00:00
|
|
|
#endif
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ WithEnterStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->expression());
|
2008-12-18 11:28:13 +00:00
|
|
|
if (node->is_catch_block()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kPushCatchContext, 1);
|
2008-12-18 11:28:13 +00:00
|
|
|
} else {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kPushContext, 1);
|
2008-12-18 11:28:13 +00:00
|
|
|
}
|
2009-04-22 09:25:41 +00:00
|
|
|
#ifdef DEBUG
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget verified_true;
|
2010-04-26 11:41:39 +00:00
|
|
|
__ cmp(r0, cp);
|
2009-04-22 09:25:41 +00:00
|
|
|
verified_true.Branch(eq);
|
|
|
|
__ stop("PushContext: r0 is expected to be the same as cp");
|
|
|
|
verified_true.Bind();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
// Update context local.
|
2008-11-05 08:44:54 +00:00
|
|
|
__ str(cp, frame_->Context());
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-09-12 03:29:06 +00:00
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ WithExitStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-10-02 11:54:32 +00:00
|
|
|
// Pop context.
|
|
|
|
__ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX));
|
|
|
|
// Update context local.
|
2008-11-05 08:44:54 +00:00
|
|
|
__ str(cp, frame_->Context());
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-09-12 03:29:06 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ SwitchStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
2008-09-12 03:29:06 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->tag());
|
2008-10-03 12:04:59 +00:00
|
|
|
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget next_test;
|
|
|
|
JumpTarget fall_through;
|
|
|
|
JumpTarget default_entry;
|
|
|
|
JumpTarget default_exit(JumpTarget::BIDIRECTIONAL);
|
2008-10-02 11:54:32 +00:00
|
|
|
ZoneList<CaseClause*>* cases = node->cases();
|
|
|
|
int length = cases->length();
|
2009-02-27 13:00:32 +00:00
|
|
|
CaseClause* default_clause = NULL;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
CaseClause* clause = cases->at(i);
|
|
|
|
if (clause->is_default()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
// Remember the default clause and compile it at the end.
|
|
|
|
default_clause = clause;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Comment cmnt(masm_, "[ Case clause");
|
|
|
|
// Compile the test.
|
|
|
|
next_test.Bind();
|
|
|
|
next_test.Unuse();
|
|
|
|
// Duplicate TOS.
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->Dup();
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(eq, NULL, clause->label(), true);
|
2009-02-27 13:00:32 +00:00
|
|
|
Branch(false, &next_test);
|
|
|
|
|
|
|
|
// Before entering the body from the test, remove the switch value from
|
|
|
|
// the stack.
|
|
|
|
frame_->Drop();
|
|
|
|
|
|
|
|
// Label the body so that fall through is enabled.
|
|
|
|
if (i > 0 && cases->at(i - 1)->is_default()) {
|
|
|
|
default_exit.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2009-02-27 13:00:32 +00:00
|
|
|
fall_through.Bind();
|
|
|
|
fall_through.Unuse();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-05-31 08:52:57 +00:00
|
|
|
VisitStatements(clause->statements());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// If control flow can fall through from the body, jump to the next body
|
|
|
|
// or the end of the statement.
|
|
|
|
if (frame_ != NULL) {
|
|
|
|
if (i < length - 1 && cases->at(i + 1)->is_default()) {
|
|
|
|
default_entry.Jump();
|
|
|
|
} else {
|
|
|
|
fall_through.Jump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// The final "test" removes the switch value.
|
|
|
|
next_test.Bind();
|
|
|
|
frame_->Drop();
|
|
|
|
|
|
|
|
// If there is a default clause, compile it.
|
|
|
|
if (default_clause != NULL) {
|
|
|
|
Comment cmnt(masm_, "[ Default clause");
|
|
|
|
default_entry.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
VisitStatements(default_clause->statements());
|
2009-02-27 13:00:32 +00:00
|
|
|
// If control flow can fall out of the default and there is a case after
|
2010-06-24 07:54:48 +00:00
|
|
|
// it, jump to that case's body.
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL && default_exit.is_bound()) {
|
|
|
|
default_exit.Jump();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
if (fall_through.is_linked()) {
|
|
|
|
fall_through.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
if (node->break_target()->is_linked()) {
|
|
|
|
node->break_target()->Bind();
|
|
|
|
}
|
2009-03-11 10:25:48 +00:00
|
|
|
node->break_target()->Unuse();
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2009-10-12 13:14:06 +00:00
|
|
|
Comment cmnt(masm_, "[ DoWhileStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
JumpTarget body(JumpTarget::BIDIRECTIONAL);
|
2010-04-15 14:06:57 +00:00
|
|
|
IncrementLoopNesting();
|
2009-10-12 13:14:06 +00:00
|
|
|
|
|
|
|
// Label the top of the loop for the backward CFG edge. If the test
|
|
|
|
// is always true we can use the continue target, and if the test is
|
|
|
|
// always false there is no need.
|
|
|
|
ConditionAnalysis info = AnalyzeCondition(node->cond());
|
|
|
|
switch (info) {
|
|
|
|
case ALWAYS_TRUE:
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
node->continue_target()->Bind();
|
|
|
|
break;
|
|
|
|
case ALWAYS_FALSE:
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
break;
|
|
|
|
case DONT_KNOW:
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
body.Bind();
|
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
CheckStack(); // TODO(1222600): ignore if body contains calls.
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->body());
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-12-01 10:25:29 +00:00
|
|
|
// Compile the test.
|
2009-10-12 13:14:06 +00:00
|
|
|
switch (info) {
|
|
|
|
case ALWAYS_TRUE:
|
|
|
|
// If control can fall off the end of the body, jump back to the
|
|
|
|
// top.
|
|
|
|
if (has_valid_frame()) {
|
|
|
|
node->continue_target()->Jump();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ALWAYS_FALSE:
|
|
|
|
// If we have a continue in the body, we only have to bind its
|
|
|
|
// jump target.
|
|
|
|
if (node->continue_target()->is_linked()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
node->continue_target()->Bind();
|
|
|
|
}
|
2009-10-12 13:14:06 +00:00
|
|
|
break;
|
|
|
|
case DONT_KNOW:
|
|
|
|
// We have to compile the test expression if it can be reached by
|
|
|
|
// control flow falling out of the body or via continue.
|
|
|
|
if (node->continue_target()->is_linked()) {
|
|
|
|
node->continue_target()->Bind();
|
|
|
|
}
|
|
|
|
if (has_valid_frame()) {
|
2009-11-16 21:59:31 +00:00
|
|
|
Comment cmnt(masm_, "[ DoWhileCondition");
|
|
|
|
CodeForDoWhileConditionPosition(node);
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->cond(), &body, node->break_target(), true);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (has_valid_frame()) {
|
2009-10-12 13:14:06 +00:00
|
|
|
// A invalid frame here indicates that control did not
|
|
|
|
// fall out of the test expression.
|
|
|
|
Branch(true, &body);
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-10-12 13:14:06 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
if (node->break_target()->is_linked()) {
|
|
|
|
node->break_target()->Bind();
|
|
|
|
}
|
2010-04-15 14:06:57 +00:00
|
|
|
DecrementLoopNesting();
|
2009-10-12 13:14:06 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void CodeGenerator::VisitWhileStatement(WhileStatement* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ WhileStatement");
|
|
|
|
CodeForStatementPosition(node);
|
2008-10-02 11:14:50 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
// If the test is never true and has no side effects there is no need
|
|
|
|
// to compile the test or body.
|
|
|
|
ConditionAnalysis info = AnalyzeCondition(node->cond());
|
|
|
|
if (info == ALWAYS_FALSE) return;
|
2008-09-11 08:44:32 +00:00
|
|
|
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
2010-04-15 14:06:57 +00:00
|
|
|
IncrementLoopNesting();
|
2009-10-12 13:14:06 +00:00
|
|
|
|
|
|
|
// Label the top of the loop with the continue target for the backward
|
|
|
|
// CFG edge.
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
node->continue_target()->Bind();
|
|
|
|
|
|
|
|
if (info == DONT_KNOW) {
|
2010-06-24 07:54:48 +00:00
|
|
|
JumpTarget body(JumpTarget::BIDIRECTIONAL);
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->cond(), &body, node->break_target(), true);
|
2009-10-12 13:14:06 +00:00
|
|
|
if (has_valid_frame()) {
|
|
|
|
// A NULL frame indicates that control did not fall out of the
|
|
|
|
// test expression.
|
|
|
|
Branch(false, node->break_target());
|
|
|
|
}
|
|
|
|
if (has_valid_frame() || body.is_linked()) {
|
|
|
|
body.Bind();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2009-10-12 13:14:06 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
if (has_valid_frame()) {
|
|
|
|
CheckStack(); // TODO(1222600): ignore if body contains calls.
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->body());
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
// If control flow can fall out of the body, jump back to the top.
|
|
|
|
if (has_valid_frame()) {
|
|
|
|
node->continue_target()->Jump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node->break_target()->is_linked()) {
|
|
|
|
node->break_target()->Bind();
|
|
|
|
}
|
2010-04-15 14:06:57 +00:00
|
|
|
DecrementLoopNesting();
|
2009-10-12 13:14:06 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void CodeGenerator::VisitForStatement(ForStatement* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ ForStatement");
|
|
|
|
CodeForStatementPosition(node);
|
|
|
|
if (node->init() != NULL) {
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->init());
|
2009-10-12 13:14:06 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
// If the test is never true there is no need to compile the test or
|
|
|
|
// body.
|
|
|
|
ConditionAnalysis info = AnalyzeCondition(node->cond());
|
|
|
|
if (info == ALWAYS_FALSE) return;
|
|
|
|
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
2010-04-15 14:06:57 +00:00
|
|
|
IncrementLoopNesting();
|
2009-10-12 13:14:06 +00:00
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
// We know that the loop index is a smi if it is not modified in the
|
|
|
|
// loop body and it is checked against a constant limit in the loop
|
|
|
|
// condition. In this case, we reset the static type information of the
|
|
|
|
// loop index to smi before compiling the body, the update expression, and
|
|
|
|
// the bottom check of the loop condition.
|
|
|
|
TypeInfoCodeGenState type_info_scope(this,
|
|
|
|
node->is_fast_smi_loop() ?
|
2010-09-24 07:53:59 +00:00
|
|
|
node->loop_variable()->AsSlot() :
|
|
|
|
NULL,
|
2010-06-02 09:37:02 +00:00
|
|
|
TypeInfo::Smi());
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
// If there is no update statement, label the top of the loop with the
|
|
|
|
// continue target, otherwise with the loop target.
|
|
|
|
JumpTarget loop(JumpTarget::BIDIRECTIONAL);
|
|
|
|
if (node->next() == NULL) {
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
node->continue_target()->Bind();
|
|
|
|
} else {
|
2010-05-10 11:32:25 +00:00
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-10-12 13:14:06 +00:00
|
|
|
loop.Bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the test is always true, there is no need to compile it.
|
|
|
|
if (info == DONT_KNOW) {
|
|
|
|
JumpTarget body;
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->cond(), &body, node->break_target(), true);
|
2009-10-12 13:14:06 +00:00
|
|
|
if (has_valid_frame()) {
|
|
|
|
Branch(false, node->break_target());
|
|
|
|
}
|
|
|
|
if (has_valid_frame() || body.is_linked()) {
|
|
|
|
body.Bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_valid_frame()) {
|
|
|
|
CheckStack(); // TODO(1222600): ignore if body contains calls.
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->body());
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
if (node->next() == NULL) {
|
|
|
|
// If there is no update statement and control flow can fall out
|
|
|
|
// of the loop, jump directly to the continue label.
|
2009-02-27 13:00:32 +00:00
|
|
|
if (has_valid_frame()) {
|
2009-10-12 13:14:06 +00:00
|
|
|
node->continue_target()->Jump();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If there is an update statement and control flow can reach it
|
|
|
|
// via falling out of the body of the loop or continuing, we
|
|
|
|
// compile the update statement.
|
|
|
|
if (node->continue_target()->is_linked()) {
|
|
|
|
node->continue_target()->Bind();
|
|
|
|
}
|
|
|
|
if (has_valid_frame()) {
|
|
|
|
// Record source position of the statement as this code which is
|
|
|
|
// after the code for the body actually belongs to the loop
|
|
|
|
// statement and not the body.
|
|
|
|
CodeForStatementPosition(node);
|
2010-05-31 08:52:57 +00:00
|
|
|
Visit(node->next());
|
2009-10-12 13:14:06 +00:00
|
|
|
loop.Jump();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
if (node->break_target()->is_linked()) {
|
|
|
|
node->break_target()->Bind();
|
|
|
|
}
|
2010-04-15 14:06:57 +00:00
|
|
|
DecrementLoopNesting();
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-09-11 08:44:32 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitForInStatement(ForInStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ForInStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-09-11 08:44:32 +00:00
|
|
|
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget primitive;
|
|
|
|
JumpTarget jsobject;
|
|
|
|
JumpTarget fixed_array;
|
|
|
|
JumpTarget entry(JumpTarget::BIDIRECTIONAL);
|
|
|
|
JumpTarget end_del_check;
|
|
|
|
JumpTarget exit;
|
2008-10-02 11:14:50 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get the object to enumerate over (converted to JSObject).
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->enumerable());
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2010-08-16 11:43:30 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2008-10-02 11:54:32 +00:00
|
|
|
// Both SpiderMonkey and kjs ignore null and undefined in contrast
|
|
|
|
// to the specification. 12.6.4 mandates a call to ToObject.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPop(r0);
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ cmp(r0, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Branch(eq);
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kNullValueRootIndex);
|
|
|
|
__ cmp(r0, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Stack layout in body:
|
|
|
|
// [iteration counter (Smi)]
|
|
|
|
// [length of array]
|
|
|
|
// [FixedArray]
|
|
|
|
// [Map or 0]
|
|
|
|
// [Object]
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Check if enumerable is already a JSObject
|
|
|
|
__ tst(r0, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
primitive.Branch(eq);
|
2009-06-10 11:42:13 +00:00
|
|
|
__ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE);
|
2009-02-27 13:00:32 +00:00
|
|
|
jsobject.Branch(hs);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
primitive.Bind();
|
|
|
|
frame_->EmitPush(r0);
|
2009-12-04 12:17:02 +00:00
|
|
|
frame_->InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS, 1);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
jsobject.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get the set of properties (as a FixedArray or Map).
|
2009-12-03 10:24:16 +00:00
|
|
|
// r0: value to be iterated over
|
|
|
|
frame_->EmitPush(r0); // Push the object being iterated over.
|
|
|
|
|
|
|
|
// Check cache validity in generated code. This is a fast case for
|
|
|
|
// the JSObject::IsSimpleEnum cache validity checks. If we cannot
|
|
|
|
// guarantee cache validity, call the runtime system to check cache
|
|
|
|
// validity or get the property names in a fixed array.
|
|
|
|
JumpTarget call_runtime;
|
|
|
|
JumpTarget loop(JumpTarget::BIDIRECTIONAL);
|
|
|
|
JumpTarget check_prototype;
|
|
|
|
JumpTarget use_cache;
|
|
|
|
__ mov(r1, Operand(r0));
|
|
|
|
loop.Bind();
|
|
|
|
// Check that there are no elements.
|
|
|
|
__ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset));
|
|
|
|
__ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex);
|
|
|
|
__ cmp(r2, r4);
|
|
|
|
call_runtime.Branch(ne);
|
|
|
|
// Check that instance descriptors are not empty so that we can
|
|
|
|
// check for an enum cache. Leave the map in r3 for the subsequent
|
|
|
|
// prototype load.
|
|
|
|
__ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ ldr(r2, FieldMemOperand(r3, Map::kInstanceDescriptorsOffset));
|
|
|
|
__ LoadRoot(ip, Heap::kEmptyDescriptorArrayRootIndex);
|
|
|
|
__ cmp(r2, ip);
|
|
|
|
call_runtime.Branch(eq);
|
|
|
|
// Check that there in an enum cache in the non-empty instance
|
|
|
|
// descriptors. This is the case if the next enumeration index
|
|
|
|
// field does not contain a smi.
|
|
|
|
__ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumerationIndexOffset));
|
|
|
|
__ tst(r2, Operand(kSmiTagMask));
|
|
|
|
call_runtime.Branch(eq);
|
|
|
|
// For all objects but the receiver, check that the cache is empty.
|
|
|
|
// r4: empty fixed array root.
|
|
|
|
__ cmp(r1, r0);
|
|
|
|
check_prototype.Branch(eq);
|
|
|
|
__ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset));
|
|
|
|
__ cmp(r2, r4);
|
|
|
|
call_runtime.Branch(ne);
|
|
|
|
check_prototype.Bind();
|
|
|
|
// Load the prototype from the map and loop if non-null.
|
|
|
|
__ ldr(r1, FieldMemOperand(r3, Map::kPrototypeOffset));
|
|
|
|
__ LoadRoot(ip, Heap::kNullValueRootIndex);
|
|
|
|
__ cmp(r1, ip);
|
|
|
|
loop.Branch(ne);
|
|
|
|
// The enum cache is valid. Load the map of the object being
|
|
|
|
// iterated over and use the cache for the iteration.
|
|
|
|
__ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset));
|
|
|
|
use_cache.Jump();
|
|
|
|
|
|
|
|
call_runtime.Bind();
|
|
|
|
// Call the runtime to get the property names for the object.
|
|
|
|
frame_->EmitPush(r0); // push the object (slot 4) for the runtime call
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kGetPropertyNamesFast, 1);
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2009-12-03 10:24:16 +00:00
|
|
|
// If we got a map from the runtime call, we can do a fast
|
|
|
|
// modification check. Otherwise, we got a fixed array, and we have
|
|
|
|
// to do a slow check.
|
|
|
|
// r0: map or fixed array (result from call to
|
|
|
|
// Runtime::kGetPropertyNamesFast)
|
2008-10-02 11:54:32 +00:00
|
|
|
__ mov(r2, Operand(r0));
|
|
|
|
__ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kMetaMapRootIndex);
|
|
|
|
__ cmp(r1, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
fixed_array.Branch(ne);
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2009-12-03 10:24:16 +00:00
|
|
|
use_cache.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get enum cache
|
2009-12-03 10:24:16 +00:00
|
|
|
// r0: map (either the result from a call to
|
|
|
|
// Runtime::kGetPropertyNamesFast or has been fetched directly from
|
|
|
|
// the object)
|
2008-10-02 11:54:32 +00:00
|
|
|
__ mov(r1, Operand(r0));
|
|
|
|
__ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset));
|
|
|
|
__ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset));
|
|
|
|
__ ldr(r2,
|
|
|
|
FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset));
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0); // map
|
|
|
|
frame_->EmitPush(r2); // enum cache bridge cache
|
2008-10-02 11:54:32 +00:00
|
|
|
__ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(0)));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
entry.Jump();
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
fixed_array.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
__ mov(r1, Operand(Smi::FromInt(0)));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r1); // insert 0 in place of Map
|
|
|
|
frame_->EmitPush(r0);
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Push the length of the array and the initial index onto the stack.
|
|
|
|
__ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(0))); // init index
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Condition.
|
2009-02-27 13:00:32 +00:00
|
|
|
entry.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
// sp[0] : index
|
|
|
|
// sp[1] : array/enum cache length
|
|
|
|
// sp[2] : array or enum cache
|
|
|
|
// sp[3] : 0 or map
|
|
|
|
// sp[4] : enumerable
|
2009-03-11 06:17:19 +00:00
|
|
|
// Grab the current frame's height for the break and continue
|
|
|
|
// targets only after all the state is pushed on the frame.
|
2010-05-10 11:32:25 +00:00
|
|
|
node->break_target()->SetExpectedHeight();
|
|
|
|
node->continue_target()->SetExpectedHeight();
|
2009-03-11 06:17:19 +00:00
|
|
|
|
2010-05-07 20:02:57 +00:00
|
|
|
// Load the current count to r0, load the length to r1.
|
2010-05-26 11:19:39 +00:00
|
|
|
__ Ldrd(r0, r1, frame_->ElementAt(0));
|
2010-04-26 11:41:39 +00:00
|
|
|
__ cmp(r0, r1); // compare to the array length
|
2009-02-27 13:00:32 +00:00
|
|
|
node->break_target()->Branch(hs);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get the i'th entry of the array.
|
2009-02-27 13:00:32 +00:00
|
|
|
__ ldr(r2, frame_->ElementAt(2));
|
2008-10-02 11:54:32 +00:00
|
|
|
__ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get Map or 0.
|
2009-02-27 13:00:32 +00:00
|
|
|
__ ldr(r2, frame_->ElementAt(3));
|
2008-10-02 11:54:32 +00:00
|
|
|
// Check if this (still) matches the map of the enumerable.
|
|
|
|
// If not, we have to filter the key.
|
2009-02-27 13:00:32 +00:00
|
|
|
__ ldr(r1, frame_->ElementAt(4));
|
2008-10-02 11:54:32 +00:00
|
|
|
__ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset));
|
|
|
|
__ cmp(r1, Operand(r2));
|
2009-02-27 13:00:32 +00:00
|
|
|
end_del_check.Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Convert the entry to a string (or null if it isn't a property anymore).
|
2009-02-27 13:00:32 +00:00
|
|
|
__ ldr(r0, frame_->ElementAt(4)); // push enumerable
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
frame_->EmitPush(r3); // push entry
|
2009-12-04 12:17:02 +00:00
|
|
|
frame_->InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS, 2);
|
2010-08-11 13:46:10 +00:00
|
|
|
__ mov(r3, Operand(r0), SetCC);
|
2008-10-02 11:54:32 +00:00
|
|
|
// If the property has been removed while iterating, we just skip it.
|
2009-02-27 13:00:32 +00:00
|
|
|
node->continue_target()->Branch(eq);
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
end_del_check.Bind();
|
|
|
|
// Store the entry in the 'each' expression and take another spin in the
|
|
|
|
// loop. r3: i'th entry of the enum cache (or string there of)
|
|
|
|
frame_->EmitPush(r3); // push entry
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
Reference each(this, node->each());
|
2008-10-02 11:54:32 +00:00
|
|
|
if (!each.is_illegal()) {
|
|
|
|
if (each.size() > 0) {
|
2010-08-16 11:43:30 +00:00
|
|
|
// Loading a reference may leave the frame in an unspilled state.
|
|
|
|
frame_->SpillAll(); // Sync stack to memory.
|
|
|
|
// Get the value (under the reference on the stack) from memory.
|
2009-02-27 13:00:32 +00:00
|
|
|
__ ldr(r0, frame_->ElementAt(each.size()));
|
|
|
|
frame_->EmitPush(r0);
|
2010-07-01 15:06:24 +00:00
|
|
|
each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI);
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->Drop(2); // The result of the set and the extra pushed value.
|
2010-01-27 14:07:12 +00:00
|
|
|
} else {
|
|
|
|
// If the reference was to a slot we rely on the convenient property
|
2010-08-16 11:43:30 +00:00
|
|
|
// that it doesn't matter whether a value (eg, ebx pushed above) is
|
2010-01-27 14:07:12 +00:00
|
|
|
// right on top of or right underneath a zero-sized reference.
|
2010-07-01 15:06:24 +00:00
|
|
|
each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI);
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->Drop(1); // Drop the result of the set operation.
|
2008-08-27 10:11:39 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
// Body.
|
2008-10-02 11:54:32 +00:00
|
|
|
CheckStack(); // TODO(1222600): ignore if body contains calls.
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
Visit(node->body());
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-03-24 08:29:24 +00:00
|
|
|
// Next. Reestablish a spilled frame in case we are coming here via
|
|
|
|
// a continue in the body.
|
2009-02-27 13:00:32 +00:00
|
|
|
node->continue_target()->Bind();
|
2009-03-24 08:29:24 +00:00
|
|
|
frame_->SpillAll();
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPop(r0);
|
|
|
|
__ add(r0, r0, Operand(Smi::FromInt(1)));
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
entry.Jump();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-24 08:29:24 +00:00
|
|
|
// Cleanup. No need to spill because VirtualFrame::Drop is safe for
|
|
|
|
// any frame.
|
2009-02-27 13:00:32 +00:00
|
|
|
node->break_target()->Bind();
|
2008-11-07 08:21:07 +00:00
|
|
|
frame_->Drop(5);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Exit.
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Bind();
|
2009-03-11 10:25:48 +00:00
|
|
|
node->continue_target()->Unuse();
|
|
|
|
node->break_target()->Unuse();
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void CodeGenerator::VisitTryCatchStatement(TryCatchStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2009-10-12 13:14:06 +00:00
|
|
|
Comment cmnt(masm_, "[ TryCatchStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget try_block;
|
|
|
|
JumpTarget exit;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
try_block.Call();
|
2008-10-02 11:54:32 +00:00
|
|
|
// --- Catch block ---
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Store the caught exception in the catch variable.
|
2010-01-13 16:01:15 +00:00
|
|
|
Variable* catch_var = node->catch_var()->var();
|
2010-09-24 07:53:59 +00:00
|
|
|
ASSERT(catch_var != NULL && catch_var->AsSlot() != NULL);
|
|
|
|
StoreToSlot(catch_var->AsSlot(), NOT_CONST_INIT);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Remove the exception from the stack.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
VisitStatements(node->catch_block()->statements());
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
if (frame_ != NULL) {
|
|
|
|
exit.Jump();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// --- Try block ---
|
2009-02-27 13:00:32 +00:00
|
|
|
try_block.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->PushTryHandler(TRY_CATCH_HANDLER);
|
|
|
|
int handler_height = frame_->height();
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-10-22 12:45:33 +00:00
|
|
|
// Shadow the labels for all escapes from the try block, including
|
|
|
|
// returns. During shadowing, the original label is hidden as the
|
|
|
|
// LabelShadow and operations on the original actually affect the
|
|
|
|
// shadowing label.
|
|
|
|
//
|
|
|
|
// We should probably try to unify the escaping labels and the return
|
|
|
|
// label.
|
2009-02-27 13:00:32 +00:00
|
|
|
int nof_escapes = node->escaping_targets()->length();
|
|
|
|
List<ShadowTarget*> shadows(1 + nof_escapes);
|
|
|
|
|
|
|
|
// Add the shadow target for the function return.
|
|
|
|
static const int kReturnShadowIndex = 0;
|
|
|
|
shadows.Add(new ShadowTarget(&function_return_));
|
|
|
|
bool function_return_was_shadowed = function_return_is_shadowed_;
|
|
|
|
function_return_is_shadowed_ = true;
|
|
|
|
ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_);
|
|
|
|
|
|
|
|
// Add the remaining shadow targets.
|
2008-10-02 11:54:32 +00:00
|
|
|
for (int i = 0; i < nof_escapes; i++) {
|
2009-02-27 13:00:32 +00:00
|
|
|
shadows.Add(new ShadowTarget(node->escaping_targets()->at(i)));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Generate code for the statements in the try block.
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
VisitStatements(node->try_block()->statements());
|
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Stop the introduced shadowing and count the number of required unlinks.
|
2008-10-22 12:45:33 +00:00
|
|
|
// After shadowing stops, the original labels are unshadowed and the
|
|
|
|
// LabelShadows represent the formerly shadowing labels.
|
2009-03-09 10:51:57 +00:00
|
|
|
bool has_unlinks = false;
|
2009-03-11 12:08:28 +00:00
|
|
|
for (int i = 0; i < shadows.length(); i++) {
|
2008-10-02 11:54:32 +00:00
|
|
|
shadows[i]->StopShadowing();
|
2009-03-09 10:51:57 +00:00
|
|
|
has_unlinks = has_unlinks || shadows[i]->is_linked();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
function_return_is_shadowed_ = function_return_was_shadowed;
|
|
|
|
|
2009-03-09 10:51:57 +00:00
|
|
|
// Get an external reference to the handler address.
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference handler_address(Isolate::k_handler_address, isolate());
|
2009-03-09 10:51:57 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// If we can fall off the end of the try block, unlink from try chain.
|
|
|
|
if (has_valid_frame()) {
|
2009-06-10 09:00:07 +00:00
|
|
|
// The next handler address is on top of the frame. Unlink from
|
|
|
|
// the handler list and drop the rest of this handler from the
|
|
|
|
// frame.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->EmitPop(r1); // r0 can contain the return value.
|
2009-03-09 10:51:57 +00:00
|
|
|
__ mov(r3, Operand(handler_address));
|
2009-02-27 13:00:32 +00:00
|
|
|
__ str(r1, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1);
|
2009-03-09 10:51:57 +00:00
|
|
|
if (has_unlinks) {
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Jump();
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-10-22 12:45:33 +00:00
|
|
|
// Generate unlink code for the (formerly) shadowing labels that have been
|
2009-03-11 12:08:28 +00:00
|
|
|
// jumped to. Deallocate each shadow target.
|
|
|
|
for (int i = 0; i < shadows.length(); i++) {
|
2008-10-02 11:54:32 +00:00
|
|
|
if (shadows[i]->is_linked()) {
|
|
|
|
// Unlink from try chain;
|
2009-02-27 13:00:32 +00:00
|
|
|
shadows[i]->Bind();
|
|
|
|
// Because we can be jumping here (to spilled code) from unspilled
|
|
|
|
// code, we need to reestablish a spilled frame at this block.
|
|
|
|
frame_->SpillAll();
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Reload sp from the top handler, because some statements that we
|
|
|
|
// break from (eg, for...in) may have left stuff on the stack.
|
2009-03-09 10:51:57 +00:00
|
|
|
__ mov(r3, Operand(handler_address));
|
2008-10-02 11:54:32 +00:00
|
|
|
__ ldr(sp, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->Forget(frame_->height() - handler_height);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->EmitPop(r1); // r0 can contain the return value.
|
2008-10-02 11:54:32 +00:00
|
|
|
__ str(r1, MemOperand(r3));
|
2008-11-07 08:21:07 +00:00
|
|
|
frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1);
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
if (!function_return_is_shadowed_ && i == kReturnShadowIndex) {
|
|
|
|
frame_->PrepareForReturn();
|
|
|
|
}
|
|
|
|
shadows[i]->other_target()->Jump();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Bind();
|
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-07-30 08:49:36 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-10-12 13:14:06 +00:00
|
|
|
void CodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2009-10-12 13:14:06 +00:00
|
|
|
Comment cmnt(masm_, "[ TryFinallyStatement");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// State: Used to keep track of reason for entering the finally
|
|
|
|
// block. Should probably be extended to hold information for
|
|
|
|
// break/continue from within the try block.
|
|
|
|
enum { FALLING, THROWING, JUMPING };
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget try_block;
|
|
|
|
JumpTarget finally_block;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
try_block.Call();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0); // save exception object on the stack
|
2008-10-02 11:54:32 +00:00
|
|
|
// In case of thrown exceptions, this is where we continue.
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(THROWING)));
|
2009-02-27 13:00:32 +00:00
|
|
|
finally_block.Jump();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// --- Try block ---
|
2009-02-27 13:00:32 +00:00
|
|
|
try_block.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->PushTryHandler(TRY_FINALLY_HANDLER);
|
|
|
|
int handler_height = frame_->height();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-22 12:45:33 +00:00
|
|
|
// Shadow the labels for all escapes from the try block, including
|
|
|
|
// returns. Shadowing hides the original label as the LabelShadow and
|
|
|
|
// operations on the original actually affect the shadowing label.
|
|
|
|
//
|
|
|
|
// We should probably try to unify the escaping labels and the return
|
|
|
|
// label.
|
2009-02-27 13:00:32 +00:00
|
|
|
int nof_escapes = node->escaping_targets()->length();
|
|
|
|
List<ShadowTarget*> shadows(1 + nof_escapes);
|
|
|
|
|
|
|
|
// Add the shadow target for the function return.
|
|
|
|
static const int kReturnShadowIndex = 0;
|
|
|
|
shadows.Add(new ShadowTarget(&function_return_));
|
|
|
|
bool function_return_was_shadowed = function_return_is_shadowed_;
|
|
|
|
function_return_is_shadowed_ = true;
|
|
|
|
ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_);
|
|
|
|
|
|
|
|
// Add the remaining shadow targets.
|
2008-10-02 11:54:32 +00:00
|
|
|
for (int i = 0; i < nof_escapes; i++) {
|
2009-02-27 13:00:32 +00:00
|
|
|
shadows.Add(new ShadowTarget(node->escaping_targets()->at(i)));
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Generate code for the statements in the try block.
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
VisitStatements(node->try_block()->statements());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-22 12:45:33 +00:00
|
|
|
// Stop the introduced shadowing and count the number of required unlinks.
|
|
|
|
// After shadowing stops, the original labels are unshadowed and the
|
|
|
|
// LabelShadows represent the formerly shadowing labels.
|
2008-10-02 11:54:32 +00:00
|
|
|
int nof_unlinks = 0;
|
2009-03-11 12:08:28 +00:00
|
|
|
for (int i = 0; i < shadows.length(); i++) {
|
2008-10-02 11:54:32 +00:00
|
|
|
shadows[i]->StopShadowing();
|
|
|
|
if (shadows[i]->is_linked()) nof_unlinks++;
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
function_return_is_shadowed_ = function_return_was_shadowed;
|
|
|
|
|
2009-03-09 10:51:57 +00:00
|
|
|
// Get an external reference to the handler address.
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference handler_address(Isolate::k_handler_address, isolate());
|
2009-03-09 10:51:57 +00:00
|
|
|
|
|
|
|
// If we can fall off the end of the try block, unlink from the try
|
|
|
|
// chain and set the state on the frame to FALLING.
|
2009-02-27 13:00:32 +00:00
|
|
|
if (has_valid_frame()) {
|
2009-06-10 09:00:07 +00:00
|
|
|
// The next handler address is on top of the frame.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->EmitPop(r1);
|
2009-03-09 10:51:57 +00:00
|
|
|
__ mov(r3, Operand(handler_address));
|
|
|
|
__ str(r1, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1);
|
2009-03-09 10:51:57 +00:00
|
|
|
|
|
|
|
// Fake a top of stack value (unneeded when FALLING) and set the
|
|
|
|
// state in r2, then jump around the unlink blocks if any.
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(FALLING)));
|
|
|
|
if (nof_unlinks > 0) {
|
2009-03-09 10:51:57 +00:00
|
|
|
finally_block.Jump();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-09 10:51:57 +00:00
|
|
|
// Generate code to unlink and set the state for the (formerly)
|
2009-03-11 12:08:28 +00:00
|
|
|
// shadowing targets that have been jumped to.
|
|
|
|
for (int i = 0; i < shadows.length(); i++) {
|
2008-10-02 11:54:32 +00:00
|
|
|
if (shadows[i]->is_linked()) {
|
2009-03-09 10:51:57 +00:00
|
|
|
// If we have come from the shadowed return, the return value is
|
|
|
|
// in (a non-refcounted reference to) r0. We must preserve it
|
|
|
|
// until it is pushed.
|
|
|
|
//
|
2009-02-27 13:00:32 +00:00
|
|
|
// Because we can be jumping here (to spilled code) from
|
|
|
|
// unspilled code, we need to reestablish a spilled frame at
|
|
|
|
// this block.
|
|
|
|
shadows[i]->Bind();
|
|
|
|
frame_->SpillAll();
|
2009-03-09 10:51:57 +00:00
|
|
|
|
|
|
|
// Reload sp from the top handler, because some statements that
|
|
|
|
// we break from (eg, for...in) may have left stuff on the
|
|
|
|
// stack.
|
|
|
|
__ mov(r3, Operand(handler_address));
|
|
|
|
__ ldr(sp, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->Forget(frame_->height() - handler_height);
|
2009-03-09 10:51:57 +00:00
|
|
|
|
|
|
|
// Unlink this handler and drop it from the frame. The next
|
2009-06-10 09:00:07 +00:00
|
|
|
// handler address is currently on top of the frame.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0);
|
2009-03-09 10:51:57 +00:00
|
|
|
frame_->EmitPop(r1);
|
|
|
|
__ str(r1, MemOperand(r3));
|
2009-06-10 09:00:07 +00:00
|
|
|
frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1);
|
2009-03-09 10:51:57 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
if (i == kReturnShadowIndex) {
|
2008-10-22 12:45:33 +00:00
|
|
|
// If this label shadowed the function return, materialize the
|
|
|
|
// return value on the stack.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2009-02-27 13:00:32 +00:00
|
|
|
// Fake TOS for targets that shadowed breaks and continues.
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
__ mov(r2, Operand(Smi::FromInt(JUMPING + i)));
|
2009-03-09 10:51:57 +00:00
|
|
|
if (--nof_unlinks > 0) {
|
|
|
|
// If this is not the last unlink block, jump around the next.
|
|
|
|
finally_block.Jump();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// --- Finally block ---
|
2009-02-27 13:00:32 +00:00
|
|
|
finally_block.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Push the state on the stack.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r2);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// We keep two elements on the stack - the (possibly faked) result
|
2009-03-11 06:17:19 +00:00
|
|
|
// and the state - while evaluating the finally block.
|
|
|
|
//
|
2008-10-02 11:54:32 +00:00
|
|
|
// Generate code for the statements in the finally block.
|
2010-08-16 11:43:30 +00:00
|
|
|
{ VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
VisitStatements(node->finally_block()->statements());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
if (has_valid_frame()) {
|
|
|
|
// Restore state and return value or faked TOS.
|
|
|
|
frame_->EmitPop(r2);
|
|
|
|
frame_->EmitPop(r0);
|
2009-03-11 13:14:27 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2009-03-11 13:14:27 +00:00
|
|
|
// Generate code to jump to the right destination for all used
|
|
|
|
// formerly shadowing targets. Deallocate each shadow target.
|
|
|
|
for (int i = 0; i < shadows.length(); i++) {
|
|
|
|
if (has_valid_frame() && shadows[i]->is_bound()) {
|
|
|
|
JumpTarget* original = shadows[i]->other_target();
|
|
|
|
__ cmp(r2, Operand(Smi::FromInt(JUMPING + i)));
|
|
|
|
if (!function_return_is_shadowed_ && i == kReturnShadowIndex) {
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget skip;
|
2009-03-11 13:14:27 +00:00
|
|
|
skip.Branch(ne);
|
|
|
|
frame_->PrepareForReturn();
|
|
|
|
original->Jump();
|
|
|
|
skip.Bind();
|
|
|
|
} else {
|
|
|
|
original->Branch(eq);
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-03-11 13:14:27 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-11 13:14:27 +00:00
|
|
|
if (has_valid_frame()) {
|
2009-02-27 13:00:32 +00:00
|
|
|
// Check if we need to rethrow the exception.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget exit;
|
2009-02-27 13:00:32 +00:00
|
|
|
__ cmp(r2, Operand(Smi::FromInt(THROWING)));
|
|
|
|
exit.Branch(ne);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Rethrow exception.
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
frame_->CallRuntime(Runtime::kReThrow, 1);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
// Done.
|
|
|
|
exit.Bind();
|
|
|
|
}
|
|
|
|
ASSERT(!has_valid_frame() || frame_->height() == original_height);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ DebuggerStatament");
|
2009-02-27 13:00:32 +00:00
|
|
|
CodeForStatementPosition(node);
|
2009-04-20 16:36:13 +00:00
|
|
|
#ifdef ENABLE_DEBUGGER_SUPPORT
|
2010-02-08 13:44:49 +00:00
|
|
|
frame_->DebugBreak();
|
2009-04-20 16:36:13 +00:00
|
|
|
#endif
|
2008-10-24 10:13:22 +00:00
|
|
|
// Ignore the return value.
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
void CodeGenerator::InstantiateFunction(
|
2010-11-22 09:57:21 +00:00
|
|
|
Handle<SharedFunctionInfo> function_info,
|
|
|
|
bool pretenure) {
|
2010-01-12 07:16:49 +00:00
|
|
|
// Use the fast case closure allocation code that allocates in new
|
|
|
|
// space for nested functions that don't need literals cloning.
|
2011-03-17 20:28:17 +00:00
|
|
|
if (!pretenure &&
|
|
|
|
scope()->is_function_scope() &&
|
2011-03-17 20:28:30 +00:00
|
|
|
function_info->num_literals() == 0) {
|
|
|
|
FastNewClosureStub stub(
|
|
|
|
function_info->strict_mode() ? kStrictMode : kNonStrictMode);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(Operand(function_info));
|
|
|
|
frame_->SpillAll();
|
2010-01-12 07:16:49 +00:00
|
|
|
frame_->CallStub(&stub, 1);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
} else {
|
|
|
|
// Create a new closure.
|
|
|
|
frame_->EmitPush(cp);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(Operand(function_info));
|
2010-11-22 09:57:21 +00:00
|
|
|
frame_->EmitPush(Operand(pretenure
|
2011-03-18 20:35:07 +00:00
|
|
|
? FACTORY->true_value()
|
|
|
|
: FACTORY->false_value()));
|
2010-11-22 09:57:21 +00:00
|
|
|
frame_->CallRuntime(Runtime::kNewClosure, 3);
|
2010-01-12 07:16:49 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ FunctionLiteral");
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
// Build the function info and instantiate it.
|
|
|
|
Handle<SharedFunctionInfo> function_info =
|
2010-10-04 14:30:43 +00:00
|
|
|
Compiler::BuildFunctionInfo(node, script());
|
|
|
|
if (function_info.is_null()) {
|
|
|
|
SetStackOverflow();
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(frame_->height() == original_height);
|
|
|
|
return;
|
|
|
|
}
|
2010-11-22 09:57:21 +00:00
|
|
|
InstantiateFunction(function_info, node->pretenure());
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-23 06:04:44 +00:00
|
|
|
void CodeGenerator::VisitSharedFunctionInfoLiteral(
|
|
|
|
SharedFunctionInfoLiteral* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2010-03-23 06:04:44 +00:00
|
|
|
Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
|
2010-11-22 09:57:21 +00:00
|
|
|
InstantiateFunction(node->shared_function_info(), false);
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitConditional(Conditional* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Conditional");
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget then;
|
|
|
|
JumpTarget else_;
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->condition(), &then, &else_, true);
|
2009-07-09 04:22:05 +00:00
|
|
|
if (has_valid_frame()) {
|
2009-07-08 19:43:22 +00:00
|
|
|
Branch(false, &else_);
|
|
|
|
}
|
2009-07-09 04:22:05 +00:00
|
|
|
if (has_valid_frame() || then.is_linked()) {
|
2009-07-08 19:43:22 +00:00
|
|
|
then.Bind();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->then_expression());
|
2009-07-08 19:43:22 +00:00
|
|
|
}
|
|
|
|
if (else_.is_linked()) {
|
2009-07-09 04:22:05 +00:00
|
|
|
JumpTarget exit;
|
|
|
|
if (has_valid_frame()) exit.Jump();
|
2009-07-08 19:43:22 +00:00
|
|
|
else_.Bind();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->else_expression());
|
2009-07-09 04:22:05 +00:00
|
|
|
if (exit.is_linked()) exit.Bind();
|
2009-07-08 19:43:22 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) {
|
2008-10-08 07:24:06 +00:00
|
|
|
if (slot->type() == Slot::LOOKUP) {
|
2009-02-18 13:04:28 +00:00
|
|
|
ASSERT(slot->var()->is_dynamic());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-27 19:24:36 +00:00
|
|
|
// JumpTargets do not yet support merging frames so the frame must be
|
|
|
|
// spilled when jumping to these targets.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget slow;
|
|
|
|
JumpTarget done;
|
2009-02-18 13:54:13 +00:00
|
|
|
|
2010-05-12 09:12:23 +00:00
|
|
|
// Generate fast case for loading from slots that correspond to
|
|
|
|
// local/global variables or arguments unless they are shadowed by
|
|
|
|
// eval-introduced bindings.
|
|
|
|
EmitDynamicLoadFromSlotFastCase(slot,
|
|
|
|
typeof_state,
|
|
|
|
&slow,
|
|
|
|
&done);
|
2009-02-18 13:54:13 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
slow.Bind();
|
|
|
|
frame_->EmitPush(cp);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(slot->var()->name()));
|
2008-09-16 11:40:21 +00:00
|
|
|
|
2008-10-08 07:24:06 +00:00
|
|
|
if (typeof_state == INSIDE_TYPEOF) {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2);
|
2008-10-08 07:24:06 +00:00
|
|
|
} else {
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kLoadContextSlot, 2);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-02-18 13:54:13 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
done.Bind();
|
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-09-16 11:23:02 +00:00
|
|
|
} else {
|
2010-04-08 22:30:30 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2010-06-02 09:37:02 +00:00
|
|
|
TypeInfo info = type_info(slot);
|
|
|
|
frame_->EmitPush(SlotOperand(slot, scratch), info);
|
2010-06-24 07:54:48 +00:00
|
|
|
|
2008-10-08 07:24:06 +00:00
|
|
|
if (slot->var()->mode() == Variable::CONST) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// Const slots may contain 'the hole' value (the constant hasn't been
|
|
|
|
// initialized yet) which needs to be converted into the 'undefined'
|
|
|
|
// value.
|
|
|
|
Comment cmnt(masm_, "[ Unhole const");
|
2010-06-24 07:54:48 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(tos, ip);
|
|
|
|
__ LoadRoot(tos, Heap::kUndefinedValueRootIndex, eq);
|
|
|
|
frame_->EmitPush(tos);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
void CodeGenerator::LoadFromSlotCheckForArguments(Slot* slot,
|
|
|
|
TypeofState state) {
|
2010-06-24 07:54:48 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
2010-04-22 12:20:36 +00:00
|
|
|
LoadFromSlot(slot, state);
|
|
|
|
|
|
|
|
// Bail out quickly if we're not using lazy arguments allocation.
|
|
|
|
if (ArgumentsMode() != LAZY_ARGUMENTS_ALLOCATION) return;
|
|
|
|
|
|
|
|
// ... or if the slot isn't a non-parameter arguments slot.
|
|
|
|
if (slot->type() == Slot::PARAMETER || !slot->is_arguments()) return;
|
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
// Load the loaded value from the stack into a register but leave it on the
|
2010-04-22 12:20:36 +00:00
|
|
|
// stack.
|
2010-06-24 07:54:48 +00:00
|
|
|
Register tos = frame_->Peek();
|
2010-04-22 12:20:36 +00:00
|
|
|
|
|
|
|
// If the loaded value is the sentinel that indicates that we
|
|
|
|
// haven't loaded the arguments object yet, we need to do it now.
|
|
|
|
JumpTarget exit;
|
2011-01-06 15:53:56 +00:00
|
|
|
__ LoadRoot(ip, Heap::kArgumentsMarkerRootIndex);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(tos, ip);
|
2010-04-22 12:20:36 +00:00
|
|
|
exit.Branch(ne);
|
|
|
|
frame_->Drop();
|
|
|
|
StoreArgumentsObject(false);
|
|
|
|
exit.Bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 17:22:57 +00:00
|
|
|
void CodeGenerator::StoreToSlot(Slot* slot, InitState init_state) {
|
|
|
|
ASSERT(slot != NULL);
|
2010-06-24 07:54:48 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
2010-01-12 17:22:57 +00:00
|
|
|
if (slot->type() == Slot::LOOKUP) {
|
|
|
|
ASSERT(slot->var()->is_dynamic());
|
|
|
|
|
|
|
|
// For now, just do a runtime call.
|
|
|
|
frame_->EmitPush(cp);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(slot->var()->name()));
|
2010-01-12 17:22:57 +00:00
|
|
|
|
|
|
|
if (init_state == CONST_INIT) {
|
|
|
|
// Same as the case for a normal store, but ignores attribute
|
|
|
|
// (e.g. READ_ONLY) of context slot so that we can initialize
|
|
|
|
// const properties (introduced via eval("const foo = (some
|
|
|
|
// expr);")). Also, uses the current function context instead of
|
|
|
|
// the top context.
|
|
|
|
//
|
|
|
|
// Note that we must declare the foo upon entry of eval(), via a
|
|
|
|
// context slot declaration, but we cannot initialize it at the
|
|
|
|
// same time, because the const declaration may be at the end of
|
|
|
|
// the eval code (sigh...) and the const variable may have been
|
|
|
|
// used before (where its value is 'undefined'). Thus, we can only
|
|
|
|
// do the initialization when we actually encounter the expression
|
|
|
|
// and when the expression operands are defined and valid, and
|
|
|
|
// thus we need the split into 2 operations: declaration of the
|
|
|
|
// context slot followed by initialization.
|
|
|
|
frame_->CallRuntime(Runtime::kInitializeConstContextSlot, 3);
|
|
|
|
} else {
|
2011-03-02 04:53:43 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(strict_mode_flag())));
|
|
|
|
frame_->CallRuntime(Runtime::kStoreContextSlot, 4);
|
2010-01-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
// Storing a variable must keep the (new) value on the expression
|
|
|
|
// stack. This is necessary for compiling assignment expressions.
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ASSERT(!slot->var()->is_dynamic());
|
2010-04-08 22:30:30 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2010-06-24 07:54:48 +00:00
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2010-01-12 17:22:57 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
// The frame must be spilled when branching to this target.
|
2010-01-12 17:22:57 +00:00
|
|
|
JumpTarget exit;
|
2010-04-08 22:30:30 +00:00
|
|
|
|
2010-01-12 17:22:57 +00:00
|
|
|
if (init_state == CONST_INIT) {
|
|
|
|
ASSERT(slot->var()->mode() == Variable::CONST);
|
|
|
|
// Only the first const initialization must be executed (the slot
|
|
|
|
// still contains 'the hole' value). When the assignment is
|
|
|
|
// executed, the code is identical to a normal store (see below).
|
|
|
|
Comment cmnt(masm_, "[ Init const");
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldr(scratch, SlotOperand(slot, scratch));
|
2010-01-12 17:22:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(scratch, ip);
|
2010-01-12 17:22:57 +00:00
|
|
|
exit.Branch(ne);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We must execute the store. Storing a variable must keep the
|
|
|
|
// (new) value on the stack. This is necessary for compiling
|
|
|
|
// assignment expressions.
|
|
|
|
//
|
|
|
|
// Note: We will reach here even with slot->var()->mode() ==
|
|
|
|
// Variable::CONST because of const declarations which will
|
|
|
|
// initialize consts to 'the hole' value and by doing so, end up
|
|
|
|
// calling this code. r2 may be loaded with context; used below in
|
|
|
|
// RecordWrite.
|
2010-04-08 22:30:30 +00:00
|
|
|
Register tos = frame_->Peek();
|
|
|
|
__ str(tos, SlotOperand(slot, scratch));
|
2010-01-12 17:22:57 +00:00
|
|
|
if (slot->type() == Slot::CONTEXT) {
|
|
|
|
// Skip write barrier if the written value is a smi.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
// We don't use tos any more after here.
|
2010-01-12 17:22:57 +00:00
|
|
|
exit.Branch(eq);
|
2010-04-08 22:30:30 +00:00
|
|
|
// scratch is loaded with context when calling SlotOperand above.
|
2010-01-12 17:22:57 +00:00
|
|
|
int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize;
|
2010-06-24 07:54:48 +00:00
|
|
|
// We need an extra register. Until we have a way to do that in the
|
|
|
|
// virtual frame we will cheat and ask for a free TOS register.
|
|
|
|
Register scratch3 = frame_->GetTOSRegister();
|
|
|
|
__ RecordWrite(scratch, Operand(offset), scratch2, scratch3);
|
2010-01-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
// If we definitely did not jump over the assignment, we do not need
|
|
|
|
// to bind the exit label. Doing so can defeat peephole
|
|
|
|
// optimization.
|
|
|
|
if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) {
|
|
|
|
exit.Bind();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-18 13:54:13 +00:00
|
|
|
void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot,
|
|
|
|
TypeofState typeof_state,
|
2009-02-27 13:00:32 +00:00
|
|
|
JumpTarget* slow) {
|
2009-02-18 13:54:13 +00:00
|
|
|
// Check that no extension objects have been created by calls to
|
|
|
|
// eval from the current scope to the global scope.
|
2010-04-27 19:24:36 +00:00
|
|
|
Register tmp = frame_->scratch0();
|
|
|
|
Register tmp2 = frame_->scratch1();
|
2009-02-18 13:54:13 +00:00
|
|
|
Register context = cp;
|
2009-02-24 13:11:53 +00:00
|
|
|
Scope* s = scope();
|
|
|
|
while (s != NULL) {
|
2009-02-18 13:54:13 +00:00
|
|
|
if (s->num_heap_slots() > 0) {
|
|
|
|
if (s->calls_eval()) {
|
2010-04-27 19:24:36 +00:00
|
|
|
frame_->SpillAll();
|
2009-02-18 13:54:13 +00:00
|
|
|
// Check that extension is NULL.
|
|
|
|
__ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX));
|
|
|
|
__ tst(tmp2, tmp2);
|
2009-02-27 13:00:32 +00:00
|
|
|
slow->Branch(ne);
|
2009-02-18 13:54:13 +00:00
|
|
|
}
|
|
|
|
// Load next context in chain.
|
|
|
|
__ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX));
|
|
|
|
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
|
|
|
|
context = tmp;
|
|
|
|
}
|
|
|
|
// If no outer scope calls eval, we do not need to check more
|
|
|
|
// context extensions.
|
2009-02-24 13:11:53 +00:00
|
|
|
if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break;
|
|
|
|
s = s->outer_scope();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->is_eval_scope()) {
|
2010-04-27 19:24:36 +00:00
|
|
|
frame_->SpillAll();
|
2009-02-24 13:11:53 +00:00
|
|
|
Label next, fast;
|
2010-04-08 22:30:30 +00:00
|
|
|
__ Move(tmp, context);
|
2009-02-24 13:11:53 +00:00
|
|
|
__ bind(&next);
|
|
|
|
// Terminate at global context.
|
|
|
|
__ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kGlobalContextMapRootIndex);
|
|
|
|
__ cmp(tmp2, ip);
|
2009-02-24 13:11:53 +00:00
|
|
|
__ b(eq, &fast);
|
|
|
|
// Check that extension is NULL.
|
|
|
|
__ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX));
|
|
|
|
__ tst(tmp2, tmp2);
|
2009-02-27 13:00:32 +00:00
|
|
|
slow->Branch(ne);
|
2009-02-24 13:11:53 +00:00
|
|
|
// Load next context in chain.
|
|
|
|
__ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX));
|
|
|
|
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset));
|
|
|
|
__ b(&next);
|
|
|
|
__ bind(&fast);
|
2009-02-18 13:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load the global object.
|
|
|
|
LoadGlobal();
|
2010-04-22 07:18:30 +00:00
|
|
|
// Setup the name register and call load IC.
|
2010-05-05 06:50:15 +00:00
|
|
|
frame_->CallLoadIC(slot->var()->name(),
|
|
|
|
typeof_state == INSIDE_TYPEOF
|
|
|
|
? RelocInfo::CODE_TARGET
|
|
|
|
: RelocInfo::CODE_TARGET_CONTEXT);
|
2009-02-18 13:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 09:12:23 +00:00
|
|
|
void CodeGenerator::EmitDynamicLoadFromSlotFastCase(Slot* slot,
|
|
|
|
TypeofState typeof_state,
|
|
|
|
JumpTarget* slow,
|
|
|
|
JumpTarget* done) {
|
|
|
|
// Generate fast-case code for variables that might be shadowed by
|
|
|
|
// eval-introduced variables. Eval is used a lot without
|
|
|
|
// introducing variables. In those cases, we do not want to
|
|
|
|
// perform a runtime call for all variables in the scope
|
|
|
|
// containing the eval.
|
|
|
|
if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) {
|
|
|
|
LoadFromGlobalSlotCheckExtensions(slot, typeof_state, slow);
|
|
|
|
frame_->SpillAll();
|
|
|
|
done->Jump();
|
|
|
|
|
|
|
|
} else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) {
|
|
|
|
frame_->SpillAll();
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot();
|
2010-05-12 09:12:23 +00:00
|
|
|
Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite();
|
|
|
|
if (potential_slot != NULL) {
|
|
|
|
// Generate fast case for locals that rewrite to slots.
|
|
|
|
__ ldr(r0,
|
|
|
|
ContextSlotOperandCheckExtensions(potential_slot,
|
|
|
|
r1,
|
|
|
|
r2,
|
|
|
|
slow));
|
|
|
|
if (potential_slot->var()->mode() == Variable::CONST) {
|
|
|
|
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ cmp(r0, ip);
|
|
|
|
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq);
|
|
|
|
}
|
|
|
|
done->Jump();
|
|
|
|
} else if (rewrite != NULL) {
|
|
|
|
// Generate fast case for argument loads.
|
|
|
|
Property* property = rewrite->AsProperty();
|
|
|
|
if (property != NULL) {
|
|
|
|
VariableProxy* obj_proxy = property->obj()->AsVariableProxy();
|
|
|
|
Literal* key_literal = property->key()->AsLiteral();
|
|
|
|
if (obj_proxy != NULL &&
|
|
|
|
key_literal != NULL &&
|
|
|
|
obj_proxy->IsArguments() &&
|
|
|
|
key_literal->handle()->IsSmi()) {
|
|
|
|
// Load arguments object if there are no eval-introduced
|
|
|
|
// variables. Then load the argument from the arguments
|
|
|
|
// object using keyed load.
|
|
|
|
__ ldr(r0,
|
2010-09-24 07:53:59 +00:00
|
|
|
ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(),
|
2010-05-12 09:12:23 +00:00
|
|
|
r1,
|
|
|
|
r2,
|
|
|
|
slow));
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
__ mov(r1, Operand(key_literal->handle()));
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
EmitKeyedLoad();
|
|
|
|
done->Jump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitSlot(Slot* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-08 07:24:06 +00:00
|
|
|
Comment cmnt(masm_, "[ Slot");
|
2010-04-22 12:20:36 +00:00
|
|
|
LoadFromSlotCheckForArguments(node, NOT_INSIDE_TYPEOF);
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-08 07:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitVariableProxy(VariableProxy* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ VariableProxy");
|
2008-10-10 00:00:52 +00:00
|
|
|
|
2008-10-08 07:24:06 +00:00
|
|
|
Variable* var = node->var();
|
|
|
|
Expression* expr = var->rewrite();
|
2008-10-02 11:54:32 +00:00
|
|
|
if (expr != NULL) {
|
|
|
|
Visit(expr);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2008-10-08 07:24:06 +00:00
|
|
|
ASSERT(var->is_global());
|
|
|
|
Reference ref(this, node);
|
2010-04-08 22:30:30 +00:00
|
|
|
ref.GetValue();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitLiteral(Literal* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Literal");
|
2010-04-08 22:30:30 +00:00
|
|
|
Register reg = frame_->GetTOSRegister();
|
2010-06-02 09:37:02 +00:00
|
|
|
bool is_smi = node->handle()->IsSmi();
|
2010-04-08 22:30:30 +00:00
|
|
|
__ mov(reg, Operand(node->handle()));
|
2010-06-02 09:37:02 +00:00
|
|
|
frame_->EmitPush(reg, is_smi ? TypeInfo::Smi() : TypeInfo::Unknown());
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ RexExp Literal");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
Register tmp = VirtualFrame::scratch0();
|
|
|
|
// Free up a TOS register that can be used to push the literal.
|
|
|
|
Register literal = frame_->GetTOSRegister();
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Retrieve the literal array and check the allocated entry.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the function of this activation.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(tmp, frame_->Function());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the literals array of the function.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(tmp, FieldMemOperand(tmp, JSFunction::kLiteralsOffset));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the literal at the ast saved index.
|
|
|
|
int literal_offset =
|
|
|
|
FixedArray::kHeaderSize + node->literal_index() * kPointerSize;
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(literal, FieldMemOperand(tmp, literal_offset));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-06 13:04:27 +00:00
|
|
|
JumpTarget materialized;
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ cmp(literal, ip);
|
|
|
|
// This branch locks the virtual frame at the done label to match the
|
|
|
|
// one we have here, where the literal register is not on the stack and
|
|
|
|
// nothing is spilled.
|
2010-08-06 13:04:27 +00:00
|
|
|
materialized.Branch(ne);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
// If the entry is undefined we call the runtime system to compute
|
2008-10-02 11:54:32 +00:00
|
|
|
// the literal.
|
2010-06-24 07:54:48 +00:00
|
|
|
// literal array (0)
|
|
|
|
frame_->EmitPush(tmp);
|
|
|
|
// literal index (1)
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(node->literal_index())));
|
|
|
|
// RegExp pattern (2)
|
|
|
|
frame_->EmitPush(Operand(node->pattern()));
|
|
|
|
// RegExp flags (3)
|
|
|
|
frame_->EmitPush(Operand(node->flags()));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kMaterializeRegExpLiteral, 4);
|
2010-06-24 07:54:48 +00:00
|
|
|
__ Move(literal, r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-06 13:04:27 +00:00
|
|
|
materialized.Bind();
|
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(literal);
|
2010-08-06 13:04:27 +00:00
|
|
|
int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(size)));
|
|
|
|
frame_->CallRuntime(Runtime::kAllocateInNewSpace, 1);
|
|
|
|
// TODO(lrn): Use AllocateInNewSpace macro with fallback to runtime.
|
|
|
|
// r0 is newly allocated space.
|
|
|
|
|
|
|
|
// Reuse literal variable with (possibly) a new register, still holding
|
|
|
|
// the materialized boilerplate.
|
|
|
|
literal = frame_->PopToRegister(r0);
|
|
|
|
|
|
|
|
__ CopyFields(r0, literal, tmp.bit(), size / kPointerSize);
|
|
|
|
|
|
|
|
// Push the clone.
|
|
|
|
frame_->EmitPush(r0);
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ObjectLiteral");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
Register literal = frame_->GetTOSRegister();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the function of this activation.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(literal, frame_->Function());
|
2009-12-22 12:41:45 +00:00
|
|
|
// Literal array.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(literal, FieldMemOperand(literal, JSFunction::kLiteralsOffset));
|
|
|
|
frame_->EmitPush(literal);
|
2009-12-22 12:41:45 +00:00
|
|
|
// Literal index.
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(node->literal_index())));
|
2009-12-22 12:41:45 +00:00
|
|
|
// Constant properties.
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(node->constant_properties()));
|
2010-03-11 10:34:29 +00:00
|
|
|
// Should the object literal have fast elements?
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(node->fast_elements() ? 1 : 0)));
|
2009-12-22 12:41:45 +00:00
|
|
|
if (node->depth() > 1) {
|
2010-03-11 10:34:29 +00:00
|
|
|
frame_->CallRuntime(Runtime::kCreateObjectLiteral, 4);
|
2009-12-22 12:41:45 +00:00
|
|
|
} else {
|
2010-03-11 10:34:29 +00:00
|
|
|
frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4);
|
2009-03-23 07:27:47 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0); // save the result
|
2010-10-27 11:37:59 +00:00
|
|
|
|
|
|
|
// Mark all computed expressions that are bound to a key that
|
|
|
|
// is shadowed by a later occurrence of the same key. For the
|
|
|
|
// marked expressions, no store code is emitted.
|
|
|
|
node->CalculateEmitStore();
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
for (int i = 0; i < node->properties()->length(); i++) {
|
2010-02-10 15:06:08 +00:00
|
|
|
// At the start of each iteration, the top of stack contains
|
|
|
|
// the newly created object literal.
|
2008-10-02 11:54:32 +00:00
|
|
|
ObjectLiteral::Property* property = node->properties()->at(i);
|
|
|
|
Literal* key = property->key();
|
|
|
|
Expression* value = property->value();
|
|
|
|
switch (property->kind()) {
|
2009-03-23 07:27:47 +00:00
|
|
|
case ObjectLiteral::Property::CONSTANT:
|
|
|
|
break;
|
|
|
|
case ObjectLiteral::Property::MATERIALIZED_LITERAL:
|
2009-03-24 08:55:11 +00:00
|
|
|
if (CompileTimeValue::IsCompileTimeValue(property->value())) break;
|
2009-03-23 07:27:47 +00:00
|
|
|
// else fall through
|
2010-02-10 15:06:08 +00:00
|
|
|
case ObjectLiteral::Property::COMPUTED:
|
|
|
|
if (key->handle()->IsSymbol()) {
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kStoreIC_Initialize));
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(value);
|
2010-10-27 11:37:59 +00:00
|
|
|
if (property->emit_store()) {
|
|
|
|
frame_->PopToR0();
|
|
|
|
// Fetch the object literal.
|
|
|
|
frame_->SpillAllButCopyTOSToR1();
|
|
|
|
__ mov(r2, Operand(key->handle()));
|
|
|
|
frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0);
|
|
|
|
} else {
|
|
|
|
frame_->Drop();
|
|
|
|
}
|
2010-02-10 15:06:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// else fall through
|
2008-10-02 11:54:32 +00:00
|
|
|
case ObjectLiteral::Property::PROTOTYPE: {
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->Dup();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(key);
|
|
|
|
Load(value);
|
2010-10-27 11:37:59 +00:00
|
|
|
if (property->emit_store()) {
|
2011-03-02 04:53:43 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(NONE))); // PropertyAttributes
|
|
|
|
frame_->CallRuntime(Runtime::kSetProperty, 4);
|
2010-10-27 11:37:59 +00:00
|
|
|
} else {
|
|
|
|
frame_->Drop(3);
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ObjectLiteral::Property::SETTER: {
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->Dup();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(key);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(1)));
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(value);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDefineAccessor, 4);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-08-13 09:32:07 +00:00
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
case ObjectLiteral::Property::GETTER: {
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->Dup();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(key);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(0)));
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(value);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDefineAccessor, 4);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-08-13 09:32:07 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ ArrayLiteral");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
Register tos = frame_->GetTOSRegister();
|
2009-03-23 07:27:47 +00:00
|
|
|
// Load the function of this activation.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(tos, frame_->Function());
|
2010-02-11 12:28:49 +00:00
|
|
|
// Load the literals array of the function.
|
2010-06-24 07:54:48 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, JSFunction::kLiteralsOffset));
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(node->literal_index())));
|
|
|
|
frame_->EmitPush(Operand(node->constant_elements()));
|
2010-02-11 12:28:49 +00:00
|
|
|
int length = node->values()->length();
|
2011-03-18 20:35:07 +00:00
|
|
|
if (node->constant_elements()->map() == HEAP->fixed_cow_array_map()) {
|
2010-08-16 16:06:46 +00:00
|
|
|
FastCloneShallowArrayStub stub(
|
|
|
|
FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length);
|
|
|
|
frame_->CallStub(&stub, 3);
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->cow_arrays_created_stub(),
|
|
|
|
1, r1, r2);
|
2010-08-16 16:06:46 +00:00
|
|
|
} else if (node->depth() > 1) {
|
2009-12-22 12:41:45 +00:00
|
|
|
frame_->CallRuntime(Runtime::kCreateArrayLiteral, 3);
|
2010-08-16 16:06:46 +00:00
|
|
|
} else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) {
|
2009-12-22 12:41:45 +00:00
|
|
|
frame_->CallRuntime(Runtime::kCreateArrayLiteralShallow, 3);
|
2010-02-11 12:28:49 +00:00
|
|
|
} else {
|
2010-08-16 16:06:46 +00:00
|
|
|
FastCloneShallowArrayStub stub(
|
|
|
|
FastCloneShallowArrayStub::CLONE_ELEMENTS, length);
|
2010-02-11 12:28:49 +00:00
|
|
|
frame_->CallStub(&stub, 3);
|
2009-03-23 07:27:47 +00:00
|
|
|
}
|
|
|
|
frame_->EmitPush(r0); // save the result
|
2009-12-22 12:41:45 +00:00
|
|
|
// r0: created object literal
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Generate code to set the elements in the array that are not
|
|
|
|
// literals.
|
|
|
|
for (int i = 0; i < node->values()->length(); i++) {
|
|
|
|
Expression* value = node->values()->at(i);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-24 08:55:11 +00:00
|
|
|
// If value is a literal the property value is already set in the
|
|
|
|
// boilerplate object.
|
|
|
|
if (value->AsLiteral() != NULL) continue;
|
|
|
|
// If value is a materialized literal the property value is already set
|
|
|
|
// in the boilerplate object if it is simple.
|
|
|
|
if (CompileTimeValue::IsCompileTimeValue(value)) continue;
|
|
|
|
|
|
|
|
// The property must be set by generated code.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(value);
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->PopToR0();
|
2009-03-24 08:55:11 +00:00
|
|
|
// Fetch the object literal.
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->SpillAllButCopyTOSToR1();
|
|
|
|
|
2009-03-24 08:55:11 +00:00
|
|
|
// Get the elements array.
|
|
|
|
__ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-24 08:55:11 +00:00
|
|
|
// Write to the indexed properties array.
|
2009-07-17 12:12:24 +00:00
|
|
|
int offset = i * kPointerSize + FixedArray::kHeaderSize;
|
2009-03-24 08:55:11 +00:00
|
|
|
__ str(r0, FieldMemOperand(r1, offset));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-24 08:55:11 +00:00
|
|
|
// Update the write barrier for the array address.
|
2010-06-17 10:45:37 +00:00
|
|
|
__ RecordWrite(r1, Operand(offset), r3, r2);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-01-16 09:42:08 +00:00
|
|
|
void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2009-01-16 09:42:08 +00:00
|
|
|
// Call runtime routine to allocate the catch extension object and
|
|
|
|
// assign the exception value to the catch variable.
|
2009-02-27 13:00:32 +00:00
|
|
|
Comment cmnt(masm_, "[ CatchExtensionObject");
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->key());
|
|
|
|
Load(node->value());
|
2009-08-11 11:46:27 +00:00
|
|
|
frame_->CallRuntime(Runtime::kCreateCatchExtensionObject, 2);
|
|
|
|
frame_->EmitPush(r0);
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2009-01-16 09:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
void CodeGenerator::EmitSlotAssignment(Assignment* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2010-05-04 09:33:12 +00:00
|
|
|
Comment cmnt(masm(), "[ Variable Assignment");
|
|
|
|
Variable* var = node->target()->AsVariableProxy()->AsVariable();
|
|
|
|
ASSERT(var != NULL);
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = var->AsSlot();
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT(slot != NULL);
|
2009-02-27 13:00:32 +00:00
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
// Evaluate the right-hand side.
|
|
|
|
if (node->is_compound()) {
|
|
|
|
// For a compound assignment the right-hand side is a binary operation
|
|
|
|
// between the current property value and the actual right-hand side.
|
|
|
|
LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF);
|
|
|
|
|
|
|
|
// Perform the binary operation.
|
|
|
|
Literal* literal = node->value()->AsLiteral();
|
2010-08-25 11:10:05 +00:00
|
|
|
bool overwrite_value = node->value()->ResultOverwriteAllowed();
|
2010-05-04 09:33:12 +00:00
|
|
|
if (literal != NULL && literal->handle()->IsSmi()) {
|
|
|
|
SmiOperation(node->binary_op(),
|
|
|
|
literal->handle(),
|
|
|
|
false,
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
|
|
|
|
} else {
|
2010-06-02 09:37:02 +00:00
|
|
|
GenerateInlineSmi inline_smi =
|
|
|
|
loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI;
|
|
|
|
if (literal != NULL) {
|
|
|
|
ASSERT(!literal->handle()->IsSmi());
|
|
|
|
inline_smi = DONT_GENERATE_INLINE_SMI;
|
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
Load(node->value());
|
2010-06-02 09:37:02 +00:00
|
|
|
GenericBinaryOperation(node->binary_op(),
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE,
|
|
|
|
inline_smi);
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
} else {
|
|
|
|
Load(node->value());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
// Perform the assignment.
|
|
|
|
if (var->mode() != Variable::CONST || node->op() == Token::INIT_CONST) {
|
|
|
|
CodeForSourcePosition(node->position());
|
|
|
|
StoreToSlot(slot,
|
|
|
|
node->op() == Token::INIT_CONST ? CONST_INIT : NOT_CONST_INIT);
|
|
|
|
}
|
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm(), "[ Named Property Assignment");
|
|
|
|
Variable* var = node->target()->AsVariableProxy()->AsVariable();
|
|
|
|
Property* prop = node->target()->AsProperty();
|
|
|
|
ASSERT(var == NULL || (prop == NULL && var->is_global()));
|
|
|
|
|
|
|
|
// Initialize name and evaluate the receiver sub-expression if necessary. If
|
|
|
|
// the receiver is trivial it is not placed on the stack at this point, but
|
|
|
|
// loaded whenever actually needed.
|
|
|
|
Handle<String> name;
|
|
|
|
bool is_trivial_receiver = false;
|
|
|
|
if (var != NULL) {
|
|
|
|
name = var->name();
|
|
|
|
} else {
|
|
|
|
Literal* lit = prop->key()->AsLiteral();
|
|
|
|
ASSERT_NOT_NULL(lit);
|
|
|
|
name = Handle<String>::cast(lit->handle());
|
|
|
|
// Do not materialize the receiver on the frame if it is trivial.
|
|
|
|
is_trivial_receiver = prop->obj()->IsTrivial();
|
|
|
|
if (!is_trivial_receiver) Load(prop->obj());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change to slow case in the beginning of an initialization block to
|
|
|
|
// avoid the quadratic behavior of repeatedly adding fast properties.
|
|
|
|
if (node->starts_initialization_block()) {
|
2010-05-05 06:57:41 +00:00
|
|
|
// Initialization block consists of assignments of the form expr.x = ..., so
|
2010-05-04 09:33:12 +00:00
|
|
|
// this will never be an assignment to a variable, so there must be a
|
|
|
|
// receiver object.
|
|
|
|
ASSERT_EQ(NULL, var);
|
|
|
|
if (is_trivial_receiver) {
|
|
|
|
Load(prop->obj());
|
|
|
|
} else {
|
|
|
|
frame_->Dup();
|
|
|
|
}
|
|
|
|
frame_->CallRuntime(Runtime::kToSlowProperties, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change to fast case at the end of an initialization block. To prepare for
|
|
|
|
// that add an extra copy of the receiver to the frame, so that it can be
|
|
|
|
// converted back to fast case after the assignment.
|
|
|
|
if (node->ends_initialization_block() && !is_trivial_receiver) {
|
|
|
|
frame_->Dup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : receiver (only materialized if non-trivial)
|
|
|
|
// [tos+1] : receiver if at the end of an initialization block
|
|
|
|
|
|
|
|
// Evaluate the right-hand side.
|
|
|
|
if (node->is_compound()) {
|
|
|
|
// For a compound assignment the right-hand side is a binary operation
|
|
|
|
// between the current property value and the actual right-hand side.
|
|
|
|
if (is_trivial_receiver) {
|
|
|
|
Load(prop->obj());
|
|
|
|
} else if (var != NULL) {
|
|
|
|
LoadGlobal();
|
|
|
|
} else {
|
|
|
|
frame_->Dup();
|
|
|
|
}
|
|
|
|
EmitNamedLoad(name, var != NULL);
|
|
|
|
|
|
|
|
// Perform the binary operation.
|
|
|
|
Literal* literal = node->value()->AsLiteral();
|
2010-08-25 11:10:05 +00:00
|
|
|
bool overwrite_value = node->value()->ResultOverwriteAllowed();
|
2010-05-04 09:33:12 +00:00
|
|
|
if (literal != NULL && literal->handle()->IsSmi()) {
|
|
|
|
SmiOperation(node->binary_op(),
|
|
|
|
literal->handle(),
|
|
|
|
false,
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
|
|
|
|
} else {
|
2010-06-02 09:37:02 +00:00
|
|
|
GenerateInlineSmi inline_smi =
|
|
|
|
loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI;
|
|
|
|
if (literal != NULL) {
|
|
|
|
ASSERT(!literal->handle()->IsSmi());
|
|
|
|
inline_smi = DONT_GENERATE_INLINE_SMI;
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
Load(node->value());
|
2010-06-02 09:37:02 +00:00
|
|
|
GenericBinaryOperation(node->binary_op(),
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE,
|
|
|
|
inline_smi);
|
2010-05-04 09:33:12 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// For non-compound assignment just load the right-hand side.
|
|
|
|
Load(node->value());
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
// Stack layout:
|
|
|
|
// [tos] : value
|
|
|
|
// [tos+1] : receiver (only materialized if non-trivial)
|
|
|
|
// [tos+2] : receiver if at the end of an initialization block
|
|
|
|
|
|
|
|
// Perform the assignment. It is safe to ignore constants here.
|
|
|
|
ASSERT(var == NULL || var->mode() != Variable::CONST);
|
|
|
|
ASSERT_NE(Token::INIT_CONST, node->op());
|
|
|
|
if (is_trivial_receiver) {
|
|
|
|
// Load the receiver and swap with the value.
|
|
|
|
Load(prop->obj());
|
|
|
|
Register t0 = frame_->PopToRegister();
|
|
|
|
Register t1 = frame_->PopToRegister(t0);
|
|
|
|
frame_->EmitPush(t0);
|
|
|
|
frame_->EmitPush(t1);
|
|
|
|
}
|
|
|
|
CodeForSourcePosition(node->position());
|
|
|
|
bool is_contextual = (var != NULL);
|
|
|
|
EmitNamedStore(name, is_contextual);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
// Change to fast case at the end of an initialization block.
|
|
|
|
if (node->ends_initialization_block()) {
|
|
|
|
ASSERT_EQ(NULL, var);
|
|
|
|
// The argument to the runtime call is the receiver.
|
|
|
|
if (is_trivial_receiver) {
|
|
|
|
Load(prop->obj());
|
|
|
|
} else {
|
|
|
|
// A copy of the receiver is below the value of the assignment. Swap
|
|
|
|
// the receiver and the value of the assignment expression.
|
|
|
|
Register t0 = frame_->PopToRegister();
|
|
|
|
Register t1 = frame_->PopToRegister(t0);
|
|
|
|
frame_->EmitPush(t0);
|
|
|
|
frame_->EmitPush(t1);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
frame_->CallRuntime(Runtime::kToFastProperties, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : result
|
|
|
|
|
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ Keyed Property Assignment");
|
|
|
|
Property* prop = node->target()->AsProperty();
|
|
|
|
ASSERT_NOT_NULL(prop);
|
|
|
|
|
|
|
|
// Evaluate the receiver subexpression.
|
|
|
|
Load(prop->obj());
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
WriteBarrierCharacter wb_info;
|
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
// Change to slow case in the beginning of an initialization block to
|
|
|
|
// avoid the quadratic behavior of repeatedly adding fast properties.
|
|
|
|
if (node->starts_initialization_block()) {
|
|
|
|
frame_->Dup();
|
|
|
|
frame_->CallRuntime(Runtime::kToSlowProperties, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change to fast case at the end of an initialization block. To prepare for
|
|
|
|
// that add an extra copy of the receiver to the frame, so that it can be
|
|
|
|
// converted back to fast case after the assignment.
|
|
|
|
if (node->ends_initialization_block()) {
|
|
|
|
frame_->Dup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Evaluate the key subexpression.
|
|
|
|
Load(prop->key());
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : key
|
|
|
|
// [tos+1] : receiver
|
|
|
|
// [tos+2] : receiver if at the end of an initialization block
|
2010-07-01 15:06:24 +00:00
|
|
|
//
|
2010-05-04 09:33:12 +00:00
|
|
|
// Evaluate the right-hand side.
|
|
|
|
if (node->is_compound()) {
|
|
|
|
// For a compound assignment the right-hand side is a binary operation
|
|
|
|
// between the current property value and the actual right-hand side.
|
2010-05-07 10:16:11 +00:00
|
|
|
// Duplicate receiver and key for loading the current property value.
|
|
|
|
frame_->Dup2();
|
2010-05-04 09:33:12 +00:00
|
|
|
EmitKeyedLoad();
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
// Perform the binary operation.
|
|
|
|
Literal* literal = node->value()->AsLiteral();
|
2010-08-25 11:10:05 +00:00
|
|
|
bool overwrite_value = node->value()->ResultOverwriteAllowed();
|
2010-05-04 09:33:12 +00:00
|
|
|
if (literal != NULL && literal->handle()->IsSmi()) {
|
|
|
|
SmiOperation(node->binary_op(),
|
|
|
|
literal->handle(),
|
|
|
|
false,
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2010-06-02 09:37:02 +00:00
|
|
|
GenerateInlineSmi inline_smi =
|
|
|
|
loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI;
|
|
|
|
if (literal != NULL) {
|
|
|
|
ASSERT(!literal->handle()->IsSmi());
|
|
|
|
inline_smi = DONT_GENERATE_INLINE_SMI;
|
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
Load(node->value());
|
2010-06-02 09:37:02 +00:00
|
|
|
GenericBinaryOperation(node->binary_op(),
|
|
|
|
overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE,
|
|
|
|
inline_smi);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-07-01 15:06:24 +00:00
|
|
|
wb_info = node->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI;
|
2010-05-04 09:33:12 +00:00
|
|
|
} else {
|
|
|
|
// For non-compound assignment just load the right-hand side.
|
|
|
|
Load(node->value());
|
2010-07-01 15:06:24 +00:00
|
|
|
wb_info = node->value()->AsLiteral() != NULL ?
|
|
|
|
NEVER_NEWSPACE :
|
|
|
|
(node->value()->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI);
|
2010-05-04 09:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : value
|
|
|
|
// [tos+1] : key
|
|
|
|
// [tos+2] : receiver
|
|
|
|
// [tos+3] : receiver if at the end of an initialization block
|
|
|
|
|
|
|
|
// Perform the assignment. It is safe to ignore constants here.
|
|
|
|
ASSERT(node->op() != Token::INIT_CONST);
|
|
|
|
CodeForSourcePosition(node->position());
|
2010-07-01 15:06:24 +00:00
|
|
|
EmitKeyedStore(prop->key()->type(), wb_info);
|
2010-05-04 09:33:12 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : result
|
|
|
|
// [tos+1] : receiver if at the end of an initialization block
|
|
|
|
|
|
|
|
// Change to fast case at the end of an initialization block.
|
|
|
|
if (node->ends_initialization_block()) {
|
|
|
|
// The argument to the runtime call is the extra copy of the receiver,
|
|
|
|
// which is below the value of the assignment. Swap the receiver and
|
|
|
|
// the value of the assignment expression.
|
|
|
|
Register t0 = frame_->PopToRegister();
|
|
|
|
Register t1 = frame_->PopToRegister(t0);
|
|
|
|
frame_->EmitPush(t1);
|
|
|
|
frame_->EmitPush(t0);
|
|
|
|
frame_->CallRuntime(Runtime::kToFastProperties, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stack layout:
|
|
|
|
// [tos] : result
|
|
|
|
|
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::VisitAssignment(Assignment* node) {
|
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ Assignment");
|
|
|
|
|
|
|
|
Variable* var = node->target()->AsVariableProxy()->AsVariable();
|
|
|
|
Property* prop = node->target()->AsProperty();
|
|
|
|
|
|
|
|
if (var != NULL && !var->is_global()) {
|
|
|
|
EmitSlotAssignment(node);
|
|
|
|
|
|
|
|
} else if ((prop != NULL && prop->key()->IsPropertyName()) ||
|
|
|
|
(var != NULL && var->is_global())) {
|
|
|
|
// Properties whose keys are property names and global variables are
|
|
|
|
// treated as named property references. We do not need to consider
|
|
|
|
// global 'this' because it is not a valid left-hand side.
|
|
|
|
EmitNamedPropertyAssignment(node);
|
|
|
|
|
|
|
|
} else if (prop != NULL) {
|
|
|
|
// Other properties (including rewritten parameters for a function that
|
|
|
|
// uses arguments) are keyed property assignments.
|
|
|
|
EmitKeyedPropertyAssignment(node);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Invalid left-hand side.
|
|
|
|
Load(node->target());
|
|
|
|
frame_->CallRuntime(Runtime::kThrowReferenceError, 1);
|
|
|
|
// The runtime call doesn't actually return but the code generator will
|
|
|
|
// still generate code and expects a certain frame height.
|
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitThrow(Throw* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Throw");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->exception());
|
2008-12-17 08:45:42 +00:00
|
|
|
CodeForSourcePosition(node->position());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kThrow, 1);
|
|
|
|
frame_->EmitPush(r0);
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitProperty(Property* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Property");
|
2008-10-10 00:00:52 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
{ Reference property(this, node);
|
2010-04-08 22:30:30 +00:00
|
|
|
property.GetValue();
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitCall(Call* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ Call");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-29 13:28:30 +00:00
|
|
|
Expression* function = node->expression();
|
2008-10-02 11:54:32 +00:00
|
|
|
ZoneList<Expression*>* args = node->arguments();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Standard function call.
|
|
|
|
// Check if the function is a variable or a property.
|
|
|
|
Variable* var = function->AsVariableProxy()->AsVariable();
|
|
|
|
Property* property = function->AsProperty();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// Fast-case: Use inline caching.
|
|
|
|
// ---
|
|
|
|
// According to ECMA-262, section 11.2.3, page 44, the function to call
|
|
|
|
// must be resolved after the arguments have been evaluated. The IC code
|
|
|
|
// automatically handles this by loading the arguments before the function
|
|
|
|
// is resolved in cache misses (this also holds for megamorphic calls).
|
|
|
|
// ------------------------------------------------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-09-29 13:28:30 +00:00
|
|
|
if (var != NULL && var->is_possibly_eval()) {
|
|
|
|
// ----------------------------------
|
|
|
|
// JavaScript example: 'eval(arg)' // eval is not known to be shadowed
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
// In a call to eval, we first call %ResolvePossiblyDirectEval to
|
|
|
|
// resolve the function we need to call and the receiver of the
|
|
|
|
// call. Then we call the resolved function using the given
|
|
|
|
// arguments.
|
2010-06-07 07:12:00 +00:00
|
|
|
|
2009-09-29 13:28:30 +00:00
|
|
|
// Prepare stack for call to resolved function.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(function);
|
2010-06-07 07:12:00 +00:00
|
|
|
|
|
|
|
// Allocate a frame slot for the receiver.
|
2010-06-24 07:54:48 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex);
|
2010-06-07 07:12:00 +00:00
|
|
|
|
|
|
|
// Load the arguments.
|
2009-09-29 13:28:30 +00:00
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2009-09-29 13:28:30 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 07:54:48 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
|
|
|
|
2010-06-07 07:12:00 +00:00
|
|
|
// If we know that eval can only be shadowed by eval-introduced
|
|
|
|
// variables we attempt to load the global eval function directly
|
|
|
|
// in generated code. If we succeed, there is no need to perform a
|
|
|
|
// context lookup in the runtime system.
|
|
|
|
JumpTarget done;
|
2010-09-24 07:53:59 +00:00
|
|
|
if (var->AsSlot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) {
|
|
|
|
ASSERT(var->AsSlot()->type() == Slot::LOOKUP);
|
2010-06-07 07:12:00 +00:00
|
|
|
JumpTarget slow;
|
|
|
|
// Prepare the stack for the call to
|
|
|
|
// ResolvePossiblyDirectEvalNoLookup by pushing the loaded
|
|
|
|
// function, the first argument to the eval call and the
|
|
|
|
// receiver.
|
2010-09-24 07:53:59 +00:00
|
|
|
LoadFromGlobalSlotCheckExtensions(var->AsSlot(),
|
2010-06-07 07:12:00 +00:00
|
|
|
NOT_INSIDE_TYPEOF,
|
|
|
|
&slow);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
if (arg_count > 0) {
|
|
|
|
__ ldr(r1, MemOperand(sp, arg_count * kPointerSize));
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
} else {
|
|
|
|
frame_->EmitPush(r2);
|
|
|
|
}
|
|
|
|
__ ldr(r1, frame_->Receiver());
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
|
2011-02-04 18:15:49 +00:00
|
|
|
// Push the strict mode flag.
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(strict_mode_flag())));
|
|
|
|
|
|
|
|
frame_->CallRuntime(Runtime::kResolvePossiblyDirectEvalNoLookup, 4);
|
2010-06-07 07:12:00 +00:00
|
|
|
|
|
|
|
done.Jump();
|
|
|
|
slow.Bind();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare the stack for the call to ResolvePossiblyDirectEval by
|
|
|
|
// pushing the loaded function, the first argument to the eval
|
|
|
|
// call and the receiver.
|
2009-09-29 13:28:30 +00:00
|
|
|
__ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize));
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
if (arg_count > 0) {
|
|
|
|
__ ldr(r1, MemOperand(sp, arg_count * kPointerSize));
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
} else {
|
|
|
|
frame_->EmitPush(r2);
|
|
|
|
}
|
2010-01-05 09:38:02 +00:00
|
|
|
__ ldr(r1, frame_->Receiver());
|
|
|
|
frame_->EmitPush(r1);
|
|
|
|
|
2011-02-04 18:15:49 +00:00
|
|
|
// Push the strict mode flag.
|
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(strict_mode_flag())));
|
|
|
|
|
2009-09-29 13:28:30 +00:00
|
|
|
// Resolve the call.
|
2011-02-04 18:15:49 +00:00
|
|
|
frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 4);
|
2009-09-29 13:28:30 +00:00
|
|
|
|
2010-06-07 07:12:00 +00:00
|
|
|
// If we generated fast-case code bind the jump-target where fast
|
|
|
|
// and slow case merge.
|
|
|
|
if (done.is_linked()) done.Bind();
|
|
|
|
|
2009-09-29 13:28:30 +00:00
|
|
|
// Touch up stack with the right values for the function and the receiver.
|
2010-01-05 09:38:02 +00:00
|
|
|
__ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize));
|
2009-09-29 13:28:30 +00:00
|
|
|
__ str(r1, MemOperand(sp, arg_count * kPointerSize));
|
|
|
|
|
|
|
|
// Call the function.
|
|
|
|
CodeForSourcePosition(node->position());
|
|
|
|
|
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2010-01-15 13:42:32 +00:00
|
|
|
CallFunctionStub call_function(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE);
|
2009-09-29 13:28:30 +00:00
|
|
|
frame_->CallStub(&call_function, arg_count + 1);
|
|
|
|
|
|
|
|
__ ldr(cp, frame_->Context());
|
|
|
|
// Remove the function from the stack.
|
|
|
|
frame_->Drop();
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
|
|
|
} else if (var != NULL && !var->is_this() && var->is_global()) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// ----------------------------------
|
|
|
|
// JavaScript example: 'foo(1, 2, 3)' // foo is global
|
|
|
|
// ----------------------------------
|
2008-10-27 14:12:02 +00:00
|
|
|
// Pass the global object as the receiver and let the IC stub
|
|
|
|
// patch the stack to use the global proxy as 'this' in the
|
|
|
|
// invoked function.
|
|
|
|
LoadGlobal();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the arguments.
|
2009-02-27 13:00:32 +00:00
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2010-02-15 12:26:07 +00:00
|
|
|
// Setup the name register and call the IC initialization code.
|
|
|
|
__ mov(r2, Operand(var->name()));
|
2009-05-25 18:29:02 +00:00
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> stub =
|
|
|
|
ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop);
|
2008-12-17 08:45:42 +00:00
|
|
|
CodeForSourcePosition(node->position());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET_CONTEXT,
|
|
|
|
arg_count + 1);
|
2008-11-05 08:44:54 +00:00
|
|
|
__ ldr(cp, frame_->Context());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-09-24 07:53:59 +00:00
|
|
|
} else if (var != NULL && var->AsSlot() != NULL &&
|
|
|
|
var->AsSlot()->type() == Slot::LOOKUP) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// ----------------------------------
|
2010-05-07 10:25:11 +00:00
|
|
|
// JavaScript examples:
|
|
|
|
//
|
2010-05-10 12:20:06 +00:00
|
|
|
// with (obj) foo(1, 2, 3) // foo may be in obj.
|
2010-05-07 10:25:11 +00:00
|
|
|
//
|
|
|
|
// function f() {};
|
|
|
|
// function g() {
|
|
|
|
// eval(...);
|
2010-05-10 12:20:06 +00:00
|
|
|
// f(); // f could be in extension object.
|
2010-05-07 10:25:11 +00:00
|
|
|
// }
|
2008-10-02 11:54:32 +00:00
|
|
|
// ----------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-12 09:12:23 +00:00
|
|
|
JumpTarget slow, done;
|
2010-05-07 10:25:11 +00:00
|
|
|
|
2010-05-12 09:12:23 +00:00
|
|
|
// Generate fast case for loading functions from slots that
|
|
|
|
// correspond to local/global variables or arguments unless they
|
|
|
|
// are shadowed by eval-introduced bindings.
|
2010-09-24 07:53:59 +00:00
|
|
|
EmitDynamicLoadFromSlotFastCase(var->AsSlot(),
|
2010-05-12 09:12:23 +00:00
|
|
|
NOT_INSIDE_TYPEOF,
|
|
|
|
&slow,
|
|
|
|
&done);
|
2010-05-07 10:25:11 +00:00
|
|
|
|
|
|
|
slow.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the function
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(cp);
|
2010-08-16 11:43:30 +00:00
|
|
|
frame_->EmitPush(Operand(var->name()));
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kLoadContextSlot, 2);
|
2008-10-02 11:54:32 +00:00
|
|
|
// r0: slot value; r1: receiver
|
2008-10-01 10:57:37 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the receiver.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0); // function
|
|
|
|
frame_->EmitPush(r1); // receiver
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-12 09:12:23 +00:00
|
|
|
// If fast case code has been generated, emit code to push the
|
|
|
|
// function and receiver and have the slow path jump around this
|
|
|
|
// code.
|
|
|
|
if (done.is_linked()) {
|
|
|
|
JumpTarget call;
|
|
|
|
call.Jump();
|
|
|
|
done.Bind();
|
|
|
|
frame_->EmitPush(r0); // function
|
2010-08-16 11:43:30 +00:00
|
|
|
LoadGlobalReceiver(VirtualFrame::scratch0()); // receiver
|
2010-05-12 09:12:23 +00:00
|
|
|
call.Bind();
|
|
|
|
}
|
|
|
|
|
2010-05-07 10:25:11 +00:00
|
|
|
// Call the function. At this point, everything is spilled but the
|
|
|
|
// function and receiver are in r0 and r1.
|
2010-01-15 13:42:32 +00:00
|
|
|
CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (property != NULL) {
|
|
|
|
// Check if the key is a literal string.
|
|
|
|
Literal* literal = property->key()->AsLiteral();
|
2008-10-01 07:43:00 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
if (literal != NULL && literal->handle()->IsSymbol()) {
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)'
|
|
|
|
// ------------------------------------------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
Handle<String> name = Handle<String>::cast(literal->handle());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-22 12:20:36 +00:00
|
|
|
if (ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION &&
|
|
|
|
name->IsEqualTo(CStrVector("apply")) &&
|
|
|
|
args->length() == 2 &&
|
|
|
|
args->at(1)->AsVariableProxy() != NULL &&
|
|
|
|
args->at(1)->AsVariableProxy()->IsArguments()) {
|
|
|
|
// Use the optimized Function.prototype.apply that avoids
|
|
|
|
// allocating lazily allocated arguments objects.
|
|
|
|
CallApplyLazy(property->obj(),
|
|
|
|
args->at(0),
|
|
|
|
args->at(1)->AsVariableProxy(),
|
|
|
|
node->position());
|
|
|
|
|
|
|
|
} else {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(property->obj()); // Receiver.
|
2010-04-22 12:20:36 +00:00
|
|
|
// Load the arguments.
|
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2010-04-22 12:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2010-04-22 12:20:36 +00:00
|
|
|
// Set the name register and call the IC initialization code.
|
|
|
|
__ mov(r2, Operand(name));
|
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2010-11-11 10:33:51 +00:00
|
|
|
Handle<Code> stub =
|
2011-03-18 20:35:07 +00:00
|
|
|
ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop);
|
2010-04-22 12:20:36 +00:00
|
|
|
CodeForSourcePosition(node->position());
|
|
|
|
frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1);
|
|
|
|
__ ldr(cp, frame_->Context());
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
// -------------------------------------------
|
|
|
|
// JavaScript example: 'array[index](1, 2, 3)'
|
|
|
|
// -------------------------------------------
|
2010-11-17 13:59:07 +00:00
|
|
|
|
|
|
|
// Load the receiver and name of the function.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(property->obj());
|
2010-11-17 13:59:07 +00:00
|
|
|
Load(property->key());
|
|
|
|
|
2009-03-10 12:28:34 +00:00
|
|
|
if (property->is_synthetic()) {
|
2010-06-16 10:03:47 +00:00
|
|
|
EmitKeyedLoad();
|
|
|
|
// Put the function below the receiver.
|
2010-01-27 14:07:12 +00:00
|
|
|
// Use the global receiver.
|
2010-05-07 10:16:11 +00:00
|
|
|
frame_->EmitPush(r0); // Function.
|
2010-08-16 11:43:30 +00:00
|
|
|
LoadGlobalReceiver(VirtualFrame::scratch0());
|
2010-06-16 10:03:47 +00:00
|
|
|
// Call the function.
|
|
|
|
CallWithArguments(args, RECEIVER_MIGHT_BE_VALUE, node->position());
|
|
|
|
frame_->EmitPush(r0);
|
2009-03-10 12:28:34 +00:00
|
|
|
} else {
|
2010-11-17 13:59:07 +00:00
|
|
|
// Swap the name of the function and the receiver on the stack to follow
|
|
|
|
// the calling convention for call ICs.
|
|
|
|
Register key = frame_->PopToRegister();
|
|
|
|
Register receiver = frame_->PopToRegister(key);
|
|
|
|
frame_->EmitPush(key);
|
|
|
|
frame_->EmitPush(receiver);
|
|
|
|
|
2010-06-16 10:03:47 +00:00
|
|
|
// Load the arguments.
|
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
|
|
|
Load(args->at(i));
|
|
|
|
}
|
2009-03-10 12:28:34 +00:00
|
|
|
|
2010-11-17 13:59:07 +00:00
|
|
|
// Load the key into r2 and call the IC initialization code.
|
2010-06-16 10:03:47 +00:00
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2010-11-11 10:33:51 +00:00
|
|
|
Handle<Code> stub =
|
2011-03-18 20:35:07 +00:00
|
|
|
ISOLATE->stub_cache()->ComputeKeyedCallInitialize(arg_count,
|
|
|
|
in_loop);
|
2010-06-16 10:03:47 +00:00
|
|
|
CodeForSourcePosition(node->position());
|
2010-11-17 13:59:07 +00:00
|
|
|
frame_->SpillAll();
|
|
|
|
__ ldr(r2, frame_->ElementAt(arg_count + 1));
|
2010-06-16 10:03:47 +00:00
|
|
|
frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1);
|
2010-11-17 13:59:07 +00:00
|
|
|
frame_->Drop(); // Drop the key still on the stack.
|
2010-06-16 10:03:47 +00:00
|
|
|
__ ldr(cp, frame_->Context());
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
// ----------------------------------
|
|
|
|
// JavaScript example: 'foo(1, 2, 3)' // foo is not global
|
|
|
|
// ----------------------------------
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the function.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(function);
|
|
|
|
|
2008-10-24 12:58:17 +00:00
|
|
|
// Pass the global proxy as the receiver.
|
2010-08-16 11:43:30 +00:00
|
|
|
LoadGlobalReceiver(VirtualFrame::scratch0());
|
2008-10-24 12:58:17 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Call the function.
|
2010-01-15 13:42:32 +00:00
|
|
|
CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitCallNew(CallNew* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ CallNew");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// According to ECMA-262, section 11.2.2, page 44, the function
|
|
|
|
// expression in new calls must be evaluated before the
|
|
|
|
// arguments. This is different from ordinary calls, where the
|
|
|
|
// actual function to call is resolved after the arguments have been
|
|
|
|
// evaluated.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-25 07:18:32 +00:00
|
|
|
// 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.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->expression());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Push the arguments ("left-to-right") on the stack.
|
|
|
|
ZoneList<Expression*>* args = node->arguments();
|
2009-02-27 13:00:32 +00:00
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-08-25 07:18:32 +00:00
|
|
|
// Spill everything from here to simplify the implementation.
|
2010-05-28 11:23:07 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
|
|
|
|
2010-08-25 07:18:32 +00:00
|
|
|
// Load the argument count into r0 and the function into r1 as per
|
|
|
|
// calling convention.
|
2009-08-11 11:46:27 +00:00
|
|
|
__ mov(r0, Operand(arg_count));
|
2010-08-25 07:18:32 +00:00
|
|
|
__ ldr(r1, frame_->ElementAt(arg_count));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Call the construct call builtin that handles allocation and
|
|
|
|
// constructor invocation.
|
2008-12-17 08:45:42 +00:00
|
|
|
CodeForSourcePosition(node->position());
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kJSConstructCall));
|
2010-02-02 13:40:53 +00:00
|
|
|
frame_->CallCodeObject(ic, RelocInfo::CONSTRUCT_CALL, arg_count + 1);
|
2010-08-25 07:18:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-06-29 10:45:16 +00:00
|
|
|
void CodeGenerator::GenerateClassOf(ZoneList<Expression*>* args) {
|
2010-08-10 11:52:18 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2010-08-16 11:43:30 +00:00
|
|
|
JumpTarget null, function, leave, non_function_constructor;
|
2009-07-02 14:17:10 +00:00
|
|
|
|
2010-08-10 11:52:18 +00:00
|
|
|
// Load the object into register.
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2010-08-10 11:52:18 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
2009-07-02 14:17:10 +00:00
|
|
|
|
|
|
|
// If the object is a smi, we return null.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-07-02 14:17:10 +00:00
|
|
|
null.Branch(eq);
|
|
|
|
|
|
|
|
// Check that the object is a JS object but take special care of JS
|
|
|
|
// functions to make sure they have 'Function' as their class.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ CompareObjectType(tos, tos, scratch, FIRST_JS_OBJECT_TYPE);
|
2009-07-02 14:17:10 +00:00
|
|
|
null.Branch(lt);
|
|
|
|
|
|
|
|
// As long as JS_FUNCTION_TYPE is the last instance type and it is
|
|
|
|
// right after LAST_JS_OBJECT_TYPE, we can avoid checking for
|
|
|
|
// LAST_JS_OBJECT_TYPE.
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE);
|
|
|
|
STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1);
|
2010-08-10 11:52:18 +00:00
|
|
|
__ cmp(scratch, Operand(JS_FUNCTION_TYPE));
|
2009-07-02 14:17:10 +00:00
|
|
|
function.Branch(eq);
|
|
|
|
|
|
|
|
// Check if the constructor in the map is a function.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, Map::kConstructorOffset));
|
|
|
|
__ CompareObjectType(tos, scratch, scratch, JS_FUNCTION_TYPE);
|
2009-07-02 14:17:10 +00:00
|
|
|
non_function_constructor.Branch(ne);
|
|
|
|
|
2010-08-10 11:52:18 +00:00
|
|
|
// The tos register now contains the constructor function. Grab the
|
2009-07-02 14:17:10 +00:00
|
|
|
// instance class name from there.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
__ ldr(tos,
|
|
|
|
FieldMemOperand(tos, SharedFunctionInfo::kInstanceClassNameOffset));
|
|
|
|
frame_->EmitPush(tos);
|
2009-07-02 14:17:10 +00:00
|
|
|
leave.Jump();
|
|
|
|
|
|
|
|
// Functions have class 'Function'.
|
|
|
|
function.Bind();
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(tos, Operand(FACTORY->function_class_symbol()));
|
2010-08-10 11:52:18 +00:00
|
|
|
frame_->EmitPush(tos);
|
2009-07-02 14:17:10 +00:00
|
|
|
leave.Jump();
|
|
|
|
|
|
|
|
// Objects with a non-function constructor have class 'Object'.
|
|
|
|
non_function_constructor.Bind();
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(tos, Operand(FACTORY->Object_symbol()));
|
2010-08-10 11:52:18 +00:00
|
|
|
frame_->EmitPush(tos);
|
2009-07-02 14:17:10 +00:00
|
|
|
leave.Jump();
|
|
|
|
|
|
|
|
// Non-JS objects have class null.
|
|
|
|
null.Bind();
|
2010-08-10 11:52:18 +00:00
|
|
|
__ LoadRoot(tos, Heap::kNullValueRootIndex);
|
|
|
|
frame_->EmitPush(tos);
|
2009-07-02 14:17:10 +00:00
|
|
|
|
|
|
|
// All done.
|
|
|
|
leave.Bind();
|
2009-06-29 10:45:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) {
|
2010-08-10 11:52:18 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget leave;
|
2010-08-10 11:52:18 +00:00
|
|
|
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2010-08-10 11:52:18 +00:00
|
|
|
Register tos = frame_->PopToRegister(); // tos contains object.
|
2008-10-02 11:54:32 +00:00
|
|
|
// if (object->IsSmi()) return the object.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Branch(eq);
|
2009-06-10 11:42:13 +00:00
|
|
|
// It is a heap object - get map. If (!object->IsJSValue()) return the object.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ CompareObjectType(tos, scratch, scratch, JS_VALUE_TYPE);
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Branch(ne);
|
2008-10-02 11:54:32 +00:00
|
|
|
// Load the value.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, JSValue::kValueOffset));
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Bind();
|
2010-08-10 11:52:18 +00:00
|
|
|
frame_->EmitPush(tos);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) {
|
2010-08-10 11:52:18 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget leave;
|
2010-08-10 11:52:18 +00:00
|
|
|
|
|
|
|
ASSERT(args->length() == 2);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0)); // Load the object.
|
|
|
|
Load(args->at(1)); // Load the value.
|
2010-08-10 11:52:18 +00:00
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
Register object = frame_->PopToRegister(value);
|
2008-10-02 11:54:32 +00:00
|
|
|
// if (object->IsSmi()) return object.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ tst(object, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Branch(eq);
|
2009-06-10 11:42:13 +00:00
|
|
|
// It is a heap object - get map. If (!object->IsJSValue()) return the object.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ CompareObjectType(object, scratch1, scratch1, JS_VALUE_TYPE);
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Branch(ne);
|
2008-10-02 11:54:32 +00:00
|
|
|
// Store the value.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ str(value, FieldMemOperand(object, JSValue::kValueOffset));
|
2008-10-02 11:54:32 +00:00
|
|
|
// Update the write barrier.
|
2010-08-10 11:52:18 +00:00
|
|
|
__ RecordWrite(object,
|
|
|
|
Operand(JSValue::kValueOffset - kHeapObjectTag),
|
|
|
|
scratch1,
|
|
|
|
scratch2);
|
2008-10-02 11:54:32 +00:00
|
|
|
// Leave.
|
2009-02-27 13:00:32 +00:00
|
|
|
leave.Bind();
|
2010-08-10 11:52:18 +00:00
|
|
|
frame_->EmitPush(value);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 1);
|
2010-05-26 08:40:11 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Register reg = frame_->PopToRegister();
|
|
|
|
__ tst(reg, Operand(kSmiTagMask));
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2009-01-06 13:24:52 +00:00
|
|
|
void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) {
|
|
|
|
// See comment in CodeGenerator::GenerateLog in codegen-ia32.cc.
|
|
|
|
ASSERT_EQ(args->length(), 3);
|
2009-01-07 14:24:08 +00:00
|
|
|
#ifdef ENABLE_LOGGING_AND_PROFILING
|
2009-01-06 13:24:52 +00:00
|
|
|
if (ShouldGenerateLog(args->at(0))) {
|
2010-05-26 08:40:11 +00:00
|
|
|
Load(args->at(1));
|
|
|
|
Load(args->at(2));
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->CallRuntime(Runtime::kLog, 2);
|
2009-01-06 13:24:52 +00:00
|
|
|
}
|
2009-01-07 14:24:08 +00:00
|
|
|
#endif
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex);
|
2009-01-06 13:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 1);
|
2010-05-26 08:40:11 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Register reg = frame_->PopToRegister();
|
|
|
|
__ tst(reg, Operand(kSmiTagMask | 0x80000000u));
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-29 09:40:36 +00:00
|
|
|
// Generates the Math.pow method.
|
2010-03-08 13:49:23 +00:00
|
|
|
void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) {
|
2010-02-26 10:24:58 +00:00
|
|
|
ASSERT(args->length() == 2);
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
2010-06-29 09:40:36 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-06-29 09:40:36 +00:00
|
|
|
frame_->CallRuntime(Runtime::kMath_pow, 2);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
} else {
|
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
JumpTarget runtime, done;
|
2010-06-30 12:22:15 +00:00
|
|
|
Label exponent_nonsmi, base_nonsmi, powi, not_minus_half, allocate_return;
|
2010-06-29 09:40:36 +00:00
|
|
|
|
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
|
|
|
|
|
|
|
// Get base and exponent to registers.
|
|
|
|
Register exponent = frame_->PopToRegister();
|
|
|
|
Register base = frame_->PopToRegister(exponent);
|
2010-06-30 12:22:15 +00:00
|
|
|
Register heap_number_map = no_reg;
|
2010-06-29 09:40:36 +00:00
|
|
|
|
|
|
|
// Set the frame for the runtime jump target. The code below jumps to the
|
|
|
|
// jump target label so the frame needs to be established before that.
|
|
|
|
ASSERT(runtime.entry_frame() == NULL);
|
|
|
|
runtime.set_entry_frame(frame_);
|
|
|
|
|
2011-01-26 07:44:45 +00:00
|
|
|
__ JumpIfNotSmi(exponent, &exponent_nonsmi);
|
|
|
|
__ JumpIfNotSmi(base, &base_nonsmi);
|
2010-06-29 09:40:36 +00:00
|
|
|
|
2010-06-30 12:22:15 +00:00
|
|
|
heap_number_map = r6;
|
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
|
|
|
|
// Exponent is a smi and base is a smi. Get the smi value into vfp register
|
|
|
|
// d1.
|
|
|
|
__ SmiToDoubleVFPRegister(base, d1, scratch1, s0);
|
|
|
|
__ b(&powi);
|
|
|
|
|
|
|
|
__ bind(&base_nonsmi);
|
|
|
|
// Exponent is smi and base is non smi. Get the double value from the base
|
|
|
|
// into vfp register d1.
|
|
|
|
__ ObjectToDoubleVFPRegister(base, d1,
|
|
|
|
scratch1, scratch2, heap_number_map, s0,
|
|
|
|
runtime.entry_label());
|
|
|
|
|
|
|
|
__ bind(&powi);
|
|
|
|
|
|
|
|
// Load 1.0 into d0.
|
2010-07-08 12:38:02 +00:00
|
|
|
__ vmov(d0, 1.0);
|
2010-06-30 12:22:15 +00:00
|
|
|
|
|
|
|
// Get the absolute untagged value of the exponent and use that for the
|
|
|
|
// calculation.
|
|
|
|
__ mov(scratch1, Operand(exponent, ASR, kSmiTagSize), SetCC);
|
2010-09-07 11:09:45 +00:00
|
|
|
// Negate if negative.
|
|
|
|
__ rsb(scratch1, scratch1, Operand(0, RelocInfo::NONE), LeaveCC, mi);
|
2010-06-30 12:22:15 +00:00
|
|
|
__ vmov(d2, d0, mi); // 1.0 needed in d2 later if exponent is negative.
|
|
|
|
|
|
|
|
// Run through all the bits in the exponent. The result is calculated in d0
|
|
|
|
// and d1 holds base^(bit^2).
|
|
|
|
Label more_bits;
|
|
|
|
__ bind(&more_bits);
|
|
|
|
__ mov(scratch1, Operand(scratch1, LSR, 1), SetCC);
|
|
|
|
__ vmul(d0, d0, d1, cs); // Multiply with base^(bit^2) if bit is set.
|
|
|
|
__ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done.
|
|
|
|
__ b(ne, &more_bits);
|
|
|
|
|
2010-06-30 15:19:06 +00:00
|
|
|
// If exponent is positive we are done.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ cmp(exponent, Operand(0, RelocInfo::NONE));
|
2010-06-30 15:19:06 +00:00
|
|
|
__ b(ge, &allocate_return);
|
|
|
|
|
|
|
|
// If exponent is negative result is 1/result (d2 already holds 1.0 in that
|
|
|
|
// case). However if d0 has reached infinity this will not provide the
|
|
|
|
// correct result, so call runtime if that is the case.
|
|
|
|
__ mov(scratch2, Operand(0x7FF00000));
|
2010-09-07 11:09:45 +00:00
|
|
|
__ mov(scratch1, Operand(0, RelocInfo::NONE));
|
2010-06-30 15:19:06 +00:00
|
|
|
__ vmov(d1, scratch1, scratch2); // Load infinity into d1.
|
2011-01-11 12:45:25 +00:00
|
|
|
__ VFPCompareAndSetFlags(d0, d1);
|
2010-06-30 15:19:06 +00:00
|
|
|
runtime.Branch(eq); // d0 reached infinity.
|
|
|
|
__ vdiv(d0, d2, d0);
|
2010-06-30 12:22:15 +00:00
|
|
|
__ b(&allocate_return);
|
|
|
|
|
|
|
|
__ bind(&exponent_nonsmi);
|
2010-06-29 09:40:36 +00:00
|
|
|
// Special handling of raising to the power of -0.5 and 0.5. First check
|
|
|
|
// that the value is a heap number and that the lower bits (which for both
|
|
|
|
// values are zero).
|
2010-06-30 12:22:15 +00:00
|
|
|
heap_number_map = r6;
|
2010-06-29 09:40:36 +00:00
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ ldr(scratch1, FieldMemOperand(exponent, HeapObject::kMapOffset));
|
|
|
|
__ ldr(scratch2, FieldMemOperand(exponent, HeapNumber::kMantissaOffset));
|
|
|
|
__ cmp(scratch1, heap_number_map);
|
|
|
|
runtime.Branch(ne);
|
|
|
|
__ tst(scratch2, scratch2);
|
|
|
|
runtime.Branch(ne);
|
|
|
|
|
2010-06-30 12:22:15 +00:00
|
|
|
// Load the higher bits (which contains the floating point exponent).
|
2010-06-29 09:40:36 +00:00
|
|
|
__ ldr(scratch1, FieldMemOperand(exponent, HeapNumber::kExponentOffset));
|
|
|
|
|
|
|
|
// Compare exponent with -0.5.
|
|
|
|
__ cmp(scratch1, Operand(0xbfe00000));
|
|
|
|
__ b(ne, ¬_minus_half);
|
|
|
|
|
|
|
|
// Get the double value from the base into vfp register d0.
|
|
|
|
__ ObjectToDoubleVFPRegister(base, d0,
|
|
|
|
scratch1, scratch2, heap_number_map, s0,
|
|
|
|
runtime.entry_label(),
|
|
|
|
AVOID_NANS_AND_INFINITIES);
|
|
|
|
|
2011-02-02 12:54:58 +00:00
|
|
|
// Convert -0 into +0 by adding +0.
|
|
|
|
__ vmov(d2, 0.0);
|
|
|
|
__ vadd(d0, d2, d0);
|
2010-06-29 09:40:36 +00:00
|
|
|
// Load 1.0 into d2.
|
2010-07-08 12:38:02 +00:00
|
|
|
__ vmov(d2, 1.0);
|
2010-06-29 09:40:36 +00:00
|
|
|
|
2011-02-02 12:54:58 +00:00
|
|
|
// Calculate the reciprocal of the square root.
|
2010-06-29 09:40:36 +00:00
|
|
|
__ vsqrt(d0, d0);
|
2011-02-02 12:54:58 +00:00
|
|
|
__ vdiv(d0, d2, d0);
|
2010-06-29 09:40:36 +00:00
|
|
|
|
|
|
|
__ b(&allocate_return);
|
|
|
|
|
|
|
|
__ bind(¬_minus_half);
|
|
|
|
// Compare exponent with 0.5.
|
|
|
|
__ cmp(scratch1, Operand(0x3fe00000));
|
|
|
|
runtime.Branch(ne);
|
|
|
|
|
|
|
|
// Get the double value from the base into vfp register d0.
|
|
|
|
__ ObjectToDoubleVFPRegister(base, d0,
|
|
|
|
scratch1, scratch2, heap_number_map, s0,
|
|
|
|
runtime.entry_label(),
|
|
|
|
AVOID_NANS_AND_INFINITIES);
|
2011-02-02 12:54:58 +00:00
|
|
|
// Convert -0 into +0 by adding +0.
|
|
|
|
__ vmov(d2, 0.0);
|
|
|
|
__ vadd(d0, d2, d0);
|
2010-06-29 09:40:36 +00:00
|
|
|
__ vsqrt(d0, d0);
|
|
|
|
|
|
|
|
__ bind(&allocate_return);
|
2010-06-30 13:39:03 +00:00
|
|
|
Register scratch3 = r5;
|
|
|
|
__ AllocateHeapNumberWithValue(scratch3, d0, scratch1, scratch2,
|
|
|
|
heap_number_map, runtime.entry_label());
|
|
|
|
__ mov(base, scratch3);
|
2010-06-29 09:40:36 +00:00
|
|
|
done.Jump();
|
|
|
|
|
|
|
|
runtime.Bind();
|
|
|
|
|
|
|
|
// Push back the arguments again for the runtime call.
|
|
|
|
frame_->EmitPush(base);
|
|
|
|
frame_->EmitPush(exponent);
|
|
|
|
frame_->CallRuntime(Runtime::kMath_pow, 2);
|
|
|
|
__ Move(base, r0);
|
|
|
|
|
|
|
|
done.Bind();
|
|
|
|
frame_->EmitPush(base);
|
|
|
|
}
|
2010-02-26 10:24:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-08 13:49:23 +00:00
|
|
|
|
2010-06-29 09:40:36 +00:00
|
|
|
// Generates the Math.sqrt method.
|
2010-03-08 13:49:23 +00:00
|
|
|
void CodeGenerator::GenerateMathSqrt(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
Load(args->at(0));
|
2010-06-29 09:40:36 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
if (!Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-06-29 09:40:36 +00:00
|
|
|
frame_->CallRuntime(Runtime::kMath_sqrt, 1);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
} else {
|
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
JumpTarget runtime, done;
|
|
|
|
|
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
|
|
|
|
|
|
|
// Get the value from the frame.
|
|
|
|
Register tos = frame_->PopToRegister();
|
|
|
|
|
|
|
|
// Set the frame for the runtime jump target. The code below jumps to the
|
|
|
|
// jump target label so the frame needs to be established before that.
|
|
|
|
ASSERT(runtime.entry_frame() == NULL);
|
|
|
|
runtime.set_entry_frame(frame_);
|
|
|
|
|
|
|
|
Register heap_number_map = r6;
|
2010-10-20 12:01:17 +00:00
|
|
|
Register new_heap_number = r5;
|
2010-06-29 09:40:36 +00:00
|
|
|
__ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex);
|
|
|
|
|
|
|
|
// Get the double value from the heap number into vfp register d0.
|
|
|
|
__ ObjectToDoubleVFPRegister(tos, d0,
|
|
|
|
scratch1, scratch2, heap_number_map, s0,
|
|
|
|
runtime.entry_label());
|
|
|
|
|
|
|
|
// Calculate the square root of d0 and place result in a heap number object.
|
|
|
|
__ vsqrt(d0, d0);
|
2010-10-20 12:01:17 +00:00
|
|
|
__ AllocateHeapNumberWithValue(new_heap_number,
|
|
|
|
d0,
|
|
|
|
scratch1, scratch2,
|
|
|
|
heap_number_map,
|
|
|
|
runtime.entry_label());
|
|
|
|
__ mov(tos, Operand(new_heap_number));
|
2010-06-29 09:40:36 +00:00
|
|
|
done.Jump();
|
|
|
|
|
|
|
|
runtime.Bind();
|
|
|
|
// Push back the argument again for the runtime call.
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
frame_->CallRuntime(Runtime::kMath_sqrt, 1);
|
|
|
|
__ Move(tos, r0);
|
|
|
|
|
|
|
|
done.Bind();
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
}
|
2010-03-08 13:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-26 14:23:19 +00:00
|
|
|
class DeferredStringCharCodeAt : public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredStringCharCodeAt(Register object,
|
|
|
|
Register index,
|
|
|
|
Register scratch,
|
|
|
|
Register result)
|
|
|
|
: result_(result),
|
|
|
|
char_code_at_generator_(object,
|
|
|
|
index,
|
|
|
|
scratch,
|
|
|
|
result,
|
|
|
|
&need_conversion_,
|
|
|
|
&need_conversion_,
|
|
|
|
&index_out_of_range_,
|
|
|
|
STRING_INDEX_IS_NUMBER) {}
|
|
|
|
|
|
|
|
StringCharCodeAtGenerator* fast_case_generator() {
|
|
|
|
return &char_code_at_generator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate() {
|
|
|
|
VirtualFrameRuntimeCallHelper call_helper(frame_state());
|
|
|
|
char_code_at_generator_.GenerateSlow(masm(), call_helper);
|
|
|
|
|
|
|
|
__ bind(&need_conversion_);
|
|
|
|
// Move the undefined value into the result register, which will
|
|
|
|
// trigger conversion.
|
|
|
|
__ LoadRoot(result_, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ jmp(exit_label());
|
|
|
|
|
|
|
|
__ bind(&index_out_of_range_);
|
|
|
|
// When the index is out of range, the spec requires us to return
|
|
|
|
// NaN.
|
|
|
|
__ LoadRoot(result_, Heap::kNanValueRootIndex);
|
|
|
|
__ jmp(exit_label());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register result_;
|
|
|
|
|
|
|
|
Label need_conversion_;
|
|
|
|
Label index_out_of_range_;
|
|
|
|
|
|
|
|
StringCharCodeAtGenerator char_code_at_generator_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This generates code that performs a String.prototype.charCodeAt() call
|
|
|
|
// or returns a smi in order to trigger conversion.
|
|
|
|
void CodeGenerator::GenerateStringCharCodeAt(ZoneList<Expression*>* args) {
|
|
|
|
Comment(masm_, "[ GenerateStringCharCodeAt");
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 2);
|
2009-11-18 10:20:24 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
2009-11-18 10:20:24 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
Register index = frame_->PopToRegister();
|
|
|
|
Register object = frame_->PopToRegister(index);
|
2010-05-26 14:23:19 +00:00
|
|
|
|
|
|
|
// We need two extra registers.
|
2010-08-11 10:55:44 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
Register result = VirtualFrame::scratch1();
|
2009-11-18 10:20:24 +00:00
|
|
|
|
2010-05-26 14:23:19 +00:00
|
|
|
DeferredStringCharCodeAt* deferred =
|
|
|
|
new DeferredStringCharCodeAt(object,
|
|
|
|
index,
|
|
|
|
scratch,
|
|
|
|
result);
|
|
|
|
deferred->fast_case_generator()->GenerateFast(masm_);
|
|
|
|
deferred->BindExit();
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->EmitPush(result);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-26 14:23:19 +00:00
|
|
|
class DeferredStringCharFromCode : public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredStringCharFromCode(Register code,
|
|
|
|
Register result)
|
|
|
|
: char_from_code_generator_(code, result) {}
|
|
|
|
|
|
|
|
StringCharFromCodeGenerator* fast_case_generator() {
|
|
|
|
return &char_from_code_generator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate() {
|
|
|
|
VirtualFrameRuntimeCallHelper call_helper(frame_state());
|
|
|
|
char_from_code_generator_.GenerateSlow(masm(), call_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
StringCharFromCodeGenerator char_from_code_generator_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Generates code for creating a one-char string from a char code.
|
|
|
|
void CodeGenerator::GenerateStringCharFromCode(ZoneList<Expression*>* args) {
|
|
|
|
Comment(masm_, "[ GenerateStringCharFromCode");
|
2010-02-26 20:14:20 +00:00
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2010-05-26 14:23:19 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
Register result = frame_->GetTOSRegister();
|
|
|
|
Register code = frame_->PopToRegister(result);
|
2010-02-26 20:14:20 +00:00
|
|
|
|
2010-05-26 14:23:19 +00:00
|
|
|
DeferredStringCharFromCode* deferred = new DeferredStringCharFromCode(
|
|
|
|
code, result);
|
|
|
|
deferred->fast_case_generator()->GenerateFast(masm_);
|
|
|
|
deferred->BindExit();
|
|
|
|
frame_->EmitPush(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DeferredStringCharAt : public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredStringCharAt(Register object,
|
|
|
|
Register index,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register result)
|
|
|
|
: result_(result),
|
|
|
|
char_at_generator_(object,
|
|
|
|
index,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
result,
|
|
|
|
&need_conversion_,
|
|
|
|
&need_conversion_,
|
|
|
|
&index_out_of_range_,
|
|
|
|
STRING_INDEX_IS_NUMBER) {}
|
|
|
|
|
|
|
|
StringCharAtGenerator* fast_case_generator() {
|
|
|
|
return &char_at_generator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate() {
|
|
|
|
VirtualFrameRuntimeCallHelper call_helper(frame_state());
|
|
|
|
char_at_generator_.GenerateSlow(masm(), call_helper);
|
|
|
|
|
|
|
|
__ bind(&need_conversion_);
|
|
|
|
// Move smi zero into the result register, which will trigger
|
|
|
|
// conversion.
|
|
|
|
__ mov(result_, Operand(Smi::FromInt(0)));
|
|
|
|
__ jmp(exit_label());
|
|
|
|
|
|
|
|
__ bind(&index_out_of_range_);
|
|
|
|
// When the index is out of range, the spec requires us to return
|
|
|
|
// the empty string.
|
|
|
|
__ LoadRoot(result_, Heap::kEmptyStringRootIndex);
|
|
|
|
__ jmp(exit_label());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register result_;
|
|
|
|
|
|
|
|
Label need_conversion_;
|
|
|
|
Label index_out_of_range_;
|
|
|
|
|
|
|
|
StringCharAtGenerator char_at_generator_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This generates code that performs a String.prototype.charAt() call
|
|
|
|
// or returns a smi in order to trigger conversion.
|
|
|
|
void CodeGenerator::GenerateStringCharAt(ZoneList<Expression*>* args) {
|
|
|
|
Comment(masm_, "[ GenerateStringCharAt");
|
|
|
|
ASSERT(args->length() == 2);
|
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
2010-05-26 14:23:19 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
Register index = frame_->PopToRegister();
|
|
|
|
Register object = frame_->PopToRegister(index);
|
2010-05-26 14:23:19 +00:00
|
|
|
|
|
|
|
// We need three extra registers.
|
2010-08-11 10:55:44 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
|
|
|
// Use r6 without notifying the virtual frame.
|
|
|
|
Register result = r6;
|
2010-05-26 14:23:19 +00:00
|
|
|
|
|
|
|
DeferredStringCharAt* deferred =
|
|
|
|
new DeferredStringCharAt(object,
|
|
|
|
index,
|
|
|
|
scratch1,
|
|
|
|
scratch2,
|
|
|
|
result);
|
|
|
|
deferred->fast_case_generator()->GenerateFast(masm_);
|
|
|
|
deferred->BindExit();
|
2010-05-04 09:32:07 +00:00
|
|
|
frame_->EmitPush(result);
|
2010-02-26 20:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget answer;
|
2008-10-02 11:54:32 +00:00
|
|
|
// We need the CC bits to come out as not_equal in the case where the
|
|
|
|
// object is a smi. This can't be done with the usual test opcode so
|
|
|
|
// we use XOR to get the right CC bits.
|
2010-05-28 11:23:07 +00:00
|
|
|
Register possible_array = frame_->PopToRegister();
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
__ and_(scratch, possible_array, Operand(kSmiTagMask));
|
|
|
|
__ eor(scratch, scratch, Operand(kSmiTagMask), SetCC);
|
2009-02-27 13:00:32 +00:00
|
|
|
answer.Branch(ne);
|
2009-06-10 11:42:13 +00:00
|
|
|
// It is a heap object - get the map. Check if the object is a JS array.
|
2010-05-28 11:23:07 +00:00
|
|
|
__ CompareObjectType(possible_array, scratch, scratch, JS_ARRAY_TYPE);
|
2009-02-27 13:00:32 +00:00
|
|
|
answer.Bind();
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-02-19 13:07:37 +00:00
|
|
|
void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2010-02-19 13:07:37 +00:00
|
|
|
JumpTarget answer;
|
|
|
|
// We need the CC bits to come out as not_equal in the case where the
|
|
|
|
// object is a smi. This can't be done with the usual test opcode so
|
|
|
|
// we use XOR to get the right CC bits.
|
2010-05-28 11:23:07 +00:00
|
|
|
Register possible_regexp = frame_->PopToRegister();
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
__ and_(scratch, possible_regexp, Operand(kSmiTagMask));
|
|
|
|
__ eor(scratch, scratch, Operand(kSmiTagMask), SetCC);
|
2010-02-19 13:07:37 +00:00
|
|
|
answer.Branch(ne);
|
|
|
|
// It is a heap object - get the map. Check if the object is a regexp.
|
2010-05-28 11:23:07 +00:00
|
|
|
__ CompareObjectType(possible_regexp, scratch, scratch, JS_REGEXP_TYPE);
|
2010-02-19 13:07:37 +00:00
|
|
|
answer.Bind();
|
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 07:41:32 +00:00
|
|
|
void CodeGenerator::GenerateIsObject(ZoneList<Expression*>* args) {
|
|
|
|
// This generates a fast version of:
|
|
|
|
// (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp')
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Register possible_object = frame_->PopToRegister();
|
|
|
|
__ tst(possible_object, Operand(kSmiTagMask));
|
2009-11-19 07:41:32 +00:00
|
|
|
false_target()->Branch(eq);
|
|
|
|
|
|
|
|
__ LoadRoot(ip, Heap::kNullValueRootIndex);
|
2010-05-28 11:23:07 +00:00
|
|
|
__ cmp(possible_object, ip);
|
2009-11-19 07:41:32 +00:00
|
|
|
true_target()->Branch(eq);
|
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
Register map_reg = VirtualFrame::scratch0();
|
|
|
|
__ ldr(map_reg, FieldMemOperand(possible_object, HeapObject::kMapOffset));
|
2009-11-19 07:41:32 +00:00
|
|
|
// Undetectable objects behave like undefined when tested with typeof.
|
2010-05-28 11:23:07 +00:00
|
|
|
__ ldrb(possible_object, FieldMemOperand(map_reg, Map::kBitFieldOffset));
|
|
|
|
__ tst(possible_object, Operand(1 << Map::kIsUndetectable));
|
2010-05-25 14:08:17 +00:00
|
|
|
false_target()->Branch(ne);
|
2009-11-19 07:41:32 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
__ ldrb(possible_object, FieldMemOperand(map_reg, Map::kInstanceTypeOffset));
|
|
|
|
__ cmp(possible_object, Operand(FIRST_JS_OBJECT_TYPE));
|
2009-11-19 07:41:32 +00:00
|
|
|
false_target()->Branch(lt);
|
2010-05-28 11:23:07 +00:00
|
|
|
__ cmp(possible_object, Operand(LAST_JS_OBJECT_TYPE));
|
2009-11-19 07:41:32 +00:00
|
|
|
cc_reg_ = le;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-16 11:21:08 +00:00
|
|
|
void CodeGenerator::GenerateIsSpecObject(ZoneList<Expression*>* args) {
|
|
|
|
// This generates a fast version of:
|
|
|
|
// (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp' ||
|
|
|
|
// typeof(arg) == function).
|
|
|
|
// It includes undetectable objects (as opposed to IsObject).
|
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
Load(args->at(0));
|
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
__ tst(value, Operand(kSmiTagMask));
|
|
|
|
false_target()->Branch(eq);
|
|
|
|
// Check that this is an object.
|
|
|
|
__ ldr(value, FieldMemOperand(value, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(value, FieldMemOperand(value, Map::kInstanceTypeOffset));
|
|
|
|
__ cmp(value, Operand(FIRST_JS_OBJECT_TYPE));
|
|
|
|
cc_reg_ = ge;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-12 13:43:08 +00:00
|
|
|
// Deferred code to check whether the String JavaScript object is safe for using
|
|
|
|
// default value of. This code is called after the bit caching this information
|
|
|
|
// in the map has been checked with the map for the object in the map_result_
|
|
|
|
// register. On return the register map_result_ contains 1 for true and 0 for
|
|
|
|
// false.
|
|
|
|
class DeferredIsStringWrapperSafeForDefaultValueOf : public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredIsStringWrapperSafeForDefaultValueOf(Register object,
|
|
|
|
Register map_result,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2)
|
|
|
|
: object_(object),
|
|
|
|
map_result_(map_result),
|
|
|
|
scratch1_(scratch1),
|
|
|
|
scratch2_(scratch2) { }
|
|
|
|
|
|
|
|
virtual void Generate() {
|
|
|
|
Label false_result;
|
|
|
|
|
|
|
|
// Check that map is loaded as expected.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ ldr(ip, FieldMemOperand(object_, HeapObject::kMapOffset));
|
|
|
|
__ cmp(map_result_, ip);
|
|
|
|
__ Assert(eq, "Map not in expected register");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for fast case object. Generate false result for slow case object.
|
|
|
|
__ ldr(scratch1_, FieldMemOperand(object_, JSObject::kPropertiesOffset));
|
|
|
|
__ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset));
|
|
|
|
__ LoadRoot(ip, Heap::kHashTableMapRootIndex);
|
|
|
|
__ cmp(scratch1_, ip);
|
|
|
|
__ b(eq, &false_result);
|
|
|
|
|
|
|
|
// Look for valueOf symbol in the descriptor array, and indicate false if
|
|
|
|
// found. The type is not checked, so if it is a transition it is a false
|
|
|
|
// negative.
|
|
|
|
__ ldr(map_result_,
|
|
|
|
FieldMemOperand(map_result_, Map::kInstanceDescriptorsOffset));
|
|
|
|
__ ldr(scratch2_, FieldMemOperand(map_result_, FixedArray::kLengthOffset));
|
|
|
|
// map_result_: descriptor array
|
|
|
|
// scratch2_: length of descriptor array
|
|
|
|
// Calculate the end of the descriptor array.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
STATIC_ASSERT(kPointerSize == 4);
|
|
|
|
__ add(scratch1_,
|
|
|
|
map_result_,
|
|
|
|
Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ add(scratch1_,
|
|
|
|
scratch1_,
|
|
|
|
Operand(scratch2_, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
|
|
|
|
// Calculate location of the first key name.
|
|
|
|
__ add(map_result_,
|
|
|
|
map_result_,
|
2010-08-13 11:18:16 +00:00
|
|
|
Operand(FixedArray::kHeaderSize - kHeapObjectTag +
|
2010-08-12 13:43:08 +00:00
|
|
|
DescriptorArray::kFirstIndex * kPointerSize));
|
|
|
|
// Loop through all the keys in the descriptor array. If one of these is the
|
|
|
|
// symbol valueOf the result is false.
|
|
|
|
Label entry, loop;
|
2010-08-13 12:36:59 +00:00
|
|
|
// The use of ip to store the valueOf symbol asumes that it is not otherwise
|
|
|
|
// used in the loop below.
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(ip, Operand(FACTORY->value_of_symbol()));
|
2010-08-12 13:43:08 +00:00
|
|
|
__ jmp(&entry);
|
|
|
|
__ bind(&loop);
|
2010-08-13 12:36:59 +00:00
|
|
|
__ ldr(scratch2_, MemOperand(map_result_, 0));
|
|
|
|
__ cmp(scratch2_, ip);
|
2010-08-12 13:43:08 +00:00
|
|
|
__ b(eq, &false_result);
|
|
|
|
__ add(map_result_, map_result_, Operand(kPointerSize));
|
|
|
|
__ bind(&entry);
|
|
|
|
__ cmp(map_result_, Operand(scratch1_));
|
|
|
|
__ b(ne, &loop);
|
|
|
|
|
|
|
|
// Reload map as register map_result_ was used as temporary above.
|
|
|
|
__ ldr(map_result_, FieldMemOperand(object_, HeapObject::kMapOffset));
|
|
|
|
|
|
|
|
// If a valueOf property is not found on the object check that it's
|
|
|
|
// prototype is the un-modified String prototype. If not result is false.
|
|
|
|
__ ldr(scratch1_, FieldMemOperand(map_result_, Map::kPrototypeOffset));
|
|
|
|
__ tst(scratch1_, Operand(kSmiTagMask));
|
|
|
|
__ b(eq, &false_result);
|
|
|
|
__ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset));
|
|
|
|
__ ldr(scratch2_,
|
2010-11-10 17:00:20 +00:00
|
|
|
ContextOperand(cp, Context::GLOBAL_INDEX));
|
2010-08-12 13:43:08 +00:00
|
|
|
__ ldr(scratch2_,
|
|
|
|
FieldMemOperand(scratch2_, GlobalObject::kGlobalContextOffset));
|
|
|
|
__ ldr(scratch2_,
|
2010-11-10 17:00:20 +00:00
|
|
|
ContextOperand(
|
2010-08-12 13:43:08 +00:00
|
|
|
scratch2_, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX));
|
|
|
|
__ cmp(scratch1_, scratch2_);
|
|
|
|
__ b(ne, &false_result);
|
|
|
|
|
|
|
|
// Set the bit in the map to indicate that it has been checked safe for
|
|
|
|
// default valueOf and set true result.
|
2011-03-01 11:23:29 +00:00
|
|
|
__ ldrb(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset));
|
2010-08-12 13:43:08 +00:00
|
|
|
__ orr(scratch1_,
|
|
|
|
scratch1_,
|
|
|
|
Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
|
2011-03-01 11:23:29 +00:00
|
|
|
__ strb(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset));
|
2010-08-12 13:43:08 +00:00
|
|
|
__ mov(map_result_, Operand(1));
|
|
|
|
__ jmp(exit_label());
|
|
|
|
__ bind(&false_result);
|
|
|
|
// Set false result.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ mov(map_result_, Operand(0, RelocInfo::NONE));
|
2010-08-12 13:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register object_;
|
|
|
|
Register map_result_;
|
|
|
|
Register scratch1_;
|
|
|
|
Register scratch2_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::GenerateIsStringWrapperSafeForDefaultValueOf(
|
|
|
|
ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
Load(args->at(0));
|
|
|
|
Register obj = frame_->PopToRegister(); // Pop the string wrapper.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ AbortIfSmi(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether this map has already been checked to be safe for default
|
|
|
|
// valueOf.
|
|
|
|
Register map_result = VirtualFrame::scratch0();
|
|
|
|
__ ldr(map_result, FieldMemOperand(obj, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(ip, FieldMemOperand(map_result, Map::kBitField2Offset));
|
|
|
|
__ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf));
|
|
|
|
true_target()->Branch(ne);
|
|
|
|
|
|
|
|
// We need an additional two scratch registers for the deferred code.
|
|
|
|
Register scratch1 = VirtualFrame::scratch1();
|
|
|
|
// Use r6 without notifying the virtual frame.
|
|
|
|
Register scratch2 = r6;
|
|
|
|
|
|
|
|
DeferredIsStringWrapperSafeForDefaultValueOf* deferred =
|
|
|
|
new DeferredIsStringWrapperSafeForDefaultValueOf(
|
|
|
|
obj, map_result, scratch1, scratch2);
|
|
|
|
deferred->Branch(eq);
|
|
|
|
deferred->BindExit();
|
|
|
|
__ tst(map_result, Operand(map_result));
|
|
|
|
cc_reg_ = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 07:41:32 +00:00
|
|
|
void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) {
|
|
|
|
// This generates a fast version of:
|
|
|
|
// (%_ClassOf(arg) === 'Function')
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Register possible_function = frame_->PopToRegister();
|
|
|
|
__ tst(possible_function, Operand(kSmiTagMask));
|
2009-11-19 07:41:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2010-05-28 11:23:07 +00:00
|
|
|
Register map_reg = VirtualFrame::scratch0();
|
|
|
|
Register scratch = VirtualFrame::scratch1();
|
|
|
|
__ CompareObjectType(possible_function, map_reg, scratch, JS_FUNCTION_TYPE);
|
2009-11-19 07:41:32 +00:00
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-19 14:15:47 +00:00
|
|
|
void CodeGenerator::GenerateIsUndetectableObject(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Register possible_undetectable = frame_->PopToRegister();
|
|
|
|
__ tst(possible_undetectable, Operand(kSmiTagMask));
|
2010-01-19 14:15:47 +00:00
|
|
|
false_target()->Branch(eq);
|
2010-05-28 11:23:07 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
__ ldr(scratch,
|
|
|
|
FieldMemOperand(possible_undetectable, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset));
|
|
|
|
__ tst(scratch, Operand(1 << Map::kIsUndetectable));
|
2010-01-19 14:15:47 +00:00
|
|
|
cc_reg_ = ne;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-29 08:14:06 +00:00
|
|
|
void CodeGenerator::GenerateIsConstructCall(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 0);
|
2009-07-07 19:00:24 +00:00
|
|
|
|
2010-05-26 08:40:11 +00:00
|
|
|
Register scratch0 = VirtualFrame::scratch0();
|
|
|
|
Register scratch1 = VirtualFrame::scratch1();
|
2009-07-07 19:00:24 +00:00
|
|
|
// Get the frame pointer for the calling frame.
|
2010-05-26 08:40:11 +00:00
|
|
|
__ ldr(scratch0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
2009-07-07 19:00:24 +00:00
|
|
|
|
|
|
|
// Skip the arguments adaptor frame if it exists.
|
2010-05-26 08:40:11 +00:00
|
|
|
__ ldr(scratch1,
|
|
|
|
MemOperand(scratch0, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
__ ldr(scratch0,
|
|
|
|
MemOperand(scratch0, StandardFrameConstants::kCallerFPOffset), eq);
|
2009-07-07 19:00:24 +00:00
|
|
|
|
|
|
|
// Check the marker in the calling frame.
|
2010-05-26 08:40:11 +00:00
|
|
|
__ ldr(scratch1,
|
|
|
|
MemOperand(scratch0, StandardFrameConstants::kMarkerOffset));
|
|
|
|
__ cmp(scratch1, Operand(Smi::FromInt(StackFrame::CONSTRUCT)));
|
2009-07-07 19:00:24 +00:00
|
|
|
cc_reg_ = eq;
|
2009-06-29 08:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-26 08:40:11 +00:00
|
|
|
Register tos = frame_->GetTOSRegister();
|
|
|
|
Register scratch0 = VirtualFrame::scratch0();
|
|
|
|
Register scratch1 = VirtualFrame::scratch1();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-30 13:55:03 +00:00
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
2010-05-26 08:40:11 +00:00
|
|
|
__ ldr(scratch0,
|
|
|
|
MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ ldr(scratch1,
|
|
|
|
MemOperand(scratch0, StandardFrameConstants::kContextOffset));
|
|
|
|
__ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
|
|
|
|
|
|
|
|
// Get the number of formal parameters.
|
|
|
|
__ mov(tos, Operand(Smi::FromInt(scope()->num_parameters())), LeaveCC, ne);
|
2010-03-30 13:55:03 +00:00
|
|
|
|
|
|
|
// Arguments adaptor case: Read the arguments length from the
|
|
|
|
// adaptor frame.
|
2010-05-26 08:40:11 +00:00
|
|
|
__ ldr(tos,
|
|
|
|
MemOperand(scratch0, ArgumentsAdaptorFrameConstants::kLengthOffset),
|
|
|
|
eq);
|
2010-03-30 13:55:03 +00:00
|
|
|
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->EmitPush(tos);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-03-11 09:27:12 +00:00
|
|
|
void CodeGenerator::GenerateArguments(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
|
|
|
|
// Satisfy contract with ArgumentsAccessStub:
|
|
|
|
// Load the key into r1 and the formal parameters count into r0.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(0));
|
2010-08-11 10:55:44 +00:00
|
|
|
frame_->PopToR1();
|
|
|
|
frame_->SpillAll();
|
2010-02-03 16:12:55 +00:00
|
|
|
__ mov(r0, Operand(Smi::FromInt(scope()->num_parameters())));
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
// Call the shared stub to get to arguments[key].
|
2008-10-06 06:08:15 +00:00
|
|
|
ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallStub(&stub, 0);
|
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2010-04-07 08:18:51 +00:00
|
|
|
void CodeGenerator::GenerateRandomHeapNumber(
|
|
|
|
ZoneList<Expression*>* args) {
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
2009-06-15 08:04:47 +00:00
|
|
|
ASSERT(args->length() == 0);
|
2010-04-07 08:18:51 +00:00
|
|
|
|
|
|
|
Label slow_allocate_heapnumber;
|
|
|
|
Label heapnumber_allocated;
|
|
|
|
|
2010-06-17 21:51:51 +00:00
|
|
|
__ LoadRoot(r6, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber);
|
2010-04-07 08:18:51 +00:00
|
|
|
__ jmp(&heapnumber_allocated);
|
|
|
|
|
|
|
|
__ bind(&slow_allocate_heapnumber);
|
2010-07-08 13:50:13 +00:00
|
|
|
// Allocate a heap number.
|
|
|
|
__ CallRuntime(Runtime::kNumberAlloc, 0);
|
2010-04-22 17:25:42 +00:00
|
|
|
__ mov(r4, Operand(r0));
|
2010-04-07 08:18:51 +00:00
|
|
|
|
|
|
|
__ bind(&heapnumber_allocated);
|
2010-04-22 17:25:42 +00:00
|
|
|
|
|
|
|
// Convert 32 random bits in r0 to 0.(32 random bits) in a double
|
|
|
|
// by computing:
|
|
|
|
// ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2010-04-22 17:25:42 +00:00
|
|
|
__ PrepareCallCFunction(0, r1);
|
2011-03-22 13:20:04 +00:00
|
|
|
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 0);
|
2010-04-22 17:25:42 +00:00
|
|
|
|
|
|
|
CpuFeatures::Scope scope(VFP3);
|
|
|
|
// 0x41300000 is the top half of 1.0 x 2^20 as a double.
|
|
|
|
// Create this constant using mov/orr to avoid PC relative load.
|
|
|
|
__ mov(r1, Operand(0x41000000));
|
|
|
|
__ orr(r1, r1, Operand(0x300000));
|
|
|
|
// Move 0x41300000xxxxxxxx (x = random bits) to VFP.
|
|
|
|
__ vmov(d7, r0, r1);
|
|
|
|
// Move 0x4130000000000000 to VFP.
|
2010-09-07 11:09:45 +00:00
|
|
|
__ mov(r0, Operand(0, RelocInfo::NONE));
|
2010-04-22 17:25:42 +00:00
|
|
|
__ vmov(d8, r0, r1);
|
|
|
|
// Subtract and store the result in the heap number.
|
|
|
|
__ vsub(d7, d7, d8);
|
|
|
|
__ sub(r0, r4, Operand(kHeapObjectTag));
|
|
|
|
__ vstr(d7, r0, HeapNumber::kValueOffset);
|
|
|
|
frame_->EmitPush(r4);
|
|
|
|
} else {
|
|
|
|
__ mov(r0, Operand(r4));
|
|
|
|
__ PrepareCallCFunction(1, r1);
|
|
|
|
__ CallCFunction(
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::fill_heap_number_with_random_function(isolate()), 1);
|
2010-04-22 17:25:42 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
2009-06-15 08:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-03 07:56:21 +00:00
|
|
|
void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(2, args->length());
|
|
|
|
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
|
2010-02-05 12:00:42 +00:00
|
|
|
StringAddStub stub(NO_STRING_ADD_FLAGS);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->SpillAll();
|
2010-02-05 12:00:42 +00:00
|
|
|
frame_->CallStub(&stub, 2);
|
2009-12-03 07:56:21 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-07 09:59:37 +00:00
|
|
|
void CodeGenerator::GenerateSubString(ZoneList<Expression*>* args) {
|
2010-01-07 13:17:37 +00:00
|
|
|
ASSERT_EQ(3, args->length());
|
2010-01-07 09:59:37 +00:00
|
|
|
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
Load(args->at(2));
|
|
|
|
|
2010-02-04 09:11:43 +00:00
|
|
|
SubStringStub stub;
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->SpillAll();
|
2010-02-04 09:11:43 +00:00
|
|
|
frame_->CallStub(&stub, 3);
|
2010-01-07 09:59:37 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-08 11:58:15 +00:00
|
|
|
void CodeGenerator::GenerateStringCompare(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(2, args->length());
|
|
|
|
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
|
2010-01-21 12:10:56 +00:00
|
|
|
StringCompareStub stub;
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->SpillAll();
|
2010-01-21 12:10:56 +00:00
|
|
|
frame_->CallStub(&stub, 2);
|
2010-01-08 11:58:15 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-06 11:09:30 +00:00
|
|
|
void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(4, args->length());
|
|
|
|
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
Load(args->at(2));
|
|
|
|
Load(args->at(3));
|
2010-04-14 09:25:33 +00:00
|
|
|
RegExpExecStub stub;
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->SpillAll();
|
2010-04-14 09:25:33 +00:00
|
|
|
frame_->CallStub(&stub, 4);
|
2010-01-06 11:09:30 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-13 09:31:03 +00:00
|
|
|
void CodeGenerator::GenerateRegExpConstructResult(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(3, args->length());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-04-13 09:31:03 +00:00
|
|
|
Load(args->at(0)); // Size of array, smi.
|
|
|
|
Load(args->at(1)); // "index" property value.
|
|
|
|
Load(args->at(2)); // "input" property value.
|
2010-12-07 11:31:57 +00:00
|
|
|
RegExpConstructResultStub stub;
|
|
|
|
frame_->SpillAll();
|
|
|
|
frame_->CallStub(&stub, 3);
|
2010-04-13 09:31:03 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-14 14:46:15 +00:00
|
|
|
class DeferredSearchCache: public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredSearchCache(Register dst, Register cache, Register key)
|
|
|
|
: dst_(dst), cache_(cache), key_(key) {
|
|
|
|
set_comment("[ DeferredSearchCache");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register dst_, cache_, key_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredSearchCache::Generate() {
|
2010-04-26 14:25:29 +00:00
|
|
|
__ Push(cache_, key_);
|
2010-04-14 14:46:15 +00:00
|
|
|
__ CallRuntime(Runtime::kGetFromCache, 2);
|
2010-08-11 10:55:44 +00:00
|
|
|
__ Move(dst_, r0);
|
2010-04-14 14:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::GenerateGetFromCache(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(2, args->length());
|
|
|
|
|
|
|
|
ASSERT_NE(NULL, args->at(0)->AsLiteral());
|
|
|
|
int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value();
|
|
|
|
|
|
|
|
Handle<FixedArray> jsfunction_result_caches(
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->global_context()->jsfunction_result_caches());
|
2010-04-14 14:46:15 +00:00
|
|
|
if (jsfunction_result_caches->length() <= cache_id) {
|
|
|
|
__ Abort("Attempt to use undefined cache.");
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex);
|
2010-04-14 14:46:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Load(args->at(1));
|
2010-05-28 11:23:07 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
frame_->PopToR1();
|
|
|
|
frame_->SpillAll();
|
|
|
|
Register key = r1; // Just poped to r1
|
|
|
|
Register result = r0; // Free, as frame has just been spilled.
|
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2010-04-14 14:46:15 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
__ ldr(scratch1, ContextOperand(cp, Context::GLOBAL_INDEX));
|
|
|
|
__ ldr(scratch1,
|
|
|
|
FieldMemOperand(scratch1, GlobalObject::kGlobalContextOffset));
|
|
|
|
__ ldr(scratch1,
|
|
|
|
ContextOperand(scratch1, Context::JSFUNCTION_RESULT_CACHES_INDEX));
|
|
|
|
__ ldr(scratch1,
|
|
|
|
FieldMemOperand(scratch1, FixedArray::OffsetOfElementAt(cache_id)));
|
2010-04-25 10:31:52 +00:00
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
DeferredSearchCache* deferred =
|
|
|
|
new DeferredSearchCache(result, scratch1, key);
|
2010-04-14 14:46:15 +00:00
|
|
|
|
|
|
|
const int kFingerOffset =
|
|
|
|
FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex);
|
2010-07-23 08:25:48 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1);
|
2010-08-11 10:55:44 +00:00
|
|
|
__ ldr(result, FieldMemOperand(scratch1, kFingerOffset));
|
|
|
|
// result now holds finger offset as a smi.
|
|
|
|
__ add(scratch2, scratch1, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
// scratch2 now points to the start of fixed array elements.
|
|
|
|
__ ldr(result,
|
|
|
|
MemOperand(
|
|
|
|
scratch2, result, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex));
|
|
|
|
// Note side effect of PreIndex: scratch2 now points to the key of the pair.
|
|
|
|
__ cmp(key, result);
|
2010-04-14 14:46:15 +00:00
|
|
|
deferred->Branch(ne);
|
|
|
|
|
2010-08-11 10:55:44 +00:00
|
|
|
__ ldr(result, MemOperand(scratch2, kPointerSize));
|
2010-04-14 14:46:15 +00:00
|
|
|
|
|
|
|
deferred->BindExit();
|
2010-08-11 10:55:44 +00:00
|
|
|
frame_->EmitPush(result);
|
2010-04-14 14:46:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-16 09:41:11 +00:00
|
|
|
void CodeGenerator::GenerateNumberToString(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(args->length(), 1);
|
|
|
|
|
|
|
|
// Load the argument on the stack and jump to the runtime.
|
|
|
|
Load(args->at(0));
|
|
|
|
|
2010-03-15 17:11:08 +00:00
|
|
|
NumberToStringStub stub;
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->SpillAll();
|
2010-03-15 17:11:08 +00:00
|
|
|
frame_->CallStub(&stub, 1);
|
2010-02-16 09:41:11 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 11:06:59 +00:00
|
|
|
class DeferredSwapElements: public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredSwapElements(Register object, Register index1, Register index2)
|
|
|
|
: object_(object), index1_(index1), index2_(index2) {
|
|
|
|
set_comment("[ DeferredSwapElements");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register object_, index1_, index2_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredSwapElements::Generate() {
|
|
|
|
__ push(object_);
|
|
|
|
__ push(index1_);
|
|
|
|
__ push(index2_);
|
|
|
|
__ CallRuntime(Runtime::kSwapElements, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-29 15:14:39 +00:00
|
|
|
void CodeGenerator::GenerateSwapElements(ZoneList<Expression*>* args) {
|
|
|
|
Comment cmnt(masm_, "[ GenerateSwapElements");
|
|
|
|
|
|
|
|
ASSERT_EQ(3, args->length());
|
|
|
|
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
Load(args->at(2));
|
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
|
|
|
|
2010-05-04 11:06:59 +00:00
|
|
|
Register index2 = r2;
|
|
|
|
Register index1 = r1;
|
|
|
|
Register object = r0;
|
|
|
|
Register tmp1 = r3;
|
|
|
|
Register tmp2 = r4;
|
|
|
|
|
|
|
|
frame_->EmitPop(index2);
|
|
|
|
frame_->EmitPop(index1);
|
|
|
|
frame_->EmitPop(object);
|
|
|
|
|
|
|
|
DeferredSwapElements* deferred =
|
|
|
|
new DeferredSwapElements(object, index1, index2);
|
|
|
|
|
|
|
|
// Fetch the map and check if array is in fast case.
|
|
|
|
// Check that object doesn't require security checks and
|
|
|
|
// has no indexed interceptor.
|
2011-03-15 10:03:57 +00:00
|
|
|
__ CompareObjectType(object, tmp1, tmp2, JS_ARRAY_TYPE);
|
|
|
|
deferred->Branch(ne);
|
2010-05-04 11:06:59 +00:00
|
|
|
__ ldrb(tmp2, FieldMemOperand(tmp1, Map::kBitFieldOffset));
|
|
|
|
__ tst(tmp2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask));
|
2011-01-26 08:32:54 +00:00
|
|
|
deferred->Branch(ne);
|
2010-05-04 11:06:59 +00:00
|
|
|
|
2010-08-16 16:06:46 +00:00
|
|
|
// Check the object's elements are in fast case and writable.
|
2010-05-04 11:06:59 +00:00
|
|
|
__ ldr(tmp1, FieldMemOperand(object, JSObject::kElementsOffset));
|
|
|
|
__ ldr(tmp2, FieldMemOperand(tmp1, HeapObject::kMapOffset));
|
|
|
|
__ LoadRoot(ip, Heap::kFixedArrayMapRootIndex);
|
|
|
|
__ cmp(tmp2, ip);
|
|
|
|
deferred->Branch(ne);
|
|
|
|
|
|
|
|
// Smi-tagging is equivalent to multiplying by 2.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
|
|
|
// Check that both indices are smis.
|
|
|
|
__ mov(tmp2, index1);
|
|
|
|
__ orr(tmp2, tmp2, index2);
|
|
|
|
__ tst(tmp2, Operand(kSmiTagMask));
|
2011-01-26 08:32:54 +00:00
|
|
|
deferred->Branch(ne);
|
2010-05-04 11:06:59 +00:00
|
|
|
|
2010-12-15 09:52:58 +00:00
|
|
|
// Check that both indices are valid.
|
|
|
|
__ ldr(tmp2, FieldMemOperand(object, JSArray::kLengthOffset));
|
|
|
|
__ cmp(tmp2, index1);
|
|
|
|
__ cmp(tmp2, index2, hi);
|
|
|
|
deferred->Branch(ls);
|
|
|
|
|
2010-05-04 11:06:59 +00:00
|
|
|
// Bring the offsets into the fixed array in tmp1 into index1 and
|
|
|
|
// index2.
|
|
|
|
__ mov(tmp2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ add(index1, tmp2, Operand(index1, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
__ add(index2, tmp2, Operand(index2, LSL, kPointerSizeLog2 - kSmiTagSize));
|
|
|
|
|
|
|
|
// Swap elements.
|
|
|
|
Register tmp3 = object;
|
|
|
|
object = no_reg;
|
|
|
|
__ ldr(tmp3, MemOperand(tmp1, index1));
|
|
|
|
__ ldr(tmp2, MemOperand(tmp1, index2));
|
|
|
|
__ str(tmp3, MemOperand(tmp1, index2));
|
|
|
|
__ str(tmp2, MemOperand(tmp1, index1));
|
|
|
|
|
|
|
|
Label done;
|
|
|
|
__ InNewSpace(tmp1, tmp2, eq, &done);
|
|
|
|
// Possible optimization: do a check that both values are Smis
|
|
|
|
// (or them and test against Smi mask.)
|
|
|
|
|
|
|
|
__ mov(tmp2, tmp1);
|
2011-01-03 14:59:12 +00:00
|
|
|
__ add(index1, index1, tmp1);
|
|
|
|
__ add(index2, index2, tmp1);
|
|
|
|
__ RecordWriteHelper(tmp1, index1, tmp3);
|
|
|
|
__ RecordWriteHelper(tmp2, index2, tmp3);
|
2010-05-04 11:06:59 +00:00
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
deferred->BindExit();
|
|
|
|
__ LoadRoot(tmp1, Heap::kUndefinedValueRootIndex);
|
|
|
|
frame_->EmitPush(tmp1);
|
2010-04-29 15:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 07:05:24 +00:00
|
|
|
void CodeGenerator::GenerateCallFunction(ZoneList<Expression*>* args) {
|
|
|
|
Comment cmnt(masm_, "[ GenerateCallFunction");
|
|
|
|
|
|
|
|
ASSERT(args->length() >= 2);
|
|
|
|
|
|
|
|
int n_args = args->length() - 2; // for receiver and function.
|
|
|
|
Load(args->at(0)); // receiver
|
|
|
|
for (int i = 0; i < n_args; i++) {
|
|
|
|
Load(args->at(i + 1));
|
|
|
|
}
|
|
|
|
Load(args->at(n_args + 1)); // function
|
|
|
|
frame_->CallJSFunction(n_args);
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-23 10:29:02 +00:00
|
|
|
void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(args->length(), 1);
|
|
|
|
Load(args->at(0));
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2011-03-02 14:40:38 +00:00
|
|
|
TranscendentalCacheStub stub(TranscendentalCache::SIN,
|
|
|
|
TranscendentalCacheStub::TAGGED);
|
2010-06-11 10:18:44 +00:00
|
|
|
frame_->SpillAllButCopyTOSToR0();
|
|
|
|
frame_->CallStub(&stub, 1);
|
|
|
|
} else {
|
|
|
|
frame_->CallRuntime(Runtime::kMath_sin, 1);
|
|
|
|
}
|
2010-02-23 10:29:02 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(args->length(), 1);
|
|
|
|
Load(args->at(0));
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2011-03-02 14:40:38 +00:00
|
|
|
TranscendentalCacheStub stub(TranscendentalCache::COS,
|
|
|
|
TranscendentalCacheStub::TAGGED);
|
2010-06-11 10:18:44 +00:00
|
|
|
frame_->SpillAllButCopyTOSToR0();
|
|
|
|
frame_->CallStub(&stub, 1);
|
|
|
|
} else {
|
|
|
|
frame_->CallRuntime(Runtime::kMath_cos, 1);
|
|
|
|
}
|
2010-02-23 10:29:02 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-02 11:20:44 +00:00
|
|
|
void CodeGenerator::GenerateMathLog(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT_EQ(args->length(), 1);
|
|
|
|
Load(args->at(0));
|
2011-03-18 20:35:07 +00:00
|
|
|
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
|
2011-03-02 14:40:38 +00:00
|
|
|
TranscendentalCacheStub stub(TranscendentalCache::LOG,
|
|
|
|
TranscendentalCacheStub::TAGGED);
|
2010-12-02 11:20:44 +00:00
|
|
|
frame_->SpillAllButCopyTOSToR0();
|
|
|
|
frame_->CallStub(&stub, 1);
|
|
|
|
} else {
|
|
|
|
frame_->CallRuntime(Runtime::kMath_log, 1);
|
|
|
|
}
|
|
|
|
frame_->EmitPush(r0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) {
|
2008-10-02 11:54:32 +00:00
|
|
|
ASSERT(args->length() == 2);
|
|
|
|
|
|
|
|
// Load the two objects into registers and perform the comparison.
|
2010-05-26 08:40:11 +00:00
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
Register lhs = frame_->PopToRegister();
|
|
|
|
Register rhs = frame_->PopToRegister(lhs);
|
|
|
|
__ cmp(lhs, rhs);
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-06 13:04:27 +00:00
|
|
|
void CodeGenerator::GenerateIsRegExpEquivalent(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 2);
|
|
|
|
|
|
|
|
// Load the two objects into registers and perform the comparison.
|
|
|
|
Load(args->at(0));
|
|
|
|
Load(args->at(1));
|
|
|
|
Register right = frame_->PopToRegister();
|
|
|
|
Register left = frame_->PopToRegister(right);
|
|
|
|
Register tmp = frame_->scratch0();
|
|
|
|
Register tmp2 = frame_->scratch1();
|
|
|
|
|
|
|
|
// Jumps to done must have the eq flag set if the test is successful
|
|
|
|
// and clear if the test has failed.
|
|
|
|
Label done;
|
|
|
|
|
|
|
|
// Fail if either is a non-HeapObject.
|
|
|
|
__ cmp(left, Operand(right));
|
|
|
|
__ b(eq, &done);
|
|
|
|
__ and_(tmp, left, Operand(right));
|
|
|
|
__ eor(tmp, tmp, Operand(kSmiTagMask));
|
|
|
|
__ tst(tmp, Operand(kSmiTagMask));
|
|
|
|
__ b(ne, &done);
|
|
|
|
__ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset));
|
|
|
|
__ cmp(tmp2, Operand(JS_REGEXP_TYPE));
|
|
|
|
__ b(ne, &done);
|
|
|
|
__ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset));
|
|
|
|
__ cmp(tmp, Operand(tmp2));
|
|
|
|
__ b(ne, &done);
|
|
|
|
__ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset));
|
|
|
|
__ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset));
|
|
|
|
__ cmp(tmp, tmp2);
|
|
|
|
__ bind(&done);
|
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-27 11:47:12 +00:00
|
|
|
void CodeGenerator::GenerateHasCachedArrayIndex(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
Load(args->at(0));
|
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
Register tmp = frame_->scratch0();
|
|
|
|
__ ldr(tmp, FieldMemOperand(value, String::kHashFieldOffset));
|
|
|
|
__ tst(tmp, Operand(String::kContainsCachedArrayIndexMask));
|
|
|
|
cc_reg_ = eq;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::GenerateGetCachedArrayIndex(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 1);
|
|
|
|
Load(args->at(0));
|
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
|
|
|
|
__ ldr(value, FieldMemOperand(value, String::kHashFieldOffset));
|
|
|
|
__ IndexFromHash(value, value);
|
|
|
|
frame_->EmitPush(value);
|
|
|
|
}
|
|
|
|
|
2010-08-06 13:04:27 +00:00
|
|
|
|
2010-11-19 09:25:46 +00:00
|
|
|
void CodeGenerator::GenerateFastAsciiArrayJoin(ZoneList<Expression*>* args) {
|
|
|
|
ASSERT(args->length() == 2);
|
|
|
|
Load(args->at(0));
|
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
__ LoadRoot(value, Heap::kUndefinedValueRootIndex);
|
|
|
|
frame_->EmitPush(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitCallRuntime(CallRuntime* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
if (CheckForInlineRuntimeCall(node)) {
|
|
|
|
ASSERT((has_cc() && frame_->height() == original_height) ||
|
|
|
|
(!has_cc() && frame_->height() == original_height + 1));
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
ZoneList<Expression*>* args = node->arguments();
|
|
|
|
Comment cmnt(masm_, "[ CallRuntime");
|
2011-03-18 20:35:07 +00:00
|
|
|
const Runtime::Function* function = node->function();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-03-25 11:05:36 +00:00
|
|
|
if (function == NULL) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// Prepare stack for calling JS runtime function.
|
|
|
|
// Push the builtins object found in the current global object.
|
2010-05-28 11:23:07 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2010-11-10 17:00:20 +00:00
|
|
|
__ ldr(scratch, GlobalObjectOperand());
|
2010-05-28 11:23:07 +00:00
|
|
|
Register builtins = frame_->GetTOSRegister();
|
|
|
|
__ ldr(builtins, FieldMemOperand(scratch, GlobalObject::kBuiltinsOffset));
|
|
|
|
frame_->EmitPush(builtins);
|
2009-03-25 11:05:36 +00:00
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2009-03-25 11:05:36 +00:00
|
|
|
// Push the arguments ("left-to-right").
|
|
|
|
int arg_count = args->length();
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(args->at(i));
|
2009-03-25 11:05:36 +00:00
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2010-05-28 11:23:07 +00:00
|
|
|
VirtualFrame::SpilledScope spilled_scope(frame_);
|
|
|
|
|
2009-03-25 11:05:36 +00:00
|
|
|
if (function == NULL) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// Call the JS runtime function.
|
2010-02-15 12:26:07 +00:00
|
|
|
__ mov(r2, Operand(node->name()));
|
2009-05-25 18:29:02 +00:00
|
|
|
InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP;
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> stub =
|
|
|
|
ISOLATE->stub_cache()->ComputeCallInitialize(arg_count, in_loop);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1);
|
2008-11-05 08:44:54 +00:00
|
|
|
__ ldr(cp, frame_->Context());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(r0);
|
2009-03-25 11:05:36 +00:00
|
|
|
} else {
|
|
|
|
// Call the C runtime function.
|
|
|
|
frame_->CallRuntime(function, arg_count);
|
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ UnaryOperation");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
Token::Value op = node->op();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
if (op == Token::NOT) {
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->expression(), false_target(), true_target(), true);
|
2009-07-09 04:22:05 +00:00
|
|
|
// LoadCondition may (and usually does) leave a test and branch to
|
|
|
|
// be emitted by the caller. In that case, negate the condition.
|
2009-07-08 22:05:06 +00:00
|
|
|
if (has_cc()) cc_reg_ = NegateCondition(cc_reg_);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (op == Token::DELETE) {
|
|
|
|
Property* property = node->expression()->AsProperty();
|
|
|
|
Variable* variable = node->expression()->AsVariableProxy()->AsVariable();
|
|
|
|
if (property != NULL) {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(property->obj());
|
|
|
|
Load(property->key());
|
2011-02-14 23:41:47 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(strict_mode_flag())));
|
|
|
|
frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 3);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (variable != NULL) {
|
2011-02-14 23:41:47 +00:00
|
|
|
// Delete of an unqualified identifier is disallowed in strict mode
|
2011-02-22 17:20:25 +00:00
|
|
|
// but "delete this" is.
|
|
|
|
ASSERT(strict_mode_flag() == kNonStrictMode || variable->is_this());
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = variable->AsSlot();
|
2008-10-02 11:54:32 +00:00
|
|
|
if (variable->is_global()) {
|
|
|
|
LoadGlobal();
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(Operand(variable->name()));
|
2011-02-14 23:41:47 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(kNonStrictMode)));
|
|
|
|
frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 3);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (slot != NULL && slot->type() == Slot::LOOKUP) {
|
2011-01-24 14:03:30 +00:00
|
|
|
// Delete from the context holding the named variable.
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->EmitPush(cp);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(Operand(variable->name()));
|
2011-01-24 14:03:30 +00:00
|
|
|
frame_->CallRuntime(Runtime::kDeleteContextSlot, 2);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
// Default: Result of deleting non-global, not dynamically
|
|
|
|
// introduced variables is false.
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kFalseValueRootIndex);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
// Default: Result of deleting expressions is true.
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->expression()); // may have side-effects
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->Drop();
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPushRoot(Heap::kTrueValueRootIndex);
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (op == Token::TYPEOF) {
|
|
|
|
// Special case for loading the typeof expression; see comment on
|
|
|
|
// LoadTypeofExpression().
|
|
|
|
LoadTypeofExpression(node->expression());
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallRuntime(Runtime::kTypeof, 1);
|
|
|
|
frame_->EmitPush(r0); // r0 has result
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2010-08-25 11:10:05 +00:00
|
|
|
bool can_overwrite = node->expression()->ResultOverwriteAllowed();
|
2010-07-05 11:03:16 +00:00
|
|
|
UnaryOverwriteMode overwrite =
|
|
|
|
can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE;
|
|
|
|
|
|
|
|
bool no_negative_zero = node->expression()->no_negative_zero();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->expression());
|
2008-10-02 11:54:32 +00:00
|
|
|
switch (op) {
|
|
|
|
case Token::NOT:
|
|
|
|
case Token::DELETE:
|
|
|
|
case Token::TYPEOF:
|
|
|
|
UNREACHABLE(); // handled above
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::SUB: {
|
2010-06-24 11:05:38 +00:00
|
|
|
frame_->PopToR0();
|
2010-07-05 11:03:16 +00:00
|
|
|
GenericUnaryOpStub stub(
|
|
|
|
Token::SUB,
|
|
|
|
overwrite,
|
2010-09-15 10:14:25 +00:00
|
|
|
NO_UNARY_FLAGS,
|
2010-07-05 11:03:16 +00:00
|
|
|
no_negative_zero ? kIgnoreNegativeZero : kStrictNegativeZero);
|
2009-02-27 13:00:32 +00:00
|
|
|
frame_->CallStub(&stub, 0);
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->EmitPush(r0); // r0 has result
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
case Token::BIT_NOT: {
|
2010-06-24 11:05:38 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
|
|
|
JumpTarget not_smi_label;
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget continue_label;
|
2010-06-24 11:05:38 +00:00
|
|
|
// Smi check.
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
not_smi_label.Branch(ne);
|
|
|
|
|
|
|
|
__ mvn(tos, Operand(tos));
|
|
|
|
__ bic(tos, tos, Operand(kSmiTagMask)); // Bit-clear inverted smi-tag.
|
|
|
|
frame_->EmitPush(tos);
|
|
|
|
// The fast case is the first to jump to the continue label, so it gets
|
|
|
|
// to decide the virtual frame layout.
|
|
|
|
continue_label.Jump();
|
2008-10-02 11:54:32 +00:00
|
|
|
|
2010-06-24 11:05:38 +00:00
|
|
|
not_smi_label.Bind();
|
|
|
|
frame_->SpillAll();
|
|
|
|
__ Move(r0, tos);
|
2010-09-15 10:14:25 +00:00
|
|
|
GenericUnaryOpStub stub(Token::BIT_NOT,
|
|
|
|
overwrite,
|
|
|
|
NO_UNARY_SMI_CODE_IN_STUB);
|
2010-01-28 08:14:19 +00:00
|
|
|
frame_->CallStub(&stub, 0);
|
2010-06-24 11:05:38 +00:00
|
|
|
frame_->EmitPush(r0);
|
2010-01-28 08:14:19 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
continue_label.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
case Token::VOID:
|
2010-05-28 11:23:07 +00:00
|
|
|
frame_->Drop();
|
|
|
|
frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Token::ADD: {
|
2010-06-24 11:05:38 +00:00
|
|
|
Register tos = frame_->Peek();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Smi check.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget continue_label;
|
2010-06-24 11:05:38 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
continue_label.Branch(eq);
|
2010-06-24 11:05:38 +00:00
|
|
|
|
2009-12-04 12:17:02 +00:00
|
|
|
frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1);
|
2010-06-24 11:05:38 +00:00
|
|
|
frame_->EmitPush(r0);
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
continue_label.Bind();
|
2008-07-03 15:10:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-23 11:40:14 +00:00
|
|
|
ASSERT(!has_valid_frame() ||
|
|
|
|
(has_cc() && frame_->height() == original_height) ||
|
2009-02-27 13:00:32 +00:00
|
|
|
(!has_cc() && frame_->height() == original_height + 1));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-24 09:55:58 +00:00
|
|
|
class DeferredCountOperation: public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredCountOperation(Register value,
|
|
|
|
bool is_increment,
|
|
|
|
bool is_postfix,
|
|
|
|
int target_size)
|
|
|
|
: value_(value),
|
|
|
|
is_increment_(is_increment),
|
|
|
|
is_postfix_(is_postfix),
|
|
|
|
target_size_(target_size) {}
|
|
|
|
|
|
|
|
virtual void Generate() {
|
|
|
|
VirtualFrame copied_frame(*frame_state()->frame());
|
|
|
|
|
|
|
|
Label slow;
|
|
|
|
// Check for smi operand.
|
|
|
|
__ tst(value_, Operand(kSmiTagMask));
|
|
|
|
__ b(ne, &slow);
|
|
|
|
|
|
|
|
// Revert optimistic increment/decrement.
|
|
|
|
if (is_increment_) {
|
|
|
|
__ sub(value_, value_, Operand(Smi::FromInt(1)));
|
|
|
|
} else {
|
|
|
|
__ add(value_, value_, Operand(Smi::FromInt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slow case: Convert to number. At this point the
|
|
|
|
// value to be incremented is in the value register..
|
|
|
|
__ bind(&slow);
|
|
|
|
|
|
|
|
// Convert the operand to a number.
|
|
|
|
copied_frame.EmitPush(value_);
|
|
|
|
|
|
|
|
copied_frame.InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1);
|
|
|
|
|
|
|
|
if (is_postfix_) {
|
|
|
|
// Postfix: store to result (on the stack).
|
|
|
|
__ str(r0, MemOperand(sp, target_size_ * kPointerSize));
|
|
|
|
}
|
|
|
|
|
|
|
|
copied_frame.EmitPush(r0);
|
|
|
|
copied_frame.EmitPush(Operand(Smi::FromInt(1)));
|
|
|
|
|
|
|
|
if (is_increment_) {
|
|
|
|
copied_frame.CallRuntime(Runtime::kNumberAdd, 2);
|
|
|
|
} else {
|
|
|
|
copied_frame.CallRuntime(Runtime::kNumberSub, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ Move(value_, r0);
|
|
|
|
|
|
|
|
copied_frame.MergeTo(frame_state()->frame());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register value_;
|
|
|
|
bool is_increment_;
|
|
|
|
bool is_postfix_;
|
|
|
|
int target_size_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitCountOperation(CountOperation* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ CountOperation");
|
2010-06-24 11:05:38 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
bool is_postfix = node->is_postfix();
|
|
|
|
bool is_increment = node->op() == Token::INC;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
Variable* var = node->expression()->AsVariableProxy()->AsVariable();
|
|
|
|
bool is_const = (var != NULL && var->mode() == Variable::CONST);
|
2010-06-02 09:37:02 +00:00
|
|
|
bool is_slot = (var != NULL && var->mode() == Variable::VAR);
|
|
|
|
|
2010-09-24 07:53:59 +00:00
|
|
|
if (!is_const && is_slot && type_info(var->AsSlot()).IsSmi()) {
|
2010-06-02 09:37:02 +00:00
|
|
|
// The type info declares that this variable is always a Smi. That
|
|
|
|
// means it is a Smi both before and after the increment/decrement.
|
|
|
|
// Lets make use of that to make a very minimal count.
|
|
|
|
Reference target(this, node->expression(), !is_const);
|
|
|
|
ASSERT(!target.is_illegal());
|
|
|
|
target.GetValue(); // Pushes the value.
|
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
if (is_postfix) frame_->EmitPush(value);
|
|
|
|
if (is_increment) {
|
|
|
|
__ add(value, value, Operand(Smi::FromInt(1)));
|
|
|
|
} else {
|
|
|
|
__ sub(value, value, Operand(Smi::FromInt(1)));
|
|
|
|
}
|
|
|
|
frame_->EmitPush(value);
|
2010-07-01 15:06:24 +00:00
|
|
|
target.SetValue(NOT_CONST_INIT, LIKELY_SMI);
|
2010-06-02 09:37:02 +00:00
|
|
|
if (is_postfix) frame_->Pop();
|
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-06-02 09:37:02 +00:00
|
|
|
// If it's a postfix expression and its result is not ignored and the
|
|
|
|
// reference is non-trivial, then push a placeholder on the stack now
|
|
|
|
// to hold the result of the expression.
|
|
|
|
bool placeholder_pushed = false;
|
|
|
|
if (!is_slot && is_postfix) {
|
2010-05-12 09:00:29 +00:00
|
|
|
frame_->EmitPush(Operand(Smi::FromInt(0)));
|
2010-06-02 09:37:02 +00:00
|
|
|
placeholder_pushed = true;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-01-27 14:07:12 +00:00
|
|
|
// A constant reference is not saved to, so a constant reference is not a
|
|
|
|
// compound assignment reference.
|
|
|
|
{ Reference target(this, node->expression(), !is_const);
|
2009-02-27 13:00:32 +00:00
|
|
|
if (target.is_illegal()) {
|
|
|
|
// Spoof the virtual frame to have the expected height (one higher
|
|
|
|
// than on entry).
|
2010-06-02 09:37:02 +00:00
|
|
|
if (!placeholder_pushed) frame_->EmitPush(Operand(Smi::FromInt(0)));
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2009-02-27 13:00:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-02 09:37:02 +00:00
|
|
|
|
2010-05-12 09:00:29 +00:00
|
|
|
// This pushes 0, 1 or 2 words on the object to be used later when updating
|
|
|
|
// the target. It also pushes the current value of the target.
|
2010-04-08 22:30:30 +00:00
|
|
|
target.GetValue();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-11-24 09:55:58 +00:00
|
|
|
bool value_is_known_smi = frame_->KnownSmiAt(0);
|
2010-05-12 09:00:29 +00:00
|
|
|
Register value = frame_->PopToRegister();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Postfix: Store the old value as the result.
|
2010-06-02 09:37:02 +00:00
|
|
|
if (placeholder_pushed) {
|
2010-05-12 09:00:29 +00:00
|
|
|
frame_->SetElementAt(value, target.size());
|
2010-06-02 09:37:02 +00:00
|
|
|
} else if (is_postfix) {
|
|
|
|
frame_->EmitPush(value);
|
|
|
|
__ mov(VirtualFrame::scratch0(), value);
|
|
|
|
value = VirtualFrame::scratch0();
|
2008-11-05 08:44:54 +00:00
|
|
|
}
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2010-11-24 09:55:58 +00:00
|
|
|
// We can't use any type information here since the virtual frame from the
|
|
|
|
// deferred code may have lost information and we can't merge a virtual
|
|
|
|
// frame with less specific type knowledge to a virtual frame with more
|
|
|
|
// specific knowledge that has already used that specific knowledge to
|
|
|
|
// generate code.
|
|
|
|
frame_->ForgetTypeInfo();
|
|
|
|
|
|
|
|
// The constructor here will capture the current virtual frame and use it to
|
|
|
|
// merge to after the deferred code has run. No virtual frame changes are
|
|
|
|
// allowed from here until the 'BindExit' below.
|
|
|
|
DeferredCode* deferred =
|
|
|
|
new DeferredCountOperation(value,
|
|
|
|
is_increment,
|
|
|
|
is_postfix,
|
|
|
|
target.size());
|
|
|
|
if (!value_is_known_smi) {
|
|
|
|
// Check for smi operand.
|
|
|
|
__ tst(value, Operand(kSmiTagMask));
|
|
|
|
|
|
|
|
deferred->Branch(ne);
|
|
|
|
}
|
2010-06-02 09:37:02 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Perform optimistic increment/decrement.
|
|
|
|
if (is_increment) {
|
2010-05-12 09:00:29 +00:00
|
|
|
__ add(value, value, Operand(Smi::FromInt(1)), SetCC);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2010-05-12 09:00:29 +00:00
|
|
|
__ sub(value, value, Operand(Smi::FromInt(1)), SetCC);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 09:55:58 +00:00
|
|
|
// If increment/decrement overflows, go to deferred code.
|
|
|
|
deferred->Branch(vs);
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2010-11-24 09:55:58 +00:00
|
|
|
deferred->BindExit();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Store the new value in the target if not const.
|
2010-05-12 09:00:29 +00:00
|
|
|
// At this point the answer is in the value register.
|
|
|
|
frame_->EmitPush(value);
|
|
|
|
// Set the target with the result, leaving the result on
|
|
|
|
// top of the stack. Removes the target from the stack if
|
|
|
|
// it has a non-zero size.
|
2010-07-01 15:06:24 +00:00
|
|
|
if (!is_const) target.SetValue(NOT_CONST_INIT, LIKELY_SMI);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2008-10-02 11:54:32 +00:00
|
|
|
|
|
|
|
// Postfix: Discard the new value and use the old.
|
2010-05-12 09:00:29 +00:00
|
|
|
if (is_postfix) frame_->Pop();
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-26 07:55:38 +00:00
|
|
|
void CodeGenerator::GenerateLogicalBooleanOperation(BinaryOperation* node) {
|
2008-10-02 11:54:32 +00:00
|
|
|
// According to ECMA-262 section 11.11, page 58, the binary logical
|
|
|
|
// operators must yield the result of one of the two expressions
|
|
|
|
// before any ToBoolean() conversions. This means that the value
|
|
|
|
// produced by a && or || operator is not necessarily a boolean.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// NOTE: If the left hand side produces a materialized value (not in
|
|
|
|
// the CC register), we force the right hand side to do the
|
|
|
|
// same. This is necessary because we may have to branch to the exit
|
|
|
|
// after evaluating the left hand side (due to the shortcut
|
|
|
|
// semantics), but the compiler must (statically) know if the result
|
|
|
|
// of compiling the binary operation is materialized or not.
|
2010-03-26 07:55:38 +00:00
|
|
|
if (node->op() == Token::AND) {
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget is_true;
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->left(), &is_true, false_target(), false);
|
2009-07-23 11:40:14 +00:00
|
|
|
if (has_valid_frame() && !has_cc()) {
|
|
|
|
// The left-hand side result is on top of the virtual frame.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget pop_and_continue;
|
|
|
|
JumpTarget exit;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->Dup();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Avoid popping the result if it converts to 'false' using the
|
|
|
|
// standard ToBoolean() conversion as described in ECMA-262,
|
|
|
|
// section 9.2, page 30.
|
|
|
|
ToBoolean(&pop_and_continue, &exit);
|
|
|
|
Branch(false, &exit);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Pop the result of evaluating the first part.
|
2009-02-27 13:00:32 +00:00
|
|
|
pop_and_continue.Bind();
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->Pop();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Evaluate right side expression.
|
2009-02-27 13:00:32 +00:00
|
|
|
is_true.Bind();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->right());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Exit (always with a materialized value).
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Bind();
|
2009-07-23 11:40:14 +00:00
|
|
|
} else if (has_cc() || is_true.is_linked()) {
|
|
|
|
// The left-hand side is either (a) partially compiled to
|
|
|
|
// control flow with a final branch left to emit or (b) fully
|
|
|
|
// compiled to control flow and possibly true.
|
|
|
|
if (has_cc()) {
|
|
|
|
Branch(false, false_target());
|
|
|
|
}
|
|
|
|
is_true.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->right(), true_target(), false_target(), false);
|
2009-07-23 11:40:14 +00:00
|
|
|
} else {
|
|
|
|
// Nothing to do.
|
|
|
|
ASSERT(!has_valid_frame() && !has_cc() && !is_true.is_linked());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-03-26 07:55:38 +00:00
|
|
|
} else {
|
|
|
|
ASSERT(node->op() == Token::OR);
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget is_false;
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->left(), true_target(), &is_false, false);
|
2009-07-23 11:40:14 +00:00
|
|
|
if (has_valid_frame() && !has_cc()) {
|
|
|
|
// The left-hand side result is on top of the virtual frame.
|
2009-05-18 12:26:59 +00:00
|
|
|
JumpTarget pop_and_continue;
|
|
|
|
JumpTarget exit;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->Dup();
|
2008-10-02 11:54:32 +00:00
|
|
|
// Avoid popping the result if it converts to 'true' using the
|
|
|
|
// standard ToBoolean() conversion as described in ECMA-262,
|
|
|
|
// section 9.2, page 30.
|
|
|
|
ToBoolean(&exit, &pop_and_continue);
|
|
|
|
Branch(true, &exit);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Pop the result of evaluating the first part.
|
2009-02-27 13:00:32 +00:00
|
|
|
pop_and_continue.Bind();
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->Pop();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Evaluate right side expression.
|
2009-02-27 13:00:32 +00:00
|
|
|
is_false.Bind();
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(node->right());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Exit (always with a materialized value).
|
2009-02-27 13:00:32 +00:00
|
|
|
exit.Bind();
|
2009-07-23 11:40:14 +00:00
|
|
|
} else if (has_cc() || is_false.is_linked()) {
|
|
|
|
// The left-hand side is either (a) partially compiled to
|
|
|
|
// control flow with a final branch left to emit or (b) fully
|
|
|
|
// compiled to control flow and possibly false.
|
|
|
|
if (has_cc()) {
|
|
|
|
Branch(true, true_target());
|
|
|
|
}
|
|
|
|
is_false.Bind();
|
2010-05-31 08:52:57 +00:00
|
|
|
LoadCondition(node->right(), true_target(), false_target(), false);
|
2009-07-23 11:40:14 +00:00
|
|
|
} else {
|
|
|
|
// Nothing to do.
|
|
|
|
ASSERT(!has_valid_frame() && !has_cc() && !is_false.is_linked());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2010-03-26 07:55:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ BinaryOperation");
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2010-03-26 07:55:38 +00:00
|
|
|
if (node->op() == Token::AND || node->op() == Token::OR) {
|
|
|
|
GenerateLogicalBooleanOperation(node);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
|
|
|
// Optimize for the case where (at least) one of the expressions
|
|
|
|
// is a literal small integer.
|
|
|
|
Literal* lliteral = node->left()->AsLiteral();
|
|
|
|
Literal* rliteral = node->right()->AsLiteral();
|
2009-04-16 09:30:23 +00:00
|
|
|
// NOTE: The code below assumes that the slow cases (calls to runtime)
|
|
|
|
// never return a constant/immutable object.
|
2010-08-25 11:10:05 +00:00
|
|
|
bool overwrite_left = node->left()->ResultOverwriteAllowed();
|
|
|
|
bool overwrite_right = node->right()->ResultOverwriteAllowed();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
if (rliteral != NULL && rliteral->handle()->IsSmi()) {
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
Load(node->left());
|
2010-06-02 09:37:02 +00:00
|
|
|
if (frame_->KnownSmiAt(0)) overwrite_left = false;
|
2010-04-29 13:09:31 +00:00
|
|
|
SmiOperation(node->op(),
|
|
|
|
rliteral->handle(),
|
|
|
|
false,
|
2010-06-02 09:37:02 +00:00
|
|
|
overwrite_left ? OVERWRITE_LEFT : NO_OVERWRITE);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else if (lliteral != NULL && lliteral->handle()->IsSmi()) {
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
|
|
|
Load(node->right());
|
2010-06-02 09:37:02 +00:00
|
|
|
if (frame_->KnownSmiAt(0)) overwrite_right = false;
|
2010-04-29 13:09:31 +00:00
|
|
|
SmiOperation(node->op(),
|
|
|
|
lliteral->handle(),
|
|
|
|
true,
|
2010-06-02 09:37:02 +00:00
|
|
|
overwrite_right ? OVERWRITE_RIGHT : NO_OVERWRITE);
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2010-06-02 09:37:02 +00:00
|
|
|
GenerateInlineSmi inline_smi =
|
|
|
|
loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI;
|
|
|
|
if (lliteral != NULL) {
|
|
|
|
ASSERT(!lliteral->handle()->IsSmi());
|
|
|
|
inline_smi = DONT_GENERATE_INLINE_SMI;
|
|
|
|
}
|
|
|
|
if (rliteral != NULL) {
|
|
|
|
ASSERT(!rliteral->handle()->IsSmi());
|
|
|
|
inline_smi = DONT_GENERATE_INLINE_SMI;
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope scope(this);
|
2009-04-16 09:30:23 +00:00
|
|
|
OverwriteMode overwrite_mode = NO_OVERWRITE;
|
|
|
|
if (overwrite_left) {
|
|
|
|
overwrite_mode = OVERWRITE_LEFT;
|
|
|
|
} else if (overwrite_right) {
|
|
|
|
overwrite_mode = OVERWRITE_RIGHT;
|
|
|
|
}
|
2010-04-08 22:30:30 +00:00
|
|
|
Load(node->left());
|
|
|
|
Load(node->right());
|
2010-06-02 09:37:02 +00:00
|
|
|
GenericBinaryOperation(node->op(), overwrite_mode, inline_smi);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-23 11:40:14 +00:00
|
|
|
ASSERT(!has_valid_frame() ||
|
|
|
|
(has_cc() && frame_->height() == original_height) ||
|
2009-02-27 13:00:32 +00:00
|
|
|
(!has_cc() && frame_->height() == original_height + 1));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitThisFunction(ThisFunction* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2010-05-26 08:40:11 +00:00
|
|
|
frame_->EmitPush(MemOperand(frame_->Function()));
|
2010-05-04 09:33:12 +00:00
|
|
|
ASSERT_EQ(original_height + 1, frame_->height());
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2008-10-10 00:00:52 +00:00
|
|
|
void CodeGenerator::VisitCompareOperation(CompareOperation* node) {
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
2008-10-02 11:54:32 +00:00
|
|
|
Comment cmnt(masm_, "[ CompareOperation");
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
VirtualFrame::RegisterAllocationScope nonspilled_scope(this);
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
// Get the expressions from the node.
|
|
|
|
Expression* left = node->left();
|
|
|
|
Expression* right = node->right();
|
|
|
|
Token::Value op = node->op();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-12 11:00:12 +00:00
|
|
|
// To make typeof testing for natives implemented in JavaScript really
|
|
|
|
// efficient, we generate special code for expressions of the form:
|
|
|
|
// 'typeof <expression> == <string>'.
|
2008-10-02 11:54:32 +00:00
|
|
|
UnaryOperation* operation = left->AsUnaryOperation();
|
|
|
|
if ((op == Token::EQ || op == Token::EQ_STRICT) &&
|
|
|
|
(operation != NULL && operation->op() == Token::TYPEOF) &&
|
|
|
|
(right->AsLiteral() != NULL &&
|
|
|
|
right->AsLiteral()->handle()->IsString())) {
|
|
|
|
Handle<String> check(String::cast(*right->AsLiteral()->handle()));
|
2008-09-03 07:34:21 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
// Load the operand, move it to a register.
|
2008-10-02 11:54:32 +00:00
|
|
|
LoadTypeofExpression(operation->expression());
|
2010-04-08 22:30:30 +00:00
|
|
|
Register tos = frame_->PopToRegister();
|
|
|
|
|
|
|
|
Register scratch = VirtualFrame::scratch0();
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
if (check->Equals(HEAP->number_symbol())) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
true_target()->Branch(eq);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset));
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, ip);
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-30 08:49:36 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} else if (check->Equals(HEAP->string_symbol())) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-12 11:00:12 +00:00
|
|
|
// It can be an undetectable string object.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset));
|
|
|
|
__ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ cmp(scratch, Operand(1 << Map::kIsUndetectable));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldrb(scratch, FieldMemOperand(tos, Map::kInstanceTypeOffset));
|
|
|
|
__ cmp(scratch, Operand(FIRST_NONSTRING_TYPE));
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = lt;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} else if (check->Equals(HEAP->boolean_symbol())) {
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kTrueValueRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
true_target()->Branch(eq);
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kFalseValueRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, ip);
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} else if (check->Equals(HEAP->undefined_symbol())) {
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
true_target()->Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-11-12 11:00:12 +00:00
|
|
|
// It can be an undetectable object.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset));
|
|
|
|
__ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ cmp(scratch, Operand(1 << Map::kIsUndetectable));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} else if (check->Equals(HEAP->function_symbol())) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2010-04-08 22:30:30 +00:00
|
|
|
Register map_reg = scratch;
|
|
|
|
__ CompareObjectType(tos, map_reg, tos, JS_FUNCTION_TYPE);
|
2009-11-05 16:08:48 +00:00
|
|
|
true_target()->Branch(eq);
|
|
|
|
// Regular expressions are callable so typeof == 'function'.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ CompareInstanceType(map_reg, tos, JS_REGEXP_TYPE);
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = eq;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
} else if (check->Equals(HEAP->object_symbol())) {
|
2010-04-08 22:30:30 +00:00
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2008-09-08 06:17:38 +00:00
|
|
|
|
2009-08-24 11:57:57 +00:00
|
|
|
__ LoadRoot(ip, Heap::kNullValueRootIndex);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, ip);
|
2009-02-27 13:00:32 +00:00
|
|
|
true_target()->Branch(eq);
|
2008-09-08 06:17:38 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
Register map_reg = scratch;
|
|
|
|
__ CompareObjectType(tos, map_reg, tos, JS_REGEXP_TYPE);
|
2009-11-05 16:08:48 +00:00
|
|
|
false_target()->Branch(eq);
|
|
|
|
|
2008-11-12 11:00:12 +00:00
|
|
|
// It can be an undetectable object.
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldrb(tos, FieldMemOperand(map_reg, Map::kBitFieldOffset));
|
|
|
|
__ and_(tos, tos, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ cmp(tos, Operand(1 << Map::kIsUndetectable));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(eq);
|
2008-09-08 06:17:38 +00:00
|
|
|
|
2010-04-08 22:30:30 +00:00
|
|
|
__ ldrb(tos, FieldMemOperand(map_reg, Map::kInstanceTypeOffset));
|
|
|
|
__ cmp(tos, Operand(FIRST_JS_OBJECT_TYPE));
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Branch(lt);
|
2010-04-08 22:30:30 +00:00
|
|
|
__ cmp(tos, Operand(LAST_JS_OBJECT_TYPE));
|
2008-10-02 11:54:32 +00:00
|
|
|
cc_reg_ = le;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
} else {
|
2008-11-12 11:00:12 +00:00
|
|
|
// Uncommon case: typeof testing against a string literal that is
|
|
|
|
// never returned from the typeof operator.
|
2009-02-27 13:00:32 +00:00
|
|
|
false_target()->Jump();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(!has_valid_frame() ||
|
|
|
|
(has_cc() && frame_->height() == original_height));
|
2008-10-02 11:54:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
switch (op) {
|
|
|
|
case Token::EQ:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(eq, left, right, false);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::LT:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(lt, left, right);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-08-13 09:32:07 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::GT:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(gt, left, right);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::LTE:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(le, left, right);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::GTE:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(ge, left, right);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
case Token::EQ_STRICT:
|
2009-06-29 13:52:13 +00:00
|
|
|
Comparison(eq, left, right, true);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
case Token::IN: {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(left);
|
|
|
|
Load(right);
|
2009-12-04 12:17:02 +00:00
|
|
|
frame_->InvokeBuiltin(Builtins::IN, CALL_JS, 2);
|
2009-08-11 11:46:27 +00:00
|
|
|
frame_->EmitPush(r0);
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
case Token::INSTANCEOF: {
|
2010-05-28 11:23:07 +00:00
|
|
|
Load(left);
|
|
|
|
Load(right);
|
2010-12-16 08:58:42 +00:00
|
|
|
InstanceofStub stub(InstanceofStub::kNoFlags);
|
2009-08-11 11:46:27 +00:00
|
|
|
frame_->CallStub(&stub, 2);
|
2009-06-10 11:42:13 +00:00
|
|
|
// At this point if instanceof succeeded then r0 == 0.
|
2009-08-11 11:46:27 +00:00
|
|
|
__ tst(r0, Operand(r0));
|
2008-10-08 13:33:16 +00:00
|
|
|
cc_reg_ = eq;
|
2008-10-02 11:54:32 +00:00
|
|
|
break;
|
2009-02-27 13:00:32 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT((has_cc() && frame_->height() == original_height) ||
|
|
|
|
(!has_cc() && frame_->height() == original_height + 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-24 07:26:49 +00:00
|
|
|
void CodeGenerator::VisitCompareToNull(CompareToNull* node) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
int original_height = frame_->height();
|
|
|
|
#endif
|
|
|
|
Comment cmnt(masm_, "[ CompareToNull");
|
|
|
|
|
|
|
|
Load(node->expression());
|
|
|
|
Register tos = frame_->PopToRegister();
|
|
|
|
__ LoadRoot(ip, Heap::kNullValueRootIndex);
|
|
|
|
__ cmp(tos, ip);
|
|
|
|
|
|
|
|
// The 'null' value is only equal to 'undefined' if using non-strict
|
|
|
|
// comparisons.
|
|
|
|
if (!node->is_strict()) {
|
|
|
|
true_target()->Branch(eq);
|
|
|
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ cmp(tos, Operand(ip));
|
|
|
|
true_target()->Branch(eq);
|
|
|
|
|
|
|
|
__ tst(tos, Operand(kSmiTagMask));
|
|
|
|
false_target()->Branch(eq);
|
|
|
|
|
|
|
|
// It can be an undetectable object.
|
|
|
|
__ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset));
|
|
|
|
__ ldrb(tos, FieldMemOperand(tos, Map::kBitFieldOffset));
|
|
|
|
__ and_(tos, tos, Operand(1 << Map::kIsUndetectable));
|
|
|
|
__ cmp(tos, Operand(1 << Map::kIsUndetectable));
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_reg_ = eq;
|
|
|
|
ASSERT(has_cc() && frame_->height() == original_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-22 07:18:30 +00:00
|
|
|
class DeferredReferenceGetNamedValue: public DeferredCode {
|
|
|
|
public:
|
2010-05-19 10:29:19 +00:00
|
|
|
explicit DeferredReferenceGetNamedValue(Register receiver,
|
2010-11-24 09:40:58 +00:00
|
|
|
Handle<String> name,
|
|
|
|
bool is_contextual)
|
|
|
|
: receiver_(receiver),
|
|
|
|
name_(name),
|
|
|
|
is_contextual_(is_contextual),
|
|
|
|
is_dont_delete_(false) {
|
|
|
|
set_comment(is_contextual
|
|
|
|
? "[ DeferredReferenceGetNamedValue (contextual)"
|
|
|
|
: "[ DeferredReferenceGetNamedValue");
|
2010-04-22 07:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
|
|
|
|
2010-11-24 09:40:58 +00:00
|
|
|
void set_is_dont_delete(bool value) {
|
|
|
|
ASSERT(is_contextual_);
|
|
|
|
is_dont_delete_ = value;
|
|
|
|
}
|
|
|
|
|
2010-04-22 07:18:30 +00:00
|
|
|
private:
|
2010-05-19 10:29:19 +00:00
|
|
|
Register receiver_;
|
2010-04-22 07:18:30 +00:00
|
|
|
Handle<String> name_;
|
2010-11-24 09:40:58 +00:00
|
|
|
bool is_contextual_;
|
|
|
|
bool is_dont_delete_;
|
2010-04-22 07:18:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
// Convention for this is that on entry the receiver is in a register that
|
|
|
|
// is not used by the stack. On exit the answer is found in that same
|
|
|
|
// register and the stack has the same height.
|
2010-04-22 07:18:30 +00:00
|
|
|
void DeferredReferenceGetNamedValue::Generate() {
|
2010-05-27 13:48:52 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int expected_height = frame_state()->frame()->height();
|
|
|
|
#endif
|
|
|
|
VirtualFrame copied_frame(*frame_state()->frame());
|
|
|
|
copied_frame.SpillAll();
|
2010-05-19 10:29:19 +00:00
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2010-05-27 13:48:52 +00:00
|
|
|
ASSERT(!receiver_.is(scratch1) && !receiver_.is(scratch2));
|
2011-03-23 11:13:07 +00:00
|
|
|
__ DecrementCounter(masm_->isolate()->counters()->named_load_inline(),
|
|
|
|
1, scratch1, scratch2);
|
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->named_load_inline_miss(),
|
|
|
|
1, scratch1, scratch2);
|
2010-04-27 09:09:51 +00:00
|
|
|
|
2010-05-19 10:29:19 +00:00
|
|
|
// Ensure receiver in r0 and name in r2 to match load ic calling convention.
|
|
|
|
__ Move(r0, receiver_);
|
2010-04-22 07:18:30 +00:00
|
|
|
__ mov(r2, Operand(name_));
|
2010-04-23 07:42:45 +00:00
|
|
|
|
2010-04-27 09:09:51 +00:00
|
|
|
// The rest of the instructions in the deferred code must be together.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kLoadIC_Initialize));
|
2010-11-24 09:40:58 +00:00
|
|
|
RelocInfo::Mode mode = is_contextual_
|
|
|
|
? RelocInfo::CODE_TARGET_CONTEXT
|
|
|
|
: RelocInfo::CODE_TARGET;
|
|
|
|
__ Call(ic, mode);
|
|
|
|
// We must mark the code just after the call with the correct marker.
|
|
|
|
MacroAssembler::NopMarkerTypes code_marker;
|
|
|
|
if (is_contextual_) {
|
|
|
|
code_marker = is_dont_delete_
|
|
|
|
? MacroAssembler::PROPERTY_ACCESS_INLINED_CONTEXT_DONT_DELETE
|
|
|
|
: MacroAssembler::PROPERTY_ACCESS_INLINED_CONTEXT;
|
|
|
|
} else {
|
|
|
|
code_marker = MacroAssembler::PROPERTY_ACCESS_INLINED;
|
|
|
|
}
|
|
|
|
__ MarkCode(code_marker);
|
2010-04-27 11:16:05 +00:00
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
// At this point the answer is in r0. We move it to the expected register
|
|
|
|
// if necessary.
|
|
|
|
__ Move(receiver_, r0);
|
|
|
|
|
|
|
|
// Now go back to the frame that we entered with. This will not overwrite
|
|
|
|
// the receiver register since that register was not in use when we came
|
|
|
|
// in. The instructions emitted by this merge are skipped over by the
|
|
|
|
// inline load patching mechanism when looking for the branch instruction
|
|
|
|
// that tells it where the code to patch is.
|
|
|
|
copied_frame.MergeTo(frame_state()->frame());
|
|
|
|
|
2010-04-27 11:16:05 +00:00
|
|
|
// Block the constant pool for one more instruction after leaving this
|
|
|
|
// constant pool block scope to include the branch instruction ending the
|
|
|
|
// deferred code.
|
|
|
|
__ BlockConstPoolFor(1);
|
|
|
|
}
|
2010-05-27 13:48:52 +00:00
|
|
|
ASSERT_EQ(expected_height, frame_state()->frame()->height());
|
2010-04-27 11:16:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DeferredReferenceGetKeyedValue: public DeferredCode {
|
|
|
|
public:
|
2010-05-10 13:23:42 +00:00
|
|
|
DeferredReferenceGetKeyedValue(Register key, Register receiver)
|
|
|
|
: key_(key), receiver_(receiver) {
|
2010-04-27 11:16:05 +00:00
|
|
|
set_comment("[ DeferredReferenceGetKeyedValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
2010-05-10 13:23:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register key_;
|
|
|
|
Register receiver_;
|
2010-04-27 11:16:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-24 11:05:38 +00:00
|
|
|
// Takes key and register in r0 and r1 or vice versa. Returns result
|
|
|
|
// in r0.
|
2010-04-27 11:16:05 +00:00
|
|
|
void DeferredReferenceGetKeyedValue::Generate() {
|
2010-05-10 13:23:42 +00:00
|
|
|
ASSERT((key_.is(r0) && receiver_.is(r1)) ||
|
|
|
|
(key_.is(r1) && receiver_.is(r0)));
|
|
|
|
|
2010-06-24 11:05:38 +00:00
|
|
|
VirtualFrame copied_frame(*frame_state()->frame());
|
|
|
|
copied_frame.SpillAll();
|
|
|
|
|
2010-04-28 09:12:04 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2011-03-23 11:13:07 +00:00
|
|
|
__ DecrementCounter(masm_->isolate()->counters()->keyed_load_inline(),
|
|
|
|
1, scratch1, scratch2);
|
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->keyed_load_inline_miss(),
|
|
|
|
1, scratch1, scratch2);
|
2010-04-27 11:16:05 +00:00
|
|
|
|
2010-05-10 13:23:42 +00:00
|
|
|
// Ensure key in r0 and receiver in r1 to match keyed load ic calling
|
|
|
|
// convention.
|
|
|
|
if (key_.is(r1)) {
|
|
|
|
__ Swap(r0, r1, ip);
|
|
|
|
}
|
|
|
|
|
2010-04-27 11:16:05 +00:00
|
|
|
// The rest of the instructions in the deferred code must be together.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
2010-05-07 10:16:11 +00:00
|
|
|
// Call keyed load IC. It has the arguments key and receiver in r0 and r1.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
Builtins::kKeyedLoadIC_Initialize));
|
2010-04-27 11:16:05 +00:00
|
|
|
__ Call(ic, RelocInfo::CODE_TARGET);
|
|
|
|
// The call must be followed by a nop instruction to indicate that the
|
|
|
|
// keyed load has been inlined.
|
2010-11-24 09:40:58 +00:00
|
|
|
__ MarkCode(MacroAssembler::PROPERTY_ACCESS_INLINED);
|
2010-04-28 11:14:31 +00:00
|
|
|
|
2010-06-24 11:05:38 +00:00
|
|
|
// Now go back to the frame that we entered with. This will not overwrite
|
|
|
|
// the receiver or key registers since they were not in use when we came
|
|
|
|
// in. The instructions emitted by this merge are skipped over by the
|
|
|
|
// inline load patching mechanism when looking for the branch instruction
|
|
|
|
// that tells it where the code to patch is.
|
|
|
|
copied_frame.MergeTo(frame_state()->frame());
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// Block the constant pool for one more instruction after leaving this
|
|
|
|
// constant pool block scope to include the branch instruction ending the
|
|
|
|
// deferred code.
|
|
|
|
__ BlockConstPoolFor(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class DeferredReferenceSetKeyedValue: public DeferredCode {
|
|
|
|
public:
|
2010-05-18 06:57:12 +00:00
|
|
|
DeferredReferenceSetKeyedValue(Register value,
|
|
|
|
Register key,
|
2011-03-02 04:53:43 +00:00
|
|
|
Register receiver,
|
|
|
|
StrictModeFlag strict_mode)
|
|
|
|
: value_(value),
|
|
|
|
key_(key),
|
|
|
|
receiver_(receiver),
|
|
|
|
strict_mode_(strict_mode) {
|
2010-04-28 11:14:31 +00:00
|
|
|
set_comment("[ DeferredReferenceSetKeyedValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
2010-05-18 06:57:12 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Register value_;
|
|
|
|
Register key_;
|
|
|
|
Register receiver_;
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode_;
|
2010-04-28 11:14:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void DeferredReferenceSetKeyedValue::Generate() {
|
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2011-03-23 11:13:07 +00:00
|
|
|
__ DecrementCounter(masm_->isolate()->counters()->keyed_store_inline(),
|
|
|
|
1, scratch1, scratch2);
|
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->keyed_store_inline_miss(),
|
2011-03-18 20:35:07 +00:00
|
|
|
1, scratch1, scratch2);
|
2010-04-28 11:14:31 +00:00
|
|
|
|
2010-05-18 06:57:12 +00:00
|
|
|
// Ensure value in r0, key in r1 and receiver in r2 to match keyed store ic
|
|
|
|
// calling convention.
|
|
|
|
if (value_.is(r1)) {
|
|
|
|
__ Swap(r0, r1, ip);
|
|
|
|
}
|
|
|
|
ASSERT(receiver_.is(r2));
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// The rest of the instructions in the deferred code must be together.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
2010-05-18 06:57:12 +00:00
|
|
|
// Call keyed store IC. It has the arguments value, key and receiver in r0,
|
|
|
|
// r1 and r2.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
(strict_mode_ == kStrictMode)
|
|
|
|
? Builtins::kKeyedStoreIC_Initialize_Strict
|
|
|
|
: Builtins::kKeyedStoreIC_Initialize));
|
2010-04-28 11:14:31 +00:00
|
|
|
__ Call(ic, RelocInfo::CODE_TARGET);
|
|
|
|
// The call must be followed by a nop instruction to indicate that the
|
|
|
|
// keyed store has been inlined.
|
2010-11-24 09:40:58 +00:00
|
|
|
__ MarkCode(MacroAssembler::PROPERTY_ACCESS_INLINED);
|
2010-04-23 07:42:45 +00:00
|
|
|
|
2010-04-27 09:09:51 +00:00
|
|
|
// Block the constant pool for one more instruction after leaving this
|
|
|
|
// constant pool block scope to include the branch instruction ending the
|
|
|
|
// deferred code.
|
|
|
|
__ BlockConstPoolFor(1);
|
|
|
|
}
|
2010-04-22 07:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-22 08:17:40 +00:00
|
|
|
class DeferredReferenceSetNamedValue: public DeferredCode {
|
|
|
|
public:
|
|
|
|
DeferredReferenceSetNamedValue(Register value,
|
|
|
|
Register receiver,
|
2011-03-02 04:53:43 +00:00
|
|
|
Handle<String> name,
|
|
|
|
StrictModeFlag strict_mode)
|
|
|
|
: value_(value),
|
|
|
|
receiver_(receiver),
|
|
|
|
name_(name),
|
|
|
|
strict_mode_(strict_mode) {
|
2010-07-22 08:17:40 +00:00
|
|
|
set_comment("[ DeferredReferenceSetNamedValue");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Generate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Register value_;
|
|
|
|
Register receiver_;
|
|
|
|
Handle<String> name_;
|
2011-03-02 04:53:43 +00:00
|
|
|
StrictModeFlag strict_mode_;
|
2010-07-22 08:17:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-23 08:47:15 +00:00
|
|
|
// Takes value in r0, receiver in r1 and returns the result (the
|
|
|
|
// value) in r0.
|
2010-07-22 08:17:40 +00:00
|
|
|
void DeferredReferenceSetNamedValue::Generate() {
|
2010-07-23 08:47:15 +00:00
|
|
|
// Record the entry frame and spill.
|
|
|
|
VirtualFrame copied_frame(*frame_state()->frame());
|
|
|
|
copied_frame.SpillAll();
|
|
|
|
|
2010-07-22 08:17:40 +00:00
|
|
|
// Ensure value in r0, receiver in r1 to match store ic calling
|
|
|
|
// convention.
|
|
|
|
ASSERT(value_.is(r0) && receiver_.is(r1));
|
|
|
|
__ mov(r2, Operand(name_));
|
|
|
|
|
|
|
|
// The rest of the instructions in the deferred code must be together.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
|
|
|
// Call keyed store IC. It has the arguments value, key and receiver in r0,
|
|
|
|
// r1 and r2.
|
2011-03-18 20:35:07 +00:00
|
|
|
Handle<Code> ic(Isolate::Current()->builtins()->builtin(
|
2011-03-23 13:40:07 +00:00
|
|
|
(strict_mode_ == kStrictMode) ? Builtins::kStoreIC_Initialize_Strict
|
|
|
|
: Builtins::kStoreIC_Initialize));
|
2010-07-22 08:17:40 +00:00
|
|
|
__ Call(ic, RelocInfo::CODE_TARGET);
|
|
|
|
// The call must be followed by a nop instruction to indicate that the
|
|
|
|
// named store has been inlined.
|
2010-11-24 09:40:58 +00:00
|
|
|
__ MarkCode(MacroAssembler::PROPERTY_ACCESS_INLINED);
|
2010-07-22 08:17:40 +00:00
|
|
|
|
2010-07-23 08:47:15 +00:00
|
|
|
// Go back to the frame we entered with. The instructions
|
|
|
|
// generated by this merge are skipped over by the inline store
|
|
|
|
// patching mechanism when looking for the branch instruction that
|
|
|
|
// tells it where the code to patch is.
|
|
|
|
copied_frame.MergeTo(frame_state()->frame());
|
|
|
|
|
2010-07-22 08:17:40 +00:00
|
|
|
// Block the constant pool for one more instruction after leaving this
|
|
|
|
// constant pool block scope to include the branch instruction ending the
|
|
|
|
// deferred code.
|
|
|
|
__ BlockConstPoolFor(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
// Consumes the top of stack (the receiver) and pushes the result instead.
|
2010-04-22 07:18:30 +00:00
|
|
|
void CodeGenerator::EmitNamedLoad(Handle<String> name, bool is_contextual) {
|
2010-11-24 09:40:58 +00:00
|
|
|
bool contextual_load_in_builtin =
|
|
|
|
is_contextual &&
|
2011-03-18 20:35:07 +00:00
|
|
|
(ISOLATE->bootstrapper()->IsActive() ||
|
2010-11-24 09:40:58 +00:00
|
|
|
(!info_->closure().is_null() && info_->closure()->IsBuiltin()));
|
|
|
|
|
|
|
|
if (scope()->is_global_scope() ||
|
|
|
|
loop_nesting() == 0 ||
|
|
|
|
contextual_load_in_builtin) {
|
2010-04-22 07:18:30 +00:00
|
|
|
Comment cmnt(masm(), "[ Load from named Property");
|
|
|
|
// Setup the name register and call load IC.
|
2010-05-05 06:50:15 +00:00
|
|
|
frame_->CallLoadIC(name,
|
|
|
|
is_contextual
|
|
|
|
? RelocInfo::CODE_TARGET_CONTEXT
|
|
|
|
: RelocInfo::CODE_TARGET);
|
2010-05-27 13:48:52 +00:00
|
|
|
frame_->EmitPush(r0); // Push answer.
|
2010-04-22 07:18:30 +00:00
|
|
|
} else {
|
2010-04-27 11:16:05 +00:00
|
|
|
// Inline the in-object property case.
|
2010-11-24 09:40:58 +00:00
|
|
|
Comment cmnt(masm(), is_contextual
|
|
|
|
? "[ Inlined contextual property load"
|
|
|
|
: "[ Inlined named property load");
|
2010-04-22 07:18:30 +00:00
|
|
|
|
2010-04-27 09:09:51 +00:00
|
|
|
// Counter will be decremented in the deferred code. Placed here to avoid
|
|
|
|
// having it in the instruction stream below where patching will occur.
|
2010-11-24 09:40:58 +00:00
|
|
|
if (is_contextual) {
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(
|
|
|
|
masm_->isolate()->counters()->named_load_global_inline(),
|
|
|
|
1, frame_->scratch0(), frame_->scratch1());
|
2010-11-24 09:40:58 +00:00
|
|
|
} else {
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->named_load_inline(),
|
|
|
|
1, frame_->scratch0(), frame_->scratch1());
|
2010-11-24 09:40:58 +00:00
|
|
|
}
|
2010-04-27 09:09:51 +00:00
|
|
|
|
2010-04-22 07:18:30 +00:00
|
|
|
// The following instructions are the inlined load of an in-object property.
|
|
|
|
// Parts of this code is patched, so the exact instructions generated needs
|
|
|
|
// to be fixed. Therefore the instruction pool is blocked when generating
|
|
|
|
// this code
|
2010-04-27 19:24:36 +00:00
|
|
|
|
|
|
|
// Load the receiver from the stack.
|
2010-05-19 10:29:19 +00:00
|
|
|
Register receiver = frame_->PopToRegister();
|
2010-04-27 19:24:36 +00:00
|
|
|
|
|
|
|
DeferredReferenceGetNamedValue* deferred =
|
2010-11-24 09:40:58 +00:00
|
|
|
new DeferredReferenceGetNamedValue(receiver, name, is_contextual);
|
|
|
|
|
|
|
|
bool is_dont_delete = false;
|
|
|
|
if (is_contextual) {
|
|
|
|
if (!info_->closure().is_null()) {
|
|
|
|
// When doing lazy compilation we can check if the global cell
|
|
|
|
// already exists and use its "don't delete" status as a hint.
|
|
|
|
AssertNoAllocation no_gc;
|
|
|
|
v8::internal::GlobalObject* global_object =
|
|
|
|
info_->closure()->context()->global();
|
|
|
|
LookupResult lookup;
|
|
|
|
global_object->LocalLookupRealNamedProperty(*name, &lookup);
|
|
|
|
if (lookup.IsProperty() && lookup.type() == NORMAL) {
|
|
|
|
ASSERT(lookup.holder() == global_object);
|
|
|
|
ASSERT(global_object->property_dictionary()->ValueAt(
|
|
|
|
lookup.GetDictionaryEntry())->IsJSGlobalPropertyCell());
|
|
|
|
is_dont_delete = lookup.IsDontDelete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_dont_delete) {
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(
|
|
|
|
masm_->isolate()->counters()->dont_delete_hint_hit(),
|
|
|
|
1, frame_->scratch0(), frame_->scratch1());
|
2010-11-24 09:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
|
|
|
if (!is_contextual) {
|
|
|
|
// Check that the receiver is a heap object.
|
|
|
|
__ tst(receiver, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(eq);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the_hole_value if necessary.
|
|
|
|
// Below we rely on the number of instructions generated, and we can't
|
|
|
|
// cope with the Check macro which does not generate a fixed number of
|
|
|
|
// instructions.
|
|
|
|
Label skip, check_the_hole, cont;
|
|
|
|
if (FLAG_debug_code && is_contextual && is_dont_delete) {
|
|
|
|
__ b(&skip);
|
|
|
|
__ bind(&check_the_hole);
|
|
|
|
__ Check(ne, "DontDelete cells can't contain the hole");
|
|
|
|
__ b(&cont);
|
|
|
|
__ bind(&skip);
|
|
|
|
}
|
2010-04-27 19:24:36 +00:00
|
|
|
|
2010-04-22 07:18:30 +00:00
|
|
|
#ifdef DEBUG
|
2010-11-24 09:40:58 +00:00
|
|
|
int InlinedNamedLoadInstructions = 5;
|
|
|
|
Label check_inlined_codesize;
|
|
|
|
masm_->bind(&check_inlined_codesize);
|
2010-04-22 07:18:30 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
Register scratch = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
|
|
|
|
2010-04-22 07:18:30 +00:00
|
|
|
// Check the map. The null map used below is patched by the inline cache
|
2010-05-27 13:48:52 +00:00
|
|
|
// code. Therefore we can't use a LoadRoot call.
|
|
|
|
__ ldr(scratch, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(scratch2, Operand(FACTORY->null_value()));
|
2010-05-27 13:48:52 +00:00
|
|
|
__ cmp(scratch, scratch2);
|
2010-04-22 07:18:30 +00:00
|
|
|
deferred->Branch(ne);
|
|
|
|
|
2010-11-24 09:40:58 +00:00
|
|
|
if (is_contextual) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
InlinedNamedLoadInstructions += 1;
|
|
|
|
#endif
|
|
|
|
// Load the (initially invalid) cell and get its value.
|
2011-03-18 20:35:07 +00:00
|
|
|
masm()->mov(receiver, Operand(FACTORY->null_value()));
|
2010-11-24 09:40:58 +00:00
|
|
|
__ ldr(receiver,
|
|
|
|
FieldMemOperand(receiver, JSGlobalPropertyCell::kValueOffset));
|
|
|
|
|
|
|
|
deferred->set_is_dont_delete(is_dont_delete);
|
|
|
|
|
|
|
|
if (!is_dont_delete) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
InlinedNamedLoadInstructions += 3;
|
|
|
|
#endif
|
2011-03-18 20:35:07 +00:00
|
|
|
__ cmp(receiver, Operand(FACTORY->the_hole_value()));
|
2010-11-24 09:40:58 +00:00
|
|
|
deferred->Branch(eq);
|
|
|
|
} else if (FLAG_debug_code) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
InlinedNamedLoadInstructions += 3;
|
|
|
|
#endif
|
2011-03-18 20:35:07 +00:00
|
|
|
__ cmp(receiver, Operand(FACTORY->the_hole_value()));
|
2010-11-24 09:40:58 +00:00
|
|
|
__ b(&check_the_hole, eq);
|
|
|
|
__ bind(&cont);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Initially use an invalid index. The index will be patched by the
|
|
|
|
// inline cache code.
|
|
|
|
__ ldr(receiver, MemOperand(receiver, 0));
|
|
|
|
}
|
2010-04-22 07:18:30 +00:00
|
|
|
|
2010-04-27 09:09:51 +00:00
|
|
|
// Make sure that the expected number of instructions are generated.
|
2010-11-24 09:40:58 +00:00
|
|
|
// If the code before is updated, the offsets in ic-arm.cc
|
|
|
|
// LoadIC::PatchInlinedContextualLoad and PatchInlinedLoad need
|
|
|
|
// to be updated.
|
|
|
|
ASSERT_EQ(InlinedNamedLoadInstructions,
|
2010-04-27 09:09:51 +00:00
|
|
|
masm_->InstructionsGeneratedSince(&check_inlined_codesize));
|
|
|
|
}
|
2010-04-22 07:18:30 +00:00
|
|
|
|
|
|
|
deferred->BindExit();
|
2010-05-27 13:48:52 +00:00
|
|
|
// At this point the receiver register has the result, either from the
|
|
|
|
// deferred code or from the inlined code.
|
|
|
|
frame_->EmitPush(receiver);
|
2010-04-22 07:18:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 09:33:12 +00:00
|
|
|
void CodeGenerator::EmitNamedStore(Handle<String> name, bool is_contextual) {
|
|
|
|
#ifdef DEBUG
|
2010-07-22 08:17:40 +00:00
|
|
|
int expected_height = frame()->height() - (is_contextual ? 1 : 2);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Result result;
|
|
|
|
if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) {
|
2011-02-13 16:19:53 +00:00
|
|
|
frame()->CallStoreIC(name, is_contextual, strict_mode_flag());
|
2010-07-22 08:17:40 +00:00
|
|
|
} else {
|
|
|
|
// Inline the in-object property case.
|
|
|
|
JumpTarget slow, done;
|
|
|
|
|
|
|
|
// Get the value and receiver from the stack.
|
|
|
|
frame()->PopToR0();
|
|
|
|
Register value = r0;
|
|
|
|
frame()->PopToR1();
|
|
|
|
Register receiver = r1;
|
|
|
|
|
|
|
|
DeferredReferenceSetNamedValue* deferred =
|
2011-03-02 04:53:43 +00:00
|
|
|
new DeferredReferenceSetNamedValue(
|
|
|
|
value, receiver, name, strict_mode_flag());
|
2010-07-22 08:17:40 +00:00
|
|
|
|
|
|
|
// Check that the receiver is a heap object.
|
|
|
|
__ tst(receiver, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(eq);
|
|
|
|
|
|
|
|
// The following instructions are the part of the inlined
|
|
|
|
// in-object property store code which can be patched. Therefore
|
|
|
|
// the exact number of instructions generated must be fixed, so
|
|
|
|
// the constant pool is blocked while generating this code.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
|
|
|
Register scratch0 = VirtualFrame::scratch0();
|
|
|
|
Register scratch1 = VirtualFrame::scratch1();
|
|
|
|
|
|
|
|
// Check the map. Initially use an invalid map to force a
|
|
|
|
// failure. The map check will be patched in the runtime system.
|
|
|
|
__ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
Label check_inlined_codesize;
|
|
|
|
masm_->bind(&check_inlined_codesize);
|
2010-05-04 09:33:12 +00:00
|
|
|
#endif
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(scratch0, Operand(FACTORY->null_value()));
|
2010-07-22 08:17:40 +00:00
|
|
|
__ cmp(scratch0, scratch1);
|
|
|
|
deferred->Branch(ne);
|
2010-05-04 09:33:12 +00:00
|
|
|
|
2010-07-22 08:17:40 +00:00
|
|
|
int offset = 0;
|
|
|
|
__ str(value, MemOperand(receiver, offset));
|
|
|
|
|
2010-07-23 08:47:15 +00:00
|
|
|
// Update the write barrier and record its size. We do not use
|
|
|
|
// the RecordWrite macro here because we want the offset
|
|
|
|
// addition instruction first to make it easy to patch.
|
|
|
|
Label record_write_start, record_write_done;
|
|
|
|
__ bind(&record_write_start);
|
|
|
|
// Add offset into the object.
|
|
|
|
__ add(scratch0, receiver, Operand(offset));
|
|
|
|
// Test that the object is not in the new space. We cannot set
|
|
|
|
// region marks for new space pages.
|
|
|
|
__ InNewSpace(receiver, scratch1, eq, &record_write_done);
|
|
|
|
// Record the actual write.
|
|
|
|
__ RecordWriteHelper(receiver, scratch0, scratch1);
|
|
|
|
__ bind(&record_write_done);
|
|
|
|
// Clobber all input registers when running with the debug-code flag
|
|
|
|
// turned on to provoke errors.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ mov(receiver, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
__ mov(scratch0, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
__ mov(scratch1, Operand(BitCast<int32_t>(kZapValue)));
|
|
|
|
}
|
|
|
|
// Check that this is the first inlined write barrier or that
|
|
|
|
// this inlined write barrier has the same size as all the other
|
|
|
|
// inlined write barriers.
|
2011-03-18 20:35:07 +00:00
|
|
|
ASSERT((Isolate::Current()->inlined_write_barrier_size() == -1) ||
|
|
|
|
(Isolate::Current()->inlined_write_barrier_size() ==
|
2010-07-23 08:47:15 +00:00
|
|
|
masm()->InstructionsGeneratedSince(&record_write_start)));
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate::Current()->set_inlined_write_barrier_size(
|
|
|
|
masm()->InstructionsGeneratedSince(&record_write_start));
|
2010-07-23 08:47:15 +00:00
|
|
|
|
2010-07-22 08:17:40 +00:00
|
|
|
// Make sure that the expected number of instructions are generated.
|
|
|
|
ASSERT_EQ(GetInlinedNamedStoreInstructionsAfterPatch(),
|
2010-07-23 08:47:15 +00:00
|
|
|
masm()->InstructionsGeneratedSince(&check_inlined_codesize));
|
2010-07-22 08:17:40 +00:00
|
|
|
}
|
|
|
|
deferred->BindExit();
|
|
|
|
}
|
|
|
|
ASSERT_EQ(expected_height, frame()->height());
|
2010-05-04 09:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-27 11:16:05 +00:00
|
|
|
void CodeGenerator::EmitKeyedLoad() {
|
|
|
|
if (loop_nesting() == 0) {
|
|
|
|
Comment cmnt(masm_, "[ Load from keyed property");
|
|
|
|
frame_->CallKeyedLoadIC();
|
|
|
|
} else {
|
|
|
|
// Inline the keyed load.
|
|
|
|
Comment cmnt(masm_, "[ Inlined load from keyed property");
|
|
|
|
|
|
|
|
// Counter will be decremented in the deferred code. Placed here to avoid
|
|
|
|
// having it in the instruction stream below where patching will occur.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->keyed_load_inline(),
|
|
|
|
1, frame_->scratch0(), frame_->scratch1());
|
2010-04-27 11:16:05 +00:00
|
|
|
|
2010-05-10 13:23:42 +00:00
|
|
|
// Load the key and receiver from the stack.
|
2010-06-02 09:37:02 +00:00
|
|
|
bool key_is_known_smi = frame_->KnownSmiAt(0);
|
2010-05-10 13:23:42 +00:00
|
|
|
Register key = frame_->PopToRegister();
|
|
|
|
Register receiver = frame_->PopToRegister(key);
|
2010-04-27 19:24:36 +00:00
|
|
|
|
2010-05-10 13:23:42 +00:00
|
|
|
// The deferred code expects key and receiver in registers.
|
2010-04-27 19:24:36 +00:00
|
|
|
DeferredReferenceGetKeyedValue* deferred =
|
2010-05-10 13:23:42 +00:00
|
|
|
new DeferredReferenceGetKeyedValue(key, receiver);
|
2010-04-27 11:16:05 +00:00
|
|
|
|
|
|
|
// Check that the receiver is a heap object.
|
2010-04-28 09:12:04 +00:00
|
|
|
__ tst(receiver, Operand(kSmiTagMask));
|
2010-04-27 11:16:05 +00:00
|
|
|
deferred->Branch(eq);
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// The following instructions are the part of the inlined load keyed
|
|
|
|
// property code which can be patched. Therefore the exact number of
|
|
|
|
// instructions generated need to be fixed, so the constant pool is blocked
|
|
|
|
// while generating this code.
|
2010-04-27 11:16:05 +00:00
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
2010-04-28 09:12:04 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
2010-04-27 11:16:05 +00:00
|
|
|
// Check the map. The null map used below is patched by the inline cache
|
|
|
|
// code.
|
2010-04-28 09:12:04 +00:00
|
|
|
__ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
2010-06-02 09:37:02 +00:00
|
|
|
|
|
|
|
// Check that the key is a smi.
|
|
|
|
if (!key_is_known_smi) {
|
|
|
|
__ tst(key, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(ne);
|
|
|
|
}
|
|
|
|
|
2010-05-10 10:45:18 +00:00
|
|
|
#ifdef DEBUG
|
2010-06-02 09:37:02 +00:00
|
|
|
Label check_inlined_codesize;
|
|
|
|
masm_->bind(&check_inlined_codesize);
|
2010-05-10 10:45:18 +00:00
|
|
|
#endif
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(scratch2, Operand(FACTORY->null_value()));
|
2010-04-28 09:12:04 +00:00
|
|
|
__ cmp(scratch1, scratch2);
|
2010-04-27 11:16:05 +00:00
|
|
|
deferred->Branch(ne);
|
|
|
|
|
2010-08-16 16:06:46 +00:00
|
|
|
// Get the elements array from the receiver.
|
2010-04-28 09:12:04 +00:00
|
|
|
__ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
2010-08-16 16:06:46 +00:00
|
|
|
__ AssertFastElements(scratch1);
|
2010-04-27 11:16:05 +00:00
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// Check that key is within bounds. Use unsigned comparison to handle
|
|
|
|
// negative keys.
|
2010-04-28 09:12:04 +00:00
|
|
|
__ ldr(scratch2, FieldMemOperand(scratch1, FixedArray::kLengthOffset));
|
2010-05-27 12:30:45 +00:00
|
|
|
__ cmp(scratch2, key);
|
2010-04-27 11:16:05 +00:00
|
|
|
deferred->Branch(ls); // Unsigned less equal.
|
|
|
|
|
2010-04-28 09:12:04 +00:00
|
|
|
// Load and check that the result is not the hole (key is a smi).
|
|
|
|
__ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ add(scratch1,
|
|
|
|
scratch1,
|
|
|
|
Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
2010-05-10 10:45:18 +00:00
|
|
|
__ ldr(scratch1,
|
2010-04-28 09:12:04 +00:00
|
|
|
MemOperand(scratch1, key, LSL,
|
|
|
|
kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize)));
|
2010-05-10 10:45:18 +00:00
|
|
|
__ cmp(scratch1, scratch2);
|
2010-04-27 11:16:05 +00:00
|
|
|
deferred->Branch(eq);
|
|
|
|
|
2010-05-10 10:45:18 +00:00
|
|
|
__ mov(r0, scratch1);
|
2010-04-27 11:16:05 +00:00
|
|
|
// Make sure that the expected number of instructions are generated.
|
2010-06-24 13:56:35 +00:00
|
|
|
ASSERT_EQ(GetInlinedKeyedLoadInstructionsAfterPatch(),
|
2010-04-27 11:16:05 +00:00
|
|
|
masm_->InstructionsGeneratedSince(&check_inlined_codesize));
|
|
|
|
}
|
|
|
|
|
|
|
|
deferred->BindExit();
|
|
|
|
}
|
2010-01-27 14:07:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
void CodeGenerator::EmitKeyedStore(StaticType* key_type,
|
|
|
|
WriteBarrierCharacter wb_info) {
|
2010-04-28 11:14:31 +00:00
|
|
|
// Generate inlined version of the keyed store if the code is in a loop
|
|
|
|
// and the key is likely to be a smi.
|
|
|
|
if (loop_nesting() > 0 && key_type->IsLikelySmi()) {
|
|
|
|
// Inline the keyed store.
|
|
|
|
Comment cmnt(masm_, "[ Inlined store to keyed property");
|
|
|
|
|
2010-05-18 06:57:12 +00:00
|
|
|
Register scratch1 = VirtualFrame::scratch0();
|
|
|
|
Register scratch2 = VirtualFrame::scratch1();
|
|
|
|
Register scratch3 = r3;
|
2010-04-28 11:14:31 +00:00
|
|
|
|
|
|
|
// Counter will be decremented in the deferred code. Placed here to avoid
|
|
|
|
// having it in the instruction stream below where patching will occur.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(masm_->isolate()->counters()->keyed_store_inline(),
|
|
|
|
1, scratch1, scratch2);
|
2010-05-18 06:57:12 +00:00
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
|
2010-05-18 06:57:12 +00:00
|
|
|
// Load the value, key and receiver from the stack.
|
2010-07-01 15:06:24 +00:00
|
|
|
bool value_is_harmless = frame_->KnownSmiAt(0);
|
|
|
|
if (wb_info == NEVER_NEWSPACE) value_is_harmless = true;
|
|
|
|
bool key_is_smi = frame_->KnownSmiAt(1);
|
2010-05-18 06:57:12 +00:00
|
|
|
Register value = frame_->PopToRegister();
|
|
|
|
Register key = frame_->PopToRegister(value);
|
2010-06-24 07:54:48 +00:00
|
|
|
VirtualFrame::SpilledScope spilled(frame_);
|
2010-05-18 06:57:12 +00:00
|
|
|
Register receiver = r2;
|
|
|
|
frame_->EmitPop(receiver);
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool we_remembered_the_write_barrier = value_is_harmless;
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 06:57:12 +00:00
|
|
|
// The deferred code expects value, key and receiver in registers.
|
|
|
|
DeferredReferenceSetKeyedValue* deferred =
|
2011-03-02 04:53:43 +00:00
|
|
|
new DeferredReferenceSetKeyedValue(
|
|
|
|
value, key, receiver, strict_mode_flag());
|
2010-04-28 11:14:31 +00:00
|
|
|
|
|
|
|
// Check that the value is a smi. As this inlined code does not set the
|
|
|
|
// write barrier it is only possible to store smi values.
|
2010-07-01 15:06:24 +00:00
|
|
|
if (!value_is_harmless) {
|
|
|
|
// If the value is not likely to be a Smi then let's test the fixed array
|
|
|
|
// for new space instead. See below.
|
|
|
|
if (wb_info == LIKELY_SMI) {
|
|
|
|
__ tst(value, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(ne);
|
|
|
|
#ifdef DEBUG
|
|
|
|
we_remembered_the_write_barrier = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-04-28 11:14:31 +00:00
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
if (!key_is_smi) {
|
|
|
|
// Check that the key is a smi.
|
|
|
|
__ tst(key, Operand(kSmiTagMask));
|
|
|
|
deferred->Branch(ne);
|
|
|
|
}
|
2010-04-28 11:14:31 +00:00
|
|
|
|
|
|
|
// Check that the receiver is a heap object.
|
2010-05-18 06:57:12 +00:00
|
|
|
__ tst(receiver, Operand(kSmiTagMask));
|
2010-04-28 11:14:31 +00:00
|
|
|
deferred->Branch(eq);
|
|
|
|
|
|
|
|
// Check that the receiver is a JSArray.
|
2010-05-18 06:57:12 +00:00
|
|
|
__ CompareObjectType(receiver, scratch1, scratch1, JS_ARRAY_TYPE);
|
2010-04-28 11:14:31 +00:00
|
|
|
deferred->Branch(ne);
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
// Get the elements array from the receiver.
|
|
|
|
__ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
|
|
|
if (!value_is_harmless && wb_info != LIKELY_SMI) {
|
|
|
|
Label ok;
|
2011-03-22 13:20:04 +00:00
|
|
|
__ and_(scratch2,
|
|
|
|
scratch1,
|
|
|
|
Operand(ExternalReference::new_space_mask(isolate())));
|
|
|
|
__ cmp(scratch2, Operand(ExternalReference::new_space_start(isolate())));
|
2010-07-01 15:06:24 +00:00
|
|
|
__ tst(value, Operand(kSmiTagMask), ne);
|
|
|
|
deferred->Branch(ne);
|
|
|
|
#ifdef DEBUG
|
|
|
|
we_remembered_the_write_barrier = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
// Check that the elements array is not a dictionary.
|
|
|
|
__ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset));
|
2011-03-15 10:03:57 +00:00
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// The following instructions are the part of the inlined store keyed
|
|
|
|
// property code which can be patched. Therefore the exact number of
|
|
|
|
// instructions generated need to be fixed, so the constant pool is blocked
|
|
|
|
// while generating this code.
|
|
|
|
{ Assembler::BlockConstPoolScope block_const_pool(masm_);
|
2010-07-01 15:06:24 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
Label check_inlined_codesize;
|
|
|
|
masm_->bind(&check_inlined_codesize);
|
|
|
|
#endif
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// Read the fixed array map from the constant pool (not from the root
|
|
|
|
// array) so that the value can be patched. When debugging, we patch this
|
|
|
|
// comparison to always fail so that we will hit the IC call in the
|
|
|
|
// deferred code which will allow the debugger to break for fast case
|
|
|
|
// stores.
|
2011-03-18 20:35:07 +00:00
|
|
|
__ mov(scratch3, Operand(FACTORY->fixed_array_map()));
|
2010-05-18 06:57:12 +00:00
|
|
|
__ cmp(scratch2, scratch3);
|
2010-04-28 11:14:31 +00:00
|
|
|
deferred->Branch(ne);
|
|
|
|
|
2011-03-15 10:03:57 +00:00
|
|
|
// Check that the key is within bounds. Both the key and the length of
|
|
|
|
// the JSArray are smis (because the fixed array check above ensures the
|
|
|
|
// elements are in fast case). Use unsigned comparison to handle negative
|
|
|
|
// keys.
|
|
|
|
__ ldr(scratch3, FieldMemOperand(receiver, JSArray::kLengthOffset));
|
|
|
|
__ cmp(scratch3, key);
|
|
|
|
deferred->Branch(ls); // Unsigned less equal.
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
// Store the value.
|
2010-05-18 06:57:12 +00:00
|
|
|
__ add(scratch1, scratch1,
|
|
|
|
Operand(FixedArray::kHeaderSize - kHeapObjectTag));
|
|
|
|
__ str(value,
|
|
|
|
MemOperand(scratch1, key, LSL,
|
|
|
|
kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize)));
|
2010-04-28 11:14:31 +00:00
|
|
|
|
|
|
|
// Make sure that the expected number of instructions are generated.
|
2010-05-18 06:57:12 +00:00
|
|
|
ASSERT_EQ(kInlinedKeyedStoreInstructionsAfterPatch,
|
2010-04-28 11:14:31 +00:00
|
|
|
masm_->InstructionsGeneratedSince(&check_inlined_codesize));
|
|
|
|
}
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
ASSERT(we_remembered_the_write_barrier);
|
|
|
|
|
2010-04-28 11:14:31 +00:00
|
|
|
deferred->BindExit();
|
|
|
|
} else {
|
2011-03-02 04:53:43 +00:00
|
|
|
frame()->CallKeyedStoreIC(strict_mode_flag());
|
2010-04-28 11:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-27 13:00:32 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool CodeGenerator::HasValidEntryRegisters() { return true; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-10-02 11:54:32 +00:00
|
|
|
#undef __
|
2009-04-21 13:42:12 +00:00
|
|
|
#define __ ACCESS_MASM(masm)
|
2009-04-16 09:30:23 +00:00
|
|
|
|
2008-10-08 07:24:06 +00:00
|
|
|
Handle<String> Reference::GetName() {
|
|
|
|
ASSERT(type_ == NAMED);
|
|
|
|
Property* property = expression_->AsProperty();
|
|
|
|
if (property == NULL) {
|
|
|
|
// Global variable reference treated as a named property reference.
|
|
|
|
VariableProxy* proxy = expression_->AsVariableProxy();
|
|
|
|
ASSERT(proxy->AsVariable() != NULL);
|
|
|
|
ASSERT(proxy->AsVariable()->is_global());
|
|
|
|
return proxy->name();
|
|
|
|
} else {
|
|
|
|
Literal* raw_name = property->key()->AsLiteral();
|
|
|
|
ASSERT(raw_name != NULL);
|
|
|
|
return Handle<String>(String::cast(*raw_name->handle()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-27 13:48:52 +00:00
|
|
|
void Reference::DupIfPersist() {
|
|
|
|
if (persist_after_get_) {
|
|
|
|
switch (type_) {
|
|
|
|
case KEYED:
|
|
|
|
cgen_->frame()->Dup2();
|
|
|
|
break;
|
|
|
|
case NAMED:
|
|
|
|
cgen_->frame()->Dup();
|
|
|
|
// Fall through.
|
|
|
|
case UNLOADED:
|
|
|
|
case ILLEGAL:
|
|
|
|
case SLOT:
|
|
|
|
// Do nothing.
|
|
|
|
;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set_unloaded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 13:56:41 +00:00
|
|
|
void Reference::GetValue() {
|
2009-02-27 13:00:32 +00:00
|
|
|
ASSERT(cgen_->HasValidEntryRegisters());
|
2008-10-08 07:24:06 +00:00
|
|
|
ASSERT(!is_illegal());
|
|
|
|
ASSERT(!cgen_->has_cc());
|
|
|
|
MacroAssembler* masm = cgen_->masm();
|
|
|
|
Property* property = expression_->AsProperty();
|
|
|
|
if (property != NULL) {
|
2008-12-17 08:45:42 +00:00
|
|
|
cgen_->CodeForSourcePosition(property->position());
|
2008-10-08 07:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (type_) {
|
|
|
|
case SLOT: {
|
|
|
|
Comment cmnt(masm, "[ Load from Slot");
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = expression_->AsVariableProxy()->AsVariable()->AsSlot();
|
2008-10-08 07:24:06 +00:00
|
|
|
ASSERT(slot != NULL);
|
2010-05-27 13:48:52 +00:00
|
|
|
DupIfPersist();
|
2010-04-22 12:20:36 +00:00
|
|
|
cgen_->LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF);
|
2008-10-08 07:24:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NAMED: {
|
|
|
|
Variable* var = expression_->AsVariableProxy()->AsVariable();
|
2010-04-22 07:18:30 +00:00
|
|
|
bool is_global = var != NULL;
|
|
|
|
ASSERT(!is_global || var->is_global());
|
2010-05-27 13:48:52 +00:00
|
|
|
Handle<String> name = GetName();
|
|
|
|
DupIfPersist();
|
|
|
|
cgen_->EmitNamedLoad(name, is_global);
|
2008-10-08 07:24:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KEYED: {
|
2010-05-19 10:29:19 +00:00
|
|
|
ASSERT(property != NULL);
|
2010-05-27 13:48:52 +00:00
|
|
|
DupIfPersist();
|
2010-04-27 11:16:05 +00:00
|
|
|
cgen_->EmitKeyedLoad();
|
2010-01-27 14:07:12 +00:00
|
|
|
cgen_->frame()->EmitPush(r0);
|
2008-10-08 07:24:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-01 15:06:24 +00:00
|
|
|
void Reference::SetValue(InitState init_state, WriteBarrierCharacter wb_info) {
|
2008-10-07 11:19:44 +00:00
|
|
|
ASSERT(!is_illegal());
|
|
|
|
ASSERT(!cgen_->has_cc());
|
|
|
|
MacroAssembler* masm = cgen_->masm();
|
2008-11-07 08:21:07 +00:00
|
|
|
VirtualFrame* frame = cgen_->frame();
|
2008-10-08 07:24:06 +00:00
|
|
|
Property* property = expression_->AsProperty();
|
|
|
|
if (property != NULL) {
|
2008-12-17 08:45:42 +00:00
|
|
|
cgen_->CodeForSourcePosition(property->position());
|
2008-10-08 07:24:06 +00:00
|
|
|
}
|
|
|
|
|
2008-10-07 11:19:44 +00:00
|
|
|
switch (type_) {
|
|
|
|
case SLOT: {
|
|
|
|
Comment cmnt(masm, "[ Store to Slot");
|
2010-09-24 07:53:59 +00:00
|
|
|
Slot* slot = expression_->AsVariableProxy()->AsVariable()->AsSlot();
|
2010-01-12 17:22:57 +00:00
|
|
|
cgen_->StoreToSlot(slot, init_state);
|
2010-05-04 09:33:12 +00:00
|
|
|
set_unloaded();
|
2008-10-07 11:19:44 +00:00
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-07 11:19:44 +00:00
|
|
|
case NAMED: {
|
|
|
|
Comment cmnt(masm, "[ Store to named Property");
|
2010-05-04 09:33:12 +00:00
|
|
|
cgen_->EmitNamedStore(GetName(), false);
|
2009-08-11 11:46:27 +00:00
|
|
|
frame->EmitPush(r0);
|
2010-02-10 15:06:08 +00:00
|
|
|
set_unloaded();
|
2008-10-07 11:19:44 +00:00
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-07 11:19:44 +00:00
|
|
|
case KEYED: {
|
|
|
|
Comment cmnt(masm, "[ Store to keyed Property");
|
|
|
|
Property* property = expression_->AsProperty();
|
|
|
|
ASSERT(property != NULL);
|
2008-12-17 08:45:42 +00:00
|
|
|
cgen_->CodeForSourcePosition(property->position());
|
2010-07-01 15:06:24 +00:00
|
|
|
cgen_->EmitKeyedStore(property->key()->type(), wb_info);
|
2009-08-11 11:46:27 +00:00
|
|
|
frame->EmitPush(r0);
|
2010-05-18 06:57:12 +00:00
|
|
|
set_unloaded();
|
2008-10-07 11:19:44 +00:00
|
|
|
break;
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-07 11:19:44 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
2008-10-02 11:54:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
const char* GenericBinaryOpStub::GetName() {
|
|
|
|
if (name_ != NULL) return name_;
|
|
|
|
const int len = 100;
|
2011-03-18 20:35:07 +00:00
|
|
|
name_ = Isolate::Current()->bootstrapper()->AllocateAutoDeletedArray(len);
|
2010-08-25 09:44:44 +00:00
|
|
|
if (name_ == NULL) return "OOM";
|
|
|
|
const char* op_name = Token::Name(op_);
|
|
|
|
const char* overwrite_name;
|
2009-06-10 10:20:37 +00:00
|
|
|
switch (mode_) {
|
2010-08-25 09:44:44 +00:00
|
|
|
case NO_OVERWRITE: overwrite_name = "Alloc"; break;
|
|
|
|
case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break;
|
|
|
|
case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break;
|
|
|
|
default: overwrite_name = "UnknownOverwrite"; break;
|
2009-12-11 10:40:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OS::SNPrintF(Vector<char>(name_, len),
|
2010-06-21 10:34:25 +00:00
|
|
|
"GenericBinaryOpStub_%s_%s%s_%s",
|
2009-12-11 10:40:01 +00:00
|
|
|
op_name,
|
|
|
|
overwrite_name,
|
2010-06-21 10:34:25 +00:00
|
|
|
specialized_on_rhs_ ? "_ConstantRhs" : "",
|
|
|
|
BinaryOpIC::GetName(runtime_operands_type_));
|
2009-12-11 10:40:01 +00:00
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
#undef __
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
2010-05-17 15:41:35 +00:00
|
|
|
|
|
|
|
#endif // V8_TARGET_ARCH_ARM
|