| 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_IA32 | 5 #if V8_TARGET_ARCH_IA32 |
| 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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 __ cmp(ebx, isolate()->factory()->catch_context_map()); | 694 __ cmp(ebx, isolate()->factory()->catch_context_map()); |
| 695 __ Check(not_equal, kDeclarationInCatchContext); | 695 __ Check(not_equal, kDeclarationInCatchContext); |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 | 698 |
| 699 | 699 |
| 700 void FullCodeGenerator::VisitVariableDeclaration( | 700 void FullCodeGenerator::VisitVariableDeclaration( |
| 701 VariableDeclaration* declaration) { | 701 VariableDeclaration* declaration) { |
| 702 VariableProxy* proxy = declaration->proxy(); | 702 VariableProxy* proxy = declaration->proxy(); |
| 703 Variable* variable = proxy->var(); | 703 Variable* variable = proxy->var(); |
| 704 DCHECK(!variable->binding_needs_init()); | |
| 705 switch (variable->location()) { | 704 switch (variable->location()) { |
| 706 case VariableLocation::UNALLOCATED: { | 705 case VariableLocation::UNALLOCATED: { |
| 706 DCHECK(!variable->binding_needs_init()); |
| 707 globals_->Add(variable->name(), zone()); | 707 globals_->Add(variable->name(), zone()); |
| 708 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); | 708 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); |
| 709 DCHECK(!slot.IsInvalid()); | 709 DCHECK(!slot.IsInvalid()); |
| 710 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); | 710 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); |
| 711 globals_->Add(isolate()->factory()->undefined_value(), zone()); | 711 globals_->Add(isolate()->factory()->undefined_value(), zone()); |
| 712 break; | 712 break; |
| 713 } | 713 } |
| 714 case VariableLocation::PARAMETER: | 714 case VariableLocation::PARAMETER: |
| 715 case VariableLocation::LOCAL: | 715 case VariableLocation::LOCAL: |
| 716 if (variable->binding_needs_init()) { |
| 717 Comment cmnt(masm_, "[ VariableDeclaration"); |
| 718 __ mov(StackOperand(variable), |
| 719 Immediate(isolate()->factory()->the_hole_value())); |
| 720 } |
| 721 break; |
| 722 |
| 716 case VariableLocation::CONTEXT: | 723 case VariableLocation::CONTEXT: |
| 724 if (variable->binding_needs_init()) { |
| 725 Comment cmnt(masm_, "[ VariableDeclaration"); |
| 726 EmitDebugCheckDeclarationContext(variable); |
| 727 __ mov(ContextOperand(esi, variable->index()), |
| 728 Immediate(isolate()->factory()->the_hole_value())); |
| 729 // No write barrier since the hole value is in old space. |
| 730 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); |
| 731 } |
| 717 break; | 732 break; |
| 718 | 733 |
| 719 case VariableLocation::LOOKUP: | 734 case VariableLocation::LOOKUP: |
| 720 case VariableLocation::MODULE: | 735 case VariableLocation::MODULE: |
| 721 UNREACHABLE(); | 736 UNREACHABLE(); |
| 722 } | 737 } |
| 723 } | 738 } |
| 724 | 739 |
| 725 | 740 |
| 726 void FullCodeGenerator::VisitFunctionDeclaration( | 741 void FullCodeGenerator::VisitFunctionDeclaration( |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 __ mov(StoreDescriptor::ReceiverRegister(), eax); | 1065 __ mov(StoreDescriptor::ReceiverRegister(), eax); |
| 1051 __ mov(StoreDescriptor::ValueRegister(), Operand(esp, offset * kPointerSize)); | 1066 __ mov(StoreDescriptor::ValueRegister(), Operand(esp, offset * kPointerSize)); |
| 1052 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); | 1067 CallStoreIC(slot, isolate()->factory()->home_object_symbol()); |
| 1053 } | 1068 } |
| 1054 | 1069 |
| 1055 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, | 1070 void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy, |
| 1056 TypeofMode typeof_mode) { | 1071 TypeofMode typeof_mode) { |
| 1057 SetExpressionPosition(proxy); | 1072 SetExpressionPosition(proxy); |
| 1058 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); | 1073 PrepareForBailoutForId(proxy->BeforeId(), BailoutState::NO_REGISTERS); |
| 1059 Variable* var = proxy->var(); | 1074 Variable* var = proxy->var(); |
| 1060 DCHECK(!var->binding_needs_init()); | |
| 1061 | 1075 |
| 1062 // Two cases: global variables and all other types of variables. | 1076 // Two cases: global variables and all other types of variables. |
| 1063 switch (var->location()) { | 1077 switch (var->location()) { |
| 1064 case VariableLocation::UNALLOCATED: { | 1078 case VariableLocation::UNALLOCATED: { |
| 1065 Comment cmnt(masm_, "[ Global variable"); | 1079 Comment cmnt(masm_, "[ Global variable"); |
| 1066 EmitGlobalVariableLoad(proxy, typeof_mode); | 1080 EmitGlobalVariableLoad(proxy, typeof_mode); |
| 1067 context()->Plug(eax); | 1081 context()->Plug(eax); |
| 1068 break; | 1082 break; |
| 1069 } | 1083 } |
| 1070 | 1084 |
| 1071 case VariableLocation::PARAMETER: | 1085 case VariableLocation::PARAMETER: |
| 1072 case VariableLocation::LOCAL: | 1086 case VariableLocation::LOCAL: |
| 1073 case VariableLocation::CONTEXT: { | 1087 case VariableLocation::CONTEXT: { |
| 1074 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | 1088 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); |
| 1075 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | 1089 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
| 1076 : "[ Stack variable"); | 1090 : "[ Stack variable"); |
| 1091 |
| 1092 if (proxy->hole_check_mode() == HoleCheckMode::kRequired) { |
| 1093 // Throw a reference error when using an uninitialized let/const |
| 1094 // binding in harmony mode. |
| 1095 Label done; |
| 1096 GetVar(eax, var); |
| 1097 __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1098 __ j(not_equal, &done, Label::kNear); |
| 1099 __ push(Immediate(var->name())); |
| 1100 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1101 __ bind(&done); |
| 1102 context()->Plug(eax); |
| 1103 break; |
| 1104 } |
| 1077 context()->Plug(var); | 1105 context()->Plug(var); |
| 1078 break; | 1106 break; |
| 1079 } | 1107 } |
| 1080 | 1108 |
| 1081 case VariableLocation::LOOKUP: | 1109 case VariableLocation::LOOKUP: |
| 1082 case VariableLocation::MODULE: | 1110 case VariableLocation::MODULE: |
| 1083 UNREACHABLE(); | 1111 UNREACHABLE(); |
| 1084 } | 1112 } |
| 1085 } | 1113 } |
| 1086 | 1114 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 } else { | 1412 } else { |
| 1385 VisitForAccumulatorValue(expr->value()); | 1413 VisitForAccumulatorValue(expr->value()); |
| 1386 } | 1414 } |
| 1387 | 1415 |
| 1388 SetExpressionPosition(expr); | 1416 SetExpressionPosition(expr); |
| 1389 | 1417 |
| 1390 // Store the value. | 1418 // Store the value. |
| 1391 switch (assign_type) { | 1419 switch (assign_type) { |
| 1392 case VARIABLE: { | 1420 case VARIABLE: { |
| 1393 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 1421 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
| 1394 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot()); | 1422 EmitVariableAssignment(proxy->var(), expr->op(), expr->AssignmentSlot(), |
| 1423 proxy->hole_check_mode()); |
| 1395 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 1424 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
| 1396 context()->Plug(eax); | 1425 context()->Plug(eax); |
| 1397 break; | 1426 break; |
| 1398 } | 1427 } |
| 1399 case NAMED_PROPERTY: | 1428 case NAMED_PROPERTY: |
| 1400 EmitNamedPropertyAssignment(expr); | 1429 EmitNamedPropertyAssignment(expr); |
| 1401 break; | 1430 break; |
| 1402 case KEYED_PROPERTY: | 1431 case KEYED_PROPERTY: |
| 1403 EmitKeyedPropertyAssignment(expr); | 1432 EmitKeyedPropertyAssignment(expr); |
| 1404 break; | 1433 break; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 FeedbackVectorSlot slot) { | 1594 FeedbackVectorSlot slot) { |
| 1566 DCHECK(expr->IsValidReferenceExpressionOrThis()); | 1595 DCHECK(expr->IsValidReferenceExpressionOrThis()); |
| 1567 | 1596 |
| 1568 Property* prop = expr->AsProperty(); | 1597 Property* prop = expr->AsProperty(); |
| 1569 LhsKind assign_type = Property::GetAssignType(prop); | 1598 LhsKind assign_type = Property::GetAssignType(prop); |
| 1570 | 1599 |
| 1571 switch (assign_type) { | 1600 switch (assign_type) { |
| 1572 case VARIABLE: { | 1601 case VARIABLE: { |
| 1573 VariableProxy* proxy = expr->AsVariableProxy(); | 1602 VariableProxy* proxy = expr->AsVariableProxy(); |
| 1574 EffectContext context(this); | 1603 EffectContext context(this); |
| 1575 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot); | 1604 EmitVariableAssignment(proxy->var(), Token::ASSIGN, slot, |
| 1605 proxy->hole_check_mode()); |
| 1576 break; | 1606 break; |
| 1577 } | 1607 } |
| 1578 case NAMED_PROPERTY: { | 1608 case NAMED_PROPERTY: { |
| 1579 PushOperand(eax); // Preserve value. | 1609 PushOperand(eax); // Preserve value. |
| 1580 VisitForAccumulatorValue(prop->obj()); | 1610 VisitForAccumulatorValue(prop->obj()); |
| 1581 __ Move(StoreDescriptor::ReceiverRegister(), eax); | 1611 __ Move(StoreDescriptor::ReceiverRegister(), eax); |
| 1582 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. | 1612 PopOperand(StoreDescriptor::ValueRegister()); // Restore value. |
| 1583 CallStoreIC(slot, prop->key()->AsLiteral()->value()); | 1613 CallStoreIC(slot, prop->key()->AsLiteral()->value()); |
| 1584 break; | 1614 break; |
| 1585 } | 1615 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1606 Variable* var, MemOperand location) { | 1636 Variable* var, MemOperand location) { |
| 1607 __ mov(location, eax); | 1637 __ mov(location, eax); |
| 1608 if (var->IsContextSlot()) { | 1638 if (var->IsContextSlot()) { |
| 1609 __ mov(edx, eax); | 1639 __ mov(edx, eax); |
| 1610 int offset = Context::SlotOffset(var->index()); | 1640 int offset = Context::SlotOffset(var->index()); |
| 1611 __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); | 1641 __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
| 1612 } | 1642 } |
| 1613 } | 1643 } |
| 1614 | 1644 |
| 1615 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | 1645 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, |
| 1616 FeedbackVectorSlot slot) { | 1646 FeedbackVectorSlot slot, |
| 1617 DCHECK(!var->binding_needs_init()); | 1647 HoleCheckMode hole_check_mode) { |
| 1618 if (var->IsUnallocated()) { | 1648 if (var->IsUnallocated()) { |
| 1619 // Global var, const, or let. | 1649 // Global var, const, or let. |
| 1620 __ mov(StoreDescriptor::ReceiverRegister(), NativeContextOperand()); | 1650 __ mov(StoreDescriptor::ReceiverRegister(), NativeContextOperand()); |
| 1621 __ mov(StoreDescriptor::ReceiverRegister(), | 1651 __ mov(StoreDescriptor::ReceiverRegister(), |
| 1622 ContextOperand(StoreDescriptor::ReceiverRegister(), | 1652 ContextOperand(StoreDescriptor::ReceiverRegister(), |
| 1623 Context::EXTENSION_INDEX)); | 1653 Context::EXTENSION_INDEX)); |
| 1624 CallStoreIC(slot, var->name()); | 1654 CallStoreIC(slot, var->name()); |
| 1625 | 1655 |
| 1626 } else if (var->mode() == CONST && op != Token::INIT) { | 1656 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { |
| 1627 if (var->throw_on_const_assignment(language_mode())) { | 1657 DCHECK(!var->IsLookupSlot()); |
| 1658 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 1659 MemOperand location = VarOperand(var, ecx); |
| 1660 // Perform an initialization check for lexically declared variables. |
| 1661 if (hole_check_mode == HoleCheckMode::kRequired) { |
| 1662 Label assign; |
| 1663 __ mov(edx, location); |
| 1664 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 1665 __ j(not_equal, &assign, Label::kNear); |
| 1666 __ push(Immediate(var->name())); |
| 1667 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1668 __ bind(&assign); |
| 1669 } |
| 1670 if (var->mode() != CONST) { |
| 1671 EmitStoreToStackLocalOrContextSlot(var, location); |
| 1672 } else if (var->throw_on_const_assignment(language_mode())) { |
| 1628 __ CallRuntime(Runtime::kThrowConstAssignError); | 1673 __ CallRuntime(Runtime::kThrowConstAssignError); |
| 1629 } | 1674 } |
| 1675 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { |
| 1676 // Initializing assignment to const {this} needs a write barrier. |
| 1677 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 1678 Label uninitialized_this; |
| 1679 MemOperand location = VarOperand(var, ecx); |
| 1680 __ mov(edx, location); |
| 1681 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 1682 __ j(equal, &uninitialized_this); |
| 1683 __ push(Immediate(var->name())); |
| 1684 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1685 __ bind(&uninitialized_this); |
| 1686 EmitStoreToStackLocalOrContextSlot(var, location); |
| 1687 |
| 1630 } else { | 1688 } else { |
| 1631 DCHECK(!var->is_this()); | 1689 DCHECK(var->mode() != CONST || op == Token::INIT); |
| 1632 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 1690 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 1633 DCHECK(!var->IsLookupSlot()); | 1691 DCHECK(!var->IsLookupSlot()); |
| 1692 // Assignment to var or initializing assignment to let/const in harmony |
| 1693 // mode. |
| 1634 MemOperand location = VarOperand(var, ecx); | 1694 MemOperand location = VarOperand(var, ecx); |
| 1695 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { |
| 1696 // Check for an uninitialized let binding. |
| 1697 __ mov(edx, location); |
| 1698 __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 1699 __ Check(equal, kLetBindingReInitialization); |
| 1700 } |
| 1635 EmitStoreToStackLocalOrContextSlot(var, location); | 1701 EmitStoreToStackLocalOrContextSlot(var, location); |
| 1636 } | 1702 } |
| 1637 } | 1703 } |
| 1638 | 1704 |
| 1639 | 1705 |
| 1640 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { | 1706 void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 1641 // Assignment to a property, using a named store IC. | 1707 // Assignment to a property, using a named store IC. |
| 1642 // eax : value | 1708 // eax : value |
| 1643 // esp[0] : receiver | 1709 // esp[0] : receiver |
| 1644 Property* prop = expr->target()->AsProperty(); | 1710 Property* prop = expr->target()->AsProperty(); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 patch_site.EmitPatchInfo(); | 2410 patch_site.EmitPatchInfo(); |
| 2345 __ bind(&done); | 2411 __ bind(&done); |
| 2346 | 2412 |
| 2347 // Store the value returned in eax. | 2413 // Store the value returned in eax. |
| 2348 switch (assign_type) { | 2414 switch (assign_type) { |
| 2349 case VARIABLE: { | 2415 case VARIABLE: { |
| 2350 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2416 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
| 2351 if (expr->is_postfix()) { | 2417 if (expr->is_postfix()) { |
| 2352 // Perform the assignment as if via '='. | 2418 // Perform the assignment as if via '='. |
| 2353 { EffectContext context(this); | 2419 { EffectContext context(this); |
| 2354 EmitVariableAssignment(proxy->var(), Token::ASSIGN, | 2420 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), |
| 2355 expr->CountSlot()); | 2421 proxy->hole_check_mode()); |
| 2356 PrepareForBailoutForId(expr->AssignmentId(), | 2422 PrepareForBailoutForId(expr->AssignmentId(), |
| 2357 BailoutState::TOS_REGISTER); | 2423 BailoutState::TOS_REGISTER); |
| 2358 context.Plug(eax); | 2424 context.Plug(eax); |
| 2359 } | 2425 } |
| 2360 // For all contexts except EffectContext We have the result on | 2426 // For all contexts except EffectContext We have the result on |
| 2361 // top of the stack. | 2427 // top of the stack. |
| 2362 if (!context()->IsEffect()) { | 2428 if (!context()->IsEffect()) { |
| 2363 context()->PlugTOS(); | 2429 context()->PlugTOS(); |
| 2364 } | 2430 } |
| 2365 } else { | 2431 } else { |
| 2366 // Perform the assignment as if via '='. | 2432 // Perform the assignment as if via '='. |
| 2367 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot()); | 2433 EmitVariableAssignment(proxy->var(), Token::ASSIGN, expr->CountSlot(), |
| 2434 proxy->hole_check_mode()); |
| 2368 PrepareForBailoutForId(expr->AssignmentId(), | 2435 PrepareForBailoutForId(expr->AssignmentId(), |
| 2369 BailoutState::TOS_REGISTER); | 2436 BailoutState::TOS_REGISTER); |
| 2370 context()->Plug(eax); | 2437 context()->Plug(eax); |
| 2371 } | 2438 } |
| 2372 break; | 2439 break; |
| 2373 } | 2440 } |
| 2374 case NAMED_PROPERTY: { | 2441 case NAMED_PROPERTY: { |
| 2375 PopOperand(StoreDescriptor::ReceiverRegister()); | 2442 PopOperand(StoreDescriptor::ReceiverRegister()); |
| 2376 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); | 2443 CallStoreIC(expr->CountSlot(), prop->key()->AsLiteral()->value()); |
| 2377 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); | 2444 PrepareForBailoutForId(expr->AssignmentId(), BailoutState::TOS_REGISTER); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2706 isolate->builtins()->OnStackReplacement()->entry(), | 2773 isolate->builtins()->OnStackReplacement()->entry(), |
| 2707 Assembler::target_address_at(call_target_address, unoptimized_code)); | 2774 Assembler::target_address_at(call_target_address, unoptimized_code)); |
| 2708 return ON_STACK_REPLACEMENT; | 2775 return ON_STACK_REPLACEMENT; |
| 2709 } | 2776 } |
| 2710 | 2777 |
| 2711 | 2778 |
| 2712 } // namespace internal | 2779 } // namespace internal |
| 2713 } // namespace v8 | 2780 } // namespace v8 |
| 2714 | 2781 |
| 2715 #endif // V8_TARGET_ARCH_IA32 | 2782 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |