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