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