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); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1553 | if (op == Token::ADD || |
| 1554 | op == Token::SUB || |
| 1555 | op == Token::MUL || |
| 1556 | op == Token::DIV || |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1557 | op == Token::MOD || |
| 1558 | op == Token::BIT_OR || |
| 1559 | op == Token::BIT_AND || |
| 1560 | op == Token::BIT_XOR) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1561 | TypeRecordingBinaryOpStub stub(op, mode); |
| 1562 | __ CallStub(&stub); |
| 1563 | } else { |
| 1564 | GenericBinaryOpStub stub(op, mode, r1, r0); |
| 1565 | __ CallStub(&stub); |
| 1566 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1567 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1571 | void FullCodeGenerator::EmitAssignment(Expression* expr, int bailout_ast_id) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1572 | // Invalid left-hand sides are rewritten to have a 'throw |
| 1573 | // ReferenceError' on the left-hand side. |
| 1574 | if (!expr->IsValidLeftHandSide()) { |
| 1575 | VisitForEffect(expr); |
| 1576 | return; |
| 1577 | } |
| 1578 | |
| 1579 | // Left-hand side can only be a property, a global or a (parameter or local) |
| 1580 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 1581 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 1582 | LhsKind assign_type = VARIABLE; |
| 1583 | Property* prop = expr->AsProperty(); |
| 1584 | if (prop != NULL) { |
| 1585 | assign_type = (prop->key()->IsPropertyName()) |
| 1586 | ? NAMED_PROPERTY |
| 1587 | : KEYED_PROPERTY; |
| 1588 | } |
| 1589 | |
| 1590 | switch (assign_type) { |
| 1591 | case VARIABLE: { |
| 1592 | Variable* var = expr->AsVariableProxy()->var(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1593 | EffectContext context(this); |
| 1594 | EmitVariableAssignment(var, Token::ASSIGN); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1595 | break; |
| 1596 | } |
| 1597 | case NAMED_PROPERTY: { |
| 1598 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1599 | VisitForAccumulatorValue(prop->obj()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1600 | __ mov(r1, r0); |
| 1601 | __ pop(r0); // Restore value. |
| 1602 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
| 1603 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1604 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1605 | break; |
| 1606 | } |
| 1607 | case KEYED_PROPERTY: { |
| 1608 | __ push(r0); // Preserve value. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1609 | VisitForStackValue(prop->obj()); |
| 1610 | VisitForAccumulatorValue(prop->key()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1611 | __ mov(r1, r0); |
| 1612 | __ pop(r2); |
| 1613 | __ pop(r0); // Restore value. |
| 1614 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1615 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1616 | break; |
| 1617 | } |
| 1618 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1619 | PrepareForBailoutForId(bailout_ast_id, TOS_REG); |
| 1620 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1624 | void FullCodeGenerator::EmitVariableAssignment(Variable* var, |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1625 | Token::Value op) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1626 | // Left-hand sides that rewrite to explicit property accesses do not reach |
| 1627 | // here. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1628 | ASSERT(var != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1629 | ASSERT(var->is_global() || var->AsSlot() != NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1630 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1631 | if (var->is_global()) { |
| 1632 | ASSERT(!var->is_this()); |
| 1633 | // Assignment to a global variable. Use inline caching for the |
| 1634 | // 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] | 1635 | // r2, and the global object in r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1636 | __ mov(r2, Operand(var->name())); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1637 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1638 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1639 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1640 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1641 | } else if (var->mode() != Variable::CONST || op == Token::INIT_CONST) { |
| 1642 | // Perform the assignment for non-const variables and for initialization |
| 1643 | // of const variables. Const assignments are simply skipped. |
| 1644 | Label done; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1645 | Slot* slot = var->AsSlot(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1646 | switch (slot->type()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1647 | case Slot::PARAMETER: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1648 | case Slot::LOCAL: |
| 1649 | if (op == Token::INIT_CONST) { |
| 1650 | // Detect const reinitialization by checking for the hole value. |
| 1651 | __ ldr(r1, MemOperand(fp, SlotOffset(slot))); |
| 1652 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 1653 | __ cmp(r1, ip); |
| 1654 | __ b(ne, &done); |
| 1655 | } |
| 1656 | // Perform the assignment. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1657 | __ str(result_register(), MemOperand(fp, SlotOffset(slot))); |
| 1658 | break; |
| 1659 | |
| 1660 | case Slot::CONTEXT: { |
| 1661 | MemOperand target = EmitSlotSearch(slot, r1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1662 | if (op == Token::INIT_CONST) { |
| 1663 | // Detect const reinitialization by checking for the hole value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1664 | __ ldr(r2, target); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1665 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1666 | __ cmp(r2, ip); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1667 | __ b(ne, &done); |
| 1668 | } |
| 1669 | // Perform the assignment and issue the write barrier. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1670 | __ str(result_register(), target); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1671 | // RecordWrite may destroy all its register arguments. |
| 1672 | __ mov(r3, result_register()); |
| 1673 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 1674 | __ RecordWrite(r1, Operand(offset), r2, r3); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1675 | break; |
| 1676 | } |
| 1677 | |
| 1678 | case Slot::LOOKUP: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1679 | // Call the runtime for the assignment. The runtime will ignore |
| 1680 | // const reinitialization. |
| 1681 | __ push(r0); // Value. |
| 1682 | __ mov(r0, Operand(slot->var()->name())); |
| 1683 | __ Push(cp, r0); // Context and name. |
| 1684 | if (op == Token::INIT_CONST) { |
| 1685 | // The runtime will ignore const redeclaration. |
| 1686 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 1687 | } else { |
| 1688 | __ CallRuntime(Runtime::kStoreContextSlot, 3); |
| 1689 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1690 | break; |
| 1691 | } |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1692 | __ bind(&done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | |
| 1697 | void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
| 1698 | // Assignment to a property, using a named store IC. |
| 1699 | Property* prop = expr->target()->AsProperty(); |
| 1700 | ASSERT(prop != NULL); |
| 1701 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 1702 | |
| 1703 | // If the assignment starts a block of assignments to the same object, |
| 1704 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1705 | // adding fast properties. |
| 1706 | if (expr->starts_initialization_block()) { |
| 1707 | __ push(result_register()); |
| 1708 | __ ldr(ip, MemOperand(sp, kPointerSize)); // Receiver is now under value. |
| 1709 | __ push(ip); |
| 1710 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1711 | __ pop(result_register()); |
| 1712 | } |
| 1713 | |
| 1714 | // Record source code position before IC call. |
| 1715 | SetSourcePosition(expr->position()); |
| 1716 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1717 | // Load receiver to r1. Leave a copy in the stack if needed for turning the |
| 1718 | // receiver into fast case. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1719 | if (expr->ends_initialization_block()) { |
| 1720 | __ ldr(r1, MemOperand(sp)); |
| 1721 | } else { |
| 1722 | __ pop(r1); |
| 1723 | } |
| 1724 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1725 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1726 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1727 | |
| 1728 | // If the assignment ends an initialization block, revert to fast case. |
| 1729 | if (expr->ends_initialization_block()) { |
| 1730 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1731 | // Receiver is under the result value. |
| 1732 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1733 | __ push(ip); |
| 1734 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1735 | __ pop(r0); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1736 | __ Drop(1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1737 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1738 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1739 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
| 1744 | // Assignment to a property, using a keyed store IC. |
| 1745 | |
| 1746 | // If the assignment starts a block of assignments to the same object, |
| 1747 | // change to slow case to avoid the quadratic behavior of repeatedly |
| 1748 | // adding fast properties. |
| 1749 | if (expr->starts_initialization_block()) { |
| 1750 | __ push(result_register()); |
| 1751 | // Receiver is now under the key and value. |
| 1752 | __ ldr(ip, MemOperand(sp, 2 * kPointerSize)); |
| 1753 | __ push(ip); |
| 1754 | __ CallRuntime(Runtime::kToSlowProperties, 1); |
| 1755 | __ pop(result_register()); |
| 1756 | } |
| 1757 | |
| 1758 | // Record source code position before IC call. |
| 1759 | SetSourcePosition(expr->position()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1760 | __ pop(r1); // Key. |
| 1761 | // Load receiver to r2. Leave a copy in the stack if needed for turning the |
| 1762 | // receiver into fast case. |
| 1763 | if (expr->ends_initialization_block()) { |
| 1764 | __ ldr(r2, MemOperand(sp)); |
| 1765 | } else { |
| 1766 | __ pop(r2); |
| 1767 | } |
| 1768 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1769 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1770 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1771 | |
| 1772 | // If the assignment ends an initialization block, revert to fast case. |
| 1773 | if (expr->ends_initialization_block()) { |
| 1774 | __ push(r0); // Result of assignment, saved even if not needed. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1775 | // Receiver is under the result value. |
| 1776 | __ ldr(ip, MemOperand(sp, kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1777 | __ push(ip); |
| 1778 | __ CallRuntime(Runtime::kToFastProperties, 1); |
| 1779 | __ pop(r0); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1780 | __ Drop(1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1781 | } |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1782 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 1783 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | void FullCodeGenerator::VisitProperty(Property* expr) { |
| 1788 | Comment cmnt(masm_, "[ Property"); |
| 1789 | Expression* key = expr->key(); |
| 1790 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1791 | if (key->IsPropertyName()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1792 | VisitForAccumulatorValue(expr->obj()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1793 | EmitNamedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1794 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1795 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1796 | VisitForStackValue(expr->obj()); |
| 1797 | VisitForAccumulatorValue(expr->key()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 1798 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1799 | EmitKeyedPropertyLoad(expr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1800 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1801 | } |
| 1802 | } |
| 1803 | |
| 1804 | void FullCodeGenerator::EmitCallWithIC(Call* expr, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1805 | Handle<Object> name, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1806 | RelocInfo::Mode mode) { |
| 1807 | // Code common for calls using the IC. |
| 1808 | ZoneList<Expression*>* args = expr->arguments(); |
| 1809 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1810 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1811 | for (int i = 0; i < arg_count; i++) { |
| 1812 | VisitForStackValue(args->at(i)); |
| 1813 | } |
| 1814 | __ mov(r2, Operand(name)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1815 | } |
| 1816 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1818 | // Call the IC initialization code. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1819 | 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] | 1820 | Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, in_loop); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1821 | EmitCallIC(ic, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1822 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1823 | // Restore context register. |
| 1824 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1825 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1829 | void FullCodeGenerator::EmitKeyedCallWithIC(Call* expr, |
| 1830 | Expression* key, |
| 1831 | RelocInfo::Mode mode) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1832 | // Load the key. |
| 1833 | VisitForAccumulatorValue(key); |
| 1834 | |
| 1835 | // Swap the name of the function and the receiver on the stack to follow |
| 1836 | // the calling convention for call ICs. |
| 1837 | __ pop(r1); |
| 1838 | __ push(r0); |
| 1839 | __ push(r1); |
| 1840 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1841 | // Code common for calls using the IC. |
| 1842 | ZoneList<Expression*>* args = expr->arguments(); |
| 1843 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1844 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1845 | for (int i = 0; i < arg_count; i++) { |
| 1846 | VisitForStackValue(args->at(i)); |
| 1847 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1848 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1849 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1850 | SetSourcePosition(expr->position()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1851 | // Call the IC initialization code. |
| 1852 | 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] | 1853 | Handle<Code> ic = StubCache::ComputeKeyedCallInitialize(arg_count, in_loop); |
| 1854 | __ ldr(r2, MemOperand(sp, (arg_count + 1) * kPointerSize)); // Key. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 1855 | EmitCallIC(ic, mode); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1856 | RecordJSReturnSite(expr); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1857 | // Restore context register. |
| 1858 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1859 | context()->DropAndPlug(1, r0); // Drop the key still on the stack. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1863 | void FullCodeGenerator::EmitCallWithStub(Call* expr) { |
| 1864 | // Code common for calls using the call stub. |
| 1865 | ZoneList<Expression*>* args = expr->arguments(); |
| 1866 | int arg_count = args->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1867 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1868 | for (int i = 0; i < arg_count; i++) { |
| 1869 | VisitForStackValue(args->at(i)); |
| 1870 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1871 | } |
| 1872 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1873 | SetSourcePosition(expr->position()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1874 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1875 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1876 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1877 | RecordJSReturnSite(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1878 | // Restore context register. |
| 1879 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1880 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | |
| 1884 | void FullCodeGenerator::VisitCall(Call* expr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1885 | #ifdef DEBUG |
| 1886 | // We want to verify that RecordJSReturnSite gets called on all paths |
| 1887 | // through this function. Avoid early returns. |
| 1888 | expr->return_is_recorded_ = false; |
| 1889 | #endif |
| 1890 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1891 | Comment cmnt(masm_, "[ Call"); |
| 1892 | Expression* fun = expr->expression(); |
| 1893 | Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 1894 | |
| 1895 | if (var != NULL && var->is_possibly_eval()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1896 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 1897 | // resolve the function we need to call and the receiver of the |
| 1898 | // call. Then we call the resolved function using the given |
| 1899 | // arguments. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1900 | ZoneList<Expression*>* args = expr->arguments(); |
| 1901 | int arg_count = args->length(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1902 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1903 | { PreservePositionScope pos_scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1904 | VisitForStackValue(fun); |
| 1905 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 1906 | __ push(r2); // Reserved receiver slot. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1907 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1908 | // Push the arguments. |
| 1909 | for (int i = 0; i < arg_count; i++) { |
| 1910 | VisitForStackValue(args->at(i)); |
| 1911 | } |
| 1912 | |
| 1913 | // Push copy of the function - found below the arguments. |
| 1914 | __ ldr(r1, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1915 | __ push(r1); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1916 | |
| 1917 | // Push copy of the first argument or undefined if it doesn't exist. |
| 1918 | if (arg_count > 0) { |
| 1919 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 1920 | __ push(r1); |
| 1921 | } else { |
| 1922 | __ push(r2); |
| 1923 | } |
| 1924 | |
| 1925 | // Push the receiver of the enclosing function and do runtime call. |
| 1926 | __ ldr(r1, |
| 1927 | MemOperand(fp, (2 + scope()->num_parameters()) * kPointerSize)); |
| 1928 | __ push(r1); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame^] | 1929 | // Push the strict mode flag. |
| 1930 | __ mov(r1, Operand(Smi::FromInt(strict_mode_flag()))); |
| 1931 | __ push(r1); |
| 1932 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 4); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1933 | |
| 1934 | // The runtime call returns a pair of values in r0 (function) and |
| 1935 | // r1 (receiver). Touch up the stack with the right values. |
| 1936 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
| 1937 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1938 | } |
| 1939 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1940 | // Record source position for debugger. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | SetSourcePosition(expr->position()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1942 | InLoopFlag in_loop = (loop_depth() > 0) ? IN_LOOP : NOT_IN_LOOP; |
| 1943 | CallFunctionStub stub(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
| 1944 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | RecordJSReturnSite(expr); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1946 | // Restore context register. |
| 1947 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1948 | context()->DropAndPlug(1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1949 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1950 | // Push global object as receiver for the call IC. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1951 | __ ldr(r0, GlobalObjectOperand()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1952 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1953 | EmitCallWithIC(expr, var->name(), RelocInfo::CODE_TARGET_CONTEXT); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1954 | } else if (var != NULL && var->AsSlot() != NULL && |
| 1955 | var->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1956 | // Call to a lookup slot (dynamically introduced variable). |
| 1957 | Label slow, done; |
| 1958 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1959 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 1960 | // Generate code for loading from variables potentially shadowed |
| 1961 | // by eval-introduced variables. |
| 1962 | EmitDynamicLoadFromSlotFastCase(var->AsSlot(), |
| 1963 | NOT_INSIDE_TYPEOF, |
| 1964 | &slow, |
| 1965 | &done); |
| 1966 | } |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1967 | |
| 1968 | __ bind(&slow); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1969 | // 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] | 1970 | // and the object holding it (returned in edx). |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1971 | __ push(context_register()); |
| 1972 | __ mov(r2, Operand(var->name())); |
| 1973 | __ push(r2); |
| 1974 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1975 | __ Push(r0, r1); // Function, receiver. |
| 1976 | |
| 1977 | // If fast case code has been generated, emit code to push the |
| 1978 | // function and receiver and have the slow path jump around this |
| 1979 | // code. |
| 1980 | if (done.is_linked()) { |
| 1981 | Label call; |
| 1982 | __ b(&call); |
| 1983 | __ bind(&done); |
| 1984 | // Push function. |
| 1985 | __ push(r0); |
| 1986 | // Push global receiver. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 1987 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 1988 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 1989 | __ push(r1); |
| 1990 | __ bind(&call); |
| 1991 | } |
| 1992 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1993 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1994 | } else if (fun->AsProperty() != NULL) { |
| 1995 | // Call to an object property. |
| 1996 | Property* prop = fun->AsProperty(); |
| 1997 | Literal* key = prop->key()->AsLiteral(); |
| 1998 | if (key != NULL && key->handle()->IsSymbol()) { |
| 1999 | // Call to a named property, use call IC. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2000 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2001 | VisitForStackValue(prop->obj()); |
| 2002 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2003 | EmitCallWithIC(expr, key->handle(), RelocInfo::CODE_TARGET); |
| 2004 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2005 | // Call to a keyed property. |
| 2006 | // For a synthetic property use keyed load IC followed by function call, |
| 2007 | // for a regular property use keyed CallIC. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2008 | if (prop->is_synthetic()) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2009 | // Do not visit the object and key subexpressions (they are shared |
| 2010 | // by all occurrences of the same rewritten parameter). |
| 2011 | ASSERT(prop->obj()->AsVariableProxy() != NULL); |
| 2012 | ASSERT(prop->obj()->AsVariableProxy()->var()->AsSlot() != NULL); |
| 2013 | Slot* slot = prop->obj()->AsVariableProxy()->var()->AsSlot(); |
| 2014 | MemOperand operand = EmitSlotSearch(slot, r1); |
| 2015 | __ ldr(r1, operand); |
| 2016 | |
| 2017 | ASSERT(prop->key()->AsLiteral() != NULL); |
| 2018 | ASSERT(prop->key()->AsLiteral()->handle()->IsSmi()); |
| 2019 | __ mov(r0, Operand(prop->key()->AsLiteral()->handle())); |
| 2020 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2021 | // Record source code position for IC call. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2022 | SetSourcePosition(prop->position()); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2023 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2024 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2025 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2026 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2027 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2028 | __ Push(r0, r1); // Function, receiver. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2029 | EmitCallWithStub(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2030 | } else { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2031 | { PreservePositionScope scope(masm()->positions_recorder()); |
| 2032 | VisitForStackValue(prop->obj()); |
| 2033 | } |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2034 | EmitKeyedCallWithIC(expr, prop->key(), RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2035 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2036 | } |
| 2037 | } else { |
| 2038 | // Call to some other expression. If the expression is an anonymous |
| 2039 | // function literal not called in a loop, mark it as one that should |
| 2040 | // also use the fast code generator. |
| 2041 | FunctionLiteral* lit = fun->AsFunctionLiteral(); |
| 2042 | if (lit != NULL && |
| 2043 | lit->name()->Equals(Heap::empty_string()) && |
| 2044 | loop_depth() == 0) { |
| 2045 | lit->set_try_full_codegen(true); |
| 2046 | } |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2047 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2048 | { PreservePositionScope scope(masm()->positions_recorder()); |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 2049 | VisitForStackValue(fun); |
| 2050 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2051 | // Load global receiver object. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2052 | __ ldr(r1, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2053 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 2054 | __ push(r1); |
| 2055 | // Emit function call. |
| 2056 | EmitCallWithStub(expr); |
| 2057 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2058 | |
| 2059 | #ifdef DEBUG |
| 2060 | // RecordJSReturnSite should have been called. |
| 2061 | ASSERT(expr->return_is_recorded_); |
| 2062 | #endif |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | |
| 2066 | void FullCodeGenerator::VisitCallNew(CallNew* expr) { |
| 2067 | Comment cmnt(masm_, "[ CallNew"); |
| 2068 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2069 | // expression in new calls must be evaluated before the |
| 2070 | // arguments. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2071 | |
| 2072 | // Push constructor on the stack. If it's not a function it's used as |
| 2073 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 2074 | // ignored. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2075 | VisitForStackValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2076 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2077 | // Push the arguments ("left-to-right") on the stack. |
| 2078 | ZoneList<Expression*>* args = expr->arguments(); |
| 2079 | int arg_count = args->length(); |
| 2080 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2081 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | // Call the construct call builtin that handles allocation and |
| 2085 | // constructor invocation. |
| 2086 | SetSourcePosition(expr->position()); |
| 2087 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2088 | // Load function and argument count into r1 and r0. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2089 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2090 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2091 | |
| 2092 | Handle<Code> construct_builtin(Builtins::builtin(Builtins::JSConstructCall)); |
| 2093 | __ Call(construct_builtin, RelocInfo::CONSTRUCT_CALL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2094 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2098 | void FullCodeGenerator::EmitIsSmi(ZoneList<Expression*>* args) { |
| 2099 | ASSERT(args->length() == 1); |
| 2100 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2101 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2102 | |
| 2103 | Label materialize_true, materialize_false; |
| 2104 | Label* if_true = NULL; |
| 2105 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2106 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2107 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2108 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2109 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2110 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 2111 | __ tst(r0, Operand(kSmiTagMask)); |
| 2112 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2113 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2114 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | |
| 2118 | void FullCodeGenerator::EmitIsNonNegativeSmi(ZoneList<Expression*>* args) { |
| 2119 | ASSERT(args->length() == 1); |
| 2120 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2121 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2122 | |
| 2123 | Label materialize_true, materialize_false; |
| 2124 | Label* if_true = NULL; |
| 2125 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2126 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2127 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2128 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2129 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2130 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2131 | __ tst(r0, Operand(kSmiTagMask | 0x80000000)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2132 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2133 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2134 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | void FullCodeGenerator::EmitIsObject(ZoneList<Expression*>* args) { |
| 2139 | ASSERT(args->length() == 1); |
| 2140 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2141 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2142 | |
| 2143 | Label materialize_true, materialize_false; |
| 2144 | Label* if_true = NULL; |
| 2145 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2146 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2147 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2148 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2149 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2150 | __ JumpIfSmi(r0, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2151 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2152 | __ cmp(r0, ip); |
| 2153 | __ b(eq, if_true); |
| 2154 | __ ldr(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2155 | // Undetectable objects behave like undefined when tested with typeof. |
| 2156 | __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 2157 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
| 2158 | __ b(ne, if_false); |
| 2159 | __ ldrb(r1, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 2160 | __ cmp(r1, Operand(FIRST_JS_OBJECT_TYPE)); |
| 2161 | __ b(lt, if_false); |
| 2162 | __ cmp(r1, Operand(LAST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2163 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2164 | Split(le, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2165 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2166 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
| 2169 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2170 | void FullCodeGenerator::EmitIsSpecObject(ZoneList<Expression*>* args) { |
| 2171 | ASSERT(args->length() == 1); |
| 2172 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2173 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2174 | |
| 2175 | Label materialize_true, materialize_false; |
| 2176 | Label* if_true = NULL; |
| 2177 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2178 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2179 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2180 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2181 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2182 | __ JumpIfSmi(r0, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2183 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2184 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2185 | Split(ge, if_true, if_false, fall_through); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2186 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2187 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2191 | void FullCodeGenerator::EmitIsUndetectableObject(ZoneList<Expression*>* args) { |
| 2192 | ASSERT(args->length() == 1); |
| 2193 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2194 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2195 | |
| 2196 | Label materialize_true, materialize_false; |
| 2197 | Label* if_true = NULL; |
| 2198 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2199 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2200 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2201 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2202 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2203 | __ JumpIfSmi(r0, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2204 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2205 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 2206 | __ tst(r1, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2207 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2208 | Split(ne, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2209 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2210 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2214 | void FullCodeGenerator::EmitIsStringWrapperSafeForDefaultValueOf( |
| 2215 | ZoneList<Expression*>* args) { |
| 2216 | |
| 2217 | ASSERT(args->length() == 1); |
| 2218 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2219 | VisitForAccumulatorValue(args->at(0)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2220 | |
| 2221 | Label materialize_true, materialize_false; |
| 2222 | Label* if_true = NULL; |
| 2223 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2224 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2225 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2226 | &if_true, &if_false, &fall_through); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2227 | |
| 2228 | // Just indicate false, as %_IsStringWrapperSafeForDefaultValueOf() is only |
| 2229 | // used in a few functions in runtime.js which should not normally be hit by |
| 2230 | // this compiler. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2231 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2232 | __ jmp(if_false); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2233 | context()->Plug(if_true, if_false); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2237 | void FullCodeGenerator::EmitIsFunction(ZoneList<Expression*>* args) { |
| 2238 | ASSERT(args->length() == 1); |
| 2239 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2240 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2241 | |
| 2242 | Label materialize_true, materialize_false; |
| 2243 | Label* if_true = NULL; |
| 2244 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2245 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2246 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2247 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2248 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2249 | __ JumpIfSmi(r0, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2250 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2252 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2253 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2254 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | void FullCodeGenerator::EmitIsArray(ZoneList<Expression*>* args) { |
| 2259 | ASSERT(args->length() == 1); |
| 2260 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2261 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2262 | |
| 2263 | Label materialize_true, materialize_false; |
| 2264 | Label* if_true = NULL; |
| 2265 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2266 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2267 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2268 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2269 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2270 | __ JumpIfSmi(r0, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2271 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2273 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2274 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2275 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | |
| 2279 | void FullCodeGenerator::EmitIsRegExp(ZoneList<Expression*>* args) { |
| 2280 | ASSERT(args->length() == 1); |
| 2281 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2282 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2283 | |
| 2284 | Label materialize_true, materialize_false; |
| 2285 | Label* if_true = NULL; |
| 2286 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2287 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2288 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2289 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2290 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2291 | __ JumpIfSmi(r0, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2292 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2293 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2294 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2295 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2296 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | void FullCodeGenerator::EmitIsConstructCall(ZoneList<Expression*>* args) { |
| 2302 | ASSERT(args->length() == 0); |
| 2303 | |
| 2304 | Label materialize_true, materialize_false; |
| 2305 | Label* if_true = NULL; |
| 2306 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2307 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2308 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2309 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2310 | |
| 2311 | // Get the frame pointer for the calling frame. |
| 2312 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2313 | |
| 2314 | // Skip the arguments adaptor frame if it exists. |
| 2315 | Label check_frame_marker; |
| 2316 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2317 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2318 | __ b(ne, &check_frame_marker); |
| 2319 | __ ldr(r2, MemOperand(r2, StandardFrameConstants::kCallerFPOffset)); |
| 2320 | |
| 2321 | // Check the marker in the calling frame. |
| 2322 | __ bind(&check_frame_marker); |
| 2323 | __ ldr(r1, MemOperand(r2, StandardFrameConstants::kMarkerOffset)); |
| 2324 | __ cmp(r1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2325 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2326 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2327 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2328 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | |
| 2332 | void FullCodeGenerator::EmitObjectEquals(ZoneList<Expression*>* args) { |
| 2333 | ASSERT(args->length() == 2); |
| 2334 | |
| 2335 | // Load the two objects into registers and perform the comparison. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2336 | VisitForStackValue(args->at(0)); |
| 2337 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2338 | |
| 2339 | Label materialize_true, materialize_false; |
| 2340 | Label* if_true = NULL; |
| 2341 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2342 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2343 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2344 | &if_true, &if_false, &fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2345 | |
| 2346 | __ pop(r1); |
| 2347 | __ cmp(r0, r1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2348 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2349 | Split(eq, if_true, if_false, fall_through); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2350 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2351 | context()->Plug(if_true, if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2352 | } |
| 2353 | |
| 2354 | |
| 2355 | void FullCodeGenerator::EmitArguments(ZoneList<Expression*>* args) { |
| 2356 | ASSERT(args->length() == 1); |
| 2357 | |
| 2358 | // ArgumentsAccessStub expects the key in edx and the formal |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2359 | // parameter count in r0. |
| 2360 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2361 | __ mov(r1, r0); |
| 2362 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2363 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
| 2364 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2365 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | |
| 2369 | void FullCodeGenerator::EmitArgumentsLength(ZoneList<Expression*>* args) { |
| 2370 | ASSERT(args->length() == 0); |
| 2371 | |
| 2372 | Label exit; |
| 2373 | // Get the number of formal parameters. |
| 2374 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 2375 | |
| 2376 | // Check if the calling frame is an arguments adaptor frame. |
| 2377 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 2378 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 2379 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 2380 | __ b(ne, &exit); |
| 2381 | |
| 2382 | // Arguments adaptor case: Read the arguments length from the |
| 2383 | // adaptor frame. |
| 2384 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2385 | |
| 2386 | __ bind(&exit); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2387 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | |
| 2391 | void FullCodeGenerator::EmitClassOf(ZoneList<Expression*>* args) { |
| 2392 | ASSERT(args->length() == 1); |
| 2393 | Label done, null, function, non_function_constructor; |
| 2394 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2395 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2396 | |
| 2397 | // If the object is a smi, we return null. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2398 | __ JumpIfSmi(r0, &null); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2399 | |
| 2400 | // Check that the object is a JS object but take special care of JS |
| 2401 | // functions to make sure they have 'Function' as their class. |
| 2402 | __ CompareObjectType(r0, r0, r1, FIRST_JS_OBJECT_TYPE); // Map is now in r0. |
| 2403 | __ b(lt, &null); |
| 2404 | |
| 2405 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 2406 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 2407 | // LAST_JS_OBJECT_TYPE. |
| 2408 | ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 2409 | ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
| 2410 | __ cmp(r1, Operand(JS_FUNCTION_TYPE)); |
| 2411 | __ b(eq, &function); |
| 2412 | |
| 2413 | // Check if the constructor in the map is a function. |
| 2414 | __ ldr(r0, FieldMemOperand(r0, Map::kConstructorOffset)); |
| 2415 | __ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE); |
| 2416 | __ b(ne, &non_function_constructor); |
| 2417 | |
| 2418 | // r0 now contains the constructor function. Grab the |
| 2419 | // instance class name from there. |
| 2420 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 2421 | __ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 2422 | __ b(&done); |
| 2423 | |
| 2424 | // Functions have class 'Function'. |
| 2425 | __ bind(&function); |
| 2426 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2427 | __ jmp(&done); |
| 2428 | |
| 2429 | // Objects with a non-function constructor have class 'Object'. |
| 2430 | __ bind(&non_function_constructor); |
| 2431 | __ LoadRoot(r0, Heap::kfunction_class_symbolRootIndex); |
| 2432 | __ jmp(&done); |
| 2433 | |
| 2434 | // Non-JS objects have class null. |
| 2435 | __ bind(&null); |
| 2436 | __ LoadRoot(r0, Heap::kNullValueRootIndex); |
| 2437 | |
| 2438 | // All done. |
| 2439 | __ bind(&done); |
| 2440 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2441 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | void FullCodeGenerator::EmitLog(ZoneList<Expression*>* args) { |
| 2446 | // Conditionally generate a log call. |
| 2447 | // Args: |
| 2448 | // 0 (literal string): The type of logging (corresponds to the flags). |
| 2449 | // This is used to determine whether or not to generate the log call. |
| 2450 | // 1 (string): Format string. Access the string at argument index 2 |
| 2451 | // with '%2s' (see Logger::LogRuntime for all the formats). |
| 2452 | // 2 (array): Arguments to the format string. |
| 2453 | ASSERT_EQ(args->length(), 3); |
| 2454 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 2455 | if (CodeGenerator::ShouldGenerateLog(args->at(0))) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2456 | VisitForStackValue(args->at(1)); |
| 2457 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2458 | __ CallRuntime(Runtime::kLog, 2); |
| 2459 | } |
| 2460 | #endif |
| 2461 | // Finally, we're expected to leave a value on the top of the stack. |
| 2462 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2463 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) { |
| 2468 | ASSERT(args->length() == 0); |
| 2469 | |
| 2470 | Label slow_allocate_heapnumber; |
| 2471 | Label heapnumber_allocated; |
| 2472 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2473 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 2474 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2475 | __ jmp(&heapnumber_allocated); |
| 2476 | |
| 2477 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2478 | // Allocate a heap number. |
| 2479 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2480 | __ mov(r4, Operand(r0)); |
| 2481 | |
| 2482 | __ bind(&heapnumber_allocated); |
| 2483 | |
| 2484 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 2485 | // by computing: |
| 2486 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 2487 | if (CpuFeatures::IsSupported(VFP3)) { |
| 2488 | __ PrepareCallCFunction(0, r1); |
| 2489 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 2490 | |
| 2491 | CpuFeatures::Scope scope(VFP3); |
| 2492 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 2493 | // Create this constant using mov/orr to avoid PC relative load. |
| 2494 | __ mov(r1, Operand(0x41000000)); |
| 2495 | __ orr(r1, r1, Operand(0x300000)); |
| 2496 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 2497 | __ vmov(d7, r0, r1); |
| 2498 | // Move 0x4130000000000000 to VFP. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2499 | __ mov(r0, Operand(0, RelocInfo::NONE)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2500 | __ vmov(d8, r0, r1); |
| 2501 | // Subtract and store the result in the heap number. |
| 2502 | __ vsub(d7, d7, d8); |
| 2503 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 2504 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 2505 | __ mov(r0, r4); |
| 2506 | } else { |
| 2507 | __ mov(r0, Operand(r4)); |
| 2508 | __ PrepareCallCFunction(1, r1); |
| 2509 | __ CallCFunction( |
| 2510 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 2511 | } |
| 2512 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2513 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | |
| 2517 | void FullCodeGenerator::EmitSubString(ZoneList<Expression*>* args) { |
| 2518 | // Load the arguments on the stack and call the stub. |
| 2519 | SubStringStub stub; |
| 2520 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2521 | VisitForStackValue(args->at(0)); |
| 2522 | VisitForStackValue(args->at(1)); |
| 2523 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2524 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2525 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | |
| 2529 | void FullCodeGenerator::EmitRegExpExec(ZoneList<Expression*>* args) { |
| 2530 | // Load the arguments on the stack and call the stub. |
| 2531 | RegExpExecStub stub; |
| 2532 | ASSERT(args->length() == 4); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2533 | VisitForStackValue(args->at(0)); |
| 2534 | VisitForStackValue(args->at(1)); |
| 2535 | VisitForStackValue(args->at(2)); |
| 2536 | VisitForStackValue(args->at(3)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2537 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2538 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | void FullCodeGenerator::EmitValueOf(ZoneList<Expression*>* args) { |
| 2543 | ASSERT(args->length() == 1); |
| 2544 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2545 | VisitForAccumulatorValue(args->at(0)); // Load the object. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2546 | |
| 2547 | Label done; |
| 2548 | // If the object is a smi return the object. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2549 | __ JumpIfSmi(r0, &done); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2550 | // If the object is not a value type, return the object. |
| 2551 | __ CompareObjectType(r0, r1, r1, JS_VALUE_TYPE); |
| 2552 | __ b(ne, &done); |
| 2553 | __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset)); |
| 2554 | |
| 2555 | __ bind(&done); |
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::EmitMathPow(ZoneList<Expression*>* args) { |
| 2561 | // Load the arguments on the stack and call the runtime function. |
| 2562 | ASSERT(args->length() == 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2563 | VisitForStackValue(args->at(0)); |
| 2564 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2565 | __ CallRuntime(Runtime::kMath_pow, 2); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2566 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | |
| 2570 | void FullCodeGenerator::EmitSetValueOf(ZoneList<Expression*>* args) { |
| 2571 | ASSERT(args->length() == 2); |
| 2572 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2573 | VisitForStackValue(args->at(0)); // Load the object. |
| 2574 | VisitForAccumulatorValue(args->at(1)); // Load the value. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2575 | __ pop(r1); // r0 = value. r1 = object. |
| 2576 | |
| 2577 | Label done; |
| 2578 | // If the object is a smi, return the value. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2579 | __ JumpIfSmi(r1, &done); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2580 | |
| 2581 | // If the object is not a value type, return the value. |
| 2582 | __ CompareObjectType(r1, r2, r2, JS_VALUE_TYPE); |
| 2583 | __ b(ne, &done); |
| 2584 | |
| 2585 | // Store the value. |
| 2586 | __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); |
| 2587 | // Update the write barrier. Save the value as it will be |
| 2588 | // overwritten by the write barrier code and is needed afterward. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 2589 | __ RecordWrite(r1, Operand(JSValue::kValueOffset - kHeapObjectTag), r2, r3); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2590 | |
| 2591 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2592 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
| 2595 | |
| 2596 | void FullCodeGenerator::EmitNumberToString(ZoneList<Expression*>* args) { |
| 2597 | ASSERT_EQ(args->length(), 1); |
| 2598 | |
| 2599 | // Load the argument on the stack and call the stub. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2600 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2601 | |
| 2602 | NumberToStringStub stub; |
| 2603 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2604 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
| 2607 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2608 | void FullCodeGenerator::EmitStringCharFromCode(ZoneList<Expression*>* args) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2609 | ASSERT(args->length() == 1); |
| 2610 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2611 | VisitForAccumulatorValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2612 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2613 | Label done; |
| 2614 | StringCharFromCodeGenerator generator(r0, r1); |
| 2615 | generator.GenerateFast(masm_); |
| 2616 | __ jmp(&done); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2617 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2618 | NopRuntimeCallHelper call_helper; |
| 2619 | generator.GenerateSlow(masm_, call_helper); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2620 | |
| 2621 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2622 | context()->Plug(r1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2626 | void FullCodeGenerator::EmitStringCharCodeAt(ZoneList<Expression*>* args) { |
| 2627 | ASSERT(args->length() == 2); |
| 2628 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2629 | VisitForStackValue(args->at(0)); |
| 2630 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2631 | |
| 2632 | Register object = r1; |
| 2633 | Register index = r0; |
| 2634 | Register scratch = r2; |
| 2635 | Register result = r3; |
| 2636 | |
| 2637 | __ pop(object); |
| 2638 | |
| 2639 | Label need_conversion; |
| 2640 | Label index_out_of_range; |
| 2641 | Label done; |
| 2642 | StringCharCodeAtGenerator generator(object, |
| 2643 | index, |
| 2644 | scratch, |
| 2645 | result, |
| 2646 | &need_conversion, |
| 2647 | &need_conversion, |
| 2648 | &index_out_of_range, |
| 2649 | STRING_INDEX_IS_NUMBER); |
| 2650 | generator.GenerateFast(masm_); |
| 2651 | __ jmp(&done); |
| 2652 | |
| 2653 | __ bind(&index_out_of_range); |
| 2654 | // When the index is out of range, the spec requires us to return |
| 2655 | // NaN. |
| 2656 | __ LoadRoot(result, Heap::kNanValueRootIndex); |
| 2657 | __ jmp(&done); |
| 2658 | |
| 2659 | __ bind(&need_conversion); |
| 2660 | // Load the undefined value into the result register, which will |
| 2661 | // trigger conversion. |
| 2662 | __ LoadRoot(result, Heap::kUndefinedValueRootIndex); |
| 2663 | __ jmp(&done); |
| 2664 | |
| 2665 | NopRuntimeCallHelper call_helper; |
| 2666 | generator.GenerateSlow(masm_, call_helper); |
| 2667 | |
| 2668 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2669 | context()->Plug(result); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2670 | } |
| 2671 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2672 | |
| 2673 | void FullCodeGenerator::EmitStringCharAt(ZoneList<Expression*>* args) { |
| 2674 | ASSERT(args->length() == 2); |
| 2675 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2676 | VisitForStackValue(args->at(0)); |
| 2677 | VisitForAccumulatorValue(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2678 | |
| 2679 | Register object = r1; |
| 2680 | Register index = r0; |
| 2681 | Register scratch1 = r2; |
| 2682 | Register scratch2 = r3; |
| 2683 | Register result = r0; |
| 2684 | |
| 2685 | __ pop(object); |
| 2686 | |
| 2687 | Label need_conversion; |
| 2688 | Label index_out_of_range; |
| 2689 | Label done; |
| 2690 | StringCharAtGenerator generator(object, |
| 2691 | index, |
| 2692 | scratch1, |
| 2693 | scratch2, |
| 2694 | result, |
| 2695 | &need_conversion, |
| 2696 | &need_conversion, |
| 2697 | &index_out_of_range, |
| 2698 | STRING_INDEX_IS_NUMBER); |
| 2699 | generator.GenerateFast(masm_); |
| 2700 | __ jmp(&done); |
| 2701 | |
| 2702 | __ bind(&index_out_of_range); |
| 2703 | // When the index is out of range, the spec requires us to return |
| 2704 | // the empty string. |
| 2705 | __ LoadRoot(result, Heap::kEmptyStringRootIndex); |
| 2706 | __ jmp(&done); |
| 2707 | |
| 2708 | __ bind(&need_conversion); |
| 2709 | // Move smi zero into the result register, which will trigger |
| 2710 | // conversion. |
| 2711 | __ mov(result, Operand(Smi::FromInt(0))); |
| 2712 | __ jmp(&done); |
| 2713 | |
| 2714 | NopRuntimeCallHelper call_helper; |
| 2715 | generator.GenerateSlow(masm_, call_helper); |
| 2716 | |
| 2717 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2718 | context()->Plug(result); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2722 | void FullCodeGenerator::EmitStringAdd(ZoneList<Expression*>* args) { |
| 2723 | ASSERT_EQ(2, args->length()); |
| 2724 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2725 | VisitForStackValue(args->at(0)); |
| 2726 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2727 | |
| 2728 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
| 2729 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2730 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | void FullCodeGenerator::EmitStringCompare(ZoneList<Expression*>* args) { |
| 2735 | ASSERT_EQ(2, args->length()); |
| 2736 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2737 | VisitForStackValue(args->at(0)); |
| 2738 | VisitForStackValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2739 | |
| 2740 | StringCompareStub stub; |
| 2741 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2742 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | void FullCodeGenerator::EmitMathSin(ZoneList<Expression*>* args) { |
| 2747 | // Load the argument on the stack and call the runtime. |
| 2748 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2749 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2750 | __ CallRuntime(Runtime::kMath_sin, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2751 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | |
| 2755 | void FullCodeGenerator::EmitMathCos(ZoneList<Expression*>* args) { |
| 2756 | // Load the argument on the stack and call the runtime. |
| 2757 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2758 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2759 | __ CallRuntime(Runtime::kMath_cos, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2760 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | |
| 2764 | void FullCodeGenerator::EmitMathSqrt(ZoneList<Expression*>* args) { |
| 2765 | // Load the argument on the stack and call the runtime function. |
| 2766 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2767 | VisitForStackValue(args->at(0)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2768 | __ CallRuntime(Runtime::kMath_sqrt, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2769 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
| 2772 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2773 | void FullCodeGenerator::EmitMathLog(ZoneList<Expression*>* args) { |
| 2774 | // Load the argument on the stack and call the runtime function. |
| 2775 | ASSERT(args->length() == 1); |
| 2776 | VisitForStackValue(args->at(0)); |
| 2777 | __ CallRuntime(Runtime::kMath_log, 1); |
| 2778 | context()->Plug(r0); |
| 2779 | } |
| 2780 | |
| 2781 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2782 | void FullCodeGenerator::EmitCallFunction(ZoneList<Expression*>* args) { |
| 2783 | ASSERT(args->length() >= 2); |
| 2784 | |
| 2785 | int arg_count = args->length() - 2; // For receiver and function. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2786 | VisitForStackValue(args->at(0)); // Receiver. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2787 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2788 | VisitForStackValue(args->at(i + 1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2789 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2790 | VisitForAccumulatorValue(args->at(arg_count + 1)); // Function. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2791 | |
| 2792 | // InvokeFunction requires function in r1. Move it in there. |
| 2793 | if (!result_register().is(r1)) __ mov(r1, result_register()); |
| 2794 | ParameterCount count(arg_count); |
| 2795 | __ InvokeFunction(r1, count, CALL_FUNCTION); |
| 2796 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2797 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | |
| 2801 | void FullCodeGenerator::EmitRegExpConstructResult(ZoneList<Expression*>* args) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2802 | RegExpConstructResultStub stub; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 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)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2807 | __ CallStub(&stub); |
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::EmitSwapElements(ZoneList<Expression*>* args) { |
| 2813 | ASSERT(args->length() == 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2814 | VisitForStackValue(args->at(0)); |
| 2815 | VisitForStackValue(args->at(1)); |
| 2816 | VisitForStackValue(args->at(2)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2817 | __ CallRuntime(Runtime::kSwapElements, 3); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2818 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | |
| 2822 | void FullCodeGenerator::EmitGetFromCache(ZoneList<Expression*>* args) { |
| 2823 | ASSERT_EQ(2, args->length()); |
| 2824 | |
| 2825 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 2826 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 2827 | |
| 2828 | Handle<FixedArray> jsfunction_result_caches( |
| 2829 | Top::global_context()->jsfunction_result_caches()); |
| 2830 | if (jsfunction_result_caches->length() <= cache_id) { |
| 2831 | __ Abort("Attempt to use undefined cache."); |
| 2832 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2833 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2834 | return; |
| 2835 | } |
| 2836 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2837 | VisitForAccumulatorValue(args->at(1)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2838 | |
| 2839 | Register key = r0; |
| 2840 | Register cache = r1; |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2841 | __ ldr(cache, ContextOperand(cp, Context::GLOBAL_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2842 | __ ldr(cache, FieldMemOperand(cache, GlobalObject::kGlobalContextOffset)); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 2843 | __ ldr(cache, ContextOperand(cache, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2844 | __ ldr(cache, |
| 2845 | FieldMemOperand(cache, FixedArray::OffsetOfElementAt(cache_id))); |
| 2846 | |
| 2847 | |
| 2848 | Label done, not_found; |
| 2849 | // tmp now holds finger offset as a smi. |
| 2850 | ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 2851 | __ ldr(r2, FieldMemOperand(cache, JSFunctionResultCache::kFingerOffset)); |
| 2852 | // r2 now holds finger offset as a smi. |
| 2853 | __ add(r3, cache, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2854 | // r3 now points to the start of fixed array elements. |
| 2855 | __ ldr(r2, MemOperand(r3, r2, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 2856 | // Note side effect of PreIndex: r3 now points to the key of the pair. |
| 2857 | __ cmp(key, r2); |
| 2858 | __ b(ne, ¬_found); |
| 2859 | |
| 2860 | __ ldr(r0, MemOperand(r3, kPointerSize)); |
| 2861 | __ b(&done); |
| 2862 | |
| 2863 | __ bind(¬_found); |
| 2864 | // Call runtime to perform the lookup. |
| 2865 | __ Push(cache, key); |
| 2866 | __ CallRuntime(Runtime::kGetFromCache, 2); |
| 2867 | |
| 2868 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2869 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2873 | void FullCodeGenerator::EmitIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 2874 | ASSERT_EQ(2, args->length()); |
| 2875 | |
| 2876 | Register right = r0; |
| 2877 | Register left = r1; |
| 2878 | Register tmp = r2; |
| 2879 | Register tmp2 = r3; |
| 2880 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2881 | VisitForStackValue(args->at(0)); |
| 2882 | VisitForAccumulatorValue(args->at(1)); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2883 | __ pop(left); |
| 2884 | |
| 2885 | Label done, fail, ok; |
| 2886 | __ cmp(left, Operand(right)); |
| 2887 | __ b(eq, &ok); |
| 2888 | // Fail if either is a non-HeapObject. |
| 2889 | __ and_(tmp, left, Operand(right)); |
| 2890 | __ tst(tmp, Operand(kSmiTagMask)); |
| 2891 | __ b(eq, &fail); |
| 2892 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 2893 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 2894 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 2895 | __ b(ne, &fail); |
| 2896 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 2897 | __ cmp(tmp, Operand(tmp2)); |
| 2898 | __ b(ne, &fail); |
| 2899 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 2900 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 2901 | __ cmp(tmp, tmp2); |
| 2902 | __ b(eq, &ok); |
| 2903 | __ bind(&fail); |
| 2904 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 2905 | __ jmp(&done); |
| 2906 | __ bind(&ok); |
| 2907 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 2908 | __ bind(&done); |
| 2909 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2910 | context()->Plug(r0); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2914 | void FullCodeGenerator::EmitHasCachedArrayIndex(ZoneList<Expression*>* args) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2915 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2916 | |
| 2917 | Label materialize_true, materialize_false; |
| 2918 | Label* if_true = NULL; |
| 2919 | Label* if_false = NULL; |
| 2920 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2921 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 2922 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2923 | |
| 2924 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2925 | __ tst(r0, Operand(String::kContainsCachedArrayIndexMask)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2926 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 2927 | Split(eq, if_true, if_false, fall_through); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2928 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2929 | context()->Plug(if_true, if_false); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | |
| 2933 | void FullCodeGenerator::EmitGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 2934 | ASSERT(args->length() == 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2935 | VisitForAccumulatorValue(args->at(0)); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2936 | __ ldr(r0, FieldMemOperand(r0, String::kHashFieldOffset)); |
| 2937 | __ IndexFromHash(r0, r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2938 | context()->Plug(r0); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 2942 | void FullCodeGenerator::EmitFastAsciiArrayJoin(ZoneList<Expression*>* args) { |
| 2943 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 2944 | context()->Plug(r0); |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2949 | void FullCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2950 | Handle<String> name = expr->name(); |
| 2951 | if (name->length() > 0 && name->Get(0) == '_') { |
| 2952 | Comment cmnt(masm_, "[ InlineRuntimeCall"); |
| 2953 | EmitInlineRuntimeCall(expr); |
| 2954 | return; |
| 2955 | } |
| 2956 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2957 | Comment cmnt(masm_, "[ CallRuntime"); |
| 2958 | ZoneList<Expression*>* args = expr->arguments(); |
| 2959 | |
| 2960 | if (expr->is_jsruntime()) { |
| 2961 | // Prepare for calling JS runtime function. |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2962 | __ ldr(r0, GlobalObjectOperand()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2963 | __ ldr(r0, FieldMemOperand(r0, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2964 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | // Push the arguments ("left-to-right"). |
| 2968 | int arg_count = args->length(); |
| 2969 | for (int i = 0; i < arg_count; i++) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2970 | VisitForStackValue(args->at(i)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | if (expr->is_jsruntime()) { |
| 2974 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2975 | __ mov(r2, Operand(expr->name())); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 2976 | Handle<Code> ic = StubCache::ComputeCallInitialize(arg_count, NOT_IN_LOOP); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2977 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2978 | // Restore context register. |
| 2979 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2980 | } else { |
| 2981 | // Call the C runtime function. |
| 2982 | __ CallRuntime(expr->function(), arg_count); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2983 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2984 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | |
| 2988 | void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { |
| 2989 | switch (expr->op()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2990 | case Token::DELETE: { |
| 2991 | Comment cmnt(masm_, "[ UnaryOperation (DELETE)"); |
| 2992 | Property* prop = expr->expression()->AsProperty(); |
| 2993 | Variable* var = expr->expression()->AsVariableProxy()->AsVariable(); |
| 2994 | if (prop == NULL && var == NULL) { |
| 2995 | // Result of deleting non-property, non-variable reference is true. |
| 2996 | // The subexpression may have side effects. |
| 2997 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2998 | context()->Plug(true); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2999 | } else if (var != NULL && |
| 3000 | !var->is_global() && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3001 | var->AsSlot() != NULL && |
| 3002 | var->AsSlot()->type() != Slot::LOOKUP) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3003 | // Result of deleting non-global, non-dynamic variables is false. |
| 3004 | // The subexpression does not have side effects. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3005 | context()->Plug(false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3006 | } else { |
| 3007 | // Property or variable reference. Call the delete builtin with |
| 3008 | // object and property name as arguments. |
| 3009 | if (prop != NULL) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3010 | VisitForStackValue(prop->obj()); |
| 3011 | VisitForStackValue(prop->key()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3012 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3013 | } else if (var->is_global()) { |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3014 | __ ldr(r1, GlobalObjectOperand()); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3015 | __ mov(r0, Operand(var->name())); |
| 3016 | __ Push(r1, r0); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3017 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3018 | } else { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3019 | // Non-global variable. Call the runtime to delete from the |
| 3020 | // context where the variable was introduced. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3021 | __ push(context_register()); |
| 3022 | __ mov(r2, Operand(var->name())); |
| 3023 | __ push(r2); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 3024 | __ CallRuntime(Runtime::kDeleteContextSlot, 2); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3025 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3026 | context()->Plug(r0); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3027 | } |
| 3028 | break; |
| 3029 | } |
| 3030 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3031 | case Token::VOID: { |
| 3032 | Comment cmnt(masm_, "[ UnaryOperation (VOID)"); |
| 3033 | VisitForEffect(expr->expression()); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3034 | context()->Plug(Heap::kUndefinedValueRootIndex); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3035 | break; |
| 3036 | } |
| 3037 | |
| 3038 | case Token::NOT: { |
| 3039 | Comment cmnt(masm_, "[ UnaryOperation (NOT)"); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3040 | Label materialize_true, materialize_false; |
| 3041 | Label* if_true = NULL; |
| 3042 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3043 | Label* fall_through = NULL; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3044 | |
| 3045 | // Notice that the labels are swapped. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3046 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3047 | &if_false, &if_true, &fall_through); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3048 | if (context()->IsTest()) ForwardBailoutToChild(expr); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3049 | VisitForControl(expr->expression(), if_true, if_false, fall_through); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3050 | context()->Plug(if_false, if_true); // Labels swapped. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3051 | break; |
| 3052 | } |
| 3053 | |
| 3054 | case Token::TYPEOF: { |
| 3055 | Comment cmnt(masm_, "[ UnaryOperation (TYPEOF)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3056 | { StackValueContext context(this); |
| 3057 | VisitForTypeofValue(expr->expression()); |
| 3058 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3059 | __ CallRuntime(Runtime::kTypeof, 1); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3060 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3061 | break; |
| 3062 | } |
| 3063 | |
| 3064 | case Token::ADD: { |
| 3065 | Comment cmt(masm_, "[ UnaryOperation (ADD)"); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3066 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3067 | Label no_conversion; |
| 3068 | __ tst(result_register(), Operand(kSmiTagMask)); |
| 3069 | __ b(eq, &no_conversion); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3070 | ToNumberStub convert_stub; |
| 3071 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3072 | __ bind(&no_conversion); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3073 | context()->Plug(result_register()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3074 | break; |
| 3075 | } |
| 3076 | |
| 3077 | case Token::SUB: { |
| 3078 | Comment cmt(masm_, "[ UnaryOperation (SUB)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3079 | bool can_overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3080 | UnaryOverwriteMode overwrite = |
| 3081 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3082 | GenericUnaryOpStub stub(Token::SUB, |
| 3083 | overwrite, |
| 3084 | NO_UNARY_FLAGS); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3085 | // GenericUnaryOpStub expects the argument to be in the |
| 3086 | // accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3087 | VisitForAccumulatorValue(expr->expression()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3088 | __ CallStub(&stub); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3089 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3090 | break; |
| 3091 | } |
| 3092 | |
| 3093 | case Token::BIT_NOT: { |
| 3094 | Comment cmt(masm_, "[ UnaryOperation (BIT_NOT)"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3095 | // The generic unary operation stub expects the argument to be |
| 3096 | // in the accumulator register r0. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3097 | VisitForAccumulatorValue(expr->expression()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3098 | Label done; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3099 | bool inline_smi_code = ShouldInlineSmiCase(expr->op()); |
| 3100 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3101 | Label call_stub; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3102 | __ JumpIfNotSmi(r0, &call_stub); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3103 | __ mvn(r0, Operand(r0)); |
| 3104 | // Bit-clear inverted smi-tag. |
| 3105 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 3106 | __ b(&done); |
| 3107 | __ bind(&call_stub); |
| 3108 | } |
| 3109 | bool overwrite = expr->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3110 | UnaryOpFlags flags = inline_smi_code |
| 3111 | ? NO_UNARY_SMI_CODE_IN_STUB |
| 3112 | : NO_UNARY_FLAGS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3113 | UnaryOverwriteMode mode = |
| 3114 | overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3115 | GenericUnaryOpStub stub(Token::BIT_NOT, mode, flags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3116 | __ CallStub(&stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3117 | __ bind(&done); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3118 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3119 | break; |
| 3120 | } |
| 3121 | |
| 3122 | default: |
| 3123 | UNREACHABLE(); |
| 3124 | } |
| 3125 | } |
| 3126 | |
| 3127 | |
| 3128 | void FullCodeGenerator::VisitCountOperation(CountOperation* expr) { |
| 3129 | Comment cmnt(masm_, "[ CountOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3130 | SetSourcePosition(expr->position()); |
| 3131 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3132 | // Invalid left-hand sides are rewritten to have a 'throw ReferenceError' |
| 3133 | // as the left-hand side. |
| 3134 | if (!expr->expression()->IsValidLeftHandSide()) { |
| 3135 | VisitForEffect(expr->expression()); |
| 3136 | return; |
| 3137 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3138 | |
| 3139 | // Expression can only be a property, a global or a (parameter or local) |
| 3140 | // slot. Variables with rewrite to .arguments are treated as KEYED_PROPERTY. |
| 3141 | enum LhsKind { VARIABLE, NAMED_PROPERTY, KEYED_PROPERTY }; |
| 3142 | LhsKind assign_type = VARIABLE; |
| 3143 | Property* prop = expr->expression()->AsProperty(); |
| 3144 | // In case of a property we use the uninitialized expression context |
| 3145 | // of the key to detect a named property. |
| 3146 | if (prop != NULL) { |
| 3147 | assign_type = |
| 3148 | (prop->key()->IsPropertyName()) ? NAMED_PROPERTY : KEYED_PROPERTY; |
| 3149 | } |
| 3150 | |
| 3151 | // Evaluate expression and get value. |
| 3152 | if (assign_type == VARIABLE) { |
| 3153 | ASSERT(expr->expression()->AsVariableProxy()->var() != NULL); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3154 | AccumulatorValueContext context(this); |
| 3155 | EmitVariableLoad(expr->expression()->AsVariableProxy()->var()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3156 | } else { |
| 3157 | // Reserve space for result of postfix operation. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3158 | if (expr->is_postfix() && !context()->IsEffect()) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3159 | __ mov(ip, Operand(Smi::FromInt(0))); |
| 3160 | __ push(ip); |
| 3161 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3162 | if (assign_type == NAMED_PROPERTY) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3163 | // Put the object both on the stack and in the accumulator. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3164 | VisitForAccumulatorValue(prop->obj()); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3165 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3166 | EmitNamedPropertyLoad(prop); |
| 3167 | } else { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3168 | if (prop->is_arguments_access()) { |
| 3169 | VariableProxy* obj_proxy = prop->obj()->AsVariableProxy(); |
| 3170 | __ ldr(r0, EmitSlotSearch(obj_proxy->var()->AsSlot(), r0)); |
| 3171 | __ push(r0); |
| 3172 | __ mov(r0, Operand(prop->key()->AsLiteral()->handle())); |
| 3173 | } else { |
| 3174 | VisitForStackValue(prop->obj()); |
| 3175 | VisitForAccumulatorValue(prop->key()); |
| 3176 | } |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3177 | __ ldr(r1, MemOperand(sp, 0)); |
| 3178 | __ push(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3179 | EmitKeyedPropertyLoad(prop); |
| 3180 | } |
| 3181 | } |
| 3182 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3183 | // We need a second deoptimization point after loading the value |
| 3184 | // in case evaluating the property load my have a side effect. |
| 3185 | PrepareForBailout(expr->increment(), TOS_REG); |
| 3186 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3187 | // Call ToNumber only if operand is not a smi. |
| 3188 | Label no_conversion; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3189 | __ JumpIfSmi(r0, &no_conversion); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 3190 | ToNumberStub convert_stub; |
| 3191 | __ CallStub(&convert_stub); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3192 | __ bind(&no_conversion); |
| 3193 | |
| 3194 | // Save result for postfix expressions. |
| 3195 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3196 | if (!context()->IsEffect()) { |
| 3197 | // Save the result on the stack. If we have a named or keyed property |
| 3198 | // we store the result under the receiver that is currently on top |
| 3199 | // of the stack. |
| 3200 | switch (assign_type) { |
| 3201 | case VARIABLE: |
| 3202 | __ push(r0); |
| 3203 | break; |
| 3204 | case NAMED_PROPERTY: |
| 3205 | __ str(r0, MemOperand(sp, kPointerSize)); |
| 3206 | break; |
| 3207 | case KEYED_PROPERTY: |
| 3208 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
| 3209 | break; |
| 3210 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | |
| 3215 | // Inline smi case if we are in a loop. |
| 3216 | Label stub_call, done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3217 | int count_value = expr->op() == Token::INC ? 1 : -1; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3218 | if (ShouldInlineSmiCase(expr->op())) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3219 | __ add(r0, r0, Operand(Smi::FromInt(count_value)), SetCC); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3220 | __ b(vs, &stub_call); |
| 3221 | // We could eliminate this smi check if we split the code at |
| 3222 | // the first smi check before calling ToNumber. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3223 | __ JumpIfSmi(r0, &done); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3224 | __ bind(&stub_call); |
| 3225 | // Call stub. Undo operation first. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3226 | __ sub(r0, r0, Operand(Smi::FromInt(count_value))); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3227 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3228 | __ mov(r1, Operand(Smi::FromInt(count_value))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3229 | |
| 3230 | // Record position before stub call. |
| 3231 | SetSourcePosition(expr->position()); |
| 3232 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3233 | GenericBinaryOpStub stub(Token::ADD, NO_OVERWRITE, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3234 | __ CallStub(&stub); |
| 3235 | __ bind(&done); |
| 3236 | |
| 3237 | // Store the value returned in r0. |
| 3238 | switch (assign_type) { |
| 3239 | case VARIABLE: |
| 3240 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3241 | { EffectContext context(this); |
| 3242 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
| 3243 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3244 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 3245 | context.Plug(r0); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3246 | } |
| 3247 | // For all contexts except EffectConstant We have the result on |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3248 | // top of the stack. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3249 | if (!context()->IsEffect()) { |
| 3250 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3251 | } |
| 3252 | } else { |
| 3253 | EmitVariableAssignment(expr->expression()->AsVariableProxy()->var(), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3254 | Token::ASSIGN); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3255 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
| 3256 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3257 | } |
| 3258 | break; |
| 3259 | case NAMED_PROPERTY: { |
| 3260 | __ mov(r2, Operand(prop->key()->AsLiteral()->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3261 | __ pop(r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3262 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3263 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3264 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3265 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3266 | if (!context()->IsEffect()) { |
| 3267 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3268 | } |
| 3269 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3270 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3271 | } |
| 3272 | break; |
| 3273 | } |
| 3274 | case KEYED_PROPERTY: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3275 | __ pop(r1); // Key. |
| 3276 | __ pop(r2); // Receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3277 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3278 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3279 | PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3280 | if (expr->is_postfix()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3281 | if (!context()->IsEffect()) { |
| 3282 | context()->PlugTOS(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3283 | } |
| 3284 | } else { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3285 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3286 | } |
| 3287 | break; |
| 3288 | } |
| 3289 | } |
| 3290 | } |
| 3291 | |
| 3292 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3293 | void FullCodeGenerator::VisitForTypeofValue(Expression* expr) { |
| 3294 | ASSERT(!context()->IsEffect()); |
| 3295 | ASSERT(!context()->IsTest()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3296 | VariableProxy* proxy = expr->AsVariableProxy(); |
| 3297 | if (proxy != NULL && !proxy->var()->is_this() && proxy->var()->is_global()) { |
| 3298 | Comment cmnt(masm_, "Global variable"); |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 3299 | __ ldr(r0, GlobalObjectOperand()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3300 | __ mov(r2, Operand(proxy->name())); |
| 3301 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 3302 | // Use a regular load, not a contextual load, to avoid a reference |
| 3303 | // error. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3304 | EmitCallIC(ic, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3305 | PrepareForBailout(expr, TOS_REG); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3306 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3307 | } else if (proxy != NULL && |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3308 | proxy->var()->AsSlot() != NULL && |
| 3309 | proxy->var()->AsSlot()->type() == Slot::LOOKUP) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3310 | Label done, slow; |
| 3311 | |
| 3312 | // Generate code for loading from variables potentially shadowed |
| 3313 | // by eval-introduced variables. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3314 | Slot* slot = proxy->var()->AsSlot(); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3315 | EmitDynamicLoadFromSlotFastCase(slot, INSIDE_TYPEOF, &slow, &done); |
| 3316 | |
| 3317 | __ bind(&slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3318 | __ mov(r0, Operand(proxy->name())); |
| 3319 | __ Push(cp, r0); |
| 3320 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3321 | PrepareForBailout(expr, TOS_REG); |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3322 | __ bind(&done); |
| 3323 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3324 | context()->Plug(r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3325 | } else { |
| 3326 | // This expression cannot throw a reference error at the top level. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3327 | context()->HandleExpression(expr); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3332 | bool FullCodeGenerator::TryLiteralCompare(Token::Value op, |
| 3333 | Expression* left, |
| 3334 | Expression* right, |
| 3335 | Label* if_true, |
| 3336 | Label* if_false, |
| 3337 | Label* fall_through) { |
| 3338 | if (op != Token::EQ && op != Token::EQ_STRICT) return false; |
| 3339 | |
| 3340 | // Check for the pattern: typeof <expression> == <string literal>. |
| 3341 | Literal* right_literal = right->AsLiteral(); |
| 3342 | if (right_literal == NULL) return false; |
| 3343 | Handle<Object> right_literal_value = right_literal->handle(); |
| 3344 | if (!right_literal_value->IsString()) return false; |
| 3345 | UnaryOperation* left_unary = left->AsUnaryOperation(); |
| 3346 | if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false; |
| 3347 | Handle<String> check = Handle<String>::cast(right_literal_value); |
| 3348 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3349 | { AccumulatorValueContext context(this); |
| 3350 | VisitForTypeofValue(left_unary->expression()); |
| 3351 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3352 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
| 3353 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3354 | if (check->Equals(Heap::number_symbol())) { |
| 3355 | __ tst(r0, Operand(kSmiTagMask)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3356 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3357 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3358 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
| 3359 | __ cmp(r0, ip); |
| 3360 | Split(eq, if_true, if_false, fall_through); |
| 3361 | } else if (check->Equals(Heap::string_symbol())) { |
| 3362 | __ tst(r0, Operand(kSmiTagMask)); |
| 3363 | __ b(eq, if_false); |
| 3364 | // Check for undetectable objects => false. |
| 3365 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3366 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3367 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3368 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3369 | __ b(eq, if_false); |
| 3370 | __ ldrb(r1, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 3371 | __ cmp(r1, Operand(FIRST_NONSTRING_TYPE)); |
| 3372 | Split(lt, if_true, if_false, fall_through); |
| 3373 | } else if (check->Equals(Heap::boolean_symbol())) { |
| 3374 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3375 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3376 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3377 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 3378 | __ cmp(r0, ip); |
| 3379 | Split(eq, if_true, if_false, fall_through); |
| 3380 | } else if (check->Equals(Heap::undefined_symbol())) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3381 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3382 | __ cmp(r0, ip); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3383 | __ b(eq, if_true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3384 | __ tst(r0, Operand(kSmiTagMask)); |
| 3385 | __ b(eq, if_false); |
| 3386 | // Check for undetectable objects => true. |
| 3387 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3388 | __ ldrb(r1, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3389 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3390 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3391 | Split(eq, if_true, if_false, fall_through); |
| 3392 | } else if (check->Equals(Heap::function_symbol())) { |
| 3393 | __ tst(r0, Operand(kSmiTagMask)); |
| 3394 | __ b(eq, if_false); |
| 3395 | __ CompareObjectType(r0, r1, r0, JS_FUNCTION_TYPE); |
| 3396 | __ b(eq, if_true); |
| 3397 | // Regular expressions => 'function' (they are callable). |
| 3398 | __ CompareInstanceType(r1, r0, JS_REGEXP_TYPE); |
| 3399 | Split(eq, if_true, if_false, fall_through); |
| 3400 | } else if (check->Equals(Heap::object_symbol())) { |
| 3401 | __ tst(r0, Operand(kSmiTagMask)); |
| 3402 | __ b(eq, if_false); |
| 3403 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 3404 | __ cmp(r0, ip); |
| 3405 | __ b(eq, if_true); |
| 3406 | // Regular expressions => 'function', not 'object'. |
| 3407 | __ CompareObjectType(r0, r1, r0, JS_REGEXP_TYPE); |
| 3408 | __ b(eq, if_false); |
| 3409 | // Check for undetectable objects => false. |
| 3410 | __ ldrb(r0, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3411 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 3412 | __ cmp(r0, Operand(1 << Map::kIsUndetectable)); |
| 3413 | __ b(eq, if_false); |
| 3414 | // Check for JS objects => true. |
| 3415 | __ ldrb(r0, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 3416 | __ cmp(r0, Operand(FIRST_JS_OBJECT_TYPE)); |
| 3417 | __ b(lt, if_false); |
| 3418 | __ cmp(r0, Operand(LAST_JS_OBJECT_TYPE)); |
| 3419 | Split(le, if_true, if_false, fall_through); |
| 3420 | } else { |
| 3421 | if (if_false != fall_through) __ jmp(if_false); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3422 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | |
| 3424 | return true; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3428 | void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 3429 | Comment cmnt(masm_, "[ CompareOperation"); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | SetSourcePosition(expr->position()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3431 | |
| 3432 | // Always perform the comparison for its control flow. Pack the result |
| 3433 | // into the expression's context after the comparison is performed. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 3434 | |
| 3435 | Label materialize_true, materialize_false; |
| 3436 | Label* if_true = NULL; |
| 3437 | Label* if_false = NULL; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3438 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3439 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3440 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3441 | |
| 3442 | // First we try a fast inlined version of the compare when one of |
| 3443 | // the operands is a literal. |
| 3444 | Token::Value op = expr->op(); |
| 3445 | Expression* left = expr->left(); |
| 3446 | Expression* right = expr->right(); |
| 3447 | if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3448 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3449 | return; |
| 3450 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3451 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3452 | VisitForStackValue(expr->left()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3453 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3454 | case Token::IN: |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3455 | VisitForStackValue(expr->right()); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3456 | __ InvokeBuiltin(Builtins::IN, CALL_JS); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3457 | PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3458 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 3459 | __ cmp(r0, ip); |
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 | case Token::INSTANCEOF: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3464 | VisitForStackValue(expr->right()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3465 | InstanceofStub stub(InstanceofStub::kNoFlags); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3466 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3467 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3468 | // The stub returns 0 for true. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3469 | __ tst(r0, r0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3470 | Split(eq, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3471 | break; |
| 3472 | } |
| 3473 | |
| 3474 | default: { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3475 | VisitForAccumulatorValue(expr->right()); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3476 | Condition cond = eq; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3477 | bool strict = false; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3478 | switch (op) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3479 | case Token::EQ_STRICT: |
| 3480 | strict = true; |
| 3481 | // Fall through |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3482 | case Token::EQ: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3483 | cond = eq; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3484 | __ pop(r1); |
| 3485 | break; |
| 3486 | case Token::LT: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3487 | cond = lt; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3488 | __ pop(r1); |
| 3489 | break; |
| 3490 | case Token::GT: |
| 3491 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3492 | cond = lt; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3493 | __ mov(r1, result_register()); |
| 3494 | __ pop(r0); |
| 3495 | break; |
| 3496 | case Token::LTE: |
| 3497 | // Reverse left and right sides to obtain ECMA-262 conversion order. |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3498 | cond = ge; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3499 | __ mov(r1, result_register()); |
| 3500 | __ pop(r0); |
| 3501 | break; |
| 3502 | case Token::GTE: |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3503 | cond = ge; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3504 | __ pop(r1); |
| 3505 | break; |
| 3506 | case Token::IN: |
| 3507 | case Token::INSTANCEOF: |
| 3508 | default: |
| 3509 | UNREACHABLE(); |
| 3510 | } |
| 3511 | |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3512 | bool inline_smi_code = ShouldInlineSmiCase(op); |
| 3513 | if (inline_smi_code) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3514 | Label slow_case; |
| 3515 | __ orr(r2, r0, Operand(r1)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3516 | __ JumpIfNotSmi(r2, &slow_case); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3517 | __ cmp(r1, r0); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3518 | Split(cond, if_true, if_false, NULL); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3519 | __ bind(&slow_case); |
| 3520 | } |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3521 | CompareFlags flags = inline_smi_code |
| 3522 | ? NO_SMI_COMPARE_IN_STUB |
| 3523 | : NO_COMPARE_FLAGS; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3524 | CompareStub stub(cond, strict, flags, r1, r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3525 | __ CallStub(&stub); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3526 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 3527 | __ cmp(r0, Operand(0, RelocInfo::NONE)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 3528 | Split(cond, if_true, if_false, fall_through); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3529 | } |
| 3530 | } |
| 3531 | |
| 3532 | // Convert the result of the comparison into one expected for this |
| 3533 | // expression's context. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3534 | context()->Plug(if_true, if_false); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3538 | void FullCodeGenerator::VisitCompareToNull(CompareToNull* expr) { |
| 3539 | Comment cmnt(masm_, "[ CompareToNull"); |
| 3540 | Label materialize_true, materialize_false; |
| 3541 | Label* if_true = NULL; |
| 3542 | Label* if_false = NULL; |
| 3543 | Label* fall_through = NULL; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3544 | context()->PrepareTest(&materialize_true, &materialize_false, |
| 3545 | &if_true, &if_false, &fall_through); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3546 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3547 | VisitForAccumulatorValue(expr->expression()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3548 | PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3549 | __ LoadRoot(r1, Heap::kNullValueRootIndex); |
| 3550 | __ cmp(r0, r1); |
| 3551 | if (expr->is_strict()) { |
| 3552 | Split(eq, if_true, if_false, fall_through); |
| 3553 | } else { |
| 3554 | __ b(eq, if_true); |
| 3555 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 3556 | __ cmp(r0, r1); |
| 3557 | __ b(eq, if_true); |
| 3558 | __ tst(r0, Operand(kSmiTagMask)); |
| 3559 | __ b(eq, if_false); |
| 3560 | // It can be an undetectable object. |
| 3561 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3562 | __ ldrb(r1, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3563 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3564 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3565 | Split(eq, if_true, if_false, fall_through); |
| 3566 | } |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3567 | context()->Plug(if_true, if_false); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3568 | } |
| 3569 | |
| 3570 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3571 | void FullCodeGenerator::VisitThisFunction(ThisFunction* expr) { |
| 3572 | __ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3573 | context()->Plug(r0); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3574 | } |
| 3575 | |
| 3576 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3577 | Register FullCodeGenerator::result_register() { |
| 3578 | return r0; |
| 3579 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3580 | |
| 3581 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 3582 | Register FullCodeGenerator::context_register() { |
| 3583 | return cp; |
| 3584 | } |
| 3585 | |
| 3586 | |
| 3587 | void FullCodeGenerator::EmitCallIC(Handle<Code> ic, RelocInfo::Mode mode) { |
| 3588 | ASSERT(mode == RelocInfo::CODE_TARGET || |
| 3589 | mode == RelocInfo::CODE_TARGET_CONTEXT); |
| 3590 | __ Call(ic, mode); |
| 3591 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3592 | |
| 3593 | |
| 3594 | void FullCodeGenerator::StoreToFrameField(int frame_offset, Register value) { |
| 3595 | ASSERT_EQ(POINTER_SIZE_ALIGN(frame_offset), frame_offset); |
| 3596 | __ str(value, MemOperand(fp, frame_offset)); |
| 3597 | } |
| 3598 | |
| 3599 | |
| 3600 | void FullCodeGenerator::LoadContextField(Register dst, int context_index) { |
sgjesse@chromium.org | 2ec107f | 2010-09-13 09:19:46 +0000 | [diff] [blame] | 3601 | __ ldr(dst, ContextOperand(cp, context_index)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | |
| 3605 | // ---------------------------------------------------------------------------- |
| 3606 | // Non-local control flow support. |
| 3607 | |
| 3608 | void FullCodeGenerator::EnterFinallyBlock() { |
| 3609 | ASSERT(!result_register().is(r1)); |
| 3610 | // Store result register while executing finally block. |
| 3611 | __ push(result_register()); |
| 3612 | // Cook return address in link register to stack (smi encoded Code* delta) |
| 3613 | __ sub(r1, lr, Operand(masm_->CodeObject())); |
| 3614 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3615 | ASSERT_EQ(0, kSmiTag); |
| 3616 | __ add(r1, r1, Operand(r1)); // Convert to smi. |
| 3617 | __ push(r1); |
| 3618 | } |
| 3619 | |
| 3620 | |
| 3621 | void FullCodeGenerator::ExitFinallyBlock() { |
| 3622 | ASSERT(!result_register().is(r1)); |
| 3623 | // Restore result register from stack. |
| 3624 | __ pop(r1); |
| 3625 | // Uncook return address and return. |
| 3626 | __ pop(result_register()); |
| 3627 | ASSERT_EQ(1, kSmiTagSize + kSmiShiftSize); |
| 3628 | __ mov(r1, Operand(r1, ASR, 1)); // Un-smi-tag value. |
| 3629 | __ add(pc, r1, Operand(masm_->CodeObject())); |
| 3630 | } |
| 3631 | |
| 3632 | |
| 3633 | #undef __ |
| 3634 | |
| 3635 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 3636 | |
| 3637 | #endif // V8_TARGET_ARCH_ARM |