Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: src/ia32/fast-codegen-ia32.cc

Issue 273050: Initial infrastructure for fast compilation of top-level code. The... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/codegen-ia32.h ('k') | src/v8-counters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "v8.h"
29
30 #include "codegen-inl.h"
31 #include "fast-codegen.h"
32 // #include "scopes.h"
33
34 namespace v8 {
35 namespace internal {
36
37 #define __ ACCESS_MASM(masm_)
38
39 // Generate code for a JS function. On entry to the function the receiver
40 // and arguments have been pushed on the stack left to right, with the
41 // return address on top of them. The actual argument count matches the
42 // formal parameter count expected by the function.
43 //
44 // The live registers are:
45 // o edi: the JS function object being called (ie, ourselves)
46 // o esi: our context
47 // o ebp: our caller's frame pointer
48 //
49 // The function builds a JS frame. Please see JavaScriptFrameConstants in
50 // frames-ia32.h for its layout.
51 void FastCodeGenerator::Generate(FunctionLiteral* fun) {
52 function_ = fun;
53
54 __ push(ebp); // Caller's frame pointer.
55 __ mov(ebp, esp);
56 __ push(esi); // Callee's context.
57 __ push(edi); // Callee's JS Function.
58
59 { Comment cmnt(masm_, "[ Allocate locals");
60 int locals_count = fun->scope()->num_stack_slots();
61 for (int i = 0; i < locals_count; i++) {
62 __ push(Immediate(Factory::undefined_value()));
63 }
64 }
65
66 { Comment cmnt(masm_, "[ Stack check");
67 Label ok;
68 ExternalReference stack_guard_limit =
69 ExternalReference::address_of_stack_guard_limit();
70 __ cmp(esp, Operand::StaticVariable(stack_guard_limit));
71 __ j(above_equal, &ok, taken);
72 StackCheckStub stub;
73 __ CallStub(&stub);
74 __ bind(&ok);
75 }
76
77 { Comment cmnt(masm_, "[ Body");
78 VisitStatements(fun->body());
79 }
80
81 { Comment cmnt(masm_, "[ return <undefined>;");
82 // Emit a 'return undefined' in case control fell off the end of the
83 // body.
84 __ mov(eax, Factory::undefined_value());
85 __ RecordJSReturn();
86 // Do not use the leave instruction here because it is too short to
87 // patch with the code required by the debugger.
88 __ mov(esp, ebp);
89 __ pop(ebp);
90 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize);
91 }
92 }
93
94
95 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
96 Comment cmnt(masm_, "[ ExpressionStatement");
97 Visit(stmt->expression());
98 __ pop(eax);
99 }
100
101
102 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
103 Comment cmnt(masm_, "[ ReturnStatement");
104 Visit(stmt->expression());
105 __ pop(eax);
106 __ RecordJSReturn();
107 // Do not use the leave instruction here because it is too short to
108 // patch with the code required by the debugger.
109 __ mov(esp, ebp);
110 __ pop(ebp);
111 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize);
112 }
113
114
115 void FastCodeGenerator::VisitSlot(Slot* expr) {
116 Comment cmnt(masm_, "[ Slot");
117 __ push(Operand(ebp, SlotOffset(expr)));
118 }
119
120
121 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) {
122 Comment cmnt(masm_, "[ VariableProxy");
123 Expression* rewrite = expr->var()->rewrite();
124 ASSERT(rewrite != NULL);
125 Visit(rewrite);
126 }
127
128
129 void FastCodeGenerator::VisitLiteral(Literal* expr) {
130 Comment cmnt(masm_, "[ Literal");
131 __ push(Immediate(expr->handle()));
132 }
133
134
135 void FastCodeGenerator::VisitAssignment(Assignment* expr) {
136 Comment cmnt(masm_, "[ Assignment");
137 ASSERT(expr->op() == Token::ASSIGN || expr->op() == Token::INIT_VAR);
138
139 Visit(expr->value());
140
141 Variable* var = expr->target()->AsVariableProxy()->AsVariable();
142 ASSERT(var != NULL && var->slot() != NULL);
143 __ mov(eax, Operand(esp, 0));
144 __ mov(Operand(ebp, SlotOffset(var->slot())), eax);
145 }
146
147
148 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.h ('k') | src/v8-counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698