OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 | 1487 |
1488 // The break target may be already bound (by the condition), or there | 1488 // The break target may be already bound (by the condition), or there |
1489 // may not be a valid frame. Bind it only if needed. | 1489 // may not be a valid frame. Bind it only if needed. |
1490 if (node->break_target()->is_linked()) { | 1490 if (node->break_target()->is_linked()) { |
1491 node->break_target()->Bind(); | 1491 node->break_target()->Bind(); |
1492 } | 1492 } |
1493 DecrementLoopNesting(); | 1493 DecrementLoopNesting(); |
1494 } | 1494 } |
1495 | 1495 |
1496 | 1496 |
| 1497 void CodeGenerator::SetTypeForStackSlot(Slot* slot, TypeInfo info) { |
| 1498 ASSERT(slot->type() == Slot::LOCAL || slot->type() == Slot::PARAMETER); |
| 1499 if (slot->type() == Slot::LOCAL) { |
| 1500 frame_->SetTypeForLocalAt(slot->index(), info); |
| 1501 } else { |
| 1502 frame_->SetTypeForParamAt(slot->index(), info); |
| 1503 } |
| 1504 if (FLAG_debug_code && info.IsSmi()) { |
| 1505 if (slot->type() == Slot::LOCAL) { |
| 1506 frame_->PushLocalAt(slot->index()); |
| 1507 } else { |
| 1508 frame_->PushParameterAt(slot->index()); |
| 1509 } |
| 1510 Result var = frame_->Pop(); |
| 1511 var.ToRegister(); |
| 1512 __ AbortIfNotSmi(var.reg(), "Non-smi value in smi-typed stack slot."); |
| 1513 } |
| 1514 } |
| 1515 |
| 1516 |
1497 void CodeGenerator::VisitForStatement(ForStatement* node) { | 1517 void CodeGenerator::VisitForStatement(ForStatement* node) { |
1498 ASSERT(!in_spilled_code()); | 1518 ASSERT(!in_spilled_code()); |
1499 Comment cmnt(masm_, "[ ForStatement"); | 1519 Comment cmnt(masm_, "[ ForStatement"); |
1500 CodeForStatementPosition(node); | 1520 CodeForStatementPosition(node); |
1501 | 1521 |
1502 // Compile the init expression if present. | 1522 // Compile the init expression if present. |
1503 if (node->init() != NULL) { | 1523 if (node->init() != NULL) { |
1504 Visit(node->init()); | 1524 Visit(node->init()); |
1505 } | 1525 } |
1506 | 1526 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 body.Bind(); | 1600 body.Bind(); |
1581 } | 1601 } |
1582 break; | 1602 break; |
1583 } | 1603 } |
1584 case ALWAYS_FALSE: | 1604 case ALWAYS_FALSE: |
1585 UNREACHABLE(); | 1605 UNREACHABLE(); |
1586 break; | 1606 break; |
1587 } | 1607 } |
1588 | 1608 |
1589 CheckStack(); // TODO(1222600): ignore if body contains calls. | 1609 CheckStack(); // TODO(1222600): ignore if body contains calls. |
| 1610 |
| 1611 // We know that the loop index is a smi if it is not modified in the |
| 1612 // loop body and it is checked against a constant limit in the loop |
| 1613 // condition. In this case, we reset the static type information of the |
| 1614 // loop index to smi before compiling the body, the update expression, and |
| 1615 // the bottom check of the loop condition. |
| 1616 if (node->is_fast_smi_loop()) { |
| 1617 // Set number type of the loop variable to smi. |
| 1618 SetTypeForStackSlot(node->loop_variable()->slot(), TypeInfo::Smi()); |
| 1619 } |
| 1620 |
1590 Visit(node->body()); | 1621 Visit(node->body()); |
1591 | 1622 |
1592 // If there is an update expression, compile it if necessary. | 1623 // If there is an update expression, compile it if necessary. |
1593 if (node->next() != NULL) { | 1624 if (node->next() != NULL) { |
1594 if (node->continue_target()->is_linked()) { | 1625 if (node->continue_target()->is_linked()) { |
1595 node->continue_target()->Bind(); | 1626 node->continue_target()->Bind(); |
1596 } | 1627 } |
1597 | 1628 |
1598 // Control can reach the update by falling out of the body or by a | 1629 // Control can reach the update by falling out of the body or by a |
1599 // continue. | 1630 // continue. |
1600 if (has_valid_frame()) { | 1631 if (has_valid_frame()) { |
1601 // Record the source position of the statement as this code which | 1632 // Record the source position of the statement as this code which |
1602 // is after the code for the body actually belongs to the loop | 1633 // is after the code for the body actually belongs to the loop |
1603 // statement and not the body. | 1634 // statement and not the body. |
1604 CodeForStatementPosition(node); | 1635 CodeForStatementPosition(node); |
1605 Visit(node->next()); | 1636 Visit(node->next()); |
1606 } | 1637 } |
1607 } | 1638 } |
1608 | 1639 |
| 1640 // Set the type of the loop variable to smi before compiling the test |
| 1641 // expression if we are in a fast smi loop condition. |
| 1642 if (node->is_fast_smi_loop() && has_valid_frame()) { |
| 1643 // Set number type of the loop variable to smi. |
| 1644 SetTypeForStackSlot(node->loop_variable()->slot(), TypeInfo::Smi()); |
| 1645 } |
| 1646 |
1609 // Based on the condition analysis, compile the backward jump as | 1647 // Based on the condition analysis, compile the backward jump as |
1610 // necessary. | 1648 // necessary. |
1611 switch (info) { | 1649 switch (info) { |
1612 case ALWAYS_TRUE: | 1650 case ALWAYS_TRUE: |
1613 if (has_valid_frame()) { | 1651 if (has_valid_frame()) { |
1614 if (node->next() == NULL) { | 1652 if (node->next() == NULL) { |
1615 node->continue_target()->Jump(); | 1653 node->continue_target()->Jump(); |
1616 } else { | 1654 } else { |
1617 loop.Jump(); | 1655 loop.Jump(); |
1618 } | 1656 } |
(...skipping 8547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10166 // Call the function from C++. | 10204 // Call the function from C++. |
10167 return FUNCTION_CAST<ModuloFunction>(buffer); | 10205 return FUNCTION_CAST<ModuloFunction>(buffer); |
10168 } | 10206 } |
10169 | 10207 |
10170 #endif | 10208 #endif |
10171 | 10209 |
10172 | 10210 |
10173 #undef __ | 10211 #undef __ |
10174 | 10212 |
10175 } } // namespace v8::internal | 10213 } } // namespace v8::internal |
OLD | NEW |