karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 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 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 30 | #include "codegen.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 31 | #include "compiler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 32 | #include "debug.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 33 | #include "full-codegen.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 34 | #include "liveedit.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 35 | #include "macro-assembler.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 36 | #include "prettyprinter.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 37 | #include "scopes.h" |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 38 | #include "scopeinfo.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 39 | #include "stub-cache.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 40 | |
| 41 | namespace v8 { |
| 42 | namespace internal { |
| 43 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 44 | void BreakableStatementChecker::Check(Statement* stmt) { |
| 45 | Visit(stmt); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | void BreakableStatementChecker::Check(Expression* expr) { |
| 50 | Visit(expr); |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void BreakableStatementChecker::VisitDeclaration(Declaration* decl) { |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void BreakableStatementChecker::VisitBlock(Block* stmt) { |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void BreakableStatementChecker::VisitExpressionStatement( |
| 63 | ExpressionStatement* stmt) { |
| 64 | // Check if expression is breakable. |
| 65 | Visit(stmt->expression()); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void BreakableStatementChecker::VisitEmptyStatement(EmptyStatement* stmt) { |
| 70 | } |
| 71 | |
| 72 | |
| 73 | void BreakableStatementChecker::VisitIfStatement(IfStatement* stmt) { |
| 74 | // If the condition is breakable the if statement is breakable. |
| 75 | Visit(stmt->condition()); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | void BreakableStatementChecker::VisitContinueStatement( |
| 80 | ContinueStatement* stmt) { |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void BreakableStatementChecker::VisitBreakStatement(BreakStatement* stmt) { |
| 85 | } |
| 86 | |
| 87 | |
| 88 | void BreakableStatementChecker::VisitReturnStatement(ReturnStatement* stmt) { |
| 89 | // Return is breakable if the expression is. |
| 90 | Visit(stmt->expression()); |
| 91 | } |
| 92 | |
| 93 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 94 | void BreakableStatementChecker::VisitWithStatement(WithStatement* stmt) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 95 | Visit(stmt->expression()); |
| 96 | } |
| 97 | |
| 98 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 99 | void BreakableStatementChecker::VisitSwitchStatement(SwitchStatement* stmt) { |
| 100 | // Switch statements breakable if the tag expression is. |
| 101 | Visit(stmt->tag()); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | void BreakableStatementChecker::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 106 | // Mark do while as breakable to avoid adding a break slot in front of it. |
| 107 | is_breakable_ = true; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) { |
| 112 | // Mark while statements breakable if the condition expression is. |
| 113 | Visit(stmt->cond()); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) { |
| 118 | // Mark for statements breakable if the condition expression is. |
| 119 | if (stmt->cond() != NULL) { |
| 120 | Visit(stmt->cond()); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) { |
| 126 | // Mark for in statements breakable if the enumerable expression is. |
| 127 | Visit(stmt->enumerable()); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | void BreakableStatementChecker::VisitTryCatchStatement( |
| 132 | TryCatchStatement* stmt) { |
| 133 | // Mark try catch as breakable to avoid adding a break slot in front of it. |
| 134 | is_breakable_ = true; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | void BreakableStatementChecker::VisitTryFinallyStatement( |
| 139 | TryFinallyStatement* stmt) { |
| 140 | // Mark try finally as breakable to avoid adding a break slot in front of it. |
| 141 | is_breakable_ = true; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void BreakableStatementChecker::VisitDebuggerStatement( |
| 146 | DebuggerStatement* stmt) { |
| 147 | // The debugger statement is breakable. |
| 148 | is_breakable_ = true; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 153 | } |
| 154 | |
| 155 | |
| 156 | void BreakableStatementChecker::VisitSharedFunctionInfoLiteral( |
| 157 | SharedFunctionInfoLiteral* expr) { |
| 158 | } |
| 159 | |
| 160 | |
| 161 | void BreakableStatementChecker::VisitConditional(Conditional* expr) { |
| 162 | } |
| 163 | |
| 164 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 165 | void BreakableStatementChecker::VisitVariableProxy(VariableProxy* expr) { |
| 166 | } |
| 167 | |
| 168 | |
| 169 | void BreakableStatementChecker::VisitLiteral(Literal* expr) { |
| 170 | } |
| 171 | |
| 172 | |
| 173 | void BreakableStatementChecker::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 174 | } |
| 175 | |
| 176 | |
| 177 | void BreakableStatementChecker::VisitObjectLiteral(ObjectLiteral* expr) { |
| 178 | } |
| 179 | |
| 180 | |
| 181 | void BreakableStatementChecker::VisitArrayLiteral(ArrayLiteral* expr) { |
| 182 | } |
| 183 | |
| 184 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 185 | void BreakableStatementChecker::VisitAssignment(Assignment* expr) { |
| 186 | // If assigning to a property (including a global property) the assignment is |
| 187 | // breakable. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 188 | VariableProxy* proxy = expr->target()->AsVariableProxy(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 189 | Property* prop = expr->target()->AsProperty(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 190 | if (prop != NULL || (proxy != NULL && proxy->var()->IsUnallocated())) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 191 | is_breakable_ = true; |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | // Otherwise the assignment is breakable if the assigned value is. |
| 196 | Visit(expr->value()); |
| 197 | } |
| 198 | |
| 199 | |
| 200 | void BreakableStatementChecker::VisitThrow(Throw* expr) { |
| 201 | // Throw is breakable if the expression is. |
| 202 | Visit(expr->exception()); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | void BreakableStatementChecker::VisitProperty(Property* expr) { |
| 207 | // Property load is breakable. |
| 208 | is_breakable_ = true; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | void BreakableStatementChecker::VisitCall(Call* expr) { |
| 213 | // Function calls both through IC and call stub are breakable. |
| 214 | is_breakable_ = true; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | void BreakableStatementChecker::VisitCallNew(CallNew* expr) { |
| 219 | // Function calls through new are breakable. |
| 220 | is_breakable_ = true; |
| 221 | } |
| 222 | |
| 223 | |
| 224 | void BreakableStatementChecker::VisitCallRuntime(CallRuntime* expr) { |
| 225 | } |
| 226 | |
| 227 | |
| 228 | void BreakableStatementChecker::VisitUnaryOperation(UnaryOperation* expr) { |
| 229 | Visit(expr->expression()); |
| 230 | } |
| 231 | |
| 232 | |
| 233 | void BreakableStatementChecker::VisitCountOperation(CountOperation* expr) { |
| 234 | Visit(expr->expression()); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | void BreakableStatementChecker::VisitBinaryOperation(BinaryOperation* expr) { |
| 239 | Visit(expr->left()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 240 | if (expr->op() != Token::AND && |
| 241 | expr->op() != Token::OR) { |
| 242 | Visit(expr->right()); |
| 243 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
| 247 | void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) { |
| 248 | Visit(expr->left()); |
| 249 | Visit(expr->right()); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) { |
| 254 | } |
| 255 | |
| 256 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 257 | #define __ ACCESS_MASM(masm()) |
| 258 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 259 | bool FullCodeGenerator::MakeCode(CompilationInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 260 | Isolate* isolate = info->isolate(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 261 | Handle<Script> script = info->script(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 262 | if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 263 | int len = String::cast(script->source())->length(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 264 | isolate->counters()->total_full_codegen_source_size()->Increment(len); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 265 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 266 | if (FLAG_trace_codegen) { |
| 267 | PrintF("Full Compiler - "); |
| 268 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 269 | CodeGenerator::MakeCodePrologue(info); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 270 | const int kInitialBufferSize = 4 * KB; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 271 | MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 272 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 273 | masm.positions_recorder()->StartGDBJITLineInfoRecording(); |
| 274 | #endif |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 275 | |
| 276 | FullCodeGenerator cgen(&masm); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 277 | cgen.Generate(info); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 278 | if (cgen.HasStackOverflow()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 279 | ASSERT(!isolate->has_pending_exception()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 280 | return false; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 281 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 282 | unsigned table_offset = cgen.EmitStackCheckTable(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 283 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 284 | Code::Flags flags = Code::ComputeFlags(Code::FUNCTION); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 285 | Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 286 | code->set_optimizable(info->IsOptimizable()); |
| 287 | cgen.PopulateDeoptimizationData(code); |
| 288 | code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame^] | 289 | #ifdef ENABLE_DEBUGGER_SUPPORT |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 290 | code->set_has_debug_break_slots( |
| 291 | info->isolate()->debugger()->IsDebuggerActive()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame^] | 292 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 293 | code->set_allow_osr_at_loop_nesting_level(0); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 294 | code->set_stack_check_table_offset(table_offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 295 | CodeGenerator::PrintCode(code, info); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 296 | info->SetCode(code); // may be an empty handle. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 297 | #ifdef ENABLE_GDB_JIT_INTERFACE |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 298 | if (FLAG_gdbjit && !code.is_null()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 299 | GDBJITLineInfo* lineinfo = |
| 300 | masm.positions_recorder()->DetachGDBJITLineInfo(); |
| 301 | |
| 302 | GDBJIT(RegisterDetailedLineInfo(*code, lineinfo)); |
| 303 | } |
| 304 | #endif |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 305 | return !code.is_null(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 309 | unsigned FullCodeGenerator::EmitStackCheckTable() { |
| 310 | // The stack check table consists of a length (in number of entries) |
| 311 | // field, and then a sequence of entries. Each entry is a pair of AST id |
| 312 | // and code-relative pc offset. |
| 313 | masm()->Align(kIntSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 314 | unsigned offset = masm()->pc_offset(); |
| 315 | unsigned length = stack_checks_.length(); |
| 316 | __ dd(length); |
| 317 | for (unsigned i = 0; i < length; ++i) { |
| 318 | __ dd(stack_checks_[i].id); |
| 319 | __ dd(stack_checks_[i].pc_and_state); |
| 320 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 321 | return offset; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
| 326 | // Fill in the deoptimization information. |
| 327 | ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
| 328 | if (!info_->HasDeoptimizationSupport()) return; |
| 329 | int length = bailout_entries_.length(); |
| 330 | Handle<DeoptimizationOutputData> data = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 331 | isolate()->factory()-> |
| 332 | NewDeoptimizationOutputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 333 | for (int i = 0; i < length; i++) { |
| 334 | data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id)); |
| 335 | data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); |
| 336 | } |
| 337 | code->set_deoptimization_data(*data); |
| 338 | } |
| 339 | |
| 340 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 341 | void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | PrepareForBailoutForId(node->id(), state); |
| 343 | } |
| 344 | |
| 345 | |
| 346 | void FullCodeGenerator::RecordJSReturnSite(Call* call) { |
| 347 | // We record the offset of the function return so we can rebuild the frame |
| 348 | // if the function was inlined, i.e., this is the return address in the |
| 349 | // inlined function's frame. |
| 350 | // |
| 351 | // The state is ignored. We defensively set it to TOS_REG, which is the |
| 352 | // real state of the unoptimized code at the return site. |
| 353 | PrepareForBailoutForId(call->ReturnId(), TOS_REG); |
| 354 | #ifdef DEBUG |
| 355 | // In debug builds, mark the return so we can verify that this function |
| 356 | // was called. |
| 357 | ASSERT(!call->return_is_recorded_); |
| 358 | call->return_is_recorded_ = true; |
| 359 | #endif |
| 360 | } |
| 361 | |
| 362 | |
| 363 | void FullCodeGenerator::PrepareForBailoutForId(int id, State state) { |
| 364 | // There's no need to prepare this code for bailouts from already optimized |
| 365 | // code or code that can't be optimized. |
| 366 | if (!FLAG_deopt || !info_->HasDeoptimizationSupport()) return; |
| 367 | unsigned pc_and_state = |
| 368 | StateField::encode(state) | PcField::encode(masm_->pc_offset()); |
| 369 | BailoutEntry entry = { id, pc_and_state }; |
| 370 | #ifdef DEBUG |
| 371 | // Assert that we don't have multiple bailout entries for the same node. |
| 372 | for (int i = 0; i < bailout_entries_.length(); i++) { |
| 373 | if (bailout_entries_.at(i).id == entry.id) { |
| 374 | AstPrinter printer; |
| 375 | PrintF("%s", printer.PrintProgram(info_->function())); |
| 376 | UNREACHABLE(); |
| 377 | } |
| 378 | } |
| 379 | #endif // DEBUG |
| 380 | bailout_entries_.Add(entry); |
| 381 | } |
| 382 | |
| 383 | |
| 384 | void FullCodeGenerator::RecordStackCheck(int ast_id) { |
| 385 | // The pc offset does not need to be encoded and packed together with a |
| 386 | // state. |
| 387 | BailoutEntry entry = { ast_id, masm_->pc_offset() }; |
| 388 | stack_checks_.Add(entry); |
| 389 | } |
| 390 | |
| 391 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 392 | bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 393 | // Inline smi case inside loops, but not division and modulo which |
| 394 | // are too complicated and take up too much space. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 395 | if (op == Token::DIV ||op == Token::MOD) return false; |
| 396 | if (FLAG_always_inline_smi_code) return true; |
| 397 | return loop_depth_ > 0; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 401 | void FullCodeGenerator::EffectContext::Plug(Register reg) const { |
| 402 | } |
| 403 | |
| 404 | |
| 405 | void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 406 | __ Move(result_register(), reg); |
| 407 | } |
| 408 | |
| 409 | |
| 410 | void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 411 | __ push(reg); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 412 | codegen()->increment_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | |
| 416 | void FullCodeGenerator::TestContext::Plug(Register reg) const { |
| 417 | // For simplicity we always test the accumulator register. |
| 418 | __ Move(result_register(), reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 419 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 420 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
| 424 | void FullCodeGenerator::EffectContext::PlugTOS() const { |
| 425 | __ Drop(1); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 426 | codegen()->decrement_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | |
| 430 | void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
| 431 | __ pop(result_register()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 432 | codegen()->decrement_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| 436 | void FullCodeGenerator::StackValueContext::PlugTOS() const { |
| 437 | } |
| 438 | |
| 439 | |
| 440 | void FullCodeGenerator::TestContext::PlugTOS() const { |
| 441 | // For simplicity we always test the accumulator register. |
| 442 | __ pop(result_register()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 443 | codegen()->decrement_stack_height(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 444 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 445 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
| 449 | void FullCodeGenerator::EffectContext::PrepareTest( |
| 450 | Label* materialize_true, |
| 451 | Label* materialize_false, |
| 452 | Label** if_true, |
| 453 | Label** if_false, |
| 454 | Label** fall_through) const { |
| 455 | // In an effect context, the true and the false case branch to the |
| 456 | // same label. |
| 457 | *if_true = *if_false = *fall_through = materialize_true; |
| 458 | } |
| 459 | |
| 460 | |
| 461 | void FullCodeGenerator::AccumulatorValueContext::PrepareTest( |
| 462 | Label* materialize_true, |
| 463 | Label* materialize_false, |
| 464 | Label** if_true, |
| 465 | Label** if_false, |
| 466 | Label** fall_through) const { |
| 467 | *if_true = *fall_through = materialize_true; |
| 468 | *if_false = materialize_false; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | void FullCodeGenerator::StackValueContext::PrepareTest( |
| 473 | Label* materialize_true, |
| 474 | Label* materialize_false, |
| 475 | Label** if_true, |
| 476 | Label** if_false, |
| 477 | Label** fall_through) const { |
| 478 | *if_true = *fall_through = materialize_true; |
| 479 | *if_false = materialize_false; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | void FullCodeGenerator::TestContext::PrepareTest( |
| 484 | Label* materialize_true, |
| 485 | Label* materialize_false, |
| 486 | Label** if_true, |
| 487 | Label** if_false, |
| 488 | Label** fall_through) const { |
| 489 | *if_true = true_label_; |
| 490 | *if_false = false_label_; |
| 491 | *fall_through = fall_through_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 495 | void FullCodeGenerator::DoTest(const TestContext* context) { |
| 496 | DoTest(context->condition(), |
| 497 | context->true_label(), |
| 498 | context->false_label(), |
| 499 | context->fall_through()); |
| 500 | } |
| 501 | |
| 502 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 503 | void FullCodeGenerator::VisitDeclarations( |
| 504 | ZoneList<Declaration*>* declarations) { |
| 505 | int length = declarations->length(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 506 | int global_count = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 507 | for (int i = 0; i < length; i++) { |
| 508 | Declaration* decl = declarations->at(i); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 509 | EmitDeclaration(decl->proxy(), decl->mode(), decl->fun(), &global_count); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 510 | } |
| 511 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 512 | // Batch declare global functions and variables. |
| 513 | if (global_count > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 514 | Handle<FixedArray> array = |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 515 | isolate()->factory()->NewFixedArray(2 * global_count, TENURED); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 516 | for (int j = 0, i = 0; i < length; i++) { |
| 517 | Declaration* decl = declarations->at(i); |
| 518 | Variable* var = decl->proxy()->var(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 519 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 520 | if (var->IsUnallocated()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 521 | array->set(j++, *(var->name())); |
| 522 | if (decl->fun() == NULL) { |
| 523 | if (var->mode() == Variable::CONST) { |
| 524 | // In case this is const property use the hole. |
| 525 | array->set_the_hole(j++); |
| 526 | } else { |
| 527 | array->set_undefined(j++); |
| 528 | } |
| 529 | } else { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 530 | Handle<SharedFunctionInfo> function = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 531 | Compiler::BuildFunctionInfo(decl->fun(), script()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 532 | // Check for stack-overflow exception. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 533 | if (function.is_null()) { |
| 534 | SetStackOverflow(); |
| 535 | return; |
| 536 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 537 | array->set(j++, *function); |
| 538 | } |
| 539 | } |
| 540 | } |
| 541 | // Invoke the platform-dependent code generator to do the actual |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 542 | // declaration the global functions and variables. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 543 | DeclareGlobals(array); |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 548 | int FullCodeGenerator::DeclareGlobalsFlags() { |
| 549 | int flags = 0; |
| 550 | if (is_eval()) flags |= kDeclareGlobalsEvalFlag; |
| 551 | if (is_strict_mode()) flags |= kDeclareGlobalsStrictModeFlag; |
| 552 | if (is_native()) flags |= kDeclareGlobalsNativeFlag; |
| 553 | return flags; |
| 554 | } |
| 555 | |
| 556 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 557 | void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 558 | CodeGenerator::RecordPositions(masm_, fun->start_position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | |
| 562 | void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 563 | CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
| 567 | void FullCodeGenerator::SetStatementPosition(Statement* stmt) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 568 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 569 | if (!isolate()->debugger()->IsDebuggerActive()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 570 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 571 | } else { |
| 572 | // Check if the statement will be breakable without adding a debug break |
| 573 | // slot. |
| 574 | BreakableStatementChecker checker; |
| 575 | checker.Check(stmt); |
| 576 | // Record the statement position right here if the statement is not |
| 577 | // breakable. For breakable statements the actual recording of the |
| 578 | // position will be postponed to the breakable code (typically an IC). |
| 579 | bool position_recorded = CodeGenerator::RecordPositions( |
| 580 | masm_, stmt->statement_pos(), !checker.is_breakable()); |
| 581 | // If the position recording did record a new position generate a debug |
| 582 | // break slot to make the statement breakable. |
| 583 | if (position_recorded) { |
| 584 | Debug::GenerateSlot(masm_); |
| 585 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 586 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 587 | #else |
| 588 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
| 589 | #endif |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | |
| 593 | void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 594 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 595 | if (!isolate()->debugger()->IsDebuggerActive()) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 596 | CodeGenerator::RecordPositions(masm_, pos); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 597 | } else { |
| 598 | // Check if the expression will be breakable without adding a debug break |
| 599 | // slot. |
| 600 | BreakableStatementChecker checker; |
| 601 | checker.Check(expr); |
| 602 | // Record a statement position right here if the expression is not |
| 603 | // breakable. For breakable expressions the actual recording of the |
| 604 | // position will be postponed to the breakable code (typically an IC). |
| 605 | // NOTE this will record a statement position for something which might |
| 606 | // not be a statement. As stepping in the debugger will only stop at |
| 607 | // statement positions this is used for e.g. the condition expression of |
| 608 | // a do while loop. |
| 609 | bool position_recorded = CodeGenerator::RecordPositions( |
| 610 | masm_, pos, !checker.is_breakable()); |
| 611 | // If the position recording did record a new position generate a debug |
| 612 | // break slot to make the statement breakable. |
| 613 | if (position_recorded) { |
| 614 | Debug::GenerateSlot(masm_); |
| 615 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 616 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 617 | #else |
| 618 | CodeGenerator::RecordPositions(masm_, pos); |
| 619 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | |
| 623 | void FullCodeGenerator::SetStatementPosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 624 | CodeGenerator::RecordPositions(masm_, pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 628 | void FullCodeGenerator::SetSourcePosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 629 | if (pos != RelocInfo::kNoPosition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 630 | masm_->positions_recorder()->RecordPosition(pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 631 | } |
| 632 | } |
| 633 | |
| 634 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 635 | // Lookup table for code generators for special runtime calls which are |
| 636 | // generated inline. |
| 637 | #define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \ |
| 638 | &FullCodeGenerator::Emit##Name, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 639 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 640 | const FullCodeGenerator::InlineFunctionGenerator |
| 641 | FullCodeGenerator::kInlineFunctionGenerators[] = { |
| 642 | INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 643 | INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 644 | }; |
| 645 | #undef INLINE_FUNCTION_GENERATOR_ADDRESS |
| 646 | |
| 647 | |
| 648 | FullCodeGenerator::InlineFunctionGenerator |
| 649 | FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 650 | int lookup_index = |
| 651 | static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction); |
| 652 | ASSERT(lookup_index >= 0); |
| 653 | ASSERT(static_cast<size_t>(lookup_index) < |
| 654 | ARRAY_SIZE(kInlineFunctionGenerators)); |
| 655 | return kInlineFunctionGenerators[lookup_index]; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | |
| 659 | void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) { |
| 660 | ZoneList<Expression*>* args = node->arguments(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 661 | const Runtime::Function* function = node->function(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 662 | ASSERT(function != NULL); |
| 663 | ASSERT(function->intrinsic_type == Runtime::INLINE); |
| 664 | InlineFunctionGenerator generator = |
| 665 | FindInlineFunctionGenerator(function->function_id); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 666 | ((*this).*(generator))(args); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
| 670 | void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 671 | switch (expr->op()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 672 | case Token::COMMA: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 673 | return VisitComma(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 674 | case Token::OR: |
| 675 | case Token::AND: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 676 | return VisitLogicalExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 677 | default: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 678 | return VisitArithmeticExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 679 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 683 | void FullCodeGenerator::VisitComma(BinaryOperation* expr) { |
| 684 | Comment cmnt(masm_, "[ Comma"); |
| 685 | VisitForEffect(expr->left()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 686 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 687 | VisitInCurrentContext(expr->right()); |
| 688 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 689 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 690 | |
| 691 | void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) { |
| 692 | bool is_logical_and = expr->op() == Token::AND; |
| 693 | Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR"); |
| 694 | Expression* left = expr->left(); |
| 695 | Expression* right = expr->right(); |
| 696 | int right_id = expr->RightId(); |
| 697 | Label done; |
| 698 | |
| 699 | if (context()->IsTest()) { |
| 700 | Label eval_right; |
| 701 | const TestContext* test = TestContext::cast(context()); |
| 702 | if (is_logical_and) { |
| 703 | VisitForControl(left, &eval_right, test->false_label(), &eval_right); |
| 704 | } else { |
| 705 | VisitForControl(left, test->true_label(), &eval_right, &eval_right); |
| 706 | } |
| 707 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 708 | __ bind(&eval_right); |
| 709 | ForwardBailoutToChild(expr); |
| 710 | |
| 711 | } else if (context()->IsAccumulatorValue()) { |
| 712 | VisitForAccumulatorValue(left); |
| 713 | // We want the value in the accumulator for the test, and on the stack in |
| 714 | // case we need it. |
| 715 | __ push(result_register()); |
| 716 | Label discard, restore; |
| 717 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 718 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 719 | DoTest(left, &discard, &restore, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 720 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 721 | DoTest(left, &restore, &discard, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 722 | } |
| 723 | __ bind(&restore); |
| 724 | __ pop(result_register()); |
| 725 | __ jmp(&done); |
| 726 | __ bind(&discard); |
| 727 | __ Drop(1); |
| 728 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 729 | |
| 730 | } else if (context()->IsStackValue()) { |
| 731 | VisitForAccumulatorValue(left); |
| 732 | // We want the value in the accumulator for the test, and on the stack in |
| 733 | // case we need it. |
| 734 | __ push(result_register()); |
| 735 | Label discard; |
| 736 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 737 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 738 | DoTest(left, &discard, &done, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 739 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 740 | DoTest(left, &done, &discard, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 741 | } |
| 742 | __ bind(&discard); |
| 743 | __ Drop(1); |
| 744 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 745 | |
| 746 | } else { |
| 747 | ASSERT(context()->IsEffect()); |
| 748 | Label eval_right; |
| 749 | if (is_logical_and) { |
| 750 | VisitForControl(left, &eval_right, &done, &eval_right); |
| 751 | } else { |
| 752 | VisitForControl(left, &done, &eval_right, &eval_right); |
| 753 | } |
| 754 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 755 | __ bind(&eval_right); |
| 756 | } |
| 757 | |
| 758 | VisitInCurrentContext(right); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 759 | __ bind(&done); |
| 760 | } |
| 761 | |
| 762 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 763 | void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
| 764 | Token::Value op = expr->op(); |
| 765 | Comment cmnt(masm_, "[ ArithmeticExpression"); |
| 766 | Expression* left = expr->left(); |
| 767 | Expression* right = expr->right(); |
| 768 | OverwriteMode mode = |
| 769 | left->ResultOverwriteAllowed() |
| 770 | ? OVERWRITE_LEFT |
| 771 | : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 772 | |
| 773 | VisitForStackValue(left); |
| 774 | VisitForAccumulatorValue(right); |
| 775 | |
| 776 | SetSourcePosition(expr->position()); |
| 777 | if (ShouldInlineSmiCase(op)) { |
| 778 | EmitInlineSmiBinaryOp(expr, op, mode, left, right); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 779 | } else { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 780 | EmitBinaryOp(expr, op, mode); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 785 | void FullCodeGenerator::ForwardBailoutToChild(Expression* expr) { |
| 786 | if (!info_->HasDeoptimizationSupport()) return; |
| 787 | ASSERT(context()->IsTest()); |
| 788 | ASSERT(expr == forward_bailout_stack_->expr()); |
| 789 | forward_bailout_pending_ = forward_bailout_stack_; |
| 790 | } |
| 791 | |
| 792 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 793 | void FullCodeGenerator::VisitInCurrentContext(Expression* expr) { |
| 794 | if (context()->IsTest()) { |
| 795 | ForwardBailoutStack stack(expr, forward_bailout_pending_); |
| 796 | ForwardBailoutStack* saved = forward_bailout_stack_; |
| 797 | forward_bailout_pending_ = NULL; |
| 798 | forward_bailout_stack_ = &stack; |
| 799 | Visit(expr); |
| 800 | forward_bailout_stack_ = saved; |
| 801 | } else { |
| 802 | ASSERT(forward_bailout_pending_ == NULL); |
| 803 | Visit(expr); |
| 804 | State state = context()->IsAccumulatorValue() ? TOS_REG : NO_REGISTERS; |
| 805 | PrepareForBailout(expr, state); |
| 806 | // Forwarding bailouts to children is a one shot operation. It should have |
| 807 | // been processed at this point. |
| 808 | ASSERT(forward_bailout_pending_ == NULL); |
| 809 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 813 | void FullCodeGenerator::VisitBlock(Block* stmt) { |
| 814 | Comment cmnt(masm_, "[ Block"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 815 | NestedBlock nested_block(this, stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 816 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 817 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 818 | Scope* saved_scope = scope(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 819 | // Push a block context when entering a block with block scoped variables. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 820 | if (stmt->block_scope() != NULL) { |
| 821 | { Comment cmnt(masm_, "[ Extend block context"); |
| 822 | scope_ = stmt->block_scope(); |
| 823 | __ Push(scope_->GetSerializedScopeInfo()); |
| 824 | PushFunctionArgumentForContextAllocation(); |
| 825 | __ CallRuntime(Runtime::kPushBlockContext, 2); |
| 826 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 827 | context_register()); |
| 828 | } |
| 829 | { Comment cmnt(masm_, "[ Declarations"); |
| 830 | VisitDeclarations(scope_->declarations()); |
| 831 | } |
| 832 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 833 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 834 | VisitStatements(stmt->statements()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 835 | scope_ = saved_scope; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 836 | __ bind(nested_block.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 837 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 838 | |
| 839 | // Pop block context if necessary. |
| 840 | if (stmt->block_scope() != NULL) { |
| 841 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 842 | // Update local stack frame context field. |
| 843 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 844 | context_register()); |
| 845 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | |
| 849 | void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 850 | Comment cmnt(masm_, "[ ExpressionStatement"); |
| 851 | SetStatementPosition(stmt); |
| 852 | VisitForEffect(stmt->expression()); |
| 853 | } |
| 854 | |
| 855 | |
| 856 | void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
| 857 | Comment cmnt(masm_, "[ EmptyStatement"); |
| 858 | SetStatementPosition(stmt); |
| 859 | } |
| 860 | |
| 861 | |
| 862 | void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) { |
| 863 | Comment cmnt(masm_, "[ IfStatement"); |
| 864 | SetStatementPosition(stmt); |
| 865 | Label then_part, else_part, done; |
| 866 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 867 | if (stmt->HasElseStatement()) { |
| 868 | VisitForControl(stmt->condition(), &then_part, &else_part, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 869 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 870 | __ bind(&then_part); |
| 871 | Visit(stmt->then_statement()); |
| 872 | __ jmp(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 873 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 874 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 875 | __ bind(&else_part); |
| 876 | Visit(stmt->else_statement()); |
| 877 | } else { |
| 878 | VisitForControl(stmt->condition(), &then_part, &done, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 879 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 880 | __ bind(&then_part); |
| 881 | Visit(stmt->then_statement()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 882 | |
| 883 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 884 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 885 | __ bind(&done); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 886 | PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
| 890 | void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) { |
| 891 | Comment cmnt(masm_, "[ ContinueStatement"); |
| 892 | SetStatementPosition(stmt); |
| 893 | NestedStatement* current = nesting_stack_; |
| 894 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 895 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 896 | // When continuing, we clobber the unpredictable value in the accumulator |
| 897 | // with one that's safe for GC. If we hit an exit from the try block of |
| 898 | // try...finally on our way out, we will unconditionally preserve the |
| 899 | // accumulator on the stack. |
| 900 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 901 | while (!current->IsContinueTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 902 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 903 | } |
| 904 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 905 | if (context_length > 0) { |
| 906 | while (context_length > 0) { |
| 907 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 908 | --context_length; |
| 909 | } |
| 910 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 911 | context_register()); |
| 912 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 913 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 914 | __ jmp(current->AsIteration()->continue_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | |
| 918 | void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
| 919 | Comment cmnt(masm_, "[ BreakStatement"); |
| 920 | SetStatementPosition(stmt); |
| 921 | NestedStatement* current = nesting_stack_; |
| 922 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 923 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 924 | // When breaking, we clobber the unpredictable value in the accumulator |
| 925 | // with one that's safe for GC. If we hit an exit from the try block of |
| 926 | // try...finally on our way out, we will unconditionally preserve the |
| 927 | // accumulator on the stack. |
| 928 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 929 | while (!current->IsBreakTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 930 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 931 | } |
| 932 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 933 | if (context_length > 0) { |
| 934 | while (context_length > 0) { |
| 935 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 936 | --context_length; |
| 937 | } |
| 938 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 939 | context_register()); |
| 940 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 941 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 942 | __ jmp(current->AsBreakable()->break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | |
| 946 | void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 947 | Comment cmnt(masm_, "[ ReturnStatement"); |
| 948 | SetStatementPosition(stmt); |
| 949 | Expression* expr = stmt->expression(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 950 | VisitForAccumulatorValue(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 951 | |
| 952 | // Exit all nested statements. |
| 953 | NestedStatement* current = nesting_stack_; |
| 954 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 955 | int context_length = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 956 | while (current != NULL) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 957 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 958 | } |
| 959 | __ Drop(stack_depth); |
| 960 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 961 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 965 | void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { |
| 966 | Comment cmnt(masm_, "[ WithStatement"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 967 | SetStatementPosition(stmt); |
| 968 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 969 | VisitForStackValue(stmt->expression()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 970 | PushFunctionArgumentForContextAllocation(); |
| 971 | __ CallRuntime(Runtime::kPushWithContext, 2); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 972 | decrement_stack_height(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 973 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 974 | |
| 975 | { WithOrCatch body(this); |
| 976 | Visit(stmt->statement()); |
| 977 | } |
| 978 | |
| 979 | // Pop context. |
| 980 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 981 | // Update local stack frame context field. |
| 982 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 986 | void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 987 | Comment cmnt(masm_, "[ DoWhileStatement"); |
| 988 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 989 | Label body, stack_check; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 990 | |
| 991 | Iteration loop_statement(this, stmt); |
| 992 | increment_loop_depth(); |
| 993 | |
| 994 | __ bind(&body); |
| 995 | Visit(stmt->body()); |
| 996 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 997 | // Record the position of the do while condition and make sure it is |
| 998 | // possible to break on the condition. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 999 | __ bind(loop_statement.continue_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1000 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1001 | SetExpressionPosition(stmt->cond(), stmt->condition_position()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1002 | VisitForControl(stmt->cond(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1003 | &stack_check, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1004 | loop_statement.break_label(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1005 | &stack_check); |
| 1006 | |
| 1007 | // Check stack before looping. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1008 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1009 | __ bind(&stack_check); |
| 1010 | EmitStackCheck(stmt); |
| 1011 | __ jmp(&body); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1013 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1014 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1015 | decrement_loop_depth(); |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { |
| 1020 | Comment cmnt(masm_, "[ WhileStatement"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1021 | Label test, body; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1022 | |
| 1023 | Iteration loop_statement(this, stmt); |
| 1024 | increment_loop_depth(); |
| 1025 | |
| 1026 | // Emit the test at the bottom of the loop. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1027 | __ jmp(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1028 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1029 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1030 | __ bind(&body); |
| 1031 | Visit(stmt->body()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1032 | |
| 1033 | // Emit the statement position here as this is where the while |
| 1034 | // statement code starts. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1035 | __ bind(loop_statement.continue_label()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1036 | SetStatementPosition(stmt); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1037 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1038 | // Check stack before looping. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1039 | EmitStackCheck(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1040 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | __ bind(&test); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1042 | VisitForControl(stmt->cond(), |
| 1043 | &body, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1044 | loop_statement.break_label(), |
| 1045 | loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1046 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1048 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1049 | decrement_loop_depth(); |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { |
| 1054 | Comment cmnt(masm_, "[ ForStatement"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1055 | Label test, body; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1056 | |
| 1057 | Iteration loop_statement(this, stmt); |
| 1058 | if (stmt->init() != NULL) { |
| 1059 | Visit(stmt->init()); |
| 1060 | } |
| 1061 | |
| 1062 | increment_loop_depth(); |
| 1063 | // Emit the test at the bottom of the loop (even if empty). |
| 1064 | __ jmp(&test); |
| 1065 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1066 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1067 | __ bind(&body); |
| 1068 | Visit(stmt->body()); |
| 1069 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1070 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1071 | __ bind(loop_statement.continue_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1072 | SetStatementPosition(stmt); |
| 1073 | if (stmt->next() != NULL) { |
| 1074 | Visit(stmt->next()); |
| 1075 | } |
| 1076 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1077 | // Emit the statement position here as this is where the for |
| 1078 | // statement code starts. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1079 | SetStatementPosition(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Check stack before looping. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1082 | EmitStackCheck(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1083 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1084 | __ bind(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1085 | if (stmt->cond() != NULL) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1086 | VisitForControl(stmt->cond(), |
| 1087 | &body, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1088 | loop_statement.break_label(), |
| 1089 | loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1090 | } else { |
| 1091 | __ jmp(&body); |
| 1092 | } |
| 1093 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1094 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1095 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1096 | decrement_loop_depth(); |
| 1097 | } |
| 1098 | |
| 1099 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1100 | void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| 1101 | Comment cmnt(masm_, "[ TryCatchStatement"); |
| 1102 | SetStatementPosition(stmt); |
| 1103 | // The try block adds a handler to the exception handler chain |
| 1104 | // before entering, and removes it again when exiting normally. |
| 1105 | // If an exception is thrown during execution of the try block, |
| 1106 | // control is passed to the handler, which also consumes the handler. |
| 1107 | // At this point, the exception is in a register, and store it in |
| 1108 | // the temporary local variable (prints as ".catch-var") before |
| 1109 | // executing the catch block. The catch block has been rewritten |
| 1110 | // to introduce a new scope to bind the catch variable and to remove |
| 1111 | // that scope again afterwards. |
| 1112 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1113 | Label try_handler_setup, done; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1114 | __ Call(&try_handler_setup); |
| 1115 | // Try handler code, exception in result register. |
| 1116 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1117 | // Extend the context before executing the catch block. |
| 1118 | { Comment cmnt(masm_, "[ Extend catch context"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1119 | __ Push(stmt->variable()->name()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1120 | __ push(result_register()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1121 | PushFunctionArgumentForContextAllocation(); |
| 1122 | __ CallRuntime(Runtime::kPushCatchContext, 3); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1123 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1124 | context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1127 | Scope* saved_scope = scope(); |
| 1128 | scope_ = stmt->scope(); |
| 1129 | ASSERT(scope_->declarations()->is_empty()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1130 | { WithOrCatch body(this); |
| 1131 | Visit(stmt->catch_block()); |
| 1132 | } |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 1133 | // Restore the context. |
| 1134 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1135 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1136 | scope_ = saved_scope; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1137 | __ jmp(&done); |
| 1138 | |
| 1139 | // Try block code. Sets up the exception handler chain. |
| 1140 | __ bind(&try_handler_setup); |
| 1141 | { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1142 | const int delta = StackHandlerConstants::kSize / kPointerSize; |
| 1143 | TryCatch try_block(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1144 | __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1145 | increment_stack_height(delta); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1146 | Visit(stmt->try_block()); |
| 1147 | __ PopTryHandler(); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1148 | decrement_stack_height(delta); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1149 | } |
| 1150 | __ bind(&done); |
| 1151 | } |
| 1152 | |
| 1153 | |
| 1154 | void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| 1155 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
| 1156 | SetStatementPosition(stmt); |
| 1157 | // Try finally is compiled by setting up a try-handler on the stack while |
| 1158 | // executing the try body, and removing it again afterwards. |
| 1159 | // |
| 1160 | // The try-finally construct can enter the finally block in three ways: |
| 1161 | // 1. By exiting the try-block normally. This removes the try-handler and |
| 1162 | // calls the finally block code before continuing. |
| 1163 | // 2. By exiting the try-block with a function-local control flow transfer |
| 1164 | // (break/continue/return). The site of the, e.g., break removes the |
| 1165 | // try handler and calls the finally block code before continuing |
| 1166 | // its outward control transfer. |
| 1167 | // 3. by exiting the try-block with a thrown exception. |
| 1168 | // This can happen in nested function calls. It traverses the try-handler |
| 1169 | // chain and consumes the try-handler entry before jumping to the |
| 1170 | // handler code. The handler code then calls the finally-block before |
| 1171 | // rethrowing the exception. |
| 1172 | // |
| 1173 | // The finally block must assume a return address on top of the stack |
| 1174 | // (or in the link register on ARM chips) and a value (return value or |
| 1175 | // exception) in the result register (rax/eax/r0), both of which must |
| 1176 | // be preserved. The return address isn't GC-safe, so it should be |
| 1177 | // cooked before GC. |
| 1178 | Label finally_entry; |
| 1179 | Label try_handler_setup; |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1180 | const int original_stack_height = stack_height(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1181 | |
| 1182 | // Setup the try-handler chain. Use a call to |
| 1183 | // Jump to try-handler setup and try-block code. Use call to put try-handler |
| 1184 | // address on stack. |
| 1185 | __ Call(&try_handler_setup); |
| 1186 | // Try handler code. Return address of call is pushed on handler stack. |
| 1187 | { |
| 1188 | // This code is only executed during stack-handler traversal when an |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1189 | // exception is thrown. The exception is in the result register, which |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1190 | // is retained by the finally block. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1191 | // Call the finally block and then rethrow the exception if it returns. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1192 | __ Call(&finally_entry); |
| 1193 | __ push(result_register()); |
| 1194 | __ CallRuntime(Runtime::kReThrow, 1); |
| 1195 | } |
| 1196 | |
| 1197 | __ bind(&finally_entry); |
| 1198 | { |
| 1199 | // Finally block implementation. |
| 1200 | Finally finally_block(this); |
| 1201 | EnterFinallyBlock(); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1202 | set_stack_height(original_stack_height + Finally::kElementCount); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1203 | Visit(stmt->finally_block()); |
| 1204 | ExitFinallyBlock(); // Return to the calling code. |
| 1205 | } |
| 1206 | |
| 1207 | __ bind(&try_handler_setup); |
| 1208 | { |
| 1209 | // Setup try handler (stack pointer registers). |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1210 | const int delta = StackHandlerConstants::kSize / kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1211 | TryFinally try_block(this, &finally_entry); |
| 1212 | __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1213 | set_stack_height(original_stack_height + delta); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1214 | Visit(stmt->try_block()); |
| 1215 | __ PopTryHandler(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1216 | set_stack_height(original_stack_height); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1217 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1218 | // Execute the finally block on the way out. Clobber the unpredictable |
| 1219 | // value in the accumulator with one that's safe for GC. The finally |
| 1220 | // block will unconditionally preserve the accumulator on the stack. |
| 1221 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1222 | __ Call(&finally_entry); |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1227 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1228 | Comment cmnt(masm_, "[ DebuggerStatement"); |
| 1229 | SetStatementPosition(stmt); |
| 1230 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1231 | __ DebugBreak(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1232 | // Ignore the return value. |
| 1233 | #endif |
| 1234 | } |
| 1235 | |
| 1236 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1237 | void FullCodeGenerator::VisitConditional(Conditional* expr) { |
| 1238 | Comment cmnt(masm_, "[ Conditional"); |
| 1239 | Label true_case, false_case, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1240 | VisitForControl(expr->condition(), &true_case, &false_case, &true_case); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1241 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1242 | PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1243 | __ bind(&true_case); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1244 | SetExpressionPosition(expr->then_expression(), |
| 1245 | expr->then_expression_position()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1246 | int start_stack_height = stack_height(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1247 | if (context()->IsTest()) { |
| 1248 | const TestContext* for_test = TestContext::cast(context()); |
| 1249 | VisitForControl(expr->then_expression(), |
| 1250 | for_test->true_label(), |
| 1251 | for_test->false_label(), |
| 1252 | NULL); |
| 1253 | } else { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1254 | VisitInCurrentContext(expr->then_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1255 | __ jmp(&done); |
| 1256 | } |
| 1257 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1258 | PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1259 | __ bind(&false_case); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1260 | set_stack_height(start_stack_height); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1261 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1262 | SetExpressionPosition(expr->else_expression(), |
| 1263 | expr->else_expression_position()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1264 | VisitInCurrentContext(expr->else_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1265 | // If control flow falls through Visit, merge it with true case here. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1266 | if (!context()->IsTest()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1267 | __ bind(&done); |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1272 | void FullCodeGenerator::VisitLiteral(Literal* expr) { |
| 1273 | Comment cmnt(masm_, "[ Literal"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1274 | context()->Plug(expr->handle()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1278 | void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 1279 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 1280 | |
| 1281 | // Build the function boilerplate and instantiate it. |
| 1282 | Handle<SharedFunctionInfo> function_info = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1283 | Compiler::BuildFunctionInfo(expr, script()); |
| 1284 | if (function_info.is_null()) { |
| 1285 | SetStackOverflow(); |
| 1286 | return; |
| 1287 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1288 | EmitNewClosure(function_info, expr->pretenure()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | void FullCodeGenerator::VisitSharedFunctionInfoLiteral( |
| 1293 | SharedFunctionInfoLiteral* expr) { |
| 1294 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1295 | EmitNewClosure(expr->shared_function_info(), false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1299 | void FullCodeGenerator::VisitThrow(Throw* expr) { |
| 1300 | Comment cmnt(masm_, "[ Throw"); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1301 | // Throw has no effect on the stack height or the current expression context. |
| 1302 | // Usually the expression context is null, because throw is a statement. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1303 | VisitForStackValue(expr->exception()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1304 | __ CallRuntime(Runtime::kThrow, 1); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1305 | decrement_stack_height(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1306 | // Never returns here. |
| 1307 | } |
| 1308 | |
| 1309 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1310 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit( |
| 1311 | int* stack_depth, |
| 1312 | int* context_length) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1313 | // The macros used here must preserve the result register. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1314 | __ Drop(*stack_depth); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1315 | __ PopTryHandler(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1316 | *stack_depth = 0; |
| 1317 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1320 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame^] | 1321 | bool FullCodeGenerator::TryLiteralCompare(CompareOperation* expr) { |
| 1322 | Expression *sub_expr; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1323 | Handle<String> check; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame^] | 1324 | if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) { |
| 1325 | EmitLiteralCompareTypeof(sub_expr, check); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1326 | return true; |
| 1327 | } |
| 1328 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame^] | 1329 | if (expr->IsLiteralCompareUndefined(&sub_expr)) { |
| 1330 | EmitLiteralCompareNil(expr, sub_expr, kUndefinedValue); |
| 1331 | return true; |
| 1332 | } |
| 1333 | |
| 1334 | if (expr->IsLiteralCompareNull(&sub_expr)) { |
| 1335 | EmitLiteralCompareNil(expr, sub_expr, kNullValue); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1336 | return true; |
| 1337 | } |
| 1338 | |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
| 1342 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1343 | #undef __ |
| 1344 | |
| 1345 | |
| 1346 | } } // namespace v8::internal |