Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: src/full-codegen.cc

Issue 682413004: Fix stepping in for-loops. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/ast.h" 7 #include "src/ast.h"
8 #include "src/ast-numbering.h" 8 #include "src/ast-numbering.h"
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 129 }
130 130
131 131
132 void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) { 132 void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) {
133 // Mark while statements breakable if the condition expression is. 133 // Mark while statements breakable if the condition expression is.
134 Visit(stmt->cond()); 134 Visit(stmt->cond());
135 } 135 }
136 136
137 137
138 void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) { 138 void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) {
139 // Mark for statements breakable if the condition expression is. 139 // We set positions for both init and condition, if they exist.
140 if (stmt->cond() != NULL) { 140 if (stmt->cond() != NULL || stmt->init() != NULL) is_breakable_ = true;
141 Visit(stmt->cond());
142 }
143 } 141 }
144 142
145 143
146 void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) { 144 void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) {
147 // Mark for in statements breakable if the enumerable expression is. 145 // For-in is breakable because we set the position for the enumerable.
148 Visit(stmt->enumerable()); 146 is_breakable_ = true;
149 } 147 }
150 148
151 149
152 void BreakableStatementChecker::VisitForOfStatement(ForOfStatement* stmt) { 150 void BreakableStatementChecker::VisitForOfStatement(ForOfStatement* stmt) {
153 // For-of is breakable because of the next() call. 151 // For-of is breakable because we set the position for the next() call.
154 is_breakable_ = true; 152 is_breakable_ = true;
155 } 153 }
156 154
157 155
158 void BreakableStatementChecker::VisitTryCatchStatement( 156 void BreakableStatementChecker::VisitTryCatchStatement(
159 TryCatchStatement* stmt) { 157 TryCatchStatement* stmt) {
160 // Mark try catch as breakable to avoid adding a break slot in front of it. 158 // Mark try catch as breakable to avoid adding a break slot in front of it.
161 is_breakable_ = true; 159 is_breakable_ = true;
162 } 160 }
163 161
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 void FullCodeGenerator::VisitForStatement(ForStatement* stmt) { 1336 void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
1339 Comment cmnt(masm_, "[ ForStatement"); 1337 Comment cmnt(masm_, "[ ForStatement");
1340 Label test, body; 1338 Label test, body;
1341 1339
1342 Iteration loop_statement(this, stmt); 1340 Iteration loop_statement(this, stmt);
1343 1341
1344 // Set statement position for a break slot before entering the for-body. 1342 // Set statement position for a break slot before entering the for-body.
1345 SetStatementPosition(stmt); 1343 SetStatementPosition(stmt);
1346 1344
1347 if (stmt->init() != NULL) { 1345 if (stmt->init() != NULL) {
1346 SetStatementPosition(stmt->init());
1348 Visit(stmt->init()); 1347 Visit(stmt->init());
1349 } 1348 }
1350 1349
1351 increment_loop_depth(); 1350 increment_loop_depth();
1352 // Emit the test at the bottom of the loop (even if empty). 1351 // Emit the test at the bottom of the loop (even if empty).
1353 __ jmp(&test); 1352 __ jmp(&test);
1354 1353
1355 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); 1354 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
1356 __ bind(&body); 1355 __ bind(&body);
1357 Visit(stmt->body()); 1356 Visit(stmt->body());
1358 1357
1359 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS); 1358 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
1360 __ bind(loop_statement.continue_label()); 1359 __ bind(loop_statement.continue_label());
1361 if (stmt->next() != NULL) { 1360 if (stmt->next() != NULL) {
1361 SetStatementPosition(stmt->next());
1362 Visit(stmt->next()); 1362 Visit(stmt->next());
1363 } 1363 }
1364 1364
1365 // Emit the statement position here as this is where the for 1365 // Emit the statement position here as this is where the for
1366 // statement code starts. 1366 // statement code starts.
1367 SetStatementPosition(stmt); 1367 SetStatementPosition(stmt);
1368 1368
1369 // Check stack before looping. 1369 // Check stack before looping.
1370 EmitBackEdgeBookkeeping(stmt, &body); 1370 EmitBackEdgeBookkeeping(stmt, &body);
1371 1371
1372 __ bind(&test); 1372 __ bind(&test);
1373 if (stmt->cond() != NULL) { 1373 if (stmt->cond() != NULL) {
1374 SetExpressionPosition(stmt->cond());
1374 VisitForControl(stmt->cond(), 1375 VisitForControl(stmt->cond(),
1375 &body, 1376 &body,
1376 loop_statement.break_label(), 1377 loop_statement.break_label(),
1377 loop_statement.break_label()); 1378 loop_statement.break_label());
1378 } else { 1379 } else {
1379 __ jmp(&body); 1380 __ jmp(&body);
1380 } 1381 }
1381 1382
1382 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); 1383 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1383 __ bind(loop_statement.break_label()); 1384 __ bind(loop_statement.break_label());
1384 decrement_loop_depth(); 1385 decrement_loop_depth();
1385 } 1386 }
1386 1387
1387 1388
1389 void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) {
1390 Comment cmnt(masm_, "[ ForOfStatement");
1391 SetStatementPosition(stmt);
1392
1393 Iteration loop_statement(this, stmt);
1394 increment_loop_depth();
1395
1396 // var iterator = iterable[Symbol.iterator]();
1397 VisitForEffect(stmt->assign_iterator());
1398
1399 // Loop entry.
1400 __ bind(loop_statement.continue_label());
1401
1402 // result = iterator.next()
1403 SetExpressionPosition(stmt->next_result());
1404 VisitForEffect(stmt->next_result());
1405
1406 // if (result.done) break;
1407 Label result_not_done;
1408 VisitForControl(stmt->result_done(), loop_statement.break_label(),
1409 &result_not_done, &result_not_done);
1410 __ bind(&result_not_done);
1411
1412 // each = result.value
1413 VisitForEffect(stmt->assign_each());
1414
1415 // Generate code for the body of the loop.
1416 Visit(stmt->body());
1417
1418 // Check stack before looping.
1419 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS);
1420 EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label());
1421 __ jmp(loop_statement.continue_label());
1422
1423 // Exit and decrement the loop depth.
1424 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
1425 __ bind(loop_statement.break_label());
1426 decrement_loop_depth();
1427 }
1428
1429
1388 void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) { 1430 void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1389 Comment cmnt(masm_, "[ TryCatchStatement"); 1431 Comment cmnt(masm_, "[ TryCatchStatement");
1390 SetStatementPosition(stmt); 1432 SetStatementPosition(stmt);
1391 // The try block adds a handler to the exception handler chain before 1433 // The try block adds a handler to the exception handler chain before
1392 // entering, and removes it again when exiting normally. If an exception 1434 // entering, and removes it again when exiting normally. If an exception
1393 // is thrown during execution of the try block, the handler is consumed 1435 // is thrown during execution of the try block, the handler is consumed
1394 // and control is passed to the catch block with the exception in the 1436 // and control is passed to the catch block with the exception in the
1395 // result register. 1437 // result register.
1396 1438
1397 Label try_entry, handler_entry, exit; 1439 Label try_entry, handler_entry, exit;
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 } 1793 }
1752 return true; 1794 return true;
1753 } 1795 }
1754 #endif // DEBUG 1796 #endif // DEBUG
1755 1797
1756 1798
1757 #undef __ 1799 #undef __
1758 1800
1759 1801
1760 } } // namespace v8::internal 1802 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ia32/full-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698