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: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 110 | // o edi: the JS function object being called (i.e. ourselves) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 111 | // o esi: our context |
| 112 | // o ebp: our caller's frame pointer |
| 113 | // o esp: stack pointer (pointing to return address) |
| 114 | // |
| 115 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 116 | // frames-ia32.h for its layout. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 117 | void FullCodeGenerator::Generate() { |
| 118 | CompilationInfo* info = info_; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 119 | handler_table_ = |
| 120 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 121 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame^] | 122 | InitializeFeedbackVector(); |
| 123 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 124 | profiling_counter_ = isolate()->factory()->NewCell( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 125 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 126 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 127 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 128 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 129 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 130 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 131 | #ifdef DEBUG |
| 132 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 133 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 134 | __ int3(); |
| 135 | } |
| 136 | #endif |
| 137 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 138 | // Sloppy mode functions and builtins need to replace the receiver with the |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 139 | // global proxy when called as functions (without an explicit receiver |
| 140 | // object). |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 141 | if (info->strict_mode() == SLOPPY && !info->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 142 | Label ok; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 143 | // +1 for return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 144 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 145 | __ mov(ecx, Operand(esp, receiver_offset)); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 146 | |
| 147 | __ cmp(ecx, isolate()->factory()->undefined_value()); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 148 | __ j(not_equal, &ok, Label::kNear); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 149 | |
| 150 | __ mov(ecx, GlobalObjectOperand()); |
| 151 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 152 | |
| 153 | __ mov(Operand(esp, receiver_offset), ecx); |
| 154 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 155 | __ bind(&ok); |
| 156 | } |
| 157 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 158 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 159 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 160 | // the frame (that is done below). |
| 161 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 162 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 163 | info->set_prologue_offset(masm_->pc_offset()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 164 | __ Prologue(BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 165 | info->AddNoFrameRange(0, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 166 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 167 | { Comment cmnt(masm_, "[ Allocate locals"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 168 | int locals_count = info->scope()->num_stack_slots(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 169 | // Generators allocate locals, if any, in context slots. |
| 170 | ASSERT(!info->function()->is_generator() || locals_count == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 171 | if (locals_count == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 172 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 173 | } else if (locals_count > 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 174 | __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 175 | for (int i = 0; i < locals_count; i++) { |
| 176 | __ push(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 177 | } |
| 178 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 179 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 180 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 181 | bool function_in_register = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 182 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 183 | // Possibly allocate a local context. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 184 | 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] | 185 | if (heap_slots > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 186 | Comment cmnt(masm_, "[ Allocate context"); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 187 | // Argument to NewContext is the function, which is still in edi. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 188 | if (FLAG_harmony_scoping && info->scope()->is_global_scope()) { |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 189 | __ push(edi); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 190 | __ Push(info->scope()->GetScopeInfo()); |
| 191 | __ CallRuntime(Runtime::kNewGlobalContext, 2); |
| 192 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 193 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 194 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 195 | } else { |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 196 | __ push(edi); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 197 | __ CallRuntime(Runtime::kNewFunctionContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 198 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 199 | function_in_register = false; |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 200 | // Context is returned in eax. It replaces the context passed to us. |
| 201 | // It's saved in the stack and kept live in esi. |
| 202 | __ mov(esi, eax); |
| 203 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 204 | |
| 205 | // Copy parameters into context if necessary. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 206 | int num_parameters = info->scope()->num_parameters(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 207 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 208 | Variable* var = scope()->parameter(i); |
| 209 | if (var->IsContextSlot()) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 210 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 211 | (num_parameters - 1 - i) * kPointerSize; |
| 212 | // Load parameter from stack. |
| 213 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 214 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 215 | int context_offset = Context::SlotOffset(var->index()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 216 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 217 | // Update the write barrier. This clobbers eax and ebx. |
| 218 | __ RecordWriteContextSlot(esi, |
| 219 | context_offset, |
| 220 | eax, |
| 221 | ebx, |
| 222 | kDontSaveFPRegs); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 227 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 228 | if (arguments != NULL) { |
| 229 | // Function uses arguments object. |
| 230 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 231 | if (function_in_register) { |
| 232 | __ push(edi); |
| 233 | } else { |
| 234 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 235 | } |
| 236 | // Receiver is just before the parameters on the caller's stack. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 237 | int num_parameters = info->scope()->num_parameters(); |
| 238 | int offset = num_parameters * kPointerSize; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 239 | __ lea(edx, |
| 240 | Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 241 | __ push(edx); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 242 | __ push(Immediate(Smi::FromInt(num_parameters))); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 243 | // Arguments to ArgumentsAccessStub: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 244 | // function, receiver address, parameter count. |
| 245 | // The stub will rewrite receiver and parameter count if the previous |
| 246 | // stack frame was an arguments adapter frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 247 | ArgumentsAccessStub::Type type; |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 248 | if (strict_mode() == STRICT) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 249 | type = ArgumentsAccessStub::NEW_STRICT; |
| 250 | } else if (function()->has_duplicate_parameters()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 251 | type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 252 | } else { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 253 | type = ArgumentsAccessStub::NEW_SLOPPY_FAST; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 254 | } |
| 255 | ArgumentsAccessStub stub(type); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 256 | __ CallStub(&stub); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 257 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 258 | SetVar(arguments, eax, ebx, edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 259 | } |
| 260 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 261 | if (FLAG_trace) { |
| 262 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 263 | } |
| 264 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 265 | // Visit the declarations and body unless there is an illegal |
| 266 | // redeclaration. |
| 267 | if (scope()->HasIllegalRedeclaration()) { |
| 268 | Comment cmnt(masm_, "[ Declarations"); |
| 269 | scope()->VisitIllegalRedeclaration(this); |
| 270 | |
| 271 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 272 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 273 | { Comment cmnt(masm_, "[ Declarations"); |
| 274 | // For named function expressions, declare the function name as a |
| 275 | // constant. |
| 276 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 277 | VariableDeclaration* function = scope()->function(); |
| 278 | ASSERT(function->proxy()->var()->mode() == CONST || |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 279 | function->proxy()->var()->mode() == CONST_LEGACY); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 280 | ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 281 | VisitVariableDeclaration(function); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 282 | } |
| 283 | VisitDeclarations(scope()->declarations()); |
| 284 | } |
| 285 | |
| 286 | { Comment cmnt(masm_, "[ Stack check"); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 287 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 288 | Label ok; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 289 | ExternalReference stack_limit = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 290 | ExternalReference::address_of_stack_limit(isolate()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 291 | __ cmp(esp, Operand::StaticVariable(stack_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 292 | __ j(above_equal, &ok, Label::kNear); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 293 | __ call(isolate()->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 294 | __ bind(&ok); |
| 295 | } |
| 296 | |
| 297 | { Comment cmnt(masm_, "[ Body"); |
| 298 | ASSERT(loop_depth() == 0); |
| 299 | VisitStatements(function()->body()); |
| 300 | ASSERT(loop_depth() == 0); |
| 301 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 302 | } |
| 303 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 304 | // Always emit a 'return undefined' in case control fell off the end of |
| 305 | // the body. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 306 | { Comment cmnt(masm_, "[ return <undefined>;"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 307 | __ mov(eax, isolate()->factory()->undefined_value()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 308 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 313 | void FullCodeGenerator::ClearAccumulator() { |
| 314 | __ Set(eax, Immediate(Smi::FromInt(0))); |
| 315 | } |
| 316 | |
| 317 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 318 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 319 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 320 | __ sub(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 321 | Immediate(Smi::FromInt(delta))); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 326 | int reset_value = FLAG_interrupt_budget; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 327 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 328 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 329 | Immediate(Smi::FromInt(reset_value))); |
| 330 | } |
| 331 | |
| 332 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 333 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 334 | Label* back_edge_target) { |
| 335 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 336 | Label ok; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 337 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 338 | ASSERT(back_edge_target->is_bound()); |
| 339 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 340 | int weight = Min(kMaxBackEdgeWeight, |
| 341 | Max(1, distance / kCodeSizeMultiplier)); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 342 | EmitProfilingCounterDecrement(weight); |
| 343 | __ j(positive, &ok, Label::kNear); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 344 | __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 345 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 346 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 347 | // the AST id from the unoptimized code in order to use it as a key into |
| 348 | // the deoptimization input data found in the optimized code. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 349 | RecordBackEdge(stmt->OsrEntryId()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 350 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 351 | EmitProfilingCounterReset(); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 352 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 353 | __ bind(&ok); |
| 354 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 355 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 356 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 357 | // we want it to work if it is. |
| 358 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 362 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 363 | Comment cmnt(masm_, "[ Return sequence"); |
| 364 | if (return_label_.is_bound()) { |
| 365 | __ jmp(&return_label_); |
| 366 | } else { |
| 367 | // Common return label |
| 368 | __ bind(&return_label_); |
| 369 | if (FLAG_trace) { |
| 370 | __ push(eax); |
| 371 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 372 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 373 | // Pretend that the exit is a backwards jump to the entry. |
| 374 | int weight = 1; |
| 375 | if (info_->ShouldSelfOptimize()) { |
| 376 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 377 | } else { |
| 378 | int distance = masm_->pc_offset(); |
| 379 | weight = Min(kMaxBackEdgeWeight, |
| 380 | Max(1, distance / kCodeSizeMultiplier)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 381 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 382 | EmitProfilingCounterDecrement(weight); |
| 383 | Label ok; |
| 384 | __ j(positive, &ok, Label::kNear); |
| 385 | __ push(eax); |
| 386 | __ call(isolate()->builtins()->InterruptCheck(), |
| 387 | RelocInfo::CODE_TARGET); |
| 388 | __ pop(eax); |
| 389 | EmitProfilingCounterReset(); |
| 390 | __ bind(&ok); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 391 | #ifdef DEBUG |
| 392 | // Add a label for checking the size of the code used for returning. |
| 393 | Label check_exit_codesize; |
| 394 | masm_->bind(&check_exit_codesize); |
| 395 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 396 | SetSourcePosition(function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 397 | __ RecordJSReturn(); |
| 398 | // Do not use the leave instruction here because it is too short to |
| 399 | // patch with the code required by the debugger. |
| 400 | __ mov(esp, ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 401 | int no_frame_start = masm_->pc_offset(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 402 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 403 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 404 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 405 | __ Ret(arguments_bytes, ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 406 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 407 | // Check that the size of the code used for returning is large enough |
| 408 | // for the debugger's requirements. |
| 409 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 410 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 411 | #endif |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 412 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | |
| 416 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 417 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 418 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 422 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 423 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 424 | codegen()->GetVar(result_register(), var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 428 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 429 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 430 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 431 | // Memory operands can be pushed directly. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 432 | __ push(operand); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 436 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 437 | // For simplicity we always test the accumulator register. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 438 | codegen()->GetVar(result_register(), var); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 439 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 440 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
| 444 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 445 | UNREACHABLE(); // Not used on IA32. |
| 446 | } |
| 447 | |
| 448 | |
| 449 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 450 | Heap::RootListIndex index) const { |
| 451 | UNREACHABLE(); // Not used on IA32. |
| 452 | } |
| 453 | |
| 454 | |
| 455 | void FullCodeGenerator::StackValueContext::Plug( |
| 456 | Heap::RootListIndex index) const { |
| 457 | UNREACHABLE(); // Not used on IA32. |
| 458 | } |
| 459 | |
| 460 | |
| 461 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 462 | UNREACHABLE(); // Not used on IA32. |
| 463 | } |
| 464 | |
| 465 | |
| 466 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 467 | } |
| 468 | |
| 469 | |
| 470 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 471 | Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 472 | if (lit->IsSmi()) { |
| 473 | __ SafeSet(result_register(), Immediate(lit)); |
| 474 | } else { |
| 475 | __ Set(result_register(), Immediate(lit)); |
| 476 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | |
| 480 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 481 | if (lit->IsSmi()) { |
| 482 | __ SafePush(Immediate(lit)); |
| 483 | } else { |
| 484 | __ push(Immediate(lit)); |
| 485 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | |
| 489 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 490 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 491 | true, |
| 492 | true_label_, |
| 493 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 494 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 495 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
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 if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 498 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 499 | } else if (lit->IsString()) { |
| 500 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 501 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 502 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 503 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 504 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 505 | } else if (lit->IsSmi()) { |
| 506 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 507 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 508 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 509 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 510 | } |
| 511 | } else { |
| 512 | // For simplicity we always test the accumulator register. |
| 513 | __ mov(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 514 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 519 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 520 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 521 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 522 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 526 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 527 | int count, |
| 528 | Register reg) const { |
| 529 | ASSERT(count > 0); |
| 530 | __ Drop(count); |
| 531 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 535 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 536 | Register reg) const { |
| 537 | ASSERT(count > 0); |
| 538 | if (count > 1) __ Drop(count - 1); |
| 539 | __ mov(Operand(esp, 0), reg); |
| 540 | } |
| 541 | |
| 542 | |
| 543 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 544 | Register reg) const { |
| 545 | ASSERT(count > 0); |
| 546 | // For simplicity we always test the accumulator register. |
| 547 | __ Drop(count); |
| 548 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 549 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 550 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | |
| 554 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 555 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 556 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 557 | __ bind(materialize_true); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 562 | Label* materialize_true, |
| 563 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 564 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 565 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 566 | __ mov(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 567 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 568 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 569 | __ mov(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 570 | __ bind(&done); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | void FullCodeGenerator::StackValueContext::Plug( |
| 575 | Label* materialize_true, |
| 576 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 577 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 578 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 579 | __ push(Immediate(isolate()->factory()->true_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 580 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 581 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 582 | __ push(Immediate(isolate()->factory()->false_value())); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 583 | __ bind(&done); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 588 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 589 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 590 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | |
| 594 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 595 | } |
| 596 | |
| 597 | |
| 598 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 599 | Handle<Object> value = flag |
| 600 | ? isolate()->factory()->true_value() |
| 601 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 602 | __ mov(result_register(), value); |
| 603 | } |
| 604 | |
| 605 | |
| 606 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 607 | Handle<Object> value = flag |
| 608 | ? isolate()->factory()->true_value() |
| 609 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 610 | __ push(Immediate(value)); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 615 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 616 | true, |
| 617 | true_label_, |
| 618 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 619 | if (flag) { |
| 620 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 621 | } else { |
| 622 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
| 626 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 627 | void FullCodeGenerator::DoTest(Expression* condition, |
| 628 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 629 | Label* if_false, |
| 630 | Label* fall_through) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 631 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 632 | CallIC(ic, condition->test_id()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 633 | __ test(result_register(), result_register()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 634 | // The stub returns nonzero for true. |
| 635 | Split(not_zero, if_true, if_false, fall_through); |
| 636 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 637 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 638 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 639 | void FullCodeGenerator::Split(Condition cc, |
| 640 | Label* if_true, |
| 641 | Label* if_false, |
| 642 | Label* fall_through) { |
| 643 | if (if_false == fall_through) { |
| 644 | __ j(cc, if_true); |
| 645 | } else if (if_true == fall_through) { |
| 646 | __ j(NegateCondition(cc), if_false); |
| 647 | } else { |
| 648 | __ j(cc, if_true); |
| 649 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 650 | } |
| 651 | } |
| 652 | |
| 653 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 654 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 655 | ASSERT(var->IsStackAllocated()); |
| 656 | // Offset is negative because higher indexes are at lower addresses. |
| 657 | int offset = -var->index() * kPointerSize; |
| 658 | // Adjust by a (parameter or local) base offset. |
| 659 | if (var->IsParameter()) { |
| 660 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 661 | } else { |
| 662 | offset += JavaScriptFrameConstants::kLocal0Offset; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 663 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 664 | return Operand(ebp, offset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 668 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 669 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 670 | if (var->IsContextSlot()) { |
| 671 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 672 | __ LoadContext(scratch, context_chain_length); |
| 673 | return ContextOperand(scratch, var->index()); |
| 674 | } else { |
| 675 | return StackOperand(var); |
| 676 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 680 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 681 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 682 | MemOperand location = VarOperand(var, dest); |
| 683 | __ mov(dest, location); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | void FullCodeGenerator::SetVar(Variable* var, |
| 688 | Register src, |
| 689 | Register scratch0, |
| 690 | Register scratch1) { |
| 691 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 692 | ASSERT(!scratch0.is(src)); |
| 693 | ASSERT(!scratch0.is(scratch1)); |
| 694 | ASSERT(!scratch1.is(src)); |
| 695 | MemOperand location = VarOperand(var, scratch0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | __ mov(location, src); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 697 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | // 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] | 699 | if (var->IsContextSlot()) { |
| 700 | int offset = Context::SlotOffset(var->index()); |
| 701 | ASSERT(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 702 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 707 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 708 | bool should_normalize, |
| 709 | Label* if_true, |
| 710 | Label* if_false) { |
| 711 | // Only prepare for bailouts before splits if we're in a test |
| 712 | // context. Otherwise, we let the Visit function deal with the |
| 713 | // preparation to avoid preparing with the same AST id twice. |
| 714 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 715 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 716 | Label skip; |
| 717 | if (should_normalize) __ jmp(&skip, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 718 | PrepareForBailout(expr, TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 719 | if (should_normalize) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 720 | __ cmp(eax, isolate()->factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 721 | Split(equal, if_true, if_false, NULL); |
| 722 | __ bind(&skip); |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 727 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 728 | // 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] | 729 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 730 | if (generate_debug_code_) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 731 | // Check that we're not inside a with or catch context. |
| 732 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 733 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 734 | __ Check(not_equal, kDeclarationInWithContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 735 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 736 | __ Check(not_equal, kDeclarationInCatchContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 737 | } |
| 738 | } |
| 739 | |
| 740 | |
| 741 | void FullCodeGenerator::VisitVariableDeclaration( |
| 742 | VariableDeclaration* declaration) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 743 | // If it was not possible to allocate the variable at compile time, we |
| 744 | // need to "declare" it at runtime to make sure it actually exists in the |
| 745 | // local context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 746 | VariableProxy* proxy = declaration->proxy(); |
| 747 | VariableMode mode = declaration->mode(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 748 | Variable* variable = proxy->var(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 749 | bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 750 | switch (variable->location()) { |
| 751 | case Variable::UNALLOCATED: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 752 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 753 | globals_->Add(variable->binding_needs_init() |
| 754 | ? isolate()->factory()->the_hole_value() |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 755 | : isolate()->factory()->undefined_value(), zone()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case Variable::PARAMETER: |
| 759 | case Variable::LOCAL: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 760 | if (hole_init) { |
| 761 | Comment cmnt(masm_, "[ VariableDeclaration"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 762 | __ mov(StackOperand(variable), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 763 | Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 764 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 765 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 766 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 767 | case Variable::CONTEXT: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 768 | if (hole_init) { |
| 769 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 770 | EmitDebugCheckDeclarationContext(variable); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 771 | __ mov(ContextOperand(esi, variable->index()), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 772 | Immediate(isolate()->factory()->the_hole_value())); |
| 773 | // No write barrier since the hole value is in old space. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 774 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 775 | } |
| 776 | break; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 777 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 778 | case Variable::LOOKUP: { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 779 | Comment cmnt(masm_, "[ VariableDeclaration"); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 780 | __ push(esi); |
| 781 | __ push(Immediate(variable->name())); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 782 | // VariableDeclaration nodes are always introduced in one of four modes. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 783 | ASSERT(IsDeclaredVariableMode(mode)); |
| 784 | PropertyAttributes attr = |
| 785 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 786 | __ push(Immediate(Smi::FromInt(attr))); |
| 787 | // Push initial value, if any. |
| 788 | // Note: For variables we must not push an initial value (such as |
| 789 | // 'undefined') because we may have a (legal) redeclaration and we |
| 790 | // must not destroy the current value. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 791 | if (hole_init) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 792 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 793 | } else { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 794 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 795 | } |
| 796 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 797 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 803 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 804 | FunctionDeclaration* declaration) { |
| 805 | VariableProxy* proxy = declaration->proxy(); |
| 806 | Variable* variable = proxy->var(); |
| 807 | switch (variable->location()) { |
| 808 | case Variable::UNALLOCATED: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 809 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 810 | Handle<SharedFunctionInfo> function = |
| 811 | Compiler::BuildFunctionInfo(declaration->fun(), script()); |
| 812 | // Check for stack-overflow exception. |
| 813 | if (function.is_null()) return SetStackOverflow(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 814 | globals_->Add(function, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 815 | break; |
| 816 | } |
| 817 | |
| 818 | case Variable::PARAMETER: |
| 819 | case Variable::LOCAL: { |
| 820 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 821 | VisitForAccumulatorValue(declaration->fun()); |
| 822 | __ mov(StackOperand(variable), result_register()); |
| 823 | break; |
| 824 | } |
| 825 | |
| 826 | case Variable::CONTEXT: { |
| 827 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 828 | EmitDebugCheckDeclarationContext(variable); |
| 829 | VisitForAccumulatorValue(declaration->fun()); |
| 830 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 831 | // We know that we have written a function, which is not a smi. |
| 832 | __ RecordWriteContextSlot(esi, |
| 833 | Context::SlotOffset(variable->index()), |
| 834 | result_register(), |
| 835 | ecx, |
| 836 | kDontSaveFPRegs, |
| 837 | EMIT_REMEMBERED_SET, |
| 838 | OMIT_SMI_CHECK); |
| 839 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | case Variable::LOOKUP: { |
| 844 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 845 | __ push(esi); |
| 846 | __ push(Immediate(variable->name())); |
| 847 | __ push(Immediate(Smi::FromInt(NONE))); |
| 848 | VisitForStackValue(declaration->fun()); |
| 849 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 850 | break; |
| 851 | } |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | |
| 856 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 857 | Variable* variable = declaration->proxy()->var(); |
| 858 | ASSERT(variable->location() == Variable::CONTEXT); |
| 859 | ASSERT(variable->interface()->IsFrozen()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 860 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 861 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 862 | EmitDebugCheckDeclarationContext(variable); |
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 | // Load instance object. |
| 865 | __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 866 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 867 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 868 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 869 | // Assign it. |
| 870 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 871 | // We know that we have written a module, which is not a smi. |
| 872 | __ RecordWriteContextSlot(esi, |
| 873 | Context::SlotOffset(variable->index()), |
| 874 | eax, |
| 875 | ecx, |
| 876 | kDontSaveFPRegs, |
| 877 | EMIT_REMEMBERED_SET, |
| 878 | OMIT_SMI_CHECK); |
| 879 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 880 | |
| 881 | // Traverse into body. |
| 882 | Visit(declaration->module()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | |
| 886 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 887 | VariableProxy* proxy = declaration->proxy(); |
| 888 | Variable* variable = proxy->var(); |
| 889 | switch (variable->location()) { |
| 890 | case Variable::UNALLOCATED: |
| 891 | // TODO(rossberg) |
| 892 | break; |
| 893 | |
| 894 | case Variable::CONTEXT: { |
| 895 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 896 | EmitDebugCheckDeclarationContext(variable); |
| 897 | // TODO(rossberg) |
| 898 | break; |
| 899 | } |
| 900 | |
| 901 | case Variable::PARAMETER: |
| 902 | case Variable::LOCAL: |
| 903 | case Variable::LOOKUP: |
| 904 | UNREACHABLE(); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | |
| 909 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 910 | // TODO(rossberg) |
| 911 | } |
| 912 | |
| 913 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 914 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 915 | // Call the runtime to declare the globals. |
| 916 | __ push(esi); // The context is the first argument. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 917 | __ Push(pairs); |
| 918 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 919 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 920 | // Return value is ignored. |
| 921 | } |
| 922 | |
| 923 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 924 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 925 | // Call the runtime to declare the modules. |
| 926 | __ Push(descriptions); |
| 927 | __ CallRuntime(Runtime::kDeclareModules, 1); |
| 928 | // Return value is ignored. |
| 929 | } |
| 930 | |
| 931 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 932 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 933 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 934 | Breakable nested_statement(this, stmt); |
| 935 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 936 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 937 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 938 | VisitForStackValue(stmt->tag()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 939 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 940 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 941 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 942 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 943 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 944 | Label next_test; // Recycled for each test. |
| 945 | // Compile all the tests with branches to their bodies. |
| 946 | for (int i = 0; i < clauses->length(); i++) { |
| 947 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 948 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 949 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 950 | // The default is not a test, but remember it as final fall through. |
| 951 | if (clause->is_default()) { |
| 952 | default_clause = clause; |
| 953 | continue; |
| 954 | } |
| 955 | |
| 956 | Comment cmnt(masm_, "[ Case comparison"); |
| 957 | __ bind(&next_test); |
| 958 | next_test.Unuse(); |
| 959 | |
| 960 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 961 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 962 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 963 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 964 | __ mov(edx, Operand(esp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 965 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 966 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 967 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 968 | Label slow_case; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 969 | __ mov(ecx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 970 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 971 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 972 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 973 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 974 | __ j(not_equal, &next_test); |
| 975 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 976 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 977 | __ bind(&slow_case); |
| 978 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 979 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | // Record position before stub call for type feedback. |
| 981 | SetSourcePosition(clause->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 982 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 983 | CallIC(ic, clause->CompareId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 984 | patch_site.EmitPatchInfo(); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 985 | |
| 986 | Label skip; |
| 987 | __ jmp(&skip, Label::kNear); |
| 988 | PrepareForBailout(clause, TOS_REG); |
| 989 | __ cmp(eax, isolate()->factory()->true_value()); |
| 990 | __ j(not_equal, &next_test); |
| 991 | __ Drop(1); |
| 992 | __ jmp(clause->body_target()); |
| 993 | __ bind(&skip); |
| 994 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 995 | __ test(eax, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 996 | __ j(not_equal, &next_test); |
| 997 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 998 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // Discard the test value and jump to the default if present, otherwise to |
| 1002 | // the end of the statement. |
| 1003 | __ bind(&next_test); |
| 1004 | __ Drop(1); // Switch value is no longer needed. |
| 1005 | if (default_clause == NULL) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1006 | __ jmp(nested_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1007 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1008 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | // Compile all the case bodies. |
| 1012 | for (int i = 0; i < clauses->length(); i++) { |
| 1013 | Comment cmnt(masm_, "[ Case body"); |
| 1014 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1015 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1016 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1017 | VisitStatements(clause->statements()); |
| 1018 | } |
| 1019 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1020 | __ bind(nested_statement.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1021 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | |
| 1025 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1026 | Comment cmnt(masm_, "[ ForInStatement"); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1027 | int slot = stmt->ForInFeedbackSlot(); |
| 1028 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1029 | SetStatementPosition(stmt); |
| 1030 | |
| 1031 | Label loop, exit; |
| 1032 | ForIn loop_statement(this, stmt); |
| 1033 | increment_loop_depth(); |
| 1034 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1035 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1036 | // 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] | 1037 | VisitForAccumulatorValue(stmt->enumerable()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1038 | __ cmp(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1039 | __ j(equal, &exit); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1040 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1041 | __ j(equal, &exit); |
| 1042 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1043 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1044 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1045 | // Convert the object to a JS object. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1046 | Label convert, done_convert; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1047 | __ JumpIfSmi(eax, &convert, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1048 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1049 | __ j(above_equal, &done_convert, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1050 | __ bind(&convert); |
| 1051 | __ push(eax); |
| 1052 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1053 | __ bind(&done_convert); |
| 1054 | __ push(eax); |
| 1055 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1056 | // Check for proxies. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1057 | Label call_runtime, use_cache, fixed_array; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1058 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1059 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1060 | __ j(below_equal, &call_runtime); |
| 1061 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1062 | // Check cache validity in generated code. This is a fast case for |
| 1063 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1064 | // guarantee cache validity, call the runtime system to check cache |
| 1065 | // validity or get the property names in a fixed array. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1066 | __ CheckEnumCache(&call_runtime); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1067 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1068 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1069 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1070 | |
| 1071 | // Get the set of properties to enumerate. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1072 | __ bind(&call_runtime); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1073 | __ push(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1074 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1075 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1076 | isolate()->factory()->meta_map()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1077 | __ j(not_equal, &fixed_array); |
| 1078 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1079 | |
| 1080 | // 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] | 1081 | Label no_descriptors; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1082 | __ bind(&use_cache); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1083 | |
| 1084 | __ EnumLength(edx, eax); |
| 1085 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1086 | __ j(equal, &no_descriptors); |
| 1087 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1088 | __ LoadInstanceDescriptors(eax, ecx); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1089 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1090 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1091 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1092 | // Set up the four remaining stack slots. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1093 | __ push(eax); // Map. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1094 | __ push(ecx); // Enumeration cache. |
| 1095 | __ 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] | 1096 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1097 | __ jmp(&loop); |
| 1098 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1099 | __ bind(&no_descriptors); |
| 1100 | __ add(esp, Immediate(kPointerSize)); |
| 1101 | __ jmp(&exit); |
| 1102 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1103 | // 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] | 1104 | Label non_proxy; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1105 | __ bind(&fixed_array); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1106 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame^] | 1107 | Handle<Object> feedback = Handle<Object>( |
| 1108 | Smi::FromInt(TypeFeedbackInfo::kForInFastCaseMarker), |
| 1109 | isolate()); |
| 1110 | StoreFeedbackVectorSlot(slot, feedback); |
| 1111 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1112 | // No need for a write barrier, we are storing a Smi in the feedback vector. |
| 1113 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 1114 | __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(slot)), |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame^] | 1115 | Immediate(Smi::FromInt(TypeFeedbackInfo::kForInSlowCaseMarker))); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1116 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1117 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1118 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1119 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1120 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1121 | __ j(above, &non_proxy); |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame] | 1122 | __ Set(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1123 | __ bind(&non_proxy); |
| 1124 | __ push(ebx); // Smi |
| 1125 | __ push(eax); // Array |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1126 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1127 | __ push(eax); // Fixed array length (as smi). |
| 1128 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1129 | |
| 1130 | // Generate code for doing the condition check. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1131 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1132 | __ bind(&loop); |
| 1133 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1134 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1135 | __ j(above_equal, loop_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1136 | |
| 1137 | // Get the current entry of the array into register ebx. |
| 1138 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1139 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1140 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1141 | // 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] | 1142 | // permanent slow case into register edx. |
| 1143 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1144 | |
| 1145 | // 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] | 1146 | // If not, we may have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1147 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1148 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1149 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1150 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1151 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1152 | // For proxies, no filtering is done. |
| 1153 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1154 | ASSERT(Smi::FromInt(0) == 0); |
| 1155 | __ test(edx, edx); |
| 1156 | __ j(zero, &update_each); |
| 1157 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1158 | // Convert the entry to a string or null if it isn't a property |
| 1159 | // anymore. If the property has been removed while iterating, we |
| 1160 | // just skip it. |
| 1161 | __ push(ecx); // Enumerable. |
| 1162 | __ push(ebx); // Current entry. |
| 1163 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1164 | __ test(eax, eax); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1165 | __ j(equal, loop_statement.continue_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1166 | __ mov(ebx, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1167 | |
| 1168 | // Update the 'each' property or variable from the possibly filtered |
| 1169 | // entry in register ebx. |
| 1170 | __ bind(&update_each); |
| 1171 | __ mov(result_register(), ebx); |
| 1172 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1173 | { EffectContext context(this); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1174 | EmitAssignment(stmt->each()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1175 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1176 | |
| 1177 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1178 | Visit(stmt->body()); |
| 1179 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1180 | // Generate code for going to the next element by incrementing the |
| 1181 | // index (smi) stored on top of the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1182 | __ bind(loop_statement.continue_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1183 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1184 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1185 | EmitBackEdgeBookkeeping(stmt, &loop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1186 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1187 | |
| 1188 | // Remove the pointers stored on the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1189 | __ bind(loop_statement.break_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1190 | __ add(esp, Immediate(5 * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1191 | |
| 1192 | // Exit and decrement the loop depth. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1193 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1194 | __ bind(&exit); |
| 1195 | decrement_loop_depth(); |
| 1196 | } |
| 1197 | |
| 1198 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1199 | void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 1200 | Comment cmnt(masm_, "[ ForOfStatement"); |
| 1201 | SetStatementPosition(stmt); |
| 1202 | |
| 1203 | Iteration loop_statement(this, stmt); |
| 1204 | increment_loop_depth(); |
| 1205 | |
| 1206 | // var iterator = iterable[@@iterator]() |
| 1207 | VisitForAccumulatorValue(stmt->assign_iterator()); |
| 1208 | |
| 1209 | // As with for-in, skip the loop if the iterator is null or undefined. |
| 1210 | __ CompareRoot(eax, Heap::kUndefinedValueRootIndex); |
| 1211 | __ j(equal, loop_statement.break_label()); |
| 1212 | __ CompareRoot(eax, Heap::kNullValueRootIndex); |
| 1213 | __ j(equal, loop_statement.break_label()); |
| 1214 | |
| 1215 | // Convert the iterator to a JS object. |
| 1216 | Label convert, done_convert; |
| 1217 | __ JumpIfSmi(eax, &convert); |
| 1218 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1219 | __ j(above_equal, &done_convert); |
| 1220 | __ bind(&convert); |
| 1221 | __ push(eax); |
| 1222 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1223 | __ bind(&done_convert); |
| 1224 | |
| 1225 | // Loop entry. |
| 1226 | __ bind(loop_statement.continue_label()); |
| 1227 | |
| 1228 | // result = iterator.next() |
| 1229 | VisitForEffect(stmt->next_result()); |
| 1230 | |
| 1231 | // if (result.done) break; |
| 1232 | Label result_not_done; |
| 1233 | VisitForControl(stmt->result_done(), |
| 1234 | loop_statement.break_label(), |
| 1235 | &result_not_done, |
| 1236 | &result_not_done); |
| 1237 | __ bind(&result_not_done); |
| 1238 | |
| 1239 | // each = result.value |
| 1240 | VisitForEffect(stmt->assign_each()); |
| 1241 | |
| 1242 | // Generate code for the body of the loop. |
| 1243 | Visit(stmt->body()); |
| 1244 | |
| 1245 | // Check stack before looping. |
| 1246 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
| 1247 | EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); |
| 1248 | __ jmp(loop_statement.continue_label()); |
| 1249 | |
| 1250 | // Exit and decrement the loop depth. |
| 1251 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1252 | __ bind(loop_statement.break_label()); |
| 1253 | decrement_loop_depth(); |
| 1254 | } |
| 1255 | |
| 1256 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1257 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1258 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1259 | // Use the fast case closure allocation code that allocates in new |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1260 | // space for nested functions that don't need literals cloning. If |
| 1261 | // we're running with the --always-opt or the --prepare-always-opt |
| 1262 | // flag, we need to use the runtime function so that the new function |
| 1263 | // we are creating here gets a chance to have its code optimized and |
| 1264 | // doesn't just get a copy of the existing unoptimized code. |
| 1265 | if (!FLAG_always_opt && |
| 1266 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1267 | !pretenure && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1268 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1269 | info->num_literals() == 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1270 | FastNewClosureStub stub(info->strict_mode(), info->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1271 | __ mov(ebx, Immediate(info)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1272 | __ CallStub(&stub); |
| 1273 | } else { |
| 1274 | __ push(esi); |
| 1275 | __ push(Immediate(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1276 | __ push(Immediate(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1277 | ? isolate()->factory()->true_value() |
| 1278 | : isolate()->factory()->false_value())); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1279 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1280 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1281 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | |
| 1285 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1286 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1287 | EmitVariableLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1291 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
| 1292 | TypeofState typeof_state, |
| 1293 | Label* slow) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1294 | Register context = esi; |
| 1295 | Register temp = edx; |
| 1296 | |
| 1297 | Scope* s = scope(); |
| 1298 | while (s != NULL) { |
| 1299 | if (s->num_heap_slots() > 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1300 | if (s->calls_sloppy_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1301 | // Check that extension is NULL. |
| 1302 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1303 | Immediate(0)); |
| 1304 | __ j(not_equal, slow); |
| 1305 | } |
| 1306 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1307 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1308 | // Walk the rest of the chain without clobbering esi. |
| 1309 | context = temp; |
| 1310 | } |
| 1311 | // If no outer scope calls eval, we do not need to check more |
| 1312 | // context extensions. If we have reached an eval scope, we check |
| 1313 | // all extensions from this point. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1314 | if (!s->outer_scope_calls_sloppy_eval() || s->is_eval_scope()) break; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1315 | s = s->outer_scope(); |
| 1316 | } |
| 1317 | |
| 1318 | if (s != NULL && s->is_eval_scope()) { |
| 1319 | // Loop up the context chain. There is no frame effect so it is |
| 1320 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1321 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1322 | if (!context.is(temp)) { |
| 1323 | __ mov(temp, context); |
| 1324 | } |
| 1325 | __ bind(&next); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1326 | // Terminate at native context. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1327 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1328 | Immediate(isolate()->factory()->native_context_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1329 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1330 | // Check that extension is NULL. |
| 1331 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1332 | __ j(not_equal, slow); |
| 1333 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1334 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1335 | __ jmp(&next); |
| 1336 | __ bind(&fast); |
| 1337 | } |
| 1338 | |
| 1339 | // All extension objects were empty and it is safe to use a global |
| 1340 | // load IC call. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1341 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1342 | __ mov(ecx, var->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1343 | ContextualMode mode = (typeof_state == INSIDE_TYPEOF) |
| 1344 | ? NOT_CONTEXTUAL |
| 1345 | : CONTEXTUAL; |
| 1346 | |
| 1347 | CallLoadIC(mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1351 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1352 | Label* slow) { |
| 1353 | ASSERT(var->IsContextSlot()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1354 | Register context = esi; |
| 1355 | Register temp = ebx; |
| 1356 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1357 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1358 | if (s->num_heap_slots() > 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1359 | if (s->calls_sloppy_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1360 | // Check that extension is NULL. |
| 1361 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1362 | Immediate(0)); |
| 1363 | __ j(not_equal, slow); |
| 1364 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1365 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1366 | // Walk the rest of the chain without clobbering esi. |
| 1367 | context = temp; |
| 1368 | } |
| 1369 | } |
| 1370 | // Check that last extension is NULL. |
| 1371 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1372 | __ j(not_equal, slow); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1373 | |
| 1374 | // This function is used only for loads, not stores, so it's safe to |
| 1375 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1376 | // destroy the esi register). |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1377 | return ContextOperand(context, var->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1381 | void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| 1382 | TypeofState typeof_state, |
| 1383 | Label* slow, |
| 1384 | Label* done) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1385 | // Generate fast-case code for variables that might be shadowed by |
| 1386 | // eval-introduced variables. Eval is used a lot without |
| 1387 | // introducing variables. In those cases, we do not want to |
| 1388 | // perform a runtime call for all variables in the scope |
| 1389 | // containing the eval. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1390 | if (var->mode() == DYNAMIC_GLOBAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1391 | EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1392 | __ jmp(done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1393 | } else if (var->mode() == DYNAMIC_LOCAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1394 | Variable* local = var->local_if_not_shadowed(); |
| 1395 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1396 | if (local->mode() == LET || local->mode() == CONST || |
| 1397 | local->mode() == CONST_LEGACY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1398 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1399 | __ j(not_equal, done); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1400 | if (local->mode() == CONST_LEGACY) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1401 | __ mov(eax, isolate()->factory()->undefined_value()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1402 | } else { // LET || CONST |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1403 | __ push(Immediate(var->name())); |
| 1404 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1405 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1406 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1407 | __ jmp(done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1412 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1413 | // Record position before possible IC call. |
| 1414 | SetSourcePosition(proxy->position()); |
| 1415 | Variable* var = proxy->var(); |
| 1416 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1417 | // Three cases: global variables, lookup variables, and all other types of |
| 1418 | // variables. |
| 1419 | switch (var->location()) { |
| 1420 | case Variable::UNALLOCATED: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1421 | Comment cmnt(masm_, "[ Global variable"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1422 | // Use inline caching. Variable name is passed in ecx and the global |
| 1423 | // object in eax. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1424 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1425 | __ mov(ecx, var->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1426 | CallLoadIC(CONTEXTUAL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1427 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1428 | break; |
| 1429 | } |
| 1430 | |
| 1431 | case Variable::PARAMETER: |
| 1432 | case Variable::LOCAL: |
| 1433 | case Variable::CONTEXT: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1434 | Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
| 1435 | : "[ Stack variable"); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1436 | if (var->binding_needs_init()) { |
| 1437 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1438 | // refers to a potential outside binding. Currently those bindings are |
| 1439 | // always looked up dynamically, i.e. in that case |
| 1440 | // var->location() == LOOKUP. |
| 1441 | // always holds. |
| 1442 | ASSERT(var->scope() != NULL); |
| 1443 | |
| 1444 | // Check if the binding really needs an initialization check. The check |
| 1445 | // can be skipped in the following situation: we have a LET or CONST |
| 1446 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1447 | // the same declaration scope (i.e. they are both in global code, in the |
| 1448 | // same function or in the same eval code) and the VariableProxy is in |
| 1449 | // the source physically located after the initializer of the variable. |
| 1450 | // |
| 1451 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1452 | // mode because const variables may be declared but never initialized: |
| 1453 | // if (false) { const x; }; var y = x; |
| 1454 | // |
| 1455 | // The condition on the declaration scopes is a conservative check for |
| 1456 | // nested functions that access a binding and are called before the |
| 1457 | // binding is initialized: |
| 1458 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1459 | // |
| 1460 | bool skip_init_check; |
| 1461 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1462 | skip_init_check = false; |
jkummerow@chromium.org | ac45fed | 2011-11-07 13:11:02 +0000 | [diff] [blame] | 1463 | } else { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1464 | // Check that we always have valid source position. |
| 1465 | ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1466 | ASSERT(proxy->position() != RelocInfo::kNoPosition); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1467 | skip_init_check = var->mode() != CONST_LEGACY && |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1468 | var->initializer_position() < proxy->position(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1469 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1470 | |
| 1471 | if (!skip_init_check) { |
| 1472 | // Let and const need a read barrier. |
| 1473 | Label done; |
| 1474 | GetVar(eax, var); |
| 1475 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1476 | __ j(not_equal, &done, Label::kNear); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1477 | if (var->mode() == LET || var->mode() == CONST) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1478 | // Throw a reference error when using an uninitialized let/const |
| 1479 | // binding in harmony mode. |
| 1480 | __ push(Immediate(var->name())); |
| 1481 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 1482 | } else { |
| 1483 | // Uninitalized const bindings outside of harmony mode are unholed. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1484 | ASSERT(var->mode() == CONST_LEGACY); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1485 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1486 | } |
| 1487 | __ bind(&done); |
| 1488 | context()->Plug(eax); |
| 1489 | break; |
| 1490 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1491 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1492 | context()->Plug(var); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1493 | break; |
| 1494 | } |
| 1495 | |
| 1496 | case Variable::LOOKUP: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1497 | Comment cmnt(masm_, "[ Lookup variable"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1498 | Label done, slow; |
| 1499 | // Generate code for loading from variables potentially shadowed |
| 1500 | // by eval-introduced variables. |
| 1501 | EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1502 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1503 | __ push(esi); // Context. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1504 | __ push(Immediate(var->name())); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1505 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1506 | __ bind(&done); |
| 1507 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1508 | break; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1509 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | |
| 1514 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1515 | Comment cmnt(masm_, "[ RegExpLiteral"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1516 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1517 | // Registers will be used as follows: |
| 1518 | // edi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1519 | // ecx = literals array. |
| 1520 | // ebx = regexp literal. |
| 1521 | // eax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1522 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1523 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1524 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1525 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1526 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1527 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1528 | __ j(not_equal, &materialized, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1529 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1530 | // Create regexp literal using runtime function |
| 1531 | // Result will be in eax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1532 | __ push(ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1533 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1534 | __ push(Immediate(expr->pattern())); |
| 1535 | __ push(Immediate(expr->flags())); |
| 1536 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1537 | __ mov(ebx, eax); |
| 1538 | |
| 1539 | __ bind(&materialized); |
| 1540 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1541 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1542 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1543 | __ jmp(&allocated); |
| 1544 | |
| 1545 | __ bind(&runtime_allocate); |
| 1546 | __ push(ebx); |
| 1547 | __ push(Immediate(Smi::FromInt(size))); |
| 1548 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 1549 | __ pop(ebx); |
| 1550 | |
| 1551 | __ bind(&allocated); |
| 1552 | // Copy the content into the newly allocated memory. |
| 1553 | // (Unroll copy loop once for better throughput). |
| 1554 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1555 | __ mov(edx, FieldOperand(ebx, i)); |
| 1556 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1557 | __ mov(FieldOperand(eax, i), edx); |
| 1558 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1559 | } |
| 1560 | if ((size % (2 * kPointerSize)) != 0) { |
| 1561 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1562 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1563 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1564 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1568 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1569 | if (expression == NULL) { |
| 1570 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1571 | } else { |
| 1572 | VisitForStackValue(expression); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1577 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1578 | Comment cmnt(masm_, "[ ObjectLiteral"); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1579 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1580 | expr->BuildConstantProperties(isolate()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1581 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1582 | int flags = expr->fast_elements() |
| 1583 | ? ObjectLiteral::kFastElements |
| 1584 | : ObjectLiteral::kNoFlags; |
| 1585 | flags |= expr->has_function() |
| 1586 | ? ObjectLiteral::kHasFunction |
| 1587 | : ObjectLiteral::kNoFlags; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1588 | int properties_count = constant_properties->length() / 2; |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1589 | if (expr->may_store_doubles() || expr->depth() > 1 || Serializer::enabled() || |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1590 | flags != ObjectLiteral::kFastElements || |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1591 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1592 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1593 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1594 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1595 | __ push(Immediate(constant_properties)); |
| 1596 | __ push(Immediate(Smi::FromInt(flags))); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1597 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1598 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1599 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1600 | __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1601 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1602 | __ mov(ecx, Immediate(constant_properties)); |
| 1603 | __ mov(edx, Immediate(Smi::FromInt(flags))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1604 | FastCloneShallowObjectStub stub(properties_count); |
| 1605 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | // If result_saved is true the result is on top of the stack. If |
| 1609 | // result_saved is false the result is in eax. |
| 1610 | bool result_saved = false; |
| 1611 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1612 | // Mark all computed expressions that are bound to a key that |
| 1613 | // is shadowed by a later occurrence of the same key. For the |
| 1614 | // marked expressions, no store code is emitted. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1615 | expr->CalculateEmitStore(zone()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1616 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1617 | AccessorTable accessor_table(zone()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1618 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1619 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1620 | if (property->IsCompileTimeValue()) continue; |
| 1621 | |
| 1622 | Literal* key = property->key(); |
| 1623 | Expression* value = property->value(); |
| 1624 | if (!result_saved) { |
| 1625 | __ push(eax); // Save result on the stack |
| 1626 | result_saved = true; |
| 1627 | } |
| 1628 | switch (property->kind()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1629 | case ObjectLiteral::Property::CONSTANT: |
| 1630 | UNREACHABLE(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1631 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1632 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1633 | // Fall through. |
| 1634 | case ObjectLiteral::Property::COMPUTED: |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1635 | if (key->value()->IsInternalizedString()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1636 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1637 | VisitForAccumulatorValue(value); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1638 | __ mov(ecx, Immediate(key->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | __ mov(edx, Operand(esp, 0)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1640 | CallStoreIC(key->LiteralFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1641 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1642 | } else { |
| 1643 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1644 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1645 | break; |
| 1646 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1647 | __ push(Operand(esp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1648 | VisitForStackValue(key); |
| 1649 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1650 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1651 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1652 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1653 | } else { |
| 1654 | __ Drop(3); |
| 1655 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1656 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1657 | case ObjectLiteral::Property::PROTOTYPE: |
| 1658 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1659 | VisitForStackValue(value); |
| 1660 | if (property->emit_store()) { |
| 1661 | __ CallRuntime(Runtime::kSetPrototype, 2); |
| 1662 | } else { |
| 1663 | __ Drop(2); |
| 1664 | } |
| 1665 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1666 | case ObjectLiteral::Property::GETTER: |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1667 | accessor_table.lookup(key)->second->getter = value; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1668 | break; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1669 | case ObjectLiteral::Property::SETTER: |
| 1670 | accessor_table.lookup(key)->second->setter = value; |
| 1671 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1672 | } |
| 1673 | } |
| 1674 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1675 | // Emit code to define accessors, using only a single call to the runtime for |
| 1676 | // each pair of corresponding getters and setters. |
| 1677 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1678 | it != accessor_table.end(); |
| 1679 | ++it) { |
| 1680 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1681 | VisitForStackValue(it->first); |
| 1682 | EmitAccessor(it->second->getter); |
| 1683 | EmitAccessor(it->second->setter); |
| 1684 | __ push(Immediate(Smi::FromInt(NONE))); |
| 1685 | __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1686 | } |
| 1687 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1688 | if (expr->has_function()) { |
| 1689 | ASSERT(result_saved); |
| 1690 | __ push(Operand(esp, 0)); |
| 1691 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1692 | } |
| 1693 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1694 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1695 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1696 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1697 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1698 | } |
| 1699 | } |
| 1700 | |
| 1701 | |
| 1702 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1703 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1704 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1705 | expr->BuildConstantElements(isolate()); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1706 | int flags = expr->depth() == 1 |
| 1707 | ? ArrayLiteral::kShallowElements |
| 1708 | : ArrayLiteral::kNoFlags; |
| 1709 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1710 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1711 | int length = subexprs->length(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1712 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1713 | ASSERT_EQ(2, constant_elements->length()); |
| 1714 | ElementsKind constant_elements_kind = |
| 1715 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1716 | bool has_constant_fast_elements = |
| 1717 | IsFastObjectElementsKind(constant_elements_kind); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1718 | Handle<FixedArrayBase> constant_elements_values( |
| 1719 | FixedArrayBase::cast(constant_elements->get(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1720 | |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1721 | AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1722 | if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1723 | // If the only customer of allocation sites is transitioning, then |
| 1724 | // we can turn it off if we don't have anywhere else to transition to. |
| 1725 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1726 | } |
| 1727 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1728 | Heap* heap = isolate()->heap(); |
| 1729 | if (has_constant_fast_elements && |
| 1730 | constant_elements_values->map() == heap->fixed_cow_array_map()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1731 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1732 | // change, so it's possible to specialize the stub in advance. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1733 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1734 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1735 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1736 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1737 | __ mov(ecx, Immediate(constant_elements)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1738 | FastCloneShallowArrayStub stub( |
| 1739 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1740 | allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1741 | length); |
| 1742 | __ CallStub(&stub); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1743 | } else if (expr->depth() > 1 || Serializer::enabled() || |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1744 | length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1745 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1746 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1747 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1748 | __ push(Immediate(constant_elements)); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1749 | __ push(Immediate(Smi::FromInt(flags))); |
| 1750 | __ CallRuntime(Runtime::kCreateArrayLiteral, 4); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1751 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1752 | ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1753 | FLAG_smi_only_arrays); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1754 | FastCloneShallowArrayStub::Mode mode = |
| 1755 | FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1756 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1757 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1758 | // change, so it's possible to specialize the stub in advance. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1759 | if (has_constant_fast_elements) { |
| 1760 | mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1763 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1764 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1765 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1766 | __ mov(ecx, Immediate(constant_elements)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1767 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1768 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | bool result_saved = false; // Is the result saved to the stack? |
| 1772 | |
| 1773 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1774 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1775 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1776 | Expression* subexpr = subexprs->at(i); |
| 1777 | // If the subexpression is a literal or a simple materialized literal it |
| 1778 | // is already set in the cloned array. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1779 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1780 | |
| 1781 | if (!result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1782 | __ push(eax); // array literal. |
| 1783 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1784 | result_saved = true; |
| 1785 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1786 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1787 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1788 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1789 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1790 | // cannot transition and don't need to call the runtime stub. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1791 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1792 | __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1793 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1794 | // Store the subexpression value in the array's elements. |
| 1795 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1796 | // Update the write barrier for the array store. |
| 1797 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1798 | kDontSaveFPRegs, |
| 1799 | EMIT_REMEMBERED_SET, |
| 1800 | INLINE_SMI_CHECK); |
| 1801 | } else { |
| 1802 | // Store the subexpression value in the array's elements. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1803 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1804 | StoreArrayLiteralElementStub stub; |
| 1805 | __ CallStub(&stub); |
| 1806 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | |
| 1808 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | if (result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1812 | __ add(esp, Immediate(kPointerSize)); // literal index |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1813 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1814 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1815 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1820 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1821 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1822 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1823 | // on the left-hand side. |
| 1824 | if (!expr->target()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1825 | VisitForEffect(expr->target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1826 | return; |
| 1827 | } |
| 1828 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1829 | // 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] | 1830 | // slot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1831 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1832 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1833 | Property* property = expr->target()->AsProperty(); |
| 1834 | if (property != NULL) { |
| 1835 | assign_type = (property->key()->IsPropertyName()) |
| 1836 | ? NAMED_PROPERTY |
| 1837 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | // Evaluate LHS expression. |
| 1841 | switch (assign_type) { |
| 1842 | case VARIABLE: |
| 1843 | // Nothing to do here. |
| 1844 | break; |
| 1845 | case NAMED_PROPERTY: |
| 1846 | if (expr->is_compound()) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1847 | // We need the receiver both on the stack and in edx. |
| 1848 | VisitForStackValue(property->obj()); |
| 1849 | __ mov(edx, Operand(esp, 0)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1850 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1851 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1852 | } |
| 1853 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1854 | case KEYED_PROPERTY: { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1855 | if (expr->is_compound()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1856 | VisitForStackValue(property->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1857 | VisitForStackValue(property->key()); |
| 1858 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 1859 | __ mov(ecx, Operand(esp, 0)); // Key. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1860 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1861 | VisitForStackValue(property->obj()); |
| 1862 | VisitForStackValue(property->key()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1863 | } |
| 1864 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1865 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1866 | } |
| 1867 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1868 | // For compound assignments we need another deoptimization point after the |
| 1869 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1870 | if (expr->is_compound()) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1871 | AccumulatorValueContext result_context(this); |
| 1872 | { AccumulatorValueContext left_operand_context(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1873 | switch (assign_type) { |
| 1874 | case VARIABLE: |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1875 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1876 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1877 | break; |
| 1878 | case NAMED_PROPERTY: |
| 1879 | EmitNamedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1880 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1881 | break; |
| 1882 | case KEYED_PROPERTY: |
| 1883 | EmitKeyedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1884 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1885 | break; |
| 1886 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1887 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1888 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1889 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1890 | __ push(eax); // Left operand goes on the stack. |
| 1891 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1892 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1893 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1894 | ? OVERWRITE_RIGHT |
| 1895 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1896 | SetSourcePosition(expr->position() + 1); |
| 1897 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1898 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1899 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1900 | mode, |
| 1901 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1902 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1903 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1904 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1905 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1906 | |
| 1907 | // Deoptimization point in case the binary operation may have side effects. |
| 1908 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1909 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1910 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | // Record source position before possible IC call. |
| 1914 | SetSourcePosition(expr->position()); |
| 1915 | |
| 1916 | // Store the value. |
| 1917 | switch (assign_type) { |
| 1918 | case VARIABLE: |
| 1919 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1920 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1921 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1922 | context()->Plug(eax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1923 | break; |
| 1924 | case NAMED_PROPERTY: |
| 1925 | EmitNamedPropertyAssignment(expr); |
| 1926 | break; |
| 1927 | case KEYED_PROPERTY: |
| 1928 | EmitKeyedPropertyAssignment(expr); |
| 1929 | break; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1934 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1935 | Comment cmnt(masm_, "[ Yield"); |
| 1936 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1937 | // this. It stays on the stack while we update the iterator. |
| 1938 | VisitForStackValue(expr->expression()); |
| 1939 | |
| 1940 | switch (expr->yield_kind()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1941 | case Yield::SUSPEND: |
| 1942 | // Pop value from top-of-stack slot; box result into result register. |
| 1943 | EmitCreateIteratorResult(false); |
| 1944 | __ push(result_register()); |
| 1945 | // Fall through. |
| 1946 | case Yield::INITIAL: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1947 | Label suspend, continuation, post_runtime, resume; |
| 1948 | |
| 1949 | __ jmp(&suspend); |
| 1950 | |
| 1951 | __ bind(&continuation); |
| 1952 | __ jmp(&resume); |
| 1953 | |
| 1954 | __ bind(&suspend); |
| 1955 | VisitForAccumulatorValue(expr->generator_object()); |
| 1956 | ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1957 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 1958 | Immediate(Smi::FromInt(continuation.pos()))); |
| 1959 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 1960 | __ mov(ecx, esi); |
| 1961 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 1962 | kDontSaveFPRegs); |
| 1963 | __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
| 1964 | __ cmp(esp, ebx); |
| 1965 | __ j(equal, &post_runtime); |
| 1966 | __ push(eax); // generator object |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1967 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 1968 | __ mov(context_register(), |
| 1969 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1970 | __ bind(&post_runtime); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1971 | __ pop(result_register()); |
| 1972 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1973 | |
| 1974 | __ bind(&resume); |
| 1975 | context()->Plug(result_register()); |
| 1976 | break; |
| 1977 | } |
| 1978 | |
| 1979 | case Yield::FINAL: { |
| 1980 | VisitForAccumulatorValue(expr->generator_object()); |
| 1981 | __ mov(FieldOperand(result_register(), |
| 1982 | JSGeneratorObject::kContinuationOffset), |
| 1983 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1984 | // Pop value from top-of-stack slot, box result into result register. |
| 1985 | EmitCreateIteratorResult(true); |
| 1986 | EmitUnwindBeforeReturn(); |
| 1987 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1988 | break; |
| 1989 | } |
| 1990 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1991 | case Yield::DELEGATING: { |
| 1992 | VisitForStackValue(expr->generator_object()); |
| 1993 | |
| 1994 | // Initial stack layout is as follows: |
| 1995 | // [sp + 1 * kPointerSize] iter |
| 1996 | // [sp + 0 * kPointerSize] g |
| 1997 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1998 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 1999 | Label l_next, l_call, l_loop; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2000 | // Initial send value is undefined. |
| 2001 | __ mov(eax, isolate()->factory()->undefined_value()); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2002 | __ jmp(&l_next); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2003 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2004 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2005 | __ bind(&l_catch); |
| 2006 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2007 | __ mov(ecx, isolate()->factory()->throw_string()); // "throw" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2008 | __ push(ecx); // "throw" |
| 2009 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2010 | __ push(eax); // exception |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2011 | __ jmp(&l_call); |
| 2012 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2013 | // try { received = %yield result } |
| 2014 | // Shuffle the received result above a try handler and yield it without |
| 2015 | // re-boxing. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2016 | __ bind(&l_try); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2017 | __ pop(eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2018 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 2019 | const int handler_size = StackHandlerConstants::kSize; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2020 | __ push(eax); // result |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2021 | __ jmp(&l_suspend); |
| 2022 | __ bind(&l_continuation); |
| 2023 | __ jmp(&l_resume); |
| 2024 | __ bind(&l_suspend); |
| 2025 | const int generator_object_depth = kPointerSize + handler_size; |
| 2026 | __ mov(eax, Operand(esp, generator_object_depth)); |
| 2027 | __ push(eax); // g |
| 2028 | ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2029 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 2030 | Immediate(Smi::FromInt(l_continuation.pos()))); |
| 2031 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 2032 | __ mov(ecx, esi); |
| 2033 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 2034 | kDontSaveFPRegs); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2035 | __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
| 2036 | __ mov(context_register(), |
| 2037 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2038 | __ pop(eax); // result |
| 2039 | EmitReturnSequence(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2040 | __ bind(&l_resume); // received in eax |
| 2041 | __ PopTryHandler(); |
| 2042 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2043 | // receiver = iter; f = iter.next; arg = received; |
| 2044 | __ bind(&l_next); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2045 | __ mov(ecx, isolate()->factory()->next_string()); // "next" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2046 | __ push(ecx); |
| 2047 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2048 | __ push(eax); // received |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2049 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2050 | // result = receiver[f](arg); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2051 | __ bind(&l_call); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2052 | __ mov(edx, Operand(esp, kPointerSize)); |
| 2053 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2054 | CallIC(ic, TypeFeedbackId::None()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2055 | __ mov(edi, eax); |
| 2056 | __ mov(Operand(esp, 2 * kPointerSize), edi); |
| 2057 | CallFunctionStub stub(1, CALL_AS_METHOD); |
| 2058 | __ CallStub(&stub); |
| 2059 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2060 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2061 | __ Drop(1); // The function is still on the stack; drop it. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2062 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2063 | // if (!result.done) goto l_try; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2064 | __ bind(&l_loop); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2065 | __ push(eax); // save result |
| 2066 | __ mov(edx, eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2067 | __ mov(ecx, isolate()->factory()->done_string()); // "done" |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2068 | CallLoadIC(NOT_CONTEXTUAL); // result.done in eax |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2069 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2070 | CallIC(bool_ic); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2071 | __ test(eax, eax); |
| 2072 | __ j(zero, &l_try); |
| 2073 | |
| 2074 | // result.value |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2075 | __ pop(edx); // result |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2076 | __ mov(ecx, isolate()->factory()->value_string()); // "value" |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2077 | CallLoadIC(NOT_CONTEXTUAL); // result.value in eax |
| 2078 | context()->DropAndPlug(2, eax); // drop iter and g |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2079 | break; |
| 2080 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
| 2084 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2085 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2086 | Expression *value, |
| 2087 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2088 | // The value stays in eax, and is ultimately read by the resumed generator, as |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2089 | // if the CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it |
| 2090 | // is read to throw the value when the resumed generator is already closed. |
| 2091 | // ebx will hold the generator object until the activation has been resumed. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2092 | VisitForStackValue(generator); |
| 2093 | VisitForAccumulatorValue(value); |
| 2094 | __ pop(ebx); |
| 2095 | |
| 2096 | // Check generator state. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2097 | Label wrong_state, closed_state, done; |
| 2098 | STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); |
| 2099 | STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2100 | __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2101 | Immediate(Smi::FromInt(0))); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2102 | __ j(equal, &closed_state); |
| 2103 | __ j(less, &wrong_state); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2104 | |
| 2105 | // Load suspended function and context. |
| 2106 | __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 2107 | __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 2108 | |
| 2109 | // Push receiver. |
| 2110 | __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
| 2111 | |
| 2112 | // Push holes for arguments to generator function. |
| 2113 | __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2114 | __ mov(edx, |
| 2115 | FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 2116 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 2117 | Label push_argument_holes, push_frame; |
| 2118 | __ bind(&push_argument_holes); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2119 | __ sub(edx, Immediate(Smi::FromInt(1))); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2120 | __ j(carry, &push_frame); |
| 2121 | __ push(ecx); |
| 2122 | __ jmp(&push_argument_holes); |
| 2123 | |
| 2124 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2125 | // the generator was suspended. |
| 2126 | Label resume_frame; |
| 2127 | __ bind(&push_frame); |
| 2128 | __ call(&resume_frame); |
| 2129 | __ jmp(&done); |
| 2130 | __ bind(&resume_frame); |
| 2131 | __ push(ebp); // Caller's frame pointer. |
| 2132 | __ mov(ebp, esp); |
| 2133 | __ push(esi); // Callee's context. |
| 2134 | __ push(edi); // Callee's JS Function. |
| 2135 | |
| 2136 | // Load the operand stack size. |
| 2137 | __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 2138 | __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 2139 | __ SmiUntag(edx); |
| 2140 | |
| 2141 | // If we are sending a value and there is no operand stack, we can jump back |
| 2142 | // in directly. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2143 | if (resume_mode == JSGeneratorObject::NEXT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2144 | Label slow_resume; |
| 2145 | __ cmp(edx, Immediate(0)); |
| 2146 | __ j(not_zero, &slow_resume); |
| 2147 | __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2148 | __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 2149 | __ SmiUntag(ecx); |
| 2150 | __ add(edx, ecx); |
| 2151 | __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2152 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2153 | __ jmp(edx); |
| 2154 | __ bind(&slow_resume); |
| 2155 | } |
| 2156 | |
| 2157 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2158 | // up the stack and the handlers. |
| 2159 | Label push_operand_holes, call_resume; |
| 2160 | __ bind(&push_operand_holes); |
| 2161 | __ sub(edx, Immediate(1)); |
| 2162 | __ j(carry, &call_resume); |
| 2163 | __ push(ecx); |
| 2164 | __ jmp(&push_operand_holes); |
| 2165 | __ bind(&call_resume); |
| 2166 | __ push(ebx); |
| 2167 | __ push(result_register()); |
| 2168 | __ Push(Smi::FromInt(resume_mode)); |
| 2169 | __ CallRuntime(Runtime::kResumeJSGeneratorObject, 3); |
| 2170 | // Not reached: the runtime call returns elsewhere. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2171 | __ Abort(kGeneratorFailedToResume); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2172 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2173 | // Reach here when generator is closed. |
| 2174 | __ bind(&closed_state); |
| 2175 | if (resume_mode == JSGeneratorObject::NEXT) { |
| 2176 | // Return completed iterator result when generator is closed. |
| 2177 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 2178 | // Pop value from top-of-stack slot; box result into result register. |
| 2179 | EmitCreateIteratorResult(true); |
| 2180 | } else { |
| 2181 | // Throw the provided value. |
| 2182 | __ push(eax); |
| 2183 | __ CallRuntime(Runtime::kThrow, 1); |
| 2184 | } |
| 2185 | __ jmp(&done); |
| 2186 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2187 | // Throw error if we attempt to operate on a running generator. |
| 2188 | __ bind(&wrong_state); |
| 2189 | __ push(ebx); |
| 2190 | __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
| 2191 | |
| 2192 | __ bind(&done); |
| 2193 | context()->Plug(result_register()); |
| 2194 | } |
| 2195 | |
| 2196 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2197 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2198 | Label gc_required; |
| 2199 | Label allocated; |
| 2200 | |
| 2201 | Handle<Map> map(isolate()->native_context()->generator_result_map()); |
| 2202 | |
| 2203 | __ Allocate(map->instance_size(), eax, ecx, edx, &gc_required, TAG_OBJECT); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2204 | __ jmp(&allocated); |
| 2205 | |
| 2206 | __ bind(&gc_required); |
| 2207 | __ Push(Smi::FromInt(map->instance_size())); |
| 2208 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2209 | __ mov(context_register(), |
| 2210 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2211 | |
| 2212 | __ bind(&allocated); |
| 2213 | __ mov(ebx, map); |
| 2214 | __ pop(ecx); |
| 2215 | __ mov(edx, isolate()->factory()->ToBoolean(done)); |
| 2216 | ASSERT_EQ(map->instance_size(), 5 * kPointerSize); |
| 2217 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2218 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2219 | isolate()->factory()->empty_fixed_array()); |
| 2220 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2221 | isolate()->factory()->empty_fixed_array()); |
| 2222 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2223 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2224 | |
| 2225 | // Only the value field needs a write barrier, as the other values are in the |
| 2226 | // root set. |
| 2227 | __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2228 | ecx, edx, kDontSaveFPRegs); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
| 2231 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2232 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 2233 | SetSourcePosition(prop->position()); |
| 2234 | Literal* key = prop->key()->AsLiteral(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2235 | ASSERT(!key->value()->IsSmi()); |
| 2236 | __ mov(ecx, Immediate(key->value())); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2237 | CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | |
| 2241 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 2242 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2243 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2244 | CallIC(ic, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2245 | } |
| 2246 | |
| 2247 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2248 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2249 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2250 | OverwriteMode mode, |
| 2251 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2252 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2253 | // Do combined smi check of the operands. Left operand is on the |
| 2254 | // stack. Right operand is in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2255 | Label smi_case, done, stub_call; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2256 | __ pop(edx); |
| 2257 | __ mov(ecx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2258 | __ or_(eax, edx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2259 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2260 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2261 | |
| 2262 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2263 | __ mov(eax, ecx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2264 | BinaryOpICStub stub(op, mode); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2265 | CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2266 | patch_site.EmitPatchInfo(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2267 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2268 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2269 | // Smi case. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2270 | __ bind(&smi_case); |
| 2271 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 2272 | |
| 2273 | switch (op) { |
| 2274 | case Token::SAR: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2275 | __ SmiUntag(ecx); |
| 2276 | __ sar_cl(eax); // No checks of result necessary |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 2277 | __ and_(eax, Immediate(~kSmiTagMask)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2278 | break; |
| 2279 | case Token::SHL: { |
| 2280 | Label result_ok; |
| 2281 | __ SmiUntag(eax); |
| 2282 | __ SmiUntag(ecx); |
| 2283 | __ shl_cl(eax); |
| 2284 | // Check that the *signed* result fits in a smi. |
| 2285 | __ cmp(eax, 0xc0000000); |
| 2286 | __ j(positive, &result_ok); |
| 2287 | __ SmiTag(ecx); |
| 2288 | __ jmp(&stub_call); |
| 2289 | __ bind(&result_ok); |
| 2290 | __ SmiTag(eax); |
| 2291 | break; |
| 2292 | } |
| 2293 | case Token::SHR: { |
| 2294 | Label result_ok; |
| 2295 | __ SmiUntag(eax); |
| 2296 | __ SmiUntag(ecx); |
| 2297 | __ shr_cl(eax); |
| 2298 | __ test(eax, Immediate(0xc0000000)); |
| 2299 | __ j(zero, &result_ok); |
| 2300 | __ SmiTag(ecx); |
| 2301 | __ jmp(&stub_call); |
| 2302 | __ bind(&result_ok); |
| 2303 | __ SmiTag(eax); |
| 2304 | break; |
| 2305 | } |
| 2306 | case Token::ADD: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2307 | __ add(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2308 | __ j(overflow, &stub_call); |
| 2309 | break; |
| 2310 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2311 | __ sub(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2312 | __ j(overflow, &stub_call); |
| 2313 | break; |
| 2314 | case Token::MUL: { |
| 2315 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2316 | __ imul(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2317 | __ j(overflow, &stub_call); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2318 | __ test(eax, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2319 | __ j(not_zero, &done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2320 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2321 | __ or_(ebx, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2322 | __ j(negative, &stub_call); |
| 2323 | break; |
| 2324 | } |
| 2325 | case Token::BIT_OR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2326 | __ or_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2327 | break; |
| 2328 | case Token::BIT_AND: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2329 | __ and_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2330 | break; |
| 2331 | case Token::BIT_XOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2332 | __ xor_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2333 | break; |
| 2334 | default: |
| 2335 | UNREACHABLE(); |
| 2336 | } |
| 2337 | |
| 2338 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2339 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2340 | } |
| 2341 | |
| 2342 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2343 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2344 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2345 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2346 | __ pop(edx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2347 | BinaryOpICStub stub(op, mode); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2348 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2349 | CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2350 | patch_site.EmitPatchInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2351 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2355 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2356 | // 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] | 2357 | // ReferenceError' on the left-hand side. |
| 2358 | if (!expr->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2359 | VisitForEffect(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2360 | return; |
| 2361 | } |
| 2362 | |
| 2363 | // 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] | 2364 | // slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2365 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2366 | LhsKind assign_type = VARIABLE; |
| 2367 | Property* prop = expr->AsProperty(); |
| 2368 | if (prop != NULL) { |
| 2369 | assign_type = (prop->key()->IsPropertyName()) |
| 2370 | ? NAMED_PROPERTY |
| 2371 | : KEYED_PROPERTY; |
| 2372 | } |
| 2373 | |
| 2374 | switch (assign_type) { |
| 2375 | case VARIABLE: { |
| 2376 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2377 | EffectContext context(this); |
| 2378 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | } |
| 2381 | case NAMED_PROPERTY: { |
| 2382 | __ push(eax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2383 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2384 | __ mov(edx, eax); |
| 2385 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2386 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2387 | CallStoreIC(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2388 | break; |
| 2389 | } |
| 2390 | case KEYED_PROPERTY: { |
| 2391 | __ push(eax); // Preserve value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2392 | VisitForStackValue(prop->obj()); |
| 2393 | VisitForAccumulatorValue(prop->key()); |
| 2394 | __ mov(ecx, eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2395 | __ pop(edx); // Receiver. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2396 | __ pop(eax); // Restore value. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2397 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2398 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2399 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2400 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2401 | break; |
| 2402 | } |
| 2403 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2404 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
| 2407 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2408 | void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
| 2409 | Variable* var, MemOperand location) { |
| 2410 | __ mov(location, eax); |
| 2411 | if (var->IsContextSlot()) { |
| 2412 | __ mov(edx, eax); |
| 2413 | int offset = Context::SlotOffset(var->index()); |
| 2414 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
| 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | |
| 2419 | void FullCodeGenerator::EmitCallStoreContextSlot( |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2420 | Handle<String> name, StrictMode strict_mode) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2421 | __ push(eax); // Value. |
| 2422 | __ push(esi); // Context. |
| 2423 | __ push(Immediate(name)); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2424 | __ push(Immediate(Smi::FromInt(strict_mode))); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2425 | __ CallRuntime(Runtime::kStoreContextSlot, 4); |
| 2426 | } |
| 2427 | |
| 2428 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2429 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2430 | Token::Value op) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2431 | if (var->IsUnallocated()) { |
| 2432 | // Global var, const, or let. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2433 | __ mov(ecx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2434 | __ mov(edx, GlobalObjectOperand()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2435 | CallStoreIC(); |
| 2436 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2437 | } else if (op == Token::INIT_CONST_LEGACY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2438 | // Const initializers need a write barrier. |
| 2439 | ASSERT(!var->IsParameter()); // No const parameters. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2440 | if (var->IsLookupSlot()) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2441 | __ push(eax); |
| 2442 | __ push(esi); |
| 2443 | __ push(Immediate(var->name())); |
| 2444 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2445 | } else { |
| 2446 | ASSERT(var->IsStackLocal() || var->IsContextSlot()); |
| 2447 | Label skip; |
| 2448 | MemOperand location = VarOperand(var, ecx); |
| 2449 | __ mov(edx, location); |
| 2450 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2451 | __ j(not_equal, &skip, Label::kNear); |
| 2452 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2453 | __ bind(&skip); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2454 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2455 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2456 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2457 | // Non-initializing assignment to let variable needs a write barrier. |
| 2458 | if (var->IsLookupSlot()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2459 | EmitCallStoreContextSlot(var->name(), strict_mode()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2460 | } else { |
| 2461 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 2462 | Label assign; |
| 2463 | MemOperand location = VarOperand(var, ecx); |
| 2464 | __ mov(edx, location); |
| 2465 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2466 | __ j(not_equal, &assign, Label::kNear); |
| 2467 | __ push(Immediate(var->name())); |
| 2468 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 2469 | __ bind(&assign); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2470 | EmitStoreToStackLocalOrContextSlot(var, location); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2471 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2472 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2473 | } else if (!var->is_const_mode() || op == Token::INIT_CONST) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2474 | // Assignment to var or initializing assignment to let/const |
| 2475 | // in harmony mode. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2476 | if (var->IsLookupSlot()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2477 | EmitCallStoreContextSlot(var->name(), strict_mode()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2478 | } else { |
| 2479 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2480 | MemOperand location = VarOperand(var, ecx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2481 | if (generate_debug_code_ && op == Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2482 | // Check for an uninitialized let binding. |
| 2483 | __ mov(edx, location); |
| 2484 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2485 | __ Check(equal, kLetBindingReInitialization); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2486 | } |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2487 | EmitStoreToStackLocalOrContextSlot(var, location); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2488 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2489 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2490 | // Non-initializing assignments to consts are ignored. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | |
| 2494 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2495 | // Assignment to a property, using a named store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2496 | // eax : value |
| 2497 | // esp[0] : receiver |
| 2498 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2499 | Property* prop = expr->target()->AsProperty(); |
| 2500 | ASSERT(prop != NULL); |
| 2501 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2502 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2503 | // Record source code position before IC call. |
| 2504 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2505 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2506 | __ pop(edx); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2507 | CallStoreIC(expr->AssignmentFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2508 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2509 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2510 | } |
| 2511 | |
| 2512 | |
| 2513 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2514 | // Assignment to a property, using a keyed store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2515 | // eax : value |
| 2516 | // esp[0] : key |
| 2517 | // esp[kPointerSize] : receiver |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2518 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2519 | __ pop(ecx); // Key. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2520 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2521 | // Record source code position before IC call. |
| 2522 | SetSourcePosition(expr->position()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2523 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2524 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2525 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2526 | CallIC(ic, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2527 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2528 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2529 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2534 | Comment cmnt(masm_, "[ Property"); |
| 2535 | Expression* key = expr->key(); |
| 2536 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2537 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2538 | VisitForAccumulatorValue(expr->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2539 | __ mov(edx, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2540 | EmitNamedPropertyLoad(expr); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2541 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2542 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2543 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2544 | VisitForStackValue(expr->obj()); |
| 2545 | VisitForAccumulatorValue(expr->key()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2546 | __ pop(edx); // Object. |
| 2547 | __ mov(ecx, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2548 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2549 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2554 | void FullCodeGenerator::CallIC(Handle<Code> code, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2555 | TypeFeedbackId ast_id) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2556 | ic_total_count_++; |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2557 | __ call(code, RelocInfo::CODE_TARGET, ast_id); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | |
| 2561 | |
| 2562 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2563 | // Code common for calls using the IC. |
| 2564 | void FullCodeGenerator::EmitCallWithIC(Call* expr) { |
| 2565 | Expression* callee = expr->expression(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2566 | ZoneList<Expression*>* args = expr->arguments(); |
| 2567 | int arg_count = args->length(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2568 | |
| 2569 | CallFunctionFlags flags; |
| 2570 | // Get the target function. |
| 2571 | if (callee->IsVariableProxy()) { |
| 2572 | { StackValueContext context(this); |
| 2573 | EmitVariableLoad(callee->AsVariableProxy()); |
| 2574 | PrepareForBailout(callee, NO_REGISTERS); |
| 2575 | } |
| 2576 | // Push undefined as receiver. This is patched in the method prologue if it |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2577 | // is a sloppy mode method. |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2578 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 2579 | flags = NO_CALL_FUNCTION_FLAGS; |
| 2580 | } else { |
| 2581 | // Load the function from the receiver. |
| 2582 | ASSERT(callee->IsProperty()); |
| 2583 | __ mov(edx, Operand(esp, 0)); |
| 2584 | EmitNamedPropertyLoad(callee->AsProperty()); |
| 2585 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2586 | // Push the target function under the receiver. |
| 2587 | __ push(Operand(esp, 0)); |
| 2588 | __ mov(Operand(esp, kPointerSize), eax); |
| 2589 | flags = CALL_AS_METHOD; |
| 2590 | } |
| 2591 | |
| 2592 | // Load the arguments. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2593 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2594 | for (int i = 0; i < arg_count; i++) { |
| 2595 | VisitForStackValue(args->at(i)); |
| 2596 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2597 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2598 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2599 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2600 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2601 | CallFunctionStub stub(arg_count, flags); |
| 2602 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 2603 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2604 | RecordJSReturnSite(expr); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2605 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2606 | // Restore context register. |
| 2607 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2608 | |
| 2609 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
| 2612 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2613 | // Code common for calls using the IC. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2614 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2615 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2616 | // Load the key. |
| 2617 | VisitForAccumulatorValue(key); |
| 2618 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2619 | Expression* callee = expr->expression(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2620 | ZoneList<Expression*>* args = expr->arguments(); |
| 2621 | int arg_count = args->length(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2622 | |
| 2623 | // Load the function from the receiver. |
| 2624 | ASSERT(callee->IsProperty()); |
| 2625 | __ mov(edx, Operand(esp, 0)); |
| 2626 | // Move the key into the right register for the keyed load IC. |
| 2627 | __ mov(ecx, eax); |
| 2628 | EmitKeyedPropertyLoad(callee->AsProperty()); |
| 2629 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2630 | |
| 2631 | // Push the target function under the receiver. |
| 2632 | __ push(Operand(esp, 0)); |
| 2633 | __ mov(Operand(esp, kPointerSize), eax); |
| 2634 | |
| 2635 | // Load the arguments. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2636 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2637 | for (int i = 0; i < arg_count; i++) { |
| 2638 | VisitForStackValue(args->at(i)); |
| 2639 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2640 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2641 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2642 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2643 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2644 | CallFunctionStub stub(arg_count, CALL_AS_METHOD); |
| 2645 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 2646 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2647 | RecordJSReturnSite(expr); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2648 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2649 | // Restore context register. |
| 2650 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2651 | |
| 2652 | context()->DropAndPlug(1, eax); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2656 | void FullCodeGenerator::EmitCallWithStub(Call* expr) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2657 | // Code common for calls using the call stub. |
| 2658 | ZoneList<Expression*>* args = expr->arguments(); |
| 2659 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2660 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2661 | for (int i = 0; i < arg_count; i++) { |
| 2662 | VisitForStackValue(args->at(i)); |
| 2663 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2664 | } |
| 2665 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2666 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2667 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame^] | 2668 | Handle<Object> uninitialized = |
| 2669 | TypeFeedbackInfo::UninitializedSentinel(isolate()); |
| 2670 | StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2671 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 2672 | __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2673 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2674 | // Record call targets in unoptimized code. |
| 2675 | CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2676 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2677 | __ CallStub(&stub); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2678 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2679 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2680 | // Restore context register. |
| 2681 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2682 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2686 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2687 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2688 | if (arg_count > 0) { |
| 2689 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2690 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2691 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | // Push the receiver of the enclosing function. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2695 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2696 | // Push the language mode. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2697 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2698 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2699 | // Push the start position of the scope the calls resides in. |
| 2700 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
| 2701 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2702 | // Do the runtime call. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2703 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2707 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2708 | #ifdef DEBUG |
| 2709 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2710 | // through this function. Avoid early returns. |
| 2711 | expr->return_is_recorded_ = false; |
| 2712 | #endif |
| 2713 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2714 | Comment cmnt(masm_, "[ Call"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2715 | Expression* callee = expr->expression(); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2716 | Call::CallType call_type = expr->GetCallType(isolate()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2717 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2718 | if (call_type == Call::POSSIBLY_EVAL_CALL) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2719 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2720 | // resolve the function we need to call and the receiver of the call. |
| 2721 | // Then we call the resolved function using the given arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2722 | ZoneList<Expression*>* args = expr->arguments(); |
| 2723 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2724 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2725 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2726 | // Reserved receiver slot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2727 | __ push(Immediate(isolate()->factory()->undefined_value())); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2728 | // Push the arguments. |
| 2729 | for (int i = 0; i < arg_count; i++) { |
| 2730 | VisitForStackValue(args->at(i)); |
| 2731 | } |
| 2732 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2733 | // Push a copy of the function (found below the arguments) and |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2734 | // resolve eval. |
| 2735 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2736 | EmitResolvePossiblyDirectEval(arg_count); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2737 | |
| 2738 | // The runtime call returns a pair of values in eax (function) and |
| 2739 | // edx (receiver). Touch up the stack with the right values. |
| 2740 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2741 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2742 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2743 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2744 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2745 | CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2746 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2747 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2748 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2749 | // Restore context register. |
| 2750 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2751 | context()->DropAndPlug(1, eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2752 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2753 | } else if (call_type == Call::GLOBAL_CALL) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2754 | EmitCallWithIC(expr); |
| 2755 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2756 | } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2757 | // Call to a lookup slot (dynamically introduced variable). |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2758 | VariableProxy* proxy = callee->AsVariableProxy(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2759 | Label slow, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2760 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2761 | // Generate code for loading from variables potentially shadowed by |
| 2762 | // eval-introduced variables. |
| 2763 | EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2764 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2765 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2766 | // Call the runtime to find the function to call (returned in eax) and |
| 2767 | // the object holding it (returned in edx). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2768 | __ push(context_register()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2769 | __ push(Immediate(proxy->name())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2770 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2771 | __ push(eax); // Function. |
| 2772 | __ push(edx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2773 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2774 | // If fast case code has been generated, emit code to push the function |
| 2775 | // and receiver and have the slow path jump around this code. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2776 | if (done.is_linked()) { |
| 2777 | Label call; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2778 | __ jmp(&call, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2779 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2780 | // Push function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2781 | __ push(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2782 | // The receiver is implicitly the global receiver. Indicate this by |
| 2783 | // passing the hole to the call function stub. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2784 | __ push(Immediate(isolate()->factory()->undefined_value())); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2785 | __ bind(&call); |
| 2786 | } |
| 2787 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2788 | // The receiver is either the global receiver or an object found by |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2789 | // LoadContextSlot. |
| 2790 | EmitCallWithStub(expr); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2791 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2792 | } else if (call_type == Call::PROPERTY_CALL) { |
| 2793 | Property* property = callee->AsProperty(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2794 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2795 | VisitForStackValue(property->obj()); |
| 2796 | } |
| 2797 | if (property->key()->IsPropertyName()) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2798 | EmitCallWithIC(expr); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2799 | } else { |
| 2800 | EmitKeyedCallWithIC(expr, property->key()); |
| 2801 | } |
| 2802 | |
| 2803 | } else { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2804 | ASSERT(call_type == Call::OTHER_CALL); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2805 | // Call to an arbitrary expression not handled specially above. |
| 2806 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2807 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2808 | } |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2809 | __ push(Immediate(isolate()->factory()->undefined_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2810 | // Emit function call. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2811 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2812 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2813 | |
| 2814 | #ifdef DEBUG |
| 2815 | // RecordJSReturnSite should have been called. |
| 2816 | ASSERT(expr->return_is_recorded_); |
| 2817 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | |
| 2821 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2822 | Comment cmnt(masm_, "[ CallNew"); |
| 2823 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2824 | // expression in new calls must be evaluated before the |
| 2825 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2826 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2827 | // Push constructor on the stack. If it's not a function it's used as |
| 2828 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2829 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2830 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2831 | |
| 2832 | // Push the arguments ("left-to-right") on the stack. |
| 2833 | ZoneList<Expression*>* args = expr->arguments(); |
| 2834 | int arg_count = args->length(); |
| 2835 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2836 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | // Call the construct call builtin that handles allocation and |
| 2840 | // constructor invocation. |
| 2841 | SetSourcePosition(expr->position()); |
| 2842 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2843 | // Load function and argument count into edi and eax. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 2844 | __ Set(eax, Immediate(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2845 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2846 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2847 | // Record call targets in unoptimized code. |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame^] | 2848 | Handle<Object> uninitialized = |
| 2849 | TypeFeedbackInfo::UninitializedSentinel(isolate()); |
| 2850 | StoreFeedbackVectorSlot(expr->CallNewFeedbackSlot(), uninitialized); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2851 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 2852 | __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2853 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2854 | CallConstructStub stub(RECORD_CALL_TARGET); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2855 | __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2856 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2857 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2858 | } |
| 2859 | |
| 2860 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2861 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2862 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2863 | ASSERT(args->length() == 1); |
| 2864 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2865 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2866 | |
| 2867 | Label materialize_true, materialize_false; |
| 2868 | Label* if_true = NULL; |
| 2869 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2871 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2872 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2873 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2874 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2875 | __ test(eax, Immediate(kSmiTagMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2876 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2877 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2878 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2879 | } |
| 2880 | |
| 2881 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2882 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2883 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2884 | ASSERT(args->length() == 1); |
| 2885 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2886 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2887 | |
| 2888 | Label materialize_true, materialize_false; |
| 2889 | Label* if_true = NULL; |
| 2890 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2891 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2892 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2893 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2894 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2895 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2896 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2897 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2898 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2899 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2903 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2904 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2905 | ASSERT(args->length() == 1); |
| 2906 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2907 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2908 | |
| 2909 | Label materialize_true, materialize_false; |
| 2910 | Label* if_true = NULL; |
| 2911 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2912 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2913 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2914 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2915 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2916 | __ JumpIfSmi(eax, if_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2917 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2918 | __ j(equal, if_true); |
| 2919 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2920 | // Undetectable objects behave like undefined when tested with typeof. |
| 2921 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2922 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 2923 | __ j(not_zero, if_false); |
| 2924 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2925 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2926 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2927 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2928 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2929 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2930 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2931 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2935 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2936 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2937 | ASSERT(args->length() == 1); |
| 2938 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2939 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2940 | |
| 2941 | Label materialize_true, materialize_false; |
| 2942 | Label* if_true = NULL; |
| 2943 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2944 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2945 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2946 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2947 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2948 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2949 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2950 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2951 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2952 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2953 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2957 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2958 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2959 | ASSERT(args->length() == 1); |
| 2960 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2961 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2962 | |
| 2963 | Label materialize_true, materialize_false; |
| 2964 | Label* if_true = NULL; |
| 2965 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2966 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2967 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2968 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2969 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2970 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2971 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2972 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2973 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2974 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2975 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2976 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2977 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2981 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2982 | CallRuntime* expr) { |
| 2983 | ZoneList<Expression*>* args = expr->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2984 | ASSERT(args->length() == 1); |
| 2985 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2986 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2987 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 2988 | Label materialize_true, materialize_false, skip_lookup; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2989 | Label* if_true = NULL; |
| 2990 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2991 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2992 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2993 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2994 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2995 | __ AssertNotSmi(eax); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2996 | |
| 2997 | // Check whether this map has already been checked to be safe for default |
| 2998 | // valueOf. |
| 2999 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3000 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 3001 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3002 | __ j(not_zero, &skip_lookup); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3003 | |
| 3004 | // Check for fast case object. Return false for slow case objects. |
| 3005 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 3006 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3007 | __ cmp(ecx, isolate()->factory()->hash_table_map()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3008 | __ j(equal, if_false); |
| 3009 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3010 | // 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] | 3011 | // found. Since we omit an enumeration index check, if it is added via a |
| 3012 | // transition that shares its descriptor array, this is a false positive. |
| 3013 | Label entry, loop, done; |
| 3014 | |
| 3015 | // Skip loop if no descriptors are valid. |
| 3016 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 3017 | __ cmp(ecx, 0); |
| 3018 | __ j(equal, &done); |
| 3019 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3020 | __ LoadInstanceDescriptors(ebx, ebx); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3021 | // ebx: descriptor array. |
| 3022 | // ecx: valid entries in the descriptor array. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3023 | // Calculate the end of the descriptor array. |
| 3024 | STATIC_ASSERT(kSmiTag == 0); |
| 3025 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3026 | STATIC_ASSERT(kPointerSize == 4); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3027 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 3028 | __ lea(ecx, Operand(ebx, ecx, times_2, DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3029 | // Calculate location of the first key name. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3030 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3031 | // 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] | 3032 | // internalized string "valueOf" the result is false. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3033 | __ jmp(&entry); |
| 3034 | __ bind(&loop); |
| 3035 | __ mov(edx, FieldOperand(ebx, 0)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3036 | __ cmp(edx, isolate()->factory()->value_of_string()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3037 | __ j(equal, if_false); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3038 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3039 | __ bind(&entry); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3040 | __ cmp(ebx, ecx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3041 | __ j(not_equal, &loop); |
| 3042 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3043 | __ bind(&done); |
| 3044 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3045 | // Reload map as register ebx was used as temporary above. |
| 3046 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3047 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3048 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3049 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 3050 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 3051 | |
| 3052 | __ bind(&skip_lookup); |
| 3053 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3054 | // 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] | 3055 | // prototype is the un-modified String prototype. If not result is false. |
| 3056 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3057 | __ JumpIfSmi(ecx, if_false); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3058 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3059 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3060 | __ mov(edx, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3061 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3062 | __ cmp(ecx, |
| 3063 | ContextOperand(edx, |
| 3064 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3065 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3066 | Split(equal, if_true, if_false, fall_through); |
| 3067 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3068 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3072 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3073 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3074 | ASSERT(args->length() == 1); |
| 3075 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3076 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3077 | |
| 3078 | Label materialize_true, materialize_false; |
| 3079 | Label* if_true = NULL; |
| 3080 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3081 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3082 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3083 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3084 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3085 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3086 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3087 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3088 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3089 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3090 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3094 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3095 | ZoneList<Expression*>* args = expr->arguments(); |
| 3096 | ASSERT(args->length() == 1); |
| 3097 | |
| 3098 | VisitForAccumulatorValue(args->at(0)); |
| 3099 | |
| 3100 | Label materialize_true, materialize_false; |
| 3101 | Label* if_true = NULL; |
| 3102 | Label* if_false = NULL; |
| 3103 | Label* fall_through = NULL; |
| 3104 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3105 | &if_true, &if_false, &fall_through); |
| 3106 | |
| 3107 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 3108 | __ CheckMap(eax, map, if_false, DO_SMI_CHECK); |
| 3109 | __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x80000000)); |
| 3110 | __ j(not_equal, if_false); |
| 3111 | __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x00000000)); |
| 3112 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3113 | Split(equal, if_true, if_false, fall_through); |
| 3114 | |
| 3115 | context()->Plug(if_true, if_false); |
| 3116 | } |
| 3117 | |
| 3118 | |
| 3119 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3120 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3121 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3122 | ASSERT(args->length() == 1); |
| 3123 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3124 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3125 | |
| 3126 | Label materialize_true, materialize_false; |
| 3127 | Label* if_true = NULL; |
| 3128 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3129 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3130 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3131 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3132 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3133 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3134 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3135 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3136 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3137 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3138 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3142 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3143 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3144 | ASSERT(args->length() == 1); |
| 3145 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3146 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3147 | |
| 3148 | Label materialize_true, materialize_false; |
| 3149 | Label* if_true = NULL; |
| 3150 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3151 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3152 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3153 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3154 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3155 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3156 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3157 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3158 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3159 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3160 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3161 | } |
| 3162 | |
| 3163 | |
| 3164 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3165 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 3166 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3167 | |
| 3168 | Label materialize_true, materialize_false; |
| 3169 | Label* if_true = NULL; |
| 3170 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3171 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3172 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3173 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3174 | |
| 3175 | // Get the frame pointer for the calling frame. |
| 3176 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3177 | |
| 3178 | // Skip the arguments adaptor frame if it exists. |
| 3179 | Label check_frame_marker; |
| 3180 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 3181 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3182 | __ j(not_equal, &check_frame_marker); |
| 3183 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 3184 | |
| 3185 | // Check the marker in the calling frame. |
| 3186 | __ bind(&check_frame_marker); |
| 3187 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 3188 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3189 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3190 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3191 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3192 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3193 | } |
| 3194 | |
| 3195 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3196 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3197 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3198 | ASSERT(args->length() == 2); |
| 3199 | |
| 3200 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3201 | VisitForStackValue(args->at(0)); |
| 3202 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3203 | |
| 3204 | Label materialize_true, materialize_false; |
| 3205 | Label* if_true = NULL; |
| 3206 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3207 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3208 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3209 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3210 | |
| 3211 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3212 | __ cmp(eax, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3213 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3214 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3215 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3216 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3220 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3221 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3222 | ASSERT(args->length() == 1); |
| 3223 | |
| 3224 | // ArgumentsAccessStub expects the key in edx and the formal |
| 3225 | // parameter count in eax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3226 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3227 | __ mov(edx, eax); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3228 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3229 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 3230 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3231 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3235 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 3236 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3237 | |
| 3238 | Label exit; |
| 3239 | // Get the number of formal parameters. |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3240 | __ Set(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3241 | |
| 3242 | // Check if the calling frame is an arguments adaptor frame. |
| 3243 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3244 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 3245 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3246 | __ j(not_equal, &exit); |
| 3247 | |
| 3248 | // Arguments adaptor case: Read the arguments length from the |
| 3249 | // adaptor frame. |
| 3250 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3251 | |
| 3252 | __ bind(&exit); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3253 | __ AssertSmi(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3254 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3258 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3259 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3260 | ASSERT(args->length() == 1); |
| 3261 | Label done, null, function, non_function_constructor; |
| 3262 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3263 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3264 | |
| 3265 | // If the object is a smi, we return null. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3266 | __ JumpIfSmi(eax, &null); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3267 | |
| 3268 | // Check that the object is a JS object but take special care of JS |
| 3269 | // functions to make sure they have 'Function' as their class. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3270 | // Assume that there are only two callable types, and one of them is at |
| 3271 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3272 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3273 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 3274 | // Map is now in eax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3275 | __ j(below, &null); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3276 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3277 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3278 | __ j(equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3279 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3280 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 3281 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3282 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3283 | __ j(equal, &function); |
| 3284 | // Assume that there is no larger type. |
| 3285 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3286 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3287 | // 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] | 3288 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 3289 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3290 | __ j(not_equal, &non_function_constructor); |
| 3291 | |
| 3292 | // eax now contains the constructor function. Grab the |
| 3293 | // instance class name from there. |
| 3294 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3295 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3296 | __ jmp(&done); |
| 3297 | |
| 3298 | // Functions have class 'Function'. |
| 3299 | __ bind(&function); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3300 | __ mov(eax, isolate()->factory()->function_class_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3301 | __ jmp(&done); |
| 3302 | |
| 3303 | // Objects with a non-function constructor have class 'Object'. |
| 3304 | __ bind(&non_function_constructor); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3305 | __ mov(eax, isolate()->factory()->Object_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3306 | __ jmp(&done); |
| 3307 | |
| 3308 | // Non-JS objects have class null. |
| 3309 | __ bind(&null); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3310 | __ mov(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3311 | |
| 3312 | // All done. |
| 3313 | __ bind(&done); |
| 3314 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3315 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3319 | void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3320 | // Conditionally generate a log call. |
| 3321 | // Args: |
| 3322 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 3323 | // This is used to determine whether or not to generate the log call. |
| 3324 | // 1 (string): Format string. Access the string at argument index 2 |
| 3325 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 3326 | // 2 (array): Arguments to the format string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3327 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3328 | ASSERT_EQ(args->length(), 3); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3329 | if (CodeGenerator::ShouldGenerateLog(isolate(), args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3330 | VisitForStackValue(args->at(1)); |
| 3331 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3332 | __ CallRuntime(Runtime::kLog, 2); |
| 3333 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3334 | // 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] | 3335 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3336 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3337 | } |
| 3338 | |
| 3339 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3340 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3341 | // Load the arguments on the stack and call the stub. |
| 3342 | SubStringStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3343 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3344 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3345 | VisitForStackValue(args->at(0)); |
| 3346 | VisitForStackValue(args->at(1)); |
| 3347 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3348 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3349 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3353 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3354 | // Load the arguments on the stack and call the stub. |
| 3355 | RegExpExecStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3356 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3357 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3358 | VisitForStackValue(args->at(0)); |
| 3359 | VisitForStackValue(args->at(1)); |
| 3360 | VisitForStackValue(args->at(2)); |
| 3361 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3362 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3363 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3367 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3368 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3369 | ASSERT(args->length() == 1); |
| 3370 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3371 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3372 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3373 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3374 | // If the object is a smi return the object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3375 | __ JumpIfSmi(eax, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3376 | // If the object is not a value type, return the object. |
| 3377 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3378 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3379 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3380 | |
| 3381 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3382 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3386 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3387 | ZoneList<Expression*>* args = expr->arguments(); |
| 3388 | ASSERT(args->length() == 2); |
| 3389 | ASSERT_NE(NULL, args->at(1)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3390 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3391 | |
| 3392 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3393 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3394 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3395 | Register object = eax; |
| 3396 | Register result = eax; |
| 3397 | Register scratch = ecx; |
| 3398 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3399 | __ JumpIfSmi(object, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3400 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3401 | __ j(not_equal, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3402 | |
| 3403 | if (index->value() == 0) { |
| 3404 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3405 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3406 | } else { |
| 3407 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3408 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3409 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3410 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3411 | __ j(not_equal, &runtime, Label::kNear); |
| 3412 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3413 | kPointerSize * index->value())); |
| 3414 | __ jmp(&done); |
| 3415 | } |
| 3416 | __ bind(&runtime); |
| 3417 | __ PrepareCallCFunction(2, scratch); |
| 3418 | __ mov(Operand(esp, 0), object); |
| 3419 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3420 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3421 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3422 | } |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3423 | |
| 3424 | __ bind(¬_date_object); |
| 3425 | __ CallRuntime(Runtime::kThrowNotDateError, 0); |
| 3426 | __ bind(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3427 | context()->Plug(result); |
| 3428 | } |
| 3429 | |
| 3430 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3431 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3432 | ZoneList<Expression*>* args = expr->arguments(); |
| 3433 | ASSERT_EQ(3, args->length()); |
| 3434 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3435 | Register string = eax; |
| 3436 | Register index = ebx; |
| 3437 | Register value = ecx; |
| 3438 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3439 | VisitForStackValue(args->at(1)); // index |
| 3440 | VisitForStackValue(args->at(2)); // value |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3441 | VisitForAccumulatorValue(args->at(0)); // string |
| 3442 | |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3443 | __ pop(value); |
| 3444 | __ pop(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3445 | |
| 3446 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3447 | __ test(value, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3448 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3449 | __ test(index, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3450 | __ Check(zero, kNonSmiValue); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | __ SmiUntag(value); |
| 3454 | __ SmiUntag(index); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3455 | |
| 3456 | if (FLAG_debug_code) { |
| 3457 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3458 | __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3459 | } |
| 3460 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3461 | __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3462 | value); |
| 3463 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | |
| 3467 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3468 | ZoneList<Expression*>* args = expr->arguments(); |
| 3469 | ASSERT_EQ(3, args->length()); |
| 3470 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3471 | Register string = eax; |
| 3472 | Register index = ebx; |
| 3473 | Register value = ecx; |
| 3474 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3475 | VisitForStackValue(args->at(1)); // index |
| 3476 | VisitForStackValue(args->at(2)); // value |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3477 | VisitForAccumulatorValue(args->at(0)); // string |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3478 | __ pop(value); |
| 3479 | __ pop(index); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3480 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3481 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3482 | __ test(value, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3483 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3484 | __ test(index, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3485 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3486 | __ SmiUntag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3487 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3488 | __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3489 | __ SmiTag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | __ SmiUntag(value); |
| 3493 | // No need to untag a smi for two-byte addressing. |
| 3494 | __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), |
| 3495 | value); |
| 3496 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3500 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3501 | // Load the arguments on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3502 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3503 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3504 | VisitForStackValue(args->at(0)); |
| 3505 | VisitForStackValue(args->at(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3506 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3507 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3508 | MathPowStub stub(MathPowStub::ON_STACK); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3509 | __ CallStub(&stub); |
| 3510 | } else { |
| 3511 | __ CallRuntime(Runtime::kMath_pow, 2); |
| 3512 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3513 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3517 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3518 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3519 | ASSERT(args->length() == 2); |
| 3520 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3521 | VisitForStackValue(args->at(0)); // Load the object. |
| 3522 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3523 | __ pop(ebx); // eax = value. ebx = object. |
| 3524 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3525 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3526 | // If the object is a smi, return the value. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3527 | __ JumpIfSmi(ebx, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3528 | |
| 3529 | // If the object is not a value type, return the value. |
| 3530 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3531 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3532 | |
| 3533 | // Store the value. |
| 3534 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3535 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3536 | // Update the write barrier. Save the value as it will be |
| 3537 | // overwritten by the write barrier code and is needed afterward. |
| 3538 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3539 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3540 | |
| 3541 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3542 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3546 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3547 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3548 | ASSERT_EQ(args->length(), 1); |
| 3549 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3550 | // Load the argument into eax and call the stub. |
| 3551 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3552 | |
| 3553 | NumberToStringStub stub; |
| 3554 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3555 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3556 | } |
| 3557 | |
| 3558 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3559 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3560 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3561 | ASSERT(args->length() == 1); |
| 3562 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3563 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3564 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3565 | Label done; |
| 3566 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3567 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3568 | __ jmp(&done); |
| 3569 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3570 | NopRuntimeCallHelper call_helper; |
| 3571 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3572 | |
| 3573 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3574 | context()->Plug(ebx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3578 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3579 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3580 | ASSERT(args->length() == 2); |
| 3581 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3582 | VisitForStackValue(args->at(0)); |
| 3583 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3584 | |
| 3585 | Register object = ebx; |
| 3586 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3587 | Register result = edx; |
| 3588 | |
| 3589 | __ pop(object); |
| 3590 | |
| 3591 | Label need_conversion; |
| 3592 | Label index_out_of_range; |
| 3593 | Label done; |
| 3594 | StringCharCodeAtGenerator generator(object, |
| 3595 | index, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3596 | result, |
| 3597 | &need_conversion, |
| 3598 | &need_conversion, |
| 3599 | &index_out_of_range, |
| 3600 | STRING_INDEX_IS_NUMBER); |
| 3601 | generator.GenerateFast(masm_); |
| 3602 | __ jmp(&done); |
| 3603 | |
| 3604 | __ bind(&index_out_of_range); |
| 3605 | // When the index is out of range, the spec requires us to return |
| 3606 | // NaN. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3607 | __ Set(result, Immediate(isolate()->factory()->nan_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3608 | __ jmp(&done); |
| 3609 | |
| 3610 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3611 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3612 | // trigger conversion. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3613 | __ Set(result, Immediate(isolate()->factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3614 | __ jmp(&done); |
| 3615 | |
| 3616 | NopRuntimeCallHelper call_helper; |
| 3617 | generator.GenerateSlow(masm_, call_helper); |
| 3618 | |
| 3619 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3620 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3621 | } |
| 3622 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3623 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3624 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3625 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3626 | ASSERT(args->length() == 2); |
| 3627 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3628 | VisitForStackValue(args->at(0)); |
| 3629 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3630 | |
| 3631 | Register object = ebx; |
| 3632 | Register index = eax; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3633 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3634 | Register result = eax; |
| 3635 | |
| 3636 | __ pop(object); |
| 3637 | |
| 3638 | Label need_conversion; |
| 3639 | Label index_out_of_range; |
| 3640 | Label done; |
| 3641 | StringCharAtGenerator generator(object, |
| 3642 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3643 | scratch, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3644 | result, |
| 3645 | &need_conversion, |
| 3646 | &need_conversion, |
| 3647 | &index_out_of_range, |
| 3648 | STRING_INDEX_IS_NUMBER); |
| 3649 | generator.GenerateFast(masm_); |
| 3650 | __ jmp(&done); |
| 3651 | |
| 3652 | __ bind(&index_out_of_range); |
| 3653 | // When the index is out of range, the spec requires us to return |
| 3654 | // the empty string. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3655 | __ Set(result, Immediate(isolate()->factory()->empty_string())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3656 | __ jmp(&done); |
| 3657 | |
| 3658 | __ bind(&need_conversion); |
| 3659 | // Move smi zero into the result register, which will trigger |
| 3660 | // conversion. |
| 3661 | __ Set(result, Immediate(Smi::FromInt(0))); |
| 3662 | __ jmp(&done); |
| 3663 | |
| 3664 | NopRuntimeCallHelper call_helper; |
| 3665 | generator.GenerateSlow(masm_, call_helper); |
| 3666 | |
| 3667 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3668 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3672 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3673 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3674 | ASSERT_EQ(2, args->length()); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 3675 | VisitForStackValue(args->at(0)); |
| 3676 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3677 | |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 3678 | __ pop(edx); |
| 3679 | StringAddStub stub(STRING_ADD_CHECK_BOTH, NOT_TENURED); |
| 3680 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3681 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
| 3684 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3685 | void FullCodeGenerator::EmitStringCompare(CallRuntime* expr) { |
| 3686 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3687 | ASSERT_EQ(2, args->length()); |
| 3688 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3689 | VisitForStackValue(args->at(0)); |
| 3690 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3691 | |
| 3692 | StringCompareStub stub; |
| 3693 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3694 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3695 | } |
| 3696 | |
| 3697 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3698 | void FullCodeGenerator::EmitMathLog(CallRuntime* expr) { |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3699 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3700 | ZoneList<Expression*>* args = expr->arguments(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3701 | ASSERT(args->length() == 1); |
| 3702 | VisitForStackValue(args->at(0)); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 3703 | __ CallRuntime(Runtime::kMath_log, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3704 | context()->Plug(eax); |
| 3705 | } |
| 3706 | |
| 3707 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3708 | void FullCodeGenerator::EmitMathSqrt(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3709 | // Load the argument on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3710 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3711 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3712 | VisitForStackValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3713 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3714 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3718 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3719 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3720 | ASSERT(args->length() >= 2); |
| 3721 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3722 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3723 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3724 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3725 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3726 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3727 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3728 | Label runtime, done; |
| 3729 | // Check for non-function argument (including proxy). |
| 3730 | __ JumpIfSmi(eax, &runtime); |
| 3731 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3732 | __ j(not_equal, &runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3733 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3734 | // InvokeFunction requires the function in edi. Move it in there. |
| 3735 | __ mov(edi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3736 | ParameterCount count(arg_count); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3737 | __ InvokeFunction(edi, count, CALL_FUNCTION, NullCallWrapper()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3738 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3739 | __ jmp(&done); |
| 3740 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3741 | __ bind(&runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3742 | __ push(eax); |
| 3743 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3744 | __ bind(&done); |
| 3745 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3746 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3750 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3751 | // Load the arguments on the stack and call the stub. |
| 3752 | RegExpConstructResultStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3753 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3754 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3755 | VisitForStackValue(args->at(0)); |
| 3756 | VisitForStackValue(args->at(1)); |
machenbach@chromium.org | 09cae8d | 2014-01-30 01:05:27 +0000 | [diff] [blame] | 3757 | VisitForAccumulatorValue(args->at(2)); |
| 3758 | __ pop(ebx); |
| 3759 | __ pop(ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3760 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3761 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3765 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3766 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3767 | ASSERT_EQ(2, args->length()); |
| 3768 | |
| 3769 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3770 | 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] | 3771 | |
| 3772 | Handle<FixedArray> jsfunction_result_caches( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3773 | isolate()->native_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3774 | if (jsfunction_result_caches->length() <= cache_id) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3775 | __ Abort(kAttemptToUseUndefinedCache); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3776 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3777 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3778 | return; |
| 3779 | } |
| 3780 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3781 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3782 | |
| 3783 | Register key = eax; |
| 3784 | Register cache = ebx; |
| 3785 | Register tmp = ecx; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3786 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3787 | __ mov(cache, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3788 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3789 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3790 | __ mov(cache, |
| 3791 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3792 | |
| 3793 | Label done, not_found; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3794 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3795 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
machenbach@chromium.org | 0a73036 | 2014-02-05 03:04:56 +0000 | [diff] [blame] | 3796 | // tmp now holds finger offset as a smi. |
| 3797 | __ cmp(key, FixedArrayElementOperand(cache, tmp)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3798 | __ j(not_equal, ¬_found); |
| 3799 | |
machenbach@chromium.org | 0a73036 | 2014-02-05 03:04:56 +0000 | [diff] [blame] | 3800 | __ mov(eax, FixedArrayElementOperand(cache, tmp, 1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3801 | __ jmp(&done); |
| 3802 | |
| 3803 | __ bind(¬_found); |
| 3804 | // Call runtime to perform the lookup. |
| 3805 | __ push(cache); |
| 3806 | __ push(key); |
| 3807 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 3808 | |
| 3809 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3810 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3814 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3815 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3816 | ASSERT(args->length() == 1); |
| 3817 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3818 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3819 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3820 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3821 | |
| 3822 | Label materialize_true, materialize_false; |
| 3823 | Label* if_true = NULL; |
| 3824 | Label* if_false = NULL; |
| 3825 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3826 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3827 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3828 | |
| 3829 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 3830 | Immediate(String::kContainsCachedArrayIndexMask)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3831 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3832 | Split(zero, if_true, if_false, fall_through); |
| 3833 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3834 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3838 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3839 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3840 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3841 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3842 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3843 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3844 | |
| 3845 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 3846 | __ IndexFromHash(eax, eax); |
| 3847 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3848 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3849 | } |
| 3850 | |
| 3851 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3852 | void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3853 | Label bailout, done, one_char_separator, long_separator, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3854 | non_trivial_array, not_size_one_array, loop, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3855 | 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] | 3856 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3857 | ZoneList<Expression*>* args = expr->arguments(); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3858 | ASSERT(args->length() == 2); |
| 3859 | // We will leave the separator on the stack until the end of the function. |
| 3860 | VisitForStackValue(args->at(1)); |
| 3861 | // Load this to eax (= array) |
| 3862 | VisitForAccumulatorValue(args->at(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3863 | // All aliases of the same register have disjoint lifetimes. |
| 3864 | Register array = eax; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3865 | Register elements = no_reg; // Will be eax. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3866 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3867 | Register index = edx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3868 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3869 | Register string_length = ecx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3870 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3871 | Register string = esi; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3872 | |
| 3873 | Register scratch = ebx; |
| 3874 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3875 | Register array_length = edi; |
| 3876 | Register result_pos = no_reg; // Will be edi. |
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 | // Separator operand is already pushed. |
| 3879 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 3880 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 3881 | Operand array_length_operand = Operand(esp, 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3882 | __ sub(esp, Immediate(2 * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3883 | __ cld(); |
| 3884 | // Check that the array is a JSArray |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3885 | __ JumpIfSmi(array, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3886 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3887 | __ j(not_equal, &bailout); |
| 3888 | |
| 3889 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3890 | __ CheckFastElements(scratch, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3891 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3892 | // If the array has length zero, return the empty string. |
| 3893 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3894 | __ SmiUntag(array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3895 | __ j(not_zero, &non_trivial_array); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3896 | __ mov(result_operand, isolate()->factory()->empty_string()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3897 | __ jmp(&done); |
| 3898 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3899 | // Save the array length. |
| 3900 | __ bind(&non_trivial_array); |
| 3901 | __ mov(array_length_operand, array_length); |
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 | // Save the FixedArray containing array's elements. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3904 | // End of array's live range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3905 | elements = array; |
| 3906 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3907 | array = no_reg; |
| 3908 | |
| 3909 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3910 | // Check that all array elements are sequential ASCII strings, and |
| 3911 | // accumulate the sum of their lengths, as a smi-encoded value. |
| 3912 | __ Set(index, Immediate(0)); |
| 3913 | __ Set(string_length, Immediate(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3914 | // Loop condition: while (index < length). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3915 | // Live loop registers: index, array_length, string, |
| 3916 | // scratch, string_length, elements. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 3917 | if (generate_debug_code_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3918 | __ cmp(index, array_length); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3919 | __ Assert(less, kNoEmptyArraysHereInEmitFastAsciiArrayJoin); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3920 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3921 | __ bind(&loop); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3922 | __ mov(string, FieldOperand(elements, |
| 3923 | index, |
| 3924 | times_pointer_size, |
| 3925 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3926 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3927 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3928 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3929 | __ and_(scratch, Immediate( |
| 3930 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3931 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3932 | __ j(not_equal, &bailout); |
| 3933 | __ add(string_length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3934 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3935 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3936 | __ add(index, Immediate(1)); |
| 3937 | __ cmp(index, array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3938 | __ j(less, &loop); |
| 3939 | |
| 3940 | // If array_length is 1, return elements[0], a string. |
| 3941 | __ cmp(array_length, 1); |
| 3942 | __ j(not_equal, ¬_size_one_array); |
| 3943 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3944 | __ mov(result_operand, scratch); |
| 3945 | __ jmp(&done); |
| 3946 | |
| 3947 | __ bind(¬_size_one_array); |
| 3948 | |
| 3949 | // End of array_length live range. |
| 3950 | result_pos = array_length; |
| 3951 | array_length = no_reg; |
| 3952 | |
| 3953 | // Live registers: |
| 3954 | // string_length: Sum of string lengths, as a smi. |
| 3955 | // elements: FixedArray of strings. |
| 3956 | |
| 3957 | // Check that the separator is a flat ASCII string. |
| 3958 | __ mov(string, separator_operand); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3959 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3960 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3961 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3962 | __ and_(scratch, Immediate( |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3963 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3964 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3965 | __ j(not_equal, &bailout); |
| 3966 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3967 | // Add (separator length times array_length) - separator length |
| 3968 | // to string_length. |
| 3969 | __ mov(scratch, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3970 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3971 | __ sub(string_length, scratch); // May be negative, temporarily. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3972 | __ imul(scratch, array_length_operand); |
| 3973 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3974 | __ add(string_length, scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3975 | __ j(overflow, &bailout); |
| 3976 | |
| 3977 | __ shr(string_length, 1); |
| 3978 | // Live registers and stack values: |
| 3979 | // string_length |
| 3980 | // elements |
| 3981 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 3982 | index, string, &bailout); |
| 3983 | __ mov(result_operand, result_pos); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3984 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3985 | |
| 3986 | |
| 3987 | __ mov(string, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3988 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3989 | Immediate(Smi::FromInt(1))); |
| 3990 | __ j(equal, &one_char_separator); |
| 3991 | __ j(greater, &long_separator); |
| 3992 | |
| 3993 | |
| 3994 | // Empty separator case |
| 3995 | __ mov(index, Immediate(0)); |
| 3996 | __ jmp(&loop_1_condition); |
| 3997 | // Loop condition: while (index < length). |
| 3998 | __ bind(&loop_1); |
| 3999 | // Each iteration of the loop concatenates one string to the result. |
| 4000 | // Live values in registers: |
| 4001 | // index: which element of the elements array we are adding to the result. |
| 4002 | // result_pos: the position to which we are currently copying characters. |
| 4003 | // elements: the FixedArray of strings we are joining. |
| 4004 | |
| 4005 | // Get string = array[index]. |
| 4006 | __ mov(string, FieldOperand(elements, index, |
| 4007 | times_pointer_size, |
| 4008 | FixedArray::kHeaderSize)); |
| 4009 | __ mov(string_length, |
| 4010 | FieldOperand(string, String::kLengthOffset)); |
| 4011 | __ shr(string_length, 1); |
| 4012 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4013 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4014 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4015 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4016 | __ bind(&loop_1_condition); |
| 4017 | __ cmp(index, array_length_operand); |
| 4018 | __ j(less, &loop_1); // End while (index < length). |
| 4019 | __ jmp(&done); |
| 4020 | |
| 4021 | |
| 4022 | |
| 4023 | // One-character separator case |
| 4024 | __ bind(&one_char_separator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4025 | // Replace separator with its ASCII character value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4026 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4027 | __ mov_b(separator_operand, scratch); |
| 4028 | |
| 4029 | __ Set(index, Immediate(0)); |
| 4030 | // Jump into the loop after the code that copies the separator, so the first |
| 4031 | // element is not preceded by a separator |
| 4032 | __ jmp(&loop_2_entry); |
| 4033 | // Loop condition: while (index < length). |
| 4034 | __ bind(&loop_2); |
| 4035 | // Each iteration of the loop concatenates one string to the result. |
| 4036 | // Live values in registers: |
| 4037 | // index: which element of the elements array we are adding to the result. |
| 4038 | // result_pos: the position to which we are currently copying characters. |
| 4039 | |
| 4040 | // Copy the separator character to the result. |
| 4041 | __ mov_b(scratch, separator_operand); |
| 4042 | __ mov_b(Operand(result_pos, 0), scratch); |
| 4043 | __ inc(result_pos); |
| 4044 | |
| 4045 | __ bind(&loop_2_entry); |
| 4046 | // Get string = array[index]. |
| 4047 | __ mov(string, FieldOperand(elements, index, |
| 4048 | times_pointer_size, |
| 4049 | FixedArray::kHeaderSize)); |
| 4050 | __ mov(string_length, |
| 4051 | FieldOperand(string, String::kLengthOffset)); |
| 4052 | __ shr(string_length, 1); |
| 4053 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4054 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4055 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4056 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4057 | |
| 4058 | __ cmp(index, array_length_operand); |
| 4059 | __ j(less, &loop_2); // End while (index < length). |
| 4060 | __ jmp(&done); |
| 4061 | |
| 4062 | |
| 4063 | // Long separator case (separator is more than one character). |
| 4064 | __ bind(&long_separator); |
| 4065 | |
| 4066 | __ Set(index, Immediate(0)); |
| 4067 | // Jump into the loop after the code that copies the separator, so the first |
| 4068 | // element is not preceded by a separator |
| 4069 | __ jmp(&loop_3_entry); |
| 4070 | // Loop condition: while (index < length). |
| 4071 | __ bind(&loop_3); |
| 4072 | // Each iteration of the loop concatenates one string to the result. |
| 4073 | // Live values in registers: |
| 4074 | // index: which element of the elements array we are adding to the result. |
| 4075 | // result_pos: the position to which we are currently copying characters. |
| 4076 | |
| 4077 | // Copy the separator to the result. |
| 4078 | __ mov(string, separator_operand); |
| 4079 | __ mov(string_length, |
| 4080 | FieldOperand(string, String::kLengthOffset)); |
| 4081 | __ shr(string_length, 1); |
| 4082 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4083 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4084 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 4085 | |
| 4086 | __ bind(&loop_3_entry); |
| 4087 | // Get string = array[index]. |
| 4088 | __ mov(string, FieldOperand(elements, index, |
| 4089 | times_pointer_size, |
| 4090 | FixedArray::kHeaderSize)); |
| 4091 | __ mov(string_length, |
| 4092 | FieldOperand(string, String::kLengthOffset)); |
| 4093 | __ shr(string_length, 1); |
| 4094 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4095 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4096 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4097 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4098 | |
| 4099 | __ cmp(index, array_length_operand); |
| 4100 | __ j(less, &loop_3); // End while (index < length). |
| 4101 | __ jmp(&done); |
| 4102 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4103 | |
| 4104 | __ bind(&bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4105 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4106 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4107 | __ mov(eax, result_operand); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4108 | // Drop temp values from the stack, and restore context register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4109 | __ add(esp, Immediate(3 * kPointerSize)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4110 | |
| 4111 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4112 | context()->Plug(eax); |
| 4113 | } |
| 4114 | |
| 4115 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4116 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4117 | Handle<String> name = expr->name(); |
| 4118 | if (name->length() > 0 && name->Get(0) == '_') { |
| 4119 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4120 | EmitInlineRuntimeCall(expr); |
| 4121 | return; |
| 4122 | } |
| 4123 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4124 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4125 | ZoneList<Expression*>* args = expr->arguments(); |
| 4126 | |
| 4127 | if (expr->is_jsruntime()) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4128 | // Push the builtins object as receiver. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4129 | __ mov(eax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4130 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4131 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4132 | // Load the function from the receiver. |
| 4133 | __ mov(edx, Operand(esp, 0)); |
| 4134 | __ mov(ecx, Immediate(expr->name())); |
| 4135 | CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4136 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4137 | // Push the target function under the receiver. |
| 4138 | __ push(Operand(esp, 0)); |
| 4139 | __ mov(Operand(esp, kPointerSize), eax); |
| 4140 | |
| 4141 | // Code common for calls using the IC. |
| 4142 | ZoneList<Expression*>* args = expr->arguments(); |
| 4143 | int arg_count = args->length(); |
| 4144 | for (int i = 0; i < arg_count; i++) { |
| 4145 | VisitForStackValue(args->at(i)); |
| 4146 | } |
| 4147 | |
| 4148 | // Record source position of the IC call. |
| 4149 | SetSourcePosition(expr->position()); |
| 4150 | CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
| 4151 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 4152 | __ CallStub(&stub); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4153 | // Restore context register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4154 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4155 | context()->DropAndPlug(1, eax); |
| 4156 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4157 | } else { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4158 | // Push the arguments ("left-to-right"). |
| 4159 | int arg_count = args->length(); |
| 4160 | for (int i = 0; i < arg_count; i++) { |
| 4161 | VisitForStackValue(args->at(i)); |
| 4162 | } |
| 4163 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4164 | // Call the C runtime function. |
| 4165 | __ CallRuntime(expr->function(), arg_count); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4166 | |
| 4167 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4168 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4169 | } |
| 4170 | |
| 4171 | |
| 4172 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 4173 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4174 | case Token::DELETE: { |
| 4175 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4176 | Property* property = expr->expression()->AsProperty(); |
| 4177 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4178 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4179 | if (property != NULL) { |
| 4180 | VisitForStackValue(property->obj()); |
| 4181 | VisitForStackValue(property->key()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4182 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4183 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4184 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4185 | } else if (proxy != NULL) { |
| 4186 | Variable* var = proxy->var(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4187 | // Delete of an unqualified identifier is disallowed in strict mode |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4188 | // but "delete this" is allowed. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4189 | ASSERT(strict_mode() == SLOPPY || var->is_this()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4190 | if (var->IsUnallocated()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4191 | __ push(GlobalObjectOperand()); |
| 4192 | __ push(Immediate(var->name())); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4193 | __ push(Immediate(Smi::FromInt(SLOPPY))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4194 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4195 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4196 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4197 | // Result of deleting non-global variables is false. 'this' is |
| 4198 | // not really a variable, though we implement it as one. The |
| 4199 | // subexpression does not have side effects. |
| 4200 | context()->Plug(var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4201 | } else { |
| 4202 | // Non-global variable. Call the runtime to try to delete from the |
| 4203 | // context where the variable was introduced. |
| 4204 | __ push(context_register()); |
| 4205 | __ push(Immediate(var->name())); |
| 4206 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
| 4207 | context()->Plug(eax); |
| 4208 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4209 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4210 | // Result of deleting non-property, non-variable reference is true. |
| 4211 | // The subexpression may have side effects. |
| 4212 | VisitForEffect(expr->expression()); |
| 4213 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4214 | } |
| 4215 | break; |
| 4216 | } |
| 4217 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4218 | case Token::VOID: { |
| 4219 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 4220 | VisitForEffect(expr->expression()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4221 | context()->Plug(isolate()->factory()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4222 | break; |
| 4223 | } |
| 4224 | |
| 4225 | case Token::NOT: { |
| 4226 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4227 | if (context()->IsEffect()) { |
| 4228 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4229 | // subexpression. Match the optimizing compiler by not branching. |
| 4230 | VisitForEffect(expr->expression()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4231 | } else if (context()->IsTest()) { |
| 4232 | const TestContext* test = TestContext::cast(context()); |
| 4233 | // The labels are swapped for the recursive call. |
| 4234 | VisitForControl(expr->expression(), |
| 4235 | test->false_label(), |
| 4236 | test->true_label(), |
| 4237 | test->fall_through()); |
| 4238 | context()->Plug(test->true_label(), test->false_label()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4239 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4240 | // We handle value contexts explicitly rather than simply visiting |
| 4241 | // for control and plugging the control flow into the context, |
| 4242 | // because we need to prepare a pair of extra administrative AST ids |
| 4243 | // for the optimizing compiler. |
| 4244 | ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 4245 | Label materialize_true, materialize_false, done; |
| 4246 | VisitForControl(expr->expression(), |
| 4247 | &materialize_false, |
| 4248 | &materialize_true, |
| 4249 | &materialize_true); |
| 4250 | __ bind(&materialize_true); |
| 4251 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4252 | if (context()->IsAccumulatorValue()) { |
| 4253 | __ mov(eax, isolate()->factory()->true_value()); |
| 4254 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4255 | __ Push(isolate()->factory()->true_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4256 | } |
| 4257 | __ jmp(&done, Label::kNear); |
| 4258 | __ bind(&materialize_false); |
| 4259 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4260 | if (context()->IsAccumulatorValue()) { |
| 4261 | __ mov(eax, isolate()->factory()->false_value()); |
| 4262 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4263 | __ Push(isolate()->factory()->false_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4264 | } |
| 4265 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4266 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4267 | break; |
| 4268 | } |
| 4269 | |
| 4270 | case Token::TYPEOF: { |
| 4271 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4272 | { StackValueContext context(this); |
| 4273 | VisitForTypeofValue(expr->expression()); |
| 4274 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4275 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4276 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4277 | break; |
| 4278 | } |
| 4279 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4280 | default: |
| 4281 | UNREACHABLE(); |
| 4282 | } |
| 4283 | } |
| 4284 | |
| 4285 | |
| 4286 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 4287 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4288 | SetSourcePosition(expr->position()); |
| 4289 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4290 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 4291 | // as the left-hand side. |
| 4292 | if (!expr->expression()->IsValidLeftHandSide()) { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4293 | VisitForEffect(expr->expression()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4294 | return; |
| 4295 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4296 | |
| 4297 | // 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] | 4298 | // slot. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4299 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 4300 | LhsKind assign_type = VARIABLE; |
| 4301 | Property* prop = expr->expression()->AsProperty(); |
| 4302 | // In case of a property we use the uninitialized expression context |
| 4303 | // of the key to detect a named property. |
| 4304 | if (prop != NULL) { |
| 4305 | assign_type = |
| 4306 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 4307 | } |
| 4308 | |
| 4309 | // Evaluate expression and get value. |
| 4310 | if (assign_type == VARIABLE) { |
| 4311 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4312 | AccumulatorValueContext context(this); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4313 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4314 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4315 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4316 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4317 | __ push(Immediate(Smi::FromInt(0))); |
| 4318 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4319 | if (assign_type == NAMED_PROPERTY) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4320 | // Put the object both on the stack and in edx. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4321 | VisitForAccumulatorValue(prop->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4322 | __ push(eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4323 | __ mov(edx, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4324 | EmitNamedPropertyLoad(prop); |
| 4325 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4326 | VisitForStackValue(prop->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4327 | VisitForStackValue(prop->key()); |
| 4328 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 4329 | __ mov(ecx, Operand(esp, 0)); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4330 | EmitKeyedPropertyLoad(prop); |
| 4331 | } |
| 4332 | } |
| 4333 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4334 | // We need a second deoptimization point after loading the value |
| 4335 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4336 | if (assign_type == VARIABLE) { |
| 4337 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4338 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4339 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4340 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4341 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4342 | // Inline smi case if we are in a loop. |
| 4343 | Label done, stub_call; |
| 4344 | JumpPatchSite patch_site(masm_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4345 | if (ShouldInlineSmiCase(expr->op())) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4346 | Label slow; |
| 4347 | patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); |
| 4348 | |
| 4349 | // Save result for postfix expressions. |
| 4350 | if (expr->is_postfix()) { |
| 4351 | if (!context()->IsEffect()) { |
| 4352 | // Save the result on the stack. If we have a named or keyed property |
| 4353 | // we store the result under the receiver that is currently on top |
| 4354 | // of the stack. |
| 4355 | switch (assign_type) { |
| 4356 | case VARIABLE: |
| 4357 | __ push(eax); |
| 4358 | break; |
| 4359 | case NAMED_PROPERTY: |
| 4360 | __ mov(Operand(esp, kPointerSize), eax); |
| 4361 | break; |
| 4362 | case KEYED_PROPERTY: |
| 4363 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4364 | break; |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | |
| 4369 | if (expr->op() == Token::INC) { |
| 4370 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4371 | } else { |
| 4372 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4373 | } |
| 4374 | __ j(no_overflow, &done, Label::kNear); |
| 4375 | // Call stub. Undo operation first. |
| 4376 | if (expr->op() == Token::INC) { |
| 4377 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4378 | } else { |
| 4379 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4380 | } |
| 4381 | __ jmp(&stub_call, Label::kNear); |
| 4382 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4383 | } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4384 | ToNumberStub convert_stub; |
| 4385 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4386 | |
| 4387 | // Save result for postfix expressions. |
| 4388 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4389 | if (!context()->IsEffect()) { |
| 4390 | // Save the result on the stack. If we have a named or keyed property |
| 4391 | // we store the result under the receiver that is currently on top |
| 4392 | // of the stack. |
| 4393 | switch (assign_type) { |
| 4394 | case VARIABLE: |
| 4395 | __ push(eax); |
| 4396 | break; |
| 4397 | case NAMED_PROPERTY: |
| 4398 | __ mov(Operand(esp, kPointerSize), eax); |
| 4399 | break; |
| 4400 | case KEYED_PROPERTY: |
| 4401 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4402 | break; |
| 4403 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4404 | } |
| 4405 | } |
| 4406 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4407 | // Record position before stub call. |
| 4408 | SetSourcePosition(expr->position()); |
| 4409 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4410 | // Call stub for +1/-1. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4411 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4412 | __ mov(edx, eax); |
| 4413 | __ mov(eax, Immediate(Smi::FromInt(1))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4414 | BinaryOpICStub stub(expr->binary_op(), NO_OVERWRITE); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4415 | CallIC(stub.GetCode(isolate()), expr->CountBinOpFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4416 | patch_site.EmitPatchInfo(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4417 | __ bind(&done); |
| 4418 | |
| 4419 | // Store the value returned in eax. |
| 4420 | switch (assign_type) { |
| 4421 | case VARIABLE: |
| 4422 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4423 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4424 | { EffectContext context(this); |
| 4425 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4426 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4427 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4428 | context.Plug(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4429 | } |
| 4430 | // For all contexts except EffectContext We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4431 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4432 | if (!context()->IsEffect()) { |
| 4433 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4434 | } |
| 4435 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4436 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4437 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4438 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4439 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4440 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4441 | } |
| 4442 | break; |
| 4443 | case NAMED_PROPERTY: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4444 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4445 | __ pop(edx); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4446 | CallStoreIC(expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4447 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4448 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4449 | if (!context()->IsEffect()) { |
| 4450 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4451 | } |
| 4452 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4453 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4454 | } |
| 4455 | break; |
| 4456 | } |
| 4457 | case KEYED_PROPERTY: { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4458 | __ pop(ecx); |
| 4459 | __ pop(edx); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4460 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4461 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 4462 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4463 | CallIC(ic, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4464 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4465 | if (expr->is_postfix()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4466 | // Result is on the stack |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4467 | if (!context()->IsEffect()) { |
| 4468 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4469 | } |
| 4470 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4471 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4472 | } |
| 4473 | break; |
| 4474 | } |
| 4475 | } |
| 4476 | } |
| 4477 | |
| 4478 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4479 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4480 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4481 | ASSERT(!context()->IsEffect()); |
| 4482 | ASSERT(!context()->IsTest()); |
| 4483 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4484 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4485 | Comment cmnt(masm_, "[ Global variable"); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4486 | __ mov(edx, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4487 | __ mov(ecx, Immediate(proxy->name())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4488 | // Use a regular load, not a contextual load, to avoid a reference |
| 4489 | // error. |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 4490 | CallLoadIC(NOT_CONTEXTUAL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4491 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4492 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4493 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4494 | Comment cmnt(masm_, "[ Lookup slot"); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4495 | Label done, slow; |
| 4496 | |
| 4497 | // Generate code for loading from variables potentially shadowed |
| 4498 | // by eval-introduced variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4499 | EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4500 | |
| 4501 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4502 | __ push(esi); |
| 4503 | __ push(Immediate(proxy->name())); |
| 4504 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4505 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4506 | __ bind(&done); |
| 4507 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4508 | context()->Plug(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4509 | } else { |
| 4510 | // This expression cannot throw a reference error at the top level. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4511 | VisitInDuplicateContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4512 | } |
| 4513 | } |
| 4514 | |
| 4515 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4516 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4517 | Expression* sub_expr, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4518 | Handle<String> check) { |
| 4519 | Label materialize_true, materialize_false; |
| 4520 | Label* if_true = NULL; |
| 4521 | Label* if_false = NULL; |
| 4522 | Label* fall_through = NULL; |
| 4523 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4524 | &if_true, &if_false, &fall_through); |
| 4525 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4526 | { AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4527 | VisitForTypeofValue(sub_expr); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4528 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4529 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4530 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4531 | if (check->Equals(isolate()->heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4532 | __ JumpIfSmi(eax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4533 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4534 | isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4536 | } else if (check->Equals(isolate()->heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4537 | __ JumpIfSmi(eax, if_false); |
| 4538 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4539 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4540 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4541 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4542 | 1 << Map::kIsUndetectable); |
| 4543 | Split(zero, if_true, if_false, fall_through); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4544 | } else if (check->Equals(isolate()->heap()->symbol_string())) { |
| 4545 | __ JumpIfSmi(eax, if_false); |
| 4546 | __ CmpObjectType(eax, SYMBOL_TYPE, edx); |
| 4547 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4548 | } else if (check->Equals(isolate()->heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4549 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4550 | __ j(equal, if_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4551 | __ cmp(eax, isolate()->factory()->false_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4552 | Split(equal, if_true, if_false, fall_through); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4553 | } else if (FLAG_harmony_typeof && |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4554 | check->Equals(isolate()->heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4555 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4556 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4557 | } else if (check->Equals(isolate()->heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4558 | __ cmp(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4559 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4560 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4561 | // Check for undetectable objects => true. |
| 4562 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4563 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4564 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4565 | Split(not_zero, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4566 | } else if (check->Equals(isolate()->heap()->function_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4567 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4568 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4569 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4570 | __ j(equal, if_true); |
| 4571 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4572 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4573 | } else if (check->Equals(isolate()->heap()->object_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4574 | __ JumpIfSmi(eax, if_false); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4575 | if (!FLAG_harmony_typeof) { |
| 4576 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4577 | __ j(equal, if_true); |
| 4578 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4579 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4580 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4581 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4582 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4583 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4584 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4585 | 1 << Map::kIsUndetectable); |
| 4586 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4587 | } else { |
| 4588 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4589 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4590 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4591 | } |
| 4592 | |
| 4593 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4594 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4595 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4596 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4597 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4598 | // First we try a fast inlined version of the compare when one of |
| 4599 | // the operands is a literal. |
| 4600 | if (TryLiteralCompare(expr)) return; |
| 4601 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4602 | // Always perform the comparison for its control flow. Pack the result |
| 4603 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4604 | Label materialize_true, materialize_false; |
| 4605 | Label* if_true = NULL; |
| 4606 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4607 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4608 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4609 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4610 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4611 | Token::Value op = expr->op(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4612 | VisitForStackValue(expr->left()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4613 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4614 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4615 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4616 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4617 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4618 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4619 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4620 | break; |
| 4621 | |
| 4622 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4623 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4624 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4625 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4626 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4627 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4628 | // The stub returns 0 for true. |
| 4629 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4630 | break; |
| 4631 | } |
| 4632 | |
| 4633 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4634 | VisitForAccumulatorValue(expr->right()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4635 | Condition cc = CompareIC::ComputeCondition(op); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4636 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4637 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4638 | bool inline_smi_code = ShouldInlineSmiCase(op); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4639 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4640 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4641 | Label slow_case; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4642 | __ mov(ecx, edx); |
| 4643 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4644 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4645 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4646 | Split(cc, if_true, if_false, NULL); |
| 4647 | __ bind(&slow_case); |
| 4648 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4649 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4650 | // Record position and call the compare IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4651 | SetSourcePosition(expr->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4652 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4653 | CallIC(ic, expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4654 | patch_site.EmitPatchInfo(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4655 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4656 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4657 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4658 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | // Convert the result of the comparison into one expected for this |
| 4663 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4664 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4665 | } |
| 4666 | |
| 4667 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4668 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4669 | Expression* sub_expr, |
| 4670 | NilValue nil) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4671 | Label materialize_true, materialize_false; |
| 4672 | Label* if_true = NULL; |
| 4673 | Label* if_false = NULL; |
| 4674 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4675 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4676 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4677 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4678 | VisitForAccumulatorValue(sub_expr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4679 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4680 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4681 | Handle<Object> nil_value = nil == kNullValue |
| 4682 | ? isolate()->factory()->null_value() |
| 4683 | : isolate()->factory()->undefined_value(); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4684 | if (expr->op() == Token::EQ_STRICT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4685 | __ cmp(eax, nil_value); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4686 | Split(equal, if_true, if_false, fall_through); |
| 4687 | } else { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4688 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4689 | CallIC(ic, expr->CompareOperationFeedbackId()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4690 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4691 | Split(not_zero, if_true, if_false, fall_through); |
| 4692 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4693 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4697 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4698 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4699 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4703 | Register FullCodeGenerator::result_register() { |
| 4704 | return eax; |
| 4705 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4706 | |
| 4707 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4708 | Register FullCodeGenerator::context_register() { |
| 4709 | return esi; |
| 4710 | } |
| 4711 | |
| 4712 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4713 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4714 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 4715 | __ mov(Operand(ebp, frame_offset), value); |
| 4716 | } |
| 4717 | |
| 4718 | |
| 4719 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4720 | __ mov(dst, ContextOperand(esi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4724 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4725 | Scope* declaration_scope = scope()->DeclarationScope(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4726 | if (declaration_scope->is_global_scope() || |
| 4727 | declaration_scope->is_module_scope()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4728 | // Contexts nested in the native context have a canonical empty function |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4729 | // as their closure, not the anonymous closure containing the global |
| 4730 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4731 | // function. |
| 4732 | __ push(Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4733 | } else if (declaration_scope->is_eval_scope()) { |
| 4734 | // Contexts nested inside eval code have the same closure as the context |
| 4735 | // calling eval, not the anonymous closure containing the eval code. |
| 4736 | // Fetch it from the context. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4737 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 4738 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4739 | ASSERT(declaration_scope->is_function_scope()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4740 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4745 | // ---------------------------------------------------------------------------- |
| 4746 | // Non-local control flow support. |
| 4747 | |
| 4748 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4749 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4750 | ASSERT(!result_register().is(edx)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4751 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4752 | __ sub(edx, Immediate(masm_->CodeObject())); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4753 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4754 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4755 | __ SmiTag(edx); |
| 4756 | __ push(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4757 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4758 | // Store result register while executing finally block. |
| 4759 | __ push(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4760 | |
| 4761 | // Store pending message while executing finally block. |
| 4762 | ExternalReference pending_message_obj = |
| 4763 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4764 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4765 | __ push(edx); |
| 4766 | |
| 4767 | ExternalReference has_pending_message = |
| 4768 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4769 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4770 | __ SmiTag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4771 | __ push(edx); |
| 4772 | |
| 4773 | ExternalReference pending_message_script = |
| 4774 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4775 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 4776 | __ push(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4777 | } |
| 4778 | |
| 4779 | |
| 4780 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4781 | ASSERT(!result_register().is(edx)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4782 | // Restore pending message from stack. |
| 4783 | __ pop(edx); |
| 4784 | ExternalReference pending_message_script = |
| 4785 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4786 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 4787 | |
| 4788 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4789 | __ SmiUntag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4790 | ExternalReference has_pending_message = |
| 4791 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4792 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 4793 | |
| 4794 | __ pop(edx); |
| 4795 | ExternalReference pending_message_obj = |
| 4796 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4797 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4798 | |
| 4799 | // Restore result register from stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4800 | __ pop(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4801 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4802 | // Uncook return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4803 | __ pop(edx); |
| 4804 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4805 | __ add(edx, Immediate(masm_->CodeObject())); |
| 4806 | __ jmp(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | |
| 4810 | #undef __ |
| 4811 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4812 | #define __ ACCESS_MASM(masm()) |
| 4813 | |
| 4814 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 4815 | int* stack_depth, |
| 4816 | int* context_length) { |
| 4817 | // The macros used here must preserve the result register. |
| 4818 | |
| 4819 | // Because the handler block contains the context of the finally |
| 4820 | // code, we can restore it directly from there for the finally code |
| 4821 | // rather than iteratively unwinding contexts via their previous |
| 4822 | // links. |
| 4823 | __ Drop(*stack_depth); // Down to the handler block. |
| 4824 | if (*context_length > 0) { |
| 4825 | // Restore the context to its dedicated register and the stack. |
| 4826 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 4827 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 4828 | } |
| 4829 | __ PopTryHandler(); |
| 4830 | __ call(finally_entry_); |
| 4831 | |
| 4832 | *stack_depth = 0; |
| 4833 | *context_length = 0; |
| 4834 | return previous_; |
| 4835 | } |
| 4836 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4837 | #undef __ |
| 4838 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4839 | |
| 4840 | static const byte kJnsInstruction = 0x79; |
| 4841 | static const byte kJnsOffset = 0x11; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4842 | static const byte kNopByteOne = 0x66; |
| 4843 | static const byte kNopByteTwo = 0x90; |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 4844 | #ifdef DEBUG |
| 4845 | static const byte kCallInstruction = 0xe8; |
| 4846 | #endif |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4847 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4848 | |
| 4849 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 4850 | Address pc, |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4851 | BackEdgeState target_state, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4852 | Code* replacement_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4853 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4854 | Address jns_instr_address = call_target_address - 3; |
| 4855 | Address jns_offset_address = call_target_address - 2; |
| 4856 | |
| 4857 | switch (target_state) { |
| 4858 | case INTERRUPT: |
| 4859 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4860 | // jns ok |
| 4861 | // call <interrupt stub> |
| 4862 | // ok: |
| 4863 | *jns_instr_address = kJnsInstruction; |
| 4864 | *jns_offset_address = kJnsOffset; |
| 4865 | break; |
| 4866 | case ON_STACK_REPLACEMENT: |
| 4867 | case OSR_AFTER_STACK_CHECK: |
| 4868 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4869 | // nop |
| 4870 | // nop |
| 4871 | // call <on-stack replacment> |
| 4872 | // ok: |
| 4873 | *jns_instr_address = kNopByteOne; |
| 4874 | *jns_offset_address = kNopByteTwo; |
| 4875 | break; |
| 4876 | } |
| 4877 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4878 | Assembler::set_target_address_at(call_target_address, |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4879 | unoptimized_code, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4880 | replacement_code->entry()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4881 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 4882 | unoptimized_code, call_target_address, replacement_code); |
| 4883 | } |
| 4884 | |
| 4885 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4886 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 4887 | Isolate* isolate, |
| 4888 | Code* unoptimized_code, |
| 4889 | Address pc) { |
| 4890 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4891 | Address jns_instr_address = call_target_address - 3; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4892 | ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4893 | |
| 4894 | if (*jns_instr_address == kJnsInstruction) { |
| 4895 | ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 4896 | ASSERT_EQ(isolate->builtins()->InterruptCheck()->entry(), |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4897 | Assembler::target_address_at(call_target_address, |
| 4898 | unoptimized_code)); |
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 | |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4905 | if (Assembler::target_address_at(call_target_address, unoptimized_code) == |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4906 | isolate->builtins()->OnStackReplacement()->entry()) { |
| 4907 | return ON_STACK_REPLACEMENT; |
| 4908 | } |
| 4909 | |
| 4910 | ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4911 | Assembler::target_address_at(call_target_address, |
| 4912 | unoptimized_code)); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4913 | return OSR_AFTER_STACK_CHECK; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4914 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4915 | |
| 4916 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4917 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4918 | |
| 4919 | #endif // V8_TARGET_ARCH_IA32 |