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 && |
| 130 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 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; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 141 | Label start; |
| 142 | __ bind(&start); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 143 | __ test(ecx, ecx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 144 | __ j(zero, &ok, Label::kNear); |
| 145 | // +1 for return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 146 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 147 | __ mov(ecx, Operand(esp, receiver_offset)); |
| 148 | __ JumpIfSmi(ecx, &ok); |
| 149 | __ CmpObjectType(ecx, JS_GLOBAL_PROXY_TYPE, ecx); |
| 150 | __ j(not_equal, &ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 151 | __ mov(Operand(esp, receiver_offset), |
| 152 | Immediate(isolate()->factory()->undefined_value())); |
| 153 | __ bind(&ok); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 154 | ASSERT(!FLAG_age_code || |
| 155 | (kSizeOfFullCodegenStrictModePrologue == ok.pos() - start.pos())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 156 | } |
| 157 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 158 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 159 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 160 | // the frame (that is done below). |
| 161 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 162 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 163 | __ push(ebp); // Caller's frame pointer. |
| 164 | __ mov(ebp, esp); |
| 165 | __ push(esi); // Callee's context. |
| 166 | __ push(edi); // Callee's JS Function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 167 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 168 | { Comment cmnt(masm_, "[ Allocate locals"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 169 | int locals_count = info->scope()->num_stack_slots(); |
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 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 335 | void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt, |
| 336 | Label* back_edge_target) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 337 | Comment cmnt(masm_, "[ Stack check"); |
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 | |
| 340 | if (FLAG_count_based_interrupts) { |
| 341 | int weight = 1; |
| 342 | if (FLAG_weighted_back_edges) { |
| 343 | ASSERT(back_edge_target->is_bound()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 344 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 345 | weight = Min(kMaxBackEdgeWeight, |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 346 | Max(1, distance / kBackEdgeDistanceUnit)); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 347 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 348 | EmitProfilingCounterDecrement(weight); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 349 | __ j(positive, &ok, Label::kNear); |
| 350 | InterruptStub stub; |
| 351 | __ CallStub(&stub); |
| 352 | } else { |
| 353 | // Count based interrupts happen often enough when they are enabled |
| 354 | // that the additional stack checks are not necessary (they would |
| 355 | // only check for interrupts). |
| 356 | ExternalReference stack_limit = |
| 357 | ExternalReference::address_of_stack_limit(isolate()); |
| 358 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
| 359 | __ j(above_equal, &ok, Label::kNear); |
| 360 | StackCheckStub stub; |
| 361 | __ CallStub(&stub); |
| 362 | } |
| 363 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 364 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 365 | // the AST id from the unoptimized code in order to use it as a key into |
| 366 | // the deoptimization input data found in the optimized code. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 367 | RecordStackCheck(stmt->OsrEntryId()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 368 | |
| 369 | // Loop stack checks can be patched to perform on-stack replacement. In |
| 370 | // order to decide whether or not to perform OSR we embed the loop depth |
| 371 | // in a test instruction after the call so we can extract it from the OSR |
| 372 | // builtin. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 373 | ASSERT(loop_depth() > 0); |
| 374 | __ test(eax, Immediate(Min(loop_depth(), Code::kMaxLoopNestingMarker))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 375 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 376 | if (FLAG_count_based_interrupts) { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 377 | EmitProfilingCounterReset(); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 378 | } |
| 379 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 380 | __ bind(&ok); |
| 381 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 382 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 383 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 384 | // we want it to work if it is. |
| 385 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 389 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 390 | Comment cmnt(masm_, "[ Return sequence"); |
| 391 | if (return_label_.is_bound()) { |
| 392 | __ jmp(&return_label_); |
| 393 | } else { |
| 394 | // Common return label |
| 395 | __ bind(&return_label_); |
| 396 | if (FLAG_trace) { |
| 397 | __ push(eax); |
| 398 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 399 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 400 | if (FLAG_interrupt_at_exit || FLAG_self_optimization) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 401 | // Pretend that the exit is a backwards jump to the entry. |
| 402 | int weight = 1; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 403 | if (info_->ShouldSelfOptimize()) { |
| 404 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 405 | } else if (FLAG_weighted_back_edges) { |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 406 | int distance = masm_->pc_offset(); |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 407 | weight = Min(kMaxBackEdgeWeight, |
danno@chromium.org | 129d398 | 2012-07-25 15:01:47 +0000 | [diff] [blame] | 408 | Max(1, distance / kBackEdgeDistanceUnit)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 409 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 410 | EmitProfilingCounterDecrement(weight); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 411 | Label ok; |
| 412 | __ j(positive, &ok, Label::kNear); |
| 413 | __ push(eax); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 414 | if (info_->ShouldSelfOptimize() && FLAG_direct_self_opt) { |
| 415 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 416 | __ CallRuntime(Runtime::kOptimizeFunctionOnNextCall, 1); |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 417 | } else { |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 418 | InterruptStub stub; |
| 419 | __ CallStub(&stub); |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 420 | } |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 421 | __ pop(eax); |
| 422 | EmitProfilingCounterReset(); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 423 | __ bind(&ok); |
| 424 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 425 | #ifdef DEBUG |
| 426 | // Add a label for checking the size of the code used for returning. |
| 427 | Label check_exit_codesize; |
| 428 | masm_->bind(&check_exit_codesize); |
| 429 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 430 | SetSourcePosition(function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 431 | __ RecordJSReturn(); |
| 432 | // Do not use the leave instruction here because it is too short to |
| 433 | // patch with the code required by the debugger. |
| 434 | __ mov(esp, ebp); |
| 435 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 436 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 437 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 438 | __ Ret(arguments_bytes, ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 439 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 440 | // Check that the size of the code used for returning is large enough |
| 441 | // for the debugger's requirements. |
| 442 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 443 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 444 | #endif |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 449 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 450 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 454 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 455 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 456 | codegen()->GetVar(result_register(), var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 460 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 461 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 462 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 463 | // Memory operands can be pushed directly. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 464 | __ push(operand); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 468 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 469 | // For simplicity we always test the accumulator register. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 470 | codegen()->GetVar(result_register(), var); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 471 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 472 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
| 476 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 477 | UNREACHABLE(); // Not used on IA32. |
| 478 | } |
| 479 | |
| 480 | |
| 481 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 482 | Heap::RootListIndex index) const { |
| 483 | UNREACHABLE(); // Not used on IA32. |
| 484 | } |
| 485 | |
| 486 | |
| 487 | void FullCodeGenerator::StackValueContext::Plug( |
| 488 | Heap::RootListIndex index) const { |
| 489 | UNREACHABLE(); // Not used on IA32. |
| 490 | } |
| 491 | |
| 492 | |
| 493 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 494 | UNREACHABLE(); // Not used on IA32. |
| 495 | } |
| 496 | |
| 497 | |
| 498 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 499 | } |
| 500 | |
| 501 | |
| 502 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 503 | Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 504 | if (lit->IsSmi()) { |
| 505 | __ SafeSet(result_register(), Immediate(lit)); |
| 506 | } else { |
| 507 | __ Set(result_register(), Immediate(lit)); |
| 508 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | |
| 512 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 513 | if (lit->IsSmi()) { |
| 514 | __ SafePush(Immediate(lit)); |
| 515 | } else { |
| 516 | __ push(Immediate(lit)); |
| 517 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
| 521 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 522 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 523 | true, |
| 524 | true_label_, |
| 525 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 526 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 527 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 528 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 529 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 530 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 531 | } else if (lit->IsString()) { |
| 532 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 533 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 534 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 535 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 536 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 537 | } else if (lit->IsSmi()) { |
| 538 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 539 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 540 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 541 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 542 | } |
| 543 | } else { |
| 544 | // For simplicity we always test the accumulator register. |
| 545 | __ mov(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 546 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
| 550 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 551 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 552 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 553 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 554 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 558 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 559 | int count, |
| 560 | Register reg) const { |
| 561 | ASSERT(count > 0); |
| 562 | __ Drop(count); |
| 563 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 567 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 568 | Register reg) const { |
| 569 | ASSERT(count > 0); |
| 570 | if (count > 1) __ Drop(count - 1); |
| 571 | __ mov(Operand(esp, 0), reg); |
| 572 | } |
| 573 | |
| 574 | |
| 575 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 576 | Register reg) const { |
| 577 | ASSERT(count > 0); |
| 578 | // For simplicity we always test the accumulator register. |
| 579 | __ Drop(count); |
| 580 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 581 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 582 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | |
| 586 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 587 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 588 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 589 | __ bind(materialize_true); |
| 590 | } |
| 591 | |
| 592 | |
| 593 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 594 | Label* materialize_true, |
| 595 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 596 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 597 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 598 | __ mov(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 599 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 600 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 601 | __ mov(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 602 | __ bind(&done); |
| 603 | } |
| 604 | |
| 605 | |
| 606 | void FullCodeGenerator::StackValueContext::Plug( |
| 607 | Label* materialize_true, |
| 608 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 609 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 610 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 611 | __ push(Immediate(isolate()->factory()->true_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 612 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 613 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 614 | __ push(Immediate(isolate()->factory()->false_value())); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 615 | __ bind(&done); |
| 616 | } |
| 617 | |
| 618 | |
| 619 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 620 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 621 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 622 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | |
| 626 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 627 | } |
| 628 | |
| 629 | |
| 630 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 631 | Handle<Object> value = flag |
| 632 | ? isolate()->factory()->true_value() |
| 633 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 634 | __ mov(result_register(), value); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 639 | Handle<Object> value = flag |
| 640 | ? isolate()->factory()->true_value() |
| 641 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 642 | __ push(Immediate(value)); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 647 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 648 | true, |
| 649 | true_label_, |
| 650 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 651 | if (flag) { |
| 652 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 653 | } else { |
| 654 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
| 657 | |
| 658 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 659 | void FullCodeGenerator::DoTest(Expression* condition, |
| 660 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 661 | Label* if_false, |
| 662 | Label* fall_through) { |
lrn@chromium.org | ac2828d | 2011-06-23 06:29:21 +0000 | [diff] [blame] | 663 | ToBooleanStub stub(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 664 | __ push(result_register()); |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 665 | __ CallStub(&stub, condition->test_id()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 666 | __ test(result_register(), result_register()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 667 | // The stub returns nonzero for true. |
| 668 | Split(not_zero, if_true, if_false, fall_through); |
| 669 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 670 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 671 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 672 | void FullCodeGenerator::Split(Condition cc, |
| 673 | Label* if_true, |
| 674 | Label* if_false, |
| 675 | Label* fall_through) { |
| 676 | if (if_false == fall_through) { |
| 677 | __ j(cc, if_true); |
| 678 | } else if (if_true == fall_through) { |
| 679 | __ j(NegateCondition(cc), if_false); |
| 680 | } else { |
| 681 | __ j(cc, if_true); |
| 682 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 687 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 688 | ASSERT(var->IsStackAllocated()); |
| 689 | // Offset is negative because higher indexes are at lower addresses. |
| 690 | int offset = -var->index() * kPointerSize; |
| 691 | // Adjust by a (parameter or local) base offset. |
| 692 | if (var->IsParameter()) { |
| 693 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 694 | } else { |
| 695 | offset += JavaScriptFrameConstants::kLocal0Offset; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 697 | return Operand(ebp, offset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 701 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 702 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 703 | if (var->IsContextSlot()) { |
| 704 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 705 | __ LoadContext(scratch, context_chain_length); |
| 706 | return ContextOperand(scratch, var->index()); |
| 707 | } else { |
| 708 | return StackOperand(var); |
| 709 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 713 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 714 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 715 | MemOperand location = VarOperand(var, dest); |
| 716 | __ mov(dest, location); |
| 717 | } |
| 718 | |
| 719 | |
| 720 | void FullCodeGenerator::SetVar(Variable* var, |
| 721 | Register src, |
| 722 | Register scratch0, |
| 723 | Register scratch1) { |
| 724 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 725 | ASSERT(!scratch0.is(src)); |
| 726 | ASSERT(!scratch0.is(scratch1)); |
| 727 | ASSERT(!scratch1.is(src)); |
| 728 | MemOperand location = VarOperand(var, scratch0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 729 | __ mov(location, src); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 730 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 731 | // 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] | 732 | if (var->IsContextSlot()) { |
| 733 | int offset = Context::SlotOffset(var->index()); |
| 734 | ASSERT(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 735 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
| 739 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 740 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 741 | bool should_normalize, |
| 742 | Label* if_true, |
| 743 | Label* if_false) { |
| 744 | // Only prepare for bailouts before splits if we're in a test |
| 745 | // context. Otherwise, we let the Visit function deal with the |
| 746 | // preparation to avoid preparing with the same AST id twice. |
| 747 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 748 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 749 | Label skip; |
| 750 | if (should_normalize) __ jmp(&skip, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 751 | PrepareForBailout(expr, TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 752 | if (should_normalize) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 753 | __ cmp(eax, isolate()->factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 754 | Split(equal, if_true, if_false, NULL); |
| 755 | __ bind(&skip); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 760 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 761 | // 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] | 762 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 763 | if (generate_debug_code_) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 764 | // Check that we're not inside a with or catch context. |
| 765 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 766 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
| 767 | __ Check(not_equal, "Declaration in with context."); |
| 768 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
| 769 | __ Check(not_equal, "Declaration in catch context."); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | |
| 774 | void FullCodeGenerator::VisitVariableDeclaration( |
| 775 | VariableDeclaration* declaration) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 776 | // If it was not possible to allocate the variable at compile time, we |
| 777 | // need to "declare" it at runtime to make sure it actually exists in the |
| 778 | // local context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 779 | VariableProxy* proxy = declaration->proxy(); |
| 780 | VariableMode mode = declaration->mode(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 781 | Variable* variable = proxy->var(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 782 | bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 783 | switch (variable->location()) { |
| 784 | case Variable::UNALLOCATED: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 785 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 786 | globals_->Add(variable->binding_needs_init() |
| 787 | ? isolate()->factory()->the_hole_value() |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 788 | : isolate()->factory()->undefined_value(), zone()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 789 | break; |
| 790 | |
| 791 | case Variable::PARAMETER: |
| 792 | case Variable::LOCAL: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 793 | if (hole_init) { |
| 794 | Comment cmnt(masm_, "[ VariableDeclaration"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 795 | __ mov(StackOperand(variable), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 796 | Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 797 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 798 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 799 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 800 | case Variable::CONTEXT: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 801 | if (hole_init) { |
| 802 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 803 | EmitDebugCheckDeclarationContext(variable); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 804 | __ mov(ContextOperand(esi, variable->index()), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 805 | Immediate(isolate()->factory()->the_hole_value())); |
| 806 | // No write barrier since the hole value is in old space. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 807 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 808 | } |
| 809 | break; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 810 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 811 | case Variable::LOOKUP: { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 812 | Comment cmnt(masm_, "[ VariableDeclaration"); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 813 | __ push(esi); |
| 814 | __ push(Immediate(variable->name())); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 815 | // VariableDeclaration nodes are always introduced in one of four modes. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 816 | ASSERT(IsDeclaredVariableMode(mode)); |
| 817 | PropertyAttributes attr = |
| 818 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 819 | __ push(Immediate(Smi::FromInt(attr))); |
| 820 | // Push initial value, if any. |
| 821 | // Note: For variables we must not push an initial value (such as |
| 822 | // 'undefined') because we may have a (legal) redeclaration and we |
| 823 | // must not destroy the current value. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 824 | if (hole_init) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 825 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 826 | } else { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 827 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 828 | } |
| 829 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 830 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 836 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 837 | FunctionDeclaration* declaration) { |
| 838 | VariableProxy* proxy = declaration->proxy(); |
| 839 | Variable* variable = proxy->var(); |
| 840 | switch (variable->location()) { |
| 841 | case Variable::UNALLOCATED: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 842 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 843 | Handle<SharedFunctionInfo> function = |
| 844 | Compiler::BuildFunctionInfo(declaration->fun(), script()); |
| 845 | // Check for stack-overflow exception. |
| 846 | if (function.is_null()) return SetStackOverflow(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 847 | globals_->Add(function, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 848 | break; |
| 849 | } |
| 850 | |
| 851 | case Variable::PARAMETER: |
| 852 | case Variable::LOCAL: { |
| 853 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 854 | VisitForAccumulatorValue(declaration->fun()); |
| 855 | __ mov(StackOperand(variable), result_register()); |
| 856 | break; |
| 857 | } |
| 858 | |
| 859 | case Variable::CONTEXT: { |
| 860 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 861 | EmitDebugCheckDeclarationContext(variable); |
| 862 | VisitForAccumulatorValue(declaration->fun()); |
| 863 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 864 | // We know that we have written a function, which is not a smi. |
| 865 | __ RecordWriteContextSlot(esi, |
| 866 | Context::SlotOffset(variable->index()), |
| 867 | result_register(), |
| 868 | ecx, |
| 869 | kDontSaveFPRegs, |
| 870 | EMIT_REMEMBERED_SET, |
| 871 | OMIT_SMI_CHECK); |
| 872 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | case Variable::LOOKUP: { |
| 877 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 878 | __ push(esi); |
| 879 | __ push(Immediate(variable->name())); |
| 880 | __ push(Immediate(Smi::FromInt(NONE))); |
| 881 | VisitForStackValue(declaration->fun()); |
| 882 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 883 | break; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 890 | Variable* variable = declaration->proxy()->var(); |
| 891 | ASSERT(variable->location() == Variable::CONTEXT); |
| 892 | ASSERT(variable->interface()->IsFrozen()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 893 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 894 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 895 | EmitDebugCheckDeclarationContext(variable); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 896 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 897 | // Load instance object. |
| 898 | __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 899 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 900 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 901 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 902 | // Assign it. |
| 903 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 904 | // We know that we have written a module, which is not a smi. |
| 905 | __ RecordWriteContextSlot(esi, |
| 906 | Context::SlotOffset(variable->index()), |
| 907 | eax, |
| 908 | ecx, |
| 909 | kDontSaveFPRegs, |
| 910 | EMIT_REMEMBERED_SET, |
| 911 | OMIT_SMI_CHECK); |
| 912 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 913 | |
| 914 | // Traverse into body. |
| 915 | Visit(declaration->module()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | |
| 919 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 920 | VariableProxy* proxy = declaration->proxy(); |
| 921 | Variable* variable = proxy->var(); |
| 922 | switch (variable->location()) { |
| 923 | case Variable::UNALLOCATED: |
| 924 | // TODO(rossberg) |
| 925 | break; |
| 926 | |
| 927 | case Variable::CONTEXT: { |
| 928 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 929 | EmitDebugCheckDeclarationContext(variable); |
| 930 | // TODO(rossberg) |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | case Variable::PARAMETER: |
| 935 | case Variable::LOCAL: |
| 936 | case Variable::LOOKUP: |
| 937 | UNREACHABLE(); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
| 942 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 943 | // TODO(rossberg) |
| 944 | } |
| 945 | |
| 946 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 947 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 948 | // Call the runtime to declare the globals. |
| 949 | __ push(esi); // The context is the first argument. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 950 | __ Push(pairs); |
| 951 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 952 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 953 | // Return value is ignored. |
| 954 | } |
| 955 | |
| 956 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 957 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 958 | // Call the runtime to declare the modules. |
| 959 | __ Push(descriptions); |
| 960 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 961 | // Return value is ignored. |
| 962 | } |
| 963 | |
| 964 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 965 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 966 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 967 | Breakable nested_statement(this, stmt); |
| 968 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 969 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 970 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 971 | VisitForStackValue(stmt->tag()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 972 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 973 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 974 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 975 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 976 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 977 | Label next_test; // Recycled for each test. |
| 978 | // Compile all the tests with branches to their bodies. |
| 979 | for (int i = 0; i < clauses->length(); i++) { |
| 980 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 981 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 982 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 983 | // The default is not a test, but remember it as final fall through. |
| 984 | if (clause->is_default()) { |
| 985 | default_clause = clause; |
| 986 | continue; |
| 987 | } |
| 988 | |
| 989 | Comment cmnt(masm_, "[ Case comparison"); |
| 990 | __ bind(&next_test); |
| 991 | next_test.Unuse(); |
| 992 | |
| 993 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 994 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 995 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 996 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 997 | __ mov(edx, Operand(esp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 998 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 999 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1000 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1001 | Label slow_case; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1002 | __ mov(ecx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1003 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1004 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1005 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1006 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1007 | __ j(not_equal, &next_test); |
| 1008 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1009 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1010 | __ bind(&slow_case); |
| 1011 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1013 | // Record position before stub call for type feedback. |
| 1014 | SetSourcePosition(clause->position()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1015 | Handle<Code> ic = CompareIC::GetUninitialized(Token::EQ_STRICT); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1016 | CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1017 | patch_site.EmitPatchInfo(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1018 | __ test(eax, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1019 | __ j(not_equal, &next_test); |
| 1020 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1021 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | // Discard the test value and jump to the default if present, otherwise to |
| 1025 | // the end of the statement. |
| 1026 | __ bind(&next_test); |
| 1027 | __ Drop(1); // Switch value is no longer needed. |
| 1028 | if (default_clause == NULL) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1029 | __ jmp(nested_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1030 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1031 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // Compile all the case bodies. |
| 1035 | for (int i = 0; i < clauses->length(); i++) { |
| 1036 | Comment cmnt(masm_, "[ Case body"); |
| 1037 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1038 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1039 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1040 | VisitStatements(clause->statements()); |
| 1041 | } |
| 1042 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1043 | __ bind(nested_statement.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1044 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1049 | Comment cmnt(masm_, "[ ForInStatement"); |
| 1050 | SetStatementPosition(stmt); |
| 1051 | |
| 1052 | Label loop, exit; |
| 1053 | ForIn loop_statement(this, stmt); |
| 1054 | increment_loop_depth(); |
| 1055 | |
| 1056 | // Get the object to enumerate over. Both SpiderMonkey and JSC |
| 1057 | // ignore null and undefined in contrast to the specification; see |
| 1058 | // ECMA-262 section 12.6.4. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1059 | VisitForAccumulatorValue(stmt->enumerable()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1060 | __ cmp(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1061 | __ j(equal, &exit); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1062 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1063 | __ j(equal, &exit); |
| 1064 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1065 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1066 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1067 | // Convert the object to a JS object. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1068 | Label convert, done_convert; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1069 | __ JumpIfSmi(eax, &convert, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1070 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1071 | __ j(above_equal, &done_convert, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1072 | __ bind(&convert); |
| 1073 | __ push(eax); |
| 1074 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1075 | __ bind(&done_convert); |
| 1076 | __ push(eax); |
| 1077 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1078 | // Check for proxies. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1079 | Label call_runtime, use_cache, fixed_array; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1080 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1081 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1082 | __ j(below_equal, &call_runtime); |
| 1083 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1084 | // Check cache validity in generated code. This is a fast case for |
| 1085 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1086 | // guarantee cache validity, call the runtime system to check cache |
| 1087 | // validity or get the property names in a fixed array. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1088 | __ CheckEnumCache(&call_runtime); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1089 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1090 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1091 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1092 | |
| 1093 | // Get the set of properties to enumerate. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1094 | __ bind(&call_runtime); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1095 | __ push(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1096 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1097 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1098 | isolate()->factory()->meta_map()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1099 | __ j(not_equal, &fixed_array); |
| 1100 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1101 | |
| 1102 | // 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] | 1103 | Label no_descriptors; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1104 | __ bind(&use_cache); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1105 | |
| 1106 | __ EnumLength(edx, eax); |
| 1107 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1108 | __ j(equal, &no_descriptors); |
| 1109 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1110 | __ LoadInstanceDescriptors(eax, ecx); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1111 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1112 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1113 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1114 | // Set up the four remaining stack slots. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1115 | __ push(eax); // Map. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1116 | __ push(ecx); // Enumeration cache. |
| 1117 | __ 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] | 1118 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1119 | __ jmp(&loop); |
| 1120 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1121 | __ bind(&no_descriptors); |
| 1122 | __ add(esp, Immediate(kPointerSize)); |
| 1123 | __ jmp(&exit); |
| 1124 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1125 | // 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] | 1126 | Label non_proxy; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1127 | __ bind(&fixed_array); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1128 | |
| 1129 | Handle<JSGlobalPropertyCell> cell = |
| 1130 | isolate()->factory()->NewJSGlobalPropertyCell( |
| 1131 | Handle<Object>( |
| 1132 | Smi::FromInt(TypeFeedbackCells::kForInFastCaseMarker))); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1133 | RecordTypeFeedbackCell(stmt->ForInFeedbackId(), cell); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1134 | __ LoadHeapObject(ebx, cell); |
| 1135 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 1136 | Immediate(Smi::FromInt(TypeFeedbackCells::kForInSlowCaseMarker))); |
| 1137 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1138 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1139 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1140 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1141 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1142 | __ j(above, &non_proxy); |
| 1143 | __ mov(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
| 1144 | __ bind(&non_proxy); |
| 1145 | __ push(ebx); // Smi |
| 1146 | __ push(eax); // Array |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1147 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1148 | __ push(eax); // Fixed array length (as smi). |
| 1149 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1150 | |
| 1151 | // Generate code for doing the condition check. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1152 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1153 | __ bind(&loop); |
| 1154 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1155 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1156 | __ j(above_equal, loop_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1157 | |
| 1158 | // Get the current entry of the array into register ebx. |
| 1159 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1160 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1161 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1162 | // 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] | 1163 | // permanent slow case into register edx. |
| 1164 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1165 | |
| 1166 | // 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] | 1167 | // If not, we may have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1168 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1169 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1170 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1171 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1172 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1173 | // For proxies, no filtering is done. |
| 1174 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1175 | ASSERT(Smi::FromInt(0) == 0); |
| 1176 | __ test(edx, edx); |
| 1177 | __ j(zero, &update_each); |
| 1178 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1179 | // Convert the entry to a string or null if it isn't a property |
| 1180 | // anymore. If the property has been removed while iterating, we |
| 1181 | // just skip it. |
| 1182 | __ push(ecx); // Enumerable. |
| 1183 | __ push(ebx); // Current entry. |
| 1184 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1185 | __ test(eax, eax); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1186 | __ j(equal, loop_statement.continue_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1187 | __ mov(ebx, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1188 | |
| 1189 | // Update the 'each' property or variable from the possibly filtered |
| 1190 | // entry in register ebx. |
| 1191 | __ bind(&update_each); |
| 1192 | __ mov(result_register(), ebx); |
| 1193 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1194 | { EffectContext context(this); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1195 | EmitAssignment(stmt->each()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1196 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1197 | |
| 1198 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1199 | Visit(stmt->body()); |
| 1200 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1201 | // Generate code for going to the next element by incrementing the |
| 1202 | // index (smi) stored on top of the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1203 | __ bind(loop_statement.continue_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1204 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1205 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1206 | EmitStackCheck(stmt, &loop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1207 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1208 | |
| 1209 | // Remove the pointers stored on the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1210 | __ bind(loop_statement.break_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1211 | __ add(esp, Immediate(5 * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1212 | |
| 1213 | // Exit and decrement the loop depth. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1214 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1215 | __ bind(&exit); |
| 1216 | decrement_loop_depth(); |
| 1217 | } |
| 1218 | |
| 1219 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1220 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1221 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1222 | // Use the fast case closure allocation code that allocates in new |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | // space for nested functions that don't need literals cloning. If |
| 1224 | // we're running with the --always-opt or the --prepare-always-opt |
| 1225 | // flag, we need to use the runtime function so that the new function |
| 1226 | // we are creating here gets a chance to have its code optimized and |
| 1227 | // doesn't just get a copy of the existing unoptimized code. |
| 1228 | if (!FLAG_always_opt && |
| 1229 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1230 | !pretenure && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1231 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1232 | info->num_literals() == 0) { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1233 | FastNewClosureStub stub(info->language_mode()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1234 | __ push(Immediate(info)); |
| 1235 | __ CallStub(&stub); |
| 1236 | } else { |
| 1237 | __ push(esi); |
| 1238 | __ push(Immediate(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1239 | __ push(Immediate(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1240 | ? isolate()->factory()->true_value() |
| 1241 | : isolate()->factory()->false_value())); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1242 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1243 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1244 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | |
| 1248 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1249 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1250 | EmitVariableLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1254 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
| 1255 | TypeofState typeof_state, |
| 1256 | Label* slow) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1257 | Register context = esi; |
| 1258 | Register temp = edx; |
| 1259 | |
| 1260 | Scope* s = scope(); |
| 1261 | while (s != NULL) { |
| 1262 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1263 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1264 | // Check that extension is NULL. |
| 1265 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1266 | Immediate(0)); |
| 1267 | __ j(not_equal, slow); |
| 1268 | } |
| 1269 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1270 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1271 | // Walk the rest of the chain without clobbering esi. |
| 1272 | context = temp; |
| 1273 | } |
| 1274 | // If no outer scope calls eval, we do not need to check more |
| 1275 | // context extensions. If we have reached an eval scope, we check |
| 1276 | // all extensions from this point. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1277 | 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] | 1278 | s = s->outer_scope(); |
| 1279 | } |
| 1280 | |
| 1281 | if (s != NULL && s->is_eval_scope()) { |
| 1282 | // Loop up the context chain. There is no frame effect so it is |
| 1283 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1284 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1285 | if (!context.is(temp)) { |
| 1286 | __ mov(temp, context); |
| 1287 | } |
| 1288 | __ bind(&next); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1289 | // Terminate at native context. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1290 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1291 | Immediate(isolate()->factory()->native_context_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1292 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1293 | // Check that extension is NULL. |
| 1294 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1295 | __ j(not_equal, slow); |
| 1296 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1297 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1298 | __ jmp(&next); |
| 1299 | __ bind(&fast); |
| 1300 | } |
| 1301 | |
| 1302 | // All extension objects were empty and it is safe to use a global |
| 1303 | // load IC call. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1304 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1305 | __ mov(ecx, var->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1306 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1307 | RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF) |
| 1308 | ? RelocInfo::CODE_TARGET |
| 1309 | : RelocInfo::CODE_TARGET_CONTEXT; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1310 | CallIC(ic, mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1314 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1315 | Label* slow) { |
| 1316 | ASSERT(var->IsContextSlot()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1317 | Register context = esi; |
| 1318 | Register temp = ebx; |
| 1319 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1320 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1321 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1322 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1323 | // Check that extension is NULL. |
| 1324 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1325 | Immediate(0)); |
| 1326 | __ j(not_equal, slow); |
| 1327 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1328 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1329 | // Walk the rest of the chain without clobbering esi. |
| 1330 | context = temp; |
| 1331 | } |
| 1332 | } |
| 1333 | // Check that last extension is NULL. |
| 1334 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1335 | __ j(not_equal, slow); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1336 | |
| 1337 | // This function is used only for loads, not stores, so it's safe to |
| 1338 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1339 | // destroy the esi register). |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1340 | return ContextOperand(context, var->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1344 | void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| 1345 | TypeofState typeof_state, |
| 1346 | Label* slow, |
| 1347 | Label* done) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1348 | // Generate fast-case code for variables that might be shadowed by |
| 1349 | // eval-introduced variables. Eval is used a lot without |
| 1350 | // introducing variables. In those cases, we do not want to |
| 1351 | // perform a runtime call for all variables in the scope |
| 1352 | // containing the eval. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1353 | if (var->mode() == DYNAMIC_GLOBAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1354 | EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1355 | __ jmp(done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1356 | } else if (var->mode() == DYNAMIC_LOCAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1357 | Variable* local = var->local_if_not_shadowed(); |
| 1358 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1359 | if (local->mode() == LET || |
| 1360 | local->mode() == CONST || |
| 1361 | local->mode() == CONST_HARMONY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1362 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1363 | __ j(not_equal, done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1364 | if (local->mode() == CONST) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1365 | __ mov(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1366 | } else { // LET || CONST_HARMONY |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1367 | __ push(Immediate(var->name())); |
| 1368 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1369 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1370 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1371 | __ jmp(done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1376 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1377 | // Record position before possible IC call. |
| 1378 | SetSourcePosition(proxy->position()); |
| 1379 | Variable* var = proxy->var(); |
| 1380 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1381 | // Three cases: global variables, lookup variables, and all other types of |
| 1382 | // variables. |
| 1383 | switch (var->location()) { |
| 1384 | case Variable::UNALLOCATED: { |
| 1385 | Comment cmnt(masm_, "Global variable"); |
| 1386 | // Use inline caching. Variable name is passed in ecx and the global |
| 1387 | // object in eax. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1388 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1389 | __ mov(ecx, var->name()); |
| 1390 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1391 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1392 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1393 | break; |
| 1394 | } |
| 1395 | |
| 1396 | case Variable::PARAMETER: |
| 1397 | case Variable::LOCAL: |
| 1398 | case Variable::CONTEXT: { |
| 1399 | Comment cmnt(masm_, var->IsContextSlot() |
| 1400 | ? "Context variable" |
| 1401 | : "Stack variable"); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1402 | if (var->binding_needs_init()) { |
| 1403 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1404 | // refers to a potential outside binding. Currently those bindings are |
| 1405 | // always looked up dynamically, i.e. in that case |
| 1406 | // var->location() == LOOKUP. |
| 1407 | // always holds. |
| 1408 | ASSERT(var->scope() != NULL); |
| 1409 | |
| 1410 | // Check if the binding really needs an initialization check. The check |
| 1411 | // can be skipped in the following situation: we have a LET or CONST |
| 1412 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1413 | // the same declaration scope (i.e. they are both in global code, in the |
| 1414 | // same function or in the same eval code) and the VariableProxy is in |
| 1415 | // the source physically located after the initializer of the variable. |
| 1416 | // |
| 1417 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1418 | // mode because const variables may be declared but never initialized: |
| 1419 | // if (false) { const x; }; var y = x; |
| 1420 | // |
| 1421 | // The condition on the declaration scopes is a conservative check for |
| 1422 | // nested functions that access a binding and are called before the |
| 1423 | // binding is initialized: |
| 1424 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1425 | // |
| 1426 | bool skip_init_check; |
| 1427 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1428 | skip_init_check = false; |
jkummerow@chromium.org | ac45fed | 2011-11-07 13:11:02 +0000 | [diff] [blame] | 1429 | } else { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1430 | // Check that we always have valid source position. |
| 1431 | ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1432 | ASSERT(proxy->position() != RelocInfo::kNoPosition); |
| 1433 | skip_init_check = var->mode() != CONST && |
| 1434 | var->initializer_position() < proxy->position(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1435 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1436 | |
| 1437 | if (!skip_init_check) { |
| 1438 | // Let and const need a read barrier. |
| 1439 | Label done; |
| 1440 | GetVar(eax, var); |
| 1441 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1442 | __ j(not_equal, &done, Label::kNear); |
| 1443 | if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1444 | // Throw a reference error when using an uninitialized let/const |
| 1445 | // binding in harmony mode. |
| 1446 | __ push(Immediate(var->name())); |
| 1447 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1448 | } else { |
| 1449 | // Uninitalized const bindings outside of harmony mode are unholed. |
| 1450 | ASSERT(var->mode() == CONST); |
| 1451 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1452 | } |
| 1453 | __ bind(&done); |
| 1454 | context()->Plug(eax); |
| 1455 | break; |
| 1456 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1457 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1458 | context()->Plug(var); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1459 | break; |
| 1460 | } |
| 1461 | |
| 1462 | case Variable::LOOKUP: { |
| 1463 | Label done, slow; |
| 1464 | // Generate code for loading from variables potentially shadowed |
| 1465 | // by eval-introduced variables. |
| 1466 | EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1467 | __ bind(&slow); |
| 1468 | Comment cmnt(masm_, "Lookup variable"); |
| 1469 | __ push(esi); // Context. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1470 | __ push(Immediate(var->name())); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1471 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1472 | __ bind(&done); |
| 1473 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1474 | break; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1475 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | |
| 1480 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1481 | Comment cmnt(masm_, "[ RegExpLiteral"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1482 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1483 | // Registers will be used as follows: |
| 1484 | // edi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1485 | // ecx = literals array. |
| 1486 | // ebx = regexp literal. |
| 1487 | // eax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1488 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1489 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1490 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1491 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1492 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1493 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1494 | __ j(not_equal, &materialized, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1495 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1496 | // Create regexp literal using runtime function |
| 1497 | // Result will be in eax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1498 | __ push(ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1499 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1500 | __ push(Immediate(expr->pattern())); |
| 1501 | __ push(Immediate(expr->flags())); |
| 1502 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1503 | __ mov(ebx, eax); |
| 1504 | |
| 1505 | __ bind(&materialized); |
| 1506 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1507 | Label allocated, runtime_allocate; |
| 1508 | __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
| 1509 | __ jmp(&allocated); |
| 1510 | |
| 1511 | __ bind(&runtime_allocate); |
| 1512 | __ push(ebx); |
| 1513 | __ push(Immediate(Smi::FromInt(size))); |
| 1514 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1515 | __ pop(ebx); |
| 1516 | |
| 1517 | __ bind(&allocated); |
| 1518 | // Copy the content into the newly allocated memory. |
| 1519 | // (Unroll copy loop once for better throughput). |
| 1520 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1521 | __ mov(edx, FieldOperand(ebx, i)); |
| 1522 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1523 | __ mov(FieldOperand(eax, i), edx); |
| 1524 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1525 | } |
| 1526 | if ((size % (2 * kPointerSize)) != 0) { |
| 1527 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1528 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1529 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1530 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1534 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1535 | if (expression == NULL) { |
| 1536 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1537 | } else { |
| 1538 | VisitForStackValue(expression); |
| 1539 | } |
| 1540 | } |
| 1541 | |
| 1542 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1543 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1544 | Comment cmnt(masm_, "[ ObjectLiteral"); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1545 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1546 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1547 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1548 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1549 | __ push(Immediate(constant_properties)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1550 | int flags = expr->fast_elements() |
| 1551 | ? ObjectLiteral::kFastElements |
| 1552 | : ObjectLiteral::kNoFlags; |
| 1553 | flags |= expr->has_function() |
| 1554 | ? ObjectLiteral::kHasFunction |
| 1555 | : ObjectLiteral::kNoFlags; |
| 1556 | __ push(Immediate(Smi::FromInt(flags))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1557 | int properties_count = constant_properties->length() / 2; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1558 | if (expr->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1559 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1560 | } else if (flags != ObjectLiteral::kFastElements || |
| 1561 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1562 | __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1563 | } else { |
| 1564 | FastCloneShallowObjectStub stub(properties_count); |
| 1565 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | // If result_saved is true the result is on top of the stack. If |
| 1569 | // result_saved is false the result is in eax. |
| 1570 | bool result_saved = false; |
| 1571 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1572 | // Mark all computed expressions that are bound to a key that |
| 1573 | // is shadowed by a later occurrence of the same key. For the |
| 1574 | // marked expressions, no store code is emitted. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1575 | expr->CalculateEmitStore(zone()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1576 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1577 | AccessorTable accessor_table(zone()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1578 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1579 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1580 | if (property->IsCompileTimeValue()) continue; |
| 1581 | |
| 1582 | Literal* key = property->key(); |
| 1583 | Expression* value = property->value(); |
| 1584 | if (!result_saved) { |
| 1585 | __ push(eax); // Save result on the stack |
| 1586 | result_saved = true; |
| 1587 | } |
| 1588 | switch (property->kind()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1589 | case ObjectLiteral::Property::CONSTANT: |
| 1590 | UNREACHABLE(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1591 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1592 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1593 | // Fall through. |
| 1594 | case ObjectLiteral::Property::COMPUTED: |
| 1595 | if (key->handle()->IsSymbol()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1596 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1597 | VisitForAccumulatorValue(value); |
| 1598 | __ mov(ecx, Immediate(key->handle())); |
| 1599 | __ mov(edx, Operand(esp, 0)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1600 | Handle<Code> ic = is_classic_mode() |
| 1601 | ? isolate()->builtins()->StoreIC_Initialize() |
| 1602 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1603 | CallIC(ic, RelocInfo::CODE_TARGET, key->LiteralFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1604 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1605 | } else { |
| 1606 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1607 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | } |
| 1610 | // Fall through. |
| 1611 | case ObjectLiteral::Property::PROTOTYPE: |
| 1612 | __ push(Operand(esp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1613 | VisitForStackValue(key); |
| 1614 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1615 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1616 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1617 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1618 | } else { |
| 1619 | __ Drop(3); |
| 1620 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1621 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1622 | case ObjectLiteral::Property::GETTER: |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1623 | accessor_table.lookup(key)->second->getter = value; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1624 | break; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1625 | case ObjectLiteral::Property::SETTER: |
| 1626 | accessor_table.lookup(key)->second->setter = value; |
| 1627 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1628 | } |
| 1629 | } |
| 1630 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1631 | // Emit code to define accessors, using only a single call to the runtime for |
| 1632 | // each pair of corresponding getters and setters. |
| 1633 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1634 | it != accessor_table.end(); |
| 1635 | ++it) { |
| 1636 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1637 | VisitForStackValue(it->first); |
| 1638 | EmitAccessor(it->second->getter); |
| 1639 | EmitAccessor(it->second->setter); |
| 1640 | __ push(Immediate(Smi::FromInt(NONE))); |
| 1641 | __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1642 | } |
| 1643 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1644 | if (expr->has_function()) { |
| 1645 | ASSERT(result_saved); |
| 1646 | __ push(Operand(esp, 0)); |
| 1647 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1648 | } |
| 1649 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1650 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1651 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1652 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1653 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1659 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1660 | |
| 1661 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1662 | int length = subexprs->length(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1663 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1664 | ASSERT_EQ(2, constant_elements->length()); |
| 1665 | ElementsKind constant_elements_kind = |
| 1666 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1667 | bool has_constant_fast_elements = |
| 1668 | IsFastObjectElementsKind(constant_elements_kind); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1669 | Handle<FixedArrayBase> constant_elements_values( |
| 1670 | FixedArrayBase::cast(constant_elements->get(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1671 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1672 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1673 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1674 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1675 | __ push(Immediate(constant_elements)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1676 | Heap* heap = isolate()->heap(); |
| 1677 | if (has_constant_fast_elements && |
| 1678 | constant_elements_values->map() == heap->fixed_cow_array_map()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1679 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1680 | // change, so it's possible to specialize the stub in advance. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1681 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1682 | FastCloneShallowArrayStub stub( |
| 1683 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
| 1684 | length); |
| 1685 | __ CallStub(&stub); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1686 | } else if (expr->depth() > 1) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1687 | __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1688 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1689 | __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1690 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1691 | ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1692 | FLAG_smi_only_arrays); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1693 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1694 | // change, so it's possible to specialize the stub in advance. |
| 1695 | FastCloneShallowArrayStub::Mode mode = has_constant_fast_elements |
| 1696 | ? FastCloneShallowArrayStub::CLONE_ELEMENTS |
| 1697 | : FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1698 | FastCloneShallowArrayStub stub(mode, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1699 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | bool result_saved = false; // Is the result saved to the stack? |
| 1703 | |
| 1704 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1705 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1706 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1707 | Expression* subexpr = subexprs->at(i); |
| 1708 | // If the subexpression is a literal or a simple materialized literal it |
| 1709 | // is already set in the cloned array. |
| 1710 | if (subexpr->AsLiteral() != NULL || |
| 1711 | CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1712 | continue; |
| 1713 | } |
| 1714 | |
| 1715 | if (!result_saved) { |
| 1716 | __ push(eax); |
| 1717 | result_saved = true; |
| 1718 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1719 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1720 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1721 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1722 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1723 | // cannot transition and don't need to call the runtime stub. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1724 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1725 | __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1726 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1727 | // Store the subexpression value in the array's elements. |
| 1728 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1729 | // Update the write barrier for the array store. |
| 1730 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1731 | kDontSaveFPRegs, |
| 1732 | EMIT_REMEMBERED_SET, |
| 1733 | INLINE_SMI_CHECK); |
| 1734 | } else { |
| 1735 | // Store the subexpression value in the array's elements. |
| 1736 | __ mov(ebx, Operand(esp, 0)); // Copy of array literal. |
| 1737 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 1738 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
| 1739 | __ mov(edx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1740 | StoreArrayLiteralElementStub stub; |
| 1741 | __ CallStub(&stub); |
| 1742 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1743 | |
| 1744 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1748 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1749 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1750 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1751 | } |
| 1752 | } |
| 1753 | |
| 1754 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1755 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1756 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1757 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1758 | // on the left-hand side. |
| 1759 | if (!expr->target()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1760 | VisitForEffect(expr->target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1761 | return; |
| 1762 | } |
| 1763 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1764 | // 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] | 1765 | // slot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1766 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1767 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1768 | Property* property = expr->target()->AsProperty(); |
| 1769 | if (property != NULL) { |
| 1770 | assign_type = (property->key()->IsPropertyName()) |
| 1771 | ? NAMED_PROPERTY |
| 1772 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | // Evaluate LHS expression. |
| 1776 | switch (assign_type) { |
| 1777 | case VARIABLE: |
| 1778 | // Nothing to do here. |
| 1779 | break; |
| 1780 | case NAMED_PROPERTY: |
| 1781 | if (expr->is_compound()) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1782 | // We need the receiver both on the stack and in edx. |
| 1783 | VisitForStackValue(property->obj()); |
| 1784 | __ mov(edx, Operand(esp, 0)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1785 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1786 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1787 | } |
| 1788 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1789 | case KEYED_PROPERTY: { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1790 | if (expr->is_compound()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1791 | VisitForStackValue(property->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1792 | VisitForStackValue(property->key()); |
| 1793 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 1794 | __ mov(ecx, Operand(esp, 0)); // Key. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1795 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1796 | VisitForStackValue(property->obj()); |
| 1797 | VisitForStackValue(property->key()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1798 | } |
| 1799 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1800 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1803 | // For compound assignments we need another deoptimization point after the |
| 1804 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1805 | if (expr->is_compound()) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1806 | AccumulatorValueContext result_context(this); |
| 1807 | { AccumulatorValueContext left_operand_context(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1808 | switch (assign_type) { |
| 1809 | case VARIABLE: |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1810 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1811 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | case NAMED_PROPERTY: |
| 1814 | EmitNamedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1815 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1816 | break; |
| 1817 | case KEYED_PROPERTY: |
| 1818 | EmitKeyedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1819 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1822 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1823 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1824 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1825 | __ push(eax); // Left operand goes on the stack. |
| 1826 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1827 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1828 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1829 | ? OVERWRITE_RIGHT |
| 1830 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1831 | SetSourcePosition(expr->position() + 1); |
| 1832 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1833 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1834 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1835 | mode, |
| 1836 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1837 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1838 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1839 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1840 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1841 | |
| 1842 | // Deoptimization point in case the binary operation may have side effects. |
| 1843 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1844 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1845 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | // Record source position before possible IC call. |
| 1849 | SetSourcePosition(expr->position()); |
| 1850 | |
| 1851 | // Store the value. |
| 1852 | switch (assign_type) { |
| 1853 | case VARIABLE: |
| 1854 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1855 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1856 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1857 | context()->Plug(eax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1858 | break; |
| 1859 | case NAMED_PROPERTY: |
| 1860 | EmitNamedPropertyAssignment(expr); |
| 1861 | break; |
| 1862 | case KEYED_PROPERTY: |
| 1863 | EmitKeyedPropertyAssignment(expr); |
| 1864 | break; |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1869 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 1870 | SetSourcePosition(prop->position()); |
| 1871 | Literal* key = prop->key()->AsLiteral(); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1872 | ASSERT(!key->handle()->IsSmi()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1873 | __ mov(ecx, Immediate(key->handle())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1874 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1875 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1876 | } |
| 1877 | |
| 1878 | |
| 1879 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 1880 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1881 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1882 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1886 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1887 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1888 | OverwriteMode mode, |
| 1889 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1890 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1891 | // Do combined smi check of the operands. Left operand is on the |
| 1892 | // stack. Right operand is in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1893 | Label smi_case, done, stub_call; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1894 | __ pop(edx); |
| 1895 | __ mov(ecx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1896 | __ or_(eax, edx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1897 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1898 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1899 | |
| 1900 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1901 | __ mov(eax, ecx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1902 | BinaryOpStub stub(op, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1903 | CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, |
| 1904 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1905 | patch_site.EmitPatchInfo(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1906 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1907 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1908 | // Smi case. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1909 | __ bind(&smi_case); |
| 1910 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 1911 | |
| 1912 | switch (op) { |
| 1913 | case Token::SAR: |
| 1914 | __ SmiUntag(eax); |
| 1915 | __ SmiUntag(ecx); |
| 1916 | __ sar_cl(eax); // No checks of result necessary |
| 1917 | __ SmiTag(eax); |
| 1918 | break; |
| 1919 | case Token::SHL: { |
| 1920 | Label result_ok; |
| 1921 | __ SmiUntag(eax); |
| 1922 | __ SmiUntag(ecx); |
| 1923 | __ shl_cl(eax); |
| 1924 | // Check that the *signed* result fits in a smi. |
| 1925 | __ cmp(eax, 0xc0000000); |
| 1926 | __ j(positive, &result_ok); |
| 1927 | __ SmiTag(ecx); |
| 1928 | __ jmp(&stub_call); |
| 1929 | __ bind(&result_ok); |
| 1930 | __ SmiTag(eax); |
| 1931 | break; |
| 1932 | } |
| 1933 | case Token::SHR: { |
| 1934 | Label result_ok; |
| 1935 | __ SmiUntag(eax); |
| 1936 | __ SmiUntag(ecx); |
| 1937 | __ shr_cl(eax); |
| 1938 | __ test(eax, Immediate(0xc0000000)); |
| 1939 | __ j(zero, &result_ok); |
| 1940 | __ SmiTag(ecx); |
| 1941 | __ jmp(&stub_call); |
| 1942 | __ bind(&result_ok); |
| 1943 | __ SmiTag(eax); |
| 1944 | break; |
| 1945 | } |
| 1946 | case Token::ADD: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1947 | __ add(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1948 | __ j(overflow, &stub_call); |
| 1949 | break; |
| 1950 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1951 | __ sub(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1952 | __ j(overflow, &stub_call); |
| 1953 | break; |
| 1954 | case Token::MUL: { |
| 1955 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1956 | __ imul(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1957 | __ j(overflow, &stub_call); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1958 | __ test(eax, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1959 | __ j(not_zero, &done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1960 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1961 | __ or_(ebx, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1962 | __ j(negative, &stub_call); |
| 1963 | break; |
| 1964 | } |
| 1965 | case Token::BIT_OR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1966 | __ or_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1967 | break; |
| 1968 | case Token::BIT_AND: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1969 | __ and_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1970 | break; |
| 1971 | case Token::BIT_XOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1972 | __ xor_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1973 | break; |
| 1974 | default: |
| 1975 | UNREACHABLE(); |
| 1976 | } |
| 1977 | |
| 1978 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1979 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1983 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 1984 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1985 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1986 | __ pop(edx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1987 | BinaryOpStub stub(op, mode); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1988 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1989 | CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, |
| 1990 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1991 | patch_site.EmitPatchInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1992 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1996 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1997 | // Invalid left-hand sides are rewritten to have a 'throw |
| 1998 | // ReferenceError' on the left-hand side. |
| 1999 | if (!expr->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2000 | VisitForEffect(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | // 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] | 2005 | // slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2006 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2007 | LhsKind assign_type = VARIABLE; |
| 2008 | Property* prop = expr->AsProperty(); |
| 2009 | if (prop != NULL) { |
| 2010 | assign_type = (prop->key()->IsPropertyName()) |
| 2011 | ? NAMED_PROPERTY |
| 2012 | : KEYED_PROPERTY; |
| 2013 | } |
| 2014 | |
| 2015 | switch (assign_type) { |
| 2016 | case VARIABLE: { |
| 2017 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2018 | EffectContext context(this); |
| 2019 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2020 | break; |
| 2021 | } |
| 2022 | case NAMED_PROPERTY: { |
| 2023 | __ push(eax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2024 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2025 | __ mov(edx, eax); |
| 2026 | __ pop(eax); // Restore value. |
| 2027 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2028 | Handle<Code> ic = is_classic_mode() |
| 2029 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2030 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2031 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2032 | break; |
| 2033 | } |
| 2034 | case KEYED_PROPERTY: { |
| 2035 | __ push(eax); // Preserve value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2036 | VisitForStackValue(prop->obj()); |
| 2037 | VisitForAccumulatorValue(prop->key()); |
| 2038 | __ mov(ecx, eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2039 | __ pop(edx); // Receiver. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2040 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2041 | Handle<Code> ic = is_classic_mode() |
| 2042 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2043 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2044 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2045 | break; |
| 2046 | } |
| 2047 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2048 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2052 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2053 | Token::Value op) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2054 | if (var->IsUnallocated()) { |
| 2055 | // Global var, const, or let. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2056 | __ mov(ecx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2057 | __ mov(edx, GlobalObjectOperand()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2058 | Handle<Code> ic = is_classic_mode() |
| 2059 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2060 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2061 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2062 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2063 | } else if (op == Token::INIT_CONST) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2064 | // Const initializers need a write barrier. |
| 2065 | ASSERT(!var->IsParameter()); // No const parameters. |
| 2066 | if (var->IsStackLocal()) { |
| 2067 | Label skip; |
| 2068 | __ mov(edx, StackOperand(var)); |
| 2069 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2070 | __ j(not_equal, &skip); |
| 2071 | __ mov(StackOperand(var), eax); |
| 2072 | __ bind(&skip); |
| 2073 | } else { |
| 2074 | ASSERT(var->IsContextSlot() || var->IsLookupSlot()); |
| 2075 | // Like var declarations, const declarations are hoisted to function |
| 2076 | // scope. However, unlike var initializers, const initializers are |
| 2077 | // able to drill a hole to that function context, even from inside a |
| 2078 | // 'with' context. We thus bypass the normal static scope lookup for |
| 2079 | // var->IsContextSlot(). |
| 2080 | __ push(eax); |
| 2081 | __ push(esi); |
| 2082 | __ push(Immediate(var->name())); |
| 2083 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2084 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2085 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2086 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2087 | // Non-initializing assignment to let variable needs a write barrier. |
| 2088 | if (var->IsLookupSlot()) { |
| 2089 | __ push(eax); // Value. |
| 2090 | __ push(esi); // Context. |
| 2091 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2092 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2093 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
| 2094 | } else { |
| 2095 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 2096 | Label assign; |
| 2097 | MemOperand location = VarOperand(var, ecx); |
| 2098 | __ mov(edx, location); |
| 2099 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2100 | __ j(not_equal, &assign, Label::kNear); |
| 2101 | __ push(Immediate(var->name())); |
| 2102 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2103 | __ bind(&assign); |
| 2104 | __ mov(location, eax); |
| 2105 | if (var->IsContextSlot()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2106 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2107 | int offset = Context::SlotOffset(var->index()); |
| 2108 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2109 | } |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2110 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2111 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2112 | } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
| 2113 | // Assignment to var or initializing assignment to let/const |
| 2114 | // in harmony mode. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2115 | if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 2116 | MemOperand location = VarOperand(var, ecx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2117 | if (generate_debug_code_ && op == Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2118 | // Check for an uninitialized let binding. |
| 2119 | __ mov(edx, location); |
| 2120 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2121 | __ Check(equal, "Let binding re-initialization."); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2122 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2123 | // Perform the assignment. |
| 2124 | __ mov(location, eax); |
| 2125 | if (var->IsContextSlot()) { |
| 2126 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2127 | int offset = Context::SlotOffset(var->index()); |
| 2128 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2129 | } |
| 2130 | } else { |
| 2131 | ASSERT(var->IsLookupSlot()); |
| 2132 | __ push(eax); // Value. |
| 2133 | __ push(esi); // Context. |
| 2134 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2135 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2136 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2137 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2138 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2139 | // Non-initializing assignments to consts are ignored. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2144 | // Assignment to a property, using a named store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2145 | // eax : value |
| 2146 | // esp[0] : receiver |
| 2147 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2148 | Property* prop = expr->target()->AsProperty(); |
| 2149 | ASSERT(prop != NULL); |
| 2150 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2151 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2152 | // Record source code position before IC call. |
| 2153 | SetSourcePosition(expr->position()); |
| 2154 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2155 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2156 | Handle<Code> ic = is_classic_mode() |
| 2157 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2158 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2159 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2160 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2161 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2162 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | |
| 2166 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2167 | // Assignment to a property, using a keyed store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2168 | // eax : value |
| 2169 | // esp[0] : key |
| 2170 | // esp[kPointerSize] : receiver |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2171 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2172 | __ pop(ecx); // Key. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2173 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2174 | // Record source code position before IC call. |
| 2175 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2176 | Handle<Code> ic = is_classic_mode() |
| 2177 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2178 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2179 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2180 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2181 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2182 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | |
| 2186 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2187 | Comment cmnt(masm_, "[ Property"); |
| 2188 | Expression* key = expr->key(); |
| 2189 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2190 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2191 | VisitForAccumulatorValue(expr->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2192 | __ mov(edx, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2193 | EmitNamedPropertyLoad(expr); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2194 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2195 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2196 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2197 | VisitForStackValue(expr->obj()); |
| 2198 | VisitForAccumulatorValue(expr->key()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2199 | __ pop(edx); // Object. |
| 2200 | __ mov(ecx, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2201 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2202 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2203 | } |
| 2204 | } |
| 2205 | |
| 2206 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2207 | void FullCodeGenerator::CallIC(Handle<Code> code, |
| 2208 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2209 | TypeFeedbackId ast_id) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2210 | ic_total_count_++; |
| 2211 | __ call(code, rmode, ast_id); |
| 2212 | } |
| 2213 | |
| 2214 | |
| 2215 | |
| 2216 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2217 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
| 2218 | Handle<Object> name, |
| 2219 | RelocInfo::Mode mode) { |
| 2220 | // Code common for calls using the IC. |
| 2221 | ZoneList<Expression*>* args = expr->arguments(); |
| 2222 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2223 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2224 | for (int i = 0; i < arg_count; i++) { |
| 2225 | VisitForStackValue(args->at(i)); |
| 2226 | } |
| 2227 | __ Set(ecx, Immediate(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2228 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2229 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2230 | SetSourcePosition(expr->position()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2231 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2232 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2233 | CallIC(ic, mode, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2234 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2235 | // Restore context register. |
| 2236 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2237 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2241 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2242 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2243 | // Load the key. |
| 2244 | VisitForAccumulatorValue(key); |
| 2245 | |
| 2246 | // Swap the name of the function and the receiver on the stack to follow |
| 2247 | // the calling convention for call ICs. |
| 2248 | __ pop(ecx); |
| 2249 | __ push(eax); |
| 2250 | __ push(ecx); |
| 2251 | |
| 2252 | // Load the arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2253 | ZoneList<Expression*>* args = expr->arguments(); |
| 2254 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2255 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2256 | for (int i = 0; i < arg_count; i++) { |
| 2257 | VisitForStackValue(args->at(i)); |
| 2258 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2259 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2260 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2261 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2262 | Handle<Code> ic = |
| 2263 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2264 | __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2265 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2266 | RecordJSReturnSite(expr); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2267 | // Restore context register. |
| 2268 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2269 | context()->DropAndPlug(1, eax); // Drop the key still on the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2273 | void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2274 | // Code common for calls using the call stub. |
| 2275 | ZoneList<Expression*>* args = expr->arguments(); |
| 2276 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2277 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2278 | for (int i = 0; i < arg_count; i++) { |
| 2279 | VisitForStackValue(args->at(i)); |
| 2280 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2281 | } |
| 2282 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2283 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2284 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2285 | // Record call targets in unoptimized code. |
| 2286 | flags = static_cast<CallFunctionFlags>(flags | RECORD_CALL_TARGET); |
| 2287 | Handle<Object> uninitialized = |
| 2288 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
| 2289 | Handle<JSGlobalPropertyCell> cell = |
| 2290 | isolate()->factory()->NewJSGlobalPropertyCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2291 | RecordTypeFeedbackCell(expr->CallFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2292 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2293 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2294 | CallFunctionStub stub(arg_count, flags); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2295 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2296 | __ CallStub(&stub, expr->CallFeedbackId()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2297 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2298 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2299 | // Restore context register. |
| 2300 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2301 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
| 2304 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2305 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2306 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2307 | if (arg_count > 0) { |
| 2308 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2309 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2310 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | // Push the receiver of the enclosing function. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2314 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2315 | // Push the language mode. |
| 2316 | __ push(Immediate(Smi::FromInt(language_mode()))); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2317 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2318 | // Push the start position of the scope the calls resides in. |
| 2319 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
| 2320 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2321 | // Do the runtime call. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2322 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2326 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2327 | #ifdef DEBUG |
| 2328 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2329 | // through this function. Avoid early returns. |
| 2330 | expr->return_is_recorded_ = false; |
| 2331 | #endif |
| 2332 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2333 | Comment cmnt(masm_, "[ Call"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2334 | Expression* callee = expr->expression(); |
| 2335 | VariableProxy* proxy = callee->AsVariableProxy(); |
| 2336 | Property* property = callee->AsProperty(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2337 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2338 | if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2339 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2340 | // resolve the function we need to call and the receiver of the call. |
| 2341 | // Then we call the resolved function using the given arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2342 | ZoneList<Expression*>* args = expr->arguments(); |
| 2343 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2345 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2346 | // Reserved receiver slot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2347 | __ push(Immediate(isolate()->factory()->undefined_value())); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2348 | // Push the arguments. |
| 2349 | for (int i = 0; i < arg_count; i++) { |
| 2350 | VisitForStackValue(args->at(i)); |
| 2351 | } |
| 2352 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2353 | // Push a copy of the function (found below the arguments) and |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2354 | // resolve eval. |
| 2355 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2356 | EmitResolvePossiblyDirectEval(arg_count); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2357 | |
| 2358 | // The runtime call returns a pair of values in eax (function) and |
| 2359 | // edx (receiver). Touch up the stack with the right values. |
| 2360 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2361 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2362 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2363 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2364 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2365 | CallFunctionStub stub(arg_count, RECEIVER_MIGHT_BE_IMPLICIT); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2366 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2367 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2368 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2369 | // Restore context register. |
| 2370 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2371 | context()->DropAndPlug(1, eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2372 | |
| 2373 | } else if (proxy != NULL && proxy->var()->IsUnallocated()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2374 | // Push global object as receiver for the call IC. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2375 | __ push(GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2376 | EmitCallWithIC(expr, proxy->name(), RelocInfo::CODE_TARGET_CONTEXT); |
| 2377 | |
| 2378 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2379 | // Call to a lookup slot (dynamically introduced variable). |
| 2380 | Label slow, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2381 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2382 | // Generate code for loading from variables potentially shadowed by |
| 2383 | // eval-introduced variables. |
| 2384 | EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2385 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2386 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2387 | // Call the runtime to find the function to call (returned in eax) and |
| 2388 | // the object holding it (returned in edx). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2389 | __ push(context_register()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2390 | __ push(Immediate(proxy->name())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2391 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2392 | __ push(eax); // Function. |
| 2393 | __ push(edx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2394 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2395 | // If fast case code has been generated, emit code to push the function |
| 2396 | // and receiver and have the slow path jump around this code. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2397 | if (done.is_linked()) { |
| 2398 | Label call; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2399 | __ jmp(&call, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2400 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2401 | // Push function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2402 | __ push(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2403 | // The receiver is implicitly the global receiver. Indicate this by |
| 2404 | // passing the hole to the call function stub. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2405 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2406 | __ bind(&call); |
| 2407 | } |
| 2408 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2409 | // The receiver is either the global receiver or an object found by |
| 2410 | // LoadContextSlot. That object could be the hole if the receiver is |
| 2411 | // implicitly the global object. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2412 | EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2413 | |
| 2414 | } else if (property != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2415 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2416 | VisitForStackValue(property->obj()); |
| 2417 | } |
| 2418 | if (property->key()->IsPropertyName()) { |
| 2419 | EmitCallWithIC(expr, |
| 2420 | property->key()->AsLiteral()->handle(), |
| 2421 | RelocInfo::CODE_TARGET); |
| 2422 | } else { |
| 2423 | EmitKeyedCallWithIC(expr, property->key()); |
| 2424 | } |
| 2425 | |
| 2426 | } else { |
| 2427 | // Call to an arbitrary expression not handled specially above. |
| 2428 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2429 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2430 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2431 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2432 | __ mov(ebx, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2433 | __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
| 2434 | // Emit function call. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2435 | EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2436 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2437 | |
| 2438 | #ifdef DEBUG |
| 2439 | // RecordJSReturnSite should have been called. |
| 2440 | ASSERT(expr->return_is_recorded_); |
| 2441 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2446 | Comment cmnt(masm_, "[ CallNew"); |
| 2447 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2448 | // expression in new calls must be evaluated before the |
| 2449 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2450 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | // Push constructor on the stack. If it's not a function it's used as |
| 2452 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2453 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2454 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2455 | |
| 2456 | // Push the arguments ("left-to-right") on the stack. |
| 2457 | ZoneList<Expression*>* args = expr->arguments(); |
| 2458 | int arg_count = args->length(); |
| 2459 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2460 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| 2463 | // Call the construct call builtin that handles allocation and |
| 2464 | // constructor invocation. |
| 2465 | SetSourcePosition(expr->position()); |
| 2466 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2467 | // Load function and argument count into edi and eax. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2468 | __ Set(eax, Immediate(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2469 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2470 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2471 | // Record call targets in unoptimized code. |
| 2472 | Handle<Object> uninitialized = |
| 2473 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
| 2474 | Handle<JSGlobalPropertyCell> cell = |
| 2475 | isolate()->factory()->NewJSGlobalPropertyCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2476 | RecordTypeFeedbackCell(expr->CallNewFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2477 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2478 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2479 | CallConstructStub stub(RECORD_CALL_TARGET); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2480 | __ call(stub.GetCode(), RelocInfo::CONSTRUCT_CALL); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2481 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2482 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2486 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2487 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2488 | ASSERT(args->length() == 1); |
| 2489 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2490 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2491 | |
| 2492 | Label materialize_true, materialize_false; |
| 2493 | Label* if_true = NULL; |
| 2494 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2495 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2496 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2497 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2498 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2499 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2500 | __ test(eax, Immediate(kSmiTagMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2501 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2502 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2503 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2507 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2508 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2509 | ASSERT(args->length() == 1); |
| 2510 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2511 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2512 | |
| 2513 | Label materialize_true, materialize_false; |
| 2514 | Label* if_true = NULL; |
| 2515 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2516 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2517 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2518 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2519 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2520 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2521 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2522 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2523 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2524 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2528 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2529 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2530 | ASSERT(args->length() == 1); |
| 2531 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2532 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2533 | |
| 2534 | Label materialize_true, materialize_false; |
| 2535 | Label* if_true = NULL; |
| 2536 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2537 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2538 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2539 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2540 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2541 | __ JumpIfSmi(eax, if_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2542 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2543 | __ j(equal, if_true); |
| 2544 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2545 | // Undetectable objects behave like undefined when tested with typeof. |
| 2546 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2547 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 2548 | __ j(not_zero, if_false); |
| 2549 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2550 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2551 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2552 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2553 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2554 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2555 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2556 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2560 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2561 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2562 | ASSERT(args->length() == 1); |
| 2563 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2564 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2565 | |
| 2566 | Label materialize_true, materialize_false; |
| 2567 | Label* if_true = NULL; |
| 2568 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2569 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2570 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2571 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2572 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2573 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2574 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2575 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2576 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2577 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2578 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
| 2581 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2582 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2583 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2584 | ASSERT(args->length() == 1); |
| 2585 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2586 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2587 | |
| 2588 | Label materialize_true, materialize_false; |
| 2589 | Label* if_true = NULL; |
| 2590 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2591 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2592 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2593 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2594 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2595 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2596 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2597 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2598 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2599 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2600 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2601 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2602 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2606 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2607 | CallRuntime* expr) { |
| 2608 | ZoneList<Expression*>* args = expr->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2609 | ASSERT(args->length() == 1); |
| 2610 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2611 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2612 | |
| 2613 | Label materialize_true, materialize_false; |
| 2614 | Label* if_true = NULL; |
| 2615 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2616 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2617 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2618 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2619 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2620 | __ AssertNotSmi(eax); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2621 | |
| 2622 | // Check whether this map has already been checked to be safe for default |
| 2623 | // valueOf. |
| 2624 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2625 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 2626 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 2627 | __ j(not_zero, if_true); |
| 2628 | |
| 2629 | // Check for fast case object. Return false for slow case objects. |
| 2630 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 2631 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
| 2632 | __ cmp(ecx, FACTORY->hash_table_map()); |
| 2633 | __ j(equal, if_false); |
| 2634 | |
| 2635 | // Look for valueOf symbol in the descriptor array, and indicate false if |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2636 | // found. Since we omit an enumeration index check, if it is added via a |
| 2637 | // transition that shares its descriptor array, this is a false positive. |
| 2638 | Label entry, loop, done; |
| 2639 | |
| 2640 | // Skip loop if no descriptors are valid. |
| 2641 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 2642 | __ cmp(ecx, 0); |
| 2643 | __ j(equal, &done); |
| 2644 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2645 | __ LoadInstanceDescriptors(ebx, ebx); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2646 | // ebx: descriptor array. |
| 2647 | // ecx: valid entries in the descriptor array. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2648 | // Calculate the end of the descriptor array. |
| 2649 | STATIC_ASSERT(kSmiTag == 0); |
| 2650 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2651 | STATIC_ASSERT(kPointerSize == 4); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2652 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 2653 | __ lea(ecx, Operand(ebx, ecx, times_2, DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2654 | // Calculate location of the first key name. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2655 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2656 | // Loop through all the keys in the descriptor array. If one of these is the |
| 2657 | // symbol valueOf the result is false. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2658 | __ jmp(&entry); |
| 2659 | __ bind(&loop); |
| 2660 | __ mov(edx, FieldOperand(ebx, 0)); |
| 2661 | __ cmp(edx, FACTORY->value_of_symbol()); |
| 2662 | __ j(equal, if_false); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2663 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2664 | __ bind(&entry); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2665 | __ cmp(ebx, ecx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2666 | __ j(not_equal, &loop); |
| 2667 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2668 | __ bind(&done); |
| 2669 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2670 | // Reload map as register ebx was used as temporary above. |
| 2671 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2672 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2673 | // 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] | 2674 | // prototype is the un-modified String prototype. If not result is false. |
| 2675 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2676 | __ JumpIfSmi(ecx, if_false); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2677 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2678 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2679 | __ mov(edx, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2680 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2681 | __ cmp(ecx, |
| 2682 | ContextOperand(edx, |
| 2683 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 2684 | __ j(not_equal, if_false); |
| 2685 | // Set the bit in the map to indicate that it has been checked safe for |
| 2686 | // default valueOf and set true result. |
| 2687 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 2688 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 2689 | __ jmp(if_true); |
| 2690 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2691 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2692 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2696 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 2697 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2698 | ASSERT(args->length() == 1); |
| 2699 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2700 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2701 | |
| 2702 | Label materialize_true, materialize_false; |
| 2703 | Label* if_true = NULL; |
| 2704 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2705 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2706 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2707 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2708 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2709 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2710 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2711 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2712 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2713 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2714 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2718 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 2719 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2720 | ASSERT(args->length() == 1); |
| 2721 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2722 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2723 | |
| 2724 | Label materialize_true, materialize_false; |
| 2725 | Label* if_true = NULL; |
| 2726 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2727 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2728 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2729 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2730 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2731 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2732 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2733 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2734 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2735 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2736 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2737 | } |
| 2738 | |
| 2739 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2740 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 2741 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2742 | ASSERT(args->length() == 1); |
| 2743 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2744 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2745 | |
| 2746 | Label materialize_true, materialize_false; |
| 2747 | Label* if_true = NULL; |
| 2748 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2749 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2750 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2751 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2752 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2753 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2754 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2755 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2756 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2757 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2758 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | |
| 2762 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2763 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 2764 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2765 | |
| 2766 | Label materialize_true, materialize_false; |
| 2767 | Label* if_true = NULL; |
| 2768 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2769 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2770 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2771 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2772 | |
| 2773 | // Get the frame pointer for the calling frame. |
| 2774 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2775 | |
| 2776 | // Skip the arguments adaptor frame if it exists. |
| 2777 | Label check_frame_marker; |
| 2778 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 2779 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2780 | __ j(not_equal, &check_frame_marker); |
| 2781 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 2782 | |
| 2783 | // Check the marker in the calling frame. |
| 2784 | __ bind(&check_frame_marker); |
| 2785 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 2786 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2787 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2788 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2789 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2790 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2794 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 2795 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2796 | ASSERT(args->length() == 2); |
| 2797 | |
| 2798 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2799 | VisitForStackValue(args->at(0)); |
| 2800 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2801 | |
| 2802 | Label materialize_true, materialize_false; |
| 2803 | Label* if_true = NULL; |
| 2804 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2805 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2806 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2807 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2808 | |
| 2809 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2810 | __ cmp(eax, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2811 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2812 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2813 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2814 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2818 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 2819 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2820 | ASSERT(args->length() == 1); |
| 2821 | |
| 2822 | // ArgumentsAccessStub expects the key in edx and the formal |
| 2823 | // parameter count in eax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2824 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2825 | __ mov(edx, eax); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2826 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2827 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 2828 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2829 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2833 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 2834 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2835 | |
| 2836 | Label exit; |
| 2837 | // Get the number of formal parameters. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2838 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2839 | |
| 2840 | // Check if the calling frame is an arguments adaptor frame. |
| 2841 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2842 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 2843 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2844 | __ j(not_equal, &exit); |
| 2845 | |
| 2846 | // Arguments adaptor case: Read the arguments length from the |
| 2847 | // adaptor frame. |
| 2848 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2849 | |
| 2850 | __ bind(&exit); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2851 | __ AssertSmi(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2852 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2856 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 2857 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2858 | ASSERT(args->length() == 1); |
| 2859 | Label done, null, function, non_function_constructor; |
| 2860 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2861 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2862 | |
| 2863 | // If the object is a smi, we return null. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2864 | __ JumpIfSmi(eax, &null); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2865 | |
| 2866 | // Check that the object is a JS object but take special care of JS |
| 2867 | // functions to make sure they have 'Function' as their class. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2868 | // Assume that there are only two callable types, and one of them is at |
| 2869 | // either end of the type range for JS object types. Saves extra comparisons. |
| 2870 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2871 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 2872 | // Map is now in eax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2873 | __ j(below, &null); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2874 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2875 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 2876 | __ j(equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2877 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2878 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 2879 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 2880 | LAST_SPEC_OBJECT_TYPE - 1); |
| 2881 | __ j(equal, &function); |
| 2882 | // Assume that there is no larger type. |
| 2883 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2884 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2885 | // 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] | 2886 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 2887 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 2888 | __ j(not_equal, &non_function_constructor); |
| 2889 | |
| 2890 | // eax now contains the constructor function. Grab the |
| 2891 | // instance class name from there. |
| 2892 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 2893 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2894 | __ jmp(&done); |
| 2895 | |
| 2896 | // Functions have class 'Function'. |
| 2897 | __ bind(&function); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2898 | __ mov(eax, isolate()->factory()->function_class_symbol()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2899 | __ jmp(&done); |
| 2900 | |
| 2901 | // Objects with a non-function constructor have class 'Object'. |
| 2902 | __ bind(&non_function_constructor); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2903 | __ mov(eax, isolate()->factory()->Object_symbol()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2904 | __ jmp(&done); |
| 2905 | |
| 2906 | // Non-JS objects have class null. |
| 2907 | __ bind(&null); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2908 | __ mov(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2909 | |
| 2910 | // All done. |
| 2911 | __ bind(&done); |
| 2912 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2913 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2917 | void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2918 | // Conditionally generate a log call. |
| 2919 | // Args: |
| 2920 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 2921 | // This is used to determine whether or not to generate the log call. |
| 2922 | // 1 (string): Format string. Access the string at argument index 2 |
| 2923 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 2924 | // 2 (array): Arguments to the format string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2925 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2926 | ASSERT_EQ(args->length(), 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2927 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2928 | VisitForStackValue(args->at(1)); |
| 2929 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2930 | __ CallRuntime(Runtime::kLog, 2); |
| 2931 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2932 | // 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] | 2933 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2934 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2938 | void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) { |
| 2939 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2940 | |
| 2941 | Label slow_allocate_heapnumber; |
| 2942 | Label heapnumber_allocated; |
| 2943 | |
| 2944 | __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber); |
| 2945 | __ jmp(&heapnumber_allocated); |
| 2946 | |
| 2947 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2948 | // Allocate a heap number. |
| 2949 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2950 | __ mov(edi, eax); |
| 2951 | |
| 2952 | __ bind(&heapnumber_allocated); |
| 2953 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2954 | __ PrepareCallCFunction(1, ebx); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2955 | __ mov(eax, ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX)); |
| 2956 | __ mov(eax, FieldOperand(eax, GlobalObject::kNativeContextOffset)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2957 | __ mov(Operand(esp, 0), eax); |
| 2958 | __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2959 | |
| 2960 | // Convert 32 random bits in eax to 0.(32 random bits) in a double |
| 2961 | // by computing: |
| 2962 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 2963 | // This is implemented on both SSE2 and FPU. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2964 | if (CpuFeatures::IsSupported(SSE2)) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2965 | CpuFeatures::Scope fscope(SSE2); |
| 2966 | __ 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] | 2967 | __ movd(xmm1, ebx); |
| 2968 | __ movd(xmm0, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2969 | __ cvtss2sd(xmm1, xmm1); |
fschneider@chromium.org | fb144a0 | 2011-05-04 12:43:48 +0000 | [diff] [blame] | 2970 | __ xorps(xmm0, xmm1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2971 | __ subsd(xmm0, xmm1); |
| 2972 | __ movdbl(FieldOperand(edi, HeapNumber::kValueOffset), xmm0); |
| 2973 | } else { |
| 2974 | // 0x4130000000000000 is 1.0 x 2^20 as a double. |
| 2975 | __ mov(FieldOperand(edi, HeapNumber::kExponentOffset), |
| 2976 | Immediate(0x41300000)); |
| 2977 | __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax); |
| 2978 | __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 2979 | __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0)); |
| 2980 | __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 2981 | __ fsubp(1); |
| 2982 | __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset)); |
| 2983 | } |
| 2984 | __ mov(eax, edi); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2985 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2986 | } |
| 2987 | |
| 2988 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2989 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2990 | // Load the arguments on the stack and call the stub. |
| 2991 | SubStringStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2992 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2993 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2994 | VisitForStackValue(args->at(0)); |
| 2995 | VisitForStackValue(args->at(1)); |
| 2996 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2997 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2998 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2999 | } |
| 3000 | |
| 3001 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3002 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3003 | // Load the arguments on the stack and call the stub. |
| 3004 | RegExpExecStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3005 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3006 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3007 | VisitForStackValue(args->at(0)); |
| 3008 | VisitForStackValue(args->at(1)); |
| 3009 | VisitForStackValue(args->at(2)); |
| 3010 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3011 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3012 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3016 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3017 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3018 | ASSERT(args->length() == 1); |
| 3019 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3020 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3021 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3022 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3023 | // If the object is a smi return the object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3024 | __ JumpIfSmi(eax, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3025 | // If the object is not a value type, return the object. |
| 3026 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3027 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3028 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3029 | |
| 3030 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3031 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3035 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3036 | ZoneList<Expression*>* args = expr->arguments(); |
| 3037 | ASSERT(args->length() == 2); |
| 3038 | ASSERT_NE(NULL, args->at(1)->AsLiteral()); |
| 3039 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->handle())); |
| 3040 | |
| 3041 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3042 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3043 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3044 | Register object = eax; |
| 3045 | Register result = eax; |
| 3046 | Register scratch = ecx; |
| 3047 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3048 | __ JumpIfSmi(object, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3049 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3050 | __ j(not_equal, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3051 | |
| 3052 | if (index->value() == 0) { |
| 3053 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3054 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3055 | } else { |
| 3056 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3057 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3058 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3059 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3060 | __ j(not_equal, &runtime, Label::kNear); |
| 3061 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3062 | kPointerSize * index->value())); |
| 3063 | __ jmp(&done); |
| 3064 | } |
| 3065 | __ bind(&runtime); |
| 3066 | __ PrepareCallCFunction(2, scratch); |
| 3067 | __ mov(Operand(esp, 0), object); |
| 3068 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3069 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3070 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3071 | } |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3072 | |
| 3073 | __ bind(¬_date_object); |
| 3074 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3075 | __ bind(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3076 | context()->Plug(result); |
| 3077 | } |
| 3078 | |
| 3079 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3080 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3081 | // Load the arguments on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3082 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3083 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3084 | VisitForStackValue(args->at(0)); |
| 3085 | VisitForStackValue(args->at(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3086 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3087 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3088 | MathPowStub stub(MathPowStub::ON_STACK); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3089 | __ CallStub(&stub); |
| 3090 | } else { |
| 3091 | __ CallRuntime(Runtime::kMath_pow, 2); |
| 3092 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3093 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3097 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3098 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3099 | ASSERT(args->length() == 2); |
| 3100 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3101 | VisitForStackValue(args->at(0)); // Load the object. |
| 3102 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3103 | __ pop(ebx); // eax = value. ebx = object. |
| 3104 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3105 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3106 | // If the object is a smi, return the value. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3107 | __ JumpIfSmi(ebx, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3108 | |
| 3109 | // If the object is not a value type, return the value. |
| 3110 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3111 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3112 | |
| 3113 | // Store the value. |
| 3114 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3115 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3116 | // Update the write barrier. Save the value as it will be |
| 3117 | // overwritten by the write barrier code and is needed afterward. |
| 3118 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3119 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3120 | |
| 3121 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3122 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3126 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3127 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3128 | ASSERT_EQ(args->length(), 1); |
| 3129 | |
| 3130 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3131 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3132 | |
| 3133 | NumberToStringStub stub; |
| 3134 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3135 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3139 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3140 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3141 | ASSERT(args->length() == 1); |
| 3142 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3143 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3144 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3145 | Label done; |
| 3146 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3147 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3148 | __ jmp(&done); |
| 3149 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3150 | NopRuntimeCallHelper call_helper; |
| 3151 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3152 | |
| 3153 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3154 | context()->Plug(ebx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3158 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3159 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3160 | ASSERT(args->length() == 2); |
| 3161 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3162 | VisitForStackValue(args->at(0)); |
| 3163 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3164 | |
| 3165 | Register object = ebx; |
| 3166 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3167 | Register result = edx; |
| 3168 | |
| 3169 | __ pop(object); |
| 3170 | |
| 3171 | Label need_conversion; |
| 3172 | Label index_out_of_range; |
| 3173 | Label done; |
| 3174 | StringCharCodeAtGenerator generator(object, |
| 3175 | index, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3176 | result, |
| 3177 | &need_conversion, |
| 3178 | &need_conversion, |
| 3179 | &index_out_of_range, |
| 3180 | STRING_INDEX_IS_NUMBER); |
| 3181 | generator.GenerateFast(masm_); |
| 3182 | __ jmp(&done); |
| 3183 | |
| 3184 | __ bind(&index_out_of_range); |
| 3185 | // When the index is out of range, the spec requires us to return |
| 3186 | // NaN. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3187 | __ Set(result, Immediate(isolate()->factory()->nan_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3188 | __ jmp(&done); |
| 3189 | |
| 3190 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3191 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3192 | // trigger conversion. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3193 | __ Set(result, Immediate(isolate()->factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3194 | __ jmp(&done); |
| 3195 | |
| 3196 | NopRuntimeCallHelper call_helper; |
| 3197 | generator.GenerateSlow(masm_, call_helper); |
| 3198 | |
| 3199 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3200 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3203 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3204 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3205 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3206 | ASSERT(args->length() == 2); |
| 3207 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3208 | VisitForStackValue(args->at(0)); |
| 3209 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3210 | |
| 3211 | Register object = ebx; |
| 3212 | Register index = eax; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3213 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3214 | Register result = eax; |
| 3215 | |
| 3216 | __ pop(object); |
| 3217 | |
| 3218 | Label need_conversion; |
| 3219 | Label index_out_of_range; |
| 3220 | Label done; |
| 3221 | StringCharAtGenerator generator(object, |
| 3222 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3223 | scratch, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3224 | result, |
| 3225 | &need_conversion, |
| 3226 | &need_conversion, |
| 3227 | &index_out_of_range, |
| 3228 | STRING_INDEX_IS_NUMBER); |
| 3229 | generator.GenerateFast(masm_); |
| 3230 | __ jmp(&done); |
| 3231 | |
| 3232 | __ bind(&index_out_of_range); |
| 3233 | // When the index is out of range, the spec requires us to return |
| 3234 | // the empty string. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3235 | __ Set(result, Immediate(isolate()->factory()->empty_string())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3236 | __ jmp(&done); |
| 3237 | |
| 3238 | __ bind(&need_conversion); |
| 3239 | // Move smi zero into the result register, which will trigger |
| 3240 | // conversion. |
| 3241 | __ Set(result, Immediate(Smi::FromInt(0))); |
| 3242 | __ jmp(&done); |
| 3243 | |
| 3244 | NopRuntimeCallHelper call_helper; |
| 3245 | generator.GenerateSlow(masm_, call_helper); |
| 3246 | |
| 3247 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3248 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3252 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3253 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3254 | ASSERT_EQ(2, args->length()); |
| 3255 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3256 | VisitForStackValue(args->at(0)); |
| 3257 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3258 | |
| 3259 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 3260 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3261 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3262 | } |
| 3263 | |
| 3264 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3265 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3266 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3267 | ASSERT_EQ(2, args->length()); |
| 3268 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3269 | VisitForStackValue(args->at(0)); |
| 3270 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3271 | |
| 3272 | StringCompareStub stub; |
| 3273 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3274 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3278 | void FullCodeGenerator::EmitMathSin(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3279 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3280 | TranscendentalCacheStub stub(TranscendentalCache::SIN, |
| 3281 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3282 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3283 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3284 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3285 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3286 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3290 | void FullCodeGenerator::EmitMathCos(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3291 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3292 | TranscendentalCacheStub stub(TranscendentalCache::COS, |
| 3293 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3294 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3295 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3296 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3297 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3298 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3302 | void FullCodeGenerator::EmitMathTan(CallRuntime* expr) { |
| 3303 | // Load the argument on the stack and call the stub. |
| 3304 | TranscendentalCacheStub stub(TranscendentalCache::TAN, |
| 3305 | TranscendentalCacheStub::TAGGED); |
| 3306 | ZoneList<Expression*>* args = expr->arguments(); |
| 3307 | ASSERT(args->length() == 1); |
| 3308 | VisitForStackValue(args->at(0)); |
| 3309 | __ CallStub(&stub); |
| 3310 | context()->Plug(eax); |
| 3311 | } |
| 3312 | |
| 3313 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3314 | void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3315 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3316 | TranscendentalCacheStub stub(TranscendentalCache::LOG, |
| 3317 | TranscendentalCacheStub::TAGGED); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3318 | ZoneList<Expression*>* args = expr->arguments(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3319 | ASSERT(args->length() == 1); |
| 3320 | VisitForStackValue(args->at(0)); |
| 3321 | __ CallStub(&stub); |
| 3322 | context()->Plug(eax); |
| 3323 | } |
| 3324 | |
| 3325 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3326 | void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3327 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3328 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3329 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3330 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3331 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3332 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3336 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3337 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3338 | ASSERT(args->length() >= 2); |
| 3339 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3340 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3341 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3342 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3343 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3344 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3345 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3346 | Label runtime, done; |
| 3347 | // Check for non-function argument (including proxy). |
| 3348 | __ JumpIfSmi(eax, &runtime); |
| 3349 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3350 | __ j(not_equal, &runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3351 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3352 | // InvokeFunction requires the function in edi. Move it in there. |
| 3353 | __ mov(edi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3354 | ParameterCount count(arg_count); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3355 | __ InvokeFunction(edi, count, CALL_FUNCTION, |
| 3356 | NullCallWrapper(), CALL_AS_METHOD); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3357 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3358 | __ jmp(&done); |
| 3359 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3360 | __ bind(&runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3361 | __ push(eax); |
| 3362 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3363 | __ bind(&done); |
| 3364 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3365 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
| 3368 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3369 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3370 | // Load the arguments on the stack and call the stub. |
| 3371 | RegExpConstructResultStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3372 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3373 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3374 | VisitForStackValue(args->at(0)); |
| 3375 | VisitForStackValue(args->at(1)); |
| 3376 | VisitForStackValue(args->at(2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3377 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3378 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3382 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3383 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3384 | ASSERT_EQ(2, args->length()); |
| 3385 | |
| 3386 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 3387 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 3388 | |
| 3389 | Handle<FixedArray> jsfunction_result_caches( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3390 | isolate()->native_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3391 | if (jsfunction_result_caches->length() <= cache_id) { |
| 3392 | __ Abort("Attempt to use undefined cache."); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3393 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3394 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3395 | return; |
| 3396 | } |
| 3397 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3398 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3399 | |
| 3400 | Register key = eax; |
| 3401 | Register cache = ebx; |
| 3402 | Register tmp = ecx; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3403 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3404 | __ mov(cache, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3405 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3406 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3407 | __ mov(cache, |
| 3408 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3409 | |
| 3410 | Label done, not_found; |
| 3411 | // tmp now holds finger offset as a smi. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3412 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3413 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 3414 | __ cmp(key, CodeGenerator::FixedArrayElementOperand(cache, tmp)); |
| 3415 | __ j(not_equal, ¬_found); |
| 3416 | |
| 3417 | __ mov(eax, CodeGenerator::FixedArrayElementOperand(cache, tmp, 1)); |
| 3418 | __ jmp(&done); |
| 3419 | |
| 3420 | __ bind(¬_found); |
| 3421 | // Call runtime to perform the lookup. |
| 3422 | __ push(cache); |
| 3423 | __ push(key); |
| 3424 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3425 | |
| 3426 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3427 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3428 | } |
| 3429 | |
| 3430 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3431 | void FullCodeGenerator::EmitIsRegExpEquivalent(CallRuntime* expr) { |
| 3432 | ZoneList<Expression*>* args = expr->arguments(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3433 | ASSERT_EQ(2, args->length()); |
| 3434 | |
| 3435 | Register right = eax; |
| 3436 | Register left = ebx; |
| 3437 | Register tmp = ecx; |
| 3438 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3439 | VisitForStackValue(args->at(0)); |
| 3440 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3441 | __ pop(left); |
| 3442 | |
| 3443 | Label done, fail, ok; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3444 | __ cmp(left, right); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3445 | __ j(equal, &ok); |
| 3446 | // Fail if either is a non-HeapObject. |
| 3447 | __ mov(tmp, left); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3448 | __ and_(tmp, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3449 | __ JumpIfSmi(tmp, &fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3450 | __ mov(tmp, FieldOperand(left, HeapObject::kMapOffset)); |
| 3451 | __ CmpInstanceType(tmp, JS_REGEXP_TYPE); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3452 | __ j(not_equal, &fail); |
| 3453 | __ cmp(tmp, FieldOperand(right, HeapObject::kMapOffset)); |
| 3454 | __ j(not_equal, &fail); |
| 3455 | __ mov(tmp, FieldOperand(left, JSRegExp::kDataOffset)); |
| 3456 | __ cmp(tmp, FieldOperand(right, JSRegExp::kDataOffset)); |
| 3457 | __ j(equal, &ok); |
| 3458 | __ bind(&fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3459 | __ mov(eax, Immediate(isolate()->factory()->false_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3460 | __ jmp(&done); |
| 3461 | __ bind(&ok); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3462 | __ mov(eax, Immediate(isolate()->factory()->true_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3463 | __ bind(&done); |
| 3464 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3465 | context()->Plug(eax); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3466 | } |
| 3467 | |
| 3468 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3469 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3470 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3471 | ASSERT(args->length() == 1); |
| 3472 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3473 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3474 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3475 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3476 | |
| 3477 | Label materialize_true, materialize_false; |
| 3478 | Label* if_true = NULL; |
| 3479 | Label* if_false = NULL; |
| 3480 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3481 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3482 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3483 | |
| 3484 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 3485 | Immediate(String::kContainsCachedArrayIndexMask)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3486 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3487 | Split(zero, if_true, if_false, fall_through); |
| 3488 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3489 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3493 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3494 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3495 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3496 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3497 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3498 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3499 | |
| 3500 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 3501 | __ IndexFromHash(eax, eax); |
| 3502 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3503 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3507 | void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3508 | Label bailout, done, one_char_separator, long_separator, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3509 | non_trivial_array, not_size_one_array, loop, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3510 | 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] | 3511 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3512 | ZoneList<Expression*>* args = expr->arguments(); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3513 | ASSERT(args->length() == 2); |
| 3514 | // We will leave the separator on the stack until the end of the function. |
| 3515 | VisitForStackValue(args->at(1)); |
| 3516 | // Load this to eax (= array) |
| 3517 | VisitForAccumulatorValue(args->at(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3518 | // All aliases of the same register have disjoint lifetimes. |
| 3519 | Register array = eax; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3520 | Register elements = no_reg; // Will be eax. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3521 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3522 | Register index = edx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3523 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3524 | Register string_length = ecx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3525 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3526 | Register string = esi; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3527 | |
| 3528 | Register scratch = ebx; |
| 3529 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3530 | Register array_length = edi; |
| 3531 | Register result_pos = no_reg; // Will be edi. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3532 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3533 | // Separator operand is already pushed. |
| 3534 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 3535 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 3536 | Operand array_length_operand = Operand(esp, 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3537 | __ sub(esp, Immediate(2 * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3538 | __ cld(); |
| 3539 | // Check that the array is a JSArray |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3540 | __ JumpIfSmi(array, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3541 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3542 | __ j(not_equal, &bailout); |
| 3543 | |
| 3544 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3545 | __ CheckFastElements(scratch, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3546 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3547 | // If the array has length zero, return the empty string. |
| 3548 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3549 | __ SmiUntag(array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3550 | __ j(not_zero, &non_trivial_array); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3551 | __ mov(result_operand, isolate()->factory()->empty_string()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3552 | __ jmp(&done); |
| 3553 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3554 | // Save the array length. |
| 3555 | __ bind(&non_trivial_array); |
| 3556 | __ mov(array_length_operand, array_length); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3557 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3558 | // Save the FixedArray containing array's elements. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3559 | // End of array's live range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3560 | elements = array; |
| 3561 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3562 | array = no_reg; |
| 3563 | |
| 3564 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3565 | // Check that all array elements are sequential ASCII strings, and |
| 3566 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 3567 | __ Set(index, Immediate(0)); |
| 3568 | __ Set(string_length, Immediate(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3569 | // Loop condition: while (index < length). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3570 | // Live loop registers: index, array_length, string, |
| 3571 | // scratch, string_length, elements. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 3572 | if (generate_debug_code_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3573 | __ cmp(index, array_length); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3574 | __ Assert(less, "No empty arrays here in EmitFastAsciiArrayJoin"); |
| 3575 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3576 | __ bind(&loop); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3577 | __ mov(string, FieldOperand(elements, |
| 3578 | index, |
| 3579 | times_pointer_size, |
| 3580 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3581 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3582 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3583 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3584 | __ and_(scratch, Immediate( |
| 3585 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3586 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3587 | __ j(not_equal, &bailout); |
| 3588 | __ add(string_length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3589 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3590 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3591 | __ add(index, Immediate(1)); |
| 3592 | __ cmp(index, array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3593 | __ j(less, &loop); |
| 3594 | |
| 3595 | // If array_length is 1, return elements[0], a string. |
| 3596 | __ cmp(array_length, 1); |
| 3597 | __ j(not_equal, ¬_size_one_array); |
| 3598 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3599 | __ mov(result_operand, scratch); |
| 3600 | __ jmp(&done); |
| 3601 | |
| 3602 | __ bind(¬_size_one_array); |
| 3603 | |
| 3604 | // End of array_length live range. |
| 3605 | result_pos = array_length; |
| 3606 | array_length = no_reg; |
| 3607 | |
| 3608 | // Live registers: |
| 3609 | // string_length: Sum of string lengths, as a smi. |
| 3610 | // elements: FixedArray of strings. |
| 3611 | |
| 3612 | // Check that the separator is a flat ASCII string. |
| 3613 | __ mov(string, separator_operand); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3614 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3615 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3616 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3617 | __ and_(scratch, Immediate( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3618 | kIsNotStringMask | kStringEncodingMask | kAsciiDataHintMask | |
| 3619 | kStringRepresentationMask)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3620 | __ cmp(scratch, ASCII_STRING_TYPE); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3621 | __ j(not_equal, &bailout); |
| 3622 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3623 | // Add (separator length times array_length) - separator length |
| 3624 | // to string_length. |
| 3625 | __ mov(scratch, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3626 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3627 | __ sub(string_length, scratch); // May be negative, temporarily. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3628 | __ imul(scratch, array_length_operand); |
| 3629 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3630 | __ add(string_length, scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3631 | __ j(overflow, &bailout); |
| 3632 | |
| 3633 | __ shr(string_length, 1); |
| 3634 | // Live registers and stack values: |
| 3635 | // string_length |
| 3636 | // elements |
| 3637 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 3638 | index, string, &bailout); |
| 3639 | __ mov(result_operand, result_pos); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3640 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3641 | |
| 3642 | |
| 3643 | __ mov(string, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3644 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3645 | Immediate(Smi::FromInt(1))); |
| 3646 | __ j(equal, &one_char_separator); |
| 3647 | __ j(greater, &long_separator); |
| 3648 | |
| 3649 | |
| 3650 | // Empty separator case |
| 3651 | __ mov(index, Immediate(0)); |
| 3652 | __ jmp(&loop_1_condition); |
| 3653 | // Loop condition: while (index < length). |
| 3654 | __ bind(&loop_1); |
| 3655 | // Each iteration of the loop concatenates one string to the result. |
| 3656 | // Live values in registers: |
| 3657 | // index: which element of the elements array we are adding to the result. |
| 3658 | // result_pos: the position to which we are currently copying characters. |
| 3659 | // elements: the FixedArray of strings we are joining. |
| 3660 | |
| 3661 | // Get string = array[index]. |
| 3662 | __ mov(string, FieldOperand(elements, index, |
| 3663 | times_pointer_size, |
| 3664 | FixedArray::kHeaderSize)); |
| 3665 | __ mov(string_length, |
| 3666 | FieldOperand(string, String::kLengthOffset)); |
| 3667 | __ shr(string_length, 1); |
| 3668 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3669 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3670 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3671 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3672 | __ bind(&loop_1_condition); |
| 3673 | __ cmp(index, array_length_operand); |
| 3674 | __ j(less, &loop_1); // End while (index < length). |
| 3675 | __ jmp(&done); |
| 3676 | |
| 3677 | |
| 3678 | |
| 3679 | // One-character separator case |
| 3680 | __ bind(&one_char_separator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3681 | // Replace separator with its ASCII character value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3682 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3683 | __ mov_b(separator_operand, scratch); |
| 3684 | |
| 3685 | __ Set(index, Immediate(0)); |
| 3686 | // Jump into the loop after the code that copies the separator, so the first |
| 3687 | // element is not preceded by a separator |
| 3688 | __ jmp(&loop_2_entry); |
| 3689 | // Loop condition: while (index < length). |
| 3690 | __ bind(&loop_2); |
| 3691 | // Each iteration of the loop concatenates one string to the result. |
| 3692 | // Live values in registers: |
| 3693 | // index: which element of the elements array we are adding to the result. |
| 3694 | // result_pos: the position to which we are currently copying characters. |
| 3695 | |
| 3696 | // Copy the separator character to the result. |
| 3697 | __ mov_b(scratch, separator_operand); |
| 3698 | __ mov_b(Operand(result_pos, 0), scratch); |
| 3699 | __ inc(result_pos); |
| 3700 | |
| 3701 | __ bind(&loop_2_entry); |
| 3702 | // Get string = array[index]. |
| 3703 | __ mov(string, FieldOperand(elements, index, |
| 3704 | times_pointer_size, |
| 3705 | FixedArray::kHeaderSize)); |
| 3706 | __ mov(string_length, |
| 3707 | FieldOperand(string, String::kLengthOffset)); |
| 3708 | __ shr(string_length, 1); |
| 3709 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3710 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3711 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3712 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3713 | |
| 3714 | __ cmp(index, array_length_operand); |
| 3715 | __ j(less, &loop_2); // End while (index < length). |
| 3716 | __ jmp(&done); |
| 3717 | |
| 3718 | |
| 3719 | // Long separator case (separator is more than one character). |
| 3720 | __ bind(&long_separator); |
| 3721 | |
| 3722 | __ Set(index, Immediate(0)); |
| 3723 | // Jump into the loop after the code that copies the separator, so the first |
| 3724 | // element is not preceded by a separator |
| 3725 | __ jmp(&loop_3_entry); |
| 3726 | // Loop condition: while (index < length). |
| 3727 | __ bind(&loop_3); |
| 3728 | // Each iteration of the loop concatenates one string to the result. |
| 3729 | // Live values in registers: |
| 3730 | // index: which element of the elements array we are adding to the result. |
| 3731 | // result_pos: the position to which we are currently copying characters. |
| 3732 | |
| 3733 | // Copy the separator to the result. |
| 3734 | __ mov(string, separator_operand); |
| 3735 | __ mov(string_length, |
| 3736 | FieldOperand(string, String::kLengthOffset)); |
| 3737 | __ shr(string_length, 1); |
| 3738 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3739 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3740 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 3741 | |
| 3742 | __ bind(&loop_3_entry); |
| 3743 | // Get string = array[index]. |
| 3744 | __ mov(string, FieldOperand(elements, index, |
| 3745 | times_pointer_size, |
| 3746 | FixedArray::kHeaderSize)); |
| 3747 | __ mov(string_length, |
| 3748 | FieldOperand(string, String::kLengthOffset)); |
| 3749 | __ shr(string_length, 1); |
| 3750 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3751 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3752 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3753 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3754 | |
| 3755 | __ cmp(index, array_length_operand); |
| 3756 | __ j(less, &loop_3); // End while (index < length). |
| 3757 | __ jmp(&done); |
| 3758 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3759 | |
| 3760 | __ bind(&bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3761 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3762 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3763 | __ mov(eax, result_operand); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3764 | // Drop temp values from the stack, and restore context register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3765 | __ add(esp, Immediate(3 * kPointerSize)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3766 | |
| 3767 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 3768 | context()->Plug(eax); |
| 3769 | } |
| 3770 | |
| 3771 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3772 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3773 | Handle<String> name = expr->name(); |
| 3774 | if (name->length() > 0 && name->Get(0) == '_') { |
| 3775 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 3776 | EmitInlineRuntimeCall(expr); |
| 3777 | return; |
| 3778 | } |
| 3779 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3780 | Comment cmnt(masm_, "[ CallRuntime"); |
| 3781 | ZoneList<Expression*>* args = expr->arguments(); |
| 3782 | |
| 3783 | if (expr->is_jsruntime()) { |
| 3784 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3785 | __ mov(eax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3786 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
| 3787 | } |
| 3788 | |
| 3789 | // Push the arguments ("left-to-right"). |
| 3790 | int arg_count = args->length(); |
| 3791 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3792 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
| 3795 | if (expr->is_jsruntime()) { |
| 3796 | // Call the JS runtime function via a call IC. |
| 3797 | __ Set(ecx, Immediate(expr->name())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3798 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3799 | Handle<Code> ic = |
| 3800 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3801 | CallIC(ic, mode, expr->CallRuntimeFeedbackId()); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3802 | // Restore context register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3803 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 3804 | } else { |
| 3805 | // Call the C runtime function. |
| 3806 | __ CallRuntime(expr->function(), arg_count); |
| 3807 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3808 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | |
| 3812 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 3813 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3814 | case Token::DELETE: { |
| 3815 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3816 | Property* property = expr->expression()->AsProperty(); |
| 3817 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3818 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3819 | if (property != NULL) { |
| 3820 | VisitForStackValue(property->obj()); |
| 3821 | VisitForStackValue(property->key()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3822 | StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE) |
| 3823 | ? kNonStrictMode : kStrictMode; |
| 3824 | __ push(Immediate(Smi::FromInt(strict_mode_flag))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3825 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3826 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3827 | } else if (proxy != NULL) { |
| 3828 | Variable* var = proxy->var(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3829 | // Delete of an unqualified identifier is disallowed in strict mode |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3830 | // but "delete this" is allowed. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3831 | ASSERT(language_mode() == CLASSIC_MODE || var->is_this()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3832 | if (var->IsUnallocated()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3833 | __ push(GlobalObjectOperand()); |
| 3834 | __ push(Immediate(var->name())); |
| 3835 | __ push(Immediate(Smi::FromInt(kNonStrictMode))); |
| 3836 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 3837 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 3838 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 3839 | // Result of deleting non-global variables is false. 'this' is |
| 3840 | // not really a variable, though we implement it as one. The |
| 3841 | // subexpression does not have side effects. |
| 3842 | context()->Plug(var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3843 | } else { |
| 3844 | // Non-global variable. Call the runtime to try to delete from the |
| 3845 | // context where the variable was introduced. |
| 3846 | __ push(context_register()); |
| 3847 | __ push(Immediate(var->name())); |
| 3848 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
| 3849 | context()->Plug(eax); |
| 3850 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3851 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3852 | // Result of deleting non-property, non-variable reference is true. |
| 3853 | // The subexpression may have side effects. |
| 3854 | VisitForEffect(expr->expression()); |
| 3855 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3856 | } |
| 3857 | break; |
| 3858 | } |
| 3859 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3860 | case Token::VOID: { |
| 3861 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 3862 | VisitForEffect(expr->expression()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3863 | context()->Plug(isolate()->factory()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3864 | break; |
| 3865 | } |
| 3866 | |
| 3867 | case Token::NOT: { |
| 3868 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3869 | if (context()->IsEffect()) { |
| 3870 | // Unary NOT has no side effects so it's only necessary to visit the |
| 3871 | // subexpression. Match the optimizing compiler by not branching. |
| 3872 | VisitForEffect(expr->expression()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3873 | } else if (context()->IsTest()) { |
| 3874 | const TestContext* test = TestContext::cast(context()); |
| 3875 | // The labels are swapped for the recursive call. |
| 3876 | VisitForControl(expr->expression(), |
| 3877 | test->false_label(), |
| 3878 | test->true_label(), |
| 3879 | test->fall_through()); |
| 3880 | context()->Plug(test->true_label(), test->false_label()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3881 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3882 | // We handle value contexts explicitly rather than simply visiting |
| 3883 | // for control and plugging the control flow into the context, |
| 3884 | // because we need to prepare a pair of extra administrative AST ids |
| 3885 | // for the optimizing compiler. |
| 3886 | ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 3887 | Label materialize_true, materialize_false, done; |
| 3888 | VisitForControl(expr->expression(), |
| 3889 | &materialize_false, |
| 3890 | &materialize_true, |
| 3891 | &materialize_true); |
| 3892 | __ bind(&materialize_true); |
| 3893 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 3894 | if (context()->IsAccumulatorValue()) { |
| 3895 | __ mov(eax, isolate()->factory()->true_value()); |
| 3896 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3897 | __ Push(isolate()->factory()->true_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3898 | } |
| 3899 | __ jmp(&done, Label::kNear); |
| 3900 | __ bind(&materialize_false); |
| 3901 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 3902 | if (context()->IsAccumulatorValue()) { |
| 3903 | __ mov(eax, isolate()->factory()->false_value()); |
| 3904 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3905 | __ Push(isolate()->factory()->false_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3906 | } |
| 3907 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 3908 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3909 | break; |
| 3910 | } |
| 3911 | |
| 3912 | case Token::TYPEOF: { |
| 3913 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3914 | { StackValueContext context(this); |
| 3915 | VisitForTypeofValue(expr->expression()); |
| 3916 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3917 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3918 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3919 | break; |
| 3920 | } |
| 3921 | |
| 3922 | case Token::ADD: { |
| 3923 | Comment cmt(masm_, "[ UnaryOperation (ADD)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3924 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3925 | Label no_conversion; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3926 | __ JumpIfSmi(result_register(), &no_conversion); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3927 | ToNumberStub convert_stub; |
| 3928 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3929 | __ bind(&no_conversion); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3930 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3931 | break; |
| 3932 | } |
| 3933 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3934 | case Token::SUB: |
| 3935 | EmitUnaryOperation(expr, "[ UnaryOperation (SUB)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3936 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3937 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3938 | case Token::BIT_NOT: |
| 3939 | EmitUnaryOperation(expr, "[ UnaryOperation (BIT_NOT)"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3940 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3941 | |
| 3942 | default: |
| 3943 | UNREACHABLE(); |
| 3944 | } |
| 3945 | } |
| 3946 | |
| 3947 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3948 | void FullCodeGenerator::EmitUnaryOperation(UnaryOperation* expr, |
| 3949 | const char* comment) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3950 | Comment cmt(masm_, comment); |
| 3951 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
| 3952 | UnaryOverwriteMode overwrite = |
| 3953 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3954 | UnaryOpStub stub(expr->op(), overwrite); |
| 3955 | // UnaryOpStub expects the argument to be in the |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3956 | // accumulator register eax. |
| 3957 | VisitForAccumulatorValue(expr->expression()); |
| 3958 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 3959 | CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, |
| 3960 | expr->UnaryOperationFeedbackId()); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3961 | context()->Plug(eax); |
| 3962 | } |
| 3963 | |
| 3964 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3965 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 3966 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3967 | SetSourcePosition(expr->position()); |
| 3968 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3969 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 3970 | // as the left-hand side. |
| 3971 | if (!expr->expression()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3972 | VisitForEffect(expr->expression()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3973 | return; |
| 3974 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3975 | |
| 3976 | // 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] | 3977 | // slot. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3978 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 3979 | LhsKind assign_type = VARIABLE; |
| 3980 | Property* prop = expr->expression()->AsProperty(); |
| 3981 | // In case of a property we use the uninitialized expression context |
| 3982 | // of the key to detect a named property. |
| 3983 | if (prop != NULL) { |
| 3984 | assign_type = |
| 3985 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 3986 | } |
| 3987 | |
| 3988 | // Evaluate expression and get value. |
| 3989 | if (assign_type == VARIABLE) { |
| 3990 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3991 | AccumulatorValueContext context(this); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 3992 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3993 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3994 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3995 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3996 | __ push(Immediate(Smi::FromInt(0))); |
| 3997 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3998 | if (assign_type == NAMED_PROPERTY) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 3999 | // Put the object both on the stack and in edx. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4000 | VisitForAccumulatorValue(prop->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4001 | __ push(eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4002 | __ mov(edx, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4003 | EmitNamedPropertyLoad(prop); |
| 4004 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4005 | VisitForStackValue(prop->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4006 | VisitForStackValue(prop->key()); |
| 4007 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 4008 | __ mov(ecx, Operand(esp, 0)); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4009 | EmitKeyedPropertyLoad(prop); |
| 4010 | } |
| 4011 | } |
| 4012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4013 | // We need a second deoptimization point after loading the value |
| 4014 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4015 | if (assign_type == VARIABLE) { |
| 4016 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4017 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4018 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4019 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4020 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4021 | // Call ToNumber only if operand is not a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4022 | Label no_conversion; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4023 | if (ShouldInlineSmiCase(expr->op())) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4024 | __ JumpIfSmi(eax, &no_conversion, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4025 | } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4026 | ToNumberStub convert_stub; |
| 4027 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4028 | __ bind(&no_conversion); |
| 4029 | |
| 4030 | // Save result for postfix expressions. |
| 4031 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4032 | if (!context()->IsEffect()) { |
| 4033 | // Save the result on the stack. If we have a named or keyed property |
| 4034 | // we store the result under the receiver that is currently on top |
| 4035 | // of the stack. |
| 4036 | switch (assign_type) { |
| 4037 | case VARIABLE: |
| 4038 | __ push(eax); |
| 4039 | break; |
| 4040 | case NAMED_PROPERTY: |
| 4041 | __ mov(Operand(esp, kPointerSize), eax); |
| 4042 | break; |
| 4043 | case KEYED_PROPERTY: |
| 4044 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4045 | break; |
| 4046 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | // Inline smi case if we are in a loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4051 | Label done, stub_call; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4052 | JumpPatchSite patch_site(masm_); |
| 4053 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4054 | if (ShouldInlineSmiCase(expr->op())) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4055 | if (expr->op() == Token::INC) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4056 | __ add(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4057 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4058 | __ sub(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4059 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4060 | __ j(overflow, &stub_call, Label::kNear); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4061 | // We could eliminate this smi check if we split the code at |
| 4062 | // the first smi check before calling ToNumber. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4063 | patch_site.EmitJumpIfSmi(eax, &done, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4064 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4065 | __ bind(&stub_call); |
| 4066 | // Call stub. Undo operation first. |
| 4067 | if (expr->op() == Token::INC) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4068 | __ sub(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4069 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4070 | __ add(eax, Immediate(Smi::FromInt(1))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4071 | } |
| 4072 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4073 | |
| 4074 | // Record position before stub call. |
| 4075 | SetSourcePosition(expr->position()); |
| 4076 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4077 | // Call stub for +1/-1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4078 | __ mov(edx, eax); |
| 4079 | __ mov(eax, Immediate(Smi::FromInt(1))); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4080 | BinaryOpStub stub(expr->binary_op(), NO_OVERWRITE); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4081 | CallIC(stub.GetCode(), RelocInfo::CODE_TARGET, expr->CountBinOpFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4082 | patch_site.EmitPatchInfo(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4083 | __ bind(&done); |
| 4084 | |
| 4085 | // Store the value returned in eax. |
| 4086 | switch (assign_type) { |
| 4087 | case VARIABLE: |
| 4088 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4089 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4090 | { EffectContext context(this); |
| 4091 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4092 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4093 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4094 | context.Plug(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4095 | } |
| 4096 | // For all contexts except EffectContext We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4097 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4098 | if (!context()->IsEffect()) { |
| 4099 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4100 | } |
| 4101 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4102 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4103 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4104 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4105 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4106 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4107 | } |
| 4108 | break; |
| 4109 | case NAMED_PROPERTY: { |
| 4110 | __ mov(ecx, prop->key()->AsLiteral()->handle()); |
| 4111 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4112 | Handle<Code> ic = is_classic_mode() |
| 4113 | ? isolate()->builtins()->StoreIC_Initialize() |
| 4114 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4115 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4116 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4117 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4118 | if (!context()->IsEffect()) { |
| 4119 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4120 | } |
| 4121 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4122 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4123 | } |
| 4124 | break; |
| 4125 | } |
| 4126 | case KEYED_PROPERTY: { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4127 | __ pop(ecx); |
| 4128 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4129 | Handle<Code> ic = is_classic_mode() |
| 4130 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 4131 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4132 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4133 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4134 | if (expr->is_postfix()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4135 | // Result is on the stack |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4136 | if (!context()->IsEffect()) { |
| 4137 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4138 | } |
| 4139 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4140 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4141 | } |
| 4142 | break; |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4148 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4149 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4150 | ASSERT(!context()->IsEffect()); |
| 4151 | ASSERT(!context()->IsTest()); |
| 4152 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4153 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4154 | Comment cmnt(masm_, "Global variable"); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4155 | __ mov(edx, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4156 | __ mov(ecx, Immediate(proxy->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4157 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4158 | // Use a regular load, not a contextual load, to avoid a reference |
| 4159 | // error. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4160 | CallIC(ic); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4161 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4162 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4163 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4164 | Label done, slow; |
| 4165 | |
| 4166 | // Generate code for loading from variables potentially shadowed |
| 4167 | // by eval-introduced variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4168 | EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4169 | |
| 4170 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | __ push(esi); |
| 4172 | __ push(Immediate(proxy->name())); |
| 4173 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4174 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4175 | __ bind(&done); |
| 4176 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4177 | context()->Plug(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4178 | } else { |
| 4179 | // This expression cannot throw a reference error at the top level. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4180 | VisitInDuplicateContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4185 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4186 | Expression* sub_expr, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4187 | Handle<String> check) { |
| 4188 | Label materialize_true, materialize_false; |
| 4189 | Label* if_true = NULL; |
| 4190 | Label* if_false = NULL; |
| 4191 | Label* fall_through = NULL; |
| 4192 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4193 | &if_true, &if_false, &fall_through); |
| 4194 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4195 | { AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4196 | VisitForTypeofValue(sub_expr); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4197 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4198 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4199 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4200 | if (check->Equals(isolate()->heap()->number_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4201 | __ JumpIfSmi(eax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4202 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4203 | isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4204 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4205 | } else if (check->Equals(isolate()->heap()->string_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4206 | __ JumpIfSmi(eax, if_false); |
| 4207 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4208 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4209 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4210 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4211 | 1 << Map::kIsUndetectable); |
| 4212 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4213 | } else if (check->Equals(isolate()->heap()->boolean_symbol())) { |
| 4214 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4215 | __ j(equal, if_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4216 | __ cmp(eax, isolate()->factory()->false_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4217 | Split(equal, if_true, if_false, fall_through); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4218 | } else if (FLAG_harmony_typeof && |
| 4219 | check->Equals(isolate()->heap()->null_symbol())) { |
| 4220 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4221 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4222 | } else if (check->Equals(isolate()->heap()->undefined_symbol())) { |
| 4223 | __ cmp(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4224 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4225 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4226 | // Check for undetectable objects => true. |
| 4227 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4228 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4229 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4230 | Split(not_zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4231 | } else if (check->Equals(isolate()->heap()->function_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4232 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4233 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4234 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4235 | __ j(equal, if_true); |
| 4236 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4237 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4238 | } else if (check->Equals(isolate()->heap()->object_symbol())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4239 | __ JumpIfSmi(eax, if_false); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4240 | if (!FLAG_harmony_typeof) { |
| 4241 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4242 | __ j(equal, if_true); |
| 4243 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4244 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4245 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4246 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4247 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4248 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4249 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4250 | 1 << Map::kIsUndetectable); |
| 4251 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4252 | } else { |
| 4253 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4254 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4255 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4256 | } |
| 4257 | |
| 4258 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4259 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4260 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4261 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4262 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4263 | // First we try a fast inlined version of the compare when one of |
| 4264 | // the operands is a literal. |
| 4265 | if (TryLiteralCompare(expr)) return; |
| 4266 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4267 | // Always perform the comparison for its control flow. Pack the result |
| 4268 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4269 | Label materialize_true, materialize_false; |
| 4270 | Label* if_true = NULL; |
| 4271 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4272 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4273 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4274 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4275 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4276 | Token::Value op = expr->op(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4277 | VisitForStackValue(expr->left()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4278 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4279 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4280 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4281 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4282 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4283 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4284 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4285 | break; |
| 4286 | |
| 4287 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4288 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4289 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4290 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4291 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4292 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4293 | // The stub returns 0 for true. |
| 4294 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4295 | break; |
| 4296 | } |
| 4297 | |
| 4298 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4299 | VisitForAccumulatorValue(expr->right()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4300 | Condition cc = CompareIC::ComputeCondition(op); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4301 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4302 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4303 | bool inline_smi_code = ShouldInlineSmiCase(op); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4304 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4305 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4306 | Label slow_case; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4307 | __ mov(ecx, edx); |
| 4308 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4309 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4310 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4311 | Split(cc, if_true, if_false, NULL); |
| 4312 | __ bind(&slow_case); |
| 4313 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4314 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4315 | // Record position and call the compare IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4316 | SetSourcePosition(expr->position()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4317 | Handle<Code> ic = CompareIC::GetUninitialized(op); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4318 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4319 | patch_site.EmitPatchInfo(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4320 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4321 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4322 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4323 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4324 | } |
| 4325 | } |
| 4326 | |
| 4327 | // Convert the result of the comparison into one expected for this |
| 4328 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4329 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4330 | } |
| 4331 | |
| 4332 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4333 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4334 | Expression* sub_expr, |
| 4335 | NilValue nil) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4336 | Label materialize_true, materialize_false; |
| 4337 | Label* if_true = NULL; |
| 4338 | Label* if_false = NULL; |
| 4339 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4340 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4341 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4342 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4343 | VisitForAccumulatorValue(sub_expr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4344 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4345 | Handle<Object> nil_value = nil == kNullValue ? |
| 4346 | isolate()->factory()->null_value() : |
| 4347 | isolate()->factory()->undefined_value(); |
| 4348 | __ cmp(eax, nil_value); |
| 4349 | if (expr->op() == Token::EQ_STRICT) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4350 | Split(equal, if_true, if_false, fall_through); |
| 4351 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4352 | Handle<Object> other_nil_value = nil == kNullValue ? |
| 4353 | isolate()->factory()->undefined_value() : |
| 4354 | isolate()->factory()->null_value(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4355 | __ j(equal, if_true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4356 | __ cmp(eax, other_nil_value); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4357 | __ j(equal, if_true); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4358 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4359 | // It can be an undetectable object. |
| 4360 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4361 | __ movzx_b(edx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4362 | __ test(edx, Immediate(1 << Map::kIsUndetectable)); |
| 4363 | Split(not_zero, if_true, if_false, fall_through); |
| 4364 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4365 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4369 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4370 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4371 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4375 | Register FullCodeGenerator::result_register() { |
| 4376 | return eax; |
| 4377 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4378 | |
| 4379 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4380 | Register FullCodeGenerator::context_register() { |
| 4381 | return esi; |
| 4382 | } |
| 4383 | |
| 4384 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4385 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4386 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 4387 | __ mov(Operand(ebp, frame_offset), value); |
| 4388 | } |
| 4389 | |
| 4390 | |
| 4391 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4392 | __ mov(dst, ContextOperand(esi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4396 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4397 | Scope* declaration_scope = scope()->DeclarationScope(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4398 | if (declaration_scope->is_global_scope() || |
| 4399 | declaration_scope->is_module_scope()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4400 | // Contexts nested in the native context have a canonical empty function |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4401 | // as their closure, not the anonymous closure containing the global |
| 4402 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4403 | // function. |
| 4404 | __ push(Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4405 | } else if (declaration_scope->is_eval_scope()) { |
| 4406 | // Contexts nested inside eval code have the same closure as the context |
| 4407 | // calling eval, not the anonymous closure containing the eval code. |
| 4408 | // Fetch it from the context. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4409 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 4410 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4411 | ASSERT(declaration_scope->is_function_scope()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4412 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4417 | // ---------------------------------------------------------------------------- |
| 4418 | // Non-local control flow support. |
| 4419 | |
| 4420 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4421 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4422 | ASSERT(!result_register().is(edx)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4423 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4424 | __ sub(edx, Immediate(masm_->CodeObject())); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4425 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4426 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4427 | __ SmiTag(edx); |
| 4428 | __ push(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4429 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4430 | // Store result register while executing finally block. |
| 4431 | __ push(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4432 | |
| 4433 | // Store pending message while executing finally block. |
| 4434 | ExternalReference pending_message_obj = |
| 4435 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4436 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4437 | __ push(edx); |
| 4438 | |
| 4439 | ExternalReference has_pending_message = |
| 4440 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4441 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4442 | __ SmiTag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4443 | __ push(edx); |
| 4444 | |
| 4445 | ExternalReference pending_message_script = |
| 4446 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4447 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 4448 | __ push(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | |
| 4452 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4453 | ASSERT(!result_register().is(edx)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4454 | // Restore pending message from stack. |
| 4455 | __ pop(edx); |
| 4456 | ExternalReference pending_message_script = |
| 4457 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4458 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 4459 | |
| 4460 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4461 | __ SmiUntag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4462 | ExternalReference has_pending_message = |
| 4463 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4464 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 4465 | |
| 4466 | __ pop(edx); |
| 4467 | ExternalReference pending_message_obj = |
| 4468 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4469 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4470 | |
| 4471 | // Restore result register from stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4472 | __ pop(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4473 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4474 | // Uncook return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4475 | __ pop(edx); |
| 4476 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4477 | __ add(edx, Immediate(masm_->CodeObject())); |
| 4478 | __ jmp(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | |
| 4482 | #undef __ |
| 4483 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4484 | #define __ ACCESS_MASM(masm()) |
| 4485 | |
| 4486 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 4487 | int* stack_depth, |
| 4488 | int* context_length) { |
| 4489 | // The macros used here must preserve the result register. |
| 4490 | |
| 4491 | // Because the handler block contains the context of the finally |
| 4492 | // code, we can restore it directly from there for the finally code |
| 4493 | // rather than iteratively unwinding contexts via their previous |
| 4494 | // links. |
| 4495 | __ Drop(*stack_depth); // Down to the handler block. |
| 4496 | if (*context_length > 0) { |
| 4497 | // Restore the context to its dedicated register and the stack. |
| 4498 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 4499 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 4500 | } |
| 4501 | __ PopTryHandler(); |
| 4502 | __ call(finally_entry_); |
| 4503 | |
| 4504 | *stack_depth = 0; |
| 4505 | *context_length = 0; |
| 4506 | return previous_; |
| 4507 | } |
| 4508 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4509 | #undef __ |
| 4510 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4511 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4512 | |
| 4513 | #endif // V8_TARGET_ARCH_IA32 |