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