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 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex); | 748 __ CompareRoot(r1, Heap::kCatchContextMapRootIndex); |
749 __ Check(ne, kDeclarationInCatchContext); | 749 __ Check(ne, kDeclarationInCatchContext); |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
753 | 753 |
754 void FullCodeGenerator::VisitVariableDeclaration( | 754 void FullCodeGenerator::VisitVariableDeclaration( |
755 VariableDeclaration* declaration) { | 755 VariableDeclaration* declaration) { |
756 VariableProxy* proxy = declaration->proxy(); | 756 VariableProxy* proxy = declaration->proxy(); |
757 Variable* variable = proxy->var(); | 757 Variable* variable = proxy->var(); |
| 758 DCHECK(!variable->binding_needs_init()); |
758 switch (variable->location()) { | 759 switch (variable->location()) { |
759 case VariableLocation::UNALLOCATED: { | 760 case VariableLocation::UNALLOCATED: { |
760 DCHECK(!variable->binding_needs_init()); | |
761 globals_->Add(variable->name(), zone()); | 761 globals_->Add(variable->name(), zone()); |
762 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); | 762 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); |
763 DCHECK(!slot.IsInvalid()); | 763 DCHECK(!slot.IsInvalid()); |
764 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); | 764 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); |
765 globals_->Add(isolate()->factory()->undefined_value(), zone()); | 765 globals_->Add(isolate()->factory()->undefined_value(), zone()); |
766 break; | 766 break; |
767 } | 767 } |
768 case VariableLocation::PARAMETER: | 768 case VariableLocation::PARAMETER: |
769 case VariableLocation::LOCAL: | 769 case VariableLocation::LOCAL: |
770 if (variable->binding_needs_init()) { | |
771 Comment cmnt(masm_, "[ VariableDeclaration"); | |
772 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); | |
773 __ str(r0, StackOperand(variable)); | |
774 } | |
775 break; | |
776 | |
777 case VariableLocation::CONTEXT: | 770 case VariableLocation::CONTEXT: |
778 if (variable->binding_needs_init()) { | |
779 Comment cmnt(masm_, "[ VariableDeclaration"); | |
780 EmitDebugCheckDeclarationContext(variable); | |
781 __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); | |
782 __ str(r0, ContextMemOperand(cp, variable->index())); | |
783 // No write barrier since the_hole_value is in old space. | |
784 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); | |
785 } | |
786 break; | 771 break; |
787 | 772 |
788 case VariableLocation::LOOKUP: | 773 case VariableLocation::LOOKUP: |
789 case VariableLocation::MODULE: | 774 case VariableLocation::MODULE: |
790 UNREACHABLE(); | 775 UNREACHABLE(); |
791 } | 776 } |
792 } | 777 } |
793 | 778 |
794 | 779 |
795 void FullCodeGenerator::VisitFunctionDeclaration( | 780 void FullCodeGenerator::VisitFunctionDeclaration( |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 MemOperand(sp, offset * kPointerSize)); | 1125 MemOperand(sp, offset * kPointerSize)); |
1141 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); | 1126 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); |
1142 } | 1127 } |
1143 | 1128 |
1144 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, | 1129 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, |
1145 TypeofMode typeof_mode) { | 1130 TypeofMode typeof_mode) { |
1146 // Record position before possible IC call. | 1131 // Record position before possible IC call. |
1147 SetExpressionPosition(proxy); | 1132 SetExpressionPosition(proxy); |
1148 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); | 1133 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); |
1149 Variable* var = proxy->var(); | 1134 Variable* var = proxy->var(); |
| 1135 DCHECK(!var->binding_needs_init()); |
1150 | 1136 |
1151 // Two cases: global variables and all other types of variables. | 1137 // Two cases: global variables and all other types of variables. |
1152 switch (var->location()) { | 1138 switch (var->location()) { |
1153 case VariableLocation::UNALLOCATED: { | 1139 case VariableLocation::UNALLOCATED: { |
1154 Comment cmnt(masm_, "[ Global variable"); | 1140 Comment cmnt(masm_, "[ Global variable"); |
1155 EmitGlobalVariableLoad(proxy, typeof_mode); | 1141 EmitGlobalVariableLoad(proxy, typeof_mode); |
1156 context()->Plug(r0); | 1142 context()->Plug(r0); |
1157 break; | 1143 break; |
1158 } | 1144 } |
1159 | 1145 |
1160 case VariableLocation::PARAMETER: | 1146 case VariableLocation::PARAMETER: |
1161 case VariableLocation::LOCAL: | 1147 case VariableLocation::LOCAL: |
1162 case VariableLocation::CONTEXT: { | 1148 case VariableLocation::CONTEXT: { |
1163 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | 1149 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); |
1164 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | 1150 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
1165 : "[ Stack variable"); | 1151 : "[ Stack variable"); |
1166 if (proxy->hole_check_mode() == HoleCheckMode::kRequired) { | |
1167 // Throw a reference error when using an uninitialized let/const | |
1168 // binding in harmony mode. | |
1169 Label done; | |
1170 GetVar(r0, var); | |
1171 __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); | |
1172 __ b(ne, &done); | |
1173 __ mov(r0, Operand(var->name())); | |
1174 __ push(r0); | |
1175 __ CallRuntime(Runtime::kThrowReferenceError); | |
1176 __ bind(&done); | |
1177 context()->Plug(r0); | |
1178 break; | |
1179 } | |
1180 context()->Plug(var); | 1152 context()->Plug(var); |
1181 break; | 1153 break; |
1182 } | 1154 } |
1183 | 1155 |
1184 case VariableLocation::LOOKUP: | 1156 case VariableLocation::LOOKUP: |
1185 case VariableLocation::MODULE: | 1157 case VariableLocation::MODULE: |
1186 UNREACHABLE(); | 1158 UNREACHABLE(); |
1187 } | 1159 } |
1188 } | 1160 } |
1189 | 1161 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 } else { | 1457 } else { |
1486 VisitForAccumulatorValue(expr->value()); | 1458 VisitForAccumulatorValue(expr->value()); |
1487 } | 1459 } |
1488 | 1460 |
1489 SetExpressionPosition(expr); | 1461 SetExpressionPosition(expr); |
1490 | 1462 |
1491 // Store the value. | 1463 // Store the value. |
1492 switch (assign_type) { | 1464 switch (assign_type) { |
1493 case VARIABLE: { | 1465 case VARIABLE: { |
1494 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 1466 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
1495 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(), | 1467 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot()); |
1496 proxy->hole_check_mode()); | |
1497 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 1468 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
1498 context()->Plug(r0); | 1469 context()->Plug(r0); |
1499 break; | 1470 break; |
1500 } | 1471 } |
1501 case NAMED_PROPERTY: | 1472 case NAMED_PROPERTY: |
1502 EmitNamedPropertyAssignment(expr); | 1473 EmitNamedPropertyAssignment(expr); |
1503 break; | 1474 break; |
1504 case KEYED_PROPERTY: | 1475 case KEYED_PROPERTY: |
1505 EmitKeyedPropertyAssignment(expr); | 1476 EmitKeyedPropertyAssignment(expr); |
1506 break; | 1477 break; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1668 FeedbackVectorSlot slot) { | 1639 FeedbackVectorSlot slot) { |
1669 DCHECK(expr->IsValidReferenceExpressionOrThis()); | 1640 DCHECK(expr->IsValidReferenceExpressionOrThis()); |
1670 | 1641 |
1671 Property* prop = expr->AsProperty(); | 1642 Property* prop = expr->AsProperty(); |
1672 LhsKind assign_type = Property::GetAssignType(prop); | 1643 LhsKind assign_type = Property::GetAssignType(prop); |
1673 | 1644 |
1674 switch (assign_type) { | 1645 switch (assign_type) { |
1675 case VARIABLE: { | 1646 case VARIABLE: { |
1676 VariableProxy* proxy = expr->AsVariableProxy(); | 1647 VariableProxy* proxy = expr->AsVariableProxy(); |
1677 EffectContext context(this); | 1648 EffectContext context(this); |
1678 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot, | 1649 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot); |
1679 proxy->hole_check_mode()); | |
1680 break; | 1650 break; |
1681 } | 1651 } |
1682 case NAMED_PROPERTY: { | 1652 case NAMED_PROPERTY: { |
1683 PushOperand(r0); // Preserve value. | 1653 PushOperand(r0); // Preserve value. |
1684 VisitForAccumulatorValue(prop->obj()); | 1654 VisitForAccumulatorValue(prop->obj()); |
1685 __ Move(StoreDescriptor::ReceiverRegister(), r0); | 1655 __ Move(StoreDescriptor::ReceiverRegister(), r0); |
1686 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. | 1656 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. |
1687 CallStoreIC(slot, prop->key()->AsLiteral()->value()); | 1657 CallStoreIC(slot, prop->key()->AsLiteral()->value()); |
1688 break; | 1658 break; |
1689 } | 1659 } |
(...skipping 22 matching lines...) Expand all Loading... |
1712 if (var->IsContextSlot()) { | 1682 if (var->IsContextSlot()) { |
1713 // RecordWrite may destroy all its register arguments. | 1683 // RecordWrite may destroy all its register arguments. |
1714 __ mov(r3, result_register()); | 1684 __ mov(r3, result_register()); |
1715 int offset = Context::SlotOffset(var->index()); | 1685 int offset = Context::SlotOffset(var->index()); |
1716 __ RecordWriteContextSlot( | 1686 __ RecordWriteContextSlot( |
1717 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); | 1687 r1, offset, r3, r2, kLRHasBeenSaved, kDontSaveFPRegs); |
1718 } | 1688 } |
1719 } | 1689 } |
1720 | 1690 |
1721 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | 1691 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, |
1722 FeedbackVectorSlot slot, | 1692 FeedbackVectorSlot slot) { |
1723 HoleCheckMode hole_check_mode) { | 1693 DCHECK(!var->binding_needs_init()); |
1724 if (var->IsUnallocated()) { | 1694 if (var->IsUnallocated()) { |
1725 // Global var, const, or let. | 1695 // Global var, const, or let. |
1726 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); | 1696 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); |
1727 CallStoreIC(slot, var->name()); | 1697 CallStoreIC(slot, var->name()); |
1728 | 1698 |
1729 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { | 1699 } else if (var->mode() == CONST && op != Token::INIT) { |
1730 DCHECK(!var->IsLookupSlot()); | 1700 if (var->throw_on_const_assignment(language_mode())) { |
1731 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
1732 MemOperand location = VarOperand(var, r1); | |
1733 // Perform an initialization check for lexically declared variables. | |
1734 if (hole_check_mode == HoleCheckMode::kRequired) { | |
1735 Label assign; | |
1736 __ ldr(r3, location); | |
1737 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); | |
1738 __ b(ne, &assign); | |
1739 __ mov(r3, Operand(var->name())); | |
1740 __ push(r3); | |
1741 __ CallRuntime(Runtime::kThrowReferenceError); | |
1742 __ bind(&assign); | |
1743 } | |
1744 if (var->mode() != CONST) { | |
1745 EmitStoreToStackLocalOrContextSlot(var, location); | |
1746 } else if (var->throw_on_const_assignment(language_mode())) { | |
1747 __ CallRuntime(Runtime::kThrowConstAssignError); | 1701 __ CallRuntime(Runtime::kThrowConstAssignError); |
1748 } | 1702 } |
1749 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { | |
1750 // Initializing assignment to const {this} needs a write barrier. | |
1751 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | |
1752 Label uninitialized_this; | |
1753 MemOperand location = VarOperand(var, r1); | |
1754 __ ldr(r3, location); | |
1755 __ CompareRoot(r3, Heap::kTheHoleValueRootIndex); | |
1756 __ b(eq, &uninitialized_this); | |
1757 __ mov(r0, Operand(var->name())); | |
1758 __ Push(r0); | |
1759 __ CallRuntime(Runtime::kThrowReferenceError); | |
1760 __ bind(&uninitialized_this); | |
1761 EmitStoreToStackLocalOrContextSlot(var, location); | |
1762 | |
1763 } else { | 1703 } else { |
1764 DCHECK(var->mode() != CONST || op == Token::INIT); | 1704 DCHECK(!var->is_this()); |
1765 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 1705 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
1766 DCHECK(!var->IsLookupSlot()); | 1706 DCHECK(!var->IsLookupSlot()); |
1767 // Assignment to var or initializing assignment to let/const in harmony | |
1768 // mode. | |
1769 MemOperand location = VarOperand(var, r1); | 1707 MemOperand location = VarOperand(var, r1); |
1770 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { | |
1771 // Check for an uninitialized let binding. | |
1772 __ ldr(r2, location); | |
1773 __ CompareRoot(r2, Heap::kTheHoleValueRootIndex); | |
1774 __ Check(eq, kLetBindingReInitialization); | |
1775 } | |
1776 EmitStoreToStackLocalOrContextSlot(var, location); | 1708 EmitStoreToStackLocalOrContextSlot(var, location); |
1777 } | 1709 } |
1778 } | 1710 } |
1779 | 1711 |
1780 | 1712 |
1781 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { | 1713 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
1782 // Assignment to a property, using a named store IC. | 1714 // Assignment to a property, using a named store IC. |
1783 Property* prop = expr->target()->AsProperty(); | 1715 Property* prop = expr->target()->AsProperty(); |
1784 DCHECK(prop != NULL); | 1716 DCHECK(prop != NULL); |
1785 DCHECK(prop->key()->IsLiteral()); | 1717 DCHECK(prop->key()->IsLiteral()); |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 CallIC(code, expr->CountBinOpFeedbackId()); | 2429 CallIC(code, expr->CountBinOpFeedbackId()); |
2498 patch_site.EmitPatchInfo(); | 2430 patch_site.EmitPatchInfo(); |
2499 __ bind(&done); | 2431 __ bind(&done); |
2500 | 2432 |
2501 // Store the value returned in r0. | 2433 // Store the value returned in r0. |
2502 switch (assign_type) { | 2434 switch (assign_type) { |
2503 case VARIABLE: { | 2435 case VARIABLE: { |
2504 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2436 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
2505 if (expr->is_postfix()) { | 2437 if (expr->is_postfix()) { |
2506 { EffectContext context(this); | 2438 { EffectContext context(this); |
2507 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), | 2439 EmitVariableAssignment(proxy->var(), Token::ASSIGN, |
2508 proxy->hole_check_mode()); | 2440 expr->CountSlot()); |
2509 PrepareForBailoutForId(expr->AssignmentId(), | 2441 PrepareForBailoutForId(expr->AssignmentId(), |
2510 BailoutState::TOS_REGISTER); | 2442 BailoutState::TOS_REGISTER); |
2511 context.Plug(r0); | 2443 context.Plug(r0); |
2512 } | 2444 } |
2513 // For all contexts except EffectConstant We have the result on | 2445 // For all contexts except EffectConstant We have the result on |
2514 // top of the stack. | 2446 // top of the stack. |
2515 if (!context()->IsEffect()) { | 2447 if (!context()->IsEffect()) { |
2516 context()->PlugTOS(); | 2448 context()->PlugTOS(); |
2517 } | 2449 } |
2518 } else { | 2450 } else { |
2519 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), | 2451 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot()); |
2520 proxy->hole_check_mode()); | |
2521 PrepareForBailoutForId(expr->AssignmentId(), | 2452 PrepareForBailoutForId(expr->AssignmentId(), |
2522 BailoutState::TOS_REGISTER); | 2453 BailoutState::TOS_REGISTER); |
2523 context()->Plug(r0); | 2454 context()->Plug(r0); |
2524 } | 2455 } |
2525 break; | 2456 break; |
2526 } | 2457 } |
2527 case NAMED_PROPERTY: { | 2458 case NAMED_PROPERTY: { |
2528 PopOperand(StoreDescriptor::ReceiverRegister()); | 2459 PopOperand(StoreDescriptor::ReceiverRegister()); |
2529 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); | 2460 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); |
2530 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 2461 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2923 DCHECK(interrupt_address == | 2854 DCHECK(interrupt_address == |
2924 isolate->builtins()->OnStackReplacement()->entry()); | 2855 isolate->builtins()->OnStackReplacement()->entry()); |
2925 return ON_STACK_REPLACEMENT; | 2856 return ON_STACK_REPLACEMENT; |
2926 } | 2857 } |
2927 | 2858 |
2928 | 2859 |
2929 } // namespace internal | 2860 } // namespace internal |
2930 } // namespace v8 | 2861 } // namespace v8 |
2931 | 2862 |
2932 #endif // V8_TARGET_ARCH_ARM | 2863 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |