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