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