yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 33 | #include "codegen.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 34 | #include "compiler.h" |
| 35 | #include "debug.h" |
| 36 | #include "full-codegen.h" |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 37 | #include "isolate-inl.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 38 | #include "parser.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 39 | #include "scopes.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 40 | #include "stub-cache.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
| 45 | #define __ ACCESS_MASM(masm_) |
| 46 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 47 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 48 | class JumpPatchSite BASE_EMBEDDED { |
| 49 | public: |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 50 | explicit JumpPatchSite(MacroAssembler* masm) : masm_(masm) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 51 | #ifdef DEBUG |
| 52 | info_emitted_ = false; |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | ~JumpPatchSite() { |
| 57 | ASSERT(patch_site_.is_bound() == info_emitted_); |
| 58 | } |
| 59 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 60 | void EmitJumpIfNotSmi(Register reg, |
| 61 | Label* target, |
| 62 | Label::Distance distance = Label::kFar) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 63 | __ test(reg, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 64 | EmitJump(not_carry, target, distance); // Always taken before patched. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 65 | } |
| 66 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 67 | void EmitJumpIfSmi(Register reg, |
| 68 | Label* target, |
| 69 | Label::Distance distance = Label::kFar) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 70 | __ test(reg, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 71 | EmitJump(carry, target, distance); // Never taken before patched. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | void EmitPatchInfo() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 75 | if (patch_site_.is_bound()) { |
| 76 | int delta_to_patch_site = masm_->SizeOfCodeGeneratedSince(&patch_site_); |
| 77 | ASSERT(is_int8(delta_to_patch_site)); |
| 78 | __ test(eax, Immediate(delta_to_patch_site)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 79 | #ifdef DEBUG |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 80 | info_emitted_ = true; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 81 | #endif |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 82 | } else { |
| 83 | __ nop(); // Signals no inlined code. |
| 84 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 85 | } |
| 86 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 87 | private: |
| 88 | // jc will be patched with jz, jnc will become jnz. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 89 | void EmitJump(Condition cc, Label* target, Label::Distance distance) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 90 | ASSERT(!patch_site_.is_bound() && !info_emitted_); |
| 91 | ASSERT(cc == carry || cc == not_carry); |
| 92 | __ bind(&patch_site_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 93 | __ j(cc, target, distance); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | MacroAssembler* masm_; |
| 97 | Label patch_site_; |
| 98 | #ifdef DEBUG |
| 99 | bool info_emitted_; |
| 100 | #endif |
| 101 | }; |
| 102 | |
| 103 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 104 | // Generate code for a JS function. On entry to the function the receiver |
| 105 | // and arguments have been pushed on the stack left to right, with the |
| 106 | // return address on top of them. The actual argument count matches the |
| 107 | // formal parameter count expected by the function. |
| 108 | // |
| 109 | // The live registers are: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 110 | // o edi: the JS function object being called (i.e. ourselves) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 111 | // o esi: our context |
| 112 | // o ebp: our caller's frame pointer |
| 113 | // o esp: stack pointer (pointing to return address) |
| 114 | // |
| 115 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 116 | // frames-ia32.h for its layout. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 117 | void FullCodeGenerator::Generate() { |
| 118 | CompilationInfo* info = info_; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 119 | handler_table_ = |
| 120 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 121 | profiling_counter_ = isolate()->factory()->NewJSGlobalPropertyCell( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 122 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 123 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 124 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 125 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 126 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 127 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 128 | #ifdef DEBUG |
| 129 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 130 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 131 | __ int3(); |
| 132 | } |
| 133 | #endif |
| 134 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 135 | // Strict mode functions and builtins need to replace the receiver |
| 136 | // with undefined when called as functions (without an explicit |
| 137 | // receiver object). ecx is zero for method calls and non-zero for |
| 138 | // function calls. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 139 | if (!info->is_classic_mode() || info->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 140 | Label ok; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 141 | __ test(ecx, ecx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 142 | __ j(zero, &ok, Label::kNear); |
| 143 | // +1 for return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 144 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 145 | __ mov(ecx, Operand(esp, receiver_offset)); |
| 146 | __ JumpIfSmi(ecx, &ok); |
| 147 | __ CmpObjectType(ecx, JS_GLOBAL_PROXY_TYPE, ecx); |
| 148 | __ j(not_equal, &ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 149 | __ mov(Operand(esp, receiver_offset), |
| 150 | Immediate(isolate()->factory()->undefined_value())); |
| 151 | __ bind(&ok); |
| 152 | } |
| 153 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 154 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 155 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 156 | // the frame (that is done below). |
| 157 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 158 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 159 | info->set_prologue_offset(masm_->pc_offset()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 160 | __ push(ebp); // Caller's frame pointer. |
| 161 | __ mov(ebp, esp); |
| 162 | __ push(esi); // Callee's context. |
| 163 | __ push(edi); // Callee's JS Function. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 164 | info->AddNoFrameRange(0, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 165 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 166 | { Comment cmnt(masm_, "[ Allocate locals"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 167 | int locals_count = info->scope()->num_stack_slots(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 168 | // Generators allocate locals, if any, in context slots. |
| 169 | ASSERT(!info->function()->is_generator() || locals_count == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 170 | if (locals_count == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 171 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 172 | } else if (locals_count > 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 173 | __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 174 | for (int i = 0; i < locals_count; i++) { |
| 175 | __ push(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 176 | } |
| 177 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 178 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 179 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 180 | bool function_in_register = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 181 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 182 | // Possibly allocate a local context. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 183 | int heap_slots = info->scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 184 | if (heap_slots > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 185 | Comment cmnt(masm_, "[ Allocate context"); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 186 | // Argument to NewContext is the function, which is still in edi. |
| 187 | __ push(edi); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 188 | if (FLAG_harmony_scoping && info->scope()->is_global_scope()) { |
| 189 | __ Push(info->scope()->GetScopeInfo()); |
| 190 | __ CallRuntime(Runtime::kNewGlobalContext, 2); |
| 191 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 192 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 193 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 194 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 195 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 196 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 197 | function_in_register = false; |
| 198 | // Context is returned in both eax and esi. It replaces the context |
| 199 | // passed to us. It's saved in the stack and kept live in esi. |
| 200 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 201 | |
| 202 | // Copy parameters into context if necessary. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 203 | int num_parameters = info->scope()->num_parameters(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 204 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 205 | Variable* var = scope()->parameter(i); |
| 206 | if (var->IsContextSlot()) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 207 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 208 | (num_parameters - 1 - i) * kPointerSize; |
| 209 | // Load parameter from stack. |
| 210 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 211 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 212 | int context_offset = Context::SlotOffset(var->index()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 213 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 214 | // Update the write barrier. This clobbers eax and ebx. |
| 215 | __ RecordWriteContextSlot(esi, |
| 216 | context_offset, |
| 217 | eax, |
| 218 | ebx, |
| 219 | kDontSaveFPRegs); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 224 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 225 | if (arguments != NULL) { |
| 226 | // Function uses arguments object. |
| 227 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 228 | if (function_in_register) { |
| 229 | __ push(edi); |
| 230 | } else { |
| 231 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 232 | } |
| 233 | // Receiver is just before the parameters on the caller's stack. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 234 | int num_parameters = info->scope()->num_parameters(); |
| 235 | int offset = num_parameters * kPointerSize; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 236 | __ lea(edx, |
| 237 | Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 238 | __ push(edx); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 239 | __ push(Immediate(Smi::FromInt(num_parameters))); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 240 | // Arguments to ArgumentsAccessStub: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 241 | // function, receiver address, parameter count. |
| 242 | // The stub will rewrite receiver and parameter count if the previous |
| 243 | // stack frame was an arguments adapter frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 244 | ArgumentsAccessStub::Type type; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 245 | if (!is_classic_mode()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 246 | type = ArgumentsAccessStub::NEW_STRICT; |
| 247 | } else if (function()->has_duplicate_parameters()) { |
| 248 | type = ArgumentsAccessStub::NEW_NON_STRICT_SLOW; |
| 249 | } else { |
| 250 | type = ArgumentsAccessStub::NEW_NON_STRICT_FAST; |
| 251 | } |
| 252 | ArgumentsAccessStub stub(type); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 253 | __ CallStub(&stub); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 254 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 255 | SetVar(arguments, eax, ebx, edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 256 | } |
| 257 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 258 | if (FLAG_trace) { |
| 259 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 260 | } |
| 261 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 262 | // Visit the declarations and body unless there is an illegal |
| 263 | // redeclaration. |
| 264 | if (scope()->HasIllegalRedeclaration()) { |
| 265 | Comment cmnt(masm_, "[ Declarations"); |
| 266 | scope()->VisitIllegalRedeclaration(this); |
| 267 | |
| 268 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 269 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 270 | { Comment cmnt(masm_, "[ Declarations"); |
| 271 | // For named function expressions, declare the function name as a |
| 272 | // constant. |
| 273 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 274 | VariableDeclaration* function = scope()->function(); |
| 275 | ASSERT(function->proxy()->var()->mode() == CONST || |
| 276 | function->proxy()->var()->mode() == CONST_HARMONY); |
| 277 | ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 278 | VisitVariableDeclaration(function); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 279 | } |
| 280 | VisitDeclarations(scope()->declarations()); |
| 281 | } |
| 282 | |
| 283 | { Comment cmnt(masm_, "[ Stack check"); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 284 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 285 | Label ok; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 286 | ExternalReference stack_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 287 | ExternalReference::address_of_stack_limit(isolate()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 288 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 289 | __ j(above_equal, &ok, Label::kNear); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 290 | StackCheckStub stub; |
| 291 | __ CallStub(&stub); |
| 292 | __ bind(&ok); |
| 293 | } |
| 294 | |
| 295 | { Comment cmnt(masm_, "[ Body"); |
| 296 | ASSERT(loop_depth() == 0); |
| 297 | VisitStatements(function()->body()); |
| 298 | ASSERT(loop_depth() == 0); |
| 299 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 300 | } |
| 301 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 302 | // Always emit a 'return undefined' in case control fell off the end of |
| 303 | // the body. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 304 | { Comment cmnt(masm_, "[ return <undefined>;"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 305 | __ mov(eax, isolate()->factory()->undefined_value()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 306 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
| 310 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 311 | void FullCodeGenerator::ClearAccumulator() { |
| 312 | __ Set(eax, Immediate(Smi::FromInt(0))); |
| 313 | } |
| 314 | |
| 315 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 316 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 317 | __ mov(ebx, Immediate(profiling_counter_)); |
| 318 | __ sub(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 319 | Immediate(Smi::FromInt(delta))); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 324 | int reset_value = FLAG_interrupt_budget; |
| 325 | if (info_->ShouldSelfOptimize() && !FLAG_retry_self_opt) { |
| 326 | // Self-optimization is a one-off thing: if it fails, don't try again. |
| 327 | reset_value = Smi::kMaxValue; |
| 328 | } |
| 329 | __ mov(ebx, Immediate(profiling_counter_)); |
| 330 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 331 | Immediate(Smi::FromInt(reset_value))); |
| 332 | } |
| 333 | |
| 334 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 335 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 336 | Label* back_edge_target) { |
| 337 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 338 | Label ok; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 339 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 340 | int weight = 1; |
| 341 | if (FLAG_weighted_back_edges) { |
| 342 | ASSERT(back_edge_target->is_bound()); |
| 343 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 344 | weight = Min(kMaxBackEdgeWeight, |
| 345 | Max(1, distance / kBackEdgeDistanceUnit)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 346 | } |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 347 | EmitProfilingCounterDecrement(weight); |
| 348 | __ j(positive, &ok, Label::kNear); |
| 349 | InterruptStub stub; |
| 350 | __ CallStub(&stub); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 351 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 352 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 353 | // the AST id from the unoptimized code in order to use it as a key into |
| 354 | // the deoptimization input data found in the optimized code. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 355 | RecordBackEdge(stmt->OsrEntryId()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 356 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 357 | EmitProfilingCounterReset(); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 358 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 359 | __ bind(&ok); |
| 360 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 361 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 362 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 363 | // we want it to work if it is. |
| 364 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 368 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 369 | Comment cmnt(masm_, "[ Return sequence"); |
| 370 | if (return_label_.is_bound()) { |
| 371 | __ jmp(&return_label_); |
| 372 | } else { |
| 373 | // Common return label |
| 374 | __ bind(&return_label_); |
| 375 | if (FLAG_trace) { |
| 376 | __ push(eax); |
| 377 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 378 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 379 | if (FLAG_interrupt_at_exit || FLAG_self_optimization) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 380 | // Pretend that the exit is a backwards jump to the entry. |
| 381 | int weight = 1; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 382 | if (info_->ShouldSelfOptimize()) { |
| 383 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 384 | } else if (FLAG_weighted_back_edges) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 385 | int distance = masm_->pc_offset(); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 386 | weight = Min(kMaxBackEdgeWeight, |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 387 | Max(1, distance / kBackEdgeDistanceUnit)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 388 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 389 | EmitProfilingCounterDecrement(weight); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 390 | Label ok; |
| 391 | __ j(positive, &ok, Label::kNear); |
| 392 | __ push(eax); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 393 | if (info_->ShouldSelfOptimize() && FLAG_direct_self_opt) { |
| 394 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 395 | __ CallRuntime(Runtime::kOptimizeFunctionOnNextCall, 1); |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 396 | } else { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 397 | InterruptStub stub; |
| 398 | __ CallStub(&stub); |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 399 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 400 | __ pop(eax); |
| 401 | EmitProfilingCounterReset(); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 402 | __ bind(&ok); |
| 403 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 404 | #ifdef DEBUG |
| 405 | // Add a label for checking the size of the code used for returning. |
| 406 | Label check_exit_codesize; |
| 407 | masm_->bind(&check_exit_codesize); |
| 408 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 409 | SetSourcePosition(function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 410 | __ RecordJSReturn(); |
| 411 | // Do not use the leave instruction here because it is too short to |
| 412 | // patch with the code required by the debugger. |
| 413 | __ mov(esp, ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 414 | int no_frame_start = masm_->pc_offset(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 415 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 416 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 417 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 418 | __ Ret(arguments_bytes, ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 419 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 420 | // Check that the size of the code used for returning is large enough |
| 421 | // for the debugger's requirements. |
| 422 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 423 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 424 | #endif |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 425 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 430 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 431 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 435 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 436 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 437 | codegen()->GetVar(result_register(), var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 441 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 442 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 443 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 444 | // Memory operands can be pushed directly. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 445 | __ push(operand); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 449 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 450 | // For simplicity we always test the accumulator register. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 451 | codegen()->GetVar(result_register(), var); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 452 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 453 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | |
| 457 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 458 | UNREACHABLE(); // Not used on IA32. |
| 459 | } |
| 460 | |
| 461 | |
| 462 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 463 | Heap::RootListIndex index) const { |
| 464 | UNREACHABLE(); // Not used on IA32. |
| 465 | } |
| 466 | |
| 467 | |
| 468 | void FullCodeGenerator::StackValueContext::Plug( |
| 469 | Heap::RootListIndex index) const { |
| 470 | UNREACHABLE(); // Not used on IA32. |
| 471 | } |
| 472 | |
| 473 | |
| 474 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 475 | UNREACHABLE(); // Not used on IA32. |
| 476 | } |
| 477 | |
| 478 | |
| 479 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 480 | } |
| 481 | |
| 482 | |
| 483 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 484 | Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 485 | if (lit->IsSmi()) { |
| 486 | __ SafeSet(result_register(), Immediate(lit)); |
| 487 | } else { |
| 488 | __ Set(result_register(), Immediate(lit)); |
| 489 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | |
| 493 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 494 | if (lit->IsSmi()) { |
| 495 | __ SafePush(Immediate(lit)); |
| 496 | } else { |
| 497 | __ push(Immediate(lit)); |
| 498 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | |
| 502 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 503 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 504 | true, |
| 505 | true_label_, |
| 506 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 507 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 508 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 509 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 510 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 511 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 512 | } else if (lit->IsString()) { |
| 513 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 514 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 515 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 516 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 517 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 518 | } else if (lit->IsSmi()) { |
| 519 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 520 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 521 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 522 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 523 | } |
| 524 | } else { |
| 525 | // For simplicity we always test the accumulator register. |
| 526 | __ mov(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 527 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 532 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 533 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 534 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 535 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 539 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 540 | int count, |
| 541 | Register reg) const { |
| 542 | ASSERT(count > 0); |
| 543 | __ Drop(count); |
| 544 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 548 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 549 | Register reg) const { |
| 550 | ASSERT(count > 0); |
| 551 | if (count > 1) __ Drop(count - 1); |
| 552 | __ mov(Operand(esp, 0), reg); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 557 | Register reg) const { |
| 558 | ASSERT(count > 0); |
| 559 | // For simplicity we always test the accumulator register. |
| 560 | __ Drop(count); |
| 561 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 562 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 563 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
| 567 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 568 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 569 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 570 | __ bind(materialize_true); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 575 | Label* materialize_true, |
| 576 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 577 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 578 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 579 | __ mov(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 580 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 581 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 582 | __ mov(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 583 | __ bind(&done); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void FullCodeGenerator::StackValueContext::Plug( |
| 588 | Label* materialize_true, |
| 589 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 590 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 591 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 592 | __ push(Immediate(isolate()->factory()->true_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 593 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 594 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 595 | __ push(Immediate(isolate()->factory()->false_value())); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 596 | __ bind(&done); |
| 597 | } |
| 598 | |
| 599 | |
| 600 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 601 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 602 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 603 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | |
| 607 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 608 | } |
| 609 | |
| 610 | |
| 611 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | Handle<Object> value = flag |
| 613 | ? isolate()->factory()->true_value() |
| 614 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 615 | __ mov(result_register(), value); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 620 | Handle<Object> value = flag |
| 621 | ? isolate()->factory()->true_value() |
| 622 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 623 | __ push(Immediate(value)); |
| 624 | } |
| 625 | |
| 626 | |
| 627 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 628 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 629 | true, |
| 630 | true_label_, |
| 631 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 632 | if (flag) { |
| 633 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 634 | } else { |
| 635 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
| 639 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 640 | void FullCodeGenerator::DoTest(Expression* condition, |
| 641 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 642 | Label* if_false, |
| 643 | Label* fall_through) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame^] | 644 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
| 645 | CallIC(ic, RelocInfo::CODE_TARGET, condition->test_id()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 646 | __ test(result_register(), result_register()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 647 | // The stub returns nonzero for true. |
| 648 | Split(not_zero, if_true, if_false, fall_through); |
| 649 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 650 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 651 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 652 | void FullCodeGenerator::Split(Condition cc, |
| 653 | Label* if_true, |
| 654 | Label* if_false, |
| 655 | Label* fall_through) { |
| 656 | if (if_false == fall_through) { |
| 657 | __ j(cc, if_true); |
| 658 | } else if (if_true == fall_through) { |
| 659 | __ j(NegateCondition(cc), if_false); |
| 660 | } else { |
| 661 | __ j(cc, if_true); |
| 662 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 663 | } |
| 664 | } |
| 665 | |
| 666 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 667 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 668 | ASSERT(var->IsStackAllocated()); |
| 669 | // Offset is negative because higher indexes are at lower addresses. |
| 670 | int offset = -var->index() * kPointerSize; |
| 671 | // Adjust by a (parameter or local) base offset. |
| 672 | if (var->IsParameter()) { |
| 673 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 674 | } else { |
| 675 | offset += JavaScriptFrameConstants::kLocal0Offset; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 676 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 677 | return Operand(ebp, offset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 681 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 682 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 683 | if (var->IsContextSlot()) { |
| 684 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 685 | __ LoadContext(scratch, context_chain_length); |
| 686 | return ContextOperand(scratch, var->index()); |
| 687 | } else { |
| 688 | return StackOperand(var); |
| 689 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 693 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 694 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 695 | MemOperand location = VarOperand(var, dest); |
| 696 | __ mov(dest, location); |
| 697 | } |
| 698 | |
| 699 | |
| 700 | void FullCodeGenerator::SetVar(Variable* var, |
| 701 | Register src, |
| 702 | Register scratch0, |
| 703 | Register scratch1) { |
| 704 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 705 | ASSERT(!scratch0.is(src)); |
| 706 | ASSERT(!scratch0.is(scratch1)); |
| 707 | ASSERT(!scratch1.is(src)); |
| 708 | MemOperand location = VarOperand(var, scratch0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 709 | __ mov(location, src); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 710 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 711 | // Emit the write barrier code if the location is in the heap. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 712 | if (var->IsContextSlot()) { |
| 713 | int offset = Context::SlotOffset(var->index()); |
| 714 | ASSERT(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 715 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
| 719 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 720 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 721 | bool should_normalize, |
| 722 | Label* if_true, |
| 723 | Label* if_false) { |
| 724 | // Only prepare for bailouts before splits if we're in a test |
| 725 | // context. Otherwise, we let the Visit function deal with the |
| 726 | // preparation to avoid preparing with the same AST id twice. |
| 727 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 728 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 729 | Label skip; |
| 730 | if (should_normalize) __ jmp(&skip, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 731 | PrepareForBailout(expr, TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 732 | if (should_normalize) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 733 | __ cmp(eax, isolate()->factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 734 | Split(equal, if_true, if_false, NULL); |
| 735 | __ bind(&skip); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 740 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 741 | // The variable in the declaration always resides in the current context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 742 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 743 | if (generate_debug_code_) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 744 | // Check that we're not inside a with or catch context. |
| 745 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 746 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
| 747 | __ Check(not_equal, "Declaration in with context."); |
| 748 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
| 749 | __ Check(not_equal, "Declaration in catch context."); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | |
| 754 | void FullCodeGenerator::VisitVariableDeclaration( |
| 755 | VariableDeclaration* declaration) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 756 | // If it was not possible to allocate the variable at compile time, we |
| 757 | // need to "declare" it at runtime to make sure it actually exists in the |
| 758 | // local context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 759 | VariableProxy* proxy = declaration->proxy(); |
| 760 | VariableMode mode = declaration->mode(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 761 | Variable* variable = proxy->var(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 762 | bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 763 | switch (variable->location()) { |
| 764 | case Variable::UNALLOCATED: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 765 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 766 | globals_->Add(variable->binding_needs_init() |
| 767 | ? isolate()->factory()->the_hole_value() |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 768 | : isolate()->factory()->undefined_value(), zone()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case Variable::PARAMETER: |
| 772 | case Variable::LOCAL: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 773 | if (hole_init) { |
| 774 | Comment cmnt(masm_, "[ VariableDeclaration"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 775 | __ mov(StackOperand(variable), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 776 | Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 777 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 778 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 779 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 780 | case Variable::CONTEXT: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 781 | if (hole_init) { |
| 782 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 783 | EmitDebugCheckDeclarationContext(variable); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 784 | __ mov(ContextOperand(esi, variable->index()), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 785 | Immediate(isolate()->factory()->the_hole_value())); |
| 786 | // No write barrier since the hole value is in old space. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 787 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 788 | } |
| 789 | break; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 790 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 791 | case Variable::LOOKUP: { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 792 | Comment cmnt(masm_, "[ VariableDeclaration"); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 793 | __ push(esi); |
| 794 | __ push(Immediate(variable->name())); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 795 | // VariableDeclaration nodes are always introduced in one of four modes. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 796 | ASSERT(IsDeclaredVariableMode(mode)); |
| 797 | PropertyAttributes attr = |
| 798 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 799 | __ push(Immediate(Smi::FromInt(attr))); |
| 800 | // Push initial value, if any. |
| 801 | // Note: For variables we must not push an initial value (such as |
| 802 | // 'undefined') because we may have a (legal) redeclaration and we |
| 803 | // must not destroy the current value. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 804 | if (hole_init) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 805 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 806 | } else { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 807 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 808 | } |
| 809 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 810 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | } |
| 814 | |
| 815 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 816 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 817 | FunctionDeclaration* declaration) { |
| 818 | VariableProxy* proxy = declaration->proxy(); |
| 819 | Variable* variable = proxy->var(); |
| 820 | switch (variable->location()) { |
| 821 | case Variable::UNALLOCATED: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 822 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 823 | Handle<SharedFunctionInfo> function = |
| 824 | Compiler::BuildFunctionInfo(declaration->fun(), script()); |
| 825 | // Check for stack-overflow exception. |
| 826 | if (function.is_null()) return SetStackOverflow(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 827 | globals_->Add(function, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 828 | break; |
| 829 | } |
| 830 | |
| 831 | case Variable::PARAMETER: |
| 832 | case Variable::LOCAL: { |
| 833 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 834 | VisitForAccumulatorValue(declaration->fun()); |
| 835 | __ mov(StackOperand(variable), result_register()); |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | case Variable::CONTEXT: { |
| 840 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 841 | EmitDebugCheckDeclarationContext(variable); |
| 842 | VisitForAccumulatorValue(declaration->fun()); |
| 843 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 844 | // We know that we have written a function, which is not a smi. |
| 845 | __ RecordWriteContextSlot(esi, |
| 846 | Context::SlotOffset(variable->index()), |
| 847 | result_register(), |
| 848 | ecx, |
| 849 | kDontSaveFPRegs, |
| 850 | EMIT_REMEMBERED_SET, |
| 851 | OMIT_SMI_CHECK); |
| 852 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 853 | break; |
| 854 | } |
| 855 | |
| 856 | case Variable::LOOKUP: { |
| 857 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 858 | __ push(esi); |
| 859 | __ push(Immediate(variable->name())); |
| 860 | __ push(Immediate(Smi::FromInt(NONE))); |
| 861 | VisitForStackValue(declaration->fun()); |
| 862 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 863 | break; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | |
| 869 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 870 | Variable* variable = declaration->proxy()->var(); |
| 871 | ASSERT(variable->location() == Variable::CONTEXT); |
| 872 | ASSERT(variable->interface()->IsFrozen()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 873 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 874 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 875 | EmitDebugCheckDeclarationContext(variable); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 876 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 877 | // Load instance object. |
| 878 | __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 879 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 880 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 881 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 882 | // Assign it. |
| 883 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 884 | // We know that we have written a module, which is not a smi. |
| 885 | __ RecordWriteContextSlot(esi, |
| 886 | Context::SlotOffset(variable->index()), |
| 887 | eax, |
| 888 | ecx, |
| 889 | kDontSaveFPRegs, |
| 890 | EMIT_REMEMBERED_SET, |
| 891 | OMIT_SMI_CHECK); |
| 892 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 893 | |
| 894 | // Traverse into body. |
| 895 | Visit(declaration->module()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | |
| 899 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 900 | VariableProxy* proxy = declaration->proxy(); |
| 901 | Variable* variable = proxy->var(); |
| 902 | switch (variable->location()) { |
| 903 | case Variable::UNALLOCATED: |
| 904 | // TODO(rossberg) |
| 905 | break; |
| 906 | |
| 907 | case Variable::CONTEXT: { |
| 908 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 909 | EmitDebugCheckDeclarationContext(variable); |
| 910 | // TODO(rossberg) |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | case Variable::PARAMETER: |
| 915 | case Variable::LOCAL: |
| 916 | case Variable::LOOKUP: |
| 917 | UNREACHABLE(); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | |
| 922 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 923 | // TODO(rossberg) |
| 924 | } |
| 925 | |
| 926 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 927 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 928 | // Call the runtime to declare the globals. |
| 929 | __ push(esi); // The context is the first argument. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 930 | __ Push(pairs); |
| 931 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 932 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 933 | // Return value is ignored. |
| 934 | } |
| 935 | |
| 936 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 937 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 938 | // Call the runtime to declare the modules. |
| 939 | __ Push(descriptions); |
| 940 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 941 | // Return value is ignored. |
| 942 | } |
| 943 | |
| 944 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 945 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 946 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 947 | Breakable nested_statement(this, stmt); |
| 948 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 949 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 950 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 951 | VisitForStackValue(stmt->tag()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 952 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 953 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 954 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 955 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 956 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 957 | Label next_test; // Recycled for each test. |
| 958 | // Compile all the tests with branches to their bodies. |
| 959 | for (int i = 0; i < clauses->length(); i++) { |
| 960 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 961 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 962 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 963 | // The default is not a test, but remember it as final fall through. |
| 964 | if (clause->is_default()) { |
| 965 | default_clause = clause; |
| 966 | continue; |
| 967 | } |
| 968 | |
| 969 | Comment cmnt(masm_, "[ Case comparison"); |
| 970 | __ bind(&next_test); |
| 971 | next_test.Unuse(); |
| 972 | |
| 973 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 974 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 975 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 976 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 977 | __ mov(edx, Operand(esp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 978 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 979 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 980 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 981 | Label slow_case; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 982 | __ mov(ecx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 983 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 984 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 985 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 986 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 987 | __ j(not_equal, &next_test); |
| 988 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 989 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 990 | __ bind(&slow_case); |
| 991 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 992 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 993 | // Record position before stub call for type feedback. |
| 994 | SetSourcePosition(clause->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 995 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 996 | CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 997 | patch_site.EmitPatchInfo(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 998 | __ test(eax, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 999 | __ j(not_equal, &next_test); |
| 1000 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1001 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | // Discard the test value and jump to the default if present, otherwise to |
| 1005 | // the end of the statement. |
| 1006 | __ bind(&next_test); |
| 1007 | __ Drop(1); // Switch value is no longer needed. |
| 1008 | if (default_clause == NULL) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1009 | __ jmp(nested_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1010 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1011 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | // Compile all the case bodies. |
| 1015 | for (int i = 0; i < clauses->length(); i++) { |
| 1016 | Comment cmnt(masm_, "[ Case body"); |
| 1017 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1018 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1019 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1020 | VisitStatements(clause->statements()); |
| 1021 | } |
| 1022 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1023 | __ bind(nested_statement.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1024 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1029 | Comment cmnt(masm_, "[ ForInStatement"); |
| 1030 | SetStatementPosition(stmt); |
| 1031 | |
| 1032 | Label loop, exit; |
| 1033 | ForIn loop_statement(this, stmt); |
| 1034 | increment_loop_depth(); |
| 1035 | |
| 1036 | // Get the object to enumerate over. Both SpiderMonkey and JSC |
| 1037 | // ignore null and undefined in contrast to the specification; see |
| 1038 | // ECMA-262 section 12.6.4. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1039 | VisitForAccumulatorValue(stmt->enumerable()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1040 | __ cmp(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1041 | __ j(equal, &exit); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1042 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1043 | __ j(equal, &exit); |
| 1044 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1045 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1046 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1047 | // Convert the object to a JS object. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1048 | Label convert, done_convert; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1049 | __ JumpIfSmi(eax, &convert, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1050 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1051 | __ j(above_equal, &done_convert, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1052 | __ bind(&convert); |
| 1053 | __ push(eax); |
| 1054 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1055 | __ bind(&done_convert); |
| 1056 | __ push(eax); |
| 1057 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1058 | // Check for proxies. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1059 | Label call_runtime, use_cache, fixed_array; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1060 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1061 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1062 | __ j(below_equal, &call_runtime); |
| 1063 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1064 | // Check cache validity in generated code. This is a fast case for |
| 1065 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1066 | // guarantee cache validity, call the runtime system to check cache |
| 1067 | // validity or get the property names in a fixed array. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1068 | __ CheckEnumCache(&call_runtime); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1069 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1070 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1071 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Get the set of properties to enumerate. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1074 | __ bind(&call_runtime); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1075 | __ push(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1076 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1077 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1078 | isolate()->factory()->meta_map()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1079 | __ j(not_equal, &fixed_array); |
| 1080 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1081 | |
| 1082 | // We got a map in register eax. Get the enumeration cache from it. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1083 | Label no_descriptors; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1084 | __ bind(&use_cache); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1085 | |
| 1086 | __ EnumLength(edx, eax); |
| 1087 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1088 | __ j(equal, &no_descriptors); |
| 1089 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1090 | __ LoadInstanceDescriptors(eax, ecx); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1091 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1092 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1093 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1094 | // Set up the four remaining stack slots. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1095 | __ push(eax); // Map. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1096 | __ push(ecx); // Enumeration cache. |
| 1097 | __ push(edx); // Number of valid entries for the map in the enum cache. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1098 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1099 | __ jmp(&loop); |
| 1100 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1101 | __ bind(&no_descriptors); |
| 1102 | __ add(esp, Immediate(kPointerSize)); |
| 1103 | __ jmp(&exit); |
| 1104 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1105 | // We got a fixed array in register eax. Iterate through that. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1106 | Label non_proxy; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1107 | __ bind(&fixed_array); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1108 | |
| 1109 | Handle<JSGlobalPropertyCell> cell = |
| 1110 | isolate()->factory()->NewJSGlobalPropertyCell( |
| 1111 | Handle<Object>( |
ulan@chromium.org | 09d7ab5 | 2013-02-25 15:50:35 +0000 | [diff] [blame] | 1112 | Smi::FromInt(TypeFeedbackCells::kForInFastCaseMarker), |
| 1113 | isolate())); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1114 | RecordTypeFeedbackCell(stmt->ForInFeedbackId(), cell); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1115 | __ LoadHeapObject(ebx, cell); |
| 1116 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 1117 | Immediate(Smi::FromInt(TypeFeedbackCells::kForInSlowCaseMarker))); |
| 1118 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1119 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1120 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1121 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1122 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1123 | __ j(above, &non_proxy); |
| 1124 | __ mov(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
| 1125 | __ bind(&non_proxy); |
| 1126 | __ push(ebx); // Smi |
| 1127 | __ push(eax); // Array |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1128 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1129 | __ push(eax); // Fixed array length (as smi). |
| 1130 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1131 | |
| 1132 | // Generate code for doing the condition check. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1133 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1134 | __ bind(&loop); |
| 1135 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1136 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1137 | __ j(above_equal, loop_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1138 | |
| 1139 | // Get the current entry of the array into register ebx. |
| 1140 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1141 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1142 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1143 | // Get the expected map from the stack or a smi in the |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1144 | // permanent slow case into register edx. |
| 1145 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1146 | |
| 1147 | // Check if the expected map still matches that of the enumerable. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1148 | // If not, we may have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1149 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1150 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1151 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1152 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1153 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1154 | // For proxies, no filtering is done. |
| 1155 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1156 | ASSERT(Smi::FromInt(0) == 0); |
| 1157 | __ test(edx, edx); |
| 1158 | __ j(zero, &update_each); |
| 1159 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1160 | // Convert the entry to a string or null if it isn't a property |
| 1161 | // anymore. If the property has been removed while iterating, we |
| 1162 | // just skip it. |
| 1163 | __ push(ecx); // Enumerable. |
| 1164 | __ push(ebx); // Current entry. |
| 1165 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1166 | __ test(eax, eax); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1167 | __ j(equal, loop_statement.continue_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1168 | __ mov(ebx, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1169 | |
| 1170 | // Update the 'each' property or variable from the possibly filtered |
| 1171 | // entry in register ebx. |
| 1172 | __ bind(&update_each); |
| 1173 | __ mov(result_register(), ebx); |
| 1174 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1175 | { EffectContext context(this); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1176 | EmitAssignment(stmt->each()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1177 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1180 | Visit(stmt->body()); |
| 1181 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1182 | // Generate code for going to the next element by incrementing the |
| 1183 | // index (smi) stored on top of the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1184 | __ bind(loop_statement.continue_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1185 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1186 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1187 | EmitBackEdgeBookkeeping(stmt, &loop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1188 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1189 | |
| 1190 | // Remove the pointers stored on the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1191 | __ bind(loop_statement.break_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1192 | __ add(esp, Immediate(5 * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1193 | |
| 1194 | // Exit and decrement the loop depth. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1195 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1196 | __ bind(&exit); |
| 1197 | decrement_loop_depth(); |
| 1198 | } |
| 1199 | |
| 1200 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1201 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1202 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1203 | // Use the fast case closure allocation code that allocates in new |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1204 | // space for nested functions that don't need literals cloning. If |
| 1205 | // we're running with the --always-opt or the --prepare-always-opt |
| 1206 | // flag, we need to use the runtime function so that the new function |
| 1207 | // we are creating here gets a chance to have its code optimized and |
| 1208 | // doesn't just get a copy of the existing unoptimized code. |
| 1209 | if (!FLAG_always_opt && |
| 1210 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1211 | !pretenure && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1212 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1213 | info->num_literals() == 0) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1214 | FastNewClosureStub stub(info->language_mode(), info->is_generator()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1215 | __ push(Immediate(info)); |
| 1216 | __ CallStub(&stub); |
| 1217 | } else { |
| 1218 | __ push(esi); |
| 1219 | __ push(Immediate(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1220 | __ push(Immediate(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1221 | ? isolate()->factory()->true_value() |
| 1222 | : isolate()->factory()->false_value())); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1223 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1224 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1225 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| 1228 | |
| 1229 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1230 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1231 | EmitVariableLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1235 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
| 1236 | TypeofState typeof_state, |
| 1237 | Label* slow) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1238 | Register context = esi; |
| 1239 | Register temp = edx; |
| 1240 | |
| 1241 | Scope* s = scope(); |
| 1242 | while (s != NULL) { |
| 1243 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1244 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1245 | // Check that extension is NULL. |
| 1246 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1247 | Immediate(0)); |
| 1248 | __ j(not_equal, slow); |
| 1249 | } |
| 1250 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1251 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1252 | // Walk the rest of the chain without clobbering esi. |
| 1253 | context = temp; |
| 1254 | } |
| 1255 | // If no outer scope calls eval, we do not need to check more |
| 1256 | // context extensions. If we have reached an eval scope, we check |
| 1257 | // all extensions from this point. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1258 | if (!s->outer_scope_calls_non_strict_eval() || s->is_eval_scope()) break; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1259 | s = s->outer_scope(); |
| 1260 | } |
| 1261 | |
| 1262 | if (s != NULL && s->is_eval_scope()) { |
| 1263 | // Loop up the context chain. There is no frame effect so it is |
| 1264 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1265 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1266 | if (!context.is(temp)) { |
| 1267 | __ mov(temp, context); |
| 1268 | } |
| 1269 | __ bind(&next); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1270 | // Terminate at native context. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1271 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1272 | Immediate(isolate()->factory()->native_context_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1273 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1274 | // Check that extension is NULL. |
| 1275 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1276 | __ j(not_equal, slow); |
| 1277 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1278 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1279 | __ jmp(&next); |
| 1280 | __ bind(&fast); |
| 1281 | } |
| 1282 | |
| 1283 | // All extension objects were empty and it is safe to use a global |
| 1284 | // load IC call. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1285 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1286 | __ mov(ecx, var->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1287 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1288 | RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF) |
| 1289 | ? RelocInfo::CODE_TARGET |
| 1290 | : RelocInfo::CODE_TARGET_CONTEXT; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1291 | CallIC(ic, mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1295 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1296 | Label* slow) { |
| 1297 | ASSERT(var->IsContextSlot()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1298 | Register context = esi; |
| 1299 | Register temp = ebx; |
| 1300 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1301 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1302 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1303 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1304 | // Check that extension is NULL. |
| 1305 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1306 | Immediate(0)); |
| 1307 | __ j(not_equal, slow); |
| 1308 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1309 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1310 | // Walk the rest of the chain without clobbering esi. |
| 1311 | context = temp; |
| 1312 | } |
| 1313 | } |
| 1314 | // Check that last extension is NULL. |
| 1315 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1316 | __ j(not_equal, slow); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1317 | |
| 1318 | // This function is used only for loads, not stores, so it's safe to |
| 1319 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1320 | // destroy the esi register). |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1321 | return ContextOperand(context, var->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1325 | void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| 1326 | TypeofState typeof_state, |
| 1327 | Label* slow, |
| 1328 | Label* done) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1329 | // Generate fast-case code for variables that might be shadowed by |
| 1330 | // eval-introduced variables. Eval is used a lot without |
| 1331 | // introducing variables. In those cases, we do not want to |
| 1332 | // perform a runtime call for all variables in the scope |
| 1333 | // containing the eval. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1334 | if (var->mode() == DYNAMIC_GLOBAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1335 | EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1336 | __ jmp(done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1337 | } else if (var->mode() == DYNAMIC_LOCAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1338 | Variable* local = var->local_if_not_shadowed(); |
| 1339 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1340 | if (local->mode() == LET || |
| 1341 | local->mode() == CONST || |
| 1342 | local->mode() == CONST_HARMONY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1343 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1344 | __ j(not_equal, done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1345 | if (local->mode() == CONST) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1346 | __ mov(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1347 | } else { // LET || CONST_HARMONY |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1348 | __ push(Immediate(var->name())); |
| 1349 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1350 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1351 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1352 | __ jmp(done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1357 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1358 | // Record position before possible IC call. |
| 1359 | SetSourcePosition(proxy->position()); |
| 1360 | Variable* var = proxy->var(); |
| 1361 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1362 | // Three cases: global variables, lookup variables, and all other types of |
| 1363 | // variables. |
| 1364 | switch (var->location()) { |
| 1365 | case Variable::UNALLOCATED: { |
| 1366 | Comment cmnt(masm_, "Global variable"); |
| 1367 | // Use inline caching. Variable name is passed in ecx and the global |
| 1368 | // object in eax. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1369 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1370 | __ mov(ecx, var->name()); |
| 1371 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1372 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1373 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1374 | break; |
| 1375 | } |
| 1376 | |
| 1377 | case Variable::PARAMETER: |
| 1378 | case Variable::LOCAL: |
| 1379 | case Variable::CONTEXT: { |
| 1380 | Comment cmnt(masm_, var->IsContextSlot() |
| 1381 | ? "Context variable" |
| 1382 | : "Stack variable"); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1383 | if (var->binding_needs_init()) { |
| 1384 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1385 | // refers to a potential outside binding. Currently those bindings are |
| 1386 | // always looked up dynamically, i.e. in that case |
| 1387 | // var->location() == LOOKUP. |
| 1388 | // always holds. |
| 1389 | ASSERT(var->scope() != NULL); |
| 1390 | |
| 1391 | // Check if the binding really needs an initialization check. The check |
| 1392 | // can be skipped in the following situation: we have a LET or CONST |
| 1393 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1394 | // the same declaration scope (i.e. they are both in global code, in the |
| 1395 | // same function or in the same eval code) and the VariableProxy is in |
| 1396 | // the source physically located after the initializer of the variable. |
| 1397 | // |
| 1398 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1399 | // mode because const variables may be declared but never initialized: |
| 1400 | // if (false) { const x; }; var y = x; |
| 1401 | // |
| 1402 | // The condition on the declaration scopes is a conservative check for |
| 1403 | // nested functions that access a binding and are called before the |
| 1404 | // binding is initialized: |
| 1405 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1406 | // |
| 1407 | bool skip_init_check; |
| 1408 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1409 | skip_init_check = false; |
jkummerow@chromium.org | ac45fed | 2011-11-07 13:11:02 +0000 | [diff] [blame] | 1410 | } else { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1411 | // Check that we always have valid source position. |
| 1412 | ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1413 | ASSERT(proxy->position() != RelocInfo::kNoPosition); |
| 1414 | skip_init_check = var->mode() != CONST && |
| 1415 | var->initializer_position() < proxy->position(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1416 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1417 | |
| 1418 | if (!skip_init_check) { |
| 1419 | // Let and const need a read barrier. |
| 1420 | Label done; |
| 1421 | GetVar(eax, var); |
| 1422 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1423 | __ j(not_equal, &done, Label::kNear); |
| 1424 | if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1425 | // Throw a reference error when using an uninitialized let/const |
| 1426 | // binding in harmony mode. |
| 1427 | __ push(Immediate(var->name())); |
| 1428 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1429 | } else { |
| 1430 | // Uninitalized const bindings outside of harmony mode are unholed. |
| 1431 | ASSERT(var->mode() == CONST); |
| 1432 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1433 | } |
| 1434 | __ bind(&done); |
| 1435 | context()->Plug(eax); |
| 1436 | break; |
| 1437 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1438 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1439 | context()->Plug(var); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1440 | break; |
| 1441 | } |
| 1442 | |
| 1443 | case Variable::LOOKUP: { |
| 1444 | Label done, slow; |
| 1445 | // Generate code for loading from variables potentially shadowed |
| 1446 | // by eval-introduced variables. |
| 1447 | EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1448 | __ bind(&slow); |
| 1449 | Comment cmnt(masm_, "Lookup variable"); |
| 1450 | __ push(esi); // Context. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1451 | __ push(Immediate(var->name())); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1452 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1453 | __ bind(&done); |
| 1454 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1455 | break; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1456 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | |
| 1461 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1462 | Comment cmnt(masm_, "[ RegExpLiteral"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1463 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1464 | // Registers will be used as follows: |
| 1465 | // edi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1466 | // ecx = literals array. |
| 1467 | // ebx = regexp literal. |
| 1468 | // eax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1469 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1470 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1471 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1472 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1473 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1474 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1475 | __ j(not_equal, &materialized, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1476 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1477 | // Create regexp literal using runtime function |
| 1478 | // Result will be in eax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1479 | __ push(ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1480 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1481 | __ push(Immediate(expr->pattern())); |
| 1482 | __ push(Immediate(expr->flags())); |
| 1483 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1484 | __ mov(ebx, eax); |
| 1485 | |
| 1486 | __ bind(&materialized); |
| 1487 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1488 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1489 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1490 | __ jmp(&allocated); |
| 1491 | |
| 1492 | __ bind(&runtime_allocate); |
| 1493 | __ push(ebx); |
| 1494 | __ push(Immediate(Smi::FromInt(size))); |
| 1495 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1496 | __ pop(ebx); |
| 1497 | |
| 1498 | __ bind(&allocated); |
| 1499 | // Copy the content into the newly allocated memory. |
| 1500 | // (Unroll copy loop once for better throughput). |
| 1501 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1502 | __ mov(edx, FieldOperand(ebx, i)); |
| 1503 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1504 | __ mov(FieldOperand(eax, i), edx); |
| 1505 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1506 | } |
| 1507 | if ((size % (2 * kPointerSize)) != 0) { |
| 1508 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1509 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1510 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1511 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1515 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1516 | if (expression == NULL) { |
| 1517 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1518 | } else { |
| 1519 | VisitForStackValue(expression); |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1524 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1525 | Comment cmnt(masm_, "[ ObjectLiteral"); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1526 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1527 | int flags = expr->fast_elements() |
| 1528 | ? ObjectLiteral::kFastElements |
| 1529 | : ObjectLiteral::kNoFlags; |
| 1530 | flags |= expr->has_function() |
| 1531 | ? ObjectLiteral::kHasFunction |
| 1532 | : ObjectLiteral::kNoFlags; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1533 | int properties_count = constant_properties->length() / 2; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1534 | if ((FLAG_track_double_fields && expr->may_store_doubles()) || |
| 1535 | expr->depth() > 1) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1536 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1537 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1538 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1539 | __ push(Immediate(constant_properties)); |
| 1540 | __ push(Immediate(Smi::FromInt(flags))); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1541 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1542 | } else if (Serializer::enabled() || flags != ObjectLiteral::kFastElements || |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1543 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1544 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1545 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1546 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1547 | __ push(Immediate(constant_properties)); |
| 1548 | __ push(Immediate(Smi::FromInt(flags))); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1549 | __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1550 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1551 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1552 | __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1553 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1554 | __ mov(ecx, Immediate(constant_properties)); |
| 1555 | __ mov(edx, Immediate(Smi::FromInt(flags))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1556 | FastCloneShallowObjectStub stub(properties_count); |
| 1557 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | // If result_saved is true the result is on top of the stack. If |
| 1561 | // result_saved is false the result is in eax. |
| 1562 | bool result_saved = false; |
| 1563 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1564 | // Mark all computed expressions that are bound to a key that |
| 1565 | // is shadowed by a later occurrence of the same key. For the |
| 1566 | // marked expressions, no store code is emitted. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1567 | expr->CalculateEmitStore(zone()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1568 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1569 | AccessorTable accessor_table(zone()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1570 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1571 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1572 | if (property->IsCompileTimeValue()) continue; |
| 1573 | |
| 1574 | Literal* key = property->key(); |
| 1575 | Expression* value = property->value(); |
| 1576 | if (!result_saved) { |
| 1577 | __ push(eax); // Save result on the stack |
| 1578 | result_saved = true; |
| 1579 | } |
| 1580 | switch (property->kind()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1581 | case ObjectLiteral::Property::CONSTANT: |
| 1582 | UNREACHABLE(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1583 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1584 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1585 | // Fall through. |
| 1586 | case ObjectLiteral::Property::COMPUTED: |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1587 | if (key->handle()->IsInternalizedString()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1588 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1589 | VisitForAccumulatorValue(value); |
| 1590 | __ mov(ecx, Immediate(key->handle())); |
| 1591 | __ mov(edx, Operand(esp, 0)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1592 | Handle<Code> ic = is_classic_mode() |
| 1593 | ? isolate()->builtins()->StoreIC_Initialize() |
| 1594 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1595 | CallIC(ic, RelocInfo::CODE_TARGET, key->LiteralFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1596 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1597 | } else { |
| 1598 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1599 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1602 | __ push(Operand(esp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1603 | VisitForStackValue(key); |
| 1604 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1605 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1606 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1607 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1608 | } else { |
| 1609 | __ Drop(3); |
| 1610 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1611 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1612 | case ObjectLiteral::Property::PROTOTYPE: |
| 1613 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1614 | VisitForStackValue(value); |
| 1615 | if (property->emit_store()) { |
| 1616 | __ CallRuntime(Runtime::kSetPrototype, 2); |
| 1617 | } else { |
| 1618 | __ Drop(2); |
| 1619 | } |
| 1620 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1621 | case ObjectLiteral::Property::GETTER: |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1622 | accessor_table.lookup(key)->second->getter = value; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1623 | break; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1624 | case ObjectLiteral::Property::SETTER: |
| 1625 | accessor_table.lookup(key)->second->setter = value; |
| 1626 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1627 | } |
| 1628 | } |
| 1629 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1630 | // Emit code to define accessors, using only a single call to the runtime for |
| 1631 | // each pair of corresponding getters and setters. |
| 1632 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1633 | it != accessor_table.end(); |
| 1634 | ++it) { |
| 1635 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1636 | VisitForStackValue(it->first); |
| 1637 | EmitAccessor(it->second->getter); |
| 1638 | EmitAccessor(it->second->setter); |
| 1639 | __ push(Immediate(Smi::FromInt(NONE))); |
| 1640 | __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1641 | } |
| 1642 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1643 | if (expr->has_function()) { |
| 1644 | ASSERT(result_saved); |
| 1645 | __ push(Operand(esp, 0)); |
| 1646 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1647 | } |
| 1648 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1649 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1650 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1651 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1652 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | |
| 1657 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1658 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1659 | |
| 1660 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1661 | int length = subexprs->length(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1662 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1663 | ASSERT_EQ(2, constant_elements->length()); |
| 1664 | ElementsKind constant_elements_kind = |
| 1665 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1666 | bool has_constant_fast_elements = |
| 1667 | IsFastObjectElementsKind(constant_elements_kind); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1668 | Handle<FixedArrayBase> constant_elements_values( |
| 1669 | FixedArrayBase::cast(constant_elements->get(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1670 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1671 | Heap* heap = isolate()->heap(); |
| 1672 | if (has_constant_fast_elements && |
| 1673 | constant_elements_values->map() == heap->fixed_cow_array_map()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1674 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1675 | // change, so it's possible to specialize the stub in advance. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1676 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1677 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1678 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1679 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1680 | __ mov(ecx, Immediate(constant_elements)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1681 | FastCloneShallowArrayStub stub( |
| 1682 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1683 | DONT_TRACK_ALLOCATION_SITE, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1684 | length); |
| 1685 | __ CallStub(&stub); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1686 | } else if (expr->depth() > 1) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1687 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1688 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1689 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1690 | __ push(Immediate(constant_elements)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1691 | __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1692 | } else if (Serializer::enabled() || |
| 1693 | length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
| 1694 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1695 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1696 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1697 | __ push(Immediate(constant_elements)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1698 | __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1699 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1700 | ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1701 | FLAG_smi_only_arrays); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1702 | FastCloneShallowArrayStub::Mode mode = |
| 1703 | FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
| 1704 | AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites |
| 1705 | ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE; |
| 1706 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1707 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1708 | // change, so it's possible to specialize the stub in advance. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1709 | if (has_constant_fast_elements) { |
| 1710 | mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 1711 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1714 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1715 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1716 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1717 | __ mov(ecx, Immediate(constant_elements)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1718 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1719 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | bool result_saved = false; // Is the result saved to the stack? |
| 1723 | |
| 1724 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1725 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1726 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1727 | Expression* subexpr = subexprs->at(i); |
| 1728 | // If the subexpression is a literal or a simple materialized literal it |
| 1729 | // is already set in the cloned array. |
| 1730 | if (subexpr->AsLiteral() != NULL || |
| 1731 | CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1732 | continue; |
| 1733 | } |
| 1734 | |
| 1735 | if (!result_saved) { |
| 1736 | __ push(eax); |
| 1737 | result_saved = true; |
| 1738 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1739 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1740 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1741 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1742 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1743 | // cannot transition and don't need to call the runtime stub. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1744 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1745 | __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1746 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1747 | // Store the subexpression value in the array's elements. |
| 1748 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1749 | // Update the write barrier for the array store. |
| 1750 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1751 | kDontSaveFPRegs, |
| 1752 | EMIT_REMEMBERED_SET, |
| 1753 | INLINE_SMI_CHECK); |
| 1754 | } else { |
| 1755 | // Store the subexpression value in the array's elements. |
| 1756 | __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1757 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 1758 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
| 1759 | __ mov(edx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1760 | StoreArrayLiteralElementStub stub; |
| 1761 | __ CallStub(&stub); |
| 1762 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | |
| 1764 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1768 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1769 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1770 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1775 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1776 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1777 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1778 | // on the left-hand side. |
| 1779 | if (!expr->target()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1780 | VisitForEffect(expr->target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1781 | return; |
| 1782 | } |
| 1783 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1784 | // Left-hand side can only be a property, a global or a (parameter or local) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1785 | // slot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1786 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1787 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1788 | Property* property = expr->target()->AsProperty(); |
| 1789 | if (property != NULL) { |
| 1790 | assign_type = (property->key()->IsPropertyName()) |
| 1791 | ? NAMED_PROPERTY |
| 1792 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | // Evaluate LHS expression. |
| 1796 | switch (assign_type) { |
| 1797 | case VARIABLE: |
| 1798 | // Nothing to do here. |
| 1799 | break; |
| 1800 | case NAMED_PROPERTY: |
| 1801 | if (expr->is_compound()) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1802 | // We need the receiver both on the stack and in edx. |
| 1803 | VisitForStackValue(property->obj()); |
| 1804 | __ mov(edx, Operand(esp, 0)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1805 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1806 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1807 | } |
| 1808 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | case KEYED_PROPERTY: { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1810 | if (expr->is_compound()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1811 | VisitForStackValue(property->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1812 | VisitForStackValue(property->key()); |
| 1813 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 1814 | __ mov(ecx, Operand(esp, 0)); // Key. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1815 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1816 | VisitForStackValue(property->obj()); |
| 1817 | VisitForStackValue(property->key()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1818 | } |
| 1819 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1820 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1823 | // For compound assignments we need another deoptimization point after the |
| 1824 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1825 | if (expr->is_compound()) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1826 | AccumulatorValueContext result_context(this); |
| 1827 | { AccumulatorValueContext left_operand_context(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1828 | switch (assign_type) { |
| 1829 | case VARIABLE: |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1830 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1831 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1832 | break; |
| 1833 | case NAMED_PROPERTY: |
| 1834 | EmitNamedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1835 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1836 | break; |
| 1837 | case KEYED_PROPERTY: |
| 1838 | EmitKeyedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1839 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1840 | break; |
| 1841 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1842 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1843 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1844 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1845 | __ push(eax); // Left operand goes on the stack. |
| 1846 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1847 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1848 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1849 | ? OVERWRITE_RIGHT |
| 1850 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1851 | SetSourcePosition(expr->position() + 1); |
| 1852 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1853 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1854 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1855 | mode, |
| 1856 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1857 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1858 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1859 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1860 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1861 | |
| 1862 | // Deoptimization point in case the binary operation may have side effects. |
| 1863 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1864 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1865 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | // Record source position before possible IC call. |
| 1869 | SetSourcePosition(expr->position()); |
| 1870 | |
| 1871 | // Store the value. |
| 1872 | switch (assign_type) { |
| 1873 | case VARIABLE: |
| 1874 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1875 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1876 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1877 | context()->Plug(eax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1878 | break; |
| 1879 | case NAMED_PROPERTY: |
| 1880 | EmitNamedPropertyAssignment(expr); |
| 1881 | break; |
| 1882 | case KEYED_PROPERTY: |
| 1883 | EmitKeyedPropertyAssignment(expr); |
| 1884 | break; |
| 1885 | } |
| 1886 | } |
| 1887 | |
| 1888 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1889 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1890 | Comment cmnt(masm_, "[ Yield"); |
| 1891 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1892 | // this. It stays on the stack while we update the iterator. |
| 1893 | VisitForStackValue(expr->expression()); |
| 1894 | |
| 1895 | switch (expr->yield_kind()) { |
| 1896 | case Yield::INITIAL: |
| 1897 | case Yield::SUSPEND: { |
| 1898 | VisitForStackValue(expr->generator_object()); |
| 1899 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1900 | __ mov(context_register(), |
| 1901 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 1902 | |
| 1903 | Label resume; |
| 1904 | __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex); |
| 1905 | __ j(not_equal, &resume); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1906 | if (expr->yield_kind() == Yield::SUSPEND) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1907 | EmitReturnIteratorResult(false); |
| 1908 | } else { |
| 1909 | __ pop(result_register()); |
| 1910 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1911 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1912 | |
| 1913 | __ bind(&resume); |
| 1914 | context()->Plug(result_register()); |
| 1915 | break; |
| 1916 | } |
| 1917 | |
| 1918 | case Yield::FINAL: { |
| 1919 | VisitForAccumulatorValue(expr->generator_object()); |
| 1920 | __ mov(FieldOperand(result_register(), |
| 1921 | JSGeneratorObject::kContinuationOffset), |
| 1922 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1923 | EmitReturnIteratorResult(true); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1924 | break; |
| 1925 | } |
| 1926 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1927 | case Yield::DELEGATING: { |
| 1928 | VisitForStackValue(expr->generator_object()); |
| 1929 | |
| 1930 | // Initial stack layout is as follows: |
| 1931 | // [sp + 1 * kPointerSize] iter |
| 1932 | // [sp + 0 * kPointerSize] g |
| 1933 | |
| 1934 | Label l_catch, l_try, l_resume, l_send, l_call, l_loop; |
| 1935 | // Initial send value is undefined. |
| 1936 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1937 | __ jmp(&l_send); |
| 1938 | |
| 1939 | // catch (e) { receiver = iter; f = iter.throw; arg = e; goto l_call; } |
| 1940 | __ bind(&l_catch); |
| 1941 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
| 1942 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // iter |
| 1943 | __ push(edx); // iter |
| 1944 | __ push(eax); // exception |
| 1945 | __ mov(ecx, isolate()->factory()->throw_string()); // "throw" |
| 1946 | Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 1947 | CallIC(throw_ic); // iter.throw in eax |
| 1948 | __ jmp(&l_call); |
| 1949 | |
| 1950 | // try { received = yield result.value } |
| 1951 | __ bind(&l_try); |
| 1952 | __ pop(eax); // result.value |
| 1953 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 1954 | const int handler_size = StackHandlerConstants::kSize; |
| 1955 | __ push(eax); // result.value |
| 1956 | __ push(Operand(esp, (0 + 1) * kPointerSize + handler_size)); // g |
| 1957 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1958 | __ mov(context_register(), |
| 1959 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 1960 | __ CompareRoot(eax, Heap::kTheHoleValueRootIndex); |
| 1961 | __ j(not_equal, &l_resume); |
| 1962 | EmitReturnIteratorResult(false); |
| 1963 | __ bind(&l_resume); // received in eax |
| 1964 | __ PopTryHandler(); |
| 1965 | |
| 1966 | // receiver = iter; f = iter.send; arg = received; |
| 1967 | __ bind(&l_send); |
| 1968 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // iter |
| 1969 | __ push(edx); // iter |
| 1970 | __ push(eax); // received |
| 1971 | __ mov(ecx, isolate()->factory()->send_string()); // "send" |
| 1972 | Handle<Code> send_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 1973 | CallIC(send_ic); // iter.send in eax |
| 1974 | |
| 1975 | // result = f.call(receiver, arg); |
| 1976 | __ bind(&l_call); |
| 1977 | Label l_call_runtime; |
| 1978 | __ JumpIfSmi(eax, &l_call_runtime); |
| 1979 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 1980 | __ j(not_equal, &l_call_runtime); |
| 1981 | __ mov(edi, eax); |
| 1982 | ParameterCount count(1); |
| 1983 | __ InvokeFunction(edi, count, CALL_FUNCTION, |
| 1984 | NullCallWrapper(), CALL_AS_METHOD); |
| 1985 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 1986 | __ jmp(&l_loop); |
| 1987 | __ bind(&l_call_runtime); |
| 1988 | __ push(eax); |
| 1989 | __ CallRuntime(Runtime::kCall, 3); |
| 1990 | |
| 1991 | // val = result.value; if (!result.done) goto l_try; |
| 1992 | __ bind(&l_loop); |
| 1993 | // result.value |
| 1994 | __ push(eax); // save result |
| 1995 | __ mov(edx, eax); // result |
| 1996 | __ mov(ecx, isolate()->factory()->value_string()); // "value" |
| 1997 | Handle<Code> value_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 1998 | CallIC(value_ic); // result.value in eax |
| 1999 | __ pop(ebx); // result |
| 2000 | __ push(eax); // result.value |
| 2001 | __ mov(edx, ebx); // result |
| 2002 | __ mov(ecx, isolate()->factory()->done_string()); // "done" |
| 2003 | Handle<Code> done_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2004 | CallIC(done_ic); // result.done in eax |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame^] | 2005 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2006 | CallIC(bool_ic); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2007 | __ test(eax, eax); |
| 2008 | __ j(zero, &l_try); |
| 2009 | |
| 2010 | // result.value |
| 2011 | __ pop(eax); // result.value |
| 2012 | context()->DropAndPlug(2, eax); // drop iter and g |
| 2013 | break; |
| 2014 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2019 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2020 | Expression *value, |
| 2021 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2022 | // The value stays in eax, and is ultimately read by the resumed generator, as |
| 2023 | // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. ebx |
| 2024 | // will hold the generator object until the activation has been resumed. |
| 2025 | VisitForStackValue(generator); |
| 2026 | VisitForAccumulatorValue(value); |
| 2027 | __ pop(ebx); |
| 2028 | |
| 2029 | // Check generator state. |
| 2030 | Label wrong_state, done; |
| 2031 | STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); |
| 2032 | STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); |
| 2033 | __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2034 | Immediate(Smi::FromInt(0))); |
| 2035 | __ j(less_equal, &wrong_state); |
| 2036 | |
| 2037 | // Load suspended function and context. |
| 2038 | __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 2039 | __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 2040 | |
| 2041 | // Push receiver. |
| 2042 | __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
| 2043 | |
| 2044 | // Push holes for arguments to generator function. |
| 2045 | __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2046 | __ mov(edx, |
| 2047 | FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 2048 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 2049 | Label push_argument_holes, push_frame; |
| 2050 | __ bind(&push_argument_holes); |
| 2051 | __ sub(edx, Immediate(1)); |
| 2052 | __ j(carry, &push_frame); |
| 2053 | __ push(ecx); |
| 2054 | __ jmp(&push_argument_holes); |
| 2055 | |
| 2056 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2057 | // the generator was suspended. |
| 2058 | Label resume_frame; |
| 2059 | __ bind(&push_frame); |
| 2060 | __ call(&resume_frame); |
| 2061 | __ jmp(&done); |
| 2062 | __ bind(&resume_frame); |
| 2063 | __ push(ebp); // Caller's frame pointer. |
| 2064 | __ mov(ebp, esp); |
| 2065 | __ push(esi); // Callee's context. |
| 2066 | __ push(edi); // Callee's JS Function. |
| 2067 | |
| 2068 | // Load the operand stack size. |
| 2069 | __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 2070 | __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 2071 | __ SmiUntag(edx); |
| 2072 | |
| 2073 | // If we are sending a value and there is no operand stack, we can jump back |
| 2074 | // in directly. |
| 2075 | if (resume_mode == JSGeneratorObject::SEND) { |
| 2076 | Label slow_resume; |
| 2077 | __ cmp(edx, Immediate(0)); |
| 2078 | __ j(not_zero, &slow_resume); |
| 2079 | __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2080 | __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 2081 | __ SmiUntag(ecx); |
| 2082 | __ add(edx, ecx); |
| 2083 | __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2084 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2085 | __ jmp(edx); |
| 2086 | __ bind(&slow_resume); |
| 2087 | } |
| 2088 | |
| 2089 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2090 | // up the stack and the handlers. |
| 2091 | Label push_operand_holes, call_resume; |
| 2092 | __ bind(&push_operand_holes); |
| 2093 | __ sub(edx, Immediate(1)); |
| 2094 | __ j(carry, &call_resume); |
| 2095 | __ push(ecx); |
| 2096 | __ jmp(&push_operand_holes); |
| 2097 | __ bind(&call_resume); |
| 2098 | __ push(ebx); |
| 2099 | __ push(result_register()); |
| 2100 | __ Push(Smi::FromInt(resume_mode)); |
| 2101 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2102 | // Not reached: the runtime call returns elsewhere. |
| 2103 | __ Abort("Generator failed to resume."); |
| 2104 | |
| 2105 | // Throw error if we attempt to operate on a running generator. |
| 2106 | __ bind(&wrong_state); |
| 2107 | __ push(ebx); |
| 2108 | __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
| 2109 | |
| 2110 | __ bind(&done); |
| 2111 | context()->Plug(result_register()); |
| 2112 | } |
| 2113 | |
| 2114 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2115 | void FullCodeGenerator::EmitReturnIteratorResult(bool done) { |
| 2116 | Label gc_required; |
| 2117 | Label allocated; |
| 2118 | |
| 2119 | Handle<Map> map(isolate()->native_context()->generator_result_map()); |
| 2120 | |
| 2121 | __ Allocate(map->instance_size(), eax, ecx, edx, &gc_required, TAG_OBJECT); |
| 2122 | |
| 2123 | __ bind(&allocated); |
| 2124 | __ mov(ebx, map); |
| 2125 | __ pop(ecx); |
| 2126 | __ mov(edx, isolate()->factory()->ToBoolean(done)); |
| 2127 | ASSERT_EQ(map->instance_size(), 5 * kPointerSize); |
| 2128 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2129 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2130 | isolate()->factory()->empty_fixed_array()); |
| 2131 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2132 | isolate()->factory()->empty_fixed_array()); |
| 2133 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2134 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2135 | |
| 2136 | // Only the value field needs a write barrier, as the other values are in the |
| 2137 | // root set. |
| 2138 | __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2139 | ecx, edx, kDontSaveFPRegs); |
| 2140 | |
| 2141 | if (done) { |
| 2142 | // Exit all nested statements. |
| 2143 | NestedStatement* current = nesting_stack_; |
| 2144 | int stack_depth = 0; |
| 2145 | int context_length = 0; |
| 2146 | while (current != NULL) { |
| 2147 | current = current->Exit(&stack_depth, &context_length); |
| 2148 | } |
| 2149 | __ Drop(stack_depth); |
| 2150 | } |
| 2151 | |
| 2152 | EmitReturnSequence(); |
| 2153 | |
| 2154 | __ bind(&gc_required); |
| 2155 | __ Push(Smi::FromInt(map->instance_size())); |
| 2156 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2157 | __ mov(context_register(), |
| 2158 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2159 | __ jmp(&allocated); |
| 2160 | } |
| 2161 | |
| 2162 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2163 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 2164 | SetSourcePosition(prop->position()); |
| 2165 | Literal* key = prop->key()->AsLiteral(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2166 | ASSERT(!key->handle()->IsSmi()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2167 | __ mov(ecx, Immediate(key->handle())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2168 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2169 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 2174 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2175 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2176 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2180 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2181 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2182 | OverwriteMode mode, |
| 2183 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2184 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2185 | // Do combined smi check of the operands. Left operand is on the |
| 2186 | // stack. Right operand is in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2187 | Label smi_case, done, stub_call; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2188 | __ pop(edx); |
| 2189 | __ mov(ecx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2190 | __ or_(eax, edx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2191 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2192 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2193 | |
| 2194 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2195 | __ mov(eax, ecx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2196 | BinaryOpStub stub(op, mode); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2197 | CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2198 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2199 | patch_site.EmitPatchInfo(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2200 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2201 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2202 | // Smi case. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2203 | __ bind(&smi_case); |
| 2204 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 2205 | |
| 2206 | switch (op) { |
| 2207 | case Token::SAR: |
| 2208 | __ SmiUntag(eax); |
| 2209 | __ SmiUntag(ecx); |
| 2210 | __ sar_cl(eax); // No checks of result necessary |
| 2211 | __ SmiTag(eax); |
| 2212 | break; |
| 2213 | case Token::SHL: { |
| 2214 | Label result_ok; |
| 2215 | __ SmiUntag(eax); |
| 2216 | __ SmiUntag(ecx); |
| 2217 | __ shl_cl(eax); |
| 2218 | // Check that the *signed* result fits in a smi. |
| 2219 | __ cmp(eax, 0xc0000000); |
| 2220 | __ j(positive, &result_ok); |
| 2221 | __ SmiTag(ecx); |
| 2222 | __ jmp(&stub_call); |
| 2223 | __ bind(&result_ok); |
| 2224 | __ SmiTag(eax); |
| 2225 | break; |
| 2226 | } |
| 2227 | case Token::SHR: { |
| 2228 | Label result_ok; |
| 2229 | __ SmiUntag(eax); |
| 2230 | __ SmiUntag(ecx); |
| 2231 | __ shr_cl(eax); |
| 2232 | __ test(eax, Immediate(0xc0000000)); |
| 2233 | __ j(zero, &result_ok); |
| 2234 | __ SmiTag(ecx); |
| 2235 | __ jmp(&stub_call); |
| 2236 | __ bind(&result_ok); |
| 2237 | __ SmiTag(eax); |
| 2238 | break; |
| 2239 | } |
| 2240 | case Token::ADD: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2241 | __ add(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2242 | __ j(overflow, &stub_call); |
| 2243 | break; |
| 2244 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2245 | __ sub(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2246 | __ j(overflow, &stub_call); |
| 2247 | break; |
| 2248 | case Token::MUL: { |
| 2249 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2250 | __ imul(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2251 | __ j(overflow, &stub_call); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2252 | __ test(eax, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2253 | __ j(not_zero, &done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2254 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2255 | __ or_(ebx, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2256 | __ j(negative, &stub_call); |
| 2257 | break; |
| 2258 | } |
| 2259 | case Token::BIT_OR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2260 | __ or_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2261 | break; |
| 2262 | case Token::BIT_AND: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2263 | __ and_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2264 | break; |
| 2265 | case Token::BIT_XOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2266 | __ xor_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2267 | break; |
| 2268 | default: |
| 2269 | UNREACHABLE(); |
| 2270 | } |
| 2271 | |
| 2272 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2273 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2277 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2278 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2279 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | __ pop(edx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2281 | BinaryOpStub stub(op, mode); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2282 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2283 | CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2284 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2285 | patch_site.EmitPatchInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2286 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2290 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2291 | // Invalid left-hand sides are rewritten by the parser to have a 'throw |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2292 | // ReferenceError' on the left-hand side. |
| 2293 | if (!expr->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2294 | VisitForEffect(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2295 | return; |
| 2296 | } |
| 2297 | |
| 2298 | // Left-hand side can only be a property, a global or a (parameter or local) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2299 | // slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2300 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2301 | LhsKind assign_type = VARIABLE; |
| 2302 | Property* prop = expr->AsProperty(); |
| 2303 | if (prop != NULL) { |
| 2304 | assign_type = (prop->key()->IsPropertyName()) |
| 2305 | ? NAMED_PROPERTY |
| 2306 | : KEYED_PROPERTY; |
| 2307 | } |
| 2308 | |
| 2309 | switch (assign_type) { |
| 2310 | case VARIABLE: { |
| 2311 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2312 | EffectContext context(this); |
| 2313 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2314 | break; |
| 2315 | } |
| 2316 | case NAMED_PROPERTY: { |
| 2317 | __ push(eax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2318 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2319 | __ mov(edx, eax); |
| 2320 | __ pop(eax); // Restore value. |
| 2321 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2322 | Handle<Code> ic = is_classic_mode() |
| 2323 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2324 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2325 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2326 | break; |
| 2327 | } |
| 2328 | case KEYED_PROPERTY: { |
| 2329 | __ push(eax); // Preserve value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2330 | VisitForStackValue(prop->obj()); |
| 2331 | VisitForAccumulatorValue(prop->key()); |
| 2332 | __ mov(ecx, eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2333 | __ pop(edx); // Receiver. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2334 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2335 | Handle<Code> ic = is_classic_mode() |
| 2336 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2337 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2338 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2339 | break; |
| 2340 | } |
| 2341 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2342 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2346 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2347 | Token::Value op) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2348 | if (var->IsUnallocated()) { |
| 2349 | // Global var, const, or let. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2350 | __ mov(ecx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2351 | __ mov(edx, GlobalObjectOperand()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2352 | Handle<Code> ic = is_classic_mode() |
| 2353 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2354 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2355 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2356 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2357 | } else if (op == Token::INIT_CONST) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2358 | // Const initializers need a write barrier. |
| 2359 | ASSERT(!var->IsParameter()); // No const parameters. |
| 2360 | if (var->IsStackLocal()) { |
| 2361 | Label skip; |
| 2362 | __ mov(edx, StackOperand(var)); |
| 2363 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2364 | __ j(not_equal, &skip); |
| 2365 | __ mov(StackOperand(var), eax); |
| 2366 | __ bind(&skip); |
| 2367 | } else { |
| 2368 | ASSERT(var->IsContextSlot() || var->IsLookupSlot()); |
| 2369 | // Like var declarations, const declarations are hoisted to function |
| 2370 | // scope. However, unlike var initializers, const initializers are |
| 2371 | // able to drill a hole to that function context, even from inside a |
| 2372 | // 'with' context. We thus bypass the normal static scope lookup for |
| 2373 | // var->IsContextSlot(). |
| 2374 | __ push(eax); |
| 2375 | __ push(esi); |
| 2376 | __ push(Immediate(var->name())); |
| 2377 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2378 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2379 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2380 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2381 | // Non-initializing assignment to let variable needs a write barrier. |
| 2382 | if (var->IsLookupSlot()) { |
| 2383 | __ push(eax); // Value. |
| 2384 | __ push(esi); // Context. |
| 2385 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2386 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2387 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
| 2388 | } else { |
| 2389 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 2390 | Label assign; |
| 2391 | MemOperand location = VarOperand(var, ecx); |
| 2392 | __ mov(edx, location); |
| 2393 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2394 | __ j(not_equal, &assign, Label::kNear); |
| 2395 | __ push(Immediate(var->name())); |
| 2396 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2397 | __ bind(&assign); |
| 2398 | __ mov(location, eax); |
| 2399 | if (var->IsContextSlot()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2400 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2401 | int offset = Context::SlotOffset(var->index()); |
| 2402 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2403 | } |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2404 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2405 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2406 | } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
| 2407 | // Assignment to var or initializing assignment to let/const |
| 2408 | // in harmony mode. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2409 | if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 2410 | MemOperand location = VarOperand(var, ecx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2411 | if (generate_debug_code_ && op == Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2412 | // Check for an uninitialized let binding. |
| 2413 | __ mov(edx, location); |
| 2414 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2415 | __ Check(equal, "Let binding re-initialization."); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2416 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2417 | // Perform the assignment. |
| 2418 | __ mov(location, eax); |
| 2419 | if (var->IsContextSlot()) { |
| 2420 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2421 | int offset = Context::SlotOffset(var->index()); |
| 2422 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2423 | } |
| 2424 | } else { |
| 2425 | ASSERT(var->IsLookupSlot()); |
| 2426 | __ push(eax); // Value. |
| 2427 | __ push(esi); // Context. |
| 2428 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2429 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2430 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2431 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2432 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2433 | // Non-initializing assignments to consts are ignored. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
| 2436 | |
| 2437 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2438 | // Assignment to a property, using a named store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2439 | // eax : value |
| 2440 | // esp[0] : receiver |
| 2441 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2442 | Property* prop = expr->target()->AsProperty(); |
| 2443 | ASSERT(prop != NULL); |
| 2444 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2445 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2446 | // Record source code position before IC call. |
| 2447 | SetSourcePosition(expr->position()); |
| 2448 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2449 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2450 | Handle<Code> ic = is_classic_mode() |
| 2451 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2452 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2453 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2454 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2455 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2456 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | |
| 2460 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2461 | // Assignment to a property, using a keyed store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2462 | // eax : value |
| 2463 | // esp[0] : key |
| 2464 | // esp[kPointerSize] : receiver |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2465 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2466 | __ pop(ecx); // Key. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2467 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2468 | // Record source code position before IC call. |
| 2469 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2470 | Handle<Code> ic = is_classic_mode() |
| 2471 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2472 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2473 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2474 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2475 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2476 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2477 | } |
| 2478 | |
| 2479 | |
| 2480 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2481 | Comment cmnt(masm_, "[ Property"); |
| 2482 | Expression* key = expr->key(); |
| 2483 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2484 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2485 | VisitForAccumulatorValue(expr->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2486 | __ mov(edx, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2487 | EmitNamedPropertyLoad(expr); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2488 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2489 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2490 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2491 | VisitForStackValue(expr->obj()); |
| 2492 | VisitForAccumulatorValue(expr->key()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2493 | __ pop(edx); // Object. |
| 2494 | __ mov(ecx, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2495 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2496 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | |
| 2500 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2501 | void FullCodeGenerator::CallIC(Handle<Code> code, |
| 2502 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2503 | TypeFeedbackId ast_id) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2504 | ic_total_count_++; |
| 2505 | __ call(code, rmode, ast_id); |
| 2506 | } |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2511 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
| 2512 | Handle<Object> name, |
| 2513 | RelocInfo::Mode mode) { |
| 2514 | // Code common for calls using the IC. |
| 2515 | ZoneList<Expression*>* args = expr->arguments(); |
| 2516 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2517 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2518 | for (int i = 0; i < arg_count; i++) { |
| 2519 | VisitForStackValue(args->at(i)); |
| 2520 | } |
| 2521 | __ Set(ecx, Immediate(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2522 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2523 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2524 | SetSourcePosition(expr->position()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2525 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2526 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2527 | CallIC(ic, mode, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2528 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2529 | // Restore context register. |
| 2530 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2531 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2535 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2536 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2537 | // Load the key. |
| 2538 | VisitForAccumulatorValue(key); |
| 2539 | |
| 2540 | // Swap the name of the function and the receiver on the stack to follow |
| 2541 | // the calling convention for call ICs. |
| 2542 | __ pop(ecx); |
| 2543 | __ push(eax); |
| 2544 | __ push(ecx); |
| 2545 | |
| 2546 | // Load the arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2547 | ZoneList<Expression*>* args = expr->arguments(); |
| 2548 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2549 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2550 | for (int i = 0; i < arg_count; i++) { |
| 2551 | VisitForStackValue(args->at(i)); |
| 2552 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2553 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2554 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2555 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2556 | Handle<Code> ic = |
| 2557 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2558 | __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2559 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2560 | RecordJSReturnSite(expr); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2561 | // Restore context register. |
| 2562 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2563 | context()->DropAndPlug(1, eax); // Drop the key still on the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2567 | void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2568 | // Code common for calls using the call stub. |
| 2569 | ZoneList<Expression*>* args = expr->arguments(); |
| 2570 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2571 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2572 | for (int i = 0; i < arg_count; i++) { |
| 2573 | VisitForStackValue(args->at(i)); |
| 2574 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2575 | } |
| 2576 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2577 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2578 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2579 | // Record call targets in unoptimized code. |
| 2580 | flags = static_cast<CallFunctionFlags>(flags | RECORD_CALL_TARGET); |
| 2581 | Handle<Object> uninitialized = |
| 2582 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
| 2583 | Handle<JSGlobalPropertyCell> cell = |
| 2584 | isolate()->factory()->NewJSGlobalPropertyCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2585 | RecordTypeFeedbackCell(expr->CallFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2586 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2587 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2588 | CallFunctionStub stub(arg_count, flags); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2589 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2590 | __ CallStub(&stub, expr->CallFeedbackId()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2591 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2592 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2593 | // Restore context register. |
| 2594 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2595 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
| 2598 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2599 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2600 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2601 | if (arg_count > 0) { |
| 2602 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2603 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2604 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | // Push the receiver of the enclosing function. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2608 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2609 | // Push the language mode. |
| 2610 | __ push(Immediate(Smi::FromInt(language_mode()))); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2611 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2612 | // Push the start position of the scope the calls resides in. |
| 2613 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
| 2614 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2615 | // Do the runtime call. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2616 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2620 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2621 | #ifdef DEBUG |
| 2622 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2623 | // through this function. Avoid early returns. |
| 2624 | expr->return_is_recorded_ = false; |
| 2625 | #endif |
| 2626 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2627 | Comment cmnt(masm_, "[ Call"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2628 | Expression* callee = expr->expression(); |
| 2629 | VariableProxy* proxy = callee->AsVariableProxy(); |
| 2630 | Property* property = callee->AsProperty(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2631 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2632 | if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2633 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2634 | // resolve the function we need to call and the receiver of the call. |
| 2635 | // Then we call the resolved function using the given arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2636 | ZoneList<Expression*>* args = expr->arguments(); |
| 2637 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2638 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2639 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2640 | // Reserved receiver slot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2641 | __ push(Immediate(isolate()->factory()->undefined_value())); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2642 | // Push the arguments. |
| 2643 | for (int i = 0; i < arg_count; i++) { |
| 2644 | VisitForStackValue(args->at(i)); |
| 2645 | } |
| 2646 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2647 | // Push a copy of the function (found below the arguments) and |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2648 | // resolve eval. |
| 2649 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2650 | EmitResolvePossiblyDirectEval(arg_count); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2651 | |
| 2652 | // The runtime call returns a pair of values in eax (function) and |
| 2653 | // edx (receiver). Touch up the stack with the right values. |
| 2654 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2655 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2656 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2657 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2658 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2659 | CallFunctionStub stub(arg_count, RECEIVER_MIGHT_BE_IMPLICIT); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2660 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2661 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2662 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2663 | // Restore context register. |
| 2664 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2665 | context()->DropAndPlug(1, eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2666 | |
| 2667 | } else if (proxy != NULL && proxy->var()->IsUnallocated()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2668 | // Push global object as receiver for the call IC. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2669 | __ push(GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2670 | EmitCallWithIC(expr, proxy->name(), RelocInfo::CODE_TARGET_CONTEXT); |
| 2671 | |
| 2672 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2673 | // Call to a lookup slot (dynamically introduced variable). |
| 2674 | Label slow, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2675 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2676 | // Generate code for loading from variables potentially shadowed by |
| 2677 | // eval-introduced variables. |
| 2678 | EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2679 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2680 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2681 | // Call the runtime to find the function to call (returned in eax) and |
| 2682 | // the object holding it (returned in edx). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2683 | __ push(context_register()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2684 | __ push(Immediate(proxy->name())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2685 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2686 | __ push(eax); // Function. |
| 2687 | __ push(edx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2688 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2689 | // If fast case code has been generated, emit code to push the function |
| 2690 | // and receiver and have the slow path jump around this code. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2691 | if (done.is_linked()) { |
| 2692 | Label call; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2693 | __ jmp(&call, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2694 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2695 | // Push function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2696 | __ push(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2697 | // The receiver is implicitly the global receiver. Indicate this by |
| 2698 | // passing the hole to the call function stub. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2699 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2700 | __ bind(&call); |
| 2701 | } |
| 2702 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2703 | // The receiver is either the global receiver or an object found by |
| 2704 | // LoadContextSlot. That object could be the hole if the receiver is |
| 2705 | // implicitly the global object. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2706 | EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2707 | |
| 2708 | } else if (property != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2709 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2710 | VisitForStackValue(property->obj()); |
| 2711 | } |
| 2712 | if (property->key()->IsPropertyName()) { |
| 2713 | EmitCallWithIC(expr, |
| 2714 | property->key()->AsLiteral()->handle(), |
| 2715 | RelocInfo::CODE_TARGET); |
| 2716 | } else { |
| 2717 | EmitKeyedCallWithIC(expr, property->key()); |
| 2718 | } |
| 2719 | |
| 2720 | } else { |
| 2721 | // Call to an arbitrary expression not handled specially above. |
| 2722 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2723 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2724 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2725 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2726 | __ mov(ebx, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2727 | __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
| 2728 | // Emit function call. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2729 | EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2730 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2731 | |
| 2732 | #ifdef DEBUG |
| 2733 | // RecordJSReturnSite should have been called. |
| 2734 | ASSERT(expr->return_is_recorded_); |
| 2735 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | |
| 2739 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2740 | Comment cmnt(masm_, "[ CallNew"); |
| 2741 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2742 | // expression in new calls must be evaluated before the |
| 2743 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2744 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2745 | // Push constructor on the stack. If it's not a function it's used as |
| 2746 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2747 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2748 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2749 | |
| 2750 | // Push the arguments ("left-to-right") on the stack. |
| 2751 | ZoneList<Expression*>* args = expr->arguments(); |
| 2752 | int arg_count = args->length(); |
| 2753 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2754 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | // Call the construct call builtin that handles allocation and |
| 2758 | // constructor invocation. |
| 2759 | SetSourcePosition(expr->position()); |
| 2760 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2761 | // Load function and argument count into edi and eax. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2762 | __ Set(eax, Immediate(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2763 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2764 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2765 | // Record call targets in unoptimized code. |
| 2766 | Handle<Object> uninitialized = |
| 2767 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
| 2768 | Handle<JSGlobalPropertyCell> cell = |
| 2769 | isolate()->factory()->NewJSGlobalPropertyCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2770 | RecordTypeFeedbackCell(expr->CallNewFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2771 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2772 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2773 | CallConstructStub stub(RECORD_CALL_TARGET); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2774 | __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2775 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2776 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2780 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2781 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2782 | ASSERT(args->length() == 1); |
| 2783 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2784 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2785 | |
| 2786 | Label materialize_true, materialize_false; |
| 2787 | Label* if_true = NULL; |
| 2788 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2789 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2790 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2791 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2792 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2793 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2794 | __ test(eax, Immediate(kSmiTagMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2795 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2796 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2797 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2801 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2802 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2803 | ASSERT(args->length() == 1); |
| 2804 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2805 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2806 | |
| 2807 | Label materialize_true, materialize_false; |
| 2808 | Label* if_true = NULL; |
| 2809 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2810 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2811 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2812 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2813 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2814 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2815 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2816 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2817 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2818 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2822 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2823 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2824 | ASSERT(args->length() == 1); |
| 2825 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2826 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2827 | |
| 2828 | Label materialize_true, materialize_false; |
| 2829 | Label* if_true = NULL; |
| 2830 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2831 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2832 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2833 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2834 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2835 | __ JumpIfSmi(eax, if_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2836 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2837 | __ j(equal, if_true); |
| 2838 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2839 | // Undetectable objects behave like undefined when tested with typeof. |
| 2840 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2841 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 2842 | __ j(not_zero, if_false); |
| 2843 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2844 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2845 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2846 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2847 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2848 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2849 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2850 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2854 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2855 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2856 | ASSERT(args->length() == 1); |
| 2857 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2858 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2859 | |
| 2860 | Label materialize_true, materialize_false; |
| 2861 | Label* if_true = NULL; |
| 2862 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2863 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2864 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2865 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2866 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2867 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2868 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2869 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2871 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2872 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2876 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2877 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2878 | ASSERT(args->length() == 1); |
| 2879 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2880 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2881 | |
| 2882 | Label materialize_true, materialize_false; |
| 2883 | Label* if_true = NULL; |
| 2884 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2885 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2886 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2887 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2888 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2889 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2890 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2891 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2892 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2893 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2894 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2895 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2896 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2900 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2901 | CallRuntime* expr) { |
| 2902 | ZoneList<Expression*>* args = expr->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2903 | ASSERT(args->length() == 1); |
| 2904 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2905 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2906 | |
| 2907 | Label materialize_true, materialize_false; |
| 2908 | Label* if_true = NULL; |
| 2909 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2910 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2911 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2912 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2913 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2914 | __ AssertNotSmi(eax); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2915 | |
| 2916 | // Check whether this map has already been checked to be safe for default |
| 2917 | // valueOf. |
| 2918 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2919 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 2920 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 2921 | __ j(not_zero, if_true); |
| 2922 | |
| 2923 | // Check for fast case object. Return false for slow case objects. |
| 2924 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 2925 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 2926 | __ cmp(ecx, FACTORY->hash_table_map()); |
| 2927 | __ j(equal, if_false); |
| 2928 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2929 | // Look for valueOf string in the descriptor array, and indicate false if |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2930 | // found. Since we omit an enumeration index check, if it is added via a |
| 2931 | // transition that shares its descriptor array, this is a false positive. |
| 2932 | Label entry, loop, done; |
| 2933 | |
| 2934 | // Skip loop if no descriptors are valid. |
| 2935 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 2936 | __ cmp(ecx, 0); |
| 2937 | __ j(equal, &done); |
| 2938 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2939 | __ LoadInstanceDescriptors(ebx, ebx); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2940 | // ebx: descriptor array. |
| 2941 | // ecx: valid entries in the descriptor array. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2942 | // Calculate the end of the descriptor array. |
| 2943 | STATIC_ASSERT(kSmiTag == 0); |
| 2944 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2945 | STATIC_ASSERT(kPointerSize == 4); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2946 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 2947 | __ lea(ecx, Operand(ebx, ecx, times_2, DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2948 | // Calculate location of the first key name. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2949 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2950 | // Loop through all the keys in the descriptor array. If one of these is the |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2951 | // internalized string "valueOf" the result is false. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2952 | __ jmp(&entry); |
| 2953 | __ bind(&loop); |
| 2954 | __ mov(edx, FieldOperand(ebx, 0)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2955 | __ cmp(edx, FACTORY->value_of_string()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2956 | __ j(equal, if_false); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2957 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2958 | __ bind(&entry); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2959 | __ cmp(ebx, ecx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2960 | __ j(not_equal, &loop); |
| 2961 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2962 | __ bind(&done); |
| 2963 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2964 | // Reload map as register ebx was used as temporary above. |
| 2965 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2966 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2967 | // If a valueOf property is not found on the object check that its |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2968 | // prototype is the un-modified String prototype. If not result is false. |
| 2969 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2970 | __ JumpIfSmi(ecx, if_false); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2971 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2972 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2973 | __ mov(edx, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2974 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2975 | __ cmp(ecx, |
| 2976 | ContextOperand(edx, |
| 2977 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 2978 | __ j(not_equal, if_false); |
| 2979 | // Set the bit in the map to indicate that it has been checked safe for |
| 2980 | // default valueOf and set true result. |
| 2981 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 2982 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 2983 | __ jmp(if_true); |
| 2984 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2985 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2986 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2990 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 2991 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2992 | ASSERT(args->length() == 1); |
| 2993 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2994 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2995 | |
| 2996 | Label materialize_true, materialize_false; |
| 2997 | Label* if_true = NULL; |
| 2998 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2999 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3000 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3001 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3002 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3003 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3004 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3005 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3006 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3007 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3008 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3012 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3013 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3014 | ASSERT(args->length() == 1); |
| 3015 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3016 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3017 | |
| 3018 | Label materialize_true, materialize_false; |
| 3019 | Label* if_true = NULL; |
| 3020 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3021 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3022 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3023 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3024 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3025 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3026 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3027 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3028 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3029 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3030 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3031 | } |
| 3032 | |
| 3033 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3034 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3035 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3036 | ASSERT(args->length() == 1); |
| 3037 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3038 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3039 | |
| 3040 | Label materialize_true, materialize_false; |
| 3041 | Label* if_true = NULL; |
| 3042 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3043 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3044 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3045 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3046 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3047 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3048 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3049 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3050 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3051 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3052 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | |
| 3056 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3057 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 3058 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3059 | |
| 3060 | Label materialize_true, materialize_false; |
| 3061 | Label* if_true = NULL; |
| 3062 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3063 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3064 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3065 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3066 | |
| 3067 | // Get the frame pointer for the calling frame. |
| 3068 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3069 | |
| 3070 | // Skip the arguments adaptor frame if it exists. |
| 3071 | Label check_frame_marker; |
| 3072 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 3073 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3074 | __ j(not_equal, &check_frame_marker); |
| 3075 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 3076 | |
| 3077 | // Check the marker in the calling frame. |
| 3078 | __ bind(&check_frame_marker); |
| 3079 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 3080 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3081 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3082 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3083 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3084 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3088 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3089 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3090 | ASSERT(args->length() == 2); |
| 3091 | |
| 3092 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3093 | VisitForStackValue(args->at(0)); |
| 3094 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3095 | |
| 3096 | Label materialize_true, materialize_false; |
| 3097 | Label* if_true = NULL; |
| 3098 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3099 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3100 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3101 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3102 | |
| 3103 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3104 | __ cmp(eax, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3105 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3106 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3107 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3108 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3112 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3113 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3114 | ASSERT(args->length() == 1); |
| 3115 | |
| 3116 | // ArgumentsAccessStub expects the key in edx and the formal |
| 3117 | // parameter count in eax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3118 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3119 | __ mov(edx, eax); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3120 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3121 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 3122 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3123 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3127 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 3128 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3129 | |
| 3130 | Label exit; |
| 3131 | // Get the number of formal parameters. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3132 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3133 | |
| 3134 | // Check if the calling frame is an arguments adaptor frame. |
| 3135 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3136 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 3137 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3138 | __ j(not_equal, &exit); |
| 3139 | |
| 3140 | // Arguments adaptor case: Read the arguments length from the |
| 3141 | // adaptor frame. |
| 3142 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3143 | |
| 3144 | __ bind(&exit); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3145 | __ AssertSmi(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3146 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3150 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3151 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3152 | ASSERT(args->length() == 1); |
| 3153 | Label done, null, function, non_function_constructor; |
| 3154 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3155 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3156 | |
| 3157 | // If the object is a smi, we return null. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3158 | __ JumpIfSmi(eax, &null); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3159 | |
| 3160 | // Check that the object is a JS object but take special care of JS |
| 3161 | // functions to make sure they have 'Function' as their class. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3162 | // Assume that there are only two callable types, and one of them is at |
| 3163 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3164 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3165 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 3166 | // Map is now in eax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3167 | __ j(below, &null); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3168 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3169 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3170 | __ j(equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3171 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3172 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 3173 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3174 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3175 | __ j(equal, &function); |
| 3176 | // Assume that there is no larger type. |
| 3177 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3178 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3179 | // Check if the constructor in the map is a JS function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3180 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 3181 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3182 | __ j(not_equal, &non_function_constructor); |
| 3183 | |
| 3184 | // eax now contains the constructor function. Grab the |
| 3185 | // instance class name from there. |
| 3186 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3187 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3188 | __ jmp(&done); |
| 3189 | |
| 3190 | // Functions have class 'Function'. |
| 3191 | __ bind(&function); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3192 | __ mov(eax, isolate()->factory()->function_class_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3193 | __ jmp(&done); |
| 3194 | |
| 3195 | // Objects with a non-function constructor have class 'Object'. |
| 3196 | __ bind(&non_function_constructor); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3197 | __ mov(eax, isolate()->factory()->Object_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3198 | __ jmp(&done); |
| 3199 | |
| 3200 | // Non-JS objects have class null. |
| 3201 | __ bind(&null); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3202 | __ mov(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3203 | |
| 3204 | // All done. |
| 3205 | __ bind(&done); |
| 3206 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3207 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3211 | void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3212 | // Conditionally generate a log call. |
| 3213 | // Args: |
| 3214 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 3215 | // This is used to determine whether or not to generate the log call. |
| 3216 | // 1 (string): Format string. Access the string at argument index 2 |
| 3217 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 3218 | // 2 (array): Arguments to the format string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3219 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3220 | ASSERT_EQ(args->length(), 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3221 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3222 | VisitForStackValue(args->at(1)); |
| 3223 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3224 | __ CallRuntime(Runtime::kLog, 2); |
| 3225 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3226 | // Finally, we're expected to leave a value on the top of the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3227 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3228 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3232 | void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) { |
| 3233 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3234 | |
| 3235 | Label slow_allocate_heapnumber; |
| 3236 | Label heapnumber_allocated; |
| 3237 | |
| 3238 | __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber); |
| 3239 | __ jmp(&heapnumber_allocated); |
| 3240 | |
| 3241 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3242 | // Allocate a heap number. |
| 3243 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3244 | __ mov(edi, eax); |
| 3245 | |
| 3246 | __ bind(&heapnumber_allocated); |
| 3247 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3248 | __ PrepareCallCFunction(1, ebx); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3249 | __ mov(eax, ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX)); |
| 3250 | __ mov(eax, FieldOperand(eax, GlobalObject::kNativeContextOffset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3251 | __ mov(Operand(esp, 0), eax); |
| 3252 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3253 | |
| 3254 | // Convert 32 random bits in eax to 0.(32 random bits) in a double |
| 3255 | // by computing: |
| 3256 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 3257 | // This is implemented on both SSE2 and FPU. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3258 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3259 | CpuFeatureScope fscope(masm(), SSE2); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3260 | __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3261 | __ movd(xmm1, ebx); |
| 3262 | __ movd(xmm0, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3263 | __ cvtss2sd(xmm1, xmm1); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 3264 | __ xorps(xmm0, xmm1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3265 | __ subsd(xmm0, xmm1); |
| 3266 | __ movdbl(FieldOperand(edi, HeapNumber::kValueOffset), xmm0); |
| 3267 | } else { |
| 3268 | // 0x4130000000000000 is 1.0 x 2^20 as a double. |
| 3269 | __ mov(FieldOperand(edi, HeapNumber::kExponentOffset), |
| 3270 | Immediate(0x41300000)); |
| 3271 | __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax); |
| 3272 | __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 3273 | __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0)); |
| 3274 | __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 3275 | __ fsubp(1); |
| 3276 | __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 3277 | } |
| 3278 | __ mov(eax, edi); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3279 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3283 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3284 | // Load the arguments on the stack and call the stub. |
| 3285 | SubStringStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3286 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3287 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3288 | VisitForStackValue(args->at(0)); |
| 3289 | VisitForStackValue(args->at(1)); |
| 3290 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3291 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3292 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3293 | } |
| 3294 | |
| 3295 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3296 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3297 | // Load the arguments on the stack and call the stub. |
| 3298 | RegExpExecStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3299 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3300 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3301 | VisitForStackValue(args->at(0)); |
| 3302 | VisitForStackValue(args->at(1)); |
| 3303 | VisitForStackValue(args->at(2)); |
| 3304 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3305 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3306 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3310 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3311 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3312 | ASSERT(args->length() == 1); |
| 3313 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3314 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3315 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3316 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3317 | // If the object is a smi return the object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3318 | __ JumpIfSmi(eax, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3319 | // If the object is not a value type, return the object. |
| 3320 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3321 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3322 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3323 | |
| 3324 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3325 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3329 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3330 | ZoneList<Expression*>* args = expr->arguments(); |
| 3331 | ASSERT(args->length() == 2); |
| 3332 | ASSERT_NE(NULL, args->at(1)->AsLiteral()); |
| 3333 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->handle())); |
| 3334 | |
| 3335 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3336 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3337 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3338 | Register object = eax; |
| 3339 | Register result = eax; |
| 3340 | Register scratch = ecx; |
| 3341 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3342 | __ JumpIfSmi(object, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3343 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3344 | __ j(not_equal, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3345 | |
| 3346 | if (index->value() == 0) { |
| 3347 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3348 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3349 | } else { |
| 3350 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3351 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3352 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3353 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3354 | __ j(not_equal, &runtime, Label::kNear); |
| 3355 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3356 | kPointerSize * index->value())); |
| 3357 | __ jmp(&done); |
| 3358 | } |
| 3359 | __ bind(&runtime); |
| 3360 | __ PrepareCallCFunction(2, scratch); |
| 3361 | __ mov(Operand(esp, 0), object); |
| 3362 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3363 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3364 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3365 | } |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3366 | |
| 3367 | __ bind(¬_date_object); |
| 3368 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3369 | __ bind(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3370 | context()->Plug(result); |
| 3371 | } |
| 3372 | |
| 3373 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3374 | void FullCodeGenerator::EmitSeqStringSetCharCheck(Register string, |
| 3375 | Register index, |
| 3376 | Register value, |
| 3377 | uint32_t encoding_mask) { |
| 3378 | __ test(index, Immediate(kSmiTagMask)); |
| 3379 | __ Check(zero, "Non-smi index"); |
| 3380 | __ test(value, Immediate(kSmiTagMask)); |
| 3381 | __ Check(zero, "Non-smi value"); |
| 3382 | |
| 3383 | __ cmp(index, FieldOperand(string, String::kLengthOffset)); |
| 3384 | __ Check(less, "Index is too large"); |
| 3385 | |
| 3386 | __ cmp(index, Immediate(Smi::FromInt(0))); |
| 3387 | __ Check(greater_equal, "Index is negative"); |
| 3388 | |
| 3389 | __ push(value); |
| 3390 | __ mov(value, FieldOperand(string, HeapObject::kMapOffset)); |
| 3391 | __ movzx_b(value, FieldOperand(value, Map::kInstanceTypeOffset)); |
| 3392 | |
| 3393 | __ and_(value, Immediate(kStringRepresentationMask | kStringEncodingMask)); |
| 3394 | __ cmp(value, Immediate(encoding_mask)); |
| 3395 | __ Check(equal, "Unexpected string type"); |
| 3396 | __ pop(value); |
| 3397 | } |
| 3398 | |
| 3399 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3400 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3401 | ZoneList<Expression*>* args = expr->arguments(); |
| 3402 | ASSERT_EQ(3, args->length()); |
| 3403 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3404 | Register string = eax; |
| 3405 | Register index = ebx; |
| 3406 | Register value = ecx; |
| 3407 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3408 | VisitForStackValue(args->at(1)); // index |
| 3409 | VisitForStackValue(args->at(2)); // value |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3410 | __ pop(value); |
| 3411 | __ pop(index); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3412 | VisitForAccumulatorValue(args->at(0)); // string |
| 3413 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3414 | |
| 3415 | if (FLAG_debug_code) { |
| 3416 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3417 | EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3418 | } |
| 3419 | |
| 3420 | __ SmiUntag(value); |
| 3421 | __ SmiUntag(index); |
| 3422 | __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3423 | value); |
| 3424 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | |
| 3428 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3429 | ZoneList<Expression*>* args = expr->arguments(); |
| 3430 | ASSERT_EQ(3, args->length()); |
| 3431 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3432 | Register string = eax; |
| 3433 | Register index = ebx; |
| 3434 | Register value = ecx; |
| 3435 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3436 | VisitForStackValue(args->at(1)); // index |
| 3437 | VisitForStackValue(args->at(2)); // value |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3438 | __ pop(value); |
| 3439 | __ pop(index); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3440 | VisitForAccumulatorValue(args->at(0)); // string |
| 3441 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3442 | if (FLAG_debug_code) { |
| 3443 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
| 3444 | EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3445 | } |
| 3446 | |
| 3447 | __ SmiUntag(value); |
| 3448 | // No need to untag a smi for two-byte addressing. |
| 3449 | __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), |
| 3450 | value); |
| 3451 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3455 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3456 | // Load the arguments on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3457 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3458 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3459 | VisitForStackValue(args->at(0)); |
| 3460 | VisitForStackValue(args->at(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3461 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3462 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3463 | MathPowStub stub(MathPowStub::ON_STACK); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3464 | __ CallStub(&stub); |
| 3465 | } else { |
| 3466 | __ CallRuntime(Runtime::kMath_pow, 2); |
| 3467 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3468 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3472 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3473 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3474 | ASSERT(args->length() == 2); |
| 3475 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3476 | VisitForStackValue(args->at(0)); // Load the object. |
| 3477 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3478 | __ pop(ebx); // eax = value. ebx = object. |
| 3479 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3480 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3481 | // If the object is a smi, return the value. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3482 | __ JumpIfSmi(ebx, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3483 | |
| 3484 | // If the object is not a value type, return the value. |
| 3485 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3486 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3487 | |
| 3488 | // Store the value. |
| 3489 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3490 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3491 | // Update the write barrier. Save the value as it will be |
| 3492 | // overwritten by the write barrier code and is needed afterward. |
| 3493 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3494 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3495 | |
| 3496 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3497 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3498 | } |
| 3499 | |
| 3500 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3501 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3502 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3503 | ASSERT_EQ(args->length(), 1); |
| 3504 | |
| 3505 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3506 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3507 | |
| 3508 | NumberToStringStub stub; |
| 3509 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3510 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3514 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3515 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3516 | ASSERT(args->length() == 1); |
| 3517 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3518 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3519 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3520 | Label done; |
| 3521 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3522 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3523 | __ jmp(&done); |
| 3524 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3525 | NopRuntimeCallHelper call_helper; |
| 3526 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3527 | |
| 3528 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3529 | context()->Plug(ebx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3533 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3534 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3535 | ASSERT(args->length() == 2); |
| 3536 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3537 | VisitForStackValue(args->at(0)); |
| 3538 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3539 | |
| 3540 | Register object = ebx; |
| 3541 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3542 | Register result = edx; |
| 3543 | |
| 3544 | __ pop(object); |
| 3545 | |
| 3546 | Label need_conversion; |
| 3547 | Label index_out_of_range; |
| 3548 | Label done; |
| 3549 | StringCharCodeAtGenerator generator(object, |
| 3550 | index, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3551 | result, |
| 3552 | &need_conversion, |
| 3553 | &need_conversion, |
| 3554 | &index_out_of_range, |
| 3555 | STRING_INDEX_IS_NUMBER); |
| 3556 | generator.GenerateFast(masm_); |
| 3557 | __ jmp(&done); |
| 3558 | |
| 3559 | __ bind(&index_out_of_range); |
| 3560 | // When the index is out of range, the spec requires us to return |
| 3561 | // NaN. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3562 | __ Set(result, Immediate(isolate()->factory()->nan_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3563 | __ jmp(&done); |
| 3564 | |
| 3565 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3566 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3567 | // trigger conversion. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3568 | __ Set(result, Immediate(isolate()->factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3569 | __ jmp(&done); |
| 3570 | |
| 3571 | NopRuntimeCallHelper call_helper; |
| 3572 | generator.GenerateSlow(masm_, call_helper); |
| 3573 | |
| 3574 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3575 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3578 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3579 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3580 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3581 | ASSERT(args->length() == 2); |
| 3582 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3583 | VisitForStackValue(args->at(0)); |
| 3584 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3585 | |
| 3586 | Register object = ebx; |
| 3587 | Register index = eax; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3588 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3589 | Register result = eax; |
| 3590 | |
| 3591 | __ pop(object); |
| 3592 | |
| 3593 | Label need_conversion; |
| 3594 | Label index_out_of_range; |
| 3595 | Label done; |
| 3596 | StringCharAtGenerator generator(object, |
| 3597 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3598 | scratch, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3599 | result, |
| 3600 | &need_conversion, |
| 3601 | &need_conversion, |
| 3602 | &index_out_of_range, |
| 3603 | STRING_INDEX_IS_NUMBER); |
| 3604 | generator.GenerateFast(masm_); |
| 3605 | __ jmp(&done); |
| 3606 | |
| 3607 | __ bind(&index_out_of_range); |
| 3608 | // When the index is out of range, the spec requires us to return |
| 3609 | // the empty string. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3610 | __ Set(result, Immediate(isolate()->factory()->empty_string())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3611 | __ jmp(&done); |
| 3612 | |
| 3613 | __ bind(&need_conversion); |
| 3614 | // Move smi zero into the result register, which will trigger |
| 3615 | // conversion. |
| 3616 | __ Set(result, Immediate(Smi::FromInt(0))); |
| 3617 | __ jmp(&done); |
| 3618 | |
| 3619 | NopRuntimeCallHelper call_helper; |
| 3620 | generator.GenerateSlow(masm_, call_helper); |
| 3621 | |
| 3622 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3623 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3627 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3628 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3629 | ASSERT_EQ(2, args->length()); |
| 3630 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3631 | VisitForStackValue(args->at(0)); |
| 3632 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3633 | |
| 3634 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 3635 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3636 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3640 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3641 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3642 | ASSERT_EQ(2, args->length()); |
| 3643 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3644 | VisitForStackValue(args->at(0)); |
| 3645 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3646 | |
| 3647 | StringCompareStub stub; |
| 3648 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3649 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
| 3652 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3653 | void FullCodeGenerator::EmitMathSin(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3654 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3655 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 3656 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3657 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3658 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3659 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3660 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3661 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3665 | void FullCodeGenerator::EmitMathCos(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3666 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3667 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 3668 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3669 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3670 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3671 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3672 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3673 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3677 | void FullCodeGenerator::EmitMathTan(CallRuntime* expr) { |
| 3678 | // Load the argument on the stack and call the stub. |
| 3679 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 3680 | TranscendentalCacheStub::TAGGED); |
| 3681 | ZoneList<Expression*>* args = expr->arguments(); |
| 3682 | ASSERT(args->length() == 1); |
| 3683 | VisitForStackValue(args->at(0)); |
| 3684 | __ CallStub(&stub); |
| 3685 | context()->Plug(eax); |
| 3686 | } |
| 3687 | |
| 3688 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3689 | void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3690 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3691 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 3692 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3693 | ZoneList<Expression*>* args = expr->arguments(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3694 | ASSERT(args->length() == 1); |
| 3695 | VisitForStackValue(args->at(0)); |
| 3696 | __ CallStub(&stub); |
| 3697 | context()->Plug(eax); |
| 3698 | } |
| 3699 | |
| 3700 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3701 | void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3702 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3703 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3704 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3705 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3706 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3707 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3711 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3712 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3713 | ASSERT(args->length() >= 2); |
| 3714 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3715 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3716 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3717 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3718 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3719 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3720 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3721 | Label runtime, done; |
| 3722 | // Check for non-function argument (including proxy). |
| 3723 | __ JumpIfSmi(eax, &runtime); |
| 3724 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3725 | __ j(not_equal, &runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3726 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3727 | // InvokeFunction requires the function in edi. Move it in there. |
| 3728 | __ mov(edi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3729 | ParameterCount count(arg_count); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3730 | __ InvokeFunction(edi, count, CALL_FUNCTION, |
| 3731 | NullCallWrapper(), CALL_AS_METHOD); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3732 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3733 | __ jmp(&done); |
| 3734 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3735 | __ bind(&runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3736 | __ push(eax); |
| 3737 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3738 | __ bind(&done); |
| 3739 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3740 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3744 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3745 | // Load the arguments on the stack and call the stub. |
| 3746 | RegExpConstructResultStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3747 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3748 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3749 | VisitForStackValue(args->at(0)); |
| 3750 | VisitForStackValue(args->at(1)); |
| 3751 | VisitForStackValue(args->at(2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3752 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3753 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3754 | } |
| 3755 | |
| 3756 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3757 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3758 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3759 | ASSERT_EQ(2, args->length()); |
| 3760 | |
| 3761 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 3762 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 3763 | |
| 3764 | Handle<FixedArray> jsfunction_result_caches( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3765 | isolate()->native_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3766 | if (jsfunction_result_caches->length() <= cache_id) { |
| 3767 | __ Abort("Attempt to use undefined cache."); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3768 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3769 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3770 | return; |
| 3771 | } |
| 3772 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3773 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3774 | |
| 3775 | Register key = eax; |
| 3776 | Register cache = ebx; |
| 3777 | Register tmp = ecx; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3778 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3779 | __ mov(cache, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3780 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3781 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3782 | __ mov(cache, |
| 3783 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3784 | |
| 3785 | Label done, not_found; |
| 3786 | // tmp now holds finger offset as a smi. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3787 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3788 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 3789 | __ cmp(key, CodeGenerator::FixedArrayElementOperand(cache, tmp)); |
| 3790 | __ j(not_equal, ¬_found); |
| 3791 | |
| 3792 | __ mov(eax, CodeGenerator::FixedArrayElementOperand(cache, tmp, 1)); |
| 3793 | __ jmp(&done); |
| 3794 | |
| 3795 | __ bind(¬_found); |
| 3796 | // Call runtime to perform the lookup. |
| 3797 | __ push(cache); |
| 3798 | __ push(key); |
| 3799 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3800 | |
| 3801 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3802 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3806 | void FullCodeGenerator::EmitIsRegExpEquivalent(CallRuntime* expr) { |
| 3807 | ZoneList<Expression*>* args = expr->arguments(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3808 | ASSERT_EQ(2, args->length()); |
| 3809 | |
| 3810 | Register right = eax; |
| 3811 | Register left = ebx; |
| 3812 | Register tmp = ecx; |
| 3813 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3814 | VisitForStackValue(args->at(0)); |
| 3815 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3816 | __ pop(left); |
| 3817 | |
| 3818 | Label done, fail, ok; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3819 | __ cmp(left, right); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3820 | __ j(equal, &ok); |
| 3821 | // Fail if either is a non-HeapObject. |
| 3822 | __ mov(tmp, left); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3823 | __ and_(tmp, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3824 | __ JumpIfSmi(tmp, &fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3825 | __ mov(tmp, FieldOperand(left, HeapObject::kMapOffset)); |
| 3826 | __ CmpInstanceType(tmp, JS_REGEXP_TYPE); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3827 | __ j(not_equal, &fail); |
| 3828 | __ cmp(tmp, FieldOperand(right, HeapObject::kMapOffset)); |
| 3829 | __ j(not_equal, &fail); |
| 3830 | __ mov(tmp, FieldOperand(left, JSRegExp::kDataOffset)); |
| 3831 | __ cmp(tmp, FieldOperand(right, JSRegExp::kDataOffset)); |
| 3832 | __ j(equal, &ok); |
| 3833 | __ bind(&fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3834 | __ mov(eax, Immediate(isolate()->factory()->false_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3835 | __ jmp(&done); |
| 3836 | __ bind(&ok); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3837 | __ mov(eax, Immediate(isolate()->factory()->true_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3838 | __ bind(&done); |
| 3839 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3840 | context()->Plug(eax); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3841 | } |
| 3842 | |
| 3843 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3844 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3845 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3846 | ASSERT(args->length() == 1); |
| 3847 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3848 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3849 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3850 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3851 | |
| 3852 | Label materialize_true, materialize_false; |
| 3853 | Label* if_true = NULL; |
| 3854 | Label* if_false = NULL; |
| 3855 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3856 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3857 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3858 | |
| 3859 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 3860 | Immediate(String::kContainsCachedArrayIndexMask)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3861 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3862 | Split(zero, if_true, if_false, fall_through); |
| 3863 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3864 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
| 3867 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3868 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3869 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3870 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3871 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3872 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3873 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3874 | |
| 3875 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 3876 | __ IndexFromHash(eax, eax); |
| 3877 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3878 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3879 | } |
| 3880 | |
| 3881 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3882 | void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3883 | Label bailout, done, one_char_separator, long_separator, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3884 | non_trivial_array, not_size_one_array, loop, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3885 | loop_1, loop_1_condition, loop_2, loop_2_entry, loop_3, loop_3_entry; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3886 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3887 | ZoneList<Expression*>* args = expr->arguments(); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3888 | ASSERT(args->length() == 2); |
| 3889 | // We will leave the separator on the stack until the end of the function. |
| 3890 | VisitForStackValue(args->at(1)); |
| 3891 | // Load this to eax (= array) |
| 3892 | VisitForAccumulatorValue(args->at(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3893 | // All aliases of the same register have disjoint lifetimes. |
| 3894 | Register array = eax; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3895 | Register elements = no_reg; // Will be eax. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3896 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3897 | Register index = edx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3898 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3899 | Register string_length = ecx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3900 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3901 | Register string = esi; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3902 | |
| 3903 | Register scratch = ebx; |
| 3904 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3905 | Register array_length = edi; |
| 3906 | Register result_pos = no_reg; // Will be edi. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3907 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3908 | // Separator operand is already pushed. |
| 3909 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 3910 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 3911 | Operand array_length_operand = Operand(esp, 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3912 | __ sub(esp, Immediate(2 * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3913 | __ cld(); |
| 3914 | // Check that the array is a JSArray |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3915 | __ JumpIfSmi(array, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3916 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3917 | __ j(not_equal, &bailout); |
| 3918 | |
| 3919 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3920 | __ CheckFastElements(scratch, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3921 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3922 | // If the array has length zero, return the empty string. |
| 3923 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3924 | __ SmiUntag(array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3925 | __ j(not_zero, &non_trivial_array); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3926 | __ mov(result_operand, isolate()->factory()->empty_string()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3927 | __ jmp(&done); |
| 3928 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3929 | // Save the array length. |
| 3930 | __ bind(&non_trivial_array); |
| 3931 | __ mov(array_length_operand, array_length); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3932 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3933 | // Save the FixedArray containing array's elements. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3934 | // End of array's live range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3935 | elements = array; |
| 3936 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3937 | array = no_reg; |
| 3938 | |
| 3939 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3940 | // Check that all array elements are sequential ASCII strings, and |
| 3941 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 3942 | __ Set(index, Immediate(0)); |
| 3943 | __ Set(string_length, Immediate(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3944 | // Loop condition: while (index < length). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3945 | // Live loop registers: index, array_length, string, |
| 3946 | // scratch, string_length, elements. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 3947 | if (generate_debug_code_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3948 | __ cmp(index, array_length); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3949 | __ Assert(less, "No empty arrays here in EmitFastAsciiArrayJoin"); |
| 3950 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3951 | __ bind(&loop); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3952 | __ mov(string, FieldOperand(elements, |
| 3953 | index, |
| 3954 | times_pointer_size, |
| 3955 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3956 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3957 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3958 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3959 | __ and_(scratch, Immediate( |
| 3960 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3961 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3962 | __ j(not_equal, &bailout); |
| 3963 | __ add(string_length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3964 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3965 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3966 | __ add(index, Immediate(1)); |
| 3967 | __ cmp(index, array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3968 | __ j(less, &loop); |
| 3969 | |
| 3970 | // If array_length is 1, return elements[0], a string. |
| 3971 | __ cmp(array_length, 1); |
| 3972 | __ j(not_equal, ¬_size_one_array); |
| 3973 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3974 | __ mov(result_operand, scratch); |
| 3975 | __ jmp(&done); |
| 3976 | |
| 3977 | __ bind(¬_size_one_array); |
| 3978 | |
| 3979 | // End of array_length live range. |
| 3980 | result_pos = array_length; |
| 3981 | array_length = no_reg; |
| 3982 | |
| 3983 | // Live registers: |
| 3984 | // string_length: Sum of string lengths, as a smi. |
| 3985 | // elements: FixedArray of strings. |
| 3986 | |
| 3987 | // Check that the separator is a flat ASCII string. |
| 3988 | __ mov(string, separator_operand); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3989 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3990 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3991 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3992 | __ and_(scratch, Immediate( |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3993 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3994 | __ cmp(scratch, ASCII_STRING_TYPE); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3995 | __ j(not_equal, &bailout); |
| 3996 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3997 | // Add (separator length times array_length) - separator length |
| 3998 | // to string_length. |
| 3999 | __ mov(scratch, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4000 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4001 | __ sub(string_length, scratch); // May be negative, temporarily. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4002 | __ imul(scratch, array_length_operand); |
| 4003 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4004 | __ add(string_length, scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4005 | __ j(overflow, &bailout); |
| 4006 | |
| 4007 | __ shr(string_length, 1); |
| 4008 | // Live registers and stack values: |
| 4009 | // string_length |
| 4010 | // elements |
| 4011 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 4012 | index, string, &bailout); |
| 4013 | __ mov(result_operand, result_pos); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4014 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4015 | |
| 4016 | |
| 4017 | __ mov(string, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4018 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4019 | Immediate(Smi::FromInt(1))); |
| 4020 | __ j(equal, &one_char_separator); |
| 4021 | __ j(greater, &long_separator); |
| 4022 | |
| 4023 | |
| 4024 | // Empty separator case |
| 4025 | __ mov(index, Immediate(0)); |
| 4026 | __ jmp(&loop_1_condition); |
| 4027 | // Loop condition: while (index < length). |
| 4028 | __ bind(&loop_1); |
| 4029 | // Each iteration of the loop concatenates one string to the result. |
| 4030 | // Live values in registers: |
| 4031 | // index: which element of the elements array we are adding to the result. |
| 4032 | // result_pos: the position to which we are currently copying characters. |
| 4033 | // elements: the FixedArray of strings we are joining. |
| 4034 | |
| 4035 | // Get string = array[index]. |
| 4036 | __ mov(string, FieldOperand(elements, index, |
| 4037 | times_pointer_size, |
| 4038 | FixedArray::kHeaderSize)); |
| 4039 | __ mov(string_length, |
| 4040 | FieldOperand(string, String::kLengthOffset)); |
| 4041 | __ shr(string_length, 1); |
| 4042 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4043 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4044 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4045 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4046 | __ bind(&loop_1_condition); |
| 4047 | __ cmp(index, array_length_operand); |
| 4048 | __ j(less, &loop_1); // End while (index < length). |
| 4049 | __ jmp(&done); |
| 4050 | |
| 4051 | |
| 4052 | |
| 4053 | // One-character separator case |
| 4054 | __ bind(&one_char_separator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4055 | // Replace separator with its ASCII character value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4056 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4057 | __ mov_b(separator_operand, scratch); |
| 4058 | |
| 4059 | __ Set(index, Immediate(0)); |
| 4060 | // Jump into the loop after the code that copies the separator, so the first |
| 4061 | // element is not preceded by a separator |
| 4062 | __ jmp(&loop_2_entry); |
| 4063 | // Loop condition: while (index < length). |
| 4064 | __ bind(&loop_2); |
| 4065 | // Each iteration of the loop concatenates one string to the result. |
| 4066 | // Live values in registers: |
| 4067 | // index: which element of the elements array we are adding to the result. |
| 4068 | // result_pos: the position to which we are currently copying characters. |
| 4069 | |
| 4070 | // Copy the separator character to the result. |
| 4071 | __ mov_b(scratch, separator_operand); |
| 4072 | __ mov_b(Operand(result_pos, 0), scratch); |
| 4073 | __ inc(result_pos); |
| 4074 | |
| 4075 | __ bind(&loop_2_entry); |
| 4076 | // Get string = array[index]. |
| 4077 | __ mov(string, FieldOperand(elements, index, |
| 4078 | times_pointer_size, |
| 4079 | FixedArray::kHeaderSize)); |
| 4080 | __ mov(string_length, |
| 4081 | FieldOperand(string, String::kLengthOffset)); |
| 4082 | __ shr(string_length, 1); |
| 4083 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4084 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4085 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4086 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4087 | |
| 4088 | __ cmp(index, array_length_operand); |
| 4089 | __ j(less, &loop_2); // End while (index < length). |
| 4090 | __ jmp(&done); |
| 4091 | |
| 4092 | |
| 4093 | // Long separator case (separator is more than one character). |
| 4094 | __ bind(&long_separator); |
| 4095 | |
| 4096 | __ Set(index, Immediate(0)); |
| 4097 | // Jump into the loop after the code that copies the separator, so the first |
| 4098 | // element is not preceded by a separator |
| 4099 | __ jmp(&loop_3_entry); |
| 4100 | // Loop condition: while (index < length). |
| 4101 | __ bind(&loop_3); |
| 4102 | // Each iteration of the loop concatenates one string to the result. |
| 4103 | // Live values in registers: |
| 4104 | // index: which element of the elements array we are adding to the result. |
| 4105 | // result_pos: the position to which we are currently copying characters. |
| 4106 | |
| 4107 | // Copy the separator to the result. |
| 4108 | __ mov(string, separator_operand); |
| 4109 | __ mov(string_length, |
| 4110 | FieldOperand(string, String::kLengthOffset)); |
| 4111 | __ shr(string_length, 1); |
| 4112 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4113 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4114 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 4115 | |
| 4116 | __ bind(&loop_3_entry); |
| 4117 | // Get string = array[index]. |
| 4118 | __ mov(string, FieldOperand(elements, index, |
| 4119 | times_pointer_size, |
| 4120 | FixedArray::kHeaderSize)); |
| 4121 | __ mov(string_length, |
| 4122 | FieldOperand(string, String::kLengthOffset)); |
| 4123 | __ shr(string_length, 1); |
| 4124 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4125 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4126 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4127 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4128 | |
| 4129 | __ cmp(index, array_length_operand); |
| 4130 | __ j(less, &loop_3); // End while (index < length). |
| 4131 | __ jmp(&done); |
| 4132 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4133 | |
| 4134 | __ bind(&bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4135 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4136 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4137 | __ mov(eax, result_operand); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4138 | // Drop temp values from the stack, and restore context register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4139 | __ add(esp, Immediate(3 * kPointerSize)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4140 | |
| 4141 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4142 | context()->Plug(eax); |
| 4143 | } |
| 4144 | |
| 4145 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4146 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4147 | Handle<String> name = expr->name(); |
| 4148 | if (name->length() > 0 && name->Get(0) == '_') { |
| 4149 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4150 | EmitInlineRuntimeCall(expr); |
| 4151 | return; |
| 4152 | } |
| 4153 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4154 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4155 | ZoneList<Expression*>* args = expr->arguments(); |
| 4156 | |
| 4157 | if (expr->is_jsruntime()) { |
| 4158 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4159 | __ mov(eax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4160 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
| 4161 | } |
| 4162 | |
| 4163 | // Push the arguments ("left-to-right"). |
| 4164 | int arg_count = args->length(); |
| 4165 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4166 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | if (expr->is_jsruntime()) { |
| 4170 | // Call the JS runtime function via a call IC. |
| 4171 | __ Set(ecx, Immediate(expr->name())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4172 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4173 | Handle<Code> ic = |
| 4174 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4175 | CallIC(ic, mode, expr->CallRuntimeFeedbackId()); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4176 | // Restore context register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4177 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4178 | } else { |
| 4179 | // Call the C runtime function. |
| 4180 | __ CallRuntime(expr->function(), arg_count); |
| 4181 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4182 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
| 4185 | |
| 4186 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 4187 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4188 | case Token::DELETE: { |
| 4189 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4190 | Property* property = expr->expression()->AsProperty(); |
| 4191 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4192 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4193 | if (property != NULL) { |
| 4194 | VisitForStackValue(property->obj()); |
| 4195 | VisitForStackValue(property->key()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4196 | StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE) |
| 4197 | ? kNonStrictMode : kStrictMode; |
| 4198 | __ push(Immediate(Smi::FromInt(strict_mode_flag))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4199 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4200 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4201 | } else if (proxy != NULL) { |
| 4202 | Variable* var = proxy->var(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4203 | // Delete of an unqualified identifier is disallowed in strict mode |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4204 | // but "delete this" is allowed. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4205 | ASSERT(language_mode() == CLASSIC_MODE || var->is_this()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4206 | if (var->IsUnallocated()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4207 | __ push(GlobalObjectOperand()); |
| 4208 | __ push(Immediate(var->name())); |
| 4209 | __ push(Immediate(Smi::FromInt(kNonStrictMode))); |
| 4210 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4211 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4212 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4213 | // Result of deleting non-global variables is false. 'this' is |
| 4214 | // not really a variable, though we implement it as one. The |
| 4215 | // subexpression does not have side effects. |
| 4216 | context()->Plug(var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4217 | } else { |
| 4218 | // Non-global variable. Call the runtime to try to delete from the |
| 4219 | // context where the variable was introduced. |
| 4220 | __ push(context_register()); |
| 4221 | __ push(Immediate(var->name())); |
| 4222 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
| 4223 | context()->Plug(eax); |
| 4224 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4225 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4226 | // Result of deleting non-property, non-variable reference is true. |
| 4227 | // The subexpression may have side effects. |
| 4228 | VisitForEffect(expr->expression()); |
| 4229 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4230 | } |
| 4231 | break; |
| 4232 | } |
| 4233 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4234 | case Token::VOID: { |
| 4235 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 4236 | VisitForEffect(expr->expression()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4237 | context()->Plug(isolate()->factory()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4238 | break; |
| 4239 | } |
| 4240 | |
| 4241 | case Token::NOT: { |
| 4242 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4243 | if (context()->IsEffect()) { |
| 4244 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4245 | // subexpression. Match the optimizing compiler by not branching. |
| 4246 | VisitForEffect(expr->expression()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4247 | } else if (context()->IsTest()) { |
| 4248 | const TestContext* test = TestContext::cast(context()); |
| 4249 | // The labels are swapped for the recursive call. |
| 4250 | VisitForControl(expr->expression(), |
| 4251 | test->false_label(), |
| 4252 | test->true_label(), |
| 4253 | test->fall_through()); |
| 4254 | context()->Plug(test->true_label(), test->false_label()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4255 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4256 | // We handle value contexts explicitly rather than simply visiting |
| 4257 | // for control and plugging the control flow into the context, |
| 4258 | // because we need to prepare a pair of extra administrative AST ids |
| 4259 | // for the optimizing compiler. |
| 4260 | ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 4261 | Label materialize_true, materialize_false, done; |
| 4262 | VisitForControl(expr->expression(), |
| 4263 | &materialize_false, |
| 4264 | &materialize_true, |
| 4265 | &materialize_true); |
| 4266 | __ bind(&materialize_true); |
| 4267 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4268 | if (context()->IsAccumulatorValue()) { |
| 4269 | __ mov(eax, isolate()->factory()->true_value()); |
| 4270 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4271 | __ Push(isolate()->factory()->true_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4272 | } |
| 4273 | __ jmp(&done, Label::kNear); |
| 4274 | __ bind(&materialize_false); |
| 4275 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4276 | if (context()->IsAccumulatorValue()) { |
| 4277 | __ mov(eax, isolate()->factory()->false_value()); |
| 4278 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4279 | __ Push(isolate()->factory()->false_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4280 | } |
| 4281 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4282 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4283 | break; |
| 4284 | } |
| 4285 | |
| 4286 | case Token::TYPEOF: { |
| 4287 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4288 | { StackValueContext context(this); |
| 4289 | VisitForTypeofValue(expr->expression()); |
| 4290 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4291 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4292 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4293 | break; |
| 4294 | } |
| 4295 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4296 | case Token::SUB: |
| 4297 | EmitUnaryOperation(expr, "[ UnaryOperation (SUB)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4298 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4299 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4300 | case Token::BIT_NOT: |
| 4301 | EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4302 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4303 | |
| 4304 | default: |
| 4305 | UNREACHABLE(); |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4310 | void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr, |
| 4311 | const char* comment) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4312 | Comment cmt(masm_, comment); |
| 4313 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
| 4314 | UnaryOverwriteMode overwrite = |
| 4315 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4316 | UnaryOpStub stub(expr->op(), overwrite); |
| 4317 | // UnaryOpStub expects the argument to be in the |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4318 | // accumulator register eax. |
| 4319 | VisitForAccumulatorValue(expr->expression()); |
| 4320 | SetSourcePosition(expr->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4321 | CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4322 | expr->UnaryOperationFeedbackId()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 4323 | context()->Plug(eax); |
| 4324 | } |
| 4325 | |
| 4326 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4327 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 4328 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4329 | SetSourcePosition(expr->position()); |
| 4330 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4331 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 4332 | // as the left-hand side. |
| 4333 | if (!expr->expression()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4334 | VisitForEffect(expr->expression()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4335 | return; |
| 4336 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4337 | |
| 4338 | // Expression can only be a property, a global or a (parameter or local) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4339 | // slot. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4340 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 4341 | LhsKind assign_type = VARIABLE; |
| 4342 | Property* prop = expr->expression()->AsProperty(); |
| 4343 | // In case of a property we use the uninitialized expression context |
| 4344 | // of the key to detect a named property. |
| 4345 | if (prop != NULL) { |
| 4346 | assign_type = |
| 4347 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 4348 | } |
| 4349 | |
| 4350 | // Evaluate expression and get value. |
| 4351 | if (assign_type == VARIABLE) { |
| 4352 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4353 | AccumulatorValueContext context(this); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4354 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4355 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4356 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4357 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4358 | __ push(Immediate(Smi::FromInt(0))); |
| 4359 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4360 | if (assign_type == NAMED_PROPERTY) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4361 | // Put the object both on the stack and in edx. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4362 | VisitForAccumulatorValue(prop->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4363 | __ push(eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4364 | __ mov(edx, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4365 | EmitNamedPropertyLoad(prop); |
| 4366 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4367 | VisitForStackValue(prop->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4368 | VisitForStackValue(prop->key()); |
| 4369 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 4370 | __ mov(ecx, Operand(esp, 0)); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4371 | EmitKeyedPropertyLoad(prop); |
| 4372 | } |
| 4373 | } |
| 4374 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4375 | // We need a second deoptimization point after loading the value |
| 4376 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4377 | if (assign_type == VARIABLE) { |
| 4378 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4379 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4380 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4381 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4382 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4383 | // Call ToNumber only if operand is not a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4384 | Label no_conversion; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4385 | if (ShouldInlineSmiCase(expr->op())) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4386 | __ JumpIfSmi(eax, &no_conversion, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4387 | } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4388 | ToNumberStub convert_stub; |
| 4389 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4390 | __ bind(&no_conversion); |
| 4391 | |
| 4392 | // Save result for postfix expressions. |
| 4393 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4394 | if (!context()->IsEffect()) { |
| 4395 | // Save the result on the stack. If we have a named or keyed property |
| 4396 | // we store the result under the receiver that is currently on top |
| 4397 | // of the stack. |
| 4398 | switch (assign_type) { |
| 4399 | case VARIABLE: |
| 4400 | __ push(eax); |
| 4401 | break; |
| 4402 | case NAMED_PROPERTY: |
| 4403 | __ mov(Operand(esp, kPointerSize), eax); |
| 4404 | break; |
| 4405 | case KEYED_PROPERTY: |
| 4406 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4407 | break; |
| 4408 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | // Inline smi case if we are in a loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4413 | Label done, stub_call; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4414 | JumpPatchSite patch_site(masm_); |
| 4415 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4416 | if (ShouldInlineSmiCase(expr->op())) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4417 | if (expr->op() == Token::INC) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4418 | __ add(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4419 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4420 | __ sub(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4421 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4422 | __ j(overflow, &stub_call, Label::kNear); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4423 | // We could eliminate this smi check if we split the code at |
| 4424 | // the first smi check before calling ToNumber. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4425 | patch_site.EmitJumpIfSmi(eax, &done, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4426 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4427 | __ bind(&stub_call); |
| 4428 | // Call stub. Undo operation first. |
| 4429 | if (expr->op() == Token::INC) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4430 | __ sub(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4431 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4432 | __ add(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4433 | } |
| 4434 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4435 | |
| 4436 | // Record position before stub call. |
| 4437 | SetSourcePosition(expr->position()); |
| 4438 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4439 | // Call stub for +1/-1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4440 | __ mov(edx, eax); |
| 4441 | __ mov(eax, Immediate(Smi::FromInt(1))); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4442 | BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4443 | CallIC(stub.GetCode(isolate()), |
| 4444 | RelocInfo::CODE_TARGET, |
| 4445 | expr->CountBinOpFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4446 | patch_site.EmitPatchInfo(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4447 | __ bind(&done); |
| 4448 | |
| 4449 | // Store the value returned in eax. |
| 4450 | switch (assign_type) { |
| 4451 | case VARIABLE: |
| 4452 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4453 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4454 | { EffectContext context(this); |
| 4455 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4456 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4457 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4458 | context.Plug(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4459 | } |
| 4460 | // For all contexts except EffectContext We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4461 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4462 | if (!context()->IsEffect()) { |
| 4463 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4464 | } |
| 4465 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4466 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4467 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4468 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4469 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4470 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4471 | } |
| 4472 | break; |
| 4473 | case NAMED_PROPERTY: { |
| 4474 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
| 4475 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4476 | Handle<Code> ic = is_classic_mode() |
| 4477 | ? isolate()->builtins()->StoreIC_Initialize() |
| 4478 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4479 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4480 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4481 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4482 | if (!context()->IsEffect()) { |
| 4483 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4484 | } |
| 4485 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4486 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4487 | } |
| 4488 | break; |
| 4489 | } |
| 4490 | case KEYED_PROPERTY: { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4491 | __ pop(ecx); |
| 4492 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4493 | Handle<Code> ic = is_classic_mode() |
| 4494 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 4495 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4496 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4497 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4498 | if (expr->is_postfix()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4499 | // Result is on the stack |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4500 | if (!context()->IsEffect()) { |
| 4501 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4502 | } |
| 4503 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4504 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4505 | } |
| 4506 | break; |
| 4507 | } |
| 4508 | } |
| 4509 | } |
| 4510 | |
| 4511 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4512 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4513 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4514 | ASSERT(!context()->IsEffect()); |
| 4515 | ASSERT(!context()->IsTest()); |
| 4516 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4517 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4518 | Comment cmnt(masm_, "Global variable"); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4519 | __ mov(edx, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4520 | __ mov(ecx, Immediate(proxy->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4521 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4522 | // Use a regular load, not a contextual load, to avoid a reference |
| 4523 | // error. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4524 | CallIC(ic); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4525 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4526 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4527 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4528 | Label done, slow; |
| 4529 | |
| 4530 | // Generate code for loading from variables potentially shadowed |
| 4531 | // by eval-introduced variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4532 | EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4533 | |
| 4534 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | __ push(esi); |
| 4536 | __ push(Immediate(proxy->name())); |
| 4537 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4538 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4539 | __ bind(&done); |
| 4540 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4541 | context()->Plug(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4542 | } else { |
| 4543 | // This expression cannot throw a reference error at the top level. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4544 | VisitInDuplicateContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4549 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4550 | Expression* sub_expr, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4551 | Handle<String> check) { |
| 4552 | Label materialize_true, materialize_false; |
| 4553 | Label* if_true = NULL; |
| 4554 | Label* if_false = NULL; |
| 4555 | Label* fall_through = NULL; |
| 4556 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4557 | &if_true, &if_false, &fall_through); |
| 4558 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4559 | { AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4560 | VisitForTypeofValue(sub_expr); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4561 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4562 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4563 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4564 | if (check->Equals(isolate()->heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4565 | __ JumpIfSmi(eax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4566 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4567 | isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4568 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4569 | } else if (check->Equals(isolate()->heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4570 | __ JumpIfSmi(eax, if_false); |
| 4571 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4572 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4573 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4574 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4575 | 1 << Map::kIsUndetectable); |
| 4576 | Split(zero, if_true, if_false, fall_through); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4577 | } else if (check->Equals(isolate()->heap()->symbol_string())) { |
| 4578 | __ JumpIfSmi(eax, if_false); |
| 4579 | __ CmpObjectType(eax, SYMBOL_TYPE, edx); |
| 4580 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4581 | } else if (check->Equals(isolate()->heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4582 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4583 | __ j(equal, if_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4584 | __ cmp(eax, isolate()->factory()->false_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | Split(equal, if_true, if_false, fall_through); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4586 | } else if (FLAG_harmony_typeof && |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4587 | check->Equals(isolate()->heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4588 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4589 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4590 | } else if (check->Equals(isolate()->heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4591 | __ cmp(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4592 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4593 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4594 | // Check for undetectable objects => true. |
| 4595 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4596 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4597 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4598 | Split(not_zero, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4599 | } else if (check->Equals(isolate()->heap()->function_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4600 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4601 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4602 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4603 | __ j(equal, if_true); |
| 4604 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4605 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4606 | } else if (check->Equals(isolate()->heap()->object_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4607 | __ JumpIfSmi(eax, if_false); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4608 | if (!FLAG_harmony_typeof) { |
| 4609 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4610 | __ j(equal, if_true); |
| 4611 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4612 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4613 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4614 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4615 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4616 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4617 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4618 | 1 << Map::kIsUndetectable); |
| 4619 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4620 | } else { |
| 4621 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4622 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4623 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4627 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4628 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4629 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4630 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4631 | // First we try a fast inlined version of the compare when one of |
| 4632 | // the operands is a literal. |
| 4633 | if (TryLiteralCompare(expr)) return; |
| 4634 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4635 | // Always perform the comparison for its control flow. Pack the result |
| 4636 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4637 | Label materialize_true, materialize_false; |
| 4638 | Label* if_true = NULL; |
| 4639 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4640 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4641 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4642 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4643 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4644 | Token::Value op = expr->op(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4645 | VisitForStackValue(expr->left()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4646 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4647 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4648 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4649 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4650 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4651 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4652 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4653 | break; |
| 4654 | |
| 4655 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4656 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4657 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4658 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4659 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4660 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4661 | // The stub returns 0 for true. |
| 4662 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4663 | break; |
| 4664 | } |
| 4665 | |
| 4666 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4667 | VisitForAccumulatorValue(expr->right()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4668 | Condition cc = CompareIC::ComputeCondition(op); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4669 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4670 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4671 | bool inline_smi_code = ShouldInlineSmiCase(op); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4672 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4673 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4674 | Label slow_case; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4675 | __ mov(ecx, edx); |
| 4676 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4677 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4678 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4679 | Split(cc, if_true, if_false, NULL); |
| 4680 | __ bind(&slow_case); |
| 4681 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4682 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4683 | // Record position and call the compare IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4684 | SetSourcePosition(expr->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4685 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4686 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4687 | patch_site.EmitPatchInfo(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4688 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4689 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4690 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4691 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4692 | } |
| 4693 | } |
| 4694 | |
| 4695 | // Convert the result of the comparison into one expected for this |
| 4696 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4697 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
| 4700 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4701 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4702 | Expression* sub_expr, |
| 4703 | NilValue nil) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4704 | Label materialize_true, materialize_false; |
| 4705 | Label* if_true = NULL; |
| 4706 | Label* if_false = NULL; |
| 4707 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4708 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4709 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4710 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4711 | VisitForAccumulatorValue(sub_expr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4712 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4713 | |
| 4714 | EqualityKind kind = expr->op() == Token::EQ_STRICT |
| 4715 | ? kStrictEquality : kNonStrictEquality; |
| 4716 | Handle<Object> nil_value = nil == kNullValue |
| 4717 | ? isolate()->factory()->null_value() |
| 4718 | : isolate()->factory()->undefined_value(); |
| 4719 | if (kind == kStrictEquality) { |
| 4720 | __ cmp(eax, nil_value); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4721 | Split(equal, if_true, if_false, fall_through); |
| 4722 | } else { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4723 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), |
| 4724 | kNonStrictEquality, |
| 4725 | nil); |
| 4726 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CompareOperationFeedbackId()); |
| 4727 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4728 | Split(not_zero, if_true, if_false, fall_through); |
| 4729 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4730 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4731 | } |
| 4732 | |
| 4733 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4734 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4735 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4736 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4740 | Register FullCodeGenerator::result_register() { |
| 4741 | return eax; |
| 4742 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4743 | |
| 4744 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4745 | Register FullCodeGenerator::context_register() { |
| 4746 | return esi; |
| 4747 | } |
| 4748 | |
| 4749 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4750 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4751 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 4752 | __ mov(Operand(ebp, frame_offset), value); |
| 4753 | } |
| 4754 | |
| 4755 | |
| 4756 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4757 | __ mov(dst, ContextOperand(esi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4761 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4762 | Scope* declaration_scope = scope()->DeclarationScope(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4763 | if (declaration_scope->is_global_scope() || |
| 4764 | declaration_scope->is_module_scope()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4765 | // Contexts nested in the native context have a canonical empty function |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4766 | // as their closure, not the anonymous closure containing the global |
| 4767 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4768 | // function. |
| 4769 | __ push(Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4770 | } else if (declaration_scope->is_eval_scope()) { |
| 4771 | // Contexts nested inside eval code have the same closure as the context |
| 4772 | // calling eval, not the anonymous closure containing the eval code. |
| 4773 | // Fetch it from the context. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4774 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 4775 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4776 | ASSERT(declaration_scope->is_function_scope()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4777 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4778 | } |
| 4779 | } |
| 4780 | |
| 4781 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4782 | // ---------------------------------------------------------------------------- |
| 4783 | // Non-local control flow support. |
| 4784 | |
| 4785 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4786 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4787 | ASSERT(!result_register().is(edx)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4788 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4789 | __ sub(edx, Immediate(masm_->CodeObject())); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4790 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4791 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4792 | __ SmiTag(edx); |
| 4793 | __ push(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4794 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4795 | // Store result register while executing finally block. |
| 4796 | __ push(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4797 | |
| 4798 | // Store pending message while executing finally block. |
| 4799 | ExternalReference pending_message_obj = |
| 4800 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4801 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4802 | __ push(edx); |
| 4803 | |
| 4804 | ExternalReference has_pending_message = |
| 4805 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4806 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4807 | __ SmiTag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4808 | __ push(edx); |
| 4809 | |
| 4810 | ExternalReference pending_message_script = |
| 4811 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4812 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 4813 | __ push(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4814 | } |
| 4815 | |
| 4816 | |
| 4817 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4818 | ASSERT(!result_register().is(edx)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4819 | // Restore pending message from stack. |
| 4820 | __ pop(edx); |
| 4821 | ExternalReference pending_message_script = |
| 4822 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4823 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 4824 | |
| 4825 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4826 | __ SmiUntag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4827 | ExternalReference has_pending_message = |
| 4828 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4829 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 4830 | |
| 4831 | __ pop(edx); |
| 4832 | ExternalReference pending_message_obj = |
| 4833 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4834 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4835 | |
| 4836 | // Restore result register from stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4837 | __ pop(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4838 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4839 | // Uncook return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4840 | __ pop(edx); |
| 4841 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4842 | __ add(edx, Immediate(masm_->CodeObject())); |
| 4843 | __ jmp(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
| 4846 | |
| 4847 | #undef __ |
| 4848 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4849 | #define __ ACCESS_MASM(masm()) |
| 4850 | |
| 4851 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 4852 | int* stack_depth, |
| 4853 | int* context_length) { |
| 4854 | // The macros used here must preserve the result register. |
| 4855 | |
| 4856 | // Because the handler block contains the context of the finally |
| 4857 | // code, we can restore it directly from there for the finally code |
| 4858 | // rather than iteratively unwinding contexts via their previous |
| 4859 | // links. |
| 4860 | __ Drop(*stack_depth); // Down to the handler block. |
| 4861 | if (*context_length > 0) { |
| 4862 | // Restore the context to its dedicated register and the stack. |
| 4863 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 4864 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 4865 | } |
| 4866 | __ PopTryHandler(); |
| 4867 | __ call(finally_entry_); |
| 4868 | |
| 4869 | *stack_depth = 0; |
| 4870 | *context_length = 0; |
| 4871 | return previous_; |
| 4872 | } |
| 4873 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4874 | #undef __ |
| 4875 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4876 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4877 | |
| 4878 | #endif // V8_TARGET_ARCH_IA32 |