yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 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" |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 39 | #include "snapshot.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 40 | #include "stub-cache.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 45 | void BreakableStatementChecker::Check(Statement* stmt) { |
| 46 | Visit(stmt); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void BreakableStatementChecker::Check(Expression* expr) { |
| 51 | Visit(expr); |
| 52 | } |
| 53 | |
| 54 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 55 | void BreakableStatementChecker::VisitVariableDeclaration( |
| 56 | VariableDeclaration* decl) { |
| 57 | } |
| 58 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 59 | void BreakableStatementChecker::VisitFunctionDeclaration( |
| 60 | FunctionDeclaration* decl) { |
| 61 | } |
| 62 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 63 | void BreakableStatementChecker::VisitModuleDeclaration( |
| 64 | ModuleDeclaration* decl) { |
| 65 | } |
| 66 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 67 | void BreakableStatementChecker::VisitImportDeclaration( |
| 68 | ImportDeclaration* decl) { |
| 69 | } |
| 70 | |
| 71 | void BreakableStatementChecker::VisitExportDeclaration( |
| 72 | ExportDeclaration* decl) { |
| 73 | } |
| 74 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 75 | |
| 76 | void BreakableStatementChecker::VisitModuleLiteral(ModuleLiteral* module) { |
| 77 | } |
| 78 | |
| 79 | void BreakableStatementChecker::VisitModuleVariable(ModuleVariable* module) { |
| 80 | } |
| 81 | |
| 82 | void BreakableStatementChecker::VisitModulePath(ModulePath* module) { |
| 83 | } |
| 84 | |
| 85 | void BreakableStatementChecker::VisitModuleUrl(ModuleUrl* module) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 89 | void BreakableStatementChecker::VisitModuleStatement(ModuleStatement* stmt) { |
| 90 | } |
| 91 | |
| 92 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 93 | void BreakableStatementChecker::VisitBlock(Block* stmt) { |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void BreakableStatementChecker::VisitExpressionStatement( |
| 98 | ExpressionStatement* stmt) { |
| 99 | // Check if expression is breakable. |
| 100 | Visit(stmt->expression()); |
| 101 | } |
| 102 | |
| 103 | |
| 104 | void BreakableStatementChecker::VisitEmptyStatement(EmptyStatement* stmt) { |
| 105 | } |
| 106 | |
| 107 | |
| 108 | void BreakableStatementChecker::VisitIfStatement(IfStatement* stmt) { |
| 109 | // If the condition is breakable the if statement is breakable. |
| 110 | Visit(stmt->condition()); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | void BreakableStatementChecker::VisitContinueStatement( |
| 115 | ContinueStatement* stmt) { |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void BreakableStatementChecker::VisitBreakStatement(BreakStatement* stmt) { |
| 120 | } |
| 121 | |
| 122 | |
| 123 | void BreakableStatementChecker::VisitReturnStatement(ReturnStatement* stmt) { |
| 124 | // Return is breakable if the expression is. |
| 125 | Visit(stmt->expression()); |
| 126 | } |
| 127 | |
| 128 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 129 | void BreakableStatementChecker::VisitWithStatement(WithStatement* stmt) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 130 | Visit(stmt->expression()); |
| 131 | } |
| 132 | |
| 133 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 134 | void BreakableStatementChecker::VisitSwitchStatement(SwitchStatement* stmt) { |
| 135 | // Switch statements breakable if the tag expression is. |
| 136 | Visit(stmt->tag()); |
| 137 | } |
| 138 | |
| 139 | |
| 140 | void BreakableStatementChecker::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 141 | // Mark do while as breakable to avoid adding a break slot in front of it. |
| 142 | is_breakable_ = true; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) { |
| 147 | // Mark while statements breakable if the condition expression is. |
| 148 | Visit(stmt->cond()); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) { |
| 153 | // Mark for statements breakable if the condition expression is. |
| 154 | if (stmt->cond() != NULL) { |
| 155 | Visit(stmt->cond()); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | |
| 160 | void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) { |
| 161 | // Mark for in statements breakable if the enumerable expression is. |
| 162 | Visit(stmt->enumerable()); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | void BreakableStatementChecker::VisitTryCatchStatement( |
| 167 | TryCatchStatement* stmt) { |
| 168 | // Mark try catch as breakable to avoid adding a break slot in front of it. |
| 169 | is_breakable_ = true; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | void BreakableStatementChecker::VisitTryFinallyStatement( |
| 174 | TryFinallyStatement* stmt) { |
| 175 | // Mark try finally as breakable to avoid adding a break slot in front of it. |
| 176 | is_breakable_ = true; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | void BreakableStatementChecker::VisitDebuggerStatement( |
| 181 | DebuggerStatement* stmt) { |
| 182 | // The debugger statement is breakable. |
| 183 | is_breakable_ = true; |
| 184 | } |
| 185 | |
| 186 | |
| 187 | void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 188 | } |
| 189 | |
| 190 | |
| 191 | void BreakableStatementChecker::VisitSharedFunctionInfoLiteral( |
| 192 | SharedFunctionInfoLiteral* expr) { |
| 193 | } |
| 194 | |
| 195 | |
| 196 | void BreakableStatementChecker::VisitConditional(Conditional* expr) { |
| 197 | } |
| 198 | |
| 199 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 200 | void BreakableStatementChecker::VisitVariableProxy(VariableProxy* expr) { |
| 201 | } |
| 202 | |
| 203 | |
| 204 | void BreakableStatementChecker::VisitLiteral(Literal* expr) { |
| 205 | } |
| 206 | |
| 207 | |
| 208 | void BreakableStatementChecker::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 209 | } |
| 210 | |
| 211 | |
| 212 | void BreakableStatementChecker::VisitObjectLiteral(ObjectLiteral* expr) { |
| 213 | } |
| 214 | |
| 215 | |
| 216 | void BreakableStatementChecker::VisitArrayLiteral(ArrayLiteral* expr) { |
| 217 | } |
| 218 | |
| 219 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 220 | void BreakableStatementChecker::VisitAssignment(Assignment* expr) { |
| 221 | // If assigning to a property (including a global property) the assignment is |
| 222 | // breakable. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 223 | VariableProxy* proxy = expr->target()->AsVariableProxy(); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 224 | Property* prop = expr->target()->AsProperty(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 225 | if (prop != NULL || (proxy != NULL && proxy->var()->IsUnallocated())) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 226 | is_breakable_ = true; |
| 227 | return; |
| 228 | } |
| 229 | |
| 230 | // Otherwise the assignment is breakable if the assigned value is. |
| 231 | Visit(expr->value()); |
| 232 | } |
| 233 | |
| 234 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 235 | void BreakableStatementChecker::VisitYield(Yield* expr) { |
| 236 | // Yield is breakable if the expression is. |
| 237 | Visit(expr->expression()); |
| 238 | } |
| 239 | |
| 240 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 241 | void BreakableStatementChecker::VisitThrow(Throw* expr) { |
| 242 | // Throw is breakable if the expression is. |
| 243 | Visit(expr->exception()); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | void BreakableStatementChecker::VisitProperty(Property* expr) { |
| 248 | // Property load is breakable. |
| 249 | is_breakable_ = true; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | void BreakableStatementChecker::VisitCall(Call* expr) { |
| 254 | // Function calls both through IC and call stub are breakable. |
| 255 | is_breakable_ = true; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | void BreakableStatementChecker::VisitCallNew(CallNew* expr) { |
| 260 | // Function calls through new are breakable. |
| 261 | is_breakable_ = true; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | void BreakableStatementChecker::VisitCallRuntime(CallRuntime* expr) { |
| 266 | } |
| 267 | |
| 268 | |
| 269 | void BreakableStatementChecker::VisitUnaryOperation(UnaryOperation* expr) { |
| 270 | Visit(expr->expression()); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | void BreakableStatementChecker::VisitCountOperation(CountOperation* expr) { |
| 275 | Visit(expr->expression()); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | void BreakableStatementChecker::VisitBinaryOperation(BinaryOperation* expr) { |
| 280 | Visit(expr->left()); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 281 | if (expr->op() != Token::AND && |
| 282 | expr->op() != Token::OR) { |
| 283 | Visit(expr->right()); |
| 284 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | |
| 288 | void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) { |
| 289 | Visit(expr->left()); |
| 290 | Visit(expr->right()); |
| 291 | } |
| 292 | |
| 293 | |
| 294 | void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) { |
| 295 | } |
| 296 | |
| 297 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 298 | #define __ ACCESS_MASM(masm()) |
| 299 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 300 | bool FullCodeGenerator::MakeCode(CompilationInfo* info) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 301 | Isolate* isolate = info->isolate(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 302 | Handle<Script> script = info->script(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 303 | if (!script->IsUndefined() && !script->source()->IsUndefined()) { |
| 304 | int len = String::cast(script->source())->length(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 305 | isolate->counters()->total_full_codegen_source_size()->Increment(len); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 306 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 307 | if (FLAG_trace_codegen) { |
| 308 | PrintF("Full Compiler - "); |
| 309 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 310 | CodeGenerator::MakeCodePrologue(info); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 311 | const int kInitialBufferSize = 4 * KB; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 312 | MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 313 | #ifdef ENABLE_GDB_JIT_INTERFACE |
| 314 | masm.positions_recorder()->StartGDBJITLineInfoRecording(); |
| 315 | #endif |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 316 | LOG_CODE_EVENT(isolate, |
| 317 | CodeStartLinePosInfoRecordEvent(masm.positions_recorder())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 318 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 319 | FullCodeGenerator cgen(&masm, info); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 320 | cgen.Generate(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 321 | if (cgen.HasStackOverflow()) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 322 | ASSERT(!isolate->has_pending_exception()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 323 | return false; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 324 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 325 | unsigned table_offset = cgen.EmitStackCheckTable(); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 326 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 327 | Code::Flags flags = Code::ComputeFlags(Code::FUNCTION); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 328 | Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info); |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 329 | code->set_optimizable(info->IsOptimizable() && |
ulan@chromium.org | d6899c3 | 2012-05-18 14:12:25 +0000 | [diff] [blame] | 330 | !info->function()->flags()->Contains(kDontOptimize) && |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 331 | info->function()->scope()->AllowsLazyCompilation()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 332 | cgen.PopulateDeoptimizationData(code); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 333 | cgen.PopulateTypeFeedbackInfo(code); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 334 | cgen.PopulateTypeFeedbackCells(code); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 335 | code->set_has_deoptimization_support(info->HasDeoptimizationSupport()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 336 | code->set_handler_table(*cgen.handler_table()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 337 | #ifdef ENABLE_DEBUGGER_SUPPORT |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 338 | code->set_has_debug_break_slots( |
| 339 | info->isolate()->debugger()->IsDebuggerActive()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 340 | code->set_compiled_optimizable(info->IsOptimizable()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 341 | #endif // ENABLE_DEBUGGER_SUPPORT |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | code->set_allow_osr_at_loop_nesting_level(0); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 343 | code->set_profiler_ticks(0); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 344 | code->set_stack_check_table_offset(table_offset); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 345 | code->set_stack_check_patched_for_osr(false); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 346 | CodeGenerator::PrintCode(code, info); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 347 | info->SetCode(code); // May be an empty handle. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 348 | #ifdef ENABLE_GDB_JIT_INTERFACE |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 349 | if (FLAG_gdbjit && !code.is_null()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 350 | GDBJITLineInfo* lineinfo = |
| 351 | masm.positions_recorder()->DetachGDBJITLineInfo(); |
| 352 | |
| 353 | GDBJIT(RegisterDetailedLineInfo(*code, lineinfo)); |
| 354 | } |
| 355 | #endif |
yangguo@chromium.org | c03a192 | 2013-02-19 13:55:47 +0000 | [diff] [blame] | 356 | if (!code.is_null()) { |
| 357 | void* line_info = |
| 358 | masm.positions_recorder()->DetachJITHandlerData(); |
| 359 | LOG_CODE_EVENT(isolate, CodeEndLinePosInfoRecordEvent(*code, line_info)); |
| 360 | } |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 361 | return !code.is_null(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 365 | unsigned FullCodeGenerator::EmitStackCheckTable() { |
| 366 | // The stack check table consists of a length (in number of entries) |
| 367 | // field, and then a sequence of entries. Each entry is a pair of AST id |
| 368 | // and code-relative pc offset. |
| 369 | masm()->Align(kIntSize); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 370 | unsigned offset = masm()->pc_offset(); |
| 371 | unsigned length = stack_checks_.length(); |
| 372 | __ dd(length); |
| 373 | for (unsigned i = 0; i < length; ++i) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 374 | __ dd(stack_checks_[i].id.ToInt()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 375 | __ dd(stack_checks_[i].pc_and_state); |
| 376 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 377 | return offset; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) { |
| 382 | // Fill in the deoptimization information. |
| 383 | ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty()); |
| 384 | if (!info_->HasDeoptimizationSupport()) return; |
| 385 | int length = bailout_entries_.length(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 386 | Handle<DeoptimizationOutputData> data = isolate()->factory()-> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 387 | NewDeoptimizationOutputData(length, TENURED); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 388 | for (int i = 0; i < length; i++) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 389 | data->SetAstId(i, bailout_entries_[i].id); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 390 | data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state)); |
| 391 | } |
| 392 | code->set_deoptimization_data(*data); |
| 393 | } |
| 394 | |
| 395 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 396 | void FullCodeGenerator::PopulateTypeFeedbackInfo(Handle<Code> code) { |
| 397 | Handle<TypeFeedbackInfo> info = isolate()->factory()->NewTypeFeedbackInfo(); |
| 398 | info->set_ic_total_count(ic_total_count_); |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 399 | ASSERT(!isolate()->heap()->InNewSpace(*info)); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 400 | code->set_type_feedback_info(*info); |
| 401 | } |
| 402 | |
| 403 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 404 | void FullCodeGenerator::Initialize() { |
| 405 | // The generation of debug code must match between the snapshot code and the |
| 406 | // code that is generated later. This is assumed by the debugger when it is |
| 407 | // calculating PC offsets after generating a debug version of code. Therefore |
| 408 | // we disable the production of debug code in the full compiler if we are |
| 409 | // either generating a snapshot or we booted from a snapshot. |
| 410 | generate_debug_code_ = FLAG_debug_code && |
| 411 | !Serializer::enabled() && |
| 412 | !Snapshot::HaveASnapshotToStartFrom(); |
| 413 | masm_->set_emit_debug_code(generate_debug_code_); |
| 414 | masm_->set_predictable_code_size(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 415 | InitializeAstVisitor(); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 419 | void FullCodeGenerator::PopulateTypeFeedbackCells(Handle<Code> code) { |
| 420 | if (type_feedback_cells_.is_empty()) return; |
| 421 | int length = type_feedback_cells_.length(); |
| 422 | int array_size = TypeFeedbackCells::LengthOfFixedArray(length); |
| 423 | Handle<TypeFeedbackCells> cache = Handle<TypeFeedbackCells>::cast( |
| 424 | isolate()->factory()->NewFixedArray(array_size, TENURED)); |
| 425 | for (int i = 0; i < length; i++) { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 426 | cache->SetAstId(i, type_feedback_cells_[i].ast_id); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 427 | cache->SetCell(i, *type_feedback_cells_[i].cell); |
| 428 | } |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 429 | TypeFeedbackInfo::cast(code->type_feedback_info())->set_type_feedback_cells( |
| 430 | *cache); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | |
| 434 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 435 | void FullCodeGenerator::PrepareForBailout(Expression* node, State state) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 436 | PrepareForBailoutForId(node->id(), state); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | void FullCodeGenerator::RecordJSReturnSite(Call* call) { |
| 441 | // We record the offset of the function return so we can rebuild the frame |
| 442 | // if the function was inlined, i.e., this is the return address in the |
| 443 | // inlined function's frame. |
| 444 | // |
| 445 | // The state is ignored. We defensively set it to TOS_REG, which is the |
| 446 | // real state of the unoptimized code at the return site. |
| 447 | PrepareForBailoutForId(call->ReturnId(), TOS_REG); |
| 448 | #ifdef DEBUG |
| 449 | // In debug builds, mark the return so we can verify that this function |
| 450 | // was called. |
| 451 | ASSERT(!call->return_is_recorded_); |
| 452 | call->return_is_recorded_ = true; |
| 453 | #endif |
| 454 | } |
| 455 | |
| 456 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 457 | void FullCodeGenerator::PrepareForBailoutForId(BailoutId id, State state) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 458 | // There's no need to prepare this code for bailouts from already optimized |
| 459 | // code or code that can't be optimized. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 460 | if (!info_->HasDeoptimizationSupport()) return; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 461 | unsigned pc_and_state = |
| 462 | StateField::encode(state) | PcField::encode(masm_->pc_offset()); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 463 | ASSERT(Smi::IsValid(pc_and_state)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 464 | BailoutEntry entry = { id, pc_and_state }; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 465 | ASSERT(!prepared_bailout_ids_.Contains(id.ToInt())); |
| 466 | prepared_bailout_ids_.Add(id.ToInt(), zone()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 467 | bailout_entries_.Add(entry, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 471 | void FullCodeGenerator::RecordTypeFeedbackCell( |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 472 | TypeFeedbackId id, Handle<JSGlobalPropertyCell> cell) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 473 | TypeFeedbackCellEntry entry = { id, cell }; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 474 | type_feedback_cells_.Add(entry, zone()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 478 | void FullCodeGenerator::RecordBackEdge(BailoutId ast_id) { |
| 479 | // The pc offset does not need to be encoded and packed together with a state. |
svenpanne@chromium.org | ecb9dd6 | 2011-12-01 08:22:35 +0000 | [diff] [blame] | 480 | ASSERT(masm_->pc_offset() > 0); |
| 481 | BailoutEntry entry = { ast_id, static_cast<unsigned>(masm_->pc_offset()) }; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 482 | stack_checks_.Add(entry, zone()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 486 | bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 487 | // Inline smi case inside loops, but not division and modulo which |
| 488 | // are too complicated and take up too much space. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 489 | if (op == Token::DIV ||op == Token::MOD) return false; |
| 490 | if (FLAG_always_inline_smi_code) return true; |
| 491 | return loop_depth_ > 0; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 495 | void FullCodeGenerator::EffectContext::Plug(Register reg) const { |
| 496 | } |
| 497 | |
| 498 | |
| 499 | void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 500 | __ Move(result_register(), reg); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 505 | __ push(reg); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | void FullCodeGenerator::TestContext::Plug(Register reg) const { |
| 510 | // For simplicity we always test the accumulator register. |
| 511 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 512 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 513 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | |
| 517 | void FullCodeGenerator::EffectContext::PlugTOS() const { |
| 518 | __ Drop(1); |
| 519 | } |
| 520 | |
| 521 | |
| 522 | void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
| 523 | __ pop(result_register()); |
| 524 | } |
| 525 | |
| 526 | |
| 527 | void FullCodeGenerator::StackValueContext::PlugTOS() const { |
| 528 | } |
| 529 | |
| 530 | |
| 531 | void FullCodeGenerator::TestContext::PlugTOS() const { |
| 532 | // For simplicity we always test the accumulator register. |
| 533 | __ pop(result_register()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 534 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 535 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
| 539 | void FullCodeGenerator::EffectContext::PrepareTest( |
| 540 | Label* materialize_true, |
| 541 | Label* materialize_false, |
| 542 | Label** if_true, |
| 543 | Label** if_false, |
| 544 | Label** fall_through) const { |
| 545 | // In an effect context, the true and the false case branch to the |
| 546 | // same label. |
| 547 | *if_true = *if_false = *fall_through = materialize_true; |
| 548 | } |
| 549 | |
| 550 | |
| 551 | void FullCodeGenerator::AccumulatorValueContext::PrepareTest( |
| 552 | Label* materialize_true, |
| 553 | Label* materialize_false, |
| 554 | Label** if_true, |
| 555 | Label** if_false, |
| 556 | Label** fall_through) const { |
| 557 | *if_true = *fall_through = materialize_true; |
| 558 | *if_false = materialize_false; |
| 559 | } |
| 560 | |
| 561 | |
| 562 | void FullCodeGenerator::StackValueContext::PrepareTest( |
| 563 | Label* materialize_true, |
| 564 | Label* materialize_false, |
| 565 | Label** if_true, |
| 566 | Label** if_false, |
| 567 | Label** fall_through) const { |
| 568 | *if_true = *fall_through = materialize_true; |
| 569 | *if_false = materialize_false; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | void FullCodeGenerator::TestContext::PrepareTest( |
| 574 | Label* materialize_true, |
| 575 | Label* materialize_false, |
| 576 | Label** if_true, |
| 577 | Label** if_false, |
| 578 | Label** fall_through) const { |
| 579 | *if_true = true_label_; |
| 580 | *if_false = false_label_; |
| 581 | *fall_through = fall_through_; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 585 | void FullCodeGenerator::DoTest(const TestContext* context) { |
| 586 | DoTest(context->condition(), |
| 587 | context->true_label(), |
| 588 | context->false_label(), |
| 589 | context->fall_through()); |
| 590 | } |
| 591 | |
| 592 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 593 | void FullCodeGenerator::AllocateModules(ZoneList<Declaration*>* declarations) { |
| 594 | ASSERT(scope_->is_global_scope()); |
| 595 | |
| 596 | for (int i = 0; i < declarations->length(); i++) { |
| 597 | ModuleDeclaration* declaration = declarations->at(i)->AsModuleDeclaration(); |
| 598 | if (declaration != NULL) { |
| 599 | ModuleLiteral* module = declaration->module()->AsModuleLiteral(); |
| 600 | if (module != NULL) { |
| 601 | Comment cmnt(masm_, "[ Link nested modules"); |
| 602 | Scope* scope = module->body()->scope(); |
| 603 | Interface* interface = scope->interface(); |
| 604 | ASSERT(interface->IsModule() && interface->IsFrozen()); |
| 605 | |
| 606 | interface->Allocate(scope->module_var()->index()); |
| 607 | |
| 608 | // Set up module context. |
| 609 | ASSERT(scope->interface()->Index() >= 0); |
| 610 | __ Push(Smi::FromInt(scope->interface()->Index())); |
| 611 | __ Push(scope->GetScopeInfo()); |
| 612 | __ CallRuntime(Runtime::kPushModuleContext, 2); |
| 613 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 614 | context_register()); |
| 615 | |
| 616 | AllocateModules(scope->declarations()); |
| 617 | |
| 618 | // Pop module context. |
| 619 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 620 | // Update local stack frame context field. |
| 621 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 622 | context_register()); |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | |
| 629 | // Modules have their own local scope, represented by their own context. |
| 630 | // Module instance objects have an accessor for every export that forwards |
| 631 | // access to the respective slot from the module's context. (Exports that are |
| 632 | // modules themselves, however, are simple data properties.) |
| 633 | // |
| 634 | // All modules have a _hosting_ scope/context, which (currently) is the |
| 635 | // (innermost) enclosing global scope. To deal with recursion, nested modules |
| 636 | // are hosted by the same scope as global ones. |
| 637 | // |
| 638 | // For every (global or nested) module literal, the hosting context has an |
| 639 | // internal slot that points directly to the respective module context. This |
| 640 | // enables quick access to (statically resolved) module members by 2-dimensional |
| 641 | // access through the hosting context. For example, |
| 642 | // |
| 643 | // module A { |
| 644 | // let x; |
| 645 | // module B { let y; } |
| 646 | // } |
| 647 | // module C { let z; } |
| 648 | // |
| 649 | // allocates contexts as follows: |
| 650 | // |
| 651 | // [header| .A | .B | .C | A | C ] (global) |
| 652 | // | | | |
| 653 | // | | +-- [header| z ] (module) |
| 654 | // | | |
| 655 | // | +------- [header| y ] (module) |
| 656 | // | |
| 657 | // +------------ [header| x | B ] (module) |
| 658 | // |
| 659 | // Here, .A, .B, .C are the internal slots pointing to the hosted module |
| 660 | // contexts, whereas A, B, C hold the actual instance objects (note that every |
| 661 | // module context also points to the respective instance object through its |
| 662 | // extension slot in the header). |
| 663 | // |
| 664 | // To deal with arbitrary recursion and aliases between modules, |
| 665 | // they are created and initialized in several stages. Each stage applies to |
| 666 | // all modules in the hosting global scope, including nested ones. |
| 667 | // |
| 668 | // 1. Allocate: for each module _literal_, allocate the module contexts and |
| 669 | // respective instance object and wire them up. This happens in the |
| 670 | // PushModuleContext runtime function, as generated by AllocateModules |
| 671 | // (invoked by VisitDeclarations in the hosting scope). |
| 672 | // |
| 673 | // 2. Bind: for each module _declaration_ (i.e. literals as well as aliases), |
| 674 | // assign the respective instance object to respective local variables. This |
| 675 | // happens in VisitModuleDeclaration, and uses the instance objects created |
| 676 | // in the previous stage. |
| 677 | // For each module _literal_, this phase also constructs a module descriptor |
| 678 | // for the next stage. This happens in VisitModuleLiteral. |
| 679 | // |
| 680 | // 3. Populate: invoke the DeclareModules runtime function to populate each |
| 681 | // _instance_ object with accessors for it exports. This is generated by |
| 682 | // DeclareModules (invoked by VisitDeclarations in the hosting scope again), |
| 683 | // and uses the descriptors generated in the previous stage. |
| 684 | // |
| 685 | // 4. Initialize: execute the module bodies (and other code) in sequence. This |
| 686 | // happens by the separate statements generated for module bodies. To reenter |
| 687 | // the module scopes properly, the parser inserted ModuleStatements. |
| 688 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 689 | void FullCodeGenerator::VisitDeclarations( |
| 690 | ZoneList<Declaration*>* declarations) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 691 | Handle<FixedArray> saved_modules = modules_; |
| 692 | int saved_module_index = module_index_; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 693 | ZoneList<Handle<Object> >* saved_globals = globals_; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 694 | ZoneList<Handle<Object> > inner_globals(10, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 695 | globals_ = &inner_globals; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 696 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 697 | if (scope_->num_modules() != 0) { |
| 698 | // This is a scope hosting modules. Allocate a descriptor array to pass |
| 699 | // to the runtime for initialization. |
| 700 | Comment cmnt(masm_, "[ Allocate modules"); |
| 701 | ASSERT(scope_->is_global_scope()); |
| 702 | modules_ = |
| 703 | isolate()->factory()->NewFixedArray(scope_->num_modules(), TENURED); |
| 704 | module_index_ = 0; |
| 705 | |
| 706 | // Generate code for allocating all modules, including nested ones. |
| 707 | // The allocated contexts are stored in internal variables in this scope. |
| 708 | AllocateModules(declarations); |
| 709 | } |
| 710 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 711 | AstVisitor::VisitDeclarations(declarations); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 712 | |
| 713 | if (scope_->num_modules() != 0) { |
| 714 | // Initialize modules from descriptor array. |
| 715 | ASSERT(module_index_ == modules_->length()); |
| 716 | DeclareModules(modules_); |
| 717 | modules_ = saved_modules; |
| 718 | module_index_ = saved_module_index; |
| 719 | } |
| 720 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 721 | if (!globals_->is_empty()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 722 | // Invoke the platform-dependent code generator to do the actual |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 723 | // declaration of the global functions and variables. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 724 | Handle<FixedArray> array = |
| 725 | isolate()->factory()->NewFixedArray(globals_->length(), TENURED); |
| 726 | for (int i = 0; i < globals_->length(); ++i) |
| 727 | array->set(i, *globals_->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 728 | DeclareGlobals(array); |
| 729 | } |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 730 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 731 | globals_ = saved_globals; |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | |
| 735 | void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 736 | Block* block = module->body(); |
| 737 | Scope* saved_scope = scope(); |
| 738 | scope_ = block->scope(); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 739 | Interface* interface = scope_->interface(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 740 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 741 | Comment cmnt(masm_, "[ ModuleLiteral"); |
| 742 | SetStatementPosition(block); |
| 743 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 744 | ASSERT(!modules_.is_null()); |
| 745 | ASSERT(module_index_ < modules_->length()); |
| 746 | int index = module_index_++; |
| 747 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 748 | // Set up module context. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 749 | ASSERT(interface->Index() >= 0); |
| 750 | __ Push(Smi::FromInt(interface->Index())); |
| 751 | __ Push(Smi::FromInt(0)); |
| 752 | __ CallRuntime(Runtime::kPushModuleContext, 2); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 753 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 754 | |
| 755 | { |
| 756 | Comment cmnt(masm_, "[ Declarations"); |
| 757 | VisitDeclarations(scope_->declarations()); |
| 758 | } |
| 759 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 760 | // Populate the module description. |
| 761 | Handle<ModuleInfo> description = |
| 762 | ModuleInfo::Create(isolate(), interface, scope_); |
| 763 | modules_->set(index, *description); |
| 764 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 765 | scope_ = saved_scope; |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 766 | // Pop module context. |
| 767 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 768 | // Update local stack frame context field. |
| 769 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | |
| 773 | void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 774 | // Nothing to do. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 775 | // The instance object is resolved statically through the module's interface. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | |
| 779 | void FullCodeGenerator::VisitModulePath(ModulePath* module) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 780 | // Nothing to do. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 781 | // The instance object is resolved statically through the module's interface. |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 785 | void FullCodeGenerator::VisitModuleUrl(ModuleUrl* module) { |
| 786 | // TODO(rossberg): dummy allocation for now. |
| 787 | Scope* scope = module->body()->scope(); |
| 788 | Interface* interface = scope_->interface(); |
| 789 | |
| 790 | ASSERT(interface->IsModule() && interface->IsFrozen()); |
| 791 | ASSERT(!modules_.is_null()); |
| 792 | ASSERT(module_index_ < modules_->length()); |
| 793 | interface->Allocate(scope->module_var()->index()); |
| 794 | int index = module_index_++; |
| 795 | |
| 796 | Handle<ModuleInfo> description = |
| 797 | ModuleInfo::Create(isolate(), interface, scope_); |
| 798 | modules_->set(index, *description); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 802 | int FullCodeGenerator::DeclareGlobalsFlags() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 803 | ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode())); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 804 | return DeclareGlobalsEvalFlag::encode(is_eval()) | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 805 | DeclareGlobalsNativeFlag::encode(is_native()) | |
| 806 | DeclareGlobalsLanguageMode::encode(language_mode()); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 810 | void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 811 | CodeGenerator::RecordPositions(masm_, fun->start_position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | |
| 815 | void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 816 | CodeGenerator::RecordPositions(masm_, fun->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | |
| 820 | void FullCodeGenerator::SetStatementPosition(Statement* stmt) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 821 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 822 | if (!isolate()->debugger()->IsDebuggerActive()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 823 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 824 | } else { |
| 825 | // Check if the statement will be breakable without adding a debug break |
| 826 | // slot. |
| 827 | BreakableStatementChecker checker; |
| 828 | checker.Check(stmt); |
| 829 | // Record the statement position right here if the statement is not |
| 830 | // breakable. For breakable statements the actual recording of the |
| 831 | // position will be postponed to the breakable code (typically an IC). |
| 832 | bool position_recorded = CodeGenerator::RecordPositions( |
| 833 | masm_, stmt->statement_pos(), !checker.is_breakable()); |
| 834 | // If the position recording did record a new position generate a debug |
| 835 | // break slot to make the statement breakable. |
| 836 | if (position_recorded) { |
| 837 | Debug::GenerateSlot(masm_); |
| 838 | } |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 839 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 840 | #else |
| 841 | CodeGenerator::RecordPositions(masm_, stmt->statement_pos()); |
| 842 | #endif |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | |
| 846 | void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 847 | #ifdef ENABLE_DEBUGGER_SUPPORT |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 848 | if (!isolate()->debugger()->IsDebuggerActive()) { |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 849 | CodeGenerator::RecordPositions(masm_, pos); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 850 | } else { |
| 851 | // Check if the expression will be breakable without adding a debug break |
| 852 | // slot. |
| 853 | BreakableStatementChecker checker; |
| 854 | checker.Check(expr); |
| 855 | // Record a statement position right here if the expression is not |
| 856 | // breakable. For breakable expressions the actual recording of the |
| 857 | // position will be postponed to the breakable code (typically an IC). |
| 858 | // NOTE this will record a statement position for something which might |
| 859 | // not be a statement. As stepping in the debugger will only stop at |
| 860 | // statement positions this is used for e.g. the condition expression of |
| 861 | // a do while loop. |
| 862 | bool position_recorded = CodeGenerator::RecordPositions( |
| 863 | masm_, pos, !checker.is_breakable()); |
| 864 | // If the position recording did record a new position generate a debug |
| 865 | // break slot to make the statement breakable. |
| 866 | if (position_recorded) { |
| 867 | Debug::GenerateSlot(masm_); |
| 868 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 869 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 870 | #else |
| 871 | CodeGenerator::RecordPositions(masm_, pos); |
| 872 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | |
| 876 | void FullCodeGenerator::SetStatementPosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 877 | CodeGenerator::RecordPositions(masm_, pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 881 | void FullCodeGenerator::SetSourcePosition(int pos) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 882 | if (pos != RelocInfo::kNoPosition) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 883 | masm_->positions_recorder()->RecordPosition(pos); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 884 | } |
| 885 | } |
| 886 | |
| 887 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 888 | // Lookup table for code generators for special runtime calls which are |
| 889 | // generated inline. |
| 890 | #define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \ |
| 891 | &FullCodeGenerator::Emit##Name, |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 892 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 893 | const FullCodeGenerator::InlineFunctionGenerator |
| 894 | FullCodeGenerator::kInlineFunctionGenerators[] = { |
| 895 | INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 896 | INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) |
| 897 | }; |
| 898 | #undef INLINE_FUNCTION_GENERATOR_ADDRESS |
| 899 | |
| 900 | |
| 901 | FullCodeGenerator::InlineFunctionGenerator |
| 902 | FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 903 | int lookup_index = |
| 904 | static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction); |
| 905 | ASSERT(lookup_index >= 0); |
| 906 | ASSERT(static_cast<size_t>(lookup_index) < |
| 907 | ARRAY_SIZE(kInlineFunctionGenerators)); |
| 908 | return kInlineFunctionGenerators[lookup_index]; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 912 | void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* expr) { |
| 913 | const Runtime::Function* function = expr->function(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 914 | ASSERT(function != NULL); |
| 915 | ASSERT(function->intrinsic_type == Runtime::INLINE); |
| 916 | InlineFunctionGenerator generator = |
| 917 | FindInlineFunctionGenerator(function->function_id); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 918 | ((*this).*(generator))(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | |
| 922 | void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 923 | switch (expr->op()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 924 | case Token::COMMA: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 925 | return VisitComma(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 926 | case Token::OR: |
| 927 | case Token::AND: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 928 | return VisitLogicalExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 929 | default: |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 930 | return VisitArithmeticExpression(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 931 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 935 | void FullCodeGenerator::VisitInDuplicateContext(Expression* expr) { |
| 936 | if (context()->IsEffect()) { |
| 937 | VisitForEffect(expr); |
| 938 | } else if (context()->IsAccumulatorValue()) { |
| 939 | VisitForAccumulatorValue(expr); |
| 940 | } else if (context()->IsStackValue()) { |
| 941 | VisitForStackValue(expr); |
| 942 | } else if (context()->IsTest()) { |
| 943 | const TestContext* test = TestContext::cast(context()); |
| 944 | VisitForControl(expr, test->true_label(), test->false_label(), |
| 945 | test->fall_through()); |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 950 | void FullCodeGenerator::VisitComma(BinaryOperation* expr) { |
| 951 | Comment cmnt(masm_, "[ Comma"); |
| 952 | VisitForEffect(expr->left()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 953 | VisitInDuplicateContext(expr->right()); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 954 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 955 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 956 | |
| 957 | void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) { |
| 958 | bool is_logical_and = expr->op() == Token::AND; |
| 959 | Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR"); |
| 960 | Expression* left = expr->left(); |
| 961 | Expression* right = expr->right(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 962 | BailoutId right_id = expr->RightId(); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 963 | Label done; |
| 964 | |
| 965 | if (context()->IsTest()) { |
| 966 | Label eval_right; |
| 967 | const TestContext* test = TestContext::cast(context()); |
| 968 | if (is_logical_and) { |
| 969 | VisitForControl(left, &eval_right, test->false_label(), &eval_right); |
| 970 | } else { |
| 971 | VisitForControl(left, test->true_label(), &eval_right, &eval_right); |
| 972 | } |
| 973 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 974 | __ bind(&eval_right); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 975 | |
| 976 | } else if (context()->IsAccumulatorValue()) { |
| 977 | VisitForAccumulatorValue(left); |
| 978 | // We want the value in the accumulator for the test, and on the stack in |
| 979 | // case we need it. |
| 980 | __ push(result_register()); |
| 981 | Label discard, restore; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 982 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 983 | DoTest(left, &discard, &restore, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 984 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 985 | DoTest(left, &restore, &discard, &restore); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 986 | } |
| 987 | __ bind(&restore); |
| 988 | __ pop(result_register()); |
| 989 | __ jmp(&done); |
| 990 | __ bind(&discard); |
| 991 | __ Drop(1); |
| 992 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 993 | |
| 994 | } else if (context()->IsStackValue()) { |
| 995 | VisitForAccumulatorValue(left); |
| 996 | // We want the value in the accumulator for the test, and on the stack in |
| 997 | // case we need it. |
| 998 | __ push(result_register()); |
| 999 | Label discard; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1000 | if (is_logical_and) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1001 | DoTest(left, &discard, &done, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1002 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1003 | DoTest(left, &done, &discard, &discard); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1004 | } |
| 1005 | __ bind(&discard); |
| 1006 | __ Drop(1); |
| 1007 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 1008 | |
| 1009 | } else { |
| 1010 | ASSERT(context()->IsEffect()); |
| 1011 | Label eval_right; |
| 1012 | if (is_logical_and) { |
| 1013 | VisitForControl(left, &eval_right, &done, &eval_right); |
| 1014 | } else { |
| 1015 | VisitForControl(left, &done, &eval_right, &eval_right); |
| 1016 | } |
| 1017 | PrepareForBailoutForId(right_id, NO_REGISTERS); |
| 1018 | __ bind(&eval_right); |
| 1019 | } |
| 1020 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1021 | VisitInDuplicateContext(right); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1022 | __ bind(&done); |
| 1023 | } |
| 1024 | |
| 1025 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1026 | void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
| 1027 | Token::Value op = expr->op(); |
| 1028 | Comment cmnt(masm_, "[ ArithmeticExpression"); |
| 1029 | Expression* left = expr->left(); |
| 1030 | Expression* right = expr->right(); |
| 1031 | OverwriteMode mode = |
| 1032 | left->ResultOverwriteAllowed() |
| 1033 | ? OVERWRITE_LEFT |
| 1034 | : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 1035 | |
| 1036 | VisitForStackValue(left); |
| 1037 | VisitForAccumulatorValue(right); |
| 1038 | |
| 1039 | SetSourcePosition(expr->position()); |
| 1040 | if (ShouldInlineSmiCase(op)) { |
| 1041 | EmitInlineSmiBinaryOp(expr, op, mode, left, right); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1042 | } else { |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1043 | EmitBinaryOp(expr, op, mode); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1048 | void FullCodeGenerator::VisitBlock(Block* stmt) { |
| 1049 | Comment cmnt(masm_, "[ Block"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1050 | NestedBlock nested_block(this, stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1051 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1052 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1053 | Scope* saved_scope = scope(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1054 | // Push a block context when entering a block with block scoped variables. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1055 | if (stmt->scope() != NULL) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 1056 | scope_ = stmt->scope(); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1057 | ASSERT(!scope_->is_module_scope()); |
| 1058 | { Comment cmnt(masm_, "[ Extend block context"); |
| 1059 | Handle<ScopeInfo> scope_info = scope_->GetScopeInfo(); |
| 1060 | int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS; |
| 1061 | __ Push(scope_info); |
| 1062 | PushFunctionArgumentForContextAllocation(); |
| 1063 | if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) { |
| 1064 | FastNewBlockContextStub stub(heap_slots); |
| 1065 | __ CallStub(&stub); |
| 1066 | } else { |
| 1067 | __ CallRuntime(Runtime::kPushBlockContext, 2); |
| 1068 | } |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1069 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1070 | // Replace the context stored in the frame. |
| 1071 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1072 | context_register()); |
| 1073 | } |
| 1074 | { Comment cmnt(masm_, "[ Declarations"); |
| 1075 | VisitDeclarations(scope_->declarations()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1076 | } |
| 1077 | } |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1078 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1079 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1080 | VisitStatements(stmt->statements()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1081 | scope_ = saved_scope; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1082 | __ bind(nested_block.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1083 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Pop block context if necessary. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1086 | if (stmt->scope() != NULL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1087 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1088 | // Update local stack frame context field. |
| 1089 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1090 | context_register()); |
| 1091 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1095 | void FullCodeGenerator::VisitModuleStatement(ModuleStatement* stmt) { |
| 1096 | Comment cmnt(masm_, "[ Module context"); |
| 1097 | |
| 1098 | __ Push(Smi::FromInt(stmt->proxy()->interface()->Index())); |
| 1099 | __ Push(Smi::FromInt(0)); |
| 1100 | __ CallRuntime(Runtime::kPushModuleContext, 2); |
| 1101 | StoreToFrameField( |
| 1102 | StandardFrameConstants::kContextOffset, context_register()); |
| 1103 | |
| 1104 | Scope* saved_scope = scope_; |
| 1105 | scope_ = stmt->body()->scope(); |
| 1106 | VisitStatements(stmt->body()->statements()); |
| 1107 | scope_ = saved_scope; |
| 1108 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1109 | // Update local stack frame context field. |
| 1110 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1111 | context_register()); |
| 1112 | } |
| 1113 | |
| 1114 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1115 | void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 1116 | Comment cmnt(masm_, "[ ExpressionStatement"); |
| 1117 | SetStatementPosition(stmt); |
| 1118 | VisitForEffect(stmt->expression()); |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) { |
| 1123 | Comment cmnt(masm_, "[ EmptyStatement"); |
| 1124 | SetStatementPosition(stmt); |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) { |
| 1129 | Comment cmnt(masm_, "[ IfStatement"); |
| 1130 | SetStatementPosition(stmt); |
| 1131 | Label then_part, else_part, done; |
| 1132 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1133 | if (stmt->HasElseStatement()) { |
| 1134 | VisitForControl(stmt->condition(), &then_part, &else_part, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1135 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1136 | __ bind(&then_part); |
| 1137 | Visit(stmt->then_statement()); |
| 1138 | __ jmp(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1139 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1140 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1141 | __ bind(&else_part); |
| 1142 | Visit(stmt->else_statement()); |
| 1143 | } else { |
| 1144 | VisitForControl(stmt->condition(), &then_part, &done, &then_part); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1145 | PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1146 | __ bind(&then_part); |
| 1147 | Visit(stmt->then_statement()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1148 | |
| 1149 | PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1150 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1151 | __ bind(&done); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1152 | PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) { |
| 1157 | Comment cmnt(masm_, "[ ContinueStatement"); |
| 1158 | SetStatementPosition(stmt); |
| 1159 | NestedStatement* current = nesting_stack_; |
| 1160 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1161 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1162 | // When continuing, we clobber the unpredictable value in the accumulator |
| 1163 | // with one that's safe for GC. If we hit an exit from the try block of |
| 1164 | // try...finally on our way out, we will unconditionally preserve the |
| 1165 | // accumulator on the stack. |
| 1166 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1167 | while (!current->IsContinueTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1168 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1169 | } |
| 1170 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1171 | if (context_length > 0) { |
| 1172 | while (context_length > 0) { |
| 1173 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1174 | --context_length; |
| 1175 | } |
| 1176 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1177 | context_register()); |
| 1178 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1179 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1180 | __ jmp(current->AsIteration()->continue_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | |
| 1184 | void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
| 1185 | Comment cmnt(masm_, "[ BreakStatement"); |
| 1186 | SetStatementPosition(stmt); |
| 1187 | NestedStatement* current = nesting_stack_; |
| 1188 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1189 | int context_length = 0; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1190 | // When breaking, we clobber the unpredictable value in the accumulator |
| 1191 | // with one that's safe for GC. If we hit an exit from the try block of |
| 1192 | // try...finally on our way out, we will unconditionally preserve the |
| 1193 | // accumulator on the stack. |
| 1194 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1195 | while (!current->IsBreakTarget(stmt->target())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1196 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1197 | } |
| 1198 | __ Drop(stack_depth); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1199 | if (context_length > 0) { |
| 1200 | while (context_length > 0) { |
| 1201 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1202 | --context_length; |
| 1203 | } |
| 1204 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1205 | context_register()); |
| 1206 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1207 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1208 | __ jmp(current->AsBreakable()->break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 1213 | Comment cmnt(masm_, "[ ReturnStatement"); |
| 1214 | SetStatementPosition(stmt); |
| 1215 | Expression* expr = stmt->expression(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1216 | VisitForAccumulatorValue(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1217 | |
| 1218 | // Exit all nested statements. |
| 1219 | NestedStatement* current = nesting_stack_; |
| 1220 | int stack_depth = 0; |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1221 | int context_length = 0; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1222 | while (current != NULL) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1223 | current = current->Exit(&stack_depth, &context_length); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1224 | } |
| 1225 | __ Drop(stack_depth); |
| 1226 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 1227 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1231 | void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) { |
| 1232 | Comment cmnt(masm_, "[ WithStatement"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1233 | SetStatementPosition(stmt); |
| 1234 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1235 | VisitForStackValue(stmt->expression()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1236 | PushFunctionArgumentForContextAllocation(); |
| 1237 | __ CallRuntime(Runtime::kPushWithContext, 2); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1238 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1239 | |
| 1240 | { WithOrCatch body(this); |
| 1241 | Visit(stmt->statement()); |
| 1242 | } |
| 1243 | |
| 1244 | // Pop context. |
| 1245 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1246 | // Update local stack frame context field. |
| 1247 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1251 | void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 1252 | Comment cmnt(masm_, "[ DoWhileStatement"); |
| 1253 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1254 | Label body, stack_check; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1255 | |
| 1256 | Iteration loop_statement(this, stmt); |
| 1257 | increment_loop_depth(); |
| 1258 | |
| 1259 | __ bind(&body); |
| 1260 | Visit(stmt->body()); |
| 1261 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1262 | // Record the position of the do while condition and make sure it is |
| 1263 | // possible to break on the condition. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1264 | __ bind(loop_statement.continue_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1265 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1266 | SetExpressionPosition(stmt->cond(), stmt->condition_position()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1267 | VisitForControl(stmt->cond(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | &stack_check, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1269 | loop_statement.break_label(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1270 | &stack_check); |
| 1271 | |
| 1272 | // Check stack before looping. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1273 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1274 | __ bind(&stack_check); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1275 | EmitBackEdgeBookkeeping(stmt, &body); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1276 | __ jmp(&body); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1277 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1278 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1279 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1280 | decrement_loop_depth(); |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { |
| 1285 | Comment cmnt(masm_, "[ WhileStatement"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1286 | Label test, body; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1287 | |
| 1288 | Iteration loop_statement(this, stmt); |
| 1289 | increment_loop_depth(); |
| 1290 | |
| 1291 | // Emit the test at the bottom of the loop. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1292 | __ jmp(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1293 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1294 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1295 | __ bind(&body); |
| 1296 | Visit(stmt->body()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1297 | |
| 1298 | // Emit the statement position here as this is where the while |
| 1299 | // statement code starts. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1300 | __ bind(loop_statement.continue_label()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1301 | SetStatementPosition(stmt); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1302 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1303 | // Check stack before looping. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1304 | EmitBackEdgeBookkeeping(stmt, &body); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1305 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1306 | __ bind(&test); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1307 | VisitForControl(stmt->cond(), |
| 1308 | &body, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1309 | loop_statement.break_label(), |
| 1310 | loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1311 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1312 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1313 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1314 | decrement_loop_depth(); |
| 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { |
| 1319 | Comment cmnt(masm_, "[ ForStatement"); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1320 | Label test, body; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1321 | |
| 1322 | Iteration loop_statement(this, stmt); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 1323 | |
| 1324 | // Set statement position for a break slot before entering the for-body. |
| 1325 | SetStatementPosition(stmt); |
| 1326 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1327 | if (stmt->init() != NULL) { |
| 1328 | Visit(stmt->init()); |
| 1329 | } |
| 1330 | |
| 1331 | increment_loop_depth(); |
| 1332 | // Emit the test at the bottom of the loop (even if empty). |
| 1333 | __ jmp(&test); |
| 1334 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1335 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1336 | __ bind(&body); |
| 1337 | Visit(stmt->body()); |
| 1338 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1339 | PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1340 | __ bind(loop_statement.continue_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1341 | if (stmt->next() != NULL) { |
| 1342 | Visit(stmt->next()); |
| 1343 | } |
| 1344 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1345 | // Emit the statement position here as this is where the for |
| 1346 | // statement code starts. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1347 | SetStatementPosition(stmt); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1348 | |
| 1349 | // Check stack before looping. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1350 | EmitBackEdgeBookkeeping(stmt, &body); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1351 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1352 | __ bind(&test); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1353 | if (stmt->cond() != NULL) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1354 | VisitForControl(stmt->cond(), |
| 1355 | &body, |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1356 | loop_statement.break_label(), |
| 1357 | loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1358 | } else { |
| 1359 | __ jmp(&body); |
| 1360 | } |
| 1361 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1362 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1363 | __ bind(loop_statement.break_label()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1364 | decrement_loop_depth(); |
| 1365 | } |
| 1366 | |
| 1367 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1368 | void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { |
| 1369 | Comment cmnt(masm_, "[ TryCatchStatement"); |
| 1370 | SetStatementPosition(stmt); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1371 | // The try block adds a handler to the exception handler chain before |
| 1372 | // entering, and removes it again when exiting normally. If an exception |
| 1373 | // is thrown during execution of the try block, the handler is consumed |
| 1374 | // and control is passed to the catch block with the exception in the |
| 1375 | // result register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1376 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1377 | Label try_entry, handler_entry, exit; |
| 1378 | __ jmp(&try_entry); |
| 1379 | __ bind(&handler_entry); |
| 1380 | handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); |
| 1381 | // Exception handler code, the exception is in the result register. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1382 | // Extend the context before executing the catch block. |
| 1383 | { Comment cmnt(masm_, "[ Extend catch context"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1384 | __ Push(stmt->variable()->name()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1385 | __ push(result_register()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 1386 | PushFunctionArgumentForContextAllocation(); |
| 1387 | __ CallRuntime(Runtime::kPushCatchContext, 3); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1388 | StoreToFrameField(StandardFrameConstants::kContextOffset, |
| 1389 | context_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1392 | Scope* saved_scope = scope(); |
| 1393 | scope_ = stmt->scope(); |
| 1394 | ASSERT(scope_->declarations()->is_empty()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1395 | { WithOrCatch catch_body(this); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1396 | Visit(stmt->catch_block()); |
| 1397 | } |
ricow@chromium.org | 55ee807 | 2011-09-08 16:33:10 +0000 | [diff] [blame] | 1398 | // Restore the context. |
| 1399 | LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| 1400 | StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1401 | scope_ = saved_scope; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1402 | __ jmp(&exit); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1403 | |
| 1404 | // Try block code. Sets up the exception handler chain. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1405 | __ bind(&try_entry); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1406 | __ PushTryHandler(StackHandler::CATCH, stmt->index()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1407 | { TryCatch try_body(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1408 | Visit(stmt->try_block()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1409 | } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1410 | __ PopTryHandler(); |
| 1411 | __ bind(&exit); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| 1416 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
| 1417 | SetStatementPosition(stmt); |
| 1418 | // Try finally is compiled by setting up a try-handler on the stack while |
| 1419 | // executing the try body, and removing it again afterwards. |
| 1420 | // |
| 1421 | // The try-finally construct can enter the finally block in three ways: |
| 1422 | // 1. By exiting the try-block normally. This removes the try-handler and |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1423 | // calls the finally block code before continuing. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1424 | // 2. By exiting the try-block with a function-local control flow transfer |
| 1425 | // (break/continue/return). The site of the, e.g., break removes the |
| 1426 | // try handler and calls the finally block code before continuing |
| 1427 | // its outward control transfer. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1428 | // 3. By exiting the try-block with a thrown exception. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1429 | // This can happen in nested function calls. It traverses the try-handler |
| 1430 | // chain and consumes the try-handler entry before jumping to the |
| 1431 | // handler code. The handler code then calls the finally-block before |
| 1432 | // rethrowing the exception. |
| 1433 | // |
| 1434 | // The finally block must assume a return address on top of the stack |
| 1435 | // (or in the link register on ARM chips) and a value (return value or |
| 1436 | // exception) in the result register (rax/eax/r0), both of which must |
| 1437 | // be preserved. The return address isn't GC-safe, so it should be |
| 1438 | // cooked before GC. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1439 | Label try_entry, handler_entry, finally_entry; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1440 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1441 | // Jump to try-handler setup and try-block code. |
| 1442 | __ jmp(&try_entry); |
| 1443 | __ bind(&handler_entry); |
| 1444 | handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos())); |
| 1445 | // Exception handler code. This code is only executed when an exception |
| 1446 | // is thrown. The exception is in the result register, and must be |
| 1447 | // preserved by the finally block. Call the finally block and then |
| 1448 | // rethrow the exception if it returns. |
| 1449 | __ Call(&finally_entry); |
| 1450 | __ push(result_register()); |
| 1451 | __ CallRuntime(Runtime::kReThrow, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1452 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1453 | // Finally block implementation. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1454 | __ bind(&finally_entry); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1455 | EnterFinallyBlock(); |
| 1456 | { Finally finally_body(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1457 | Visit(stmt->finally_block()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1458 | } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1459 | ExitFinallyBlock(); // Return to the calling code. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1460 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1461 | // Set up try handler. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1462 | __ bind(&try_entry); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1463 | __ PushTryHandler(StackHandler::FINALLY, stmt->index()); |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1464 | { TryFinally try_body(this, &finally_entry); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1465 | Visit(stmt->try_block()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1466 | } |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1467 | __ PopTryHandler(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1468 | // Execute the finally block on the way out. Clobber the unpredictable |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1469 | // value in the result register with one that's safe for GC because the |
| 1470 | // finally block will unconditionally preserve the result register on the |
| 1471 | // stack. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1472 | ClearAccumulator(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1473 | __ Call(&finally_entry); |
| 1474 | } |
| 1475 | |
| 1476 | |
| 1477 | void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1478 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1479 | Comment cmnt(masm_, "[ DebuggerStatement"); |
| 1480 | SetStatementPosition(stmt); |
| 1481 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1482 | __ DebugBreak(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1483 | // Ignore the return value. |
| 1484 | #endif |
| 1485 | } |
| 1486 | |
| 1487 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1488 | void FullCodeGenerator::VisitConditional(Conditional* expr) { |
| 1489 | Comment cmnt(masm_, "[ Conditional"); |
| 1490 | Label true_case, false_case, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1491 | VisitForControl(expr->condition(), &true_case, &false_case, &true_case); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1492 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1493 | PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1494 | __ bind(&true_case); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1495 | SetExpressionPosition(expr->then_expression(), |
| 1496 | expr->then_expression_position()); |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1497 | if (context()->IsTest()) { |
| 1498 | const TestContext* for_test = TestContext::cast(context()); |
| 1499 | VisitForControl(expr->then_expression(), |
| 1500 | for_test->true_label(), |
| 1501 | for_test->false_label(), |
| 1502 | NULL); |
| 1503 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1504 | VisitInDuplicateContext(expr->then_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1505 | __ jmp(&done); |
| 1506 | } |
| 1507 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1508 | PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1509 | __ bind(&false_case); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 1510 | SetExpressionPosition(expr->else_expression(), |
| 1511 | expr->else_expression_position()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1512 | VisitInDuplicateContext(expr->else_expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1513 | // 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] | 1514 | if (!context()->IsTest()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1515 | __ bind(&done); |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1520 | void FullCodeGenerator::VisitLiteral(Literal* expr) { |
| 1521 | Comment cmnt(masm_, "[ Literal"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1522 | context()->Plug(expr->handle()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1526 | void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 1527 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 1528 | |
| 1529 | // Build the function boilerplate and instantiate it. |
| 1530 | Handle<SharedFunctionInfo> function_info = |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 1531 | Compiler::BuildFunctionInfo(expr, script()); |
| 1532 | if (function_info.is_null()) { |
| 1533 | SetStackOverflow(); |
| 1534 | return; |
| 1535 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1536 | EmitNewClosure(function_info, expr->pretenure()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | void FullCodeGenerator::VisitSharedFunctionInfoLiteral( |
| 1541 | SharedFunctionInfoLiteral* expr) { |
| 1542 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1543 | EmitNewClosure(expr->shared_function_info(), false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame^] | 1547 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1548 | if (expr->is_delegating_yield()) |
| 1549 | UNIMPLEMENTED(); |
| 1550 | |
| 1551 | Comment cmnt(masm_, "[ Yield"); |
| 1552 | VisitForAccumulatorValue(expr->expression()); |
| 1553 | // TODO(wingo): Assert that the operand stack depth is 0, at least while |
| 1554 | // general yield expressions are unimplemented. |
| 1555 | |
| 1556 | // TODO(wingo): What follows is as in VisitReturnStatement. Replace it with a |
| 1557 | // call to a builtin that will resume the generator. |
| 1558 | NestedStatement* current = nesting_stack_; |
| 1559 | int stack_depth = 0; |
| 1560 | int context_length = 0; |
| 1561 | while (current != NULL) { |
| 1562 | current = current->Exit(&stack_depth, &context_length); |
| 1563 | } |
| 1564 | __ Drop(stack_depth); |
| 1565 | EmitReturnSequence(); |
| 1566 | } |
| 1567 | |
| 1568 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1569 | void FullCodeGenerator::VisitThrow(Throw* expr) { |
| 1570 | Comment cmnt(masm_, "[ Throw"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1571 | VisitForStackValue(expr->exception()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1572 | __ CallRuntime(Runtime::kThrow, 1); |
| 1573 | // Never returns here. |
| 1574 | } |
| 1575 | |
| 1576 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1577 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit( |
| 1578 | int* stack_depth, |
| 1579 | int* context_length) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1580 | // The macros used here must preserve the result register. |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1581 | __ Drop(*stack_depth); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1582 | __ PopTryHandler(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1583 | *stack_depth = 0; |
| 1584 | return previous_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1587 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1588 | bool FullCodeGenerator::TryLiteralCompare(CompareOperation* expr) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1589 | Expression* sub_expr; |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1590 | Handle<String> check; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1591 | if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1592 | EmitLiteralCompareTypeof(expr, sub_expr, check); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1593 | return true; |
| 1594 | } |
| 1595 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1596 | if (expr->IsLiteralCompareUndefined(&sub_expr)) { |
| 1597 | EmitLiteralCompareNil(expr, sub_expr, kUndefinedValue); |
| 1598 | return true; |
| 1599 | } |
| 1600 | |
| 1601 | if (expr->IsLiteralCompareNull(&sub_expr)) { |
| 1602 | EmitLiteralCompareNil(expr, sub_expr, kNullValue); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 1603 | return true; |
| 1604 | } |
| 1605 | |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
| 1609 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1610 | #undef __ |
| 1611 | |
| 1612 | |
| 1613 | } } // namespace v8::internal |