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