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