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