2012-01-20 16:17:08 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
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
|
|
|
// 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"
|
|
|
|
|
2011-05-06 06:50:20 +00:00
|
|
|
#include "allocation.h"
|
2013-08-06 14:38:30 +00:00
|
|
|
#include "assert-scope.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 "ast.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
#include "code-stubs.h"
|
|
|
|
#include "codegen.h"
|
2010-05-19 07:32:32 +00:00
|
|
|
#include "compiler.h"
|
2013-01-04 12:48:18 +00:00
|
|
|
#include "data-flow.h"
|
2013-08-06 14:38:30 +00:00
|
|
|
#include "globals.h"
|
|
|
|
#include "objects.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
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2010-12-15 13:56:41 +00:00
|
|
|
// Forward declarations.
|
|
|
|
class JumpPatchSite;
|
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// AST node visitor which can tell whether a given statement will be breakable
|
|
|
|
// when the code is compiled by the full compiler in the debugger. This means
|
|
|
|
// that there will be an IC (load/store/call) in the code generated for the
|
|
|
|
// debugger to piggybag on.
|
|
|
|
class BreakableStatementChecker: public AstVisitor {
|
|
|
|
public:
|
2014-01-21 16:22:52 +00:00
|
|
|
explicit BreakableStatementChecker(Zone* zone) : is_breakable_(false) {
|
|
|
|
InitializeAstVisitor(zone);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
2010-06-08 12:04:49 +00:00
|
|
|
|
|
|
|
void Check(Statement* stmt);
|
|
|
|
void Check(Expression* stmt);
|
|
|
|
|
|
|
|
bool is_breakable() { return is_breakable_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// AST node visit functions.
|
|
|
|
#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
|
|
|
|
AST_NODE_LIST(DECLARE_VISIT)
|
|
|
|
#undef DECLARE_VISIT
|
|
|
|
|
|
|
|
bool is_breakable_;
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
|
2010-06-08 12:04:49 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BreakableStatementChecker);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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-12-07 11:31:57 +00:00
|
|
|
enum State {
|
|
|
|
NO_REGISTERS,
|
|
|
|
TOS_REG
|
|
|
|
};
|
|
|
|
|
2012-06-20 08:58:41 +00:00
|
|
|
FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info)
|
2011-03-21 11:57:59 +00:00
|
|
|
: masm_(masm),
|
2012-02-14 14:14:51 +00:00
|
|
|
info_(info),
|
|
|
|
scope_(info->scope()),
|
2009-12-10 14:06:08 +00:00
|
|
|
nesting_stack_(NULL),
|
2009-11-03 14:48:59 +00:00
|
|
|
loop_depth_(0),
|
2012-04-16 14:43:27 +00:00
|
|
|
globals_(NULL),
|
2010-12-07 11:31:57 +00:00
|
|
|
context_(NULL),
|
2012-02-14 14:14:51 +00:00
|
|
|
bailout_entries_(info->HasDeoptimizationSupport()
|
2012-06-20 08:58:41 +00:00
|
|
|
? info->function()->ast_node_count() : 0,
|
|
|
|
info->zone()),
|
2013-04-10 09:24:31 +00:00
|
|
|
back_edges_(2, info->zone()),
|
2012-02-14 14:14:51 +00:00
|
|
|
type_feedback_cells_(info->HasDeoptimizationSupport()
|
2012-06-20 08:58:41 +00:00
|
|
|
? info->function()->ast_node_count() : 0,
|
|
|
|
info->zone()),
|
2014-01-21 16:22:52 +00:00
|
|
|
ic_total_count_(0) {
|
2012-07-31 14:59:32 +00:00
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Initialize();
|
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-10-04 14:30:43 +00:00
|
|
|
static bool 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
|
|
|
|
2012-02-14 14:14:51 +00:00
|
|
|
// Encode state and pc-offset as a BitField<type, start, size>.
|
|
|
|
// Only use 30 bits because we encode the result as a smi.
|
|
|
|
class StateField : public BitField<State, 0, 1> { };
|
|
|
|
class PcField : public BitField<unsigned, 1, 30-1> { };
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
static const char* State2String(State state) {
|
|
|
|
switch (state) {
|
|
|
|
case NO_REGISTERS: return "NO_REGISTERS";
|
|
|
|
case TOS_REG: return "TOS_REG";
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 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
|
|
|
|
2012-07-25 14:27:14 +00:00
|
|
|
static const int kMaxBackEdgeWeight = 127;
|
|
|
|
|
2013-06-14 11:35:00 +00:00
|
|
|
// Platform-specific code size multiplier.
|
2012-07-25 14:27:14 +00:00
|
|
|
#if V8_TARGET_ARCH_IA32
|
2013-06-14 11:35:00 +00:00
|
|
|
static const int kCodeSizeMultiplier = 100;
|
2012-07-25 14:27:14 +00:00
|
|
|
#elif V8_TARGET_ARCH_X64
|
2013-06-14 11:35:00 +00:00
|
|
|
static const int kCodeSizeMultiplier = 162;
|
2012-07-25 14:27:14 +00:00
|
|
|
#elif V8_TARGET_ARCH_ARM
|
2013-06-14 11:35:00 +00:00
|
|
|
static const int kCodeSizeMultiplier = 142;
|
2012-07-25 14:27:14 +00:00
|
|
|
#elif V8_TARGET_ARCH_MIPS
|
2013-06-14 11:35:00 +00:00
|
|
|
static const int kCodeSizeMultiplier = 142;
|
2012-07-25 14:27:14 +00:00
|
|
|
#else
|
|
|
|
#error Unsupported target architecture.
|
|
|
|
#endif
|
|
|
|
|
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;
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
class TestContext;
|
2009-12-10 14:06:08 +00:00
|
|
|
|
|
|
|
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 bool IsContinueTarget(Statement* target) { return false; }
|
|
|
|
virtual bool IsBreakTarget(Statement* target) { return false; }
|
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
// Notify the statement that we are exiting it via break, continue, or
|
|
|
|
// return and give it a chance to generate cleanup code. Return the
|
|
|
|
// next outer statement in the nesting stack. We accumulate in
|
|
|
|
// *stack_depth the amount to drop the stack and in *context_length the
|
|
|
|
// number of context chain links to unwind as we traverse the nesting
|
|
|
|
// stack from an exit to its target.
|
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
|
|
|
|
return previous_;
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2012-01-20 16:17:08 +00:00
|
|
|
protected:
|
2009-12-10 14:06:08 +00:00
|
|
|
MacroAssembler* masm() { return codegen_->masm(); }
|
2011-06-07 07:17:46 +00:00
|
|
|
|
2010-01-20 15:51:03 +00:00
|
|
|
FullCodeGenerator* codegen_;
|
2009-12-10 14:06:08 +00:00
|
|
|
NestedStatement* previous_;
|
2012-01-20 16:17:08 +00:00
|
|
|
|
|
|
|
private:
|
2009-12-10 14:06:08 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(NestedStatement);
|
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// A breakable statement such as a block.
|
2009-12-10 14:06:08 +00:00
|
|
|
class Breakable : public NestedStatement {
|
|
|
|
public:
|
2011-08-19 09:54:08 +00:00
|
|
|
Breakable(FullCodeGenerator* codegen, BreakableStatement* statement)
|
|
|
|
: NestedStatement(codegen), statement_(statement) {
|
|
|
|
}
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~Breakable() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual Breakable* AsBreakable() { return this; }
|
2011-08-19 09:54:08 +00:00
|
|
|
virtual bool IsBreakTarget(Statement* target) {
|
|
|
|
return statement() == target;
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
|
|
|
BreakableStatement* statement() { return statement_; }
|
|
|
|
Label* break_label() { return &break_label_; }
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
private:
|
2011-08-19 09:54:08 +00:00
|
|
|
BreakableStatement* statement_;
|
|
|
|
Label break_label_;
|
2009-12-10 14:06:08 +00:00
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// An iteration statement such as a while, for, or do loop.
|
2009-12-10 14:06:08 +00:00
|
|
|
class Iteration : public Breakable {
|
|
|
|
public:
|
2011-08-19 09:54:08 +00:00
|
|
|
Iteration(FullCodeGenerator* codegen, IterationStatement* statement)
|
|
|
|
: Breakable(codegen, statement) {
|
|
|
|
}
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~Iteration() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual Iteration* AsIteration() { return this; }
|
2011-08-19 09:54:08 +00:00
|
|
|
virtual bool IsContinueTarget(Statement* target) {
|
|
|
|
return statement() == target;
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
|
|
|
Label* continue_label() { return &continue_label_; }
|
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
private:
|
2011-08-19 09:54:08 +00:00
|
|
|
Label continue_label_;
|
2009-12-10 14:06:08 +00:00
|
|
|
};
|
|
|
|
|
2011-09-06 21:48:32 +00:00
|
|
|
// A nested block statement.
|
|
|
|
class NestedBlock : public Breakable {
|
|
|
|
public:
|
|
|
|
NestedBlock(FullCodeGenerator* codegen, Block* block)
|
|
|
|
: Breakable(codegen, block) {
|
|
|
|
}
|
|
|
|
virtual ~NestedBlock() {}
|
|
|
|
|
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
|
2012-04-16 14:43:27 +00:00
|
|
|
if (statement()->AsBlock()->scope() != NULL) {
|
2011-09-06 21:48:32 +00:00
|
|
|
++(*context_length);
|
|
|
|
}
|
|
|
|
return previous_;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// The try block of a try/catch statement.
|
2009-12-10 14:06:08 +00:00
|
|
|
class TryCatch : public NestedStatement {
|
|
|
|
public:
|
2011-08-19 09:54:08 +00:00
|
|
|
explicit TryCatch(FullCodeGenerator* codegen) : NestedStatement(codegen) {
|
|
|
|
}
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~TryCatch() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length);
|
2009-12-10 14:06:08 +00:00
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// The try block of a try/finally statement.
|
2009-12-10 14:06:08 +00:00
|
|
|
class TryFinally : public NestedStatement {
|
|
|
|
public:
|
2011-08-19 09:54:08 +00:00
|
|
|
TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
|
|
|
|
: NestedStatement(codegen), finally_entry_(finally_entry) {
|
|
|
|
}
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~TryFinally() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length);
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
private:
|
|
|
|
Label* finally_entry_;
|
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// The finally block of a try/finally statement.
|
2009-12-10 14:06:08 +00:00
|
|
|
class Finally : public NestedStatement {
|
|
|
|
public:
|
2012-06-11 13:18:05 +00:00
|
|
|
static const int kElementCount = 5;
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2010-01-20 15:51:03 +00:00
|
|
|
explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~Finally() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
|
2011-08-19 09:54:08 +00:00
|
|
|
*stack_depth += kElementCount;
|
2011-08-12 10:52:49 +00:00
|
|
|
return previous_;
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// The body of a for/in loop.
|
2009-12-10 14:06:08 +00:00
|
|
|
class ForIn : public Iteration {
|
|
|
|
public:
|
2011-08-19 09:54:08 +00:00
|
|
|
static const int kElementCount = 5;
|
|
|
|
|
|
|
|
ForIn(FullCodeGenerator* codegen, ForInStatement* statement)
|
|
|
|
: Iteration(codegen, statement) {
|
|
|
|
}
|
2009-12-10 14:06:08 +00:00
|
|
|
virtual ~ForIn() {}
|
2011-08-19 09:54:08 +00:00
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
|
2011-08-19 09:54:08 +00:00
|
|
|
*stack_depth += kElementCount;
|
2011-08-12 10:52:49 +00:00
|
|
|
return previous_;
|
2009-12-10 14:06:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-08-12 10:52:49 +00:00
|
|
|
|
2011-08-19 09:54:08 +00:00
|
|
|
// The body of a with or catch.
|
2011-08-12 10:52:49 +00:00
|
|
|
class WithOrCatch : public NestedStatement {
|
|
|
|
public:
|
|
|
|
explicit WithOrCatch(FullCodeGenerator* codegen)
|
|
|
|
: NestedStatement(codegen) {
|
|
|
|
}
|
|
|
|
virtual ~WithOrCatch() {}
|
|
|
|
|
|
|
|
virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
|
|
|
|
++(*context_length);
|
|
|
|
return previous_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-09-14 14:52:53 +00:00
|
|
|
// Type of a member function that generates inline code for a native function.
|
2011-11-02 16:53:32 +00:00
|
|
|
typedef void (FullCodeGenerator::*InlineFunctionGenerator)(CallRuntime* expr);
|
2010-09-14 14:52:53 +00:00
|
|
|
|
|
|
|
static const InlineFunctionGenerator kInlineFunctionGenerators[];
|
|
|
|
|
2010-12-15 16:14:29 +00:00
|
|
|
// A platform-specific utility to overwrite the accumulator register
|
|
|
|
// with a GC-safe value.
|
|
|
|
void ClearAccumulator();
|
|
|
|
|
2010-08-25 11:10:05 +00:00
|
|
|
// Determine whether or not to inline the smi case for the given
|
|
|
|
// operation.
|
|
|
|
bool ShouldInlineSmiCase(Token::Value op);
|
|
|
|
|
2010-01-18 14:04:55 +00:00
|
|
|
// 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.
|
2011-06-16 06:37:49 +00:00
|
|
|
void DoTest(Expression* condition,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false,
|
|
|
|
Label* fall_through);
|
|
|
|
void DoTest(const TestContext* context);
|
2010-08-23 12:55:29 +00:00
|
|
|
|
|
|
|
// Helper function to split control flow and avoid a branch to the
|
|
|
|
// fall-through label if it is set up.
|
2013-06-28 15:34:48 +00:00
|
|
|
#if V8_TARGET_ARCH_MIPS
|
2010-08-23 12:55:29 +00:00
|
|
|
void Split(Condition cc,
|
2011-05-17 10:24:44 +00:00
|
|
|
Register lhs,
|
|
|
|
const Operand& rhs,
|
2010-08-23 12:55:29 +00:00
|
|
|
Label* if_true,
|
|
|
|
Label* if_false,
|
|
|
|
Label* fall_through);
|
2011-05-17 10:24:44 +00:00
|
|
|
#else // All non-mips arch.
|
|
|
|
void Split(Condition cc,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false,
|
|
|
|
Label* fall_through);
|
|
|
|
#endif // V8_TARGET_ARCH_MIPS
|
2010-01-18 14:04:55 +00:00
|
|
|
|
2011-09-07 11:02:31 +00:00
|
|
|
// Load the value of a known (PARAMETER, LOCAL, or CONTEXT) variable into
|
|
|
|
// a register. Emits a context chain walk if if necessary (so does
|
|
|
|
// SetVar) so avoid calling both on the same variable.
|
|
|
|
void GetVar(Register destination, Variable* var);
|
|
|
|
|
|
|
|
// Assign to a known (PARAMETER, LOCAL, or CONTEXT) variable. If it's in
|
|
|
|
// the context, the write barrier will be emitted and source, scratch0,
|
|
|
|
// scratch1 will be clobbered. Emits a context chain walk if if necessary
|
|
|
|
// (so does GetVar) so avoid calling both on the same variable.
|
|
|
|
void SetVar(Variable* var,
|
|
|
|
Register source,
|
|
|
|
Register scratch0,
|
|
|
|
Register scratch1);
|
|
|
|
|
|
|
|
// An operand used to read/write a stack-allocated (PARAMETER or LOCAL)
|
|
|
|
// variable. Writing does not need the write barrier.
|
|
|
|
MemOperand StackOperand(Variable* var);
|
|
|
|
|
|
|
|
// An operand used to read/write a known (PARAMETER, LOCAL, or CONTEXT)
|
|
|
|
// variable. May emit code to traverse the context chain, loading the
|
|
|
|
// found context into the scratch register. Writing to this operand will
|
|
|
|
// need the write barrier if location is CONTEXT.
|
|
|
|
MemOperand VarOperand(Variable* var, Register scratch);
|
2009-10-27 13:38:57 +00:00
|
|
|
|
2010-01-19 12:41:02 +00:00
|
|
|
void VisitForEffect(Expression* expr) {
|
2010-09-23 09:22:45 +00:00
|
|
|
EffectContext context(this);
|
2011-11-02 16:53:32 +00:00
|
|
|
Visit(expr);
|
|
|
|
PrepareForBailout(expr, NO_REGISTERS);
|
2010-09-23 09:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisitForAccumulatorValue(Expression* expr) {
|
|
|
|
AccumulatorValueContext context(this);
|
2011-11-02 16:53:32 +00:00
|
|
|
Visit(expr);
|
|
|
|
PrepareForBailout(expr, TOS_REG);
|
2010-01-19 12:41:02 +00:00
|
|
|
}
|
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
void VisitForStackValue(Expression* expr) {
|
|
|
|
StackValueContext context(this);
|
2011-11-02 16:53:32 +00:00
|
|
|
Visit(expr);
|
|
|
|
PrepareForBailout(expr, NO_REGISTERS);
|
2010-01-18 14:04:55 +00:00
|
|
|
}
|
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-08-25 08:57:21 +00:00
|
|
|
void VisitForControl(Expression* expr,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false,
|
|
|
|
Label* fall_through) {
|
2011-06-16 06:37:49 +00:00
|
|
|
TestContext context(this, expr, if_true, if_false, fall_through);
|
2011-11-02 16:53:32 +00:00
|
|
|
Visit(expr);
|
|
|
|
// For test contexts, we prepare for bailout before branching, not at
|
|
|
|
// the end of the entire expression. This happens as part of visiting
|
|
|
|
// the expression.
|
2010-01-19 12:41:02 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 16:53:32 +00:00
|
|
|
void VisitInDuplicateContext(Expression* expr);
|
|
|
|
|
2009-10-21 09:17:39 +00:00
|
|
|
void VisitDeclarations(ZoneList<Declaration*>* declarations);
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
void DeclareModules(Handle<FixedArray> descriptions);
|
2009-10-21 09:17:39 +00:00
|
|
|
void DeclareGlobals(Handle<FixedArray> pairs);
|
2011-09-01 11:57:02 +00:00
|
|
|
int DeclareGlobalsFlags();
|
2009-10-21 09:17:39 +00:00
|
|
|
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
// Generate code to allocate all (including nested) modules and contexts.
|
|
|
|
// Because of recursive linking and the presence of module alias declarations,
|
|
|
|
// this has to be a separate pass _before_ populating or executing any module.
|
|
|
|
void AllocateModules(ZoneList<Declaration*>* declarations);
|
|
|
|
|
2013-06-12 11:02:51 +00:00
|
|
|
// Generate code to create an iterator result object. The "value" property is
|
|
|
|
// set to a value popped from the stack, and "done" is set according to the
|
|
|
|
// argument. The result object is left in the result register.
|
|
|
|
void EmitCreateIteratorResult(bool done);
|
2013-05-07 08:46:42 +00:00
|
|
|
|
2010-08-24 11:41:26 +00:00
|
|
|
// Try to perform a comparison as a fast inlined literal compare if
|
|
|
|
// the operands allow it. Returns true if the compare operations
|
|
|
|
// has been matched and all code generated; false otherwise.
|
2011-09-19 14:50:33 +00:00
|
|
|
bool TryLiteralCompare(CompareOperation* compare);
|
2010-08-24 11:41:26 +00:00
|
|
|
|
2011-06-24 14:30:10 +00:00
|
|
|
// Platform-specific code for comparing the type of a value with
|
|
|
|
// a given literal string.
|
2011-11-02 16:53:32 +00:00
|
|
|
void EmitLiteralCompareTypeof(Expression* expr,
|
|
|
|
Expression* sub_expr,
|
|
|
|
Handle<String> check);
|
2011-09-19 14:50:33 +00:00
|
|
|
|
|
|
|
// Platform-specific code for equality comparison with a nil-like value.
|
|
|
|
void EmitLiteralCompareNil(CompareOperation* expr,
|
|
|
|
Expression* sub_expr,
|
|
|
|
NilValue nil);
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Bailout support.
|
2011-05-31 09:34:37 +00:00
|
|
|
void PrepareForBailout(Expression* node, State state);
|
2012-08-06 14:13:09 +00:00
|
|
|
void PrepareForBailoutForId(BailoutId id, State state);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
// Cache cell support. This associates AST ids with global property cells
|
|
|
|
// that will be cleared during GC and collected by the type-feedback oracle.
|
2013-06-12 15:03:44 +00:00
|
|
|
void RecordTypeFeedbackCell(TypeFeedbackId id, Handle<Cell> cell);
|
2012-01-27 13:03:19 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Record a call's return site offset, used to rebuild the frame if the
|
|
|
|
// called function was inlined at the site.
|
|
|
|
void RecordJSReturnSite(Call* call);
|
|
|
|
|
|
|
|
// Prepare for bailout before a test (or compare) and branch. If
|
|
|
|
// should_normalize, then the following comparison will not handle the
|
|
|
|
// canonical JS true value so we will insert a (dead) test against true at
|
|
|
|
// the actual bailout target from the optimized code. If not
|
|
|
|
// should_normalize, the true and false labels are ignored.
|
2011-11-02 16:53:32 +00:00
|
|
|
void PrepareForBailoutBeforeSplit(Expression* expr,
|
2010-12-07 11:31:57 +00:00
|
|
|
bool should_normalize,
|
|
|
|
Label* if_true,
|
|
|
|
Label* if_false);
|
|
|
|
|
2012-04-16 11:48:20 +00:00
|
|
|
// If enabled, emit debug code for checking that the current context is
|
|
|
|
// neither a with nor a catch context.
|
|
|
|
void EmitDebugCheckDeclarationContext(Variable* variable);
|
2010-05-19 07:32:32 +00:00
|
|
|
|
2012-02-14 14:00:31 +00:00
|
|
|
// This is meant to be called at loop back edges, |back_edge_target| is
|
|
|
|
// the jump target of the back edge and is used to approximate the amount
|
|
|
|
// of code inside the loop.
|
2012-12-07 08:55:06 +00:00
|
|
|
void EmitBackEdgeBookkeeping(IterationStatement* stmt,
|
|
|
|
Label* back_edge_target);
|
|
|
|
// Record the OSR AST id corresponding to a back edge in the code.
|
|
|
|
void RecordBackEdge(BailoutId osr_ast_id);
|
2013-04-10 09:24:31 +00:00
|
|
|
// Emit a table of back edge ids, pcs and loop depths into the code stream.
|
|
|
|
// Return the offset of the start of the table.
|
|
|
|
unsigned EmitBackEdgeTable();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-03-09 16:23:06 +00:00
|
|
|
void EmitProfilingCounterDecrement(int delta);
|
|
|
|
void EmitProfilingCounterReset();
|
|
|
|
|
2013-06-12 11:02:51 +00:00
|
|
|
// Emit code to pop values from the stack associated with nested statements
|
|
|
|
// like try/catch, try/finally, etc, running the finallies and unwinding the
|
|
|
|
// handlers as needed.
|
|
|
|
void EmitUnwindBeforeReturn();
|
|
|
|
|
2009-11-04 14:11:39 +00:00
|
|
|
// Platform-specific return sequence
|
2010-06-10 09:02:16 +00:00
|
|
|
void EmitReturnSequence();
|
2009-11-04 14:11:39 +00:00
|
|
|
|
|
|
|
// Platform-specific code sequences for calls
|
2014-01-15 09:05:21 +00:00
|
|
|
void EmitCallWithStub(Call* expr);
|
2014-01-07 14:14:34 +00:00
|
|
|
void EmitCallWithIC(Call* expr, Handle<Object> name, ContextualMode mode);
|
2011-05-24 14:01:36 +00:00
|
|
|
void EmitKeyedCallWithIC(Call* expr, Expression* key);
|
2009-10-30 10:22:31 +00:00
|
|
|
|
2010-05-19 07:32:32 +00:00
|
|
|
// Platform-specific code for inline runtime calls.
|
2010-09-14 14:52:53 +00:00
|
|
|
InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id);
|
|
|
|
|
2010-05-19 07:32:32 +00:00
|
|
|
void EmitInlineRuntimeCall(CallRuntime* expr);
|
2010-08-20 09:37:22 +00:00
|
|
|
|
|
|
|
#define EMIT_INLINE_RUNTIME_CALL(name, x, y) \
|
2011-11-02 16:53:32 +00:00
|
|
|
void Emit##name(CallRuntime* expr);
|
2010-09-14 14:52:53 +00:00
|
|
|
INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL)
|
2010-08-20 09:37:22 +00:00
|
|
|
INLINE_RUNTIME_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL)
|
|
|
|
#undef EMIT_INLINE_RUNTIME_CALL
|
2010-05-19 07:32:32 +00:00
|
|
|
|
2013-04-24 13:00:16 +00:00
|
|
|
// Platform-specific code for resuming generators.
|
|
|
|
void EmitGeneratorResume(Expression *generator,
|
|
|
|
Expression *value,
|
|
|
|
JSGeneratorObject::ResumeMode resume_mode);
|
|
|
|
|
2009-12-11 16:09:16 +00:00
|
|
|
// Platform-specific code for loading variables.
|
2011-09-07 11:02:31 +00:00
|
|
|
void EmitLoadGlobalCheckExtensions(Variable* var,
|
|
|
|
TypeofState typeof_state,
|
|
|
|
Label* slow);
|
|
|
|
MemOperand ContextSlotOperandCheckExtensions(Variable* var, Label* slow);
|
|
|
|
void EmitDynamicLookupFastCase(Variable* var,
|
|
|
|
TypeofState typeof_state,
|
|
|
|
Label* slow,
|
|
|
|
Label* done);
|
2011-07-11 15:20:17 +00:00
|
|
|
void EmitVariableLoad(VariableProxy* proxy);
|
2009-12-11 16:09:16 +00:00
|
|
|
|
2012-03-15 07:13:46 +00:00
|
|
|
void EmitAccessor(Expression* expression);
|
|
|
|
|
2011-03-01 15:34:23 +00:00
|
|
|
// Expects the arguments and the function already pushed.
|
2011-10-31 09:38:52 +00:00
|
|
|
void EmitResolvePossiblyDirectEval(int arg_count);
|
2011-03-01 15:34:23 +00:00
|
|
|
|
2010-05-19 07:32:32 +00:00
|
|
|
// Platform-specific support for allocating a new closure based on
|
|
|
|
// the given function info.
|
2010-11-22 09:57:21 +00:00
|
|
|
void EmitNewClosure(Handle<SharedFunctionInfo> info, bool pretenure);
|
2010-05-19 07:32:32 +00:00
|
|
|
|
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.
|
2011-04-27 15:02:59 +00:00
|
|
|
void EmitBinaryOp(BinaryOperation* expr,
|
|
|
|
Token::Value op,
|
2010-08-25 11:10:05 +00:00
|
|
|
OverwriteMode mode);
|
2009-12-11 16:09:16 +00:00
|
|
|
|
2010-08-26 08:50:38 +00:00
|
|
|
// Helper functions for generating inlined smi code for certain
|
|
|
|
// binary operations.
|
2011-04-27 15:02:59 +00:00
|
|
|
void EmitInlineSmiBinaryOp(BinaryOperation* expr,
|
2010-08-26 08:50:38 +00:00
|
|
|
Token::Value op,
|
|
|
|
OverwriteMode mode,
|
|
|
|
Expression* left,
|
2011-03-01 10:58:43 +00:00
|
|
|
Expression* right);
|
2010-08-26 08:50:38 +00:00
|
|
|
|
2010-05-19 07:32:32 +00:00
|
|
|
// Assign to the given expression as if via '='. The right-hand-side value
|
|
|
|
// is expected in the accumulator.
|
2012-02-22 12:47:42 +00:00
|
|
|
void EmitAssignment(Expression* expr);
|
2010-05-19 07:32:32 +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-05-19 07:32:32 +00:00
|
|
|
void EmitVariableAssignment(Variable* var,
|
2010-09-23 09:22:45 +00:00
|
|
|
Token::Value op);
|
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
|
|
|
|
2012-02-20 12:57:23 +00:00
|
|
|
void CallIC(Handle<Code> code,
|
2014-01-07 14:14:34 +00:00
|
|
|
ContextualMode mode = NOT_CONTEXTUAL,
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId id = TypeFeedbackId::None());
|
2012-02-20 12:57:23 +00:00
|
|
|
|
2014-01-07 14:14:34 +00:00
|
|
|
void CallLoadIC(ContextualMode mode,
|
|
|
|
TypeFeedbackId id = TypeFeedbackId::None());
|
|
|
|
void CallStoreIC(ContextualMode mode,
|
|
|
|
TypeFeedbackId id = TypeFeedbackId::None());
|
|
|
|
|
2009-10-15 15:27:37 +00:00
|
|
|
void SetFunctionPosition(FunctionLiteral* fun);
|
|
|
|
void SetReturnPosition(FunctionLiteral* fun);
|
|
|
|
void SetStatementPosition(Statement* stmt);
|
2013-10-14 09:41:41 +00:00
|
|
|
void SetExpressionPosition(Expression* expr);
|
2010-01-14 17:22:59 +00:00
|
|
|
void SetStatementPosition(int pos);
|
2010-11-30 13:17:36 +00:00
|
|
|
void SetSourcePosition(int pos);
|
2009-10-15 15:27:37 +00:00
|
|
|
|
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
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
class ExpressionContext;
|
|
|
|
const ExpressionContext* context() { return context_; }
|
|
|
|
void set_new_context(const ExpressionContext* context) { context_ = context; }
|
|
|
|
|
2010-02-03 16:12:55 +00:00
|
|
|
Handle<Script> script() { return info_->script(); }
|
|
|
|
bool is_eval() { return info_->is_eval(); }
|
2011-09-01 11:57:02 +00:00
|
|
|
bool is_native() { return info_->is_native(); }
|
2012-04-16 11:48:20 +00:00
|
|
|
bool is_classic_mode() { return language_mode() == CLASSIC_MODE; }
|
2014-01-07 14:14:34 +00:00
|
|
|
StrictModeFlag strict_mode() {
|
|
|
|
return is_classic_mode() ? kNonStrictMode : kStrictMode;
|
|
|
|
}
|
2012-04-16 11:48:20 +00:00
|
|
|
LanguageMode language_mode() { return function()->language_mode(); }
|
2010-02-03 16:12:55 +00:00
|
|
|
FunctionLiteral* function() { return info_->function(); }
|
2011-06-30 14:37:55 +00:00
|
|
|
Scope* scope() { return scope_; }
|
2010-02-03 16:12:55 +00:00
|
|
|
|
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
|
|
|
|
2011-06-29 07:41:42 +00:00
|
|
|
// Push the function argument for the runtime functions PushWithContext
|
|
|
|
// and PushCatchContext.
|
|
|
|
void PushFunctionArgumentForContextAllocation();
|
|
|
|
|
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
|
2011-04-28 17:49:55 +00:00
|
|
|
|
2011-05-31 14:37:34 +00:00
|
|
|
void VisitComma(BinaryOperation* expr);
|
|
|
|
void VisitLogicalExpression(BinaryOperation* expr);
|
|
|
|
void VisitArithmeticExpression(BinaryOperation* expr);
|
2010-08-24 11:41:26 +00:00
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
void VisitForTypeofValue(Expression* expr);
|
2009-10-29 11:55:03 +00:00
|
|
|
|
2012-02-20 12:57:23 +00:00
|
|
|
void Generate();
|
|
|
|
void PopulateDeoptimizationData(Handle<Code> code);
|
|
|
|
void PopulateTypeFeedbackInfo(Handle<Code> code);
|
|
|
|
void PopulateTypeFeedbackCells(Handle<Code> code);
|
|
|
|
|
|
|
|
Handle<FixedArray> handler_table() { return handler_table_; }
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
struct BailoutEntry {
|
2012-08-06 14:13:09 +00:00
|
|
|
BailoutId id;
|
2010-12-07 11:31:57 +00:00
|
|
|
unsigned pc_and_state;
|
|
|
|
};
|
2010-02-01 17:01:58 +00:00
|
|
|
|
2013-04-10 09:24:31 +00:00
|
|
|
struct BackEdgeEntry {
|
|
|
|
BailoutId id;
|
|
|
|
unsigned pc;
|
2013-07-19 14:46:23 +00:00
|
|
|
uint32_t loop_depth;
|
2013-04-10 09:24:31 +00:00
|
|
|
};
|
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
struct TypeFeedbackCellEntry {
|
2012-08-06 14:13:09 +00:00
|
|
|
TypeFeedbackId ast_id;
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> cell;
|
2012-01-27 13:03:19 +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
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
class ExpressionContext BASE_EMBEDDED {
|
2010-09-23 09:22:45 +00:00
|
|
|
public:
|
|
|
|
explicit ExpressionContext(FullCodeGenerator* codegen)
|
|
|
|
: masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) {
|
|
|
|
codegen->set_new_context(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ExpressionContext() {
|
|
|
|
codegen_->set_new_context(old_);
|
|
|
|
}
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
Isolate* isolate() const { return codegen_->isolate(); }
|
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
// Convert constant control flow (true or false) to the result expected for
|
|
|
|
// this expression context.
|
|
|
|
virtual void Plug(bool flag) const = 0;
|
|
|
|
|
2011-09-07 11:02:31 +00:00
|
|
|
// Emit code to convert a pure value (in a register, known variable
|
|
|
|
// location, as a literal, or on top of the stack) into the result
|
|
|
|
// expected according to this expression context.
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Register reg) const = 0;
|
2011-09-07 11:02:31 +00:00
|
|
|
virtual void Plug(Variable* var) const = 0;
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Handle<Object> lit) const = 0;
|
|
|
|
virtual void Plug(Heap::RootListIndex index) const = 0;
|
|
|
|
virtual void PlugTOS() const = 0;
|
|
|
|
|
|
|
|
// Emit code to convert pure control flow to a pair of unbound labels into
|
|
|
|
// the result expected according to this expression context. The
|
2010-12-07 11:31:57 +00:00
|
|
|
// implementation will bind both labels unless it's a TestContext, which
|
|
|
|
// won't bind them at this point.
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Label* materialize_true,
|
|
|
|
Label* materialize_false) const = 0;
|
|
|
|
|
|
|
|
// Emit code to discard count elements from the top of stack, then convert
|
|
|
|
// a pure value into the result expected according to this expression
|
|
|
|
// context.
|
|
|
|
virtual void DropAndPlug(int count, Register reg) const = 0;
|
|
|
|
|
|
|
|
// Set up branch labels for a test expression. The three Label** parameters
|
|
|
|
// are output parameters.
|
|
|
|
virtual void PrepareTest(Label* materialize_true,
|
|
|
|
Label* materialize_false,
|
|
|
|
Label** if_true,
|
|
|
|
Label** if_false,
|
|
|
|
Label** fall_through) const = 0;
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Returns true if we are evaluating only for side effects (i.e. if the
|
|
|
|
// result will be discarded).
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual bool IsEffect() const { return false; }
|
|
|
|
|
2011-05-31 14:37:34 +00:00
|
|
|
// Returns true if we are evaluating for the value (in accu/on stack).
|
|
|
|
virtual bool IsAccumulatorValue() const { return false; }
|
|
|
|
virtual bool IsStackValue() const { return false; }
|
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
// Returns true if we are branching on the value rather than materializing
|
2010-12-07 11:31:57 +00:00
|
|
|
// it. Only used for asserts.
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual bool IsTest() const { return false; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
FullCodeGenerator* codegen() const { return codegen_; }
|
|
|
|
MacroAssembler* masm() const { return masm_; }
|
|
|
|
MacroAssembler* masm_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const ExpressionContext* old_;
|
|
|
|
FullCodeGenerator* codegen_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AccumulatorValueContext : public ExpressionContext {
|
|
|
|
public:
|
|
|
|
explicit AccumulatorValueContext(FullCodeGenerator* codegen)
|
2011-11-01 12:20:46 +00:00
|
|
|
: ExpressionContext(codegen) { }
|
2010-09-23 09:22:45 +00:00
|
|
|
|
|
|
|
virtual void Plug(bool flag) const;
|
|
|
|
virtual void Plug(Register reg) const;
|
|
|
|
virtual void Plug(Label* materialize_true, Label* materialize_false) const;
|
2011-09-07 11:02:31 +00:00
|
|
|
virtual void Plug(Variable* var) const;
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Handle<Object> lit) const;
|
|
|
|
virtual void Plug(Heap::RootListIndex) const;
|
|
|
|
virtual void PlugTOS() const;
|
|
|
|
virtual void DropAndPlug(int count, Register reg) const;
|
|
|
|
virtual void PrepareTest(Label* materialize_true,
|
|
|
|
Label* materialize_false,
|
|
|
|
Label** if_true,
|
|
|
|
Label** if_false,
|
|
|
|
Label** fall_through) const;
|
2011-05-31 14:37:34 +00:00
|
|
|
virtual bool IsAccumulatorValue() const { return true; }
|
2010-09-23 09:22:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class StackValueContext : public ExpressionContext {
|
|
|
|
public:
|
|
|
|
explicit StackValueContext(FullCodeGenerator* codegen)
|
2011-11-01 12:20:46 +00:00
|
|
|
: ExpressionContext(codegen) { }
|
2010-09-23 09:22:45 +00:00
|
|
|
|
|
|
|
virtual void Plug(bool flag) const;
|
|
|
|
virtual void Plug(Register reg) const;
|
|
|
|
virtual void Plug(Label* materialize_true, Label* materialize_false) const;
|
2011-09-07 11:02:31 +00:00
|
|
|
virtual void Plug(Variable* var) const;
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Handle<Object> lit) const;
|
|
|
|
virtual void Plug(Heap::RootListIndex) const;
|
|
|
|
virtual void PlugTOS() const;
|
|
|
|
virtual void DropAndPlug(int count, Register reg) const;
|
|
|
|
virtual void PrepareTest(Label* materialize_true,
|
|
|
|
Label* materialize_false,
|
|
|
|
Label** if_true,
|
|
|
|
Label** if_false,
|
|
|
|
Label** fall_through) const;
|
2011-05-31 14:37:34 +00:00
|
|
|
virtual bool IsStackValue() const { return true; }
|
2010-09-23 09:22:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class TestContext : public ExpressionContext {
|
|
|
|
public:
|
2011-06-16 06:37:49 +00:00
|
|
|
TestContext(FullCodeGenerator* codegen,
|
|
|
|
Expression* condition,
|
|
|
|
Label* true_label,
|
|
|
|
Label* false_label,
|
|
|
|
Label* fall_through)
|
2010-09-23 09:22:45 +00:00
|
|
|
: ExpressionContext(codegen),
|
2011-06-16 06:37:49 +00:00
|
|
|
condition_(condition),
|
2010-09-23 09:22:45 +00:00
|
|
|
true_label_(true_label),
|
|
|
|
false_label_(false_label),
|
2011-11-01 12:20:46 +00:00
|
|
|
fall_through_(fall_through) { }
|
2010-09-23 09:22:45 +00:00
|
|
|
|
2010-10-08 13:07:55 +00:00
|
|
|
static const TestContext* cast(const ExpressionContext* context) {
|
|
|
|
ASSERT(context->IsTest());
|
|
|
|
return reinterpret_cast<const TestContext*>(context);
|
|
|
|
}
|
|
|
|
|
2011-06-16 06:37:49 +00:00
|
|
|
Expression* condition() const { return condition_; }
|
2010-10-08 13:07:55 +00:00
|
|
|
Label* true_label() const { return true_label_; }
|
|
|
|
Label* false_label() const { return false_label_; }
|
|
|
|
Label* fall_through() const { return fall_through_; }
|
|
|
|
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(bool flag) const;
|
|
|
|
virtual void Plug(Register reg) const;
|
|
|
|
virtual void Plug(Label* materialize_true, Label* materialize_false) const;
|
2011-09-07 11:02:31 +00:00
|
|
|
virtual void Plug(Variable* var) const;
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Handle<Object> lit) const;
|
|
|
|
virtual void Plug(Heap::RootListIndex) const;
|
|
|
|
virtual void PlugTOS() const;
|
|
|
|
virtual void DropAndPlug(int count, Register reg) const;
|
|
|
|
virtual void PrepareTest(Label* materialize_true,
|
|
|
|
Label* materialize_false,
|
|
|
|
Label** if_true,
|
|
|
|
Label** if_false,
|
|
|
|
Label** fall_through) const;
|
|
|
|
virtual bool IsTest() const { return true; }
|
|
|
|
|
|
|
|
private:
|
2011-06-16 06:37:49 +00:00
|
|
|
Expression* condition_;
|
2010-09-23 09:22:45 +00:00
|
|
|
Label* true_label_;
|
|
|
|
Label* false_label_;
|
|
|
|
Label* fall_through_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EffectContext : public ExpressionContext {
|
|
|
|
public:
|
|
|
|
explicit EffectContext(FullCodeGenerator* codegen)
|
2011-11-01 12:20:46 +00:00
|
|
|
: ExpressionContext(codegen) { }
|
2010-09-23 09:22:45 +00:00
|
|
|
|
|
|
|
virtual void Plug(bool flag) const;
|
|
|
|
virtual void Plug(Register reg) const;
|
|
|
|
virtual void Plug(Label* materialize_true, Label* materialize_false) const;
|
2011-09-07 11:02:31 +00:00
|
|
|
virtual void Plug(Variable* var) const;
|
2010-09-23 09:22:45 +00:00
|
|
|
virtual void Plug(Handle<Object> lit) const;
|
|
|
|
virtual void Plug(Heap::RootListIndex) const;
|
|
|
|
virtual void PlugTOS() const;
|
|
|
|
virtual void DropAndPlug(int count, Register reg) const;
|
|
|
|
virtual void PrepareTest(Label* materialize_true,
|
|
|
|
Label* materialize_false,
|
|
|
|
Label** if_true,
|
|
|
|
Label** if_false,
|
|
|
|
Label** fall_through) const;
|
|
|
|
virtual bool IsEffect() const { return true; }
|
|
|
|
};
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
MacroAssembler* masm_;
|
|
|
|
CompilationInfo* info_;
|
2011-06-30 14:37:55 +00:00
|
|
|
Scope* scope_;
|
2010-12-07 11:31:57 +00:00
|
|
|
Label return_label_;
|
|
|
|
NestedStatement* nesting_stack_;
|
|
|
|
int loop_depth_;
|
2012-04-16 14:43:27 +00:00
|
|
|
ZoneList<Handle<Object> >* globals_;
|
Get rid of static module allocation, do it in code.
Modules now have their own local scope, represented by their own context.
Module instance objects have an accessor for every export that forwards
access to the respective slot from the module's context. (Exports that are
modules themselves, however, are simple data properties.)
All modules have a _hosting_ scope/context, which (currently) is the
(innermost) enclosing global scope. To deal with recursion, nested modules
are hosted by the same scope as global ones.
For every (global or nested) module literal, the hosting context has an
internal slot that points directly to the respective module context. This
enables quick access to (statically resolved) module members by 2-dimensional
access through the hosting context. For example,
module A {
let x;
module B { let y; }
}
module C { let z; }
allocates contexts as follows:
[header| .A | .B | .C | A | C ] (global)
| | |
| | +-- [header| z ] (module)
| |
| +------- [header| y ] (module)
|
+------------ [header| x | B ] (module)
Here, .A, .B, .C are the internal slots pointing to the hosted module
contexts, whereas A, B, C hold the actual instance objects (note that every
module context also points to the respective instance object through its
extension slot in the header).
To deal with arbitrary recursion and aliases between modules,
they are created and initialized in several stages. Each stage applies to
all modules in the hosting global scope, including nested ones.
1. Allocate: for each module _literal_, allocate the module contexts and
respective instance object and wire them up. This happens in the
PushModuleContext runtime function, as generated by AllocateModules
(invoked by VisitDeclarations in the hosting scope).
2. Bind: for each module _declaration_ (i.e. literals as well as aliases),
assign the respective instance object to respective local variables. This
happens in VisitModuleDeclaration, and uses the instance objects created
in the previous stage.
For each module _literal_, this phase also constructs a module descriptor
for the next stage. This happens in VisitModuleLiteral.
3. Populate: invoke the DeclareModules runtime function to populate each
_instance_ object with accessors for it exports. This is generated by
DeclareModules (invoked by VisitDeclarations in the hosting scope again),
and uses the descriptors generated in the previous stage.
4. Initialize: execute the module bodies (and other code) in sequence. This
happens by the separate statements generated for module bodies. To reenter
the module scopes properly, the parser inserted ModuleStatements.
R=mstarzinger@chromium.org,svenpanne@chromium.org
BUG=
Review URL: https://codereview.chromium.org/11093074
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13033 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2012-11-22 10:25:22 +00:00
|
|
|
Handle<FixedArray> modules_;
|
|
|
|
int module_index_;
|
2010-09-23 09:22:45 +00:00
|
|
|
const ExpressionContext* context_;
|
2010-12-07 11:31:57 +00:00
|
|
|
ZoneList<BailoutEntry> bailout_entries_;
|
2013-01-04 12:48:18 +00:00
|
|
|
GrowableBitVector prepared_bailout_ids_;
|
2013-04-10 09:24:31 +00:00
|
|
|
ZoneList<BackEdgeEntry> back_edges_;
|
2012-01-27 13:03:19 +00:00
|
|
|
ZoneList<TypeFeedbackCellEntry> type_feedback_cells_;
|
2012-02-20 12:57:23 +00:00
|
|
|
int ic_total_count_;
|
2011-11-11 13:48:14 +00:00
|
|
|
Handle<FixedArray> handler_table_;
|
2013-06-12 15:03:44 +00:00
|
|
|
Handle<Cell> profiling_counter_;
|
2012-07-31 14:59:32 +00:00
|
|
|
bool generate_debug_code_;
|
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
|
|
|
|
2009-12-10 14:06:08 +00:00
|
|
|
friend class NestedStatement;
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
|
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
|
|
|
|
2012-03-15 07:13:46 +00:00
|
|
|
// A map from property names to getter/setter pairs allocated in the zone.
|
|
|
|
class AccessorTable: public TemplateHashMap<Literal,
|
|
|
|
ObjectLiteral::Accessors,
|
2012-06-04 14:42:58 +00:00
|
|
|
ZoneAllocationPolicy> {
|
2012-03-15 07:13:46 +00:00
|
|
|
public:
|
|
|
|
explicit AccessorTable(Zone* zone) :
|
2012-06-04 14:42:58 +00:00
|
|
|
TemplateHashMap<Literal, ObjectLiteral::Accessors,
|
2012-06-11 12:42:31 +00:00
|
|
|
ZoneAllocationPolicy>(Literal::Match,
|
|
|
|
ZoneAllocationPolicy(zone)),
|
2012-03-15 07:13:46 +00:00
|
|
|
zone_(zone) { }
|
|
|
|
|
|
|
|
Iterator lookup(Literal* literal) {
|
2012-06-11 12:42:31 +00:00
|
|
|
Iterator it = find(literal, true, ZoneAllocationPolicy(zone_));
|
2012-03-15 07:13:46 +00:00
|
|
|
if (it->second == NULL) it->second = new(zone_) ObjectLiteral::Accessors();
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Zone* zone_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-09-19 09:08:08 +00:00
|
|
|
class BackEdgeTable {
|
|
|
|
public:
|
|
|
|
BackEdgeTable(Code* code, DisallowHeapAllocation* required) {
|
|
|
|
ASSERT(code->kind() == Code::FUNCTION);
|
|
|
|
instruction_start_ = code->instruction_start();
|
|
|
|
Address table_address = instruction_start_ + code->back_edge_table_offset();
|
|
|
|
length_ = Memory::uint32_at(table_address);
|
|
|
|
start_ = table_address + kTableLengthSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t length() { return length_; }
|
|
|
|
|
|
|
|
BailoutId ast_id(uint32_t index) {
|
|
|
|
return BailoutId(static_cast<int>(
|
|
|
|
Memory::uint32_at(entry_at(index) + kAstIdOffset)));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t loop_depth(uint32_t index) {
|
|
|
|
return Memory::uint32_at(entry_at(index) + kLoopDepthOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t pc_offset(uint32_t index) {
|
|
|
|
return Memory::uint32_at(entry_at(index) + kPcOffsetOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
Address pc(uint32_t index) {
|
|
|
|
return instruction_start_ + pc_offset(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum BackEdgeState {
|
|
|
|
INTERRUPT,
|
2013-09-25 08:26:11 +00:00
|
|
|
ON_STACK_REPLACEMENT,
|
|
|
|
OSR_AFTER_STACK_CHECK
|
2013-09-19 09:08:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Patch all interrupts with allowed loop depth in the unoptimized code to
|
|
|
|
// unconditionally call replacement_code.
|
|
|
|
static void Patch(Isolate* isolate,
|
|
|
|
Code* unoptimized_code);
|
|
|
|
|
2013-09-25 08:26:11 +00:00
|
|
|
// Patch the back edge to the target state, provided the correct callee.
|
2013-09-19 09:08:08 +00:00
|
|
|
static void PatchAt(Code* unoptimized_code,
|
2013-09-25 08:26:11 +00:00
|
|
|
Address pc,
|
|
|
|
BackEdgeState target_state,
|
2013-09-19 09:08:08 +00:00
|
|
|
Code* replacement_code);
|
|
|
|
|
2013-09-25 08:26:11 +00:00
|
|
|
// Change all patched back edges back to normal interrupts.
|
2013-09-19 09:08:08 +00:00
|
|
|
static void Revert(Isolate* isolate,
|
|
|
|
Code* unoptimized_code);
|
|
|
|
|
2013-09-25 08:26:11 +00:00
|
|
|
// Change a back edge patched for on-stack replacement to perform a
|
|
|
|
// stack check first.
|
2013-12-23 14:30:35 +00:00
|
|
|
static void AddStackCheck(Handle<Code> code, uint32_t pc_offset);
|
2013-09-19 09:08:08 +00:00
|
|
|
|
2013-12-23 14:30:35 +00:00
|
|
|
// Revert the patch by AddStackCheck.
|
|
|
|
static void RemoveStackCheck(Handle<Code> code, uint32_t pc_offset);
|
2013-09-25 08:26:11 +00:00
|
|
|
|
|
|
|
// Return the current patch state of the back edge.
|
2013-09-19 09:08:08 +00:00
|
|
|
static BackEdgeState GetBackEdgeState(Isolate* isolate,
|
|
|
|
Code* unoptimized_code,
|
|
|
|
Address pc_after);
|
|
|
|
|
2013-09-25 08:26:11 +00:00
|
|
|
#ifdef DEBUG
|
2013-09-19 09:08:08 +00:00
|
|
|
// Verify that all back edges of a certain loop depth are patched.
|
|
|
|
static bool Verify(Isolate* isolate,
|
|
|
|
Code* unoptimized_code,
|
|
|
|
int loop_nesting_level);
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
private:
|
|
|
|
Address entry_at(uint32_t index) {
|
|
|
|
ASSERT(index < length_);
|
|
|
|
return start_ + index * kEntrySize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int kTableLengthSize = kIntSize;
|
|
|
|
static const int kAstIdOffset = 0 * kIntSize;
|
|
|
|
static const int kPcOffsetOffset = 1 * kIntSize;
|
|
|
|
static const int kLoopDepthOffset = 2 * kIntSize;
|
|
|
|
static const int kEntrySize = 3 * kIntSize;
|
|
|
|
|
|
|
|
Address start_;
|
|
|
|
Address instruction_start_;
|
|
|
|
uint32_t length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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_
|