kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame^] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 30 | #if defined(V8_TARGET_ARCH_ARM) |
| 31 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 32 | #include "code-stubs.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 33 | #include "codegen-inl.h" |
| 34 | #include "compiler.h" |
| 35 | #include "debug.h" |
| 36 | #include "full-codegen.h" |
| 37 | #include "parser.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 38 | #include "scopes.h" |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 39 | #include "stub-cache.h" |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 40 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 41 | #include "arm/code-stubs-arm.h" |
| 42 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 43 | namespace v8 { |
| 44 | namespace internal { |
| 45 | |
| 46 | #define __ ACCESS_MASM(masm_) |
| 47 | |
| 48 | // Generate code for a JS function. On entry to the function the receiver |
| 49 | // and arguments have been pushed on the stack left to right. The actual |
| 50 | // argument count matches the formal parameter count expected by the |
| 51 | // function. |
| 52 | // |
| 53 | // The live registers are: |
| 54 | // o r1: the JS function object being called (ie, ourselves) |
| 55 | // o cp: our context |
| 56 | // o fp: our caller's frame pointer |
| 57 | // o sp: stack pointer |
| 58 | // o lr: return address |
| 59 | // |
| 60 | // The function builds a JS frame. Please see JavaScriptFrameConstants in |
| 61 | // frames-arm.h for its layout. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 62 | void FullCodeGenerator::Generate(CompilationInfo* info) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 63 | ASSERT(info_ == NULL); |
| 64 | info_ = info; |
| 65 | SetFunctionPosition(function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 66 | Comment cmnt(masm_, "[ function compiled by full code generator"); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 67 | |
vegorov@chromium.org | 4284196 | 2010-10-18 11:18:59 +0000 | [diff] [blame] | 68 | #ifdef DEBUG |
| 69 | if (strlen(FLAG_stop_at) > 0 && |
| 70 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
| 71 | __ stop("stop-at"); |
| 72 | } |
| 73 | #endif |
| 74 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 75 | int locals_count = scope()->num_stack_slots(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 76 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 77 | __ Push(lr, fp, cp, r1); |
| 78 | if (locals_count > 0) { |
| 79 | // Load undefined value here, so the value is ready for the loop |
| 80 | // below. |
| 81 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 82 | } |
| 83 | // Adjust fp to point to caller's fp. |
| 84 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 85 | |
| 86 | { Comment cmnt(masm_, "[ Allocate locals"); |
| 87 | for (int i = 0; i < locals_count; i++) { |
| 88 | __ push(ip); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 89 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 90 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 91 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 92 | bool function_in_register = true; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 93 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 94 | // Possibly allocate a local context. |
| 95 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 96 | if (heap_slots > 0) { |
| 97 | Comment cmnt(masm_, "[ Allocate local context"); |
| 98 | // Argument to NewContext is the function, which is in r1. |
| 99 | __ push(r1); |
| 100 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 101 | FastNewContextStub stub(heap_slots); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 102 | __ CallStub(&stub); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 103 | } else { |
| 104 | __ CallRuntime(Runtime::kNewContext, 1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 105 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 106 | function_in_register = false; |
| 107 | // Context is returned in both r0 and cp. It replaces the context |
| 108 | // passed to us. It's saved in the stack and kept live in cp. |
| 109 | __ str(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 110 | // Copy any necessary parameters into the context. |
| 111 | int num_parameters = scope()->num_parameters(); |
| 112 | for (int i = 0; i < num_parameters; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 113 | Slot* slot = scope()->parameter(i)->AsSlot(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 114 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 115 | int parameter_offset = StandardFrameConstants::kCallerSPOffset + |
| 116 | (num_parameters - 1 - i) * kPointerSize; |
| 117 | // Load parameter from stack. |
| 118 | __ ldr(r0, MemOperand(fp, parameter_offset)); |
| 119 | // Store it in the context. |
| 120 | __ mov(r1, Operand(Context::SlotOffset(slot->index()))); |
| 121 | __ str(r0, MemOperand(cp, r1)); |
| 122 | // Update the write barrier. This clobbers all involved |
| 123 | // registers, so we have to use two more registers to avoid |
| 124 | // clobbering cp. |
| 125 | __ mov(r2, Operand(cp)); |
| 126 | __ RecordWrite(r2, Operand(r1), r3, r0); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 131 | Variable* arguments = scope()->arguments(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 132 | if (arguments != NULL) { |
| 133 | // Function uses arguments object. |
| 134 | Comment cmnt(masm_, "[ Allocate arguments object"); |
| 135 | if (!function_in_register) { |
| 136 | // Load this again, if it's used by the local context below. |
| 137 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 138 | } else { |
| 139 | __ mov(r3, r1); |
| 140 | } |
| 141 | // Receiver is just before the parameters on the caller's stack. |
| 142 | int offset = scope()->num_parameters() * kPointerSize; |
| 143 | __ add(r2, fp, |
| 144 | Operand(StandardFrameConstants::kCallerSPOffset + offset)); |
| 145 | __ mov(r1, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 146 | __ Push(r3, r2, r1); |
| 147 | |
| 148 | // Arguments to ArgumentsAccessStub: |
| 149 | // function, receiver address, parameter count. |
| 150 | // The stub will rewrite receiever and parameter count if the previous |
| 151 | // stack frame was an arguments adapter frame. |
| 152 | ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 153 | __ CallStub(&stub); |
| 154 | // Duplicate the value; move-to-slot operation might clobber registers. |
| 155 | __ mov(r3, r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 156 | Move(arguments->AsSlot(), r0, r1, r2); |
| 157 | Slot* dot_arguments_slot = scope()->arguments_shadow()->AsSlot(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 158 | Move(dot_arguments_slot, r3, r1, r2); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 159 | } |
| 160 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 161 | { Comment cmnt(masm_, "[ Declarations"); |
| 162 | // For named function expressions, declare the function name as a |
| 163 | // constant. |
| 164 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 165 | EmitDeclaration(scope()->function(), Variable::CONST, NULL); |
| 166 | } |
| 167 | // Visit all the explicit declarations unless there is an illegal |
| 168 | // redeclaration. |
| 169 | if (scope()->HasIllegalRedeclaration()) { |
| 170 | scope()->VisitIllegalRedeclaration(this); |
| 171 | } else { |
| 172 | VisitDeclarations(scope()->declarations()); |
| 173 | } |
| 174 | } |
| 175 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 176 | if (FLAG_trace) { |
| 177 | __ CallRuntime(Runtime::kTraceEnter, 0); |
| 178 | } |
| 179 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 180 | // Check the stack for overflow or break request. |
| 181 | { Comment cmnt(masm_, "[ Stack check"); |
| 182 | PrepareForBailout(info->function(), NO_REGISTERS); |
| 183 | Label ok; |
| 184 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 185 | __ cmp(sp, Operand(ip)); |
| 186 | __ b(hs, &ok); |
| 187 | StackCheckStub stub; |
| 188 | __ CallStub(&stub); |
| 189 | __ bind(&ok); |
| 190 | } |
| 191 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 192 | { Comment cmnt(masm_, "[ Body"); |
| 193 | ASSERT(loop_depth() == 0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 194 | VisitStatements(function()->body()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 195 | ASSERT(loop_depth() == 0); |
| 196 | } |
| 197 | |
| 198 | { Comment cmnt(masm_, "[ return <undefined>;"); |
| 199 | // Emit a 'return undefined' in case control fell off the end of the |
| 200 | // body. |
| 201 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 202 | } |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 203 | EmitReturnSequence(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 204 | |
| 205 | // Force emit the constant pool, so it doesn't get emitted in the middle |
| 206 | // of the stack check table. |
| 207 | masm()->CheckConstPool(true, false); |
| 208 | } |
| 209 | |
| 210 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 211 | void FullCodeGenerator::ClearAccumulator() { |
| 212 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 213 | } |
| 214 | |
| 215 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 216 | void FullCodeGenerator::EmitStackCheck(IterationStatement* stmt) { |
| 217 | Comment cmnt(masm_, "[ Stack check"); |
| 218 | Label ok; |
| 219 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 220 | __ cmp(sp, Operand(ip)); |
| 221 | __ b(hs, &ok); |
| 222 | StackCheckStub stub; |
| 223 | __ CallStub(&stub); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame^] | 224 | // Record a mapping of this PC offset to the OSR id. This is used to find |
| 225 | // the AST id from the unoptimized code in order to use it as a key into |
| 226 | // the deoptimization input data found in the optimized code. |
| 227 | RecordStackCheck(stmt->OsrEntryId()); |
| 228 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 229 | __ bind(&ok); |
| 230 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame^] | 231 | // Record a mapping of the OSR id to this PC. This is used if the OSR |
| 232 | // entry becomes the target of a bailout. We don't expect it to be, but |
| 233 | // we want it to work if it is. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 234 | PrepareForBailoutForId(stmt->OsrEntryId(), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 238 | void FullCodeGenerator::EmitReturnSequence() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 239 | Comment cmnt(masm_, "[ Return sequence"); |
| 240 | if (return_label_.is_bound()) { |
| 241 | __ b(&return_label_); |
| 242 | } else { |
| 243 | __ bind(&return_label_); |
| 244 | if (FLAG_trace) { |
| 245 | // Push the return value on the stack as the parameter. |
| 246 | // Runtime::TraceExit returns its parameter in r0. |
| 247 | __ push(r0); |
| 248 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 249 | } |
| 250 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 251 | #ifdef DEBUG |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 252 | // Add a label for checking the size of the code used for returning. |
| 253 | Label check_exit_codesize; |
| 254 | masm_->bind(&check_exit_codesize); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 255 | #endif |
| 256 | // Make sure that the constant pool is not emitted inside of the return |
| 257 | // sequence. |
| 258 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 259 | // Here we use masm_-> instead of the __ macro to avoid the code coverage |
| 260 | // tool from instrumenting as we rely on the code size here. |
| 261 | int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 262 | CodeGenerator::RecordPositions(masm_, function()->end_position() - 1); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 263 | __ RecordJSReturn(); |
| 264 | masm_->mov(sp, fp); |
| 265 | masm_->ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 266 | masm_->add(sp, sp, Operand(sp_delta)); |
| 267 | masm_->Jump(lr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 268 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 269 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 270 | #ifdef DEBUG |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 271 | // Check that the size of the code used for returning matches what is |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 272 | // expected by the debugger. If the sp_delts above cannot be encoded in the |
| 273 | // add instruction the add will generate two instructions. |
| 274 | int return_sequence_length = |
| 275 | masm_->InstructionsGeneratedSince(&check_exit_codesize); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 276 | CHECK(return_sequence_length == |
| 277 | Assembler::kJSReturnSequenceInstructions || |
| 278 | return_sequence_length == |
| 279 | Assembler::kJSReturnSequenceInstructions + 1); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 280 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 285 | FullCodeGenerator::ConstantOperand FullCodeGenerator::GetConstantOperand( |
| 286 | Token::Value op, Expression* left, Expression* right) { |
| 287 | ASSERT(ShouldInlineSmiCase(op)); |
| 288 | return kNoConstants; |
| 289 | } |
| 290 | |
| 291 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 292 | void FullCodeGenerator::EffectContext::Plug(Slot* slot) const { |
| 293 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 294 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 295 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 296 | void FullCodeGenerator::AccumulatorValueContext::Plug(Slot* slot) const { |
| 297 | codegen()->Move(result_register(), slot); |
| 298 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 299 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 300 | |
| 301 | void FullCodeGenerator::StackValueContext::Plug(Slot* slot) const { |
| 302 | codegen()->Move(result_register(), slot); |
| 303 | __ push(result_register()); |
| 304 | } |
| 305 | |
| 306 | |
| 307 | void FullCodeGenerator::TestContext::Plug(Slot* slot) const { |
| 308 | // For simplicity we always test the accumulator register. |
| 309 | codegen()->Move(result_register(), slot); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 310 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 311 | codegen()->DoTest(true_label_, false_label_, fall_through_); |
| 312 | } |
| 313 | |
| 314 | |
| 315 | void FullCodeGenerator::EffectContext::Plug(Heap::RootListIndex index) const { |
| 316 | } |
| 317 | |
| 318 | |
| 319 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 320 | Heap::RootListIndex index) const { |
| 321 | __ LoadRoot(result_register(), index); |
| 322 | } |
| 323 | |
| 324 | |
| 325 | void FullCodeGenerator::StackValueContext::Plug( |
| 326 | Heap::RootListIndex index) const { |
| 327 | __ LoadRoot(result_register(), index); |
| 328 | __ push(result_register()); |
| 329 | } |
| 330 | |
| 331 | |
| 332 | void FullCodeGenerator::TestContext::Plug(Heap::RootListIndex index) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 333 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 334 | true, |
| 335 | true_label_, |
| 336 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 337 | if (index == Heap::kUndefinedValueRootIndex || |
| 338 | index == Heap::kNullValueRootIndex || |
| 339 | index == Heap::kFalseValueRootIndex) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 340 | if (false_label_ != fall_through_) __ b(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 341 | } else if (index == Heap::kTrueValueRootIndex) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | if (true_label_ != fall_through_) __ b(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 343 | } else { |
| 344 | __ LoadRoot(result_register(), index); |
| 345 | codegen()->DoTest(true_label_, false_label_, fall_through_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 350 | void FullCodeGenerator::EffectContext::Plug(Handle<Object> lit) const { |
| 351 | } |
| 352 | |
| 353 | |
| 354 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 355 | Handle<Object> lit) const { |
| 356 | __ mov(result_register(), Operand(lit)); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | void FullCodeGenerator::StackValueContext::Plug(Handle<Object> lit) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 361 | // Immediates cannot be pushed directly. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 362 | __ mov(result_register(), Operand(lit)); |
| 363 | __ push(result_register()); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | void FullCodeGenerator::TestContext::Plug(Handle<Object> lit) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 368 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 369 | true, |
| 370 | true_label_, |
| 371 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 372 | ASSERT(!lit->IsUndetectableObject()); // There are no undetectable literals. |
| 373 | if (lit->IsUndefined() || lit->IsNull() || lit->IsFalse()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 374 | if (false_label_ != fall_through_) __ b(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 375 | } else if (lit->IsTrue() || lit->IsJSObject()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 376 | if (true_label_ != fall_through_) __ b(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 377 | } else if (lit->IsString()) { |
| 378 | if (String::cast(*lit)->length() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 379 | if (false_label_ != fall_through_) __ b(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 380 | __ b(false_label_); |
| 381 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 382 | if (true_label_ != fall_through_) __ b(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 383 | } |
| 384 | } else if (lit->IsSmi()) { |
| 385 | if (Smi::cast(*lit)->value() == 0) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 386 | if (false_label_ != fall_through_) __ b(false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 387 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 388 | if (true_label_ != fall_through_) __ b(true_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 389 | } |
| 390 | } else { |
| 391 | // For simplicity we always test the accumulator register. |
| 392 | __ mov(result_register(), Operand(lit)); |
| 393 | codegen()->DoTest(true_label_, false_label_, fall_through_); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 398 | void FullCodeGenerator::EffectContext::DropAndPlug(int count, |
| 399 | Register reg) const { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 400 | ASSERT(count > 0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 401 | __ Drop(count); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 402 | } |
| 403 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 404 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 405 | void FullCodeGenerator::AccumulatorValueContext::DropAndPlug( |
| 406 | int count, |
| 407 | Register reg) const { |
| 408 | ASSERT(count > 0); |
| 409 | __ Drop(count); |
| 410 | __ Move(result_register(), reg); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 414 | void FullCodeGenerator::StackValueContext::DropAndPlug(int count, |
| 415 | Register reg) const { |
| 416 | ASSERT(count > 0); |
| 417 | if (count > 1) __ Drop(count - 1); |
| 418 | __ str(reg, MemOperand(sp, 0)); |
| 419 | } |
| 420 | |
| 421 | |
| 422 | void FullCodeGenerator::TestContext::DropAndPlug(int count, |
| 423 | Register reg) const { |
| 424 | ASSERT(count > 0); |
| 425 | // For simplicity we always test the accumulator register. |
| 426 | __ Drop(count); |
| 427 | __ Move(result_register(), reg); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 428 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 429 | codegen()->DoTest(true_label_, false_label_, fall_through_); |
| 430 | } |
| 431 | |
| 432 | |
| 433 | void FullCodeGenerator::EffectContext::Plug(Label* materialize_true, |
| 434 | Label* materialize_false) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 435 | ASSERT(materialize_true == materialize_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 436 | __ bind(materialize_true); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | void FullCodeGenerator::AccumulatorValueContext::Plug( |
| 441 | Label* materialize_true, |
| 442 | Label* materialize_false) const { |
| 443 | Label done; |
| 444 | __ bind(materialize_true); |
| 445 | __ LoadRoot(result_register(), Heap::kTrueValueRootIndex); |
| 446 | __ jmp(&done); |
| 447 | __ bind(materialize_false); |
| 448 | __ LoadRoot(result_register(), Heap::kFalseValueRootIndex); |
| 449 | __ bind(&done); |
| 450 | } |
| 451 | |
| 452 | |
| 453 | void FullCodeGenerator::StackValueContext::Plug( |
| 454 | Label* materialize_true, |
| 455 | Label* materialize_false) const { |
| 456 | Label done; |
| 457 | __ bind(materialize_true); |
| 458 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 459 | __ push(ip); |
| 460 | __ jmp(&done); |
| 461 | __ bind(materialize_false); |
| 462 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 463 | __ push(ip); |
| 464 | __ bind(&done); |
| 465 | } |
| 466 | |
| 467 | |
| 468 | void FullCodeGenerator::TestContext::Plug(Label* materialize_true, |
| 469 | Label* materialize_false) const { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 470 | ASSERT(materialize_true == true_label_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 471 | ASSERT(materialize_false == false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | |
| 475 | void FullCodeGenerator::EffectContext::Plug(bool flag) const { |
| 476 | } |
| 477 | |
| 478 | |
| 479 | void FullCodeGenerator::AccumulatorValueContext::Plug(bool flag) const { |
| 480 | Heap::RootListIndex value_root_index = |
| 481 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 482 | __ LoadRoot(result_register(), value_root_index); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | void FullCodeGenerator::StackValueContext::Plug(bool flag) const { |
| 487 | Heap::RootListIndex value_root_index = |
| 488 | flag ? Heap::kTrueValueRootIndex : Heap::kFalseValueRootIndex; |
| 489 | __ LoadRoot(ip, value_root_index); |
| 490 | __ push(ip); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | void FullCodeGenerator::TestContext::Plug(bool flag) const { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 495 | codegen()->PrepareForBailoutBeforeSplit(TOS_REG, |
| 496 | true, |
| 497 | true_label_, |
| 498 | false_label_); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 499 | if (flag) { |
| 500 | if (true_label_ != fall_through_) __ b(true_label_); |
| 501 | } else { |
| 502 | if (false_label_ != fall_through_) __ b(false_label_); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
| 506 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 507 | void FullCodeGenerator::DoTest(Label* if_true, |
| 508 | Label* if_false, |
| 509 | Label* fall_through) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 510 | // Call the runtime to find the boolean value of the source and then |
| 511 | // translate it into control flow to the pair of labels. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 512 | __ push(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 513 | __ CallRuntime(Runtime::kToBool, 1); |
| 514 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 515 | __ cmp(r0, ip); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 516 | Split(eq, if_true, if_false, fall_through); |
| 517 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 518 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 519 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 520 | void FullCodeGenerator::Split(Condition cc, |
| 521 | Label* if_true, |
| 522 | Label* if_false, |
| 523 | Label* fall_through) { |
| 524 | if (if_false == fall_through) { |
| 525 | __ b(cc, if_true); |
| 526 | } else if (if_true == fall_through) { |
| 527 | __ b(NegateCondition(cc), if_false); |
| 528 | } else { |
| 529 | __ b(cc, if_true); |
| 530 | __ b(if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
| 534 | |
| 535 | MemOperand FullCodeGenerator::EmitSlotSearch(Slot* slot, Register scratch) { |
| 536 | switch (slot->type()) { |
| 537 | case Slot::PARAMETER: |
| 538 | case Slot::LOCAL: |
| 539 | return MemOperand(fp, SlotOffset(slot)); |
| 540 | case Slot::CONTEXT: { |
| 541 | int context_chain_length = |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 542 | scope()->ContextChainLength(slot->var()->scope()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 543 | __ LoadContext(scratch, context_chain_length); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 544 | return ContextOperand(scratch, slot->index()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 545 | } |
| 546 | case Slot::LOOKUP: |
| 547 | UNREACHABLE(); |
| 548 | } |
| 549 | UNREACHABLE(); |
| 550 | return MemOperand(r0, 0); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | void FullCodeGenerator::Move(Register destination, Slot* source) { |
| 555 | // Use destination as scratch. |
| 556 | MemOperand slot_operand = EmitSlotSearch(source, destination); |
| 557 | __ ldr(destination, slot_operand); |
| 558 | } |
| 559 | |
| 560 | |
| 561 | void FullCodeGenerator::Move(Slot* dst, |
| 562 | Register src, |
| 563 | Register scratch1, |
| 564 | Register scratch2) { |
| 565 | ASSERT(dst->type() != Slot::LOOKUP); // Not yet implemented. |
| 566 | ASSERT(!scratch1.is(src) && !scratch2.is(src)); |
| 567 | MemOperand location = EmitSlotSearch(dst, scratch1); |
| 568 | __ str(src, location); |
| 569 | // Emit the write barrier code if the location is in the heap. |
| 570 | if (dst->type() == Slot::CONTEXT) { |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 571 | __ RecordWrite(scratch1, |
| 572 | Operand(Context::SlotOffset(dst->index())), |
| 573 | scratch2, |
| 574 | src); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | |
| 578 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 579 | void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state, |
| 580 | bool should_normalize, |
| 581 | Label* if_true, |
| 582 | Label* if_false) { |
| 583 | // Only prepare for bailouts before splits if we're in a test |
| 584 | // context. Otherwise, we let the Visit function deal with the |
| 585 | // preparation to avoid preparing with the same AST id twice. |
| 586 | if (!context()->IsTest() || !info_->IsOptimizable()) return; |
| 587 | |
| 588 | Label skip; |
| 589 | if (should_normalize) __ b(&skip); |
| 590 | |
| 591 | ForwardBailoutStack* current = forward_bailout_stack_; |
| 592 | while (current != NULL) { |
| 593 | PrepareForBailout(current->expr(), state); |
| 594 | current = current->parent(); |
| 595 | } |
| 596 | |
| 597 | if (should_normalize) { |
| 598 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 599 | __ cmp(r0, ip); |
| 600 | Split(eq, if_true, if_false, NULL); |
| 601 | __ bind(&skip); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 606 | void FullCodeGenerator::EmitDeclaration(Variable* variable, |
| 607 | Variable::Mode mode, |
| 608 | FunctionLiteral* function) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 609 | Comment cmnt(masm_, "[ Declaration"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 610 | ASSERT(variable != NULL); // Must have been resolved. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 611 | Slot* slot = variable->AsSlot(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 612 | Property* prop = variable->AsProperty(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 613 | |
| 614 | if (slot != NULL) { |
| 615 | switch (slot->type()) { |
| 616 | case Slot::PARAMETER: |
| 617 | case Slot::LOCAL: |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 618 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 619 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 620 | __ str(ip, MemOperand(fp, SlotOffset(slot))); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 621 | } else if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 622 | VisitForAccumulatorValue(function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 623 | __ str(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 624 | } |
| 625 | break; |
| 626 | |
| 627 | case Slot::CONTEXT: |
| 628 | // We bypass the general EmitSlotSearch because we know more about |
| 629 | // this specific context. |
| 630 | |
| 631 | // The variable in the decl always resides in the current context. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 632 | ASSERT_EQ(0, scope()->ContextChainLength(variable->scope())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 633 | if (FLAG_debug_code) { |
| 634 | // Check if we have the correct context pointer. |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 635 | __ ldr(r1, ContextOperand(cp, Context::FCONTEXT_INDEX)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 636 | __ cmp(r1, cp); |
| 637 | __ Check(eq, "Unexpected declaration in current context."); |
| 638 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 639 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 640 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 641 | __ str(ip, ContextOperand(cp, slot->index())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 642 | // No write barrier since the_hole_value is in old space. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 643 | } else if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 644 | VisitForAccumulatorValue(function); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 645 | __ str(result_register(), ContextOperand(cp, slot->index())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 646 | int offset = Context::SlotOffset(slot->index()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 647 | // We know that we have written a function, which is not a smi. |
| 648 | __ mov(r1, Operand(cp)); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 649 | __ RecordWrite(r1, Operand(offset), r2, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 650 | } |
| 651 | break; |
| 652 | |
| 653 | case Slot::LOOKUP: { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 654 | __ mov(r2, Operand(variable->name())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 655 | // Declaration nodes are always introduced in one of two modes. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 656 | ASSERT(mode == Variable::VAR || |
| 657 | mode == Variable::CONST); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 658 | PropertyAttributes attr = |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 659 | (mode == Variable::VAR) ? NONE : READ_ONLY; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 660 | __ mov(r1, Operand(Smi::FromInt(attr))); |
| 661 | // Push initial value, if any. |
| 662 | // Note: For variables we must not push an initial value (such as |
| 663 | // 'undefined') because we may have a (legal) redeclaration and we |
| 664 | // must not destroy the current value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 665 | if (mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 666 | __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 667 | __ Push(cp, r2, r1, r0); |
| 668 | } else if (function != NULL) { |
| 669 | __ Push(cp, r2, r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 670 | // Push initial value for function declaration. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 671 | VisitForStackValue(function); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 672 | } else { |
| 673 | __ mov(r0, Operand(Smi::FromInt(0))); // No initial value! |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 674 | __ Push(cp, r2, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 675 | } |
| 676 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 677 | break; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | } else if (prop != NULL) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 682 | if (function != NULL || mode == Variable::CONST) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 683 | // We are declaring a function or constant that rewrites to a |
| 684 | // property. Use (keyed) IC to set the initial value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 685 | VisitForStackValue(prop->obj()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 686 | if (function != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 687 | VisitForStackValue(prop->key()); |
| 688 | VisitForAccumulatorValue(function); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 689 | __ pop(r1); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 690 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 691 | VisitForAccumulatorValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 692 | __ mov(r1, result_register()); // Key. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 693 | __ LoadRoot(result_register(), Heap::kTheHoleValueRootIndex); |
| 694 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 695 | __ pop(r2); // Receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 696 | |
| 697 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 698 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 699 | // Value in r0 is ignored (declarations are statements). |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 705 | void FullCodeGenerator::VisitDeclaration(Declaration* decl) { |
| 706 | EmitDeclaration(decl->proxy()->var(), decl->mode(), decl->fun()); |
| 707 | } |
| 708 | |
| 709 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 710 | void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 711 | // Call the runtime to declare the globals. |
| 712 | // The context is the first argument. |
| 713 | __ mov(r1, Operand(pairs)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 714 | __ mov(r0, Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 715 | __ Push(cp, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 716 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 717 | // Return value is ignored. |
| 718 | } |
| 719 | |
| 720 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 721 | void FullCodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 722 | Comment cmnt(masm_, "[ SwitchStatement"); |
| 723 | Breakable nested_statement(this, stmt); |
| 724 | SetStatementPosition(stmt); |
| 725 | // Keep the switch value on the stack until a case matches. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 726 | VisitForStackValue(stmt->tag()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 727 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 728 | PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS); |
| 729 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 730 | ZoneList<CaseClause*>* clauses = stmt->cases(); |
| 731 | CaseClause* default_clause = NULL; // Can occur anywhere in the list. |
| 732 | |
| 733 | Label next_test; // Recycled for each test. |
| 734 | // Compile all the tests with branches to their bodies. |
| 735 | for (int i = 0; i < clauses->length(); i++) { |
| 736 | CaseClause* clause = clauses->at(i); |
| 737 | // The default is not a test, but remember it as final fall through. |
| 738 | if (clause->is_default()) { |
| 739 | default_clause = clause; |
| 740 | continue; |
| 741 | } |
| 742 | |
| 743 | Comment cmnt(masm_, "[ Case comparison"); |
| 744 | __ bind(&next_test); |
| 745 | next_test.Unuse(); |
| 746 | |
| 747 | // Compile the label expression. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 748 | VisitForAccumulatorValue(clause->label()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 749 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 750 | // Perform the comparison as if via '==='. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 751 | __ ldr(r1, MemOperand(sp, 0)); // Switch value. |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 752 | bool inline_smi_code = ShouldInlineSmiCase(Token::EQ_STRICT); |
| 753 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 754 | Label slow_case; |
| 755 | __ orr(r2, r1, r0); |
| 756 | __ tst(r2, Operand(kSmiTagMask)); |
| 757 | __ b(ne, &slow_case); |
| 758 | __ cmp(r1, r0); |
| 759 | __ b(ne, &next_test); |
| 760 | __ Drop(1); // Switch value is no longer needed. |
| 761 | __ b(clause->body_target()->entry_label()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 762 | __ bind(&slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 763 | } |
| 764 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 765 | CompareFlags flags = inline_smi_code |
| 766 | ? NO_SMI_COMPARE_IN_STUB |
| 767 | : NO_COMPARE_FLAGS; |
| 768 | CompareStub stub(eq, true, flags, r1, r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 769 | __ CallStub(&stub); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 770 | __ cmp(r0, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 771 | __ b(ne, &next_test); |
| 772 | __ Drop(1); // Switch value is no longer needed. |
| 773 | __ b(clause->body_target()->entry_label()); |
| 774 | } |
| 775 | |
| 776 | // Discard the test value and jump to the default if present, otherwise to |
| 777 | // the end of the statement. |
| 778 | __ bind(&next_test); |
| 779 | __ Drop(1); // Switch value is no longer needed. |
| 780 | if (default_clause == NULL) { |
| 781 | __ b(nested_statement.break_target()); |
| 782 | } else { |
| 783 | __ b(default_clause->body_target()->entry_label()); |
| 784 | } |
| 785 | |
| 786 | // Compile all the case bodies. |
| 787 | for (int i = 0; i < clauses->length(); i++) { |
| 788 | Comment cmnt(masm_, "[ Case body"); |
| 789 | CaseClause* clause = clauses->at(i); |
| 790 | __ bind(clause->body_target()->entry_label()); |
| 791 | VisitStatements(clause->statements()); |
| 792 | } |
| 793 | |
| 794 | __ bind(nested_statement.break_target()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 795 | PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 796 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 797 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 798 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 799 | void FullCodeGenerator::VisitForInStatement(ForInStatement* stmt) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 800 | Comment cmnt(masm_, "[ ForInStatement"); |
| 801 | SetStatementPosition(stmt); |
| 802 | |
| 803 | Label loop, exit; |
| 804 | ForIn loop_statement(this, stmt); |
| 805 | increment_loop_depth(); |
| 806 | |
| 807 | // Get the object to enumerate over. Both SpiderMonkey and JSC |
| 808 | // ignore null and undefined in contrast to the specification; see |
| 809 | // ECMA-262 section 12.6.4. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 810 | VisitForAccumulatorValue(stmt->enumerable()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 811 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 812 | __ cmp(r0, ip); |
| 813 | __ b(eq, &exit); |
| 814 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 815 | __ cmp(r0, ip); |
| 816 | __ b(eq, &exit); |
| 817 | |
| 818 | // Convert the object to a JS object. |
| 819 | Label convert, done_convert; |
| 820 | __ BranchOnSmi(r0, &convert); |
| 821 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
| 822 | __ b(hs, &done_convert); |
| 823 | __ bind(&convert); |
| 824 | __ push(r0); |
| 825 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS); |
| 826 | __ bind(&done_convert); |
| 827 | __ push(r0); |
| 828 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 829 | // BUG(867): Check cache validity in generated code. This is a fast |
| 830 | // case for the JSObject::IsSimpleEnum cache validity checks. If we |
| 831 | // cannot guarantee cache validity, call the runtime system to check |
| 832 | // cache validity or get the property names in a fixed array. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 833 | |
| 834 | // Get the set of properties to enumerate. |
| 835 | __ push(r0); // Duplicate the enumerable object on the stack. |
| 836 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
| 837 | |
| 838 | // If we got a map from the runtime call, we can do a fast |
| 839 | // modification check. Otherwise, we got a fixed array, and we have |
| 840 | // to do a slow check. |
| 841 | Label fixed_array; |
| 842 | __ mov(r2, r0); |
| 843 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 844 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 845 | __ cmp(r1, ip); |
| 846 | __ b(ne, &fixed_array); |
| 847 | |
| 848 | // We got a map in register r0. Get the enumeration cache from it. |
| 849 | __ ldr(r1, FieldMemOperand(r0, Map::kInstanceDescriptorsOffset)); |
| 850 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 851 | __ ldr(r2, FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 852 | |
| 853 | // Setup the four remaining stack slots. |
| 854 | __ push(r0); // Map. |
| 855 | __ ldr(r1, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 856 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 857 | // Push enumeration cache, enumeration cache length (as smi) and zero. |
| 858 | __ Push(r2, r1, r0); |
| 859 | __ jmp(&loop); |
| 860 | |
| 861 | // We got a fixed array in register r0. Iterate through that. |
| 862 | __ bind(&fixed_array); |
| 863 | __ mov(r1, Operand(Smi::FromInt(0))); // Map (0) - force slow check. |
| 864 | __ Push(r1, r0); |
| 865 | __ ldr(r1, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 866 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 867 | __ Push(r1, r0); // Fixed array length (as smi) and initial index. |
| 868 | |
| 869 | // Generate code for doing the condition check. |
| 870 | __ bind(&loop); |
| 871 | // Load the current count to r0, load the length to r1. |
| 872 | __ Ldrd(r0, r1, MemOperand(sp, 0 * kPointerSize)); |
| 873 | __ cmp(r0, r1); // Compare to the array length. |
| 874 | __ b(hs, loop_statement.break_target()); |
| 875 | |
| 876 | // Get the current entry of the array into register r3. |
| 877 | __ ldr(r2, MemOperand(sp, 2 * kPointerSize)); |
| 878 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 879 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 880 | |
| 881 | // Get the expected map from the stack or a zero map in the |
| 882 | // permanent slow case into register r2. |
| 883 | __ ldr(r2, MemOperand(sp, 3 * kPointerSize)); |
| 884 | |
| 885 | // Check if the expected map still matches that of the enumerable. |
| 886 | // If not, we have to filter the key. |
| 887 | Label update_each; |
| 888 | __ ldr(r1, MemOperand(sp, 4 * kPointerSize)); |
| 889 | __ ldr(r4, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 890 | __ cmp(r4, Operand(r2)); |
| 891 | __ b(eq, &update_each); |
| 892 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 893 | // Convert the entry to a string or (smi) 0 if it isn't a property |
| 894 | // any more. If the property has been removed while iterating, we |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 895 | // just skip it. |
| 896 | __ push(r1); // Enumerable. |
| 897 | __ push(r3); // Current entry. |
| 898 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 899 | __ mov(r3, Operand(r0), SetCC); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 900 | __ b(eq, loop_statement.continue_target()); |
| 901 | |
| 902 | // Update the 'each' property or variable from the possibly filtered |
| 903 | // entry in register r3. |
| 904 | __ bind(&update_each); |
| 905 | __ mov(result_register(), r3); |
| 906 | // Perform the assignment as if via '='. |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 907 | { EffectContext context(this); |
| 908 | EmitAssignment(stmt->each(), stmt->AssignmentId()); |
| 909 | } |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 910 | |
| 911 | // Generate code for the body of the loop. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 912 | Visit(stmt->body()); |
| 913 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 914 | // Generate code for the going to the next element by incrementing |
| 915 | // the index (smi) stored on top of the stack. |
| 916 | __ bind(loop_statement.continue_target()); |
| 917 | __ pop(r0); |
| 918 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 919 | __ push(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 920 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 921 | EmitStackCheck(stmt); |
| 922 | __ b(&loop); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 923 | |
| 924 | // Remove the pointers stored on the stack. |
| 925 | __ bind(loop_statement.break_target()); |
| 926 | __ Drop(5); |
| 927 | |
| 928 | // Exit and decrement the loop depth. |
| 929 | __ bind(&exit); |
| 930 | decrement_loop_depth(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 934 | void FullCodeGenerator::EmitNewClosure(Handle<SharedFunctionInfo> info, |
| 935 | bool pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 936 | // Use the fast case closure allocation code that allocates in new |
| 937 | // space for nested functions that don't need literals cloning. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 938 | if (scope()->is_function_scope() && |
| 939 | info->num_literals() == 0 && |
| 940 | !pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 941 | FastNewClosureStub stub; |
| 942 | __ mov(r0, Operand(info)); |
| 943 | __ push(r0); |
| 944 | __ CallStub(&stub); |
| 945 | } else { |
| 946 | __ mov(r0, Operand(info)); |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 947 | __ LoadRoot(r1, pretenure ? Heap::kTrueValueRootIndex |
| 948 | : Heap::kFalseValueRootIndex); |
| 949 | __ Push(cp, r0, r1); |
| 950 | __ CallRuntime(Runtime::kNewClosure, 3); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 951 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 952 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | |
| 956 | void FullCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 957 | Comment cmnt(masm_, "[ VariableProxy"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 958 | EmitVariableLoad(expr->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 962 | MemOperand FullCodeGenerator::ContextSlotOperandCheckExtensions( |
| 963 | Slot* slot, |
| 964 | Label* slow) { |
| 965 | ASSERT(slot->type() == Slot::CONTEXT); |
| 966 | Register current = cp; |
| 967 | Register next = r3; |
| 968 | Register temp = r4; |
| 969 | |
| 970 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 971 | if (s->num_heap_slots() > 0) { |
| 972 | if (s->calls_eval()) { |
| 973 | // Check that extension is NULL. |
| 974 | __ ldr(temp, ContextOperand(current, Context::EXTENSION_INDEX)); |
| 975 | __ tst(temp, temp); |
| 976 | __ b(ne, slow); |
| 977 | } |
| 978 | __ ldr(next, ContextOperand(current, Context::CLOSURE_INDEX)); |
| 979 | __ ldr(next, FieldMemOperand(next, JSFunction::kContextOffset)); |
| 980 | // Walk the rest of the chain without clobbering cp. |
| 981 | current = next; |
| 982 | } |
| 983 | } |
| 984 | // Check that last extension is NULL. |
| 985 | __ ldr(temp, ContextOperand(current, Context::EXTENSION_INDEX)); |
| 986 | __ tst(temp, temp); |
| 987 | __ b(ne, slow); |
| 988 | __ ldr(temp, ContextOperand(current, Context::FCONTEXT_INDEX)); |
| 989 | return ContextOperand(temp, slot->index()); |
| 990 | } |
| 991 | |
| 992 | |
| 993 | void FullCodeGenerator::EmitDynamicLoadFromSlotFastCase( |
| 994 | Slot* slot, |
| 995 | TypeofState typeof_state, |
| 996 | Label* slow, |
| 997 | Label* done) { |
| 998 | // Generate fast-case code for variables that might be shadowed by |
| 999 | // eval-introduced variables. Eval is used a lot without |
| 1000 | // introducing variables. In those cases, we do not want to |
| 1001 | // perform a runtime call for all variables in the scope |
| 1002 | // containing the eval. |
| 1003 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 1004 | EmitLoadGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 1005 | __ jmp(done); |
| 1006 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1007 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1008 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 1009 | if (potential_slot != NULL) { |
| 1010 | // Generate fast case for locals that rewrite to slots. |
| 1011 | __ ldr(r0, ContextSlotOperandCheckExtensions(potential_slot, slow)); |
| 1012 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 1013 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1014 | __ cmp(r0, ip); |
| 1015 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1016 | } |
| 1017 | __ jmp(done); |
| 1018 | } else if (rewrite != NULL) { |
| 1019 | // Generate fast case for calls of an argument function. |
| 1020 | Property* property = rewrite->AsProperty(); |
| 1021 | if (property != NULL) { |
| 1022 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1023 | Literal* key_literal = property->key()->AsLiteral(); |
| 1024 | if (obj_proxy != NULL && |
| 1025 | key_literal != NULL && |
| 1026 | obj_proxy->IsArguments() && |
| 1027 | key_literal->handle()->IsSmi()) { |
| 1028 | // Load arguments object if there are no eval-introduced |
| 1029 | // variables. Then load the argument from the arguments |
| 1030 | // object using keyed load. |
| 1031 | __ ldr(r1, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1032 | ContextSlotOperandCheckExtensions(obj_proxy->var()->AsSlot(), |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1033 | slow)); |
| 1034 | __ mov(r0, Operand(key_literal->handle())); |
| 1035 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1036 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1037 | __ jmp(done); |
| 1038 | } |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | |
| 1045 | void FullCodeGenerator::EmitLoadGlobalSlotCheckExtensions( |
| 1046 | Slot* slot, |
| 1047 | TypeofState typeof_state, |
| 1048 | Label* slow) { |
| 1049 | Register current = cp; |
| 1050 | Register next = r1; |
| 1051 | Register temp = r2; |
| 1052 | |
| 1053 | Scope* s = scope(); |
| 1054 | while (s != NULL) { |
| 1055 | if (s->num_heap_slots() > 0) { |
| 1056 | if (s->calls_eval()) { |
| 1057 | // Check that extension is NULL. |
| 1058 | __ ldr(temp, ContextOperand(current, Context::EXTENSION_INDEX)); |
| 1059 | __ tst(temp, temp); |
| 1060 | __ b(ne, slow); |
| 1061 | } |
| 1062 | // Load next context in chain. |
| 1063 | __ ldr(next, ContextOperand(current, Context::CLOSURE_INDEX)); |
| 1064 | __ ldr(next, FieldMemOperand(next, JSFunction::kContextOffset)); |
| 1065 | // Walk the rest of the chain without clobbering cp. |
| 1066 | current = next; |
| 1067 | } |
| 1068 | // If no outer scope calls eval, we do not need to check more |
| 1069 | // context extensions. |
| 1070 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 1071 | s = s->outer_scope(); |
| 1072 | } |
| 1073 | |
| 1074 | if (s->is_eval_scope()) { |
| 1075 | Label loop, fast; |
| 1076 | if (!current.is(next)) { |
| 1077 | __ Move(next, current); |
| 1078 | } |
| 1079 | __ bind(&loop); |
| 1080 | // Terminate at global context. |
| 1081 | __ ldr(temp, FieldMemOperand(next, HeapObject::kMapOffset)); |
| 1082 | __ LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 1083 | __ cmp(temp, ip); |
| 1084 | __ b(eq, &fast); |
| 1085 | // Check that extension is NULL. |
| 1086 | __ ldr(temp, ContextOperand(next, Context::EXTENSION_INDEX)); |
| 1087 | __ tst(temp, temp); |
| 1088 | __ b(ne, slow); |
| 1089 | // Load next context in chain. |
| 1090 | __ ldr(next, ContextOperand(next, Context::CLOSURE_INDEX)); |
| 1091 | __ ldr(next, FieldMemOperand(next, JSFunction::kContextOffset)); |
| 1092 | __ b(&loop); |
| 1093 | __ bind(&fast); |
| 1094 | } |
| 1095 | |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1096 | __ ldr(r0, GlobalObjectOperand()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1097 | __ mov(r2, Operand(slot->var()->name())); |
| 1098 | RelocInfo::Mode mode = (typeof_state == INSIDE_TYPEOF) |
| 1099 | ? RelocInfo::CODE_TARGET |
| 1100 | : RelocInfo::CODE_TARGET_CONTEXT; |
| 1101 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1102 | EmitCallIC(ic, mode); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1106 | void FullCodeGenerator::EmitVariableLoad(Variable* var) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1107 | // Four cases: non-this global variables, lookup slots, all other |
| 1108 | // types of slots, and parameters that rewrite to explicit property |
| 1109 | // accesses on the arguments object. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1110 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1111 | Property* property = var->AsProperty(); |
| 1112 | |
| 1113 | if (var->is_global() && !var->is_this()) { |
| 1114 | Comment cmnt(masm_, "Global variable"); |
| 1115 | // Use inline caching. Variable name is passed in r2 and the global |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1116 | // object (receiver) in r0. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1117 | __ ldr(r0, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1118 | __ mov(r2, Operand(var->name())); |
| 1119 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1120 | EmitCallIC(ic, RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1121 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1122 | |
| 1123 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1124 | Label done, slow; |
| 1125 | |
| 1126 | // Generate code for loading from variables potentially shadowed |
| 1127 | // by eval-introduced variables. |
| 1128 | EmitDynamicLoadFromSlotFastCase(slot, NOT_INSIDE_TYPEOF, &slow, &done); |
| 1129 | |
| 1130 | __ bind(&slow); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1131 | Comment cmnt(masm_, "Lookup slot"); |
| 1132 | __ mov(r1, Operand(var->name())); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1133 | __ Push(cp, r1); // Context and name. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1134 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1135 | __ bind(&done); |
| 1136 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1137 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1138 | |
| 1139 | } else if (slot != NULL) { |
| 1140 | Comment cmnt(masm_, (slot->type() == Slot::CONTEXT) |
| 1141 | ? "Context slot" |
| 1142 | : "Stack slot"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1143 | if (var->mode() == Variable::CONST) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1144 | // Constants may be the hole value if they have not been initialized. |
| 1145 | // Unhole them. |
| 1146 | MemOperand slot_operand = EmitSlotSearch(slot, r0); |
| 1147 | __ ldr(r0, slot_operand); |
| 1148 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1149 | __ cmp(r0, ip); |
| 1150 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1151 | context()->Plug(r0); |
| 1152 | } else { |
| 1153 | context()->Plug(slot); |
| 1154 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1155 | } else { |
| 1156 | Comment cmnt(masm_, "Rewritten parameter"); |
| 1157 | ASSERT_NOT_NULL(property); |
| 1158 | // Rewritten parameter accesses are of the form "slot[literal]". |
| 1159 | |
| 1160 | // Assert that the object is in a slot. |
| 1161 | Variable* object_var = property->obj()->AsVariableProxy()->AsVariable(); |
| 1162 | ASSERT_NOT_NULL(object_var); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1163 | Slot* object_slot = object_var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1164 | ASSERT_NOT_NULL(object_slot); |
| 1165 | |
| 1166 | // Load the object. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1167 | Move(r1, object_slot); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1168 | |
| 1169 | // Assert that the key is a smi. |
| 1170 | Literal* key_literal = property->key()->AsLiteral(); |
| 1171 | ASSERT_NOT_NULL(key_literal); |
| 1172 | ASSERT(key_literal->handle()->IsSmi()); |
| 1173 | |
| 1174 | // Load the key. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1175 | __ mov(r0, Operand(key_literal->handle())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1176 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1177 | // Call keyed load IC. It has arguments key and receiver in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1178 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1179 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1180 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | void FullCodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1186 | Comment cmnt(masm_, "[ RegExpLiteral"); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1187 | Label materialized; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1188 | // Registers will be used as follows: |
| 1189 | // r4 = JS function, literals array |
| 1190 | // r3 = literal index |
| 1191 | // r2 = RegExp pattern |
| 1192 | // r1 = RegExp flags |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1193 | // r0 = temp + materialized value (RegExp literal) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1194 | __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1195 | __ ldr(r4, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1196 | int literal_offset = |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1197 | FixedArray::kHeaderSize + expr->literal_index() * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1198 | __ ldr(r0, FieldMemOperand(r4, literal_offset)); |
| 1199 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 1200 | __ cmp(r0, ip); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1201 | __ b(ne, &materialized); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1202 | |
| 1203 | // Create regexp literal using runtime function. |
| 1204 | // Result will be in r0. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1205 | __ mov(r3, Operand(Smi::FromInt(expr->literal_index()))); |
| 1206 | __ mov(r2, Operand(expr->pattern())); |
| 1207 | __ mov(r1, Operand(expr->flags())); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1208 | __ Push(r4, r3, r2, r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1209 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1210 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1211 | __ bind(&materialized); |
| 1212 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 1213 | __ push(r0); |
| 1214 | __ mov(r0, Operand(Smi::FromInt(size))); |
| 1215 | __ push(r0); |
| 1216 | __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1217 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1218 | // After this, registers are used as follows: |
| 1219 | // r0: Newly allocated regexp. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1220 | // r1: Materialized regexp. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 1221 | // r2: temp. |
| 1222 | __ pop(r1); |
| 1223 | __ CopyFields(r0, r1, r2.bit(), size / kPointerSize); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1224 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { |
| 1229 | Comment cmnt(masm_, "[ ObjectLiteral"); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1230 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1231 | __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 1232 | __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); |
| 1233 | __ mov(r1, Operand(expr->constant_properties())); |
| 1234 | __ mov(r0, Operand(Smi::FromInt(expr->fast_elements() ? 1 : 0))); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1235 | __ Push(r3, r2, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1236 | if (expr->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1237 | __ CallRuntime(Runtime::kCreateObjectLiteral, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1238 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 1239 | __ CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | // If result_saved is true the result is on top of the stack. If |
| 1243 | // result_saved is false the result is in r0. |
| 1244 | bool result_saved = false; |
| 1245 | |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1246 | // Mark all computed expressions that are bound to a key that |
| 1247 | // is shadowed by a later occurrence of the same key. For the |
| 1248 | // marked expressions, no store code is emitted. |
| 1249 | expr->CalculateEmitStore(); |
| 1250 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1251 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1252 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1253 | if (property->IsCompileTimeValue()) continue; |
| 1254 | |
| 1255 | Literal* key = property->key(); |
| 1256 | Expression* value = property->value(); |
| 1257 | if (!result_saved) { |
| 1258 | __ push(r0); // Save result on stack |
| 1259 | result_saved = true; |
| 1260 | } |
| 1261 | switch (property->kind()) { |
| 1262 | case ObjectLiteral::Property::CONSTANT: |
| 1263 | UNREACHABLE(); |
| 1264 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1265 | ASSERT(!CompileTimeValue::IsCompileTimeValue(property->value())); |
| 1266 | // Fall through. |
| 1267 | case ObjectLiteral::Property::COMPUTED: |
| 1268 | if (key->handle()->IsSymbol()) { |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1269 | if (property->emit_store()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1270 | VisitForAccumulatorValue(value); |
| 1271 | __ mov(r2, Operand(key->handle())); |
| 1272 | __ ldr(r1, MemOperand(sp)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1273 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 1274 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1275 | PrepareForBailoutForId(key->id(), NO_REGISTERS); |
| 1276 | } else { |
| 1277 | VisitForEffect(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1278 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1279 | break; |
| 1280 | } |
| 1281 | // Fall through. |
| 1282 | case ObjectLiteral::Property::PROTOTYPE: |
| 1283 | // Duplicate receiver on stack. |
| 1284 | __ ldr(r0, MemOperand(sp)); |
| 1285 | __ push(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1286 | VisitForStackValue(key); |
| 1287 | VisitForStackValue(value); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 1288 | if (property->emit_store()) { |
| 1289 | __ CallRuntime(Runtime::kSetProperty, 3); |
| 1290 | } else { |
| 1291 | __ Drop(3); |
| 1292 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1293 | break; |
| 1294 | case ObjectLiteral::Property::GETTER: |
| 1295 | case ObjectLiteral::Property::SETTER: |
| 1296 | // Duplicate receiver on stack. |
| 1297 | __ ldr(r0, MemOperand(sp)); |
| 1298 | __ push(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1299 | VisitForStackValue(key); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1300 | __ mov(r1, Operand(property->kind() == ObjectLiteral::Property::SETTER ? |
| 1301 | Smi::FromInt(1) : |
| 1302 | Smi::FromInt(0))); |
| 1303 | __ push(r1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1304 | VisitForStackValue(value); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1305 | __ CallRuntime(Runtime::kDefineAccessor, 4); |
| 1306 | break; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1311 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1312 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1313 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1319 | Comment cmnt(masm_, "[ ArrayLiteral"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1320 | |
| 1321 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1322 | int length = subexprs->length(); |
| 1323 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1324 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1325 | __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 1326 | __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); |
| 1327 | __ mov(r1, Operand(expr->constant_elements())); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1328 | __ Push(r3, r2, r1); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1329 | if (expr->constant_elements()->map() == Heap::fixed_cow_array_map()) { |
| 1330 | FastCloneShallowArrayStub stub( |
| 1331 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 1332 | __ CallStub(&stub); |
| 1333 | __ IncrementCounter(&Counters::cow_arrays_created_stub, 1, r1, r2); |
| 1334 | } else if (expr->depth() > 1) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1335 | __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1336 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1337 | __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1338 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1339 | FastCloneShallowArrayStub stub( |
| 1340 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1341 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
| 1344 | bool result_saved = false; // Is the result saved to the stack? |
| 1345 | |
| 1346 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1347 | // them into the newly cloned array. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1348 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1349 | Expression* subexpr = subexprs->at(i); |
| 1350 | // If the subexpression is a literal or a simple materialized literal it |
| 1351 | // is already set in the cloned array. |
| 1352 | if (subexpr->AsLiteral() != NULL || |
| 1353 | CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1354 | continue; |
| 1355 | } |
| 1356 | |
| 1357 | if (!result_saved) { |
| 1358 | __ push(r0); |
| 1359 | result_saved = true; |
| 1360 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1361 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1362 | |
| 1363 | // Store the subexpression value in the array's elements. |
| 1364 | __ ldr(r1, MemOperand(sp)); // Copy of array literal. |
| 1365 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 1366 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1367 | __ str(result_register(), FieldMemOperand(r1, offset)); |
| 1368 | |
| 1369 | // Update the write barrier for the array store with r0 as the scratch |
| 1370 | // register. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1371 | __ RecordWrite(r1, Operand(offset), r2, result_register()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1372 | |
| 1373 | PrepareForBailoutForId(expr->GetIdForElement(i), NO_REGISTERS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1377 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1378 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1379 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1384 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1385 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1386 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1387 | // on the left-hand side. |
| 1388 | if (!expr->target()->IsValidLeftHandSide()) { |
| 1389 | VisitForEffect(expr->target()); |
| 1390 | return; |
| 1391 | } |
| 1392 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1393 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1394 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1395 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1396 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1397 | Property* property = expr->target()->AsProperty(); |
| 1398 | if (property != NULL) { |
| 1399 | assign_type = (property->key()->IsPropertyName()) |
| 1400 | ? NAMED_PROPERTY |
| 1401 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | // Evaluate LHS expression. |
| 1405 | switch (assign_type) { |
| 1406 | case VARIABLE: |
| 1407 | // Nothing to do here. |
| 1408 | break; |
| 1409 | case NAMED_PROPERTY: |
| 1410 | if (expr->is_compound()) { |
| 1411 | // We need the receiver both on the stack and in the accumulator. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1412 | VisitForAccumulatorValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1413 | __ push(result_register()); |
| 1414 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1415 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1416 | } |
| 1417 | break; |
| 1418 | case KEYED_PROPERTY: |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1419 | if (expr->is_compound()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1420 | if (property->is_arguments_access()) { |
| 1421 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1422 | __ ldr(r0, EmitSlotSearch(obj_proxy->var()->AsSlot(), r0)); |
| 1423 | __ push(r0); |
| 1424 | __ mov(r0, Operand(property->key()->AsLiteral()->handle())); |
| 1425 | } else { |
| 1426 | VisitForStackValue(property->obj()); |
| 1427 | VisitForAccumulatorValue(property->key()); |
| 1428 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1429 | __ ldr(r1, MemOperand(sp, 0)); |
| 1430 | __ push(r0); |
| 1431 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | if (property->is_arguments_access()) { |
| 1433 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 1434 | __ ldr(r1, EmitSlotSearch(obj_proxy->var()->AsSlot(), r0)); |
| 1435 | __ mov(r0, Operand(property->key()->AsLiteral()->handle())); |
| 1436 | __ Push(r1, r0); |
| 1437 | } else { |
| 1438 | VisitForStackValue(property->obj()); |
| 1439 | VisitForStackValue(property->key()); |
| 1440 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1441 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1442 | break; |
| 1443 | } |
| 1444 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1445 | if (expr->is_compound()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1446 | { AccumulatorValueContext context(this); |
| 1447 | switch (assign_type) { |
| 1448 | case VARIABLE: |
| 1449 | EmitVariableLoad(expr->target()->AsVariableProxy()->var()); |
| 1450 | break; |
| 1451 | case NAMED_PROPERTY: |
| 1452 | EmitNamedPropertyLoad(property); |
| 1453 | break; |
| 1454 | case KEYED_PROPERTY: |
| 1455 | EmitKeyedPropertyLoad(property); |
| 1456 | break; |
| 1457 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1458 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1459 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1460 | // For property compound assignments we need another deoptimization |
| 1461 | // point after the property load. |
| 1462 | if (property != NULL) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1463 | PrepareForBailoutForId(expr->CompoundLoadId(), TOS_REG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1466 | Token::Value op = expr->binary_op(); |
| 1467 | ConstantOperand constant = ShouldInlineSmiCase(op) |
| 1468 | ? GetConstantOperand(op, expr->target(), expr->value()) |
| 1469 | : kNoConstants; |
| 1470 | ASSERT(constant == kRightConstant || constant == kNoConstants); |
| 1471 | if (constant == kNoConstants) { |
| 1472 | __ push(r0); // Left operand goes on the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1473 | VisitForAccumulatorValue(expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1474 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1475 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1476 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1477 | ? OVERWRITE_RIGHT |
| 1478 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1479 | SetSourcePosition(expr->position() + 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1480 | AccumulatorValueContext context(this); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1481 | if (ShouldInlineSmiCase(op)) { |
| 1482 | EmitInlineSmiBinaryOp(expr, |
| 1483 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1484 | mode, |
| 1485 | expr->target(), |
| 1486 | expr->value(), |
| 1487 | constant); |
| 1488 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1489 | EmitBinaryOp(op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1490 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Deoptimization point in case the binary operation may have side effects. |
| 1493 | PrepareForBailout(expr->binary_operation(), TOS_REG); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1494 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1495 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | // Record source position before possible IC call. |
| 1499 | SetSourcePosition(expr->position()); |
| 1500 | |
| 1501 | // Store the value. |
| 1502 | switch (assign_type) { |
| 1503 | case VARIABLE: |
| 1504 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1505 | expr->op()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1506 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1507 | context()->Plug(r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | case NAMED_PROPERTY: |
| 1510 | EmitNamedPropertyAssignment(expr); |
| 1511 | break; |
| 1512 | case KEYED_PROPERTY: |
| 1513 | EmitKeyedPropertyAssignment(expr); |
| 1514 | break; |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1519 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 1520 | SetSourcePosition(prop->position()); |
| 1521 | Literal* key = prop->key()->AsLiteral(); |
| 1522 | __ mov(r2, Operand(key->handle())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1523 | // Call load IC. It has arguments receiver and property name r0 and r2. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1524 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1525 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | |
| 1529 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 1530 | SetSourcePosition(prop->position()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1531 | // Call keyed load IC. It has arguments key and receiver in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1532 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1533 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1537 | void FullCodeGenerator::EmitInlineSmiBinaryOp(Expression* expr, |
| 1538 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1539 | OverwriteMode mode, |
| 1540 | Expression* left, |
| 1541 | Expression* right, |
| 1542 | ConstantOperand constant) { |
| 1543 | ASSERT(constant == kNoConstants); // Only handled case. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1544 | EmitBinaryOp(op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1548 | void FullCodeGenerator::EmitBinaryOp(Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1549 | OverwriteMode mode) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1550 | __ pop(r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1551 | GenericBinaryOpStub stub(op, mode, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1552 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1553 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1557 | void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1558 | // Invalid left-hand sides are rewritten to have a 'throw |
| 1559 | // ReferenceError' on the left-hand side. |
| 1560 | if (!expr->IsValidLeftHandSide()) { |
| 1561 | VisitForEffect(expr); |
| 1562 | return; |
| 1563 | } |
| 1564 | |
| 1565 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1566 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1567 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1568 | LhsKind assign_type = VARIABLE; |
| 1569 | Property* prop = expr->AsProperty(); |
| 1570 | if (prop != NULL) { |
| 1571 | assign_type = (prop->key()->IsPropertyName()) |
| 1572 | ? NAMED_PROPERTY |
| 1573 | : KEYED_PROPERTY; |
| 1574 | } |
| 1575 | |
| 1576 | switch (assign_type) { |
| 1577 | case VARIABLE: { |
| 1578 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1579 | EffectContext context(this); |
| 1580 | EmitVariableAssignment(var, Token::ASSIGN); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | case NAMED_PROPERTY: { |
| 1584 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1585 | VisitForAccumulatorValue(prop->obj()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1586 | __ mov(r1, r0); |
| 1587 | __ pop(r0); // Restore value. |
| 1588 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
| 1589 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1590 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1591 | break; |
| 1592 | } |
| 1593 | case KEYED_PROPERTY: { |
| 1594 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1595 | VisitForStackValue(prop->obj()); |
| 1596 | VisitForAccumulatorValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1597 | __ mov(r1, r0); |
| 1598 | __ pop(r2); |
| 1599 | __ pop(r0); // Restore value. |
| 1600 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1601 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1602 | break; |
| 1603 | } |
| 1604 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1605 | PrepareForBailoutForId(bailout_ast_id, TOS_REG); |
| 1606 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1610 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1611 | Token::Value op) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1612 | // Left-hand sides that rewrite to explicit property accesses do not reach |
| 1613 | // here. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1614 | ASSERT(var != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1615 | ASSERT(var->is_global() || var->AsSlot() != NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1616 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1617 | if (var->is_global()) { |
| 1618 | ASSERT(!var->is_this()); |
| 1619 | // Assignment to a global variable. Use inline caching for the |
| 1620 | // assignment. Right-hand-side value is passed in r0, variable name in |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1621 | // r2, and the global object in r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1622 | __ mov(r2, Operand(var->name())); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1623 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1624 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1625 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1626 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1627 | } else if (var->mode() != Variable::CONST || op == Token::INIT_CONST) { |
| 1628 | // Perform the assignment for non-const variables and for initialization |
| 1629 | // of const variables. Const assignments are simply skipped. |
| 1630 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1631 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1632 | switch (slot->type()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1633 | case Slot::PARAMETER: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1634 | case Slot::LOCAL: |
| 1635 | if (op == Token::INIT_CONST) { |
| 1636 | // Detect const reinitialization by checking for the hole value. |
| 1637 | __ ldr(r1, MemOperand(fp, SlotOffset(slot))); |
| 1638 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1639 | __ cmp(r1, ip); |
| 1640 | __ b(ne, &done); |
| 1641 | } |
| 1642 | // Perform the assignment. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1643 | __ str(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 1644 | break; |
| 1645 | |
| 1646 | case Slot::CONTEXT: { |
| 1647 | MemOperand target = EmitSlotSearch(slot, r1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1648 | if (op == Token::INIT_CONST) { |
| 1649 | // Detect const reinitialization by checking for the hole value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1650 | __ ldr(r2, target); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1651 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1652 | __ cmp(r2, ip); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1653 | __ b(ne, &done); |
| 1654 | } |
| 1655 | // Perform the assignment and issue the write barrier. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1656 | __ str(result_register(), target); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1657 | // RecordWrite may destroy all its register arguments. |
| 1658 | __ mov(r3, result_register()); |
| 1659 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1660 | __ RecordWrite(r1, Operand(offset), r2, r3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | case Slot::LOOKUP: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1665 | // Call the runtime for the assignment. The runtime will ignore |
| 1666 | // const reinitialization. |
| 1667 | __ push(r0); // Value. |
| 1668 | __ mov(r0, Operand(slot->var()->name())); |
| 1669 | __ Push(cp, r0); // Context and name. |
| 1670 | if (op == Token::INIT_CONST) { |
| 1671 | // The runtime will ignore const redeclaration. |
| 1672 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 1673 | } else { |
| 1674 | __ CallRuntime(Runtime::kStoreContextSlot, 3); |
| 1675 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1676 | break; |
| 1677 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1678 | __ bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 1684 | // Assignment to a property, using a named store IC. |
| 1685 | Property* prop = expr->target()->AsProperty(); |
| 1686 | ASSERT(prop != NULL); |
| 1687 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 1688 | |
| 1689 | // If the assignment starts a block of assignments to the same object, |
| 1690 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1691 | // adding fast properties. |
| 1692 | if (expr->starts_initialization_block()) { |
| 1693 | __ push(result_register()); |
| 1694 | __ ldr(ip, MemOperand(sp, kPointerSize)); // Receiver is now under value. |
| 1695 | __ push(ip); |
| 1696 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1697 | __ pop(result_register()); |
| 1698 | } |
| 1699 | |
| 1700 | // Record source code position before IC call. |
| 1701 | SetSourcePosition(expr->position()); |
| 1702 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1703 | // Load receiver to r1. Leave a copy in the stack if needed for turning the |
| 1704 | // receiver into fast case. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1705 | if (expr->ends_initialization_block()) { |
| 1706 | __ ldr(r1, MemOperand(sp)); |
| 1707 | } else { |
| 1708 | __ pop(r1); |
| 1709 | } |
| 1710 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1711 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1712 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1713 | |
| 1714 | // If the assignment ends an initialization block, revert to fast case. |
| 1715 | if (expr->ends_initialization_block()) { |
| 1716 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1717 | // Receiver is under the result value. |
| 1718 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1719 | __ push(ip); |
| 1720 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1721 | __ pop(r0); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1722 | __ Drop(1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1723 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1724 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1725 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | |
| 1729 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 1730 | // Assignment to a property, using a keyed store IC. |
| 1731 | |
| 1732 | // If the assignment starts a block of assignments to the same object, |
| 1733 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1734 | // adding fast properties. |
| 1735 | if (expr->starts_initialization_block()) { |
| 1736 | __ push(result_register()); |
| 1737 | // Receiver is now under the key and value. |
| 1738 | __ ldr(ip, MemOperand(sp, 2 * kPointerSize)); |
| 1739 | __ push(ip); |
| 1740 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1741 | __ pop(result_register()); |
| 1742 | } |
| 1743 | |
| 1744 | // Record source code position before IC call. |
| 1745 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1746 | __ pop(r1); // Key. |
| 1747 | // Load receiver to r2. Leave a copy in the stack if needed for turning the |
| 1748 | // receiver into fast case. |
| 1749 | if (expr->ends_initialization_block()) { |
| 1750 | __ ldr(r2, MemOperand(sp)); |
| 1751 | } else { |
| 1752 | __ pop(r2); |
| 1753 | } |
| 1754 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1755 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1756 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1757 | |
| 1758 | // If the assignment ends an initialization block, revert to fast case. |
| 1759 | if (expr->ends_initialization_block()) { |
| 1760 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1761 | // Receiver is under the result value. |
| 1762 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1763 | __ push(ip); |
| 1764 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1765 | __ pop(r0); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1766 | __ Drop(1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1767 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1768 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1769 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | |
| 1773 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 1774 | Comment cmnt(masm_, "[ Property"); |
| 1775 | Expression* key = expr->key(); |
| 1776 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1777 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1778 | VisitForAccumulatorValue(expr->obj()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1779 | EmitNamedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1780 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1781 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1782 | VisitForStackValue(expr->obj()); |
| 1783 | VisitForAccumulatorValue(expr->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1784 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1785 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1786 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1791 | Handle<Object> name, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1792 | RelocInfo::Mode mode) { |
| 1793 | // Code common for calls using the IC. |
| 1794 | ZoneList<Expression*>* args = expr->arguments(); |
| 1795 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1796 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1797 | for (int i = 0; i < arg_count; i++) { |
| 1798 | VisitForStackValue(args->at(i)); |
| 1799 | } |
| 1800 | __ mov(r2, Operand(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1801 | } |
| 1802 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1803 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1804 | // Call the IC initialization code. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1805 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1806 | Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, in_loop); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1807 | EmitCallIC(ic, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1808 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1809 | // Restore context register. |
| 1810 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1811 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1815 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
| 1816 | Expression* key, |
| 1817 | RelocInfo::Mode mode) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1818 | // Load the key. |
| 1819 | VisitForAccumulatorValue(key); |
| 1820 | |
| 1821 | // Swap the name of the function and the receiver on the stack to follow |
| 1822 | // the calling convention for call ICs. |
| 1823 | __ pop(r1); |
| 1824 | __ push(r0); |
| 1825 | __ push(r1); |
| 1826 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1827 | // Code common for calls using the IC. |
| 1828 | ZoneList<Expression*>* args = expr->arguments(); |
| 1829 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1830 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1831 | for (int i = 0; i < arg_count; i++) { |
| 1832 | VisitForStackValue(args->at(i)); |
| 1833 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1834 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1835 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1836 | SetSourcePosition(expr->position()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1837 | // Call the IC initialization code. |
| 1838 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1839 | Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arg_count, in_loop); |
| 1840 | __ ldr(r2, MemOperand(sp, (arg_count + 1) * kPointerSize)); // Key. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1841 | EmitCallIC(ic, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1842 | RecordJSReturnSite(expr); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1843 | // Restore context register. |
| 1844 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1845 | context()->DropAndPlug(1, r0); // Drop the key still on the stack. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
| 1848 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1849 | void FullCodeGenerator::EmitCallWithStub(Call* expr) { |
| 1850 | // Code common for calls using the call stub. |
| 1851 | ZoneList<Expression*>* args = expr->arguments(); |
| 1852 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1853 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1854 | for (int i = 0; i < arg_count; i++) { |
| 1855 | VisitForStackValue(args->at(i)); |
| 1856 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1857 | } |
| 1858 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1859 | SetSourcePosition(expr->position()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1860 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1861 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1862 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1863 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1864 | // Restore context register. |
| 1865 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1866 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | |
| 1870 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1871 | #ifdef DEBUG |
| 1872 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 1873 | // through this function. Avoid early returns. |
| 1874 | expr->return_is_recorded_ = false; |
| 1875 | #endif |
| 1876 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1877 | Comment cmnt(masm_, "[ Call"); |
| 1878 | Expression* fun = expr->expression(); |
| 1879 | Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 1880 | |
| 1881 | if (var != NULL && var->is_possibly_eval()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1882 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 1883 | // resolve the function we need to call and the receiver of the |
| 1884 | // call. Then we call the resolved function using the given |
| 1885 | // arguments. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1886 | ZoneList<Expression*>* args = expr->arguments(); |
| 1887 | int arg_count = args->length(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1888 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1889 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1890 | VisitForStackValue(fun); |
| 1891 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1892 | __ push(r2); // Reserved receiver slot. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1893 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1894 | // Push the arguments. |
| 1895 | for (int i = 0; i < arg_count; i++) { |
| 1896 | VisitForStackValue(args->at(i)); |
| 1897 | } |
| 1898 | |
| 1899 | // Push copy of the function - found below the arguments. |
| 1900 | __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1901 | __ push(r1); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1902 | |
| 1903 | // Push copy of the first argument or undefined if it doesn't exist. |
| 1904 | if (arg_count > 0) { |
| 1905 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 1906 | __ push(r1); |
| 1907 | } else { |
| 1908 | __ push(r2); |
| 1909 | } |
| 1910 | |
| 1911 | // Push the receiver of the enclosing function and do runtime call. |
| 1912 | __ ldr(r1, |
| 1913 | MemOperand(fp, (2 + scope()->num_parameters()) * kPointerSize)); |
| 1914 | __ push(r1); |
| 1915 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
| 1916 | |
| 1917 | // The runtime call returns a pair of values in r0 (function) and |
| 1918 | // r1 (receiver). Touch up the stack with the right values. |
| 1919 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
| 1920 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1923 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1924 | SetSourcePosition(expr->position()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1925 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1926 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
| 1927 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1928 | RecordJSReturnSite(expr); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1929 | // Restore context register. |
| 1930 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1931 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1932 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1933 | // Push global object as receiver for the call IC. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1934 | __ ldr(r0, GlobalObjectOperand()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1935 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1936 | EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1937 | } else if (var != NULL && var->AsSlot() != NULL && |
| 1938 | var->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1939 | // Call to a lookup slot (dynamically introduced variable). |
| 1940 | Label slow, done; |
| 1941 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1943 | // Generate code for loading from variables potentially shadowed |
| 1944 | // by eval-introduced variables. |
| 1945 | EmitDynamicLoadFromSlotFastCase(var->AsSlot(), |
| 1946 | NOT_INSIDE_TYPEOF, |
| 1947 | &slow, |
| 1948 | &done); |
| 1949 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1950 | |
| 1951 | __ bind(&slow); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1952 | // Call the runtime to find the function to call (returned in r0) |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1953 | // and the object holding it (returned in edx). |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1954 | __ push(context_register()); |
| 1955 | __ mov(r2, Operand(var->name())); |
| 1956 | __ push(r2); |
| 1957 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1958 | __ Push(r0, r1); // Function, receiver. |
| 1959 | |
| 1960 | // If fast case code has been generated, emit code to push the |
| 1961 | // function and receiver and have the slow path jump around this |
| 1962 | // code. |
| 1963 | if (done.is_linked()) { |
| 1964 | Label call; |
| 1965 | __ b(&call); |
| 1966 | __ bind(&done); |
| 1967 | // Push function. |
| 1968 | __ push(r0); |
| 1969 | // Push global receiver. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1970 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1971 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 1972 | __ push(r1); |
| 1973 | __ bind(&call); |
| 1974 | } |
| 1975 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1976 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1977 | } else if (fun->AsProperty() != NULL) { |
| 1978 | // Call to an object property. |
| 1979 | Property* prop = fun->AsProperty(); |
| 1980 | Literal* key = prop->key()->AsLiteral(); |
| 1981 | if (key != NULL && key->handle()->IsSymbol()) { |
| 1982 | // Call to a named property, use call IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1983 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1984 | VisitForStackValue(prop->obj()); |
| 1985 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1986 | EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); |
| 1987 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1988 | // Call to a keyed property. |
| 1989 | // For a synthetic property use keyed load IC followed by function call, |
| 1990 | // for a regular property use keyed CallIC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1991 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1992 | VisitForStackValue(prop->obj()); |
| 1993 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1994 | if (prop->is_synthetic()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1995 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1996 | VisitForAccumulatorValue(prop->key()); |
| 1997 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1998 | // Record source code position for IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | SetSourcePosition(prop->position()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2000 | __ pop(r1); // We do not need to keep the receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2001 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2002 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2003 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2004 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2005 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2006 | __ Push(r0, r1); // Function, receiver. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2007 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2008 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2009 | EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2010 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2011 | } |
| 2012 | } else { |
| 2013 | // Call to some other expression. If the expression is an anonymous |
| 2014 | // function literal not called in a loop, mark it as one that should |
| 2015 | // also use the fast code generator. |
| 2016 | FunctionLiteral* lit = fun->AsFunctionLiteral(); |
| 2017 | if (lit != NULL && |
| 2018 | lit->name()->Equals(Heap::empty_string()) && |
| 2019 | loop_depth() == 0) { |
| 2020 | lit->set_try_full_codegen(true); |
| 2021 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2022 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2023 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2024 | VisitForStackValue(fun); |
| 2025 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2026 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2027 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2028 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 2029 | __ push(r1); |
| 2030 | // Emit function call. |
| 2031 | EmitCallWithStub(expr); |
| 2032 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | |
| 2034 | #ifdef DEBUG |
| 2035 | // RecordJSReturnSite should have been called. |
| 2036 | ASSERT(expr->return_is_recorded_); |
| 2037 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | |
| 2041 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2042 | Comment cmnt(masm_, "[ CallNew"); |
| 2043 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2044 | // expression in new calls must be evaluated before the |
| 2045 | // arguments. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2046 | |
| 2047 | // Push constructor on the stack. If it's not a function it's used as |
| 2048 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2049 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2050 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2051 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2052 | // Push the arguments ("left-to-right") on the stack. |
| 2053 | ZoneList<Expression*>* args = expr->arguments(); |
| 2054 | int arg_count = args->length(); |
| 2055 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2056 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | // Call the construct call builtin that handles allocation and |
| 2060 | // constructor invocation. |
| 2061 | SetSourcePosition(expr->position()); |
| 2062 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2063 | // Load function and argument count into r1 and r0. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2064 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2065 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2066 | |
| 2067 | Handle<Code> construct_builtin(Builtins::builtin(Builtins::JSConstructCall)); |
| 2068 | __ Call(construct_builtin, RelocInfo::CONSTRUCT_CALL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2069 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2073 | void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) { |
| 2074 | ASSERT(args->length() == 1); |
| 2075 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2076 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2077 | |
| 2078 | Label materialize_true, materialize_false; |
| 2079 | Label* if_true = NULL; |
| 2080 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2081 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2082 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2083 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2084 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2085 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 2086 | __ tst(r0, Operand(kSmiTagMask)); |
| 2087 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2088 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2089 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | |
| 2093 | void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) { |
| 2094 | ASSERT(args->length() == 1); |
| 2095 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2096 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2097 | |
| 2098 | Label materialize_true, materialize_false; |
| 2099 | Label* if_true = NULL; |
| 2100 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2101 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2102 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2103 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2104 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2105 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2106 | __ tst(r0, Operand(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2107 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2108 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2109 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | |
| 2113 | void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) { |
| 2114 | ASSERT(args->length() == 1); |
| 2115 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2116 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2117 | |
| 2118 | Label materialize_true, materialize_false; |
| 2119 | Label* if_true = NULL; |
| 2120 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2121 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2122 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2123 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2124 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2125 | __ BranchOnSmi(r0, if_false); |
| 2126 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2127 | __ cmp(r0, ip); |
| 2128 | __ b(eq, if_true); |
| 2129 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2130 | // Undetectable objects behave like undefined when tested with typeof. |
| 2131 | __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 2132 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
| 2133 | __ b(ne, if_false); |
| 2134 | __ ldrb(r1, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 2135 | __ cmp(r1, Operand(FIRST_JS_OBJECT_TYPE)); |
| 2136 | __ b(lt, if_false); |
| 2137 | __ cmp(r1, Operand(LAST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2138 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2139 | Split(le, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2140 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2141 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2145 | void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) { |
| 2146 | ASSERT(args->length() == 1); |
| 2147 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2148 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2149 | |
| 2150 | Label materialize_true, materialize_false; |
| 2151 | Label* if_true = NULL; |
| 2152 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2153 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2154 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2155 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2156 | |
| 2157 | __ BranchOnSmi(r0, if_false); |
| 2158 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2159 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2160 | Split(ge, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2161 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2162 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2166 | void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) { |
| 2167 | ASSERT(args->length() == 1); |
| 2168 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2169 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2170 | |
| 2171 | Label materialize_true, materialize_false; |
| 2172 | Label* if_true = NULL; |
| 2173 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2174 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2175 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2176 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2177 | |
| 2178 | __ BranchOnSmi(r0, if_false); |
| 2179 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2180 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 2181 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2182 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2183 | Split(ne, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2184 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2185 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2189 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
| 2190 | ZoneList<Expression*>* args) { |
| 2191 | |
| 2192 | ASSERT(args->length() == 1); |
| 2193 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2194 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2195 | |
| 2196 | Label materialize_true, materialize_false; |
| 2197 | Label* if_true = NULL; |
| 2198 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2199 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2200 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2201 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2202 | |
| 2203 | // Just indicate false, as %_IsStringWrapperSafeForDefaultValueOf() is only |
| 2204 | // used in a few functions in runtime.js which should not normally be hit by |
| 2205 | // this compiler. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2206 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2207 | __ jmp(if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2208 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2212 | void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) { |
| 2213 | ASSERT(args->length() == 1); |
| 2214 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2215 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2216 | |
| 2217 | Label materialize_true, materialize_false; |
| 2218 | Label* if_true = NULL; |
| 2219 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2220 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2221 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2222 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2223 | |
| 2224 | __ BranchOnSmi(r0, if_false); |
| 2225 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2226 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2227 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2228 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2229 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
| 2232 | |
| 2233 | void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) { |
| 2234 | ASSERT(args->length() == 1); |
| 2235 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2236 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2237 | |
| 2238 | Label materialize_true, materialize_false; |
| 2239 | Label* if_true = NULL; |
| 2240 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2241 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2242 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2243 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2244 | |
| 2245 | __ BranchOnSmi(r0, if_false); |
| 2246 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2247 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2248 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2249 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2250 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | |
| 2254 | void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) { |
| 2255 | ASSERT(args->length() == 1); |
| 2256 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2257 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2258 | |
| 2259 | Label materialize_true, materialize_false; |
| 2260 | Label* if_true = NULL; |
| 2261 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2262 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2263 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2264 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2265 | |
| 2266 | __ BranchOnSmi(r0, if_false); |
| 2267 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2268 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2269 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2270 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2271 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) { |
| 2277 | ASSERT(args->length() == 0); |
| 2278 | |
| 2279 | Label materialize_true, materialize_false; |
| 2280 | Label* if_true = NULL; |
| 2281 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2282 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2283 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2284 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2285 | |
| 2286 | // Get the frame pointer for the calling frame. |
| 2287 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2288 | |
| 2289 | // Skip the arguments adaptor frame if it exists. |
| 2290 | Label check_frame_marker; |
| 2291 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2292 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2293 | __ b(ne, &check_frame_marker); |
| 2294 | __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset)); |
| 2295 | |
| 2296 | // Check the marker in the calling frame. |
| 2297 | __ bind(&check_frame_marker); |
| 2298 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset)); |
| 2299 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2300 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2301 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2302 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2303 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | |
| 2307 | void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) { |
| 2308 | ASSERT(args->length() == 2); |
| 2309 | |
| 2310 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2311 | VisitForStackValue(args->at(0)); |
| 2312 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2313 | |
| 2314 | Label materialize_true, materialize_false; |
| 2315 | Label* if_true = NULL; |
| 2316 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2317 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2318 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2319 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2320 | |
| 2321 | __ pop(r1); |
| 2322 | __ cmp(r0, r1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2323 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2324 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2325 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2326 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | |
| 2330 | void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) { |
| 2331 | ASSERT(args->length() == 1); |
| 2332 | |
| 2333 | // ArgumentsAccessStub expects the key in edx and the formal |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2334 | // parameter count in r0. |
| 2335 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2336 | __ mov(r1, r0); |
| 2337 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2338 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 2339 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2340 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | |
| 2344 | void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) { |
| 2345 | ASSERT(args->length() == 0); |
| 2346 | |
| 2347 | Label exit; |
| 2348 | // Get the number of formal parameters. |
| 2349 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2350 | |
| 2351 | // Check if the calling frame is an arguments adaptor frame. |
| 2352 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2353 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2354 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2355 | __ b(ne, &exit); |
| 2356 | |
| 2357 | // Arguments adaptor case: Read the arguments length from the |
| 2358 | // adaptor frame. |
| 2359 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2360 | |
| 2361 | __ bind(&exit); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2362 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) { |
| 2367 | ASSERT(args->length() == 1); |
| 2368 | Label done, null, function, non_function_constructor; |
| 2369 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2370 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2371 | |
| 2372 | // If the object is a smi, we return null. |
| 2373 | __ BranchOnSmi(r0, &null); |
| 2374 | |
| 2375 | // Check that the object is a JS object but take special care of JS |
| 2376 | // functions to make sure they have 'Function' as their class. |
| 2377 | __ CompareObjectType(r0, r0, r1, FIRST_JS_OBJECT_TYPE); // Map is now in r0. |
| 2378 | __ b(lt, &null); |
| 2379 | |
| 2380 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 2381 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 2382 | // LAST_JS_OBJECT_TYPE. |
| 2383 | ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 2384 | ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
| 2385 | __ cmp(r1, Operand(JS_FUNCTION_TYPE)); |
| 2386 | __ b(eq, &function); |
| 2387 | |
| 2388 | // Check if the constructor in the map is a function. |
| 2389 | __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset)); |
| 2390 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
| 2391 | __ b(ne, &non_function_constructor); |
| 2392 | |
| 2393 | // r0 now contains the constructor function. Grab the |
| 2394 | // instance class name from there. |
| 2395 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 2396 | __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2397 | __ b(&done); |
| 2398 | |
| 2399 | // Functions have class 'Function'. |
| 2400 | __ bind(&function); |
| 2401 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2402 | __ jmp(&done); |
| 2403 | |
| 2404 | // Objects with a non-function constructor have class 'Object'. |
| 2405 | __ bind(&non_function_constructor); |
| 2406 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2407 | __ jmp(&done); |
| 2408 | |
| 2409 | // Non-JS objects have class null. |
| 2410 | __ bind(&null); |
| 2411 | __ LoadRoot(r0, Heap::kNullValueRootIndex); |
| 2412 | |
| 2413 | // All done. |
| 2414 | __ bind(&done); |
| 2415 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2416 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) { |
| 2421 | // Conditionally generate a log call. |
| 2422 | // Args: |
| 2423 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 2424 | // This is used to determine whether or not to generate the log call. |
| 2425 | // 1 (string): Format string. Access the string at argument index 2 |
| 2426 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 2427 | // 2 (array): Arguments to the format string. |
| 2428 | ASSERT_EQ(args->length(), 3); |
| 2429 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 2430 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2431 | VisitForStackValue(args->at(1)); |
| 2432 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2433 | __ CallRuntime(Runtime::kLog, 2); |
| 2434 | } |
| 2435 | #endif |
| 2436 | // Finally, we're expected to leave a value on the top of the stack. |
| 2437 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2438 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | |
| 2442 | void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) { |
| 2443 | ASSERT(args->length() == 0); |
| 2444 | |
| 2445 | Label slow_allocate_heapnumber; |
| 2446 | Label heapnumber_allocated; |
| 2447 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2448 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 2449 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2450 | __ jmp(&heapnumber_allocated); |
| 2451 | |
| 2452 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2453 | // Allocate a heap number. |
| 2454 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2455 | __ mov(r4, Operand(r0)); |
| 2456 | |
| 2457 | __ bind(&heapnumber_allocated); |
| 2458 | |
| 2459 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 2460 | // by computing: |
| 2461 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 2462 | if (CpuFeatures::IsSupported(VFP3)) { |
| 2463 | __ PrepareCallCFunction(0, r1); |
| 2464 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 2465 | |
| 2466 | CpuFeatures::Scope scope(VFP3); |
| 2467 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 2468 | // Create this constant using mov/orr to avoid PC relative load. |
| 2469 | __ mov(r1, Operand(0x41000000)); |
| 2470 | __ orr(r1, r1, Operand(0x300000)); |
| 2471 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 2472 | __ vmov(d7, r0, r1); |
| 2473 | // Move 0x4130000000000000 to VFP. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2474 | __ mov(r0, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2475 | __ vmov(d8, r0, r1); |
| 2476 | // Subtract and store the result in the heap number. |
| 2477 | __ vsub(d7, d7, d8); |
| 2478 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 2479 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 2480 | __ mov(r0, r4); |
| 2481 | } else { |
| 2482 | __ mov(r0, Operand(r4)); |
| 2483 | __ PrepareCallCFunction(1, r1); |
| 2484 | __ CallCFunction( |
| 2485 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 2486 | } |
| 2487 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2488 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | |
| 2492 | void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) { |
| 2493 | // Load the arguments on the stack and call the stub. |
| 2494 | SubStringStub stub; |
| 2495 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2496 | VisitForStackValue(args->at(0)); |
| 2497 | VisitForStackValue(args->at(1)); |
| 2498 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2499 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2500 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | |
| 2504 | void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) { |
| 2505 | // Load the arguments on the stack and call the stub. |
| 2506 | RegExpExecStub stub; |
| 2507 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2508 | VisitForStackValue(args->at(0)); |
| 2509 | VisitForStackValue(args->at(1)); |
| 2510 | VisitForStackValue(args->at(2)); |
| 2511 | VisitForStackValue(args->at(3)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2512 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2513 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | |
| 2517 | void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) { |
| 2518 | ASSERT(args->length() == 1); |
| 2519 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2520 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2521 | |
| 2522 | Label done; |
| 2523 | // If the object is a smi return the object. |
| 2524 | __ BranchOnSmi(r0, &done); |
| 2525 | // If the object is not a value type, return the object. |
| 2526 | __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE); |
| 2527 | __ b(ne, &done); |
| 2528 | __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset)); |
| 2529 | |
| 2530 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2531 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | |
| 2535 | void FullCodeGenerator::EmitMathPow(ZoneList<Expression*>* args) { |
| 2536 | // Load the arguments on the stack and call the runtime function. |
| 2537 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2538 | VisitForStackValue(args->at(0)); |
| 2539 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2540 | __ CallRuntime(Runtime::kMath_pow, 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2541 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | |
| 2545 | void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) { |
| 2546 | ASSERT(args->length() == 2); |
| 2547 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2548 | VisitForStackValue(args->at(0)); // Load the object. |
| 2549 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2550 | __ pop(r1); // r0 = value. r1 = object. |
| 2551 | |
| 2552 | Label done; |
| 2553 | // If the object is a smi, return the value. |
| 2554 | __ BranchOnSmi(r1, &done); |
| 2555 | |
| 2556 | // If the object is not a value type, return the value. |
| 2557 | __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE); |
| 2558 | __ b(ne, &done); |
| 2559 | |
| 2560 | // Store the value. |
| 2561 | __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); |
| 2562 | // Update the write barrier. Save the value as it will be |
| 2563 | // overwritten by the write barrier code and is needed afterward. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2564 | __ RecordWrite(r1, Operand(JSValue::kValueOffset - kHeapObjectTag), r2, r3); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2565 | |
| 2566 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2567 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | |
| 2571 | void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) { |
| 2572 | ASSERT_EQ(args->length(), 1); |
| 2573 | |
| 2574 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2575 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2576 | |
| 2577 | NumberToStringStub stub; |
| 2578 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2579 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2580 | } |
| 2581 | |
| 2582 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2583 | void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2584 | ASSERT(args->length() == 1); |
| 2585 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2586 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2587 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2588 | Label done; |
| 2589 | StringCharFromCodeGenerator generator(r0, r1); |
| 2590 | generator.GenerateFast(masm_); |
| 2591 | __ jmp(&done); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2592 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2593 | NopRuntimeCallHelper call_helper; |
| 2594 | generator.GenerateSlow(masm_, call_helper); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2595 | |
| 2596 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2597 | context()->Plug(r1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2601 | void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) { |
| 2602 | ASSERT(args->length() == 2); |
| 2603 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2604 | VisitForStackValue(args->at(0)); |
| 2605 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2606 | |
| 2607 | Register object = r1; |
| 2608 | Register index = r0; |
| 2609 | Register scratch = r2; |
| 2610 | Register result = r3; |
| 2611 | |
| 2612 | __ pop(object); |
| 2613 | |
| 2614 | Label need_conversion; |
| 2615 | Label index_out_of_range; |
| 2616 | Label done; |
| 2617 | StringCharCodeAtGenerator generator(object, |
| 2618 | index, |
| 2619 | scratch, |
| 2620 | result, |
| 2621 | &need_conversion, |
| 2622 | &need_conversion, |
| 2623 | &index_out_of_range, |
| 2624 | STRING_INDEX_IS_NUMBER); |
| 2625 | generator.GenerateFast(masm_); |
| 2626 | __ jmp(&done); |
| 2627 | |
| 2628 | __ bind(&index_out_of_range); |
| 2629 | // When the index is out of range, the spec requires us to return |
| 2630 | // NaN. |
| 2631 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 2632 | __ jmp(&done); |
| 2633 | |
| 2634 | __ bind(&need_conversion); |
| 2635 | // Load the undefined value into the result register, which will |
| 2636 | // trigger conversion. |
| 2637 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2638 | __ jmp(&done); |
| 2639 | |
| 2640 | NopRuntimeCallHelper call_helper; |
| 2641 | generator.GenerateSlow(masm_, call_helper); |
| 2642 | |
| 2643 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2644 | context()->Plug(result); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2645 | } |
| 2646 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2647 | |
| 2648 | void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) { |
| 2649 | ASSERT(args->length() == 2); |
| 2650 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2651 | VisitForStackValue(args->at(0)); |
| 2652 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2653 | |
| 2654 | Register object = r1; |
| 2655 | Register index = r0; |
| 2656 | Register scratch1 = r2; |
| 2657 | Register scratch2 = r3; |
| 2658 | Register result = r0; |
| 2659 | |
| 2660 | __ pop(object); |
| 2661 | |
| 2662 | Label need_conversion; |
| 2663 | Label index_out_of_range; |
| 2664 | Label done; |
| 2665 | StringCharAtGenerator generator(object, |
| 2666 | index, |
| 2667 | scratch1, |
| 2668 | scratch2, |
| 2669 | result, |
| 2670 | &need_conversion, |
| 2671 | &need_conversion, |
| 2672 | &index_out_of_range, |
| 2673 | STRING_INDEX_IS_NUMBER); |
| 2674 | generator.GenerateFast(masm_); |
| 2675 | __ jmp(&done); |
| 2676 | |
| 2677 | __ bind(&index_out_of_range); |
| 2678 | // When the index is out of range, the spec requires us to return |
| 2679 | // the empty string. |
| 2680 | __ LoadRoot(result, Heap::kEmptyStringRootIndex); |
| 2681 | __ jmp(&done); |
| 2682 | |
| 2683 | __ bind(&need_conversion); |
| 2684 | // Move smi zero into the result register, which will trigger |
| 2685 | // conversion. |
| 2686 | __ mov(result, Operand(Smi::FromInt(0))); |
| 2687 | __ jmp(&done); |
| 2688 | |
| 2689 | NopRuntimeCallHelper call_helper; |
| 2690 | generator.GenerateSlow(masm_, call_helper); |
| 2691 | |
| 2692 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2693 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2697 | void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) { |
| 2698 | ASSERT_EQ(2, args->length()); |
| 2699 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2700 | VisitForStackValue(args->at(0)); |
| 2701 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2702 | |
| 2703 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 2704 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2705 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
| 2709 | void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) { |
| 2710 | ASSERT_EQ(2, args->length()); |
| 2711 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2712 | VisitForStackValue(args->at(0)); |
| 2713 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2714 | |
| 2715 | StringCompareStub stub; |
| 2716 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2717 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | |
| 2721 | void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) { |
| 2722 | // Load the argument on the stack and call the runtime. |
| 2723 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2724 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2725 | __ CallRuntime(Runtime::kMath_sin, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2726 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2727 | } |
| 2728 | |
| 2729 | |
| 2730 | void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) { |
| 2731 | // Load the argument on the stack and call the runtime. |
| 2732 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2733 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2734 | __ CallRuntime(Runtime::kMath_cos, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2735 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | |
| 2739 | void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) { |
| 2740 | // Load the argument on the stack and call the runtime function. |
| 2741 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2742 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2743 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2744 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2748 | void FullCodeGenerator::EmitMathLog(ZoneList<Expression*>* args) { |
| 2749 | // Load the argument on the stack and call the runtime function. |
| 2750 | ASSERT(args->length() == 1); |
| 2751 | VisitForStackValue(args->at(0)); |
| 2752 | __ CallRuntime(Runtime::kMath_log, 1); |
| 2753 | context()->Plug(r0); |
| 2754 | } |
| 2755 | |
| 2756 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2757 | void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) { |
| 2758 | ASSERT(args->length() >= 2); |
| 2759 | |
| 2760 | int arg_count = args->length() - 2; // For receiver and function. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2761 | VisitForStackValue(args->at(0)); // Receiver. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2762 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2763 | VisitForStackValue(args->at(i + 1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2764 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2765 | VisitForAccumulatorValue(args->at(arg_count + 1)); // Function. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2766 | |
| 2767 | // InvokeFunction requires function in r1. Move it in there. |
| 2768 | if (!result_register().is(r1)) __ mov(r1, result_register()); |
| 2769 | ParameterCount count(arg_count); |
| 2770 | __ InvokeFunction(r1, count, CALL_FUNCTION); |
| 2771 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2772 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | |
| 2776 | void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2777 | RegExpConstructResultStub stub; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2778 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2779 | VisitForStackValue(args->at(0)); |
| 2780 | VisitForStackValue(args->at(1)); |
| 2781 | VisitForStackValue(args->at(2)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2782 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2783 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | void FullCodeGenerator::EmitSwapElements(ZoneList<Expression*>* args) { |
| 2788 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2789 | VisitForStackValue(args->at(0)); |
| 2790 | VisitForStackValue(args->at(1)); |
| 2791 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2792 | __ CallRuntime(Runtime::kSwapElements, 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2793 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2794 | } |
| 2795 | |
| 2796 | |
| 2797 | void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) { |
| 2798 | ASSERT_EQ(2, args->length()); |
| 2799 | |
| 2800 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 2801 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 2802 | |
| 2803 | Handle<FixedArray> jsfunction_result_caches( |
| 2804 | Top::global_context()->jsfunction_result_caches()); |
| 2805 | if (jsfunction_result_caches->length() <= cache_id) { |
| 2806 | __ Abort("Attempt to use undefined cache."); |
| 2807 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2808 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2809 | return; |
| 2810 | } |
| 2811 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2812 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2813 | |
| 2814 | Register key = r0; |
| 2815 | Register cache = r1; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2816 | __ ldr(cache, ContextOperand(cp, Context::GLOBAL_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2817 | __ ldr(cache, FieldMemOperand(cache, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2818 | __ ldr(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2819 | __ ldr(cache, |
| 2820 | FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 2821 | |
| 2822 | |
| 2823 | Label done, not_found; |
| 2824 | // tmp now holds finger offset as a smi. |
| 2825 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 2826 | __ ldr(r2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 2827 | // r2 now holds finger offset as a smi. |
| 2828 | __ add(r3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2829 | // r3 now points to the start of fixed array elements. |
| 2830 | __ ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 2831 | // Note side effect of PreIndex: r3 now points to the key of the pair. |
| 2832 | __ cmp(key, r2); |
| 2833 | __ b(ne, ¬_found); |
| 2834 | |
| 2835 | __ ldr(r0, MemOperand(r3, kPointerSize)); |
| 2836 | __ b(&done); |
| 2837 | |
| 2838 | __ bind(¬_found); |
| 2839 | // Call runtime to perform the lookup. |
| 2840 | __ Push(cache, key); |
| 2841 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 2842 | |
| 2843 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2844 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2848 | void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 2849 | ASSERT_EQ(2, args->length()); |
| 2850 | |
| 2851 | Register right = r0; |
| 2852 | Register left = r1; |
| 2853 | Register tmp = r2; |
| 2854 | Register tmp2 = r3; |
| 2855 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2856 | VisitForStackValue(args->at(0)); |
| 2857 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2858 | __ pop(left); |
| 2859 | |
| 2860 | Label done, fail, ok; |
| 2861 | __ cmp(left, Operand(right)); |
| 2862 | __ b(eq, &ok); |
| 2863 | // Fail if either is a non-HeapObject. |
| 2864 | __ and_(tmp, left, Operand(right)); |
| 2865 | __ tst(tmp, Operand(kSmiTagMask)); |
| 2866 | __ b(eq, &fail); |
| 2867 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 2868 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 2869 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 2870 | __ b(ne, &fail); |
| 2871 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 2872 | __ cmp(tmp, Operand(tmp2)); |
| 2873 | __ b(ne, &fail); |
| 2874 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 2875 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 2876 | __ cmp(tmp, tmp2); |
| 2877 | __ b(eq, &ok); |
| 2878 | __ bind(&fail); |
| 2879 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 2880 | __ jmp(&done); |
| 2881 | __ bind(&ok); |
| 2882 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 2883 | __ bind(&done); |
| 2884 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2885 | context()->Plug(r0); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2889 | void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2890 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2891 | |
| 2892 | Label materialize_true, materialize_false; |
| 2893 | Label* if_true = NULL; |
| 2894 | Label* if_false = NULL; |
| 2895 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2896 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2897 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2898 | |
| 2899 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2900 | __ tst(r0, Operand(String::kContainsCachedArrayIndexMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2901 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 2902 | Split(eq, if_true, if_false, fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2903 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2904 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | |
| 2908 | void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 2909 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2910 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2911 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2912 | __ IndexFromHash(r0, r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2913 | context()->Plug(r0); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 2917 | void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) { |
| 2918 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 2919 | context()->Plug(r0); |
| 2920 | return; |
| 2921 | } |
| 2922 | |
| 2923 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2924 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2925 | Handle<String> name = expr->name(); |
| 2926 | if (name->length() > 0 && name->Get(0) == '_') { |
| 2927 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 2928 | EmitInlineRuntimeCall(expr); |
| 2929 | return; |
| 2930 | } |
| 2931 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2932 | Comment cmnt(masm_, "[ CallRuntime"); |
| 2933 | ZoneList<Expression*>* args = expr->arguments(); |
| 2934 | |
| 2935 | if (expr->is_jsruntime()) { |
| 2936 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2937 | __ ldr(r0, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2938 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2939 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | // Push the arguments ("left-to-right"). |
| 2943 | int arg_count = args->length(); |
| 2944 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2945 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | if (expr->is_jsruntime()) { |
| 2949 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2950 | __ mov(r2, Operand(expr->name())); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2951 | Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, NOT_IN_LOOP); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2952 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2953 | // Restore context register. |
| 2954 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2955 | } else { |
| 2956 | // Call the C runtime function. |
| 2957 | __ CallRuntime(expr->function(), arg_count); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2958 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2959 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2960 | } |
| 2961 | |
| 2962 | |
| 2963 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 2964 | switch (expr->op()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2965 | case Token::DELETE: { |
| 2966 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
| 2967 | Property* prop = expr->expression()->AsProperty(); |
| 2968 | Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); |
| 2969 | if (prop == NULL && var == NULL) { |
| 2970 | // Result of deleting non-property, non-variable reference is true. |
| 2971 | // The subexpression may have side effects. |
| 2972 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2973 | context()->Plug(true); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2974 | } else if (var != NULL && |
| 2975 | !var->is_global() && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2976 | var->AsSlot() != NULL && |
| 2977 | var->AsSlot()->type() != Slot::LOOKUP) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2978 | // Result of deleting non-global, non-dynamic variables is false. |
| 2979 | // The subexpression does not have side effects. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2980 | context()->Plug(false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2981 | } else { |
| 2982 | // Property or variable reference. Call the delete builtin with |
| 2983 | // object and property name as arguments. |
| 2984 | if (prop != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2985 | VisitForStackValue(prop->obj()); |
| 2986 | VisitForStackValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2987 | } else if (var->is_global()) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2988 | __ ldr(r1, GlobalObjectOperand()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2989 | __ mov(r0, Operand(var->name())); |
| 2990 | __ Push(r1, r0); |
| 2991 | } else { |
| 2992 | // Non-global variable. Call the runtime to look up the context |
| 2993 | // where the variable was introduced. |
| 2994 | __ push(context_register()); |
| 2995 | __ mov(r2, Operand(var->name())); |
| 2996 | __ push(r2); |
| 2997 | __ CallRuntime(Runtime::kLookupContext, 2); |
| 2998 | __ push(r0); |
| 2999 | __ mov(r2, Operand(var->name())); |
| 3000 | __ push(r2); |
| 3001 | } |
| 3002 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3003 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3004 | } |
| 3005 | break; |
| 3006 | } |
| 3007 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3008 | case Token::VOID: { |
| 3009 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 3010 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3011 | context()->Plug(Heap::kUndefinedValueRootIndex); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3012 | break; |
| 3013 | } |
| 3014 | |
| 3015 | case Token::NOT: { |
| 3016 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3017 | Label materialize_true, materialize_false; |
| 3018 | Label* if_true = NULL; |
| 3019 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3020 | Label* fall_through = NULL; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3021 | |
| 3022 | // Notice that the labels are swapped. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3023 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3024 | &if_false, &if_true, &fall_through); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3025 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3026 | VisitForControl(expr->expression(), if_true, if_false, fall_through); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3027 | context()->Plug(if_false, if_true); // Labels swapped. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3028 | break; |
| 3029 | } |
| 3030 | |
| 3031 | case Token::TYPEOF: { |
| 3032 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3033 | { StackValueContext context(this); |
| 3034 | VisitForTypeofValue(expr->expression()); |
| 3035 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3036 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3037 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3038 | break; |
| 3039 | } |
| 3040 | |
| 3041 | case Token::ADD: { |
| 3042 | Comment cmt(masm_, "[ UnaryOperation (ADD)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3043 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3044 | Label no_conversion; |
| 3045 | __ tst(result_register(), Operand(kSmiTagMask)); |
| 3046 | __ b(eq, &no_conversion); |
| 3047 | __ push(r0); |
| 3048 | __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS); |
| 3049 | __ bind(&no_conversion); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3050 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | case Token::SUB: { |
| 3055 | Comment cmt(masm_, "[ UnaryOperation (SUB)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3056 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3057 | UnaryOverwriteMode overwrite = |
| 3058 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3059 | GenericUnaryOpStub stub(Token::SUB, |
| 3060 | overwrite, |
| 3061 | NO_UNARY_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3062 | // GenericUnaryOpStub expects the argument to be in the |
| 3063 | // accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3064 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3065 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3066 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3067 | break; |
| 3068 | } |
| 3069 | |
| 3070 | case Token::BIT_NOT: { |
| 3071 | Comment cmt(masm_, "[ UnaryOperation (BIT_NOT)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3072 | // The generic unary operation stub expects the argument to be |
| 3073 | // in the accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3074 | VisitForAccumulatorValue(expr->expression()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3075 | Label done; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3076 | bool inline_smi_code = ShouldInlineSmiCase(expr->op()); |
| 3077 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3078 | Label call_stub; |
| 3079 | __ BranchOnNotSmi(r0, &call_stub); |
| 3080 | __ mvn(r0, Operand(r0)); |
| 3081 | // Bit-clear inverted smi-tag. |
| 3082 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 3083 | __ b(&done); |
| 3084 | __ bind(&call_stub); |
| 3085 | } |
| 3086 | bool overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3087 | UnaryOpFlags flags = inline_smi_code |
| 3088 | ? NO_UNARY_SMI_CODE_IN_STUB |
| 3089 | : NO_UNARY_FLAGS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3090 | UnaryOverwriteMode mode = |
| 3091 | overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3092 | GenericUnaryOpStub stub(Token::BIT_NOT, mode, flags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3093 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3094 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3095 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3096 | break; |
| 3097 | } |
| 3098 | |
| 3099 | default: |
| 3100 | UNREACHABLE(); |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | |
| 3105 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 3106 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3107 | SetSourcePosition(expr->position()); |
| 3108 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3109 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 3110 | // as the left-hand side. |
| 3111 | if (!expr->expression()->IsValidLeftHandSide()) { |
| 3112 | VisitForEffect(expr->expression()); |
| 3113 | return; |
| 3114 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3115 | |
| 3116 | // Expression can only be a property, a global or a (parameter or local) |
| 3117 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 3118 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 3119 | LhsKind assign_type = VARIABLE; |
| 3120 | Property* prop = expr->expression()->AsProperty(); |
| 3121 | // In case of a property we use the uninitialized expression context |
| 3122 | // of the key to detect a named property. |
| 3123 | if (prop != NULL) { |
| 3124 | assign_type = |
| 3125 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 3126 | } |
| 3127 | |
| 3128 | // Evaluate expression and get value. |
| 3129 | if (assign_type == VARIABLE) { |
| 3130 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3131 | AccumulatorValueContext context(this); |
| 3132 | EmitVariableLoad(expr->expression()->AsVariableProxy()->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3133 | } else { |
| 3134 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3135 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3136 | __ mov(ip, Operand(Smi::FromInt(0))); |
| 3137 | __ push(ip); |
| 3138 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3139 | if (assign_type == NAMED_PROPERTY) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3140 | // Put the object both on the stack and in the accumulator. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3141 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3142 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3143 | EmitNamedPropertyLoad(prop); |
| 3144 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3145 | if (prop->is_arguments_access()) { |
| 3146 | VariableProxy* obj_proxy = prop->obj()->AsVariableProxy(); |
| 3147 | __ ldr(r0, EmitSlotSearch(obj_proxy->var()->AsSlot(), r0)); |
| 3148 | __ push(r0); |
| 3149 | __ mov(r0, Operand(prop->key()->AsLiteral()->handle())); |
| 3150 | } else { |
| 3151 | VisitForStackValue(prop->obj()); |
| 3152 | VisitForAccumulatorValue(prop->key()); |
| 3153 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3154 | __ ldr(r1, MemOperand(sp, 0)); |
| 3155 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3156 | EmitKeyedPropertyLoad(prop); |
| 3157 | } |
| 3158 | } |
| 3159 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3160 | // We need a second deoptimization point after loading the value |
| 3161 | // in case evaluating the property load my have a side effect. |
| 3162 | PrepareForBailout(expr->increment(), TOS_REG); |
| 3163 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3164 | // Call ToNumber only if operand is not a smi. |
| 3165 | Label no_conversion; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3166 | __ BranchOnSmi(r0, &no_conversion); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3167 | __ push(r0); |
| 3168 | __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS); |
| 3169 | __ bind(&no_conversion); |
| 3170 | |
| 3171 | // Save result for postfix expressions. |
| 3172 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3173 | if (!context()->IsEffect()) { |
| 3174 | // Save the result on the stack. If we have a named or keyed property |
| 3175 | // we store the result under the receiver that is currently on top |
| 3176 | // of the stack. |
| 3177 | switch (assign_type) { |
| 3178 | case VARIABLE: |
| 3179 | __ push(r0); |
| 3180 | break; |
| 3181 | case NAMED_PROPERTY: |
| 3182 | __ str(r0, MemOperand(sp, kPointerSize)); |
| 3183 | break; |
| 3184 | case KEYED_PROPERTY: |
| 3185 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
| 3186 | break; |
| 3187 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3188 | } |
| 3189 | } |
| 3190 | |
| 3191 | |
| 3192 | // Inline smi case if we are in a loop. |
| 3193 | Label stub_call, done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3194 | int count_value = expr->op() == Token::INC ? 1 : -1; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3195 | if (ShouldInlineSmiCase(expr->op())) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3196 | __ add(r0, r0, Operand(Smi::FromInt(count_value)), SetCC); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3197 | __ b(vs, &stub_call); |
| 3198 | // We could eliminate this smi check if we split the code at |
| 3199 | // the first smi check before calling ToNumber. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3200 | __ BranchOnSmi(r0, &done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3201 | __ bind(&stub_call); |
| 3202 | // Call stub. Undo operation first. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3203 | __ sub(r0, r0, Operand(Smi::FromInt(count_value))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3204 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3205 | __ mov(r1, Operand(Smi::FromInt(count_value))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3206 | |
| 3207 | // Record position before stub call. |
| 3208 | SetSourcePosition(expr->position()); |
| 3209 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3210 | GenericBinaryOpStub stub(Token::ADD, NO_OVERWRITE, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3211 | __ CallStub(&stub); |
| 3212 | __ bind(&done); |
| 3213 | |
| 3214 | // Store the value returned in r0. |
| 3215 | switch (assign_type) { |
| 3216 | case VARIABLE: |
| 3217 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3218 | { EffectContext context(this); |
| 3219 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 3220 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3221 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 3222 | context.Plug(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3223 | } |
| 3224 | // For all contexts except EffectConstant We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3225 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3226 | if (!context()->IsEffect()) { |
| 3227 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3228 | } |
| 3229 | } else { |
| 3230 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3231 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3232 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 3233 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3234 | } |
| 3235 | break; |
| 3236 | case NAMED_PROPERTY: { |
| 3237 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3238 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3239 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3240 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3241 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3242 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3243 | if (!context()->IsEffect()) { |
| 3244 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3245 | } |
| 3246 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3247 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3248 | } |
| 3249 | break; |
| 3250 | } |
| 3251 | case KEYED_PROPERTY: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3252 | __ pop(r1); // Key. |
| 3253 | __ pop(r2); // Receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3254 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3255 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3256 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3257 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3258 | if (!context()->IsEffect()) { |
| 3259 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3260 | } |
| 3261 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3262 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3263 | } |
| 3264 | break; |
| 3265 | } |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3270 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
| 3271 | ASSERT(!context()->IsEffect()); |
| 3272 | ASSERT(!context()->IsTest()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3273 | VariableProxy* proxy = expr->AsVariableProxy(); |
| 3274 | if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) { |
| 3275 | Comment cmnt(masm_, "Global variable"); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3276 | __ ldr(r0, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3277 | __ mov(r2, Operand(proxy->name())); |
| 3278 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 3279 | // Use a regular load, not a contextual load, to avoid a reference |
| 3280 | // error. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3281 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3282 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3283 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3284 | } else if (proxy != NULL && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3285 | proxy->var()->AsSlot() != NULL && |
| 3286 | proxy->var()->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3287 | Label done, slow; |
| 3288 | |
| 3289 | // Generate code for loading from variables potentially shadowed |
| 3290 | // by eval-introduced variables. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3291 | Slot* slot = proxy->var()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3292 | EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done); |
| 3293 | |
| 3294 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3295 | __ mov(r0, Operand(proxy->name())); |
| 3296 | __ Push(cp, r0); |
| 3297 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3298 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3299 | __ bind(&done); |
| 3300 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3301 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3302 | } else { |
| 3303 | // This expression cannot throw a reference error at the top level. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3304 | context()->HandleExpression(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3309 | bool FullCodeGenerator::TryLiteralCompare(Token::Value op, |
| 3310 | Expression* left, |
| 3311 | Expression* right, |
| 3312 | Label* if_true, |
| 3313 | Label* if_false, |
| 3314 | Label* fall_through) { |
| 3315 | if (op != Token::EQ && op != Token::EQ_STRICT) return false; |
| 3316 | |
| 3317 | // Check for the pattern: typeof <expression> == <string literal>. |
| 3318 | Literal* right_literal = right->AsLiteral(); |
| 3319 | if (right_literal == NULL) return false; |
| 3320 | Handle<Object> right_literal_value = right_literal->handle(); |
| 3321 | if (!right_literal_value->IsString()) return false; |
| 3322 | UnaryOperation* left_unary = left->AsUnaryOperation(); |
| 3323 | if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false; |
| 3324 | Handle<String> check = Handle<String>::cast(right_literal_value); |
| 3325 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3326 | { AccumulatorValueContext context(this); |
| 3327 | VisitForTypeofValue(left_unary->expression()); |
| 3328 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3329 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 3330 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3331 | if (check->Equals(Heap::number_symbol())) { |
| 3332 | __ tst(r0, Operand(kSmiTagMask)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3333 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3334 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3335 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3336 | __ cmp(r0, ip); |
| 3337 | Split(eq, if_true, if_false, fall_through); |
| 3338 | } else if (check->Equals(Heap::string_symbol())) { |
| 3339 | __ tst(r0, Operand(kSmiTagMask)); |
| 3340 | __ b(eq, if_false); |
| 3341 | // Check for undetectable objects => false. |
| 3342 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3343 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3344 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3345 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3346 | __ b(eq, if_false); |
| 3347 | __ ldrb(r1, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 3348 | __ cmp(r1, Operand(FIRST_NONSTRING_TYPE)); |
| 3349 | Split(lt, if_true, if_false, fall_through); |
| 3350 | } else if (check->Equals(Heap::boolean_symbol())) { |
| 3351 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3352 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3353 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3354 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 3355 | __ cmp(r0, ip); |
| 3356 | Split(eq, if_true, if_false, fall_through); |
| 3357 | } else if (check->Equals(Heap::undefined_symbol())) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3358 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3359 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3360 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3361 | __ tst(r0, Operand(kSmiTagMask)); |
| 3362 | __ b(eq, if_false); |
| 3363 | // Check for undetectable objects => true. |
| 3364 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3365 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3366 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3367 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3368 | Split(eq, if_true, if_false, fall_through); |
| 3369 | } else if (check->Equals(Heap::function_symbol())) { |
| 3370 | __ tst(r0, Operand(kSmiTagMask)); |
| 3371 | __ b(eq, if_false); |
| 3372 | __ CompareObjectType(r0, r1, r0, JS_FUNCTION_TYPE); |
| 3373 | __ b(eq, if_true); |
| 3374 | // Regular expressions => 'function' (they are callable). |
| 3375 | __ CompareInstanceType(r1, r0, JS_REGEXP_TYPE); |
| 3376 | Split(eq, if_true, if_false, fall_through); |
| 3377 | } else if (check->Equals(Heap::object_symbol())) { |
| 3378 | __ tst(r0, Operand(kSmiTagMask)); |
| 3379 | __ b(eq, if_false); |
| 3380 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 3381 | __ cmp(r0, ip); |
| 3382 | __ b(eq, if_true); |
| 3383 | // Regular expressions => 'function', not 'object'. |
| 3384 | __ CompareObjectType(r0, r1, r0, JS_REGEXP_TYPE); |
| 3385 | __ b(eq, if_false); |
| 3386 | // Check for undetectable objects => false. |
| 3387 | __ ldrb(r0, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3388 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 3389 | __ cmp(r0, Operand(1 << Map::kIsUndetectable)); |
| 3390 | __ b(eq, if_false); |
| 3391 | // Check for JS objects => true. |
| 3392 | __ ldrb(r0, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 3393 | __ cmp(r0, Operand(FIRST_JS_OBJECT_TYPE)); |
| 3394 | __ b(lt, if_false); |
| 3395 | __ cmp(r0, Operand(LAST_JS_OBJECT_TYPE)); |
| 3396 | Split(le, if_true, if_false, fall_through); |
| 3397 | } else { |
| 3398 | if (if_false != fall_through) __ jmp(if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3399 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3400 | |
| 3401 | return true; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3402 | } |
| 3403 | |
| 3404 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3405 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 3406 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3407 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3408 | |
| 3409 | // Always perform the comparison for its control flow. Pack the result |
| 3410 | // into the expression's context after the comparison is performed. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3411 | |
| 3412 | Label materialize_true, materialize_false; |
| 3413 | Label* if_true = NULL; |
| 3414 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3415 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3416 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3417 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3418 | |
| 3419 | // First we try a fast inlined version of the compare when one of |
| 3420 | // the operands is a literal. |
| 3421 | Token::Value op = expr->op(); |
| 3422 | Expression* left = expr->left(); |
| 3423 | Expression* right = expr->right(); |
| 3424 | if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3425 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3426 | return; |
| 3427 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3428 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3429 | VisitForStackValue(expr->left()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3431 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3432 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3433 | __ InvokeBuiltin(Builtins::IN, CALL_JS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3434 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3435 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3436 | __ cmp(r0, ip); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3437 | Split(eq, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3438 | break; |
| 3439 | |
| 3440 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3441 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3442 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3443 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3444 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3445 | // The stub returns 0 for true. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3446 | __ tst(r0, r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3447 | Split(eq, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3448 | break; |
| 3449 | } |
| 3450 | |
| 3451 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3452 | VisitForAccumulatorValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3453 | Condition cc = eq; |
| 3454 | bool strict = false; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3455 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3456 | case Token::EQ_STRICT: |
| 3457 | strict = true; |
| 3458 | // Fall through |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3459 | case Token::EQ: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3460 | cc = eq; |
| 3461 | __ pop(r1); |
| 3462 | break; |
| 3463 | case Token::LT: |
| 3464 | cc = lt; |
| 3465 | __ pop(r1); |
| 3466 | break; |
| 3467 | case Token::GT: |
| 3468 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
| 3469 | cc = lt; |
| 3470 | __ mov(r1, result_register()); |
| 3471 | __ pop(r0); |
| 3472 | break; |
| 3473 | case Token::LTE: |
| 3474 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
| 3475 | cc = ge; |
| 3476 | __ mov(r1, result_register()); |
| 3477 | __ pop(r0); |
| 3478 | break; |
| 3479 | case Token::GTE: |
| 3480 | cc = ge; |
| 3481 | __ pop(r1); |
| 3482 | break; |
| 3483 | case Token::IN: |
| 3484 | case Token::INSTANCEOF: |
| 3485 | default: |
| 3486 | UNREACHABLE(); |
| 3487 | } |
| 3488 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3489 | bool inline_smi_code = ShouldInlineSmiCase(op); |
| 3490 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3491 | Label slow_case; |
| 3492 | __ orr(r2, r0, Operand(r1)); |
| 3493 | __ BranchOnNotSmi(r2, &slow_case); |
| 3494 | __ cmp(r1, r0); |
| 3495 | Split(cc, if_true, if_false, NULL); |
| 3496 | __ bind(&slow_case); |
| 3497 | } |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3498 | CompareFlags flags = inline_smi_code |
| 3499 | ? NO_SMI_COMPARE_IN_STUB |
| 3500 | : NO_COMPARE_FLAGS; |
| 3501 | CompareStub stub(cc, strict, flags, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3502 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3503 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 3504 | __ cmp(r0, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3505 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3506 | } |
| 3507 | } |
| 3508 | |
| 3509 | // Convert the result of the comparison into one expected for this |
| 3510 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3511 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3515 | void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) { |
| 3516 | Comment cmnt(masm_, "[ CompareToNull"); |
| 3517 | Label materialize_true, materialize_false; |
| 3518 | Label* if_true = NULL; |
| 3519 | Label* if_false = NULL; |
| 3520 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3521 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3522 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3523 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3524 | VisitForAccumulatorValue(expr->expression()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3525 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3526 | __ LoadRoot(r1, Heap::kNullValueRootIndex); |
| 3527 | __ cmp(r0, r1); |
| 3528 | if (expr->is_strict()) { |
| 3529 | Split(eq, if_true, if_false, fall_through); |
| 3530 | } else { |
| 3531 | __ b(eq, if_true); |
| 3532 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 3533 | __ cmp(r0, r1); |
| 3534 | __ b(eq, if_true); |
| 3535 | __ tst(r0, Operand(kSmiTagMask)); |
| 3536 | __ b(eq, if_false); |
| 3537 | // It can be an undetectable object. |
| 3538 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3539 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3540 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3541 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3542 | Split(eq, if_true, if_false, fall_through); |
| 3543 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3544 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3548 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 3549 | __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3550 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3554 | Register FullCodeGenerator::result_register() { |
| 3555 | return r0; |
| 3556 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3557 | |
| 3558 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3559 | Register FullCodeGenerator::context_register() { |
| 3560 | return cp; |
| 3561 | } |
| 3562 | |
| 3563 | |
| 3564 | void FullCodeGenerator::EmitCallIC(Handle<Code> ic, RelocInfo::Mode mode) { |
| 3565 | ASSERT(mode == RelocInfo::CODE_TARGET || |
| 3566 | mode == RelocInfo::CODE_TARGET_CONTEXT); |
| 3567 | __ Call(ic, mode); |
| 3568 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3569 | |
| 3570 | |
| 3571 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 3572 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 3573 | __ str(value, MemOperand(fp, frame_offset)); |
| 3574 | } |
| 3575 | |
| 3576 | |
| 3577 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3578 | __ ldr(dst, ContextOperand(cp, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | |
| 3582 | // ---------------------------------------------------------------------------- |
| 3583 | // Non-local control flow support. |
| 3584 | |
| 3585 | void FullCodeGenerator::EnterFinallyBlock() { |
| 3586 | ASSERT(!result_register().is(r1)); |
| 3587 | // Store result register while executing finally block. |
| 3588 | __ push(result_register()); |
| 3589 | // Cook return address in link register to stack (smi encoded Code* delta) |
| 3590 | __ sub(r1, lr, Operand(masm_->CodeObject())); |
| 3591 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3592 | ASSERT_EQ(0, kSmiTag); |
| 3593 | __ add(r1, r1, Operand(r1)); // Convert to smi. |
| 3594 | __ push(r1); |
| 3595 | } |
| 3596 | |
| 3597 | |
| 3598 | void FullCodeGenerator::ExitFinallyBlock() { |
| 3599 | ASSERT(!result_register().is(r1)); |
| 3600 | // Restore result register from stack. |
| 3601 | __ pop(r1); |
| 3602 | // Uncook return address and return. |
| 3603 | __ pop(result_register()); |
| 3604 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3605 | __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. |
| 3606 | __ add(pc, r1, Operand(masm_->CodeObject())); |
| 3607 | } |
| 3608 | |
| 3609 | |
| 3610 | #undef __ |
| 3611 | |
| 3612 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3613 | |
| 3614 | #endif // V8_TARGET_ARCH_ARM |