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