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

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

Issue 360011: Obey the flag --lazy in the toplevel code generator.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 1 month 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/fast-codegen.h ('k') | src/handles.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "codegen-inl.h" 30 #include "codegen-inl.h"
31 #include "compiler.h"
31 #include "fast-codegen.h" 32 #include "fast-codegen.h"
32 #include "stub-cache.h" 33 #include "stub-cache.h"
33 #include "debug.h" 34 #include "debug.h"
34 35
35 namespace v8 { 36 namespace v8 {
36 namespace internal { 37 namespace internal {
37 38
38 #define __ ACCESS_MASM(masm_) 39 #define __ ACCESS_MASM(masm_)
39 40
40 Handle<Code> FastCodeGenerator::MakeCode(FunctionLiteral* fun, 41 Handle<Code> FastCodeGenerator::MakeCode(FunctionLiteral* fun,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 return offset; 73 return offset;
73 } 74 }
74 75
75 76
76 void FastCodeGenerator::VisitDeclarations( 77 void FastCodeGenerator::VisitDeclarations(
77 ZoneList<Declaration*>* declarations) { 78 ZoneList<Declaration*>* declarations) {
78 Comment cmnt(masm_, "[ Declarations"); 79 Comment cmnt(masm_, "[ Declarations");
79 int length = declarations->length(); 80 int length = declarations->length();
80 int globals = 0; 81 int globals = 0;
81 for (int i = 0; i < length; i++) { 82 for (int i = 0; i < length; i++) {
82 Declaration* node = declarations->at(i); 83 Declaration* decl = declarations->at(i);
83 Variable* var = node->proxy()->var(); 84 Variable* var = decl->proxy()->var();
84 Slot* slot = var->slot(); 85 Slot* slot = var->slot();
85 86
86 // If it was not possible to allocate the variable at compile 87 // If it was not possible to allocate the variable at compile
87 // time, we need to "declare" it at runtime to make sure it 88 // time, we need to "declare" it at runtime to make sure it
88 // actually exists in the local context. 89 // actually exists in the local context.
89 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) { 90 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
90 UNREACHABLE(); 91 UNREACHABLE();
91 } else { 92 } else {
92 // Count global variables and functions for later processing 93 // Count global variables and functions for later processing
93 globals++; 94 globals++;
94 } 95 }
95 } 96 }
96 97
97 // Return in case of no declared global functions or variables. 98 // Return in case of no declared global functions or variables.
98 if (globals == 0) return; 99 if (globals == 0) return;
99 100
100 // Compute array of global variable and function declarations. 101 // Compute array of global variable and function declarations.
101 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED); 102 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
102 for (int j = 0, i = 0; i < length; i++) { 103 for (int j = 0, i = 0; i < length; i++) {
103 Declaration* node = declarations->at(i); 104 Declaration* decl = declarations->at(i);
104 Variable* var = node->proxy()->var(); 105 Variable* var = decl->proxy()->var();
105 Slot* slot = var->slot(); 106 Slot* slot = var->slot();
106 107
107 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { 108 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) {
108 array->set(j++, *(var->name())); 109 array->set(j++, *(var->name()));
109 if (node->fun() == NULL) { 110 if (decl->fun() == NULL) {
110 if (var->mode() == Variable::CONST) { 111 if (var->mode() == Variable::CONST) {
111 // In case this is const property use the hole. 112 // In case this is const property use the hole.
112 array->set_the_hole(j++); 113 array->set_the_hole(j++);
113 } else { 114 } else {
114 array->set_undefined(j++); 115 array->set_undefined(j++);
115 } 116 }
116 } else { 117 } else {
117 Handle<JSFunction> function = BuildBoilerplate(node->fun()); 118 Handle<JSFunction> function =
119 Compiler::BuildBoilerplate(decl->fun(), script_, this);
118 // Check for stack-overflow exception. 120 // Check for stack-overflow exception.
119 if (HasStackOverflow()) return; 121 if (HasStackOverflow()) return;
120 array->set(j++, *function); 122 array->set(j++, *function);
121 } 123 }
122 } 124 }
123 } 125 }
124 126
125 // Invoke the platform-dependent code generator to do the actual 127 // Invoke the platform-dependent code generator to do the actual
126 // declaration the global variables and functions. 128 // declaration the global variables and functions.
127 DeclareGlobals(array); 129 DeclareGlobals(array);
128 } 130 }
129 131
130 Handle<JSFunction> FastCodeGenerator::BuildBoilerplate(FunctionLiteral* fun) {
131 #ifdef DEBUG
132 // We should not try to compile the same function literal more than
133 // once.
134 fun->mark_as_compiled();
135 #endif
136
137 // Generate code
138 Handle<Code> code = CodeGenerator::ComputeLazyCompile(fun->num_parameters());
139 // Check for stack-overflow exception.
140 if (code.is_null()) {
141 SetStackOverflow();
142 return Handle<JSFunction>::null();
143 }
144
145 // Create a boilerplate function.
146 Handle<JSFunction> function =
147 Factory::NewFunctionBoilerplate(fun->name(),
148 fun->materialized_literal_count(),
149 code);
150 CodeGenerator::SetFunctionInfo(function, fun, false, script_);
151
152 #ifdef ENABLE_DEBUGGER_SUPPORT
153 // Notify debugger that a new function has been added.
154 Debugger::OnNewFunction(function);
155 #endif
156
157 // Set the expected number of properties for instances and return
158 // the resulting function.
159 SetExpectedNofPropertiesFromEstimate(function,
160 fun->expected_property_count());
161 return function;
162 }
163
164 132
165 void FastCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) { 133 void FastCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
166 if (FLAG_debug_info) { 134 if (FLAG_debug_info) {
167 CodeGenerator::RecordPositions(masm_, fun->start_position()); 135 CodeGenerator::RecordPositions(masm_, fun->start_position());
168 } 136 }
169 } 137 }
170 138
171 139
172 void FastCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { 140 void FastCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
173 if (FLAG_debug_info) { 141 if (FLAG_debug_info) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 478
511 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) { 479 void FastCodeGenerator::VisitThisFunction(ThisFunction* expr) {
512 UNREACHABLE(); 480 UNREACHABLE();
513 } 481 }
514 482
515 483
516 #undef __ 484 #undef __
517 485
518 486
519 } } // namespace v8::internal 487 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/fast-codegen.h ('k') | src/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698