OLD | NEW |
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 #if V8_TARGET_ARCH_ARM | 5 #if V8_TARGET_ARCH_ARM |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex); | 746 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex); |
747 __ Check(ne, kDeclarationInCatchContext); | 747 __ Check(ne, kDeclarationInCatchContext); |
748 } | 748 } |
749 } | 749 } |
750 | 750 |
751 | 751 |
752 void FullCodeGenerator::VisitVariableDeclaration( | 752 void FullCodeGenerator::VisitVariableDeclaration( |
753 VariableDeclaration* declaration) { | 753 VariableDeclaration* declaration) { |
754 VariableProxy* proxy = declaration->proxy(); | 754 VariableProxy* proxy = declaration->proxy(); |
755 Variable* variable = proxy->var(); | 755 Variable* variable = proxy->var(); |
756 DCHECK(!variable->binding_needs_init()); | |
757 switch (variable->location()) { | 756 switch (variable->location()) { |
758 case VariableLocation::UNALLOCATED: { | 757 case VariableLocation::UNALLOCATED: { |
| 758 DCHECK(!variable->binding_needs_init()); |
759 globals_->Add(variable->name(), zone()); | 759 globals_->Add(variable->name(), zone()); |
760 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); | 760 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); |
761 DCHECK(!slot.IsInvalid()); | 761 DCHECK(!slot.IsInvalid()); |
762 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); | 762 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); |
763 globals_->Add(isolate()->factory()->undefined_value(), zone()); | 763 globals_->Add(isolate()->factory()->undefined_value(), zone()); |
764 break; | 764 break; |
765 } | 765 } |
766 case VariableLocation::PARAMETER: | 766 case VariableLocation::PARAMETER: |
767 case VariableLocation::LOCAL: | 767 case VariableLocation::LOCAL: |
| 768 if (variable->binding_needs_init()) { |
| 769 Comment cmnt(masm_, "[ VariableDeclaration"); |
| 770 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
| 771 __ str(r0, StackOperand(variable)); |
| 772 } |
| 773 break; |
| 774 |
768 case VariableLocation::CONTEXT: | 775 case VariableLocation::CONTEXT: |
| 776 if (variable->binding_needs_init()) { |
| 777 Comment cmnt(masm_, "[ VariableDeclaration"); |
| 778 EmitDebugCheckDeclarationContext(variable); |
| 779 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
| 780 __ str(r0, ContextMemOperand(cp, variable->index())); |
| 781 // No write barrier since the_hole_value is in old space. |
| 782 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); |
| 783 } |
769 break; | 784 break; |
770 | 785 |
771 case VariableLocation::LOOKUP: | 786 case VariableLocation::LOOKUP: |
772 case VariableLocation::MODULE: | 787 case VariableLocation::MODULE: |
773 UNREACHABLE(); | 788 UNREACHABLE(); |
774 } | 789 } |
775 } | 790 } |
776 | 791 |
777 | 792 |
778 void FullCodeGenerator::VisitFunctionDeclaration( | 793 void FullCodeGenerator::VisitFunctionDeclaration( |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 MemOperand(sp, offset * kPointerSize)); | 1138 MemOperand(sp, offset * kPointerSize)); |
1124 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); | 1139 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); |
1125 } | 1140 } |
1126 | 1141 |
1127 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, | 1142 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, |
1128 TypeofMode typeof_mode) { | 1143 TypeofMode typeof_mode) { |
1129 // Record position before possible IC call. | 1144 // Record position before possible IC call. |
1130 SetExpressionPosition(proxy); | 1145 SetExpressionPosition(proxy); |
1131 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); | 1146 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); |
1132 Variable* var = proxy->var(); | 1147 Variable* var = proxy->var(); |
1133 DCHECK(!var->binding_needs_init()); | |
1134 | 1148 |
1135 // Two cases: global variables and all other types of variables. | 1149 // Two cases: global variables and all other types of variables. |
1136 switch (var->location()) { | 1150 switch (var->location()) { |
1137 case VariableLocation::UNALLOCATED: { | 1151 case VariableLocation::UNALLOCATED: { |
1138 Comment cmnt(masm_, "[ Global variable"); | 1152 Comment cmnt(masm_, "[ Global variable"); |
1139 EmitGlobalVariableLoad(proxy, typeof_mode); | 1153 EmitGlobalVariableLoad(proxy, typeof_mode); |
1140 context()->Plug(r0); | 1154 context()->Plug(r0); |
1141 break; | 1155 break; |
1142 } | 1156 } |
1143 | 1157 |
1144 case VariableLocation::PARAMETER: | 1158 case VariableLocation::PARAMETER: |
1145 case VariableLocation::LOCAL: | 1159 case VariableLocation::LOCAL: |
1146 case VariableLocation::CONTEXT: { | 1160 case VariableLocation::CONTEXT: { |
1147 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | 1161 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); |
1148 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | 1162 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
1149 : "[ Stack variable"); | 1163 : "[ Stack variable"); |
| 1164 if (proxy->hole_check_mode() == HoleCheckMode::kRequired) { |
| 1165 // Throw a reference error when using an uninitialized let/const |
| 1166 // binding in harmony mode. |
| 1167 Label done; |
| 1168 GetVar(r0, var); |
| 1169 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); |
| 1170 __ b(ne, &done); |
| 1171 __ mov(r0, Operand(var->name())); |
| 1172 __ push(r0); |
| 1173 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1174 __ bind(&done); |
| 1175 context()->Plug(r0); |
| 1176 break; |
| 1177 } |
1150 context()->Plug(var); | 1178 context()->Plug(var); |
1151 break; | 1179 break; |
1152 } | 1180 } |
1153 | 1181 |
1154 case VariableLocation::LOOKUP: | 1182 case VariableLocation::LOOKUP: |
1155 case VariableLocation::MODULE: | 1183 case VariableLocation::MODULE: |
1156 UNREACHABLE(); | 1184 UNREACHABLE(); |
1157 } | 1185 } |
1158 } | 1186 } |
1159 | 1187 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 } else { | 1486 } else { |
1459 VisitForAccumulatorValue(expr->value()); | 1487 VisitForAccumulatorValue(expr->value()); |
1460 } | 1488 } |
1461 | 1489 |
1462 SetExpressionPosition(expr); | 1490 SetExpressionPosition(expr); |
1463 | 1491 |
1464 // Store the value. | 1492 // Store the value. |
1465 switch (assign_type) { | 1493 switch (assign_type) { |
1466 case VARIABLE: { | 1494 case VARIABLE: { |
1467 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 1495 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
1468 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot()); | 1496 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(), |
| 1497 proxy->hole_check_mode()); |
1469 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 1498 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
1470 context()->Plug(r0); | 1499 context()->Plug(r0); |
1471 break; | 1500 break; |
1472 } | 1501 } |
1473 case NAMED_PROPERTY: | 1502 case NAMED_PROPERTY: |
1474 EmitNamedPropertyAssignment(expr); | 1503 EmitNamedPropertyAssignment(expr); |
1475 break; | 1504 break; |
1476 case KEYED_PROPERTY: | 1505 case KEYED_PROPERTY: |
1477 EmitKeyedPropertyAssignment(expr); | 1506 EmitKeyedPropertyAssignment(expr); |
1478 break; | 1507 break; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 FeedbackVectorSlot slot) { | 1669 FeedbackVectorSlot slot) { |
1641 DCHECK(expr->IsValidReferenceExpressionOrThis()); | 1670 DCHECK(expr->IsValidReferenceExpressionOrThis()); |
1642 | 1671 |
1643 Property* prop = expr->AsProperty(); | 1672 Property* prop = expr->AsProperty(); |
1644 LhsKind assign_type = Property::GetAssignType(prop); | 1673 LhsKind assign_type = Property::GetAssignType(prop); |
1645 | 1674 |
1646 switch (assign_type) { | 1675 switch (assign_type) { |
1647 case VARIABLE: { | 1676 case VARIABLE: { |
1648 VariableProxy* proxy = expr->AsVariableProxy(); | 1677 VariableProxy* proxy = expr->AsVariableProxy(); |
1649 EffectContext context(this); | 1678 EffectContext context(this); |
1650 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot); | 1679 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot, |
| 1680 proxy->hole_check_mode()); |
1651 break; | 1681 break; |
1652 } | 1682 } |
1653 case NAMED_PROPERTY: { | 1683 case NAMED_PROPERTY: { |
1654 PushOperand(r0); // Preserve value. | 1684 PushOperand(r0); // Preserve value. |
1655 VisitForAccumulatorValue(prop->obj()); | 1685 VisitForAccumulatorValue(prop->obj()); |
1656 __ Move(StoreDescriptor::ReceiverRegister(), r0); | 1686 __ Move(StoreDescriptor::ReceiverRegister(), r0); |
1657 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. | 1687 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. |
1658 CallStoreIC(slot, prop->key()->AsLiteral()->value()); | 1688 CallStoreIC(slot, prop->key()->AsLiteral()->value()); |
1659 break; | 1689 break; |
1660 } | 1690 } |
(...skipping 22 matching lines...) Expand all Loading... |
1683 if (var->IsContextSlot()) { | 1713 if (var->IsContextSlot()) { |
1684 // RecordWrite may destroy all its register arguments. | 1714 // RecordWrite may destroy all its register arguments. |
1685 __ mov(r3, result_register()); | 1715 __ mov(r3, result_register()); |
1686 int offset = Context::SlotOffset(var->index()); | 1716 int offset = Context::SlotOffset(var->index()); |
1687 __ RecordWriteContextSlot( | 1717 __ RecordWriteContextSlot( |
1688 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); | 1718 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); |
1689 } | 1719 } |
1690 } | 1720 } |
1691 | 1721 |
1692 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | 1722 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, |
1693 FeedbackVectorSlot slot) { | 1723 FeedbackVectorSlot slot, |
1694 DCHECK(!var->binding_needs_init()); | 1724 HoleCheckMode hole_check_mode) { |
1695 if (var->IsUnallocated()) { | 1725 if (var->IsUnallocated()) { |
1696 // Global var, const, or let. | 1726 // Global var, const, or let. |
1697 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); | 1727 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); |
1698 CallStoreIC(slot, var->name()); | 1728 CallStoreIC(slot, var->name()); |
1699 | 1729 |
1700 } else if (var->mode() == CONST && op != Token::INIT) { | 1730 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { |
1701 if (var->throw_on_const_assignment(language_mode())) { | 1731 DCHECK(!var->IsLookupSlot()); |
| 1732 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 1733 MemOperand location = VarOperand(var, r1); |
| 1734 // Perform an initialization check for lexically declared variables. |
| 1735 if (hole_check_mode == HoleCheckMode::kRequired) { |
| 1736 Label assign; |
| 1737 __ ldr(r3, location); |
| 1738 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); |
| 1739 __ b(ne, &assign); |
| 1740 __ mov(r3, Operand(var->name())); |
| 1741 __ push(r3); |
| 1742 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1743 __ bind(&assign); |
| 1744 } |
| 1745 if (var->mode() != CONST) { |
| 1746 EmitStoreToStackLocalOrContextSlot(var, location); |
| 1747 } else if (var->throw_on_const_assignment(language_mode())) { |
1702 __ CallRuntime(Runtime::kThrowConstAssignError); | 1748 __ CallRuntime(Runtime::kThrowConstAssignError); |
1703 } | 1749 } |
| 1750 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { |
| 1751 // Initializing assignment to const {this} needs a write barrier. |
| 1752 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 1753 Label uninitialized_this; |
| 1754 MemOperand location = VarOperand(var, r1); |
| 1755 __ ldr(r3, location); |
| 1756 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); |
| 1757 __ b(eq, &uninitialized_this); |
| 1758 __ mov(r0, Operand(var->name())); |
| 1759 __ Push(r0); |
| 1760 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1761 __ bind(&uninitialized_this); |
| 1762 EmitStoreToStackLocalOrContextSlot(var, location); |
| 1763 |
1704 } else { | 1764 } else { |
1705 DCHECK(!var->is_this()); | 1765 DCHECK(var->mode() != CONST || op == Token::INIT); |
1706 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 1766 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
1707 DCHECK(!var->IsLookupSlot()); | 1767 DCHECK(!var->IsLookupSlot()); |
| 1768 // Assignment to var or initializing assignment to let/const in harmony |
| 1769 // mode. |
1708 MemOperand location = VarOperand(var, r1); | 1770 MemOperand location = VarOperand(var, r1); |
| 1771 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { |
| 1772 // Check for an uninitialized let binding. |
| 1773 __ ldr(r2, location); |
| 1774 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex); |
| 1775 __ Check(eq, kLetBindingReInitialization); |
| 1776 } |
1709 EmitStoreToStackLocalOrContextSlot(var, location); | 1777 EmitStoreToStackLocalOrContextSlot(var, location); |
1710 } | 1778 } |
1711 } | 1779 } |
1712 | 1780 |
1713 | 1781 |
1714 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { | 1782 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
1715 // Assignment to a property, using a named store IC. | 1783 // Assignment to a property, using a named store IC. |
1716 Property* prop = expr->target()->AsProperty(); | 1784 Property* prop = expr->target()->AsProperty(); |
1717 DCHECK(prop != NULL); | 1785 DCHECK(prop != NULL); |
1718 DCHECK(prop->key()->IsLiteral()); | 1786 DCHECK(prop->key()->IsLiteral()); |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2408 CallIC(code, expr->CountBinOpFeedbackId()); | 2476 CallIC(code, expr->CountBinOpFeedbackId()); |
2409 patch_site.EmitPatchInfo(); | 2477 patch_site.EmitPatchInfo(); |
2410 __ bind(&done); | 2478 __ bind(&done); |
2411 | 2479 |
2412 // Store the value returned in r0. | 2480 // Store the value returned in r0. |
2413 switch (assign_type) { | 2481 switch (assign_type) { |
2414 case VARIABLE: { | 2482 case VARIABLE: { |
2415 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2483 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
2416 if (expr->is_postfix()) { | 2484 if (expr->is_postfix()) { |
2417 { EffectContext context(this); | 2485 { EffectContext context(this); |
2418 EmitVariableAssignment(proxy->var(), Token::ASSIGN, | 2486 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), |
2419 expr->CountSlot()); | 2487 proxy->hole_check_mode()); |
2420 PrepareForBailoutForId(expr->AssignmentId(), | 2488 PrepareForBailoutForId(expr->AssignmentId(), |
2421 BailoutState::TOS_REGISTER); | 2489 BailoutState::TOS_REGISTER); |
2422 context.Plug(r0); | 2490 context.Plug(r0); |
2423 } | 2491 } |
2424 // For all contexts except EffectConstant We have the result on | 2492 // For all contexts except EffectConstant We have the result on |
2425 // top of the stack. | 2493 // top of the stack. |
2426 if (!context()->IsEffect()) { | 2494 if (!context()->IsEffect()) { |
2427 context()->PlugTOS(); | 2495 context()->PlugTOS(); |
2428 } | 2496 } |
2429 } else { | 2497 } else { |
2430 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot()); | 2498 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), |
| 2499 proxy->hole_check_mode()); |
2431 PrepareForBailoutForId(expr->AssignmentId(), | 2500 PrepareForBailoutForId(expr->AssignmentId(), |
2432 BailoutState::TOS_REGISTER); | 2501 BailoutState::TOS_REGISTER); |
2433 context()->Plug(r0); | 2502 context()->Plug(r0); |
2434 } | 2503 } |
2435 break; | 2504 break; |
2436 } | 2505 } |
2437 case NAMED_PROPERTY: { | 2506 case NAMED_PROPERTY: { |
2438 PopOperand(StoreDescriptor::ReceiverRegister()); | 2507 PopOperand(StoreDescriptor::ReceiverRegister()); |
2439 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); | 2508 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); |
2440 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 2509 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2833 DCHECK(interrupt_address == | 2902 DCHECK(interrupt_address == |
2834 isolate->builtins()->OnStackReplacement()->entry()); | 2903 isolate->builtins()->OnStackReplacement()->entry()); |
2835 return ON_STACK_REPLACEMENT; | 2904 return ON_STACK_REPLACEMENT; |
2836 } | 2905 } |
2837 | 2906 |
2838 | 2907 |
2839 } // namespace internal | 2908 } // namespace internal |
2840 } // namespace v8 | 2909 } // namespace v8 |
2841 | 2910 |
2842 #endif // V8_TARGET_ARCH_ARM | 2911 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |