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. |
| 193 | Variable* var = expr->target()->AsVariableProxy()->AsVariable(); |
| 194 | Property* prop = expr->target()->AsProperty(); |
| 195 | if (prop != NULL || (var != NULL && var->is_global())) { |
| 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 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 398 | int FullCodeGenerator::SlotOffset(Slot* slot) { |
| 399 | ASSERT(slot != NULL); |
| 400 | // Offset is negative because higher indexes are at lower addresses. |
| 401 | int offset = -slot->index() * kPointerSize; |
| 402 | // Adjust by a (parameter or local) base offset. |
| 403 | switch (slot->type()) { |
| 404 | case Slot::PARAMETER: |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 405 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 406 | break; |
| 407 | case Slot::LOCAL: |
| 408 | offset += JavaScriptFrameConstants::kLocal0Offset; |
| 409 | break; |
| 410 | case Slot::CONTEXT: |
| 411 | case Slot::LOOKUP: |
| 412 | UNREACHABLE(); |
| 413 | } |
| 414 | return offset; |
| 415 | } |
| 416 | |
| 417 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 418 | bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 419 | // Inline smi case inside loops, but not division and modulo which |
| 420 | // are too complicated and take up too much space. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 421 | if (op == Token::DIV ||op == Token::MOD) return false; |
| 422 | if (FLAG_always_inline_smi_code) return true; |
| 423 | return loop_depth_ > 0; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 427 | void FullCodeGenerator::EffectContext::Plug(Register reg) const { |
| 428 | } |
| 429 | |
| 430 | |
| 431 | void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 432 | __ Move(result_register(), reg); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 437 | __ push(reg); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 438 | codegen()->increment_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | |
| 442 | void FullCodeGenerator::TestContext::Plug(Register reg) const { |
| 443 | // For simplicity we always test the accumulator register. |
| 444 | __ Move(result_register(), reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 445 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 446 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | |
| 450 | void FullCodeGenerator::EffectContext::PlugTOS() const { |
| 451 | __ Drop(1); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 452 | codegen()->decrement_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | |
| 456 | void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
| 457 | __ pop(result_register()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 458 | codegen()->decrement_stack_height(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | |
| 462 | void FullCodeGenerator::StackValueContext::PlugTOS() const { |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void FullCodeGenerator::TestContext::PlugTOS() const { |
| 467 | // For simplicity we always test the accumulator register. |
| 468 | __ pop(result_register()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 469 | codegen()->decrement_stack_height(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 470 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 471 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
| 475 | void FullCodeGenerator::EffectContext::PrepareTest( |
| 476 | Label* materialize_true, |
| 477 | Label* materialize_false, |
| 478 | Label** if_true, |
| 479 | Label** if_false, |
| 480 | Label** fall_through) const { |
| 481 | // In an effect context, the true and the false case branch to the |
| 482 | // same label. |
| 483 | *if_true = *if_false = *fall_through = materialize_true; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | void FullCodeGenerator::AccumulatorValueContext::PrepareTest( |
| 488 | Label* materialize_true, |
| 489 | Label* materialize_false, |
| 490 | Label** if_true, |
| 491 | Label** if_false, |
| 492 | Label** fall_through) const { |
| 493 | *if_true = *fall_through = materialize_true; |
| 494 | *if_false = materialize_false; |
| 495 | } |
| 496 | |
| 497 | |
| 498 | void FullCodeGenerator::StackValueContext::PrepareTest( |
| 499 | Label* materialize_true, |
| 500 | Label* materialize_false, |
| 501 | Label** if_true, |
| 502 | Label** if_false, |
| 503 | Label** fall_through) const { |
| 504 | *if_true = *fall_through = materialize_true; |
| 505 | *if_false = materialize_false; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | void FullCodeGenerator::TestContext::PrepareTest( |
| 510 | Label* materialize_true, |
| 511 | Label* materialize_false, |
| 512 | Label** if_true, |
| 513 | Label** if_false, |
| 514 | Label** fall_through) const { |
| 515 | *if_true = true_label_; |
| 516 | *if_false = false_label_; |
| 517 | *fall_through = fall_through_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 521 | void FullCodeGenerator::DoTest(const TestContext* context) { |
| 522 | DoTest(context->condition(), |
| 523 | context->true_label(), |
| 524 | context->false_label(), |
| 525 | context->fall_through()); |
| 526 | } |
| 527 | |
| 528 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 529 | void FullCodeGenerator::VisitDeclarations( |
| 530 | ZoneList<Declaration*>* declarations) { |
| 531 | int length = declarations->length(); |
| 532 | int globals = 0; |
| 533 | for (int i = 0; i < length; i++) { |
| 534 | Declaration* decl = declarations->at(i); |
| 535 | Variable* var = decl->proxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 536 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 537 | |
| 538 | // If it was not possible to allocate the variable at compile |
| 539 | // time, we need to "declare" it at runtime to make sure it |
| 540 | // actually exists in the local context. |
| 541 | if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) { |
| 542 | VisitDeclaration(decl); |
| 543 | } else { |
| 544 | // Count global variables and functions for later processing |
| 545 | globals++; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | // Compute array of global variable and function declarations. |
| 550 | // Do nothing in case of no declared global functions or variables. |
| 551 | if (globals > 0) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 552 | Handle<FixedArray> array = |
| 553 | isolate()->factory()->NewFixedArray(2 * globals, TENURED); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 554 | for (int j = 0, i = 0; i < length; i++) { |
| 555 | Declaration* decl = declarations->at(i); |
| 556 | Variable* var = decl->proxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 557 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 558 | |
| 559 | if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) { |
| 560 | array->set(j++, *(var->name())); |
| 561 | if (decl->fun() == NULL) { |
| 562 | if (var->mode() == Variable::CONST) { |
| 563 | // In case this is const property use the hole. |
| 564 | array->set_the_hole(j++); |
| 565 | } else { |
| 566 | array->set_undefined(j++); |
| 567 | } |
| 568 | } else { |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 569 | Handle<SharedFunctionInfo> function = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 570 | Compiler::BuildFunctionInfo(decl->fun(), script()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 571 | // Check for stack-overflow exception. |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 572 | if (function.is_null()) { |
| 573 | SetStackOverflow(); |
| 574 | return; |
| 575 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 576 | array->set(j++, *function); |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | // Invoke the platform-dependent code generator to do the actual |
| 581 | // declaration the global variables and functions. |
| 582 | DeclareGlobals(array); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 588 | CodeGenerator::RecordPositions(masm_, fun->start_position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
| 592 | void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 593 | CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
| 597 | void FullCodeGenerator::SetStatementPosition(Statement* stmt) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 598 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 599 | if (!isolate()->debugger()->IsDebuggerActive()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 600 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 601 | } else { |
| 602 | // Check if the statement will be breakable without adding a debug break |
| 603 | // slot. |
| 604 | BreakableStatementChecker checker; |
| 605 | checker.Check(stmt); |
| 606 | // Record the statement position right here if the statement is not |
| 607 | // breakable. For breakable statements the actual recording of the |
| 608 | // position will be postponed to the breakable code (typically an IC). |
| 609 | bool position_recorded = CodeGenerator::RecordPositions( |
| 610 | masm_, stmt->statement_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 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 616 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 617 | #else |
| 618 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
| 619 | #endif |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | |
| 623 | void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 624 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 625 | if (!isolate()->debugger()->IsDebuggerActive()) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 626 | CodeGenerator::RecordPositions(masm_, pos); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 627 | } else { |
| 628 | // Check if the expression will be breakable without adding a debug break |
| 629 | // slot. |
| 630 | BreakableStatementChecker checker; |
| 631 | checker.Check(expr); |
| 632 | // Record a statement position right here if the expression is not |
| 633 | // breakable. For breakable expressions the actual recording of the |
| 634 | // position will be postponed to the breakable code (typically an IC). |
| 635 | // NOTE this will record a statement position for something which might |
| 636 | // not be a statement. As stepping in the debugger will only stop at |
| 637 | // statement positions this is used for e.g. the condition expression of |
| 638 | // a do while loop. |
| 639 | bool position_recorded = CodeGenerator::RecordPositions( |
| 640 | masm_, pos, !checker.is_breakable()); |
| 641 | // If the position recording did record a new position generate a debug |
| 642 | // break slot to make the statement breakable. |
| 643 | if (position_recorded) { |
| 644 | Debug::GenerateSlot(masm_); |
| 645 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 646 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 647 | #else |
| 648 | CodeGenerator::RecordPositions(masm_, pos); |
| 649 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | |
| 653 | void FullCodeGenerator::SetStatementPosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 654 | CodeGenerator::RecordPositions(masm_, pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 658 | void FullCodeGenerator::SetSourcePosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 659 | if (pos != RelocInfo::kNoPosition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 660 | masm_->positions_recorder()->RecordPosition(pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
| 664 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 665 | // Lookup table for code generators for special runtime calls which are |
| 666 | // generated inline. |
| 667 | #define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \ |
| 668 | &FullCodeGenerator::Emit##Name, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 669 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 670 | const FullCodeGenerator::InlineFunctionGenerator |
| 671 | FullCodeGenerator::kInlineFunctionGenerators[] = { |
| 672 | INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 673 | INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 674 | }; |
| 675 | #undef INLINE_FUNCTION_GENERATOR_ADDRESS |
| 676 | |
| 677 | |
| 678 | FullCodeGenerator::InlineFunctionGenerator |
| 679 | FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 680 | int lookup_index = |
| 681 | static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction); |
| 682 | ASSERT(lookup_index >= 0); |
| 683 | ASSERT(static_cast<size_t>(lookup_index) < |
| 684 | ARRAY_SIZE(kInlineFunctionGenerators)); |
| 685 | return kInlineFunctionGenerators[lookup_index]; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | |
| 689 | void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) { |
| 690 | ZoneList<Expression*>* args = node->arguments(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 691 | const Runtime::Function* function = node->function(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 692 | ASSERT(function != NULL); |
| 693 | ASSERT(function->intrinsic_type == Runtime::INLINE); |
| 694 | InlineFunctionGenerator generator = |
| 695 | FindInlineFunctionGenerator(function->function_id); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 696 | ((*this).*(generator))(args); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | |
| 700 | void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 701 | switch (expr->op()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 702 | case Token::COMMA: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 703 | return VisitComma(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 704 | case Token::OR: |
| 705 | case Token::AND: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 706 | return VisitLogicalExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 707 | default: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 708 | return VisitArithmeticExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 709 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 713 | void FullCodeGenerator::VisitComma(BinaryOperation* expr) { |
| 714 | Comment cmnt(masm_, "[ Comma"); |
| 715 | VisitForEffect(expr->left()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 716 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 717 | VisitInCurrentContext(expr->right()); |
| 718 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 719 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 720 | |
| 721 | void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) { |
| 722 | bool is_logical_and = expr->op() == Token::AND; |
| 723 | Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR"); |
| 724 | Expression* left = expr->left(); |
| 725 | Expression* right = expr->right(); |
| 726 | int right_id = expr->RightId(); |
| 727 | Label done; |
| 728 | |
| 729 | if (context()->IsTest()) { |
| 730 | Label eval_right; |
| 731 | const TestContext* test = TestContext::cast(context()); |
| 732 | if (is_logical_and) { |
| 733 | VisitForControl(left, &eval_right, test->false_label(), &eval_right); |
| 734 | } else { |
| 735 | VisitForControl(left, test->true_label(), &eval_right, &eval_right); |
| 736 | } |
| 737 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 738 | __ bind(&eval_right); |
| 739 | ForwardBailoutToChild(expr); |
| 740 | |
| 741 | } else if (context()->IsAccumulatorValue()) { |
| 742 | VisitForAccumulatorValue(left); |
| 743 | // We want the value in the accumulator for the test, and on the stack in |
| 744 | // case we need it. |
| 745 | __ push(result_register()); |
| 746 | Label discard, restore; |
| 747 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 748 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 749 | DoTest(left, &discard, &restore, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 750 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 751 | DoTest(left, &restore, &discard, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 752 | } |
| 753 | __ bind(&restore); |
| 754 | __ pop(result_register()); |
| 755 | __ jmp(&done); |
| 756 | __ bind(&discard); |
| 757 | __ Drop(1); |
| 758 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 759 | |
| 760 | } else if (context()->IsStackValue()) { |
| 761 | VisitForAccumulatorValue(left); |
| 762 | // We want the value in the accumulator for the test, and on the stack in |
| 763 | // case we need it. |
| 764 | __ push(result_register()); |
| 765 | Label discard; |
| 766 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 767 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 768 | DoTest(left, &discard, &done, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 769 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 770 | DoTest(left, &done, &discard, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 771 | } |
| 772 | __ bind(&discard); |
| 773 | __ Drop(1); |
| 774 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 775 | |
| 776 | } else { |
| 777 | ASSERT(context()->IsEffect()); |
| 778 | Label eval_right; |
| 779 | if (is_logical_and) { |
| 780 | VisitForControl(left, &eval_right, &done, &eval_right); |
| 781 | } else { |
| 782 | VisitForControl(left, &done, &eval_right, &eval_right); |
| 783 | } |
| 784 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 785 | __ bind(&eval_right); |
| 786 | } |
| 787 | |
| 788 | VisitInCurrentContext(right); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 789 | __ bind(&done); |
| 790 | } |
| 791 | |
| 792 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 793 | void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
| 794 | Token::Value op = expr->op(); |
| 795 | Comment cmnt(masm_, "[ ArithmeticExpression"); |
| 796 | Expression* left = expr->left(); |
| 797 | Expression* right = expr->right(); |
| 798 | OverwriteMode mode = |
| 799 | left->ResultOverwriteAllowed() |
| 800 | ? OVERWRITE_LEFT |
| 801 | : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 802 | |
| 803 | VisitForStackValue(left); |
| 804 | VisitForAccumulatorValue(right); |
| 805 | |
| 806 | SetSourcePosition(expr->position()); |
| 807 | if (ShouldInlineSmiCase(op)) { |
| 808 | EmitInlineSmiBinaryOp(expr, op, mode, left, right); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 809 | } else { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 810 | EmitBinaryOp(expr, op, mode); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
| 814 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 815 | void FullCodeGenerator::ForwardBailoutToChild(Expression* expr) { |
| 816 | if (!info_->HasDeoptimizationSupport()) return; |
| 817 | ASSERT(context()->IsTest()); |
| 818 | ASSERT(expr == forward_bailout_stack_->expr()); |
| 819 | forward_bailout_pending_ = forward_bailout_stack_; |
| 820 | } |
| 821 | |
| 822 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 823 | void FullCodeGenerator::VisitInCurrentContext(Expression* expr) { |
| 824 | if (context()->IsTest()) { |
| 825 | ForwardBailoutStack stack(expr, forward_bailout_pending_); |
| 826 | ForwardBailoutStack* saved = forward_bailout_stack_; |
| 827 | forward_bailout_pending_ = NULL; |
| 828 | forward_bailout_stack_ = &stack; |
| 829 | Visit(expr); |
| 830 | forward_bailout_stack_ = saved; |
| 831 | } else { |
| 832 | ASSERT(forward_bailout_pending_ == NULL); |
| 833 | Visit(expr); |
| 834 | State state = context()->IsAccumulatorValue() ? TOS_REG : NO_REGISTERS; |
| 835 | PrepareForBailout(expr, state); |
| 836 | // Forwarding bailouts to children is a one shot operation. It should have |
| 837 | // been processed at this point. |
| 838 | ASSERT(forward_bailout_pending_ == NULL); |
| 839 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 843 | void FullCodeGenerator::VisitBlock(Block* stmt) { |
| 844 | Comment cmnt(masm_, "[ Block"); |
| 845 | Breakable nested_statement(this, stmt); |
| 846 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 848 | Scope* saved_scope = scope(); |
| 849 | if (stmt->block_scope() != NULL) { |
| 850 | { Comment cmnt(masm_, "[ Extend block context"); |
| 851 | scope_ = stmt->block_scope(); |
| 852 | __ Push(scope_->GetSerializedScopeInfo()); |
| 853 | PushFunctionArgumentForContextAllocation(); |
| 854 | __ CallRuntime(Runtime::kPushBlockContext, 2); |
| 855 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 856 | context_register()); |
| 857 | } |
| 858 | { Comment cmnt(masm_, "[ Declarations"); |
| 859 | VisitDeclarations(scope_->declarations()); |
| 860 | } |
| 861 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 862 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 863 | VisitStatements(stmt->statements()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 864 | scope_ = saved_scope; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 865 | __ bind(nested_statement.break_target()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 866 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | |
| 870 | void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 871 | Comment cmnt(masm_, "[ ExpressionStatement"); |
| 872 | SetStatementPosition(stmt); |
| 873 | VisitForEffect(stmt->expression()); |
| 874 | } |
| 875 | |
| 876 | |
| 877 | void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
| 878 | Comment cmnt(masm_, "[ EmptyStatement"); |
| 879 | SetStatementPosition(stmt); |
| 880 | } |
| 881 | |
| 882 | |
| 883 | void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) { |
| 884 | Comment cmnt(masm_, "[ IfStatement"); |
| 885 | SetStatementPosition(stmt); |
| 886 | Label then_part, else_part, done; |
| 887 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 888 | if (stmt->HasElseStatement()) { |
| 889 | VisitForControl(stmt->condition(), &then_part, &else_part, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 890 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 891 | __ bind(&then_part); |
| 892 | Visit(stmt->then_statement()); |
| 893 | __ jmp(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 894 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 895 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 896 | __ bind(&else_part); |
| 897 | Visit(stmt->else_statement()); |
| 898 | } else { |
| 899 | VisitForControl(stmt->condition(), &then_part, &done, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 900 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 901 | __ bind(&then_part); |
| 902 | Visit(stmt->then_statement()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 903 | |
| 904 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 905 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 906 | __ bind(&done); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 907 | PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | |
| 911 | void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) { |
| 912 | Comment cmnt(masm_, "[ ContinueStatement"); |
| 913 | SetStatementPosition(stmt); |
| 914 | NestedStatement* current = nesting_stack_; |
| 915 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 916 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 917 | // When continuing, we clobber the unpredictable value in the accumulator |
| 918 | // with one that's safe for GC. If we hit an exit from the try block of |
| 919 | // try...finally on our way out, we will unconditionally preserve the |
| 920 | // accumulator on the stack. |
| 921 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 922 | while (!current->IsContinueTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 923 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 924 | } |
| 925 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 926 | if (context_length > 0) { |
| 927 | while (context_length > 0) { |
| 928 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 929 | --context_length; |
| 930 | } |
| 931 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 932 | context_register()); |
| 933 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 934 | |
| 935 | Iteration* loop = current->AsIteration(); |
| 936 | __ jmp(loop->continue_target()); |
| 937 | } |
| 938 | |
| 939 | |
| 940 | void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
| 941 | Comment cmnt(masm_, "[ BreakStatement"); |
| 942 | SetStatementPosition(stmt); |
| 943 | NestedStatement* current = nesting_stack_; |
| 944 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 945 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 946 | // When breaking, we clobber the unpredictable value in the accumulator |
| 947 | // with one that's safe for GC. If we hit an exit from the try block of |
| 948 | // try...finally on our way out, we will unconditionally preserve the |
| 949 | // accumulator on the stack. |
| 950 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 951 | while (!current->IsBreakTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 952 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 953 | } |
| 954 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 955 | if (context_length > 0) { |
| 956 | while (context_length > 0) { |
| 957 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 958 | --context_length; |
| 959 | } |
| 960 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 961 | context_register()); |
| 962 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 963 | |
| 964 | Breakable* target = current->AsBreakable(); |
| 965 | __ jmp(target->break_target()); |
| 966 | } |
| 967 | |
| 968 | |
| 969 | void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 970 | Comment cmnt(masm_, "[ ReturnStatement"); |
| 971 | SetStatementPosition(stmt); |
| 972 | Expression* expr = stmt->expression(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 973 | VisitForAccumulatorValue(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 974 | |
| 975 | // Exit all nested statements. |
| 976 | NestedStatement* current = nesting_stack_; |
| 977 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 978 | int context_length = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 979 | while (current != NULL) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 980 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 981 | } |
| 982 | __ Drop(stack_depth); |
| 983 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 984 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 988 | void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { |
| 989 | Comment cmnt(masm_, "[ WithStatement"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 990 | SetStatementPosition(stmt); |
| 991 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 992 | VisitForStackValue(stmt->expression()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 993 | PushFunctionArgumentForContextAllocation(); |
| 994 | __ CallRuntime(Runtime::kPushWithContext, 2); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 995 | decrement_stack_height(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 996 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 997 | |
| 998 | { WithOrCatch body(this); |
| 999 | Visit(stmt->statement()); |
| 1000 | } |
| 1001 | |
| 1002 | // Pop context. |
| 1003 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1004 | // Update local stack frame context field. |
| 1005 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1009 | void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) { |
| 1010 | Comment cmnt(masm_, "[ ExitContextStatement"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1011 | SetStatementPosition(stmt); |
| 1012 | |
| 1013 | // Pop context. |
| 1014 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1015 | // Update local stack frame context field. |
| 1016 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
| 1017 | } |
| 1018 | |
| 1019 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1020 | void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 1021 | Comment cmnt(masm_, "[ DoWhileStatement"); |
| 1022 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1023 | Label body, stack_check; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1024 | |
| 1025 | Iteration loop_statement(this, stmt); |
| 1026 | increment_loop_depth(); |
| 1027 | |
| 1028 | __ bind(&body); |
| 1029 | Visit(stmt->body()); |
| 1030 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1031 | // Record the position of the do while condition and make sure it is |
| 1032 | // possible to break on the condition. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1033 | __ bind(loop_statement.continue_target()); |
| 1034 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1035 | SetExpressionPosition(stmt->cond(), stmt->condition_position()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1036 | VisitForControl(stmt->cond(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1037 | &stack_check, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1038 | loop_statement.break_target(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1039 | &stack_check); |
| 1040 | |
| 1041 | // Check stack before looping. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1042 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1043 | __ bind(&stack_check); |
| 1044 | EmitStackCheck(stmt); |
| 1045 | __ jmp(&body); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1046 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1048 | __ bind(loop_statement.break_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1049 | decrement_loop_depth(); |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { |
| 1054 | Comment cmnt(masm_, "[ WhileStatement"); |
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 | increment_loop_depth(); |
| 1059 | |
| 1060 | // Emit the test at the bottom of the loop. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1061 | __ jmp(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1062 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1063 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1064 | __ bind(&body); |
| 1065 | Visit(stmt->body()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1066 | |
| 1067 | // Emit the statement position here as this is where the while |
| 1068 | // statement code starts. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1069 | __ bind(loop_statement.continue_target()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1070 | SetStatementPosition(stmt); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1071 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1072 | // Check stack before looping. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1073 | EmitStackCheck(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1074 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1075 | __ bind(&test); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1076 | VisitForControl(stmt->cond(), |
| 1077 | &body, |
| 1078 | loop_statement.break_target(), |
| 1079 | loop_statement.break_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1080 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1081 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1082 | __ bind(loop_statement.break_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1083 | decrement_loop_depth(); |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { |
| 1088 | Comment cmnt(masm_, "[ ForStatement"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1089 | Label test, body; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1090 | |
| 1091 | Iteration loop_statement(this, stmt); |
| 1092 | if (stmt->init() != NULL) { |
| 1093 | Visit(stmt->init()); |
| 1094 | } |
| 1095 | |
| 1096 | increment_loop_depth(); |
| 1097 | // Emit the test at the bottom of the loop (even if empty). |
| 1098 | __ jmp(&test); |
| 1099 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1100 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1101 | __ bind(&body); |
| 1102 | Visit(stmt->body()); |
| 1103 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1104 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1105 | __ bind(loop_statement.continue_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1106 | SetStatementPosition(stmt); |
| 1107 | if (stmt->next() != NULL) { |
| 1108 | Visit(stmt->next()); |
| 1109 | } |
| 1110 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1111 | // Emit the statement position here as this is where the for |
| 1112 | // statement code starts. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1113 | SetStatementPosition(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1114 | |
| 1115 | // Check stack before looping. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1116 | EmitStackCheck(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1117 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1118 | __ bind(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1119 | if (stmt->cond() != NULL) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1120 | VisitForControl(stmt->cond(), |
| 1121 | &body, |
| 1122 | loop_statement.break_target(), |
| 1123 | loop_statement.break_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1124 | } else { |
| 1125 | __ jmp(&body); |
| 1126 | } |
| 1127 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1128 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1129 | __ bind(loop_statement.break_target()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1130 | decrement_loop_depth(); |
| 1131 | } |
| 1132 | |
| 1133 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1134 | void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| 1135 | Comment cmnt(masm_, "[ TryCatchStatement"); |
| 1136 | SetStatementPosition(stmt); |
| 1137 | // The try block adds a handler to the exception handler chain |
| 1138 | // before entering, and removes it again when exiting normally. |
| 1139 | // If an exception is thrown during execution of the try block, |
| 1140 | // control is passed to the handler, which also consumes the handler. |
| 1141 | // At this point, the exception is in a register, and store it in |
| 1142 | // the temporary local variable (prints as ".catch-var") before |
| 1143 | // executing the catch block. The catch block has been rewritten |
| 1144 | // to introduce a new scope to bind the catch variable and to remove |
| 1145 | // that scope again afterwards. |
| 1146 | |
| 1147 | Label try_handler_setup, catch_entry, done; |
| 1148 | __ Call(&try_handler_setup); |
| 1149 | // Try handler code, exception in result register. |
| 1150 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1151 | // Extend the context before executing the catch block. |
| 1152 | { Comment cmnt(masm_, "[ Extend catch context"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1153 | __ Push(stmt->variable()->name()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1154 | __ push(result_register()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1155 | PushFunctionArgumentForContextAllocation(); |
| 1156 | __ CallRuntime(Runtime::kPushCatchContext, 3); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1157 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1158 | context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1161 | Scope* saved_scope = scope(); |
| 1162 | scope_ = stmt->scope(); |
| 1163 | ASSERT(scope_->declarations()->is_empty()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1164 | { WithOrCatch body(this); |
| 1165 | Visit(stmt->catch_block()); |
| 1166 | } |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1167 | scope_ = saved_scope; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1168 | __ jmp(&done); |
| 1169 | |
| 1170 | // Try block code. Sets up the exception handler chain. |
| 1171 | __ bind(&try_handler_setup); |
| 1172 | { |
| 1173 | TryCatch try_block(this, &catch_entry); |
| 1174 | __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1175 | increment_stack_height(StackHandlerConstants::kSize / kPointerSize); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1176 | Visit(stmt->try_block()); |
| 1177 | __ PopTryHandler(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1178 | decrement_stack_height(StackHandlerConstants::kSize / kPointerSize); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1179 | } |
| 1180 | __ bind(&done); |
| 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| 1185 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
| 1186 | SetStatementPosition(stmt); |
| 1187 | // Try finally is compiled by setting up a try-handler on the stack while |
| 1188 | // executing the try body, and removing it again afterwards. |
| 1189 | // |
| 1190 | // The try-finally construct can enter the finally block in three ways: |
| 1191 | // 1. By exiting the try-block normally. This removes the try-handler and |
| 1192 | // calls the finally block code before continuing. |
| 1193 | // 2. By exiting the try-block with a function-local control flow transfer |
| 1194 | // (break/continue/return). The site of the, e.g., break removes the |
| 1195 | // try handler and calls the finally block code before continuing |
| 1196 | // its outward control transfer. |
| 1197 | // 3. by exiting the try-block with a thrown exception. |
| 1198 | // This can happen in nested function calls. It traverses the try-handler |
| 1199 | // chain and consumes the try-handler entry before jumping to the |
| 1200 | // handler code. The handler code then calls the finally-block before |
| 1201 | // rethrowing the exception. |
| 1202 | // |
| 1203 | // The finally block must assume a return address on top of the stack |
| 1204 | // (or in the link register on ARM chips) and a value (return value or |
| 1205 | // exception) in the result register (rax/eax/r0), both of which must |
| 1206 | // be preserved. The return address isn't GC-safe, so it should be |
| 1207 | // cooked before GC. |
| 1208 | Label finally_entry; |
| 1209 | Label try_handler_setup; |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1210 | const int original_stack_height = stack_height(); |
| 1211 | const int finally_block_stack_height = original_stack_height + 2; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1212 | const int try_block_stack_height = original_stack_height + 5; |
| 1213 | STATIC_ASSERT(StackHandlerConstants::kSize == 5 * kPointerSize); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1214 | |
| 1215 | // Setup the try-handler chain. Use a call to |
| 1216 | // Jump to try-handler setup and try-block code. Use call to put try-handler |
| 1217 | // address on stack. |
| 1218 | __ Call(&try_handler_setup); |
| 1219 | // Try handler code. Return address of call is pushed on handler stack. |
| 1220 | { |
| 1221 | // This code is only executed during stack-handler traversal when an |
| 1222 | // exception is thrown. The execption is in the result register, which |
| 1223 | // is retained by the finally block. |
| 1224 | // Call the finally block and then rethrow the exception. |
| 1225 | __ Call(&finally_entry); |
| 1226 | __ push(result_register()); |
| 1227 | __ CallRuntime(Runtime::kReThrow, 1); |
| 1228 | } |
| 1229 | |
| 1230 | __ bind(&finally_entry); |
| 1231 | { |
| 1232 | // Finally block implementation. |
| 1233 | Finally finally_block(this); |
| 1234 | EnterFinallyBlock(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1235 | set_stack_height(finally_block_stack_height); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1236 | Visit(stmt->finally_block()); |
| 1237 | ExitFinallyBlock(); // Return to the calling code. |
| 1238 | } |
| 1239 | |
| 1240 | __ bind(&try_handler_setup); |
| 1241 | { |
| 1242 | // Setup try handler (stack pointer registers). |
| 1243 | TryFinally try_block(this, &finally_entry); |
| 1244 | __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1245 | set_stack_height(try_block_stack_height); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1246 | Visit(stmt->try_block()); |
| 1247 | __ PopTryHandler(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1248 | set_stack_height(original_stack_height); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1249 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1250 | // Execute the finally block on the way out. Clobber the unpredictable |
| 1251 | // value in the accumulator with one that's safe for GC. The finally |
| 1252 | // block will unconditionally preserve the accumulator on the stack. |
| 1253 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1254 | __ Call(&finally_entry); |
| 1255 | } |
| 1256 | |
| 1257 | |
| 1258 | void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1259 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1260 | Comment cmnt(masm_, "[ DebuggerStatement"); |
| 1261 | SetStatementPosition(stmt); |
| 1262 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1263 | __ DebugBreak(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1264 | // Ignore the return value. |
| 1265 | #endif |
| 1266 | } |
| 1267 | |
| 1268 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1269 | void FullCodeGenerator::VisitConditional(Conditional* expr) { |
| 1270 | Comment cmnt(masm_, "[ Conditional"); |
| 1271 | Label true_case, false_case, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1272 | VisitForControl(expr->condition(), &true_case, &false_case, &true_case); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1273 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1274 | PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1275 | __ bind(&true_case); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1276 | SetExpressionPosition(expr->then_expression(), |
| 1277 | expr->then_expression_position()); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1278 | int start_stack_height = stack_height(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1279 | if (context()->IsTest()) { |
| 1280 | const TestContext* for_test = TestContext::cast(context()); |
| 1281 | VisitForControl(expr->then_expression(), |
| 1282 | for_test->true_label(), |
| 1283 | for_test->false_label(), |
| 1284 | NULL); |
| 1285 | } else { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1286 | VisitInCurrentContext(expr->then_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1287 | __ jmp(&done); |
| 1288 | } |
| 1289 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1290 | PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1291 | __ bind(&false_case); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1292 | set_stack_height(start_stack_height); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1294 | SetExpressionPosition(expr->else_expression(), |
| 1295 | expr->else_expression_position()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1296 | VisitInCurrentContext(expr->else_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1297 | // 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] | 1298 | if (!context()->IsTest()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1299 | __ bind(&done); |
| 1300 | } |
| 1301 | } |
| 1302 | |
| 1303 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1304 | void FullCodeGenerator::VisitLiteral(Literal* expr) { |
| 1305 | Comment cmnt(masm_, "[ Literal"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1306 | context()->Plug(expr->handle()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1310 | void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 1311 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 1312 | |
| 1313 | // Build the function boilerplate and instantiate it. |
| 1314 | Handle<SharedFunctionInfo> function_info = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1315 | Compiler::BuildFunctionInfo(expr, script()); |
| 1316 | if (function_info.is_null()) { |
| 1317 | SetStackOverflow(); |
| 1318 | return; |
| 1319 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1320 | EmitNewClosure(function_info, expr->pretenure()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | void FullCodeGenerator::VisitSharedFunctionInfoLiteral( |
| 1325 | SharedFunctionInfoLiteral* expr) { |
| 1326 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1327 | EmitNewClosure(expr->shared_function_info(), false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1331 | void FullCodeGenerator::VisitThrow(Throw* expr) { |
| 1332 | Comment cmnt(masm_, "[ Throw"); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1333 | // Throw has no effect on the stack height or the current expression context. |
| 1334 | // Usually the expression context is null, because throw is a statement. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1335 | VisitForStackValue(expr->exception()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1336 | __ CallRuntime(Runtime::kThrow, 1); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1337 | decrement_stack_height(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1338 | // Never returns here. |
| 1339 | } |
| 1340 | |
| 1341 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1342 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 1343 | int* stack_depth, |
| 1344 | int* context_length) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1345 | // The macros used here must preserve the result register. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1346 | __ Drop(*stack_depth); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1347 | __ PopTryHandler(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1348 | *stack_depth = 0; |
| 1349 | |
| 1350 | Register context = FullCodeGenerator::context_register(); |
| 1351 | while (*context_length > 0) { |
| 1352 | codegen_->LoadContextField(context, Context::PREVIOUS_INDEX); |
| 1353 | --(*context_length); |
| 1354 | } |
| 1355 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1356 | __ Call(finally_entry_); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1357 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1361 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit( |
| 1362 | int* stack_depth, |
| 1363 | int* context_length) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1364 | // The macros used here must preserve the result register. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1365 | __ Drop(*stack_depth); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1366 | __ PopTryHandler(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1367 | *stack_depth = 0; |
| 1368 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1371 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1372 | bool FullCodeGenerator::TryLiteralCompare(CompareOperation* compare, |
| 1373 | Label* if_true, |
| 1374 | Label* if_false, |
| 1375 | Label* fall_through) { |
| 1376 | Expression *expr; |
| 1377 | Handle<String> check; |
| 1378 | if (compare->IsLiteralCompareTypeof(&expr, &check)) { |
| 1379 | EmitLiteralCompareTypeof(expr, check, if_true, if_false, fall_through); |
| 1380 | return true; |
| 1381 | } |
| 1382 | |
| 1383 | if (compare->IsLiteralCompareUndefined(&expr)) { |
| 1384 | EmitLiteralCompareUndefined(expr, if_true, if_false, fall_through); |
| 1385 | return true; |
| 1386 | } |
| 1387 | |
| 1388 | return false; |
| 1389 | } |
| 1390 | |
| 1391 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1392 | #undef __ |
| 1393 | |
| 1394 | |
| 1395 | } } // namespace v8::internal |