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 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 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: |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 110 | // o ecx: CallKind |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 111 | // o edi: the JS function object being called (i.e. ourselves) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 112 | // o esi: our context |
| 113 | // o ebp: our caller's frame pointer |
| 114 | // o esp: stack pointer (pointing to return address) |
| 115 | // |
| 116 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 117 | // frames-ia32.h for its layout. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 118 | void FullCodeGenerator::Generate() { |
| 119 | CompilationInfo* info = info_; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 120 | handler_table_ = |
| 121 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 122 | profiling_counter_ = isolate()->factory()->NewCell( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 123 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 124 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 125 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 126 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 127 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 128 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 129 | #ifdef DEBUG |
| 130 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 131 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 132 | __ int3(); |
| 133 | } |
| 134 | #endif |
| 135 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 136 | // Strict mode functions and builtins need to replace the receiver |
| 137 | // with undefined when called as functions (without an explicit |
| 138 | // receiver object). ecx is zero for method calls and non-zero for |
| 139 | // function calls. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 140 | if (!info->is_classic_mode() || info->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 141 | Label ok; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 142 | __ test(ecx, ecx); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 143 | __ j(zero, &ok, Label::kNear); |
| 144 | // +1 for return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 145 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 146 | __ mov(ecx, Operand(esp, receiver_offset)); |
| 147 | __ JumpIfSmi(ecx, &ok); |
| 148 | __ CmpObjectType(ecx, JS_GLOBAL_PROXY_TYPE, ecx); |
| 149 | __ j(not_equal, &ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 150 | __ mov(Operand(esp, receiver_offset), |
| 151 | Immediate(isolate()->factory()->undefined_value())); |
| 152 | __ bind(&ok); |
| 153 | } |
| 154 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 155 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 156 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 157 | // the frame (that is done below). |
| 158 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 159 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 160 | info->set_prologue_offset(masm_->pc_offset()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 161 | __ Prologue(BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 162 | info->AddNoFrameRange(0, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 163 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 164 | { Comment cmnt(masm_, "[ Allocate locals"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 165 | int locals_count = info->scope()->num_stack_slots(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 166 | // Generators allocate locals, if any, in context slots. |
| 167 | ASSERT(!info->function()->is_generator() || locals_count == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 168 | if (locals_count == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 169 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 170 | } else if (locals_count > 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 171 | __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 172 | for (int i = 0; i < locals_count; i++) { |
| 173 | __ push(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 176 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 177 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 178 | bool function_in_register = true; |
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 | // Possibly allocate a local context. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 181 | 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] | 182 | if (heap_slots > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 183 | Comment cmnt(masm_, "[ Allocate context"); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 184 | // Argument to NewContext is the function, which is still in edi. |
| 185 | __ push(edi); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 186 | if (FLAG_harmony_scoping && info->scope()->is_global_scope()) { |
| 187 | __ Push(info->scope()->GetScopeInfo()); |
| 188 | __ CallRuntime(Runtime::kNewGlobalContext, 2); |
| 189 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 190 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 191 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 192 | } else { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 193 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 194 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 195 | function_in_register = false; |
| 196 | // Context is returned in both eax and esi. It replaces the context |
| 197 | // passed to us. It's saved in the stack and kept live in esi. |
| 198 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 199 | |
| 200 | // Copy parameters into context if necessary. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 201 | int num_parameters = info->scope()->num_parameters(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 202 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 203 | Variable* var = scope()->parameter(i); |
| 204 | if (var->IsContextSlot()) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 205 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 206 | (num_parameters - 1 - i) * kPointerSize; |
| 207 | // Load parameter from stack. |
| 208 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 209 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 210 | int context_offset = Context::SlotOffset(var->index()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 211 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 212 | // Update the write barrier. This clobbers eax and ebx. |
| 213 | __ RecordWriteContextSlot(esi, |
| 214 | context_offset, |
| 215 | eax, |
| 216 | ebx, |
| 217 | kDontSaveFPRegs); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 222 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 223 | if (arguments != NULL) { |
| 224 | // Function uses arguments object. |
| 225 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 226 | if (function_in_register) { |
| 227 | __ push(edi); |
| 228 | } else { |
| 229 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 230 | } |
| 231 | // Receiver is just before the parameters on the caller's stack. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 232 | int num_parameters = info->scope()->num_parameters(); |
| 233 | int offset = num_parameters * kPointerSize; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 234 | __ lea(edx, |
| 235 | Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 236 | __ push(edx); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 237 | __ push(Immediate(Smi::FromInt(num_parameters))); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 238 | // Arguments to ArgumentsAccessStub: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 239 | // function, receiver address, parameter count. |
| 240 | // The stub will rewrite receiver and parameter count if the previous |
| 241 | // stack frame was an arguments adapter frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 242 | ArgumentsAccessStub::Type type; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 243 | if (!is_classic_mode()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 244 | type = ArgumentsAccessStub::NEW_STRICT; |
| 245 | } else if (function()->has_duplicate_parameters()) { |
| 246 | type = ArgumentsAccessStub::NEW_NON_STRICT_SLOW; |
| 247 | } else { |
| 248 | type = ArgumentsAccessStub::NEW_NON_STRICT_FAST; |
| 249 | } |
| 250 | ArgumentsAccessStub stub(type); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 251 | __ CallStub(&stub); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 252 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 253 | SetVar(arguments, eax, ebx, edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 254 | } |
| 255 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 256 | if (FLAG_trace) { |
| 257 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 258 | } |
| 259 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 260 | // Visit the declarations and body unless there is an illegal |
| 261 | // redeclaration. |
| 262 | if (scope()->HasIllegalRedeclaration()) { |
| 263 | Comment cmnt(masm_, "[ Declarations"); |
| 264 | scope()->VisitIllegalRedeclaration(this); |
| 265 | |
| 266 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 267 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 268 | { Comment cmnt(masm_, "[ Declarations"); |
| 269 | // For named function expressions, declare the function name as a |
| 270 | // constant. |
| 271 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 272 | VariableDeclaration* function = scope()->function(); |
| 273 | ASSERT(function->proxy()->var()->mode() == CONST || |
| 274 | function->proxy()->var()->mode() == CONST_HARMONY); |
| 275 | ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 276 | VisitVariableDeclaration(function); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 277 | } |
| 278 | VisitDeclarations(scope()->declarations()); |
| 279 | } |
| 280 | |
| 281 | { Comment cmnt(masm_, "[ Stack check"); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 282 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 283 | Label ok; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 284 | ExternalReference stack_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 285 | ExternalReference::address_of_stack_limit(isolate()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 286 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 287 | __ j(above_equal, &ok, Label::kNear); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 288 | __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 289 | __ bind(&ok); |
| 290 | } |
| 291 | |
| 292 | { Comment cmnt(masm_, "[ Body"); |
| 293 | ASSERT(loop_depth() == 0); |
| 294 | VisitStatements(function()->body()); |
| 295 | ASSERT(loop_depth() == 0); |
| 296 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 297 | } |
| 298 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 299 | // Always emit a 'return undefined' in case control fell off the end of |
| 300 | // the body. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 301 | { Comment cmnt(masm_, "[ return <undefined>;"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 302 | __ mov(eax, isolate()->factory()->undefined_value()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 303 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 308 | void FullCodeGenerator::ClearAccumulator() { |
| 309 | __ Set(eax, Immediate(Smi::FromInt(0))); |
| 310 | } |
| 311 | |
| 312 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 313 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 314 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 315 | __ sub(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 316 | Immediate(Smi::FromInt(delta))); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 321 | int reset_value = FLAG_interrupt_budget; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 322 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 323 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 324 | Immediate(Smi::FromInt(reset_value))); |
| 325 | } |
| 326 | |
| 327 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 328 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 329 | Label* back_edge_target) { |
| 330 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 331 | Label ok; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 332 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 333 | ASSERT(back_edge_target->is_bound()); |
| 334 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 335 | int weight = Min(kMaxBackEdgeWeight, |
| 336 | Max(1, distance / kCodeSizeMultiplier)); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 337 | EmitProfilingCounterDecrement(weight); |
| 338 | __ j(positive, &ok, Label::kNear); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 339 | __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 340 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 341 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 342 | // the AST id from the unoptimized code in order to use it as a key into |
| 343 | // the deoptimization input data found in the optimized code. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 344 | RecordBackEdge(stmt->OsrEntryId()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 345 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 346 | EmitProfilingCounterReset(); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 347 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 348 | __ bind(&ok); |
| 349 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 350 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 351 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 352 | // we want it to work if it is. |
| 353 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 357 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 358 | Comment cmnt(masm_, "[ Return sequence"); |
| 359 | if (return_label_.is_bound()) { |
| 360 | __ jmp(&return_label_); |
| 361 | } else { |
| 362 | // Common return label |
| 363 | __ bind(&return_label_); |
| 364 | if (FLAG_trace) { |
| 365 | __ push(eax); |
| 366 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 367 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 368 | // Pretend that the exit is a backwards jump to the entry. |
| 369 | int weight = 1; |
| 370 | if (info_->ShouldSelfOptimize()) { |
| 371 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 372 | } else { |
| 373 | int distance = masm_->pc_offset(); |
| 374 | weight = Min(kMaxBackEdgeWeight, |
| 375 | Max(1, distance / kCodeSizeMultiplier)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 376 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 377 | EmitProfilingCounterDecrement(weight); |
| 378 | Label ok; |
| 379 | __ j(positive, &ok, Label::kNear); |
| 380 | __ push(eax); |
| 381 | __ call(isolate()->builtins()->InterruptCheck(), |
| 382 | RelocInfo::CODE_TARGET); |
| 383 | __ pop(eax); |
| 384 | EmitProfilingCounterReset(); |
| 385 | __ bind(&ok); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 386 | #ifdef DEBUG |
| 387 | // Add a label for checking the size of the code used for returning. |
| 388 | Label check_exit_codesize; |
| 389 | masm_->bind(&check_exit_codesize); |
| 390 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 391 | SetSourcePosition(function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 392 | __ RecordJSReturn(); |
| 393 | // Do not use the leave instruction here because it is too short to |
| 394 | // patch with the code required by the debugger. |
| 395 | __ mov(esp, ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 396 | int no_frame_start = masm_->pc_offset(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 397 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 398 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 399 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 400 | __ Ret(arguments_bytes, ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 401 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 402 | // Check that the size of the code used for returning is large enough |
| 403 | // for the debugger's requirements. |
| 404 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 405 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 406 | #endif |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 407 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| 411 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 412 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 413 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 417 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 418 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 419 | codegen()->GetVar(result_register(), var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 423 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 424 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 425 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 426 | // Memory operands can be pushed directly. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 427 | __ push(operand); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 431 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 432 | // For simplicity we always test the accumulator register. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 433 | codegen()->GetVar(result_register(), var); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 434 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 435 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
| 439 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 440 | UNREACHABLE(); // Not used on IA32. |
| 441 | } |
| 442 | |
| 443 | |
| 444 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 445 | Heap::RootListIndex index) const { |
| 446 | UNREACHABLE(); // Not used on IA32. |
| 447 | } |
| 448 | |
| 449 | |
| 450 | void FullCodeGenerator::StackValueContext::Plug( |
| 451 | Heap::RootListIndex index) const { |
| 452 | UNREACHABLE(); // Not used on IA32. |
| 453 | } |
| 454 | |
| 455 | |
| 456 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 457 | UNREACHABLE(); // Not used on IA32. |
| 458 | } |
| 459 | |
| 460 | |
| 461 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 462 | } |
| 463 | |
| 464 | |
| 465 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 466 | Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 467 | if (lit->IsSmi()) { |
| 468 | __ SafeSet(result_register(), Immediate(lit)); |
| 469 | } else { |
| 470 | __ Set(result_register(), Immediate(lit)); |
| 471 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
| 475 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 476 | if (lit->IsSmi()) { |
| 477 | __ SafePush(Immediate(lit)); |
| 478 | } else { |
| 479 | __ push(Immediate(lit)); |
| 480 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | |
| 484 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 485 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 486 | true, |
| 487 | true_label_, |
| 488 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 489 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 490 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 491 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 492 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 493 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 494 | } else if (lit->IsString()) { |
| 495 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 496 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 497 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 498 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 499 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 500 | } else if (lit->IsSmi()) { |
| 501 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 502 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 503 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 504 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 505 | } |
| 506 | } else { |
| 507 | // For simplicity we always test the accumulator register. |
| 508 | __ mov(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 509 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 514 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 515 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 516 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 517 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 521 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 522 | int count, |
| 523 | Register reg) const { |
| 524 | ASSERT(count > 0); |
| 525 | __ Drop(count); |
| 526 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 530 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 531 | Register reg) const { |
| 532 | ASSERT(count > 0); |
| 533 | if (count > 1) __ Drop(count - 1); |
| 534 | __ mov(Operand(esp, 0), reg); |
| 535 | } |
| 536 | |
| 537 | |
| 538 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 539 | Register reg) const { |
| 540 | ASSERT(count > 0); |
| 541 | // For simplicity we always test the accumulator register. |
| 542 | __ Drop(count); |
| 543 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 544 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 545 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | |
| 549 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 550 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 551 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 552 | __ bind(materialize_true); |
| 553 | } |
| 554 | |
| 555 | |
| 556 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 557 | Label* materialize_true, |
| 558 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 559 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 560 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 561 | __ mov(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 562 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 563 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 564 | __ mov(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 565 | __ bind(&done); |
| 566 | } |
| 567 | |
| 568 | |
| 569 | void FullCodeGenerator::StackValueContext::Plug( |
| 570 | Label* materialize_true, |
| 571 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 572 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 573 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 574 | __ push(Immediate(isolate()->factory()->true_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 575 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 576 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 577 | __ push(Immediate(isolate()->factory()->false_value())); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 578 | __ bind(&done); |
| 579 | } |
| 580 | |
| 581 | |
| 582 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 583 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 584 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 585 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
| 589 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 590 | } |
| 591 | |
| 592 | |
| 593 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 594 | Handle<Object> value = flag |
| 595 | ? isolate()->factory()->true_value() |
| 596 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 597 | __ mov(result_register(), value); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 602 | Handle<Object> value = flag |
| 603 | ? isolate()->factory()->true_value() |
| 604 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 605 | __ push(Immediate(value)); |
| 606 | } |
| 607 | |
| 608 | |
| 609 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 610 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 611 | true, |
| 612 | true_label_, |
| 613 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 614 | if (flag) { |
| 615 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 616 | } else { |
| 617 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
| 621 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 622 | void FullCodeGenerator::DoTest(Expression* condition, |
| 623 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 624 | Label* if_false, |
| 625 | Label* fall_through) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 626 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
| 627 | CallIC(ic, RelocInfo::CODE_TARGET, condition->test_id()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 628 | __ test(result_register(), result_register()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 629 | // The stub returns nonzero for true. |
| 630 | Split(not_zero, if_true, if_false, fall_through); |
| 631 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 632 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 633 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 634 | void FullCodeGenerator::Split(Condition cc, |
| 635 | Label* if_true, |
| 636 | Label* if_false, |
| 637 | Label* fall_through) { |
| 638 | if (if_false == fall_through) { |
| 639 | __ j(cc, if_true); |
| 640 | } else if (if_true == fall_through) { |
| 641 | __ j(NegateCondition(cc), if_false); |
| 642 | } else { |
| 643 | __ j(cc, if_true); |
| 644 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 649 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 650 | ASSERT(var->IsStackAllocated()); |
| 651 | // Offset is negative because higher indexes are at lower addresses. |
| 652 | int offset = -var->index() * kPointerSize; |
| 653 | // Adjust by a (parameter or local) base offset. |
| 654 | if (var->IsParameter()) { |
| 655 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 656 | } else { |
| 657 | offset += JavaScriptFrameConstants::kLocal0Offset; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 658 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 659 | return Operand(ebp, offset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 663 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 664 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 665 | if (var->IsContextSlot()) { |
| 666 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 667 | __ LoadContext(scratch, context_chain_length); |
| 668 | return ContextOperand(scratch, var->index()); |
| 669 | } else { |
| 670 | return StackOperand(var); |
| 671 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 675 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 676 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 677 | MemOperand location = VarOperand(var, dest); |
| 678 | __ mov(dest, location); |
| 679 | } |
| 680 | |
| 681 | |
| 682 | void FullCodeGenerator::SetVar(Variable* var, |
| 683 | Register src, |
| 684 | Register scratch0, |
| 685 | Register scratch1) { |
| 686 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 687 | ASSERT(!scratch0.is(src)); |
| 688 | ASSERT(!scratch0.is(scratch1)); |
| 689 | ASSERT(!scratch1.is(src)); |
| 690 | MemOperand location = VarOperand(var, scratch0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 691 | __ mov(location, src); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 692 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 693 | // 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] | 694 | if (var->IsContextSlot()) { |
| 695 | int offset = Context::SlotOffset(var->index()); |
| 696 | ASSERT(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 697 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 702 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 703 | bool should_normalize, |
| 704 | Label* if_true, |
| 705 | Label* if_false) { |
| 706 | // Only prepare for bailouts before splits if we're in a test |
| 707 | // context. Otherwise, we let the Visit function deal with the |
| 708 | // preparation to avoid preparing with the same AST id twice. |
| 709 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 710 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 711 | Label skip; |
| 712 | if (should_normalize) __ jmp(&skip, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 713 | PrepareForBailout(expr, TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 714 | if (should_normalize) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 715 | __ cmp(eax, isolate()->factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 716 | Split(equal, if_true, if_false, NULL); |
| 717 | __ bind(&skip); |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 722 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 723 | // 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] | 724 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 725 | if (generate_debug_code_) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 726 | // Check that we're not inside a with or catch context. |
| 727 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 728 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 729 | __ Check(not_equal, kDeclarationInWithContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 730 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 731 | __ Check(not_equal, kDeclarationInCatchContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 732 | } |
| 733 | } |
| 734 | |
| 735 | |
| 736 | void FullCodeGenerator::VisitVariableDeclaration( |
| 737 | VariableDeclaration* declaration) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 738 | // If it was not possible to allocate the variable at compile time, we |
| 739 | // need to "declare" it at runtime to make sure it actually exists in the |
| 740 | // local context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 741 | VariableProxy* proxy = declaration->proxy(); |
| 742 | VariableMode mode = declaration->mode(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 743 | Variable* variable = proxy->var(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 744 | bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 745 | switch (variable->location()) { |
| 746 | case Variable::UNALLOCATED: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 747 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 748 | globals_->Add(variable->binding_needs_init() |
| 749 | ? isolate()->factory()->the_hole_value() |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 750 | : isolate()->factory()->undefined_value(), zone()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case Variable::PARAMETER: |
| 754 | case Variable::LOCAL: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 755 | if (hole_init) { |
| 756 | Comment cmnt(masm_, "[ VariableDeclaration"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 757 | __ mov(StackOperand(variable), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 758 | Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 759 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 760 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 761 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 762 | case Variable::CONTEXT: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 763 | if (hole_init) { |
| 764 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 765 | EmitDebugCheckDeclarationContext(variable); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 766 | __ mov(ContextOperand(esi, variable->index()), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 767 | Immediate(isolate()->factory()->the_hole_value())); |
| 768 | // No write barrier since the hole value is in old space. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 769 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 770 | } |
| 771 | break; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 772 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 773 | case Variable::LOOKUP: { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 774 | Comment cmnt(masm_, "[ VariableDeclaration"); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 775 | __ push(esi); |
| 776 | __ push(Immediate(variable->name())); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 777 | // VariableDeclaration nodes are always introduced in one of four modes. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 778 | ASSERT(IsDeclaredVariableMode(mode)); |
| 779 | PropertyAttributes attr = |
| 780 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 781 | __ push(Immediate(Smi::FromInt(attr))); |
| 782 | // Push initial value, if any. |
| 783 | // Note: For variables we must not push an initial value (such as |
| 784 | // 'undefined') because we may have a (legal) redeclaration and we |
| 785 | // must not destroy the current value. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 786 | if (hole_init) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 787 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 788 | } else { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 789 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 790 | } |
| 791 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 792 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 798 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 799 | FunctionDeclaration* declaration) { |
| 800 | VariableProxy* proxy = declaration->proxy(); |
| 801 | Variable* variable = proxy->var(); |
| 802 | switch (variable->location()) { |
| 803 | case Variable::UNALLOCATED: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 804 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 805 | Handle<SharedFunctionInfo> function = |
| 806 | Compiler::BuildFunctionInfo(declaration->fun(), script()); |
| 807 | // Check for stack-overflow exception. |
| 808 | if (function.is_null()) return SetStackOverflow(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 809 | globals_->Add(function, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | |
| 813 | case Variable::PARAMETER: |
| 814 | case Variable::LOCAL: { |
| 815 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 816 | VisitForAccumulatorValue(declaration->fun()); |
| 817 | __ mov(StackOperand(variable), result_register()); |
| 818 | break; |
| 819 | } |
| 820 | |
| 821 | case Variable::CONTEXT: { |
| 822 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 823 | EmitDebugCheckDeclarationContext(variable); |
| 824 | VisitForAccumulatorValue(declaration->fun()); |
| 825 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 826 | // We know that we have written a function, which is not a smi. |
| 827 | __ RecordWriteContextSlot(esi, |
| 828 | Context::SlotOffset(variable->index()), |
| 829 | result_register(), |
| 830 | ecx, |
| 831 | kDontSaveFPRegs, |
| 832 | EMIT_REMEMBERED_SET, |
| 833 | OMIT_SMI_CHECK); |
| 834 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 835 | break; |
| 836 | } |
| 837 | |
| 838 | case Variable::LOOKUP: { |
| 839 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 840 | __ push(esi); |
| 841 | __ push(Immediate(variable->name())); |
| 842 | __ push(Immediate(Smi::FromInt(NONE))); |
| 843 | VisitForStackValue(declaration->fun()); |
| 844 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | |
| 851 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 852 | Variable* variable = declaration->proxy()->var(); |
| 853 | ASSERT(variable->location() == Variable::CONTEXT); |
| 854 | ASSERT(variable->interface()->IsFrozen()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 855 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 856 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 857 | EmitDebugCheckDeclarationContext(variable); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 858 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 859 | // Load instance object. |
| 860 | __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 861 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 862 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 863 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 864 | // Assign it. |
| 865 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 866 | // We know that we have written a module, which is not a smi. |
| 867 | __ RecordWriteContextSlot(esi, |
| 868 | Context::SlotOffset(variable->index()), |
| 869 | eax, |
| 870 | ecx, |
| 871 | kDontSaveFPRegs, |
| 872 | EMIT_REMEMBERED_SET, |
| 873 | OMIT_SMI_CHECK); |
| 874 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 875 | |
| 876 | // Traverse into body. |
| 877 | Visit(declaration->module()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | |
| 881 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 882 | VariableProxy* proxy = declaration->proxy(); |
| 883 | Variable* variable = proxy->var(); |
| 884 | switch (variable->location()) { |
| 885 | case Variable::UNALLOCATED: |
| 886 | // TODO(rossberg) |
| 887 | break; |
| 888 | |
| 889 | case Variable::CONTEXT: { |
| 890 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 891 | EmitDebugCheckDeclarationContext(variable); |
| 892 | // TODO(rossberg) |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | case Variable::PARAMETER: |
| 897 | case Variable::LOCAL: |
| 898 | case Variable::LOOKUP: |
| 899 | UNREACHABLE(); |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | |
| 904 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 905 | // TODO(rossberg) |
| 906 | } |
| 907 | |
| 908 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 909 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 910 | // Call the runtime to declare the globals. |
| 911 | __ push(esi); // The context is the first argument. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 912 | __ Push(pairs); |
| 913 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 914 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 915 | // Return value is ignored. |
| 916 | } |
| 917 | |
| 918 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 919 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 920 | // Call the runtime to declare the modules. |
| 921 | __ Push(descriptions); |
| 922 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 923 | // Return value is ignored. |
| 924 | } |
| 925 | |
| 926 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 927 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 928 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 929 | Breakable nested_statement(this, stmt); |
| 930 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 931 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 932 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 933 | VisitForStackValue(stmt->tag()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 934 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 935 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 936 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 937 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 938 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 939 | Label next_test; // Recycled for each test. |
| 940 | // Compile all the tests with branches to their bodies. |
| 941 | for (int i = 0; i < clauses->length(); i++) { |
| 942 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 943 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 944 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 945 | // The default is not a test, but remember it as final fall through. |
| 946 | if (clause->is_default()) { |
| 947 | default_clause = clause; |
| 948 | continue; |
| 949 | } |
| 950 | |
| 951 | Comment cmnt(masm_, "[ Case comparison"); |
| 952 | __ bind(&next_test); |
| 953 | next_test.Unuse(); |
| 954 | |
| 955 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 956 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 957 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 958 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 959 | __ mov(edx, Operand(esp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 960 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 961 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 962 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 963 | Label slow_case; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 964 | __ mov(ecx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 965 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 966 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 967 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 968 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 969 | __ j(not_equal, &next_test); |
| 970 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 971 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 972 | __ bind(&slow_case); |
| 973 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 974 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 975 | // Record position before stub call for type feedback. |
| 976 | SetSourcePosition(clause->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 977 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 978 | CallIC(ic, RelocInfo::CODE_TARGET, clause->CompareId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 979 | patch_site.EmitPatchInfo(); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 980 | |
| 981 | Label skip; |
| 982 | __ jmp(&skip, Label::kNear); |
| 983 | PrepareForBailout(clause, TOS_REG); |
| 984 | __ cmp(eax, isolate()->factory()->true_value()); |
| 985 | __ j(not_equal, &next_test); |
| 986 | __ Drop(1); |
| 987 | __ jmp(clause->body_target()); |
| 988 | __ bind(&skip); |
| 989 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 990 | __ test(eax, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 991 | __ j(not_equal, &next_test); |
| 992 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 993 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // Discard the test value and jump to the default if present, otherwise to |
| 997 | // the end of the statement. |
| 998 | __ bind(&next_test); |
| 999 | __ Drop(1); // Switch value is no longer needed. |
| 1000 | if (default_clause == NULL) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1001 | __ jmp(nested_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1002 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1003 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // Compile all the case bodies. |
| 1007 | for (int i = 0; i < clauses->length(); i++) { |
| 1008 | Comment cmnt(masm_, "[ Case body"); |
| 1009 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1010 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1011 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1012 | VisitStatements(clause->statements()); |
| 1013 | } |
| 1014 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1015 | __ bind(nested_statement.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1016 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1021 | Comment cmnt(masm_, "[ ForInStatement"); |
| 1022 | SetStatementPosition(stmt); |
| 1023 | |
| 1024 | Label loop, exit; |
| 1025 | ForIn loop_statement(this, stmt); |
| 1026 | increment_loop_depth(); |
| 1027 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1028 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1029 | // over the loop. See ECMA-262 version 5, section 12.6.4. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1030 | VisitForAccumulatorValue(stmt->enumerable()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1031 | __ cmp(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1032 | __ j(equal, &exit); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1033 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1034 | __ j(equal, &exit); |
| 1035 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1036 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1037 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1038 | // Convert the object to a JS object. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1039 | Label convert, done_convert; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1040 | __ JumpIfSmi(eax, &convert, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1041 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1042 | __ j(above_equal, &done_convert, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1043 | __ bind(&convert); |
| 1044 | __ push(eax); |
| 1045 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1046 | __ bind(&done_convert); |
| 1047 | __ push(eax); |
| 1048 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1049 | // Check for proxies. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1050 | Label call_runtime, use_cache, fixed_array; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1051 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1052 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1053 | __ j(below_equal, &call_runtime); |
| 1054 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1055 | // Check cache validity in generated code. This is a fast case for |
| 1056 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1057 | // guarantee cache validity, call the runtime system to check cache |
| 1058 | // validity or get the property names in a fixed array. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1059 | __ CheckEnumCache(&call_runtime); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1060 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1061 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1062 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1063 | |
| 1064 | // Get the set of properties to enumerate. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1065 | __ bind(&call_runtime); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1066 | __ push(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1067 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1068 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1069 | isolate()->factory()->meta_map()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1070 | __ j(not_equal, &fixed_array); |
| 1071 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1072 | |
| 1073 | // 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] | 1074 | Label no_descriptors; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1075 | __ bind(&use_cache); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1076 | |
| 1077 | __ EnumLength(edx, eax); |
| 1078 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1079 | __ j(equal, &no_descriptors); |
| 1080 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1081 | __ LoadInstanceDescriptors(eax, ecx); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1082 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1083 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1084 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1085 | // Set up the four remaining stack slots. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1086 | __ push(eax); // Map. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1087 | __ push(ecx); // Enumeration cache. |
| 1088 | __ 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] | 1089 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1090 | __ jmp(&loop); |
| 1091 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1092 | __ bind(&no_descriptors); |
| 1093 | __ add(esp, Immediate(kPointerSize)); |
| 1094 | __ jmp(&exit); |
| 1095 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1096 | // 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] | 1097 | Label non_proxy; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1098 | __ bind(&fixed_array); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1099 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1100 | Handle<Cell> cell = isolate()->factory()->NewCell( |
| 1101 | Handle<Object>(Smi::FromInt(TypeFeedbackCells::kForInFastCaseMarker), |
| 1102 | isolate())); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1103 | RecordTypeFeedbackCell(stmt->ForInFeedbackId(), cell); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1104 | __ LoadHeapObject(ebx, cell); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1105 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1106 | Immediate(Smi::FromInt(TypeFeedbackCells::kForInSlowCaseMarker))); |
| 1107 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1108 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1109 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1110 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1111 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1112 | __ j(above, &non_proxy); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 1113 | __ Set(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1114 | __ bind(&non_proxy); |
| 1115 | __ push(ebx); // Smi |
| 1116 | __ push(eax); // Array |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1117 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1118 | __ push(eax); // Fixed array length (as smi). |
| 1119 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1120 | |
| 1121 | // Generate code for doing the condition check. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1122 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1123 | __ bind(&loop); |
| 1124 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1125 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1126 | __ j(above_equal, loop_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1127 | |
| 1128 | // Get the current entry of the array into register ebx. |
| 1129 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1130 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1131 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1132 | // 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] | 1133 | // permanent slow case into register edx. |
| 1134 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1135 | |
| 1136 | // 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] | 1137 | // If not, we may have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1138 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1139 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1140 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1141 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1142 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1143 | // For proxies, no filtering is done. |
| 1144 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1145 | ASSERT(Smi::FromInt(0) == 0); |
| 1146 | __ test(edx, edx); |
| 1147 | __ j(zero, &update_each); |
| 1148 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1149 | // Convert the entry to a string or null if it isn't a property |
| 1150 | // anymore. If the property has been removed while iterating, we |
| 1151 | // just skip it. |
| 1152 | __ push(ecx); // Enumerable. |
| 1153 | __ push(ebx); // Current entry. |
| 1154 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1155 | __ test(eax, eax); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1156 | __ j(equal, loop_statement.continue_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1157 | __ mov(ebx, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Update the 'each' property or variable from the possibly filtered |
| 1160 | // entry in register ebx. |
| 1161 | __ bind(&update_each); |
| 1162 | __ mov(result_register(), ebx); |
| 1163 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1164 | { EffectContext context(this); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1165 | EmitAssignment(stmt->each()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1166 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1167 | |
| 1168 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1169 | Visit(stmt->body()); |
| 1170 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1171 | // Generate code for going to the next element by incrementing the |
| 1172 | // index (smi) stored on top of the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1173 | __ bind(loop_statement.continue_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1174 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1175 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1176 | EmitBackEdgeBookkeeping(stmt, &loop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1177 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Remove the pointers stored on the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1180 | __ bind(loop_statement.break_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1181 | __ add(esp, Immediate(5 * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1182 | |
| 1183 | // Exit and decrement the loop depth. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1184 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1185 | __ bind(&exit); |
| 1186 | decrement_loop_depth(); |
| 1187 | } |
| 1188 | |
| 1189 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1190 | void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 1191 | Comment cmnt(masm_, "[ ForOfStatement"); |
| 1192 | SetStatementPosition(stmt); |
| 1193 | |
| 1194 | Iteration loop_statement(this, stmt); |
| 1195 | increment_loop_depth(); |
| 1196 | |
| 1197 | // var iterator = iterable[@@iterator]() |
| 1198 | VisitForAccumulatorValue(stmt->assign_iterator()); |
| 1199 | |
| 1200 | // As with for-in, skip the loop if the iterator is null or undefined. |
| 1201 | __ CompareRoot(eax, Heap::kUndefinedValueRootIndex); |
| 1202 | __ j(equal, loop_statement.break_label()); |
| 1203 | __ CompareRoot(eax, Heap::kNullValueRootIndex); |
| 1204 | __ j(equal, loop_statement.break_label()); |
| 1205 | |
| 1206 | // Convert the iterator to a JS object. |
| 1207 | Label convert, done_convert; |
| 1208 | __ JumpIfSmi(eax, &convert); |
| 1209 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1210 | __ j(above_equal, &done_convert); |
| 1211 | __ bind(&convert); |
| 1212 | __ push(eax); |
| 1213 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1214 | __ bind(&done_convert); |
| 1215 | |
| 1216 | // Loop entry. |
| 1217 | __ bind(loop_statement.continue_label()); |
| 1218 | |
| 1219 | // result = iterator.next() |
| 1220 | VisitForEffect(stmt->next_result()); |
| 1221 | |
| 1222 | // if (result.done) break; |
| 1223 | Label result_not_done; |
| 1224 | VisitForControl(stmt->result_done(), |
| 1225 | loop_statement.break_label(), |
| 1226 | &result_not_done, |
| 1227 | &result_not_done); |
| 1228 | __ bind(&result_not_done); |
| 1229 | |
| 1230 | // each = result.value |
| 1231 | VisitForEffect(stmt->assign_each()); |
| 1232 | |
| 1233 | // Generate code for the body of the loop. |
| 1234 | Visit(stmt->body()); |
| 1235 | |
| 1236 | // Check stack before looping. |
| 1237 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
| 1238 | EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); |
| 1239 | __ jmp(loop_statement.continue_label()); |
| 1240 | |
| 1241 | // Exit and decrement the loop depth. |
| 1242 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1243 | __ bind(loop_statement.break_label()); |
| 1244 | decrement_loop_depth(); |
| 1245 | } |
| 1246 | |
| 1247 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1248 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1249 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1250 | // Use the fast case closure allocation code that allocates in new |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1251 | // space for nested functions that don't need literals cloning. If |
| 1252 | // we're running with the --always-opt or the --prepare-always-opt |
| 1253 | // flag, we need to use the runtime function so that the new function |
| 1254 | // we are creating here gets a chance to have its code optimized and |
| 1255 | // doesn't just get a copy of the existing unoptimized code. |
| 1256 | if (!FLAG_always_opt && |
| 1257 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1258 | !pretenure && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1259 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1260 | info->num_literals() == 0) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1261 | FastNewClosureStub stub(info->language_mode(), info->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1262 | __ mov(ebx, Immediate(info)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1263 | __ CallStub(&stub); |
| 1264 | } else { |
| 1265 | __ push(esi); |
| 1266 | __ push(Immediate(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1267 | __ push(Immediate(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1268 | ? isolate()->factory()->true_value() |
| 1269 | : isolate()->factory()->false_value())); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1270 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1271 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1272 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1277 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1278 | EmitVariableLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1282 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
| 1283 | TypeofState typeof_state, |
| 1284 | Label* slow) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1285 | Register context = esi; |
| 1286 | Register temp = edx; |
| 1287 | |
| 1288 | Scope* s = scope(); |
| 1289 | while (s != NULL) { |
| 1290 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1291 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1292 | // Check that extension is NULL. |
| 1293 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1294 | Immediate(0)); |
| 1295 | __ j(not_equal, slow); |
| 1296 | } |
| 1297 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1298 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1299 | // Walk the rest of the chain without clobbering esi. |
| 1300 | context = temp; |
| 1301 | } |
| 1302 | // If no outer scope calls eval, we do not need to check more |
| 1303 | // context extensions. If we have reached an eval scope, we check |
| 1304 | // all extensions from this point. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1305 | 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] | 1306 | s = s->outer_scope(); |
| 1307 | } |
| 1308 | |
| 1309 | if (s != NULL && s->is_eval_scope()) { |
| 1310 | // Loop up the context chain. There is no frame effect so it is |
| 1311 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1312 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1313 | if (!context.is(temp)) { |
| 1314 | __ mov(temp, context); |
| 1315 | } |
| 1316 | __ bind(&next); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1317 | // Terminate at native context. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1318 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1319 | Immediate(isolate()->factory()->native_context_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1320 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1321 | // Check that extension is NULL. |
| 1322 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1323 | __ j(not_equal, slow); |
| 1324 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1325 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1326 | __ jmp(&next); |
| 1327 | __ bind(&fast); |
| 1328 | } |
| 1329 | |
| 1330 | // All extension objects were empty and it is safe to use a global |
| 1331 | // load IC call. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1332 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1333 | __ mov(ecx, var->name()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1334 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1335 | RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF) |
| 1336 | ? RelocInfo::CODE_TARGET |
| 1337 | : RelocInfo::CODE_TARGET_CONTEXT; |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1338 | CallIC(ic, mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1342 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1343 | Label* slow) { |
| 1344 | ASSERT(var->IsContextSlot()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1345 | Register context = esi; |
| 1346 | Register temp = ebx; |
| 1347 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1348 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1349 | if (s->num_heap_slots() > 0) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1350 | if (s->calls_non_strict_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1351 | // Check that extension is NULL. |
| 1352 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1353 | Immediate(0)); |
| 1354 | __ j(not_equal, slow); |
| 1355 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1356 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1357 | // Walk the rest of the chain without clobbering esi. |
| 1358 | context = temp; |
| 1359 | } |
| 1360 | } |
| 1361 | // Check that last extension is NULL. |
| 1362 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1363 | __ j(not_equal, slow); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1364 | |
| 1365 | // This function is used only for loads, not stores, so it's safe to |
| 1366 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1367 | // destroy the esi register). |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1368 | return ContextOperand(context, var->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1372 | void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| 1373 | TypeofState typeof_state, |
| 1374 | Label* slow, |
| 1375 | Label* done) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1376 | // Generate fast-case code for variables that might be shadowed by |
| 1377 | // eval-introduced variables. Eval is used a lot without |
| 1378 | // introducing variables. In those cases, we do not want to |
| 1379 | // perform a runtime call for all variables in the scope |
| 1380 | // containing the eval. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1381 | if (var->mode() == DYNAMIC_GLOBAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1382 | EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1383 | __ jmp(done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1384 | } else if (var->mode() == DYNAMIC_LOCAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1385 | Variable* local = var->local_if_not_shadowed(); |
| 1386 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 1387 | if (local->mode() == LET || |
| 1388 | local->mode() == CONST || |
| 1389 | local->mode() == CONST_HARMONY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1390 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1391 | __ j(not_equal, done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1392 | if (local->mode() == CONST) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1393 | __ mov(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1394 | } else { // LET || CONST_HARMONY |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1395 | __ push(Immediate(var->name())); |
| 1396 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1397 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1398 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1399 | __ jmp(done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1404 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1405 | // Record position before possible IC call. |
| 1406 | SetSourcePosition(proxy->position()); |
| 1407 | Variable* var = proxy->var(); |
| 1408 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1409 | // Three cases: global variables, lookup variables, and all other types of |
| 1410 | // variables. |
| 1411 | switch (var->location()) { |
| 1412 | case Variable::UNALLOCATED: { |
| 1413 | Comment cmnt(masm_, "Global variable"); |
| 1414 | // Use inline caching. Variable name is passed in ecx and the global |
| 1415 | // object in eax. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1416 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1417 | __ mov(ecx, var->name()); |
| 1418 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 1419 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1420 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1421 | break; |
| 1422 | } |
| 1423 | |
| 1424 | case Variable::PARAMETER: |
| 1425 | case Variable::LOCAL: |
| 1426 | case Variable::CONTEXT: { |
| 1427 | Comment cmnt(masm_, var->IsContextSlot() |
| 1428 | ? "Context variable" |
| 1429 | : "Stack variable"); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1430 | if (var->binding_needs_init()) { |
| 1431 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1432 | // refers to a potential outside binding. Currently those bindings are |
| 1433 | // always looked up dynamically, i.e. in that case |
| 1434 | // var->location() == LOOKUP. |
| 1435 | // always holds. |
| 1436 | ASSERT(var->scope() != NULL); |
| 1437 | |
| 1438 | // Check if the binding really needs an initialization check. The check |
| 1439 | // can be skipped in the following situation: we have a LET or CONST |
| 1440 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1441 | // the same declaration scope (i.e. they are both in global code, in the |
| 1442 | // same function or in the same eval code) and the VariableProxy is in |
| 1443 | // the source physically located after the initializer of the variable. |
| 1444 | // |
| 1445 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1446 | // mode because const variables may be declared but never initialized: |
| 1447 | // if (false) { const x; }; var y = x; |
| 1448 | // |
| 1449 | // The condition on the declaration scopes is a conservative check for |
| 1450 | // nested functions that access a binding and are called before the |
| 1451 | // binding is initialized: |
| 1452 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1453 | // |
| 1454 | bool skip_init_check; |
| 1455 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1456 | skip_init_check = false; |
jkummerow@chromium.org | ac45fed | 2011-11-07 13:11:02 +0000 | [diff] [blame] | 1457 | } else { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1458 | // Check that we always have valid source position. |
| 1459 | ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1460 | ASSERT(proxy->position() != RelocInfo::kNoPosition); |
| 1461 | skip_init_check = var->mode() != CONST && |
| 1462 | var->initializer_position() < proxy->position(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1463 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1464 | |
| 1465 | if (!skip_init_check) { |
| 1466 | // Let and const need a read barrier. |
| 1467 | Label done; |
| 1468 | GetVar(eax, var); |
| 1469 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1470 | __ j(not_equal, &done, Label::kNear); |
| 1471 | if (var->mode() == LET || var->mode() == CONST_HARMONY) { |
| 1472 | // Throw a reference error when using an uninitialized let/const |
| 1473 | // binding in harmony mode. |
| 1474 | __ push(Immediate(var->name())); |
| 1475 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1476 | } else { |
| 1477 | // Uninitalized const bindings outside of harmony mode are unholed. |
| 1478 | ASSERT(var->mode() == CONST); |
| 1479 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1480 | } |
| 1481 | __ bind(&done); |
| 1482 | context()->Plug(eax); |
| 1483 | break; |
| 1484 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1485 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1486 | context()->Plug(var); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1487 | break; |
| 1488 | } |
| 1489 | |
| 1490 | case Variable::LOOKUP: { |
| 1491 | Label done, slow; |
| 1492 | // Generate code for loading from variables potentially shadowed |
| 1493 | // by eval-introduced variables. |
| 1494 | EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1495 | __ bind(&slow); |
| 1496 | Comment cmnt(masm_, "Lookup variable"); |
| 1497 | __ push(esi); // Context. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1498 | __ push(Immediate(var->name())); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1499 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1500 | __ bind(&done); |
| 1501 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1502 | break; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1503 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | |
| 1508 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1509 | Comment cmnt(masm_, "[ RegExpLiteral"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1510 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1511 | // Registers will be used as follows: |
| 1512 | // edi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1513 | // ecx = literals array. |
| 1514 | // ebx = regexp literal. |
| 1515 | // eax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1516 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1517 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1518 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1519 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1520 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1521 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1522 | __ j(not_equal, &materialized, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1523 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1524 | // Create regexp literal using runtime function |
| 1525 | // Result will be in eax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1526 | __ push(ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1527 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1528 | __ push(Immediate(expr->pattern())); |
| 1529 | __ push(Immediate(expr->flags())); |
| 1530 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1531 | __ mov(ebx, eax); |
| 1532 | |
| 1533 | __ bind(&materialized); |
| 1534 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1535 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1536 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1537 | __ jmp(&allocated); |
| 1538 | |
| 1539 | __ bind(&runtime_allocate); |
| 1540 | __ push(ebx); |
| 1541 | __ push(Immediate(Smi::FromInt(size))); |
| 1542 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1543 | __ pop(ebx); |
| 1544 | |
| 1545 | __ bind(&allocated); |
| 1546 | // Copy the content into the newly allocated memory. |
| 1547 | // (Unroll copy loop once for better throughput). |
| 1548 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1549 | __ mov(edx, FieldOperand(ebx, i)); |
| 1550 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1551 | __ mov(FieldOperand(eax, i), edx); |
| 1552 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1553 | } |
| 1554 | if ((size % (2 * kPointerSize)) != 0) { |
| 1555 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1556 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1557 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1558 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1562 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1563 | if (expression == NULL) { |
| 1564 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1565 | } else { |
| 1566 | VisitForStackValue(expression); |
| 1567 | } |
| 1568 | } |
| 1569 | |
| 1570 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1571 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1572 | Comment cmnt(masm_, "[ ObjectLiteral"); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1573 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1574 | expr->BuildConstantProperties(isolate()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1575 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1576 | int flags = expr->fast_elements() |
| 1577 | ? ObjectLiteral::kFastElements |
| 1578 | : ObjectLiteral::kNoFlags; |
| 1579 | flags |= expr->has_function() |
| 1580 | ? ObjectLiteral::kHasFunction |
| 1581 | : ObjectLiteral::kNoFlags; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1582 | int properties_count = constant_properties->length() / 2; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 1583 | if ((FLAG_track_double_fields && expr->may_store_doubles()) || |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1584 | expr->depth() > 1 || Serializer::enabled() || |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1585 | flags != ObjectLiteral::kFastElements || |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1586 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1587 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1588 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1589 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1590 | __ push(Immediate(constant_properties)); |
| 1591 | __ push(Immediate(Smi::FromInt(flags))); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1592 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1593 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1594 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1595 | __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1596 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1597 | __ mov(ecx, Immediate(constant_properties)); |
| 1598 | __ mov(edx, Immediate(Smi::FromInt(flags))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1599 | FastCloneShallowObjectStub stub(properties_count); |
| 1600 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | // If result_saved is true the result is on top of the stack. If |
| 1604 | // result_saved is false the result is in eax. |
| 1605 | bool result_saved = false; |
| 1606 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1607 | // Mark all computed expressions that are bound to a key that |
| 1608 | // is shadowed by a later occurrence of the same key. For the |
| 1609 | // marked expressions, no store code is emitted. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1610 | expr->CalculateEmitStore(zone()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1611 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1612 | AccessorTable accessor_table(zone()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1613 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1614 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1615 | if (property->IsCompileTimeValue()) continue; |
| 1616 | |
| 1617 | Literal* key = property->key(); |
| 1618 | Expression* value = property->value(); |
| 1619 | if (!result_saved) { |
| 1620 | __ push(eax); // Save result on the stack |
| 1621 | result_saved = true; |
| 1622 | } |
| 1623 | switch (property->kind()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1624 | case ObjectLiteral::Property::CONSTANT: |
| 1625 | UNREACHABLE(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1626 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1627 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1628 | // Fall through. |
| 1629 | case ObjectLiteral::Property::COMPUTED: |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1630 | if (key->value()->IsInternalizedString()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1631 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1632 | VisitForAccumulatorValue(value); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1633 | __ mov(ecx, Immediate(key->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | __ mov(edx, Operand(esp, 0)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1635 | Handle<Code> ic = is_classic_mode() |
| 1636 | ? isolate()->builtins()->StoreIC_Initialize() |
| 1637 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1638 | CallIC(ic, RelocInfo::CODE_TARGET, key->LiteralFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1640 | } else { |
| 1641 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1642 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1643 | break; |
| 1644 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1645 | __ push(Operand(esp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1646 | VisitForStackValue(key); |
| 1647 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1648 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1649 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1650 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1651 | } else { |
| 1652 | __ Drop(3); |
| 1653 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1654 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1655 | case ObjectLiteral::Property::PROTOTYPE: |
| 1656 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1657 | VisitForStackValue(value); |
| 1658 | if (property->emit_store()) { |
| 1659 | __ CallRuntime(Runtime::kSetPrototype, 2); |
| 1660 | } else { |
| 1661 | __ Drop(2); |
| 1662 | } |
| 1663 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1664 | case ObjectLiteral::Property::GETTER: |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1665 | accessor_table.lookup(key)->second->getter = value; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1666 | break; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1667 | case ObjectLiteral::Property::SETTER: |
| 1668 | accessor_table.lookup(key)->second->setter = value; |
| 1669 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1670 | } |
| 1671 | } |
| 1672 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1673 | // Emit code to define accessors, using only a single call to the runtime for |
| 1674 | // each pair of corresponding getters and setters. |
| 1675 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1676 | it != accessor_table.end(); |
| 1677 | ++it) { |
| 1678 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1679 | VisitForStackValue(it->first); |
| 1680 | EmitAccessor(it->second->getter); |
| 1681 | EmitAccessor(it->second->setter); |
| 1682 | __ push(Immediate(Smi::FromInt(NONE))); |
| 1683 | __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1684 | } |
| 1685 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1686 | if (expr->has_function()) { |
| 1687 | ASSERT(result_saved); |
| 1688 | __ push(Operand(esp, 0)); |
| 1689 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1690 | } |
| 1691 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1692 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1693 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1694 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1695 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1701 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1702 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1703 | expr->BuildConstantElements(isolate()); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1704 | int flags = expr->depth() == 1 |
| 1705 | ? ArrayLiteral::kShallowElements |
| 1706 | : ArrayLiteral::kNoFlags; |
| 1707 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1708 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1709 | int length = subexprs->length(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1710 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1711 | ASSERT_EQ(2, constant_elements->length()); |
| 1712 | ElementsKind constant_elements_kind = |
| 1713 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1714 | bool has_constant_fast_elements = |
| 1715 | IsFastObjectElementsKind(constant_elements_kind); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1716 | Handle<FixedArrayBase> constant_elements_values( |
| 1717 | FixedArrayBase::cast(constant_elements->get(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1718 | |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1719 | AllocationSiteMode allocation_site_mode = FLAG_track_allocation_sites |
| 1720 | ? TRACK_ALLOCATION_SITE : DONT_TRACK_ALLOCATION_SITE; |
| 1721 | if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1722 | // If the only customer of allocation sites is transitioning, then |
| 1723 | // we can turn it off if we don't have anywhere else to transition to. |
| 1724 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1725 | } |
| 1726 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1727 | Heap* heap = isolate()->heap(); |
| 1728 | if (has_constant_fast_elements && |
| 1729 | constant_elements_values->map() == heap->fixed_cow_array_map()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1730 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1731 | // change, so it's possible to specialize the stub in advance. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1732 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1733 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1734 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1735 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1736 | __ mov(ecx, Immediate(constant_elements)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1737 | FastCloneShallowArrayStub stub( |
| 1738 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1739 | allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1740 | length); |
| 1741 | __ CallStub(&stub); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1742 | } else if (expr->depth() > 1 || Serializer::enabled() || |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1743 | length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1744 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1745 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1746 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1747 | __ push(Immediate(constant_elements)); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1748 | __ push(Immediate(Smi::FromInt(flags))); |
| 1749 | __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1750 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1751 | ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1752 | FLAG_smi_only_arrays); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1753 | FastCloneShallowArrayStub::Mode mode = |
| 1754 | FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1755 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1756 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1757 | // change, so it's possible to specialize the stub in advance. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1758 | if (has_constant_fast_elements) { |
| 1759 | mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1762 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1763 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1764 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1765 | __ mov(ecx, Immediate(constant_elements)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1766 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1767 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | bool result_saved = false; // Is the result saved to the stack? |
| 1771 | |
| 1772 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1773 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1774 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1775 | Expression* subexpr = subexprs->at(i); |
| 1776 | // If the subexpression is a literal or a simple materialized literal it |
| 1777 | // is already set in the cloned array. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1778 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1779 | |
| 1780 | if (!result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1781 | __ push(eax); // array literal. |
| 1782 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1783 | result_saved = true; |
| 1784 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1785 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1786 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1787 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1788 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1789 | // cannot transition and don't need to call the runtime stub. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1790 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1791 | __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1792 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1793 | // Store the subexpression value in the array's elements. |
| 1794 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1795 | // Update the write barrier for the array store. |
| 1796 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1797 | kDontSaveFPRegs, |
| 1798 | EMIT_REMEMBERED_SET, |
| 1799 | INLINE_SMI_CHECK); |
| 1800 | } else { |
| 1801 | // Store the subexpression value in the array's elements. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1802 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1803 | StoreArrayLiteralElementStub stub; |
| 1804 | __ CallStub(&stub); |
| 1805 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1806 | |
| 1807 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | if (result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1811 | __ add(esp, Immediate(kPointerSize)); // literal index |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1812 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1813 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1814 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1819 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1820 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1821 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1822 | // on the left-hand side. |
| 1823 | if (!expr->target()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1824 | VisitForEffect(expr->target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1825 | return; |
| 1826 | } |
| 1827 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1828 | // 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] | 1829 | // slot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1830 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1831 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1832 | Property* property = expr->target()->AsProperty(); |
| 1833 | if (property != NULL) { |
| 1834 | assign_type = (property->key()->IsPropertyName()) |
| 1835 | ? NAMED_PROPERTY |
| 1836 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | // Evaluate LHS expression. |
| 1840 | switch (assign_type) { |
| 1841 | case VARIABLE: |
| 1842 | // Nothing to do here. |
| 1843 | break; |
| 1844 | case NAMED_PROPERTY: |
| 1845 | if (expr->is_compound()) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1846 | // We need the receiver both on the stack and in edx. |
| 1847 | VisitForStackValue(property->obj()); |
| 1848 | __ mov(edx, Operand(esp, 0)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1849 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1850 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1851 | } |
| 1852 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1853 | case KEYED_PROPERTY: { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1854 | if (expr->is_compound()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1855 | VisitForStackValue(property->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1856 | VisitForStackValue(property->key()); |
| 1857 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 1858 | __ mov(ecx, Operand(esp, 0)); // Key. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1859 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1860 | VisitForStackValue(property->obj()); |
| 1861 | VisitForStackValue(property->key()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1862 | } |
| 1863 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1864 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1865 | } |
| 1866 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1867 | // For compound assignments we need another deoptimization point after the |
| 1868 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1869 | if (expr->is_compound()) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1870 | AccumulatorValueContext result_context(this); |
| 1871 | { AccumulatorValueContext left_operand_context(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1872 | switch (assign_type) { |
| 1873 | case VARIABLE: |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1874 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1875 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1876 | break; |
| 1877 | case NAMED_PROPERTY: |
| 1878 | EmitNamedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1879 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1880 | break; |
| 1881 | case KEYED_PROPERTY: |
| 1882 | EmitKeyedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1883 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1884 | break; |
| 1885 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1886 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1887 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1888 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1889 | __ push(eax); // Left operand goes on the stack. |
| 1890 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1891 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1892 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1893 | ? OVERWRITE_RIGHT |
| 1894 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1895 | SetSourcePosition(expr->position() + 1); |
| 1896 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1897 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1898 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1899 | mode, |
| 1900 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1901 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1902 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1903 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1904 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1905 | |
| 1906 | // Deoptimization point in case the binary operation may have side effects. |
| 1907 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1908 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1909 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | // Record source position before possible IC call. |
| 1913 | SetSourcePosition(expr->position()); |
| 1914 | |
| 1915 | // Store the value. |
| 1916 | switch (assign_type) { |
| 1917 | case VARIABLE: |
| 1918 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1919 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1920 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1921 | context()->Plug(eax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1922 | break; |
| 1923 | case NAMED_PROPERTY: |
| 1924 | EmitNamedPropertyAssignment(expr); |
| 1925 | break; |
| 1926 | case KEYED_PROPERTY: |
| 1927 | EmitKeyedPropertyAssignment(expr); |
| 1928 | break; |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1933 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1934 | Comment cmnt(masm_, "[ Yield"); |
| 1935 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1936 | // this. It stays on the stack while we update the iterator. |
| 1937 | VisitForStackValue(expr->expression()); |
| 1938 | |
| 1939 | switch (expr->yield_kind()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1940 | case Yield::SUSPEND: |
| 1941 | // Pop value from top-of-stack slot; box result into result register. |
| 1942 | EmitCreateIteratorResult(false); |
| 1943 | __ push(result_register()); |
| 1944 | // Fall through. |
| 1945 | case Yield::INITIAL: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1946 | Label suspend, continuation, post_runtime, resume; |
| 1947 | |
| 1948 | __ jmp(&suspend); |
| 1949 | |
| 1950 | __ bind(&continuation); |
| 1951 | __ jmp(&resume); |
| 1952 | |
| 1953 | __ bind(&suspend); |
| 1954 | VisitForAccumulatorValue(expr->generator_object()); |
| 1955 | ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1956 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 1957 | Immediate(Smi::FromInt(continuation.pos()))); |
| 1958 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 1959 | __ mov(ecx, esi); |
| 1960 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 1961 | kDontSaveFPRegs); |
| 1962 | __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
| 1963 | __ cmp(esp, ebx); |
| 1964 | __ j(equal, &post_runtime); |
| 1965 | __ push(eax); // generator object |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1966 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1967 | __ mov(context_register(), |
| 1968 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1969 | __ bind(&post_runtime); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1970 | __ pop(result_register()); |
| 1971 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1972 | |
| 1973 | __ bind(&resume); |
| 1974 | context()->Plug(result_register()); |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | case Yield::FINAL: { |
| 1979 | VisitForAccumulatorValue(expr->generator_object()); |
| 1980 | __ mov(FieldOperand(result_register(), |
| 1981 | JSGeneratorObject::kContinuationOffset), |
| 1982 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1983 | // Pop value from top-of-stack slot, box result into result register. |
| 1984 | EmitCreateIteratorResult(true); |
| 1985 | EmitUnwindBeforeReturn(); |
| 1986 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1987 | break; |
| 1988 | } |
| 1989 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1990 | case Yield::DELEGATING: { |
| 1991 | VisitForStackValue(expr->generator_object()); |
| 1992 | |
| 1993 | // Initial stack layout is as follows: |
| 1994 | // [sp + 1 * kPointerSize] iter |
| 1995 | // [sp + 0 * kPointerSize] g |
| 1996 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1997 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 1998 | Label l_next, l_call, l_loop; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1999 | // Initial send value is undefined. |
| 2000 | __ mov(eax, isolate()->factory()->undefined_value()); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2001 | __ jmp(&l_next); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2002 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2003 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2004 | __ bind(&l_catch); |
| 2005 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2006 | __ mov(ecx, isolate()->factory()->throw_string()); // "throw" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2007 | __ push(ecx); // "throw" |
| 2008 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2009 | __ push(eax); // exception |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2010 | __ jmp(&l_call); |
| 2011 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2012 | // try { received = %yield result } |
| 2013 | // Shuffle the received result above a try handler and yield it without |
| 2014 | // re-boxing. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2015 | __ bind(&l_try); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2016 | __ pop(eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2017 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 2018 | const int handler_size = StackHandlerConstants::kSize; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2019 | __ push(eax); // result |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2020 | __ jmp(&l_suspend); |
| 2021 | __ bind(&l_continuation); |
| 2022 | __ jmp(&l_resume); |
| 2023 | __ bind(&l_suspend); |
| 2024 | const int generator_object_depth = kPointerSize + handler_size; |
| 2025 | __ mov(eax, Operand(esp, generator_object_depth)); |
| 2026 | __ push(eax); // g |
| 2027 | ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2028 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 2029 | Immediate(Smi::FromInt(l_continuation.pos()))); |
| 2030 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 2031 | __ mov(ecx, esi); |
| 2032 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 2033 | kDontSaveFPRegs); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2034 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 2035 | __ mov(context_register(), |
| 2036 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2037 | __ pop(eax); // result |
| 2038 | EmitReturnSequence(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2039 | __ bind(&l_resume); // received in eax |
| 2040 | __ PopTryHandler(); |
| 2041 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2042 | // receiver = iter; f = iter.next; arg = received; |
| 2043 | __ bind(&l_next); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2044 | __ mov(ecx, isolate()->factory()->next_string()); // "next" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2045 | __ push(ecx); |
| 2046 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2047 | __ push(eax); // received |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2048 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2049 | // result = receiver[f](arg); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2050 | __ bind(&l_call); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2051 | Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(1); |
| 2052 | CallIC(ic); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2053 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2054 | __ Drop(1); // The key is still on the stack; drop it. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2055 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2056 | // if (!result.done) goto l_try; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2057 | __ bind(&l_loop); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2058 | __ push(eax); // save result |
| 2059 | __ mov(edx, eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2060 | __ mov(ecx, isolate()->factory()->done_string()); // "done" |
| 2061 | Handle<Code> done_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2062 | CallIC(done_ic); // result.done in eax |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2063 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2064 | CallIC(bool_ic); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2065 | __ test(eax, eax); |
| 2066 | __ j(zero, &l_try); |
| 2067 | |
| 2068 | // result.value |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2069 | __ pop(edx); // result |
| 2070 | __ mov(ecx, isolate()->factory()->value_string()); // "value" |
| 2071 | Handle<Code> value_ic = isolate()->builtins()->LoadIC_Initialize(); |
| 2072 | CallIC(value_ic); // result.value in eax |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2073 | context()->DropAndPlug(2, eax); // drop iter and g |
| 2074 | break; |
| 2075 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2080 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2081 | Expression *value, |
| 2082 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2083 | // The value stays in eax, and is ultimately read by the resumed generator, as |
| 2084 | // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. ebx |
| 2085 | // will hold the generator object until the activation has been resumed. |
| 2086 | VisitForStackValue(generator); |
| 2087 | VisitForAccumulatorValue(value); |
| 2088 | __ pop(ebx); |
| 2089 | |
| 2090 | // Check generator state. |
| 2091 | Label wrong_state, done; |
| 2092 | STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); |
| 2093 | STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); |
| 2094 | __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2095 | Immediate(Smi::FromInt(0))); |
| 2096 | __ j(less_equal, &wrong_state); |
| 2097 | |
| 2098 | // Load suspended function and context. |
| 2099 | __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 2100 | __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 2101 | |
| 2102 | // Push receiver. |
| 2103 | __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
| 2104 | |
| 2105 | // Push holes for arguments to generator function. |
| 2106 | __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2107 | __ mov(edx, |
| 2108 | FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 2109 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 2110 | Label push_argument_holes, push_frame; |
| 2111 | __ bind(&push_argument_holes); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2112 | __ sub(edx, Immediate(Smi::FromInt(1))); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2113 | __ j(carry, &push_frame); |
| 2114 | __ push(ecx); |
| 2115 | __ jmp(&push_argument_holes); |
| 2116 | |
| 2117 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2118 | // the generator was suspended. |
| 2119 | Label resume_frame; |
| 2120 | __ bind(&push_frame); |
| 2121 | __ call(&resume_frame); |
| 2122 | __ jmp(&done); |
| 2123 | __ bind(&resume_frame); |
| 2124 | __ push(ebp); // Caller's frame pointer. |
| 2125 | __ mov(ebp, esp); |
| 2126 | __ push(esi); // Callee's context. |
| 2127 | __ push(edi); // Callee's JS Function. |
| 2128 | |
| 2129 | // Load the operand stack size. |
| 2130 | __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 2131 | __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 2132 | __ SmiUntag(edx); |
| 2133 | |
| 2134 | // If we are sending a value and there is no operand stack, we can jump back |
| 2135 | // in directly. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2136 | if (resume_mode == JSGeneratorObject::NEXT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2137 | Label slow_resume; |
| 2138 | __ cmp(edx, Immediate(0)); |
| 2139 | __ j(not_zero, &slow_resume); |
| 2140 | __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2141 | __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 2142 | __ SmiUntag(ecx); |
| 2143 | __ add(edx, ecx); |
| 2144 | __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2145 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2146 | __ jmp(edx); |
| 2147 | __ bind(&slow_resume); |
| 2148 | } |
| 2149 | |
| 2150 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2151 | // up the stack and the handlers. |
| 2152 | Label push_operand_holes, call_resume; |
| 2153 | __ bind(&push_operand_holes); |
| 2154 | __ sub(edx, Immediate(1)); |
| 2155 | __ j(carry, &call_resume); |
| 2156 | __ push(ecx); |
| 2157 | __ jmp(&push_operand_holes); |
| 2158 | __ bind(&call_resume); |
| 2159 | __ push(ebx); |
| 2160 | __ push(result_register()); |
| 2161 | __ Push(Smi::FromInt(resume_mode)); |
| 2162 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2163 | // Not reached: the runtime call returns elsewhere. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2164 | __ Abort(kGeneratorFailedToResume); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2165 | |
| 2166 | // Throw error if we attempt to operate on a running generator. |
| 2167 | __ bind(&wrong_state); |
| 2168 | __ push(ebx); |
| 2169 | __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
| 2170 | |
| 2171 | __ bind(&done); |
| 2172 | context()->Plug(result_register()); |
| 2173 | } |
| 2174 | |
| 2175 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2176 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2177 | Label gc_required; |
| 2178 | Label allocated; |
| 2179 | |
| 2180 | Handle<Map> map(isolate()->native_context()->generator_result_map()); |
| 2181 | |
| 2182 | __ Allocate(map->instance_size(), eax, ecx, edx, &gc_required, TAG_OBJECT); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2183 | __ jmp(&allocated); |
| 2184 | |
| 2185 | __ bind(&gc_required); |
| 2186 | __ Push(Smi::FromInt(map->instance_size())); |
| 2187 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2188 | __ mov(context_register(), |
| 2189 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2190 | |
| 2191 | __ bind(&allocated); |
| 2192 | __ mov(ebx, map); |
| 2193 | __ pop(ecx); |
| 2194 | __ mov(edx, isolate()->factory()->ToBoolean(done)); |
| 2195 | ASSERT_EQ(map->instance_size(), 5 * kPointerSize); |
| 2196 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2197 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2198 | isolate()->factory()->empty_fixed_array()); |
| 2199 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2200 | isolate()->factory()->empty_fixed_array()); |
| 2201 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2202 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2203 | |
| 2204 | // Only the value field needs a write barrier, as the other values are in the |
| 2205 | // root set. |
| 2206 | __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2207 | ecx, edx, kDontSaveFPRegs); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2208 | } |
| 2209 | |
| 2210 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2211 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 2212 | SetSourcePosition(prop->position()); |
| 2213 | Literal* key = prop->key()->AsLiteral(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2214 | ASSERT(!key->value()->IsSmi()); |
| 2215 | __ mov(ecx, Immediate(key->value())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2216 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2217 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | |
| 2221 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 2222 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2223 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2224 | CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2228 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2229 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2230 | OverwriteMode mode, |
| 2231 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2232 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2233 | // Do combined smi check of the operands. Left operand is on the |
| 2234 | // stack. Right operand is in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2235 | Label smi_case, done, stub_call; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2236 | __ pop(edx); |
| 2237 | __ mov(ecx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2238 | __ or_(eax, edx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2239 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2240 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2241 | |
| 2242 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2243 | __ mov(eax, ecx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2244 | BinaryOpICStub stub(op, mode); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2245 | CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2246 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2247 | patch_site.EmitPatchInfo(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2248 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2249 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2250 | // Smi case. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2251 | __ bind(&smi_case); |
| 2252 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 2253 | |
| 2254 | switch (op) { |
| 2255 | case Token::SAR: |
| 2256 | __ SmiUntag(eax); |
| 2257 | __ SmiUntag(ecx); |
| 2258 | __ sar_cl(eax); // No checks of result necessary |
| 2259 | __ SmiTag(eax); |
| 2260 | break; |
| 2261 | case Token::SHL: { |
| 2262 | Label result_ok; |
| 2263 | __ SmiUntag(eax); |
| 2264 | __ SmiUntag(ecx); |
| 2265 | __ shl_cl(eax); |
| 2266 | // Check that the *signed* result fits in a smi. |
| 2267 | __ cmp(eax, 0xc0000000); |
| 2268 | __ j(positive, &result_ok); |
| 2269 | __ SmiTag(ecx); |
| 2270 | __ jmp(&stub_call); |
| 2271 | __ bind(&result_ok); |
| 2272 | __ SmiTag(eax); |
| 2273 | break; |
| 2274 | } |
| 2275 | case Token::SHR: { |
| 2276 | Label result_ok; |
| 2277 | __ SmiUntag(eax); |
| 2278 | __ SmiUntag(ecx); |
| 2279 | __ shr_cl(eax); |
| 2280 | __ test(eax, Immediate(0xc0000000)); |
| 2281 | __ j(zero, &result_ok); |
| 2282 | __ SmiTag(ecx); |
| 2283 | __ jmp(&stub_call); |
| 2284 | __ bind(&result_ok); |
| 2285 | __ SmiTag(eax); |
| 2286 | break; |
| 2287 | } |
| 2288 | case Token::ADD: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2289 | __ add(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2290 | __ j(overflow, &stub_call); |
| 2291 | break; |
| 2292 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2293 | __ sub(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2294 | __ j(overflow, &stub_call); |
| 2295 | break; |
| 2296 | case Token::MUL: { |
| 2297 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2298 | __ imul(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2299 | __ j(overflow, &stub_call); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2300 | __ test(eax, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2301 | __ j(not_zero, &done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2302 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2303 | __ or_(ebx, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2304 | __ j(negative, &stub_call); |
| 2305 | break; |
| 2306 | } |
| 2307 | case Token::BIT_OR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2308 | __ or_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | case Token::BIT_AND: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2311 | __ and_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2312 | break; |
| 2313 | case Token::BIT_XOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2314 | __ xor_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2315 | break; |
| 2316 | default: |
| 2317 | UNREACHABLE(); |
| 2318 | } |
| 2319 | |
| 2320 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2321 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2322 | } |
| 2323 | |
| 2324 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2325 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2326 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2327 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2328 | __ pop(edx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2329 | BinaryOpICStub stub(op, mode); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2330 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2331 | CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2332 | expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2333 | patch_site.EmitPatchInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2334 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2338 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2339 | // Invalid left-hand sides are rewritten by the parser to have a 'throw |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2340 | // ReferenceError' on the left-hand side. |
| 2341 | if (!expr->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2342 | VisitForEffect(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | // 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] | 2347 | // slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2348 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2349 | LhsKind assign_type = VARIABLE; |
| 2350 | Property* prop = expr->AsProperty(); |
| 2351 | if (prop != NULL) { |
| 2352 | assign_type = (prop->key()->IsPropertyName()) |
| 2353 | ? NAMED_PROPERTY |
| 2354 | : KEYED_PROPERTY; |
| 2355 | } |
| 2356 | |
| 2357 | switch (assign_type) { |
| 2358 | case VARIABLE: { |
| 2359 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2360 | EffectContext context(this); |
| 2361 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | } |
| 2364 | case NAMED_PROPERTY: { |
| 2365 | __ push(eax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2366 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2367 | __ mov(edx, eax); |
| 2368 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2369 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2370 | Handle<Code> ic = is_classic_mode() |
| 2371 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2372 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2373 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2374 | break; |
| 2375 | } |
| 2376 | case KEYED_PROPERTY: { |
| 2377 | __ push(eax); // Preserve value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2378 | VisitForStackValue(prop->obj()); |
| 2379 | VisitForAccumulatorValue(prop->key()); |
| 2380 | __ mov(ecx, eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2381 | __ pop(edx); // Receiver. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2382 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2383 | Handle<Code> ic = is_classic_mode() |
| 2384 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2385 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2386 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2387 | break; |
| 2388 | } |
| 2389 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2390 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2394 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2395 | Token::Value op) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2396 | if (var->IsUnallocated()) { |
| 2397 | // Global var, const, or let. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2398 | __ mov(ecx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2399 | __ mov(edx, GlobalObjectOperand()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2400 | Handle<Code> ic = is_classic_mode() |
| 2401 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2402 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2403 | CallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2404 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2405 | } else if (op == Token::INIT_CONST) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2406 | // Const initializers need a write barrier. |
| 2407 | ASSERT(!var->IsParameter()); // No const parameters. |
| 2408 | if (var->IsStackLocal()) { |
| 2409 | Label skip; |
| 2410 | __ mov(edx, StackOperand(var)); |
| 2411 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2412 | __ j(not_equal, &skip); |
| 2413 | __ mov(StackOperand(var), eax); |
| 2414 | __ bind(&skip); |
| 2415 | } else { |
| 2416 | ASSERT(var->IsContextSlot() || var->IsLookupSlot()); |
| 2417 | // Like var declarations, const declarations are hoisted to function |
| 2418 | // scope. However, unlike var initializers, const initializers are |
| 2419 | // able to drill a hole to that function context, even from inside a |
| 2420 | // 'with' context. We thus bypass the normal static scope lookup for |
| 2421 | // var->IsContextSlot(). |
| 2422 | __ push(eax); |
| 2423 | __ push(esi); |
| 2424 | __ push(Immediate(var->name())); |
| 2425 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2426 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2427 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2428 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2429 | // Non-initializing assignment to let variable needs a write barrier. |
| 2430 | if (var->IsLookupSlot()) { |
| 2431 | __ push(eax); // Value. |
| 2432 | __ push(esi); // Context. |
| 2433 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2434 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2435 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
| 2436 | } else { |
| 2437 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 2438 | Label assign; |
| 2439 | MemOperand location = VarOperand(var, ecx); |
| 2440 | __ mov(edx, location); |
| 2441 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2442 | __ j(not_equal, &assign, Label::kNear); |
| 2443 | __ push(Immediate(var->name())); |
| 2444 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2445 | __ bind(&assign); |
| 2446 | __ mov(location, eax); |
| 2447 | if (var->IsContextSlot()) { |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2448 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2449 | int offset = Context::SlotOffset(var->index()); |
| 2450 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2451 | } |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2452 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2453 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2454 | } else if (!var->is_const_mode() || op == Token::INIT_CONST_HARMONY) { |
| 2455 | // Assignment to var or initializing assignment to let/const |
| 2456 | // in harmony mode. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2457 | if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 2458 | MemOperand location = VarOperand(var, ecx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2459 | if (generate_debug_code_ && op == Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2460 | // Check for an uninitialized let binding. |
| 2461 | __ mov(edx, location); |
| 2462 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2463 | __ Check(equal, kLetBindingReInitialization); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2464 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2465 | // Perform the assignment. |
| 2466 | __ mov(location, eax); |
| 2467 | if (var->IsContextSlot()) { |
| 2468 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2469 | int offset = Context::SlotOffset(var->index()); |
| 2470 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2471 | } |
| 2472 | } else { |
| 2473 | ASSERT(var->IsLookupSlot()); |
| 2474 | __ push(eax); // Value. |
| 2475 | __ push(esi); // Context. |
| 2476 | __ push(Immediate(var->name())); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2477 | __ push(Immediate(Smi::FromInt(language_mode()))); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2478 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2479 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2480 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2481 | // Non-initializing assignments to consts are ignored. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2482 | } |
| 2483 | |
| 2484 | |
| 2485 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2486 | // Assignment to a property, using a named store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2487 | // eax : value |
| 2488 | // esp[0] : receiver |
| 2489 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2490 | Property* prop = expr->target()->AsProperty(); |
| 2491 | ASSERT(prop != NULL); |
| 2492 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2493 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2494 | // Record source code position before IC call. |
| 2495 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2496 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2497 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2498 | Handle<Code> ic = is_classic_mode() |
| 2499 | ? isolate()->builtins()->StoreIC_Initialize() |
| 2500 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2501 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2502 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2503 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2504 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
| 2507 | |
| 2508 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2509 | // Assignment to a property, using a keyed store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2510 | // eax : value |
| 2511 | // esp[0] : key |
| 2512 | // esp[kPointerSize] : receiver |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2513 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2514 | __ pop(ecx); // Key. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2515 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2516 | // Record source code position before IC call. |
| 2517 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2518 | Handle<Code> ic = is_classic_mode() |
| 2519 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2520 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2521 | CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2522 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2523 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2524 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | |
| 2528 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2529 | Comment cmnt(masm_, "[ Property"); |
| 2530 | Expression* key = expr->key(); |
| 2531 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2532 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2533 | VisitForAccumulatorValue(expr->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2534 | __ mov(edx, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2535 | EmitNamedPropertyLoad(expr); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2536 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2537 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2538 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2539 | VisitForStackValue(expr->obj()); |
| 2540 | VisitForAccumulatorValue(expr->key()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2541 | __ pop(edx); // Object. |
| 2542 | __ mov(ecx, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2543 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2544 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2545 | } |
| 2546 | } |
| 2547 | |
| 2548 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2549 | void FullCodeGenerator::CallIC(Handle<Code> code, |
| 2550 | RelocInfo::Mode rmode, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2551 | TypeFeedbackId ast_id) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2552 | ic_total_count_++; |
| 2553 | __ call(code, rmode, ast_id); |
| 2554 | } |
| 2555 | |
| 2556 | |
| 2557 | |
| 2558 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2559 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
| 2560 | Handle<Object> name, |
| 2561 | RelocInfo::Mode mode) { |
| 2562 | // Code common for calls using the IC. |
| 2563 | ZoneList<Expression*>* args = expr->arguments(); |
| 2564 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2565 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2566 | for (int i = 0; i < arg_count; i++) { |
| 2567 | VisitForStackValue(args->at(i)); |
| 2568 | } |
| 2569 | __ Set(ecx, Immediate(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2570 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2571 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2572 | SetSourcePosition(expr->position()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2573 | Handle<Code> ic = |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2574 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2575 | CallIC(ic, mode, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2576 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2577 | // Restore context register. |
| 2578 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2579 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2583 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2584 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2585 | // Load the key. |
| 2586 | VisitForAccumulatorValue(key); |
| 2587 | |
| 2588 | // Swap the name of the function and the receiver on the stack to follow |
| 2589 | // the calling convention for call ICs. |
| 2590 | __ pop(ecx); |
| 2591 | __ push(eax); |
| 2592 | __ push(ecx); |
| 2593 | |
| 2594 | // Load the arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2595 | ZoneList<Expression*>* args = expr->arguments(); |
| 2596 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2597 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2598 | for (int i = 0; i < arg_count; i++) { |
| 2599 | VisitForStackValue(args->at(i)); |
| 2600 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2601 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2602 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2603 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2604 | Handle<Code> ic = |
| 2605 | isolate()->stub_cache()->ComputeKeyedCallInitialize(arg_count); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2606 | __ mov(ecx, Operand(esp, (arg_count + 1) * kPointerSize)); // Key. |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2607 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CallFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2608 | RecordJSReturnSite(expr); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2609 | // Restore context register. |
| 2610 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2611 | context()->DropAndPlug(1, eax); // Drop the key still on the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2615 | void FullCodeGenerator::EmitCallWithStub(Call* expr, CallFunctionFlags flags) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2616 | // Code common for calls using the call stub. |
| 2617 | ZoneList<Expression*>* args = expr->arguments(); |
| 2618 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2619 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2620 | for (int i = 0; i < arg_count; i++) { |
| 2621 | VisitForStackValue(args->at(i)); |
| 2622 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2623 | } |
| 2624 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2625 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2626 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2627 | // Record call targets in unoptimized code. |
| 2628 | flags = static_cast<CallFunctionFlags>(flags | RECORD_CALL_TARGET); |
| 2629 | Handle<Object> uninitialized = |
| 2630 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2631 | Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2632 | RecordTypeFeedbackCell(expr->CallFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2633 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2634 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2635 | CallFunctionStub stub(arg_count, flags); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2636 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2637 | __ CallStub(&stub, expr->CallFeedbackId()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2638 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2639 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2640 | // Restore context register. |
| 2641 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2642 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2646 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2647 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2648 | if (arg_count > 0) { |
| 2649 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2650 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2651 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | // Push the receiver of the enclosing function. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2655 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2656 | // Push the language mode. |
| 2657 | __ push(Immediate(Smi::FromInt(language_mode()))); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2658 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2659 | // Push the start position of the scope the calls resides in. |
| 2660 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
| 2661 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2662 | // Do the runtime call. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2663 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2667 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2668 | #ifdef DEBUG |
| 2669 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2670 | // through this function. Avoid early returns. |
| 2671 | expr->return_is_recorded_ = false; |
| 2672 | #endif |
| 2673 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2674 | Comment cmnt(masm_, "[ Call"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2675 | Expression* callee = expr->expression(); |
| 2676 | VariableProxy* proxy = callee->AsVariableProxy(); |
| 2677 | Property* property = callee->AsProperty(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2678 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2679 | if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2680 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2681 | // resolve the function we need to call and the receiver of the call. |
| 2682 | // Then we call the resolved function using the given arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2683 | ZoneList<Expression*>* args = expr->arguments(); |
| 2684 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2685 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2686 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2687 | // Reserved receiver slot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2688 | __ push(Immediate(isolate()->factory()->undefined_value())); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2689 | // Push the arguments. |
| 2690 | for (int i = 0; i < arg_count; i++) { |
| 2691 | VisitForStackValue(args->at(i)); |
| 2692 | } |
| 2693 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2694 | // Push a copy of the function (found below the arguments) and |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2695 | // resolve eval. |
| 2696 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2697 | EmitResolvePossiblyDirectEval(arg_count); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2698 | |
| 2699 | // The runtime call returns a pair of values in eax (function) and |
| 2700 | // edx (receiver). Touch up the stack with the right values. |
| 2701 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2702 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2703 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2704 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2705 | SetSourcePosition(expr->position()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2706 | CallFunctionStub stub(arg_count, RECEIVER_MIGHT_BE_IMPLICIT); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2707 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2708 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2709 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2710 | // Restore context register. |
| 2711 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2712 | context()->DropAndPlug(1, eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2713 | |
| 2714 | } else if (proxy != NULL && proxy->var()->IsUnallocated()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2715 | // Push global object as receiver for the call IC. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2716 | __ push(GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2717 | EmitCallWithIC(expr, proxy->name(), RelocInfo::CODE_TARGET_CONTEXT); |
| 2718 | |
| 2719 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2720 | // Call to a lookup slot (dynamically introduced variable). |
| 2721 | Label slow, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2722 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2723 | // Generate code for loading from variables potentially shadowed by |
| 2724 | // eval-introduced variables. |
| 2725 | EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2726 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2727 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2728 | // Call the runtime to find the function to call (returned in eax) and |
| 2729 | // the object holding it (returned in edx). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2730 | __ push(context_register()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2731 | __ push(Immediate(proxy->name())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2732 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2733 | __ push(eax); // Function. |
| 2734 | __ push(edx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2735 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2736 | // If fast case code has been generated, emit code to push the function |
| 2737 | // and receiver and have the slow path jump around this code. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2738 | if (done.is_linked()) { |
| 2739 | Label call; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2740 | __ jmp(&call, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2741 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2742 | // Push function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2743 | __ push(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2744 | // The receiver is implicitly the global receiver. Indicate this by |
| 2745 | // passing the hole to the call function stub. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2746 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2747 | __ bind(&call); |
| 2748 | } |
| 2749 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2750 | // The receiver is either the global receiver or an object found by |
| 2751 | // LoadContextSlot. That object could be the hole if the receiver is |
| 2752 | // implicitly the global object. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2753 | EmitCallWithStub(expr, RECEIVER_MIGHT_BE_IMPLICIT); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2754 | |
| 2755 | } else if (property != NULL) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2756 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2757 | VisitForStackValue(property->obj()); |
| 2758 | } |
| 2759 | if (property->key()->IsPropertyName()) { |
| 2760 | EmitCallWithIC(expr, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2761 | property->key()->AsLiteral()->value(), |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2762 | RelocInfo::CODE_TARGET); |
| 2763 | } else { |
| 2764 | EmitKeyedCallWithIC(expr, property->key()); |
| 2765 | } |
| 2766 | |
| 2767 | } else { |
| 2768 | // Call to an arbitrary expression not handled specially above. |
| 2769 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2770 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2771 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2772 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2773 | __ mov(ebx, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2774 | __ push(FieldOperand(ebx, GlobalObject::kGlobalReceiverOffset)); |
| 2775 | // Emit function call. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2776 | EmitCallWithStub(expr, NO_CALL_FUNCTION_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2777 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2778 | |
| 2779 | #ifdef DEBUG |
| 2780 | // RecordJSReturnSite should have been called. |
| 2781 | ASSERT(expr->return_is_recorded_); |
| 2782 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | |
| 2786 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2787 | Comment cmnt(masm_, "[ CallNew"); |
| 2788 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2789 | // expression in new calls must be evaluated before the |
| 2790 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2791 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2792 | // Push constructor on the stack. If it's not a function it's used as |
| 2793 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2794 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2795 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2796 | |
| 2797 | // Push the arguments ("left-to-right") on the stack. |
| 2798 | ZoneList<Expression*>* args = expr->arguments(); |
| 2799 | int arg_count = args->length(); |
| 2800 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2801 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | // Call the construct call builtin that handles allocation and |
| 2805 | // constructor invocation. |
| 2806 | SetSourcePosition(expr->position()); |
| 2807 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2808 | // Load function and argument count into edi and eax. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2809 | __ Set(eax, Immediate(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2810 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2811 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2812 | // Record call targets in unoptimized code. |
| 2813 | Handle<Object> uninitialized = |
| 2814 | TypeFeedbackCells::UninitializedSentinel(isolate()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2815 | Handle<Cell> cell = isolate()->factory()->NewCell(uninitialized); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2816 | RecordTypeFeedbackCell(expr->CallNewFeedbackId(), cell); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2817 | __ mov(ebx, cell); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2818 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2819 | CallConstructStub stub(RECORD_CALL_TARGET); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2820 | __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2821 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2822 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2826 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2827 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2828 | ASSERT(args->length() == 1); |
| 2829 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2830 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2831 | |
| 2832 | Label materialize_true, materialize_false; |
| 2833 | Label* if_true = NULL; |
| 2834 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2835 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2836 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2837 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2838 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2839 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2840 | __ test(eax, Immediate(kSmiTagMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2841 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2842 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2843 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2847 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2848 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2849 | ASSERT(args->length() == 1); |
| 2850 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2851 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2852 | |
| 2853 | Label materialize_true, materialize_false; |
| 2854 | Label* if_true = NULL; |
| 2855 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2856 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2857 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2858 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2859 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2860 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2861 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2862 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2863 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2864 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
| 2867 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2868 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2869 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2870 | ASSERT(args->length() == 1); |
| 2871 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2872 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2873 | |
| 2874 | Label materialize_true, materialize_false; |
| 2875 | Label* if_true = NULL; |
| 2876 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2877 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2878 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2879 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2880 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2881 | __ JumpIfSmi(eax, if_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2882 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2883 | __ j(equal, if_true); |
| 2884 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2885 | // Undetectable objects behave like undefined when tested with typeof. |
| 2886 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2887 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 2888 | __ j(not_zero, if_false); |
| 2889 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2890 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2891 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2892 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2893 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2894 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2895 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2896 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2900 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2901 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2902 | ASSERT(args->length() == 1); |
| 2903 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2904 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2905 | |
| 2906 | Label materialize_true, materialize_false; |
| 2907 | Label* if_true = NULL; |
| 2908 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2909 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2910 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2911 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2912 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2913 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2914 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2915 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2916 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2917 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2918 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2922 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2923 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2924 | ASSERT(args->length() == 1); |
| 2925 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2926 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2927 | |
| 2928 | Label materialize_true, materialize_false; |
| 2929 | Label* if_true = NULL; |
| 2930 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2931 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2932 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2933 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2934 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2935 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2936 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2937 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2938 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2939 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2940 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2941 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2942 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2943 | } |
| 2944 | |
| 2945 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2946 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2947 | CallRuntime* expr) { |
| 2948 | ZoneList<Expression*>* args = expr->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2949 | ASSERT(args->length() == 1); |
| 2950 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2951 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2952 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 2953 | Label materialize_true, materialize_false, skip_lookup; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2954 | Label* if_true = NULL; |
| 2955 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2956 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2957 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2958 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2959 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2960 | __ AssertNotSmi(eax); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2961 | |
| 2962 | // Check whether this map has already been checked to be safe for default |
| 2963 | // valueOf. |
| 2964 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2965 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 2966 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 2967 | __ j(not_zero, &skip_lookup); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2968 | |
| 2969 | // Check for fast case object. Return false for slow case objects. |
| 2970 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 2971 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2972 | __ cmp(ecx, isolate()->factory()->hash_table_map()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2973 | __ j(equal, if_false); |
| 2974 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2975 | // Look for valueOf string in the descriptor array, and indicate false if |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2976 | // found. Since we omit an enumeration index check, if it is added via a |
| 2977 | // transition that shares its descriptor array, this is a false positive. |
| 2978 | Label entry, loop, done; |
| 2979 | |
| 2980 | // Skip loop if no descriptors are valid. |
| 2981 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 2982 | __ cmp(ecx, 0); |
| 2983 | __ j(equal, &done); |
| 2984 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2985 | __ LoadInstanceDescriptors(ebx, ebx); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2986 | // ebx: descriptor array. |
| 2987 | // ecx: valid entries in the descriptor array. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2988 | // Calculate the end of the descriptor array. |
| 2989 | STATIC_ASSERT(kSmiTag == 0); |
| 2990 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2991 | STATIC_ASSERT(kPointerSize == 4); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 2992 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 2993 | __ lea(ecx, Operand(ebx, ecx, times_2, DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2994 | // Calculate location of the first key name. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2995 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2996 | // Loop through all the keys in the descriptor array. If one of these is the |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2997 | // internalized string "valueOf" the result is false. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2998 | __ jmp(&entry); |
| 2999 | __ bind(&loop); |
| 3000 | __ mov(edx, FieldOperand(ebx, 0)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3001 | __ cmp(edx, isolate()->factory()->value_of_string()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3002 | __ j(equal, if_false); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3003 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3004 | __ bind(&entry); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3005 | __ cmp(ebx, ecx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3006 | __ j(not_equal, &loop); |
| 3007 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3008 | __ bind(&done); |
| 3009 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3010 | // Reload map as register ebx was used as temporary above. |
| 3011 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3012 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3013 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3014 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 3015 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 3016 | |
| 3017 | __ bind(&skip_lookup); |
| 3018 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3019 | // 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] | 3020 | // prototype is the un-modified String prototype. If not result is false. |
| 3021 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3022 | __ JumpIfSmi(ecx, if_false); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3023 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3024 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3025 | __ mov(edx, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3026 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3027 | __ cmp(ecx, |
| 3028 | ContextOperand(edx, |
| 3029 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3030 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3031 | Split(equal, if_true, if_false, fall_through); |
| 3032 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3033 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3037 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3038 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3039 | ASSERT(args->length() == 1); |
| 3040 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3041 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3042 | |
| 3043 | Label materialize_true, materialize_false; |
| 3044 | Label* if_true = NULL; |
| 3045 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3046 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3047 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3048 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3049 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3050 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3051 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3052 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3053 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3054 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3055 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3059 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3060 | ZoneList<Expression*>* args = expr->arguments(); |
| 3061 | ASSERT(args->length() == 1); |
| 3062 | |
| 3063 | VisitForAccumulatorValue(args->at(0)); |
| 3064 | |
| 3065 | Label materialize_true, materialize_false; |
| 3066 | Label* if_true = NULL; |
| 3067 | Label* if_false = NULL; |
| 3068 | Label* fall_through = NULL; |
| 3069 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3070 | &if_true, &if_false, &fall_through); |
| 3071 | |
| 3072 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 3073 | __ CheckMap(eax, map, if_false, DO_SMI_CHECK); |
| 3074 | __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x80000000)); |
| 3075 | __ j(not_equal, if_false); |
| 3076 | __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x00000000)); |
| 3077 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3078 | Split(equal, if_true, if_false, fall_through); |
| 3079 | |
| 3080 | context()->Plug(if_true, if_false); |
| 3081 | } |
| 3082 | |
| 3083 | |
| 3084 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3085 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3086 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3087 | ASSERT(args->length() == 1); |
| 3088 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3089 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3090 | |
| 3091 | Label materialize_true, materialize_false; |
| 3092 | Label* if_true = NULL; |
| 3093 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3094 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3095 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3096 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3097 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3098 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3099 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3100 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3101 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3102 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3103 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
| 3106 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3107 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3108 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3109 | ASSERT(args->length() == 1); |
| 3110 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3111 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3112 | |
| 3113 | Label materialize_true, materialize_false; |
| 3114 | Label* if_true = NULL; |
| 3115 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3116 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3117 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3118 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3119 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3120 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3121 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3122 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3123 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3124 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3125 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | |
| 3129 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3130 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 3131 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3132 | |
| 3133 | Label materialize_true, materialize_false; |
| 3134 | Label* if_true = NULL; |
| 3135 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3136 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3137 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3138 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3139 | |
| 3140 | // Get the frame pointer for the calling frame. |
| 3141 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3142 | |
| 3143 | // Skip the arguments adaptor frame if it exists. |
| 3144 | Label check_frame_marker; |
| 3145 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 3146 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3147 | __ j(not_equal, &check_frame_marker); |
| 3148 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 3149 | |
| 3150 | // Check the marker in the calling frame. |
| 3151 | __ bind(&check_frame_marker); |
| 3152 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 3153 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3154 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3155 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3156 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3157 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3161 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3162 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3163 | ASSERT(args->length() == 2); |
| 3164 | |
| 3165 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3166 | VisitForStackValue(args->at(0)); |
| 3167 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3168 | |
| 3169 | Label materialize_true, materialize_false; |
| 3170 | Label* if_true = NULL; |
| 3171 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3172 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3173 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3174 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3175 | |
| 3176 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3177 | __ cmp(eax, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3178 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3179 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3180 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3181 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3185 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3186 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3187 | ASSERT(args->length() == 1); |
| 3188 | |
| 3189 | // ArgumentsAccessStub expects the key in edx and the formal |
| 3190 | // parameter count in eax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3191 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3192 | __ mov(edx, eax); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3193 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3194 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 3195 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3196 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3200 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 3201 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3202 | |
| 3203 | Label exit; |
| 3204 | // Get the number of formal parameters. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3205 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3206 | |
| 3207 | // Check if the calling frame is an arguments adaptor frame. |
| 3208 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3209 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 3210 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3211 | __ j(not_equal, &exit); |
| 3212 | |
| 3213 | // Arguments adaptor case: Read the arguments length from the |
| 3214 | // adaptor frame. |
| 3215 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3216 | |
| 3217 | __ bind(&exit); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3218 | __ AssertSmi(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3219 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3223 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3224 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3225 | ASSERT(args->length() == 1); |
| 3226 | Label done, null, function, non_function_constructor; |
| 3227 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3228 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3229 | |
| 3230 | // If the object is a smi, we return null. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3231 | __ JumpIfSmi(eax, &null); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3232 | |
| 3233 | // Check that the object is a JS object but take special care of JS |
| 3234 | // functions to make sure they have 'Function' as their class. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3235 | // Assume that there are only two callable types, and one of them is at |
| 3236 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3237 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3238 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 3239 | // Map is now in eax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3240 | __ j(below, &null); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3241 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3242 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3243 | __ j(equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3244 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3245 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 3246 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3247 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3248 | __ j(equal, &function); |
| 3249 | // Assume that there is no larger type. |
| 3250 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3251 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3252 | // 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] | 3253 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 3254 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3255 | __ j(not_equal, &non_function_constructor); |
| 3256 | |
| 3257 | // eax now contains the constructor function. Grab the |
| 3258 | // instance class name from there. |
| 3259 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3260 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3261 | __ jmp(&done); |
| 3262 | |
| 3263 | // Functions have class 'Function'. |
| 3264 | __ bind(&function); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3265 | __ mov(eax, isolate()->factory()->function_class_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3266 | __ jmp(&done); |
| 3267 | |
| 3268 | // Objects with a non-function constructor have class 'Object'. |
| 3269 | __ bind(&non_function_constructor); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3270 | __ mov(eax, isolate()->factory()->Object_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3271 | __ jmp(&done); |
| 3272 | |
| 3273 | // Non-JS objects have class null. |
| 3274 | __ bind(&null); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3275 | __ mov(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3276 | |
| 3277 | // All done. |
| 3278 | __ bind(&done); |
| 3279 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3280 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3281 | } |
| 3282 | |
| 3283 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3284 | void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3285 | // Conditionally generate a log call. |
| 3286 | // Args: |
| 3287 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 3288 | // This is used to determine whether or not to generate the log call. |
| 3289 | // 1 (string): Format string. Access the string at argument index 2 |
| 3290 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 3291 | // 2 (array): Arguments to the format string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3292 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3293 | ASSERT_EQ(args->length(), 3); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3294 | if (CodeGenerator::ShouldGenerateLog(isolate(), args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3295 | VisitForStackValue(args->at(1)); |
| 3296 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3297 | __ CallRuntime(Runtime::kLog, 2); |
| 3298 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3299 | // 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] | 3300 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3301 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3302 | } |
| 3303 | |
| 3304 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3305 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3306 | // Load the arguments on the stack and call the stub. |
| 3307 | SubStringStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3308 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3309 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3310 | VisitForStackValue(args->at(0)); |
| 3311 | VisitForStackValue(args->at(1)); |
| 3312 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3313 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3314 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3315 | } |
| 3316 | |
| 3317 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3318 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3319 | // Load the arguments on the stack and call the stub. |
| 3320 | RegExpExecStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3321 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3322 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3323 | VisitForStackValue(args->at(0)); |
| 3324 | VisitForStackValue(args->at(1)); |
| 3325 | VisitForStackValue(args->at(2)); |
| 3326 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3327 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3328 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3332 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3333 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3334 | ASSERT(args->length() == 1); |
| 3335 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3336 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3337 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3338 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3339 | // If the object is a smi return the object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3340 | __ JumpIfSmi(eax, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3341 | // If the object is not a value type, return the object. |
| 3342 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3343 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3344 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3345 | |
| 3346 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3347 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3351 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3352 | ZoneList<Expression*>* args = expr->arguments(); |
| 3353 | ASSERT(args->length() == 2); |
| 3354 | ASSERT_NE(NULL, args->at(1)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3355 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3356 | |
| 3357 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3358 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3359 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3360 | Register object = eax; |
| 3361 | Register result = eax; |
| 3362 | Register scratch = ecx; |
| 3363 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3364 | __ JumpIfSmi(object, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3365 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3366 | __ j(not_equal, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3367 | |
| 3368 | if (index->value() == 0) { |
| 3369 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3370 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3371 | } else { |
| 3372 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3373 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3374 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3375 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3376 | __ j(not_equal, &runtime, Label::kNear); |
| 3377 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3378 | kPointerSize * index->value())); |
| 3379 | __ jmp(&done); |
| 3380 | } |
| 3381 | __ bind(&runtime); |
| 3382 | __ PrepareCallCFunction(2, scratch); |
| 3383 | __ mov(Operand(esp, 0), object); |
| 3384 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3385 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3386 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3387 | } |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3388 | |
| 3389 | __ bind(¬_date_object); |
| 3390 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3391 | __ bind(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3392 | context()->Plug(result); |
| 3393 | } |
| 3394 | |
| 3395 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3396 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3397 | ZoneList<Expression*>* args = expr->arguments(); |
| 3398 | ASSERT_EQ(3, args->length()); |
| 3399 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3400 | Register string = eax; |
| 3401 | Register index = ebx; |
| 3402 | Register value = ecx; |
| 3403 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3404 | VisitForStackValue(args->at(1)); // index |
| 3405 | VisitForStackValue(args->at(2)); // value |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3406 | VisitForAccumulatorValue(args->at(0)); // string |
| 3407 | |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3408 | __ pop(value); |
| 3409 | __ pop(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3410 | |
| 3411 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3412 | __ test(value, Immediate(kSmiTagMask)); |
| 3413 | __ ThrowIf(not_zero, kNonSmiValue); |
| 3414 | __ test(index, Immediate(kSmiTagMask)); |
| 3415 | __ ThrowIf(not_zero, kNonSmiValue); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | __ SmiUntag(value); |
| 3419 | __ SmiUntag(index); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3420 | |
| 3421 | if (FLAG_debug_code) { |
| 3422 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3423 | __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3424 | } |
| 3425 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3426 | __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3427 | value); |
| 3428 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3429 | } |
| 3430 | |
| 3431 | |
| 3432 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3433 | ZoneList<Expression*>* args = expr->arguments(); |
| 3434 | ASSERT_EQ(3, args->length()); |
| 3435 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3436 | Register string = eax; |
| 3437 | Register index = ebx; |
| 3438 | Register value = ecx; |
| 3439 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3440 | VisitForStackValue(args->at(1)); // index |
| 3441 | VisitForStackValue(args->at(2)); // value |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3442 | VisitForAccumulatorValue(args->at(0)); // string |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3443 | __ pop(value); |
| 3444 | __ pop(index); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3445 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3446 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3447 | __ test(value, Immediate(kSmiTagMask)); |
| 3448 | __ ThrowIf(not_zero, kNonSmiValue); |
| 3449 | __ test(index, Immediate(kSmiTagMask)); |
| 3450 | __ ThrowIf(not_zero, kNonSmiValue); |
| 3451 | __ SmiUntag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3452 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3453 | __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3454 | __ SmiTag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
| 3457 | __ SmiUntag(value); |
| 3458 | // No need to untag a smi for two-byte addressing. |
| 3459 | __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), |
| 3460 | value); |
| 3461 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3465 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3466 | // Load the arguments on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3467 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3468 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3469 | VisitForStackValue(args->at(0)); |
| 3470 | VisitForStackValue(args->at(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3471 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3472 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3473 | MathPowStub stub(MathPowStub::ON_STACK); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3474 | __ CallStub(&stub); |
| 3475 | } else { |
| 3476 | __ CallRuntime(Runtime::kMath_pow, 2); |
| 3477 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3478 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3482 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3483 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3484 | ASSERT(args->length() == 2); |
| 3485 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3486 | VisitForStackValue(args->at(0)); // Load the object. |
| 3487 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3488 | __ pop(ebx); // eax = value. ebx = object. |
| 3489 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3490 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3491 | // If the object is a smi, return the value. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3492 | __ JumpIfSmi(ebx, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3493 | |
| 3494 | // If the object is not a value type, return the value. |
| 3495 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3496 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3497 | |
| 3498 | // Store the value. |
| 3499 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3500 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3501 | // Update the write barrier. Save the value as it will be |
| 3502 | // overwritten by the write barrier code and is needed afterward. |
| 3503 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3504 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3505 | |
| 3506 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3507 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3511 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3512 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3513 | ASSERT_EQ(args->length(), 1); |
| 3514 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3515 | // Load the argument into eax and call the stub. |
| 3516 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3517 | |
| 3518 | NumberToStringStub stub; |
| 3519 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3520 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3521 | } |
| 3522 | |
| 3523 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3524 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3525 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3526 | ASSERT(args->length() == 1); |
| 3527 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3528 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3529 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3530 | Label done; |
| 3531 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3532 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3533 | __ jmp(&done); |
| 3534 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3535 | NopRuntimeCallHelper call_helper; |
| 3536 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3537 | |
| 3538 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3539 | context()->Plug(ebx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3543 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3544 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3545 | ASSERT(args->length() == 2); |
| 3546 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3547 | VisitForStackValue(args->at(0)); |
| 3548 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3549 | |
| 3550 | Register object = ebx; |
| 3551 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3552 | Register result = edx; |
| 3553 | |
| 3554 | __ pop(object); |
| 3555 | |
| 3556 | Label need_conversion; |
| 3557 | Label index_out_of_range; |
| 3558 | Label done; |
| 3559 | StringCharCodeAtGenerator generator(object, |
| 3560 | index, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3561 | result, |
| 3562 | &need_conversion, |
| 3563 | &need_conversion, |
| 3564 | &index_out_of_range, |
| 3565 | STRING_INDEX_IS_NUMBER); |
| 3566 | generator.GenerateFast(masm_); |
| 3567 | __ jmp(&done); |
| 3568 | |
| 3569 | __ bind(&index_out_of_range); |
| 3570 | // When the index is out of range, the spec requires us to return |
| 3571 | // NaN. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3572 | __ Set(result, Immediate(isolate()->factory()->nan_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3573 | __ jmp(&done); |
| 3574 | |
| 3575 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3576 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3577 | // trigger conversion. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3578 | __ Set(result, Immediate(isolate()->factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3579 | __ jmp(&done); |
| 3580 | |
| 3581 | NopRuntimeCallHelper call_helper; |
| 3582 | generator.GenerateSlow(masm_, call_helper); |
| 3583 | |
| 3584 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3585 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3586 | } |
| 3587 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3588 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3589 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3590 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3591 | ASSERT(args->length() == 2); |
| 3592 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3593 | VisitForStackValue(args->at(0)); |
| 3594 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3595 | |
| 3596 | Register object = ebx; |
| 3597 | Register index = eax; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3598 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3599 | Register result = eax; |
| 3600 | |
| 3601 | __ pop(object); |
| 3602 | |
| 3603 | Label need_conversion; |
| 3604 | Label index_out_of_range; |
| 3605 | Label done; |
| 3606 | StringCharAtGenerator generator(object, |
| 3607 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3608 | scratch, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3609 | result, |
| 3610 | &need_conversion, |
| 3611 | &need_conversion, |
| 3612 | &index_out_of_range, |
| 3613 | STRING_INDEX_IS_NUMBER); |
| 3614 | generator.GenerateFast(masm_); |
| 3615 | __ jmp(&done); |
| 3616 | |
| 3617 | __ bind(&index_out_of_range); |
| 3618 | // When the index is out of range, the spec requires us to return |
| 3619 | // the empty string. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3620 | __ Set(result, Immediate(isolate()->factory()->empty_string())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3621 | __ jmp(&done); |
| 3622 | |
| 3623 | __ bind(&need_conversion); |
| 3624 | // Move smi zero into the result register, which will trigger |
| 3625 | // conversion. |
| 3626 | __ Set(result, Immediate(Smi::FromInt(0))); |
| 3627 | __ jmp(&done); |
| 3628 | |
| 3629 | NopRuntimeCallHelper call_helper; |
| 3630 | generator.GenerateSlow(masm_, call_helper); |
| 3631 | |
| 3632 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3633 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
| 3636 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3637 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3638 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3639 | ASSERT_EQ(2, args->length()); |
| 3640 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3641 | if (FLAG_new_string_add) { |
| 3642 | VisitForStackValue(args->at(0)); |
| 3643 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3644 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3645 | __ pop(edx); |
| 3646 | NewStringAddStub stub(STRING_ADD_CHECK_BOTH, NOT_TENURED); |
| 3647 | __ CallStub(&stub); |
| 3648 | } else { |
| 3649 | VisitForStackValue(args->at(0)); |
| 3650 | VisitForStackValue(args->at(1)); |
| 3651 | |
| 3652 | StringAddStub stub(STRING_ADD_CHECK_BOTH); |
| 3653 | __ CallStub(&stub); |
| 3654 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3655 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3659 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3660 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3661 | ASSERT_EQ(2, args->length()); |
| 3662 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3663 | VisitForStackValue(args->at(0)); |
| 3664 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3665 | |
| 3666 | StringCompareStub stub; |
| 3667 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3668 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3672 | void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3673 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3674 | ZoneList<Expression*>* args = expr->arguments(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3675 | ASSERT(args->length() == 1); |
| 3676 | VisitForStackValue(args->at(0)); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3677 | __ CallRuntime(Runtime::kMath_log, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3678 | context()->Plug(eax); |
| 3679 | } |
| 3680 | |
| 3681 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3682 | void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3683 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3684 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3685 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3686 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3687 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3688 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3689 | } |
| 3690 | |
| 3691 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3692 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3693 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3694 | ASSERT(args->length() >= 2); |
| 3695 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3696 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3697 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3698 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3699 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3700 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3701 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3702 | Label runtime, done; |
| 3703 | // Check for non-function argument (including proxy). |
| 3704 | __ JumpIfSmi(eax, &runtime); |
| 3705 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3706 | __ j(not_equal, &runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3707 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3708 | // InvokeFunction requires the function in edi. Move it in there. |
| 3709 | __ mov(edi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3710 | ParameterCount count(arg_count); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3711 | __ InvokeFunction(edi, count, CALL_FUNCTION, |
| 3712 | NullCallWrapper(), CALL_AS_METHOD); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3713 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3714 | __ jmp(&done); |
| 3715 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3716 | __ bind(&runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3717 | __ push(eax); |
| 3718 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3719 | __ bind(&done); |
| 3720 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3721 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3725 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3726 | // Load the arguments on the stack and call the stub. |
| 3727 | RegExpConstructResultStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3728 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3729 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3730 | VisitForStackValue(args->at(0)); |
| 3731 | VisitForStackValue(args->at(1)); |
| 3732 | VisitForStackValue(args->at(2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3733 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3734 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3738 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3739 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3740 | ASSERT_EQ(2, args->length()); |
| 3741 | |
| 3742 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3743 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->value()))->value(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3744 | |
| 3745 | Handle<FixedArray> jsfunction_result_caches( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3746 | isolate()->native_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3747 | if (jsfunction_result_caches->length() <= cache_id) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3748 | __ Abort(kAttemptToUseUndefinedCache); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3749 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3750 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3751 | return; |
| 3752 | } |
| 3753 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3754 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3755 | |
| 3756 | Register key = eax; |
| 3757 | Register cache = ebx; |
| 3758 | Register tmp = ecx; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3759 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3760 | __ mov(cache, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3761 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3762 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3763 | __ mov(cache, |
| 3764 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3765 | |
| 3766 | Label done, not_found; |
| 3767 | // tmp now holds finger offset as a smi. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3768 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3769 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 3770 | __ cmp(key, CodeGenerator::FixedArrayElementOperand(cache, tmp)); |
| 3771 | __ j(not_equal, ¬_found); |
| 3772 | |
| 3773 | __ mov(eax, CodeGenerator::FixedArrayElementOperand(cache, tmp, 1)); |
| 3774 | __ jmp(&done); |
| 3775 | |
| 3776 | __ bind(¬_found); |
| 3777 | // Call runtime to perform the lookup. |
| 3778 | __ push(cache); |
| 3779 | __ push(key); |
| 3780 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3781 | |
| 3782 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3783 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3787 | void FullCodeGenerator::EmitIsRegExpEquivalent(CallRuntime* expr) { |
| 3788 | ZoneList<Expression*>* args = expr->arguments(); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3789 | ASSERT_EQ(2, args->length()); |
| 3790 | |
| 3791 | Register right = eax; |
| 3792 | Register left = ebx; |
| 3793 | Register tmp = ecx; |
| 3794 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3795 | VisitForStackValue(args->at(0)); |
| 3796 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3797 | __ pop(left); |
| 3798 | |
| 3799 | Label done, fail, ok; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3800 | __ cmp(left, right); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3801 | __ j(equal, &ok); |
| 3802 | // Fail if either is a non-HeapObject. |
| 3803 | __ mov(tmp, left); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3804 | __ and_(tmp, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3805 | __ JumpIfSmi(tmp, &fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3806 | __ mov(tmp, FieldOperand(left, HeapObject::kMapOffset)); |
| 3807 | __ CmpInstanceType(tmp, JS_REGEXP_TYPE); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3808 | __ j(not_equal, &fail); |
| 3809 | __ cmp(tmp, FieldOperand(right, HeapObject::kMapOffset)); |
| 3810 | __ j(not_equal, &fail); |
| 3811 | __ mov(tmp, FieldOperand(left, JSRegExp::kDataOffset)); |
| 3812 | __ cmp(tmp, FieldOperand(right, JSRegExp::kDataOffset)); |
| 3813 | __ j(equal, &ok); |
| 3814 | __ bind(&fail); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3815 | __ mov(eax, Immediate(isolate()->factory()->false_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3816 | __ jmp(&done); |
| 3817 | __ bind(&ok); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3818 | __ mov(eax, Immediate(isolate()->factory()->true_value())); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3819 | __ bind(&done); |
| 3820 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3821 | context()->Plug(eax); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
| 3824 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3825 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3826 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3827 | ASSERT(args->length() == 1); |
| 3828 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3829 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3830 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3831 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3832 | |
| 3833 | Label materialize_true, materialize_false; |
| 3834 | Label* if_true = NULL; |
| 3835 | Label* if_false = NULL; |
| 3836 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3837 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3838 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3839 | |
| 3840 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 3841 | Immediate(String::kContainsCachedArrayIndexMask)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3842 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3843 | Split(zero, if_true, if_false, fall_through); |
| 3844 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3845 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
| 3848 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3849 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3850 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3851 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3852 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3853 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3854 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3855 | |
| 3856 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 3857 | __ IndexFromHash(eax, eax); |
| 3858 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3859 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3863 | void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3864 | Label bailout, done, one_char_separator, long_separator, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3865 | non_trivial_array, not_size_one_array, loop, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3866 | 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] | 3867 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3868 | ZoneList<Expression*>* args = expr->arguments(); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3869 | ASSERT(args->length() == 2); |
| 3870 | // We will leave the separator on the stack until the end of the function. |
| 3871 | VisitForStackValue(args->at(1)); |
| 3872 | // Load this to eax (= array) |
| 3873 | VisitForAccumulatorValue(args->at(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3874 | // All aliases of the same register have disjoint lifetimes. |
| 3875 | Register array = eax; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3876 | Register elements = no_reg; // Will be eax. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3877 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3878 | Register index = edx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3879 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3880 | Register string_length = ecx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3881 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3882 | Register string = esi; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3883 | |
| 3884 | Register scratch = ebx; |
| 3885 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3886 | Register array_length = edi; |
| 3887 | Register result_pos = no_reg; // Will be edi. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3888 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3889 | // Separator operand is already pushed. |
| 3890 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 3891 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 3892 | Operand array_length_operand = Operand(esp, 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3893 | __ sub(esp, Immediate(2 * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3894 | __ cld(); |
| 3895 | // Check that the array is a JSArray |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3896 | __ JumpIfSmi(array, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3897 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3898 | __ j(not_equal, &bailout); |
| 3899 | |
| 3900 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3901 | __ CheckFastElements(scratch, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3902 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3903 | // If the array has length zero, return the empty string. |
| 3904 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3905 | __ SmiUntag(array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3906 | __ j(not_zero, &non_trivial_array); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3907 | __ mov(result_operand, isolate()->factory()->empty_string()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3908 | __ jmp(&done); |
| 3909 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3910 | // Save the array length. |
| 3911 | __ bind(&non_trivial_array); |
| 3912 | __ mov(array_length_operand, array_length); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3913 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3914 | // Save the FixedArray containing array's elements. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3915 | // End of array's live range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3916 | elements = array; |
| 3917 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3918 | array = no_reg; |
| 3919 | |
| 3920 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3921 | // Check that all array elements are sequential ASCII strings, and |
| 3922 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 3923 | __ Set(index, Immediate(0)); |
| 3924 | __ Set(string_length, Immediate(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3925 | // Loop condition: while (index < length). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3926 | // Live loop registers: index, array_length, string, |
| 3927 | // scratch, string_length, elements. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 3928 | if (generate_debug_code_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3929 | __ cmp(index, array_length); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3930 | __ Assert(less, kNoEmptyArraysHereInEmitFastAsciiArrayJoin); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3931 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3932 | __ bind(&loop); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3933 | __ mov(string, FieldOperand(elements, |
| 3934 | index, |
| 3935 | times_pointer_size, |
| 3936 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3937 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3938 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3939 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3940 | __ and_(scratch, Immediate( |
| 3941 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3942 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3943 | __ j(not_equal, &bailout); |
| 3944 | __ add(string_length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3945 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3946 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3947 | __ add(index, Immediate(1)); |
| 3948 | __ cmp(index, array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3949 | __ j(less, &loop); |
| 3950 | |
| 3951 | // If array_length is 1, return elements[0], a string. |
| 3952 | __ cmp(array_length, 1); |
| 3953 | __ j(not_equal, ¬_size_one_array); |
| 3954 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3955 | __ mov(result_operand, scratch); |
| 3956 | __ jmp(&done); |
| 3957 | |
| 3958 | __ bind(¬_size_one_array); |
| 3959 | |
| 3960 | // End of array_length live range. |
| 3961 | result_pos = array_length; |
| 3962 | array_length = no_reg; |
| 3963 | |
| 3964 | // Live registers: |
| 3965 | // string_length: Sum of string lengths, as a smi. |
| 3966 | // elements: FixedArray of strings. |
| 3967 | |
| 3968 | // Check that the separator is a flat ASCII string. |
| 3969 | __ mov(string, separator_operand); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3970 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3971 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3972 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3973 | __ and_(scratch, Immediate( |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3974 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3975 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3976 | __ j(not_equal, &bailout); |
| 3977 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3978 | // Add (separator length times array_length) - separator length |
| 3979 | // to string_length. |
| 3980 | __ mov(scratch, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3981 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3982 | __ sub(string_length, scratch); // May be negative, temporarily. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3983 | __ imul(scratch, array_length_operand); |
| 3984 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3985 | __ add(string_length, scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3986 | __ j(overflow, &bailout); |
| 3987 | |
| 3988 | __ shr(string_length, 1); |
| 3989 | // Live registers and stack values: |
| 3990 | // string_length |
| 3991 | // elements |
| 3992 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 3993 | index, string, &bailout); |
| 3994 | __ mov(result_operand, result_pos); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3995 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3996 | |
| 3997 | |
| 3998 | __ mov(string, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3999 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4000 | Immediate(Smi::FromInt(1))); |
| 4001 | __ j(equal, &one_char_separator); |
| 4002 | __ j(greater, &long_separator); |
| 4003 | |
| 4004 | |
| 4005 | // Empty separator case |
| 4006 | __ mov(index, Immediate(0)); |
| 4007 | __ jmp(&loop_1_condition); |
| 4008 | // Loop condition: while (index < length). |
| 4009 | __ bind(&loop_1); |
| 4010 | // Each iteration of the loop concatenates one string to the result. |
| 4011 | // Live values in registers: |
| 4012 | // index: which element of the elements array we are adding to the result. |
| 4013 | // result_pos: the position to which we are currently copying characters. |
| 4014 | // elements: the FixedArray of strings we are joining. |
| 4015 | |
| 4016 | // Get string = array[index]. |
| 4017 | __ mov(string, FieldOperand(elements, index, |
| 4018 | times_pointer_size, |
| 4019 | FixedArray::kHeaderSize)); |
| 4020 | __ mov(string_length, |
| 4021 | FieldOperand(string, String::kLengthOffset)); |
| 4022 | __ shr(string_length, 1); |
| 4023 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4024 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4025 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4026 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4027 | __ bind(&loop_1_condition); |
| 4028 | __ cmp(index, array_length_operand); |
| 4029 | __ j(less, &loop_1); // End while (index < length). |
| 4030 | __ jmp(&done); |
| 4031 | |
| 4032 | |
| 4033 | |
| 4034 | // One-character separator case |
| 4035 | __ bind(&one_char_separator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4036 | // Replace separator with its ASCII character value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4037 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4038 | __ mov_b(separator_operand, scratch); |
| 4039 | |
| 4040 | __ Set(index, Immediate(0)); |
| 4041 | // Jump into the loop after the code that copies the separator, so the first |
| 4042 | // element is not preceded by a separator |
| 4043 | __ jmp(&loop_2_entry); |
| 4044 | // Loop condition: while (index < length). |
| 4045 | __ bind(&loop_2); |
| 4046 | // Each iteration of the loop concatenates one string to the result. |
| 4047 | // Live values in registers: |
| 4048 | // index: which element of the elements array we are adding to the result. |
| 4049 | // result_pos: the position to which we are currently copying characters. |
| 4050 | |
| 4051 | // Copy the separator character to the result. |
| 4052 | __ mov_b(scratch, separator_operand); |
| 4053 | __ mov_b(Operand(result_pos, 0), scratch); |
| 4054 | __ inc(result_pos); |
| 4055 | |
| 4056 | __ bind(&loop_2_entry); |
| 4057 | // Get string = array[index]. |
| 4058 | __ mov(string, FieldOperand(elements, index, |
| 4059 | times_pointer_size, |
| 4060 | FixedArray::kHeaderSize)); |
| 4061 | __ mov(string_length, |
| 4062 | FieldOperand(string, String::kLengthOffset)); |
| 4063 | __ shr(string_length, 1); |
| 4064 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4065 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4066 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4067 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4068 | |
| 4069 | __ cmp(index, array_length_operand); |
| 4070 | __ j(less, &loop_2); // End while (index < length). |
| 4071 | __ jmp(&done); |
| 4072 | |
| 4073 | |
| 4074 | // Long separator case (separator is more than one character). |
| 4075 | __ bind(&long_separator); |
| 4076 | |
| 4077 | __ Set(index, Immediate(0)); |
| 4078 | // Jump into the loop after the code that copies the separator, so the first |
| 4079 | // element is not preceded by a separator |
| 4080 | __ jmp(&loop_3_entry); |
| 4081 | // Loop condition: while (index < length). |
| 4082 | __ bind(&loop_3); |
| 4083 | // Each iteration of the loop concatenates one string to the result. |
| 4084 | // Live values in registers: |
| 4085 | // index: which element of the elements array we are adding to the result. |
| 4086 | // result_pos: the position to which we are currently copying characters. |
| 4087 | |
| 4088 | // Copy the separator to the result. |
| 4089 | __ mov(string, separator_operand); |
| 4090 | __ mov(string_length, |
| 4091 | FieldOperand(string, String::kLengthOffset)); |
| 4092 | __ shr(string_length, 1); |
| 4093 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4094 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4095 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 4096 | |
| 4097 | __ bind(&loop_3_entry); |
| 4098 | // Get string = array[index]. |
| 4099 | __ mov(string, FieldOperand(elements, index, |
| 4100 | times_pointer_size, |
| 4101 | FixedArray::kHeaderSize)); |
| 4102 | __ mov(string_length, |
| 4103 | FieldOperand(string, String::kLengthOffset)); |
| 4104 | __ shr(string_length, 1); |
| 4105 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4106 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4107 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4108 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4109 | |
| 4110 | __ cmp(index, array_length_operand); |
| 4111 | __ j(less, &loop_3); // End while (index < length). |
| 4112 | __ jmp(&done); |
| 4113 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4114 | |
| 4115 | __ bind(&bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4116 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4117 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4118 | __ mov(eax, result_operand); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4119 | // Drop temp values from the stack, and restore context register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4120 | __ add(esp, Immediate(3 * kPointerSize)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4121 | |
| 4122 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4123 | context()->Plug(eax); |
| 4124 | } |
| 4125 | |
| 4126 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4127 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4128 | Handle<String> name = expr->name(); |
| 4129 | if (name->length() > 0 && name->Get(0) == '_') { |
| 4130 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4131 | EmitInlineRuntimeCall(expr); |
| 4132 | return; |
| 4133 | } |
| 4134 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4135 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4136 | ZoneList<Expression*>* args = expr->arguments(); |
| 4137 | |
| 4138 | if (expr->is_jsruntime()) { |
| 4139 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4140 | __ mov(eax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4141 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
| 4142 | } |
| 4143 | |
| 4144 | // Push the arguments ("left-to-right"). |
| 4145 | int arg_count = args->length(); |
| 4146 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4147 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | if (expr->is_jsruntime()) { |
| 4151 | // Call the JS runtime function via a call IC. |
| 4152 | __ Set(ecx, Immediate(expr->name())); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4153 | RelocInfo::Mode mode = RelocInfo::CODE_TARGET; |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4154 | Handle<Code> ic = |
| 4155 | isolate()->stub_cache()->ComputeCallInitialize(arg_count, mode); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4156 | CallIC(ic, mode, expr->CallRuntimeFeedbackId()); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4157 | // Restore context register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4158 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4159 | } else { |
| 4160 | // Call the C runtime function. |
| 4161 | __ CallRuntime(expr->function(), arg_count); |
| 4162 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4163 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | |
| 4167 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 4168 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4169 | case Token::DELETE: { |
| 4170 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4171 | Property* property = expr->expression()->AsProperty(); |
| 4172 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4173 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4174 | if (property != NULL) { |
| 4175 | VisitForStackValue(property->obj()); |
| 4176 | VisitForStackValue(property->key()); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4177 | StrictModeFlag strict_mode_flag = (language_mode() == CLASSIC_MODE) |
| 4178 | ? kNonStrictMode : kStrictMode; |
| 4179 | __ push(Immediate(Smi::FromInt(strict_mode_flag))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4180 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4181 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4182 | } else if (proxy != NULL) { |
| 4183 | Variable* var = proxy->var(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4184 | // Delete of an unqualified identifier is disallowed in strict mode |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4185 | // but "delete this" is allowed. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4186 | ASSERT(language_mode() == CLASSIC_MODE || var->is_this()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4187 | if (var->IsUnallocated()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4188 | __ push(GlobalObjectOperand()); |
| 4189 | __ push(Immediate(var->name())); |
| 4190 | __ push(Immediate(Smi::FromInt(kNonStrictMode))); |
| 4191 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4192 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4193 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4194 | // Result of deleting non-global variables is false. 'this' is |
| 4195 | // not really a variable, though we implement it as one. The |
| 4196 | // subexpression does not have side effects. |
| 4197 | context()->Plug(var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4198 | } else { |
| 4199 | // Non-global variable. Call the runtime to try to delete from the |
| 4200 | // context where the variable was introduced. |
| 4201 | __ push(context_register()); |
| 4202 | __ push(Immediate(var->name())); |
| 4203 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
| 4204 | context()->Plug(eax); |
| 4205 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4206 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4207 | // Result of deleting non-property, non-variable reference is true. |
| 4208 | // The subexpression may have side effects. |
| 4209 | VisitForEffect(expr->expression()); |
| 4210 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4211 | } |
| 4212 | break; |
| 4213 | } |
| 4214 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4215 | case Token::VOID: { |
| 4216 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 4217 | VisitForEffect(expr->expression()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4218 | context()->Plug(isolate()->factory()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4219 | break; |
| 4220 | } |
| 4221 | |
| 4222 | case Token::NOT: { |
| 4223 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4224 | if (context()->IsEffect()) { |
| 4225 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4226 | // subexpression. Match the optimizing compiler by not branching. |
| 4227 | VisitForEffect(expr->expression()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4228 | } else if (context()->IsTest()) { |
| 4229 | const TestContext* test = TestContext::cast(context()); |
| 4230 | // The labels are swapped for the recursive call. |
| 4231 | VisitForControl(expr->expression(), |
| 4232 | test->false_label(), |
| 4233 | test->true_label(), |
| 4234 | test->fall_through()); |
| 4235 | context()->Plug(test->true_label(), test->false_label()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4236 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4237 | // We handle value contexts explicitly rather than simply visiting |
| 4238 | // for control and plugging the control flow into the context, |
| 4239 | // because we need to prepare a pair of extra administrative AST ids |
| 4240 | // for the optimizing compiler. |
| 4241 | ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 4242 | Label materialize_true, materialize_false, done; |
| 4243 | VisitForControl(expr->expression(), |
| 4244 | &materialize_false, |
| 4245 | &materialize_true, |
| 4246 | &materialize_true); |
| 4247 | __ bind(&materialize_true); |
| 4248 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4249 | if (context()->IsAccumulatorValue()) { |
| 4250 | __ mov(eax, isolate()->factory()->true_value()); |
| 4251 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4252 | __ Push(isolate()->factory()->true_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4253 | } |
| 4254 | __ jmp(&done, Label::kNear); |
| 4255 | __ bind(&materialize_false); |
| 4256 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4257 | if (context()->IsAccumulatorValue()) { |
| 4258 | __ mov(eax, isolate()->factory()->false_value()); |
| 4259 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4260 | __ Push(isolate()->factory()->false_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4261 | } |
| 4262 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4263 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4264 | break; |
| 4265 | } |
| 4266 | |
| 4267 | case Token::TYPEOF: { |
| 4268 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4269 | { StackValueContext context(this); |
| 4270 | VisitForTypeofValue(expr->expression()); |
| 4271 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4272 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4273 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4274 | break; |
| 4275 | } |
| 4276 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4277 | default: |
| 4278 | UNREACHABLE(); |
| 4279 | } |
| 4280 | } |
| 4281 | |
| 4282 | |
| 4283 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 4284 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4285 | SetSourcePosition(expr->position()); |
| 4286 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4287 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 4288 | // as the left-hand side. |
| 4289 | if (!expr->expression()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4290 | VisitForEffect(expr->expression()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4291 | return; |
| 4292 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4293 | |
| 4294 | // 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] | 4295 | // slot. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4296 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 4297 | LhsKind assign_type = VARIABLE; |
| 4298 | Property* prop = expr->expression()->AsProperty(); |
| 4299 | // In case of a property we use the uninitialized expression context |
| 4300 | // of the key to detect a named property. |
| 4301 | if (prop != NULL) { |
| 4302 | assign_type = |
| 4303 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 4304 | } |
| 4305 | |
| 4306 | // Evaluate expression and get value. |
| 4307 | if (assign_type == VARIABLE) { |
| 4308 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4309 | AccumulatorValueContext context(this); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4310 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4311 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4312 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4313 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4314 | __ push(Immediate(Smi::FromInt(0))); |
| 4315 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4316 | if (assign_type == NAMED_PROPERTY) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4317 | // Put the object both on the stack and in edx. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4318 | VisitForAccumulatorValue(prop->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4319 | __ push(eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4320 | __ mov(edx, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4321 | EmitNamedPropertyLoad(prop); |
| 4322 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4323 | VisitForStackValue(prop->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4324 | VisitForStackValue(prop->key()); |
| 4325 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 4326 | __ mov(ecx, Operand(esp, 0)); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4327 | EmitKeyedPropertyLoad(prop); |
| 4328 | } |
| 4329 | } |
| 4330 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4331 | // We need a second deoptimization point after loading the value |
| 4332 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4333 | if (assign_type == VARIABLE) { |
| 4334 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4335 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4336 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4337 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4338 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4339 | // Inline smi case if we are in a loop. |
| 4340 | Label done, stub_call; |
| 4341 | JumpPatchSite patch_site(masm_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4342 | if (ShouldInlineSmiCase(expr->op())) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4343 | Label slow; |
| 4344 | patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); |
| 4345 | |
| 4346 | // Save result for postfix expressions. |
| 4347 | if (expr->is_postfix()) { |
| 4348 | if (!context()->IsEffect()) { |
| 4349 | // Save the result on the stack. If we have a named or keyed property |
| 4350 | // we store the result under the receiver that is currently on top |
| 4351 | // of the stack. |
| 4352 | switch (assign_type) { |
| 4353 | case VARIABLE: |
| 4354 | __ push(eax); |
| 4355 | break; |
| 4356 | case NAMED_PROPERTY: |
| 4357 | __ mov(Operand(esp, kPointerSize), eax); |
| 4358 | break; |
| 4359 | case KEYED_PROPERTY: |
| 4360 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4361 | break; |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | if (expr->op() == Token::INC) { |
| 4367 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4368 | } else { |
| 4369 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4370 | } |
| 4371 | __ j(no_overflow, &done, Label::kNear); |
| 4372 | // Call stub. Undo operation first. |
| 4373 | if (expr->op() == Token::INC) { |
| 4374 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4375 | } else { |
| 4376 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4377 | } |
| 4378 | __ jmp(&stub_call, Label::kNear); |
| 4379 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4380 | } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4381 | ToNumberStub convert_stub; |
| 4382 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4383 | |
| 4384 | // Save result for postfix expressions. |
| 4385 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4386 | if (!context()->IsEffect()) { |
| 4387 | // Save the result on the stack. If we have a named or keyed property |
| 4388 | // we store the result under the receiver that is currently on top |
| 4389 | // of the stack. |
| 4390 | switch (assign_type) { |
| 4391 | case VARIABLE: |
| 4392 | __ push(eax); |
| 4393 | break; |
| 4394 | case NAMED_PROPERTY: |
| 4395 | __ mov(Operand(esp, kPointerSize), eax); |
| 4396 | break; |
| 4397 | case KEYED_PROPERTY: |
| 4398 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4399 | break; |
| 4400 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4404 | // Record position before stub call. |
| 4405 | SetSourcePosition(expr->position()); |
| 4406 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4407 | // Call stub for +1/-1. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4408 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4409 | __ mov(edx, eax); |
| 4410 | __ mov(eax, Immediate(Smi::FromInt(1))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4411 | BinaryOpICStub stub(expr->binary_op(), NO_OVERWRITE); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4412 | CallIC(stub.GetCode(isolate()), |
| 4413 | RelocInfo::CODE_TARGET, |
| 4414 | expr->CountBinOpFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4415 | patch_site.EmitPatchInfo(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4416 | __ bind(&done); |
| 4417 | |
| 4418 | // Store the value returned in eax. |
| 4419 | switch (assign_type) { |
| 4420 | case VARIABLE: |
| 4421 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4422 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4423 | { EffectContext context(this); |
| 4424 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4425 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4426 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4427 | context.Plug(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4428 | } |
| 4429 | // For all contexts except EffectContext We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4430 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4431 | if (!context()->IsEffect()) { |
| 4432 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4433 | } |
| 4434 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4435 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4436 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4437 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4438 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4439 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4440 | } |
| 4441 | break; |
| 4442 | case NAMED_PROPERTY: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4443 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4444 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4445 | Handle<Code> ic = is_classic_mode() |
| 4446 | ? isolate()->builtins()->StoreIC_Initialize() |
| 4447 | : isolate()->builtins()->StoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4448 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4449 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4450 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4451 | if (!context()->IsEffect()) { |
| 4452 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4453 | } |
| 4454 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4455 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4456 | } |
| 4457 | break; |
| 4458 | } |
| 4459 | case KEYED_PROPERTY: { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4460 | __ pop(ecx); |
| 4461 | __ pop(edx); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4462 | Handle<Code> ic = is_classic_mode() |
| 4463 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 4464 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4465 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4466 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4467 | if (expr->is_postfix()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4468 | // Result is on the stack |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4469 | if (!context()->IsEffect()) { |
| 4470 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4471 | } |
| 4472 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4473 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4474 | } |
| 4475 | break; |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | |
| 4480 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4481 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4482 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4483 | ASSERT(!context()->IsEffect()); |
| 4484 | ASSERT(!context()->IsTest()); |
| 4485 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4486 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4487 | Comment cmnt(masm_, "Global variable"); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4488 | __ mov(edx, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4489 | __ mov(ecx, Immediate(proxy->name())); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4490 | Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4491 | // Use a regular load, not a contextual load, to avoid a reference |
| 4492 | // error. |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4493 | CallIC(ic); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4494 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4495 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4496 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4497 | Label done, slow; |
| 4498 | |
| 4499 | // Generate code for loading from variables potentially shadowed |
| 4500 | // by eval-introduced variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4501 | EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4502 | |
| 4503 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4504 | __ push(esi); |
| 4505 | __ push(Immediate(proxy->name())); |
| 4506 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4507 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4508 | __ bind(&done); |
| 4509 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4510 | context()->Plug(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4511 | } else { |
| 4512 | // This expression cannot throw a reference error at the top level. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4513 | VisitInDuplicateContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4518 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4519 | Expression* sub_expr, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4520 | Handle<String> check) { |
| 4521 | Label materialize_true, materialize_false; |
| 4522 | Label* if_true = NULL; |
| 4523 | Label* if_false = NULL; |
| 4524 | Label* fall_through = NULL; |
| 4525 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4526 | &if_true, &if_false, &fall_through); |
| 4527 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4528 | { AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4529 | VisitForTypeofValue(sub_expr); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4530 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4531 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4532 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4533 | if (check->Equals(isolate()->heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4534 | __ JumpIfSmi(eax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4536 | isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4537 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4538 | } else if (check->Equals(isolate()->heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4539 | __ JumpIfSmi(eax, if_false); |
| 4540 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4541 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4542 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4543 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4544 | 1 << Map::kIsUndetectable); |
| 4545 | Split(zero, if_true, if_false, fall_through); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4546 | } else if (check->Equals(isolate()->heap()->symbol_string())) { |
| 4547 | __ JumpIfSmi(eax, if_false); |
| 4548 | __ CmpObjectType(eax, SYMBOL_TYPE, edx); |
| 4549 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4550 | } else if (check->Equals(isolate()->heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4551 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4552 | __ j(equal, if_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4553 | __ cmp(eax, isolate()->factory()->false_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4554 | Split(equal, if_true, if_false, fall_through); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4555 | } else if (FLAG_harmony_typeof && |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4556 | check->Equals(isolate()->heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4557 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4558 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4559 | } else if (check->Equals(isolate()->heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4560 | __ cmp(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4561 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4562 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4563 | // Check for undetectable objects => true. |
| 4564 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4565 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4566 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4567 | Split(not_zero, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4568 | } else if (check->Equals(isolate()->heap()->function_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4569 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4570 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4571 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4572 | __ j(equal, if_true); |
| 4573 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4574 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4575 | } else if (check->Equals(isolate()->heap()->object_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4576 | __ JumpIfSmi(eax, if_false); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4577 | if (!FLAG_harmony_typeof) { |
| 4578 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4579 | __ j(equal, if_true); |
| 4580 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4581 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4582 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4583 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4584 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4586 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4587 | 1 << Map::kIsUndetectable); |
| 4588 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4589 | } else { |
| 4590 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4591 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4592 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
| 4595 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4596 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4597 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4598 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4599 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4600 | // First we try a fast inlined version of the compare when one of |
| 4601 | // the operands is a literal. |
| 4602 | if (TryLiteralCompare(expr)) return; |
| 4603 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4604 | // Always perform the comparison for its control flow. Pack the result |
| 4605 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4606 | Label materialize_true, materialize_false; |
| 4607 | Label* if_true = NULL; |
| 4608 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4609 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4610 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4611 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4612 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4613 | Token::Value op = expr->op(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4614 | VisitForStackValue(expr->left()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4615 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4616 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4617 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4618 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4619 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4620 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4621 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4622 | break; |
| 4623 | |
| 4624 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4625 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4626 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4627 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4628 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4629 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4630 | // The stub returns 0 for true. |
| 4631 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4632 | break; |
| 4633 | } |
| 4634 | |
| 4635 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4636 | VisitForAccumulatorValue(expr->right()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4637 | Condition cc = CompareIC::ComputeCondition(op); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4638 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4639 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4640 | bool inline_smi_code = ShouldInlineSmiCase(op); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4641 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4642 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4643 | Label slow_case; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4644 | __ mov(ecx, edx); |
| 4645 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4646 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4647 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4648 | Split(cc, if_true, if_false, NULL); |
| 4649 | __ bind(&slow_case); |
| 4650 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4651 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4652 | // Record position and call the compare IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4653 | SetSourcePosition(expr->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4654 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4655 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4656 | patch_site.EmitPatchInfo(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4657 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4658 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4659 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4660 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4661 | } |
| 4662 | } |
| 4663 | |
| 4664 | // Convert the result of the comparison into one expected for this |
| 4665 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4666 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4670 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4671 | Expression* sub_expr, |
| 4672 | NilValue nil) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4673 | Label materialize_true, materialize_false; |
| 4674 | Label* if_true = NULL; |
| 4675 | Label* if_false = NULL; |
| 4676 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4677 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4678 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4679 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4680 | VisitForAccumulatorValue(sub_expr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4681 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4682 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4683 | Handle<Object> nil_value = nil == kNullValue |
| 4684 | ? isolate()->factory()->null_value() |
| 4685 | : isolate()->factory()->undefined_value(); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4686 | if (expr->op() == Token::EQ_STRICT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4687 | __ cmp(eax, nil_value); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4688 | Split(equal, if_true, if_false, fall_through); |
| 4689 | } else { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4690 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4691 | CallIC(ic, RelocInfo::CODE_TARGET, expr->CompareOperationFeedbackId()); |
| 4692 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4693 | Split(not_zero, if_true, if_false, fall_through); |
| 4694 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4695 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4699 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4700 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4701 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4705 | Register FullCodeGenerator::result_register() { |
| 4706 | return eax; |
| 4707 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4708 | |
| 4709 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4710 | Register FullCodeGenerator::context_register() { |
| 4711 | return esi; |
| 4712 | } |
| 4713 | |
| 4714 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4715 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4716 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 4717 | __ mov(Operand(ebp, frame_offset), value); |
| 4718 | } |
| 4719 | |
| 4720 | |
| 4721 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4722 | __ mov(dst, ContextOperand(esi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4726 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4727 | Scope* declaration_scope = scope()->DeclarationScope(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4728 | if (declaration_scope->is_global_scope() || |
| 4729 | declaration_scope->is_module_scope()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4730 | // Contexts nested in the native context have a canonical empty function |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4731 | // as their closure, not the anonymous closure containing the global |
| 4732 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4733 | // function. |
| 4734 | __ push(Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4735 | } else if (declaration_scope->is_eval_scope()) { |
| 4736 | // Contexts nested inside eval code have the same closure as the context |
| 4737 | // calling eval, not the anonymous closure containing the eval code. |
| 4738 | // Fetch it from the context. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4739 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 4740 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4741 | ASSERT(declaration_scope->is_function_scope()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4742 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4743 | } |
| 4744 | } |
| 4745 | |
| 4746 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4747 | // ---------------------------------------------------------------------------- |
| 4748 | // Non-local control flow support. |
| 4749 | |
| 4750 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4751 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4752 | ASSERT(!result_register().is(edx)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4753 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4754 | __ sub(edx, Immediate(masm_->CodeObject())); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4755 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4756 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4757 | __ SmiTag(edx); |
| 4758 | __ push(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4759 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4760 | // Store result register while executing finally block. |
| 4761 | __ push(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4762 | |
| 4763 | // Store pending message while executing finally block. |
| 4764 | ExternalReference pending_message_obj = |
| 4765 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4766 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4767 | __ push(edx); |
| 4768 | |
| 4769 | ExternalReference has_pending_message = |
| 4770 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4771 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4772 | __ SmiTag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4773 | __ push(edx); |
| 4774 | |
| 4775 | ExternalReference pending_message_script = |
| 4776 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4777 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 4778 | __ push(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4779 | } |
| 4780 | |
| 4781 | |
| 4782 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4783 | ASSERT(!result_register().is(edx)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4784 | // Restore pending message from stack. |
| 4785 | __ pop(edx); |
| 4786 | ExternalReference pending_message_script = |
| 4787 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4788 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 4789 | |
| 4790 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4791 | __ SmiUntag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4792 | ExternalReference has_pending_message = |
| 4793 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4794 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 4795 | |
| 4796 | __ pop(edx); |
| 4797 | ExternalReference pending_message_obj = |
| 4798 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4799 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4800 | |
| 4801 | // Restore result register from stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4802 | __ pop(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4803 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4804 | // Uncook return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4805 | __ pop(edx); |
| 4806 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4807 | __ add(edx, Immediate(masm_->CodeObject())); |
| 4808 | __ jmp(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4809 | } |
| 4810 | |
| 4811 | |
| 4812 | #undef __ |
| 4813 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4814 | #define __ ACCESS_MASM(masm()) |
| 4815 | |
| 4816 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 4817 | int* stack_depth, |
| 4818 | int* context_length) { |
| 4819 | // The macros used here must preserve the result register. |
| 4820 | |
| 4821 | // Because the handler block contains the context of the finally |
| 4822 | // code, we can restore it directly from there for the finally code |
| 4823 | // rather than iteratively unwinding contexts via their previous |
| 4824 | // links. |
| 4825 | __ Drop(*stack_depth); // Down to the handler block. |
| 4826 | if (*context_length > 0) { |
| 4827 | // Restore the context to its dedicated register and the stack. |
| 4828 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 4829 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 4830 | } |
| 4831 | __ PopTryHandler(); |
| 4832 | __ call(finally_entry_); |
| 4833 | |
| 4834 | *stack_depth = 0; |
| 4835 | *context_length = 0; |
| 4836 | return previous_; |
| 4837 | } |
| 4838 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4839 | #undef __ |
| 4840 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4841 | |
| 4842 | static const byte kJnsInstruction = 0x79; |
| 4843 | static const byte kJnsOffset = 0x11; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4844 | static const byte kNopByteOne = 0x66; |
| 4845 | static const byte kNopByteTwo = 0x90; |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 4846 | #ifdef DEBUG |
| 4847 | static const byte kCallInstruction = 0xe8; |
| 4848 | #endif |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4849 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4850 | |
| 4851 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 4852 | Address pc, |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4853 | BackEdgeState target_state, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4854 | Code* replacement_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4855 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4856 | Address jns_instr_address = call_target_address - 3; |
| 4857 | Address jns_offset_address = call_target_address - 2; |
| 4858 | |
| 4859 | switch (target_state) { |
| 4860 | case INTERRUPT: |
| 4861 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4862 | // jns ok |
| 4863 | // call <interrupt stub> |
| 4864 | // ok: |
| 4865 | *jns_instr_address = kJnsInstruction; |
| 4866 | *jns_offset_address = kJnsOffset; |
| 4867 | break; |
| 4868 | case ON_STACK_REPLACEMENT: |
| 4869 | case OSR_AFTER_STACK_CHECK: |
| 4870 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4871 | // nop |
| 4872 | // nop |
| 4873 | // call <on-stack replacment> |
| 4874 | // ok: |
| 4875 | *jns_instr_address = kNopByteOne; |
| 4876 | *jns_offset_address = kNopByteTwo; |
| 4877 | break; |
| 4878 | } |
| 4879 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4880 | Assembler::set_target_address_at(call_target_address, |
| 4881 | replacement_code->entry()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4882 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 4883 | unoptimized_code, call_target_address, replacement_code); |
| 4884 | } |
| 4885 | |
| 4886 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4887 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 4888 | Isolate* isolate, |
| 4889 | Code* unoptimized_code, |
| 4890 | Address pc) { |
| 4891 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4892 | Address jns_instr_address = call_target_address - 3; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4893 | ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4894 | |
| 4895 | if (*jns_instr_address == kJnsInstruction) { |
| 4896 | ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 4897 | ASSERT_EQ(isolate->builtins()->InterruptCheck()->entry(), |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4898 | Assembler::target_address_at(call_target_address)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4899 | return INTERRUPT; |
| 4900 | } |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4901 | |
| 4902 | ASSERT_EQ(kNopByteOne, *jns_instr_address); |
| 4903 | ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 4904 | |
| 4905 | if (Assembler::target_address_at(call_target_address) == |
| 4906 | isolate->builtins()->OnStackReplacement()->entry()) { |
| 4907 | return ON_STACK_REPLACEMENT; |
| 4908 | } |
| 4909 | |
| 4910 | ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 4911 | Assembler::target_address_at(call_target_address)); |
| 4912 | return OSR_AFTER_STACK_CHECK; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4913 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4914 | |
| 4915 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4916 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4917 | |
| 4918 | #endif // V8_TARGET_ARCH_IA32 |