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