Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 7 | #if V8_TARGET_ARCH_IA32 |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 8 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 9 | #include "src/code-factory.h" |
| 10 | #include "src/code-stubs.h" |
| 11 | #include "src/codegen.h" |
| 12 | #include "src/compiler.h" |
| 13 | #include "src/debug.h" |
| 14 | #include "src/full-codegen.h" |
| 15 | #include "src/ic/ic.h" |
| 16 | #include "src/isolate-inl.h" |
| 17 | #include "src/parser.h" |
| 18 | #include "src/scopes.h" |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 19 | |
| 20 | namespace v8 { |
| 21 | namespace internal { |
| 22 | |
| 23 | #define __ ACCESS_MASM(masm_) |
| 24 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 25 | |
| 26 | class JumpPatchSite BASE_EMBEDDED { |
| 27 | public: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 28 | explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 29 | #ifdef DEBUG |
| 30 | info_emitted_ = false; |
| 31 | #endif |
| 32 | } |
| 33 | |
| 34 | ~JumpPatchSite() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 35 | DCHECK(patch_site_.is_bound() == info_emitted_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 36 | } |
| 37 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 38 | void EmitJumpIfNotSmi(Register reg, |
| 39 | Label* target, |
| 40 | Label::Distance distance = Label::kFar) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 41 | __ test(reg, Immediate(kSmiTagMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 42 | EmitJump(not_carry, target, distance); // Always taken before patched. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 43 | } |
| 44 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 45 | void EmitJumpIfSmi(Register reg, |
| 46 | Label* target, |
| 47 | Label::Distance distance = Label::kFar) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 48 | __ test(reg, Immediate(kSmiTagMask)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 49 | EmitJump(carry, target, distance); // Never taken before patched. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void EmitPatchInfo() { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 53 | if (patch_site_.is_bound()) { |
| 54 | int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | DCHECK(is_uint8(delta_to_patch_site)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 56 | __ test(eax, Immediate(delta_to_patch_site)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 57 | #ifdef DEBUG |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 58 | info_emitted_ = true; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 59 | #endif |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 60 | } else { |
| 61 | __ nop(); // Signals no inlined code. |
| 62 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 65 | private: |
| 66 | // jc will be patched with jz, jnc will become jnz. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 67 | void EmitJump(Condition cc, Label* target, Label::Distance distance) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | DCHECK(!patch_site_.is_bound() && !info_emitted_); |
| 69 | DCHECK(cc == carry || cc == not_carry); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 70 | __ bind(&patch_site_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 71 | __ j(cc, target, distance); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | MacroAssembler* masm_; |
| 75 | Label patch_site_; |
| 76 | #ifdef DEBUG |
| 77 | bool info_emitted_; |
| 78 | #endif |
| 79 | }; |
| 80 | |
| 81 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 82 | // Generate code for a JS function. On entry to the function the receiver |
| 83 | // and arguments have been pushed on the stack left to right, with the |
| 84 | // return address on top of them. The actual argument count matches the |
| 85 | // formal parameter count expected by the function. |
| 86 | // |
| 87 | // The live registers are: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 88 | // o edi: the JS function object being called (i.e. ourselves) |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 89 | // o esi: our context |
| 90 | // o ebp: our caller's frame pointer |
| 91 | // o esp: stack pointer (pointing to return address) |
| 92 | // |
| 93 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 94 | // frames-ia32.h for its layout. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 95 | void FullCodeGenerator::Generate() { |
| 96 | CompilationInfo* info = info_; |
| 97 | handler_table_ = |
| 98 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 99 | |
| 100 | profiling_counter_ = isolate()->factory()->NewCell( |
| 101 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 102 | SetFunctionPosition(function()); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 103 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 105 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 106 | |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 107 | #ifdef DEBUG |
| 108 | if (strlen(FLAG_stop_at) > 0 && |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 110 | __ int3(); |
| 111 | } |
| 112 | #endif |
| 113 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 114 | // Sloppy mode functions and builtins need to replace the receiver with the |
| 115 | // global proxy when called as functions (without an explicit receiver |
| 116 | // object). |
| 117 | if (info->strict_mode() == SLOPPY && !info->is_native()) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 118 | Label ok; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 119 | // +1 for return address. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 120 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 121 | __ mov(ecx, Operand(esp, receiver_offset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 122 | |
| 123 | __ cmp(ecx, isolate()->factory()->undefined_value()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 124 | __ j(not_equal, &ok, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 125 | |
| 126 | __ mov(ecx, GlobalObjectOperand()); |
| 127 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalProxyOffset)); |
| 128 | |
| 129 | __ mov(Operand(esp, receiver_offset), ecx); |
| 130 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 131 | __ bind(&ok); |
| 132 | } |
| 133 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 134 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 135 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 136 | // the frame (that is done below). |
| 137 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 138 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 139 | info->set_prologue_offset(masm_->pc_offset()); |
| 140 | __ Prologue(info->IsCodePreAgingActive()); |
| 141 | info->AddNoFrameRange(0, masm_->pc_offset()); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 142 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 143 | { Comment cmnt(masm_, "[ Allocate locals"); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 144 | int locals_count = info->scope()->num_stack_slots(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 145 | // Generators allocate locals, if any, in context slots. |
| 146 | DCHECK(!info->function()->is_generator() || locals_count == 0); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 147 | if (locals_count == 1) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 148 | __ push(Immediate(isolate()->factory()->undefined_value())); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 149 | } else if (locals_count > 1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 150 | if (locals_count >= 128) { |
| 151 | Label ok; |
| 152 | __ mov(ecx, esp); |
| 153 | __ sub(ecx, Immediate(locals_count * kPointerSize)); |
| 154 | ExternalReference stack_limit = |
| 155 | ExternalReference::address_of_real_stack_limit(isolate()); |
| 156 | __ cmp(ecx, Operand::StaticVariable(stack_limit)); |
| 157 | __ j(above_equal, &ok, Label::kNear); |
| 158 | __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 159 | __ bind(&ok); |
| 160 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 161 | __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 162 | const int kMaxPushes = 32; |
| 163 | if (locals_count >= kMaxPushes) { |
| 164 | int loop_iterations = locals_count / kMaxPushes; |
| 165 | __ mov(ecx, loop_iterations); |
| 166 | Label loop_header; |
| 167 | __ bind(&loop_header); |
| 168 | // Do pushes. |
| 169 | for (int i = 0; i < kMaxPushes; i++) { |
| 170 | __ push(eax); |
| 171 | } |
| 172 | __ dec(ecx); |
| 173 | __ j(not_zero, &loop_header, Label::kNear); |
| 174 | } |
| 175 | int remaining = locals_count % kMaxPushes; |
| 176 | // Emit the remaining pushes. |
| 177 | for (int i = 0; i < remaining; i++) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 178 | __ push(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 179 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 180 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 181 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 182 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 183 | bool function_in_register = true; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 184 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 185 | // Possibly allocate a local context. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 186 | int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 187 | if (heap_slots > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 188 | Comment cmnt(masm_, "[ Allocate context"); |
| 189 | bool need_write_barrier = true; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 190 | // Argument to NewContext is the function, which is still in edi. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 191 | if (FLAG_harmony_scoping && info->scope()->is_script_scope()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 192 | __ push(edi); |
| 193 | __ Push(info->scope()->GetScopeInfo()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 194 | __ CallRuntime(Runtime::kNewScriptContext, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 195 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 196 | FastNewContextStub stub(isolate(), heap_slots); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 197 | __ CallStub(&stub); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 198 | // Result of FastNewContextStub is always in new space. |
| 199 | need_write_barrier = false; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 200 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | __ push(edi); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 202 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 203 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 204 | function_in_register = false; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 205 | // Context is returned in eax. It replaces the context passed to us. |
| 206 | // It's saved in the stack and kept live in esi. |
| 207 | __ mov(esi, eax); |
| 208 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 209 | |
| 210 | // Copy parameters into context if necessary. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 211 | int num_parameters = info->scope()->num_parameters(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 212 | for (int i = 0; i < num_parameters; i++) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 213 | Variable* var = scope()->parameter(i); |
| 214 | if (var->IsContextSlot()) { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 215 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 216 | (num_parameters - 1 - i) * kPointerSize; |
| 217 | // Load parameter from stack. |
| 218 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 219 | // Store it in the context. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 220 | int context_offset = Context::SlotOffset(var->index()); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 221 | __ mov(Operand(esi, context_offset), eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 222 | // Update the write barrier. This clobbers eax and ebx. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 223 | if (need_write_barrier) { |
| 224 | __ RecordWriteContextSlot(esi, |
| 225 | context_offset, |
| 226 | eax, |
| 227 | ebx, |
| 228 | kDontSaveFPRegs); |
| 229 | } else if (FLAG_debug_code) { |
| 230 | Label done; |
| 231 | __ JumpIfInNewSpace(esi, eax, &done, Label::kNear); |
| 232 | __ Abort(kExpectedNewSpaceObject); |
| 233 | __ bind(&done); |
| 234 | } |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 239 | Variable* arguments = scope()->arguments(); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 240 | if (arguments != NULL) { |
| 241 | // Function uses arguments object. |
| 242 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 243 | if (function_in_register) { |
| 244 | __ push(edi); |
| 245 | } else { |
| 246 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 247 | } |
| 248 | // Receiver is just before the parameters on the caller's stack. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 249 | int num_parameters = info->scope()->num_parameters(); |
| 250 | int offset = num_parameters * kPointerSize; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 251 | __ lea(edx, |
| 252 | Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 253 | __ push(edx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 254 | __ push(Immediate(Smi::FromInt(num_parameters))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 255 | // Arguments to ArgumentsAccessStub: |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 256 | // function, receiver address, parameter count. |
| 257 | // The stub will rewrite receiver and parameter count if the previous |
| 258 | // stack frame was an arguments adapter frame. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 259 | ArgumentsAccessStub::Type type; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | if (strict_mode() == STRICT) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 261 | type = ArgumentsAccessStub::NEW_STRICT; |
| 262 | } else if (function()->has_duplicate_parameters()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 263 | type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 264 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 265 | type = ArgumentsAccessStub::NEW_SLOPPY_FAST; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 266 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 267 | ArgumentsAccessStub stub(isolate(), type); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 268 | __ CallStub(&stub); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 269 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 270 | SetVar(arguments, eax, ebx, edx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 273 | if (FLAG_trace) { |
| 274 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 275 | } |
| 276 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 277 | // Visit the declarations and body unless there is an illegal |
| 278 | // redeclaration. |
| 279 | if (scope()->HasIllegalRedeclaration()) { |
| 280 | Comment cmnt(masm_, "[ Declarations"); |
| 281 | scope()->VisitIllegalRedeclaration(this); |
| 282 | |
| 283 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 284 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 285 | { Comment cmnt(masm_, "[ Declarations"); |
| 286 | // For named function expressions, declare the function name as a |
| 287 | // constant. |
| 288 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 289 | VariableDeclaration* function = scope()->function(); |
| 290 | DCHECK(function->proxy()->var()->mode() == CONST || |
| 291 | function->proxy()->var()->mode() == CONST_LEGACY); |
| 292 | DCHECK(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 293 | VisitVariableDeclaration(function); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 294 | } |
| 295 | VisitDeclarations(scope()->declarations()); |
| 296 | } |
| 297 | |
| 298 | { Comment cmnt(masm_, "[ Stack check"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 299 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 300 | Label ok; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 301 | ExternalReference stack_limit |
| 302 | = ExternalReference::address_of_stack_limit(isolate()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 303 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 304 | __ j(above_equal, &ok, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 305 | __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 306 | __ bind(&ok); |
| 307 | } |
| 308 | |
| 309 | { Comment cmnt(masm_, "[ Body"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 310 | DCHECK(loop_depth() == 0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 311 | VisitStatements(function()->body()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 312 | DCHECK(loop_depth() == 0); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 313 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 316 | // Always emit a 'return undefined' in case control fell off the end of |
| 317 | // the body. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 318 | { Comment cmnt(masm_, "[ return <undefined>;"); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 319 | __ mov(eax, isolate()->factory()->undefined_value()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 320 | EmitReturnSequence(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 323 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 324 | |
Ben Murdoch | db5a90a | 2011-01-06 18:27:03 +0000 | [diff] [blame] | 325 | void FullCodeGenerator::ClearAccumulator() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 326 | __ Move(eax, Immediate(Smi::FromInt(0))); |
Ben Murdoch | db5a90a | 2011-01-06 18:27:03 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 330 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 331 | __ mov(ebx, Immediate(profiling_counter_)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | __ sub(FieldOperand(ebx, Cell::kValueOffset), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 333 | Immediate(Smi::FromInt(delta))); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 338 | int reset_value = FLAG_interrupt_budget; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 339 | __ mov(ebx, Immediate(profiling_counter_)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 340 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 341 | Immediate(Smi::FromInt(reset_value))); |
| 342 | } |
| 343 | |
| 344 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 345 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 346 | Label* back_edge_target) { |
| 347 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 348 | Label ok; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 349 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 350 | DCHECK(back_edge_target->is_bound()); |
| 351 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 352 | int weight = Min(kMaxBackEdgeWeight, |
| 353 | Max(1, distance / kCodeSizeMultiplier)); |
| 354 | EmitProfilingCounterDecrement(weight); |
| 355 | __ j(positive, &ok, Label::kNear); |
| 356 | __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 357 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 358 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 359 | // the AST id from the unoptimized code in order to use it as a key into |
| 360 | // the deoptimization input data found in the optimized code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 361 | RecordBackEdge(stmt->OsrEntryId()); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 362 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 363 | EmitProfilingCounterReset(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 364 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 365 | __ bind(&ok); |
| 366 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 367 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 368 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 369 | // we want it to work if it is. |
| 370 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 374 | void FullCodeGenerator::EmitReturnSequence() { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 375 | Comment cmnt(masm_, "[ Return sequence"); |
| 376 | if (return_label_.is_bound()) { |
| 377 | __ jmp(&return_label_); |
| 378 | } else { |
| 379 | // Common return label |
| 380 | __ bind(&return_label_); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 381 | if (FLAG_trace) { |
| 382 | __ push(eax); |
| 383 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 384 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 385 | // Pretend that the exit is a backwards jump to the entry. |
| 386 | int weight = 1; |
| 387 | if (info_->ShouldSelfOptimize()) { |
| 388 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 389 | } else { |
| 390 | int distance = masm_->pc_offset(); |
| 391 | weight = Min(kMaxBackEdgeWeight, |
| 392 | Max(1, distance / kCodeSizeMultiplier)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 393 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | EmitProfilingCounterDecrement(weight); |
| 395 | Label ok; |
| 396 | __ j(positive, &ok, Label::kNear); |
| 397 | __ push(eax); |
| 398 | __ call(isolate()->builtins()->InterruptCheck(), |
| 399 | RelocInfo::CODE_TARGET); |
| 400 | __ pop(eax); |
| 401 | EmitProfilingCounterReset(); |
| 402 | __ bind(&ok); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 403 | #ifdef DEBUG |
| 404 | // Add a label for checking the size of the code used for returning. |
| 405 | Label check_exit_codesize; |
| 406 | masm_->bind(&check_exit_codesize); |
| 407 | #endif |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 408 | SetSourcePosition(function()->end_position() - 1); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 409 | __ RecordJSReturn(); |
| 410 | // Do not use the leave instruction here because it is too short to |
| 411 | // patch with the code required by the debugger. |
| 412 | __ mov(esp, ebp); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 413 | int no_frame_start = masm_->pc_offset(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 414 | __ pop(ebp); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 415 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 416 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 417 | __ Ret(arguments_bytes, ecx); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 418 | // Check that the size of the code used for returning is large enough |
| 419 | // for the debugger's requirements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 420 | DCHECK(Assembler::kJSReturnSequenceLength <= |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 421 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 422 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
| 426 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 427 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 428 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 432 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 433 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 434 | codegen()->GetVar(result_register(), var); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 438 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 439 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 440 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 441 | // Memory operands can be pushed directly. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 442 | __ push(operand); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 446 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 447 | // For simplicity we always test the accumulator register. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 448 | codegen()->GetVar(result_register(), var); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 449 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 450 | codegen()->DoTest(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
| 454 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 455 | UNREACHABLE(); // Not used on IA32. |
| 456 | } |
| 457 | |
| 458 | |
| 459 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 460 | Heap::RootListIndex index) const { |
| 461 | UNREACHABLE(); // Not used on IA32. |
| 462 | } |
| 463 | |
| 464 | |
| 465 | void FullCodeGenerator::StackValueContext::Plug( |
| 466 | Heap::RootListIndex index) const { |
| 467 | UNREACHABLE(); // Not used on IA32. |
| 468 | } |
| 469 | |
| 470 | |
| 471 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 472 | UNREACHABLE(); // Not used on IA32. |
| 473 | } |
| 474 | |
| 475 | |
| 476 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 477 | } |
| 478 | |
| 479 | |
| 480 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 481 | Handle<Object> lit) const { |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 482 | if (lit->IsSmi()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 483 | __ SafeMove(result_register(), Immediate(lit)); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 484 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 485 | __ Move(result_register(), Immediate(lit)); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 486 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | |
| 490 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 491 | if (lit->IsSmi()) { |
| 492 | __ SafePush(Immediate(lit)); |
| 493 | } else { |
| 494 | __ push(Immediate(lit)); |
| 495 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
| 499 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 500 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 501 | true, |
| 502 | true_label_, |
| 503 | false_label_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 504 | DCHECK(!lit->IsUndetectableObject()); // There are no undetectable literals. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 505 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 506 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 507 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 508 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 509 | } else if (lit->IsString()) { |
| 510 | if (String::cast(*lit)->length() == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 511 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 512 | } else { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 513 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 514 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 515 | } else if (lit->IsSmi()) { |
| 516 | if (Smi::cast(*lit)->value() == 0) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 517 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 518 | } else { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 519 | if (true_label_ != fall_through_) __ jmp(true_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 520 | } |
| 521 | } else { |
| 522 | // For simplicity we always test the accumulator register. |
| 523 | __ mov(result_register(), lit); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 524 | codegen()->DoTest(this); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
| 528 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 529 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 530 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 531 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 532 | __ Drop(count); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 536 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 537 | int count, |
| 538 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 539 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 540 | __ Drop(count); |
| 541 | __ Move(result_register(), reg); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 545 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 546 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 547 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 548 | if (count > 1) __ Drop(count - 1); |
| 549 | __ mov(Operand(esp, 0), reg); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 554 | Register reg) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 555 | DCHECK(count > 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 556 | // For simplicity we always test the accumulator register. |
| 557 | __ Drop(count); |
| 558 | __ Move(result_register(), reg); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 559 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 560 | codegen()->DoTest(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | |
| 564 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 565 | Label* materialize_false) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 566 | DCHECK(materialize_true == materialize_false); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 567 | __ bind(materialize_true); |
| 568 | } |
| 569 | |
| 570 | |
| 571 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 572 | Label* materialize_true, |
| 573 | Label* materialize_false) const { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 574 | Label done; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 575 | __ bind(materialize_true); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 576 | __ mov(result_register(), isolate()->factory()->true_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 577 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 578 | __ bind(materialize_false); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 579 | __ mov(result_register(), isolate()->factory()->false_value()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 580 | __ bind(&done); |
| 581 | } |
| 582 | |
| 583 | |
| 584 | void FullCodeGenerator::StackValueContext::Plug( |
| 585 | Label* materialize_true, |
| 586 | Label* materialize_false) const { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 587 | Label done; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 588 | __ bind(materialize_true); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 589 | __ push(Immediate(isolate()->factory()->true_value())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 590 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 591 | __ bind(materialize_false); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 592 | __ push(Immediate(isolate()->factory()->false_value())); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 593 | __ bind(&done); |
| 594 | } |
| 595 | |
| 596 | |
| 597 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 598 | Label* materialize_false) const { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | DCHECK(materialize_true == true_label_); |
| 600 | DCHECK(materialize_false == false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | |
| 604 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 605 | } |
| 606 | |
| 607 | |
| 608 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 609 | Handle<Object> value = flag |
| 610 | ? isolate()->factory()->true_value() |
| 611 | : isolate()->factory()->false_value(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 612 | __ mov(result_register(), value); |
| 613 | } |
| 614 | |
| 615 | |
| 616 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 617 | Handle<Object> value = flag |
| 618 | ? isolate()->factory()->true_value() |
| 619 | : isolate()->factory()->false_value(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 620 | __ push(Immediate(value)); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 625 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 626 | true, |
| 627 | true_label_, |
| 628 | false_label_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 629 | if (flag) { |
| 630 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 631 | } else { |
| 632 | if (false_label_ != fall_through_) __ jmp(false_label_); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 637 | void FullCodeGenerator::DoTest(Expression* condition, |
| 638 | Label* if_true, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 639 | Label* if_false, |
| 640 | Label* fall_through) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 641 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
| 642 | CallIC(ic, condition->test_id()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 643 | __ test(result_register(), result_register()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 644 | // The stub returns nonzero for true. |
| 645 | Split(not_zero, if_true, if_false, fall_through); |
| 646 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 647 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 648 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 649 | void FullCodeGenerator::Split(Condition cc, |
| 650 | Label* if_true, |
| 651 | Label* if_false, |
| 652 | Label* fall_through) { |
| 653 | if (if_false == fall_through) { |
| 654 | __ j(cc, if_true); |
| 655 | } else if (if_true == fall_through) { |
| 656 | __ j(NegateCondition(cc), if_false); |
| 657 | } else { |
| 658 | __ j(cc, if_true); |
| 659 | __ jmp(if_false); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
| 663 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 664 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 665 | DCHECK(var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 666 | // Offset is negative because higher indexes are at lower addresses. |
| 667 | int offset = -var->index() * kPointerSize; |
| 668 | // Adjust by a (parameter or local) base offset. |
| 669 | if (var->IsParameter()) { |
| 670 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 671 | } else { |
| 672 | offset += JavaScriptFrameConstants::kLocal0Offset; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 673 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 674 | return Operand(ebp, offset); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 678 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 679 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 680 | if (var->IsContextSlot()) { |
| 681 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 682 | __ LoadContext(scratch, context_chain_length); |
| 683 | return ContextOperand(scratch, var->index()); |
| 684 | } else { |
| 685 | return StackOperand(var); |
| 686 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 690 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 691 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 692 | MemOperand location = VarOperand(var, dest); |
| 693 | __ mov(dest, location); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | void FullCodeGenerator::SetVar(Variable* var, |
| 698 | Register src, |
| 699 | Register scratch0, |
| 700 | Register scratch1) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 701 | DCHECK(var->IsContextSlot() || var->IsStackAllocated()); |
| 702 | DCHECK(!scratch0.is(src)); |
| 703 | DCHECK(!scratch0.is(scratch1)); |
| 704 | DCHECK(!scratch1.is(src)); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 705 | MemOperand location = VarOperand(var, scratch0); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 706 | __ mov(location, src); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 707 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 708 | // Emit the write barrier code if the location is in the heap. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 709 | if (var->IsContextSlot()) { |
| 710 | int offset = Context::SlotOffset(var->index()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 711 | DCHECK(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 712 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
| 716 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 717 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 718 | bool should_normalize, |
| 719 | Label* if_true, |
| 720 | Label* if_false) { |
| 721 | // Only prepare for bailouts before splits if we're in a test |
| 722 | // context. Otherwise, we let the Visit function deal with the |
| 723 | // preparation to avoid preparing with the same AST id twice. |
| 724 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 725 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 726 | Label skip; |
| 727 | if (should_normalize) __ jmp(&skip, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 728 | PrepareForBailout(expr, TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 729 | if (should_normalize) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 730 | __ cmp(eax, isolate()->factory()->true_value()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 731 | Split(equal, if_true, if_false, NULL); |
| 732 | __ bind(&skip); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 737 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
| 738 | // The variable in the declaration always resides in the current context. |
| 739 | DCHECK_EQ(0, scope()->ContextChainLength(variable->scope())); |
| 740 | if (generate_debug_code_) { |
| 741 | // Check that we're not inside a with or catch context. |
| 742 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 743 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
| 744 | __ Check(not_equal, kDeclarationInWithContext); |
| 745 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
| 746 | __ Check(not_equal, kDeclarationInCatchContext); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | |
| 751 | void FullCodeGenerator::VisitVariableDeclaration( |
| 752 | VariableDeclaration* declaration) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 753 | // If it was not possible to allocate the variable at compile time, we |
| 754 | // need to "declare" it at runtime to make sure it actually exists in the |
| 755 | // local context. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | VariableProxy* proxy = declaration->proxy(); |
| 757 | VariableMode mode = declaration->mode(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 758 | Variable* variable = proxy->var(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 759 | bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 760 | switch (variable->location()) { |
| 761 | case Variable::UNALLOCATED: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 762 | globals_->Add(variable->name(), zone()); |
| 763 | globals_->Add(variable->binding_needs_init() |
| 764 | ? isolate()->factory()->the_hole_value() |
| 765 | : isolate()->factory()->undefined_value(), zone()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 766 | break; |
| 767 | |
| 768 | case Variable::PARAMETER: |
| 769 | case Variable::LOCAL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | if (hole_init) { |
| 771 | Comment cmnt(masm_, "[ VariableDeclaration"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 772 | __ mov(StackOperand(variable), |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 773 | Immediate(isolate()->factory()->the_hole_value())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 774 | } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 775 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 776 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 777 | case Variable::CONTEXT: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 778 | if (hole_init) { |
| 779 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 780 | EmitDebugCheckDeclarationContext(variable); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 781 | __ mov(ContextOperand(esi, variable->index()), |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 782 | Immediate(isolate()->factory()->the_hole_value())); |
| 783 | // No write barrier since the hole value is in old space. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 784 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 785 | } |
| 786 | break; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 787 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 788 | case Variable::LOOKUP: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 789 | Comment cmnt(masm_, "[ VariableDeclaration"); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 790 | __ push(esi); |
| 791 | __ push(Immediate(variable->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 792 | // VariableDeclaration nodes are always introduced in one of four modes. |
| 793 | DCHECK(IsDeclaredVariableMode(mode)); |
| 794 | PropertyAttributes attr = |
| 795 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 796 | __ push(Immediate(Smi::FromInt(attr))); |
| 797 | // Push initial value, if any. |
| 798 | // Note: For variables we must not push an initial value (such as |
| 799 | // 'undefined') because we may have a (legal) redeclaration and we |
| 800 | // must not destroy the current value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 801 | if (hole_init) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 802 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 803 | } else { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 804 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 805 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 806 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 807 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 808 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 809 | } |
| 810 | } |
| 811 | |
| 812 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 813 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 814 | FunctionDeclaration* declaration) { |
| 815 | VariableProxy* proxy = declaration->proxy(); |
| 816 | Variable* variable = proxy->var(); |
| 817 | switch (variable->location()) { |
| 818 | case Variable::UNALLOCATED: { |
| 819 | globals_->Add(variable->name(), zone()); |
| 820 | Handle<SharedFunctionInfo> function = |
| 821 | Compiler::BuildFunctionInfo(declaration->fun(), script(), info_); |
| 822 | // Check for stack-overflow exception. |
| 823 | if (function.is_null()) return SetStackOverflow(); |
| 824 | globals_->Add(function, zone()); |
| 825 | break; |
| 826 | } |
| 827 | |
| 828 | case Variable::PARAMETER: |
| 829 | case Variable::LOCAL: { |
| 830 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 831 | VisitForAccumulatorValue(declaration->fun()); |
| 832 | __ mov(StackOperand(variable), result_register()); |
| 833 | break; |
| 834 | } |
| 835 | |
| 836 | case Variable::CONTEXT: { |
| 837 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 838 | EmitDebugCheckDeclarationContext(variable); |
| 839 | VisitForAccumulatorValue(declaration->fun()); |
| 840 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 841 | // We know that we have written a function, which is not a smi. |
| 842 | __ RecordWriteContextSlot(esi, |
| 843 | Context::SlotOffset(variable->index()), |
| 844 | result_register(), |
| 845 | ecx, |
| 846 | kDontSaveFPRegs, |
| 847 | EMIT_REMEMBERED_SET, |
| 848 | OMIT_SMI_CHECK); |
| 849 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | case Variable::LOOKUP: { |
| 854 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 855 | __ push(esi); |
| 856 | __ push(Immediate(variable->name())); |
| 857 | __ push(Immediate(Smi::FromInt(NONE))); |
| 858 | VisitForStackValue(declaration->fun()); |
| 859 | __ CallRuntime(Runtime::kDeclareLookupSlot, 4); |
| 860 | break; |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | |
| 866 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
| 867 | Variable* variable = declaration->proxy()->var(); |
| 868 | DCHECK(variable->location() == Variable::CONTEXT); |
| 869 | DCHECK(variable->interface()->IsFrozen()); |
| 870 | |
| 871 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 872 | EmitDebugCheckDeclarationContext(variable); |
| 873 | |
| 874 | // Load instance object. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 875 | __ LoadContext(eax, scope_->ContextChainLength(scope_->ScriptScope())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 876 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 877 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
| 878 | |
| 879 | // Assign it. |
| 880 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 881 | // We know that we have written a module, which is not a smi. |
| 882 | __ RecordWriteContextSlot(esi, |
| 883 | Context::SlotOffset(variable->index()), |
| 884 | eax, |
| 885 | ecx, |
| 886 | kDontSaveFPRegs, |
| 887 | EMIT_REMEMBERED_SET, |
| 888 | OMIT_SMI_CHECK); |
| 889 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 890 | |
| 891 | // Traverse into body. |
| 892 | Visit(declaration->module()); |
| 893 | } |
| 894 | |
| 895 | |
| 896 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 897 | VariableProxy* proxy = declaration->proxy(); |
| 898 | Variable* variable = proxy->var(); |
| 899 | switch (variable->location()) { |
| 900 | case Variable::UNALLOCATED: |
| 901 | // TODO(rossberg) |
| 902 | break; |
| 903 | |
| 904 | case Variable::CONTEXT: { |
| 905 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 906 | EmitDebugCheckDeclarationContext(variable); |
| 907 | // TODO(rossberg) |
| 908 | break; |
| 909 | } |
| 910 | |
| 911 | case Variable::PARAMETER: |
| 912 | case Variable::LOCAL: |
| 913 | case Variable::LOOKUP: |
| 914 | UNREACHABLE(); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | |
| 919 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 920 | // TODO(rossberg) |
| 921 | } |
| 922 | |
| 923 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 924 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 925 | // Call the runtime to declare the globals. |
| 926 | __ push(esi); // The context is the first argument. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 927 | __ Push(pairs); |
| 928 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 929 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 930 | // Return value is ignored. |
| 931 | } |
| 932 | |
| 933 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 934 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 935 | // Call the runtime to declare the modules. |
| 936 | __ Push(descriptions); |
| 937 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 938 | // Return value is ignored. |
| 939 | } |
| 940 | |
| 941 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 942 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 943 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 944 | Breakable nested_statement(this, stmt); |
| 945 | SetStatementPosition(stmt); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 946 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 947 | // Keep the switch value on the stack until a case matches. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 948 | VisitForStackValue(stmt->tag()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 949 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 950 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 951 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 952 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 953 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 954 | Label next_test; // Recycled for each test. |
| 955 | // Compile all the tests with branches to their bodies. |
| 956 | for (int i = 0; i < clauses->length(); i++) { |
| 957 | CaseClause* clause = clauses->at(i); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 958 | clause->body_target()->Unuse(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 959 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 960 | // The default is not a test, but remember it as final fall through. |
| 961 | if (clause->is_default()) { |
| 962 | default_clause = clause; |
| 963 | continue; |
| 964 | } |
| 965 | |
| 966 | Comment cmnt(masm_, "[ Case comparison"); |
| 967 | __ bind(&next_test); |
| 968 | next_test.Unuse(); |
| 969 | |
| 970 | // Compile the label expression. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 971 | VisitForAccumulatorValue(clause->label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 972 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 973 | // Perform the comparison as if via '==='. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 974 | __ mov(edx, Operand(esp, 0)); // Switch value. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 975 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 976 | JumpPatchSite patch_site(masm_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 977 | if (inline_smi_code) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 978 | Label slow_case; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 979 | __ mov(ecx, edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 980 | __ or_(ecx, eax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 981 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 982 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 983 | __ cmp(edx, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 984 | __ j(not_equal, &next_test); |
| 985 | __ Drop(1); // Switch value is no longer needed. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 986 | __ jmp(clause->body_target()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 987 | __ bind(&slow_case); |
| 988 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 989 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 990 | // Record position before stub call for type feedback. |
| 991 | SetSourcePosition(clause->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 992 | Handle<Code> ic = |
| 993 | CodeFactory::CompareIC(isolate(), Token::EQ_STRICT).code(); |
| 994 | CallIC(ic, clause->CompareId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 995 | patch_site.EmitPatchInfo(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 996 | |
| 997 | Label skip; |
| 998 | __ jmp(&skip, Label::kNear); |
| 999 | PrepareForBailout(clause, TOS_REG); |
| 1000 | __ cmp(eax, isolate()->factory()->true_value()); |
| 1001 | __ j(not_equal, &next_test); |
| 1002 | __ Drop(1); |
| 1003 | __ jmp(clause->body_target()); |
| 1004 | __ bind(&skip); |
| 1005 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1006 | __ test(eax, eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1007 | __ j(not_equal, &next_test); |
| 1008 | __ Drop(1); // Switch value is no longer needed. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1009 | __ jmp(clause->body_target()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | // Discard the test value and jump to the default if present, otherwise to |
| 1013 | // the end of the statement. |
| 1014 | __ bind(&next_test); |
| 1015 | __ Drop(1); // Switch value is no longer needed. |
| 1016 | if (default_clause == NULL) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1017 | __ jmp(nested_statement.break_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1018 | } else { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1019 | __ jmp(default_clause->body_target()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | // Compile all the case bodies. |
| 1023 | for (int i = 0; i < clauses->length(); i++) { |
| 1024 | Comment cmnt(masm_, "[ Case body"); |
| 1025 | CaseClause* clause = clauses->at(i); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1026 | __ bind(clause->body_target()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1027 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1028 | VisitStatements(clause->statements()); |
| 1029 | } |
| 1030 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1031 | __ bind(nested_statement.break_label()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1032 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | |
| 1036 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1037 | Comment cmnt(masm_, "[ ForInStatement"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1038 | FeedbackVectorSlot slot = stmt->ForInFeedbackSlot(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1039 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1040 | SetStatementPosition(stmt); |
| 1041 | |
| 1042 | Label loop, exit; |
| 1043 | ForIn loop_statement(this, stmt); |
| 1044 | increment_loop_depth(); |
| 1045 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1046 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1047 | // over the loop. See ECMA-262 version 5, section 12.6.4. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1048 | SetExpressionPosition(stmt->enumerable()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1049 | VisitForAccumulatorValue(stmt->enumerable()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1050 | __ cmp(eax, isolate()->factory()->undefined_value()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1051 | __ j(equal, &exit); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1052 | __ cmp(eax, isolate()->factory()->null_value()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1053 | __ j(equal, &exit); |
| 1054 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1055 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1056 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1057 | // Convert the object to a JS object. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1058 | Label convert, done_convert; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1059 | __ JumpIfSmi(eax, &convert, Label::kNear); |
| 1060 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1061 | __ j(above_equal, &done_convert, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1062 | __ bind(&convert); |
| 1063 | __ push(eax); |
| 1064 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1065 | __ bind(&done_convert); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1066 | PrepareForBailoutForId(stmt->ToObjectId(), TOS_REG); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1067 | __ push(eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1068 | |
| 1069 | // Check for proxies. |
| 1070 | Label call_runtime, use_cache, fixed_array; |
| 1071 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1072 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1073 | __ j(below_equal, &call_runtime); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1074 | |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1075 | // Check cache validity in generated code. This is a fast case for |
| 1076 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1077 | // guarantee cache validity, call the runtime system to check cache |
| 1078 | // validity or get the property names in a fixed array. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1079 | __ CheckEnumCache(&call_runtime); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1080 | |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1081 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1082 | __ jmp(&use_cache, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1083 | |
| 1084 | // Get the set of properties to enumerate. |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1085 | __ bind(&call_runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1086 | __ push(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1087 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1088 | PrepareForBailoutForId(stmt->EnumId(), TOS_REG); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1089 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1090 | isolate()->factory()->meta_map()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1091 | __ j(not_equal, &fixed_array); |
| 1092 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1093 | |
| 1094 | // We got a map in register eax. Get the enumeration cache from it. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1095 | Label no_descriptors; |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1096 | __ bind(&use_cache); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1097 | |
| 1098 | __ EnumLength(edx, eax); |
| 1099 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1100 | __ j(equal, &no_descriptors); |
| 1101 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1102 | __ LoadInstanceDescriptors(eax, ecx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1103 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
| 1104 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1105 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1106 | // Set up the four remaining stack slots. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1107 | __ push(eax); // Map. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1108 | __ push(ecx); // Enumeration cache. |
| 1109 | __ push(edx); // Number of valid entries for the map in the enum cache. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1110 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1111 | __ jmp(&loop); |
| 1112 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1113 | __ bind(&no_descriptors); |
| 1114 | __ add(esp, Immediate(kPointerSize)); |
| 1115 | __ jmp(&exit); |
| 1116 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1117 | // We got a fixed array in register eax. Iterate through that. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1118 | Label non_proxy; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1119 | __ bind(&fixed_array); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1120 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1121 | // No need for a write barrier, we are storing a Smi in the feedback vector. |
| 1122 | __ LoadHeapObject(ebx, FeedbackVector()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1123 | int vector_index = FeedbackVector()->GetIndex(slot); |
| 1124 | __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(vector_index)), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1125 | Immediate(TypeFeedbackVector::MegamorphicSentinel(isolate()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1126 | |
| 1127 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1128 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1129 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1130 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1131 | __ j(above, &non_proxy); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1132 | __ Move(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1133 | __ bind(&non_proxy); |
| 1134 | __ push(ebx); // Smi |
| 1135 | __ push(eax); // Array |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1136 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1137 | __ push(eax); // Fixed array length (as smi). |
| 1138 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1139 | |
| 1140 | // Generate code for doing the condition check. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1141 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1142 | __ bind(&loop); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1143 | SetExpressionPosition(stmt->each()); |
| 1144 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1145 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1146 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1147 | __ j(above_equal, loop_statement.break_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1148 | |
| 1149 | // Get the current entry of the array into register ebx. |
| 1150 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1151 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1152 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1153 | // Get the expected map from the stack or a smi in the |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1154 | // permanent slow case into register edx. |
| 1155 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1156 | |
| 1157 | // Check if the expected map still matches that of the enumerable. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1158 | // If not, we may have to filter the key. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1159 | Label update_each; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1160 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1161 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1162 | __ j(equal, &update_each, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1163 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1164 | // For proxies, no filtering is done. |
| 1165 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1166 | DCHECK(Smi::FromInt(0) == 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1167 | __ test(edx, edx); |
| 1168 | __ j(zero, &update_each); |
| 1169 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1170 | // Convert the entry to a string or null if it isn't a property |
| 1171 | // anymore. If the property has been removed while iterating, we |
| 1172 | // just skip it. |
| 1173 | __ push(ecx); // Enumerable. |
| 1174 | __ push(ebx); // Current entry. |
| 1175 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1176 | __ test(eax, eax); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1177 | __ j(equal, loop_statement.continue_label()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1178 | __ mov(ebx, eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1179 | |
| 1180 | // Update the 'each' property or variable from the possibly filtered |
| 1181 | // entry in register ebx. |
| 1182 | __ bind(&update_each); |
| 1183 | __ mov(result_register(), ebx); |
| 1184 | // Perform the assignment as if via '='. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1185 | { EffectContext context(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1186 | EmitAssignment(stmt->each()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1187 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1188 | |
| 1189 | // Generate code for the body of the loop. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1190 | Visit(stmt->body()); |
| 1191 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1192 | // Generate code for going to the next element by incrementing the |
| 1193 | // index (smi) stored on top of the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1194 | __ bind(loop_statement.continue_label()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1195 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1196 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1197 | EmitBackEdgeBookkeeping(stmt, &loop); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1198 | __ jmp(&loop); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1199 | |
| 1200 | // Remove the pointers stored on the stack. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1201 | __ bind(loop_statement.break_label()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1202 | __ add(esp, Immediate(5 * kPointerSize)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1203 | |
| 1204 | // Exit and decrement the loop depth. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1205 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1206 | __ bind(&exit); |
| 1207 | decrement_loop_depth(); |
| 1208 | } |
| 1209 | |
| 1210 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1211 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1212 | bool pretenure) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1213 | // Use the fast case closure allocation code that allocates in new |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1214 | // space for nested functions that don't need literals cloning. If |
| 1215 | // we're running with the --always-opt or the --prepare-always-opt |
| 1216 | // flag, we need to use the runtime function so that the new function |
| 1217 | // we are creating here gets a chance to have its code optimized and |
| 1218 | // doesn't just get a copy of the existing unoptimized code. |
| 1219 | if (!FLAG_always_opt && |
| 1220 | !FLAG_prepare_always_opt && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1221 | !pretenure && |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1222 | scope()->is_function_scope() && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1223 | info->num_literals() == 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1224 | FastNewClosureStub stub(isolate(), info->strict_mode(), info->kind()); |
| 1225 | __ mov(ebx, Immediate(info)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1226 | __ CallStub(&stub); |
| 1227 | } else { |
| 1228 | __ push(esi); |
| 1229 | __ push(Immediate(info)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1230 | __ push(Immediate(pretenure |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1231 | ? isolate()->factory()->true_value() |
| 1232 | : isolate()->factory()->false_value())); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 1233 | __ CallRuntime(Runtime::kNewClosure, 3); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1234 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1235 | context()->Plug(eax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1239 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1240 | Comment cmnt(masm_, "[ VariableProxy"); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1241 | EmitVariableLoad(expr); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1245 | void FullCodeGenerator::EmitLoadHomeObject(SuperReference* expr) { |
| 1246 | Comment cnmt(masm_, "[ SuperReference "); |
| 1247 | |
| 1248 | __ mov(LoadDescriptor::ReceiverRegister(), |
| 1249 | Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1250 | |
| 1251 | Handle<Symbol> home_object_symbol(isolate()->heap()->home_object_symbol()); |
| 1252 | __ mov(LoadDescriptor::NameRegister(), home_object_symbol); |
| 1253 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1254 | if (FLAG_vector_ics) { |
| 1255 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
| 1256 | Immediate(SmiFromSlot(expr->HomeObjectFeedbackSlot()))); |
| 1257 | CallLoadIC(NOT_CONTEXTUAL); |
| 1258 | } else { |
| 1259 | CallLoadIC(NOT_CONTEXTUAL, expr->HomeObjectFeedbackId()); |
| 1260 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1261 | |
| 1262 | __ cmp(eax, isolate()->factory()->undefined_value()); |
| 1263 | Label done; |
| 1264 | __ j(not_equal, &done); |
| 1265 | __ CallRuntime(Runtime::kThrowNonMethodError, 0); |
| 1266 | __ bind(&done); |
| 1267 | } |
| 1268 | |
| 1269 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1270 | void FullCodeGenerator::EmitSetHomeObjectIfNeeded(Expression* initializer, |
| 1271 | int offset) { |
| 1272 | if (NeedsHomeObject(initializer)) { |
| 1273 | __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 1274 | __ mov(StoreDescriptor::NameRegister(), |
| 1275 | Immediate(isolate()->factory()->home_object_symbol())); |
| 1276 | __ mov(StoreDescriptor::ValueRegister(), |
| 1277 | Operand(esp, offset * kPointerSize)); |
| 1278 | CallStoreIC(); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1283 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(VariableProxy* proxy, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1284 | TypeofState typeof_state, |
| 1285 | Label* slow) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1286 | Register context = esi; |
| 1287 | Register temp = edx; |
| 1288 | |
| 1289 | Scope* s = scope(); |
| 1290 | while (s != NULL) { |
| 1291 | if (s->num_heap_slots() > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1292 | if (s->calls_sloppy_eval()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1293 | // Check that extension is NULL. |
| 1294 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1295 | Immediate(0)); |
| 1296 | __ j(not_equal, slow); |
| 1297 | } |
| 1298 | // Load next context in chain. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1299 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1300 | // Walk the rest of the chain without clobbering esi. |
| 1301 | context = temp; |
| 1302 | } |
| 1303 | // If no outer scope calls eval, we do not need to check more |
| 1304 | // context extensions. If we have reached an eval scope, we check |
| 1305 | // all extensions from this point. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1306 | if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1307 | s = s->outer_scope(); |
| 1308 | } |
| 1309 | |
| 1310 | if (s != NULL && s->is_eval_scope()) { |
| 1311 | // Loop up the context chain. There is no frame effect so it is |
| 1312 | // safe to use raw labels here. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1313 | Label next, fast; |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1314 | if (!context.is(temp)) { |
| 1315 | __ mov(temp, context); |
| 1316 | } |
| 1317 | __ bind(&next); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1318 | // Terminate at native context. |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1319 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1320 | Immediate(isolate()->factory()->native_context_map())); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1321 | __ j(equal, &fast, Label::kNear); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1322 | // Check that extension is NULL. |
| 1323 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1324 | __ j(not_equal, slow); |
| 1325 | // Load next context in chain. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1326 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1327 | __ jmp(&next); |
| 1328 | __ bind(&fast); |
| 1329 | } |
| 1330 | |
| 1331 | // All extension objects were empty and it is safe to use a global |
| 1332 | // load IC call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1333 | __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 1334 | __ mov(LoadDescriptor::NameRegister(), proxy->var()->name()); |
| 1335 | if (FLAG_vector_ics) { |
| 1336 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1337 | Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | ContextualMode mode = (typeof_state == INSIDE_TYPEOF) |
| 1341 | ? NOT_CONTEXTUAL |
| 1342 | : CONTEXTUAL; |
| 1343 | |
| 1344 | CallLoadIC(mode); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1348 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1349 | Label* slow) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1350 | DCHECK(var->IsContextSlot()); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1351 | Register context = esi; |
| 1352 | Register temp = ebx; |
| 1353 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1354 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1355 | if (s->num_heap_slots() > 0) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1356 | if (s->calls_sloppy_eval()) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1357 | // Check that extension is NULL. |
| 1358 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1359 | Immediate(0)); |
| 1360 | __ j(not_equal, slow); |
| 1361 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1362 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1363 | // Walk the rest of the chain without clobbering esi. |
| 1364 | context = temp; |
| 1365 | } |
| 1366 | } |
| 1367 | // Check that last extension is NULL. |
| 1368 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1369 | __ j(not_equal, slow); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1370 | |
| 1371 | // This function is used only for loads, not stores, so it's safe to |
| 1372 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1373 | // destroy the esi register). |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1374 | return ContextOperand(context, var->index()); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1378 | void FullCodeGenerator::EmitDynamicLookupFastCase(VariableProxy* proxy, |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1379 | TypeofState typeof_state, |
| 1380 | Label* slow, |
| 1381 | Label* done) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1382 | // Generate fast-case code for variables that might be shadowed by |
| 1383 | // eval-introduced variables. Eval is used a lot without |
| 1384 | // introducing variables. In those cases, we do not want to |
| 1385 | // perform a runtime call for all variables in the scope |
| 1386 | // containing the eval. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1387 | Variable* var = proxy->var(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1388 | if (var->mode() == DYNAMIC_GLOBAL) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1389 | EmitLoadGlobalCheckExtensions(proxy, typeof_state, slow); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1390 | __ jmp(done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1391 | } else if (var->mode() == DYNAMIC_LOCAL) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1392 | Variable* local = var->local_if_not_shadowed(); |
| 1393 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1394 | if (local->mode() == LET || local->mode() == CONST || |
| 1395 | local->mode() == CONST_LEGACY) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1396 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1397 | __ j(not_equal, done); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1398 | if (local->mode() == CONST_LEGACY) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1399 | __ mov(eax, isolate()->factory()->undefined_value()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1400 | } else { // LET || CONST |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1401 | __ push(Immediate(var->name())); |
| 1402 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1403 | } |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1404 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1405 | __ jmp(done); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1410 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1411 | // Record position before possible IC call. |
| 1412 | SetSourcePosition(proxy->position()); |
| 1413 | Variable* var = proxy->var(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1414 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1415 | // Three cases: global variables, lookup variables, and all other types of |
| 1416 | // variables. |
| 1417 | switch (var->location()) { |
| 1418 | case Variable::UNALLOCATED: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1419 | Comment cmnt(masm_, "[ Global variable"); |
| 1420 | __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 1421 | __ mov(LoadDescriptor::NameRegister(), var->name()); |
| 1422 | if (FLAG_vector_ics) { |
| 1423 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1424 | Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1425 | } |
| 1426 | CallLoadIC(CONTEXTUAL); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1427 | context()->Plug(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | case Variable::PARAMETER: |
| 1432 | case Variable::LOCAL: |
| 1433 | case Variable::CONTEXT: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1434 | Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
| 1435 | : "[ Stack variable"); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1436 | if (var->binding_needs_init()) { |
| 1437 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1438 | // refers to a potential outside binding. Currently those bindings are |
| 1439 | // always looked up dynamically, i.e. in that case |
| 1440 | // var->location() == LOOKUP. |
| 1441 | // always holds. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1442 | DCHECK(var->scope() != NULL); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1443 | |
| 1444 | // Check if the binding really needs an initialization check. The check |
| 1445 | // can be skipped in the following situation: we have a LET or CONST |
| 1446 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1447 | // the same declaration scope (i.e. they are both in global code, in the |
| 1448 | // same function or in the same eval code) and the VariableProxy is in |
| 1449 | // the source physically located after the initializer of the variable. |
| 1450 | // |
| 1451 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1452 | // mode because const variables may be declared but never initialized: |
| 1453 | // if (false) { const x; }; var y = x; |
| 1454 | // |
| 1455 | // The condition on the declaration scopes is a conservative check for |
| 1456 | // nested functions that access a binding and are called before the |
| 1457 | // binding is initialized: |
| 1458 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1459 | // |
| 1460 | bool skip_init_check; |
| 1461 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1462 | skip_init_check = false; |
| 1463 | } else { |
| 1464 | // Check that we always have valid source position. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1465 | DCHECK(var->initializer_position() != RelocInfo::kNoPosition); |
| 1466 | DCHECK(proxy->position() != RelocInfo::kNoPosition); |
| 1467 | skip_init_check = var->mode() != CONST_LEGACY && |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1468 | var->initializer_position() < proxy->position(); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1469 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1470 | |
| 1471 | if (!skip_init_check) { |
| 1472 | // Let and const need a read barrier. |
| 1473 | Label done; |
| 1474 | GetVar(eax, var); |
| 1475 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1476 | __ j(not_equal, &done, Label::kNear); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1477 | if (var->mode() == LET || var->mode() == CONST) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1478 | // Throw a reference error when using an uninitialized let/const |
| 1479 | // binding in harmony mode. |
| 1480 | __ push(Immediate(var->name())); |
| 1481 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1482 | } else { |
| 1483 | // Uninitalized const bindings outside of harmony mode are unholed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1484 | DCHECK(var->mode() == CONST_LEGACY); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1485 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1486 | } |
| 1487 | __ bind(&done); |
| 1488 | context()->Plug(eax); |
| 1489 | break; |
| 1490 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1491 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1492 | context()->Plug(var); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | case Variable::LOOKUP: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1497 | Comment cmnt(masm_, "[ Lookup variable"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1498 | Label done, slow; |
| 1499 | // Generate code for loading from variables potentially shadowed |
| 1500 | // by eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1501 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1502 | __ bind(&slow); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1503 | __ push(esi); // Context. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1504 | __ push(Immediate(var->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1505 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1506 | __ bind(&done); |
| 1507 | context()->Plug(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 1508 | break; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1509 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1514 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1515 | Comment cmnt(masm_, "[ RegExpLiteral"); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1516 | Label materialized; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1517 | // Registers will be used as follows: |
| 1518 | // edi = JS function. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1519 | // ecx = literals array. |
| 1520 | // ebx = regexp literal. |
| 1521 | // eax = regexp literal clone. |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1522 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1523 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1524 | int literal_offset = |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1525 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1526 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1527 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1528 | __ j(not_equal, &materialized, Label::kNear); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1529 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1530 | // Create regexp literal using runtime function |
| 1531 | // Result will be in eax. |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1532 | __ push(ecx); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1533 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1534 | __ push(Immediate(expr->pattern())); |
| 1535 | __ push(Immediate(expr->flags())); |
| 1536 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1537 | __ mov(ebx, eax); |
| 1538 | |
| 1539 | __ bind(&materialized); |
| 1540 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1541 | Label allocated, runtime_allocate; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1542 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 1543 | __ jmp(&allocated); |
| 1544 | |
| 1545 | __ bind(&runtime_allocate); |
| 1546 | __ push(ebx); |
| 1547 | __ push(Immediate(Smi::FromInt(size))); |
| 1548 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1549 | __ pop(ebx); |
| 1550 | |
| 1551 | __ bind(&allocated); |
| 1552 | // Copy the content into the newly allocated memory. |
| 1553 | // (Unroll copy loop once for better throughput). |
| 1554 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1555 | __ mov(edx, FieldOperand(ebx, i)); |
| 1556 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1557 | __ mov(FieldOperand(eax, i), edx); |
| 1558 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1559 | } |
| 1560 | if ((size % (2 * kPointerSize)) != 0) { |
| 1561 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1562 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1563 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1564 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1568 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1569 | if (expression == NULL) { |
| 1570 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1571 | } else { |
| 1572 | VisitForStackValue(expression); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1577 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1578 | Comment cmnt(masm_, "[ ObjectLiteral"); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1579 | |
| 1580 | expr->BuildConstantProperties(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1581 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1582 | int flags = expr->fast_elements() |
| 1583 | ? ObjectLiteral::kFastElements |
| 1584 | : ObjectLiteral::kNoFlags; |
| 1585 | flags |= expr->has_function() |
| 1586 | ? ObjectLiteral::kHasFunction |
| 1587 | : ObjectLiteral::kNoFlags; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1588 | int properties_count = constant_properties->length() / 2; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1589 | if (expr->may_store_doubles() || expr->depth() > 1 || |
| 1590 | masm()->serializer_enabled() || |
| 1591 | flags != ObjectLiteral::kFastElements || |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1592 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1593 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1594 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1595 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1596 | __ push(Immediate(constant_properties)); |
| 1597 | __ push(Immediate(Smi::FromInt(flags))); |
| 1598 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1599 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1600 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1601 | __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1602 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1603 | __ mov(ecx, Immediate(constant_properties)); |
| 1604 | __ mov(edx, Immediate(Smi::FromInt(flags))); |
| 1605 | FastCloneShallowObjectStub stub(isolate(), properties_count); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1606 | __ CallStub(&stub); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1607 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1608 | PrepareForBailoutForId(expr->CreateLiteralId(), TOS_REG); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1609 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1610 | // If result_saved is true the result is on top of the stack. If |
| 1611 | // result_saved is false the result is in eax. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1612 | bool result_saved = false; |
| 1613 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1614 | // Mark all computed expressions that are bound to a key that |
| 1615 | // is shadowed by a later occurrence of the same key. For the |
| 1616 | // marked expressions, no store code is emitted. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1617 | expr->CalculateEmitStore(zone()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1618 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1619 | AccessorTable accessor_table(zone()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1620 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1621 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1622 | if (property->IsCompileTimeValue()) continue; |
| 1623 | |
| 1624 | Literal* key = property->key(); |
| 1625 | Expression* value = property->value(); |
| 1626 | if (!result_saved) { |
| 1627 | __ push(eax); // Save result on the stack |
| 1628 | result_saved = true; |
| 1629 | } |
| 1630 | switch (property->kind()) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1631 | case ObjectLiteral::Property::CONSTANT: |
| 1632 | UNREACHABLE(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1633 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1634 | DCHECK(!CompileTimeValue::IsCompileTimeValue(value)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1635 | // Fall through. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1636 | case ObjectLiteral::Property::COMPUTED: |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1637 | // It is safe to use [[Put]] here because the boilerplate already |
| 1638 | // contains computed properties with an uninitialized value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1639 | if (key->value()->IsInternalizedString()) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1640 | if (property->emit_store()) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1641 | VisitForAccumulatorValue(value); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1642 | DCHECK(StoreDescriptor::ValueRegister().is(eax)); |
| 1643 | __ mov(StoreDescriptor::NameRegister(), Immediate(key->value())); |
| 1644 | __ mov(StoreDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 1645 | CallStoreIC(key->LiteralFeedbackId()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1646 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1647 | |
| 1648 | if (NeedsHomeObject(value)) { |
| 1649 | __ mov(StoreDescriptor::ReceiverRegister(), eax); |
| 1650 | __ mov(StoreDescriptor::NameRegister(), |
| 1651 | Immediate(isolate()->factory()->home_object_symbol())); |
| 1652 | __ mov(StoreDescriptor::ValueRegister(), Operand(esp, 0)); |
| 1653 | CallStoreIC(); |
| 1654 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1655 | } else { |
| 1656 | VisitForEffect(value); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1657 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1658 | break; |
| 1659 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1660 | __ push(Operand(esp, 0)); // Duplicate receiver. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1661 | VisitForStackValue(key); |
| 1662 | VisitForStackValue(value); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1663 | if (property->emit_store()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1664 | EmitSetHomeObjectIfNeeded(value, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1665 | __ push(Immediate(Smi::FromInt(SLOPPY))); // Strict mode |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1666 | __ CallRuntime(Runtime::kSetProperty, 4); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 1667 | } else { |
| 1668 | __ Drop(3); |
| 1669 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1670 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1671 | case ObjectLiteral::Property::PROTOTYPE: |
| 1672 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1673 | VisitForStackValue(value); |
| 1674 | if (property->emit_store()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1675 | __ CallRuntime(Runtime::kInternalSetPrototype, 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1676 | } else { |
| 1677 | __ Drop(2); |
| 1678 | } |
| 1679 | break; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1680 | case ObjectLiteral::Property::GETTER: |
| 1681 | accessor_table.lookup(key)->second->getter = value; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1682 | break; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 1683 | case ObjectLiteral::Property::SETTER: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1684 | accessor_table.lookup(key)->second->setter = value; |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 1685 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 1686 | } |
| 1687 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1688 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1689 | // Emit code to define accessors, using only a single call to the runtime for |
| 1690 | // each pair of corresponding getters and setters. |
| 1691 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1692 | it != accessor_table.end(); |
| 1693 | ++it) { |
| 1694 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1695 | VisitForStackValue(it->first); |
| 1696 | EmitAccessor(it->second->getter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1697 | EmitSetHomeObjectIfNeeded(it->second->getter, 2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1698 | EmitAccessor(it->second->setter); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1699 | EmitSetHomeObjectIfNeeded(it->second->setter, 3); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1700 | __ push(Immediate(Smi::FromInt(NONE))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1701 | __ CallRuntime(Runtime::kDefineAccessorPropertyUnchecked, 5); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1704 | if (expr->has_function()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1705 | DCHECK(result_saved); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1706 | __ push(Operand(esp, 0)); |
| 1707 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1708 | } |
| 1709 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1710 | if (result_saved) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1711 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1712 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1713 | context()->Plug(eax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1718 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1719 | Comment cmnt(masm_, "[ ArrayLiteral"); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1720 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1721 | expr->BuildConstantElements(isolate()); |
| 1722 | int flags = expr->depth() == 1 |
| 1723 | ? ArrayLiteral::kShallowElements |
| 1724 | : ArrayLiteral::kNoFlags; |
| 1725 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1726 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1727 | int length = subexprs->length(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1728 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1729 | DCHECK_EQ(2, constant_elements->length()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1730 | ElementsKind constant_elements_kind = |
| 1731 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1732 | bool has_constant_fast_elements = |
| 1733 | IsFastObjectElementsKind(constant_elements_kind); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1734 | Handle<FixedArrayBase> constant_elements_values( |
| 1735 | FixedArrayBase::cast(constant_elements->get(1))); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1736 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1737 | AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
| 1738 | if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1739 | // If the only customer of allocation sites is transitioning, then |
| 1740 | // we can turn it off if we don't have anywhere else to transition to. |
| 1741 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1742 | } |
| 1743 | |
| 1744 | if (expr->depth() > 1 || length > JSObject::kInitialMaxFastElementArray) { |
| 1745 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1746 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1747 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1748 | __ push(Immediate(constant_elements)); |
| 1749 | __ push(Immediate(Smi::FromInt(flags))); |
| 1750 | __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1751 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1752 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1753 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1754 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1755 | __ mov(ecx, Immediate(constant_elements)); |
| 1756 | FastCloneShallowArrayStub stub(isolate(), allocation_site_mode); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1757 | __ CallStub(&stub); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | bool result_saved = false; // Is the result saved to the stack? |
| 1761 | |
| 1762 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1763 | // them into the newly cloned array. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1764 | for (int i = 0; i < length; i++) { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1765 | Expression* subexpr = subexprs->at(i); |
| 1766 | // If the subexpression is a literal or a simple materialized literal it |
| 1767 | // is already set in the cloned array. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1768 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1769 | |
| 1770 | if (!result_saved) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1771 | __ push(eax); // array literal. |
| 1772 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1773 | result_saved = true; |
| 1774 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1775 | VisitForAccumulatorValue(subexpr); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1776 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1777 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1778 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1779 | // cannot transition and don't need to call the runtime stub. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1780 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1781 | __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1782 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1783 | // Store the subexpression value in the array's elements. |
| 1784 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1785 | // Update the write barrier for the array store. |
| 1786 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1787 | kDontSaveFPRegs, |
| 1788 | EMIT_REMEMBERED_SET, |
| 1789 | INLINE_SMI_CHECK); |
| 1790 | } else { |
| 1791 | // Store the subexpression value in the array's elements. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1792 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1793 | StoreArrayLiteralElementStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1794 | __ CallStub(&stub); |
| 1795 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1796 | |
| 1797 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1800 | if (result_saved) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1801 | __ add(esp, Immediate(kPointerSize)); // literal index |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1802 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1803 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1804 | context()->Plug(eax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | |
| 1808 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1809 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1810 | DCHECK(expr->target()->IsValidReferenceExpression()); |
| 1811 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1812 | Comment cmnt(masm_, "[ Assignment"); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 1813 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1814 | Property* property = expr->target()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1815 | LhsKind assign_type = GetAssignType(property); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Evaluate LHS expression. |
| 1818 | switch (assign_type) { |
| 1819 | case VARIABLE: |
| 1820 | // Nothing to do here. |
| 1821 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1822 | case NAMED_SUPER_PROPERTY: |
| 1823 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1824 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1825 | __ push(result_register()); |
| 1826 | if (expr->is_compound()) { |
| 1827 | __ push(MemOperand(esp, kPointerSize)); |
| 1828 | __ push(result_register()); |
| 1829 | } |
| 1830 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1831 | case NAMED_PROPERTY: |
| 1832 | if (expr->is_compound()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1833 | // We need the receiver both on the stack and in the register. |
| 1834 | VisitForStackValue(property->obj()); |
| 1835 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1836 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1837 | VisitForStackValue(property->obj()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1838 | } |
| 1839 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1840 | case KEYED_SUPER_PROPERTY: |
| 1841 | VisitForStackValue(property->obj()->AsSuperReference()->this_var()); |
| 1842 | EmitLoadHomeObject(property->obj()->AsSuperReference()); |
| 1843 | __ Push(result_register()); |
| 1844 | VisitForAccumulatorValue(property->key()); |
| 1845 | __ Push(result_register()); |
| 1846 | if (expr->is_compound()) { |
| 1847 | __ push(MemOperand(esp, 2 * kPointerSize)); |
| 1848 | __ push(MemOperand(esp, 2 * kPointerSize)); |
| 1849 | __ push(result_register()); |
| 1850 | } |
| 1851 | break; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1852 | case KEYED_PROPERTY: { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1853 | if (expr->is_compound()) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1854 | VisitForStackValue(property->obj()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1855 | VisitForStackValue(property->key()); |
| 1856 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, kPointerSize)); |
| 1857 | __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1858 | } else { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1859 | VisitForStackValue(property->obj()); |
| 1860 | VisitForStackValue(property->key()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1861 | } |
| 1862 | break; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1863 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1864 | } |
| 1865 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1866 | // For compound assignments we need another deoptimization point after the |
| 1867 | // variable/property load. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1868 | if (expr->is_compound()) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 1869 | AccumulatorValueContext result_context(this); |
| 1870 | { AccumulatorValueContext left_operand_context(this); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1871 | switch (assign_type) { |
| 1872 | case VARIABLE: |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1873 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1874 | PrepareForBailout(expr->target(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1875 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1876 | case NAMED_SUPER_PROPERTY: |
| 1877 | EmitNamedSuperPropertyLoad(property); |
| 1878 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1879 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1880 | case NAMED_PROPERTY: |
| 1881 | EmitNamedPropertyLoad(property); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1882 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1883 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1884 | case KEYED_SUPER_PROPERTY: |
| 1885 | EmitKeyedSuperPropertyLoad(property); |
| 1886 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
| 1887 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1888 | case KEYED_PROPERTY: |
| 1889 | EmitKeyedPropertyLoad(property); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1890 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1891 | break; |
| 1892 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1893 | } |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1894 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1895 | Token::Value op = expr->binary_op(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1896 | __ push(eax); // Left operand goes on the stack. |
| 1897 | VisitForAccumulatorValue(expr->value()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1898 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1899 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1900 | ? OVERWRITE_RIGHT |
| 1901 | : NO_OVERWRITE; |
| 1902 | SetSourcePosition(expr->position() + 1); |
| 1903 | if (ShouldInlineSmiCase(op)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1904 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1905 | op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1906 | mode, |
| 1907 | expr->target(), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1908 | expr->value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1909 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1910 | EmitBinaryOp(expr->binary_operation(), op, mode); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1911 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1912 | |
| 1913 | // Deoptimization point in case the binary operation may have side effects. |
| 1914 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1915 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1916 | VisitForAccumulatorValue(expr->value()); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | // Record source position before possible IC call. |
| 1920 | SetSourcePosition(expr->position()); |
| 1921 | |
| 1922 | // Store the value. |
| 1923 | switch (assign_type) { |
| 1924 | case VARIABLE: |
| 1925 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1926 | expr->op()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1927 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1928 | context()->Plug(eax); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1929 | break; |
| 1930 | case NAMED_PROPERTY: |
| 1931 | EmitNamedPropertyAssignment(expr); |
| 1932 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 1933 | case NAMED_SUPER_PROPERTY: |
| 1934 | EmitNamedSuperPropertyStore(property); |
| 1935 | context()->Plug(result_register()); |
| 1936 | break; |
| 1937 | case KEYED_SUPER_PROPERTY: |
| 1938 | EmitKeyedSuperPropertyStore(property); |
| 1939 | context()->Plug(result_register()); |
| 1940 | break; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1941 | case KEYED_PROPERTY: |
| 1942 | EmitKeyedPropertyAssignment(expr); |
| 1943 | break; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1948 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1949 | Comment cmnt(masm_, "[ Yield"); |
| 1950 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1951 | // this. It stays on the stack while we update the iterator. |
| 1952 | VisitForStackValue(expr->expression()); |
| 1953 | |
| 1954 | switch (expr->yield_kind()) { |
| 1955 | case Yield::kSuspend: |
| 1956 | // Pop value from top-of-stack slot; box result into result register. |
| 1957 | EmitCreateIteratorResult(false); |
| 1958 | __ push(result_register()); |
| 1959 | // Fall through. |
| 1960 | case Yield::kInitial: { |
| 1961 | Label suspend, continuation, post_runtime, resume; |
| 1962 | |
| 1963 | __ jmp(&suspend); |
| 1964 | |
| 1965 | __ bind(&continuation); |
| 1966 | __ jmp(&resume); |
| 1967 | |
| 1968 | __ bind(&suspend); |
| 1969 | VisitForAccumulatorValue(expr->generator_object()); |
| 1970 | DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1971 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 1972 | Immediate(Smi::FromInt(continuation.pos()))); |
| 1973 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 1974 | __ mov(ecx, esi); |
| 1975 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 1976 | kDontSaveFPRegs); |
| 1977 | __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
| 1978 | __ cmp(esp, ebx); |
| 1979 | __ j(equal, &post_runtime); |
| 1980 | __ push(eax); // generator object |
| 1981 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1982 | __ mov(context_register(), |
| 1983 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 1984 | __ bind(&post_runtime); |
| 1985 | __ pop(result_register()); |
| 1986 | EmitReturnSequence(); |
| 1987 | |
| 1988 | __ bind(&resume); |
| 1989 | context()->Plug(result_register()); |
| 1990 | break; |
| 1991 | } |
| 1992 | |
| 1993 | case Yield::kFinal: { |
| 1994 | VisitForAccumulatorValue(expr->generator_object()); |
| 1995 | __ mov(FieldOperand(result_register(), |
| 1996 | JSGeneratorObject::kContinuationOffset), |
| 1997 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
| 1998 | // Pop value from top-of-stack slot, box result into result register. |
| 1999 | EmitCreateIteratorResult(true); |
| 2000 | EmitUnwindBeforeReturn(); |
| 2001 | EmitReturnSequence(); |
| 2002 | break; |
| 2003 | } |
| 2004 | |
| 2005 | case Yield::kDelegating: { |
| 2006 | VisitForStackValue(expr->generator_object()); |
| 2007 | |
| 2008 | // Initial stack layout is as follows: |
| 2009 | // [sp + 1 * kPointerSize] iter |
| 2010 | // [sp + 0 * kPointerSize] g |
| 2011 | |
| 2012 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 2013 | Label l_next, l_call, l_loop; |
| 2014 | Register load_receiver = LoadDescriptor::ReceiverRegister(); |
| 2015 | Register load_name = LoadDescriptor::NameRegister(); |
| 2016 | |
| 2017 | // Initial send value is undefined. |
| 2018 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 2019 | __ jmp(&l_next); |
| 2020 | |
| 2021 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
| 2022 | __ bind(&l_catch); |
| 2023 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
| 2024 | __ mov(load_name, isolate()->factory()->throw_string()); // "throw" |
| 2025 | __ push(load_name); // "throw" |
| 2026 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2027 | __ push(eax); // exception |
| 2028 | __ jmp(&l_call); |
| 2029 | |
| 2030 | // try { received = %yield result } |
| 2031 | // Shuffle the received result above a try handler and yield it without |
| 2032 | // re-boxing. |
| 2033 | __ bind(&l_try); |
| 2034 | __ pop(eax); // result |
| 2035 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 2036 | const int handler_size = StackHandlerConstants::kSize; |
| 2037 | __ push(eax); // result |
| 2038 | __ jmp(&l_suspend); |
| 2039 | __ bind(&l_continuation); |
| 2040 | __ jmp(&l_resume); |
| 2041 | __ bind(&l_suspend); |
| 2042 | const int generator_object_depth = kPointerSize + handler_size; |
| 2043 | __ mov(eax, Operand(esp, generator_object_depth)); |
| 2044 | __ push(eax); // g |
| 2045 | DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2046 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 2047 | Immediate(Smi::FromInt(l_continuation.pos()))); |
| 2048 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 2049 | __ mov(ecx, esi); |
| 2050 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 2051 | kDontSaveFPRegs); |
| 2052 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 2053 | __ mov(context_register(), |
| 2054 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2055 | __ pop(eax); // result |
| 2056 | EmitReturnSequence(); |
| 2057 | __ bind(&l_resume); // received in eax |
| 2058 | __ PopTryHandler(); |
| 2059 | |
| 2060 | // receiver = iter; f = iter.next; arg = received; |
| 2061 | __ bind(&l_next); |
| 2062 | |
| 2063 | __ mov(load_name, isolate()->factory()->next_string()); |
| 2064 | __ push(load_name); // "next" |
| 2065 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2066 | __ push(eax); // received |
| 2067 | |
| 2068 | // result = receiver[f](arg); |
| 2069 | __ bind(&l_call); |
| 2070 | __ mov(load_receiver, Operand(esp, kPointerSize)); |
| 2071 | if (FLAG_vector_ics) { |
| 2072 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2073 | Immediate(SmiFromSlot(expr->KeyedLoadFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2074 | } |
| 2075 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 2076 | CallIC(ic, TypeFeedbackId::None()); |
| 2077 | __ mov(edi, eax); |
| 2078 | __ mov(Operand(esp, 2 * kPointerSize), edi); |
| 2079 | CallFunctionStub stub(isolate(), 1, CALL_AS_METHOD); |
| 2080 | __ CallStub(&stub); |
| 2081 | |
| 2082 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2083 | __ Drop(1); // The function is still on the stack; drop it. |
| 2084 | |
| 2085 | // if (!result.done) goto l_try; |
| 2086 | __ bind(&l_loop); |
| 2087 | __ push(eax); // save result |
| 2088 | __ Move(load_receiver, eax); // result |
| 2089 | __ mov(load_name, |
| 2090 | isolate()->factory()->done_string()); // "done" |
| 2091 | if (FLAG_vector_ics) { |
| 2092 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2093 | Immediate(SmiFromSlot(expr->DoneFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2094 | } |
| 2095 | CallLoadIC(NOT_CONTEXTUAL); // result.done in eax |
| 2096 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2097 | CallIC(bool_ic); |
| 2098 | __ test(eax, eax); |
| 2099 | __ j(zero, &l_try); |
| 2100 | |
| 2101 | // result.value |
| 2102 | __ pop(load_receiver); // result |
| 2103 | __ mov(load_name, |
| 2104 | isolate()->factory()->value_string()); // "value" |
| 2105 | if (FLAG_vector_ics) { |
| 2106 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2107 | Immediate(SmiFromSlot(expr->ValueFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2108 | } |
| 2109 | CallLoadIC(NOT_CONTEXTUAL); // result.value in eax |
| 2110 | context()->DropAndPlug(2, eax); // drop iter and g |
| 2111 | break; |
| 2112 | } |
| 2113 | } |
| 2114 | } |
| 2115 | |
| 2116 | |
| 2117 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2118 | Expression *value, |
| 2119 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2120 | // The value stays in eax, and is ultimately read by the resumed generator, as |
| 2121 | // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
| 2122 | // is read to throw the value when the resumed generator is already closed. |
| 2123 | // ebx will hold the generator object until the activation has been resumed. |
| 2124 | VisitForStackValue(generator); |
| 2125 | VisitForAccumulatorValue(value); |
| 2126 | __ pop(ebx); |
| 2127 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2128 | // Load suspended function and context. |
| 2129 | __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 2130 | __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 2131 | |
| 2132 | // Push receiver. |
| 2133 | __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
| 2134 | |
| 2135 | // Push holes for arguments to generator function. |
| 2136 | __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2137 | __ mov(edx, |
| 2138 | FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 2139 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 2140 | Label push_argument_holes, push_frame; |
| 2141 | __ bind(&push_argument_holes); |
| 2142 | __ sub(edx, Immediate(Smi::FromInt(1))); |
| 2143 | __ j(carry, &push_frame); |
| 2144 | __ push(ecx); |
| 2145 | __ jmp(&push_argument_holes); |
| 2146 | |
| 2147 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2148 | // the generator was suspended. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2149 | Label resume_frame, done; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2150 | __ bind(&push_frame); |
| 2151 | __ call(&resume_frame); |
| 2152 | __ jmp(&done); |
| 2153 | __ bind(&resume_frame); |
| 2154 | __ push(ebp); // Caller's frame pointer. |
| 2155 | __ mov(ebp, esp); |
| 2156 | __ push(esi); // Callee's context. |
| 2157 | __ push(edi); // Callee's JS Function. |
| 2158 | |
| 2159 | // Load the operand stack size. |
| 2160 | __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 2161 | __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 2162 | __ SmiUntag(edx); |
| 2163 | |
| 2164 | // If we are sending a value and there is no operand stack, we can jump back |
| 2165 | // in directly. |
| 2166 | if (resume_mode == JSGeneratorObject::NEXT) { |
| 2167 | Label slow_resume; |
| 2168 | __ cmp(edx, Immediate(0)); |
| 2169 | __ j(not_zero, &slow_resume); |
| 2170 | __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2171 | __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 2172 | __ SmiUntag(ecx); |
| 2173 | __ add(edx, ecx); |
| 2174 | __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2175 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2176 | __ jmp(edx); |
| 2177 | __ bind(&slow_resume); |
| 2178 | } |
| 2179 | |
| 2180 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2181 | // up the stack and the handlers. |
| 2182 | Label push_operand_holes, call_resume; |
| 2183 | __ bind(&push_operand_holes); |
| 2184 | __ sub(edx, Immediate(1)); |
| 2185 | __ j(carry, &call_resume); |
| 2186 | __ push(ecx); |
| 2187 | __ jmp(&push_operand_holes); |
| 2188 | __ bind(&call_resume); |
| 2189 | __ push(ebx); |
| 2190 | __ push(result_register()); |
| 2191 | __ Push(Smi::FromInt(resume_mode)); |
| 2192 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2193 | // Not reached: the runtime call returns elsewhere. |
| 2194 | __ Abort(kGeneratorFailedToResume); |
| 2195 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2196 | __ bind(&done); |
| 2197 | context()->Plug(result_register()); |
| 2198 | } |
| 2199 | |
| 2200 | |
| 2201 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
| 2202 | Label gc_required; |
| 2203 | Label allocated; |
| 2204 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2205 | const int instance_size = 5 * kPointerSize; |
| 2206 | DCHECK_EQ(isolate()->native_context()->iterator_result_map()->instance_size(), |
| 2207 | instance_size); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2208 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2209 | __ Allocate(instance_size, eax, ecx, edx, &gc_required, TAG_OBJECT); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2210 | __ jmp(&allocated); |
| 2211 | |
| 2212 | __ bind(&gc_required); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2213 | __ Push(Smi::FromInt(instance_size)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2214 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2215 | __ mov(context_register(), |
| 2216 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2217 | |
| 2218 | __ bind(&allocated); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2219 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2220 | __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); |
| 2221 | __ mov(ebx, ContextOperand(ebx, Context::ITERATOR_RESULT_MAP_INDEX)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2222 | __ pop(ecx); |
| 2223 | __ mov(edx, isolate()->factory()->ToBoolean(done)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2224 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2225 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2226 | isolate()->factory()->empty_fixed_array()); |
| 2227 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2228 | isolate()->factory()->empty_fixed_array()); |
| 2229 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2230 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2231 | |
| 2232 | // Only the value field needs a write barrier, as the other values are in the |
| 2233 | // root set. |
| 2234 | __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2235 | ecx, edx, kDontSaveFPRegs); |
| 2236 | } |
| 2237 | |
| 2238 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2239 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2240 | SetSourcePosition(prop->position()); |
| 2241 | Literal* key = prop->key()->AsLiteral(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2242 | DCHECK(!key->value()->IsSmi()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2243 | DCHECK(!prop->IsSuperAccess()); |
| 2244 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2245 | __ mov(LoadDescriptor::NameRegister(), Immediate(key->value())); |
| 2246 | if (FLAG_vector_ics) { |
| 2247 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2248 | Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2249 | CallLoadIC(NOT_CONTEXTUAL); |
| 2250 | } else { |
| 2251 | CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | |
| 2256 | void FullCodeGenerator::EmitNamedSuperPropertyLoad(Property* prop) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2257 | // Stack: receiver, home_object. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2258 | SetSourcePosition(prop->position()); |
| 2259 | Literal* key = prop->key()->AsLiteral(); |
| 2260 | DCHECK(!key->value()->IsSmi()); |
| 2261 | DCHECK(prop->IsSuperAccess()); |
| 2262 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2263 | __ push(Immediate(key->value())); |
| 2264 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2268 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2269 | SetSourcePosition(prop->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2270 | Handle<Code> ic = CodeFactory::KeyedLoadIC(isolate()).code(); |
| 2271 | if (FLAG_vector_ics) { |
| 2272 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2273 | Immediate(SmiFromSlot(prop->PropertyFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2274 | CallIC(ic); |
| 2275 | } else { |
| 2276 | CallIC(ic, prop->PropertyFeedbackId()); |
| 2277 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2281 | void FullCodeGenerator::EmitKeyedSuperPropertyLoad(Property* prop) { |
| 2282 | // Stack: receiver, home_object, key. |
| 2283 | SetSourcePosition(prop->position()); |
| 2284 | |
| 2285 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2286 | } |
| 2287 | |
| 2288 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2289 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2290 | Token::Value op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2291 | OverwriteMode mode, |
| 2292 | Expression* left, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2293 | Expression* right) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2294 | // Do combined smi check of the operands. Left operand is on the |
| 2295 | // stack. Right operand is in eax. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2296 | Label smi_case, done, stub_call; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2297 | __ pop(edx); |
| 2298 | __ mov(ecx, eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2299 | __ or_(eax, edx); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2300 | JumpPatchSite patch_site(masm_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2301 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2302 | |
| 2303 | __ bind(&stub_call); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2304 | __ mov(eax, ecx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2305 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
| 2306 | CallIC(code, expr->BinaryOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2307 | patch_site.EmitPatchInfo(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2308 | __ jmp(&done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2309 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2310 | // Smi case. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2311 | __ bind(&smi_case); |
| 2312 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 2313 | |
| 2314 | switch (op) { |
| 2315 | case Token::SAR: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2316 | __ SmiUntag(ecx); |
| 2317 | __ sar_cl(eax); // No checks of result necessary |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2318 | __ and_(eax, Immediate(~kSmiTagMask)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2319 | break; |
| 2320 | case Token::SHL: { |
| 2321 | Label result_ok; |
| 2322 | __ SmiUntag(eax); |
| 2323 | __ SmiUntag(ecx); |
| 2324 | __ shl_cl(eax); |
| 2325 | // Check that the *signed* result fits in a smi. |
| 2326 | __ cmp(eax, 0xc0000000); |
| 2327 | __ j(positive, &result_ok); |
| 2328 | __ SmiTag(ecx); |
| 2329 | __ jmp(&stub_call); |
| 2330 | __ bind(&result_ok); |
| 2331 | __ SmiTag(eax); |
| 2332 | break; |
| 2333 | } |
| 2334 | case Token::SHR: { |
| 2335 | Label result_ok; |
| 2336 | __ SmiUntag(eax); |
| 2337 | __ SmiUntag(ecx); |
| 2338 | __ shr_cl(eax); |
| 2339 | __ test(eax, Immediate(0xc0000000)); |
| 2340 | __ j(zero, &result_ok); |
| 2341 | __ SmiTag(ecx); |
| 2342 | __ jmp(&stub_call); |
| 2343 | __ bind(&result_ok); |
| 2344 | __ SmiTag(eax); |
| 2345 | break; |
| 2346 | } |
| 2347 | case Token::ADD: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2348 | __ add(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2349 | __ j(overflow, &stub_call); |
| 2350 | break; |
| 2351 | case Token::SUB: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2352 | __ sub(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2353 | __ j(overflow, &stub_call); |
| 2354 | break; |
| 2355 | case Token::MUL: { |
| 2356 | __ SmiUntag(eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2357 | __ imul(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2358 | __ j(overflow, &stub_call); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2359 | __ test(eax, eax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2360 | __ j(not_zero, &done, Label::kNear); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2361 | __ mov(ebx, edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2362 | __ or_(ebx, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2363 | __ j(negative, &stub_call); |
| 2364 | break; |
| 2365 | } |
| 2366 | case Token::BIT_OR: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2367 | __ or_(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2368 | break; |
| 2369 | case Token::BIT_AND: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2370 | __ and_(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2371 | break; |
| 2372 | case Token::BIT_XOR: |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2373 | __ xor_(eax, ecx); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2374 | break; |
| 2375 | default: |
| 2376 | UNREACHABLE(); |
| 2377 | } |
| 2378 | |
| 2379 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2380 | context()->Plug(eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2384 | void FullCodeGenerator::EmitClassDefineProperties(ClassLiteral* lit) { |
| 2385 | // Constructor is in eax. |
| 2386 | DCHECK(lit != NULL); |
| 2387 | __ push(eax); |
| 2388 | |
| 2389 | // No access check is needed here since the constructor is created by the |
| 2390 | // class literal. |
| 2391 | Register scratch = ebx; |
| 2392 | __ mov(scratch, FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset)); |
| 2393 | __ Push(scratch); |
| 2394 | |
| 2395 | for (int i = 0; i < lit->properties()->length(); i++) { |
| 2396 | ObjectLiteral::Property* property = lit->properties()->at(i); |
| 2397 | Literal* key = property->key()->AsLiteral(); |
| 2398 | Expression* value = property->value(); |
| 2399 | DCHECK(key != NULL); |
| 2400 | |
| 2401 | if (property->is_static()) { |
| 2402 | __ push(Operand(esp, kPointerSize)); // constructor |
| 2403 | } else { |
| 2404 | __ push(Operand(esp, 0)); // prototype |
| 2405 | } |
| 2406 | VisitForStackValue(key); |
| 2407 | VisitForStackValue(value); |
| 2408 | EmitSetHomeObjectIfNeeded(value, 2); |
| 2409 | |
| 2410 | switch (property->kind()) { |
| 2411 | case ObjectLiteral::Property::CONSTANT: |
| 2412 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 2413 | case ObjectLiteral::Property::COMPUTED: |
| 2414 | case ObjectLiteral::Property::PROTOTYPE: |
| 2415 | __ CallRuntime(Runtime::kDefineClassMethod, 3); |
| 2416 | break; |
| 2417 | |
| 2418 | case ObjectLiteral::Property::GETTER: |
| 2419 | __ CallRuntime(Runtime::kDefineClassGetter, 3); |
| 2420 | break; |
| 2421 | |
| 2422 | case ObjectLiteral::Property::SETTER: |
| 2423 | __ CallRuntime(Runtime::kDefineClassSetter, 3); |
| 2424 | break; |
| 2425 | |
| 2426 | default: |
| 2427 | UNREACHABLE(); |
| 2428 | } |
| 2429 | } |
| 2430 | |
| 2431 | // prototype |
| 2432 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2433 | |
| 2434 | // constructor |
| 2435 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 2436 | } |
| 2437 | |
| 2438 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2439 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2440 | Token::Value op, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2441 | OverwriteMode mode) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2442 | __ pop(edx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2443 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), op, mode).code(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2444 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2445 | CallIC(code, expr->BinaryOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2446 | patch_site.EmitPatchInfo(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2447 | context()->Plug(eax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2451 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2452 | DCHECK(expr->IsValidReferenceExpression()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2453 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2454 | Property* prop = expr->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2455 | LhsKind assign_type = GetAssignType(prop); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2456 | |
| 2457 | switch (assign_type) { |
| 2458 | case VARIABLE: { |
| 2459 | Variable* var = expr->AsVariableProxy()->var(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2460 | EffectContext context(this); |
| 2461 | EmitVariableAssignment(var, Token::ASSIGN); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2462 | break; |
| 2463 | } |
| 2464 | case NAMED_PROPERTY: { |
| 2465 | __ push(eax); // Preserve value. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2466 | VisitForAccumulatorValue(prop->obj()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2467 | __ Move(StoreDescriptor::ReceiverRegister(), eax); |
| 2468 | __ pop(StoreDescriptor::ValueRegister()); // Restore value. |
| 2469 | __ mov(StoreDescriptor::NameRegister(), |
| 2470 | prop->key()->AsLiteral()->value()); |
| 2471 | CallStoreIC(); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2472 | break; |
| 2473 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2474 | case NAMED_SUPER_PROPERTY: { |
| 2475 | __ push(eax); |
| 2476 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2477 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2478 | // stack: value, this; eax: home_object |
| 2479 | Register scratch = ecx; |
| 2480 | Register scratch2 = edx; |
| 2481 | __ mov(scratch, result_register()); // home_object |
| 2482 | __ mov(eax, MemOperand(esp, kPointerSize)); // value |
| 2483 | __ mov(scratch2, MemOperand(esp, 0)); // this |
| 2484 | __ mov(MemOperand(esp, kPointerSize), scratch2); // this |
| 2485 | __ mov(MemOperand(esp, 0), scratch); // home_object |
| 2486 | // stack: this, home_object. eax: value |
| 2487 | EmitNamedSuperPropertyStore(prop); |
| 2488 | break; |
| 2489 | } |
| 2490 | case KEYED_SUPER_PROPERTY: { |
| 2491 | __ push(eax); |
| 2492 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 2493 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 2494 | __ push(result_register()); |
| 2495 | VisitForAccumulatorValue(prop->key()); |
| 2496 | Register scratch = ecx; |
| 2497 | Register scratch2 = edx; |
| 2498 | __ mov(scratch2, MemOperand(esp, 2 * kPointerSize)); // value |
| 2499 | // stack: value, this, home_object; eax: key, edx: value |
| 2500 | __ mov(scratch, MemOperand(esp, kPointerSize)); // this |
| 2501 | __ mov(MemOperand(esp, 2 * kPointerSize), scratch); |
| 2502 | __ mov(scratch, MemOperand(esp, 0)); // home_object |
| 2503 | __ mov(MemOperand(esp, kPointerSize), scratch); |
| 2504 | __ mov(MemOperand(esp, 0), eax); |
| 2505 | __ mov(eax, scratch2); |
| 2506 | // stack: this, home_object, key; eax: value. |
| 2507 | EmitKeyedSuperPropertyStore(prop); |
| 2508 | break; |
| 2509 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2510 | case KEYED_PROPERTY: { |
| 2511 | __ push(eax); // Preserve value. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 2512 | VisitForStackValue(prop->obj()); |
| 2513 | VisitForAccumulatorValue(prop->key()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2514 | __ Move(StoreDescriptor::NameRegister(), eax); |
| 2515 | __ pop(StoreDescriptor::ReceiverRegister()); // Receiver. |
| 2516 | __ pop(StoreDescriptor::ValueRegister()); // Restore value. |
| 2517 | Handle<Code> ic = |
| 2518 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2519 | CallIC(ic); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2520 | break; |
| 2521 | } |
| 2522 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2523 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2527 | void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
| 2528 | Variable* var, MemOperand location) { |
| 2529 | __ mov(location, eax); |
| 2530 | if (var->IsContextSlot()) { |
| 2531 | __ mov(edx, eax); |
| 2532 | int offset = Context::SlotOffset(var->index()); |
| 2533 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
| 2534 | } |
| 2535 | } |
| 2536 | |
| 2537 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2538 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2539 | Token::Value op) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2540 | if (var->IsUnallocated()) { |
| 2541 | // Global var, const, or let. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2542 | __ mov(StoreDescriptor::NameRegister(), var->name()); |
| 2543 | __ mov(StoreDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 2544 | CallStoreIC(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2545 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2546 | } else if (op == Token::INIT_CONST_LEGACY) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2547 | // Const initializers need a write barrier. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2548 | DCHECK(!var->IsParameter()); // No const parameters. |
| 2549 | if (var->IsLookupSlot()) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2550 | __ push(eax); |
| 2551 | __ push(esi); |
| 2552 | __ push(Immediate(var->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2553 | __ CallRuntime(Runtime::kInitializeLegacyConstLookupSlot, 3); |
| 2554 | } else { |
| 2555 | DCHECK(var->IsStackLocal() || var->IsContextSlot()); |
| 2556 | Label skip; |
| 2557 | MemOperand location = VarOperand(var, ecx); |
| 2558 | __ mov(edx, location); |
| 2559 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2560 | __ j(not_equal, &skip, Label::kNear); |
| 2561 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2562 | __ bind(&skip); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2563 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2564 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2565 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2566 | // Non-initializing assignment to let variable needs a write barrier. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2567 | DCHECK(!var->IsLookupSlot()); |
| 2568 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
| 2569 | Label assign; |
| 2570 | MemOperand location = VarOperand(var, ecx); |
| 2571 | __ mov(edx, location); |
| 2572 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2573 | __ j(not_equal, &assign, Label::kNear); |
| 2574 | __ push(Immediate(var->name())); |
| 2575 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2576 | __ bind(&assign); |
| 2577 | EmitStoreToStackLocalOrContextSlot(var, location); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2578 | } else if (!var->is_const_mode() || op == Token::INIT_CONST) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2579 | if (var->IsLookupSlot()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2580 | // Assignment to var. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2581 | __ push(eax); // Value. |
| 2582 | __ push(esi); // Context. |
| 2583 | __ push(Immediate(var->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2584 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
| 2585 | __ CallRuntime(Runtime::kStoreLookupSlot, 4); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2586 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2587 | // Assignment to var or initializing assignment to let/const in harmony |
| 2588 | // mode. |
| 2589 | DCHECK(var->IsStackAllocated() || var->IsContextSlot()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2590 | MemOperand location = VarOperand(var, ecx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2591 | if (generate_debug_code_ && op == Token::INIT_LET) { |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2592 | // Check for an uninitialized let binding. |
| 2593 | __ mov(edx, location); |
| 2594 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2595 | __ Check(equal, kLetBindingReInitialization); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2596 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2597 | EmitStoreToStackLocalOrContextSlot(var, location); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2598 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2599 | } else if (IsSignallingAssignmentToConst(var, op, strict_mode())) { |
| 2600 | __ CallRuntime(Runtime::kThrowConstAssignError, 0); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2605 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2606 | // Assignment to a property, using a named store IC. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2607 | // eax : value |
| 2608 | // esp[0] : receiver |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2609 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2610 | Property* prop = expr->target()->AsProperty(); |
| 2611 | DCHECK(prop != NULL); |
| 2612 | DCHECK(prop->key()->IsLiteral()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2613 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2614 | // Record source code position before IC call. |
| 2615 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2616 | __ mov(StoreDescriptor::NameRegister(), prop->key()->AsLiteral()->value()); |
| 2617 | __ pop(StoreDescriptor::ReceiverRegister()); |
| 2618 | CallStoreIC(expr->AssignmentFeedbackId()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2619 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2620 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2624 | void FullCodeGenerator::EmitNamedSuperPropertyStore(Property* prop) { |
| 2625 | // Assignment to named property of super. |
| 2626 | // eax : value |
| 2627 | // stack : receiver ('this'), home_object |
| 2628 | DCHECK(prop != NULL); |
| 2629 | Literal* key = prop->key()->AsLiteral(); |
| 2630 | DCHECK(key != NULL); |
| 2631 | |
| 2632 | __ push(Immediate(key->value())); |
| 2633 | __ push(eax); |
| 2634 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreToSuper_Strict |
| 2635 | : Runtime::kStoreToSuper_Sloppy), |
| 2636 | 4); |
| 2637 | } |
| 2638 | |
| 2639 | |
| 2640 | void FullCodeGenerator::EmitKeyedSuperPropertyStore(Property* prop) { |
| 2641 | // Assignment to named property of super. |
| 2642 | // eax : value |
| 2643 | // stack : receiver ('this'), home_object, key |
| 2644 | |
| 2645 | __ push(eax); |
| 2646 | __ CallRuntime((strict_mode() == STRICT ? Runtime::kStoreKeyedToSuper_Strict |
| 2647 | : Runtime::kStoreKeyedToSuper_Sloppy), |
| 2648 | 4); |
| 2649 | } |
| 2650 | |
| 2651 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2652 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2653 | // Assignment to a property, using a keyed store IC. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2654 | // eax : value |
| 2655 | // esp[0] : key |
| 2656 | // esp[kPointerSize] : receiver |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2657 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2658 | __ pop(StoreDescriptor::NameRegister()); // Key. |
| 2659 | __ pop(StoreDescriptor::ReceiverRegister()); |
| 2660 | DCHECK(StoreDescriptor::ValueRegister().is(eax)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2661 | // Record source code position before IC call. |
| 2662 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2663 | Handle<Code> ic = CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 2664 | CallIC(ic, expr->AssignmentFeedbackId()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2665 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2666 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2667 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2671 | void FullCodeGenerator::VisitProperty(Property* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2672 | Comment cmnt(masm_, "[ Property"); |
| 2673 | Expression* key = expr->key(); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2674 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 2675 | if (key->IsPropertyName()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2676 | if (!expr->IsSuperAccess()) { |
| 2677 | VisitForAccumulatorValue(expr->obj()); |
| 2678 | __ Move(LoadDescriptor::ReceiverRegister(), result_register()); |
| 2679 | EmitNamedPropertyLoad(expr); |
| 2680 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2681 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2682 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2683 | __ push(result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2684 | EmitNamedSuperPropertyLoad(expr); |
| 2685 | } |
| 2686 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2687 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2688 | } else { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2689 | if (!expr->IsSuperAccess()) { |
| 2690 | VisitForStackValue(expr->obj()); |
| 2691 | VisitForAccumulatorValue(expr->key()); |
| 2692 | __ pop(LoadDescriptor::ReceiverRegister()); // Object. |
| 2693 | __ Move(LoadDescriptor::NameRegister(), result_register()); // Key. |
| 2694 | EmitKeyedPropertyLoad(expr); |
| 2695 | } else { |
| 2696 | VisitForStackValue(expr->obj()->AsSuperReference()->this_var()); |
| 2697 | EmitLoadHomeObject(expr->obj()->AsSuperReference()); |
| 2698 | __ push(result_register()); |
| 2699 | VisitForStackValue(expr->key()); |
| 2700 | EmitKeyedSuperPropertyLoad(expr); |
| 2701 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2702 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2703 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2707 | void FullCodeGenerator::CallIC(Handle<Code> code, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2708 | TypeFeedbackId ast_id) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2709 | ic_total_count_++; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2710 | __ call(code, RelocInfo::CODE_TARGET, ast_id); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2714 | // Code common for calls using the IC. |
| 2715 | void FullCodeGenerator::EmitCallWithLoadIC(Call* expr) { |
| 2716 | Expression* callee = expr->expression(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2717 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2718 | CallICState::CallType call_type = |
| 2719 | callee->IsVariableProxy() ? CallICState::FUNCTION : CallICState::METHOD; |
| 2720 | // Get the target function. |
| 2721 | if (call_type == CallICState::FUNCTION) { |
| 2722 | { StackValueContext context(this); |
| 2723 | EmitVariableLoad(callee->AsVariableProxy()); |
| 2724 | PrepareForBailout(callee, NO_REGISTERS); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2725 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2726 | // Push undefined as receiver. This is patched in the method prologue if it |
| 2727 | // is a sloppy mode method. |
| 2728 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 2729 | } else { |
| 2730 | // Load the function from the receiver. |
| 2731 | DCHECK(callee->IsProperty()); |
| 2732 | DCHECK(!callee->AsProperty()->IsSuperAccess()); |
| 2733 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 2734 | EmitNamedPropertyLoad(callee->AsProperty()); |
| 2735 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2736 | // Push the target function under the receiver. |
| 2737 | __ push(Operand(esp, 0)); |
| 2738 | __ mov(Operand(esp, kPointerSize), eax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 2739 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2740 | |
| 2741 | EmitCall(expr, call_type); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2745 | void FullCodeGenerator::EmitSuperCallWithLoadIC(Call* expr) { |
| 2746 | Expression* callee = expr->expression(); |
| 2747 | DCHECK(callee->IsProperty()); |
| 2748 | Property* prop = callee->AsProperty(); |
| 2749 | DCHECK(prop->IsSuperAccess()); |
| 2750 | |
| 2751 | SetSourcePosition(prop->position()); |
| 2752 | Literal* key = prop->key()->AsLiteral(); |
| 2753 | DCHECK(!key->value()->IsSmi()); |
| 2754 | // Load the function from the receiver. |
| 2755 | SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); |
| 2756 | EmitLoadHomeObject(super_ref); |
| 2757 | __ push(eax); |
| 2758 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2759 | __ push(eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2760 | __ push(eax); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2761 | __ push(Operand(esp, kPointerSize * 2)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2762 | __ push(Immediate(key->value())); |
| 2763 | // Stack here: |
| 2764 | // - home_object |
| 2765 | // - this (receiver) |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2766 | // - this (receiver) <-- LoadFromSuper will pop here and below. |
| 2767 | // - home_object |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2768 | // - key |
| 2769 | __ CallRuntime(Runtime::kLoadFromSuper, 3); |
| 2770 | |
| 2771 | // Replace home_object with target function. |
| 2772 | __ mov(Operand(esp, kPointerSize), eax); |
| 2773 | |
| 2774 | // Stack here: |
| 2775 | // - target function |
| 2776 | // - this (receiver) |
| 2777 | EmitCall(expr, CallICState::METHOD); |
| 2778 | } |
| 2779 | |
| 2780 | |
| 2781 | // Code common for calls using the IC. |
| 2782 | void FullCodeGenerator::EmitKeyedCallWithLoadIC(Call* expr, |
| 2783 | Expression* key) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2784 | // Load the key. |
| 2785 | VisitForAccumulatorValue(key); |
| 2786 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2787 | Expression* callee = expr->expression(); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2788 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2789 | // Load the function from the receiver. |
| 2790 | DCHECK(callee->IsProperty()); |
| 2791 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 2792 | __ mov(LoadDescriptor::NameRegister(), eax); |
| 2793 | EmitKeyedPropertyLoad(callee->AsProperty()); |
| 2794 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2795 | |
| 2796 | // Push the target function under the receiver. |
| 2797 | __ push(Operand(esp, 0)); |
| 2798 | __ mov(Operand(esp, kPointerSize), eax); |
| 2799 | |
| 2800 | EmitCall(expr, CallICState::METHOD); |
| 2801 | } |
| 2802 | |
| 2803 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2804 | void FullCodeGenerator::EmitKeyedSuperCallWithLoadIC(Call* expr) { |
| 2805 | Expression* callee = expr->expression(); |
| 2806 | DCHECK(callee->IsProperty()); |
| 2807 | Property* prop = callee->AsProperty(); |
| 2808 | DCHECK(prop->IsSuperAccess()); |
| 2809 | |
| 2810 | SetSourcePosition(prop->position()); |
| 2811 | // Load the function from the receiver. |
| 2812 | SuperReference* super_ref = callee->AsProperty()->obj()->AsSuperReference(); |
| 2813 | EmitLoadHomeObject(super_ref); |
| 2814 | __ push(eax); |
| 2815 | VisitForAccumulatorValue(super_ref->this_var()); |
| 2816 | __ push(eax); |
| 2817 | __ push(eax); |
| 2818 | __ push(Operand(esp, kPointerSize * 2)); |
| 2819 | VisitForStackValue(prop->key()); |
| 2820 | // Stack here: |
| 2821 | // - home_object |
| 2822 | // - this (receiver) |
| 2823 | // - this (receiver) <-- LoadKeyedFromSuper will pop here and below. |
| 2824 | // - home_object |
| 2825 | // - key |
| 2826 | __ CallRuntime(Runtime::kLoadKeyedFromSuper, 3); |
| 2827 | |
| 2828 | // Replace home_object with target function. |
| 2829 | __ mov(Operand(esp, kPointerSize), eax); |
| 2830 | |
| 2831 | // Stack here: |
| 2832 | // - target function |
| 2833 | // - this (receiver) |
| 2834 | EmitCall(expr, CallICState::METHOD); |
| 2835 | } |
| 2836 | |
| 2837 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2838 | void FullCodeGenerator::EmitCall(Call* expr, CallICState::CallType call_type) { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 2839 | // Load the arguments. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2840 | ZoneList<Expression*>* args = expr->arguments(); |
| 2841 | int arg_count = args->length(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2842 | { PreservePositionScope scope(masm()->positions_recorder()); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2843 | for (int i = 0; i < arg_count; i++) { |
| 2844 | VisitForStackValue(args->at(i)); |
| 2845 | } |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2846 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2847 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 2848 | // Record source position of the IC call. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2849 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2850 | Handle<Code> ic = CallIC::initialize_stub( |
| 2851 | isolate(), arg_count, call_type); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2852 | __ Move(edx, Immediate(SmiFromSlot(expr->CallFeedbackSlot()))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2853 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2854 | // Don't assign a type feedback id to the IC, since type feedback is provided |
| 2855 | // by the vector above. |
| 2856 | CallIC(ic); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2857 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2858 | RecordJSReturnSite(expr); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2859 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2860 | // Restore context register. |
| 2861 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2862 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2863 | context()->DropAndPlug(1, eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2867 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2868 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2869 | if (arg_count > 0) { |
| 2870 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2871 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2872 | __ push(Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2873 | } |
| 2874 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2875 | // Push the enclosing function. |
| 2876 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2877 | // Push the receiver of the enclosing function. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2878 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2879 | // Push the language mode. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2880 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2881 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2882 | // Push the start position of the scope the calls resides in. |
| 2883 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2884 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2885 | // Do the runtime call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2886 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 6); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2890 | void FullCodeGenerator::EmitLoadSuperConstructor(SuperReference* super_ref) { |
| 2891 | DCHECK(super_ref != NULL); |
| 2892 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 2893 | __ CallRuntime(Runtime::kGetPrototype, 1); |
| 2894 | } |
| 2895 | |
| 2896 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 2897 | void FullCodeGenerator::VisitCall(Call* expr) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2898 | #ifdef DEBUG |
| 2899 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2900 | // through this function. Avoid early returns. |
| 2901 | expr->return_is_recorded_ = false; |
| 2902 | #endif |
| 2903 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2904 | Comment cmnt(masm_, "[ Call"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2905 | Expression* callee = expr->expression(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2906 | Call::CallType call_type = expr->GetCallType(isolate()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 2907 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2908 | if (call_type == Call::POSSIBLY_EVAL_CALL) { |
| 2909 | // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval |
| 2910 | // to resolve the function we need to call and the receiver of the call. |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2911 | // Then we call the resolved function using the given arguments. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2912 | ZoneList<Expression*>* args = expr->arguments(); |
| 2913 | int arg_count = args->length(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2914 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2915 | VisitForStackValue(callee); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2916 | // Reserved receiver slot. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2917 | __ push(Immediate(isolate()->factory()->undefined_value())); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2918 | // Push the arguments. |
| 2919 | for (int i = 0; i < arg_count; i++) { |
| 2920 | VisitForStackValue(args->at(i)); |
| 2921 | } |
| 2922 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2923 | // Push a copy of the function (found below the arguments) and |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2924 | // resolve eval. |
| 2925 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2926 | EmitResolvePossiblyDirectEval(arg_count); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2927 | |
| 2928 | // The runtime call returns a pair of values in eax (function) and |
| 2929 | // edx (receiver). Touch up the stack with the right values. |
| 2930 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2931 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2932 | |
| 2933 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2934 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2935 | // Record source position for debugger. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2936 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2937 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2938 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2939 | __ CallStub(&stub); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2940 | RecordJSReturnSite(expr); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2941 | // Restore context register. |
| 2942 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 2943 | context()->DropAndPlug(1, eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2944 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2945 | } else if (call_type == Call::GLOBAL_CALL) { |
| 2946 | EmitCallWithLoadIC(expr); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2947 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2948 | } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2949 | // Call to a lookup slot (dynamically introduced variable). |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2950 | VariableProxy* proxy = callee->AsVariableProxy(); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2951 | Label slow, done; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2952 | { PreservePositionScope scope(masm()->positions_recorder()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2953 | // Generate code for loading from variables potentially shadowed by |
| 2954 | // eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2955 | EmitDynamicLookupFastCase(proxy, NOT_INSIDE_TYPEOF, &slow, &done); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2956 | } |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2957 | __ bind(&slow); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2958 | // Call the runtime to find the function to call (returned in eax) and |
| 2959 | // the object holding it (returned in edx). |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2960 | __ push(context_register()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2961 | __ push(Immediate(proxy->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2962 | __ CallRuntime(Runtime::kLoadLookupSlot, 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 2963 | __ push(eax); // Function. |
| 2964 | __ push(edx); // Receiver. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2965 | PrepareForBailoutForId(expr->EvalOrLookupId(), NO_REGISTERS); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2966 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2967 | // If fast case code has been generated, emit code to push the function |
| 2968 | // and receiver and have the slow path jump around this code. |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2969 | if (done.is_linked()) { |
| 2970 | Label call; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2971 | __ jmp(&call, Label::kNear); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2972 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 2973 | // Push function. |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2974 | __ push(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2975 | // The receiver is implicitly the global receiver. Indicate this by |
| 2976 | // passing the hole to the call function stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2977 | __ push(Immediate(isolate()->factory()->undefined_value())); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 2978 | __ bind(&call); |
| 2979 | } |
| 2980 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2981 | // The receiver is either the global receiver or an object found by |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2982 | // LoadContextSlot. |
| 2983 | EmitCall(expr); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2984 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2985 | } else if (call_type == Call::PROPERTY_CALL) { |
| 2986 | Property* property = callee->AsProperty(); |
| 2987 | bool is_named_call = property->key()->IsPropertyName(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 2988 | if (property->IsSuperAccess()) { |
| 2989 | if (is_named_call) { |
| 2990 | EmitSuperCallWithLoadIC(expr); |
| 2991 | } else { |
| 2992 | EmitKeyedSuperCallWithLoadIC(expr); |
| 2993 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 2994 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2995 | { |
| 2996 | PreservePositionScope scope(masm()->positions_recorder()); |
| 2997 | VisitForStackValue(property->obj()); |
| 2998 | } |
| 2999 | if (is_named_call) { |
| 3000 | EmitCallWithLoadIC(expr); |
| 3001 | } else { |
| 3002 | EmitKeyedCallWithLoadIC(expr, property->key()); |
| 3003 | } |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 3004 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3005 | } else if (call_type == Call::SUPER_CALL) { |
| 3006 | SuperReference* super_ref = callee->AsSuperReference(); |
| 3007 | EmitLoadSuperConstructor(super_ref); |
| 3008 | __ push(result_register()); |
| 3009 | VisitForStackValue(super_ref->this_var()); |
| 3010 | EmitCall(expr, CallICState::METHOD); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 3011 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3012 | DCHECK(call_type == Call::OTHER_CALL); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 3013 | // Call to an arbitrary expression not handled specially above. |
| 3014 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 3015 | VisitForStackValue(callee); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 3016 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3017 | __ push(Immediate(isolate()->factory()->undefined_value())); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3018 | // Emit function call. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3019 | EmitCall(expr); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3020 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3021 | |
| 3022 | #ifdef DEBUG |
| 3023 | // RecordJSReturnSite should have been called. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3024 | DCHECK(expr->return_is_recorded_); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3025 | #endif |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 3029 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3030 | Comment cmnt(masm_, "[ CallNew"); |
| 3031 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 3032 | // expression in new calls must be evaluated before the |
| 3033 | // arguments. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3034 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3035 | // Push constructor on the stack. If it's not a function it's used as |
| 3036 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 3037 | // ignored. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3038 | if (expr->expression()->IsSuperReference()) { |
| 3039 | EmitLoadSuperConstructor(expr->expression()->AsSuperReference()); |
| 3040 | __ push(result_register()); |
| 3041 | } else { |
| 3042 | VisitForStackValue(expr->expression()); |
| 3043 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3044 | |
| 3045 | // Push the arguments ("left-to-right") on the stack. |
| 3046 | ZoneList<Expression*>* args = expr->arguments(); |
| 3047 | int arg_count = args->length(); |
| 3048 | for (int i = 0; i < arg_count; i++) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3049 | VisitForStackValue(args->at(i)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | // Call the construct call builtin that handles allocation and |
| 3053 | // constructor invocation. |
| 3054 | SetSourcePosition(expr->position()); |
| 3055 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3056 | // Load function and argument count into edi and eax. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3057 | __ Move(eax, Immediate(arg_count)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3058 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 3059 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3060 | // Record call targets in unoptimized code. |
| 3061 | if (FLAG_pretenuring_call_new) { |
| 3062 | EnsureSlotContainsAllocationSite(expr->AllocationSiteFeedbackSlot()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3063 | DCHECK(expr->AllocationSiteFeedbackSlot().ToInt() == |
| 3064 | expr->CallNewFeedbackSlot().ToInt() + 1); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3065 | } |
Ben Murdoch | 5d4cdbf | 2012-04-11 10:23:59 +0100 | [diff] [blame] | 3066 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3067 | __ LoadHeapObject(ebx, FeedbackVector()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3068 | __ mov(edx, Immediate(SmiFromSlot(expr->CallNewFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3069 | |
| 3070 | CallConstructStub stub(isolate(), RECORD_CONSTRUCTOR_TARGET); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3071 | __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); |
| 3072 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3073 | context()->Plug(eax); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3077 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 3078 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3079 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3080 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3081 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3082 | |
| 3083 | Label materialize_true, materialize_false; |
| 3084 | Label* if_true = NULL; |
| 3085 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3086 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3087 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3088 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3089 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3090 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3091 | __ test(eax, Immediate(kSmiTagMask)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3092 | Split(zero, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3093 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3094 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3098 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 3099 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3100 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3101 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3102 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3103 | |
| 3104 | Label materialize_true, materialize_false; |
| 3105 | Label* if_true = NULL; |
| 3106 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3107 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3108 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3109 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3110 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3111 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3112 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3113 | Split(zero, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3114 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3115 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3119 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 3120 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3121 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3122 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3123 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3124 | |
| 3125 | Label materialize_true, materialize_false; |
| 3126 | Label* if_true = NULL; |
| 3127 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3128 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3129 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3130 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3131 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3132 | __ JumpIfSmi(eax, if_false); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3133 | __ cmp(eax, isolate()->factory()->null_value()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3134 | __ j(equal, if_true); |
| 3135 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3136 | // Undetectable objects behave like undefined when tested with typeof. |
| 3137 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 3138 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 3139 | __ j(not_zero, if_false); |
| 3140 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3141 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3142 | __ j(below, if_false); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3143 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3144 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3145 | Split(below_equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3146 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3147 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3151 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 3152 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3153 | DCHECK(args->length() == 1); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3154 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3155 | VisitForAccumulatorValue(args->at(0)); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3156 | |
| 3157 | Label materialize_true, materialize_false; |
| 3158 | Label* if_true = NULL; |
| 3159 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3160 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3161 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3162 | &if_true, &if_false, &fall_through); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3163 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3164 | __ JumpIfSmi(eax, if_false); |
| 3165 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3166 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3167 | Split(above_equal, if_true, if_false, fall_through); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3168 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3169 | context()->Plug(if_true, if_false); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3173 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 3174 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3175 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3176 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3177 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3178 | |
| 3179 | Label materialize_true, materialize_false; |
| 3180 | Label* if_true = NULL; |
| 3181 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3182 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3183 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3184 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3185 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3186 | __ JumpIfSmi(eax, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3187 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3188 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 3189 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3190 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3191 | Split(not_zero, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3192 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3193 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3197 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3198 | CallRuntime* expr) { |
| 3199 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3200 | DCHECK(args->length() == 1); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3201 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3202 | VisitForAccumulatorValue(args->at(0)); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3203 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3204 | Label materialize_true, materialize_false, skip_lookup; |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3205 | Label* if_true = NULL; |
| 3206 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3207 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3208 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3209 | &if_true, &if_false, &fall_through); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3210 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3211 | __ AssertNotSmi(eax); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3212 | |
| 3213 | // Check whether this map has already been checked to be safe for default |
| 3214 | // valueOf. |
| 3215 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3216 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 3217 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3218 | __ j(not_zero, &skip_lookup); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3219 | |
| 3220 | // Check for fast case object. Return false for slow case objects. |
| 3221 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 3222 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3223 | __ cmp(ecx, isolate()->factory()->hash_table_map()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3224 | __ j(equal, if_false); |
| 3225 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3226 | // Look for valueOf string in the descriptor array, and indicate false if |
| 3227 | // found. Since we omit an enumeration index check, if it is added via a |
| 3228 | // transition that shares its descriptor array, this is a false positive. |
| 3229 | Label entry, loop, done; |
| 3230 | |
| 3231 | // Skip loop if no descriptors are valid. |
| 3232 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 3233 | __ cmp(ecx, 0); |
| 3234 | __ j(equal, &done); |
| 3235 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3236 | __ LoadInstanceDescriptors(ebx, ebx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3237 | // ebx: descriptor array. |
| 3238 | // ecx: valid entries in the descriptor array. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3239 | // Calculate the end of the descriptor array. |
| 3240 | STATIC_ASSERT(kSmiTag == 0); |
| 3241 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3242 | STATIC_ASSERT(kPointerSize == 4); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3243 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 3244 | __ lea(ecx, Operand(ebx, ecx, times_4, DescriptorArray::kFirstOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3245 | // Calculate location of the first key name. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3246 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3247 | // Loop through all the keys in the descriptor array. If one of these is the |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3248 | // internalized string "valueOf" the result is false. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3249 | __ jmp(&entry); |
| 3250 | __ bind(&loop); |
| 3251 | __ mov(edx, FieldOperand(ebx, 0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3252 | __ cmp(edx, isolate()->factory()->value_of_string()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3253 | __ j(equal, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3254 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3255 | __ bind(&entry); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3256 | __ cmp(ebx, ecx); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3257 | __ j(not_equal, &loop); |
| 3258 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3259 | __ bind(&done); |
| 3260 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3261 | // Reload map as register ebx was used as temporary above. |
| 3262 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3263 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3264 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3265 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 3266 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 3267 | |
| 3268 | __ bind(&skip_lookup); |
| 3269 | |
| 3270 | // If a valueOf property is not found on the object check that its |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3271 | // prototype is the un-modified String prototype. If not result is false. |
| 3272 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3273 | __ JumpIfSmi(ecx, if_false); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3274 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3275 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3276 | __ mov(edx, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3277 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3278 | __ cmp(ecx, |
| 3279 | ContextOperand(edx, |
| 3280 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3281 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3282 | Split(equal, if_true, if_false, fall_through); |
| 3283 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3284 | context()->Plug(if_true, if_false); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3288 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3289 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3290 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3291 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3292 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3293 | |
| 3294 | Label materialize_true, materialize_false; |
| 3295 | Label* if_true = NULL; |
| 3296 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3297 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3298 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3299 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3300 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3301 | __ JumpIfSmi(eax, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3302 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3303 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3304 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3305 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3306 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3310 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3311 | ZoneList<Expression*>* args = expr->arguments(); |
| 3312 | DCHECK(args->length() == 1); |
| 3313 | |
| 3314 | VisitForAccumulatorValue(args->at(0)); |
| 3315 | |
| 3316 | Label materialize_true, materialize_false; |
| 3317 | Label* if_true = NULL; |
| 3318 | Label* if_false = NULL; |
| 3319 | Label* fall_through = NULL; |
| 3320 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3321 | &if_true, &if_false, &fall_through); |
| 3322 | |
| 3323 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 3324 | __ CheckMap(eax, map, if_false, DO_SMI_CHECK); |
| 3325 | // Check if the exponent half is 0x80000000. Comparing against 1 and |
| 3326 | // checking for overflow is the shortest possible encoding. |
| 3327 | __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x1)); |
| 3328 | __ j(no_overflow, if_false); |
| 3329 | __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x0)); |
| 3330 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3331 | Split(equal, if_true, if_false, fall_through); |
| 3332 | |
| 3333 | context()->Plug(if_true, if_false); |
| 3334 | } |
| 3335 | |
| 3336 | |
| 3337 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3338 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3339 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3340 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3341 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3342 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3343 | |
| 3344 | Label materialize_true, materialize_false; |
| 3345 | Label* if_true = NULL; |
| 3346 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3347 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3348 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3349 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3350 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3351 | __ JumpIfSmi(eax, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3352 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3353 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3354 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3355 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3356 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3357 | } |
| 3358 | |
| 3359 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3360 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3361 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3362 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3363 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3364 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3365 | |
| 3366 | Label materialize_true, materialize_false; |
| 3367 | Label* if_true = NULL; |
| 3368 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3369 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3370 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3371 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3372 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3373 | __ JumpIfSmi(eax, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3374 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3375 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3376 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3377 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3378 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 3382 | void FullCodeGenerator::EmitIsJSProxy(CallRuntime* expr) { |
| 3383 | ZoneList<Expression*>* args = expr->arguments(); |
| 3384 | DCHECK(args->length() == 1); |
| 3385 | |
| 3386 | VisitForAccumulatorValue(args->at(0)); |
| 3387 | |
| 3388 | Label materialize_true, materialize_false; |
| 3389 | Label* if_true = NULL; |
| 3390 | Label* if_false = NULL; |
| 3391 | Label* fall_through = NULL; |
| 3392 | context()->PrepareTest(&materialize_true, &materialize_false, &if_true, |
| 3393 | &if_false, &fall_through); |
| 3394 | |
| 3395 | __ JumpIfSmi(eax, if_false); |
| 3396 | Register map = ebx; |
| 3397 | __ mov(map, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3398 | __ CmpInstanceType(map, FIRST_JS_PROXY_TYPE); |
| 3399 | __ j(less, if_false); |
| 3400 | __ CmpInstanceType(map, LAST_JS_PROXY_TYPE); |
| 3401 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3402 | Split(less_equal, if_true, if_false, fall_through); |
| 3403 | |
| 3404 | context()->Plug(if_true, if_false); |
| 3405 | } |
| 3406 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3407 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3408 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3409 | DCHECK(expr->arguments()->length() == 0); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3410 | |
| 3411 | Label materialize_true, materialize_false; |
| 3412 | Label* if_true = NULL; |
| 3413 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3414 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3415 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3416 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3417 | |
| 3418 | // Get the frame pointer for the calling frame. |
| 3419 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3420 | |
| 3421 | // Skip the arguments adaptor frame if it exists. |
| 3422 | Label check_frame_marker; |
| 3423 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 3424 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3425 | __ j(not_equal, &check_frame_marker); |
| 3426 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 3427 | |
| 3428 | // Check the marker in the calling frame. |
| 3429 | __ bind(&check_frame_marker); |
| 3430 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 3431 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3432 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3433 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3434 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3435 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3439 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3440 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3441 | DCHECK(args->length() == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3442 | |
| 3443 | // Load the two objects into registers and perform the comparison. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3444 | VisitForStackValue(args->at(0)); |
| 3445 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3446 | |
| 3447 | Label materialize_true, materialize_false; |
| 3448 | Label* if_true = NULL; |
| 3449 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3450 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3451 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3452 | &if_true, &if_false, &fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3453 | |
| 3454 | __ pop(ebx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3455 | __ cmp(eax, ebx); |
| 3456 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3457 | Split(equal, if_true, if_false, fall_through); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3458 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3459 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3463 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3464 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3465 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3466 | |
| 3467 | // ArgumentsAccessStub expects the key in edx and the formal |
| 3468 | // parameter count in eax. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3469 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3470 | __ mov(edx, eax); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3471 | __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
| 3472 | ArgumentsAccessStub stub(isolate(), ArgumentsAccessStub::READ_ELEMENT); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3473 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3474 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3478 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3479 | DCHECK(expr->arguments()->length() == 0); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3480 | |
| 3481 | Label exit; |
| 3482 | // Get the number of formal parameters. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3483 | __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3484 | |
| 3485 | // Check if the calling frame is an arguments adaptor frame. |
| 3486 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3487 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 3488 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3489 | __ j(not_equal, &exit); |
| 3490 | |
| 3491 | // Arguments adaptor case: Read the arguments length from the |
| 3492 | // adaptor frame. |
| 3493 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3494 | |
| 3495 | __ bind(&exit); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3496 | __ AssertSmi(eax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3497 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3501 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3502 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3503 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3504 | Label done, null, function, non_function_constructor; |
| 3505 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3506 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3507 | |
| 3508 | // If the object is a smi, we return null. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3509 | __ JumpIfSmi(eax, &null); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3510 | |
| 3511 | // Check that the object is a JS object but take special care of JS |
| 3512 | // functions to make sure they have 'Function' as their class. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3513 | // Assume that there are only two callable types, and one of them is at |
| 3514 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3515 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3516 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 3517 | // Map is now in eax. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3518 | __ j(below, &null); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3519 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3520 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3521 | __ j(equal, &function); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3522 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3523 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 3524 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3525 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3526 | __ j(equal, &function); |
| 3527 | // Assume that there is no larger type. |
| 3528 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3529 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3530 | // Check if the constructor in the map is a JS function. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3531 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 3532 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3533 | __ j(not_equal, &non_function_constructor); |
| 3534 | |
| 3535 | // eax now contains the constructor function. Grab the |
| 3536 | // instance class name from there. |
| 3537 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3538 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3539 | __ jmp(&done); |
| 3540 | |
| 3541 | // Functions have class 'Function'. |
| 3542 | __ bind(&function); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3543 | __ mov(eax, isolate()->factory()->Function_string()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3544 | __ jmp(&done); |
| 3545 | |
| 3546 | // Objects with a non-function constructor have class 'Object'. |
| 3547 | __ bind(&non_function_constructor); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3548 | __ mov(eax, isolate()->factory()->Object_string()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3549 | __ jmp(&done); |
| 3550 | |
| 3551 | // Non-JS objects have class null. |
| 3552 | __ bind(&null); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3553 | __ mov(eax, isolate()->factory()->null_value()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3554 | |
| 3555 | // All done. |
| 3556 | __ bind(&done); |
| 3557 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3558 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3559 | } |
| 3560 | |
| 3561 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3562 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3563 | // Load the arguments on the stack and call the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3564 | SubStringStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3565 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3566 | DCHECK(args->length() == 3); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3567 | VisitForStackValue(args->at(0)); |
| 3568 | VisitForStackValue(args->at(1)); |
| 3569 | VisitForStackValue(args->at(2)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3570 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3571 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3572 | } |
| 3573 | |
| 3574 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3575 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3576 | // Load the arguments on the stack and call the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3577 | RegExpExecStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3578 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3579 | DCHECK(args->length() == 4); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3580 | VisitForStackValue(args->at(0)); |
| 3581 | VisitForStackValue(args->at(1)); |
| 3582 | VisitForStackValue(args->at(2)); |
| 3583 | VisitForStackValue(args->at(3)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3584 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3585 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3589 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3590 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3591 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3592 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3593 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3594 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3595 | Label done; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3596 | // If the object is a smi return the object. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3597 | __ JumpIfSmi(eax, &done, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3598 | // If the object is not a value type, return the object. |
| 3599 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3600 | __ j(not_equal, &done, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3601 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3602 | |
| 3603 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3604 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3608 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3609 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3610 | DCHECK(args->length() == 2); |
| 3611 | DCHECK_NE(NULL, args->at(1)->AsLiteral()); |
| 3612 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3613 | |
| 3614 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3615 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3616 | Label runtime, done, not_date_object; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3617 | Register object = eax; |
| 3618 | Register result = eax; |
| 3619 | Register scratch = ecx; |
| 3620 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3621 | __ JumpIfSmi(object, ¬_date_object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3622 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3623 | __ j(not_equal, ¬_date_object); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3624 | |
| 3625 | if (index->value() == 0) { |
| 3626 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3627 | __ jmp(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3628 | } else { |
| 3629 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3630 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3631 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3632 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3633 | __ j(not_equal, &runtime, Label::kNear); |
| 3634 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3635 | kPointerSize * index->value())); |
| 3636 | __ jmp(&done); |
| 3637 | } |
| 3638 | __ bind(&runtime); |
| 3639 | __ PrepareCallCFunction(2, scratch); |
| 3640 | __ mov(Operand(esp, 0), object); |
| 3641 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3642 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3643 | __ jmp(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3644 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3645 | |
| 3646 | __ bind(¬_date_object); |
| 3647 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3648 | __ bind(&done); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3649 | context()->Plug(result); |
| 3650 | } |
| 3651 | |
| 3652 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3653 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3654 | ZoneList<Expression*>* args = expr->arguments(); |
| 3655 | DCHECK_EQ(3, args->length()); |
| 3656 | |
| 3657 | Register string = eax; |
| 3658 | Register index = ebx; |
| 3659 | Register value = ecx; |
| 3660 | |
| 3661 | VisitForStackValue(args->at(0)); // index |
| 3662 | VisitForStackValue(args->at(1)); // value |
| 3663 | VisitForAccumulatorValue(args->at(2)); // string |
| 3664 | |
| 3665 | __ pop(value); |
| 3666 | __ pop(index); |
| 3667 | |
| 3668 | if (FLAG_debug_code) { |
| 3669 | __ test(value, Immediate(kSmiTagMask)); |
| 3670 | __ Check(zero, kNonSmiValue); |
| 3671 | __ test(index, Immediate(kSmiTagMask)); |
| 3672 | __ Check(zero, kNonSmiValue); |
| 3673 | } |
| 3674 | |
| 3675 | __ SmiUntag(value); |
| 3676 | __ SmiUntag(index); |
| 3677 | |
| 3678 | if (FLAG_debug_code) { |
| 3679 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3680 | __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3681 | } |
| 3682 | |
| 3683 | __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3684 | value); |
| 3685 | context()->Plug(string); |
| 3686 | } |
| 3687 | |
| 3688 | |
| 3689 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3690 | ZoneList<Expression*>* args = expr->arguments(); |
| 3691 | DCHECK_EQ(3, args->length()); |
| 3692 | |
| 3693 | Register string = eax; |
| 3694 | Register index = ebx; |
| 3695 | Register value = ecx; |
| 3696 | |
| 3697 | VisitForStackValue(args->at(0)); // index |
| 3698 | VisitForStackValue(args->at(1)); // value |
| 3699 | VisitForAccumulatorValue(args->at(2)); // string |
| 3700 | __ pop(value); |
| 3701 | __ pop(index); |
| 3702 | |
| 3703 | if (FLAG_debug_code) { |
| 3704 | __ test(value, Immediate(kSmiTagMask)); |
| 3705 | __ Check(zero, kNonSmiValue); |
| 3706 | __ test(index, Immediate(kSmiTagMask)); |
| 3707 | __ Check(zero, kNonSmiValue); |
| 3708 | __ SmiUntag(index); |
| 3709 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 3710 | __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3711 | __ SmiTag(index); |
| 3712 | } |
| 3713 | |
| 3714 | __ SmiUntag(value); |
| 3715 | // No need to untag a smi for two-byte addressing. |
| 3716 | __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), |
| 3717 | value); |
| 3718 | context()->Plug(string); |
| 3719 | } |
| 3720 | |
| 3721 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3722 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3723 | // Load the arguments on the stack and call the runtime function. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3724 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3725 | DCHECK(args->length() == 2); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3726 | VisitForStackValue(args->at(0)); |
| 3727 | VisitForStackValue(args->at(1)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3728 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3729 | MathPowStub stub(isolate(), MathPowStub::ON_STACK); |
| 3730 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3731 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3735 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3736 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3737 | DCHECK(args->length() == 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3738 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3739 | VisitForStackValue(args->at(0)); // Load the object. |
| 3740 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3741 | __ pop(ebx); // eax = value. ebx = object. |
| 3742 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3743 | Label done; |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3744 | // If the object is a smi, return the value. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3745 | __ JumpIfSmi(ebx, &done, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3746 | |
| 3747 | // If the object is not a value type, return the value. |
| 3748 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3749 | __ j(not_equal, &done, Label::kNear); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3750 | |
| 3751 | // Store the value. |
| 3752 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3753 | |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3754 | // Update the write barrier. Save the value as it will be |
| 3755 | // overwritten by the write barrier code and is needed afterward. |
| 3756 | __ mov(edx, eax); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3757 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3758 | |
| 3759 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3760 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3764 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3765 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3766 | DCHECK_EQ(args->length(), 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3767 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3768 | // Load the argument into eax and call the stub. |
| 3769 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3770 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3771 | NumberToStringStub stub(isolate()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3772 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3773 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3777 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3778 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3779 | DCHECK(args->length() == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3780 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3781 | VisitForAccumulatorValue(args->at(0)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3782 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3783 | Label done; |
| 3784 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3785 | generator.GenerateFast(masm_); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3786 | __ jmp(&done); |
| 3787 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3788 | NopRuntimeCallHelper call_helper; |
| 3789 | generator.GenerateSlow(masm_, call_helper); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3790 | |
| 3791 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3792 | context()->Plug(ebx); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3796 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3797 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3798 | DCHECK(args->length() == 2); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3799 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3800 | VisitForStackValue(args->at(0)); |
| 3801 | VisitForAccumulatorValue(args->at(1)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3802 | |
| 3803 | Register object = ebx; |
| 3804 | Register index = eax; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3805 | Register result = edx; |
| 3806 | |
| 3807 | __ pop(object); |
| 3808 | |
| 3809 | Label need_conversion; |
| 3810 | Label index_out_of_range; |
| 3811 | Label done; |
| 3812 | StringCharCodeAtGenerator generator(object, |
| 3813 | index, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3814 | result, |
| 3815 | &need_conversion, |
| 3816 | &need_conversion, |
| 3817 | &index_out_of_range, |
| 3818 | STRING_INDEX_IS_NUMBER); |
| 3819 | generator.GenerateFast(masm_); |
| 3820 | __ jmp(&done); |
| 3821 | |
| 3822 | __ bind(&index_out_of_range); |
| 3823 | // When the index is out of range, the spec requires us to return |
| 3824 | // NaN. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3825 | __ Move(result, Immediate(isolate()->factory()->nan_value())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3826 | __ jmp(&done); |
| 3827 | |
| 3828 | __ bind(&need_conversion); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3829 | // Move the undefined value into the result register, which will |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3830 | // trigger conversion. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3831 | __ Move(result, Immediate(isolate()->factory()->undefined_value())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3832 | __ jmp(&done); |
| 3833 | |
| 3834 | NopRuntimeCallHelper call_helper; |
| 3835 | generator.GenerateSlow(masm_, call_helper); |
| 3836 | |
| 3837 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3838 | context()->Plug(result); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3839 | } |
| 3840 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3841 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3842 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3843 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3844 | DCHECK(args->length() == 2); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3845 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3846 | VisitForStackValue(args->at(0)); |
| 3847 | VisitForAccumulatorValue(args->at(1)); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3848 | |
| 3849 | Register object = ebx; |
| 3850 | Register index = eax; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3851 | Register scratch = edx; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3852 | Register result = eax; |
| 3853 | |
| 3854 | __ pop(object); |
| 3855 | |
| 3856 | Label need_conversion; |
| 3857 | Label index_out_of_range; |
| 3858 | Label done; |
| 3859 | StringCharAtGenerator generator(object, |
| 3860 | index, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3861 | scratch, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3862 | result, |
| 3863 | &need_conversion, |
| 3864 | &need_conversion, |
| 3865 | &index_out_of_range, |
| 3866 | STRING_INDEX_IS_NUMBER); |
| 3867 | generator.GenerateFast(masm_); |
| 3868 | __ jmp(&done); |
| 3869 | |
| 3870 | __ bind(&index_out_of_range); |
| 3871 | // When the index is out of range, the spec requires us to return |
| 3872 | // the empty string. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3873 | __ Move(result, Immediate(isolate()->factory()->empty_string())); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3874 | __ jmp(&done); |
| 3875 | |
| 3876 | __ bind(&need_conversion); |
| 3877 | // Move smi zero into the result register, which will trigger |
| 3878 | // conversion. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3879 | __ Move(result, Immediate(Smi::FromInt(0))); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3880 | __ jmp(&done); |
| 3881 | |
| 3882 | NopRuntimeCallHelper call_helper; |
| 3883 | generator.GenerateSlow(masm_, call_helper); |
| 3884 | |
| 3885 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3886 | context()->Plug(result); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3890 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3891 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3892 | DCHECK_EQ(2, args->length()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3893 | VisitForStackValue(args->at(0)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3894 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3895 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3896 | __ pop(edx); |
| 3897 | StringAddStub stub(isolate(), STRING_ADD_CHECK_BOTH, NOT_TENURED); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3898 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3899 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3903 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3904 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3905 | DCHECK_EQ(2, args->length()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3906 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3907 | VisitForStackValue(args->at(0)); |
| 3908 | VisitForStackValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3909 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3910 | StringCompareStub stub(isolate()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3911 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3912 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3916 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3917 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3918 | DCHECK(args->length() >= 2); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3919 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3920 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3921 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3922 | VisitForStackValue(args->at(i)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3923 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3924 | VisitForAccumulatorValue(args->last()); // Function. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3925 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3926 | Label runtime, done; |
| 3927 | // Check for non-function argument (including proxy). |
| 3928 | __ JumpIfSmi(eax, &runtime); |
| 3929 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3930 | __ j(not_equal, &runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3931 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3932 | // InvokeFunction requires the function in edi. Move it in there. |
| 3933 | __ mov(edi, result_register()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3934 | ParameterCount count(arg_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3935 | __ InvokeFunction(edi, count, CALL_FUNCTION, NullCallWrapper()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3936 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3937 | __ jmp(&done); |
| 3938 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3939 | __ bind(&runtime); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3940 | __ push(eax); |
| 3941 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3942 | __ bind(&done); |
| 3943 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3944 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3948 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3949 | // Load the arguments on the stack and call the stub. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3950 | RegExpConstructResultStub stub(isolate()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3951 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3952 | DCHECK(args->length() == 3); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3953 | VisitForStackValue(args->at(0)); |
| 3954 | VisitForStackValue(args->at(1)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3955 | VisitForAccumulatorValue(args->at(2)); |
| 3956 | __ pop(ebx); |
| 3957 | __ pop(ecx); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3958 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3959 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 3963 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3964 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3965 | DCHECK_EQ(2, args->length()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3966 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3967 | DCHECK_NE(NULL, args->at(0)->AsLiteral()); |
| 3968 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3969 | |
| 3970 | Handle<FixedArray> jsfunction_result_caches( |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3971 | isolate()->native_context()->jsfunction_result_caches()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3972 | if (jsfunction_result_caches->length() <= cache_id) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3973 | __ Abort(kAttemptToUseUndefinedCache); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3974 | __ mov(eax, isolate()->factory()->undefined_value()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3975 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3976 | return; |
| 3977 | } |
| 3978 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 3979 | VisitForAccumulatorValue(args->at(1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3980 | |
| 3981 | Register key = eax; |
| 3982 | Register cache = ebx; |
| 3983 | Register tmp = ecx; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3984 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3985 | __ mov(cache, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3986 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 3987 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3988 | __ mov(cache, |
| 3989 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3990 | |
| 3991 | Label done, not_found; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 3992 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3993 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3994 | // tmp now holds finger offset as a smi. |
| 3995 | __ cmp(key, FixedArrayElementOperand(cache, tmp)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3996 | __ j(not_equal, ¬_found); |
| 3997 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 3998 | __ mov(eax, FixedArrayElementOperand(cache, tmp, 1)); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 3999 | __ jmp(&done); |
| 4000 | |
| 4001 | __ bind(¬_found); |
| 4002 | // Call runtime to perform the lookup. |
| 4003 | __ push(cache); |
| 4004 | __ push(key); |
| 4005 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 4006 | |
| 4007 | __ bind(&done); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4008 | context()->Plug(eax); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
| 4011 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4012 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 4013 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4014 | DCHECK(args->length() == 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4015 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4016 | VisitForAccumulatorValue(args->at(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4017 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4018 | __ AssertString(eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4019 | |
| 4020 | Label materialize_true, materialize_false; |
| 4021 | Label* if_true = NULL; |
| 4022 | Label* if_false = NULL; |
| 4023 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4024 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4025 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4026 | |
| 4027 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 4028 | Immediate(String::kContainsCachedArrayIndexMask)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4029 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4030 | Split(zero, if_true, if_false, fall_through); |
| 4031 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4032 | context()->Plug(if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4036 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 4037 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4038 | DCHECK(args->length() == 1); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4039 | VisitForAccumulatorValue(args->at(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4040 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4041 | __ AssertString(eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4042 | |
| 4043 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 4044 | __ IndexFromHash(eax, eax); |
| 4045 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4046 | context()->Plug(eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4050 | void FullCodeGenerator::EmitFastOneByteArrayJoin(CallRuntime* expr) { |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4051 | Label bailout, done, one_char_separator, long_separator, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4052 | non_trivial_array, not_size_one_array, loop, |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4053 | loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4054 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4055 | ZoneList<Expression*>* args = expr->arguments(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4056 | DCHECK(args->length() == 2); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4057 | // We will leave the separator on the stack until the end of the function. |
| 4058 | VisitForStackValue(args->at(1)); |
| 4059 | // Load this to eax (= array) |
| 4060 | VisitForAccumulatorValue(args->at(0)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4061 | // All aliases of the same register have disjoint lifetimes. |
| 4062 | Register array = eax; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4063 | Register elements = no_reg; // Will be eax. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4064 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4065 | Register index = edx; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4066 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4067 | Register string_length = ecx; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4068 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4069 | Register string = esi; |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4070 | |
| 4071 | Register scratch = ebx; |
| 4072 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4073 | Register array_length = edi; |
| 4074 | Register result_pos = no_reg; // Will be edi. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4075 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4076 | // Separator operand is already pushed. |
| 4077 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 4078 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 4079 | Operand array_length_operand = Operand(esp, 0); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4080 | __ sub(esp, Immediate(2 * kPointerSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4081 | __ cld(); |
| 4082 | // Check that the array is a JSArray |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4083 | __ JumpIfSmi(array, &bailout); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4084 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 4085 | __ j(not_equal, &bailout); |
| 4086 | |
| 4087 | // Check that the array has fast elements. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4088 | __ CheckFastElements(scratch, &bailout); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4089 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4090 | // If the array has length zero, return the empty string. |
| 4091 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4092 | __ SmiUntag(array_length); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4093 | __ j(not_zero, &non_trivial_array); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4094 | __ mov(result_operand, isolate()->factory()->empty_string()); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4095 | __ jmp(&done); |
| 4096 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4097 | // Save the array length. |
| 4098 | __ bind(&non_trivial_array); |
| 4099 | __ mov(array_length_operand, array_length); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4100 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4101 | // Save the FixedArray containing array's elements. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4102 | // End of array's live range. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4103 | elements = array; |
| 4104 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4105 | array = no_reg; |
| 4106 | |
| 4107 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4108 | // Check that all array elements are sequential one-byte strings, and |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4109 | // accumulate the sum of their lengths, as a smi-encoded value. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4110 | __ Move(index, Immediate(0)); |
| 4111 | __ Move(string_length, Immediate(0)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4112 | // Loop condition: while (index < length). |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4113 | // Live loop registers: index, array_length, string, |
| 4114 | // scratch, string_length, elements. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4115 | if (generate_debug_code_) { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4116 | __ cmp(index, array_length); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4117 | __ Assert(less, kNoEmptyArraysHereInEmitFastOneByteArrayJoin); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4118 | } |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4119 | __ bind(&loop); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4120 | __ mov(string, FieldOperand(elements, |
| 4121 | index, |
| 4122 | times_pointer_size, |
| 4123 | FixedArray::kHeaderSize)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4124 | __ JumpIfSmi(string, &bailout); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4125 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 4126 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 4127 | __ and_(scratch, Immediate( |
| 4128 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4129 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4130 | __ j(not_equal, &bailout); |
| 4131 | __ add(string_length, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4132 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4133 | __ j(overflow, &bailout); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4134 | __ add(index, Immediate(1)); |
| 4135 | __ cmp(index, array_length); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4136 | __ j(less, &loop); |
| 4137 | |
| 4138 | // If array_length is 1, return elements[0], a string. |
| 4139 | __ cmp(array_length, 1); |
| 4140 | __ j(not_equal, ¬_size_one_array); |
| 4141 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 4142 | __ mov(result_operand, scratch); |
| 4143 | __ jmp(&done); |
| 4144 | |
| 4145 | __ bind(¬_size_one_array); |
| 4146 | |
| 4147 | // End of array_length live range. |
| 4148 | result_pos = array_length; |
| 4149 | array_length = no_reg; |
| 4150 | |
| 4151 | // Live registers: |
| 4152 | // string_length: Sum of string lengths, as a smi. |
| 4153 | // elements: FixedArray of strings. |
| 4154 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4155 | // Check that the separator is a flat one-byte string. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4156 | __ mov(string, separator_operand); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4157 | __ JumpIfSmi(string, &bailout); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4158 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 4159 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4160 | __ and_(scratch, Immediate( |
| 4161 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4162 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4163 | __ j(not_equal, &bailout); |
| 4164 | |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4165 | // Add (separator length times array_length) - separator length |
| 4166 | // to string_length. |
| 4167 | __ mov(scratch, separator_operand); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4168 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4169 | __ sub(string_length, scratch); // May be negative, temporarily. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4170 | __ imul(scratch, array_length_operand); |
| 4171 | __ j(overflow, &bailout); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4172 | __ add(string_length, scratch); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4173 | __ j(overflow, &bailout); |
| 4174 | |
| 4175 | __ shr(string_length, 1); |
| 4176 | // Live registers and stack values: |
| 4177 | // string_length |
| 4178 | // elements |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4179 | __ AllocateOneByteString(result_pos, string_length, scratch, index, string, |
| 4180 | &bailout); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4181 | __ mov(result_operand, result_pos); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4182 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4183 | |
| 4184 | |
| 4185 | __ mov(string, separator_operand); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4186 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4187 | Immediate(Smi::FromInt(1))); |
| 4188 | __ j(equal, &one_char_separator); |
| 4189 | __ j(greater, &long_separator); |
| 4190 | |
| 4191 | |
| 4192 | // Empty separator case |
| 4193 | __ mov(index, Immediate(0)); |
| 4194 | __ jmp(&loop_1_condition); |
| 4195 | // Loop condition: while (index < length). |
| 4196 | __ bind(&loop_1); |
| 4197 | // Each iteration of the loop concatenates one string to the result. |
| 4198 | // Live values in registers: |
| 4199 | // index: which element of the elements array we are adding to the result. |
| 4200 | // result_pos: the position to which we are currently copying characters. |
| 4201 | // elements: the FixedArray of strings we are joining. |
| 4202 | |
| 4203 | // Get string = array[index]. |
| 4204 | __ mov(string, FieldOperand(elements, index, |
| 4205 | times_pointer_size, |
| 4206 | FixedArray::kHeaderSize)); |
| 4207 | __ mov(string_length, |
| 4208 | FieldOperand(string, String::kLengthOffset)); |
| 4209 | __ shr(string_length, 1); |
| 4210 | __ lea(string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4211 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4212 | __ CopyBytes(string, result_pos, string_length, scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4213 | __ add(index, Immediate(1)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4214 | __ bind(&loop_1_condition); |
| 4215 | __ cmp(index, array_length_operand); |
| 4216 | __ j(less, &loop_1); // End while (index < length). |
| 4217 | __ jmp(&done); |
| 4218 | |
| 4219 | |
| 4220 | |
| 4221 | // One-character separator case |
| 4222 | __ bind(&one_char_separator); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4223 | // Replace separator with its one-byte character value. |
| 4224 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4225 | __ mov_b(separator_operand, scratch); |
| 4226 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4227 | __ Move(index, Immediate(0)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4228 | // Jump into the loop after the code that copies the separator, so the first |
| 4229 | // element is not preceded by a separator |
| 4230 | __ jmp(&loop_2_entry); |
| 4231 | // Loop condition: while (index < length). |
| 4232 | __ bind(&loop_2); |
| 4233 | // Each iteration of the loop concatenates one string to the result. |
| 4234 | // Live values in registers: |
| 4235 | // index: which element of the elements array we are adding to the result. |
| 4236 | // result_pos: the position to which we are currently copying characters. |
| 4237 | |
| 4238 | // Copy the separator character to the result. |
| 4239 | __ mov_b(scratch, separator_operand); |
| 4240 | __ mov_b(Operand(result_pos, 0), scratch); |
| 4241 | __ inc(result_pos); |
| 4242 | |
| 4243 | __ bind(&loop_2_entry); |
| 4244 | // Get string = array[index]. |
| 4245 | __ mov(string, FieldOperand(elements, index, |
| 4246 | times_pointer_size, |
| 4247 | FixedArray::kHeaderSize)); |
| 4248 | __ mov(string_length, |
| 4249 | FieldOperand(string, String::kLengthOffset)); |
| 4250 | __ shr(string_length, 1); |
| 4251 | __ lea(string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4252 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4253 | __ CopyBytes(string, result_pos, string_length, scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4254 | __ add(index, Immediate(1)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4255 | |
| 4256 | __ cmp(index, array_length_operand); |
| 4257 | __ j(less, &loop_2); // End while (index < length). |
| 4258 | __ jmp(&done); |
| 4259 | |
| 4260 | |
| 4261 | // Long separator case (separator is more than one character). |
| 4262 | __ bind(&long_separator); |
| 4263 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4264 | __ Move(index, Immediate(0)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4265 | // Jump into the loop after the code that copies the separator, so the first |
| 4266 | // element is not preceded by a separator |
| 4267 | __ jmp(&loop_3_entry); |
| 4268 | // Loop condition: while (index < length). |
| 4269 | __ bind(&loop_3); |
| 4270 | // Each iteration of the loop concatenates one string to the result. |
| 4271 | // Live values in registers: |
| 4272 | // index: which element of the elements array we are adding to the result. |
| 4273 | // result_pos: the position to which we are currently copying characters. |
| 4274 | |
| 4275 | // Copy the separator to the result. |
| 4276 | __ mov(string, separator_operand); |
| 4277 | __ mov(string_length, |
| 4278 | FieldOperand(string, String::kLengthOffset)); |
| 4279 | __ shr(string_length, 1); |
| 4280 | __ lea(string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4281 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4282 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 4283 | |
| 4284 | __ bind(&loop_3_entry); |
| 4285 | // Get string = array[index]. |
| 4286 | __ mov(string, FieldOperand(elements, index, |
| 4287 | times_pointer_size, |
| 4288 | FixedArray::kHeaderSize)); |
| 4289 | __ mov(string_length, |
| 4290 | FieldOperand(string, String::kLengthOffset)); |
| 4291 | __ shr(string_length, 1); |
| 4292 | __ lea(string, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4293 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4294 | __ CopyBytes(string, result_pos, string_length, scratch); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4295 | __ add(index, Immediate(1)); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4296 | |
| 4297 | __ cmp(index, array_length_operand); |
| 4298 | __ j(less, &loop_3); // End while (index < length). |
| 4299 | __ jmp(&done); |
| 4300 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4301 | |
| 4302 | __ bind(&bailout); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4303 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4304 | __ bind(&done); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 4305 | __ mov(eax, result_operand); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4306 | // Drop temp values from the stack, and restore context register. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4307 | __ add(esp, Immediate(3 * kPointerSize)); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4308 | |
| 4309 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4310 | context()->Plug(eax); |
| 4311 | } |
| 4312 | |
| 4313 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4314 | void FullCodeGenerator::EmitDebugIsActive(CallRuntime* expr) { |
| 4315 | DCHECK(expr->arguments()->length() == 0); |
| 4316 | ExternalReference debug_is_active = |
| 4317 | ExternalReference::debug_is_active_address(isolate()); |
| 4318 | __ movzx_b(eax, Operand::StaticVariable(debug_is_active)); |
| 4319 | __ SmiTag(eax); |
| 4320 | context()->Plug(eax); |
| 4321 | } |
| 4322 | |
| 4323 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4324 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4325 | if (expr->function() != NULL && |
| 4326 | expr->function()->intrinsic_type == Runtime::INLINE) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4327 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4328 | EmitInlineRuntimeCall(expr); |
| 4329 | return; |
| 4330 | } |
| 4331 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4332 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4333 | ZoneList<Expression*>* args = expr->arguments(); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4334 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4335 | if (expr->is_jsruntime()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4336 | // Push the builtins object as receiver. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 4337 | __ mov(eax, GlobalObjectOperand()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4338 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4339 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4340 | // Load the function from the receiver. |
| 4341 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 4342 | __ mov(LoadDescriptor::NameRegister(), Immediate(expr->name())); |
| 4343 | if (FLAG_vector_ics) { |
| 4344 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4345 | Immediate(SmiFromSlot(expr->CallRuntimeFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4346 | CallLoadIC(NOT_CONTEXTUAL); |
| 4347 | } else { |
| 4348 | CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); |
| 4349 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4350 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4351 | // Push the target function under the receiver. |
| 4352 | __ push(Operand(esp, 0)); |
| 4353 | __ mov(Operand(esp, kPointerSize), eax); |
| 4354 | |
| 4355 | // Code common for calls using the IC. |
| 4356 | ZoneList<Expression*>* args = expr->arguments(); |
| 4357 | int arg_count = args->length(); |
| 4358 | for (int i = 0; i < arg_count; i++) { |
| 4359 | VisitForStackValue(args->at(i)); |
| 4360 | } |
| 4361 | |
| 4362 | // Record source position of the IC call. |
| 4363 | SetSourcePosition(expr->position()); |
| 4364 | CallFunctionStub stub(isolate(), arg_count, NO_CALL_FUNCTION_FLAGS); |
| 4365 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 4366 | __ CallStub(&stub); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4367 | // Restore context register. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4368 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4369 | context()->DropAndPlug(1, eax); |
| 4370 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4371 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4372 | // Push the arguments ("left-to-right"). |
| 4373 | int arg_count = args->length(); |
| 4374 | for (int i = 0; i < arg_count; i++) { |
| 4375 | VisitForStackValue(args->at(i)); |
| 4376 | } |
| 4377 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4378 | // Call the C runtime function. |
| 4379 | __ CallRuntime(expr->function(), arg_count); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4380 | |
| 4381 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4386 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4387 | switch (expr->op()) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4388 | case Token::DELETE: { |
| 4389 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4390 | Property* property = expr->expression()->AsProperty(); |
| 4391 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4392 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4393 | if (property != NULL) { |
| 4394 | VisitForStackValue(property->obj()); |
| 4395 | VisitForStackValue(property->key()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4396 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4397 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 4398 | context()->Plug(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4399 | } else if (proxy != NULL) { |
| 4400 | Variable* var = proxy->var(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4401 | // Delete of an unqualified identifier is disallowed in strict mode |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4402 | // but "delete this" is allowed. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4403 | DCHECK(strict_mode() == SLOPPY || var->is_this()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4404 | if (var->IsUnallocated()) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4405 | __ push(GlobalObjectOperand()); |
| 4406 | __ push(Immediate(var->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4407 | __ push(Immediate(Smi::FromInt(SLOPPY))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4408 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4409 | context()->Plug(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4410 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4411 | // Result of deleting non-global variables is false. 'this' is |
| 4412 | // not really a variable, though we implement it as one. The |
| 4413 | // subexpression does not have side effects. |
| 4414 | context()->Plug(var->is_this()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4415 | } else { |
| 4416 | // Non-global variable. Call the runtime to try to delete from the |
| 4417 | // context where the variable was introduced. |
| 4418 | __ push(context_register()); |
| 4419 | __ push(Immediate(var->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4420 | __ CallRuntime(Runtime::kDeleteLookupSlot, 2); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4421 | context()->Plug(eax); |
| 4422 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4423 | } else { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4424 | // Result of deleting non-property, non-variable reference is true. |
| 4425 | // The subexpression may have side effects. |
| 4426 | VisitForEffect(expr->expression()); |
| 4427 | context()->Plug(true); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4428 | } |
| 4429 | break; |
| 4430 | } |
| 4431 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4432 | case Token::VOID: { |
| 4433 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4434 | VisitForEffect(expr->expression()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4435 | context()->Plug(isolate()->factory()->undefined_value()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4436 | break; |
| 4437 | } |
| 4438 | |
| 4439 | case Token::NOT: { |
| 4440 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4441 | if (context()->IsEffect()) { |
| 4442 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4443 | // subexpression. Match the optimizing compiler by not branching. |
| 4444 | VisitForEffect(expr->expression()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4445 | } else if (context()->IsTest()) { |
| 4446 | const TestContext* test = TestContext::cast(context()); |
| 4447 | // The labels are swapped for the recursive call. |
| 4448 | VisitForControl(expr->expression(), |
| 4449 | test->false_label(), |
| 4450 | test->true_label(), |
| 4451 | test->fall_through()); |
| 4452 | context()->Plug(test->true_label(), test->false_label()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4453 | } else { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4454 | // We handle value contexts explicitly rather than simply visiting |
| 4455 | // for control and plugging the control flow into the context, |
| 4456 | // because we need to prepare a pair of extra administrative AST ids |
| 4457 | // for the optimizing compiler. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4458 | DCHECK(context()->IsAccumulatorValue() || context()->IsStackValue()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4459 | Label materialize_true, materialize_false, done; |
| 4460 | VisitForControl(expr->expression(), |
| 4461 | &materialize_false, |
| 4462 | &materialize_true, |
| 4463 | &materialize_true); |
| 4464 | __ bind(&materialize_true); |
| 4465 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4466 | if (context()->IsAccumulatorValue()) { |
| 4467 | __ mov(eax, isolate()->factory()->true_value()); |
| 4468 | } else { |
| 4469 | __ Push(isolate()->factory()->true_value()); |
| 4470 | } |
| 4471 | __ jmp(&done, Label::kNear); |
| 4472 | __ bind(&materialize_false); |
| 4473 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4474 | if (context()->IsAccumulatorValue()) { |
| 4475 | __ mov(eax, isolate()->factory()->false_value()); |
| 4476 | } else { |
| 4477 | __ Push(isolate()->factory()->false_value()); |
| 4478 | } |
| 4479 | __ bind(&done); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4480 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4481 | break; |
| 4482 | } |
| 4483 | |
| 4484 | case Token::TYPEOF: { |
| 4485 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4486 | { StackValueContext context(this); |
| 4487 | VisitForTypeofValue(expr->expression()); |
| 4488 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4489 | __ CallRuntime(Runtime::kTypeof, 1); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4490 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4491 | break; |
| 4492 | } |
| 4493 | |
| 4494 | default: |
| 4495 | UNREACHABLE(); |
| 4496 | } |
| 4497 | } |
| 4498 | |
| 4499 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4500 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4501 | DCHECK(expr->expression()->IsValidReferenceExpression()); |
| 4502 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4503 | Comment cmnt(masm_, "[ CountOperation"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4504 | SetSourcePosition(expr->position()); |
| 4505 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4506 | Property* prop = expr->expression()->AsProperty(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4507 | LhsKind assign_type = GetAssignType(prop); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4508 | |
| 4509 | // Evaluate expression and get value. |
| 4510 | if (assign_type == VARIABLE) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4511 | DCHECK(expr->expression()->AsVariableProxy()->var() != NULL); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4512 | AccumulatorValueContext context(this); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4513 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4514 | } else { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4515 | // Reserve space for result of postfix operation. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4516 | if (expr->is_postfix() && !context()->IsEffect()) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4517 | __ push(Immediate(Smi::FromInt(0))); |
| 4518 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4519 | switch (assign_type) { |
| 4520 | case NAMED_PROPERTY: { |
| 4521 | // Put the object both on the stack and in the register. |
| 4522 | VisitForStackValue(prop->obj()); |
| 4523 | __ mov(LoadDescriptor::ReceiverRegister(), Operand(esp, 0)); |
| 4524 | EmitNamedPropertyLoad(prop); |
| 4525 | break; |
| 4526 | } |
| 4527 | |
| 4528 | case NAMED_SUPER_PROPERTY: { |
| 4529 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4530 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4531 | __ push(result_register()); |
| 4532 | __ push(MemOperand(esp, kPointerSize)); |
| 4533 | __ push(result_register()); |
| 4534 | EmitNamedSuperPropertyLoad(prop); |
| 4535 | break; |
| 4536 | } |
| 4537 | |
| 4538 | case KEYED_SUPER_PROPERTY: { |
| 4539 | VisitForStackValue(prop->obj()->AsSuperReference()->this_var()); |
| 4540 | EmitLoadHomeObject(prop->obj()->AsSuperReference()); |
| 4541 | __ push(result_register()); |
| 4542 | VisitForAccumulatorValue(prop->key()); |
| 4543 | __ push(result_register()); |
| 4544 | __ push(MemOperand(esp, 2 * kPointerSize)); |
| 4545 | __ push(MemOperand(esp, 2 * kPointerSize)); |
| 4546 | __ push(result_register()); |
| 4547 | EmitKeyedSuperPropertyLoad(prop); |
| 4548 | break; |
| 4549 | } |
| 4550 | |
| 4551 | case KEYED_PROPERTY: { |
| 4552 | VisitForStackValue(prop->obj()); |
| 4553 | VisitForStackValue(prop->key()); |
| 4554 | __ mov(LoadDescriptor::ReceiverRegister(), |
| 4555 | Operand(esp, kPointerSize)); // Object. |
| 4556 | __ mov(LoadDescriptor::NameRegister(), Operand(esp, 0)); // Key. |
| 4557 | EmitKeyedPropertyLoad(prop); |
| 4558 | break; |
| 4559 | } |
| 4560 | |
| 4561 | case VARIABLE: |
| 4562 | UNREACHABLE(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4563 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4566 | // We need a second deoptimization point after loading the value |
| 4567 | // in case evaluating the property load my have a side effect. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 4568 | if (assign_type == VARIABLE) { |
| 4569 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4570 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4571 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 4572 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4573 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4574 | // Inline smi case if we are in a loop. |
| 4575 | Label done, stub_call; |
| 4576 | JumpPatchSite patch_site(masm_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4577 | if (ShouldInlineSmiCase(expr->op())) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4578 | Label slow; |
| 4579 | patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); |
| 4580 | |
| 4581 | // Save result for postfix expressions. |
| 4582 | if (expr->is_postfix()) { |
| 4583 | if (!context()->IsEffect()) { |
| 4584 | // Save the result on the stack. If we have a named or keyed property |
| 4585 | // we store the result under the receiver that is currently on top |
| 4586 | // of the stack. |
| 4587 | switch (assign_type) { |
| 4588 | case VARIABLE: |
| 4589 | __ push(eax); |
| 4590 | break; |
| 4591 | case NAMED_PROPERTY: |
| 4592 | __ mov(Operand(esp, kPointerSize), eax); |
| 4593 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4594 | case NAMED_SUPER_PROPERTY: |
| 4595 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4596 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4597 | case KEYED_PROPERTY: |
| 4598 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4599 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4600 | case KEYED_SUPER_PROPERTY: |
| 4601 | __ mov(Operand(esp, 3 * kPointerSize), eax); |
| 4602 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4603 | } |
| 4604 | } |
| 4605 | } |
| 4606 | |
| 4607 | if (expr->op() == Token::INC) { |
| 4608 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4609 | } else { |
| 4610 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4611 | } |
| 4612 | __ j(no_overflow, &done, Label::kNear); |
| 4613 | // Call stub. Undo operation first. |
| 4614 | if (expr->op() == Token::INC) { |
| 4615 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4616 | } else { |
| 4617 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4618 | } |
| 4619 | __ jmp(&stub_call, Label::kNear); |
| 4620 | __ bind(&slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4621 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4622 | ToNumberStub convert_stub(isolate()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4623 | __ CallStub(&convert_stub); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4624 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4625 | // Save result for postfix expressions. |
| 4626 | if (expr->is_postfix()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4627 | if (!context()->IsEffect()) { |
| 4628 | // Save the result on the stack. If we have a named or keyed property |
| 4629 | // we store the result under the receiver that is currently on top |
| 4630 | // of the stack. |
| 4631 | switch (assign_type) { |
| 4632 | case VARIABLE: |
| 4633 | __ push(eax); |
| 4634 | break; |
| 4635 | case NAMED_PROPERTY: |
| 4636 | __ mov(Operand(esp, kPointerSize), eax); |
| 4637 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4638 | case NAMED_SUPER_PROPERTY: |
| 4639 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4640 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4641 | case KEYED_PROPERTY: |
| 4642 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4643 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4644 | case KEYED_SUPER_PROPERTY: |
| 4645 | __ mov(Operand(esp, 3 * kPointerSize), eax); |
| 4646 | break; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4647 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4648 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4649 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4650 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4651 | // Record position before stub call. |
| 4652 | SetSourcePosition(expr->position()); |
| 4653 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4654 | // Call stub for +1/-1. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4655 | __ bind(&stub_call); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4656 | __ mov(edx, eax); |
| 4657 | __ mov(eax, Immediate(Smi::FromInt(1))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4658 | Handle<Code> code = CodeFactory::BinaryOpIC(isolate(), expr->binary_op(), |
| 4659 | NO_OVERWRITE).code(); |
| 4660 | CallIC(code, expr->CountBinOpFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4661 | patch_site.EmitPatchInfo(); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4662 | __ bind(&done); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4663 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4664 | // Store the value returned in eax. |
| 4665 | switch (assign_type) { |
| 4666 | case VARIABLE: |
| 4667 | if (expr->is_postfix()) { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4668 | // Perform the assignment as if via '='. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4669 | { EffectContext context(this); |
| 4670 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4671 | Token::ASSIGN); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4672 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4673 | context.Plug(eax); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4674 | } |
| 4675 | // For all contexts except EffectContext We have the result on |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4676 | // top of the stack. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4677 | if (!context()->IsEffect()) { |
| 4678 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4679 | } |
| 4680 | } else { |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4681 | // Perform the assignment as if via '='. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4682 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4683 | Token::ASSIGN); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4684 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4685 | context()->Plug(eax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4686 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4687 | break; |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4688 | case NAMED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4689 | __ mov(StoreDescriptor::NameRegister(), |
| 4690 | prop->key()->AsLiteral()->value()); |
| 4691 | __ pop(StoreDescriptor::ReceiverRegister()); |
| 4692 | CallStoreIC(expr->CountStoreFeedbackId()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4693 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4694 | if (expr->is_postfix()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4695 | if (!context()->IsEffect()) { |
| 4696 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4697 | } |
| 4698 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4699 | context()->Plug(eax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4700 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4701 | break; |
| 4702 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4703 | case NAMED_SUPER_PROPERTY: { |
| 4704 | EmitNamedSuperPropertyStore(prop); |
| 4705 | if (expr->is_postfix()) { |
| 4706 | if (!context()->IsEffect()) { |
| 4707 | context()->PlugTOS(); |
| 4708 | } |
| 4709 | } else { |
| 4710 | context()->Plug(eax); |
| 4711 | } |
| 4712 | break; |
| 4713 | } |
| 4714 | case KEYED_SUPER_PROPERTY: { |
| 4715 | EmitKeyedSuperPropertyStore(prop); |
| 4716 | if (expr->is_postfix()) { |
| 4717 | if (!context()->IsEffect()) { |
| 4718 | context()->PlugTOS(); |
| 4719 | } |
| 4720 | } else { |
| 4721 | context()->Plug(eax); |
| 4722 | } |
| 4723 | break; |
| 4724 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4725 | case KEYED_PROPERTY: { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4726 | __ pop(StoreDescriptor::NameRegister()); |
| 4727 | __ pop(StoreDescriptor::ReceiverRegister()); |
| 4728 | Handle<Code> ic = |
| 4729 | CodeFactory::KeyedStoreIC(isolate(), strict_mode()).code(); |
| 4730 | CallIC(ic, expr->CountStoreFeedbackId()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4731 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4732 | if (expr->is_postfix()) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 4733 | // Result is on the stack |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4734 | if (!context()->IsEffect()) { |
| 4735 | context()->PlugTOS(); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4736 | } |
| 4737 | } else { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4738 | context()->Plug(eax); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4739 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4740 | break; |
| 4741 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4746 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4747 | VariableProxy* proxy = expr->AsVariableProxy(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4748 | DCHECK(!context()->IsEffect()); |
| 4749 | DCHECK(!context()->IsTest()); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4750 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4751 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4752 | Comment cmnt(masm_, "[ Global variable"); |
| 4753 | __ mov(LoadDescriptor::ReceiverRegister(), GlobalObjectOperand()); |
| 4754 | __ mov(LoadDescriptor::NameRegister(), Immediate(proxy->name())); |
| 4755 | if (FLAG_vector_ics) { |
| 4756 | __ mov(VectorLoadICDescriptor::SlotRegister(), |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4757 | Immediate(SmiFromSlot(proxy->VariableFeedbackSlot()))); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4758 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4759 | // Use a regular load, not a contextual load, to avoid a reference |
| 4760 | // error. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4761 | CallLoadIC(NOT_CONTEXTUAL); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4762 | PrepareForBailout(expr, TOS_REG); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4763 | context()->Plug(eax); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 4764 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4765 | Comment cmnt(masm_, "[ Lookup slot"); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4766 | Label done, slow; |
| 4767 | |
| 4768 | // Generate code for loading from variables potentially shadowed |
| 4769 | // by eval-introduced variables. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4770 | EmitDynamicLookupFastCase(proxy, INSIDE_TYPEOF, &slow, &done); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4771 | |
| 4772 | __ bind(&slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4773 | __ push(esi); |
| 4774 | __ push(Immediate(proxy->name())); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4775 | __ CallRuntime(Runtime::kLoadLookupSlotNoReferenceError, 2); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4776 | PrepareForBailout(expr, TOS_REG); |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4777 | __ bind(&done); |
| 4778 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4779 | context()->Plug(eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4780 | } else { |
| 4781 | // This expression cannot throw a reference error at the top level. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4782 | VisitInDuplicateContext(expr); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4783 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 4784 | } |
| 4785 | |
| 4786 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4787 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4788 | Expression* sub_expr, |
| 4789 | Handle<String> check) { |
| 4790 | Label materialize_true, materialize_false; |
| 4791 | Label* if_true = NULL; |
| 4792 | Label* if_false = NULL; |
| 4793 | Label* fall_through = NULL; |
| 4794 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4795 | &if_true, &if_false, &fall_through); |
| 4796 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4797 | { AccumulatorValueContext context(this); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4798 | VisitForTypeofValue(sub_expr); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4799 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4800 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4801 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4802 | Factory* factory = isolate()->factory(); |
| 4803 | if (String::Equals(check, factory->number_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4804 | __ JumpIfSmi(eax, if_true); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4805 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4806 | isolate()->factory()->heap_number_map()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4807 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4808 | } else if (String::Equals(check, factory->string_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4809 | __ JumpIfSmi(eax, if_false); |
| 4810 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4811 | __ j(above_equal, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4812 | // Check for undetectable objects => false. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4813 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4814 | 1 << Map::kIsUndetectable); |
| 4815 | Split(zero, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4816 | } else if (String::Equals(check, factory->symbol_string())) { |
| 4817 | __ JumpIfSmi(eax, if_false); |
| 4818 | __ CmpObjectType(eax, SYMBOL_TYPE, edx); |
| 4819 | Split(equal, if_true, if_false, fall_through); |
| 4820 | } else if (String::Equals(check, factory->boolean_string())) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4821 | __ cmp(eax, isolate()->factory()->true_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4822 | __ j(equal, if_true); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4823 | __ cmp(eax, isolate()->factory()->false_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4824 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4825 | } else if (String::Equals(check, factory->undefined_string())) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4826 | __ cmp(eax, isolate()->factory()->undefined_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4827 | __ j(equal, if_true); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4828 | __ JumpIfSmi(eax, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4829 | // Check for undetectable objects => true. |
| 4830 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4831 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4832 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4833 | Split(not_zero, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4834 | } else if (String::Equals(check, factory->function_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4835 | __ JumpIfSmi(eax, if_false); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4836 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4837 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4838 | __ j(equal, if_true); |
| 4839 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4840 | Split(equal, if_true, if_false, fall_through); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4841 | } else if (String::Equals(check, factory->object_string())) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4842 | __ JumpIfSmi(eax, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4843 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4844 | __ j(equal, if_true); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4845 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4846 | __ j(below, if_false); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4847 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4848 | __ j(above, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4849 | // Check for undetectable objects => false. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4850 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4851 | 1 << Map::kIsUndetectable); |
| 4852 | Split(zero, if_true, if_false, fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4853 | } else { |
| 4854 | if (if_false != fall_through) __ jmp(if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4855 | } |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4856 | context()->Plug(if_true, if_false); |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4860 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4861 | Comment cmnt(masm_, "[ CompareOperation"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4862 | SetSourcePosition(expr->position()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4863 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4864 | // First we try a fast inlined version of the compare when one of |
| 4865 | // the operands is a literal. |
| 4866 | if (TryLiteralCompare(expr)) return; |
| 4867 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4868 | // Always perform the comparison for its control flow. Pack the result |
| 4869 | // into the expression's context after the comparison is performed. |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 4870 | Label materialize_true, materialize_false; |
| 4871 | Label* if_true = NULL; |
| 4872 | Label* if_false = NULL; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4873 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4874 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4875 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4876 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4877 | Token::Value op = expr->op(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4878 | VisitForStackValue(expr->left()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4879 | switch (op) { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4880 | case Token::IN: |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4881 | VisitForStackValue(expr->right()); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4882 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4883 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4884 | __ cmp(eax, isolate()->factory()->true_value()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4885 | Split(equal, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4886 | break; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4887 | |
| 4888 | case Token::INSTANCEOF: { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4889 | VisitForStackValue(expr->right()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4890 | InstanceofStub stub(isolate(), InstanceofStub::kNoFlags); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4891 | __ CallStub(&stub); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4892 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4893 | __ test(eax, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4894 | // The stub returns 0 for true. |
| 4895 | Split(zero, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4896 | break; |
| 4897 | } |
| 4898 | |
| 4899 | default: { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4900 | VisitForAccumulatorValue(expr->right()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4901 | Condition cc = CompareIC::ComputeCondition(op); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4902 | __ pop(edx); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4903 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4904 | bool inline_smi_code = ShouldInlineSmiCase(op); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4905 | JumpPatchSite patch_site(masm_); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4906 | if (inline_smi_code) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4907 | Label slow_case; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4908 | __ mov(ecx, edx); |
| 4909 | __ or_(ecx, eax); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4910 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4911 | __ cmp(edx, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4912 | Split(cc, if_true, if_false, NULL); |
| 4913 | __ bind(&slow_case); |
| 4914 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4915 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4916 | // Record position and call the compare IC. |
| 4917 | SetSourcePosition(expr->position()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4918 | Handle<Code> ic = CodeFactory::CompareIC(isolate(), op).code(); |
| 4919 | CallIC(ic, expr->CompareOperationFeedbackId()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4920 | patch_site.EmitPatchInfo(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4921 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4922 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 4923 | __ test(eax, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4924 | Split(cc, if_true, if_false, fall_through); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4925 | } |
| 4926 | } |
| 4927 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4928 | // Convert the result of the comparison into one expected for this |
| 4929 | // expression's context. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4930 | context()->Plug(if_true, if_false); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4931 | } |
| 4932 | |
| 4933 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4934 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4935 | Expression* sub_expr, |
| 4936 | NilValue nil) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4937 | Label materialize_true, materialize_false; |
| 4938 | Label* if_true = NULL; |
| 4939 | Label* if_false = NULL; |
| 4940 | Label* fall_through = NULL; |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4941 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4942 | &if_true, &if_false, &fall_through); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4943 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4944 | VisitForAccumulatorValue(sub_expr); |
| 4945 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4946 | |
| 4947 | Handle<Object> nil_value = nil == kNullValue |
| 4948 | ? isolate()->factory()->null_value() |
| 4949 | : isolate()->factory()->undefined_value(); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 4950 | if (expr->op() == Token::EQ_STRICT) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4951 | __ cmp(eax, nil_value); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4952 | Split(equal, if_true, if_false, fall_through); |
| 4953 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4954 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
| 4955 | CallIC(ic, expr->CompareOperationFeedbackId()); |
| 4956 | __ test(eax, eax); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4957 | Split(not_zero, if_true, if_false, fall_through); |
| 4958 | } |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4959 | context()->Plug(if_true, if_false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4963 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4964 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4965 | context()->Plug(eax); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 4968 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4969 | Register FullCodeGenerator::result_register() { |
| 4970 | return eax; |
| 4971 | } |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4972 | |
| 4973 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4974 | Register FullCodeGenerator::context_register() { |
| 4975 | return esi; |
| 4976 | } |
| 4977 | |
| 4978 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4979 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4980 | DCHECK_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4981 | __ mov(Operand(ebp, frame_offset), value); |
| 4982 | } |
| 4983 | |
| 4984 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 4985 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
Steve Block | 5915150 | 2010-09-22 15:07:15 +0100 | [diff] [blame] | 4986 | __ mov(dst, ContextOperand(esi, context_index)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 4987 | } |
| 4988 | |
| 4989 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4990 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
| 4991 | Scope* declaration_scope = scope()->DeclarationScope(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 4992 | if (declaration_scope->is_script_scope() || |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 4993 | declaration_scope->is_module_scope()) { |
| 4994 | // Contexts nested in the native context have a canonical empty function |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4995 | // as their closure, not the anonymous closure containing the global |
| 4996 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4997 | // function. |
| 4998 | __ push(Immediate(Smi::FromInt(0))); |
| 4999 | } else if (declaration_scope->is_eval_scope()) { |
| 5000 | // Contexts nested inside eval code have the same closure as the context |
| 5001 | // calling eval, not the anonymous closure containing the eval code. |
| 5002 | // Fetch it from the context. |
| 5003 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 5004 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5005 | DCHECK(declaration_scope->is_function_scope()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5006 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 5007 | } |
| 5008 | } |
| 5009 | |
| 5010 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5011 | // ---------------------------------------------------------------------------- |
| 5012 | // Non-local control flow support. |
| 5013 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5014 | void FullCodeGenerator::EnterFinallyBlock() { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5015 | // Cook return address on top of stack (smi encoded Code* delta) |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5016 | DCHECK(!result_register().is(edx)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5017 | __ pop(edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5018 | __ sub(edx, Immediate(masm_->CodeObject())); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5019 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 5020 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5021 | __ SmiTag(edx); |
| 5022 | __ push(edx); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5023 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5024 | // Store result register while executing finally block. |
| 5025 | __ push(result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5026 | |
| 5027 | // Store pending message while executing finally block. |
| 5028 | ExternalReference pending_message_obj = |
| 5029 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5030 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 5031 | __ push(edx); |
| 5032 | |
| 5033 | ExternalReference has_pending_message = |
| 5034 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5035 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
| 5036 | __ SmiTag(edx); |
| 5037 | __ push(edx); |
| 5038 | |
| 5039 | ExternalReference pending_message_script = |
| 5040 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5041 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 5042 | __ push(edx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 5046 | void FullCodeGenerator::ExitFinallyBlock() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5047 | DCHECK(!result_register().is(edx)); |
| 5048 | // Restore pending message from stack. |
| 5049 | __ pop(edx); |
| 5050 | ExternalReference pending_message_script = |
| 5051 | ExternalReference::address_of_pending_message_script(isolate()); |
| 5052 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 5053 | |
| 5054 | __ pop(edx); |
| 5055 | __ SmiUntag(edx); |
| 5056 | ExternalReference has_pending_message = |
| 5057 | ExternalReference::address_of_has_pending_message(isolate()); |
| 5058 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 5059 | |
| 5060 | __ pop(edx); |
| 5061 | ExternalReference pending_message_obj = |
| 5062 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 5063 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 5064 | |
| 5065 | // Restore result register from stack. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5066 | __ pop(result_register()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5067 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5068 | // Uncook return address. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5069 | __ pop(edx); |
| 5070 | __ SmiUntag(edx); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 5071 | __ add(edx, Immediate(masm_->CodeObject())); |
| 5072 | __ jmp(edx); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 5073 | } |
| 5074 | |
| 5075 | |
| 5076 | #undef __ |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 5077 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5078 | #define __ ACCESS_MASM(masm()) |
| 5079 | |
| 5080 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 5081 | int* stack_depth, |
| 5082 | int* context_length) { |
| 5083 | // The macros used here must preserve the result register. |
| 5084 | |
| 5085 | // Because the handler block contains the context of the finally |
| 5086 | // code, we can restore it directly from there for the finally code |
| 5087 | // rather than iteratively unwinding contexts via their previous |
| 5088 | // links. |
| 5089 | __ Drop(*stack_depth); // Down to the handler block. |
| 5090 | if (*context_length > 0) { |
| 5091 | // Restore the context to its dedicated register and the stack. |
| 5092 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 5093 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 5094 | } |
| 5095 | __ PopTryHandler(); |
| 5096 | __ call(finally_entry_); |
| 5097 | |
| 5098 | *stack_depth = 0; |
| 5099 | *context_length = 0; |
| 5100 | return previous_; |
| 5101 | } |
| 5102 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 5103 | #undef __ |
| 5104 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5105 | |
| 5106 | static const byte kJnsInstruction = 0x79; |
| 5107 | static const byte kJnsOffset = 0x11; |
| 5108 | static const byte kNopByteOne = 0x66; |
| 5109 | static const byte kNopByteTwo = 0x90; |
| 5110 | #ifdef DEBUG |
| 5111 | static const byte kCallInstruction = 0xe8; |
| 5112 | #endif |
| 5113 | |
| 5114 | |
| 5115 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 5116 | Address pc, |
| 5117 | BackEdgeState target_state, |
| 5118 | Code* replacement_code) { |
| 5119 | Address call_target_address = pc - kIntSize; |
| 5120 | Address jns_instr_address = call_target_address - 3; |
| 5121 | Address jns_offset_address = call_target_address - 2; |
| 5122 | |
| 5123 | switch (target_state) { |
| 5124 | case INTERRUPT: |
| 5125 | // sub <profiling_counter>, <delta> ;; Not changed |
| 5126 | // jns ok |
| 5127 | // call <interrupt stub> |
| 5128 | // ok: |
| 5129 | *jns_instr_address = kJnsInstruction; |
| 5130 | *jns_offset_address = kJnsOffset; |
| 5131 | break; |
| 5132 | case ON_STACK_REPLACEMENT: |
| 5133 | case OSR_AFTER_STACK_CHECK: |
| 5134 | // sub <profiling_counter>, <delta> ;; Not changed |
| 5135 | // nop |
| 5136 | // nop |
| 5137 | // call <on-stack replacment> |
| 5138 | // ok: |
| 5139 | *jns_instr_address = kNopByteOne; |
| 5140 | *jns_offset_address = kNopByteTwo; |
| 5141 | break; |
| 5142 | } |
| 5143 | |
| 5144 | Assembler::set_target_address_at(call_target_address, |
| 5145 | unoptimized_code, |
| 5146 | replacement_code->entry()); |
| 5147 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 5148 | unoptimized_code, call_target_address, replacement_code); |
| 5149 | } |
| 5150 | |
| 5151 | |
| 5152 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 5153 | Isolate* isolate, |
| 5154 | Code* unoptimized_code, |
| 5155 | Address pc) { |
| 5156 | Address call_target_address = pc - kIntSize; |
| 5157 | Address jns_instr_address = call_target_address - 3; |
| 5158 | DCHECK_EQ(kCallInstruction, *(call_target_address - 1)); |
| 5159 | |
| 5160 | if (*jns_instr_address == kJnsInstruction) { |
| 5161 | DCHECK_EQ(kJnsOffset, *(call_target_address - 2)); |
| 5162 | DCHECK_EQ(isolate->builtins()->InterruptCheck()->entry(), |
| 5163 | Assembler::target_address_at(call_target_address, |
| 5164 | unoptimized_code)); |
| 5165 | return INTERRUPT; |
| 5166 | } |
| 5167 | |
| 5168 | DCHECK_EQ(kNopByteOne, *jns_instr_address); |
| 5169 | DCHECK_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 5170 | |
| 5171 | if (Assembler::target_address_at(call_target_address, unoptimized_code) == |
| 5172 | isolate->builtins()->OnStackReplacement()->entry()) { |
| 5173 | return ON_STACK_REPLACEMENT; |
| 5174 | } |
| 5175 | |
| 5176 | DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5177 | Assembler::target_address_at(call_target_address, |
| 5178 | unoptimized_code)); |
| 5179 | return OSR_AFTER_STACK_CHECK; |
| 5180 | } |
| 5181 | |
| 5182 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 5183 | } } // namespace v8::internal |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 5184 | |
| 5185 | #endif // V8_TARGET_ARCH_IA32 |