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_MIPS | 5 #if V8_TARGET_ARCH_MIPS |
6 | 6 |
7 // Note on Mips implementation: | 7 // Note on Mips implementation: |
8 // | 8 // |
9 // The result_register() for mips is the 'v0' register, which is defined | 9 // The result_register() for mips is the 'v0' register, which is defined |
10 // by the ABI to contain function return values. However, the first | 10 // by the ABI to contain function return values. However, the first |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 a1, Operand(t0)); | 748 a1, Operand(t0)); |
749 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); | 749 __ LoadRoot(t0, Heap::kCatchContextMapRootIndex); |
750 __ Check(ne, kDeclarationInCatchContext, | 750 __ Check(ne, kDeclarationInCatchContext, |
751 a1, Operand(t0)); | 751 a1, Operand(t0)); |
752 } | 752 } |
753 } | 753 } |
754 | 754 |
755 | 755 |
756 void FullCodeGenerator::VisitVariableDeclaration( | 756 void FullCodeGenerator::VisitVariableDeclaration( |
757 VariableDeclaration* declaration) { | 757 VariableDeclaration* declaration) { |
758 // If it was not possible to allocate the variable at compile time, we | |
759 // need to "declare" it at runtime to make sure it actually exists in the | |
760 // local context. | |
761 VariableProxy* proxy = declaration->proxy(); | 758 VariableProxy* proxy = declaration->proxy(); |
762 VariableMode mode = declaration->mode(); | |
763 Variable* variable = proxy->var(); | 759 Variable* variable = proxy->var(); |
764 bool hole_init = mode == LET || mode == CONST; | |
765 switch (variable->location()) { | 760 switch (variable->location()) { |
766 case VariableLocation::GLOBAL: | 761 case VariableLocation::GLOBAL: |
767 case VariableLocation::UNALLOCATED: { | 762 case VariableLocation::UNALLOCATED: { |
768 DCHECK(!variable->binding_needs_init()); | 763 DCHECK(!variable->binding_needs_init()); |
769 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); | 764 FeedbackVectorSlot slot = proxy->VariableFeedbackSlot(); |
770 DCHECK(!slot.IsInvalid()); | 765 DCHECK(!slot.IsInvalid()); |
771 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); | 766 globals_->Add(handle(Smi::FromInt(slot.ToInt()), isolate()), zone()); |
772 globals_->Add(isolate()->factory()->undefined_value(), zone()); | 767 globals_->Add(isolate()->factory()->undefined_value(), zone()); |
773 break; | 768 break; |
774 } | 769 } |
775 case VariableLocation::PARAMETER: | 770 case VariableLocation::PARAMETER: |
776 case VariableLocation::LOCAL: | 771 case VariableLocation::LOCAL: |
777 if (hole_init) { | 772 if (variable->binding_needs_init()) { |
778 Comment cmnt(masm_, "[ VariableDeclaration"); | 773 Comment cmnt(masm_, "[ VariableDeclaration"); |
779 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); | 774 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
780 __ sw(t0, StackOperand(variable)); | 775 __ sw(t0, StackOperand(variable)); |
781 } | 776 } |
782 break; | 777 break; |
783 | 778 |
784 case VariableLocation::CONTEXT: | 779 case VariableLocation::CONTEXT: |
785 if (hole_init) { | 780 if (variable->binding_needs_init()) { |
786 Comment cmnt(masm_, "[ VariableDeclaration"); | 781 Comment cmnt(masm_, "[ VariableDeclaration"); |
787 EmitDebugCheckDeclarationContext(variable); | 782 EmitDebugCheckDeclarationContext(variable); |
788 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 783 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
789 __ sw(at, ContextMemOperand(cp, variable->index())); | 784 __ sw(at, ContextMemOperand(cp, variable->index())); |
790 // No write barrier since the_hole_value is in old space. | 785 // No write barrier since the_hole_value is in old space. |
791 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); | 786 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); |
792 } | 787 } |
793 break; | 788 break; |
794 | 789 |
795 case VariableLocation::LOOKUP: { | 790 case VariableLocation::LOOKUP: { |
796 Comment cmnt(masm_, "[ VariableDeclaration"); | 791 Comment cmnt(masm_, "[ VariableDeclaration"); |
797 DCHECK_EQ(VAR, mode); | 792 DCHECK_EQ(VAR, variable->mode()); |
798 DCHECK(!hole_init); | 793 DCHECK(!variable->binding_needs_init()); |
799 __ li(a2, Operand(variable->name())); | 794 __ li(a2, Operand(variable->name())); |
800 __ Push(a2); | 795 __ Push(a2); |
801 __ CallRuntime(Runtime::kDeclareEvalVar); | 796 __ CallRuntime(Runtime::kDeclareEvalVar); |
802 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); | 797 PrepareForBailoutForId(proxy->id(), BailoutState::NO_REGISTERS); |
803 break; | 798 break; |
804 } | 799 } |
805 } | 800 } |
806 } | 801 } |
807 | 802 |
808 | 803 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 // introducing variables. In those cases, we do not want to | 1253 // introducing variables. In those cases, we do not want to |
1259 // perform a runtime call for all variables in the scope | 1254 // perform a runtime call for all variables in the scope |
1260 // containing the eval. | 1255 // containing the eval. |
1261 Variable* var = proxy->var(); | 1256 Variable* var = proxy->var(); |
1262 if (var->mode() == DYNAMIC_GLOBAL) { | 1257 if (var->mode() == DYNAMIC_GLOBAL) { |
1263 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); | 1258 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); |
1264 __ Branch(done); | 1259 __ Branch(done); |
1265 } else if (var->mode() == DYNAMIC_LOCAL) { | 1260 } else if (var->mode() == DYNAMIC_LOCAL) { |
1266 Variable* local = var->local_if_not_shadowed(); | 1261 Variable* local = var->local_if_not_shadowed(); |
1267 __ lw(v0, ContextSlotOperandCheckExtensions(local, slow)); | 1262 __ lw(v0, ContextSlotOperandCheckExtensions(local, slow)); |
1268 if (local->mode() == LET || local->mode() == CONST) { | 1263 if (local->binding_needs_init()) { |
1269 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 1264 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
1270 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. | 1265 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. |
1271 __ Branch(done, ne, at, Operand(zero_reg)); | 1266 __ Branch(done, ne, at, Operand(zero_reg)); |
1272 __ li(a0, Operand(var->name())); | 1267 __ li(a0, Operand(var->name())); |
1273 __ push(a0); | 1268 __ push(a0); |
1274 __ CallRuntime(Runtime::kThrowReferenceError); | 1269 __ CallRuntime(Runtime::kThrowReferenceError); |
| 1270 } else { |
| 1271 __ Branch(done); |
1275 } | 1272 } |
1276 __ Branch(done); | |
1277 } | 1273 } |
1278 } | 1274 } |
1279 | 1275 |
1280 | 1276 |
1281 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, | 1277 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, |
1282 TypeofMode typeof_mode) { | 1278 TypeofMode typeof_mode) { |
1283 #ifdef DEBUG | 1279 #ifdef DEBUG |
1284 Variable* var = proxy->var(); | 1280 Variable* var = proxy->var(); |
1285 DCHECK(var->IsUnallocatedOrGlobalSlot() || | 1281 DCHECK(var->IsUnallocatedOrGlobalSlot() || |
1286 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL)); | 1282 (var->IsLookupSlot() && var->mode() == DYNAMIC_GLOBAL)); |
(...skipping 22 matching lines...) Expand all Loading... |
1309 break; | 1305 break; |
1310 } | 1306 } |
1311 | 1307 |
1312 case VariableLocation::PARAMETER: | 1308 case VariableLocation::PARAMETER: |
1313 case VariableLocation::LOCAL: | 1309 case VariableLocation::LOCAL: |
1314 case VariableLocation::CONTEXT: { | 1310 case VariableLocation::CONTEXT: { |
1315 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); | 1311 DCHECK_EQ(NOT_INSIDE_TYPEOF, typeof_mode); |
1316 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" | 1312 Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
1317 : "[ Stack variable"); | 1313 : "[ Stack variable"); |
1318 if (NeedsHoleCheckForLoad(proxy)) { | 1314 if (NeedsHoleCheckForLoad(proxy)) { |
1319 // Let and const need a read barrier. | 1315 // Throw a reference error when using an uninitialized let/const |
| 1316 // binding in harmony mode. |
| 1317 Label done; |
1320 GetVar(v0, var); | 1318 GetVar(v0, var); |
1321 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 1319 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
1322 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. | 1320 __ subu(at, v0, at); // Sub as compare: at == 0 on eq. |
1323 if (var->mode() == LET || var->mode() == CONST) { | 1321 __ Branch(&done, ne, at, Operand(zero_reg)); |
1324 // Throw a reference error when using an uninitialized let/const | 1322 __ li(a0, Operand(var->name())); |
1325 // binding in harmony mode. | 1323 __ push(a0); |
1326 Label done; | 1324 __ CallRuntime(Runtime::kThrowReferenceError); |
1327 __ Branch(&done, ne, at, Operand(zero_reg)); | 1325 __ bind(&done); |
1328 __ li(a0, Operand(var->name())); | |
1329 __ push(a0); | |
1330 __ CallRuntime(Runtime::kThrowReferenceError); | |
1331 __ bind(&done); | |
1332 } | |
1333 context()->Plug(v0); | 1326 context()->Plug(v0); |
1334 break; | 1327 break; |
1335 } | 1328 } |
1336 context()->Plug(var); | 1329 context()->Plug(var); |
1337 break; | 1330 break; |
1338 } | 1331 } |
1339 | 1332 |
1340 case VariableLocation::LOOKUP: { | 1333 case VariableLocation::LOOKUP: { |
1341 Comment cmnt(masm_, "[ Lookup variable"); | 1334 Comment cmnt(masm_, "[ Lookup variable"); |
1342 Label done, slow; | 1335 Label done, slow; |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2162 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, | 2155 void FullCodeGenerator::EmitVariableAssignment(Variable* var, Token::Value op, |
2163 FeedbackVectorSlot slot) { | 2156 FeedbackVectorSlot slot) { |
2164 if (var->IsUnallocated()) { | 2157 if (var->IsUnallocated()) { |
2165 // Global var, const, or let. | 2158 // Global var, const, or let. |
2166 __ mov(StoreDescriptor::ValueRegister(), result_register()); | 2159 __ mov(StoreDescriptor::ValueRegister(), result_register()); |
2167 __ li(StoreDescriptor::NameRegister(), Operand(var->name())); | 2160 __ li(StoreDescriptor::NameRegister(), Operand(var->name())); |
2168 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); | 2161 __ LoadGlobalObject(StoreDescriptor::ReceiverRegister()); |
2169 EmitLoadStoreICSlot(slot); | 2162 EmitLoadStoreICSlot(slot); |
2170 CallStoreIC(); | 2163 CallStoreIC(); |
2171 | 2164 |
2172 } else if (var->mode() == LET && op != Token::INIT) { | 2165 } else if (IsLexicalVariableMode(var->mode()) && op != Token::INIT) { |
2173 // Non-initializing assignment to let variable needs a write barrier. | |
2174 DCHECK(!var->IsLookupSlot()); | 2166 DCHECK(!var->IsLookupSlot()); |
2175 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2167 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
2176 Label assign; | |
2177 MemOperand location = VarOperand(var, a1); | 2168 MemOperand location = VarOperand(var, a1); |
2178 __ lw(a3, location); | 2169 // Perform an initialization check for lexically declared variables. |
2179 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); | 2170 if (var->binding_needs_init()) { |
2180 __ Branch(&assign, ne, a3, Operand(t0)); | 2171 Label assign; |
2181 __ li(a3, Operand(var->name())); | 2172 __ lw(a3, location); |
2182 __ push(a3); | 2173 __ LoadRoot(t0, Heap::kTheHoleValueRootIndex); |
2183 __ CallRuntime(Runtime::kThrowReferenceError); | 2174 __ Branch(&assign, ne, a3, Operand(t0)); |
2184 // Perform the assignment. | 2175 __ li(a3, Operand(var->name())); |
2185 __ bind(&assign); | 2176 __ push(a3); |
2186 EmitStoreToStackLocalOrContextSlot(var, location); | 2177 __ CallRuntime(Runtime::kThrowReferenceError); |
2187 | 2178 __ bind(&assign); |
2188 } else if (var->mode() == CONST && op != Token::INIT) { | 2179 } |
2189 // Assignment to const variable needs a write barrier. | 2180 if (var->mode() == CONST) { |
2190 DCHECK(!var->IsLookupSlot()); | 2181 __ CallRuntime(Runtime::kThrowConstAssignError); |
2191 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2182 } else { |
2192 Label const_error; | 2183 EmitStoreToStackLocalOrContextSlot(var, location); |
2193 MemOperand location = VarOperand(var, a1); | 2184 } |
2194 __ lw(a3, location); | |
2195 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | |
2196 __ Branch(&const_error, ne, a3, Operand(at)); | |
2197 __ li(a3, Operand(var->name())); | |
2198 __ push(a3); | |
2199 __ CallRuntime(Runtime::kThrowReferenceError); | |
2200 __ bind(&const_error); | |
2201 __ CallRuntime(Runtime::kThrowConstAssignError); | |
2202 | |
2203 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { | 2185 } else if (var->is_this() && var->mode() == CONST && op == Token::INIT) { |
2204 // Initializing assignment to const {this} needs a write barrier. | 2186 // Initializing assignment to const {this} needs a write barrier. |
2205 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2187 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
2206 Label uninitialized_this; | 2188 Label uninitialized_this; |
2207 MemOperand location = VarOperand(var, a1); | 2189 MemOperand location = VarOperand(var, a1); |
2208 __ lw(a3, location); | 2190 __ lw(a3, location); |
2209 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); | 2191 __ LoadRoot(at, Heap::kTheHoleValueRootIndex); |
2210 __ Branch(&uninitialized_this, eq, a3, Operand(at)); | 2192 __ Branch(&uninitialized_this, eq, a3, Operand(at)); |
2211 __ li(a0, Operand(var->name())); | 2193 __ li(a0, Operand(var->name())); |
2212 __ Push(a0); | 2194 __ Push(a0); |
(...skipping 1567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3780 reinterpret_cast<uint32_t>( | 3762 reinterpret_cast<uint32_t>( |
3781 isolate->builtins()->OnStackReplacement()->entry())); | 3763 isolate->builtins()->OnStackReplacement()->entry())); |
3782 return ON_STACK_REPLACEMENT; | 3764 return ON_STACK_REPLACEMENT; |
3783 } | 3765 } |
3784 | 3766 |
3785 | 3767 |
3786 } // namespace internal | 3768 } // namespace internal |
3787 } // namespace v8 | 3769 } // namespace v8 |
3788 | 3770 |
3789 #endif // V8_TARGET_ARCH_MIPS | 3771 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |