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