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