Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
// 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.
|
|
|
|
|
2010-01-27 15:23:48 +00:00
|
|
|
#ifndef V8_FULL_CODEGEN_H_
|
|
|
|
#define V8_FULL_CODEGEN_H_
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "ast.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2010-01-20 15:51:03 +00:00
|
|
|
class FullCodeGenSyntaxChecker: public AstVisitor {
|
|
|
|
public:
|
|
|
|
FullCodeGenSyntaxChecker() : has_supported_syntax_(true) {}
|
|
|
|
|
|
|
|
void Check(FunctionLiteral* fun);
|
|
|
|
|
|
|
|
bool has_supported_syntax() { return has_supported_syntax_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void VisitDeclarations(ZoneList<Declaration*>* decls);
|
|
|
|
void VisitStatements(ZoneList<Statement*>* stmts);
|
|
|
|
|
|
|
|
// AST node visit functions.
|
|
|
|
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
|
|
|
|
AST_NODE_LIST(DECLARE_VISIT)
|
|
|
|
#undef DECLARE_VISIT
|
|
|
|
|
|
|
|
bool has_supported_syntax_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FullCodeGenSyntaxChecker);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2010-01-20 15:51:03 +00:00
|
|
|
// Full code generator.
|
Initial port of top-level code generator to ARM. For the constant
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
2009-10-15 12:42:16 +00:00
|
|
|
|
2010-01-20 15:51:03 +00:00
|
|
|
class FullCodeGenerator: public AstVisitor {
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
public:
|
2010-02-01 17:01:58 +00:00
|
|
|
enum Mode {
|
|
|
|
PRIMARY,
|
|
|
|
SECONDARY
|
|
|
|
};
|
|
|
|
|
2010-02-04 15:21:05 +00:00
|
|
|
explicit FullCodeGenerator(MacroAssembler* masm)
|
Initial implementation of top-level compilation of expressions in test
context. Test contexts are used for the left subexpressions of
short-circuited boolean operators. The right subexpressions inherit
their expression context from the binary op expression.
Compilation of short-circuited operations in effect and test context
is straightforward:
effect(e0 || e1) =
test(e0, L0, L1)
L1: effect(e1)
L0:
test(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test(e1, L0, L1)
Because the value of the first subexpression may be needed as the
value of the whole expression in a value context, we introduce a
hybrid value/test contest (the value is needed if true, but not if
false).
value(e0 || e1) =
value/test(e0, L0, L1)
L1: value(e1)
L0:
The compilation of value/test and test/value (introduced by boolean
AND) is:
value/test(e0 || e1, L0, L1) =
value/test(e0, L0, L2)
L2: value/test(e1, L0, L1)
test/value(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test/value(e1, L0, L1)
Boolean AND is the dual. The AST nodes themselves (not their parents)
are responsible for producing the proper result (effect, value, or
control flow) depending on their context.
Review URL: http://codereview.chromium.org/339082
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-30 14:06:48 +00:00
|
|
|
: masm_(masm),
|
2010-02-03 16:12:55 +00:00
|
|
|
info_(NULL),
|
2009-12-10 14:06:08 +00:00
|
|
|
nesting_stack_(NULL),
|
2009-11-03 14:48:59 +00:00
|
|
|
loop_depth_(0),
|
2010-01-18 14:04:55 +00:00
|
|
|
location_(kStack),
|
Initial implementation of top-level compilation of expressions in test
context. Test contexts are used for the left subexpressions of
short-circuited boolean operators. The right subexpressions inherit
their expression context from the binary op expression.
Compilation of short-circuited operations in effect and test context
is straightforward:
effect(e0 || e1) =
test(e0, L0, L1)
L1: effect(e1)
L0:
test(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test(e1, L0, L1)
Because the value of the first subexpression may be needed as the
value of the whole expression in a value context, we introduce a
hybrid value/test contest (the value is needed if true, but not if
false).
value(e0 || e1) =
value/test(e0, L0, L1)
L1: value(e1)
L0:
The compilation of value/test and test/value (introduced by boolean
AND) is:
value/test(e0 || e1, L0, L1) =
value/test(e0, L0, L2)
L2: value/test(e1, L0, L1)
test/value(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test/value(e1, L0, L1)
Boolean AND is the dual. The AST nodes themselves (not their parents)
are responsible for producing the proper result (effect, value, or
control flow) depending on their context.
Review URL: http://codereview.chromium.org/339082
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-30 14:06:48 +00:00
|
|
|
true_label_(NULL),
|
|
|
|
false_label_(NULL) {
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
}
|
|
|
|
|
2010-02-03 16:12:55 +00:00
|
|
|
static Handle<Code> MakeCode(CompilationInfo* info);
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
|
2010-02-03 16:12:55 +00:00
|
|
|
void Generate(CompilationInfo* info, Mode mode);
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
|
|
|
|
private:
|
2009-12-10 14:06:08 +00:00
|
|
|
class Breakable;
|
|
|
|
class Iteration;
|
|
|
|
class TryCatch;
|
|
|
|
class TryFinally;
|
|
|
|
class Finally;
|
|
|
|
class ForIn;
|
|
|
|
|
|
|
|
class NestedStatement BASE_EMBEDDED {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) {
|
2009-12-10 14:06:08 +00:00
|
|
|
// Link into codegen's nesting stack.
|
|
|
|
previous_ = codegen->nesting_stack_;
|
|
|
|
codegen->nesting_stack_ = this;
|
|
|
|
}
|
|
|
|
virtual ~NestedStatement() {
|
|
|
|
// Unlink from codegen's nesting stack.
|
|
|
|
ASSERT_EQ(this, codegen_->nesting_stack_);
|
|
|
|
codegen_->nesting_stack_ = previous_;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Breakable* AsBreakable() { return NULL; }
|
|
|
|
virtual Iteration* AsIteration() { return NULL; }
|
|
|
|
virtual TryCatch* AsTryCatch() { return NULL; }
|
|
|
|
virtual TryFinally* AsTryFinally() { return NULL; }
|
|
|
|
virtual Finally* AsFinally() { return NULL; }
|
|
|
|
virtual ForIn* AsForIn() { return NULL; }
|
|
|
|
|
|
|
|
virtual bool IsContinueTarget(Statement* target) { return false; }
|
|
|
|
virtual bool IsBreakTarget(Statement* target) { return false; }
|
|
|
|
|
|
|
|
// Generate code to leave the nested statement. This includes
|
|
|
|
// cleaning up any stack elements in use and restoring the
|
|
|
|
// stack to the expectations of the surrounding statements.
|
|
|
|
// Takes a number of stack elements currently on top of the
|
|
|
|
// nested statement's stack, and returns a number of stack
|
|
|
|
// elements left on top of the surrounding statement's stack.
|
|
|
|
// The generated code must preserve the result register (which
|
|
|
|
// contains the value in case of a return).
|
|
|
|
virtual int Exit(int stack_depth) {
|
|
|
|
// Default implementation for the case where there is
|
|
|
|
// nothing to clean up.
|
|
|
|
return stack_depth;
|
|
|
|
}
|
|
|
|
NestedStatement* outer() { return previous_; }
|
|
|
|
protected:
|
|
|
|
MacroAssembler* masm() { return codegen_->masm(); }
|
|
|
|
private:
|
2010-01-20 15:51:03 +00:00
|
|
|
FullCodeGenerator* codegen_;
|
2009-12-10 14:06:08 +00:00
|
|
|
NestedStatement* previous_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NestedStatement);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Breakable : public NestedStatement {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
Breakable(FullCodeGenerator* codegen,
|
2009-12-10 14:06:08 +00:00
|
|
|
BreakableStatement* break_target)
|
|
|
|
: NestedStatement(codegen),
|
|
|
|
target_(break_target) {}
|
|
|
|
virtual ~Breakable() {}
|
|
|
|
virtual Breakable* AsBreakable() { return this; }
|
|
|
|
virtual bool IsBreakTarget(Statement* statement) {
|
|
|
|
return target_ == statement;
|
|
|
|
}
|
|
|
|
BreakableStatement* statement() { return target_; }
|
|
|
|
Label* break_target() { return &break_target_label_; }
|
|
|
|
private:
|
|
|
|
BreakableStatement* target_;
|
|
|
|
Label break_target_label_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Breakable);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Iteration : public Breakable {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
Iteration(FullCodeGenerator* codegen,
|
2009-12-10 14:06:08 +00:00
|
|
|
IterationStatement* iteration_statement)
|
|
|
|
: Breakable(codegen, iteration_statement) {}
|
|
|
|
virtual ~Iteration() {}
|
|
|
|
virtual Iteration* AsIteration() { return this; }
|
|
|
|
virtual bool IsContinueTarget(Statement* statement) {
|
|
|
|
return this->statement() == statement;
|
|
|
|
}
|
|
|
|
Label* continue_target() { return &continue_target_label_; }
|
|
|
|
private:
|
|
|
|
Label continue_target_label_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Iteration);
|
|
|
|
};
|
|
|
|
|
|
|
|
// The environment inside the try block of a try/catch statement.
|
|
|
|
class TryCatch : public NestedStatement {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
explicit TryCatch(FullCodeGenerator* codegen, Label* catch_entry)
|
2009-12-10 14:06:08 +00:00
|
|
|
: NestedStatement(codegen), catch_entry_(catch_entry) { }
|
|
|
|
virtual ~TryCatch() {}
|
|
|
|
virtual TryCatch* AsTryCatch() { return this; }
|
|
|
|
Label* catch_entry() { return catch_entry_; }
|
|
|
|
virtual int Exit(int stack_depth);
|
|
|
|
private:
|
|
|
|
Label* catch_entry_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TryCatch);
|
|
|
|
};
|
|
|
|
|
|
|
|
// The environment inside the try block of a try/finally statement.
|
|
|
|
class TryFinally : public NestedStatement {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
explicit TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
|
2009-12-10 14:06:08 +00:00
|
|
|
: NestedStatement(codegen), finally_entry_(finally_entry) { }
|
|
|
|
virtual ~TryFinally() {}
|
|
|
|
virtual TryFinally* AsTryFinally() { return this; }
|
|
|
|
Label* finally_entry() { return finally_entry_; }
|
|
|
|
virtual int Exit(int stack_depth);
|
|
|
|
private:
|
|
|
|
Label* finally_entry_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TryFinally);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A FinallyEnvironment represents being inside a finally block.
|
|
|
|
// Abnormal termination of the finally block needs to clean up
|
|
|
|
// the block's parameters from the stack.
|
|
|
|
class Finally : public NestedStatement {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~Finally() {}
|
|
|
|
virtual Finally* AsFinally() { return this; }
|
|
|
|
virtual int Exit(int stack_depth) {
|
|
|
|
return stack_depth + kFinallyStackElementCount;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// Number of extra stack slots occupied during a finally block.
|
|
|
|
static const int kFinallyStackElementCount = 2;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Finally);
|
|
|
|
};
|
|
|
|
|
|
|
|
// A ForInEnvironment represents being inside a for-in loop.
|
|
|
|
// Abnormal termination of the for-in block needs to clean up
|
|
|
|
// the block's temporary storage from the stack.
|
|
|
|
class ForIn : public Iteration {
|
|
|
|
public:
|
2010-01-20 15:51:03 +00:00
|
|
|
ForIn(FullCodeGenerator* codegen,
|
2009-12-10 14:06:08 +00:00
|
|
|
ForInStatement* statement)
|
|
|
|
: Iteration(codegen, statement) { }
|
|
|
|
virtual ~ForIn() {}
|
|
|
|
virtual ForIn* AsForIn() { return this; }
|
|
|
|
virtual int Exit(int stack_depth) {
|
|
|
|
return stack_depth + kForInStackElementCount;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// TODO(lrn): Check that this value is correct when implementing
|
|
|
|
// for-in.
|
|
|
|
static const int kForInStackElementCount = 5;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ForIn);
|
|
|
|
};
|
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
enum Location {
|
|
|
|
kAccumulator,
|
|
|
|
kStack
|
|
|
|
};
|
2009-12-10 14:06:08 +00:00
|
|
|
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
int SlotOffset(Slot* slot);
|
2010-01-12 08:48:26 +00:00
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Emit code to convert a pure value (in a register, slot, as a literal,
|
|
|
|
// or on top of the stack) into the result expected according to an
|
|
|
|
// expression context.
|
2010-01-12 08:48:26 +00:00
|
|
|
void Apply(Expression::Context context, Register reg);
|
2010-01-27 12:14:26 +00:00
|
|
|
|
|
|
|
// Slot cannot have type Slot::LOOKUP.
|
2010-01-18 14:04:55 +00:00
|
|
|
void Apply(Expression::Context context, Slot* slot);
|
2010-01-27 12:14:26 +00:00
|
|
|
|
2010-01-12 08:48:26 +00:00
|
|
|
void Apply(Expression::Context context, Literal* lit);
|
|
|
|
void ApplyTOS(Expression::Context context);
|
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Emit code to discard count elements from the top of stack, then convert
|
|
|
|
// a pure value into the result expected according to an expression
|
|
|
|
// context.
|
2010-01-12 08:48:26 +00:00
|
|
|
void DropAndApply(int count, Expression::Context context, Register reg);
|
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Emit code to convert pure control flow to a pair of labels into the
|
|
|
|
// result expected according to an expression context.
|
|
|
|
void Apply(Expression::Context context,
|
|
|
|
Label* materialize_true,
|
|
|
|
Label* materialize_false);
|
|
|
|
|
|
|
|
// Helper function to convert a pure value into a test context. The value
|
|
|
|
// is expected on the stack or the accumulator, depending on the platform.
|
|
|
|
// See the platform-specific implementation for details.
|
|
|
|
void DoTest(Expression::Context context);
|
|
|
|
|
2009-11-26 10:28:32 +00:00
|
|
|
void Move(Slot* dst, Register source, Register scratch1, Register scratch2);
|
|
|
|
void Move(Register dst, Slot* source);
|
|
|
|
|
2010-01-05 11:29:27 +00:00
|
|
|
// Return an operand used to read/write to a known (ie, non-LOOKUP) slot.
|
|
|
|
// May emit code to traverse the context chain, destroying the scratch
|
|
|
|
// register.
|
|
|
|
MemOperand EmitSlotSearch(Slot* slot, Register scratch);
|
2009-10-27 13:38:57 +00:00
|
|
|
|
2010-01-19 12:41:02 +00:00
|
|
|
void VisitForEffect(Expression* expr) {
|
|
|
|
Expression::Context saved_context = context_;
|
|
|
|
context_ = Expression::kEffect;
|
|
|
|
Visit(expr);
|
|
|
|
context_ = saved_context;
|
|
|
|
}
|
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
void VisitForValue(Expression* expr, Location where) {
|
2010-01-19 12:41:02 +00:00
|
|
|
Expression::Context saved_context = context_;
|
2010-01-18 14:04:55 +00:00
|
|
|
Location saved_location = location_;
|
2010-01-19 12:41:02 +00:00
|
|
|
context_ = Expression::kValue;
|
2010-01-18 14:04:55 +00:00
|
|
|
location_ = where;
|
|
|
|
Visit(expr);
|
2010-01-19 12:41:02 +00:00
|
|
|
context_ = saved_context;
|
2010-01-18 14:04:55 +00:00
|
|
|
location_ = saved_location;
|
|
|
|
}
|
Initial implementation of top-level compilation of expressions in test
context. Test contexts are used for the left subexpressions of
short-circuited boolean operators. The right subexpressions inherit
their expression context from the binary op expression.
Compilation of short-circuited operations in effect and test context
is straightforward:
effect(e0 || e1) =
test(e0, L0, L1)
L1: effect(e1)
L0:
test(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test(e1, L0, L1)
Because the value of the first subexpression may be needed as the
value of the whole expression in a value context, we introduce a
hybrid value/test contest (the value is needed if true, but not if
false).
value(e0 || e1) =
value/test(e0, L0, L1)
L1: value(e1)
L0:
The compilation of value/test and test/value (introduced by boolean
AND) is:
value/test(e0 || e1, L0, L1) =
value/test(e0, L0, L2)
L2: value/test(e1, L0, L1)
test/value(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test/value(e1, L0, L1)
Boolean AND is the dual. The AST nodes themselves (not their parents)
are responsible for producing the proper result (effect, value, or
control flow) depending on their context.
Review URL: http://codereview.chromium.org/339082
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-30 14:06:48 +00:00
|
|
|
|
2010-01-13 11:29:08 +00:00
|
|
|
void VisitForControl(Expression* expr, Label* if_true, Label* if_false) {
|
2010-01-19 12:41:02 +00:00
|
|
|
Expression::Context saved_context = context_;
|
|
|
|
Label* saved_true = true_label_;
|
|
|
|
Label* saved_false = false_label_;
|
|
|
|
context_ = Expression::kTest;
|
|
|
|
true_label_ = if_true;
|
|
|
|
false_label_ = if_false;
|
|
|
|
Visit(expr);
|
|
|
|
context_ = saved_context;
|
|
|
|
true_label_ = saved_true;
|
|
|
|
false_label_ = saved_false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisitForValueControl(Expression* expr,
|
|
|
|
Location where,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false) {
|
|
|
|
Expression::Context saved_context = context_;
|
|
|
|
Location saved_location = location_;
|
2010-01-13 11:29:08 +00:00
|
|
|
Label* saved_true = true_label_;
|
|
|
|
Label* saved_false = false_label_;
|
2010-01-19 12:41:02 +00:00
|
|
|
context_ = Expression::kValueTest;
|
|
|
|
location_ = where;
|
2010-01-13 11:29:08 +00:00
|
|
|
true_label_ = if_true;
|
|
|
|
false_label_ = if_false;
|
|
|
|
Visit(expr);
|
2010-01-19 12:41:02 +00:00
|
|
|
context_ = saved_context;
|
|
|
|
location_ = saved_location;
|
|
|
|
true_label_ = saved_true;
|
|
|
|
false_label_ = saved_false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisitForControlValue(Expression* expr,
|
|
|
|
Location where,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false) {
|
|
|
|
Expression::Context saved_context = context_;
|
|
|
|
Location saved_location = location_;
|
|
|
|
Label* saved_true = true_label_;
|
|
|
|
Label* saved_false = false_label_;
|
|
|
|
context_ = Expression::kTestValue;
|
|
|
|
location_ = where;
|
|
|
|
true_label_ = if_true;
|
|
|
|
false_label_ = if_false;
|
|
|
|
Visit(expr);
|
|
|
|
context_ = saved_context;
|
|
|
|
location_ = saved_location;
|
2010-01-13 11:29:08 +00:00
|
|
|
true_label_ = saved_true;
|
|
|
|
false_label_ = saved_false;
|
|
|
|
}
|
|
|
|
|
2009-10-21 09:17:39 +00:00
|
|
|
void VisitDeclarations(ZoneList<Declaration*>* declarations);
|
|
|
|
void DeclareGlobals(Handle<FixedArray> pairs);
|
|
|
|
|
2009-11-04 14:11:39 +00:00
|
|
|
// Platform-specific return sequence
|
|
|
|
void EmitReturnSequence(int position);
|
|
|
|
|
|
|
|
// Platform-specific code sequences for calls
|
2009-10-30 10:22:31 +00:00
|
|
|
void EmitCallWithStub(Call* expr);
|
2009-12-17 10:23:20 +00:00
|
|
|
void EmitCallWithIC(Call* expr, Handle<Object> name, RelocInfo::Mode mode);
|
2009-10-30 10:22:31 +00:00
|
|
|
|
2009-12-11 16:09:16 +00:00
|
|
|
// Platform-specific code for loading variables.
|
|
|
|
void EmitVariableLoad(Variable* expr, Expression::Context context);
|
|
|
|
|
2009-11-02 11:01:47 +00:00
|
|
|
// Platform-specific support for compiling assignments.
|
|
|
|
|
2010-01-04 13:56:31 +00:00
|
|
|
// Load a value from a named property.
|
2009-12-11 16:09:16 +00:00
|
|
|
// The receiver is left on the stack by the IC.
|
2010-01-15 12:00:59 +00:00
|
|
|
void EmitNamedPropertyLoad(Property* expr);
|
2009-12-11 16:09:16 +00:00
|
|
|
|
2010-01-04 13:56:31 +00:00
|
|
|
// Load a value from a keyed property.
|
2009-12-11 16:09:16 +00:00
|
|
|
// The receiver and the key is left on the stack by the IC.
|
2010-01-15 12:00:59 +00:00
|
|
|
void EmitKeyedPropertyLoad(Property* expr);
|
2009-12-11 16:09:16 +00:00
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Apply the compound assignment operator. Expects the left operand on top
|
|
|
|
// of the stack and the right one in the accumulator.
|
|
|
|
void EmitBinaryOp(Token::Value op, Expression::Context context);
|
2009-12-11 16:09:16 +00:00
|
|
|
|
2009-11-02 13:30:24 +00:00
|
|
|
// Complete a variable assignment. The right-hand-side value is expected
|
2010-01-18 14:04:55 +00:00
|
|
|
// in the accumulator.
|
2010-01-04 13:56:31 +00:00
|
|
|
void EmitVariableAssignment(Variable* var, Expression::Context context);
|
2009-11-02 11:01:47 +00:00
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Complete a named property assignment. The receiver is expected on top
|
|
|
|
// of the stack and the right-hand-side value in the accumulator.
|
2009-11-02 13:30:24 +00:00
|
|
|
void EmitNamedPropertyAssignment(Assignment* expr);
|
2009-11-02 11:01:47 +00:00
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// Complete a keyed property assignment. The receiver and key are
|
|
|
|
// expected on top of the stack and the right-hand-side value in the
|
|
|
|
// accumulator.
|
2009-11-02 13:30:24 +00:00
|
|
|
void EmitKeyedPropertyAssignment(Assignment* expr);
|
2009-11-02 11:01:47 +00:00
|
|
|
|
2009-10-15 15:27:37 +00:00
|
|
|
void SetFunctionPosition(FunctionLiteral* fun);
|
|
|
|
void SetReturnPosition(FunctionLiteral* fun);
|
|
|
|
void SetStatementPosition(Statement* stmt);
|
2010-01-14 17:22:59 +00:00
|
|
|
void SetStatementPosition(int pos);
|
2009-10-15 15:27:37 +00:00
|
|
|
void SetSourcePosition(int pos);
|
|
|
|
|
2009-12-14 11:09:25 +00:00
|
|
|
// Non-local control flow support.
|
|
|
|
void EnterFinallyBlock();
|
|
|
|
void ExitFinallyBlock();
|
|
|
|
|
|
|
|
// Loop nesting counter.
|
2009-11-03 14:48:59 +00:00
|
|
|
int loop_depth() { return loop_depth_; }
|
|
|
|
void increment_loop_depth() { loop_depth_++; }
|
|
|
|
void decrement_loop_depth() {
|
|
|
|
ASSERT(loop_depth_ > 0);
|
|
|
|
loop_depth_--;
|
|
|
|
}
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
MacroAssembler* masm() { return masm_; }
|
2010-02-03 16:12:55 +00:00
|
|
|
|
|
|
|
Handle<Script> script() { return info_->script(); }
|
|
|
|
bool is_eval() { return info_->is_eval(); }
|
|
|
|
FunctionLiteral* function() { return info_->function(); }
|
|
|
|
Scope* scope() { return info_->scope(); }
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
static Register result_register();
|
2009-12-16 09:51:07 +00:00
|
|
|
static Register context_register();
|
|
|
|
|
|
|
|
// Set fields in the stack frame. Offsets are the frame pointer relative
|
|
|
|
// offsets defined in, e.g., StandardFrameConstants.
|
|
|
|
void StoreToFrameField(int frame_offset, Register value);
|
|
|
|
|
|
|
|
// Load a value from the current context. Indices are defined as an enum
|
|
|
|
// in v8::internal::Context.
|
|
|
|
void LoadContextField(Register dst, int context_index);
|
2009-12-10 14:06:08 +00:00
|
|
|
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
// AST node visit functions.
|
|
|
|
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
|
|
|
|
AST_NODE_LIST(DECLARE_VISIT)
|
|
|
|
#undef DECLARE_VISIT
|
2009-10-29 11:55:03 +00:00
|
|
|
// Handles the shortcutted logical binary operations in VisitBinaryOperation.
|
|
|
|
void EmitLogicalOperation(BinaryOperation* expr);
|
|
|
|
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
MacroAssembler* masm_;
|
2010-02-03 16:12:55 +00:00
|
|
|
CompilationInfo* info_;
|
2010-02-01 17:01:58 +00:00
|
|
|
|
2009-10-30 10:22:31 +00:00
|
|
|
Label return_label_;
|
2009-12-10 14:06:08 +00:00
|
|
|
NestedStatement* nesting_stack_;
|
2009-11-03 14:48:59 +00:00
|
|
|
int loop_depth_;
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
|
2010-01-19 12:41:02 +00:00
|
|
|
Expression::Context context_;
|
2010-01-18 14:04:55 +00:00
|
|
|
Location location_;
|
Initial implementation of top-level compilation of expressions in test
context. Test contexts are used for the left subexpressions of
short-circuited boolean operators. The right subexpressions inherit
their expression context from the binary op expression.
Compilation of short-circuited operations in effect and test context
is straightforward:
effect(e0 || e1) =
test(e0, L0, L1)
L1: effect(e1)
L0:
test(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test(e1, L0, L1)
Because the value of the first subexpression may be needed as the
value of the whole expression in a value context, we introduce a
hybrid value/test contest (the value is needed if true, but not if
false).
value(e0 || e1) =
value/test(e0, L0, L1)
L1: value(e1)
L0:
The compilation of value/test and test/value (introduced by boolean
AND) is:
value/test(e0 || e1, L0, L1) =
value/test(e0, L0, L2)
L2: value/test(e1, L0, L1)
test/value(e0 || e1, L0, L1) =
test(e0, L0, L2)
L2: test/value(e1, L0, L1)
Boolean AND is the dual. The AST nodes themselves (not their parents)
are responsible for producing the proper result (effect, value, or
control flow) depending on their context.
Review URL: http://codereview.chromium.org/339082
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-30 14:06:48 +00:00
|
|
|
Label* true_label_;
|
|
|
|
Label* false_label_;
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
friend class NestedStatement;
|
|
|
|
|
2010-01-20 15:51:03 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator);
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
};
|
|
|
|
|
Initial port of top-level code generator to ARM. For the constant
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
2009-10-15 12:42:16 +00:00
|
|
|
|
Initial infrastructure for fast compilation of top-level code. The
fast code generator is optimized for compilation time and code size.
Currently it is only implemented on IA32. It is potentially triggered
for any code in the global scope (including code eval'd in the global
scope). It performs a syntactic check and chooses to compile in fast
mode if the AST contains only supported constructs and matches some
other constraints.
Initially supported constructs are
* ExpressionStatement,
* ReturnStatement,
* VariableProxy (variable references) to parameters and
stack-allocated locals,
* Assignment with lhs a parameter or stack-allocated local, and
* Literal
This allows compilation of literals at the top level and not much
else.
All intermediate values are allocated to temporaries and the stack is
used for all temporaries. The extra memory traffic is a known issue.
The code generated for 'true' is:
0 push ebp
1 mov ebp,esp
3 push esi
4 push edi
5 push 0xf5cca135 ;; object: 0xf5cca135 <undefined>
10 cmp esp,[0x8277efc]
16 jnc 27 (0xf5cbbb1b)
22 call 0xf5cac960 ;; code: STUB, StackCheck, minor: 0
27 push 0xf5cca161 ;; object: 0xf5cca161 <true>
32 mov eax,[esp]
35 mov [ebp+0xf4],eax
38 pop eax
39 mov eax,[ebp+0xf4]
42 mov esp,ebp ;; js return
44 pop ebp
45 ret 0x4
48 mov eax,0xf5cca135 ;; object: 0xf5cca135 <undefined>
53 mov esp,ebp ;; js return
55 pop ebp
56 ret 0x4
Review URL: http://codereview.chromium.org/273050
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3067 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2009-10-14 19:30:50 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
2010-01-27 15:23:48 +00:00
|
|
|
#endif // V8_FULL_CODEGEN_H_
|