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