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