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