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