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