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