mirror of https://github.com/lukechilds/node.git
Ryan Dahl
15 years ago
132 changed files with 7981 additions and 2226 deletions
@ -0,0 +1,176 @@ |
|||||
|
// 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. The actual
|
||||
|
// argument count matches the formal parameter count expected by the
|
||||
|
// function.
|
||||
|
//
|
||||
|
// The live registers are:
|
||||
|
// o r1: the JS function object being called (ie, ourselves)
|
||||
|
// o cp: our context
|
||||
|
// o fp: our caller's frame pointer
|
||||
|
// o sp: stack pointer
|
||||
|
// o lr: return address
|
||||
|
//
|
||||
|
// The function builds a JS frame. Please see JavaScriptFrameConstants in
|
||||
|
// frames-arm.h for its layout.
|
||||
|
void FastCodeGenerator::Generate(FunctionLiteral* fun) { |
||||
|
function_ = fun; |
||||
|
// ARM does NOT call SetFunctionPosition.
|
||||
|
|
||||
|
__ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
||||
|
// Adjust fp to point to caller's fp.
|
||||
|
__ add(fp, sp, Operand(2 * kPointerSize)); |
||||
|
|
||||
|
{ Comment cmnt(masm_, "[ Allocate locals"); |
||||
|
int locals_count = fun->scope()->num_stack_slots(); |
||||
|
if (locals_count > 0) { |
||||
|
__ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
||||
|
} |
||||
|
if (FLAG_check_stack) { |
||||
|
__ LoadRoot(r2, Heap::kStackLimitRootIndex); |
||||
|
} |
||||
|
for (int i = 0; i < locals_count; i++) { |
||||
|
__ push(ip); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (FLAG_check_stack) { |
||||
|
// Put the lr setup instruction in the delay slot. The kInstrSize is
|
||||
|
// added to the implicit 8 byte offset that always applies to operations
|
||||
|
// with pc and gives a return address 12 bytes down.
|
||||
|
Comment cmnt(masm_, "[ Stack check"); |
||||
|
__ add(lr, pc, Operand(Assembler::kInstrSize)); |
||||
|
__ cmp(sp, Operand(r2)); |
||||
|
StackCheckStub stub; |
||||
|
__ mov(pc, |
||||
|
Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
||||
|
RelocInfo::CODE_TARGET), |
||||
|
LeaveCC, |
||||
|
lo); |
||||
|
} |
||||
|
|
||||
|
{ 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.
|
||||
|
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
||||
|
SetReturnPosition(fun); |
||||
|
__ RecordJSReturn(); |
||||
|
__ mov(sp, fp); |
||||
|
__ ldm(ia_w, sp, fp.bit() | lr.bit()); |
||||
|
int num_parameters = function_->scope()->num_parameters(); |
||||
|
__ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); |
||||
|
__ Jump(lr); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
||||
|
Comment cmnt(masm_, "[ ExpressionStatement"); |
||||
|
SetStatementPosition(stmt); |
||||
|
Visit(stmt->expression()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
||||
|
Comment cmnt(masm_, "[ ReturnStatement"); |
||||
|
SetStatementPosition(stmt); |
||||
|
Visit(stmt->expression()); |
||||
|
__ pop(r0); |
||||
|
__ RecordJSReturn(); |
||||
|
__ mov(sp, fp); |
||||
|
__ ldm(ia_w, sp, fp.bit() | lr.bit()); |
||||
|
int num_parameters = function_->scope()->num_parameters(); |
||||
|
__ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); |
||||
|
__ Jump(lr); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
||||
|
Comment cmnt(masm_, "[ VariableProxy"); |
||||
|
Expression* rewrite = expr->var()->rewrite(); |
||||
|
ASSERT(rewrite != NULL); |
||||
|
|
||||
|
Slot* slot = rewrite->AsSlot(); |
||||
|
ASSERT(slot != NULL); |
||||
|
{ Comment cmnt(masm_, "[ Slot"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ ldr(ip, MemOperand(fp, SlotOffset(slot))); |
||||
|
__ push(ip); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitLiteral(Literal* expr) { |
||||
|
Comment cmnt(masm_, "[ Literal"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ mov(ip, Operand(expr->handle())); |
||||
|
__ push(ip); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
|
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ ldr(ip, MemOperand(sp)); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
__ pop(ip); |
||||
|
} |
||||
|
__ str(ip, MemOperand(fp, SlotOffset(var->slot()))); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
@ -0,0 +1,269 @@ |
|||||
|
// 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 { |
||||
|
|
||||
|
Handle<Code> FastCodeGenerator::MakeCode(FunctionLiteral* fun, |
||||
|
Handle<Script> script) { |
||||
|
CodeGenerator::MakeCodePrologue(fun); |
||||
|
const int kInitialBufferSize = 4 * KB; |
||||
|
MacroAssembler masm(NULL, kInitialBufferSize); |
||||
|
FastCodeGenerator cgen(&masm); |
||||
|
cgen.Generate(fun); |
||||
|
if (cgen.HasStackOverflow()) { |
||||
|
ASSERT(!Top::has_pending_exception()); |
||||
|
return Handle<Code>::null(); |
||||
|
} |
||||
|
Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP); |
||||
|
return CodeGenerator::MakeCodeEpilogue(fun, &masm, flags, script); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
int FastCodeGenerator::SlotOffset(Slot* slot) { |
||||
|
// Offset is negative because higher indexes are at lower addresses.
|
||||
|
int offset = -slot->index() * kPointerSize; |
||||
|
// Adjust by a (parameter or local) base offset.
|
||||
|
switch (slot->type()) { |
||||
|
case Slot::PARAMETER: |
||||
|
offset += (function_->scope()->num_parameters() + 1) * kPointerSize; |
||||
|
break; |
||||
|
case Slot::LOCAL: |
||||
|
offset += JavaScriptFrameConstants::kLocal0Offset; |
||||
|
break; |
||||
|
default: |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
return offset; |
||||
|
} |
||||
|
|
||||
|
void FastCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) { |
||||
|
if (FLAG_debug_info) { |
||||
|
CodeGenerator::RecordPositions(masm_, fun->start_position()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
||||
|
if (FLAG_debug_info) { |
||||
|
CodeGenerator::RecordPositions(masm_, fun->end_position()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::SetStatementPosition(Statement* stmt) { |
||||
|
if (FLAG_debug_info) { |
||||
|
CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::SetSourcePosition(int pos) { |
||||
|
if (FLAG_debug_info && pos != RelocInfo::kNoPosition) { |
||||
|
masm_->RecordPosition(pos); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitDeclaration(Declaration* decl) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitBlock(Block* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitIfStatement(IfStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitForStatement(ForStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitFunctionBoilerplateLiteral( |
||||
|
FunctionBoilerplateLiteral* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitConditional(Conditional* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitSlot(Slot* expr) { |
||||
|
// Slots do not appear directly in the AST.
|
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitThrow(Throw* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitProperty(Property* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCall(Call* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCallNew(CallNew* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCountOperation(CountOperation* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
||||
|
UNREACHABLE(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
@ -0,0 +1,71 @@ |
|||||
|
// 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.
|
||||
|
|
||||
|
#ifndef V8_FAST_CODEGEN_H_ |
||||
|
#define V8_FAST_CODEGEN_H_ |
||||
|
|
||||
|
#include "v8.h" |
||||
|
|
||||
|
#include "ast.h" |
||||
|
|
||||
|
namespace v8 { |
||||
|
namespace internal { |
||||
|
|
||||
|
|
||||
|
class FastCodeGenerator: public AstVisitor { |
||||
|
public: |
||||
|
explicit FastCodeGenerator(MacroAssembler* masm) |
||||
|
: masm_(masm), function_(NULL) { |
||||
|
} |
||||
|
|
||||
|
static Handle<Code> MakeCode(FunctionLiteral* fun, Handle<Script> script); |
||||
|
|
||||
|
void Generate(FunctionLiteral* fun); |
||||
|
|
||||
|
private: |
||||
|
int SlotOffset(Slot* slot); |
||||
|
|
||||
|
void SetFunctionPosition(FunctionLiteral* fun); |
||||
|
void SetReturnPosition(FunctionLiteral* fun); |
||||
|
void SetStatementPosition(Statement* stmt); |
||||
|
void SetSourcePosition(int pos); |
||||
|
|
||||
|
// AST node visit functions.
|
||||
|
#define DECLARE_VISIT(type) virtual void Visit##type(type* node); |
||||
|
AST_NODE_LIST(DECLARE_VISIT) |
||||
|
#undef DECLARE_VISIT |
||||
|
|
||||
|
MacroAssembler* masm_; |
||||
|
FunctionLiteral* function_; |
||||
|
|
||||
|
DISALLOW_COPY_AND_ASSIGN(FastCodeGenerator); |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
||||
|
|
||||
|
#endif // V8_FAST_CODEGEN_H_
|
File diff suppressed because it is too large
@ -0,0 +1,163 @@ |
|||||
|
// 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; |
||||
|
SetFunctionPosition(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()); |
||||
|
SetReturnPosition(fun); |
||||
|
__ 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"); |
||||
|
SetStatementPosition(stmt); |
||||
|
Visit(stmt->expression()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
||||
|
Comment cmnt(masm_, "[ ReturnStatement"); |
||||
|
SetStatementPosition(stmt); |
||||
|
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::VisitVariableProxy(VariableProxy* expr) { |
||||
|
Comment cmnt(masm_, "[ VariableProxy"); |
||||
|
Expression* rewrite = expr->var()->rewrite(); |
||||
|
ASSERT(rewrite != NULL); |
||||
|
|
||||
|
Slot* slot = rewrite->AsSlot(); |
||||
|
ASSERT(slot != NULL); |
||||
|
{ Comment cmnt(masm_, "[ Slot"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ push(Operand(ebp, SlotOffset(slot))); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitLiteral(Literal* expr) { |
||||
|
Comment cmnt(masm_, "[ Literal"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ push(Immediate(expr->handle())); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
|
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ mov(eax, Operand(esp, 0)); |
||||
|
__ mov(Operand(ebp, SlotOffset(var->slot())), eax); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
__ pop(Operand(ebp, SlotOffset(var->slot()))); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
@ -0,0 +1,56 @@ |
|||||
|
// 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.
|
||||
|
|
||||
|
#ifndef V8_LOCATION_H_ |
||||
|
#define V8_LOCATION_H_ |
||||
|
|
||||
|
#include "utils.h" |
||||
|
|
||||
|
namespace v8 { |
||||
|
namespace internal { |
||||
|
|
||||
|
class Location BASE_EMBEDDED { |
||||
|
public: |
||||
|
static Location Temporary() { return Location(TEMP); } |
||||
|
static Location Nowhere() { return Location(NOWHERE); } |
||||
|
static Location Constant() { return Location(CONSTANT); } |
||||
|
|
||||
|
bool is_temporary() { return type_ == TEMP; } |
||||
|
bool is_nowhere() { return type_ == NOWHERE; } |
||||
|
|
||||
|
private: |
||||
|
enum Type { TEMP, NOWHERE, CONSTANT }; |
||||
|
|
||||
|
explicit Location(Type type) : type_(type) {} |
||||
|
|
||||
|
Type type_; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
||||
|
|
||||
|
#endif // V8_LOCATION_H_
|
File diff suppressed because it is too large
@ -0,0 +1,181 @@ |
|||||
|
// 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 "debug.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 rdi: the JS function object being called (ie, ourselves)
|
||||
|
// o rsi: our context
|
||||
|
// o rbp: our caller's frame pointer
|
||||
|
// o rsp: stack pointer (pointing to return address)
|
||||
|
//
|
||||
|
// The function builds a JS frame. Please see JavaScriptFrameConstants in
|
||||
|
// frames-x64.h for its layout.
|
||||
|
void FastCodeGenerator::Generate(FunctionLiteral* fun) { |
||||
|
function_ = fun; |
||||
|
SetFunctionPosition(fun); |
||||
|
|
||||
|
__ push(rbp); // Caller's frame pointer.
|
||||
|
__ movq(rbp, rsp); |
||||
|
__ push(rsi); // Callee's context.
|
||||
|
__ push(rdi); // 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++) { |
||||
|
__ PushRoot(Heap::kUndefinedValueRootIndex); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
{ Comment cmnt(masm_, "[ Stack check"); |
||||
|
Label ok; |
||||
|
__ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
||||
|
__ j(above_equal, &ok); |
||||
|
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.
|
||||
|
__ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
||||
|
SetReturnPosition(fun); |
||||
|
__ RecordJSReturn(); |
||||
|
// Do not use the leave instruction here because it is too short to
|
||||
|
// patch with the code required by the debugger.
|
||||
|
__ movq(rsp, rbp); |
||||
|
__ pop(rbp); |
||||
|
__ ret((fun->scope()->num_parameters() + 1) * kPointerSize); |
||||
|
#ifdef ENABLE_DEBUGGER_SUPPORT |
||||
|
// Add padding that will be overwritten by a debugger breakpoint. We
|
||||
|
// have just generated "movq rsp, rbp; pop rbp; ret k" with length 7
|
||||
|
// (3 + 1 + 3).
|
||||
|
const int kPadding = Debug::kX64JSReturnSequenceLength - 7; |
||||
|
for (int i = 0; i < kPadding; ++i) { |
||||
|
masm_->int3(); |
||||
|
} |
||||
|
#endif |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
||||
|
Comment cmnt(masm_, "[ ExpressionStatement"); |
||||
|
SetStatementPosition(stmt); |
||||
|
Visit(stmt->expression()); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
||||
|
Comment cmnt(masm_, "[ ReturnStatement"); |
||||
|
SetStatementPosition(stmt); |
||||
|
Visit(stmt->expression()); |
||||
|
__ pop(rax); |
||||
|
__ RecordJSReturn(); |
||||
|
// Do not use the leave instruction here because it is too short to
|
||||
|
// patch with the code required by the debugger.
|
||||
|
__ movq(rsp, rbp); |
||||
|
__ pop(rbp); |
||||
|
__ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
||||
|
#ifdef ENABLE_DEBUGGER_SUPPORT |
||||
|
// Add padding that will be overwritten by a debugger breakpoint. We
|
||||
|
// have just generated "movq rsp, rbp; pop rbp; ret k" with length 7
|
||||
|
// (3 + 1 + 3).
|
||||
|
const int kPadding = Debug::kX64JSReturnSequenceLength - 7; |
||||
|
for (int i = 0; i < kPadding; ++i) { |
||||
|
masm_->int3(); |
||||
|
} |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
||||
|
Comment cmnt(masm_, "[ VariableProxy"); |
||||
|
Expression* rewrite = expr->var()->rewrite(); |
||||
|
ASSERT(rewrite != NULL); |
||||
|
|
||||
|
Slot* slot = rewrite->AsSlot(); |
||||
|
ASSERT(slot != NULL); |
||||
|
{ Comment cmnt(masm_, "[ Slot"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ push(Operand(rbp, SlotOffset(slot))); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void FastCodeGenerator::VisitLiteral(Literal* expr) { |
||||
|
Comment cmnt(masm_, "[ Literal"); |
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ Push(expr->handle()); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
|
||||
|
if (expr->location().is_temporary()) { |
||||
|
__ movq(rax, Operand(rsp, 0)); |
||||
|
__ movq(Operand(rbp, SlotOffset(var->slot())), rax); |
||||
|
} else { |
||||
|
ASSERT(expr->location().is_nowhere()); |
||||
|
__ pop(Operand(rbp, SlotOffset(var->slot()))); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} } // namespace v8::internal
|
File diff suppressed because it is too large
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue