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_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 713 |
714 | 714 |
715 void FullCodeGenerator::VisitVariableDeclaration( | 715 void FullCodeGenerator::VisitVariableDeclaration( |
716 VariableDeclaration* declaration) { | 716 VariableDeclaration* declaration) { |
717 // If it was not possible to allocate the variable at compile time, we | 717 // If it was not possible to allocate the variable at compile time, we |
718 // need to "declare" it at runtime to make sure it actually exists in the | 718 // need to "declare" it at runtime to make sure it actually exists in the |
719 // local context. | 719 // local context. |
720 VariableProxy* proxy = declaration->proxy(); | 720 VariableProxy* proxy = declaration->proxy(); |
721 VariableMode mode = declaration->mode(); | 721 VariableMode mode = declaration->mode(); |
722 Variable* variable = proxy->var(); | 722 Variable* variable = proxy->var(); |
723 bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; | 723 bool hole_init = mode == LET || mode == CONST; |
724 switch (variable->location()) { | 724 switch (variable->location()) { |
725 case VariableLocation::GLOBAL: | 725 case VariableLocation::GLOBAL: |
726 case VariableLocation::UNALLOCATED: | 726 case VariableLocation::UNALLOCATED: |
727 globals_->Add(variable->name(), zone()); | 727 globals_->Add(variable->name(), zone()); |
728 globals_->Add(variable->binding_needs_init() | 728 globals_->Add(variable->binding_needs_init() |
729 ? isolate()->factory()->the_hole_value() | 729 ? isolate()->factory()->the_hole_value() |
730 : isolate()->factory()->undefined_value(), | 730 : isolate()->factory()->undefined_value(), |
731 zone()); | 731 zone()); |
732 break; | 732 break; |
733 | 733 |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 // introducing variables. In those cases, we do not want to | 1230 // introducing variables. In those cases, we do not want to |
1231 // perform a runtime call for all variables in the scope | 1231 // perform a runtime call for all variables in the scope |
1232 // containing the eval. | 1232 // containing the eval. |
1233 Variable* var = proxy->var(); | 1233 Variable* var = proxy->var(); |
1234 if (var->mode() == DYNAMIC_GLOBAL) { | 1234 if (var->mode() == DYNAMIC_GLOBAL) { |
1235 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); | 1235 EmitLoadGlobalCheckExtensions(proxy, typeof_mode, slow); |
1236 __ jmp(done); | 1236 __ jmp(done); |
1237 } else if (var->mode() == DYNAMIC_LOCAL) { | 1237 } else if (var->mode() == DYNAMIC_LOCAL) { |
1238 Variable* local = var->local_if_not_shadowed(); | 1238 Variable* local = var->local_if_not_shadowed(); |
1239 __ movp(rax, ContextSlotOperandCheckExtensions(local, slow)); | 1239 __ movp(rax, ContextSlotOperandCheckExtensions(local, slow)); |
1240 if (local->mode() == LET || local->mode() == CONST || | 1240 if (local->mode() == LET || local->mode() == CONST) { |
1241 local->mode() == CONST_LEGACY) { | |
1242 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1241 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
1243 __ j(not_equal, done); | 1242 __ j(not_equal, done); |
1244 if (local->mode() == CONST_LEGACY) { | 1243 __ Push(var->name()); |
1245 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 1244 __ CallRuntime(Runtime::kThrowReferenceError); |
1246 } else { // LET || CONST | |
1247 __ Push(var->name()); | |
1248 __ CallRuntime(Runtime::kThrowReferenceError); | |
1249 } | |
1250 } | 1245 } |
1251 __ jmp(done); | 1246 __ jmp(done); |
1252 } | 1247 } |
1253 } | 1248 } |
1254 | 1249 |
1255 | 1250 |
1256 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, | 1251 void FullCodeGenerator::EmitGlobalVariableLoad(VariableProxy* proxy, |
1257 TypeofMode typeof_mode) { | 1252 TypeofMode typeof_mode) { |
1258 Variable* var = proxy->var(); | 1253 Variable* var = proxy->var(); |
1259 DCHECK(var->IsUnallocatedOrGlobalSlot() || | 1254 DCHECK(var->IsUnallocatedOrGlobalSlot() || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 // Let and const need a read barrier. | 1289 // Let and const need a read barrier. |
1295 Label done; | 1290 Label done; |
1296 GetVar(rax, var); | 1291 GetVar(rax, var); |
1297 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); | 1292 __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); |
1298 __ j(not_equal, &done, Label::kNear); | 1293 __ j(not_equal, &done, Label::kNear); |
1299 if (var->mode() == LET || var->mode() == CONST) { | 1294 if (var->mode() == LET || var->mode() == CONST) { |
1300 // Throw a reference error when using an uninitialized let/const | 1295 // Throw a reference error when using an uninitialized let/const |
1301 // binding in harmony mode. | 1296 // binding in harmony mode. |
1302 __ Push(var->name()); | 1297 __ Push(var->name()); |
1303 __ CallRuntime(Runtime::kThrowReferenceError); | 1298 __ CallRuntime(Runtime::kThrowReferenceError); |
1304 } else { | |
1305 // Uninitialized legacy const bindings are unholed. | |
1306 DCHECK(var->mode() == CONST_LEGACY); | |
1307 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | |
1308 } | 1299 } |
1309 __ bind(&done); | 1300 __ bind(&done); |
1310 context()->Plug(rax); | 1301 context()->Plug(rax); |
1311 break; | 1302 break; |
1312 } | 1303 } |
1313 context()->Plug(var); | 1304 context()->Plug(var); |
1314 break; | 1305 break; |
1315 } | 1306 } |
1316 | 1307 |
1317 case VariableLocation::LOOKUP: { | 1308 case VariableLocation::LOOKUP: { |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 Label uninitialized_this; | 2116 Label uninitialized_this; |
2126 MemOperand location = VarOperand(var, rcx); | 2117 MemOperand location = VarOperand(var, rcx); |
2127 __ movp(rdx, location); | 2118 __ movp(rdx, location); |
2128 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | 2119 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
2129 __ j(equal, &uninitialized_this); | 2120 __ j(equal, &uninitialized_this); |
2130 __ Push(var->name()); | 2121 __ Push(var->name()); |
2131 __ CallRuntime(Runtime::kThrowReferenceError); | 2122 __ CallRuntime(Runtime::kThrowReferenceError); |
2132 __ bind(&uninitialized_this); | 2123 __ bind(&uninitialized_this); |
2133 EmitStoreToStackLocalOrContextSlot(var, location); | 2124 EmitStoreToStackLocalOrContextSlot(var, location); |
2134 | 2125 |
2135 } else if (!var->is_const_mode() || | 2126 } else if (!var->is_const_mode() || op == Token::INIT) { |
2136 (var->mode() == CONST && op == Token::INIT)) { | |
2137 if (var->IsLookupSlot()) { | 2127 if (var->IsLookupSlot()) { |
2138 // Assignment to var. | 2128 // Assignment to var. |
2139 __ Push(var->name()); | 2129 __ Push(var->name()); |
2140 __ Push(rax); | 2130 __ Push(rax); |
2141 __ CallRuntime(is_strict(language_mode()) | 2131 __ CallRuntime(is_strict(language_mode()) |
2142 ? Runtime::kStoreLookupSlot_Strict | 2132 ? Runtime::kStoreLookupSlot_Strict |
2143 : Runtime::kStoreLookupSlot_Sloppy); | 2133 : Runtime::kStoreLookupSlot_Sloppy); |
2144 } else { | 2134 } else { |
2145 // Assignment to var or initializing assignment to let/const in harmony | 2135 // Assignment to var or initializing assignment to let/const in harmony |
2146 // mode. | 2136 // mode. |
2147 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); | 2137 DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
2148 MemOperand location = VarOperand(var, rcx); | 2138 MemOperand location = VarOperand(var, rcx); |
2149 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { | 2139 if (FLAG_debug_code && var->mode() == LET && op == Token::INIT) { |
2150 // Check for an uninitialized let binding. | 2140 // Check for an uninitialized let binding. |
2151 __ movp(rdx, location); | 2141 __ movp(rdx, location); |
2152 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | 2142 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); |
2153 __ Check(equal, kLetBindingReInitialization); | 2143 __ Check(equal, kLetBindingReInitialization); |
2154 } | 2144 } |
2155 EmitStoreToStackLocalOrContextSlot(var, location); | 2145 EmitStoreToStackLocalOrContextSlot(var, location); |
2156 } | 2146 } |
2157 | 2147 |
2158 } else if (var->mode() == CONST_LEGACY && op == Token::INIT) { | |
2159 // Const initializers need a write barrier. | |
2160 DCHECK(!var->IsParameter()); // No const parameters. | |
2161 if (var->IsLookupSlot()) { | |
2162 __ Push(rax); | |
2163 __ Push(rsi); | |
2164 __ Push(var->name()); | |
2165 __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot); | |
2166 } else { | |
2167 DCHECK(var->IsStackLocal() || var->IsContextSlot()); | |
2168 Label skip; | |
2169 MemOperand location = VarOperand(var, rcx); | |
2170 __ movp(rdx, location); | |
2171 __ CompareRoot(rdx, Heap::kTheHoleValueRootIndex); | |
2172 __ j(not_equal, &skip); | |
2173 EmitStoreToStackLocalOrContextSlot(var, location); | |
2174 __ bind(&skip); | |
2175 } | |
2176 | |
2177 } else { | 2148 } else { |
2178 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT); | 2149 DCHECK(var->mode() == CONST_LEGACY && op != Token::INIT); |
2179 if (is_strict(language_mode())) { | 2150 if (is_strict(language_mode())) { |
2180 __ CallRuntime(Runtime::kThrowConstAssignError); | 2151 __ CallRuntime(Runtime::kThrowConstAssignError); |
2181 } | 2152 } |
2182 // Silently ignore store in sloppy mode. | 2153 // Silently ignore store in sloppy mode. |
2183 } | 2154 } |
2184 } | 2155 } |
2185 | 2156 |
2186 | 2157 |
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3883 DCHECK_EQ( | 3854 DCHECK_EQ( |
3884 isolate->builtins()->OnStackReplacement()->entry(), | 3855 isolate->builtins()->OnStackReplacement()->entry(), |
3885 Assembler::target_address_at(call_target_address, unoptimized_code)); | 3856 Assembler::target_address_at(call_target_address, unoptimized_code)); |
3886 return ON_STACK_REPLACEMENT; | 3857 return ON_STACK_REPLACEMENT; |
3887 } | 3858 } |
3888 | 3859 |
3889 } // namespace internal | 3860 } // namespace internal |
3890 } // namespace v8 | 3861 } // namespace v8 |
3891 | 3862 |
3892 #endif // V8_TARGET_ARCH_X64 | 3863 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |