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/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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 }; | 76 }; |
77 | 77 |
78 | 78 |
79 // Generate code for a JS function. On entry to the function the receiver | 79 // Generate code for a JS function. On entry to the function the receiver |
80 // and arguments have been pushed on the stack left to right, with the | 80 // and arguments have been pushed on the stack left to right, with the |
81 // return address on top of them. The actual argument count matches the | 81 // return address on top of them. The actual argument count matches the |
82 // formal parameter count expected by the function. | 82 // formal parameter count expected by the function. |
83 // | 83 // |
84 // The live registers are: | 84 // The live registers are: |
85 // o edi: the JS function object being called (i.e. ourselves) | 85 // o edi: the JS function object being called (i.e. ourselves) |
| 86 // o edx: the new target value |
86 // o esi: our context | 87 // o esi: our context |
87 // o ebp: our caller's frame pointer | 88 // o ebp: our caller's frame pointer |
88 // o esp: stack pointer (pointing to return address) | 89 // o esp: stack pointer (pointing to return address) |
89 // | 90 // |
90 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 91 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
91 // frames-ia32.h for its layout. | 92 // frames-ia32.h for its layout. |
92 void FullCodeGenerator::Generate() { | 93 void FullCodeGenerator::Generate() { |
93 CompilationInfo* info = info_; | 94 CompilationInfo* info = info_; |
94 profiling_counter_ = isolate()->factory()->NewCell( | 95 profiling_counter_ = isolate()->factory()->NewCell( |
95 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); | 96 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 if (info->scope()->num_heap_slots() > 0) { | 168 if (info->scope()->num_heap_slots() > 0) { |
168 Comment cmnt(masm_, "[ Allocate context"); | 169 Comment cmnt(masm_, "[ Allocate context"); |
169 bool need_write_barrier = true; | 170 bool need_write_barrier = true; |
170 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; | 171 int slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
171 // Argument to NewContext is the function, which is still in edi. | 172 // Argument to NewContext is the function, which is still in edi. |
172 if (info->scope()->is_script_scope()) { | 173 if (info->scope()->is_script_scope()) { |
173 __ push(edi); | 174 __ push(edi); |
174 __ Push(info->scope()->GetScopeInfo(info->isolate())); | 175 __ Push(info->scope()->GetScopeInfo(info->isolate())); |
175 __ CallRuntime(Runtime::kNewScriptContext, 2); | 176 __ CallRuntime(Runtime::kNewScriptContext, 2); |
176 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); | 177 PrepareForBailoutForId(BailoutId::ScriptContext(), TOS_REG); |
177 } else if (slots <= FastNewContextStub::kMaximumSlots) { | 178 // The new target value is not used, clobbering is safe. |
178 FastNewContextStub stub(isolate(), slots); | 179 DCHECK_NULL(info->scope()->new_target_var()); |
179 __ CallStub(&stub); | |
180 // Result of FastNewContextStub is always in new space. | |
181 need_write_barrier = false; | |
182 } else { | 180 } else { |
183 __ push(edi); | 181 if (info->scope()->new_target_var() != nullptr) { |
184 __ CallRuntime(Runtime::kNewFunctionContext, 1); | 182 __ push(edx); // Preserve new target. |
| 183 } |
| 184 if (slots <= FastNewContextStub::kMaximumSlots) { |
| 185 FastNewContextStub stub(isolate(), slots); |
| 186 __ CallStub(&stub); |
| 187 // Result of FastNewContextStub is always in new space. |
| 188 need_write_barrier = false; |
| 189 } else { |
| 190 __ push(edi); |
| 191 __ CallRuntime(Runtime::kNewFunctionContext, 1); |
| 192 } |
| 193 if (info->scope()->new_target_var() != nullptr) { |
| 194 __ pop(edx); // Restore new target. |
| 195 } |
185 } | 196 } |
186 function_in_register = false; | 197 function_in_register = false; |
187 // Context is returned in eax. It replaces the context passed to us. | 198 // Context is returned in eax. It replaces the context passed to us. |
188 // It's saved in the stack and kept live in esi. | 199 // It's saved in the stack and kept live in esi. |
189 __ mov(esi, eax); | 200 __ mov(esi, eax); |
190 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); | 201 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); |
191 | 202 |
192 // Copy parameters into context if necessary. | 203 // Copy parameters into context if necessary. |
193 int num_parameters = info->scope()->num_parameters(); | 204 int num_parameters = info->scope()->num_parameters(); |
194 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; | 205 int first_parameter = info->scope()->has_this_declaration() ? -1 : 0; |
(...skipping 16 matching lines...) Expand all Loading... |
211 kDontSaveFPRegs); | 222 kDontSaveFPRegs); |
212 } else if (FLAG_debug_code) { | 223 } else if (FLAG_debug_code) { |
213 Label done; | 224 Label done; |
214 __ JumpIfInNewSpace(esi, eax, &done, Label::kNear); | 225 __ JumpIfInNewSpace(esi, eax, &done, Label::kNear); |
215 __ Abort(kExpectedNewSpaceObject); | 226 __ Abort(kExpectedNewSpaceObject); |
216 __ bind(&done); | 227 __ bind(&done); |
217 } | 228 } |
218 } | 229 } |
219 } | 230 } |
220 } | 231 } |
| 232 |
| 233 // Register holding this function and new target are both trashed in case we |
| 234 // bailout here. But since that can happen only when new target is not used |
| 235 // and we allocate a context, the value of |function_in_register| is correct. |
221 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); | 236 PrepareForBailoutForId(BailoutId::FunctionContext(), NO_REGISTERS); |
222 | 237 |
223 // Function register is trashed in case we bailout here. But since that | |
224 // could happen only when we allocate a context the value of | |
225 // |function_in_register| is correct. | |
226 | |
227 // Possibly set up a local binding to the this function which is used in | 238 // Possibly set up a local binding to the this function which is used in |
228 // derived constructors with super calls. | 239 // derived constructors with super calls. |
229 Variable* this_function_var = scope()->this_function_var(); | 240 Variable* this_function_var = scope()->this_function_var(); |
230 if (this_function_var != nullptr) { | 241 if (this_function_var != nullptr) { |
231 Comment cmnt(masm_, "[ This function"); | 242 Comment cmnt(masm_, "[ This function"); |
232 if (!function_in_register) { | 243 if (!function_in_register) { |
233 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 244 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
234 // The write barrier clobbers register again, keep it marked as such. | 245 // The write barrier clobbers register again, keep it marked as such. |
235 } | 246 } |
236 SetVar(this_function_var, edi, ebx, edx); | 247 SetVar(this_function_var, edi, ebx, ecx); |
237 } | 248 } |
238 | 249 |
| 250 // Possibly set up a local binding to the new target value. |
239 Variable* new_target_var = scope()->new_target_var(); | 251 Variable* new_target_var = scope()->new_target_var(); |
240 if (new_target_var != nullptr) { | 252 if (new_target_var != nullptr) { |
241 Comment cmnt(masm_, "[ new.target"); | 253 Comment cmnt(masm_, "[ new.target"); |
242 __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); | 254 SetVar(new_target_var, edx, ebx, ecx); |
243 Label non_adaptor_frame; | |
244 __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), | |
245 Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); | |
246 __ j(not_equal, &non_adaptor_frame); | |
247 __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); | |
248 | |
249 __ bind(&non_adaptor_frame); | |
250 __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), | |
251 Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); | |
252 | |
253 Label non_construct_frame, done; | |
254 __ j(not_equal, &non_construct_frame); | |
255 | |
256 // Construct frame | |
257 __ mov(eax, Operand(eax, ConstructFrameConstants::kNewTargetOffset)); | |
258 __ jmp(&done); | |
259 | |
260 // Non-construct frame | |
261 __ bind(&non_construct_frame); | |
262 __ mov(eax, Immediate(isolate()->factory()->undefined_value())); | |
263 | |
264 __ bind(&done); | |
265 SetVar(new_target_var, eax, ebx, edx); | |
266 } | 255 } |
267 | 256 |
268 Variable* arguments = scope()->arguments(); | 257 Variable* arguments = scope()->arguments(); |
269 if (arguments != NULL) { | 258 if (arguments != NULL) { |
270 // Function uses arguments object. | 259 // Function uses arguments object. |
271 Comment cmnt(masm_, "[ Allocate arguments object"); | 260 Comment cmnt(masm_, "[ Allocate arguments object"); |
272 DCHECK(edi.is(ArgumentsAccessNewDescriptor::function())); | 261 DCHECK(edi.is(ArgumentsAccessNewDescriptor::function())); |
273 if (!function_in_register) { | 262 if (!function_in_register) { |
274 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 263 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
275 } | 264 } |
(...skipping 4565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4841 Assembler::target_address_at(call_target_address, | 4830 Assembler::target_address_at(call_target_address, |
4842 unoptimized_code)); | 4831 unoptimized_code)); |
4843 return OSR_AFTER_STACK_CHECK; | 4832 return OSR_AFTER_STACK_CHECK; |
4844 } | 4833 } |
4845 | 4834 |
4846 | 4835 |
4847 } // namespace internal | 4836 } // namespace internal |
4848 } // namespace v8 | 4837 } // namespace v8 |
4849 | 4838 |
4850 #endif // V8_TARGET_ARCH_IA32 | 4839 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |