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