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 | |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 104 | static void EmitStackCheck(MacroAssembler* masm_, |
| 105 | int pointers = 0, |
| 106 | Register scratch = esp) { |
| 107 | Label ok; |
| 108 | Isolate* isolate = masm_->isolate(); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 109 | ASSERT(scratch.is(esp) == (pointers == 0)); |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 110 | ExternalReference stack_limit; |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 111 | if (pointers != 0) { |
| 112 | __ mov(scratch, esp); |
| 113 | __ sub(scratch, Immediate(pointers * kPointerSize)); |
machenbach@chromium.org | 63a7c9f | 2014-04-01 00:04:36 +0000 | [diff] [blame] | 114 | stack_limit = ExternalReference::address_of_real_stack_limit(isolate); |
| 115 | } else { |
| 116 | stack_limit = ExternalReference::address_of_stack_limit(isolate); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 117 | } |
| 118 | __ cmp(scratch, Operand::StaticVariable(stack_limit)); |
| 119 | __ j(above_equal, &ok, Label::kNear); |
| 120 | __ call(isolate->builtins()->StackCheck(), RelocInfo::CODE_TARGET); |
| 121 | __ bind(&ok); |
| 122 | } |
| 123 | |
| 124 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 125 | // Generate code for a JS function. On entry to the function the receiver |
| 126 | // and arguments have been pushed on the stack left to right, with the |
| 127 | // return address on top of them. The actual argument count matches the |
| 128 | // formal parameter count expected by the function. |
| 129 | // |
| 130 | // The live registers are: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 131 | // o edi: the JS function object being called (i.e. ourselves) |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 132 | // o esi: our context |
| 133 | // o ebp: our caller's frame pointer |
| 134 | // o esp: stack pointer (pointing to return address) |
| 135 | // |
| 136 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 137 | // frames-ia32.h for its layout. |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 138 | void FullCodeGenerator::Generate() { |
| 139 | CompilationInfo* info = info_; |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 140 | handler_table_ = |
| 141 | isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 142 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame] | 143 | InitializeFeedbackVector(); |
| 144 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 145 | profiling_counter_ = isolate()->factory()->NewCell( |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 146 | Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 147 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 148 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 149 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 150 | ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
| 151 | |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 152 | #ifdef DEBUG |
| 153 | if (strlen(FLAG_stop_at) > 0 && |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 154 | info->function()->name()->IsUtf8EqualTo(CStrVector(FLAG_stop_at))) { |
yangguo@chromium.org | a7d3df9 | 2012-02-27 11:46:55 +0000 | [diff] [blame] | 155 | __ int3(); |
| 156 | } |
| 157 | #endif |
| 158 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 159 | // 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] | 160 | // global proxy when called as functions (without an explicit receiver |
| 161 | // object). |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 162 | if (info->strict_mode() == SLOPPY && !info->is_native()) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 163 | Label ok; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 164 | // +1 for return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 165 | int receiver_offset = (info->scope()->num_parameters() + 1) * kPointerSize; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 166 | __ mov(ecx, Operand(esp, receiver_offset)); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 167 | |
| 168 | __ cmp(ecx, isolate()->factory()->undefined_value()); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 169 | __ j(not_equal, &ok, Label::kNear); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 170 | |
| 171 | __ mov(ecx, GlobalObjectOperand()); |
| 172 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 173 | |
| 174 | __ mov(Operand(esp, receiver_offset), ecx); |
| 175 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 176 | __ bind(&ok); |
| 177 | } |
| 178 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 179 | // Open a frame scope to indicate that there is a frame on the stack. The |
| 180 | // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 181 | // the frame (that is done below). |
| 182 | FrameScope frame_scope(masm_, StackFrame::MANUAL); |
| 183 | |
svenpanne@chromium.org | 83130cf | 2012-11-30 10:13:25 +0000 | [diff] [blame] | 184 | info->set_prologue_offset(masm_->pc_offset()); |
bmeurer@chromium.org | c9913f0 | 2013-10-24 06:31:36 +0000 | [diff] [blame] | 185 | __ Prologue(BUILD_FUNCTION_FRAME); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 186 | info->AddNoFrameRange(0, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 187 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 188 | { Comment cmnt(masm_, "[ Allocate locals"); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 189 | int locals_count = info->scope()->num_stack_slots(); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 190 | // Generators allocate locals, if any, in context slots. |
| 191 | ASSERT(!info->function()->is_generator() || locals_count == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 192 | if (locals_count == 1) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 193 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 194 | } else if (locals_count > 1) { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 195 | if (locals_count >= 128) { |
| 196 | EmitStackCheck(masm_, locals_count, ecx); |
| 197 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 198 | __ mov(eax, Immediate(isolate()->factory()->undefined_value())); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 199 | const int kMaxPushes = 32; |
| 200 | if (locals_count >= kMaxPushes) { |
| 201 | int loop_iterations = locals_count / kMaxPushes; |
| 202 | __ mov(ecx, loop_iterations); |
| 203 | Label loop_header; |
| 204 | __ bind(&loop_header); |
| 205 | // Do pushes. |
| 206 | for (int i = 0; i < kMaxPushes; i++) { |
| 207 | __ push(eax); |
| 208 | } |
| 209 | __ dec(ecx); |
| 210 | __ j(not_zero, &loop_header, Label::kNear); |
| 211 | } |
| 212 | int remaining = locals_count % kMaxPushes; |
| 213 | // Emit the remaining pushes. |
| 214 | for (int i = 0; i < remaining; i++) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 215 | __ push(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 216 | } |
| 217 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 218 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 219 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 220 | bool function_in_register = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 221 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 222 | // Possibly allocate a local context. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 223 | 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] | 224 | if (heap_slots > 0) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 225 | Comment cmnt(masm_, "[ Allocate context"); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 226 | // Argument to NewContext is the function, which is still in edi. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 227 | if (FLAG_harmony_scoping && info->scope()->is_global_scope()) { |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 228 | __ push(edi); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 229 | __ Push(info->scope()->GetScopeInfo()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 230 | __ CallRuntime(Runtime::kHiddenNewGlobalContext, 2); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 231 | } else if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 232 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 233 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 234 | } else { |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 235 | __ push(edi); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 236 | __ CallRuntime(Runtime::kHiddenNewFunctionContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 237 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 238 | function_in_register = false; |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 239 | // Context is returned in eax. It replaces the context passed to us. |
| 240 | // It's saved in the stack and kept live in esi. |
| 241 | __ mov(esi, eax); |
| 242 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), eax); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 243 | |
| 244 | // Copy parameters into context if necessary. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 245 | int num_parameters = info->scope()->num_parameters(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 246 | for (int i = 0; i < num_parameters; i++) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 247 | Variable* var = scope()->parameter(i); |
| 248 | if (var->IsContextSlot()) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 249 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 250 | (num_parameters - 1 - i) * kPointerSize; |
| 251 | // Load parameter from stack. |
| 252 | __ mov(eax, Operand(ebp, parameter_offset)); |
| 253 | // Store it in the context. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 254 | int context_offset = Context::SlotOffset(var->index()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 255 | __ mov(Operand(esi, context_offset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 256 | // Update the write barrier. This clobbers eax and ebx. |
| 257 | __ RecordWriteContextSlot(esi, |
| 258 | context_offset, |
| 259 | eax, |
| 260 | ebx, |
| 261 | kDontSaveFPRegs); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | } |
| 265 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 266 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 267 | if (arguments != NULL) { |
| 268 | // Function uses arguments object. |
| 269 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 270 | if (function_in_register) { |
| 271 | __ push(edi); |
| 272 | } else { |
| 273 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 274 | } |
| 275 | // Receiver is just before the parameters on the caller's stack. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 276 | int num_parameters = info->scope()->num_parameters(); |
| 277 | int offset = num_parameters * kPointerSize; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 278 | __ lea(edx, |
| 279 | Operand(ebp, StandardFrameConstants::kCallerSPOffset + offset)); |
| 280 | __ push(edx); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 281 | __ push(Immediate(Smi::FromInt(num_parameters))); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 282 | // Arguments to ArgumentsAccessStub: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 283 | // function, receiver address, parameter count. |
| 284 | // The stub will rewrite receiver and parameter count if the previous |
| 285 | // stack frame was an arguments adapter frame. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 286 | ArgumentsAccessStub::Type type; |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 287 | if (strict_mode() == STRICT) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 288 | type = ArgumentsAccessStub::NEW_STRICT; |
| 289 | } else if (function()->has_duplicate_parameters()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 290 | type = ArgumentsAccessStub::NEW_SLOPPY_SLOW; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 291 | } else { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 292 | type = ArgumentsAccessStub::NEW_SLOPPY_FAST; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 293 | } |
| 294 | ArgumentsAccessStub stub(type); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 295 | __ CallStub(&stub); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 296 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 297 | SetVar(arguments, eax, ebx, edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 298 | } |
| 299 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 300 | if (FLAG_trace) { |
| 301 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 302 | } |
| 303 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 304 | // Visit the declarations and body unless there is an illegal |
| 305 | // redeclaration. |
| 306 | if (scope()->HasIllegalRedeclaration()) { |
| 307 | Comment cmnt(masm_, "[ Declarations"); |
| 308 | scope()->VisitIllegalRedeclaration(this); |
| 309 | |
| 310 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 311 | PrepareForBailoutForId(BailoutId::FunctionEntry(), NO_REGISTERS); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 312 | { Comment cmnt(masm_, "[ Declarations"); |
| 313 | // For named function expressions, declare the function name as a |
| 314 | // constant. |
| 315 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 316 | VariableDeclaration* function = scope()->function(); |
| 317 | ASSERT(function->proxy()->var()->mode() == CONST || |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 318 | function->proxy()->var()->mode() == CONST_LEGACY); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 319 | ASSERT(function->proxy()->var()->location() != Variable::UNALLOCATED); |
| 320 | VisitVariableDeclaration(function); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 321 | } |
| 322 | VisitDeclarations(scope()->declarations()); |
| 323 | } |
| 324 | |
| 325 | { Comment cmnt(masm_, "[ Stack check"); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 326 | PrepareForBailoutForId(BailoutId::Declarations(), NO_REGISTERS); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 327 | EmitStackCheck(masm_); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | { Comment cmnt(masm_, "[ Body"); |
| 331 | ASSERT(loop_depth() == 0); |
| 332 | VisitStatements(function()->body()); |
| 333 | ASSERT(loop_depth() == 0); |
| 334 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 335 | } |
| 336 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 337 | // Always emit a 'return undefined' in case control fell off the end of |
| 338 | // the body. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 339 | { Comment cmnt(masm_, "[ return <undefined>;"); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 340 | __ mov(eax, isolate()->factory()->undefined_value()); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 341 | EmitReturnSequence(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 346 | void FullCodeGenerator::ClearAccumulator() { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 347 | __ Move(eax, Immediate(Smi::FromInt(0))); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 351 | void FullCodeGenerator::EmitProfilingCounterDecrement(int delta) { |
| 352 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 353 | __ sub(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 354 | Immediate(Smi::FromInt(delta))); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void FullCodeGenerator::EmitProfilingCounterReset() { |
| 359 | int reset_value = FLAG_interrupt_budget; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 360 | __ mov(ebx, Immediate(profiling_counter_)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 361 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 362 | Immediate(Smi::FromInt(reset_value))); |
| 363 | } |
| 364 | |
| 365 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 366 | void FullCodeGenerator::EmitBackEdgeBookkeeping(IterationStatement* stmt, |
| 367 | Label* back_edge_target) { |
| 368 | Comment cmnt(masm_, "[ Back edge bookkeeping"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 369 | Label ok; |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 370 | |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 371 | ASSERT(back_edge_target->is_bound()); |
| 372 | int distance = masm_->SizeOfCodeGeneratedSince(back_edge_target); |
| 373 | int weight = Min(kMaxBackEdgeWeight, |
| 374 | Max(1, distance / kCodeSizeMultiplier)); |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 375 | EmitProfilingCounterDecrement(weight); |
| 376 | __ j(positive, &ok, Label::kNear); |
jkummerow@chromium.org | dc94e19 | 2013-08-30 11:35:42 +0000 | [diff] [blame] | 377 | __ call(isolate()->builtins()->InterruptCheck(), RelocInfo::CODE_TARGET); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 378 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 379 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 380 | // the AST id from the unoptimized code in order to use it as a key into |
| 381 | // the deoptimization input data found in the optimized code. |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 382 | RecordBackEdge(stmt->OsrEntryId()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 383 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 384 | EmitProfilingCounterReset(); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 385 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 386 | __ bind(&ok); |
| 387 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 388 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 389 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 390 | // we want it to work if it is. |
| 391 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 395 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 396 | Comment cmnt(masm_, "[ Return sequence"); |
| 397 | if (return_label_.is_bound()) { |
| 398 | __ jmp(&return_label_); |
| 399 | } else { |
| 400 | // Common return label |
| 401 | __ bind(&return_label_); |
| 402 | if (FLAG_trace) { |
| 403 | __ push(eax); |
| 404 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 405 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 406 | // Pretend that the exit is a backwards jump to the entry. |
| 407 | int weight = 1; |
| 408 | if (info_->ShouldSelfOptimize()) { |
| 409 | weight = FLAG_interrupt_budget / FLAG_self_opt_count; |
| 410 | } else { |
| 411 | int distance = masm_->pc_offset(); |
| 412 | weight = Min(kMaxBackEdgeWeight, |
| 413 | Max(1, distance / kCodeSizeMultiplier)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 414 | } |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 415 | EmitProfilingCounterDecrement(weight); |
| 416 | Label ok; |
| 417 | __ j(positive, &ok, Label::kNear); |
| 418 | __ push(eax); |
| 419 | __ call(isolate()->builtins()->InterruptCheck(), |
| 420 | RelocInfo::CODE_TARGET); |
| 421 | __ pop(eax); |
| 422 | EmitProfilingCounterReset(); |
| 423 | __ bind(&ok); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 424 | #ifdef DEBUG |
| 425 | // Add a label for checking the size of the code used for returning. |
| 426 | Label check_exit_codesize; |
| 427 | masm_->bind(&check_exit_codesize); |
| 428 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 429 | SetSourcePosition(function()->end_position() - 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 430 | __ RecordJSReturn(); |
| 431 | // Do not use the leave instruction here because it is too short to |
| 432 | // patch with the code required by the debugger. |
| 433 | __ mov(esp, ebp); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 434 | int no_frame_start = masm_->pc_offset(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 435 | __ pop(ebp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 436 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 437 | int arguments_bytes = (info_->scope()->num_parameters() + 1) * kPointerSize; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 438 | __ Ret(arguments_bytes, ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 439 | #ifdef ENABLE_DEBUGGER_SUPPORT |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 440 | // Check that the size of the code used for returning is large enough |
| 441 | // for the debugger's requirements. |
| 442 | ASSERT(Assembler::kJSReturnSequenceLength <= |
| 443 | masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 444 | #endif |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 445 | info_->AddNoFrameRange(no_frame_start, masm_->pc_offset()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
| 449 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 450 | void FullCodeGenerator::EffectContext::Plug(Variable* var) const { |
| 451 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 455 | void FullCodeGenerator::AccumulatorValueContext::Plug(Variable* var) const { |
| 456 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 457 | codegen()->GetVar(result_register(), var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 461 | void FullCodeGenerator::StackValueContext::Plug(Variable* var) const { |
| 462 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 463 | MemOperand operand = codegen()->VarOperand(var, result_register()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 464 | // Memory operands can be pushed directly. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 465 | __ push(operand); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 469 | void FullCodeGenerator::TestContext::Plug(Variable* var) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 470 | // For simplicity we always test the accumulator register. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 471 | codegen()->GetVar(result_register(), var); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 472 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 473 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 478 | UNREACHABLE(); // Not used on IA32. |
| 479 | } |
| 480 | |
| 481 | |
| 482 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 483 | Heap::RootListIndex index) const { |
| 484 | UNREACHABLE(); // Not used on IA32. |
| 485 | } |
| 486 | |
| 487 | |
| 488 | void FullCodeGenerator::StackValueContext::Plug( |
| 489 | Heap::RootListIndex index) const { |
| 490 | UNREACHABLE(); // Not used on IA32. |
| 491 | } |
| 492 | |
| 493 | |
| 494 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
| 495 | UNREACHABLE(); // Not used on IA32. |
| 496 | } |
| 497 | |
| 498 | |
| 499 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 500 | } |
| 501 | |
| 502 | |
| 503 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 504 | Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 505 | if (lit->IsSmi()) { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 506 | __ SafeMove(result_register(), Immediate(lit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 507 | } else { |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 508 | __ Move(result_register(), Immediate(lit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 509 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | |
| 513 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 514 | if (lit->IsSmi()) { |
| 515 | __ SafePush(Immediate(lit)); |
| 516 | } else { |
| 517 | __ push(Immediate(lit)); |
| 518 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | |
| 522 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 523 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 524 | true, |
| 525 | true_label_, |
| 526 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 527 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 528 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 529 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 530 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 531 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 532 | } else if (lit->IsString()) { |
| 533 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 534 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 535 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 536 | if (true_label_ != fall_through_) __ jmp(true_label_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 537 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 538 | } else if (lit->IsSmi()) { |
| 539 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 540 | if (false_label_ != fall_through_) __ jmp(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 541 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 542 | if (true_label_ != fall_through_) __ jmp(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 543 | } |
| 544 | } else { |
| 545 | // For simplicity we always test the accumulator register. |
| 546 | __ mov(result_register(), lit); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 547 | codegen()->DoTest(this); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
| 551 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 552 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 553 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 554 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 555 | __ Drop(count); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 559 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 560 | int count, |
| 561 | Register reg) const { |
| 562 | ASSERT(count > 0); |
| 563 | __ Drop(count); |
| 564 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 568 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 569 | Register reg) const { |
| 570 | ASSERT(count > 0); |
| 571 | if (count > 1) __ Drop(count - 1); |
| 572 | __ mov(Operand(esp, 0), reg); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 577 | Register reg) const { |
| 578 | ASSERT(count > 0); |
| 579 | // For simplicity we always test the accumulator register. |
| 580 | __ Drop(count); |
| 581 | __ Move(result_register(), reg); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 582 | codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 583 | codegen()->DoTest(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | |
| 587 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 588 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 589 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 590 | __ bind(materialize_true); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 595 | Label* materialize_true, |
| 596 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 597 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 598 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 599 | __ mov(result_register(), isolate()->factory()->true_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 600 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 601 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 602 | __ mov(result_register(), isolate()->factory()->false_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 603 | __ bind(&done); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | void FullCodeGenerator::StackValueContext::Plug( |
| 608 | Label* materialize_true, |
| 609 | Label* materialize_false) const { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 610 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 611 | __ bind(materialize_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 612 | __ push(Immediate(isolate()->factory()->true_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 613 | __ jmp(&done, Label::kNear); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 614 | __ bind(materialize_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 615 | __ push(Immediate(isolate()->factory()->false_value())); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 616 | __ bind(&done); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 621 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 622 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 623 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | |
| 627 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 628 | } |
| 629 | |
| 630 | |
| 631 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 632 | Handle<Object> value = flag |
| 633 | ? isolate()->factory()->true_value() |
| 634 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 635 | __ mov(result_register(), value); |
| 636 | } |
| 637 | |
| 638 | |
| 639 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 640 | Handle<Object> value = flag |
| 641 | ? isolate()->factory()->true_value() |
| 642 | : isolate()->factory()->false_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 643 | __ push(Immediate(value)); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 648 | codegen()->PrepareForBailoutBeforeSplit(condition(), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 649 | true, |
| 650 | true_label_, |
| 651 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 652 | if (flag) { |
| 653 | if (true_label_ != fall_through_) __ jmp(true_label_); |
| 654 | } else { |
| 655 | if (false_label_ != fall_through_) __ jmp(false_label_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
| 659 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 660 | void FullCodeGenerator::DoTest(Expression* condition, |
| 661 | Label* if_true, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 662 | Label* if_false, |
| 663 | Label* fall_through) { |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 664 | Handle<Code> ic = ToBooleanStub::GetUninitialized(isolate()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 665 | CallIC(ic, condition->test_id()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 666 | __ test(result_register(), result_register()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 667 | // The stub returns nonzero for true. |
| 668 | Split(not_zero, if_true, if_false, fall_through); |
| 669 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 670 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 671 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 672 | void FullCodeGenerator::Split(Condition cc, |
| 673 | Label* if_true, |
| 674 | Label* if_false, |
| 675 | Label* fall_through) { |
| 676 | if (if_false == fall_through) { |
| 677 | __ j(cc, if_true); |
| 678 | } else if (if_true == fall_through) { |
| 679 | __ j(NegateCondition(cc), if_false); |
| 680 | } else { |
| 681 | __ j(cc, if_true); |
| 682 | __ jmp(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 687 | MemOperand FullCodeGenerator::StackOperand(Variable* var) { |
| 688 | ASSERT(var->IsStackAllocated()); |
| 689 | // Offset is negative because higher indexes are at lower addresses. |
| 690 | int offset = -var->index() * kPointerSize; |
| 691 | // Adjust by a (parameter or local) base offset. |
| 692 | if (var->IsParameter()) { |
| 693 | offset += (info_->scope()->num_parameters() + 1) * kPointerSize; |
| 694 | } else { |
| 695 | offset += JavaScriptFrameConstants::kLocal0Offset; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 697 | return Operand(ebp, offset); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 701 | MemOperand FullCodeGenerator::VarOperand(Variable* var, Register scratch) { |
| 702 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 703 | if (var->IsContextSlot()) { |
| 704 | int context_chain_length = scope()->ContextChainLength(var->scope()); |
| 705 | __ LoadContext(scratch, context_chain_length); |
| 706 | return ContextOperand(scratch, var->index()); |
| 707 | } else { |
| 708 | return StackOperand(var); |
| 709 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 713 | void FullCodeGenerator::GetVar(Register dest, Variable* var) { |
| 714 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 715 | MemOperand location = VarOperand(var, dest); |
| 716 | __ mov(dest, location); |
| 717 | } |
| 718 | |
| 719 | |
| 720 | void FullCodeGenerator::SetVar(Variable* var, |
| 721 | Register src, |
| 722 | Register scratch0, |
| 723 | Register scratch1) { |
| 724 | ASSERT(var->IsContextSlot() || var->IsStackAllocated()); |
| 725 | ASSERT(!scratch0.is(src)); |
| 726 | ASSERT(!scratch0.is(scratch1)); |
| 727 | ASSERT(!scratch1.is(src)); |
| 728 | MemOperand location = VarOperand(var, scratch0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 729 | __ mov(location, src); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 730 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 731 | // Emit the write barrier code if the location is in the heap. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 732 | if (var->IsContextSlot()) { |
| 733 | int offset = Context::SlotOffset(var->index()); |
| 734 | ASSERT(!scratch0.is(esi) && !src.is(esi) && !scratch1.is(esi)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 735 | __ RecordWriteContextSlot(scratch0, offset, src, scratch1, kDontSaveFPRegs); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | |
| 739 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 740 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(Expression* expr, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 741 | bool should_normalize, |
| 742 | Label* if_true, |
| 743 | Label* if_false) { |
| 744 | // Only prepare for bailouts before splits if we're in a test |
| 745 | // context. Otherwise, we let the Visit function deal with the |
| 746 | // preparation to avoid preparing with the same AST id twice. |
| 747 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 748 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 749 | Label skip; |
| 750 | if (should_normalize) __ jmp(&skip, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 751 | PrepareForBailout(expr, TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 752 | if (should_normalize) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 753 | __ cmp(eax, isolate()->factory()->true_value()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 754 | Split(equal, if_true, if_false, NULL); |
| 755 | __ bind(&skip); |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 760 | void FullCodeGenerator::EmitDebugCheckDeclarationContext(Variable* variable) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 761 | // The variable in the declaration always resides in the current context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 762 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 763 | if (generate_debug_code_) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 764 | // Check that we're not inside a with or catch context. |
| 765 | __ mov(ebx, FieldOperand(esi, HeapObject::kMapOffset)); |
| 766 | __ cmp(ebx, isolate()->factory()->with_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 767 | __ Check(not_equal, kDeclarationInWithContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 768 | __ cmp(ebx, isolate()->factory()->catch_context_map()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 769 | __ Check(not_equal, kDeclarationInCatchContext); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
| 773 | |
| 774 | void FullCodeGenerator::VisitVariableDeclaration( |
| 775 | VariableDeclaration* declaration) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 776 | // If it was not possible to allocate the variable at compile time, we |
| 777 | // need to "declare" it at runtime to make sure it actually exists in the |
| 778 | // local context. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 779 | VariableProxy* proxy = declaration->proxy(); |
| 780 | VariableMode mode = declaration->mode(); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 781 | Variable* variable = proxy->var(); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 782 | bool hole_init = mode == LET || mode == CONST || mode == CONST_LEGACY; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 783 | switch (variable->location()) { |
| 784 | case Variable::UNALLOCATED: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 785 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 786 | globals_->Add(variable->binding_needs_init() |
| 787 | ? isolate()->factory()->the_hole_value() |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 788 | : isolate()->factory()->undefined_value(), zone()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 789 | break; |
| 790 | |
| 791 | case Variable::PARAMETER: |
| 792 | case Variable::LOCAL: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 793 | if (hole_init) { |
| 794 | Comment cmnt(masm_, "[ VariableDeclaration"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 795 | __ mov(StackOperand(variable), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 796 | Immediate(isolate()->factory()->the_hole_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 797 | } |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 798 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 799 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 800 | case Variable::CONTEXT: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 801 | if (hole_init) { |
| 802 | Comment cmnt(masm_, "[ VariableDeclaration"); |
| 803 | EmitDebugCheckDeclarationContext(variable); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 804 | __ mov(ContextOperand(esi, variable->index()), |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 805 | Immediate(isolate()->factory()->the_hole_value())); |
| 806 | // No write barrier since the hole value is in old space. |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 807 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 808 | } |
| 809 | break; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 810 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 811 | case Variable::LOOKUP: { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 812 | Comment cmnt(masm_, "[ VariableDeclaration"); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 813 | __ push(esi); |
| 814 | __ push(Immediate(variable->name())); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 815 | // VariableDeclaration nodes are always introduced in one of four modes. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 816 | ASSERT(IsDeclaredVariableMode(mode)); |
| 817 | PropertyAttributes attr = |
| 818 | IsImmutableVariableMode(mode) ? READ_ONLY : NONE; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 819 | __ push(Immediate(Smi::FromInt(attr))); |
| 820 | // Push initial value, if any. |
| 821 | // Note: For variables we must not push an initial value (such as |
| 822 | // 'undefined') because we may have a (legal) redeclaration and we |
| 823 | // must not destroy the current value. |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 824 | if (hole_init) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 825 | __ push(Immediate(isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 826 | } else { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 827 | __ push(Immediate(Smi::FromInt(0))); // Indicates no initial value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 828 | } |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 829 | __ CallRuntime(Runtime::kHiddenDeclareContextSlot, 4); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 830 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 836 | void FullCodeGenerator::VisitFunctionDeclaration( |
| 837 | FunctionDeclaration* declaration) { |
| 838 | VariableProxy* proxy = declaration->proxy(); |
| 839 | Variable* variable = proxy->var(); |
| 840 | switch (variable->location()) { |
| 841 | case Variable::UNALLOCATED: { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 842 | globals_->Add(variable->name(), zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 843 | Handle<SharedFunctionInfo> function = |
| 844 | Compiler::BuildFunctionInfo(declaration->fun(), script()); |
| 845 | // Check for stack-overflow exception. |
| 846 | if (function.is_null()) return SetStackOverflow(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 847 | globals_->Add(function, zone()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 848 | break; |
| 849 | } |
| 850 | |
| 851 | case Variable::PARAMETER: |
| 852 | case Variable::LOCAL: { |
| 853 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 854 | VisitForAccumulatorValue(declaration->fun()); |
| 855 | __ mov(StackOperand(variable), result_register()); |
| 856 | break; |
| 857 | } |
| 858 | |
| 859 | case Variable::CONTEXT: { |
| 860 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 861 | EmitDebugCheckDeclarationContext(variable); |
| 862 | VisitForAccumulatorValue(declaration->fun()); |
| 863 | __ mov(ContextOperand(esi, variable->index()), result_register()); |
| 864 | // We know that we have written a function, which is not a smi. |
| 865 | __ RecordWriteContextSlot(esi, |
| 866 | Context::SlotOffset(variable->index()), |
| 867 | result_register(), |
| 868 | ecx, |
| 869 | kDontSaveFPRegs, |
| 870 | EMIT_REMEMBERED_SET, |
| 871 | OMIT_SMI_CHECK); |
| 872 | PrepareForBailoutForId(proxy->id(), NO_REGISTERS); |
| 873 | break; |
| 874 | } |
| 875 | |
| 876 | case Variable::LOOKUP: { |
| 877 | Comment cmnt(masm_, "[ FunctionDeclaration"); |
| 878 | __ push(esi); |
| 879 | __ push(Immediate(variable->name())); |
| 880 | __ push(Immediate(Smi::FromInt(NONE))); |
| 881 | VisitForStackValue(declaration->fun()); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 882 | __ CallRuntime(Runtime::kHiddenDeclareContextSlot, 4); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 883 | break; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | |
| 889 | void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 890 | Variable* variable = declaration->proxy()->var(); |
| 891 | ASSERT(variable->location() == Variable::CONTEXT); |
| 892 | ASSERT(variable->interface()->IsFrozen()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 893 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 894 | Comment cmnt(masm_, "[ ModuleDeclaration"); |
| 895 | EmitDebugCheckDeclarationContext(variable); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 896 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 897 | // Load instance object. |
| 898 | __ LoadContext(eax, scope_->ContextChainLength(scope_->GlobalScope())); |
| 899 | __ mov(eax, ContextOperand(eax, variable->interface()->Index())); |
| 900 | __ mov(eax, ContextOperand(eax, Context::EXTENSION_INDEX)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 901 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 902 | // Assign it. |
| 903 | __ mov(ContextOperand(esi, variable->index()), eax); |
| 904 | // We know that we have written a module, which is not a smi. |
| 905 | __ RecordWriteContextSlot(esi, |
| 906 | Context::SlotOffset(variable->index()), |
| 907 | eax, |
| 908 | ecx, |
| 909 | kDontSaveFPRegs, |
| 910 | EMIT_REMEMBERED_SET, |
| 911 | OMIT_SMI_CHECK); |
| 912 | PrepareForBailoutForId(declaration->proxy()->id(), NO_REGISTERS); |
| 913 | |
| 914 | // Traverse into body. |
| 915 | Visit(declaration->module()); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | |
| 919 | void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 920 | VariableProxy* proxy = declaration->proxy(); |
| 921 | Variable* variable = proxy->var(); |
| 922 | switch (variable->location()) { |
| 923 | case Variable::UNALLOCATED: |
| 924 | // TODO(rossberg) |
| 925 | break; |
| 926 | |
| 927 | case Variable::CONTEXT: { |
| 928 | Comment cmnt(masm_, "[ ImportDeclaration"); |
| 929 | EmitDebugCheckDeclarationContext(variable); |
| 930 | // TODO(rossberg) |
| 931 | break; |
| 932 | } |
| 933 | |
| 934 | case Variable::PARAMETER: |
| 935 | case Variable::LOCAL: |
| 936 | case Variable::LOOKUP: |
| 937 | UNREACHABLE(); |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
| 942 | void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 943 | // TODO(rossberg) |
| 944 | } |
| 945 | |
| 946 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 947 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 948 | // Call the runtime to declare the globals. |
| 949 | __ push(esi); // The context is the first argument. |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 950 | __ Push(pairs); |
| 951 | __ Push(Smi::FromInt(DeclareGlobalsFlags())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 952 | __ CallRuntime(Runtime::kHiddenDeclareGlobals, 3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 953 | // Return value is ignored. |
| 954 | } |
| 955 | |
| 956 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 957 | void FullCodeGenerator::DeclareModules(Handle<FixedArray> descriptions) { |
| 958 | // Call the runtime to declare the modules. |
| 959 | __ Push(descriptions); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 960 | __ CallRuntime(Runtime::kHiddenDeclareModules, 1); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 961 | // Return value is ignored. |
| 962 | } |
| 963 | |
| 964 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 965 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
| 966 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 967 | Breakable nested_statement(this, stmt); |
| 968 | SetStatementPosition(stmt); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 969 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 970 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 971 | VisitForStackValue(stmt->tag()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 972 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 973 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 974 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 975 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 976 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 977 | Label next_test; // Recycled for each test. |
| 978 | // Compile all the tests with branches to their bodies. |
| 979 | for (int i = 0; i < clauses->length(); i++) { |
| 980 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 981 | clause->body_target()->Unuse(); |
fschneider@chromium.org | d218783 | 2011-01-26 15:44:20 +0000 | [diff] [blame] | 982 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 983 | // The default is not a test, but remember it as final fall through. |
| 984 | if (clause->is_default()) { |
| 985 | default_clause = clause; |
| 986 | continue; |
| 987 | } |
| 988 | |
| 989 | Comment cmnt(masm_, "[ Case comparison"); |
| 990 | __ bind(&next_test); |
| 991 | next_test.Unuse(); |
| 992 | |
| 993 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 994 | VisitForAccumulatorValue(clause->label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 995 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 996 | // Perform the comparison as if via '==='. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 997 | __ mov(edx, Operand(esp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 998 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 999 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 1000 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1001 | Label slow_case; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1002 | __ mov(ecx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1003 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1004 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1005 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1006 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1007 | __ j(not_equal, &next_test); |
| 1008 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1009 | __ jmp(clause->body_target()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1010 | __ bind(&slow_case); |
| 1011 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1012 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1013 | // Record position before stub call for type feedback. |
| 1014 | SetSourcePosition(clause->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1015 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), Token::EQ_STRICT); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1016 | CallIC(ic, clause->CompareId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1017 | patch_site.EmitPatchInfo(); |
hpayer@chromium.org | 4f99be9 | 2013-12-18 16:23:55 +0000 | [diff] [blame] | 1018 | |
| 1019 | Label skip; |
| 1020 | __ jmp(&skip, Label::kNear); |
| 1021 | PrepareForBailout(clause, TOS_REG); |
| 1022 | __ cmp(eax, isolate()->factory()->true_value()); |
| 1023 | __ j(not_equal, &next_test); |
| 1024 | __ Drop(1); |
| 1025 | __ jmp(clause->body_target()); |
| 1026 | __ bind(&skip); |
| 1027 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1028 | __ test(eax, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1029 | __ j(not_equal, &next_test); |
| 1030 | __ Drop(1); // Switch value is no longer needed. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1031 | __ jmp(clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | // Discard the test value and jump to the default if present, otherwise to |
| 1035 | // the end of the statement. |
| 1036 | __ bind(&next_test); |
| 1037 | __ Drop(1); // Switch value is no longer needed. |
| 1038 | if (default_clause == NULL) { |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1039 | __ jmp(nested_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1040 | } else { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1041 | __ jmp(default_clause->body_target()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | // Compile all the case bodies. |
| 1045 | for (int i = 0; i < clauses->length(); i++) { |
| 1046 | Comment cmnt(masm_, "[ Case body"); |
| 1047 | CaseClause* clause = clauses->at(i); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1048 | __ bind(clause->body_target()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1049 | PrepareForBailoutForId(clause->EntryId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1050 | VisitStatements(clause->statements()); |
| 1051 | } |
| 1052 | |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1053 | __ bind(nested_statement.break_label()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1054 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
| 1059 | Comment cmnt(masm_, "[ ForInStatement"); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1060 | int slot = stmt->ForInFeedbackSlot(); |
| 1061 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1062 | SetStatementPosition(stmt); |
| 1063 | |
| 1064 | Label loop, exit; |
| 1065 | ForIn loop_statement(this, stmt); |
| 1066 | increment_loop_depth(); |
| 1067 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1068 | // Get the object to enumerate over. If the object is null or undefined, skip |
| 1069 | // 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] | 1070 | VisitForAccumulatorValue(stmt->enumerable()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1071 | __ cmp(eax, isolate()->factory()->undefined_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1072 | __ j(equal, &exit); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1073 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1074 | __ j(equal, &exit); |
| 1075 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1076 | PrepareForBailoutForId(stmt->PrepareId(), TOS_REG); |
| 1077 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1078 | // Convert the object to a JS object. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1079 | Label convert, done_convert; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1080 | __ JumpIfSmi(eax, &convert, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1081 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1082 | __ j(above_equal, &done_convert, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1083 | __ bind(&convert); |
| 1084 | __ push(eax); |
| 1085 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1086 | __ bind(&done_convert); |
| 1087 | __ push(eax); |
| 1088 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1089 | // Check for proxies. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1090 | Label call_runtime, use_cache, fixed_array; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1091 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1092 | __ CmpObjectType(eax, LAST_JS_PROXY_TYPE, ecx); |
| 1093 | __ j(below_equal, &call_runtime); |
| 1094 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1095 | // Check cache validity in generated code. This is a fast case for |
| 1096 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 1097 | // guarantee cache validity, call the runtime system to check cache |
| 1098 | // validity or get the property names in a fixed array. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1099 | __ CheckEnumCache(&call_runtime); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1100 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1101 | __ mov(eax, FieldOperand(eax, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1102 | __ jmp(&use_cache, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1103 | |
| 1104 | // Get the set of properties to enumerate. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1105 | __ bind(&call_runtime); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1106 | __ push(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1107 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1108 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 1109 | isolate()->factory()->meta_map()); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1110 | __ j(not_equal, &fixed_array); |
| 1111 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1112 | |
| 1113 | // 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] | 1114 | Label no_descriptors; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1115 | __ bind(&use_cache); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1116 | |
| 1117 | __ EnumLength(edx, eax); |
| 1118 | __ cmp(edx, Immediate(Smi::FromInt(0))); |
| 1119 | __ j(equal, &no_descriptors); |
| 1120 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1121 | __ LoadInstanceDescriptors(eax, ecx); |
yangguo@chromium.org | 304cc33 | 2012-07-24 07:59:48 +0000 | [diff] [blame] | 1122 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheOffset)); |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1123 | __ mov(ecx, FieldOperand(ecx, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1124 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1125 | // Set up the four remaining stack slots. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1126 | __ push(eax); // Map. |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1127 | __ push(ecx); // Enumeration cache. |
| 1128 | __ 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] | 1129 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1130 | __ jmp(&loop); |
| 1131 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1132 | __ bind(&no_descriptors); |
| 1133 | __ add(esp, Immediate(kPointerSize)); |
| 1134 | __ jmp(&exit); |
| 1135 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1136 | // 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] | 1137 | Label non_proxy; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1138 | __ bind(&fixed_array); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1139 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame] | 1140 | Handle<Object> feedback = Handle<Object>( |
| 1141 | Smi::FromInt(TypeFeedbackInfo::kForInFastCaseMarker), |
| 1142 | isolate()); |
| 1143 | StoreFeedbackVectorSlot(slot, feedback); |
| 1144 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1145 | // No need for a write barrier, we are storing a Smi in the feedback vector. |
| 1146 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 1147 | __ mov(FieldOperand(ebx, FixedArray::OffsetOfElementAt(slot)), |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame] | 1148 | Immediate(Smi::FromInt(TypeFeedbackInfo::kForInSlowCaseMarker))); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 1149 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1150 | __ mov(ebx, Immediate(Smi::FromInt(1))); // Smi indicates slow check |
| 1151 | __ mov(ecx, Operand(esp, 0 * kPointerSize)); // Get enumerated object |
| 1152 | STATIC_ASSERT(FIRST_JS_PROXY_TYPE == FIRST_SPEC_OBJECT_TYPE); |
| 1153 | __ CmpObjectType(ecx, LAST_JS_PROXY_TYPE, ecx); |
| 1154 | __ j(above, &non_proxy); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 1155 | __ Move(ebx, Immediate(Smi::FromInt(0))); // Zero indicates proxy |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1156 | __ bind(&non_proxy); |
| 1157 | __ push(ebx); // Smi |
| 1158 | __ push(eax); // Array |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1159 | __ mov(eax, FieldOperand(eax, FixedArray::kLengthOffset)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1160 | __ push(eax); // Fixed array length (as smi). |
| 1161 | __ push(Immediate(Smi::FromInt(0))); // Initial index. |
| 1162 | |
| 1163 | // Generate code for doing the condition check. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1164 | PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1165 | __ bind(&loop); |
| 1166 | __ mov(eax, Operand(esp, 0 * kPointerSize)); // Get the current index. |
| 1167 | __ cmp(eax, Operand(esp, 1 * kPointerSize)); // Compare to the array length. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1168 | __ j(above_equal, loop_statement.break_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1169 | |
| 1170 | // Get the current entry of the array into register ebx. |
| 1171 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 1172 | __ mov(ebx, FieldOperand(ebx, eax, times_2, FixedArray::kHeaderSize)); |
| 1173 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1174 | // 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] | 1175 | // permanent slow case into register edx. |
| 1176 | __ mov(edx, Operand(esp, 3 * kPointerSize)); |
| 1177 | |
| 1178 | // 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] | 1179 | // If not, we may have to filter the key. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1180 | Label update_each; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1181 | __ mov(ecx, Operand(esp, 4 * kPointerSize)); |
| 1182 | __ cmp(edx, FieldOperand(ecx, HeapObject::kMapOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1183 | __ j(equal, &update_each, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1184 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1185 | // For proxies, no filtering is done. |
| 1186 | // TODO(rossberg): What if only a prototype is a proxy? Not specified yet. |
| 1187 | ASSERT(Smi::FromInt(0) == 0); |
| 1188 | __ test(edx, edx); |
| 1189 | __ j(zero, &update_each); |
| 1190 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1191 | // Convert the entry to a string or null if it isn't a property |
| 1192 | // anymore. If the property has been removed while iterating, we |
| 1193 | // just skip it. |
| 1194 | __ push(ecx); // Enumerable. |
| 1195 | __ push(ebx); // Current entry. |
| 1196 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1197 | __ test(eax, eax); |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1198 | __ j(equal, loop_statement.continue_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1199 | __ mov(ebx, eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1200 | |
| 1201 | // Update the 'each' property or variable from the possibly filtered |
| 1202 | // entry in register ebx. |
| 1203 | __ bind(&update_each); |
| 1204 | __ mov(result_register(), ebx); |
| 1205 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1206 | { EffectContext context(this); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1207 | EmitAssignment(stmt->each()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1208 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1209 | |
| 1210 | // Generate code for the body of the loop. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1211 | Visit(stmt->body()); |
| 1212 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1213 | // Generate code for going to the next element by incrementing the |
| 1214 | // index (smi) stored on top of the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1215 | __ bind(loop_statement.continue_label()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1216 | __ add(Operand(esp, 0 * kPointerSize), Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1217 | |
rossberg@chromium.org | cddc71f | 2012-12-07 12:40:13 +0000 | [diff] [blame] | 1218 | EmitBackEdgeBookkeeping(stmt, &loop); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1219 | __ jmp(&loop); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Remove the pointers stored on the stack. |
rossberg@chromium.org | 28a3708 | 2011-08-22 11:03:23 +0000 | [diff] [blame] | 1222 | __ bind(loop_statement.break_label()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1223 | __ add(esp, Immediate(5 * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1224 | |
| 1225 | // Exit and decrement the loop depth. |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 1226 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1227 | __ bind(&exit); |
| 1228 | decrement_loop_depth(); |
| 1229 | } |
| 1230 | |
| 1231 | |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 1232 | void FullCodeGenerator::VisitForOfStatement(ForOfStatement* stmt) { |
| 1233 | Comment cmnt(masm_, "[ ForOfStatement"); |
| 1234 | SetStatementPosition(stmt); |
| 1235 | |
| 1236 | Iteration loop_statement(this, stmt); |
| 1237 | increment_loop_depth(); |
| 1238 | |
| 1239 | // var iterator = iterable[@@iterator]() |
| 1240 | VisitForAccumulatorValue(stmt->assign_iterator()); |
| 1241 | |
| 1242 | // As with for-in, skip the loop if the iterator is null or undefined. |
| 1243 | __ CompareRoot(eax, Heap::kUndefinedValueRootIndex); |
| 1244 | __ j(equal, loop_statement.break_label()); |
| 1245 | __ CompareRoot(eax, Heap::kNullValueRootIndex); |
| 1246 | __ j(equal, loop_statement.break_label()); |
| 1247 | |
| 1248 | // Convert the iterator to a JS object. |
| 1249 | Label convert, done_convert; |
| 1250 | __ JumpIfSmi(eax, &convert); |
| 1251 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 1252 | __ j(above_equal, &done_convert); |
| 1253 | __ bind(&convert); |
| 1254 | __ push(eax); |
| 1255 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION); |
| 1256 | __ bind(&done_convert); |
| 1257 | |
| 1258 | // Loop entry. |
| 1259 | __ bind(loop_statement.continue_label()); |
| 1260 | |
| 1261 | // result = iterator.next() |
| 1262 | VisitForEffect(stmt->next_result()); |
| 1263 | |
| 1264 | // if (result.done) break; |
| 1265 | Label result_not_done; |
| 1266 | VisitForControl(stmt->result_done(), |
| 1267 | loop_statement.break_label(), |
| 1268 | &result_not_done, |
| 1269 | &result_not_done); |
| 1270 | __ bind(&result_not_done); |
| 1271 | |
| 1272 | // each = result.value |
| 1273 | VisitForEffect(stmt->assign_each()); |
| 1274 | |
| 1275 | // Generate code for the body of the loop. |
| 1276 | Visit(stmt->body()); |
| 1277 | |
| 1278 | // Check stack before looping. |
| 1279 | PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS); |
| 1280 | EmitBackEdgeBookkeeping(stmt, loop_statement.continue_label()); |
| 1281 | __ jmp(loop_statement.continue_label()); |
| 1282 | |
| 1283 | // Exit and decrement the loop depth. |
| 1284 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
| 1285 | __ bind(loop_statement.break_label()); |
| 1286 | decrement_loop_depth(); |
| 1287 | } |
| 1288 | |
| 1289 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1290 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 1291 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1292 | // Use the fast case closure allocation code that allocates in new |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1293 | // space for nested functions that don't need literals cloning. If |
| 1294 | // we're running with the --always-opt or the --prepare-always-opt |
| 1295 | // flag, we need to use the runtime function so that the new function |
| 1296 | // we are creating here gets a chance to have its code optimized and |
| 1297 | // doesn't just get a copy of the existing unoptimized code. |
| 1298 | if (!FLAG_always_opt && |
| 1299 | !FLAG_prepare_always_opt && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1300 | !pretenure && |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1301 | scope()->is_function_scope() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1302 | info->num_literals() == 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1303 | FastNewClosureStub stub(info->strict_mode(), info->is_generator()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1304 | __ mov(ebx, Immediate(info)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1305 | __ CallStub(&stub); |
| 1306 | } else { |
| 1307 | __ push(esi); |
| 1308 | __ push(Immediate(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 1309 | __ push(Immediate(pretenure |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1310 | ? isolate()->factory()->true_value() |
| 1311 | : isolate()->factory()->false_value())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1312 | __ CallRuntime(Runtime::kHiddenNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1313 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1314 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 1319 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1320 | EmitVariableLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1324 | void FullCodeGenerator::EmitLoadGlobalCheckExtensions(Variable* var, |
| 1325 | TypeofState typeof_state, |
| 1326 | Label* slow) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1327 | Register context = esi; |
| 1328 | Register temp = edx; |
| 1329 | |
| 1330 | Scope* s = scope(); |
| 1331 | while (s != NULL) { |
| 1332 | if (s->num_heap_slots() > 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1333 | if (s->calls_sloppy_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1334 | // Check that extension is NULL. |
| 1335 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1336 | Immediate(0)); |
| 1337 | __ j(not_equal, slow); |
| 1338 | } |
| 1339 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1340 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1341 | // Walk the rest of the chain without clobbering esi. |
| 1342 | context = temp; |
| 1343 | } |
| 1344 | // If no outer scope calls eval, we do not need to check more |
| 1345 | // context extensions. If we have reached an eval scope, we check |
| 1346 | // all extensions from this point. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1347 | 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] | 1348 | s = s->outer_scope(); |
| 1349 | } |
| 1350 | |
| 1351 | if (s != NULL && s->is_eval_scope()) { |
| 1352 | // Loop up the context chain. There is no frame effect so it is |
| 1353 | // safe to use raw labels here. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1354 | Label next, fast; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1355 | if (!context.is(temp)) { |
| 1356 | __ mov(temp, context); |
| 1357 | } |
| 1358 | __ bind(&next); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1359 | // Terminate at native context. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1360 | __ cmp(FieldOperand(temp, HeapObject::kMapOffset), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1361 | Immediate(isolate()->factory()->native_context_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1362 | __ j(equal, &fast, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1363 | // Check that extension is NULL. |
| 1364 | __ cmp(ContextOperand(temp, Context::EXTENSION_INDEX), Immediate(0)); |
| 1365 | __ j(not_equal, slow); |
| 1366 | // Load next context in chain. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1367 | __ mov(temp, ContextOperand(temp, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1368 | __ jmp(&next); |
| 1369 | __ bind(&fast); |
| 1370 | } |
| 1371 | |
| 1372 | // All extension objects were empty and it is safe to use a global |
| 1373 | // load IC call. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1374 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1375 | __ mov(ecx, var->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1376 | ContextualMode mode = (typeof_state == INSIDE_TYPEOF) |
| 1377 | ? NOT_CONTEXTUAL |
| 1378 | : CONTEXTUAL; |
| 1379 | |
| 1380 | CallLoadIC(mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1384 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions(Variable* var, |
| 1385 | Label* slow) { |
| 1386 | ASSERT(var->IsContextSlot()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1387 | Register context = esi; |
| 1388 | Register temp = ebx; |
| 1389 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1390 | for (Scope* s = scope(); s != var->scope(); s = s->outer_scope()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1391 | if (s->num_heap_slots() > 0) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1392 | if (s->calls_sloppy_eval()) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1393 | // Check that extension is NULL. |
| 1394 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), |
| 1395 | Immediate(0)); |
| 1396 | __ j(not_equal, slow); |
| 1397 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1398 | __ mov(temp, ContextOperand(context, Context::PREVIOUS_INDEX)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1399 | // Walk the rest of the chain without clobbering esi. |
| 1400 | context = temp; |
| 1401 | } |
| 1402 | } |
| 1403 | // Check that last extension is NULL. |
| 1404 | __ cmp(ContextOperand(context, Context::EXTENSION_INDEX), Immediate(0)); |
| 1405 | __ j(not_equal, slow); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1406 | |
| 1407 | // This function is used only for loads, not stores, so it's safe to |
| 1408 | // return an esi-based operand (the write barrier cannot be allowed to |
| 1409 | // destroy the esi register). |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1410 | return ContextOperand(context, var->index()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1414 | void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, |
| 1415 | TypeofState typeof_state, |
| 1416 | Label* slow, |
| 1417 | Label* done) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1418 | // Generate fast-case code for variables that might be shadowed by |
| 1419 | // eval-introduced variables. Eval is used a lot without |
| 1420 | // introducing variables. In those cases, we do not want to |
| 1421 | // perform a runtime call for all variables in the scope |
| 1422 | // containing the eval. |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1423 | if (var->mode() == DYNAMIC_GLOBAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1424 | EmitLoadGlobalCheckExtensions(var, typeof_state, slow); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1425 | __ jmp(done); |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 1426 | } else if (var->mode() == DYNAMIC_LOCAL) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1427 | Variable* local = var->local_if_not_shadowed(); |
| 1428 | __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1429 | if (local->mode() == LET || local->mode() == CONST || |
| 1430 | local->mode() == CONST_LEGACY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1431 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1432 | __ j(not_equal, done); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1433 | if (local->mode() == CONST_LEGACY) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1434 | __ mov(eax, isolate()->factory()->undefined_value()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1435 | } else { // LET || CONST |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1436 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1437 | __ CallRuntime(Runtime::kHiddenThrowReferenceError, 1); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 1438 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1439 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1440 | __ jmp(done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1445 | void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { |
| 1446 | // Record position before possible IC call. |
| 1447 | SetSourcePosition(proxy->position()); |
| 1448 | Variable* var = proxy->var(); |
| 1449 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1450 | // Three cases: global variables, lookup variables, and all other types of |
| 1451 | // variables. |
| 1452 | switch (var->location()) { |
| 1453 | case Variable::UNALLOCATED: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1454 | Comment cmnt(masm_, "[ Global variable"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1455 | // Use inline caching. Variable name is passed in ecx and the global |
| 1456 | // object in eax. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1457 | __ mov(edx, GlobalObjectOperand()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1458 | __ mov(ecx, var->name()); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1459 | CallLoadIC(CONTEXTUAL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1460 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1461 | break; |
| 1462 | } |
| 1463 | |
| 1464 | case Variable::PARAMETER: |
| 1465 | case Variable::LOCAL: |
| 1466 | case Variable::CONTEXT: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1467 | Comment cmnt(masm_, var->IsContextSlot() ? "[ Context variable" |
| 1468 | : "[ Stack variable"); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1469 | if (var->binding_needs_init()) { |
| 1470 | // var->scope() may be NULL when the proxy is located in eval code and |
| 1471 | // refers to a potential outside binding. Currently those bindings are |
| 1472 | // always looked up dynamically, i.e. in that case |
| 1473 | // var->location() == LOOKUP. |
| 1474 | // always holds. |
| 1475 | ASSERT(var->scope() != NULL); |
| 1476 | |
| 1477 | // Check if the binding really needs an initialization check. The check |
| 1478 | // can be skipped in the following situation: we have a LET or CONST |
| 1479 | // binding in harmony mode, both the Variable and the VariableProxy have |
| 1480 | // the same declaration scope (i.e. they are both in global code, in the |
| 1481 | // same function or in the same eval code) and the VariableProxy is in |
| 1482 | // the source physically located after the initializer of the variable. |
| 1483 | // |
| 1484 | // We cannot skip any initialization checks for CONST in non-harmony |
| 1485 | // mode because const variables may be declared but never initialized: |
| 1486 | // if (false) { const x; }; var y = x; |
| 1487 | // |
| 1488 | // The condition on the declaration scopes is a conservative check for |
| 1489 | // nested functions that access a binding and are called before the |
| 1490 | // binding is initialized: |
| 1491 | // function() { f(); let x = 1; function f() { x = 2; } } |
| 1492 | // |
| 1493 | bool skip_init_check; |
| 1494 | if (var->scope()->DeclarationScope() != scope()->DeclarationScope()) { |
| 1495 | skip_init_check = false; |
jkummerow@chromium.org | ac45fed | 2011-11-07 13:11:02 +0000 | [diff] [blame] | 1496 | } else { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1497 | // Check that we always have valid source position. |
| 1498 | ASSERT(var->initializer_position() != RelocInfo::kNoPosition); |
| 1499 | ASSERT(proxy->position() != RelocInfo::kNoPosition); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1500 | skip_init_check = var->mode() != CONST_LEGACY && |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1501 | var->initializer_position() < proxy->position(); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1502 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1503 | |
| 1504 | if (!skip_init_check) { |
| 1505 | // Let and const need a read barrier. |
| 1506 | Label done; |
| 1507 | GetVar(eax, var); |
| 1508 | __ cmp(eax, isolate()->factory()->the_hole_value()); |
| 1509 | __ j(not_equal, &done, Label::kNear); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1510 | if (var->mode() == LET || var->mode() == CONST) { |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1511 | // Throw a reference error when using an uninitialized let/const |
| 1512 | // binding in harmony mode. |
| 1513 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1514 | __ CallRuntime(Runtime::kHiddenThrowReferenceError, 1); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1515 | } else { |
| 1516 | // Uninitalized const bindings outside of harmony mode are unholed. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 1517 | ASSERT(var->mode() == CONST_LEGACY); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1518 | __ mov(eax, isolate()->factory()->undefined_value()); |
| 1519 | } |
| 1520 | __ bind(&done); |
| 1521 | context()->Plug(eax); |
| 1522 | break; |
| 1523 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1524 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1525 | context()->Plug(var); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1526 | break; |
| 1527 | } |
| 1528 | |
| 1529 | case Variable::LOOKUP: { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1530 | Comment cmnt(masm_, "[ Lookup variable"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1531 | Label done, slow; |
| 1532 | // Generate code for loading from variables potentially shadowed |
| 1533 | // by eval-introduced variables. |
| 1534 | EmitDynamicLookupFastCase(var, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1535 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1536 | __ push(esi); // Context. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1537 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1538 | __ CallRuntime(Runtime::kHiddenLoadContextSlot, 2); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1539 | __ bind(&done); |
| 1540 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 1541 | break; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1542 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | |
| 1547 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1548 | Comment cmnt(masm_, "[ RegExpLiteral"); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1549 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1550 | // Registers will be used as follows: |
| 1551 | // edi = JS function. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1552 | // ecx = literals array. |
| 1553 | // ebx = regexp literal. |
| 1554 | // eax = regexp literal clone. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1555 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1556 | __ mov(ecx, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1557 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1558 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1559 | __ mov(ebx, FieldOperand(ecx, literal_offset)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1560 | __ cmp(ebx, isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1561 | __ j(not_equal, &materialized, Label::kNear); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1562 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1563 | // Create regexp literal using runtime function |
| 1564 | // Result will be in eax. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1565 | __ push(ecx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1566 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1567 | __ push(Immediate(expr->pattern())); |
| 1568 | __ push(Immediate(expr->flags())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1569 | __ CallRuntime(Runtime::kHiddenMaterializeRegExpLiteral, 4); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1570 | __ mov(ebx, eax); |
| 1571 | |
| 1572 | __ bind(&materialized); |
| 1573 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1574 | Label allocated, runtime_allocate; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1575 | __ Allocate(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1576 | __ jmp(&allocated); |
| 1577 | |
| 1578 | __ bind(&runtime_allocate); |
| 1579 | __ push(ebx); |
| 1580 | __ push(Immediate(Smi::FromInt(size))); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1581 | __ CallRuntime(Runtime::kHiddenAllocateInNewSpace, 1); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1582 | __ pop(ebx); |
| 1583 | |
| 1584 | __ bind(&allocated); |
| 1585 | // Copy the content into the newly allocated memory. |
| 1586 | // (Unroll copy loop once for better throughput). |
| 1587 | for (int i = 0; i < size - kPointerSize; i += 2 * kPointerSize) { |
| 1588 | __ mov(edx, FieldOperand(ebx, i)); |
| 1589 | __ mov(ecx, FieldOperand(ebx, i + kPointerSize)); |
| 1590 | __ mov(FieldOperand(eax, i), edx); |
| 1591 | __ mov(FieldOperand(eax, i + kPointerSize), ecx); |
| 1592 | } |
| 1593 | if ((size % (2 * kPointerSize)) != 0) { |
| 1594 | __ mov(edx, FieldOperand(ebx, size - kPointerSize)); |
| 1595 | __ mov(FieldOperand(eax, size - kPointerSize), edx); |
| 1596 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1597 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1601 | void FullCodeGenerator::EmitAccessor(Expression* expression) { |
| 1602 | if (expression == NULL) { |
| 1603 | __ push(Immediate(isolate()->factory()->null_value())); |
| 1604 | } else { |
| 1605 | VisitForStackValue(expression); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1610 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1611 | Comment cmnt(masm_, "[ ObjectLiteral"); |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1612 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1613 | expr->BuildConstantProperties(isolate()); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1614 | Handle<FixedArray> constant_properties = expr->constant_properties(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1615 | int flags = expr->fast_elements() |
| 1616 | ? ObjectLiteral::kFastElements |
| 1617 | : ObjectLiteral::kNoFlags; |
| 1618 | flags |= expr->has_function() |
| 1619 | ? ObjectLiteral::kHasFunction |
| 1620 | : ObjectLiteral::kNoFlags; |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1621 | int properties_count = constant_properties->length() / 2; |
titzer@chromium.org | bc17605 | 2014-03-05 15:10:53 +0000 | [diff] [blame] | 1622 | if (expr->may_store_doubles() || expr->depth() > 1 || Serializer::enabled() || |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1623 | flags != ObjectLiteral::kFastElements || |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1624 | properties_count > FastCloneShallowObjectStub::kMaximumClonedProperties) { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1625 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1626 | __ push(FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1627 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1628 | __ push(Immediate(constant_properties)); |
| 1629 | __ push(Immediate(Smi::FromInt(flags))); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1630 | __ CallRuntime(Runtime::kHiddenCreateObjectLiteral, 4); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1631 | } else { |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1632 | __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1633 | __ mov(eax, FieldOperand(edi, JSFunction::kLiteralsOffset)); |
| 1634 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1635 | __ mov(ecx, Immediate(constant_properties)); |
| 1636 | __ mov(edx, Immediate(Smi::FromInt(flags))); |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 1637 | FastCloneShallowObjectStub stub(properties_count); |
| 1638 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | // If result_saved is true the result is on top of the stack. If |
| 1642 | // result_saved is false the result is in eax. |
| 1643 | bool result_saved = false; |
| 1644 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1645 | // Mark all computed expressions that are bound to a key that |
| 1646 | // is shadowed by a later occurrence of the same key. For the |
| 1647 | // marked expressions, no store code is emitted. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1648 | expr->CalculateEmitStore(zone()); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1649 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1650 | AccessorTable accessor_table(zone()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1651 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1652 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1653 | if (property->IsCompileTimeValue()) continue; |
| 1654 | |
| 1655 | Literal* key = property->key(); |
| 1656 | Expression* value = property->value(); |
| 1657 | if (!result_saved) { |
| 1658 | __ push(eax); // Save result on the stack |
| 1659 | result_saved = true; |
| 1660 | } |
| 1661 | switch (property->kind()) { |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1662 | case ObjectLiteral::Property::CONSTANT: |
| 1663 | UNREACHABLE(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1664 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1665 | ASSERT(!CompileTimeValue::IsCompileTimeValue(value)); |
| 1666 | // Fall through. |
| 1667 | case ObjectLiteral::Property::COMPUTED: |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1668 | if (key->value()->IsInternalizedString()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1669 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1670 | VisitForAccumulatorValue(value); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1671 | __ mov(ecx, Immediate(key->value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1672 | __ mov(edx, Operand(esp, 0)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 1673 | CallStoreIC(key->LiteralFeedbackId()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1675 | } else { |
| 1676 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1677 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1678 | break; |
| 1679 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1680 | __ push(Operand(esp, 0)); // Duplicate receiver. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1681 | VisitForStackValue(key); |
| 1682 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1683 | if (property->emit_store()) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1684 | __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| 1685 | __ CallRuntime(Runtime::kSetProperty, 4); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1686 | } else { |
| 1687 | __ Drop(3); |
| 1688 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1689 | break; |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1690 | case ObjectLiteral::Property::PROTOTYPE: |
| 1691 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1692 | VisitForStackValue(value); |
| 1693 | if (property->emit_store()) { |
| 1694 | __ CallRuntime(Runtime::kSetPrototype, 2); |
| 1695 | } else { |
| 1696 | __ Drop(2); |
| 1697 | } |
| 1698 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1699 | case ObjectLiteral::Property::GETTER: |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1700 | accessor_table.lookup(key)->second->getter = value; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1701 | break; |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1702 | case ObjectLiteral::Property::SETTER: |
| 1703 | accessor_table.lookup(key)->second->setter = value; |
| 1704 | break; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1705 | } |
| 1706 | } |
| 1707 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 1708 | // Emit code to define accessors, using only a single call to the runtime for |
| 1709 | // each pair of corresponding getters and setters. |
| 1710 | for (AccessorTable::Iterator it = accessor_table.begin(); |
| 1711 | it != accessor_table.end(); |
| 1712 | ++it) { |
| 1713 | __ push(Operand(esp, 0)); // Duplicate receiver. |
| 1714 | VisitForStackValue(it->first); |
| 1715 | EmitAccessor(it->second->getter); |
| 1716 | EmitAccessor(it->second->setter); |
| 1717 | __ push(Immediate(Smi::FromInt(NONE))); |
| 1718 | __ CallRuntime(Runtime::kDefineOrRedefineAccessorProperty, 5); |
| 1719 | } |
| 1720 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1721 | if (expr->has_function()) { |
| 1722 | ASSERT(result_saved); |
| 1723 | __ push(Operand(esp, 0)); |
| 1724 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1725 | } |
| 1726 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1727 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1728 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1729 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1730 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1731 | } |
| 1732 | } |
| 1733 | |
| 1734 | |
| 1735 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1736 | Comment cmnt(masm_, "[ ArrayLiteral"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1737 | |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1738 | expr->BuildConstantElements(isolate()); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1739 | int flags = expr->depth() == 1 |
| 1740 | ? ArrayLiteral::kShallowElements |
| 1741 | : ArrayLiteral::kNoFlags; |
| 1742 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1743 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1744 | int length = subexprs->length(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1745 | Handle<FixedArray> constant_elements = expr->constant_elements(); |
| 1746 | ASSERT_EQ(2, constant_elements->length()); |
| 1747 | ElementsKind constant_elements_kind = |
| 1748 | static_cast<ElementsKind>(Smi::cast(constant_elements->get(0))->value()); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1749 | bool has_constant_fast_elements = |
| 1750 | IsFastObjectElementsKind(constant_elements_kind); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1751 | Handle<FixedArrayBase> constant_elements_values( |
| 1752 | FixedArrayBase::cast(constant_elements->get(1))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1753 | |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 1754 | AllocationSiteMode allocation_site_mode = TRACK_ALLOCATION_SITE; |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1755 | if (has_constant_fast_elements && !FLAG_allocation_site_pretenuring) { |
| 1756 | // If the only customer of allocation sites is transitioning, then |
| 1757 | // we can turn it off if we don't have anywhere else to transition to. |
| 1758 | allocation_site_mode = DONT_TRACK_ALLOCATION_SITE; |
| 1759 | } |
| 1760 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1761 | Heap* heap = isolate()->heap(); |
| 1762 | if (has_constant_fast_elements && |
| 1763 | constant_elements_values->map() == heap->fixed_cow_array_map()) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1764 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1765 | // change, so it's possible to specialize the stub in advance. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1766 | __ IncrementCounter(isolate()->counters()->cow_arrays_created_stub(), 1); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1767 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1768 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1769 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1770 | __ mov(ecx, Immediate(constant_elements)); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1771 | FastCloneShallowArrayStub stub( |
| 1772 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, |
machenbach@chromium.org | c86e8c2 | 2013-11-27 15:11:04 +0000 | [diff] [blame] | 1773 | allocation_site_mode, |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1774 | length); |
| 1775 | __ CallStub(&stub); |
machenbach@chromium.org | 7ff7607 | 2013-11-21 09:47:43 +0000 | [diff] [blame] | 1776 | } else if (expr->depth() > 1 || Serializer::enabled() || |
verwaest@chromium.org | 057bd50 | 2013-11-06 12:03:29 +0000 | [diff] [blame] | 1777 | length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1778 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1779 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1780 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
| 1781 | __ push(Immediate(constant_elements)); |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 1782 | __ push(Immediate(Smi::FromInt(flags))); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1783 | __ CallRuntime(Runtime::kHiddenCreateArrayLiteral, 4); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1784 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1785 | ASSERT(IsFastSmiOrObjectElementsKind(constant_elements_kind) || |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1786 | FLAG_smi_only_arrays); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1787 | FastCloneShallowArrayStub::Mode mode = |
| 1788 | FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS; |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1789 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1790 | // If the elements are already FAST_*_ELEMENTS, the boilerplate cannot |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1791 | // change, so it's possible to specialize the stub in advance. |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1792 | if (has_constant_fast_elements) { |
| 1793 | mode = FastCloneShallowArrayStub::CLONE_ELEMENTS; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1796 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1797 | __ mov(eax, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 1798 | __ mov(ebx, Immediate(Smi::FromInt(expr->literal_index()))); |
| 1799 | __ mov(ecx, Immediate(constant_elements)); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 1800 | FastCloneShallowArrayStub stub(mode, allocation_site_mode, length); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1801 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | bool result_saved = false; // Is the result saved to the stack? |
| 1805 | |
| 1806 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1807 | // them into the newly cloned array. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1808 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1809 | Expression* subexpr = subexprs->at(i); |
| 1810 | // If the subexpression is a literal or a simple materialized literal it |
| 1811 | // is already set in the cloned array. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1812 | if (CompileTimeValue::IsCompileTimeValue(subexpr)) continue; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1813 | |
| 1814 | if (!result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1815 | __ push(eax); // array literal. |
| 1816 | __ push(Immediate(Smi::FromInt(expr->literal_index()))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1817 | result_saved = true; |
| 1818 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1819 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1820 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1821 | if (IsFastObjectElementsKind(constant_elements_kind)) { |
| 1822 | // Fast-case array literal with ElementsKind of FAST_*_ELEMENTS, they |
| 1823 | // cannot transition and don't need to call the runtime stub. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1824 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1825 | __ mov(ebx, Operand(esp, kPointerSize)); // Copy of array literal. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1826 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 1827 | // Store the subexpression value in the array's elements. |
| 1828 | __ mov(FieldOperand(ebx, offset), result_register()); |
| 1829 | // Update the write barrier for the array store. |
| 1830 | __ RecordWriteField(ebx, offset, result_register(), ecx, |
| 1831 | kDontSaveFPRegs, |
| 1832 | EMIT_REMEMBERED_SET, |
| 1833 | INLINE_SMI_CHECK); |
| 1834 | } else { |
| 1835 | // Store the subexpression value in the array's elements. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1836 | __ mov(ecx, Immediate(Smi::FromInt(i))); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1837 | StoreArrayLiteralElementStub stub; |
| 1838 | __ CallStub(&stub); |
| 1839 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1840 | |
| 1841 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | if (result_saved) { |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1845 | __ add(esp, Immediate(kPointerSize)); // literal index |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1846 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1847 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1848 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1853 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 1854 | ASSERT(expr->target()->IsValidReferenceExpression()); |
machenbach@chromium.org | 2904d1a | 2014-03-18 01:05:18 +0000 | [diff] [blame] | 1855 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1856 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1857 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1858 | // 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] | 1859 | // slot. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1860 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1861 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1862 | Property* property = expr->target()->AsProperty(); |
| 1863 | if (property != NULL) { |
| 1864 | assign_type = (property->key()->IsPropertyName()) |
| 1865 | ? NAMED_PROPERTY |
| 1866 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | // Evaluate LHS expression. |
| 1870 | switch (assign_type) { |
| 1871 | case VARIABLE: |
| 1872 | // Nothing to do here. |
| 1873 | break; |
| 1874 | case NAMED_PROPERTY: |
| 1875 | if (expr->is_compound()) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1876 | // We need the receiver both on the stack and in edx. |
| 1877 | VisitForStackValue(property->obj()); |
| 1878 | __ mov(edx, Operand(esp, 0)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1879 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1880 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1881 | } |
| 1882 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1883 | case KEYED_PROPERTY: { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1884 | if (expr->is_compound()) { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1885 | VisitForStackValue(property->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 1886 | VisitForStackValue(property->key()); |
| 1887 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 1888 | __ mov(ecx, Operand(esp, 0)); // Key. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1889 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1890 | VisitForStackValue(property->obj()); |
| 1891 | VisitForStackValue(property->key()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1892 | } |
| 1893 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1894 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1897 | // For compound assignments we need another deoptimization point after the |
| 1898 | // variable/property load. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1899 | if (expr->is_compound()) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1900 | AccumulatorValueContext result_context(this); |
| 1901 | { AccumulatorValueContext left_operand_context(this); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1902 | switch (assign_type) { |
| 1903 | case VARIABLE: |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 1904 | EmitVariableLoad(expr->target()->AsVariableProxy()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1905 | PrepareForBailout(expr->target(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | case NAMED_PROPERTY: |
| 1908 | EmitNamedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1909 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1910 | break; |
| 1911 | case KEYED_PROPERTY: |
| 1912 | EmitKeyedPropertyLoad(property); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1913 | PrepareForBailoutForId(property->LoadId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1914 | break; |
| 1915 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1916 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1917 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1918 | Token::Value op = expr->binary_op(); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1919 | __ push(eax); // Left operand goes on the stack. |
| 1920 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1921 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1922 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1923 | ? OVERWRITE_RIGHT |
| 1924 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1925 | SetSourcePosition(expr->position() + 1); |
| 1926 | if (ShouldInlineSmiCase(op)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1927 | EmitInlineSmiBinaryOp(expr->binary_operation(), |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1928 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1929 | mode, |
| 1930 | expr->target(), |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1931 | expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1932 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1933 | EmitBinaryOp(expr->binary_operation(), op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1934 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1935 | |
| 1936 | // Deoptimization point in case the binary operation may have side effects. |
| 1937 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1938 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1939 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | // Record source position before possible IC call. |
| 1943 | SetSourcePosition(expr->position()); |
| 1944 | |
| 1945 | // Store the value. |
| 1946 | switch (assign_type) { |
| 1947 | case VARIABLE: |
| 1948 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1949 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1950 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1951 | context()->Plug(eax); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1952 | break; |
| 1953 | case NAMED_PROPERTY: |
| 1954 | EmitNamedPropertyAssignment(expr); |
| 1955 | break; |
| 1956 | case KEYED_PROPERTY: |
| 1957 | EmitKeyedPropertyAssignment(expr); |
| 1958 | break; |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1963 | void FullCodeGenerator::VisitYield(Yield* expr) { |
| 1964 | Comment cmnt(masm_, "[ Yield"); |
| 1965 | // Evaluate yielded value first; the initial iterator definition depends on |
| 1966 | // this. It stays on the stack while we update the iterator. |
| 1967 | VisitForStackValue(expr->expression()); |
| 1968 | |
| 1969 | switch (expr->yield_kind()) { |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 1970 | case Yield::SUSPEND: |
| 1971 | // Pop value from top-of-stack slot; box result into result register. |
| 1972 | EmitCreateIteratorResult(false); |
| 1973 | __ push(result_register()); |
| 1974 | // Fall through. |
| 1975 | case Yield::INITIAL: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1976 | Label suspend, continuation, post_runtime, resume; |
| 1977 | |
| 1978 | __ jmp(&suspend); |
| 1979 | |
| 1980 | __ bind(&continuation); |
| 1981 | __ jmp(&resume); |
| 1982 | |
| 1983 | __ bind(&suspend); |
| 1984 | VisitForAccumulatorValue(expr->generator_object()); |
| 1985 | ASSERT(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); |
| 1986 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 1987 | Immediate(Smi::FromInt(continuation.pos()))); |
| 1988 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 1989 | __ mov(ecx, esi); |
| 1990 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 1991 | kDontSaveFPRegs); |
| 1992 | __ lea(ebx, Operand(ebp, StandardFrameConstants::kExpressionsOffset)); |
| 1993 | __ cmp(esp, ebx); |
| 1994 | __ j(equal, &post_runtime); |
| 1995 | __ push(eax); // generator object |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 1996 | __ CallRuntime(Runtime::kHiddenSuspendJSGeneratorObject, 1); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1997 | __ mov(context_register(), |
| 1998 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1999 | __ bind(&post_runtime); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2000 | __ pop(result_register()); |
| 2001 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2002 | |
| 2003 | __ bind(&resume); |
| 2004 | context()->Plug(result_register()); |
| 2005 | break; |
| 2006 | } |
| 2007 | |
| 2008 | case Yield::FINAL: { |
| 2009 | VisitForAccumulatorValue(expr->generator_object()); |
| 2010 | __ mov(FieldOperand(result_register(), |
| 2011 | JSGeneratorObject::kContinuationOffset), |
| 2012 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2013 | // Pop value from top-of-stack slot, box result into result register. |
| 2014 | EmitCreateIteratorResult(true); |
| 2015 | EmitUnwindBeforeReturn(); |
| 2016 | EmitReturnSequence(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2020 | case Yield::DELEGATING: { |
| 2021 | VisitForStackValue(expr->generator_object()); |
| 2022 | |
| 2023 | // Initial stack layout is as follows: |
| 2024 | // [sp + 1 * kPointerSize] iter |
| 2025 | // [sp + 0 * kPointerSize] g |
| 2026 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2027 | Label l_catch, l_try, l_suspend, l_continuation, l_resume; |
| 2028 | Label l_next, l_call, l_loop; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2029 | // Initial send value is undefined. |
| 2030 | __ mov(eax, isolate()->factory()->undefined_value()); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2031 | __ jmp(&l_next); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2032 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2033 | // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2034 | __ bind(&l_catch); |
| 2035 | handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2036 | __ mov(ecx, isolate()->factory()->throw_string()); // "throw" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2037 | __ push(ecx); // "throw" |
| 2038 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2039 | __ push(eax); // exception |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2040 | __ jmp(&l_call); |
| 2041 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2042 | // try { received = %yield result } |
| 2043 | // Shuffle the received result above a try handler and yield it without |
| 2044 | // re-boxing. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2045 | __ bind(&l_try); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2046 | __ pop(eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2047 | __ PushTryHandler(StackHandler::CATCH, expr->index()); |
| 2048 | const int handler_size = StackHandlerConstants::kSize; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2049 | __ push(eax); // result |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2050 | __ jmp(&l_suspend); |
| 2051 | __ bind(&l_continuation); |
| 2052 | __ jmp(&l_resume); |
| 2053 | __ bind(&l_suspend); |
| 2054 | const int generator_object_depth = kPointerSize + handler_size; |
| 2055 | __ mov(eax, Operand(esp, generator_object_depth)); |
| 2056 | __ push(eax); // g |
| 2057 | ASSERT(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2058 | __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 2059 | Immediate(Smi::FromInt(l_continuation.pos()))); |
| 2060 | __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 2061 | __ mov(ecx, esi); |
| 2062 | __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 2063 | kDontSaveFPRegs); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2064 | __ CallRuntime(Runtime::kHiddenSuspendJSGeneratorObject, 1); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2065 | __ mov(context_register(), |
| 2066 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2067 | __ pop(eax); // result |
| 2068 | EmitReturnSequence(); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2069 | __ bind(&l_resume); // received in eax |
| 2070 | __ PopTryHandler(); |
| 2071 | |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2072 | // receiver = iter; f = iter.next; arg = received; |
| 2073 | __ bind(&l_next); |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2074 | __ mov(ecx, isolate()->factory()->next_string()); // "next" |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2075 | __ push(ecx); |
| 2076 | __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2077 | __ push(eax); // received |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2078 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2079 | // result = receiver[f](arg); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2080 | __ bind(&l_call); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2081 | __ mov(edx, Operand(esp, kPointerSize)); |
| 2082 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2083 | CallIC(ic, TypeFeedbackId::None()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2084 | __ mov(edi, eax); |
| 2085 | __ mov(Operand(esp, 2 * kPointerSize), edi); |
| 2086 | CallFunctionStub stub(1, CALL_AS_METHOD); |
| 2087 | __ CallStub(&stub); |
| 2088 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2089 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2090 | __ Drop(1); // The function is still on the stack; drop it. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2091 | |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2092 | // if (!result.done) goto l_try; |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2093 | __ bind(&l_loop); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2094 | __ push(eax); // save result |
| 2095 | __ mov(edx, eax); // result |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2096 | __ mov(ecx, isolate()->factory()->done_string()); // "done" |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2097 | CallLoadIC(NOT_CONTEXTUAL); // result.done in eax |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2098 | Handle<Code> bool_ic = ToBooleanStub::GetUninitialized(isolate()); |
| 2099 | CallIC(bool_ic); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2100 | __ test(eax, eax); |
| 2101 | __ j(zero, &l_try); |
| 2102 | |
| 2103 | // result.value |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2104 | __ pop(edx); // result |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 2105 | __ mov(ecx, isolate()->factory()->value_string()); // "value" |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2106 | CallLoadIC(NOT_CONTEXTUAL); // result.value in eax |
| 2107 | context()->DropAndPlug(2, eax); // drop iter and g |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2108 | break; |
| 2109 | } |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2114 | void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
| 2115 | Expression *value, |
| 2116 | JSGeneratorObject::ResumeMode resume_mode) { |
| 2117 | // The value stays in eax, and is ultimately read by the resumed generator, as |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2118 | // if CallRuntime(Runtime::kHiddenSuspendJSGeneratorObject) returned it. Or it |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2119 | // is read to throw the value when the resumed generator is already closed. |
| 2120 | // 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] | 2121 | VisitForStackValue(generator); |
| 2122 | VisitForAccumulatorValue(value); |
| 2123 | __ pop(ebx); |
| 2124 | |
| 2125 | // Check generator state. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2126 | Label wrong_state, closed_state, done; |
| 2127 | STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting < 0); |
| 2128 | STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed == 0); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2129 | __ cmp(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2130 | Immediate(Smi::FromInt(0))); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2131 | __ j(equal, &closed_state); |
| 2132 | __ j(less, &wrong_state); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2133 | |
| 2134 | // Load suspended function and context. |
| 2135 | __ mov(esi, FieldOperand(ebx, JSGeneratorObject::kContextOffset)); |
| 2136 | __ mov(edi, FieldOperand(ebx, JSGeneratorObject::kFunctionOffset)); |
| 2137 | |
| 2138 | // Push receiver. |
| 2139 | __ push(FieldOperand(ebx, JSGeneratorObject::kReceiverOffset)); |
| 2140 | |
| 2141 | // Push holes for arguments to generator function. |
| 2142 | __ mov(edx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2143 | __ mov(edx, |
| 2144 | FieldOperand(edx, SharedFunctionInfo::kFormalParameterCountOffset)); |
| 2145 | __ mov(ecx, isolate()->factory()->the_hole_value()); |
| 2146 | Label push_argument_holes, push_frame; |
| 2147 | __ bind(&push_argument_holes); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2148 | __ sub(edx, Immediate(Smi::FromInt(1))); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2149 | __ j(carry, &push_frame); |
| 2150 | __ push(ecx); |
| 2151 | __ jmp(&push_argument_holes); |
| 2152 | |
| 2153 | // Enter a new JavaScript frame, and initialize its slots as they were when |
| 2154 | // the generator was suspended. |
| 2155 | Label resume_frame; |
| 2156 | __ bind(&push_frame); |
| 2157 | __ call(&resume_frame); |
| 2158 | __ jmp(&done); |
| 2159 | __ bind(&resume_frame); |
| 2160 | __ push(ebp); // Caller's frame pointer. |
| 2161 | __ mov(ebp, esp); |
| 2162 | __ push(esi); // Callee's context. |
| 2163 | __ push(edi); // Callee's JS Function. |
| 2164 | |
| 2165 | // Load the operand stack size. |
| 2166 | __ mov(edx, FieldOperand(ebx, JSGeneratorObject::kOperandStackOffset)); |
| 2167 | __ mov(edx, FieldOperand(edx, FixedArray::kLengthOffset)); |
| 2168 | __ SmiUntag(edx); |
| 2169 | |
| 2170 | // If we are sending a value and there is no operand stack, we can jump back |
| 2171 | // in directly. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 2172 | if (resume_mode == JSGeneratorObject::NEXT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2173 | Label slow_resume; |
| 2174 | __ cmp(edx, Immediate(0)); |
| 2175 | __ j(not_zero, &slow_resume); |
| 2176 | __ mov(edx, FieldOperand(edi, JSFunction::kCodeEntryOffset)); |
| 2177 | __ mov(ecx, FieldOperand(ebx, JSGeneratorObject::kContinuationOffset)); |
| 2178 | __ SmiUntag(ecx); |
| 2179 | __ add(edx, ecx); |
| 2180 | __ mov(FieldOperand(ebx, JSGeneratorObject::kContinuationOffset), |
| 2181 | Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorExecuting))); |
| 2182 | __ jmp(edx); |
| 2183 | __ bind(&slow_resume); |
| 2184 | } |
| 2185 | |
| 2186 | // Otherwise, we push holes for the operand stack and call the runtime to fix |
| 2187 | // up the stack and the handlers. |
| 2188 | Label push_operand_holes, call_resume; |
| 2189 | __ bind(&push_operand_holes); |
| 2190 | __ sub(edx, Immediate(1)); |
| 2191 | __ j(carry, &call_resume); |
| 2192 | __ push(ecx); |
| 2193 | __ jmp(&push_operand_holes); |
| 2194 | __ bind(&call_resume); |
| 2195 | __ push(ebx); |
| 2196 | __ push(result_register()); |
| 2197 | __ Push(Smi::FromInt(resume_mode)); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2198 | __ CallRuntime(Runtime::kHiddenResumeJSGeneratorObject, 3); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2199 | // Not reached: the runtime call returns elsewhere. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2200 | __ Abort(kGeneratorFailedToResume); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2201 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2202 | // Reach here when generator is closed. |
| 2203 | __ bind(&closed_state); |
| 2204 | if (resume_mode == JSGeneratorObject::NEXT) { |
| 2205 | // Return completed iterator result when generator is closed. |
| 2206 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 2207 | // Pop value from top-of-stack slot; box result into result register. |
| 2208 | EmitCreateIteratorResult(true); |
| 2209 | } else { |
| 2210 | // Throw the provided value. |
| 2211 | __ push(eax); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2212 | __ CallRuntime(Runtime::kHiddenThrow, 1); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2213 | } |
| 2214 | __ jmp(&done); |
| 2215 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2216 | // Throw error if we attempt to operate on a running generator. |
| 2217 | __ bind(&wrong_state); |
| 2218 | __ push(ebx); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2219 | __ CallRuntime(Runtime::kHiddenThrowGeneratorStateError, 1); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2220 | |
| 2221 | __ bind(&done); |
| 2222 | context()->Plug(result_register()); |
| 2223 | } |
| 2224 | |
| 2225 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2226 | void FullCodeGenerator::EmitCreateIteratorResult(bool done) { |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2227 | Label gc_required; |
| 2228 | Label allocated; |
| 2229 | |
| 2230 | Handle<Map> map(isolate()->native_context()->generator_result_map()); |
| 2231 | |
| 2232 | __ Allocate(map->instance_size(), eax, ecx, edx, &gc_required, TAG_OBJECT); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2233 | __ jmp(&allocated); |
| 2234 | |
| 2235 | __ bind(&gc_required); |
| 2236 | __ Push(Smi::FromInt(map->instance_size())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2237 | __ CallRuntime(Runtime::kHiddenAllocateInNewSpace, 1); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2238 | __ mov(context_register(), |
| 2239 | Operand(ebp, StandardFrameConstants::kContextOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2240 | |
| 2241 | __ bind(&allocated); |
| 2242 | __ mov(ebx, map); |
| 2243 | __ pop(ecx); |
| 2244 | __ mov(edx, isolate()->factory()->ToBoolean(done)); |
| 2245 | ASSERT_EQ(map->instance_size(), 5 * kPointerSize); |
| 2246 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2247 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2248 | isolate()->factory()->empty_fixed_array()); |
| 2249 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2250 | isolate()->factory()->empty_fixed_array()); |
| 2251 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2252 | __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2253 | |
| 2254 | // Only the value field needs a write barrier, as the other values are in the |
| 2255 | // root set. |
| 2256 | __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2257 | ecx, edx, kDontSaveFPRegs); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2261 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 2262 | SetSourcePosition(prop->position()); |
| 2263 | Literal* key = prop->key()->AsLiteral(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2264 | ASSERT(!key->value()->IsSmi()); |
| 2265 | __ mov(ecx, Immediate(key->value())); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2266 | CallLoadIC(NOT_CONTEXTUAL, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 2271 | SetSourcePosition(prop->position()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2272 | Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Initialize(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2273 | CallIC(ic, prop->PropertyFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2277 | void FullCodeGenerator::EmitInlineSmiBinaryOp(BinaryOperation* expr, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2278 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2279 | OverwriteMode mode, |
| 2280 | Expression* left, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2281 | Expression* right) { |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2282 | // Do combined smi check of the operands. Left operand is on the |
| 2283 | // stack. Right operand is in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2284 | Label smi_case, done, stub_call; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2285 | __ pop(edx); |
| 2286 | __ mov(ecx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2287 | __ or_(eax, edx); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2288 | JumpPatchSite patch_site(masm_); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2289 | patch_site.EmitJumpIfSmi(eax, &smi_case, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2290 | |
| 2291 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | __ mov(eax, ecx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2293 | BinaryOpICStub stub(op, mode); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2294 | CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2295 | patch_site.EmitPatchInfo(); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2296 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2297 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2298 | // Smi case. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2299 | __ bind(&smi_case); |
| 2300 | __ mov(eax, edx); // Copy left operand in case of a stub call. |
| 2301 | |
| 2302 | switch (op) { |
| 2303 | case Token::SAR: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2304 | __ SmiUntag(ecx); |
| 2305 | __ sar_cl(eax); // No checks of result necessary |
machenbach@chromium.org | ca2f204 | 2014-03-10 10:03:12 +0000 | [diff] [blame] | 2306 | __ and_(eax, Immediate(~kSmiTagMask)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2307 | break; |
| 2308 | case Token::SHL: { |
| 2309 | Label result_ok; |
| 2310 | __ SmiUntag(eax); |
| 2311 | __ SmiUntag(ecx); |
| 2312 | __ shl_cl(eax); |
| 2313 | // Check that the *signed* result fits in a smi. |
| 2314 | __ cmp(eax, 0xc0000000); |
| 2315 | __ j(positive, &result_ok); |
| 2316 | __ SmiTag(ecx); |
| 2317 | __ jmp(&stub_call); |
| 2318 | __ bind(&result_ok); |
| 2319 | __ SmiTag(eax); |
| 2320 | break; |
| 2321 | } |
| 2322 | case Token::SHR: { |
| 2323 | Label result_ok; |
| 2324 | __ SmiUntag(eax); |
| 2325 | __ SmiUntag(ecx); |
| 2326 | __ shr_cl(eax); |
| 2327 | __ test(eax, Immediate(0xc0000000)); |
| 2328 | __ j(zero, &result_ok); |
| 2329 | __ SmiTag(ecx); |
| 2330 | __ jmp(&stub_call); |
| 2331 | __ bind(&result_ok); |
| 2332 | __ SmiTag(eax); |
| 2333 | break; |
| 2334 | } |
| 2335 | case Token::ADD: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2336 | __ add(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2337 | __ j(overflow, &stub_call); |
| 2338 | break; |
| 2339 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2340 | __ sub(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2341 | __ j(overflow, &stub_call); |
| 2342 | break; |
| 2343 | case Token::MUL: { |
| 2344 | __ SmiUntag(eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2345 | __ imul(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2346 | __ j(overflow, &stub_call); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2347 | __ test(eax, eax); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2348 | __ j(not_zero, &done, Label::kNear); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2349 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2350 | __ or_(ebx, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2351 | __ j(negative, &stub_call); |
| 2352 | break; |
| 2353 | } |
| 2354 | case Token::BIT_OR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2355 | __ or_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2356 | break; |
| 2357 | case Token::BIT_AND: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2358 | __ and_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2359 | break; |
| 2360 | case Token::BIT_XOR: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2361 | __ xor_(eax, ecx); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2362 | break; |
| 2363 | default: |
| 2364 | UNREACHABLE(); |
| 2365 | } |
| 2366 | |
| 2367 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2368 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
| 2371 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 2372 | void FullCodeGenerator::EmitBinaryOp(BinaryOperation* expr, |
| 2373 | Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2374 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2375 | __ pop(edx); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2376 | BinaryOpICStub stub(op, mode); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2377 | JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2378 | CallIC(stub.GetCode(isolate()), expr->BinaryOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2379 | patch_site.EmitPatchInfo(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2380 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2384 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 2385 | ASSERT(expr->IsValidReferenceExpression()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2386 | |
| 2387 | // 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] | 2388 | // slot. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2389 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2390 | LhsKind assign_type = VARIABLE; |
| 2391 | Property* prop = expr->AsProperty(); |
| 2392 | if (prop != NULL) { |
| 2393 | assign_type = (prop->key()->IsPropertyName()) |
| 2394 | ? NAMED_PROPERTY |
| 2395 | : KEYED_PROPERTY; |
| 2396 | } |
| 2397 | |
| 2398 | switch (assign_type) { |
| 2399 | case VARIABLE: { |
| 2400 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2401 | EffectContext context(this); |
| 2402 | EmitVariableAssignment(var, Token::ASSIGN); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2403 | break; |
| 2404 | } |
| 2405 | case NAMED_PROPERTY: { |
| 2406 | __ push(eax); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2407 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2408 | __ mov(edx, eax); |
| 2409 | __ pop(eax); // Restore value. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2410 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2411 | CallStoreIC(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2412 | break; |
| 2413 | } |
| 2414 | case KEYED_PROPERTY: { |
| 2415 | __ push(eax); // Preserve value. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2416 | VisitForStackValue(prop->obj()); |
| 2417 | VisitForAccumulatorValue(prop->key()); |
| 2418 | __ mov(ecx, eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2419 | __ pop(edx); // Receiver. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2420 | __ pop(eax); // Restore value. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2421 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2422 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2423 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2424 | CallIC(ic); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2425 | break; |
| 2426 | } |
| 2427 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2428 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2432 | void FullCodeGenerator::EmitStoreToStackLocalOrContextSlot( |
| 2433 | Variable* var, MemOperand location) { |
| 2434 | __ mov(location, eax); |
| 2435 | if (var->IsContextSlot()) { |
| 2436 | __ mov(edx, eax); |
| 2437 | int offset = Context::SlotOffset(var->index()); |
| 2438 | __ RecordWriteContextSlot(ecx, offset, edx, ebx, kDontSaveFPRegs); |
| 2439 | } |
| 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | void FullCodeGenerator::EmitCallStoreContextSlot( |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2444 | Handle<String> name, StrictMode strict_mode) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2445 | __ push(eax); // Value. |
| 2446 | __ push(esi); // Context. |
| 2447 | __ push(Immediate(name)); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2448 | __ push(Immediate(Smi::FromInt(strict_mode))); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2449 | __ CallRuntime(Runtime::kHiddenStoreContextSlot, 4); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2453 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2454 | Token::Value op) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2455 | if (var->IsUnallocated()) { |
| 2456 | // Global var, const, or let. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2457 | __ mov(ecx, var->name()); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2458 | __ mov(edx, GlobalObjectOperand()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2459 | CallStoreIC(); |
| 2460 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2461 | } else if (op == Token::INIT_CONST_LEGACY) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2462 | // Const initializers need a write barrier. |
| 2463 | ASSERT(!var->IsParameter()); // No const parameters. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2464 | if (var->IsLookupSlot()) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2465 | __ push(eax); |
| 2466 | __ push(esi); |
| 2467 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2468 | __ CallRuntime(Runtime::kHiddenInitializeConstContextSlot, 3); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2469 | } else { |
| 2470 | ASSERT(var->IsStackLocal() || var->IsContextSlot()); |
| 2471 | Label skip; |
| 2472 | MemOperand location = VarOperand(var, ecx); |
| 2473 | __ mov(edx, location); |
| 2474 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2475 | __ j(not_equal, &skip, Label::kNear); |
| 2476 | EmitStoreToStackLocalOrContextSlot(var, location); |
| 2477 | __ bind(&skip); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2478 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2479 | |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 2480 | } else if (var->mode() == LET && op != Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2481 | // Non-initializing assignment to let variable needs a write barrier. |
| 2482 | if (var->IsLookupSlot()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2483 | EmitCallStoreContextSlot(var->name(), strict_mode()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2484 | } else { |
| 2485 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
| 2486 | Label assign; |
| 2487 | MemOperand location = VarOperand(var, ecx); |
| 2488 | __ mov(edx, location); |
| 2489 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
| 2490 | __ j(not_equal, &assign, Label::kNear); |
| 2491 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2492 | __ CallRuntime(Runtime::kHiddenThrowReferenceError, 1); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2493 | __ bind(&assign); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2494 | EmitStoreToStackLocalOrContextSlot(var, location); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 2495 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2496 | |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2497 | } else if (!var->is_const_mode() || op == Token::INIT_CONST) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2498 | // Assignment to var or initializing assignment to let/const |
| 2499 | // in harmony mode. |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2500 | if (var->IsLookupSlot()) { |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2501 | EmitCallStoreContextSlot(var->name(), strict_mode()); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2502 | } else { |
| 2503 | ASSERT(var->IsStackAllocated() || var->IsContextSlot()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2504 | MemOperand location = VarOperand(var, ecx); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2505 | if (generate_debug_code_ && op == Token::INIT_LET) { |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2506 | // Check for an uninitialized let binding. |
| 2507 | __ mov(edx, location); |
| 2508 | __ cmp(edx, isolate()->factory()->the_hole_value()); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2509 | __ Check(equal, kLetBindingReInitialization); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2510 | } |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2511 | EmitStoreToStackLocalOrContextSlot(var, location); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2512 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2513 | } |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2514 | // Non-initializing assignments to consts are ignored. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | |
| 2518 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 2519 | // Assignment to a property, using a named store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2520 | // eax : value |
| 2521 | // esp[0] : receiver |
| 2522 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2523 | Property* prop = expr->target()->AsProperty(); |
| 2524 | ASSERT(prop != NULL); |
| 2525 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2526 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2527 | // Record source code position before IC call. |
| 2528 | SetSourcePosition(expr->position()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2529 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2530 | __ pop(edx); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2531 | CallStoreIC(expr->AssignmentFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2532 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 2533 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | |
| 2537 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 2538 | // Assignment to a property, using a keyed store IC. |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2539 | // eax : value |
| 2540 | // esp[0] : key |
| 2541 | // esp[kPointerSize] : receiver |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2542 | |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2543 | __ pop(ecx); // Key. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2544 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2545 | // Record source code position before IC call. |
| 2546 | SetSourcePosition(expr->position()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2547 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2548 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 2549 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2550 | CallIC(ic, expr->AssignmentFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2551 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2552 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2553 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | |
| 2557 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 2558 | Comment cmnt(masm_, "[ Property"); |
| 2559 | Expression* key = expr->key(); |
| 2560 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2561 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2562 | VisitForAccumulatorValue(expr->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2563 | __ mov(edx, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2564 | EmitNamedPropertyLoad(expr); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2565 | PrepareForBailoutForId(expr->LoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2566 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2567 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2568 | VisitForStackValue(expr->obj()); |
| 2569 | VisitForAccumulatorValue(expr->key()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2570 | __ pop(edx); // Object. |
| 2571 | __ mov(ecx, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2572 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2573 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2574 | } |
| 2575 | } |
| 2576 | |
| 2577 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2578 | void FullCodeGenerator::CallIC(Handle<Code> code, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2579 | TypeFeedbackId ast_id) { |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2580 | ic_total_count_++; |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 2581 | __ call(code, RelocInfo::CODE_TARGET, ast_id); |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | |
| 2586 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2587 | // Code common for calls using the IC. |
| 2588 | void FullCodeGenerator::EmitCallWithIC(Call* expr) { |
| 2589 | Expression* callee = expr->expression(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2590 | ZoneList<Expression*>* args = expr->arguments(); |
| 2591 | int arg_count = args->length(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2592 | |
| 2593 | CallFunctionFlags flags; |
| 2594 | // Get the target function. |
| 2595 | if (callee->IsVariableProxy()) { |
| 2596 | { StackValueContext context(this); |
| 2597 | EmitVariableLoad(callee->AsVariableProxy()); |
| 2598 | PrepareForBailout(callee, NO_REGISTERS); |
| 2599 | } |
| 2600 | // 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] | 2601 | // is a sloppy mode method. |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2602 | __ push(Immediate(isolate()->factory()->undefined_value())); |
| 2603 | flags = NO_CALL_FUNCTION_FLAGS; |
| 2604 | } else { |
| 2605 | // Load the function from the receiver. |
| 2606 | ASSERT(callee->IsProperty()); |
| 2607 | __ mov(edx, Operand(esp, 0)); |
| 2608 | EmitNamedPropertyLoad(callee->AsProperty()); |
| 2609 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2610 | // Push the target function under the receiver. |
| 2611 | __ push(Operand(esp, 0)); |
| 2612 | __ mov(Operand(esp, kPointerSize), eax); |
| 2613 | flags = CALL_AS_METHOD; |
| 2614 | } |
| 2615 | |
| 2616 | // Load the arguments. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2617 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2618 | for (int i = 0; i < arg_count; i++) { |
| 2619 | VisitForStackValue(args->at(i)); |
| 2620 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2621 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2622 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2623 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2624 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2625 | CallFunctionStub stub(arg_count, flags); |
| 2626 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 2627 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2628 | RecordJSReturnSite(expr); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2629 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2630 | // Restore context register. |
| 2631 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2632 | |
| 2633 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2637 | // Code common for calls using the IC. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2638 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2639 | Expression* key) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2640 | // Load the key. |
| 2641 | VisitForAccumulatorValue(key); |
| 2642 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2643 | Expression* callee = expr->expression(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2644 | ZoneList<Expression*>* args = expr->arguments(); |
| 2645 | int arg_count = args->length(); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2646 | |
| 2647 | // Load the function from the receiver. |
| 2648 | ASSERT(callee->IsProperty()); |
| 2649 | __ mov(edx, Operand(esp, 0)); |
| 2650 | // Move the key into the right register for the keyed load IC. |
| 2651 | __ mov(ecx, eax); |
| 2652 | EmitKeyedPropertyLoad(callee->AsProperty()); |
| 2653 | PrepareForBailoutForId(callee->AsProperty()->LoadId(), TOS_REG); |
| 2654 | |
| 2655 | // Push the target function under the receiver. |
| 2656 | __ push(Operand(esp, 0)); |
| 2657 | __ mov(Operand(esp, kPointerSize), eax); |
| 2658 | |
| 2659 | // Load the arguments. |
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 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2664 | } |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2665 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2666 | // Record source position of the IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2667 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2668 | CallFunctionStub stub(arg_count, CALL_AS_METHOD); |
| 2669 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 2670 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2671 | RecordJSReturnSite(expr); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2672 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2673 | // Restore context register. |
| 2674 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2675 | |
| 2676 | context()->DropAndPlug(1, eax); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2680 | void FullCodeGenerator::EmitCallWithStub(Call* expr) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2681 | // Code common for calls using the call stub. |
| 2682 | ZoneList<Expression*>* args = expr->arguments(); |
| 2683 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2684 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2685 | for (int i = 0; i < arg_count; i++) { |
| 2686 | VisitForStackValue(args->at(i)); |
| 2687 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2688 | } |
| 2689 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2690 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2691 | |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame] | 2692 | Handle<Object> uninitialized = |
| 2693 | TypeFeedbackInfo::UninitializedSentinel(isolate()); |
| 2694 | StoreFeedbackVectorSlot(expr->CallFeedbackSlot(), uninitialized); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2695 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 2696 | __ mov(edx, Immediate(Smi::FromInt(expr->CallFeedbackSlot()))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2697 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2698 | // Record call targets in unoptimized code. |
| 2699 | CallFunctionStub stub(arg_count, RECORD_CALL_TARGET); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2700 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2701 | __ CallStub(&stub); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2702 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2703 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2704 | // Restore context register. |
| 2705 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2706 | context()->DropAndPlug(1, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2710 | void FullCodeGenerator::EmitResolvePossiblyDirectEval(int arg_count) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2711 | // Push copy of the first argument or undefined if it doesn't exist. |
| 2712 | if (arg_count > 0) { |
| 2713 | __ push(Operand(esp, arg_count * kPointerSize)); |
| 2714 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2715 | __ push(Immediate(isolate()->factory()->undefined_value())); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | // Push the receiver of the enclosing function. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2719 | __ push(Operand(ebp, (2 + info_->scope()->num_parameters()) * kPointerSize)); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2720 | // Push the language mode. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 2721 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2722 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2723 | // Push the start position of the scope the calls resides in. |
| 2724 | __ push(Immediate(Smi::FromInt(scope()->start_position()))); |
| 2725 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2726 | // Do the runtime call. |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2727 | __ CallRuntime(Runtime::kHiddenResolvePossiblyDirectEval, 5); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2731 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2732 | #ifdef DEBUG |
| 2733 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 2734 | // through this function. Avoid early returns. |
| 2735 | expr->return_is_recorded_ = false; |
| 2736 | #endif |
| 2737 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2738 | Comment cmnt(masm_, "[ Call"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2739 | Expression* callee = expr->expression(); |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2740 | Call::CallType call_type = expr->GetCallType(isolate()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2741 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2742 | if (call_type == Call::POSSIBLY_EVAL_CALL) { |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2743 | // In a call to eval, we first call RuntimeHidden_ResolvePossiblyDirectEval |
| 2744 | // to resolve the function we need to call and the receiver of the call. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2745 | // Then we call the resolved function using the given arguments. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2746 | ZoneList<Expression*>* args = expr->arguments(); |
| 2747 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2748 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2749 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2750 | // Reserved receiver slot. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2751 | __ push(Immediate(isolate()->factory()->undefined_value())); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2752 | // Push the arguments. |
| 2753 | for (int i = 0; i < arg_count; i++) { |
| 2754 | VisitForStackValue(args->at(i)); |
| 2755 | } |
| 2756 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2757 | // Push a copy of the function (found below the arguments) and |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 2758 | // resolve eval. |
| 2759 | __ push(Operand(esp, (arg_count + 1) * kPointerSize)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2760 | EmitResolvePossiblyDirectEval(arg_count); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2761 | |
| 2762 | // The runtime call returns a pair of values in eax (function) and |
| 2763 | // edx (receiver). Touch up the stack with the right values. |
| 2764 | __ mov(Operand(esp, (arg_count + 0) * kPointerSize), edx); |
| 2765 | __ mov(Operand(esp, (arg_count + 1) * kPointerSize), eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2766 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2767 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2768 | SetSourcePosition(expr->position()); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2769 | CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2770 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2771 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2772 | RecordJSReturnSite(expr); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2773 | // Restore context register. |
| 2774 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2775 | context()->DropAndPlug(1, eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2776 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2777 | } else if (call_type == Call::GLOBAL_CALL) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2778 | EmitCallWithIC(expr); |
| 2779 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2780 | } else if (call_type == Call::LOOKUP_SLOT_CALL) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2781 | // Call to a lookup slot (dynamically introduced variable). |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2782 | VariableProxy* proxy = callee->AsVariableProxy(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2783 | Label slow, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2784 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2785 | // Generate code for loading from variables potentially shadowed by |
| 2786 | // eval-introduced variables. |
| 2787 | EmitDynamicLookupFastCase(proxy->var(), NOT_INSIDE_TYPEOF, &slow, &done); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2788 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2789 | __ bind(&slow); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2790 | // Call the runtime to find the function to call (returned in eax) and |
| 2791 | // the object holding it (returned in edx). |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2792 | __ push(context_register()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2793 | __ push(Immediate(proxy->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 2794 | __ CallRuntime(Runtime::kHiddenLoadContextSlot, 2); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2795 | __ push(eax); // Function. |
| 2796 | __ push(edx); // Receiver. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2797 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2798 | // If fast case code has been generated, emit code to push the function |
| 2799 | // and receiver and have the slow path jump around this code. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2800 | if (done.is_linked()) { |
| 2801 | Label call; |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2802 | __ jmp(&call, Label::kNear); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2803 | __ bind(&done); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2804 | // Push function. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2805 | __ push(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2806 | // The receiver is implicitly the global receiver. Indicate this by |
| 2807 | // passing the hole to the call function stub. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2808 | __ push(Immediate(isolate()->factory()->undefined_value())); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2809 | __ bind(&call); |
| 2810 | } |
| 2811 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2812 | // 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] | 2813 | // LoadContextSlot. |
| 2814 | EmitCallWithStub(expr); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2815 | |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2816 | } else if (call_type == Call::PROPERTY_CALL) { |
| 2817 | Property* property = callee->AsProperty(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2818 | { PreservePositionScope scope(masm()->positions_recorder()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2819 | VisitForStackValue(property->obj()); |
| 2820 | } |
| 2821 | if (property->key()->IsPropertyName()) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 2822 | EmitCallWithIC(expr); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2823 | } else { |
| 2824 | EmitKeyedCallWithIC(expr, property->key()); |
| 2825 | } |
| 2826 | |
| 2827 | } else { |
machenbach@chromium.org | 43c51e5 | 2014-01-20 07:57:28 +0000 | [diff] [blame] | 2828 | ASSERT(call_type == Call::OTHER_CALL); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 2829 | // Call to an arbitrary expression not handled specially above. |
| 2830 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2831 | VisitForStackValue(callee); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2832 | } |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2833 | __ push(Immediate(isolate()->factory()->undefined_value())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2834 | // Emit function call. |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2835 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2836 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2837 | |
| 2838 | #ifdef DEBUG |
| 2839 | // RecordJSReturnSite should have been called. |
| 2840 | ASSERT(expr->return_is_recorded_); |
| 2841 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | |
| 2845 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2846 | Comment cmnt(masm_, "[ CallNew"); |
| 2847 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2848 | // expression in new calls must be evaluated before the |
| 2849 | // arguments. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2850 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2851 | // Push constructor on the stack. If it's not a function it's used as |
| 2852 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2853 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2854 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2855 | |
| 2856 | // Push the arguments ("left-to-right") on the stack. |
| 2857 | ZoneList<Expression*>* args = expr->arguments(); |
| 2858 | int arg_count = args->length(); |
| 2859 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2860 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | // Call the construct call builtin that handles allocation and |
| 2864 | // constructor invocation. |
| 2865 | SetSourcePosition(expr->position()); |
| 2866 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2867 | // Load function and argument count into edi and eax. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 2868 | __ Move(eax, Immediate(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2869 | __ mov(edi, Operand(esp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2870 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2871 | // Record call targets in unoptimized code. |
machenbach@chromium.org | 8545d49 | 2014-03-17 09:28:03 +0000 | [diff] [blame] | 2872 | Handle<Object> uninitialized = |
| 2873 | TypeFeedbackInfo::UninitializedSentinel(isolate()); |
| 2874 | StoreFeedbackVectorSlot(expr->CallNewFeedbackSlot(), uninitialized); |
machenbach@chromium.org | 69f64b1 | 2014-03-20 01:04:55 +0000 | [diff] [blame] | 2875 | if (FLAG_pretenuring_call_new) { |
| 2876 | StoreFeedbackVectorSlot(expr->AllocationSiteFeedbackSlot(), |
| 2877 | isolate()->factory()->NewAllocationSite()); |
| 2878 | ASSERT(expr->AllocationSiteFeedbackSlot() == |
| 2879 | expr->CallNewFeedbackSlot() + 1); |
| 2880 | } |
| 2881 | |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 2882 | __ LoadHeapObject(ebx, FeedbackVector()); |
| 2883 | __ mov(edx, Immediate(Smi::FromInt(expr->CallNewFeedbackSlot()))); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2884 | |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 2885 | CallConstructStub stub(RECORD_CALL_TARGET); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2886 | __ call(stub.GetCode(isolate()), RelocInfo::CONSTRUCT_CALL); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 2887 | PrepareForBailoutForId(expr->ReturnId(), TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2888 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
| 2891 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2892 | void FullCodeGenerator::EmitIsSmi(CallRuntime* expr) { |
| 2893 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2894 | ASSERT(args->length() == 1); |
| 2895 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2896 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2897 | |
| 2898 | Label materialize_true, materialize_false; |
| 2899 | Label* if_true = NULL; |
| 2900 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2901 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2902 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2903 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2904 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2905 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2906 | __ test(eax, Immediate(kSmiTagMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2907 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2908 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2909 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2913 | void FullCodeGenerator::EmitIsNonNegativeSmi(CallRuntime* expr) { |
| 2914 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2915 | ASSERT(args->length() == 1); |
| 2916 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2917 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2918 | |
| 2919 | Label materialize_true, materialize_false; |
| 2920 | Label* if_true = NULL; |
| 2921 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2922 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2923 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2924 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2925 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2926 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2927 | __ test(eax, Immediate(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2928 | Split(zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2929 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2930 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2934 | void FullCodeGenerator::EmitIsObject(CallRuntime* expr) { |
| 2935 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2936 | ASSERT(args->length() == 1); |
| 2937 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2938 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2939 | |
| 2940 | Label materialize_true, materialize_false; |
| 2941 | Label* if_true = NULL; |
| 2942 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2943 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2944 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2945 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2946 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2947 | __ JumpIfSmi(eax, if_false); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2948 | __ cmp(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2949 | __ j(equal, if_true); |
| 2950 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2951 | // Undetectable objects behave like undefined when tested with typeof. |
| 2952 | __ movzx_b(ecx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 2953 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 2954 | __ j(not_zero, if_false); |
| 2955 | __ movzx_b(ecx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2956 | __ cmp(ecx, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2957 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2958 | __ cmp(ecx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2959 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2960 | Split(below_equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2961 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2962 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
| 2965 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2966 | void FullCodeGenerator::EmitIsSpecObject(CallRuntime* expr) { |
| 2967 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2968 | ASSERT(args->length() == 1); |
| 2969 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2970 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2971 | |
| 2972 | Label materialize_true, materialize_false; |
| 2973 | Label* if_true = NULL; |
| 2974 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2975 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2976 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2977 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2978 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2979 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2980 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2981 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2982 | Split(above_equal, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2983 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2984 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2988 | void FullCodeGenerator::EmitIsUndetectableObject(CallRuntime* expr) { |
| 2989 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2990 | ASSERT(args->length() == 1); |
| 2991 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2992 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2993 | |
| 2994 | Label materialize_true, materialize_false; |
| 2995 | Label* if_true = NULL; |
| 2996 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2997 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2998 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2999 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3000 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3001 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3002 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3003 | __ movzx_b(ebx, FieldOperand(ebx, Map::kBitFieldOffset)); |
| 3004 | __ test(ebx, Immediate(1 << Map::kIsUndetectable)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3005 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3006 | Split(not_zero, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3007 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3008 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3012 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3013 | CallRuntime* expr) { |
| 3014 | ZoneList<Expression*>* args = expr->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3015 | ASSERT(args->length() == 1); |
| 3016 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3017 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3018 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3019 | Label materialize_true, materialize_false, skip_lookup; |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3020 | Label* if_true = NULL; |
| 3021 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3022 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3023 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3024 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3025 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3026 | __ AssertNotSmi(eax); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3027 | |
| 3028 | // Check whether this map has already been checked to be safe for default |
| 3029 | // valueOf. |
| 3030 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3031 | __ test_b(FieldOperand(ebx, Map::kBitField2Offset), |
| 3032 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3033 | __ j(not_zero, &skip_lookup); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3034 | |
| 3035 | // Check for fast case object. Return false for slow case objects. |
| 3036 | __ mov(ecx, FieldOperand(eax, JSObject::kPropertiesOffset)); |
| 3037 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3038 | __ cmp(ecx, isolate()->factory()->hash_table_map()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3039 | __ j(equal, if_false); |
| 3040 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3041 | // 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] | 3042 | // found. Since we omit an enumeration index check, if it is added via a |
| 3043 | // transition that shares its descriptor array, this is a false positive. |
| 3044 | Label entry, loop, done; |
| 3045 | |
| 3046 | // Skip loop if no descriptors are valid. |
| 3047 | __ NumberOfOwnDescriptors(ecx, ebx); |
| 3048 | __ cmp(ecx, 0); |
| 3049 | __ j(equal, &done); |
| 3050 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3051 | __ LoadInstanceDescriptors(ebx, ebx); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3052 | // ebx: descriptor array. |
| 3053 | // ecx: valid entries in the descriptor array. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3054 | // Calculate the end of the descriptor array. |
| 3055 | STATIC_ASSERT(kSmiTag == 0); |
| 3056 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3057 | STATIC_ASSERT(kPointerSize == 4); |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3058 | __ imul(ecx, ecx, DescriptorArray::kDescriptorSize); |
| 3059 | __ lea(ecx, Operand(ebx, ecx, times_2, DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3060 | // Calculate location of the first key name. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3061 | __ add(ebx, Immediate(DescriptorArray::kFirstOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3062 | // 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] | 3063 | // internalized string "valueOf" the result is false. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3064 | __ jmp(&entry); |
| 3065 | __ bind(&loop); |
| 3066 | __ mov(edx, FieldOperand(ebx, 0)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3067 | __ cmp(edx, isolate()->factory()->value_of_string()); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3068 | __ j(equal, if_false); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3069 | __ add(ebx, Immediate(DescriptorArray::kDescriptorSize * kPointerSize)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3070 | __ bind(&entry); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3071 | __ cmp(ebx, ecx); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3072 | __ j(not_equal, &loop); |
| 3073 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3074 | __ bind(&done); |
| 3075 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3076 | // Reload map as register ebx was used as temporary above. |
| 3077 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3078 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3079 | // Set the bit in the map to indicate that there is no local valueOf field. |
| 3080 | __ or_(FieldOperand(ebx, Map::kBitField2Offset), |
| 3081 | Immediate(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 3082 | |
| 3083 | __ bind(&skip_lookup); |
| 3084 | |
verwaest@chromium.org | 06ab2ec | 2012-10-09 17:00:13 +0000 | [diff] [blame] | 3085 | // 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] | 3086 | // prototype is the un-modified String prototype. If not result is false. |
| 3087 | __ mov(ecx, FieldOperand(ebx, Map::kPrototypeOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3088 | __ JumpIfSmi(ecx, if_false); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3089 | __ mov(ecx, FieldOperand(ecx, HeapObject::kMapOffset)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3090 | __ mov(edx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3091 | __ mov(edx, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3092 | FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3093 | __ cmp(ecx, |
| 3094 | ContextOperand(edx, |
| 3095 | Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3096 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 3097 | Split(equal, if_true, if_false, fall_through); |
| 3098 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3099 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3103 | void FullCodeGenerator::EmitIsFunction(CallRuntime* expr) { |
| 3104 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3105 | ASSERT(args->length() == 1); |
| 3106 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3107 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3108 | |
| 3109 | Label materialize_true, materialize_false; |
| 3110 | Label* if_true = NULL; |
| 3111 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3112 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3113 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3114 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3115 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3116 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3117 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3118 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3119 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3120 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3121 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3125 | void FullCodeGenerator::EmitIsMinusZero(CallRuntime* expr) { |
| 3126 | ZoneList<Expression*>* args = expr->arguments(); |
| 3127 | ASSERT(args->length() == 1); |
| 3128 | |
| 3129 | VisitForAccumulatorValue(args->at(0)); |
| 3130 | |
| 3131 | Label materialize_true, materialize_false; |
| 3132 | Label* if_true = NULL; |
| 3133 | Label* if_false = NULL; |
| 3134 | Label* fall_through = NULL; |
| 3135 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3136 | &if_true, &if_false, &fall_through); |
| 3137 | |
| 3138 | Handle<Map> map = masm()->isolate()->factory()->heap_number_map(); |
| 3139 | __ CheckMap(eax, map, if_false, DO_SMI_CHECK); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3140 | // Check if the exponent half is 0x80000000. Comparing against 1 and |
| 3141 | // checking for overflow is the shortest possible encoding. |
| 3142 | __ cmp(FieldOperand(eax, HeapNumber::kExponentOffset), Immediate(0x1)); |
| 3143 | __ j(no_overflow, if_false); |
| 3144 | __ cmp(FieldOperand(eax, HeapNumber::kMantissaOffset), Immediate(0x0)); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 3145 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
| 3146 | Split(equal, if_true, if_false, fall_through); |
| 3147 | |
| 3148 | context()->Plug(if_true, if_false); |
| 3149 | } |
| 3150 | |
| 3151 | |
| 3152 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3153 | void FullCodeGenerator::EmitIsArray(CallRuntime* expr) { |
| 3154 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3155 | ASSERT(args->length() == 1); |
| 3156 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3157 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3158 | |
| 3159 | Label materialize_true, materialize_false; |
| 3160 | Label* if_true = NULL; |
| 3161 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3162 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3163 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3164 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3165 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3166 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3167 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3168 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3169 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3170 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3171 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3175 | void FullCodeGenerator::EmitIsRegExp(CallRuntime* expr) { |
| 3176 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3177 | ASSERT(args->length() == 1); |
| 3178 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3179 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3180 | |
| 3181 | Label materialize_true, materialize_false; |
| 3182 | Label* if_true = NULL; |
| 3183 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3184 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3185 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3186 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3187 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3188 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3189 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3190 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3191 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3192 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3193 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | |
| 3197 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3198 | void FullCodeGenerator::EmitIsConstructCall(CallRuntime* expr) { |
| 3199 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3200 | |
| 3201 | Label materialize_true, materialize_false; |
| 3202 | Label* if_true = NULL; |
| 3203 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3204 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3205 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3206 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3207 | |
| 3208 | // Get the frame pointer for the calling frame. |
| 3209 | __ mov(eax, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3210 | |
| 3211 | // Skip the arguments adaptor frame if it exists. |
| 3212 | Label check_frame_marker; |
| 3213 | __ cmp(Operand(eax, StandardFrameConstants::kContextOffset), |
| 3214 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3215 | __ j(not_equal, &check_frame_marker); |
| 3216 | __ mov(eax, Operand(eax, StandardFrameConstants::kCallerFPOffset)); |
| 3217 | |
| 3218 | // Check the marker in the calling frame. |
| 3219 | __ bind(&check_frame_marker); |
| 3220 | __ cmp(Operand(eax, StandardFrameConstants::kMarkerOffset), |
| 3221 | Immediate(Smi::FromInt(StackFrame::CONSTRUCT))); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3222 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3223 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3224 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3225 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3226 | } |
| 3227 | |
| 3228 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3229 | void FullCodeGenerator::EmitObjectEquals(CallRuntime* expr) { |
| 3230 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3231 | ASSERT(args->length() == 2); |
| 3232 | |
| 3233 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3234 | VisitForStackValue(args->at(0)); |
| 3235 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3236 | |
| 3237 | Label materialize_true, materialize_false; |
| 3238 | Label* if_true = NULL; |
| 3239 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3240 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3241 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3242 | &if_true, &if_false, &fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3243 | |
| 3244 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3245 | __ cmp(eax, ebx); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3246 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3247 | Split(equal, if_true, if_false, fall_through); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3248 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3249 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3253 | void FullCodeGenerator::EmitArguments(CallRuntime* expr) { |
| 3254 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3255 | ASSERT(args->length() == 1); |
| 3256 | |
| 3257 | // ArgumentsAccessStub expects the key in edx and the formal |
| 3258 | // parameter count in eax. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3259 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3260 | __ mov(edx, eax); |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3261 | __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3262 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 3263 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3264 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3268 | void FullCodeGenerator::EmitArgumentsLength(CallRuntime* expr) { |
| 3269 | ASSERT(expr->arguments()->length() == 0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3270 | |
| 3271 | Label exit; |
| 3272 | // Get the number of formal parameters. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3273 | __ Move(eax, Immediate(Smi::FromInt(info_->scope()->num_parameters()))); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3274 | |
| 3275 | // Check if the calling frame is an arguments adaptor frame. |
| 3276 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3277 | __ cmp(Operand(ebx, StandardFrameConstants::kContextOffset), |
| 3278 | Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3279 | __ j(not_equal, &exit); |
| 3280 | |
| 3281 | // Arguments adaptor case: Read the arguments length from the |
| 3282 | // adaptor frame. |
| 3283 | __ mov(eax, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3284 | |
| 3285 | __ bind(&exit); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3286 | __ AssertSmi(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3287 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3291 | void FullCodeGenerator::EmitClassOf(CallRuntime* expr) { |
| 3292 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3293 | ASSERT(args->length() == 1); |
| 3294 | Label done, null, function, non_function_constructor; |
| 3295 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3296 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3297 | |
| 3298 | // If the object is a smi, we return null. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3299 | __ JumpIfSmi(eax, &null); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3300 | |
| 3301 | // Check that the object is a JS object but take special care of JS |
| 3302 | // functions to make sure they have 'Function' as their class. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3303 | // Assume that there are only two callable types, and one of them is at |
| 3304 | // either end of the type range for JS object types. Saves extra comparisons. |
| 3305 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3306 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, eax); |
| 3307 | // Map is now in eax. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3308 | __ j(below, &null); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3309 | STATIC_ASSERT(FIRST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3310 | FIRST_SPEC_OBJECT_TYPE + 1); |
| 3311 | __ j(equal, &function); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3312 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3313 | __ CmpInstanceType(eax, LAST_SPEC_OBJECT_TYPE); |
| 3314 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == |
| 3315 | LAST_SPEC_OBJECT_TYPE - 1); |
| 3316 | __ j(equal, &function); |
| 3317 | // Assume that there is no larger type. |
| 3318 | STATIC_ASSERT(LAST_NONCALLABLE_SPEC_OBJECT_TYPE == LAST_TYPE - 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3319 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3320 | // 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] | 3321 | __ mov(eax, FieldOperand(eax, Map::kConstructorOffset)); |
| 3322 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3323 | __ j(not_equal, &non_function_constructor); |
| 3324 | |
| 3325 | // eax now contains the constructor function. Grab the |
| 3326 | // instance class name from there. |
| 3327 | __ mov(eax, FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset)); |
| 3328 | __ mov(eax, FieldOperand(eax, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 3329 | __ jmp(&done); |
| 3330 | |
| 3331 | // Functions have class 'Function'. |
| 3332 | __ bind(&function); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3333 | __ mov(eax, isolate()->factory()->function_class_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3334 | __ jmp(&done); |
| 3335 | |
| 3336 | // Objects with a non-function constructor have class 'Object'. |
| 3337 | __ bind(&non_function_constructor); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3338 | __ mov(eax, isolate()->factory()->Object_string()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3339 | __ jmp(&done); |
| 3340 | |
| 3341 | // Non-JS objects have class null. |
| 3342 | __ bind(&null); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3343 | __ mov(eax, isolate()->factory()->null_value()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3344 | |
| 3345 | // All done. |
| 3346 | __ bind(&done); |
| 3347 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3348 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3352 | void FullCodeGenerator::EmitLog(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3353 | // Conditionally generate a log call. |
| 3354 | // Args: |
| 3355 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 3356 | // This is used to determine whether or not to generate the log call. |
| 3357 | // 1 (string): Format string. Access the string at argument index 2 |
| 3358 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 3359 | // 2 (array): Arguments to the format string. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3360 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3361 | ASSERT_EQ(args->length(), 3); |
mstarzinger@chromium.org | e900018 | 2013-09-03 11:25:39 +0000 | [diff] [blame] | 3362 | if (CodeGenerator::ShouldGenerateLog(isolate(), args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3363 | VisitForStackValue(args->at(1)); |
| 3364 | VisitForStackValue(args->at(2)); |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 3365 | __ CallRuntime(Runtime::kHiddenLog, 2); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3366 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3367 | // 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] | 3368 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3369 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3373 | void FullCodeGenerator::EmitSubString(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3374 | // Load the arguments on the stack and call the stub. |
| 3375 | SubStringStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3376 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3377 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3378 | VisitForStackValue(args->at(0)); |
| 3379 | VisitForStackValue(args->at(1)); |
| 3380 | VisitForStackValue(args->at(2)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3381 | __ CallStub(&stub); |
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 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3386 | void FullCodeGenerator::EmitRegExpExec(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3387 | // Load the arguments on the stack and call the stub. |
| 3388 | RegExpExecStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3389 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3390 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3391 | VisitForStackValue(args->at(0)); |
| 3392 | VisitForStackValue(args->at(1)); |
| 3393 | VisitForStackValue(args->at(2)); |
| 3394 | VisitForStackValue(args->at(3)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3395 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3396 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3400 | void FullCodeGenerator::EmitValueOf(CallRuntime* expr) { |
| 3401 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3402 | ASSERT(args->length() == 1); |
| 3403 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3404 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3405 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3406 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3407 | // If the object is a smi return the object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3408 | __ JumpIfSmi(eax, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3409 | // If the object is not a value type, return the object. |
| 3410 | __ CmpObjectType(eax, JS_VALUE_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3411 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3412 | __ mov(eax, FieldOperand(eax, JSValue::kValueOffset)); |
| 3413 | |
| 3414 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3415 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3419 | void FullCodeGenerator::EmitDateField(CallRuntime* expr) { |
| 3420 | ZoneList<Expression*>* args = expr->arguments(); |
| 3421 | ASSERT(args->length() == 2); |
| 3422 | ASSERT_NE(NULL, args->at(1)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3423 | Smi* index = Smi::cast(*(args->at(1)->AsLiteral()->value())); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3424 | |
| 3425 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
| 3426 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3427 | Label runtime, done, not_date_object; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3428 | Register object = eax; |
| 3429 | Register result = eax; |
| 3430 | Register scratch = ecx; |
| 3431 | |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3432 | __ JumpIfSmi(object, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3433 | __ CmpObjectType(object, JS_DATE_TYPE, scratch); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3434 | __ j(not_equal, ¬_date_object); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3435 | |
| 3436 | if (index->value() == 0) { |
| 3437 | __ mov(result, FieldOperand(object, JSDate::kValueOffset)); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3438 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3439 | } else { |
| 3440 | if (index->value() < JSDate::kFirstUncachedField) { |
| 3441 | ExternalReference stamp = ExternalReference::date_cache_stamp(isolate()); |
| 3442 | __ mov(scratch, Operand::StaticVariable(stamp)); |
| 3443 | __ cmp(scratch, FieldOperand(object, JSDate::kCacheStampOffset)); |
| 3444 | __ j(not_equal, &runtime, Label::kNear); |
| 3445 | __ mov(result, FieldOperand(object, JSDate::kValueOffset + |
| 3446 | kPointerSize * index->value())); |
| 3447 | __ jmp(&done); |
| 3448 | } |
| 3449 | __ bind(&runtime); |
| 3450 | __ PrepareCallCFunction(2, scratch); |
| 3451 | __ mov(Operand(esp, 0), object); |
| 3452 | __ mov(Operand(esp, 1 * kPointerSize), Immediate(index)); |
| 3453 | __ CallCFunction(ExternalReference::get_date_field_function(isolate()), 2); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3454 | __ jmp(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3455 | } |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3456 | |
| 3457 | __ bind(¬_date_object); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 3458 | __ CallRuntime(Runtime::kHiddenThrowNotDateError, 0); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 3459 | __ bind(&done); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3460 | context()->Plug(result); |
| 3461 | } |
| 3462 | |
| 3463 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3464 | void FullCodeGenerator::EmitOneByteSeqStringSetChar(CallRuntime* expr) { |
| 3465 | ZoneList<Expression*>* args = expr->arguments(); |
| 3466 | ASSERT_EQ(3, args->length()); |
| 3467 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3468 | Register string = eax; |
| 3469 | Register index = ebx; |
| 3470 | Register value = ecx; |
| 3471 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3472 | VisitForStackValue(args->at(1)); // index |
| 3473 | VisitForStackValue(args->at(2)); // value |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3474 | VisitForAccumulatorValue(args->at(0)); // string |
| 3475 | |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3476 | __ pop(value); |
| 3477 | __ pop(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3478 | |
| 3479 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3480 | __ test(value, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3481 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3482 | __ test(index, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3483 | __ Check(zero, kNonSmiValue); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | __ SmiUntag(value); |
| 3487 | __ SmiUntag(index); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3488 | |
| 3489 | if (FLAG_debug_code) { |
| 3490 | static const uint32_t one_byte_seq_type = kSeqStringTag | kOneByteStringTag; |
| 3491 | __ EmitSeqStringSetCharCheck(string, index, value, one_byte_seq_type); |
| 3492 | } |
| 3493 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3494 | __ mov_b(FieldOperand(string, index, times_1, SeqOneByteString::kHeaderSize), |
| 3495 | value); |
| 3496 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3497 | } |
| 3498 | |
| 3499 | |
| 3500 | void FullCodeGenerator::EmitTwoByteSeqStringSetChar(CallRuntime* expr) { |
| 3501 | ZoneList<Expression*>* args = expr->arguments(); |
| 3502 | ASSERT_EQ(3, args->length()); |
| 3503 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3504 | Register string = eax; |
| 3505 | Register index = ebx; |
| 3506 | Register value = ecx; |
| 3507 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3508 | VisitForStackValue(args->at(1)); // index |
| 3509 | VisitForStackValue(args->at(2)); // value |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3510 | VisitForAccumulatorValue(args->at(0)); // string |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3511 | __ pop(value); |
| 3512 | __ pop(index); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3513 | |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3514 | if (FLAG_debug_code) { |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3515 | __ test(value, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3516 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3517 | __ test(index, Immediate(kSmiTagMask)); |
machenbach@chromium.org | 05150ab | 2014-01-29 08:13:29 +0000 | [diff] [blame] | 3518 | __ Check(zero, kNonSmiValue); |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3519 | __ SmiUntag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3520 | static const uint32_t two_byte_seq_type = kSeqStringTag | kTwoByteStringTag; |
machenbach@chromium.org | 9af454f | 2013-11-20 09:25:57 +0000 | [diff] [blame] | 3521 | __ EmitSeqStringSetCharCheck(string, index, value, two_byte_seq_type); |
| 3522 | __ SmiTag(index); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | __ SmiUntag(value); |
| 3526 | // No need to untag a smi for two-byte addressing. |
| 3527 | __ mov_w(FieldOperand(string, index, times_1, SeqTwoByteString::kHeaderSize), |
| 3528 | value); |
| 3529 | context()->Plug(string); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3533 | void FullCodeGenerator::EmitMathPow(CallRuntime* expr) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3534 | // Load the arguments on the stack and call the runtime function. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3535 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3536 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3537 | VisitForStackValue(args->at(0)); |
| 3538 | VisitForStackValue(args->at(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3539 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3540 | if (CpuFeatures::IsSupported(SSE2)) { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3541 | MathPowStub stub(MathPowStub::ON_STACK); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3542 | __ CallStub(&stub); |
| 3543 | } else { |
machenbach@chromium.org | 2f599e5 | 2014-03-31 14:24:38 +0000 | [diff] [blame] | 3544 | __ CallRuntime(Runtime::kHiddenMathPowSlow, 2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3545 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3546 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3550 | void FullCodeGenerator::EmitSetValueOf(CallRuntime* expr) { |
| 3551 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3552 | ASSERT(args->length() == 2); |
| 3553 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3554 | VisitForStackValue(args->at(0)); // Load the object. |
| 3555 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3556 | __ pop(ebx); // eax = value. ebx = object. |
| 3557 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3558 | Label done; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3559 | // If the object is a smi, return the value. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3560 | __ JumpIfSmi(ebx, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3561 | |
| 3562 | // If the object is not a value type, return the value. |
| 3563 | __ CmpObjectType(ebx, JS_VALUE_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3564 | __ j(not_equal, &done, Label::kNear); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3565 | |
| 3566 | // Store the value. |
| 3567 | __ mov(FieldOperand(ebx, JSValue::kValueOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3568 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3569 | // Update the write barrier. Save the value as it will be |
| 3570 | // overwritten by the write barrier code and is needed afterward. |
| 3571 | __ mov(edx, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3572 | __ RecordWriteField(ebx, JSValue::kValueOffset, edx, ecx, kDontSaveFPRegs); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3573 | |
| 3574 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3575 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3576 | } |
| 3577 | |
| 3578 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3579 | void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { |
| 3580 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3581 | ASSERT_EQ(args->length(), 1); |
| 3582 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 3583 | // Load the argument into eax and call the stub. |
| 3584 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3585 | |
| 3586 | NumberToStringStub stub; |
| 3587 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3588 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3592 | void FullCodeGenerator::EmitStringCharFromCode(CallRuntime* expr) { |
| 3593 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3594 | ASSERT(args->length() == 1); |
| 3595 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3596 | VisitForAccumulatorValue(args->at(0)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3597 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3598 | Label done; |
| 3599 | StringCharFromCodeGenerator generator(eax, ebx); |
| 3600 | generator.GenerateFast(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3601 | __ jmp(&done); |
| 3602 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3603 | NopRuntimeCallHelper call_helper; |
| 3604 | generator.GenerateSlow(masm_, call_helper); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3605 | |
| 3606 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3607 | context()->Plug(ebx); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3611 | void FullCodeGenerator::EmitStringCharCodeAt(CallRuntime* expr) { |
| 3612 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3613 | ASSERT(args->length() == 2); |
| 3614 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3615 | VisitForStackValue(args->at(0)); |
| 3616 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3617 | |
| 3618 | Register object = ebx; |
| 3619 | Register index = eax; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3620 | Register result = edx; |
| 3621 | |
| 3622 | __ pop(object); |
| 3623 | |
| 3624 | Label need_conversion; |
| 3625 | Label index_out_of_range; |
| 3626 | Label done; |
| 3627 | StringCharCodeAtGenerator generator(object, |
| 3628 | index, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3629 | result, |
| 3630 | &need_conversion, |
| 3631 | &need_conversion, |
| 3632 | &index_out_of_range, |
| 3633 | STRING_INDEX_IS_NUMBER); |
| 3634 | generator.GenerateFast(masm_); |
| 3635 | __ jmp(&done); |
| 3636 | |
| 3637 | __ bind(&index_out_of_range); |
| 3638 | // When the index is out of range, the spec requires us to return |
| 3639 | // NaN. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3640 | __ Move(result, Immediate(isolate()->factory()->nan_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3641 | __ jmp(&done); |
| 3642 | |
| 3643 | __ bind(&need_conversion); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3644 | // Move the undefined value into the result register, which will |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3645 | // trigger conversion. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3646 | __ Move(result, Immediate(isolate()->factory()->undefined_value())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3647 | __ jmp(&done); |
| 3648 | |
| 3649 | NopRuntimeCallHelper call_helper; |
| 3650 | generator.GenerateSlow(masm_, call_helper); |
| 3651 | |
| 3652 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3653 | context()->Plug(result); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3654 | } |
| 3655 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3656 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3657 | void FullCodeGenerator::EmitStringCharAt(CallRuntime* expr) { |
| 3658 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3659 | ASSERT(args->length() == 2); |
| 3660 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3661 | VisitForStackValue(args->at(0)); |
| 3662 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3663 | |
| 3664 | Register object = ebx; |
| 3665 | Register index = eax; |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3666 | Register scratch = edx; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3667 | Register result = eax; |
| 3668 | |
| 3669 | __ pop(object); |
| 3670 | |
| 3671 | Label need_conversion; |
| 3672 | Label index_out_of_range; |
| 3673 | Label done; |
| 3674 | StringCharAtGenerator generator(object, |
| 3675 | index, |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3676 | scratch, |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3677 | result, |
| 3678 | &need_conversion, |
| 3679 | &need_conversion, |
| 3680 | &index_out_of_range, |
| 3681 | STRING_INDEX_IS_NUMBER); |
| 3682 | generator.GenerateFast(masm_); |
| 3683 | __ jmp(&done); |
| 3684 | |
| 3685 | __ bind(&index_out_of_range); |
| 3686 | // When the index is out of range, the spec requires us to return |
| 3687 | // the empty string. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3688 | __ Move(result, Immediate(isolate()->factory()->empty_string())); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3689 | __ jmp(&done); |
| 3690 | |
| 3691 | __ bind(&need_conversion); |
| 3692 | // Move smi zero into the result register, which will trigger |
| 3693 | // conversion. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3694 | __ Move(result, Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3695 | __ jmp(&done); |
| 3696 | |
| 3697 | NopRuntimeCallHelper call_helper; |
| 3698 | generator.GenerateSlow(masm_, call_helper); |
| 3699 | |
| 3700 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3701 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3705 | void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) { |
| 3706 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3707 | ASSERT_EQ(2, args->length()); |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 3708 | VisitForStackValue(args->at(0)); |
| 3709 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3710 | |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 3711 | __ pop(edx); |
| 3712 | StringAddStub stub(STRING_ADD_CHECK_BOTH, NOT_TENURED); |
| 3713 | __ CallStub(&stub); |
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::EmitStringCompare(CallRuntime* expr) { |
| 3719 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3720 | ASSERT_EQ(2, args->length()); |
| 3721 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3722 | VisitForStackValue(args->at(0)); |
| 3723 | VisitForStackValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3724 | |
| 3725 | StringCompareStub stub; |
| 3726 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3727 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3731 | void FullCodeGenerator::EmitCallFunction(CallRuntime* expr) { |
| 3732 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3733 | ASSERT(args->length() >= 2); |
| 3734 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3735 | int arg_count = args->length() - 2; // 2 ~ receiver and function. |
| 3736 | for (int i = 0; i < arg_count + 1; ++i) { |
| 3737 | VisitForStackValue(args->at(i)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3738 | } |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3739 | VisitForAccumulatorValue(args->last()); // Function. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3740 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3741 | Label runtime, done; |
| 3742 | // Check for non-function argument (including proxy). |
| 3743 | __ JumpIfSmi(eax, &runtime); |
| 3744 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx); |
| 3745 | __ j(not_equal, &runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3746 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 3747 | // InvokeFunction requires the function in edi. Move it in there. |
| 3748 | __ mov(edi, result_register()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3749 | ParameterCount count(arg_count); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 3750 | __ InvokeFunction(edi, count, CALL_FUNCTION, NullCallWrapper()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3751 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3752 | __ jmp(&done); |
| 3753 | |
verwaest@chromium.org | de64f72 | 2012-08-16 15:44:54 +0000 | [diff] [blame] | 3754 | __ bind(&runtime); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3755 | __ push(eax); |
| 3756 | __ CallRuntime(Runtime::kCall, args->length()); |
| 3757 | __ bind(&done); |
| 3758 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3759 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3763 | void FullCodeGenerator::EmitRegExpConstructResult(CallRuntime* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3764 | // Load the arguments on the stack and call the stub. |
| 3765 | RegExpConstructResultStub stub; |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3766 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3767 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3768 | VisitForStackValue(args->at(0)); |
| 3769 | VisitForStackValue(args->at(1)); |
machenbach@chromium.org | 09cae8d | 2014-01-30 01:05:27 +0000 | [diff] [blame] | 3770 | VisitForAccumulatorValue(args->at(2)); |
| 3771 | __ pop(ebx); |
| 3772 | __ pop(ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3773 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3774 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3778 | void FullCodeGenerator::EmitGetFromCache(CallRuntime* expr) { |
| 3779 | ZoneList<Expression*>* args = expr->arguments(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3780 | ASSERT_EQ(2, args->length()); |
| 3781 | |
| 3782 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 3783 | 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] | 3784 | |
| 3785 | Handle<FixedArray> jsfunction_result_caches( |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3786 | isolate()->native_context()->jsfunction_result_caches()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3787 | if (jsfunction_result_caches->length() <= cache_id) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3788 | __ Abort(kAttemptToUseUndefinedCache); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3789 | __ mov(eax, isolate()->factory()->undefined_value()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3790 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3791 | return; |
| 3792 | } |
| 3793 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3794 | VisitForAccumulatorValue(args->at(1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3795 | |
| 3796 | Register key = eax; |
| 3797 | Register cache = ebx; |
| 3798 | Register tmp = ecx; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3799 | __ mov(cache, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3800 | __ mov(cache, |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3801 | FieldOperand(cache, GlobalObject::kNativeContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3802 | __ mov(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3803 | __ mov(cache, |
| 3804 | FieldOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 3805 | |
| 3806 | Label done, not_found; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3807 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3808 | __ mov(tmp, FieldOperand(cache, JSFunctionResultCache::kFingerOffset)); |
machenbach@chromium.org | 0a73036 | 2014-02-05 03:04:56 +0000 | [diff] [blame] | 3809 | // tmp now holds finger offset as a smi. |
| 3810 | __ cmp(key, FixedArrayElementOperand(cache, tmp)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3811 | __ j(not_equal, ¬_found); |
| 3812 | |
machenbach@chromium.org | 0a73036 | 2014-02-05 03:04:56 +0000 | [diff] [blame] | 3813 | __ mov(eax, FixedArrayElementOperand(cache, tmp, 1)); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3814 | __ jmp(&done); |
| 3815 | |
| 3816 | __ bind(¬_found); |
| 3817 | // Call runtime to perform the lookup. |
| 3818 | __ push(cache); |
| 3819 | __ push(key); |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 3820 | __ CallRuntime(Runtime::kHiddenGetFromCache, 2); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3821 | |
| 3822 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3823 | context()->Plug(eax); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3827 | void FullCodeGenerator::EmitHasCachedArrayIndex(CallRuntime* expr) { |
| 3828 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3829 | ASSERT(args->length() == 1); |
| 3830 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3831 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3832 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3833 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3834 | |
| 3835 | Label materialize_true, materialize_false; |
| 3836 | Label* if_true = NULL; |
| 3837 | Label* if_false = NULL; |
| 3838 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3839 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3840 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3841 | |
| 3842 | __ test(FieldOperand(eax, String::kHashFieldOffset), |
| 3843 | Immediate(String::kContainsCachedArrayIndexMask)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3844 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3845 | Split(zero, if_true, if_false, fall_through); |
| 3846 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3847 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3848 | } |
| 3849 | |
| 3850 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3851 | void FullCodeGenerator::EmitGetCachedArrayIndex(CallRuntime* expr) { |
| 3852 | ZoneList<Expression*>* args = expr->arguments(); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3853 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3854 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3855 | |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3856 | __ AssertString(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3857 | |
| 3858 | __ mov(eax, FieldOperand(eax, String::kHashFieldOffset)); |
| 3859 | __ IndexFromHash(eax, eax); |
| 3860 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3861 | context()->Plug(eax); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3865 | void FullCodeGenerator::EmitFastAsciiArrayJoin(CallRuntime* expr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3866 | Label bailout, done, one_char_separator, long_separator, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3867 | non_trivial_array, not_size_one_array, loop, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3868 | 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] | 3869 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3870 | ZoneList<Expression*>* args = expr->arguments(); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3871 | ASSERT(args->length() == 2); |
| 3872 | // We will leave the separator on the stack until the end of the function. |
| 3873 | VisitForStackValue(args->at(1)); |
| 3874 | // Load this to eax (= array) |
| 3875 | VisitForAccumulatorValue(args->at(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3876 | // All aliases of the same register have disjoint lifetimes. |
| 3877 | Register array = eax; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3878 | Register elements = no_reg; // Will be eax. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3879 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3880 | Register index = edx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3881 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3882 | Register string_length = ecx; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3883 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3884 | Register string = esi; |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3885 | |
| 3886 | Register scratch = ebx; |
| 3887 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3888 | Register array_length = edi; |
| 3889 | Register result_pos = no_reg; // Will be edi. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3890 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3891 | // Separator operand is already pushed. |
| 3892 | Operand separator_operand = Operand(esp, 2 * kPointerSize); |
| 3893 | Operand result_operand = Operand(esp, 1 * kPointerSize); |
| 3894 | Operand array_length_operand = Operand(esp, 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3895 | __ sub(esp, Immediate(2 * kPointerSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3896 | __ cld(); |
| 3897 | // Check that the array is a JSArray |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3898 | __ JumpIfSmi(array, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3899 | __ CmpObjectType(array, JS_ARRAY_TYPE, scratch); |
| 3900 | __ j(not_equal, &bailout); |
| 3901 | |
| 3902 | // Check that the array has fast elements. |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3903 | __ CheckFastElements(scratch, &bailout); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3904 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3905 | // If the array has length zero, return the empty string. |
| 3906 | __ mov(array_length, FieldOperand(array, JSArray::kLengthOffset)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3907 | __ SmiUntag(array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3908 | __ j(not_zero, &non_trivial_array); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3909 | __ mov(result_operand, isolate()->factory()->empty_string()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3910 | __ jmp(&done); |
| 3911 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3912 | // Save the array length. |
| 3913 | __ bind(&non_trivial_array); |
| 3914 | __ mov(array_length_operand, array_length); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3915 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3916 | // Save the FixedArray containing array's elements. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3917 | // End of array's live range. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3918 | elements = array; |
| 3919 | __ mov(elements, FieldOperand(array, JSArray::kElementsOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3920 | array = no_reg; |
| 3921 | |
| 3922 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3923 | // Check that all array elements are sequential ASCII strings, and |
| 3924 | // accumulate the sum of their lengths, as a smi-encoded value. |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 3925 | __ Move(index, Immediate(0)); |
| 3926 | __ Move(string_length, Immediate(0)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3927 | // Loop condition: while (index < length). |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3928 | // Live loop registers: index, array_length, string, |
| 3929 | // scratch, string_length, elements. |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 3930 | if (generate_debug_code_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3931 | __ cmp(index, array_length); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3932 | __ Assert(less, kNoEmptyArraysHereInEmitFastAsciiArrayJoin); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3933 | } |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3934 | __ bind(&loop); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 3935 | __ mov(string, FieldOperand(elements, |
| 3936 | index, |
| 3937 | times_pointer_size, |
| 3938 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3939 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3940 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3941 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
| 3942 | __ and_(scratch, Immediate( |
| 3943 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3944 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3945 | __ j(not_equal, &bailout); |
| 3946 | __ add(string_length, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3947 | FieldOperand(string, SeqOneByteString::kLengthOffset)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3948 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3949 | __ add(index, Immediate(1)); |
| 3950 | __ cmp(index, array_length); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3951 | __ j(less, &loop); |
| 3952 | |
| 3953 | // If array_length is 1, return elements[0], a string. |
| 3954 | __ cmp(array_length, 1); |
| 3955 | __ j(not_equal, ¬_size_one_array); |
| 3956 | __ mov(scratch, FieldOperand(elements, FixedArray::kHeaderSize)); |
| 3957 | __ mov(result_operand, scratch); |
| 3958 | __ jmp(&done); |
| 3959 | |
| 3960 | __ bind(¬_size_one_array); |
| 3961 | |
| 3962 | // End of array_length live range. |
| 3963 | result_pos = array_length; |
| 3964 | array_length = no_reg; |
| 3965 | |
| 3966 | // Live registers: |
| 3967 | // string_length: Sum of string lengths, as a smi. |
| 3968 | // elements: FixedArray of strings. |
| 3969 | |
| 3970 | // Check that the separator is a flat ASCII string. |
| 3971 | __ mov(string, separator_operand); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3972 | __ JumpIfSmi(string, &bailout); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3973 | __ mov(scratch, FieldOperand(string, HeapObject::kMapOffset)); |
| 3974 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3975 | __ and_(scratch, Immediate( |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3976 | kIsNotStringMask | kStringEncodingMask | kStringRepresentationMask)); |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 3977 | __ cmp(scratch, kStringTag | kOneByteStringTag | kSeqStringTag); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 3978 | __ j(not_equal, &bailout); |
| 3979 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3980 | // Add (separator length times array_length) - separator length |
| 3981 | // to string_length. |
| 3982 | __ mov(scratch, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3983 | __ mov(scratch, FieldOperand(scratch, SeqOneByteString::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3984 | __ sub(string_length, scratch); // May be negative, temporarily. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3985 | __ imul(scratch, array_length_operand); |
| 3986 | __ j(overflow, &bailout); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3987 | __ add(string_length, scratch); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3988 | __ j(overflow, &bailout); |
| 3989 | |
| 3990 | __ shr(string_length, 1); |
| 3991 | // Live registers and stack values: |
| 3992 | // string_length |
| 3993 | // elements |
| 3994 | __ AllocateAsciiString(result_pos, string_length, scratch, |
| 3995 | index, string, &bailout); |
| 3996 | __ mov(result_operand, result_pos); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3997 | __ lea(result_pos, FieldOperand(result_pos, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3998 | |
| 3999 | |
| 4000 | __ mov(string, separator_operand); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4001 | __ cmp(FieldOperand(string, SeqOneByteString::kLengthOffset), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4002 | Immediate(Smi::FromInt(1))); |
| 4003 | __ j(equal, &one_char_separator); |
| 4004 | __ j(greater, &long_separator); |
| 4005 | |
| 4006 | |
| 4007 | // Empty separator case |
| 4008 | __ mov(index, Immediate(0)); |
| 4009 | __ jmp(&loop_1_condition); |
| 4010 | // Loop condition: while (index < length). |
| 4011 | __ bind(&loop_1); |
| 4012 | // Each iteration of the loop concatenates one string to the result. |
| 4013 | // Live values in registers: |
| 4014 | // index: which element of the elements array we are adding to the result. |
| 4015 | // result_pos: the position to which we are currently copying characters. |
| 4016 | // elements: the FixedArray of strings we are joining. |
| 4017 | |
| 4018 | // Get string = array[index]. |
| 4019 | __ mov(string, FieldOperand(elements, index, |
| 4020 | times_pointer_size, |
| 4021 | FixedArray::kHeaderSize)); |
| 4022 | __ mov(string_length, |
| 4023 | FieldOperand(string, String::kLengthOffset)); |
| 4024 | __ shr(string_length, 1); |
| 4025 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4026 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4027 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4028 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4029 | __ bind(&loop_1_condition); |
| 4030 | __ cmp(index, array_length_operand); |
| 4031 | __ j(less, &loop_1); // End while (index < length). |
| 4032 | __ jmp(&done); |
| 4033 | |
| 4034 | |
| 4035 | |
| 4036 | // One-character separator case |
| 4037 | __ bind(&one_char_separator); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4038 | // Replace separator with its ASCII character value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4039 | __ mov_b(scratch, FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4040 | __ mov_b(separator_operand, scratch); |
| 4041 | |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4042 | __ Move(index, Immediate(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4043 | // Jump into the loop after the code that copies the separator, so the first |
| 4044 | // element is not preceded by a separator |
| 4045 | __ jmp(&loop_2_entry); |
| 4046 | // Loop condition: while (index < length). |
| 4047 | __ bind(&loop_2); |
| 4048 | // Each iteration of the loop concatenates one string to the result. |
| 4049 | // Live values in registers: |
| 4050 | // index: which element of the elements array we are adding to the result. |
| 4051 | // result_pos: the position to which we are currently copying characters. |
| 4052 | |
| 4053 | // Copy the separator character to the result. |
| 4054 | __ mov_b(scratch, separator_operand); |
| 4055 | __ mov_b(Operand(result_pos, 0), scratch); |
| 4056 | __ inc(result_pos); |
| 4057 | |
| 4058 | __ bind(&loop_2_entry); |
| 4059 | // Get string = array[index]. |
| 4060 | __ mov(string, FieldOperand(elements, index, |
| 4061 | times_pointer_size, |
| 4062 | FixedArray::kHeaderSize)); |
| 4063 | __ mov(string_length, |
| 4064 | FieldOperand(string, String::kLengthOffset)); |
| 4065 | __ shr(string_length, 1); |
| 4066 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4067 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4068 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4069 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4070 | |
| 4071 | __ cmp(index, array_length_operand); |
| 4072 | __ j(less, &loop_2); // End while (index < length). |
| 4073 | __ jmp(&done); |
| 4074 | |
| 4075 | |
| 4076 | // Long separator case (separator is more than one character). |
| 4077 | __ bind(&long_separator); |
| 4078 | |
machenbach@chromium.org | a221880 | 2014-03-25 07:30:47 +0000 | [diff] [blame] | 4079 | __ Move(index, Immediate(0)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4080 | // Jump into the loop after the code that copies the separator, so the first |
| 4081 | // element is not preceded by a separator |
| 4082 | __ jmp(&loop_3_entry); |
| 4083 | // Loop condition: while (index < length). |
| 4084 | __ bind(&loop_3); |
| 4085 | // Each iteration of the loop concatenates one string to the result. |
| 4086 | // Live values in registers: |
| 4087 | // index: which element of the elements array we are adding to the result. |
| 4088 | // result_pos: the position to which we are currently copying characters. |
| 4089 | |
| 4090 | // Copy the separator to the result. |
| 4091 | __ mov(string, separator_operand); |
| 4092 | __ mov(string_length, |
| 4093 | FieldOperand(string, String::kLengthOffset)); |
| 4094 | __ shr(string_length, 1); |
| 4095 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4096 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4097 | __ CopyBytes(string, result_pos, string_length, scratch); |
| 4098 | |
| 4099 | __ bind(&loop_3_entry); |
| 4100 | // Get string = array[index]. |
| 4101 | __ mov(string, FieldOperand(elements, index, |
| 4102 | times_pointer_size, |
| 4103 | FixedArray::kHeaderSize)); |
| 4104 | __ mov(string_length, |
| 4105 | FieldOperand(string, String::kLengthOffset)); |
| 4106 | __ shr(string_length, 1); |
| 4107 | __ lea(string, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4108 | FieldOperand(string, SeqOneByteString::kHeaderSize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4109 | __ CopyBytes(string, result_pos, string_length, scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4110 | __ add(index, Immediate(1)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4111 | |
| 4112 | __ cmp(index, array_length_operand); |
| 4113 | __ j(less, &loop_3); // End while (index < length). |
| 4114 | __ jmp(&done); |
| 4115 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4116 | |
| 4117 | __ bind(&bailout); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4118 | __ mov(result_operand, isolate()->factory()->undefined_value()); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4119 | __ bind(&done); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4120 | __ mov(eax, result_operand); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4121 | // Drop temp values from the stack, and restore context register. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4122 | __ add(esp, Immediate(3 * kPointerSize)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 4123 | |
| 4124 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 4125 | context()->Plug(eax); |
| 4126 | } |
| 4127 | |
| 4128 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4129 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
machenbach@chromium.org | 9b95fd7 | 2014-03-26 01:04:35 +0000 | [diff] [blame] | 4130 | if (expr->function() != NULL && |
| 4131 | expr->function()->intrinsic_type == Runtime::INLINE) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4132 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 4133 | EmitInlineRuntimeCall(expr); |
| 4134 | return; |
| 4135 | } |
| 4136 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4137 | Comment cmnt(masm_, "[ CallRuntime"); |
| 4138 | ZoneList<Expression*>* args = expr->arguments(); |
| 4139 | |
| 4140 | if (expr->is_jsruntime()) { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4141 | // Push the builtins object as receiver. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 4142 | __ mov(eax, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4143 | __ push(FieldOperand(eax, GlobalObject::kBuiltinsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4144 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4145 | // Load the function from the receiver. |
| 4146 | __ mov(edx, Operand(esp, 0)); |
| 4147 | __ mov(ecx, Immediate(expr->name())); |
| 4148 | CallLoadIC(NOT_CONTEXTUAL, expr->CallRuntimeFeedbackId()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4149 | |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4150 | // Push the target function under the receiver. |
| 4151 | __ push(Operand(esp, 0)); |
| 4152 | __ mov(Operand(esp, kPointerSize), eax); |
| 4153 | |
| 4154 | // Code common for calls using the IC. |
| 4155 | ZoneList<Expression*>* args = expr->arguments(); |
| 4156 | int arg_count = args->length(); |
| 4157 | for (int i = 0; i < arg_count; i++) { |
| 4158 | VisitForStackValue(args->at(i)); |
| 4159 | } |
| 4160 | |
| 4161 | // Record source position of the IC call. |
| 4162 | SetSourcePosition(expr->position()); |
| 4163 | CallFunctionStub stub(arg_count, NO_CALL_FUNCTION_FLAGS); |
| 4164 | __ mov(edi, Operand(esp, (arg_count + 1) * kPointerSize)); |
| 4165 | __ CallStub(&stub); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4166 | // Restore context register. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4167 | __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4168 | context()->DropAndPlug(1, eax); |
| 4169 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4170 | } else { |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4171 | // Push the arguments ("left-to-right"). |
| 4172 | int arg_count = args->length(); |
| 4173 | for (int i = 0; i < arg_count; i++) { |
| 4174 | VisitForStackValue(args->at(i)); |
| 4175 | } |
| 4176 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4177 | // Call the C runtime function. |
| 4178 | __ CallRuntime(expr->function(), arg_count); |
machenbach@chromium.org | a03ba1e | 2014-02-01 08:54:43 +0000 | [diff] [blame] | 4179 | |
| 4180 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4181 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4182 | } |
| 4183 | |
| 4184 | |
| 4185 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 4186 | switch (expr->op()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4187 | case Token::DELETE: { |
| 4188 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4189 | Property* property = expr->expression()->AsProperty(); |
| 4190 | VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4191 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4192 | if (property != NULL) { |
| 4193 | VisitForStackValue(property->obj()); |
| 4194 | VisitForStackValue(property->key()); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4195 | __ push(Immediate(Smi::FromInt(strict_mode()))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4196 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4197 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4198 | } else if (proxy != NULL) { |
| 4199 | Variable* var = proxy->var(); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4200 | // Delete of an unqualified identifier is disallowed in strict mode |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4201 | // but "delete this" is allowed. |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4202 | ASSERT(strict_mode() == SLOPPY || var->is_this()); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4203 | if (var->IsUnallocated()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4204 | __ push(GlobalObjectOperand()); |
| 4205 | __ push(Immediate(var->name())); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4206 | __ push(Immediate(Smi::FromInt(SLOPPY))); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4207 | __ InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION); |
| 4208 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4209 | } else if (var->IsStackAllocated() || var->IsContextSlot()) { |
| 4210 | // Result of deleting non-global variables is false. 'this' is |
| 4211 | // not really a variable, though we implement it as one. The |
| 4212 | // subexpression does not have side effects. |
| 4213 | context()->Plug(var->is_this()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4214 | } else { |
| 4215 | // Non-global variable. Call the runtime to try to delete from the |
| 4216 | // context where the variable was introduced. |
| 4217 | __ push(context_register()); |
| 4218 | __ push(Immediate(var->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4219 | __ CallRuntime(Runtime::kHiddenDeleteContextSlot, 2); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4220 | context()->Plug(eax); |
| 4221 | } |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4222 | } else { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4223 | // Result of deleting non-property, non-variable reference is true. |
| 4224 | // The subexpression may have side effects. |
| 4225 | VisitForEffect(expr->expression()); |
| 4226 | context()->Plug(true); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4227 | } |
| 4228 | break; |
| 4229 | } |
| 4230 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4231 | case Token::VOID: { |
| 4232 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 4233 | VisitForEffect(expr->expression()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4234 | context()->Plug(isolate()->factory()->undefined_value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4235 | break; |
| 4236 | } |
| 4237 | |
| 4238 | case Token::NOT: { |
| 4239 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4240 | if (context()->IsEffect()) { |
| 4241 | // Unary NOT has no side effects so it's only necessary to visit the |
| 4242 | // subexpression. Match the optimizing compiler by not branching. |
| 4243 | VisitForEffect(expr->expression()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4244 | } else if (context()->IsTest()) { |
| 4245 | const TestContext* test = TestContext::cast(context()); |
| 4246 | // The labels are swapped for the recursive call. |
| 4247 | VisitForControl(expr->expression(), |
| 4248 | test->false_label(), |
| 4249 | test->true_label(), |
| 4250 | test->fall_through()); |
| 4251 | context()->Plug(test->true_label(), test->false_label()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4252 | } else { |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4253 | // We handle value contexts explicitly rather than simply visiting |
| 4254 | // for control and plugging the control flow into the context, |
| 4255 | // because we need to prepare a pair of extra administrative AST ids |
| 4256 | // for the optimizing compiler. |
| 4257 | ASSERT(context()->IsAccumulatorValue() || context()->IsStackValue()); |
| 4258 | Label materialize_true, materialize_false, done; |
| 4259 | VisitForControl(expr->expression(), |
| 4260 | &materialize_false, |
| 4261 | &materialize_true, |
| 4262 | &materialize_true); |
| 4263 | __ bind(&materialize_true); |
| 4264 | PrepareForBailoutForId(expr->MaterializeTrueId(), NO_REGISTERS); |
| 4265 | if (context()->IsAccumulatorValue()) { |
| 4266 | __ mov(eax, isolate()->factory()->true_value()); |
| 4267 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4268 | __ Push(isolate()->factory()->true_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4269 | } |
| 4270 | __ jmp(&done, Label::kNear); |
| 4271 | __ bind(&materialize_false); |
| 4272 | PrepareForBailoutForId(expr->MaterializeFalseId(), NO_REGISTERS); |
| 4273 | if (context()->IsAccumulatorValue()) { |
| 4274 | __ mov(eax, isolate()->factory()->false_value()); |
| 4275 | } else { |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4276 | __ Push(isolate()->factory()->false_value()); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4277 | } |
| 4278 | __ bind(&done); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 4279 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4280 | break; |
| 4281 | } |
| 4282 | |
| 4283 | case Token::TYPEOF: { |
| 4284 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4285 | { StackValueContext context(this); |
| 4286 | VisitForTypeofValue(expr->expression()); |
| 4287 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4288 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4289 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4290 | break; |
| 4291 | } |
| 4292 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4293 | default: |
| 4294 | UNREACHABLE(); |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | |
| 4299 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
machenbach@chromium.org | 4edebd5 | 2014-04-03 00:05:17 +0000 | [diff] [blame] | 4300 | ASSERT(expr->expression()->IsValidReferenceExpression()); |
machenbach@chromium.org | 2904d1a | 2014-03-18 01:05:18 +0000 | [diff] [blame] | 4301 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4302 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4303 | SetSourcePosition(expr->position()); |
| 4304 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4305 | // 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] | 4306 | // slot. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4307 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 4308 | LhsKind assign_type = VARIABLE; |
| 4309 | Property* prop = expr->expression()->AsProperty(); |
| 4310 | // In case of a property we use the uninitialized expression context |
| 4311 | // of the key to detect a named property. |
| 4312 | if (prop != NULL) { |
| 4313 | assign_type = |
| 4314 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 4315 | } |
| 4316 | |
| 4317 | // Evaluate expression and get value. |
| 4318 | if (assign_type == VARIABLE) { |
| 4319 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4320 | AccumulatorValueContext context(this); |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 4321 | EmitVariableLoad(expr->expression()->AsVariableProxy()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4322 | } else { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4323 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4324 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4325 | __ push(Immediate(Smi::FromInt(0))); |
| 4326 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4327 | if (assign_type == NAMED_PROPERTY) { |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4328 | // Put the object both on the stack and in edx. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4329 | VisitForAccumulatorValue(prop->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4330 | __ push(eax); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4331 | __ mov(edx, eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4332 | EmitNamedPropertyLoad(prop); |
| 4333 | } else { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4334 | VisitForStackValue(prop->obj()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4335 | VisitForStackValue(prop->key()); |
| 4336 | __ mov(edx, Operand(esp, kPointerSize)); // Object. |
| 4337 | __ mov(ecx, Operand(esp, 0)); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4338 | EmitKeyedPropertyLoad(prop); |
| 4339 | } |
| 4340 | } |
| 4341 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4342 | // We need a second deoptimization point after loading the value |
| 4343 | // in case evaluating the property load my have a side effect. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4344 | if (assign_type == VARIABLE) { |
| 4345 | PrepareForBailout(expr->expression(), TOS_REG); |
| 4346 | } else { |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 4347 | PrepareForBailoutForId(prop->LoadId(), TOS_REG); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4348 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4349 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4350 | // Inline smi case if we are in a loop. |
| 4351 | Label done, stub_call; |
| 4352 | JumpPatchSite patch_site(masm_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4353 | if (ShouldInlineSmiCase(expr->op())) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4354 | Label slow; |
| 4355 | patch_site.EmitJumpIfNotSmi(eax, &slow, Label::kNear); |
| 4356 | |
| 4357 | // Save result for postfix expressions. |
| 4358 | if (expr->is_postfix()) { |
| 4359 | if (!context()->IsEffect()) { |
| 4360 | // Save the result on the stack. If we have a named or keyed property |
| 4361 | // we store the result under the receiver that is currently on top |
| 4362 | // of the stack. |
| 4363 | switch (assign_type) { |
| 4364 | case VARIABLE: |
| 4365 | __ push(eax); |
| 4366 | break; |
| 4367 | case NAMED_PROPERTY: |
| 4368 | __ mov(Operand(esp, kPointerSize), eax); |
| 4369 | break; |
| 4370 | case KEYED_PROPERTY: |
| 4371 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4372 | break; |
| 4373 | } |
| 4374 | } |
| 4375 | } |
| 4376 | |
| 4377 | if (expr->op() == Token::INC) { |
| 4378 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4379 | } else { |
| 4380 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4381 | } |
| 4382 | __ j(no_overflow, &done, Label::kNear); |
| 4383 | // Call stub. Undo operation first. |
| 4384 | if (expr->op() == Token::INC) { |
| 4385 | __ sub(eax, Immediate(Smi::FromInt(1))); |
| 4386 | } else { |
| 4387 | __ add(eax, Immediate(Smi::FromInt(1))); |
| 4388 | } |
| 4389 | __ jmp(&stub_call, Label::kNear); |
| 4390 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4391 | } |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 4392 | ToNumberStub convert_stub; |
| 4393 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4394 | |
| 4395 | // Save result for postfix expressions. |
| 4396 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4397 | if (!context()->IsEffect()) { |
| 4398 | // Save the result on the stack. If we have a named or keyed property |
| 4399 | // we store the result under the receiver that is currently on top |
| 4400 | // of the stack. |
| 4401 | switch (assign_type) { |
| 4402 | case VARIABLE: |
| 4403 | __ push(eax); |
| 4404 | break; |
| 4405 | case NAMED_PROPERTY: |
| 4406 | __ mov(Operand(esp, kPointerSize), eax); |
| 4407 | break; |
| 4408 | case KEYED_PROPERTY: |
| 4409 | __ mov(Operand(esp, 2 * kPointerSize), eax); |
| 4410 | break; |
| 4411 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4412 | } |
| 4413 | } |
| 4414 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4415 | // Record position before stub call. |
| 4416 | SetSourcePosition(expr->position()); |
| 4417 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4418 | // Call stub for +1/-1. |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 4419 | __ bind(&stub_call); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4420 | __ mov(edx, eax); |
| 4421 | __ mov(eax, Immediate(Smi::FromInt(1))); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 4422 | BinaryOpICStub stub(expr->binary_op(), NO_OVERWRITE); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4423 | CallIC(stub.GetCode(isolate()), expr->CountBinOpFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4424 | patch_site.EmitPatchInfo(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4425 | __ bind(&done); |
| 4426 | |
| 4427 | // Store the value returned in eax. |
| 4428 | switch (assign_type) { |
| 4429 | case VARIABLE: |
| 4430 | if (expr->is_postfix()) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4431 | // Perform the assignment as if via '='. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4432 | { EffectContext context(this); |
| 4433 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 4434 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4435 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4436 | context.Plug(eax); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4437 | } |
| 4438 | // For all contexts except EffectContext We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4439 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4440 | if (!context()->IsEffect()) { |
| 4441 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4442 | } |
| 4443 | } else { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4444 | // Perform the assignment as if via '='. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4445 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4446 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4447 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 4448 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4449 | } |
| 4450 | break; |
| 4451 | case NAMED_PROPERTY: { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4452 | __ mov(ecx, prop->key()->AsLiteral()->value()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4453 | __ pop(edx); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4454 | CallStoreIC(expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4455 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4456 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4457 | if (!context()->IsEffect()) { |
| 4458 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4459 | } |
| 4460 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4461 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4462 | } |
| 4463 | break; |
| 4464 | } |
| 4465 | case KEYED_PROPERTY: { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4466 | __ pop(ecx); |
| 4467 | __ pop(edx); |
dslomov@chromium.org | 486536d | 2014-03-12 13:09:18 +0000 | [diff] [blame] | 4468 | Handle<Code> ic = strict_mode() == SLOPPY |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4469 | ? isolate()->builtins()->KeyedStoreIC_Initialize() |
| 4470 | : isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4471 | CallIC(ic, expr->CountStoreFeedbackId()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4472 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4473 | if (expr->is_postfix()) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4474 | // Result is on the stack |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4475 | if (!context()->IsEffect()) { |
| 4476 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4477 | } |
| 4478 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4479 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4480 | } |
| 4481 | break; |
| 4482 | } |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4487 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4488 | VariableProxy* proxy = expr->AsVariableProxy(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4489 | ASSERT(!context()->IsEffect()); |
| 4490 | ASSERT(!context()->IsTest()); |
| 4491 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4492 | if (proxy != NULL && proxy->var()->IsUnallocated()) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4493 | Comment cmnt(masm_, "[ Global variable"); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 4494 | __ mov(edx, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4495 | __ mov(ecx, Immediate(proxy->name())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4496 | // Use a regular load, not a contextual load, to avoid a reference |
| 4497 | // error. |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 4498 | CallLoadIC(NOT_CONTEXTUAL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4499 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4500 | context()->Plug(eax); |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4501 | } else if (proxy != NULL && proxy->var()->IsLookupSlot()) { |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4502 | Comment cmnt(masm_, "[ Lookup slot"); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4503 | Label done, slow; |
| 4504 | |
| 4505 | // Generate code for loading from variables potentially shadowed |
| 4506 | // by eval-introduced variables. |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4507 | EmitDynamicLookupFastCase(proxy->var(), INSIDE_TYPEOF, &slow, &done); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4508 | |
| 4509 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4510 | __ push(esi); |
| 4511 | __ push(Immediate(proxy->name())); |
machenbach@chromium.org | 895f00d | 2014-03-27 01:04:43 +0000 | [diff] [blame] | 4512 | __ CallRuntime(Runtime::kHiddenLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4513 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4514 | __ bind(&done); |
| 4515 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4516 | context()->Plug(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4517 | } else { |
| 4518 | // This expression cannot throw a reference error at the top level. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4519 | VisitInDuplicateContext(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4524 | void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4525 | Expression* sub_expr, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4526 | Handle<String> check) { |
| 4527 | Label materialize_true, materialize_false; |
| 4528 | Label* if_true = NULL; |
| 4529 | Label* if_false = NULL; |
| 4530 | Label* fall_through = NULL; |
| 4531 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4532 | &if_true, &if_false, &fall_through); |
| 4533 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4534 | { AccumulatorValueContext context(this); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4535 | VisitForTypeofValue(sub_expr); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4536 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4537 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4538 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4539 | if (check->Equals(isolate()->heap()->number_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4540 | __ JumpIfSmi(eax, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4541 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4542 | isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4543 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4544 | } else if (check->Equals(isolate()->heap()->string_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4545 | __ JumpIfSmi(eax, if_false); |
| 4546 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, edx); |
| 4547 | __ j(above_equal, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4548 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4549 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4550 | 1 << Map::kIsUndetectable); |
| 4551 | Split(zero, if_true, if_false, fall_through); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4552 | } else if (check->Equals(isolate()->heap()->symbol_string())) { |
| 4553 | __ JumpIfSmi(eax, if_false); |
| 4554 | __ CmpObjectType(eax, SYMBOL_TYPE, edx); |
| 4555 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4556 | } else if (check->Equals(isolate()->heap()->boolean_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4557 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4558 | __ j(equal, if_true); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4559 | __ cmp(eax, isolate()->factory()->false_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4560 | Split(equal, if_true, if_false, fall_through); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4561 | } else if (FLAG_harmony_typeof && |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4562 | check->Equals(isolate()->heap()->null_string())) { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4563 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4564 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4565 | } else if (check->Equals(isolate()->heap()->undefined_string())) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4566 | __ cmp(eax, isolate()->factory()->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4567 | __ j(equal, if_true); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4568 | __ JumpIfSmi(eax, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4569 | // Check for undetectable objects => true. |
| 4570 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4571 | __ movzx_b(ecx, FieldOperand(edx, Map::kBitFieldOffset)); |
| 4572 | __ test(ecx, Immediate(1 << Map::kIsUndetectable)); |
| 4573 | Split(not_zero, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4574 | } else if (check->Equals(isolate()->heap()->function_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4575 | __ JumpIfSmi(eax, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4576 | STATIC_ASSERT(NUM_OF_CALLABLE_SPEC_OBJECT_TYPES == 2); |
| 4577 | __ CmpObjectType(eax, JS_FUNCTION_TYPE, edx); |
| 4578 | __ j(equal, if_true); |
| 4579 | __ CmpInstanceType(edx, JS_FUNCTION_PROXY_TYPE); |
| 4580 | Split(equal, if_true, if_false, fall_through); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4581 | } else if (check->Equals(isolate()->heap()->object_string())) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4582 | __ JumpIfSmi(eax, if_false); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 4583 | if (!FLAG_harmony_typeof) { |
| 4584 | __ cmp(eax, isolate()->factory()->null_value()); |
| 4585 | __ j(equal, if_true); |
| 4586 | } |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4587 | __ CmpObjectType(eax, FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, edx); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4588 | __ j(below, if_false); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4589 | __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); |
| 4590 | __ j(above, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4591 | // Check for undetectable objects => false. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 4592 | __ test_b(FieldOperand(edx, Map::kBitFieldOffset), |
| 4593 | 1 << Map::kIsUndetectable); |
| 4594 | Split(zero, if_true, if_false, fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4595 | } else { |
| 4596 | if (if_false != fall_through) __ jmp(if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4597 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4598 | context()->Plug(if_true, if_false); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4602 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 4603 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4604 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4605 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4606 | // First we try a fast inlined version of the compare when one of |
| 4607 | // the operands is a literal. |
| 4608 | if (TryLiteralCompare(expr)) return; |
| 4609 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4610 | // Always perform the comparison for its control flow. Pack the result |
| 4611 | // into the expression's context after the comparison is performed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4612 | Label materialize_true, materialize_false; |
| 4613 | Label* if_true = NULL; |
| 4614 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4615 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4616 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4617 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4618 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 4619 | Token::Value op = expr->op(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4620 | VisitForStackValue(expr->left()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4621 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4622 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4623 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4624 | __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4625 | PrepareForBailoutBeforeSplit(expr, false, NULL, NULL); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4626 | __ cmp(eax, isolate()->factory()->true_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4627 | Split(equal, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4628 | break; |
| 4629 | |
| 4630 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4631 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4632 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4633 | __ CallStub(&stub); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4634 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4635 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4636 | // The stub returns 0 for true. |
| 4637 | Split(zero, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4638 | break; |
| 4639 | } |
| 4640 | |
| 4641 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4642 | VisitForAccumulatorValue(expr->right()); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4643 | Condition cc = CompareIC::ComputeCondition(op); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4644 | __ pop(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4645 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4646 | bool inline_smi_code = ShouldInlineSmiCase(op); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4647 | JumpPatchSite patch_site(masm_); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4648 | if (inline_smi_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4649 | Label slow_case; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4650 | __ mov(ecx, edx); |
| 4651 | __ or_(ecx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4652 | patch_site.EmitJumpIfNotSmi(ecx, &slow_case, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4653 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4654 | Split(cc, if_true, if_false, NULL); |
| 4655 | __ bind(&slow_case); |
| 4656 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4657 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4658 | // Record position and call the compare IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4659 | SetSourcePosition(expr->position()); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4660 | Handle<Code> ic = CompareIC::GetUninitialized(isolate(), op); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4661 | CallIC(ic, expr->CompareOperationFeedbackId()); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4662 | patch_site.EmitPatchInfo(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4663 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4664 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4665 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4666 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4667 | } |
| 4668 | } |
| 4669 | |
| 4670 | // Convert the result of the comparison into one expected for this |
| 4671 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4672 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4676 | void FullCodeGenerator::EmitLiteralCompareNil(CompareOperation* expr, |
| 4677 | Expression* sub_expr, |
| 4678 | NilValue nil) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4679 | Label materialize_true, materialize_false; |
| 4680 | Label* if_true = NULL; |
| 4681 | Label* if_false = NULL; |
| 4682 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4683 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 4684 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4685 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4686 | VisitForAccumulatorValue(sub_expr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4687 | PrepareForBailoutBeforeSplit(expr, true, if_true, if_false); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4688 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4689 | Handle<Object> nil_value = nil == kNullValue |
| 4690 | ? isolate()->factory()->null_value() |
| 4691 | : isolate()->factory()->undefined_value(); |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4692 | if (expr->op() == Token::EQ_STRICT) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4693 | __ cmp(eax, nil_value); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4694 | Split(equal, if_true, if_false, fall_through); |
| 4695 | } else { |
ulan@chromium.org | 837a67e | 2013-06-11 15:39:48 +0000 | [diff] [blame] | 4696 | Handle<Code> ic = CompareNilICStub::GetUninitialized(isolate(), nil); |
titzer@chromium.org | f5a2454 | 2014-03-04 09:06:17 +0000 | [diff] [blame] | 4697 | CallIC(ic, expr->CompareOperationFeedbackId()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4698 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4699 | Split(not_zero, if_true, if_false, fall_through); |
| 4700 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4701 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
| 4704 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4705 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 4706 | __ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4707 | context()->Plug(eax); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4708 | } |
| 4709 | |
| 4710 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4711 | Register FullCodeGenerator::result_register() { |
| 4712 | return eax; |
| 4713 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4714 | |
| 4715 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4716 | Register FullCodeGenerator::context_register() { |
| 4717 | return esi; |
| 4718 | } |
| 4719 | |
| 4720 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4721 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 4722 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 4723 | __ mov(Operand(ebp, frame_offset), value); |
| 4724 | } |
| 4725 | |
| 4726 | |
| 4727 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 4728 | __ mov(dst, ContextOperand(esi, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4732 | void FullCodeGenerator::PushFunctionArgumentForContextAllocation() { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4733 | Scope* declaration_scope = scope()->DeclarationScope(); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4734 | if (declaration_scope->is_global_scope() || |
| 4735 | declaration_scope->is_module_scope()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4736 | // Contexts nested in the native context have a canonical empty function |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4737 | // as their closure, not the anonymous closure containing the global |
| 4738 | // code. Pass a smi sentinel and let the runtime look up the empty |
| 4739 | // function. |
| 4740 | __ push(Immediate(Smi::FromInt(0))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4741 | } else if (declaration_scope->is_eval_scope()) { |
| 4742 | // Contexts nested inside eval code have the same closure as the context |
| 4743 | // calling eval, not the anonymous closure containing the eval code. |
| 4744 | // Fetch it from the context. |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4745 | __ push(ContextOperand(esi, Context::CLOSURE_INDEX)); |
| 4746 | } else { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4747 | ASSERT(declaration_scope->is_function_scope()); |
vegorov@chromium.org | 3cf4731 | 2011-06-29 13:20:01 +0000 | [diff] [blame] | 4748 | __ push(Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4749 | } |
| 4750 | } |
| 4751 | |
| 4752 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4753 | // ---------------------------------------------------------------------------- |
| 4754 | // Non-local control flow support. |
| 4755 | |
| 4756 | void FullCodeGenerator::EnterFinallyBlock() { |
| 4757 | // Cook return address on top of stack (smi encoded Code* delta) |
| 4758 | ASSERT(!result_register().is(edx)); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4759 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4760 | __ sub(edx, Immediate(masm_->CodeObject())); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4761 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4762 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4763 | __ SmiTag(edx); |
| 4764 | __ push(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4765 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4766 | // Store result register while executing finally block. |
| 4767 | __ push(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4768 | |
| 4769 | // Store pending message while executing finally block. |
| 4770 | ExternalReference pending_message_obj = |
| 4771 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4772 | __ mov(edx, Operand::StaticVariable(pending_message_obj)); |
| 4773 | __ push(edx); |
| 4774 | |
| 4775 | ExternalReference has_pending_message = |
| 4776 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4777 | __ mov(edx, Operand::StaticVariable(has_pending_message)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4778 | __ SmiTag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4779 | __ push(edx); |
| 4780 | |
| 4781 | ExternalReference pending_message_script = |
| 4782 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4783 | __ mov(edx, Operand::StaticVariable(pending_message_script)); |
| 4784 | __ push(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | |
| 4788 | void FullCodeGenerator::ExitFinallyBlock() { |
| 4789 | ASSERT(!result_register().is(edx)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4790 | // Restore pending message from stack. |
| 4791 | __ pop(edx); |
| 4792 | ExternalReference pending_message_script = |
| 4793 | ExternalReference::address_of_pending_message_script(isolate()); |
| 4794 | __ mov(Operand::StaticVariable(pending_message_script), edx); |
| 4795 | |
| 4796 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4797 | __ SmiUntag(edx); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4798 | ExternalReference has_pending_message = |
| 4799 | ExternalReference::address_of_has_pending_message(isolate()); |
| 4800 | __ mov(Operand::StaticVariable(has_pending_message), edx); |
| 4801 | |
| 4802 | __ pop(edx); |
| 4803 | ExternalReference pending_message_obj = |
| 4804 | ExternalReference::address_of_pending_message_obj(isolate()); |
| 4805 | __ mov(Operand::StaticVariable(pending_message_obj), edx); |
| 4806 | |
| 4807 | // Restore result register from stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4808 | __ pop(result_register()); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4809 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4810 | // Uncook return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4811 | __ pop(edx); |
| 4812 | __ SmiUntag(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4813 | __ add(edx, Immediate(masm_->CodeObject())); |
| 4814 | __ jmp(edx); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | |
| 4818 | #undef __ |
| 4819 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4820 | #define __ ACCESS_MASM(masm()) |
| 4821 | |
| 4822 | FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( |
| 4823 | int* stack_depth, |
| 4824 | int* context_length) { |
| 4825 | // The macros used here must preserve the result register. |
| 4826 | |
| 4827 | // Because the handler block contains the context of the finally |
| 4828 | // code, we can restore it directly from there for the finally code |
| 4829 | // rather than iteratively unwinding contexts via their previous |
| 4830 | // links. |
| 4831 | __ Drop(*stack_depth); // Down to the handler block. |
| 4832 | if (*context_length > 0) { |
| 4833 | // Restore the context to its dedicated register and the stack. |
| 4834 | __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); |
| 4835 | __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); |
| 4836 | } |
| 4837 | __ PopTryHandler(); |
| 4838 | __ call(finally_entry_); |
| 4839 | |
| 4840 | *stack_depth = 0; |
| 4841 | *context_length = 0; |
| 4842 | return previous_; |
| 4843 | } |
| 4844 | |
jkummerow@chromium.org | 486075a | 2011-09-07 12:44:28 +0000 | [diff] [blame] | 4845 | #undef __ |
| 4846 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4847 | |
| 4848 | static const byte kJnsInstruction = 0x79; |
| 4849 | static const byte kJnsOffset = 0x11; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4850 | static const byte kNopByteOne = 0x66; |
| 4851 | static const byte kNopByteTwo = 0x90; |
machenbach@chromium.org | afbdadc | 2013-12-09 16:12:18 +0000 | [diff] [blame] | 4852 | #ifdef DEBUG |
| 4853 | static const byte kCallInstruction = 0xe8; |
| 4854 | #endif |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4855 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4856 | |
| 4857 | void BackEdgeTable::PatchAt(Code* unoptimized_code, |
| 4858 | Address pc, |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4859 | BackEdgeState target_state, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4860 | Code* replacement_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4861 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4862 | Address jns_instr_address = call_target_address - 3; |
| 4863 | Address jns_offset_address = call_target_address - 2; |
| 4864 | |
| 4865 | switch (target_state) { |
| 4866 | case INTERRUPT: |
| 4867 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4868 | // jns ok |
| 4869 | // call <interrupt stub> |
| 4870 | // ok: |
| 4871 | *jns_instr_address = kJnsInstruction; |
| 4872 | *jns_offset_address = kJnsOffset; |
| 4873 | break; |
| 4874 | case ON_STACK_REPLACEMENT: |
| 4875 | case OSR_AFTER_STACK_CHECK: |
| 4876 | // sub <profiling_counter>, <delta> ;; Not changed |
| 4877 | // nop |
| 4878 | // nop |
| 4879 | // call <on-stack replacment> |
| 4880 | // ok: |
| 4881 | *jns_instr_address = kNopByteOne; |
| 4882 | *jns_offset_address = kNopByteTwo; |
| 4883 | break; |
| 4884 | } |
| 4885 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4886 | Assembler::set_target_address_at(call_target_address, |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4887 | unoptimized_code, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4888 | replacement_code->entry()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4889 | unoptimized_code->GetHeap()->incremental_marking()->RecordCodeTargetPatch( |
| 4890 | unoptimized_code, call_target_address, replacement_code); |
| 4891 | } |
| 4892 | |
| 4893 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4894 | BackEdgeTable::BackEdgeState BackEdgeTable::GetBackEdgeState( |
| 4895 | Isolate* isolate, |
| 4896 | Code* unoptimized_code, |
| 4897 | Address pc) { |
| 4898 | Address call_target_address = pc - kIntSize; |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4899 | Address jns_instr_address = call_target_address - 3; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4900 | ASSERT_EQ(kCallInstruction, *(call_target_address - 1)); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4901 | |
| 4902 | if (*jns_instr_address == kJnsInstruction) { |
| 4903 | ASSERT_EQ(kJnsOffset, *(call_target_address - 2)); |
| 4904 | ASSERT_EQ(isolate->builtins()->InterruptCheck()->entry(), |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4905 | Assembler::target_address_at(call_target_address, |
| 4906 | unoptimized_code)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4907 | return INTERRUPT; |
| 4908 | } |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4909 | |
| 4910 | ASSERT_EQ(kNopByteOne, *jns_instr_address); |
| 4911 | ASSERT_EQ(kNopByteTwo, *(call_target_address - 2)); |
| 4912 | |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4913 | if (Assembler::target_address_at(call_target_address, unoptimized_code) == |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4914 | isolate->builtins()->OnStackReplacement()->entry()) { |
| 4915 | return ON_STACK_REPLACEMENT; |
| 4916 | } |
| 4917 | |
| 4918 | ASSERT_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
machenbach@chromium.org | 97b98c9 | 2014-03-13 03:05:00 +0000 | [diff] [blame] | 4919 | Assembler::target_address_at(call_target_address, |
| 4920 | unoptimized_code)); |
machenbach@chromium.org | 8e36b5b | 2013-09-26 07:36:30 +0000 | [diff] [blame] | 4921 | return OSR_AFTER_STACK_CHECK; |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4922 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4923 | |
| 4924 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4925 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 4926 | |
| 4927 | #endif // V8_TARGET_ARCH_IA32 |