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