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