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