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