11d9e7ff51
true at the top level we generate: 0 stmdb sp!, {r1, r8, fp, lr} 4 add fp, sp, #8 8 ldr ip, [r10, #+4] 12 ldr r2, [r10, #+0] 16 str ip, [sp, #-4]! 20 add lr, pc, #4 24 cmp sp, r2 28 ldrcc pc, [pc, #+68] ;; code: STUB, StackCheck, minor: 0 32 ldr ip, [pc, #+68] ;; object: 0xf5bc4161 <true> 36 str ip, [sp, #-4]! 40 ldr ip, [sp, #+0] 44 str ip, [fp, #-12] 48 add sp, sp, #4 52 ldr ip, [fp, #-12] 56 str ip, [sp, #-4]! 60 ldr r0, [sp], #+4 64 mov sp, fp ;; js return 68 ldmia sp!, {fp, lr} 72 add sp, sp, #4 76 bx lr 80 ldr r0, [r10, #+4] 84 mov sp, fp ;; js return 88 ldmia sp!, {fp, lr} 92 add sp, sp, #4 96 bx lr 100 constant pool begin 104 constant 108 constant Review URL: http://codereview.chromium.org/264067 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3073 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
141 lines
4.8 KiB
C++
141 lines
4.8 KiB
C++
// Copyright 2009 the V8 project authors. All rights reserved.
|
|
// 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"
|
|
|
|
#include "codegen-inl.h"
|
|
#include "fast-codegen.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
#define __ ACCESS_MASM(masm_)
|
|
|
|
// Generate code for a JS function. On entry to the function the receiver
|
|
// and arguments have been pushed on the stack left to right, with the
|
|
// return address on top of them. The actual argument count matches the
|
|
// formal parameter count expected by the function.
|
|
//
|
|
// The live registers are:
|
|
// o edi: the JS function object being called (ie, ourselves)
|
|
// o esi: our context
|
|
// o ebp: our caller's frame pointer
|
|
// o esp: stack pointer (pointing to return address)
|
|
//
|
|
// The function builds a JS frame. Please see JavaScriptFrameConstants in
|
|
// frames-ia32.h for its layout.
|
|
void FastCodeGenerator::Generate(FunctionLiteral* fun) {
|
|
function_ = fun;
|
|
|
|
__ push(ebp); // Caller's frame pointer.
|
|
__ mov(ebp, esp);
|
|
__ push(esi); // Callee's context.
|
|
__ push(edi); // Callee's JS Function.
|
|
|
|
{ Comment cmnt(masm_, "[ Allocate locals");
|
|
int locals_count = fun->scope()->num_stack_slots();
|
|
for (int i = 0; i < locals_count; i++) {
|
|
__ push(Immediate(Factory::undefined_value()));
|
|
}
|
|
}
|
|
|
|
{ Comment cmnt(masm_, "[ Stack check");
|
|
Label ok;
|
|
ExternalReference stack_guard_limit =
|
|
ExternalReference::address_of_stack_guard_limit();
|
|
__ cmp(esp, Operand::StaticVariable(stack_guard_limit));
|
|
__ j(above_equal, &ok, taken);
|
|
StackCheckStub stub;
|
|
__ CallStub(&stub);
|
|
__ bind(&ok);
|
|
}
|
|
|
|
{ Comment cmnt(masm_, "[ Body");
|
|
VisitStatements(fun->body());
|
|
}
|
|
|
|
{ Comment cmnt(masm_, "[ return <undefined>;");
|
|
// Emit a 'return undefined' in case control fell off the end of the
|
|
// body.
|
|
__ mov(eax, Factory::undefined_value());
|
|
__ RecordJSReturn();
|
|
// Do not use the leave instruction here because it is too short to
|
|
// patch with the code required by the debugger.
|
|
__ mov(esp, ebp);
|
|
__ pop(ebp);
|
|
__ ret((fun->scope()->num_parameters() + 1) * kPointerSize);
|
|
}
|
|
}
|
|
|
|
|
|
void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
|
|
Comment cmnt(masm_, "[ ExpressionStatement");
|
|
Visit(stmt->expression());
|
|
__ pop(eax);
|
|
}
|
|
|
|
|
|
void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
|
|
Comment cmnt(masm_, "[ ReturnStatement");
|
|
Visit(stmt->expression());
|
|
__ pop(eax);
|
|
__ RecordJSReturn();
|
|
// Do not use the leave instruction here because it is too short to
|
|
// patch with the code required by the debugger.
|
|
__ mov(esp, ebp);
|
|
__ pop(ebp);
|
|
__ ret((function_->scope()->num_parameters() + 1) * kPointerSize);
|
|
}
|
|
|
|
|
|
void FastCodeGenerator::VisitSlot(Slot* expr) {
|
|
Comment cmnt(masm_, "[ Slot");
|
|
__ push(Operand(ebp, SlotOffset(expr)));
|
|
}
|
|
|
|
|
|
void FastCodeGenerator::VisitLiteral(Literal* expr) {
|
|
Comment cmnt(masm_, "[ Literal");
|
|
__ push(Immediate(expr->handle()));
|
|
}
|
|
|
|
|
|
void FastCodeGenerator::VisitAssignment(Assignment* expr) {
|
|
Comment cmnt(masm_, "[ Assignment");
|
|
ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR);
|
|
|
|
Visit(expr->value());
|
|
|
|
Variable* var = expr->target()->AsVariableProxy()->AsVariable();
|
|
ASSERT(var != NULL && var->slot() != NULL);
|
|
__ mov(eax, Operand(esp, 0));
|
|
__ mov(Operand(ebp, SlotOffset(var->slot())), eax);
|
|
}
|
|
|
|
|
|
} } // namespace v8::internal
|