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 | |
| 1172 | for (int i = 0; i < expr->properties()->length(); i++) { |
| 1173 | ObjectLiteral::Property* property = expr->properties()->at(i); |
| 1174 | if (property->IsCompileTimeValue()) continue; |
| 1175 | |
| 1176 | Literal* key = property->key(); |
| 1177 | Expression* value = property->value(); |
| 1178 | if (!result_saved) { |
| 1179 | __ push(r0); // Save result on stack |
| 1180 | result_saved = true; |
| 1181 | } |
| 1182 | switch (property->kind()) { |
| 1183 | case ObjectLiteral::Property::CONSTANT: |
| 1184 | UNREACHABLE(); |
| 1185 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 1186 | ASSERT(!CompileTimeValue::IsCompileTimeValue(property->value())); |
| 1187 | // Fall through. |
| 1188 | case ObjectLiteral::Property::COMPUTED: |
| 1189 | if (key->handle()->IsSymbol()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1190 | VisitForAccumulatorValue(value); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1191 | __ mov(r2, Operand(key->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1192 | __ ldr(r1, MemOperand(sp)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1193 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1194 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1195 | break; |
| 1196 | } |
| 1197 | // Fall through. |
| 1198 | case ObjectLiteral::Property::PROTOTYPE: |
| 1199 | // Duplicate receiver on stack. |
| 1200 | __ ldr(r0, MemOperand(sp)); |
| 1201 | __ push(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1202 | VisitForStackValue(key); |
| 1203 | VisitForStackValue(value); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1204 | __ CallRuntime(Runtime::kSetProperty, 3); |
| 1205 | break; |
| 1206 | case ObjectLiteral::Property::GETTER: |
| 1207 | case ObjectLiteral::Property::SETTER: |
| 1208 | // Duplicate receiver on stack. |
| 1209 | __ ldr(r0, MemOperand(sp)); |
| 1210 | __ push(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1211 | VisitForStackValue(key); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1212 | __ mov(r1, Operand(property->kind() == ObjectLiteral::Property::SETTER ? |
| 1213 | Smi::FromInt(1) : |
| 1214 | Smi::FromInt(0))); |
| 1215 | __ push(r1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1216 | VisitForStackValue(value); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1217 | __ CallRuntime(Runtime::kDefineAccessor, 4); |
| 1218 | break; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1223 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1224 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1225 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | void FullCodeGenerator::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1231 | Comment cmnt(masm_, "[ ArrayLiteral"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1232 | |
| 1233 | ZoneList<Expression*>* subexprs = expr->values(); |
| 1234 | int length = subexprs->length(); |
| 1235 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1236 | __ ldr(r3, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
| 1237 | __ ldr(r3, FieldMemOperand(r3, JSFunction::kLiteralsOffset)); |
| 1238 | __ mov(r2, Operand(Smi::FromInt(expr->literal_index()))); |
| 1239 | __ mov(r1, Operand(expr->constant_elements())); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 1240 | __ Push(r3, r2, r1); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1241 | if (expr->constant_elements()->map() == Heap::fixed_cow_array_map()) { |
| 1242 | FastCloneShallowArrayStub stub( |
| 1243 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 1244 | __ CallStub(&stub); |
| 1245 | __ IncrementCounter(&Counters::cow_arrays_created_stub, 1, r1, r2); |
| 1246 | } else if (expr->depth() > 1) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1247 | __ CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1248 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1249 | __ CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1250 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1251 | FastCloneShallowArrayStub stub( |
| 1252 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1253 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | bool result_saved = false; // Is the result saved to the stack? |
| 1257 | |
| 1258 | // Emit code to evaluate all the non-constant subexpressions and to store |
| 1259 | // them into the newly cloned array. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1260 | for (int i = 0; i < length; i++) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1261 | Expression* subexpr = subexprs->at(i); |
| 1262 | // If the subexpression is a literal or a simple materialized literal it |
| 1263 | // is already set in the cloned array. |
| 1264 | if (subexpr->AsLiteral() != NULL || |
| 1265 | CompileTimeValue::IsCompileTimeValue(subexpr)) { |
| 1266 | continue; |
| 1267 | } |
| 1268 | |
| 1269 | if (!result_saved) { |
| 1270 | __ push(r0); |
| 1271 | result_saved = true; |
| 1272 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1273 | VisitForAccumulatorValue(subexpr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1274 | |
| 1275 | // Store the subexpression value in the array's elements. |
| 1276 | __ ldr(r1, MemOperand(sp)); // Copy of array literal. |
| 1277 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 1278 | int offset = FixedArray::kHeaderSize + (i * kPointerSize); |
| 1279 | __ str(result_register(), FieldMemOperand(r1, offset)); |
| 1280 | |
| 1281 | // Update the write barrier for the array store with r0 as the scratch |
| 1282 | // register. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1283 | __ RecordWrite(r1, Operand(offset), r2, result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | if (result_saved) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1287 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1288 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1289 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1294 | void FullCodeGenerator::VisitAssignment(Assignment* expr) { |
| 1295 | Comment cmnt(masm_, "[ Assignment"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1296 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 1297 | // on the left-hand side. |
| 1298 | if (!expr->target()->IsValidLeftHandSide()) { |
| 1299 | VisitForEffect(expr->target()); |
| 1300 | return; |
| 1301 | } |
| 1302 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1303 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1304 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1305 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1306 | LhsKind assign_type = VARIABLE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1307 | Property* property = expr->target()->AsProperty(); |
| 1308 | if (property != NULL) { |
| 1309 | assign_type = (property->key()->IsPropertyName()) |
| 1310 | ? NAMED_PROPERTY |
| 1311 | : KEYED_PROPERTY; |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | // Evaluate LHS expression. |
| 1315 | switch (assign_type) { |
| 1316 | case VARIABLE: |
| 1317 | // Nothing to do here. |
| 1318 | break; |
| 1319 | case NAMED_PROPERTY: |
| 1320 | if (expr->is_compound()) { |
| 1321 | // 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] | 1322 | VisitForAccumulatorValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1323 | __ push(result_register()); |
| 1324 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1325 | VisitForStackValue(property->obj()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1326 | } |
| 1327 | break; |
| 1328 | case KEYED_PROPERTY: |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1329 | if (expr->is_compound()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1330 | VisitForStackValue(property->obj()); |
| 1331 | VisitForAccumulatorValue(property->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1332 | __ ldr(r1, MemOperand(sp, 0)); |
| 1333 | __ push(r0); |
| 1334 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1335 | VisitForStackValue(property->obj()); |
| 1336 | VisitForStackValue(property->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1337 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1338 | break; |
| 1339 | } |
| 1340 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1341 | if (expr->is_compound()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1342 | { AccumulatorValueContext context(this); |
| 1343 | switch (assign_type) { |
| 1344 | case VARIABLE: |
| 1345 | EmitVariableLoad(expr->target()->AsVariableProxy()->var()); |
| 1346 | break; |
| 1347 | case NAMED_PROPERTY: |
| 1348 | EmitNamedPropertyLoad(property); |
| 1349 | break; |
| 1350 | case KEYED_PROPERTY: |
| 1351 | EmitKeyedPropertyLoad(property); |
| 1352 | break; |
| 1353 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1354 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1355 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1356 | Token::Value op = expr->binary_op(); |
| 1357 | ConstantOperand constant = ShouldInlineSmiCase(op) |
| 1358 | ? GetConstantOperand(op, expr->target(), expr->value()) |
| 1359 | : kNoConstants; |
| 1360 | ASSERT(constant == kRightConstant || constant == kNoConstants); |
| 1361 | if (constant == kNoConstants) { |
| 1362 | __ push(r0); // Left operand goes on the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1363 | VisitForAccumulatorValue(expr->value()); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1364 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1365 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1366 | OverwriteMode mode = expr->value()->ResultOverwriteAllowed() |
| 1367 | ? OVERWRITE_RIGHT |
| 1368 | : NO_OVERWRITE; |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1369 | SetSourcePosition(expr->position() + 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1370 | AccumulatorValueContext context(this); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1371 | if (ShouldInlineSmiCase(op)) { |
| 1372 | EmitInlineSmiBinaryOp(expr, |
| 1373 | op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1374 | mode, |
| 1375 | expr->target(), |
| 1376 | expr->value(), |
| 1377 | constant); |
| 1378 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1379 | EmitBinaryOp(op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1380 | } |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1381 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1382 | VisitForAccumulatorValue(expr->value()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | // Record source position before possible IC call. |
| 1386 | SetSourcePosition(expr->position()); |
| 1387 | |
| 1388 | // Store the value. |
| 1389 | switch (assign_type) { |
| 1390 | case VARIABLE: |
| 1391 | EmitVariableAssignment(expr->target()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1392 | expr->op()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1393 | break; |
| 1394 | case NAMED_PROPERTY: |
| 1395 | EmitNamedPropertyAssignment(expr); |
| 1396 | break; |
| 1397 | case KEYED_PROPERTY: |
| 1398 | EmitKeyedPropertyAssignment(expr); |
| 1399 | break; |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1404 | void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
| 1405 | SetSourcePosition(prop->position()); |
| 1406 | Literal* key = prop->key()->AsLiteral(); |
| 1407 | __ mov(r2, Operand(key->handle())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1408 | // 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] | 1409 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1410 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | void FullCodeGenerator::EmitKeyedPropertyLoad(Property* prop) { |
| 1415 | SetSourcePosition(prop->position()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1416 | // 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] | 1417 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1418 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1422 | void FullCodeGenerator::EmitInlineSmiBinaryOp(Expression* expr, |
| 1423 | Token::Value op, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1424 | OverwriteMode mode, |
| 1425 | Expression* left, |
| 1426 | Expression* right, |
| 1427 | ConstantOperand constant) { |
| 1428 | ASSERT(constant == kNoConstants); // Only handled case. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1429 | EmitBinaryOp(op, mode); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1433 | void FullCodeGenerator::EmitBinaryOp(Token::Value op, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1434 | OverwriteMode mode) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1435 | __ pop(r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1436 | GenericBinaryOpStub stub(op, mode, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1437 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1438 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1442 | void FullCodeGenerator::EmitAssignment(Expression* expr) { |
| 1443 | // Invalid left-hand sides are rewritten to have a 'throw |
| 1444 | // ReferenceError' on the left-hand side. |
| 1445 | if (!expr->IsValidLeftHandSide()) { |
| 1446 | VisitForEffect(expr); |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1451 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1452 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1453 | LhsKind assign_type = VARIABLE; |
| 1454 | Property* prop = expr->AsProperty(); |
| 1455 | if (prop != NULL) { |
| 1456 | assign_type = (prop->key()->IsPropertyName()) |
| 1457 | ? NAMED_PROPERTY |
| 1458 | : KEYED_PROPERTY; |
| 1459 | } |
| 1460 | |
| 1461 | switch (assign_type) { |
| 1462 | case VARIABLE: { |
| 1463 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1464 | EffectContext context(this); |
| 1465 | EmitVariableAssignment(var, Token::ASSIGN); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1466 | break; |
| 1467 | } |
| 1468 | case NAMED_PROPERTY: { |
| 1469 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1470 | VisitForAccumulatorValue(prop->obj()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1471 | __ mov(r1, r0); |
| 1472 | __ pop(r0); // Restore value. |
| 1473 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
| 1474 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1475 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1476 | break; |
| 1477 | } |
| 1478 | case KEYED_PROPERTY: { |
| 1479 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1480 | VisitForStackValue(prop->obj()); |
| 1481 | VisitForAccumulatorValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1482 | __ mov(r1, r0); |
| 1483 | __ pop(r2); |
| 1484 | __ pop(r0); // Restore value. |
| 1485 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_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 | } |
| 1490 | } |
| 1491 | |
| 1492 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1493 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1494 | Token::Value op) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1495 | // Left-hand sides that rewrite to explicit property accesses do not reach |
| 1496 | // here. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1497 | ASSERT(var != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1498 | ASSERT(var->is_global() || var->AsSlot() != NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1499 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1500 | if (var->is_global()) { |
| 1501 | ASSERT(!var->is_this()); |
| 1502 | // Assignment to a global variable. Use inline caching for the |
| 1503 | // 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] | 1504 | // r2, and the global object in r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1505 | __ mov(r2, Operand(var->name())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1506 | __ ldr(r1, CodeGenerator::GlobalObject()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1507 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1508 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1509 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1510 | } else if (var->mode() != Variable::CONST || op == Token::INIT_CONST) { |
| 1511 | // Perform the assignment for non-const variables and for initialization |
| 1512 | // of const variables. Const assignments are simply skipped. |
| 1513 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1514 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1515 | switch (slot->type()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1516 | case Slot::PARAMETER: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1517 | case Slot::LOCAL: |
| 1518 | if (op == Token::INIT_CONST) { |
| 1519 | // Detect const reinitialization by checking for the hole value. |
| 1520 | __ ldr(r1, MemOperand(fp, SlotOffset(slot))); |
| 1521 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1522 | __ cmp(r1, ip); |
| 1523 | __ b(ne, &done); |
| 1524 | } |
| 1525 | // Perform the assignment. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1526 | __ str(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 1527 | break; |
| 1528 | |
| 1529 | case Slot::CONTEXT: { |
| 1530 | MemOperand target = EmitSlotSearch(slot, r1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1531 | if (op == Token::INIT_CONST) { |
| 1532 | // Detect const reinitialization by checking for the hole value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1533 | __ ldr(r2, target); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1534 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1535 | __ cmp(r2, ip); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1536 | __ b(ne, &done); |
| 1537 | } |
| 1538 | // Perform the assignment and issue the write barrier. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1539 | __ str(result_register(), target); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1540 | // RecordWrite may destroy all its register arguments. |
| 1541 | __ mov(r3, result_register()); |
| 1542 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1543 | __ RecordWrite(r1, Operand(offset), r2, r3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1544 | break; |
| 1545 | } |
| 1546 | |
| 1547 | case Slot::LOOKUP: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1548 | // Call the runtime for the assignment. The runtime will ignore |
| 1549 | // const reinitialization. |
| 1550 | __ push(r0); // Value. |
| 1551 | __ mov(r0, Operand(slot->var()->name())); |
| 1552 | __ Push(cp, r0); // Context and name. |
| 1553 | if (op == Token::INIT_CONST) { |
| 1554 | // The runtime will ignore const redeclaration. |
| 1555 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 1556 | } else { |
| 1557 | __ CallRuntime(Runtime::kStoreContextSlot, 3); |
| 1558 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1559 | break; |
| 1560 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1561 | __ bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1562 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1563 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1564 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 1569 | // Assignment to a property, using a named store IC. |
| 1570 | Property* prop = expr->target()->AsProperty(); |
| 1571 | ASSERT(prop != NULL); |
| 1572 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 1573 | |
| 1574 | // If the assignment starts a block of assignments to the same object, |
| 1575 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1576 | // adding fast properties. |
| 1577 | if (expr->starts_initialization_block()) { |
| 1578 | __ push(result_register()); |
| 1579 | __ ldr(ip, MemOperand(sp, kPointerSize)); // Receiver is now under value. |
| 1580 | __ push(ip); |
| 1581 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1582 | __ pop(result_register()); |
| 1583 | } |
| 1584 | |
| 1585 | // Record source code position before IC call. |
| 1586 | SetSourcePosition(expr->position()); |
| 1587 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1588 | // Load receiver to r1. Leave a copy in the stack if needed for turning the |
| 1589 | // receiver into fast case. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1590 | if (expr->ends_initialization_block()) { |
| 1591 | __ ldr(r1, MemOperand(sp)); |
| 1592 | } else { |
| 1593 | __ pop(r1); |
| 1594 | } |
| 1595 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1596 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1597 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1598 | |
| 1599 | // If the assignment ends an initialization block, revert to fast case. |
| 1600 | if (expr->ends_initialization_block()) { |
| 1601 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1602 | // Receiver is under the result value. |
| 1603 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1604 | __ push(ip); |
| 1605 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1606 | __ pop(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1607 | context()->DropAndPlug(1, r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1608 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1609 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1610 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | |
| 1614 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 1615 | // Assignment to a property, using a keyed store IC. |
| 1616 | |
| 1617 | // If the assignment starts a block of assignments to the same object, |
| 1618 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1619 | // adding fast properties. |
| 1620 | if (expr->starts_initialization_block()) { |
| 1621 | __ push(result_register()); |
| 1622 | // Receiver is now under the key and value. |
| 1623 | __ ldr(ip, MemOperand(sp, 2 * kPointerSize)); |
| 1624 | __ push(ip); |
| 1625 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1626 | __ pop(result_register()); |
| 1627 | } |
| 1628 | |
| 1629 | // Record source code position before IC call. |
| 1630 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1631 | __ pop(r1); // Key. |
| 1632 | // Load receiver to r2. Leave a copy in the stack if needed for turning the |
| 1633 | // receiver into fast case. |
| 1634 | if (expr->ends_initialization_block()) { |
| 1635 | __ ldr(r2, MemOperand(sp)); |
| 1636 | } else { |
| 1637 | __ pop(r2); |
| 1638 | } |
| 1639 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1640 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1641 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1642 | |
| 1643 | // If the assignment ends an initialization block, revert to fast case. |
| 1644 | if (expr->ends_initialization_block()) { |
| 1645 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1646 | // Receiver is under the result value. |
| 1647 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1648 | __ push(ip); |
| 1649 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1650 | __ pop(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1651 | context()->DropAndPlug(1, r0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1652 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1653 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1654 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | |
| 1658 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 1659 | Comment cmnt(masm_, "[ Property"); |
| 1660 | Expression* key = expr->key(); |
| 1661 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1662 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1663 | VisitForAccumulatorValue(expr->obj()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1664 | EmitNamedPropertyLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1665 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1666 | VisitForStackValue(expr->obj()); |
| 1667 | VisitForAccumulatorValue(expr->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1668 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1669 | EmitKeyedPropertyLoad(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1670 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1671 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1675 | Handle<Object> name, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1676 | RelocInfo::Mode mode) { |
| 1677 | // Code common for calls using the IC. |
| 1678 | ZoneList<Expression*>* args = expr->arguments(); |
| 1679 | int arg_count = args->length(); |
| 1680 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1681 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1682 | } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1683 | __ mov(r2, Operand(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1684 | // Record source position for debugger. |
| 1685 | SetSourcePosition(expr->position()); |
| 1686 | // Call the IC initialization code. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1687 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1688 | Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count, in_loop); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1689 | EmitCallIC(ic, mode); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1690 | // Restore context register. |
| 1691 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1692 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1696 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
| 1697 | Expression* key, |
| 1698 | RelocInfo::Mode mode) { |
| 1699 | // Code common for calls using the IC. |
| 1700 | ZoneList<Expression*>* args = expr->arguments(); |
| 1701 | int arg_count = args->length(); |
| 1702 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1703 | VisitForStackValue(args->at(i)); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1704 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1705 | VisitForAccumulatorValue(key); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1706 | __ mov(r2, r0); |
| 1707 | // Record source position for debugger. |
| 1708 | SetSourcePosition(expr->position()); |
| 1709 | // Call the IC initialization code. |
| 1710 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1711 | Handle<Code> ic = CodeGenerator::ComputeKeyedCallInitialize(arg_count, |
| 1712 | in_loop); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1713 | EmitCallIC(ic, mode); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1714 | // Restore context register. |
| 1715 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1716 | context()->Plug(r0); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1720 | void FullCodeGenerator::EmitCallWithStub(Call* expr) { |
| 1721 | // Code common for calls using the call stub. |
| 1722 | ZoneList<Expression*>* args = expr->arguments(); |
| 1723 | int arg_count = args->length(); |
| 1724 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1725 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1726 | } |
| 1727 | // Record source position for debugger. |
| 1728 | SetSourcePosition(expr->position()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1729 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1730 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1731 | __ CallStub(&stub); |
| 1732 | // Restore context register. |
| 1733 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1734 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | void FullCodeGenerator::VisitCall(Call* expr) { |
| 1739 | Comment cmnt(masm_, "[ Call"); |
| 1740 | Expression* fun = expr->expression(); |
| 1741 | Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 1742 | |
| 1743 | if (var != NULL && var->is_possibly_eval()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1744 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 1745 | // resolve the function we need to call and the receiver of the |
| 1746 | // call. Then we call the resolved function using the given |
| 1747 | // arguments. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1748 | VisitForStackValue(fun); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1749 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1750 | __ push(r2); // Reserved receiver slot. |
| 1751 | |
| 1752 | // Push the arguments. |
| 1753 | ZoneList<Expression*>* args = expr->arguments(); |
| 1754 | int arg_count = args->length(); |
| 1755 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1756 | VisitForStackValue(args->at(i)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1757 | } |
| 1758 | |
| 1759 | // Push copy of the function - found below the arguments. |
| 1760 | __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
| 1761 | __ push(r1); |
| 1762 | |
| 1763 | // Push copy of the first argument or undefined if it doesn't exist. |
| 1764 | if (arg_count > 0) { |
| 1765 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 1766 | __ push(r1); |
| 1767 | } else { |
| 1768 | __ push(r2); |
| 1769 | } |
| 1770 | |
| 1771 | // Push the receiver of the enclosing function and do runtime call. |
| 1772 | __ ldr(r1, MemOperand(fp, (2 + scope()->num_parameters()) * kPointerSize)); |
| 1773 | __ push(r1); |
| 1774 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
| 1775 | |
| 1776 | // The runtime call returns a pair of values in r0 (function) and |
| 1777 | // r1 (receiver). Touch up the stack with the right values. |
| 1778 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
| 1779 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 1780 | |
| 1781 | // Record source position for debugger. |
| 1782 | SetSourcePosition(expr->position()); |
| 1783 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1784 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
| 1785 | __ CallStub(&stub); |
| 1786 | // Restore context register. |
| 1787 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1788 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1789 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1790 | // Push global object as receiver for the call IC. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1791 | __ ldr(r0, CodeGenerator::GlobalObject()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1792 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1793 | EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1794 | } else if (var != NULL && var->AsSlot() != NULL && |
| 1795 | var->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1796 | // Call to a lookup slot (dynamically introduced variable). |
| 1797 | Label slow, done; |
| 1798 | |
| 1799 | // Generate code for loading from variables potentially shadowed |
| 1800 | // by eval-introduced variables. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1801 | EmitDynamicLoadFromSlotFastCase(var->AsSlot(), |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1802 | NOT_INSIDE_TYPEOF, |
| 1803 | &slow, |
| 1804 | &done); |
| 1805 | |
| 1806 | __ bind(&slow); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1807 | // 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] | 1808 | // and the object holding it (returned in edx). |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1809 | __ push(context_register()); |
| 1810 | __ mov(r2, Operand(var->name())); |
| 1811 | __ push(r2); |
| 1812 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1813 | __ Push(r0, r1); // Function, receiver. |
| 1814 | |
| 1815 | // If fast case code has been generated, emit code to push the |
| 1816 | // function and receiver and have the slow path jump around this |
| 1817 | // code. |
| 1818 | if (done.is_linked()) { |
| 1819 | Label call; |
| 1820 | __ b(&call); |
| 1821 | __ bind(&done); |
| 1822 | // Push function. |
| 1823 | __ push(r0); |
| 1824 | // Push global receiver. |
| 1825 | __ ldr(r1, CodeGenerator::GlobalObject()); |
| 1826 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 1827 | __ push(r1); |
| 1828 | __ bind(&call); |
| 1829 | } |
| 1830 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1831 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1832 | } else if (fun->AsProperty() != NULL) { |
| 1833 | // Call to an object property. |
| 1834 | Property* prop = fun->AsProperty(); |
| 1835 | Literal* key = prop->key()->AsLiteral(); |
| 1836 | if (key != NULL && key->handle()->IsSymbol()) { |
| 1837 | // Call to a named property, use call IC. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1838 | VisitForStackValue(prop->obj()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1839 | EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); |
| 1840 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1841 | // Call to a keyed property. |
| 1842 | // For a synthetic property use keyed load IC followed by function call, |
| 1843 | // for a regular property use keyed CallIC. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1844 | VisitForStackValue(prop->obj()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1845 | if (prop->is_synthetic()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1846 | VisitForAccumulatorValue(prop->key()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1847 | // Record source code position for IC call. |
| 1848 | SetSourcePosition(prop->position()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1849 | __ pop(r1); // We do not need to keep the receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1850 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1851 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1852 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1853 | __ ldr(r1, CodeGenerator::GlobalObject()); |
| 1854 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1855 | __ Push(r0, r1); // Function, receiver. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1856 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1857 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1858 | EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1859 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1860 | } |
| 1861 | } else { |
| 1862 | // Call to some other expression. If the expression is an anonymous |
| 1863 | // function literal not called in a loop, mark it as one that should |
| 1864 | // also use the fast code generator. |
| 1865 | FunctionLiteral* lit = fun->AsFunctionLiteral(); |
| 1866 | if (lit != NULL && |
| 1867 | lit->name()->Equals(Heap::empty_string()) && |
| 1868 | loop_depth() == 0) { |
| 1869 | lit->set_try_full_codegen(true); |
| 1870 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1871 | VisitForStackValue(fun); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1872 | // Load global receiver object. |
| 1873 | __ ldr(r1, CodeGenerator::GlobalObject()); |
| 1874 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 1875 | __ push(r1); |
| 1876 | // Emit function call. |
| 1877 | EmitCallWithStub(expr); |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | |
| 1882 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 1883 | Comment cmnt(masm_, "[ CallNew"); |
| 1884 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 1885 | // expression in new calls must be evaluated before the |
| 1886 | // arguments. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1887 | |
| 1888 | // Push constructor on the stack. If it's not a function it's used as |
| 1889 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 1890 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1891 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1892 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1893 | // Push the arguments ("left-to-right") on the stack. |
| 1894 | ZoneList<Expression*>* args = expr->arguments(); |
| 1895 | int arg_count = args->length(); |
| 1896 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1897 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1898 | } |
| 1899 | |
| 1900 | // Call the construct call builtin that handles allocation and |
| 1901 | // constructor invocation. |
| 1902 | SetSourcePosition(expr->position()); |
| 1903 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1904 | // Load function and argument count into r1 and r0. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1905 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1906 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1907 | |
| 1908 | Handle<Code> construct_builtin(Builtins::builtin(Builtins::JSConstructCall)); |
| 1909 | __ Call(construct_builtin, RelocInfo::CONSTRUCT_CALL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1910 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1914 | void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) { |
| 1915 | ASSERT(args->length() == 1); |
| 1916 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1917 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1918 | |
| 1919 | Label materialize_true, materialize_false; |
| 1920 | Label* if_true = NULL; |
| 1921 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1922 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1923 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 1924 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1925 | |
| 1926 | __ BranchOnSmi(r0, if_true); |
| 1927 | __ b(if_false); |
| 1928 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1929 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | |
| 1933 | void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) { |
| 1934 | ASSERT(args->length() == 1); |
| 1935 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1936 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1937 | |
| 1938 | Label materialize_true, materialize_false; |
| 1939 | Label* if_true = NULL; |
| 1940 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1941 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1942 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 1943 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1944 | |
| 1945 | __ tst(r0, Operand(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1946 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1947 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1948 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | |
| 1952 | void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) { |
| 1953 | ASSERT(args->length() == 1); |
| 1954 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1955 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1956 | |
| 1957 | Label materialize_true, materialize_false; |
| 1958 | Label* if_true = NULL; |
| 1959 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1960 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1961 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 1962 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1963 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1964 | __ BranchOnSmi(r0, if_false); |
| 1965 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 1966 | __ cmp(r0, ip); |
| 1967 | __ b(eq, if_true); |
| 1968 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 1969 | // Undetectable objects behave like undefined when tested with typeof. |
| 1970 | __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 1971 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
| 1972 | __ b(ne, if_false); |
| 1973 | __ ldrb(r1, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 1974 | __ cmp(r1, Operand(FIRST_JS_OBJECT_TYPE)); |
| 1975 | __ b(lt, if_false); |
| 1976 | __ cmp(r1, Operand(LAST_JS_OBJECT_TYPE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1977 | Split(le, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1978 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1979 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1983 | void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) { |
| 1984 | ASSERT(args->length() == 1); |
| 1985 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1986 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1987 | |
| 1988 | Label materialize_true, materialize_false; |
| 1989 | Label* if_true = NULL; |
| 1990 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1991 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1992 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 1993 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1994 | |
| 1995 | __ BranchOnSmi(r0, if_false); |
| 1996 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1997 | Split(ge, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 1998 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1999 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2003 | void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) { |
| 2004 | ASSERT(args->length() == 1); |
| 2005 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2006 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2007 | |
| 2008 | Label materialize_true, materialize_false; |
| 2009 | Label* if_true = NULL; |
| 2010 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2011 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2012 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2013 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2014 | |
| 2015 | __ BranchOnSmi(r0, if_false); |
| 2016 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2017 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 2018 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2019 | Split(ne, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2020 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2021 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2025 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
| 2026 | ZoneList<Expression*>* args) { |
| 2027 | |
| 2028 | ASSERT(args->length() == 1); |
| 2029 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2030 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2031 | |
| 2032 | Label materialize_true, materialize_false; |
| 2033 | Label* if_true = NULL; |
| 2034 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2035 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2036 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2037 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2038 | |
| 2039 | // Just indicate false, as %_IsStringWrapperSafeForDefaultValueOf() is only |
| 2040 | // used in a few functions in runtime.js which should not normally be hit by |
| 2041 | // this compiler. |
| 2042 | __ jmp(if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2043 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2047 | void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) { |
| 2048 | ASSERT(args->length() == 1); |
| 2049 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2050 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2051 | |
| 2052 | Label materialize_true, materialize_false; |
| 2053 | Label* if_true = NULL; |
| 2054 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2055 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2056 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2057 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2058 | |
| 2059 | __ BranchOnSmi(r0, if_false); |
| 2060 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2061 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2062 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2063 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
| 2067 | void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) { |
| 2068 | ASSERT(args->length() == 1); |
| 2069 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2070 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2071 | |
| 2072 | Label materialize_true, materialize_false; |
| 2073 | Label* if_true = NULL; |
| 2074 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2075 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2076 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2077 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2078 | |
| 2079 | __ BranchOnSmi(r0, if_false); |
| 2080 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2081 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2082 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2083 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | |
| 2087 | void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) { |
| 2088 | ASSERT(args->length() == 1); |
| 2089 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2090 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2091 | |
| 2092 | Label materialize_true, materialize_false; |
| 2093 | Label* if_true = NULL; |
| 2094 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2095 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2096 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2097 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2098 | |
| 2099 | __ BranchOnSmi(r0, if_false); |
| 2100 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2101 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2102 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2103 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | |
| 2108 | void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) { |
| 2109 | ASSERT(args->length() == 0); |
| 2110 | |
| 2111 | Label materialize_true, materialize_false; |
| 2112 | Label* if_true = NULL; |
| 2113 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2114 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2115 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2116 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2117 | |
| 2118 | // Get the frame pointer for the calling frame. |
| 2119 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2120 | |
| 2121 | // Skip the arguments adaptor frame if it exists. |
| 2122 | Label check_frame_marker; |
| 2123 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2124 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2125 | __ b(ne, &check_frame_marker); |
| 2126 | __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset)); |
| 2127 | |
| 2128 | // Check the marker in the calling frame. |
| 2129 | __ bind(&check_frame_marker); |
| 2130 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset)); |
| 2131 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2132 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2133 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2134 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) { |
| 2139 | ASSERT(args->length() == 2); |
| 2140 | |
| 2141 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2142 | VisitForStackValue(args->at(0)); |
| 2143 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2144 | |
| 2145 | Label materialize_true, materialize_false; |
| 2146 | Label* if_true = NULL; |
| 2147 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2148 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2149 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2150 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2151 | |
| 2152 | __ pop(r1); |
| 2153 | __ cmp(r0, r1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2154 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2155 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2156 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) { |
| 2161 | ASSERT(args->length() == 1); |
| 2162 | |
| 2163 | // ArgumentsAccessStub expects the key in edx and the formal |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2164 | // parameter count in r0. |
| 2165 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2166 | __ mov(r1, r0); |
| 2167 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2168 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 2169 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2170 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2171 | } |
| 2172 | |
| 2173 | |
| 2174 | void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) { |
| 2175 | ASSERT(args->length() == 0); |
| 2176 | |
| 2177 | Label exit; |
| 2178 | // Get the number of formal parameters. |
| 2179 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2180 | |
| 2181 | // Check if the calling frame is an arguments adaptor frame. |
| 2182 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2183 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2184 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2185 | __ b(ne, &exit); |
| 2186 | |
| 2187 | // Arguments adaptor case: Read the arguments length from the |
| 2188 | // adaptor frame. |
| 2189 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2190 | |
| 2191 | __ bind(&exit); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2192 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | |
| 2196 | void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) { |
| 2197 | ASSERT(args->length() == 1); |
| 2198 | Label done, null, function, non_function_constructor; |
| 2199 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2200 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2201 | |
| 2202 | // If the object is a smi, we return null. |
| 2203 | __ BranchOnSmi(r0, &null); |
| 2204 | |
| 2205 | // Check that the object is a JS object but take special care of JS |
| 2206 | // functions to make sure they have 'Function' as their class. |
| 2207 | __ CompareObjectType(r0, r0, r1, FIRST_JS_OBJECT_TYPE); // Map is now in r0. |
| 2208 | __ b(lt, &null); |
| 2209 | |
| 2210 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 2211 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 2212 | // LAST_JS_OBJECT_TYPE. |
| 2213 | ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 2214 | ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
| 2215 | __ cmp(r1, Operand(JS_FUNCTION_TYPE)); |
| 2216 | __ b(eq, &function); |
| 2217 | |
| 2218 | // Check if the constructor in the map is a function. |
| 2219 | __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset)); |
| 2220 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
| 2221 | __ b(ne, &non_function_constructor); |
| 2222 | |
| 2223 | // r0 now contains the constructor function. Grab the |
| 2224 | // instance class name from there. |
| 2225 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 2226 | __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2227 | __ b(&done); |
| 2228 | |
| 2229 | // Functions have class 'Function'. |
| 2230 | __ bind(&function); |
| 2231 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2232 | __ jmp(&done); |
| 2233 | |
| 2234 | // Objects with a non-function constructor have class 'Object'. |
| 2235 | __ bind(&non_function_constructor); |
| 2236 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2237 | __ jmp(&done); |
| 2238 | |
| 2239 | // Non-JS objects have class null. |
| 2240 | __ bind(&null); |
| 2241 | __ LoadRoot(r0, Heap::kNullValueRootIndex); |
| 2242 | |
| 2243 | // All done. |
| 2244 | __ bind(&done); |
| 2245 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2246 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) { |
| 2251 | // Conditionally generate a log call. |
| 2252 | // Args: |
| 2253 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 2254 | // This is used to determine whether or not to generate the log call. |
| 2255 | // 1 (string): Format string. Access the string at argument index 2 |
| 2256 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 2257 | // 2 (array): Arguments to the format string. |
| 2258 | ASSERT_EQ(args->length(), 3); |
| 2259 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 2260 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2261 | VisitForStackValue(args->at(1)); |
| 2262 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2263 | __ CallRuntime(Runtime::kLog, 2); |
| 2264 | } |
| 2265 | #endif |
| 2266 | // Finally, we're expected to leave a value on the top of the stack. |
| 2267 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2268 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | |
| 2272 | void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) { |
| 2273 | ASSERT(args->length() == 0); |
| 2274 | |
| 2275 | Label slow_allocate_heapnumber; |
| 2276 | Label heapnumber_allocated; |
| 2277 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2278 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 2279 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2280 | __ jmp(&heapnumber_allocated); |
| 2281 | |
| 2282 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2283 | // Allocate a heap number. |
| 2284 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2285 | __ mov(r4, Operand(r0)); |
| 2286 | |
| 2287 | __ bind(&heapnumber_allocated); |
| 2288 | |
| 2289 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 2290 | // by computing: |
| 2291 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 2292 | if (CpuFeatures::IsSupported(VFP3)) { |
| 2293 | __ PrepareCallCFunction(0, r1); |
| 2294 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 2295 | |
| 2296 | CpuFeatures::Scope scope(VFP3); |
| 2297 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 2298 | // Create this constant using mov/orr to avoid PC relative load. |
| 2299 | __ mov(r1, Operand(0x41000000)); |
| 2300 | __ orr(r1, r1, Operand(0x300000)); |
| 2301 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 2302 | __ vmov(d7, r0, r1); |
| 2303 | // Move 0x4130000000000000 to VFP. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2304 | __ mov(r0, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2305 | __ vmov(d8, r0, r1); |
| 2306 | // Subtract and store the result in the heap number. |
| 2307 | __ vsub(d7, d7, d8); |
| 2308 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 2309 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 2310 | __ mov(r0, r4); |
| 2311 | } else { |
| 2312 | __ mov(r0, Operand(r4)); |
| 2313 | __ PrepareCallCFunction(1, r1); |
| 2314 | __ CallCFunction( |
| 2315 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 2316 | } |
| 2317 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2318 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2319 | } |
| 2320 | |
| 2321 | |
| 2322 | void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) { |
| 2323 | // Load the arguments on the stack and call the stub. |
| 2324 | SubStringStub stub; |
| 2325 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2326 | VisitForStackValue(args->at(0)); |
| 2327 | VisitForStackValue(args->at(1)); |
| 2328 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2329 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2330 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) { |
| 2335 | // Load the arguments on the stack and call the stub. |
| 2336 | RegExpExecStub stub; |
| 2337 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2338 | VisitForStackValue(args->at(0)); |
| 2339 | VisitForStackValue(args->at(1)); |
| 2340 | VisitForStackValue(args->at(2)); |
| 2341 | VisitForStackValue(args->at(3)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2342 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2343 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | |
| 2347 | void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) { |
| 2348 | ASSERT(args->length() == 1); |
| 2349 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2350 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2351 | |
| 2352 | Label done; |
| 2353 | // If the object is a smi return the object. |
| 2354 | __ BranchOnSmi(r0, &done); |
| 2355 | // If the object is not a value type, return the object. |
| 2356 | __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE); |
| 2357 | __ b(ne, &done); |
| 2358 | __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset)); |
| 2359 | |
| 2360 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2361 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | |
| 2365 | void FullCodeGenerator::EmitMathPow(ZoneList<Expression*>* args) { |
| 2366 | // Load the arguments on the stack and call the runtime function. |
| 2367 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2368 | VisitForStackValue(args->at(0)); |
| 2369 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2370 | __ CallRuntime(Runtime::kMath_pow, 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2371 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2372 | } |
| 2373 | |
| 2374 | |
| 2375 | void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) { |
| 2376 | ASSERT(args->length() == 2); |
| 2377 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2378 | VisitForStackValue(args->at(0)); // Load the object. |
| 2379 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2380 | __ pop(r1); // r0 = value. r1 = object. |
| 2381 | |
| 2382 | Label done; |
| 2383 | // If the object is a smi, return the value. |
| 2384 | __ BranchOnSmi(r1, &done); |
| 2385 | |
| 2386 | // If the object is not a value type, return the value. |
| 2387 | __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE); |
| 2388 | __ b(ne, &done); |
| 2389 | |
| 2390 | // Store the value. |
| 2391 | __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); |
| 2392 | // Update the write barrier. Save the value as it will be |
| 2393 | // overwritten by the write barrier code and is needed afterward. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2394 | __ RecordWrite(r1, Operand(JSValue::kValueOffset - kHeapObjectTag), r2, r3); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2395 | |
| 2396 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2397 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | |
| 2401 | void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) { |
| 2402 | ASSERT_EQ(args->length(), 1); |
| 2403 | |
| 2404 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2405 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2406 | |
| 2407 | NumberToStringStub stub; |
| 2408 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2409 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2413 | void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2414 | ASSERT(args->length() == 1); |
| 2415 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2416 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2417 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2418 | Label done; |
| 2419 | StringCharFromCodeGenerator generator(r0, r1); |
| 2420 | generator.GenerateFast(masm_); |
| 2421 | __ jmp(&done); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2422 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2423 | NopRuntimeCallHelper call_helper; |
| 2424 | generator.GenerateSlow(masm_, call_helper); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2425 | |
| 2426 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2427 | context()->Plug(r1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2431 | void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) { |
| 2432 | ASSERT(args->length() == 2); |
| 2433 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2434 | VisitForStackValue(args->at(0)); |
| 2435 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2436 | |
| 2437 | Register object = r1; |
| 2438 | Register index = r0; |
| 2439 | Register scratch = r2; |
| 2440 | Register result = r3; |
| 2441 | |
| 2442 | __ pop(object); |
| 2443 | |
| 2444 | Label need_conversion; |
| 2445 | Label index_out_of_range; |
| 2446 | Label done; |
| 2447 | StringCharCodeAtGenerator generator(object, |
| 2448 | index, |
| 2449 | scratch, |
| 2450 | result, |
| 2451 | &need_conversion, |
| 2452 | &need_conversion, |
| 2453 | &index_out_of_range, |
| 2454 | STRING_INDEX_IS_NUMBER); |
| 2455 | generator.GenerateFast(masm_); |
| 2456 | __ jmp(&done); |
| 2457 | |
| 2458 | __ bind(&index_out_of_range); |
| 2459 | // When the index is out of range, the spec requires us to return |
| 2460 | // NaN. |
| 2461 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 2462 | __ jmp(&done); |
| 2463 | |
| 2464 | __ bind(&need_conversion); |
| 2465 | // Load the undefined value into the result register, which will |
| 2466 | // trigger conversion. |
| 2467 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2468 | __ jmp(&done); |
| 2469 | |
| 2470 | NopRuntimeCallHelper call_helper; |
| 2471 | generator.GenerateSlow(masm_, call_helper); |
| 2472 | |
| 2473 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2474 | context()->Plug(result); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2477 | |
| 2478 | void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) { |
| 2479 | ASSERT(args->length() == 2); |
| 2480 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2481 | VisitForStackValue(args->at(0)); |
| 2482 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2483 | |
| 2484 | Register object = r1; |
| 2485 | Register index = r0; |
| 2486 | Register scratch1 = r2; |
| 2487 | Register scratch2 = r3; |
| 2488 | Register result = r0; |
| 2489 | |
| 2490 | __ pop(object); |
| 2491 | |
| 2492 | Label need_conversion; |
| 2493 | Label index_out_of_range; |
| 2494 | Label done; |
| 2495 | StringCharAtGenerator generator(object, |
| 2496 | index, |
| 2497 | scratch1, |
| 2498 | scratch2, |
| 2499 | result, |
| 2500 | &need_conversion, |
| 2501 | &need_conversion, |
| 2502 | &index_out_of_range, |
| 2503 | STRING_INDEX_IS_NUMBER); |
| 2504 | generator.GenerateFast(masm_); |
| 2505 | __ jmp(&done); |
| 2506 | |
| 2507 | __ bind(&index_out_of_range); |
| 2508 | // When the index is out of range, the spec requires us to return |
| 2509 | // the empty string. |
| 2510 | __ LoadRoot(result, Heap::kEmptyStringRootIndex); |
| 2511 | __ jmp(&done); |
| 2512 | |
| 2513 | __ bind(&need_conversion); |
| 2514 | // Move smi zero into the result register, which will trigger |
| 2515 | // conversion. |
| 2516 | __ mov(result, Operand(Smi::FromInt(0))); |
| 2517 | __ jmp(&done); |
| 2518 | |
| 2519 | NopRuntimeCallHelper call_helper; |
| 2520 | generator.GenerateSlow(masm_, call_helper); |
| 2521 | |
| 2522 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2523 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2524 | } |
| 2525 | |
| 2526 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2527 | void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) { |
| 2528 | ASSERT_EQ(2, args->length()); |
| 2529 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2530 | VisitForStackValue(args->at(0)); |
| 2531 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2532 | |
| 2533 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 2534 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2535 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | |
| 2539 | void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) { |
| 2540 | ASSERT_EQ(2, args->length()); |
| 2541 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2542 | VisitForStackValue(args->at(0)); |
| 2543 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2544 | |
| 2545 | StringCompareStub stub; |
| 2546 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2547 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | |
| 2551 | void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) { |
| 2552 | // Load the argument on the stack and call the runtime. |
| 2553 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2554 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2555 | __ CallRuntime(Runtime::kMath_sin, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2556 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | |
| 2560 | void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) { |
| 2561 | // Load the argument on the stack and call the runtime. |
| 2562 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2563 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2564 | __ CallRuntime(Runtime::kMath_cos, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2565 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | |
| 2569 | void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) { |
| 2570 | // Load the argument on the stack and call the runtime function. |
| 2571 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2572 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2573 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2574 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2575 | } |
| 2576 | |
| 2577 | |
| 2578 | void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) { |
| 2579 | ASSERT(args->length() >= 2); |
| 2580 | |
| 2581 | int arg_count = args->length() - 2; // For receiver and function. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2582 | VisitForStackValue(args->at(0)); // Receiver. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2583 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2584 | VisitForStackValue(args->at(i + 1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2585 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2586 | VisitForAccumulatorValue(args->at(arg_count + 1)); // Function. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2587 | |
| 2588 | // InvokeFunction requires function in r1. Move it in there. |
| 2589 | if (!result_register().is(r1)) __ mov(r1, result_register()); |
| 2590 | ParameterCount count(arg_count); |
| 2591 | __ InvokeFunction(r1, count, CALL_FUNCTION); |
| 2592 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2593 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
| 2596 | |
| 2597 | void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) { |
| 2598 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2599 | VisitForStackValue(args->at(0)); |
| 2600 | VisitForStackValue(args->at(1)); |
| 2601 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2602 | __ CallRuntime(Runtime::kRegExpConstructResult, 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2603 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | |
| 2607 | void FullCodeGenerator::EmitSwapElements(ZoneList<Expression*>* args) { |
| 2608 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2609 | VisitForStackValue(args->at(0)); |
| 2610 | VisitForStackValue(args->at(1)); |
| 2611 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2612 | __ CallRuntime(Runtime::kSwapElements, 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2613 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | |
| 2617 | void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) { |
| 2618 | ASSERT_EQ(2, args->length()); |
| 2619 | |
| 2620 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 2621 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 2622 | |
| 2623 | Handle<FixedArray> jsfunction_result_caches( |
| 2624 | Top::global_context()->jsfunction_result_caches()); |
| 2625 | if (jsfunction_result_caches->length() <= cache_id) { |
| 2626 | __ Abort("Attempt to use undefined cache."); |
| 2627 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2628 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2629 | return; |
| 2630 | } |
| 2631 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2632 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2633 | |
| 2634 | Register key = r0; |
| 2635 | Register cache = r1; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2636 | __ ldr(cache, ContextOperand(cp, Context::GLOBAL_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2637 | __ ldr(cache, FieldMemOperand(cache, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2638 | __ ldr(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2639 | __ ldr(cache, |
| 2640 | FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 2641 | |
| 2642 | |
| 2643 | Label done, not_found; |
| 2644 | // tmp now holds finger offset as a smi. |
| 2645 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 2646 | __ ldr(r2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 2647 | // r2 now holds finger offset as a smi. |
| 2648 | __ add(r3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2649 | // r3 now points to the start of fixed array elements. |
| 2650 | __ ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 2651 | // Note side effect of PreIndex: r3 now points to the key of the pair. |
| 2652 | __ cmp(key, r2); |
| 2653 | __ b(ne, ¬_found); |
| 2654 | |
| 2655 | __ ldr(r0, MemOperand(r3, kPointerSize)); |
| 2656 | __ b(&done); |
| 2657 | |
| 2658 | __ bind(¬_found); |
| 2659 | // Call runtime to perform the lookup. |
| 2660 | __ Push(cache, key); |
| 2661 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 2662 | |
| 2663 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2664 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2668 | void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 2669 | ASSERT_EQ(2, args->length()); |
| 2670 | |
| 2671 | Register right = r0; |
| 2672 | Register left = r1; |
| 2673 | Register tmp = r2; |
| 2674 | Register tmp2 = r3; |
| 2675 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2676 | VisitForStackValue(args->at(0)); |
| 2677 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2678 | __ pop(left); |
| 2679 | |
| 2680 | Label done, fail, ok; |
| 2681 | __ cmp(left, Operand(right)); |
| 2682 | __ b(eq, &ok); |
| 2683 | // Fail if either is a non-HeapObject. |
| 2684 | __ and_(tmp, left, Operand(right)); |
| 2685 | __ tst(tmp, Operand(kSmiTagMask)); |
| 2686 | __ b(eq, &fail); |
| 2687 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 2688 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 2689 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 2690 | __ b(ne, &fail); |
| 2691 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 2692 | __ cmp(tmp, Operand(tmp2)); |
| 2693 | __ b(ne, &fail); |
| 2694 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 2695 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 2696 | __ cmp(tmp, tmp2); |
| 2697 | __ b(eq, &ok); |
| 2698 | __ bind(&fail); |
| 2699 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 2700 | __ jmp(&done); |
| 2701 | __ bind(&ok); |
| 2702 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 2703 | __ bind(&done); |
| 2704 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2705 | context()->Plug(r0); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2709 | void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2710 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2711 | |
| 2712 | Label materialize_true, materialize_false; |
| 2713 | Label* if_true = NULL; |
| 2714 | Label* if_false = NULL; |
| 2715 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2716 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2717 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2718 | |
| 2719 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2720 | __ tst(r0, Operand(String::kContainsCachedArrayIndexMask)); |
| 2721 | |
| 2722 | __ b(eq, if_true); |
| 2723 | __ b(if_false); |
| 2724 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2725 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | |
| 2729 | void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 2730 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2731 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2732 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2733 | __ IndexFromHash(r0, r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2734 | context()->Plug(r0); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2738 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2739 | Handle<String> name = expr->name(); |
| 2740 | if (name->length() > 0 && name->Get(0) == '_') { |
| 2741 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 2742 | EmitInlineRuntimeCall(expr); |
| 2743 | return; |
| 2744 | } |
| 2745 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2746 | Comment cmnt(masm_, "[ CallRuntime"); |
| 2747 | ZoneList<Expression*>* args = expr->arguments(); |
| 2748 | |
| 2749 | if (expr->is_jsruntime()) { |
| 2750 | // Prepare for calling JS runtime function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2751 | __ ldr(r0, CodeGenerator::GlobalObject()); |
| 2752 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2753 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | // Push the arguments ("left-to-right"). |
| 2757 | int arg_count = args->length(); |
| 2758 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2759 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | if (expr->is_jsruntime()) { |
| 2763 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2764 | __ mov(r2, Operand(expr->name())); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2765 | Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count, |
| 2766 | NOT_IN_LOOP); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2767 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2768 | // Restore context register. |
| 2769 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2770 | } else { |
| 2771 | // Call the C runtime function. |
| 2772 | __ CallRuntime(expr->function(), arg_count); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2773 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2774 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2775 | } |
| 2776 | |
| 2777 | |
| 2778 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 2779 | switch (expr->op()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2780 | case Token::DELETE: { |
| 2781 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
| 2782 | Property* prop = expr->expression()->AsProperty(); |
| 2783 | Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); |
| 2784 | if (prop == NULL && var == NULL) { |
| 2785 | // Result of deleting non-property, non-variable reference is true. |
| 2786 | // The subexpression may have side effects. |
| 2787 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2788 | context()->Plug(true); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2789 | } else if (var != NULL && |
| 2790 | !var->is_global() && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2791 | var->AsSlot() != NULL && |
| 2792 | var->AsSlot()->type() != Slot::LOOKUP) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2793 | // Result of deleting non-global, non-dynamic variables is false. |
| 2794 | // The subexpression does not have side effects. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2795 | context()->Plug(false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2796 | } else { |
| 2797 | // Property or variable reference. Call the delete builtin with |
| 2798 | // object and property name as arguments. |
| 2799 | if (prop != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2800 | VisitForStackValue(prop->obj()); |
| 2801 | VisitForStackValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2802 | } else if (var->is_global()) { |
| 2803 | __ ldr(r1, CodeGenerator::GlobalObject()); |
| 2804 | __ mov(r0, Operand(var->name())); |
| 2805 | __ Push(r1, r0); |
| 2806 | } else { |
| 2807 | // Non-global variable. Call the runtime to look up the context |
| 2808 | // where the variable was introduced. |
| 2809 | __ push(context_register()); |
| 2810 | __ mov(r2, Operand(var->name())); |
| 2811 | __ push(r2); |
| 2812 | __ CallRuntime(Runtime::kLookupContext, 2); |
| 2813 | __ push(r0); |
| 2814 | __ mov(r2, Operand(var->name())); |
| 2815 | __ push(r2); |
| 2816 | } |
| 2817 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2818 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2819 | } |
| 2820 | break; |
| 2821 | } |
| 2822 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2823 | case Token::VOID: { |
| 2824 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 2825 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2826 | context()->Plug(Heap::kUndefinedValueRootIndex); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2827 | break; |
| 2828 | } |
| 2829 | |
| 2830 | case Token::NOT: { |
| 2831 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2832 | Label materialize_true, materialize_false; |
| 2833 | Label* if_true = NULL; |
| 2834 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2835 | Label* fall_through = NULL; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2836 | |
| 2837 | // Notice that the labels are swapped. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2838 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2839 | &if_false, &if_true, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2840 | VisitForControl(expr->expression(), if_true, if_false, fall_through); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2841 | context()->Plug(if_false, if_true); // Labels swapped. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2842 | break; |
| 2843 | } |
| 2844 | |
| 2845 | case Token::TYPEOF: { |
| 2846 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2847 | { StackValueContext context(this); |
| 2848 | VisitForTypeofValue(expr->expression()); |
| 2849 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2850 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2851 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | } |
| 2854 | |
| 2855 | case Token::ADD: { |
| 2856 | Comment cmt(masm_, "[ UnaryOperation (ADD)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2857 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2858 | Label no_conversion; |
| 2859 | __ tst(result_register(), Operand(kSmiTagMask)); |
| 2860 | __ b(eq, &no_conversion); |
| 2861 | __ push(r0); |
| 2862 | __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS); |
| 2863 | __ bind(&no_conversion); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2864 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2865 | break; |
| 2866 | } |
| 2867 | |
| 2868 | case Token::SUB: { |
| 2869 | Comment cmt(masm_, "[ UnaryOperation (SUB)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 2871 | UnaryOverwriteMode overwrite = |
| 2872 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2873 | GenericUnaryOpStub stub(Token::SUB, |
| 2874 | overwrite, |
| 2875 | NO_UNARY_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2876 | // GenericUnaryOpStub expects the argument to be in the |
| 2877 | // accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2878 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2879 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2880 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2881 | break; |
| 2882 | } |
| 2883 | |
| 2884 | case Token::BIT_NOT: { |
| 2885 | Comment cmt(masm_, "[ UnaryOperation (BIT_NOT)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2886 | // The generic unary operation stub expects the argument to be |
| 2887 | // in the accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2888 | VisitForAccumulatorValue(expr->expression()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2889 | Label done; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2890 | bool inline_smi_code = ShouldInlineSmiCase(expr->op()); |
| 2891 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2892 | Label call_stub; |
| 2893 | __ BranchOnNotSmi(r0, &call_stub); |
| 2894 | __ mvn(r0, Operand(r0)); |
| 2895 | // Bit-clear inverted smi-tag. |
| 2896 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 2897 | __ b(&done); |
| 2898 | __ bind(&call_stub); |
| 2899 | } |
| 2900 | bool overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2901 | UnaryOpFlags flags = inline_smi_code |
| 2902 | ? NO_UNARY_SMI_CODE_IN_STUB |
| 2903 | : NO_UNARY_FLAGS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2904 | UnaryOverwriteMode mode = |
| 2905 | overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2906 | GenericUnaryOpStub stub(Token::BIT_NOT, mode, flags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2907 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2908 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2909 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2910 | break; |
| 2911 | } |
| 2912 | |
| 2913 | default: |
| 2914 | UNREACHABLE(); |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | |
| 2919 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 2920 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2921 | SetSourcePosition(expr->position()); |
| 2922 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2923 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 2924 | // as the left-hand side. |
| 2925 | if (!expr->expression()->IsValidLeftHandSide()) { |
| 2926 | VisitForEffect(expr->expression()); |
| 2927 | return; |
| 2928 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2929 | |
| 2930 | // Expression can only be a property, a global or a (parameter or local) |
| 2931 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 2932 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 2933 | LhsKind assign_type = VARIABLE; |
| 2934 | Property* prop = expr->expression()->AsProperty(); |
| 2935 | // In case of a property we use the uninitialized expression context |
| 2936 | // of the key to detect a named property. |
| 2937 | if (prop != NULL) { |
| 2938 | assign_type = |
| 2939 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 2940 | } |
| 2941 | |
| 2942 | // Evaluate expression and get value. |
| 2943 | if (assign_type == VARIABLE) { |
| 2944 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2945 | AccumulatorValueContext context(this); |
| 2946 | EmitVariableLoad(expr->expression()->AsVariableProxy()->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2947 | } else { |
| 2948 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2949 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2950 | __ mov(ip, Operand(Smi::FromInt(0))); |
| 2951 | __ push(ip); |
| 2952 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2953 | if (assign_type == NAMED_PROPERTY) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2954 | // Put the object both on the stack and in the accumulator. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2955 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2956 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2957 | EmitNamedPropertyLoad(prop); |
| 2958 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2959 | VisitForStackValue(prop->obj()); |
| 2960 | VisitForAccumulatorValue(prop->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2961 | __ ldr(r1, MemOperand(sp, 0)); |
| 2962 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2963 | EmitKeyedPropertyLoad(prop); |
| 2964 | } |
| 2965 | } |
| 2966 | |
| 2967 | // Call ToNumber only if operand is not a smi. |
| 2968 | Label no_conversion; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2969 | __ BranchOnSmi(r0, &no_conversion); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2970 | __ push(r0); |
| 2971 | __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS); |
| 2972 | __ bind(&no_conversion); |
| 2973 | |
| 2974 | // Save result for postfix expressions. |
| 2975 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2976 | if (!context()->IsEffect()) { |
| 2977 | // Save the result on the stack. If we have a named or keyed property |
| 2978 | // we store the result under the receiver that is currently on top |
| 2979 | // of the stack. |
| 2980 | switch (assign_type) { |
| 2981 | case VARIABLE: |
| 2982 | __ push(r0); |
| 2983 | break; |
| 2984 | case NAMED_PROPERTY: |
| 2985 | __ str(r0, MemOperand(sp, kPointerSize)); |
| 2986 | break; |
| 2987 | case KEYED_PROPERTY: |
| 2988 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
| 2989 | break; |
| 2990 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | |
| 2995 | // Inline smi case if we are in a loop. |
| 2996 | Label stub_call, done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2997 | int count_value = expr->op() == Token::INC ? 1 : -1; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2998 | if (ShouldInlineSmiCase(expr->op())) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2999 | __ add(r0, r0, Operand(Smi::FromInt(count_value)), SetCC); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3000 | __ b(vs, &stub_call); |
| 3001 | // We could eliminate this smi check if we split the code at |
| 3002 | // the first smi check before calling ToNumber. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3003 | __ BranchOnSmi(r0, &done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3004 | __ bind(&stub_call); |
| 3005 | // Call stub. Undo operation first. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3006 | __ sub(r0, r0, Operand(Smi::FromInt(count_value))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3007 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3008 | __ mov(r1, Operand(Smi::FromInt(count_value))); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3009 | GenericBinaryOpStub stub(Token::ADD, NO_OVERWRITE, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3010 | __ CallStub(&stub); |
| 3011 | __ bind(&done); |
| 3012 | |
| 3013 | // Store the value returned in r0. |
| 3014 | switch (assign_type) { |
| 3015 | case VARIABLE: |
| 3016 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3017 | { EffectContext context(this); |
| 3018 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 3019 | Token::ASSIGN); |
| 3020 | } |
| 3021 | // For all contexts except EffectConstant We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3022 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3023 | if (!context()->IsEffect()) { |
| 3024 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3025 | } |
| 3026 | } else { |
| 3027 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3028 | Token::ASSIGN); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3029 | } |
| 3030 | break; |
| 3031 | case NAMED_PROPERTY: { |
| 3032 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3033 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3034 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3035 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3036 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3037 | if (!context()->IsEffect()) { |
| 3038 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3039 | } |
| 3040 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3041 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3042 | } |
| 3043 | break; |
| 3044 | } |
| 3045 | case KEYED_PROPERTY: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3046 | __ pop(r1); // Key. |
| 3047 | __ pop(r2); // Receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3048 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3049 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3050 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3051 | if (!context()->IsEffect()) { |
| 3052 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3053 | } |
| 3054 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3055 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3056 | } |
| 3057 | break; |
| 3058 | } |
| 3059 | } |
| 3060 | } |
| 3061 | |
| 3062 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3063 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
| 3064 | ASSERT(!context()->IsEffect()); |
| 3065 | ASSERT(!context()->IsTest()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3066 | VariableProxy* proxy = expr->AsVariableProxy(); |
| 3067 | if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) { |
| 3068 | Comment cmnt(masm_, "Global variable"); |
| 3069 | __ ldr(r0, CodeGenerator::GlobalObject()); |
| 3070 | __ mov(r2, Operand(proxy->name())); |
| 3071 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 3072 | // Use a regular load, not a contextual load, to avoid a reference |
| 3073 | // error. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3074 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3075 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3076 | } else if (proxy != NULL && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3077 | proxy->var()->AsSlot() != NULL && |
| 3078 | proxy->var()->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3079 | Label done, slow; |
| 3080 | |
| 3081 | // Generate code for loading from variables potentially shadowed |
| 3082 | // by eval-introduced variables. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3083 | Slot* slot = proxy->var()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3084 | EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done); |
| 3085 | |
| 3086 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3087 | __ mov(r0, Operand(proxy->name())); |
| 3088 | __ Push(cp, r0); |
| 3089 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3090 | __ bind(&done); |
| 3091 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3092 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3093 | } else { |
| 3094 | // This expression cannot throw a reference error at the top level. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3095 | Visit(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3096 | } |
| 3097 | } |
| 3098 | |
| 3099 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3100 | bool FullCodeGenerator::TryLiteralCompare(Token::Value op, |
| 3101 | Expression* left, |
| 3102 | Expression* right, |
| 3103 | Label* if_true, |
| 3104 | Label* if_false, |
| 3105 | Label* fall_through) { |
| 3106 | if (op != Token::EQ && op != Token::EQ_STRICT) return false; |
| 3107 | |
| 3108 | // Check for the pattern: typeof <expression> == <string literal>. |
| 3109 | Literal* right_literal = right->AsLiteral(); |
| 3110 | if (right_literal == NULL) return false; |
| 3111 | Handle<Object> right_literal_value = right_literal->handle(); |
| 3112 | if (!right_literal_value->IsString()) return false; |
| 3113 | UnaryOperation* left_unary = left->AsUnaryOperation(); |
| 3114 | if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false; |
| 3115 | Handle<String> check = Handle<String>::cast(right_literal_value); |
| 3116 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3117 | { AccumulatorValueContext context(this); |
| 3118 | VisitForTypeofValue(left_unary->expression()); |
| 3119 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3120 | if (check->Equals(Heap::number_symbol())) { |
| 3121 | __ tst(r0, Operand(kSmiTagMask)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3122 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3123 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3124 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3125 | __ cmp(r0, ip); |
| 3126 | Split(eq, if_true, if_false, fall_through); |
| 3127 | } else if (check->Equals(Heap::string_symbol())) { |
| 3128 | __ tst(r0, Operand(kSmiTagMask)); |
| 3129 | __ b(eq, if_false); |
| 3130 | // Check for undetectable objects => false. |
| 3131 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3132 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3133 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3134 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3135 | __ b(eq, if_false); |
| 3136 | __ ldrb(r1, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 3137 | __ cmp(r1, Operand(FIRST_NONSTRING_TYPE)); |
| 3138 | Split(lt, if_true, if_false, fall_through); |
| 3139 | } else if (check->Equals(Heap::boolean_symbol())) { |
| 3140 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3141 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3142 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3143 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 3144 | __ cmp(r0, ip); |
| 3145 | Split(eq, if_true, if_false, fall_through); |
| 3146 | } else if (check->Equals(Heap::undefined_symbol())) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3147 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3148 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3149 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3150 | __ tst(r0, Operand(kSmiTagMask)); |
| 3151 | __ b(eq, if_false); |
| 3152 | // Check for undetectable objects => true. |
| 3153 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3154 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3155 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3156 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3157 | Split(eq, if_true, if_false, fall_through); |
| 3158 | } else if (check->Equals(Heap::function_symbol())) { |
| 3159 | __ tst(r0, Operand(kSmiTagMask)); |
| 3160 | __ b(eq, if_false); |
| 3161 | __ CompareObjectType(r0, r1, r0, JS_FUNCTION_TYPE); |
| 3162 | __ b(eq, if_true); |
| 3163 | // Regular expressions => 'function' (they are callable). |
| 3164 | __ CompareInstanceType(r1, r0, JS_REGEXP_TYPE); |
| 3165 | Split(eq, if_true, if_false, fall_through); |
| 3166 | } else if (check->Equals(Heap::object_symbol())) { |
| 3167 | __ tst(r0, Operand(kSmiTagMask)); |
| 3168 | __ b(eq, if_false); |
| 3169 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 3170 | __ cmp(r0, ip); |
| 3171 | __ b(eq, if_true); |
| 3172 | // Regular expressions => 'function', not 'object'. |
| 3173 | __ CompareObjectType(r0, r1, r0, JS_REGEXP_TYPE); |
| 3174 | __ b(eq, if_false); |
| 3175 | // Check for undetectable objects => false. |
| 3176 | __ ldrb(r0, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3177 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 3178 | __ cmp(r0, Operand(1 << Map::kIsUndetectable)); |
| 3179 | __ b(eq, if_false); |
| 3180 | // Check for JS objects => true. |
| 3181 | __ ldrb(r0, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 3182 | __ cmp(r0, Operand(FIRST_JS_OBJECT_TYPE)); |
| 3183 | __ b(lt, if_false); |
| 3184 | __ cmp(r0, Operand(LAST_JS_OBJECT_TYPE)); |
| 3185 | Split(le, if_true, if_false, fall_through); |
| 3186 | } else { |
| 3187 | if (if_false != fall_through) __ jmp(if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3188 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3189 | |
| 3190 | return true; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3194 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 3195 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3196 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3197 | |
| 3198 | // Always perform the comparison for its control flow. Pack the result |
| 3199 | // into the expression's context after the comparison is performed. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3200 | |
| 3201 | Label materialize_true, materialize_false; |
| 3202 | Label* if_true = NULL; |
| 3203 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3204 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3205 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3206 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3207 | |
| 3208 | // First we try a fast inlined version of the compare when one of |
| 3209 | // the operands is a literal. |
| 3210 | Token::Value op = expr->op(); |
| 3211 | Expression* left = expr->left(); |
| 3212 | Expression* right = expr->right(); |
| 3213 | if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3214 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3215 | return; |
| 3216 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3217 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3218 | VisitForStackValue(expr->left()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3219 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3220 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3221 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3222 | __ InvokeBuiltin(Builtins::IN, CALL_JS); |
| 3223 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3224 | __ cmp(r0, ip); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3225 | Split(eq, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | |
| 3228 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3229 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3230 | InstanceofStub stub; |
| 3231 | __ CallStub(&stub); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3232 | // The stub returns 0 for true. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3233 | __ tst(r0, r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3234 | Split(eq, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3235 | break; |
| 3236 | } |
| 3237 | |
| 3238 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3239 | VisitForAccumulatorValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3240 | Condition cc = eq; |
| 3241 | bool strict = false; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3242 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3243 | case Token::EQ_STRICT: |
| 3244 | strict = true; |
| 3245 | // Fall through |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3246 | case Token::EQ: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3247 | cc = eq; |
| 3248 | __ pop(r1); |
| 3249 | break; |
| 3250 | case Token::LT: |
| 3251 | cc = lt; |
| 3252 | __ pop(r1); |
| 3253 | break; |
| 3254 | case Token::GT: |
| 3255 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
| 3256 | cc = lt; |
| 3257 | __ mov(r1, result_register()); |
| 3258 | __ pop(r0); |
| 3259 | break; |
| 3260 | case Token::LTE: |
| 3261 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
| 3262 | cc = ge; |
| 3263 | __ mov(r1, result_register()); |
| 3264 | __ pop(r0); |
| 3265 | break; |
| 3266 | case Token::GTE: |
| 3267 | cc = ge; |
| 3268 | __ pop(r1); |
| 3269 | break; |
| 3270 | case Token::IN: |
| 3271 | case Token::INSTANCEOF: |
| 3272 | default: |
| 3273 | UNREACHABLE(); |
| 3274 | } |
| 3275 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3276 | bool inline_smi_code = ShouldInlineSmiCase(op); |
| 3277 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3278 | Label slow_case; |
| 3279 | __ orr(r2, r0, Operand(r1)); |
| 3280 | __ BranchOnNotSmi(r2, &slow_case); |
| 3281 | __ cmp(r1, r0); |
| 3282 | Split(cc, if_true, if_false, NULL); |
| 3283 | __ bind(&slow_case); |
| 3284 | } |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3285 | CompareFlags flags = inline_smi_code |
| 3286 | ? NO_SMI_COMPARE_IN_STUB |
| 3287 | : NO_COMPARE_FLAGS; |
| 3288 | CompareStub stub(cc, strict, flags, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3289 | __ CallStub(&stub); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 3290 | __ cmp(r0, Operand(0, RelocInfo::NONE)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3291 | Split(cc, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3292 | } |
| 3293 | } |
| 3294 | |
| 3295 | // Convert the result of the comparison into one expected for this |
| 3296 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3297 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3301 | void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) { |
| 3302 | Comment cmnt(masm_, "[ CompareToNull"); |
| 3303 | Label materialize_true, materialize_false; |
| 3304 | Label* if_true = NULL; |
| 3305 | Label* if_false = NULL; |
| 3306 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3307 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3308 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3309 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3310 | VisitForAccumulatorValue(expr->expression()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3311 | __ LoadRoot(r1, Heap::kNullValueRootIndex); |
| 3312 | __ cmp(r0, r1); |
| 3313 | if (expr->is_strict()) { |
| 3314 | Split(eq, if_true, if_false, fall_through); |
| 3315 | } else { |
| 3316 | __ b(eq, if_true); |
| 3317 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 3318 | __ cmp(r0, r1); |
| 3319 | __ b(eq, if_true); |
| 3320 | __ tst(r0, Operand(kSmiTagMask)); |
| 3321 | __ b(eq, if_false); |
| 3322 | // It can be an undetectable object. |
| 3323 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3324 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3325 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3326 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3327 | Split(eq, if_true, if_false, fall_through); |
| 3328 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3329 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3333 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 3334 | __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3335 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3339 | Register FullCodeGenerator::result_register() { |
| 3340 | return r0; |
| 3341 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3342 | |
| 3343 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3344 | Register FullCodeGenerator::context_register() { |
| 3345 | return cp; |
| 3346 | } |
| 3347 | |
| 3348 | |
| 3349 | void FullCodeGenerator::EmitCallIC(Handle<Code> ic, RelocInfo::Mode mode) { |
| 3350 | ASSERT(mode == RelocInfo::CODE_TARGET || |
| 3351 | mode == RelocInfo::CODE_TARGET_CONTEXT); |
| 3352 | __ Call(ic, mode); |
| 3353 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3354 | |
| 3355 | |
| 3356 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 3357 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 3358 | __ str(value, MemOperand(fp, frame_offset)); |
| 3359 | } |
| 3360 | |
| 3361 | |
| 3362 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3363 | __ ldr(dst, ContextOperand(cp, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | |
| 3367 | // ---------------------------------------------------------------------------- |
| 3368 | // Non-local control flow support. |
| 3369 | |
| 3370 | void FullCodeGenerator::EnterFinallyBlock() { |
| 3371 | ASSERT(!result_register().is(r1)); |
| 3372 | // Store result register while executing finally block. |
| 3373 | __ push(result_register()); |
| 3374 | // Cook return address in link register to stack (smi encoded Code* delta) |
| 3375 | __ sub(r1, lr, Operand(masm_->CodeObject())); |
| 3376 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3377 | ASSERT_EQ(0, kSmiTag); |
| 3378 | __ add(r1, r1, Operand(r1)); // Convert to smi. |
| 3379 | __ push(r1); |
| 3380 | } |
| 3381 | |
| 3382 | |
| 3383 | void FullCodeGenerator::ExitFinallyBlock() { |
| 3384 | ASSERT(!result_register().is(r1)); |
| 3385 | // Restore result register from stack. |
| 3386 | __ pop(r1); |
| 3387 | // Uncook return address and return. |
| 3388 | __ pop(result_register()); |
| 3389 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3390 | __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. |
| 3391 | __ add(pc, r1, Operand(masm_->CodeObject())); |
| 3392 | } |
| 3393 | |
| 3394 | |
| 3395 | #undef __ |
| 3396 | |
| 3397 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3398 | |
| 3399 | #endif // V8_TARGET_ARCH_ARM |