sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "bootstrapper.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame^] | 33 | #include "code-stubs.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "codegen-inl.h" |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 35 | #include "compiler.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | #include "debug.h" |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 37 | #include "ic-inl.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 38 | #include "jsregexp.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 39 | #include "jump-target-light-inl.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 40 | #include "parser.h" |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 41 | #include "regexp-macro-assembler.h" |
| 42 | #include "regexp-stack.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 43 | #include "register-allocator-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "runtime.h" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 45 | #include "scopes.h" |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 46 | #include "virtual-frame-inl.h" |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 47 | #include "virtual-frame-arm-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 49 | namespace v8 { |
| 50 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 51 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 52 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 53 | #define __ ACCESS_MASM(masm_) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 54 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 55 | // ------------------------------------------------------------------------- |
| 56 | // Platform-specific DeferredCode functions. |
| 57 | |
| 58 | void DeferredCode::SaveRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 59 | // On ARM you either have a completely spilled frame or you |
| 60 | // handle it yourself, but at the moment there's no automation |
| 61 | // of registers and deferred code. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | void DeferredCode::RestoreRegisters() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | |
| 69 | // ------------------------------------------------------------------------- |
| 70 | // Platform-specific RuntimeCallHelper functions. |
| 71 | |
| 72 | void VirtualFrameRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 73 | frame_state_->frame()->AssertIsSpilled(); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | void VirtualFrameRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 78 | } |
| 79 | |
| 80 | |
| 81 | void ICRuntimeCallHelper::BeforeCall(MacroAssembler* masm) const { |
| 82 | masm->EnterInternalFrame(); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void ICRuntimeCallHelper::AfterCall(MacroAssembler* masm) const { |
| 87 | masm->LeaveInternalFrame(); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 88 | } |
| 89 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 90 | |
| 91 | // ------------------------------------------------------------------------- |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 92 | // CodeGenState implementation. |
| 93 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 94 | CodeGenState::CodeGenState(CodeGenerator* owner) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 95 | : owner_(owner), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 96 | previous_(owner->state()) { |
| 97 | owner->set_state(this); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 101 | ConditionCodeGenState::ConditionCodeGenState(CodeGenerator* owner, |
| 102 | JumpTarget* true_target, |
| 103 | JumpTarget* false_target) |
| 104 | : CodeGenState(owner), |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 105 | true_target_(true_target), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 106 | false_target_(false_target) { |
| 107 | owner->set_state(this); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | TypeInfoCodeGenState::TypeInfoCodeGenState(CodeGenerator* owner, |
| 112 | Slot* slot, |
| 113 | TypeInfo type_info) |
| 114 | : CodeGenState(owner), |
| 115 | slot_(slot) { |
| 116 | owner->set_state(this); |
| 117 | old_type_info_ = owner->set_type_info(slot, type_info); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 121 | CodeGenState::~CodeGenState() { |
| 122 | ASSERT(owner_->state() == this); |
| 123 | owner_->set_state(previous_); |
| 124 | } |
| 125 | |
| 126 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 127 | TypeInfoCodeGenState::~TypeInfoCodeGenState() { |
| 128 | owner()->set_type_info(slot_, old_type_info_); |
| 129 | } |
| 130 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 131 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 132 | // CodeGenerator implementation |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 133 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 134 | int CodeGenerator::inlined_write_barrier_size_ = -1; |
| 135 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 136 | CodeGenerator::CodeGenerator(MacroAssembler* masm) |
| 137 | : deferred_(8), |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 138 | masm_(masm), |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 139 | info_(NULL), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 140 | frame_(NULL), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 141 | allocator_(NULL), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 142 | cc_reg_(al), |
| 143 | state_(NULL), |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 144 | loop_nesting_(0), |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 145 | type_info_(NULL), |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 146 | function_return_(JumpTarget::BIDIRECTIONAL), |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 147 | function_return_is_shadowed_(false) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | // Calling conventions: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 152 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 154 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | // cp: callee's context |
| 156 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 157 | void CodeGenerator::Generate(CompilationInfo* info) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 158 | // Record the position for debugging purposes. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 159 | CodeForFunctionPosition(info->function()); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 160 | Comment cmnt(masm_, "[ function compiled by virtual frame code generator"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 161 | |
| 162 | // Initialize state. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 163 | info_ = info; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 164 | |
| 165 | int slots = scope()->num_parameters() + scope()->num_stack_slots(); |
| 166 | ScopedVector<TypeInfo> type_info_array(slots); |
| 167 | type_info_ = &type_info_array; |
| 168 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 169 | ASSERT(allocator_ == NULL); |
| 170 | RegisterAllocator register_allocator(this); |
| 171 | allocator_ = ®ister_allocator; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 172 | ASSERT(frame_ == NULL); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 173 | frame_ = new VirtualFrame(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 174 | cc_reg_ = al; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 175 | |
| 176 | // Adjust for function-level loop nesting. |
| 177 | ASSERT_EQ(0, loop_nesting_); |
| 178 | loop_nesting_ = info->loop_nesting(); |
| 179 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 180 | { |
| 181 | CodeGenState state(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 182 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 183 | // Entry: |
| 184 | // Stack: receiver, arguments |
| 185 | // lr: return address |
| 186 | // fp: caller's frame pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | // sp: stack pointer |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 188 | // r1: called JS function |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 189 | // cp: callee's context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 190 | allocator_->Initialize(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 191 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 192 | #ifdef DEBUG |
| 193 | if (strlen(FLAG_stop_at) > 0 && |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 194 | info->function()->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 195 | frame_->SpillAll(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 196 | __ stop("stop-at"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 197 | } |
| 198 | #endif |
| 199 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 200 | frame_->Enter(); |
| 201 | // tos: code slot |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 202 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 203 | // Allocate space for locals and initialize them. This also checks |
| 204 | // for stack overflow. |
| 205 | frame_->AllocateStackSlots(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 206 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 207 | frame_->AssertIsSpilled(); |
| 208 | int heap_slots = scope()->num_heap_slots() - Context::MIN_CONTEXT_SLOTS; |
| 209 | if (heap_slots > 0) { |
| 210 | // Allocate local context. |
| 211 | // Get outer context and create a new context based on it. |
| 212 | __ ldr(r0, frame_->Function()); |
| 213 | frame_->EmitPush(r0); |
| 214 | if (heap_slots <= FastNewContextStub::kMaximumSlots) { |
| 215 | FastNewContextStub stub(heap_slots); |
| 216 | frame_->CallStub(&stub, 1); |
| 217 | } else { |
| 218 | frame_->CallRuntime(Runtime::kNewContext, 1); |
| 219 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 220 | |
| 221 | #ifdef DEBUG |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 222 | JumpTarget verified_true; |
| 223 | __ cmp(r0, cp); |
| 224 | verified_true.Branch(eq); |
| 225 | __ stop("NewContext: r0 is expected to be the same as cp"); |
| 226 | verified_true.Bind(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 227 | #endif |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 228 | // Update context local. |
| 229 | __ str(cp, frame_->Context()); |
| 230 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 231 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 232 | // TODO(1241774): Improve this code: |
| 233 | // 1) only needed if we have a context |
| 234 | // 2) no need to recompute context ptr every single time |
| 235 | // 3) don't copy parameter operand code from SlotOperand! |
| 236 | { |
| 237 | Comment cmnt2(masm_, "[ copy context parameters into .context"); |
| 238 | // Note that iteration order is relevant here! If we have the same |
| 239 | // parameter twice (e.g., function (x, y, x)), and that parameter |
| 240 | // needs to be copied into the context, it must be the last argument |
| 241 | // passed to the parameter that needs to be copied. This is a rare |
| 242 | // case so we don't check for it, instead we rely on the copying |
| 243 | // order: such a parameter is copied repeatedly into the same |
| 244 | // context location and thus the last value is what is seen inside |
| 245 | // the function. |
| 246 | frame_->AssertIsSpilled(); |
| 247 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 248 | Variable* par = scope()->parameter(i); |
| 249 | Slot* slot = par->slot(); |
| 250 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
| 251 | ASSERT(!scope()->is_global_scope()); // No params in global scope. |
| 252 | __ ldr(r1, frame_->ParameterAt(i)); |
| 253 | // Loads r2 with context; used below in RecordWrite. |
| 254 | __ str(r1, SlotOperand(slot, r2)); |
| 255 | // Load the offset into r3. |
| 256 | int slot_offset = |
| 257 | FixedArray::kHeaderSize + slot->index() * kPointerSize; |
| 258 | __ RecordWrite(r2, Operand(slot_offset), r3, r1); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 261 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 262 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 263 | // Store the arguments object. This must happen after context |
| 264 | // initialization because the arguments object may be stored in |
| 265 | // the context. |
| 266 | if (ArgumentsMode() != NO_ARGUMENTS_ALLOCATION) { |
| 267 | StoreArgumentsObject(true); |
| 268 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 269 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 270 | // Initialize ThisFunction reference if present. |
| 271 | if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 272 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
| 273 | StoreToSlot(scope()->function()->slot(), NOT_CONST_INIT); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 274 | } |
| 275 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 276 | // Initialize the function return target after the locals are set |
| 277 | // up, because it needs the expected frame height from the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 278 | function_return_.SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 279 | function_return_is_shadowed_ = false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 280 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 281 | // Generate code to 'execute' declarations and initialize functions |
| 282 | // (source elements). In case of an illegal redeclaration we need to |
| 283 | // handle that instead of processing the declarations. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 284 | if (scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 285 | Comment cmnt(masm_, "[ illegal redeclarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 286 | scope()->VisitIllegalRedeclaration(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | } else { |
| 288 | Comment cmnt(masm_, "[ declarations"); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 289 | ProcessDeclarations(scope()->declarations()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 290 | // Bail out if a stack-overflow exception occurred when processing |
| 291 | // declarations. |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 292 | if (HasStackOverflow()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 293 | } |
| 294 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 295 | if (FLAG_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 296 | frame_->CallRuntime(Runtime::kTraceEnter, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 297 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 298 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | |
| 300 | // Compile the body of the function in a vanilla state. Don't |
| 301 | // bother compiling all the code if the scope has an illegal |
| 302 | // redeclaration. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 303 | if (!scope()->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 304 | Comment cmnt(masm_, "[ function body"); |
| 305 | #ifdef DEBUG |
| 306 | bool is_builtin = Bootstrapper::IsActive(); |
| 307 | bool should_trace = |
| 308 | is_builtin ? FLAG_trace_builtin_calls : FLAG_trace_calls; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 309 | if (should_trace) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 310 | frame_->CallRuntime(Runtime::kDebugTrace, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 311 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 312 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 313 | #endif |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 314 | VisitStatements(info->function()->body()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 315 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | } |
| 317 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 318 | // Handle the return from the function. |
| 319 | if (has_valid_frame()) { |
| 320 | // If there is a valid frame, control flow can fall off the end of |
| 321 | // the body. In that case there is an implicit return statement. |
| 322 | ASSERT(!function_return_is_shadowed_); |
| 323 | frame_->PrepareForReturn(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 324 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 325 | if (function_return_.is_bound()) { |
| 326 | function_return_.Jump(); |
| 327 | } else { |
| 328 | function_return_.Bind(); |
| 329 | GenerateReturnSequence(); |
| 330 | } |
| 331 | } else if (function_return_.is_linked()) { |
| 332 | // If the return target has dangling jumps to it, then we have not |
| 333 | // yet generated the return sequence. This can happen when (a) |
| 334 | // control does not flow off the end of the body so we did not |
| 335 | // compile an artificial return statement just above, and (b) there |
| 336 | // are return statements in the body but (c) they are all shadowed. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 337 | function_return_.Bind(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 338 | GenerateReturnSequence(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 339 | } |
| 340 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 341 | // Adjust for function-level loop nesting. |
| 342 | ASSERT(loop_nesting_ == info->loop_nesting()); |
| 343 | loop_nesting_ = 0; |
| 344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 345 | // Code generation state must be reset. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 346 | ASSERT(!has_cc()); |
| 347 | ASSERT(state_ == NULL); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 348 | ASSERT(loop_nesting() == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 349 | ASSERT(!function_return_is_shadowed_); |
| 350 | function_return_.Unuse(); |
| 351 | DeleteFrame(); |
| 352 | |
| 353 | // Process any deferred code using the register allocator. |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 354 | if (!HasStackOverflow()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 355 | ProcessDeferred(); |
| 356 | } |
| 357 | |
| 358 | allocator_ = NULL; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 359 | type_info_ = NULL; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | int CodeGenerator::NumberOfSlot(Slot* slot) { |
| 364 | if (slot == NULL) return kInvalidSlotNumber; |
| 365 | switch (slot->type()) { |
| 366 | case Slot::PARAMETER: |
| 367 | return slot->index(); |
| 368 | case Slot::LOCAL: |
| 369 | return slot->index() + scope()->num_parameters(); |
| 370 | default: |
| 371 | break; |
| 372 | } |
| 373 | return kInvalidSlotNumber; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 377 | MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) { |
| 378 | // Currently, this assertion will fail if we try to assign to |
| 379 | // a constant variable that is constant because it is read-only |
| 380 | // (such as the variable referring to a named function expression). |
| 381 | // We need to implement assignments to read-only variables. |
| 382 | // Ideally, we should do this during AST generation (by converting |
| 383 | // such assignments into expression statements); however, in general |
| 384 | // we may not be able to make the decision until past AST generation, |
| 385 | // that is when the entire program is known. |
| 386 | ASSERT(slot != NULL); |
| 387 | int index = slot->index(); |
| 388 | switch (slot->type()) { |
| 389 | case Slot::PARAMETER: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 390 | return frame_->ParameterAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 391 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 392 | case Slot::LOCAL: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 393 | return frame_->LocalAt(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 394 | |
| 395 | case Slot::CONTEXT: { |
| 396 | // Follow the context chain if necessary. |
| 397 | ASSERT(!tmp.is(cp)); // do not overwrite context register |
| 398 | Register context = cp; |
| 399 | int chain_length = scope()->ContextChainLength(slot->var()->scope()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 400 | for (int i = 0; i < chain_length; i++) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 401 | // Load the closure. |
| 402 | // (All contexts, even 'with' contexts, have a closure, |
| 403 | // and it is the same for all contexts inside a function. |
| 404 | // There is no need to go to the function context first.) |
| 405 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 406 | // Load the function context (which is the incoming, outer context). |
| 407 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 408 | context = tmp; |
| 409 | } |
| 410 | // We may have a 'with' context now. Get the function context. |
| 411 | // (In fact this mov may never be the needed, since the scope analysis |
| 412 | // may not permit a direct context access in this case and thus we are |
| 413 | // always at a function context. However it is safe to dereference be- |
| 414 | // cause the function context of a function context is itself. Before |
| 415 | // deleting this mov we should try to create a counter-example first, |
| 416 | // though...) |
| 417 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
| 418 | return ContextOperand(tmp, index); |
| 419 | } |
| 420 | |
| 421 | default: |
| 422 | UNREACHABLE(); |
| 423 | return MemOperand(r0, 0); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 428 | MemOperand CodeGenerator::ContextSlotOperandCheckExtensions( |
| 429 | Slot* slot, |
| 430 | Register tmp, |
| 431 | Register tmp2, |
| 432 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 433 | ASSERT(slot->type() == Slot::CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 434 | Register context = cp; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 435 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 436 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 437 | if (s->num_heap_slots() > 0) { |
| 438 | if (s->calls_eval()) { |
| 439 | // Check that extension is NULL. |
| 440 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 441 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 442 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 443 | } |
| 444 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 445 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 446 | context = tmp; |
| 447 | } |
| 448 | } |
| 449 | // Check that last extension is NULL. |
| 450 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 451 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 452 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 453 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 454 | return ContextOperand(tmp, slot->index()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 458 | // Loads a value on TOS. If it is a boolean value, the result may have been |
| 459 | // (partially) translated into branches, or it may have set the condition |
| 460 | // code register. If force_cc is set, the value is forced to set the |
| 461 | // condition code register and no value is pushed. If the condition code |
| 462 | // register was set, has_cc() is true and cc_reg_ contains the condition to |
| 463 | // test for 'true'. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 464 | void CodeGenerator::LoadCondition(Expression* x, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 465 | JumpTarget* true_target, |
| 466 | JumpTarget* false_target, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 467 | bool force_cc) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 468 | ASSERT(!has_cc()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 469 | int original_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 470 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 471 | { ConditionCodeGenState new_state(this, true_target, false_target); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 472 | Visit(x); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 473 | |
| 474 | // If we hit a stack overflow, we may not have actually visited |
| 475 | // the expression. In that case, we ensure that we have a |
| 476 | // valid-looking frame state because we will continue to generate |
| 477 | // code as we unwind the C++ stack. |
| 478 | // |
| 479 | // It's possible to have both a stack overflow and a valid frame |
| 480 | // state (eg, a subexpression overflowed, visiting it returned |
| 481 | // with a dummied frame state, and visiting this expression |
| 482 | // returned with a normal-looking state). |
| 483 | if (HasStackOverflow() && |
| 484 | has_valid_frame() && |
| 485 | !has_cc() && |
| 486 | frame_->height() == original_height) { |
| 487 | true_target->Jump(); |
| 488 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 489 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 490 | if (force_cc && frame_ != NULL && !has_cc()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 491 | // Convert the TOS value to a boolean in the condition code register. |
| 492 | ToBoolean(true_target, false_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 494 | ASSERT(!force_cc || !has_valid_frame() || has_cc()); |
| 495 | ASSERT(!has_valid_frame() || |
| 496 | (has_cc() && frame_->height() == original_height) || |
| 497 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 501 | void CodeGenerator::Load(Expression* expr) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 502 | // We generally assume that we are not in a spilled scope for most |
| 503 | // of the code generator. A failure to ensure this caused issue 815 |
| 504 | // and this assert is designed to catch similar issues. |
| 505 | frame_->AssertIsNotSpilled(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 506 | #ifdef DEBUG |
| 507 | int original_height = frame_->height(); |
| 508 | #endif |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 509 | JumpTarget true_target; |
| 510 | JumpTarget false_target; |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 511 | LoadCondition(expr, &true_target, &false_target, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | |
| 513 | if (has_cc()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 514 | // Convert cc_reg_ into a boolean value. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 515 | JumpTarget loaded; |
| 516 | JumpTarget materialize_true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 517 | materialize_true.Branch(cc_reg_); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 518 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 519 | loaded.Jump(); |
| 520 | materialize_true.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 521 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 522 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | cc_reg_ = al; |
| 524 | } |
| 525 | |
| 526 | if (true_target.is_linked() || false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 527 | // We have at least one condition value that has been "translated" |
| 528 | // into a branch, thus it needs to be loaded explicitly. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 529 | JumpTarget loaded; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 530 | if (frame_ != NULL) { |
| 531 | loaded.Jump(); // Don't lose the current TOS. |
| 532 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | bool both = true_target.is_linked() && false_target.is_linked(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 534 | // Load "true" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 535 | if (true_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 536 | true_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 537 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 538 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 539 | // If both "true" and "false" need to be loaded jump across the code for |
| 540 | // "false". |
| 541 | if (both) { |
| 542 | loaded.Jump(); |
| 543 | } |
| 544 | // Load "false" if necessary. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | if (false_target.is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 546 | false_target.Bind(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 547 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 549 | // A value is loaded on all paths reaching this point. |
| 550 | loaded.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 551 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 552 | ASSERT(has_valid_frame()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | ASSERT(!has_cc()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 554 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 558 | void CodeGenerator::LoadGlobal() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 559 | Register reg = frame_->GetTOSRegister(); |
| 560 | __ ldr(reg, GlobalObject()); |
| 561 | frame_->EmitPush(reg); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 565 | void CodeGenerator::LoadGlobalReceiver(Register scratch) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 566 | Register reg = frame_->GetTOSRegister(); |
| 567 | __ ldr(reg, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 568 | __ ldr(reg, |
| 569 | FieldMemOperand(reg, GlobalObject::kGlobalReceiverOffset)); |
| 570 | frame_->EmitPush(reg); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 574 | ArgumentsAllocationMode CodeGenerator::ArgumentsMode() { |
| 575 | if (scope()->arguments() == NULL) return NO_ARGUMENTS_ALLOCATION; |
| 576 | ASSERT(scope()->arguments_shadow() != NULL); |
| 577 | // We don't want to do lazy arguments allocation for functions that |
| 578 | // have heap-allocated contexts, because it interfers with the |
| 579 | // uninitialized const tracking in the context objects. |
| 580 | return (scope()->num_heap_slots() > 0) |
| 581 | ? EAGER_ARGUMENTS_ALLOCATION |
| 582 | : LAZY_ARGUMENTS_ALLOCATION; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | void CodeGenerator::StoreArgumentsObject(bool initial) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 587 | ArgumentsAllocationMode mode = ArgumentsMode(); |
| 588 | ASSERT(mode != NO_ARGUMENTS_ALLOCATION); |
| 589 | |
| 590 | Comment cmnt(masm_, "[ store arguments object"); |
| 591 | if (mode == LAZY_ARGUMENTS_ALLOCATION && initial) { |
| 592 | // When using lazy arguments allocation, we store the hole value |
| 593 | // as a sentinel indicating that the arguments object hasn't been |
| 594 | // allocated yet. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 595 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 596 | } else { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 597 | frame_->SpillAll(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 598 | ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
| 599 | __ ldr(r2, frame_->Function()); |
| 600 | // The receiver is below the arguments, the return address, and the |
| 601 | // frame pointer on the stack. |
| 602 | const int kReceiverDisplacement = 2 + scope()->num_parameters(); |
| 603 | __ add(r1, fp, Operand(kReceiverDisplacement * kPointerSize)); |
| 604 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
| 605 | frame_->Adjust(3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 606 | __ Push(r2, r1, r0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 607 | frame_->CallStub(&stub, 3); |
| 608 | frame_->EmitPush(r0); |
| 609 | } |
| 610 | |
| 611 | Variable* arguments = scope()->arguments()->var(); |
| 612 | Variable* shadow = scope()->arguments_shadow()->var(); |
| 613 | ASSERT(arguments != NULL && arguments->slot() != NULL); |
| 614 | ASSERT(shadow != NULL && shadow->slot() != NULL); |
| 615 | JumpTarget done; |
| 616 | if (mode == LAZY_ARGUMENTS_ALLOCATION && !initial) { |
| 617 | // We have to skip storing into the arguments slot if it has |
| 618 | // already been written to. This can happen if the a function |
| 619 | // has a local variable named 'arguments'. |
| 620 | LoadFromSlot(scope()->arguments()->var()->slot(), NOT_INSIDE_TYPEOF); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 621 | Register arguments = frame_->PopToRegister(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 622 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 623 | __ cmp(arguments, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 624 | done.Branch(ne); |
| 625 | } |
| 626 | StoreToSlot(arguments->slot(), NOT_CONST_INIT); |
| 627 | if (mode == LAZY_ARGUMENTS_ALLOCATION) done.Bind(); |
| 628 | StoreToSlot(shadow->slot(), NOT_CONST_INIT); |
| 629 | } |
| 630 | |
| 631 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 632 | void CodeGenerator::LoadTypeofExpression(Expression* expr) { |
| 633 | // Special handling of identifiers as subexpressions of typeof. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 634 | Variable* variable = expr->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | if (variable != NULL && !variable->is_this() && variable->is_global()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 636 | // For a global variable we build the property reference |
| 637 | // <global>.<variable> and perform a (regular non-contextual) property |
| 638 | // load to make sure we do not get reference errors. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 639 | Slot global(variable, Slot::CONTEXT, Context::GLOBAL_INDEX); |
| 640 | Literal key(variable->name()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 641 | Property property(&global, &key, RelocInfo::kNoPosition); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 642 | Reference ref(this, &property); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 643 | ref.GetValue(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 644 | } else if (variable != NULL && variable->slot() != NULL) { |
| 645 | // For a variable that rewrites to a slot, we signal it is the immediate |
| 646 | // subexpression of a typeof. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 647 | LoadFromSlotCheckForArguments(variable->slot(), INSIDE_TYPEOF); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 648 | } else { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 649 | // Anything else can be handled normally. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 650 | Load(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 655 | Reference::Reference(CodeGenerator* cgen, |
| 656 | Expression* expression, |
| 657 | bool persist_after_get) |
| 658 | : cgen_(cgen), |
| 659 | expression_(expression), |
| 660 | type_(ILLEGAL), |
| 661 | persist_after_get_(persist_after_get) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 662 | // We generally assume that we are not in a spilled scope for most |
| 663 | // of the code generator. A failure to ensure this caused issue 815 |
| 664 | // and this assert is designed to catch similar issues. |
| 665 | cgen->frame()->AssertIsNotSpilled(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 666 | cgen->LoadReference(this); |
| 667 | } |
| 668 | |
| 669 | |
| 670 | Reference::~Reference() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 671 | ASSERT(is_unloaded() || is_illegal()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 675 | void CodeGenerator::LoadReference(Reference* ref) { |
| 676 | Comment cmnt(masm_, "[ LoadReference"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 677 | Expression* e = ref->expression(); |
| 678 | Property* property = e->AsProperty(); |
| 679 | Variable* var = e->AsVariableProxy()->AsVariable(); |
| 680 | |
| 681 | if (property != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 682 | // The expression is either a property or a variable proxy that rewrites |
| 683 | // to a property. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 684 | Load(property->obj()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 685 | if (property->key()->IsPropertyName()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 686 | ref->set_type(Reference::NAMED); |
| 687 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 688 | Load(property->key()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 689 | ref->set_type(Reference::KEYED); |
| 690 | } |
| 691 | } else if (var != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 692 | // The expression is a variable proxy that does not rewrite to a |
| 693 | // property. Global variables are treated as named property references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 694 | if (var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 695 | LoadGlobal(); |
| 696 | ref->set_type(Reference::NAMED); |
| 697 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 698 | ASSERT(var->slot() != NULL); |
| 699 | ref->set_type(Reference::SLOT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 700 | } |
| 701 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 702 | // Anything else is a runtime error. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 703 | Load(e); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 704 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 709 | void CodeGenerator::UnloadReference(Reference* ref) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 710 | int size = ref->size(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 711 | ref->set_unloaded(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 712 | if (size == 0) return; |
| 713 | |
| 714 | // Pop a reference from the stack while preserving TOS. |
| 715 | VirtualFrame::RegisterAllocationScope scope(this); |
| 716 | Comment cmnt(masm_, "[ UnloadReference"); |
| 717 | if (size > 0) { |
| 718 | Register tos = frame_->PopToRegister(); |
| 719 | frame_->Drop(size); |
| 720 | frame_->EmitPush(tos); |
| 721 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 725 | // ECMA-262, section 9.2, page 30: ToBoolean(). Convert the given |
| 726 | // register to a boolean in the condition code register. The code |
| 727 | // may jump to 'false_target' in case the register converts to 'false'. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 728 | void CodeGenerator::ToBoolean(JumpTarget* true_target, |
| 729 | JumpTarget* false_target) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 730 | // Note: The generated code snippet does not change stack variables. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 731 | // Only the condition code should be set. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 732 | bool known_smi = frame_->KnownSmiAt(0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 733 | Register tos = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 734 | |
| 735 | // Fast case checks |
| 736 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 737 | // Check if the value is 'false'. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 738 | if (!known_smi) { |
| 739 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 740 | __ cmp(tos, ip); |
| 741 | false_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 742 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 743 | // Check if the value is 'true'. |
| 744 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
| 745 | __ cmp(tos, ip); |
| 746 | true_target->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 747 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 748 | // Check if the value is 'undefined'. |
| 749 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 750 | __ cmp(tos, ip); |
| 751 | false_target->Branch(eq); |
| 752 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 753 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 754 | // Check if the value is a smi. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 755 | __ cmp(tos, Operand(Smi::FromInt(0))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 756 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 757 | if (!known_smi) { |
| 758 | false_target->Branch(eq); |
| 759 | __ tst(tos, Operand(kSmiTagMask)); |
| 760 | true_target->Branch(eq); |
| 761 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 762 | // Slow case. |
| 763 | if (CpuFeatures::IsSupported(VFP3)) { |
| 764 | CpuFeatures::Scope scope(VFP3); |
| 765 | // Implements the slow case by using ToBooleanStub. |
| 766 | // The ToBooleanStub takes a single argument, and |
| 767 | // returns a non-zero value for true, or zero for false. |
| 768 | // Both the argument value and the return value use the |
| 769 | // register assigned to tos_ |
| 770 | ToBooleanStub stub(tos); |
| 771 | frame_->CallStub(&stub, 0); |
| 772 | // Convert the result in "tos" to a condition code. |
| 773 | __ cmp(tos, Operand(0)); |
| 774 | } else { |
| 775 | // Implements slow case by calling the runtime. |
| 776 | frame_->EmitPush(tos); |
| 777 | frame_->CallRuntime(Runtime::kToBool, 1); |
| 778 | // Convert the result (r0) to a condition code. |
| 779 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
| 780 | __ cmp(r0, ip); |
| 781 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 782 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | |
| 784 | cc_reg_ = ne; |
| 785 | } |
| 786 | |
| 787 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 788 | void CodeGenerator::GenericBinaryOperation(Token::Value op, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 789 | OverwriteMode overwrite_mode, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 790 | GenerateInlineSmi inline_smi, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 791 | int constant_rhs) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 792 | // top of virtual frame: y |
| 793 | // 2nd elt. on virtual frame : x |
| 794 | // result : top of virtual frame |
| 795 | |
| 796 | // Stub is entered with a call: 'return address' is in lr. |
| 797 | switch (op) { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 798 | case Token::ADD: |
| 799 | case Token::SUB: |
| 800 | if (inline_smi) { |
| 801 | JumpTarget done; |
| 802 | Register rhs = frame_->PopToRegister(); |
| 803 | Register lhs = frame_->PopToRegister(rhs); |
| 804 | Register scratch = VirtualFrame::scratch0(); |
| 805 | __ orr(scratch, rhs, Operand(lhs)); |
| 806 | // Check they are both small and positive. |
| 807 | __ tst(scratch, Operand(kSmiTagMask | 0xc0000000)); |
| 808 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 809 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 810 | if (op == Token::ADD) { |
| 811 | __ add(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 812 | } else { |
| 813 | __ sub(r0, lhs, Operand(rhs), LeaveCC, eq); |
| 814 | } |
| 815 | done.Branch(eq); |
| 816 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 817 | frame_->SpillAll(); |
| 818 | frame_->CallStub(&stub, 0); |
| 819 | done.Bind(); |
| 820 | frame_->EmitPush(r0); |
| 821 | break; |
| 822 | } else { |
| 823 | // Fall through! |
| 824 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 825 | case Token::BIT_OR: |
| 826 | case Token::BIT_AND: |
| 827 | case Token::BIT_XOR: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 828 | if (inline_smi) { |
| 829 | bool rhs_is_smi = frame_->KnownSmiAt(0); |
| 830 | bool lhs_is_smi = frame_->KnownSmiAt(1); |
| 831 | Register rhs = frame_->PopToRegister(); |
| 832 | Register lhs = frame_->PopToRegister(rhs); |
| 833 | Register smi_test_reg; |
| 834 | Condition cond; |
| 835 | if (!rhs_is_smi || !lhs_is_smi) { |
| 836 | if (rhs_is_smi) { |
| 837 | smi_test_reg = lhs; |
| 838 | } else if (lhs_is_smi) { |
| 839 | smi_test_reg = rhs; |
| 840 | } else { |
| 841 | smi_test_reg = VirtualFrame::scratch0(); |
| 842 | __ orr(smi_test_reg, rhs, Operand(lhs)); |
| 843 | } |
| 844 | // Check they are both Smis. |
| 845 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 846 | cond = eq; |
| 847 | } else { |
| 848 | cond = al; |
| 849 | } |
| 850 | ASSERT(rhs.is(r0) || lhs.is(r0)); // r0 is free now. |
| 851 | if (op == Token::BIT_OR) { |
| 852 | __ orr(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 853 | } else if (op == Token::BIT_AND) { |
| 854 | __ and_(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 855 | } else { |
| 856 | ASSERT(op == Token::BIT_XOR); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 857 | STATIC_ASSERT(kSmiTag == 0); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 858 | __ eor(r0, lhs, Operand(rhs), LeaveCC, cond); |
| 859 | } |
| 860 | if (cond != al) { |
| 861 | JumpTarget done; |
| 862 | done.Branch(cond); |
| 863 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 864 | frame_->SpillAll(); |
| 865 | frame_->CallStub(&stub, 0); |
| 866 | done.Bind(); |
| 867 | } |
| 868 | frame_->EmitPush(r0); |
| 869 | break; |
| 870 | } else { |
| 871 | // Fall through! |
| 872 | } |
| 873 | case Token::MUL: |
| 874 | case Token::DIV: |
| 875 | case Token::MOD: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 876 | case Token::SHL: |
| 877 | case Token::SHR: |
| 878 | case Token::SAR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 879 | Register rhs = frame_->PopToRegister(); |
| 880 | Register lhs = frame_->PopToRegister(rhs); // Don't pop to rhs register. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 881 | GenericBinaryOpStub stub(op, overwrite_mode, lhs, rhs, constant_rhs); |
| 882 | frame_->SpillAll(); |
| 883 | frame_->CallStub(&stub, 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 884 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | break; |
| 886 | } |
| 887 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 888 | case Token::COMMA: { |
| 889 | Register scratch = frame_->PopToRegister(); |
| 890 | // Simply discard left value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 891 | frame_->Drop(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 892 | frame_->EmitPush(scratch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 893 | break; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 894 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 895 | |
| 896 | default: |
| 897 | // Other cases should have been handled before this point. |
| 898 | UNREACHABLE(); |
| 899 | break; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 904 | class DeferredInlineSmiOperation: public DeferredCode { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 905 | public: |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 906 | DeferredInlineSmiOperation(Token::Value op, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 907 | int value, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 908 | bool reversed, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 909 | OverwriteMode overwrite_mode, |
| 910 | Register tos) |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 911 | : op_(op), |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 912 | value_(value), |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 913 | reversed_(reversed), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 914 | overwrite_mode_(overwrite_mode), |
| 915 | tos_register_(tos) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 916 | set_comment("[ DeferredInlinedSmiOperation"); |
| 917 | } |
| 918 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 919 | virtual void Generate(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 920 | |
| 921 | private: |
| 922 | Token::Value op_; |
| 923 | int value_; |
| 924 | bool reversed_; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 925 | OverwriteMode overwrite_mode_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 926 | Register tos_register_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 927 | }; |
| 928 | |
| 929 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 930 | |
| 931 | // On entry the non-constant side of the binary operation is in tos_register_ |
| 932 | // and the constant smi side is nowhere. The tos_register_ is not used by the |
| 933 | // virtual frame. On exit the answer is in the tos_register_ and the virtual |
| 934 | // frame is unchanged. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 935 | void DeferredInlineSmiOperation::Generate() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 936 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 937 | copied_frame.SpillAll(); |
| 938 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 939 | Register lhs = r1; |
| 940 | Register rhs = r0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 941 | switch (op_) { |
| 942 | case Token::ADD: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 943 | // Revert optimistic add. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 944 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 945 | __ sub(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 946 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 947 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 948 | __ sub(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 949 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 950 | } |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | case Token::SUB: { |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 955 | // Revert optimistic sub. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 956 | if (reversed_) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 957 | __ rsb(r0, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 958 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 959 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 960 | __ add(r1, tos_register_, Operand(Smi::FromInt(value_))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 961 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 962 | } |
| 963 | break; |
| 964 | } |
| 965 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 966 | // For these operations there is no optimistic operation that needs to be |
| 967 | // reverted. |
| 968 | case Token::MUL: |
| 969 | case Token::MOD: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 970 | case Token::BIT_OR: |
| 971 | case Token::BIT_XOR: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 972 | case Token::BIT_AND: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 973 | case Token::SHL: |
| 974 | case Token::SHR: |
| 975 | case Token::SAR: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 976 | if (tos_register_.is(r1)) { |
| 977 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 978 | } else { |
| 979 | ASSERT(tos_register_.is(r0)); |
| 980 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 981 | } |
| 982 | if (reversed_ == tos_register_.is(r1)) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 983 | lhs = r0; |
| 984 | rhs = r1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 985 | } |
| 986 | break; |
| 987 | } |
| 988 | |
| 989 | default: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 990 | // Other cases should have been handled before this point. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 991 | UNREACHABLE(); |
| 992 | break; |
| 993 | } |
| 994 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 995 | GenericBinaryOpStub stub(op_, overwrite_mode_, lhs, rhs, value_); |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 996 | __ CallStub(&stub); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 997 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 998 | // The generic stub returns its value in r0, but that's not |
| 999 | // necessarily what we want. We want whatever the inlined code |
| 1000 | // expected, which is that the answer is in the same register as |
| 1001 | // the operand was. |
| 1002 | __ Move(tos_register_, r0); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1003 | |
| 1004 | // The tos register was not in use for the virtual frame that we |
| 1005 | // came into this function with, so we can merge back to that frame |
| 1006 | // without trashing it. |
| 1007 | copied_frame.MergeTo(frame_state()->frame()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1011 | static bool PopCountLessThanEqual2(unsigned int x) { |
| 1012 | x &= x - 1; |
| 1013 | return (x & (x - 1)) == 0; |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | // Returns the index of the lowest bit set. |
| 1018 | static int BitPosition(unsigned x) { |
| 1019 | int bit_posn = 0; |
| 1020 | while ((x & 0xf) == 0) { |
| 1021 | bit_posn += 4; |
| 1022 | x >>= 4; |
| 1023 | } |
| 1024 | while ((x & 1) == 0) { |
| 1025 | bit_posn++; |
| 1026 | x >>= 1; |
| 1027 | } |
| 1028 | return bit_posn; |
| 1029 | } |
| 1030 | |
| 1031 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1032 | // Can we multiply by x with max two shifts and an add. |
| 1033 | // This answers yes to all integers from 2 to 10. |
| 1034 | static bool IsEasyToMultiplyBy(int x) { |
| 1035 | if (x < 2) return false; // Avoid special cases. |
| 1036 | if (x > (Smi::kMaxValue + 1) >> 2) return false; // Almost always overflows. |
| 1037 | if (IsPowerOf2(x)) return true; // Simple shift. |
| 1038 | if (PopCountLessThanEqual2(x)) return true; // Shift and add and shift. |
| 1039 | if (IsPowerOf2(x + 1)) return true; // Patterns like 11111. |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | // Can multiply by anything that IsEasyToMultiplyBy returns true for. |
| 1045 | // Source and destination may be the same register. This routine does |
| 1046 | // not set carry and overflow the way a mul instruction would. |
| 1047 | static void InlineMultiplyByKnownInt(MacroAssembler* masm, |
| 1048 | Register source, |
| 1049 | Register destination, |
| 1050 | int known_int) { |
| 1051 | if (IsPowerOf2(known_int)) { |
| 1052 | masm->mov(destination, Operand(source, LSL, BitPosition(known_int))); |
| 1053 | } else if (PopCountLessThanEqual2(known_int)) { |
| 1054 | int first_bit = BitPosition(known_int); |
| 1055 | int second_bit = BitPosition(known_int ^ (1 << first_bit)); |
| 1056 | masm->add(destination, source, |
| 1057 | Operand(source, LSL, second_bit - first_bit)); |
| 1058 | if (first_bit != 0) { |
| 1059 | masm->mov(destination, Operand(destination, LSL, first_bit)); |
| 1060 | } |
| 1061 | } else { |
| 1062 | ASSERT(IsPowerOf2(known_int + 1)); // Patterns like 1111. |
| 1063 | int the_bit = BitPosition(known_int + 1); |
| 1064 | masm->rsb(destination, source, Operand(source, LSL, the_bit)); |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 1069 | void CodeGenerator::SmiOperation(Token::Value op, |
| 1070 | Handle<Object> value, |
| 1071 | bool reversed, |
| 1072 | OverwriteMode mode) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1073 | int int_value = Smi::cast(*value)->value(); |
| 1074 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1075 | bool both_sides_are_smi = frame_->KnownSmiAt(0); |
| 1076 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1077 | bool something_to_inline; |
| 1078 | switch (op) { |
| 1079 | case Token::ADD: |
| 1080 | case Token::SUB: |
| 1081 | case Token::BIT_AND: |
| 1082 | case Token::BIT_OR: |
| 1083 | case Token::BIT_XOR: { |
| 1084 | something_to_inline = true; |
| 1085 | break; |
| 1086 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1087 | case Token::SHL: { |
| 1088 | something_to_inline = (both_sides_are_smi || !reversed); |
| 1089 | break; |
| 1090 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1091 | case Token::SHR: |
| 1092 | case Token::SAR: { |
| 1093 | if (reversed) { |
| 1094 | something_to_inline = false; |
| 1095 | } else { |
| 1096 | something_to_inline = true; |
| 1097 | } |
| 1098 | break; |
| 1099 | } |
| 1100 | case Token::MOD: { |
| 1101 | if (reversed || int_value < 2 || !IsPowerOf2(int_value)) { |
| 1102 | something_to_inline = false; |
| 1103 | } else { |
| 1104 | something_to_inline = true; |
| 1105 | } |
| 1106 | break; |
| 1107 | } |
| 1108 | case Token::MUL: { |
| 1109 | if (!IsEasyToMultiplyBy(int_value)) { |
| 1110 | something_to_inline = false; |
| 1111 | } else { |
| 1112 | something_to_inline = true; |
| 1113 | } |
| 1114 | break; |
| 1115 | } |
| 1116 | default: { |
| 1117 | something_to_inline = false; |
| 1118 | break; |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | if (!something_to_inline) { |
| 1123 | if (!reversed) { |
| 1124 | // Push the rhs onto the virtual frame by putting it in a TOS register. |
| 1125 | Register rhs = frame_->GetTOSRegister(); |
| 1126 | __ mov(rhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1127 | frame_->EmitPush(rhs, TypeInfo::Smi()); |
| 1128 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1129 | } else { |
| 1130 | // Pop the rhs, then push lhs and rhs in the right order. Only performs |
| 1131 | // at most one pop, the rest takes place in TOS registers. |
| 1132 | Register lhs = frame_->GetTOSRegister(); // Get reg for pushing. |
| 1133 | Register rhs = frame_->PopToRegister(lhs); // Don't use lhs for this. |
| 1134 | __ mov(lhs, Operand(value)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1135 | frame_->EmitPush(lhs, TypeInfo::Smi()); |
| 1136 | TypeInfo t = both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Unknown(); |
| 1137 | frame_->EmitPush(rhs, t); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame^] | 1138 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, |
| 1139 | GenericBinaryOpStub::kUnknownIntValue); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1140 | } |
| 1141 | return; |
| 1142 | } |
| 1143 | |
| 1144 | // We move the top of stack to a register (normally no move is invoved). |
| 1145 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1146 | switch (op) { |
| 1147 | case Token::ADD: { |
| 1148 | DeferredCode* deferred = |
| 1149 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1150 | |
| 1151 | __ add(tos, tos, Operand(value), SetCC); |
| 1152 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1153 | if (!both_sides_are_smi) { |
| 1154 | __ tst(tos, Operand(kSmiTagMask)); |
| 1155 | deferred->Branch(ne); |
| 1156 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1157 | deferred->BindExit(); |
| 1158 | frame_->EmitPush(tos); |
| 1159 | break; |
| 1160 | } |
| 1161 | |
| 1162 | case Token::SUB: { |
| 1163 | DeferredCode* deferred = |
| 1164 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1165 | |
| 1166 | if (reversed) { |
| 1167 | __ rsb(tos, tos, Operand(value), SetCC); |
| 1168 | } else { |
| 1169 | __ sub(tos, tos, Operand(value), SetCC); |
| 1170 | } |
| 1171 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1172 | if (!both_sides_are_smi) { |
| 1173 | __ tst(tos, Operand(kSmiTagMask)); |
| 1174 | deferred->Branch(ne); |
| 1175 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1176 | deferred->BindExit(); |
| 1177 | frame_->EmitPush(tos); |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | |
| 1182 | case Token::BIT_OR: |
| 1183 | case Token::BIT_XOR: |
| 1184 | case Token::BIT_AND: { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1185 | if (both_sides_are_smi) { |
| 1186 | switch (op) { |
| 1187 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1188 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1189 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1190 | default: UNREACHABLE(); |
| 1191 | } |
| 1192 | frame_->EmitPush(tos, TypeInfo::Smi()); |
| 1193 | } else { |
| 1194 | DeferredCode* deferred = |
| 1195 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1196 | __ tst(tos, Operand(kSmiTagMask)); |
| 1197 | deferred->Branch(ne); |
| 1198 | switch (op) { |
| 1199 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1200 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1201 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1202 | default: UNREACHABLE(); |
| 1203 | } |
| 1204 | deferred->BindExit(); |
| 1205 | TypeInfo result_type = |
| 1206 | (op == Token::BIT_AND) ? TypeInfo::Smi() : TypeInfo::Integer32(); |
| 1207 | frame_->EmitPush(tos, result_type); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1208 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | case Token::SHL: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1213 | if (reversed) { |
| 1214 | ASSERT(both_sides_are_smi); |
| 1215 | int max_shift = 0; |
| 1216 | int max_result = int_value == 0 ? 1 : int_value; |
| 1217 | while (Smi::IsValid(max_result << 1)) { |
| 1218 | max_shift++; |
| 1219 | max_result <<= 1; |
| 1220 | } |
| 1221 | DeferredCode* deferred = |
| 1222 | new DeferredInlineSmiOperation(op, int_value, true, mode, tos); |
| 1223 | // Mask off the last 5 bits of the shift operand (rhs). This is part |
| 1224 | // of the definition of shift in JS and we know we have a Smi so we |
| 1225 | // can safely do this. The masked version gets passed to the |
| 1226 | // deferred code, but that makes no difference. |
| 1227 | __ and_(tos, tos, Operand(Smi::FromInt(0x1f))); |
| 1228 | __ cmp(tos, Operand(Smi::FromInt(max_shift))); |
| 1229 | deferred->Branch(ge); |
| 1230 | Register scratch = VirtualFrame::scratch0(); |
| 1231 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Untag. |
| 1232 | __ mov(tos, Operand(Smi::FromInt(int_value))); // Load constant. |
| 1233 | __ mov(tos, Operand(tos, LSL, scratch)); // Shift constant. |
| 1234 | deferred->BindExit(); |
| 1235 | TypeInfo result = TypeInfo::Integer32(); |
| 1236 | frame_->EmitPush(tos, result); |
| 1237 | break; |
| 1238 | } |
| 1239 | // Fall through! |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1240 | case Token::SHR: |
| 1241 | case Token::SAR: { |
| 1242 | ASSERT(!reversed); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1243 | int shift_amount = int_value & 0x1f; |
| 1244 | TypeInfo result = TypeInfo::Number(); |
| 1245 | |
| 1246 | if (op == Token::SHR) { |
| 1247 | if (shift_amount > 1) { |
| 1248 | result = TypeInfo::Smi(); |
| 1249 | } else if (shift_amount > 0) { |
| 1250 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1251 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1252 | } else if (op == Token::SAR) { |
| 1253 | if (shift_amount > 0) { |
| 1254 | result = TypeInfo::Smi(); |
| 1255 | } else { |
| 1256 | result = TypeInfo::Integer32(); |
| 1257 | } |
| 1258 | } else { |
| 1259 | ASSERT(op == Token::SHL); |
| 1260 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1261 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1262 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1263 | Register scratch = VirtualFrame::scratch0(); |
| 1264 | Register scratch2 = VirtualFrame::scratch1(); |
| 1265 | int shift_value = int_value & 0x1f; // least significant 5 bits |
| 1266 | DeferredCode* deferred = |
| 1267 | new DeferredInlineSmiOperation(op, shift_value, false, mode, tos); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1268 | uint32_t problematic_mask = kSmiTagMask; |
| 1269 | // For unsigned shift by zero all negative smis are problematic. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1270 | bool skip_smi_test = both_sides_are_smi; |
| 1271 | if (shift_value == 0 && op == Token::SHR) { |
| 1272 | problematic_mask |= 0x80000000; |
| 1273 | skip_smi_test = false; |
| 1274 | } |
| 1275 | if (!skip_smi_test) { |
| 1276 | __ tst(tos, Operand(problematic_mask)); |
| 1277 | deferred->Branch(ne); // Go slow for problematic input. |
| 1278 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1279 | switch (op) { |
| 1280 | case Token::SHL: { |
| 1281 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1282 | int adjusted_shift = shift_value - kSmiTagSize; |
| 1283 | ASSERT(adjusted_shift >= 0); |
| 1284 | if (adjusted_shift != 0) { |
| 1285 | __ mov(scratch, Operand(tos, LSL, adjusted_shift)); |
| 1286 | // Check that the *signed* result fits in a smi. |
| 1287 | __ add(scratch2, scratch, Operand(0x40000000), SetCC); |
| 1288 | deferred->Branch(mi); |
| 1289 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
| 1290 | } else { |
| 1291 | // Check that the *signed* result fits in a smi. |
| 1292 | __ add(scratch2, tos, Operand(0x40000000), SetCC); |
| 1293 | deferred->Branch(mi); |
| 1294 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
| 1295 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1296 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1297 | break; |
| 1298 | } |
| 1299 | case Token::SHR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1300 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1301 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Remove tag. |
| 1302 | // LSR by immediate 0 means shifting 32 bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1303 | __ mov(scratch, Operand(scratch, LSR, shift_value)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1304 | if (shift_value == 1) { |
| 1305 | // check that the *unsigned* result fits in a smi |
| 1306 | // neither of the two high-order bits can be set: |
| 1307 | // - 0x80000000: high bit would be lost when smi tagging |
| 1308 | // - 0x40000000: this number would convert to negative when |
| 1309 | // smi tagging these two cases can only happen with shifts |
| 1310 | // by 0 or 1 when handed a valid smi |
| 1311 | __ tst(scratch, Operand(0xc0000000)); |
| 1312 | deferred->Branch(ne); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1313 | } else { |
| 1314 | ASSERT(shift_value >= 2); |
| 1315 | result = TypeInfo::Smi(); // SHR by at least 2 gives a Smi. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1316 | } |
| 1317 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1318 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1319 | break; |
| 1320 | } |
| 1321 | case Token::SAR: { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1322 | // In the ARM instructions set, ASR by immediate 0 means shifting 32 |
| 1323 | // bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1324 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1325 | // Do the shift and the tag removal in one operation. If the shift |
| 1326 | // is 31 bits (the highest possible value) then we emit the |
| 1327 | // instruction as a shift by 0 which means shift arithmetically by |
| 1328 | // 32. |
| 1329 | __ mov(tos, Operand(tos, ASR, (kSmiTagSize + shift_value) & 0x1f)); |
| 1330 | // Put tag back. |
| 1331 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1332 | // SAR by at least 1 gives a Smi. |
| 1333 | result = TypeInfo::Smi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1334 | } |
| 1335 | break; |
| 1336 | } |
| 1337 | default: UNREACHABLE(); |
| 1338 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1339 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1340 | frame_->EmitPush(tos, result); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | case Token::MOD: { |
| 1345 | ASSERT(!reversed); |
| 1346 | ASSERT(int_value >= 2); |
| 1347 | ASSERT(IsPowerOf2(int_value)); |
| 1348 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1349 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1350 | unsigned mask = (0x80000000u | kSmiTagMask); |
| 1351 | __ tst(tos, Operand(mask)); |
| 1352 | deferred->Branch(ne); // Go to deferred code on non-Smis and negative. |
| 1353 | mask = (int_value << kSmiTagSize) - 1; |
| 1354 | __ and_(tos, tos, Operand(mask)); |
| 1355 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1356 | // Mod of positive power of 2 Smi gives a Smi if the lhs is an integer. |
| 1357 | frame_->EmitPush( |
| 1358 | tos, |
| 1359 | both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Number()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1360 | break; |
| 1361 | } |
| 1362 | |
| 1363 | case Token::MUL: { |
| 1364 | ASSERT(IsEasyToMultiplyBy(int_value)); |
| 1365 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1366 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1367 | unsigned max_smi_that_wont_overflow = Smi::kMaxValue / int_value; |
| 1368 | max_smi_that_wont_overflow <<= kSmiTagSize; |
| 1369 | unsigned mask = 0x80000000u; |
| 1370 | while ((mask & max_smi_that_wont_overflow) == 0) { |
| 1371 | mask |= mask >> 1; |
| 1372 | } |
| 1373 | mask |= kSmiTagMask; |
| 1374 | // This does a single mask that checks for a too high value in a |
| 1375 | // conservative way and for a non-Smi. It also filters out negative |
| 1376 | // numbers, unfortunately, but since this code is inline we prefer |
| 1377 | // brevity to comprehensiveness. |
| 1378 | __ tst(tos, Operand(mask)); |
| 1379 | deferred->Branch(ne); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1380 | InlineMultiplyByKnownInt(masm_, tos, tos, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1381 | deferred->BindExit(); |
| 1382 | frame_->EmitPush(tos); |
| 1383 | break; |
| 1384 | } |
| 1385 | |
| 1386 | default: |
| 1387 | UNREACHABLE(); |
| 1388 | break; |
| 1389 | } |
| 1390 | } |
| 1391 | |
| 1392 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1393 | void CodeGenerator::Comparison(Condition cc, |
| 1394 | Expression* left, |
| 1395 | Expression* right, |
| 1396 | bool strict) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1397 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1398 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1399 | if (left != NULL) Load(left); |
| 1400 | if (right != NULL) Load(right); |
| 1401 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1402 | // sp[0] : y |
| 1403 | // sp[1] : x |
| 1404 | // result : cc register |
| 1405 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1406 | // Strict only makes sense for equality comparisons. |
| 1407 | ASSERT(!strict || cc == eq); |
| 1408 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1409 | Register lhs; |
| 1410 | Register rhs; |
| 1411 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1412 | bool lhs_is_smi; |
| 1413 | bool rhs_is_smi; |
| 1414 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1415 | // We load the top two stack positions into registers chosen by the virtual |
| 1416 | // frame. This should keep the register shuffling to a minimum. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1417 | // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| 1418 | if (cc == gt || cc == le) { |
| 1419 | cc = ReverseCondition(cc); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1420 | lhs_is_smi = frame_->KnownSmiAt(0); |
| 1421 | rhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1422 | lhs = frame_->PopToRegister(); |
| 1423 | rhs = frame_->PopToRegister(lhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1424 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1425 | rhs_is_smi = frame_->KnownSmiAt(0); |
| 1426 | lhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1427 | rhs = frame_->PopToRegister(); |
| 1428 | lhs = frame_->PopToRegister(rhs); // Don't pop to the same register again! |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1429 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1430 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1431 | bool both_sides_are_smi = (lhs_is_smi && rhs_is_smi); |
| 1432 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1433 | ASSERT(rhs.is(r0) || rhs.is(r1)); |
| 1434 | ASSERT(lhs.is(r0) || lhs.is(r1)); |
| 1435 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1436 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1438 | if (!both_sides_are_smi) { |
| 1439 | // Now we have the two sides in r0 and r1. We flush any other registers |
| 1440 | // because the stub doesn't know about register allocation. |
| 1441 | frame_->SpillAll(); |
| 1442 | Register scratch = VirtualFrame::scratch0(); |
| 1443 | Register smi_test_reg; |
| 1444 | if (lhs_is_smi) { |
| 1445 | smi_test_reg = rhs; |
| 1446 | } else if (rhs_is_smi) { |
| 1447 | smi_test_reg = lhs; |
| 1448 | } else { |
| 1449 | __ orr(scratch, lhs, Operand(rhs)); |
| 1450 | smi_test_reg = scratch; |
| 1451 | } |
| 1452 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 1453 | JumpTarget smi; |
| 1454 | smi.Branch(eq); |
| 1455 | |
| 1456 | // Perform non-smi comparison by stub. |
| 1457 | // CompareStub takes arguments in r0 and r1, returns <0, >0 or 0 in r0. |
| 1458 | // We call with 0 args because there are 0 on the stack. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 1459 | CompareStub stub(cc, strict, kBothCouldBeNaN, true, lhs, rhs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1460 | frame_->CallStub(&stub, 0); |
| 1461 | __ cmp(r0, Operand(0)); |
| 1462 | exit.Jump(); |
| 1463 | |
| 1464 | smi.Bind(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1467 | // Do smi comparisons by pointer comparison. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1468 | __ cmp(lhs, Operand(rhs)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1470 | exit.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1471 | cc_reg_ = cc; |
| 1472 | } |
| 1473 | |
| 1474 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1475 | // Call the function on the stack with the given arguments. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1476 | void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1477 | CallFunctionFlags flags, |
| 1478 | int position) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1479 | // Push the arguments ("left-to-right") on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1480 | int arg_count = args->length(); |
| 1481 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1482 | Load(args->at(i)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1483 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1484 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1485 | // Record the position for debugging purposes. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1486 | CodeForSourcePosition(position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1487 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1488 | // Use the shared code stub to call the function. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1489 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1490 | CallFunctionStub call_function(arg_count, in_loop, flags); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1491 | frame_->CallStub(&call_function, arg_count + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1492 | |
| 1493 | // Restore context and pop function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1494 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1495 | frame_->Drop(); // discard the TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1499 | void CodeGenerator::CallApplyLazy(Expression* applicand, |
| 1500 | Expression* receiver, |
| 1501 | VariableProxy* arguments, |
| 1502 | int position) { |
| 1503 | // An optimized implementation of expressions of the form |
| 1504 | // x.apply(y, arguments). |
| 1505 | // If the arguments object of the scope has not been allocated, |
| 1506 | // and x.apply is Function.prototype.apply, this optimization |
| 1507 | // just copies y and the arguments of the current function on the |
| 1508 | // stack, as receiver and arguments, and calls x. |
| 1509 | // In the implementation comments, we call x the applicand |
| 1510 | // and y the receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1511 | |
| 1512 | ASSERT(ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION); |
| 1513 | ASSERT(arguments->IsArguments()); |
| 1514 | |
| 1515 | // Load applicand.apply onto the stack. This will usually |
| 1516 | // give us a megamorphic load site. Not super, but it works. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1517 | Load(applicand); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1518 | Handle<String> name = Factory::LookupAsciiSymbol("apply"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1519 | frame_->Dup(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1520 | frame_->CallLoadIC(name, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1521 | frame_->EmitPush(r0); |
| 1522 | |
| 1523 | // Load the receiver and the existing arguments object onto the |
| 1524 | // expression stack. Avoid allocating the arguments object here. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1525 | Load(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1526 | LoadFromSlot(scope()->arguments()->var()->slot(), NOT_INSIDE_TYPEOF); |
| 1527 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1528 | // At this point the top two stack elements are probably in registers |
| 1529 | // since they were just loaded. Ensure they are in regs and get the |
| 1530 | // regs. |
| 1531 | Register receiver_reg = frame_->Peek2(); |
| 1532 | Register arguments_reg = frame_->Peek(); |
| 1533 | |
| 1534 | // From now on the frame is spilled. |
| 1535 | frame_->SpillAll(); |
| 1536 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1537 | // Emit the source position information after having loaded the |
| 1538 | // receiver and the arguments. |
| 1539 | CodeForSourcePosition(position); |
| 1540 | // Contents of the stack at this point: |
| 1541 | // sp[0]: arguments object of the current function or the hole. |
| 1542 | // sp[1]: receiver |
| 1543 | // sp[2]: applicand.apply |
| 1544 | // sp[3]: applicand. |
| 1545 | |
| 1546 | // Check if the arguments object has been lazily allocated |
| 1547 | // already. If so, just use that instead of copying the arguments |
| 1548 | // from the stack. This also deals with cases where a local variable |
| 1549 | // named 'arguments' has been introduced. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1550 | JumpTarget slow; |
| 1551 | Label done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1552 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1553 | __ cmp(ip, arguments_reg); |
| 1554 | slow.Branch(ne); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1555 | |
| 1556 | Label build_args; |
| 1557 | // Get rid of the arguments object probe. |
| 1558 | frame_->Drop(); |
| 1559 | // Stack now has 3 elements on it. |
| 1560 | // Contents of stack at this point: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1561 | // sp[0]: receiver - in the receiver_reg register. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1562 | // sp[1]: applicand.apply |
| 1563 | // sp[2]: applicand. |
| 1564 | |
| 1565 | // Check that the receiver really is a JavaScript object. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1566 | __ BranchOnSmi(receiver_reg, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1567 | // We allow all JSObjects including JSFunctions. As long as |
| 1568 | // JS_FUNCTION_TYPE is the last instance type and it is right |
| 1569 | // after LAST_JS_OBJECT_TYPE, we do not have to check the upper |
| 1570 | // bound. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1571 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1572 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1573 | __ CompareObjectType(receiver_reg, r2, r3, FIRST_JS_OBJECT_TYPE); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1574 | __ b(lt, &build_args); |
| 1575 | |
| 1576 | // Check that applicand.apply is Function.prototype.apply. |
| 1577 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1578 | __ BranchOnSmi(r0, &build_args); |
| 1579 | __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE); |
| 1580 | __ b(ne, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1581 | Handle<Code> apply_code(Builtins::builtin(Builtins::FunctionApply)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1582 | __ ldr(r1, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 1583 | __ sub(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1584 | __ cmp(r1, Operand(apply_code)); |
| 1585 | __ b(ne, &build_args); |
| 1586 | |
| 1587 | // Check that applicand is a function. |
| 1588 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 1589 | __ BranchOnSmi(r1, &build_args); |
| 1590 | __ CompareObjectType(r1, r2, r3, JS_FUNCTION_TYPE); |
| 1591 | __ b(ne, &build_args); |
| 1592 | |
| 1593 | // Copy the arguments to this function possibly from the |
| 1594 | // adaptor frame below it. |
| 1595 | Label invoke, adapted; |
| 1596 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 1597 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 1598 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 1599 | __ b(eq, &adapted); |
| 1600 | |
| 1601 | // No arguments adaptor frame. Copy fixed number of arguments. |
| 1602 | __ mov(r0, Operand(scope()->num_parameters())); |
| 1603 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 1604 | __ ldr(r2, frame_->ParameterAt(i)); |
| 1605 | __ push(r2); |
| 1606 | } |
| 1607 | __ jmp(&invoke); |
| 1608 | |
| 1609 | // Arguments adaptor frame present. Copy arguments from there, but |
| 1610 | // avoid copying too many arguments to avoid stack overflows. |
| 1611 | __ bind(&adapted); |
| 1612 | static const uint32_t kArgumentsLimit = 1 * KB; |
| 1613 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1614 | __ mov(r0, Operand(r0, LSR, kSmiTagSize)); |
| 1615 | __ mov(r3, r0); |
| 1616 | __ cmp(r0, Operand(kArgumentsLimit)); |
| 1617 | __ b(gt, &build_args); |
| 1618 | |
| 1619 | // Loop through the arguments pushing them onto the execution |
| 1620 | // stack. We don't inform the virtual frame of the push, so we don't |
| 1621 | // have to worry about getting rid of the elements from the virtual |
| 1622 | // frame. |
| 1623 | Label loop; |
| 1624 | // r3 is a small non-negative integer, due to the test above. |
| 1625 | __ cmp(r3, Operand(0)); |
| 1626 | __ b(eq, &invoke); |
| 1627 | // Compute the address of the first argument. |
| 1628 | __ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2)); |
| 1629 | __ add(r2, r2, Operand(kPointerSize)); |
| 1630 | __ bind(&loop); |
| 1631 | // Post-decrement argument address by kPointerSize on each iteration. |
| 1632 | __ ldr(r4, MemOperand(r2, kPointerSize, NegPostIndex)); |
| 1633 | __ push(r4); |
| 1634 | __ sub(r3, r3, Operand(1), SetCC); |
| 1635 | __ b(gt, &loop); |
| 1636 | |
| 1637 | // Invoke the function. |
| 1638 | __ bind(&invoke); |
| 1639 | ParameterCount actual(r0); |
| 1640 | __ InvokeFunction(r1, actual, CALL_FUNCTION); |
| 1641 | // Drop applicand.apply and applicand from the stack, and push |
| 1642 | // the result of the function call, but leave the spilled frame |
| 1643 | // unchanged, with 3 elements, so it is correct when we compile the |
| 1644 | // slow-case code. |
| 1645 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 1646 | __ push(r0); |
| 1647 | // Stack now has 1 element: |
| 1648 | // sp[0]: result |
| 1649 | __ jmp(&done); |
| 1650 | |
| 1651 | // Slow-case: Allocate the arguments object since we know it isn't |
| 1652 | // there, and fall-through to the slow-case where we call |
| 1653 | // applicand.apply. |
| 1654 | __ bind(&build_args); |
| 1655 | // Stack now has 3 elements, because we have jumped from where: |
| 1656 | // sp[0]: receiver |
| 1657 | // sp[1]: applicand.apply |
| 1658 | // sp[2]: applicand. |
| 1659 | StoreArgumentsObject(false); |
| 1660 | |
| 1661 | // Stack and frame now have 4 elements. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1662 | slow.Bind(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1663 | |
| 1664 | // Generic computation of x.apply(y, args) with no special optimization. |
| 1665 | // Flip applicand.apply and applicand on the stack, so |
| 1666 | // applicand looks like the receiver of the applicand.apply call. |
| 1667 | // Then process it as a normal function call. |
| 1668 | __ ldr(r0, MemOperand(sp, 3 * kPointerSize)); |
| 1669 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1670 | __ Strd(r0, r1, MemOperand(sp, 2 * kPointerSize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1671 | |
| 1672 | CallFunctionStub call_function(2, NOT_IN_LOOP, NO_CALL_FUNCTION_FLAGS); |
| 1673 | frame_->CallStub(&call_function, 3); |
| 1674 | // The function and its two arguments have been dropped. |
| 1675 | frame_->Drop(); // Drop the receiver as well. |
| 1676 | frame_->EmitPush(r0); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1677 | frame_->SpillAll(); // A spilled frame is also jumping to label done. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1678 | // Stack now has 1 element: |
| 1679 | // sp[0]: result |
| 1680 | __ bind(&done); |
| 1681 | |
| 1682 | // Restore the context register after a call. |
| 1683 | __ ldr(cp, frame_->Context()); |
| 1684 | } |
| 1685 | |
| 1686 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1687 | void CodeGenerator::Branch(bool if_true, JumpTarget* target) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1688 | ASSERT(has_cc()); |
| 1689 | Condition cc = if_true ? cc_reg_ : NegateCondition(cc_reg_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1690 | target->Branch(cc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1691 | cc_reg_ = al; |
| 1692 | } |
| 1693 | |
| 1694 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1695 | void CodeGenerator::CheckStack() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1696 | frame_->SpillAll(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1697 | Comment cmnt(masm_, "[ check stack"); |
| 1698 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 1699 | // Put the lr setup instruction in the delay slot. kInstrSize is added to |
| 1700 | // the implicit 8 byte offset that always applies to operations with pc and |
| 1701 | // gives a return address 12 bytes down. |
| 1702 | masm_->add(lr, pc, Operand(Assembler::kInstrSize)); |
| 1703 | masm_->cmp(sp, Operand(ip)); |
| 1704 | StackCheckStub stub; |
| 1705 | // Call the stub if lower. |
| 1706 | masm_->mov(pc, |
| 1707 | Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
| 1708 | RelocInfo::CODE_TARGET), |
| 1709 | LeaveCC, |
| 1710 | lo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1714 | void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { |
| 1715 | #ifdef DEBUG |
| 1716 | int original_height = frame_->height(); |
| 1717 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1718 | for (int i = 0; frame_ != NULL && i < statements->length(); i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1719 | Visit(statements->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1720 | } |
| 1721 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 1722 | } |
| 1723 | |
| 1724 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1725 | void CodeGenerator::VisitBlock(Block* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1726 | #ifdef DEBUG |
| 1727 | int original_height = frame_->height(); |
| 1728 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1729 | Comment cmnt(masm_, "[ Block"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1730 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1731 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1732 | VisitStatements(node->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1733 | if (node->break_target()->is_linked()) { |
| 1734 | node->break_target()->Bind(); |
| 1735 | } |
| 1736 | node->break_target()->Unuse(); |
| 1737 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1741 | void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1742 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1743 | frame_->EmitPush(Operand(pairs)); |
| 1744 | frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1745 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1746 | frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1747 | // The result is discarded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1751 | void CodeGenerator::VisitDeclaration(Declaration* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1752 | #ifdef DEBUG |
| 1753 | int original_height = frame_->height(); |
| 1754 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1755 | Comment cmnt(masm_, "[ Declaration"); |
| 1756 | Variable* var = node->proxy()->var(); |
| 1757 | ASSERT(var != NULL); // must have been resolved |
| 1758 | Slot* slot = var->slot(); |
| 1759 | |
| 1760 | // If it was not possible to allocate the variable at compile time, |
| 1761 | // we need to "declare" it at runtime to make sure it actually |
| 1762 | // exists in the local context. |
| 1763 | if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1764 | // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1765 | // during variable resolution and must have mode DYNAMIC. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1766 | ASSERT(var->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1767 | // For now, just do a runtime call. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1768 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1769 | frame_->EmitPush(Operand(var->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1770 | // Declaration nodes are always declared in only two modes. |
| 1771 | ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1772 | PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1773 | frame_->EmitPush(Operand(Smi::FromInt(attr))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1774 | // Push initial value, if any. |
| 1775 | // Note: For variables we must not push an initial value (such as |
| 1776 | // 'undefined') because we may have a (legal) redeclaration and we |
| 1777 | // must not destroy the current value. |
| 1778 | if (node->mode() == Variable::CONST) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1779 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1780 | } else if (node->fun() != NULL) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1781 | Load(node->fun()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1782 | } else { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1783 | frame_->EmitPush(Operand(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1784 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1785 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1786 | frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1787 | // Ignore the return value (declarations are statements). |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1788 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1789 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1790 | return; |
| 1791 | } |
| 1792 | |
| 1793 | ASSERT(!var->is_global()); |
| 1794 | |
| 1795 | // If we have a function or a constant, we need to initialize the variable. |
| 1796 | Expression* val = NULL; |
| 1797 | if (node->mode() == Variable::CONST) { |
| 1798 | val = new Literal(Factory::the_hole_value()); |
| 1799 | } else { |
| 1800 | val = node->fun(); // NULL if we don't have a function |
| 1801 | } |
| 1802 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1803 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | if (val != NULL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1805 | WriteBarrierCharacter wb_info = |
| 1806 | val->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
| 1807 | if (val->AsLiteral() != NULL) wb_info = NEVER_NEWSPACE; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1808 | // Set initial value. |
| 1809 | Reference target(this, node->proxy()); |
| 1810 | Load(val); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1811 | target.SetValue(NOT_CONST_INIT, wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1812 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1813 | // Get rid of the assigned value (declarations are statements). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1814 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1815 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1816 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1820 | void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1821 | #ifdef DEBUG |
| 1822 | int original_height = frame_->height(); |
| 1823 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1824 | Comment cmnt(masm_, "[ ExpressionStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1825 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1826 | Expression* expression = node->expression(); |
| 1827 | expression->MarkAsStatement(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1828 | Load(expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1829 | frame_->Drop(); |
| 1830 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1834 | void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1835 | #ifdef DEBUG |
| 1836 | int original_height = frame_->height(); |
| 1837 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1838 | Comment cmnt(masm_, "// EmptyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1839 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1840 | // nothing to do |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1841 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1845 | void CodeGenerator::VisitIfStatement(IfStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1846 | #ifdef DEBUG |
| 1847 | int original_height = frame_->height(); |
| 1848 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | Comment cmnt(masm_, "[ IfStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1850 | // Generate different code depending on which parts of the if statement |
| 1851 | // are present or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | bool has_then_stm = node->HasThenStatement(); |
| 1853 | bool has_else_stm = node->HasElseStatement(); |
| 1854 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1855 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1856 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1857 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1858 | if (has_then_stm && has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1859 | Comment cmnt(masm_, "[ IfThenElse"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1860 | JumpTarget then; |
| 1861 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1863 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1864 | if (frame_ != NULL) { |
| 1865 | Branch(false, &else_); |
| 1866 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1867 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1868 | if (frame_ != NULL || then.is_linked()) { |
| 1869 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1870 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1871 | } |
| 1872 | if (frame_ != NULL) { |
| 1873 | exit.Jump(); |
| 1874 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1875 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1876 | if (else_.is_linked()) { |
| 1877 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1878 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1879 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | |
| 1881 | } else if (has_then_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1882 | Comment cmnt(masm_, "[ IfThen"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1883 | ASSERT(!has_else_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1884 | JumpTarget then; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1885 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1886 | LoadCondition(node->condition(), &then, &exit, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1887 | if (frame_ != NULL) { |
| 1888 | Branch(false, &exit); |
| 1889 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1890 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1891 | if (frame_ != NULL || then.is_linked()) { |
| 1892 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1893 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1894 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1895 | |
| 1896 | } else if (has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1897 | Comment cmnt(masm_, "[ IfElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1898 | ASSERT(!has_then_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1899 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1900 | // if (!cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1901 | LoadCondition(node->condition(), &exit, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1902 | if (frame_ != NULL) { |
| 1903 | Branch(true, &exit); |
| 1904 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1905 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1906 | if (frame_ != NULL || else_.is_linked()) { |
| 1907 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1908 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1909 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1910 | |
| 1911 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1912 | Comment cmnt(masm_, "[ If"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1913 | ASSERT(!has_then_stm && !has_else_stm); |
| 1914 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1915 | LoadCondition(node->condition(), &exit, &exit, false); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1916 | if (frame_ != NULL) { |
| 1917 | if (has_cc()) { |
| 1918 | cc_reg_ = al; |
| 1919 | } else { |
| 1920 | frame_->Drop(); |
| 1921 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1922 | } |
| 1923 | } |
| 1924 | |
| 1925 | // end |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1926 | if (exit.is_linked()) { |
| 1927 | exit.Bind(); |
| 1928 | } |
| 1929 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1933 | void CodeGenerator::VisitContinueStatement(ContinueStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1934 | Comment cmnt(masm_, "[ ContinueStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1935 | CodeForStatementPosition(node); |
| 1936 | node->target()->continue_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1940 | void CodeGenerator::VisitBreakStatement(BreakStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1941 | Comment cmnt(masm_, "[ BreakStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1942 | CodeForStatementPosition(node); |
| 1943 | node->target()->break_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1947 | void CodeGenerator::VisitReturnStatement(ReturnStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | Comment cmnt(masm_, "[ ReturnStatement"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1949 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1950 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1951 | Load(node->expression()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1952 | frame_->PopToR0(); |
| 1953 | frame_->PrepareForReturn(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1954 | if (function_return_is_shadowed_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1955 | function_return_.Jump(); |
| 1956 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1957 | // Pop the result from the frame and prepare the frame for |
| 1958 | // returning thus making it easier to merge. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1959 | if (function_return_.is_bound()) { |
| 1960 | // If the function return label is already bound we reuse the |
| 1961 | // code by jumping to the return site. |
| 1962 | function_return_.Jump(); |
| 1963 | } else { |
| 1964 | function_return_.Bind(); |
| 1965 | GenerateReturnSequence(); |
| 1966 | } |
| 1967 | } |
| 1968 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1969 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1970 | |
| 1971 | void CodeGenerator::GenerateReturnSequence() { |
| 1972 | if (FLAG_trace) { |
| 1973 | // Push the return value on the stack as the parameter. |
| 1974 | // Runtime::TraceExit returns the parameter as it is. |
| 1975 | frame_->EmitPush(r0); |
| 1976 | frame_->CallRuntime(Runtime::kTraceExit, 1); |
| 1977 | } |
| 1978 | |
| 1979 | #ifdef DEBUG |
| 1980 | // Add a label for checking the size of the code used for returning. |
| 1981 | Label check_exit_codesize; |
| 1982 | masm_->bind(&check_exit_codesize); |
| 1983 | #endif |
| 1984 | // Make sure that the constant pool is not emitted inside of the return |
| 1985 | // sequence. |
| 1986 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 1987 | // Tear down the frame which will restore the caller's frame pointer and |
| 1988 | // the link register. |
| 1989 | frame_->Exit(); |
| 1990 | |
| 1991 | // Here we use masm_-> instead of the __ macro to avoid the code coverage |
| 1992 | // tool from instrumenting as we rely on the code size here. |
| 1993 | int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
| 1994 | masm_->add(sp, sp, Operand(sp_delta)); |
| 1995 | masm_->Jump(lr); |
| 1996 | DeleteFrame(); |
| 1997 | |
| 1998 | #ifdef DEBUG |
| 1999 | // Check that the size of the code used for returning matches what is |
| 2000 | // expected by the debugger. If the sp_delts above cannot be encoded in |
| 2001 | // the add instruction the add will generate two instructions. |
| 2002 | int return_sequence_length = |
| 2003 | masm_->InstructionsGeneratedSince(&check_exit_codesize); |
| 2004 | CHECK(return_sequence_length == |
| 2005 | Assembler::kJSReturnSequenceInstructions || |
| 2006 | return_sequence_length == |
| 2007 | Assembler::kJSReturnSequenceInstructions + 1); |
| 2008 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2009 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2013 | void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2014 | #ifdef DEBUG |
| 2015 | int original_height = frame_->height(); |
| 2016 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2017 | Comment cmnt(masm_, "[ WithEnterStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2018 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2019 | Load(node->expression()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2020 | if (node->is_catch_block()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2021 | frame_->CallRuntime(Runtime::kPushCatchContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2022 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2023 | frame_->CallRuntime(Runtime::kPushContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2024 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2025 | #ifdef DEBUG |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2026 | JumpTarget verified_true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2027 | __ cmp(r0, cp); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2028 | verified_true.Branch(eq); |
| 2029 | __ stop("PushContext: r0 is expected to be the same as cp"); |
| 2030 | verified_true.Bind(); |
| 2031 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2032 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2033 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2034 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2038 | void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2039 | #ifdef DEBUG |
| 2040 | int original_height = frame_->height(); |
| 2041 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2042 | Comment cmnt(masm_, "[ WithExitStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2043 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2044 | // Pop context. |
| 2045 | __ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX)); |
| 2046 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2047 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2048 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
| 2051 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2052 | void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2053 | #ifdef DEBUG |
| 2054 | int original_height = frame_->height(); |
| 2055 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2056 | Comment cmnt(masm_, "[ SwitchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2057 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2058 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2059 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2060 | Load(node->tag()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2061 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2062 | JumpTarget next_test; |
| 2063 | JumpTarget fall_through; |
| 2064 | JumpTarget default_entry; |
| 2065 | JumpTarget default_exit(JumpTarget::BIDIRECTIONAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2066 | ZoneList<CaseClause*>* cases = node->cases(); |
| 2067 | int length = cases->length(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2068 | CaseClause* default_clause = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2069 | |
| 2070 | for (int i = 0; i < length; i++) { |
| 2071 | CaseClause* clause = cases->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2072 | if (clause->is_default()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2073 | // Remember the default clause and compile it at the end. |
| 2074 | default_clause = clause; |
| 2075 | continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2076 | } |
| 2077 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2078 | Comment cmnt(masm_, "[ Case clause"); |
| 2079 | // Compile the test. |
| 2080 | next_test.Bind(); |
| 2081 | next_test.Unuse(); |
| 2082 | // Duplicate TOS. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2083 | frame_->Dup(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2084 | Comparison(eq, NULL, clause->label(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2085 | Branch(false, &next_test); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2086 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2087 | // Before entering the body from the test, remove the switch value from |
| 2088 | // the stack. |
| 2089 | frame_->Drop(); |
| 2090 | |
| 2091 | // Label the body so that fall through is enabled. |
| 2092 | if (i > 0 && cases->at(i - 1)->is_default()) { |
| 2093 | default_exit.Bind(); |
| 2094 | } else { |
| 2095 | fall_through.Bind(); |
| 2096 | fall_through.Unuse(); |
| 2097 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2098 | VisitStatements(clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2099 | |
| 2100 | // If control flow can fall through from the body, jump to the next body |
| 2101 | // or the end of the statement. |
| 2102 | if (frame_ != NULL) { |
| 2103 | if (i < length - 1 && cases->at(i + 1)->is_default()) { |
| 2104 | default_entry.Jump(); |
| 2105 | } else { |
| 2106 | fall_through.Jump(); |
| 2107 | } |
| 2108 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2109 | } |
| 2110 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2111 | // The final "test" removes the switch value. |
| 2112 | next_test.Bind(); |
| 2113 | frame_->Drop(); |
| 2114 | |
| 2115 | // If there is a default clause, compile it. |
| 2116 | if (default_clause != NULL) { |
| 2117 | Comment cmnt(masm_, "[ Default clause"); |
| 2118 | default_entry.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2119 | VisitStatements(default_clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2120 | // If control flow can fall out of the default and there is a case after |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2121 | // it, jump to that case's body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2122 | if (frame_ != NULL && default_exit.is_bound()) { |
| 2123 | default_exit.Jump(); |
| 2124 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2125 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2126 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2127 | if (fall_through.is_linked()) { |
| 2128 | fall_through.Bind(); |
| 2129 | } |
| 2130 | |
| 2131 | if (node->break_target()->is_linked()) { |
| 2132 | node->break_target()->Bind(); |
| 2133 | } |
| 2134 | node->break_target()->Unuse(); |
| 2135 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2139 | void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2140 | #ifdef DEBUG |
| 2141 | int original_height = frame_->height(); |
| 2142 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2143 | Comment cmnt(masm_, "[ DoWhileStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2144 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2145 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2146 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2147 | IncrementLoopNesting(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2148 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2149 | // Label the top of the loop for the backward CFG edge. If the test |
| 2150 | // is always true we can use the continue target, and if the test is |
| 2151 | // always false there is no need. |
| 2152 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2153 | switch (info) { |
| 2154 | case ALWAYS_TRUE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2155 | node->continue_target()->SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2156 | node->continue_target()->Bind(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2157 | break; |
| 2158 | case ALWAYS_FALSE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2159 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2160 | break; |
| 2161 | case DONT_KNOW: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2162 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2163 | body.Bind(); |
| 2164 | break; |
| 2165 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2166 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2167 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2168 | Visit(node->body()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2169 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2170 | // Compile the test. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2171 | switch (info) { |
| 2172 | case ALWAYS_TRUE: |
| 2173 | // If control can fall off the end of the body, jump back to the |
| 2174 | // top. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2175 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2176 | node->continue_target()->Jump(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2177 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2178 | break; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2179 | case ALWAYS_FALSE: |
| 2180 | // If we have a continue in the body, we only have to bind its |
| 2181 | // jump target. |
| 2182 | if (node->continue_target()->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2183 | node->continue_target()->Bind(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2184 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2185 | break; |
| 2186 | case DONT_KNOW: |
| 2187 | // We have to compile the test expression if it can be reached by |
| 2188 | // control flow falling out of the body or via continue. |
| 2189 | if (node->continue_target()->is_linked()) { |
| 2190 | node->continue_target()->Bind(); |
| 2191 | } |
| 2192 | if (has_valid_frame()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2193 | Comment cmnt(masm_, "[ DoWhileCondition"); |
| 2194 | CodeForDoWhileConditionPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2195 | LoadCondition(node->cond(), &body, node->break_target(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2196 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2197 | // A invalid frame here indicates that control did not |
| 2198 | // fall out of the test expression. |
| 2199 | Branch(true, &body); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2200 | } |
| 2201 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | } |
| 2204 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2205 | if (node->break_target()->is_linked()) { |
| 2206 | node->break_target()->Bind(); |
| 2207 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2208 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2209 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | void CodeGenerator::VisitWhileStatement(WhileStatement* node) { |
| 2214 | #ifdef DEBUG |
| 2215 | int original_height = frame_->height(); |
| 2216 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2217 | Comment cmnt(masm_, "[ WhileStatement"); |
| 2218 | CodeForStatementPosition(node); |
| 2219 | |
| 2220 | // If the test is never true and has no side effects there is no need |
| 2221 | // to compile the test or body. |
| 2222 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2223 | if (info == ALWAYS_FALSE) return; |
| 2224 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2225 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2226 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2227 | |
| 2228 | // Label the top of the loop with the continue target for the backward |
| 2229 | // CFG edge. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2230 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2231 | node->continue_target()->Bind(); |
| 2232 | |
| 2233 | if (info == DONT_KNOW) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2234 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2235 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2236 | if (has_valid_frame()) { |
| 2237 | // A NULL frame indicates that control did not fall out of the |
| 2238 | // test expression. |
| 2239 | Branch(false, node->break_target()); |
| 2240 | } |
| 2241 | if (has_valid_frame() || body.is_linked()) { |
| 2242 | body.Bind(); |
| 2243 | } |
| 2244 | } |
| 2245 | |
| 2246 | if (has_valid_frame()) { |
| 2247 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2248 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2249 | |
| 2250 | // If control flow can fall out of the body, jump back to the top. |
| 2251 | if (has_valid_frame()) { |
| 2252 | node->continue_target()->Jump(); |
| 2253 | } |
| 2254 | } |
| 2255 | if (node->break_target()->is_linked()) { |
| 2256 | node->break_target()->Bind(); |
| 2257 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2258 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2259 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2260 | } |
| 2261 | |
| 2262 | |
| 2263 | void CodeGenerator::VisitForStatement(ForStatement* node) { |
| 2264 | #ifdef DEBUG |
| 2265 | int original_height = frame_->height(); |
| 2266 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2267 | Comment cmnt(masm_, "[ ForStatement"); |
| 2268 | CodeForStatementPosition(node); |
| 2269 | if (node->init() != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2270 | Visit(node->init()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2271 | } |
| 2272 | |
| 2273 | // If the test is never true there is no need to compile the test or |
| 2274 | // body. |
| 2275 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2276 | if (info == ALWAYS_FALSE) return; |
| 2277 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2278 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2279 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2280 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2281 | // We know that the loop index is a smi if it is not modified in the |
| 2282 | // loop body and it is checked against a constant limit in the loop |
| 2283 | // condition. In this case, we reset the static type information of the |
| 2284 | // loop index to smi before compiling the body, the update expression, and |
| 2285 | // the bottom check of the loop condition. |
| 2286 | TypeInfoCodeGenState type_info_scope(this, |
| 2287 | node->is_fast_smi_loop() ? |
| 2288 | node->loop_variable()->slot() : |
| 2289 | NULL, |
| 2290 | TypeInfo::Smi()); |
| 2291 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2292 | // If there is no update statement, label the top of the loop with the |
| 2293 | // continue target, otherwise with the loop target. |
| 2294 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2295 | if (node->next() == NULL) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2296 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2297 | node->continue_target()->Bind(); |
| 2298 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2299 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2300 | loop.Bind(); |
| 2301 | } |
| 2302 | |
| 2303 | // If the test is always true, there is no need to compile it. |
| 2304 | if (info == DONT_KNOW) { |
| 2305 | JumpTarget body; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2306 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2307 | if (has_valid_frame()) { |
| 2308 | Branch(false, node->break_target()); |
| 2309 | } |
| 2310 | if (has_valid_frame() || body.is_linked()) { |
| 2311 | body.Bind(); |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | if (has_valid_frame()) { |
| 2316 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2317 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2318 | |
| 2319 | if (node->next() == NULL) { |
| 2320 | // If there is no update statement and control flow can fall out |
| 2321 | // of the loop, jump directly to the continue label. |
| 2322 | if (has_valid_frame()) { |
| 2323 | node->continue_target()->Jump(); |
| 2324 | } |
| 2325 | } else { |
| 2326 | // If there is an update statement and control flow can reach it |
| 2327 | // via falling out of the body of the loop or continuing, we |
| 2328 | // compile the update statement. |
| 2329 | if (node->continue_target()->is_linked()) { |
| 2330 | node->continue_target()->Bind(); |
| 2331 | } |
| 2332 | if (has_valid_frame()) { |
| 2333 | // Record source position of the statement as this code which is |
| 2334 | // after the code for the body actually belongs to the loop |
| 2335 | // statement and not the body. |
| 2336 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2337 | Visit(node->next()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2338 | loop.Jump(); |
| 2339 | } |
| 2340 | } |
| 2341 | } |
| 2342 | if (node->break_target()->is_linked()) { |
| 2343 | node->break_target()->Bind(); |
| 2344 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2345 | DecrementLoopNesting(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2346 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2350 | void CodeGenerator::VisitForInStatement(ForInStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2351 | #ifdef DEBUG |
| 2352 | int original_height = frame_->height(); |
| 2353 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2354 | Comment cmnt(masm_, "[ ForInStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2355 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2356 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2357 | JumpTarget primitive; |
| 2358 | JumpTarget jsobject; |
| 2359 | JumpTarget fixed_array; |
| 2360 | JumpTarget entry(JumpTarget::BIDIRECTIONAL); |
| 2361 | JumpTarget end_del_check; |
| 2362 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2363 | |
| 2364 | // Get the object to enumerate over (converted to JSObject). |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2365 | Load(node->enumerable()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2366 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2367 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2368 | // Both SpiderMonkey and kjs ignore null and undefined in contrast |
| 2369 | // to the specification. 12.6.4 mandates a call to ToObject. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2370 | frame_->EmitPop(r0); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2371 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 2372 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2373 | exit.Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2374 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2375 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2376 | exit.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2377 | |
| 2378 | // Stack layout in body: |
| 2379 | // [iteration counter (Smi)] |
| 2380 | // [length of array] |
| 2381 | // [FixedArray] |
| 2382 | // [Map or 0] |
| 2383 | // [Object] |
| 2384 | |
| 2385 | // Check if enumerable is already a JSObject |
| 2386 | __ tst(r0, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2387 | primitive.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2388 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2389 | jsobject.Branch(hs); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2390 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2391 | primitive.Bind(); |
| 2392 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2393 | frame_->InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2394 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2395 | jsobject.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2396 | // Get the set of properties (as a FixedArray or Map). |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2397 | // r0: value to be iterated over |
| 2398 | frame_->EmitPush(r0); // Push the object being iterated over. |
| 2399 | |
| 2400 | // Check cache validity in generated code. This is a fast case for |
| 2401 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 2402 | // guarantee cache validity, call the runtime system to check cache |
| 2403 | // validity or get the property names in a fixed array. |
| 2404 | JumpTarget call_runtime; |
| 2405 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2406 | JumpTarget check_prototype; |
| 2407 | JumpTarget use_cache; |
| 2408 | __ mov(r1, Operand(r0)); |
| 2409 | loop.Bind(); |
| 2410 | // Check that there are no elements. |
| 2411 | __ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 2412 | __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex); |
| 2413 | __ cmp(r2, r4); |
| 2414 | call_runtime.Branch(ne); |
| 2415 | // Check that instance descriptors are not empty so that we can |
| 2416 | // check for an enum cache. Leave the map in r3 for the subsequent |
| 2417 | // prototype load. |
| 2418 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2419 | __ ldr(r2, FieldMemOperand(r3, Map::kInstanceDescriptorsOffset)); |
| 2420 | __ LoadRoot(ip, Heap::kEmptyDescriptorArrayRootIndex); |
| 2421 | __ cmp(r2, ip); |
| 2422 | call_runtime.Branch(eq); |
| 2423 | // Check that there in an enum cache in the non-empty instance |
| 2424 | // descriptors. This is the case if the next enumeration index |
| 2425 | // field does not contain a smi. |
| 2426 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumerationIndexOffset)); |
| 2427 | __ tst(r2, Operand(kSmiTagMask)); |
| 2428 | call_runtime.Branch(eq); |
| 2429 | // For all objects but the receiver, check that the cache is empty. |
| 2430 | // r4: empty fixed array root. |
| 2431 | __ cmp(r1, r0); |
| 2432 | check_prototype.Branch(eq); |
| 2433 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2434 | __ cmp(r2, r4); |
| 2435 | call_runtime.Branch(ne); |
| 2436 | check_prototype.Bind(); |
| 2437 | // Load the prototype from the map and loop if non-null. |
| 2438 | __ ldr(r1, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 2439 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2440 | __ cmp(r1, ip); |
| 2441 | loop.Branch(ne); |
| 2442 | // The enum cache is valid. Load the map of the object being |
| 2443 | // iterated over and use the cache for the iteration. |
| 2444 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2445 | use_cache.Jump(); |
| 2446 | |
| 2447 | call_runtime.Bind(); |
| 2448 | // Call the runtime to get the property names for the object. |
| 2449 | frame_->EmitPush(r0); // push the object (slot 4) for the runtime call |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2450 | frame_->CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2451 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2452 | // If we got a map from the runtime call, we can do a fast |
| 2453 | // modification check. Otherwise, we got a fixed array, and we have |
| 2454 | // to do a slow check. |
| 2455 | // r0: map or fixed array (result from call to |
| 2456 | // Runtime::kGetPropertyNamesFast) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2457 | __ mov(r2, Operand(r0)); |
| 2458 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2459 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 2460 | __ cmp(r1, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2461 | fixed_array.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2462 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2463 | use_cache.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2464 | // Get enum cache |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2465 | // r0: map (either the result from a call to |
| 2466 | // Runtime::kGetPropertyNamesFast or has been fetched directly from |
| 2467 | // the object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | __ mov(r1, Operand(r0)); |
| 2469 | __ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset)); |
| 2470 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 2471 | __ ldr(r2, |
| 2472 | FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2473 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2474 | frame_->EmitPush(r0); // map |
| 2475 | frame_->EmitPush(r2); // enum cache bridge cache |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2476 | __ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2477 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2478 | __ mov(r0, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2479 | frame_->EmitPush(r0); |
| 2480 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2481 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2482 | fixed_array.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2483 | __ mov(r1, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2484 | frame_->EmitPush(r1); // insert 0 in place of Map |
| 2485 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2486 | |
| 2487 | // Push the length of the array and the initial index onto the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2488 | __ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2489 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2490 | __ mov(r0, Operand(Smi::FromInt(0))); // init index |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2491 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2492 | |
| 2493 | // Condition. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2494 | entry.Bind(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2495 | // sp[0] : index |
| 2496 | // sp[1] : array/enum cache length |
| 2497 | // sp[2] : array or enum cache |
| 2498 | // sp[3] : 0 or map |
| 2499 | // sp[4] : enumerable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2500 | // Grab the current frame's height for the break and continue |
| 2501 | // targets only after all the state is pushed on the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2502 | node->break_target()->SetExpectedHeight(); |
| 2503 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2504 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2505 | // Load the current count to r0, load the length to r1. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2506 | __ Ldrd(r0, r1, frame_->ElementAt(0)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2507 | __ cmp(r0, r1); // compare to the array length |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2508 | node->break_target()->Branch(hs); |
| 2509 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2510 | // Get the i'th entry of the array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2511 | __ ldr(r2, frame_->ElementAt(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2512 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2513 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 2514 | |
| 2515 | // Get Map or 0. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2516 | __ ldr(r2, frame_->ElementAt(3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2517 | // Check if this (still) matches the map of the enumerable. |
| 2518 | // If not, we have to filter the key. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2519 | __ ldr(r1, frame_->ElementAt(4)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2520 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2521 | __ cmp(r1, Operand(r2)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2522 | end_del_check.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2523 | |
| 2524 | // Convert the entry to a string (or null if it isn't a property anymore). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2525 | __ ldr(r0, frame_->ElementAt(4)); // push enumerable |
| 2526 | frame_->EmitPush(r0); |
| 2527 | frame_->EmitPush(r3); // push entry |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2528 | frame_->InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS, 2); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2529 | __ mov(r3, Operand(r0), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2530 | // If the property has been removed while iterating, we just skip it. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2531 | node->continue_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2532 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2533 | end_del_check.Bind(); |
| 2534 | // Store the entry in the 'each' expression and take another spin in the |
| 2535 | // loop. r3: i'th entry of the enum cache (or string there of) |
| 2536 | frame_->EmitPush(r3); // push entry |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2537 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2538 | Reference each(this, node->each()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2539 | if (!each.is_illegal()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2540 | if (each.size() > 0) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2541 | // Loading a reference may leave the frame in an unspilled state. |
| 2542 | frame_->SpillAll(); // Sync stack to memory. |
| 2543 | // Get the value (under the reference on the stack) from memory. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2544 | __ ldr(r0, frame_->ElementAt(each.size())); |
| 2545 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2546 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2547 | frame_->Drop(2); // The result of the set and the extra pushed value. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2548 | } else { |
| 2549 | // If the reference was to a slot we rely on the convenient property |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2550 | // that it doesn't matter whether a value (eg, ebx pushed above) is |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2551 | // right on top of or right underneath a zero-sized reference. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2552 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2553 | frame_->Drop(1); // Drop the result of the set operation. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2554 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2555 | } |
| 2556 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2557 | // Body. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2558 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2559 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2560 | Visit(node->body()); |
| 2561 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2562 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2563 | // Next. Reestablish a spilled frame in case we are coming here via |
| 2564 | // a continue in the body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2565 | node->continue_target()->Bind(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2566 | frame_->SpillAll(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2567 | frame_->EmitPop(r0); |
| 2568 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 2569 | frame_->EmitPush(r0); |
| 2570 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2571 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2572 | // Cleanup. No need to spill because VirtualFrame::Drop is safe for |
| 2573 | // any frame. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2574 | node->break_target()->Bind(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2575 | frame_->Drop(5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2576 | |
| 2577 | // Exit. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2578 | exit.Bind(); |
| 2579 | node->continue_target()->Unuse(); |
| 2580 | node->break_target()->Unuse(); |
| 2581 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2585 | void CodeGenerator::VisitTryCatchStatement(TryCatchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2586 | #ifdef DEBUG |
| 2587 | int original_height = frame_->height(); |
| 2588 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2589 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2590 | Comment cmnt(masm_, "[ TryCatchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2591 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2592 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2593 | JumpTarget try_block; |
| 2594 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2595 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2596 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2597 | // --- Catch block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2598 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2599 | |
| 2600 | // Store the caught exception in the catch variable. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2601 | Variable* catch_var = node->catch_var()->var(); |
| 2602 | ASSERT(catch_var != NULL && catch_var->slot() != NULL); |
| 2603 | StoreToSlot(catch_var->slot(), NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2604 | |
| 2605 | // Remove the exception from the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2606 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2607 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2608 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2609 | VisitStatements(node->catch_block()->statements()); |
| 2610 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2611 | if (frame_ != NULL) { |
| 2612 | exit.Jump(); |
| 2613 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2614 | |
| 2615 | |
| 2616 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2617 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2618 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2619 | frame_->PushTryHandler(TRY_CATCH_HANDLER); |
| 2620 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2621 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2622 | // Shadow the labels for all escapes from the try block, including |
| 2623 | // returns. During shadowing, the original label is hidden as the |
| 2624 | // LabelShadow and operations on the original actually affect the |
| 2625 | // shadowing label. |
| 2626 | // |
| 2627 | // We should probably try to unify the escaping labels and the return |
| 2628 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2629 | int nof_escapes = node->escaping_targets()->length(); |
| 2630 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2631 | |
| 2632 | // Add the shadow target for the function return. |
| 2633 | static const int kReturnShadowIndex = 0; |
| 2634 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2635 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2636 | function_return_is_shadowed_ = true; |
| 2637 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2638 | |
| 2639 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2640 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2641 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2645 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2646 | VisitStatements(node->try_block()->statements()); |
| 2647 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2648 | |
| 2649 | // Stop the introduced shadowing and count the number of required unlinks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2650 | // After shadowing stops, the original labels are unshadowed and the |
| 2651 | // LabelShadows represent the formerly shadowing labels. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2652 | bool has_unlinks = false; |
| 2653 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2654 | shadows[i]->StopShadowing(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2655 | has_unlinks = has_unlinks || shadows[i]->is_linked(); |
| 2656 | } |
| 2657 | function_return_is_shadowed_ = function_return_was_shadowed; |
| 2658 | |
| 2659 | // Get an external reference to the handler address. |
| 2660 | ExternalReference handler_address(Top::k_handler_address); |
| 2661 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2662 | // If we can fall off the end of the try block, unlink from try chain. |
| 2663 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2664 | // The next handler address is on top of the frame. Unlink from |
| 2665 | // the handler list and drop the rest of this handler from the |
| 2666 | // frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2667 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2668 | frame_->EmitPop(r1); // r0 can contain the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2669 | __ mov(r3, Operand(handler_address)); |
| 2670 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2671 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2672 | if (has_unlinks) { |
| 2673 | exit.Jump(); |
| 2674 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2677 | // Generate unlink code for the (formerly) shadowing labels that have been |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2678 | // jumped to. Deallocate each shadow target. |
| 2679 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2680 | if (shadows[i]->is_linked()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2681 | // Unlink from try chain; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2682 | shadows[i]->Bind(); |
| 2683 | // Because we can be jumping here (to spilled code) from unspilled |
| 2684 | // code, we need to reestablish a spilled frame at this block. |
| 2685 | frame_->SpillAll(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2687 | // Reload sp from the top handler, because some statements that we |
| 2688 | // break from (eg, for...in) may have left stuff on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2689 | __ mov(r3, Operand(handler_address)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2690 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2691 | frame_->Forget(frame_->height() - handler_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2692 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2693 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2694 | frame_->EmitPop(r1); // r0 can contain the return value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2695 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2696 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2697 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2698 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
| 2699 | frame_->PrepareForReturn(); |
| 2700 | } |
| 2701 | shadows[i]->other_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2702 | } |
| 2703 | } |
| 2704 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2705 | exit.Bind(); |
| 2706 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2710 | void CodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2711 | #ifdef DEBUG |
| 2712 | int original_height = frame_->height(); |
| 2713 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2714 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2715 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2716 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2717 | |
| 2718 | // State: Used to keep track of reason for entering the finally |
| 2719 | // block. Should probably be extended to hold information for |
| 2720 | // break/continue from within the try block. |
| 2721 | enum { FALLING, THROWING, JUMPING }; |
| 2722 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2723 | JumpTarget try_block; |
| 2724 | JumpTarget finally_block; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2725 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2726 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2727 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2728 | frame_->EmitPush(r0); // save exception object on the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2729 | // In case of thrown exceptions, this is where we continue. |
| 2730 | __ mov(r2, Operand(Smi::FromInt(THROWING))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2731 | finally_block.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2732 | |
| 2733 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2734 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2735 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2736 | frame_->PushTryHandler(TRY_FINALLY_HANDLER); |
| 2737 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2738 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2739 | // Shadow the labels for all escapes from the try block, including |
| 2740 | // returns. Shadowing hides the original label as the LabelShadow and |
| 2741 | // operations on the original actually affect the shadowing label. |
| 2742 | // |
| 2743 | // We should probably try to unify the escaping labels and the return |
| 2744 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2745 | int nof_escapes = node->escaping_targets()->length(); |
| 2746 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2747 | |
| 2748 | // Add the shadow target for the function return. |
| 2749 | static const int kReturnShadowIndex = 0; |
| 2750 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2751 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2752 | function_return_is_shadowed_ = true; |
| 2753 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2754 | |
| 2755 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2756 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2757 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2761 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2762 | VisitStatements(node->try_block()->statements()); |
| 2763 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2765 | // Stop the introduced shadowing and count the number of required unlinks. |
| 2766 | // After shadowing stops, the original labels are unshadowed and the |
| 2767 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2768 | int nof_unlinks = 0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2769 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2770 | shadows[i]->StopShadowing(); |
| 2771 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 2772 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2773 | function_return_is_shadowed_ = function_return_was_shadowed; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2774 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2775 | // Get an external reference to the handler address. |
| 2776 | ExternalReference handler_address(Top::k_handler_address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2777 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2778 | // If we can fall off the end of the try block, unlink from the try |
| 2779 | // chain and set the state on the frame to FALLING. |
| 2780 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2781 | // The next handler address is on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2782 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2783 | frame_->EmitPop(r1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2784 | __ mov(r3, Operand(handler_address)); |
| 2785 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2786 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2787 | |
| 2788 | // Fake a top of stack value (unneeded when FALLING) and set the |
| 2789 | // state in r2, then jump around the unlink blocks if any. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2790 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2791 | frame_->EmitPush(r0); |
| 2792 | __ mov(r2, Operand(Smi::FromInt(FALLING))); |
| 2793 | if (nof_unlinks > 0) { |
| 2794 | finally_block.Jump(); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | // Generate code to unlink and set the state for the (formerly) |
| 2799 | // shadowing targets that have been jumped to. |
| 2800 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2801 | if (shadows[i]->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2802 | // If we have come from the shadowed return, the return value is |
| 2803 | // in (a non-refcounted reference to) r0. We must preserve it |
| 2804 | // until it is pushed. |
| 2805 | // |
| 2806 | // Because we can be jumping here (to spilled code) from |
| 2807 | // unspilled code, we need to reestablish a spilled frame at |
| 2808 | // this block. |
| 2809 | shadows[i]->Bind(); |
| 2810 | frame_->SpillAll(); |
| 2811 | |
| 2812 | // Reload sp from the top handler, because some statements that |
| 2813 | // we break from (eg, for...in) may have left stuff on the |
| 2814 | // stack. |
| 2815 | __ mov(r3, Operand(handler_address)); |
| 2816 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2817 | frame_->Forget(frame_->height() - handler_height); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2818 | |
| 2819 | // Unlink this handler and drop it from the frame. The next |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2820 | // handler address is currently on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2821 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2822 | frame_->EmitPop(r1); |
| 2823 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2824 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2825 | |
| 2826 | if (i == kReturnShadowIndex) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2827 | // If this label shadowed the function return, materialize the |
| 2828 | // return value on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2829 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2830 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2831 | // Fake TOS for targets that shadowed breaks and continues. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2832 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2833 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2834 | } |
| 2835 | __ mov(r2, Operand(Smi::FromInt(JUMPING + i))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2836 | if (--nof_unlinks > 0) { |
| 2837 | // If this is not the last unlink block, jump around the next. |
| 2838 | finally_block.Jump(); |
| 2839 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2840 | } |
| 2841 | } |
| 2842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2843 | // --- Finally block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2844 | finally_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2845 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2846 | // Push the state on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2847 | frame_->EmitPush(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2848 | |
| 2849 | // We keep two elements on the stack - the (possibly faked) result |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2850 | // and the state - while evaluating the finally block. |
| 2851 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2852 | // Generate code for the statements in the finally block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2853 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2854 | VisitStatements(node->finally_block()->statements()); |
| 2855 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2856 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2857 | if (has_valid_frame()) { |
| 2858 | // Restore state and return value or faked TOS. |
| 2859 | frame_->EmitPop(r2); |
| 2860 | frame_->EmitPop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2861 | } |
| 2862 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2863 | // Generate code to jump to the right destination for all used |
| 2864 | // formerly shadowing targets. Deallocate each shadow target. |
| 2865 | for (int i = 0; i < shadows.length(); i++) { |
| 2866 | if (has_valid_frame() && shadows[i]->is_bound()) { |
| 2867 | JumpTarget* original = shadows[i]->other_target(); |
| 2868 | __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); |
| 2869 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2870 | JumpTarget skip; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2871 | skip.Branch(ne); |
| 2872 | frame_->PrepareForReturn(); |
| 2873 | original->Jump(); |
| 2874 | skip.Bind(); |
| 2875 | } else { |
| 2876 | original->Branch(eq); |
| 2877 | } |
| 2878 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2879 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2880 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2881 | if (has_valid_frame()) { |
| 2882 | // Check if we need to rethrow the exception. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2883 | JumpTarget exit; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2884 | __ cmp(r2, Operand(Smi::FromInt(THROWING))); |
| 2885 | exit.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2886 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2887 | // Rethrow exception. |
| 2888 | frame_->EmitPush(r0); |
| 2889 | frame_->CallRuntime(Runtime::kReThrow, 1); |
| 2890 | |
| 2891 | // Done. |
| 2892 | exit.Bind(); |
| 2893 | } |
| 2894 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2898 | void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2899 | #ifdef DEBUG |
| 2900 | int original_height = frame_->height(); |
| 2901 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2902 | Comment cmnt(masm_, "[ DebuggerStatament"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2903 | CodeForStatementPosition(node); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2904 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2905 | frame_->DebugBreak(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2906 | #endif |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2907 | // Ignore the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2908 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2912 | void CodeGenerator::InstantiateFunction( |
| 2913 | Handle<SharedFunctionInfo> function_info) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2914 | // Use the fast case closure allocation code that allocates in new |
| 2915 | // space for nested functions that don't need literals cloning. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2916 | if (scope()->is_function_scope() && function_info->num_literals() == 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2917 | FastNewClosureStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2918 | frame_->EmitPush(Operand(function_info)); |
| 2919 | frame_->SpillAll(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2920 | frame_->CallStub(&stub, 1); |
| 2921 | frame_->EmitPush(r0); |
| 2922 | } else { |
| 2923 | // Create a new closure. |
| 2924 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2925 | frame_->EmitPush(Operand(function_info)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2926 | frame_->CallRuntime(Runtime::kNewClosure, 2); |
| 2927 | frame_->EmitPush(r0); |
| 2928 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2932 | void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2933 | #ifdef DEBUG |
| 2934 | int original_height = frame_->height(); |
| 2935 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2936 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 2937 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2938 | // Build the function info and instantiate it. |
| 2939 | Handle<SharedFunctionInfo> function_info = |
| 2940 | Compiler::BuildFunctionInfo(node, script(), this); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2941 | // Check for stack-overflow exception. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2942 | if (HasStackOverflow()) { |
| 2943 | ASSERT(frame_->height() == original_height); |
| 2944 | return; |
| 2945 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2946 | InstantiateFunction(function_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2947 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2951 | void CodeGenerator::VisitSharedFunctionInfoLiteral( |
| 2952 | SharedFunctionInfoLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2953 | #ifdef DEBUG |
| 2954 | int original_height = frame_->height(); |
| 2955 | #endif |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2956 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
| 2957 | InstantiateFunction(node->shared_function_info()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2958 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2959 | } |
| 2960 | |
| 2961 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2962 | void CodeGenerator::VisitConditional(Conditional* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2963 | #ifdef DEBUG |
| 2964 | int original_height = frame_->height(); |
| 2965 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2966 | Comment cmnt(masm_, "[ Conditional"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2967 | JumpTarget then; |
| 2968 | JumpTarget else_; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2969 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2970 | if (has_valid_frame()) { |
| 2971 | Branch(false, &else_); |
| 2972 | } |
| 2973 | if (has_valid_frame() || then.is_linked()) { |
| 2974 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2975 | Load(node->then_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2976 | } |
| 2977 | if (else_.is_linked()) { |
| 2978 | JumpTarget exit; |
| 2979 | if (has_valid_frame()) exit.Jump(); |
| 2980 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2981 | Load(node->else_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2982 | if (exit.is_linked()) exit.Bind(); |
| 2983 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2984 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2985 | } |
| 2986 | |
| 2987 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2988 | void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) { |
| 2989 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2990 | ASSERT(slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2991 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2992 | // JumpTargets do not yet support merging frames so the frame must be |
| 2993 | // spilled when jumping to these targets. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2994 | JumpTarget slow; |
| 2995 | JumpTarget done; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2996 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2997 | // Generate fast case for loading from slots that correspond to |
| 2998 | // local/global variables or arguments unless they are shadowed by |
| 2999 | // eval-introduced bindings. |
| 3000 | EmitDynamicLoadFromSlotFastCase(slot, |
| 3001 | typeof_state, |
| 3002 | &slow, |
| 3003 | &done); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3004 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3005 | slow.Bind(); |
| 3006 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3007 | frame_->EmitPush(Operand(slot->var()->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3008 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3009 | if (typeof_state == INSIDE_TYPEOF) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3010 | frame_->CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3011 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3012 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3013 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3014 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3015 | done.Bind(); |
| 3016 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3017 | |
| 3018 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3019 | Register scratch = VirtualFrame::scratch0(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3020 | TypeInfo info = type_info(slot); |
| 3021 | frame_->EmitPush(SlotOperand(slot, scratch), info); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3022 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3023 | if (slot->var()->mode() == Variable::CONST) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3024 | // Const slots may contain 'the hole' value (the constant hasn't been |
| 3025 | // initialized yet) which needs to be converted into the 'undefined' |
| 3026 | // value. |
| 3027 | Comment cmnt(masm_, "[ Unhole const"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3028 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3029 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3030 | __ cmp(tos, ip); |
| 3031 | __ LoadRoot(tos, Heap::kUndefinedValueRootIndex, eq); |
| 3032 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3033 | } |
| 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3038 | void CodeGenerator::LoadFromSlotCheckForArguments(Slot* slot, |
| 3039 | TypeofState state) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3040 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3041 | LoadFromSlot(slot, state); |
| 3042 | |
| 3043 | // Bail out quickly if we're not using lazy arguments allocation. |
| 3044 | if (ArgumentsMode() != LAZY_ARGUMENTS_ALLOCATION) return; |
| 3045 | |
| 3046 | // ... or if the slot isn't a non-parameter arguments slot. |
| 3047 | if (slot->type() == Slot::PARAMETER || !slot->is_arguments()) return; |
| 3048 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3049 | // Load the loaded value from the stack into a register but leave it on the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3050 | // stack. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3051 | Register tos = frame_->Peek(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3052 | |
| 3053 | // If the loaded value is the sentinel that indicates that we |
| 3054 | // haven't loaded the arguments object yet, we need to do it now. |
| 3055 | JumpTarget exit; |
| 3056 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3057 | __ cmp(tos, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3058 | exit.Branch(ne); |
| 3059 | frame_->Drop(); |
| 3060 | StoreArgumentsObject(false); |
| 3061 | exit.Bind(); |
| 3062 | } |
| 3063 | |
| 3064 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3065 | void CodeGenerator::StoreToSlot(Slot* slot, InitState init_state) { |
| 3066 | ASSERT(slot != NULL); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3067 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3068 | if (slot->type() == Slot::LOOKUP) { |
| 3069 | ASSERT(slot->var()->is_dynamic()); |
| 3070 | |
| 3071 | // For now, just do a runtime call. |
| 3072 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3073 | frame_->EmitPush(Operand(slot->var()->name())); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3074 | |
| 3075 | if (init_state == CONST_INIT) { |
| 3076 | // Same as the case for a normal store, but ignores attribute |
| 3077 | // (e.g. READ_ONLY) of context slot so that we can initialize |
| 3078 | // const properties (introduced via eval("const foo = (some |
| 3079 | // expr);")). Also, uses the current function context instead of |
| 3080 | // the top context. |
| 3081 | // |
| 3082 | // Note that we must declare the foo upon entry of eval(), via a |
| 3083 | // context slot declaration, but we cannot initialize it at the |
| 3084 | // same time, because the const declaration may be at the end of |
| 3085 | // the eval code (sigh...) and the const variable may have been |
| 3086 | // used before (where its value is 'undefined'). Thus, we can only |
| 3087 | // do the initialization when we actually encounter the expression |
| 3088 | // and when the expression operands are defined and valid, and |
| 3089 | // thus we need the split into 2 operations: declaration of the |
| 3090 | // context slot followed by initialization. |
| 3091 | frame_->CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 3092 | } else { |
| 3093 | frame_->CallRuntime(Runtime::kStoreContextSlot, 3); |
| 3094 | } |
| 3095 | // Storing a variable must keep the (new) value on the expression |
| 3096 | // stack. This is necessary for compiling assignment expressions. |
| 3097 | frame_->EmitPush(r0); |
| 3098 | |
| 3099 | } else { |
| 3100 | ASSERT(!slot->var()->is_dynamic()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3101 | Register scratch = VirtualFrame::scratch0(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3102 | Register scratch2 = VirtualFrame::scratch1(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3103 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3104 | // The frame must be spilled when branching to this target. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3105 | JumpTarget exit; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3106 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3107 | if (init_state == CONST_INIT) { |
| 3108 | ASSERT(slot->var()->mode() == Variable::CONST); |
| 3109 | // Only the first const initialization must be executed (the slot |
| 3110 | // still contains 'the hole' value). When the assignment is |
| 3111 | // executed, the code is identical to a normal store (see below). |
| 3112 | Comment cmnt(masm_, "[ Init const"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3113 | __ ldr(scratch, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3114 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3115 | __ cmp(scratch, ip); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3116 | exit.Branch(ne); |
| 3117 | } |
| 3118 | |
| 3119 | // We must execute the store. Storing a variable must keep the |
| 3120 | // (new) value on the stack. This is necessary for compiling |
| 3121 | // assignment expressions. |
| 3122 | // |
| 3123 | // Note: We will reach here even with slot->var()->mode() == |
| 3124 | // Variable::CONST because of const declarations which will |
| 3125 | // initialize consts to 'the hole' value and by doing so, end up |
| 3126 | // calling this code. r2 may be loaded with context; used below in |
| 3127 | // RecordWrite. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3128 | Register tos = frame_->Peek(); |
| 3129 | __ str(tos, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3130 | if (slot->type() == Slot::CONTEXT) { |
| 3131 | // Skip write barrier if the written value is a smi. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3132 | __ tst(tos, Operand(kSmiTagMask)); |
| 3133 | // We don't use tos any more after here. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3134 | exit.Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3135 | // scratch is loaded with context when calling SlotOperand above. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3136 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3137 | // We need an extra register. Until we have a way to do that in the |
| 3138 | // virtual frame we will cheat and ask for a free TOS register. |
| 3139 | Register scratch3 = frame_->GetTOSRegister(); |
| 3140 | __ RecordWrite(scratch, Operand(offset), scratch2, scratch3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3141 | } |
| 3142 | // If we definitely did not jump over the assignment, we do not need |
| 3143 | // to bind the exit label. Doing so can defeat peephole |
| 3144 | // optimization. |
| 3145 | if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) { |
| 3146 | exit.Bind(); |
| 3147 | } |
| 3148 | } |
| 3149 | } |
| 3150 | |
| 3151 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3152 | void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 3153 | TypeofState typeof_state, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3154 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3155 | // Check that no extension objects have been created by calls to |
| 3156 | // eval from the current scope to the global scope. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3157 | Register tmp = frame_->scratch0(); |
| 3158 | Register tmp2 = frame_->scratch1(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3159 | Register context = cp; |
| 3160 | Scope* s = scope(); |
| 3161 | while (s != NULL) { |
| 3162 | if (s->num_heap_slots() > 0) { |
| 3163 | if (s->calls_eval()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3164 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3165 | // Check that extension is NULL. |
| 3166 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 3167 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3168 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3169 | } |
| 3170 | // Load next context in chain. |
| 3171 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 3172 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3173 | context = tmp; |
| 3174 | } |
| 3175 | // If no outer scope calls eval, we do not need to check more |
| 3176 | // context extensions. |
| 3177 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 3178 | s = s->outer_scope(); |
| 3179 | } |
| 3180 | |
| 3181 | if (s->is_eval_scope()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3182 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3183 | Label next, fast; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3184 | __ Move(tmp, context); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3185 | __ bind(&next); |
| 3186 | // Terminate at global context. |
| 3187 | __ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3188 | __ LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 3189 | __ cmp(tmp2, ip); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3190 | __ b(eq, &fast); |
| 3191 | // Check that extension is NULL. |
| 3192 | __ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX)); |
| 3193 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3194 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3195 | // Load next context in chain. |
| 3196 | __ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 3197 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3198 | __ b(&next); |
| 3199 | __ bind(&fast); |
| 3200 | } |
| 3201 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3202 | // Load the global object. |
| 3203 | LoadGlobal(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3204 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3205 | frame_->CallLoadIC(slot->var()->name(), |
| 3206 | typeof_state == INSIDE_TYPEOF |
| 3207 | ? RelocInfo::CODE_TARGET |
| 3208 | : RelocInfo::CODE_TARGET_CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3212 | void CodeGenerator::EmitDynamicLoadFromSlotFastCase(Slot* slot, |
| 3213 | TypeofState typeof_state, |
| 3214 | JumpTarget* slow, |
| 3215 | JumpTarget* done) { |
| 3216 | // Generate fast-case code for variables that might be shadowed by |
| 3217 | // eval-introduced variables. Eval is used a lot without |
| 3218 | // introducing variables. In those cases, we do not want to |
| 3219 | // perform a runtime call for all variables in the scope |
| 3220 | // containing the eval. |
| 3221 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3222 | LoadFromGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 3223 | frame_->SpillAll(); |
| 3224 | done->Jump(); |
| 3225 | |
| 3226 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
| 3227 | frame_->SpillAll(); |
| 3228 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); |
| 3229 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 3230 | if (potential_slot != NULL) { |
| 3231 | // Generate fast case for locals that rewrite to slots. |
| 3232 | __ ldr(r0, |
| 3233 | ContextSlotOperandCheckExtensions(potential_slot, |
| 3234 | r1, |
| 3235 | r2, |
| 3236 | slow)); |
| 3237 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 3238 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3239 | __ cmp(r0, ip); |
| 3240 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 3241 | } |
| 3242 | done->Jump(); |
| 3243 | } else if (rewrite != NULL) { |
| 3244 | // Generate fast case for argument loads. |
| 3245 | Property* property = rewrite->AsProperty(); |
| 3246 | if (property != NULL) { |
| 3247 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 3248 | Literal* key_literal = property->key()->AsLiteral(); |
| 3249 | if (obj_proxy != NULL && |
| 3250 | key_literal != NULL && |
| 3251 | obj_proxy->IsArguments() && |
| 3252 | key_literal->handle()->IsSmi()) { |
| 3253 | // Load arguments object if there are no eval-introduced |
| 3254 | // variables. Then load the argument from the arguments |
| 3255 | // object using keyed load. |
| 3256 | __ ldr(r0, |
| 3257 | ContextSlotOperandCheckExtensions(obj_proxy->var()->slot(), |
| 3258 | r1, |
| 3259 | r2, |
| 3260 | slow)); |
| 3261 | frame_->EmitPush(r0); |
| 3262 | __ mov(r1, Operand(key_literal->handle())); |
| 3263 | frame_->EmitPush(r1); |
| 3264 | EmitKeyedLoad(); |
| 3265 | done->Jump(); |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | } |
| 3271 | |
| 3272 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3273 | void CodeGenerator::VisitSlot(Slot* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3274 | #ifdef DEBUG |
| 3275 | int original_height = frame_->height(); |
| 3276 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3277 | Comment cmnt(masm_, "[ Slot"); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3278 | LoadFromSlotCheckForArguments(node, NOT_INSIDE_TYPEOF); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3279 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3280 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3281 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3282 | |
| 3283 | void CodeGenerator::VisitVariableProxy(VariableProxy* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3284 | #ifdef DEBUG |
| 3285 | int original_height = frame_->height(); |
| 3286 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3287 | Comment cmnt(masm_, "[ VariableProxy"); |
| 3288 | |
| 3289 | Variable* var = node->var(); |
| 3290 | Expression* expr = var->rewrite(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3291 | if (expr != NULL) { |
| 3292 | Visit(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3293 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3294 | ASSERT(var->is_global()); |
| 3295 | Reference ref(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3296 | ref.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3297 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3298 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3302 | void CodeGenerator::VisitLiteral(Literal* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3303 | #ifdef DEBUG |
| 3304 | int original_height = frame_->height(); |
| 3305 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3306 | Comment cmnt(masm_, "[ Literal"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3307 | Register reg = frame_->GetTOSRegister(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3308 | bool is_smi = node->handle()->IsSmi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3309 | __ mov(reg, Operand(node->handle())); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3310 | frame_->EmitPush(reg, is_smi ? TypeInfo::Smi() : TypeInfo::Unknown()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3311 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3315 | void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3316 | #ifdef DEBUG |
| 3317 | int original_height = frame_->height(); |
| 3318 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3319 | Comment cmnt(masm_, "[ RexExp Literal"); |
| 3320 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3321 | Register tmp = VirtualFrame::scratch0(); |
| 3322 | // Free up a TOS register that can be used to push the literal. |
| 3323 | Register literal = frame_->GetTOSRegister(); |
| 3324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3325 | // Retrieve the literal array and check the allocated entry. |
| 3326 | |
| 3327 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3328 | __ ldr(tmp, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3329 | |
| 3330 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3331 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kLiteralsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3332 | |
| 3333 | // Load the literal at the ast saved index. |
| 3334 | int literal_offset = |
| 3335 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3336 | __ ldr(literal, FieldMemOperand(tmp, literal_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3337 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3338 | JumpTarget materialized; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3339 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3340 | __ cmp(literal, ip); |
| 3341 | // This branch locks the virtual frame at the done label to match the |
| 3342 | // one we have here, where the literal register is not on the stack and |
| 3343 | // nothing is spilled. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3344 | materialized.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3345 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3346 | // If the entry is undefined we call the runtime system to compute |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3347 | // the literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3348 | // literal array (0) |
| 3349 | frame_->EmitPush(tmp); |
| 3350 | // literal index (1) |
| 3351 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3352 | // RegExp pattern (2) |
| 3353 | frame_->EmitPush(Operand(node->pattern())); |
| 3354 | // RegExp flags (3) |
| 3355 | frame_->EmitPush(Operand(node->flags())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3356 | frame_->CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3357 | __ Move(literal, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3358 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3359 | materialized.Bind(); |
| 3360 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3361 | frame_->EmitPush(literal); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3362 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 3363 | frame_->EmitPush(Operand(Smi::FromInt(size))); |
| 3364 | frame_->CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 3365 | // TODO(lrn): Use AllocateInNewSpace macro with fallback to runtime. |
| 3366 | // r0 is newly allocated space. |
| 3367 | |
| 3368 | // Reuse literal variable with (possibly) a new register, still holding |
| 3369 | // the materialized boilerplate. |
| 3370 | literal = frame_->PopToRegister(r0); |
| 3371 | |
| 3372 | __ CopyFields(r0, literal, tmp.bit(), size / kPointerSize); |
| 3373 | |
| 3374 | // Push the clone. |
| 3375 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3376 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3380 | void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3381 | #ifdef DEBUG |
| 3382 | int original_height = frame_->height(); |
| 3383 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3384 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 3385 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3386 | Register literal = frame_->GetTOSRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3387 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3388 | __ ldr(literal, frame_->Function()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3389 | // Literal array. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3390 | __ ldr(literal, FieldMemOperand(literal, JSFunction::kLiteralsOffset)); |
| 3391 | frame_->EmitPush(literal); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3392 | // Literal index. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3393 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3394 | // Constant properties. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3395 | frame_->EmitPush(Operand(node->constant_properties())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3396 | // Should the object literal have fast elements? |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3397 | frame_->EmitPush(Operand(Smi::FromInt(node->fast_elements() ? 1 : 0))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3398 | if (node->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3399 | frame_->CallRuntime(Runtime::kCreateObjectLiteral, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3400 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3401 | frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3402 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3403 | frame_->EmitPush(r0); // save the result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3404 | for (int i = 0; i < node->properties()->length(); i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3405 | // At the start of each iteration, the top of stack contains |
| 3406 | // the newly created object literal. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3407 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 3408 | Literal* key = property->key(); |
| 3409 | Expression* value = property->value(); |
| 3410 | switch (property->kind()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3411 | case ObjectLiteral::Property::CONSTANT: |
| 3412 | break; |
| 3413 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 3414 | if (CompileTimeValue::IsCompileTimeValue(property->value())) break; |
| 3415 | // else fall through |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3416 | case ObjectLiteral::Property::COMPUTED: |
| 3417 | if (key->handle()->IsSymbol()) { |
| 3418 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3419 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3420 | frame_->PopToR0(); |
| 3421 | // Fetch the object literal. |
| 3422 | frame_->SpillAllButCopyTOSToR1(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3423 | __ mov(r2, Operand(key->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3424 | frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); |
| 3425 | break; |
| 3426 | } |
| 3427 | // else fall through |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3428 | case ObjectLiteral::Property::PROTOTYPE: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3429 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3430 | Load(key); |
| 3431 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3432 | frame_->CallRuntime(Runtime::kSetProperty, 3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3433 | break; |
| 3434 | } |
| 3435 | case ObjectLiteral::Property::SETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3436 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3437 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3438 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3439 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3440 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| 3443 | case ObjectLiteral::Property::GETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3444 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3445 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3446 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3447 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3448 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3449 | break; |
| 3450 | } |
| 3451 | } |
| 3452 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3453 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3457 | void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3458 | #ifdef DEBUG |
| 3459 | int original_height = frame_->height(); |
| 3460 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3461 | Comment cmnt(masm_, "[ ArrayLiteral"); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3462 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3463 | Register tos = frame_->GetTOSRegister(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3464 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3465 | __ ldr(tos, frame_->Function()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3466 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3467 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kLiteralsOffset)); |
| 3468 | frame_->EmitPush(tos); |
| 3469 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3470 | frame_->EmitPush(Operand(node->constant_elements())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3471 | int length = node->values()->length(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3472 | if (node->constant_elements()->map() == Heap::fixed_cow_array_map()) { |
| 3473 | FastCloneShallowArrayStub stub( |
| 3474 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 3475 | frame_->CallStub(&stub, 3); |
| 3476 | __ IncrementCounter(&Counters::cow_arrays_created_stub, 1, r1, r2); |
| 3477 | } else if (node->depth() > 1) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3478 | frame_->CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3479 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3480 | frame_->CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3481 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3482 | FastCloneShallowArrayStub stub( |
| 3483 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3484 | frame_->CallStub(&stub, 3); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3485 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3486 | frame_->EmitPush(r0); // save the result |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3487 | // r0: created object literal |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3488 | |
| 3489 | // Generate code to set the elements in the array that are not |
| 3490 | // literals. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3491 | for (int i = 0; i < node->values()->length(); i++) { |
| 3492 | Expression* value = node->values()->at(i); |
| 3493 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3494 | // If value is a literal the property value is already set in the |
| 3495 | // boilerplate object. |
| 3496 | if (value->AsLiteral() != NULL) continue; |
| 3497 | // If value is a materialized literal the property value is already set |
| 3498 | // in the boilerplate object if it is simple. |
| 3499 | if (CompileTimeValue::IsCompileTimeValue(value)) continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3500 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3501 | // The property must be set by generated code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3502 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3503 | frame_->PopToR0(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3504 | // Fetch the object literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3505 | frame_->SpillAllButCopyTOSToR1(); |
| 3506 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3507 | // Get the elements array. |
| 3508 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3509 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3510 | // Write to the indexed properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3511 | int offset = i * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3512 | __ str(r0, FieldMemOperand(r1, offset)); |
| 3513 | |
| 3514 | // Update the write barrier for the array address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3515 | __ RecordWrite(r1, Operand(offset), r3, r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3516 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3517 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3521 | void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3522 | #ifdef DEBUG |
| 3523 | int original_height = frame_->height(); |
| 3524 | #endif |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3525 | // Call runtime routine to allocate the catch extension object and |
| 3526 | // assign the exception value to the catch variable. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3527 | Comment cmnt(masm_, "[ CatchExtensionObject"); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3528 | Load(node->key()); |
| 3529 | Load(node->value()); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 3530 | frame_->CallRuntime(Runtime::kCreateCatchExtensionObject, 2); |
| 3531 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3532 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3533 | } |
| 3534 | |
| 3535 | |
| 3536 | void CodeGenerator::EmitSlotAssignment(Assignment* node) { |
| 3537 | #ifdef DEBUG |
| 3538 | int original_height = frame_->height(); |
| 3539 | #endif |
| 3540 | Comment cmnt(masm(), "[ Variable Assignment"); |
| 3541 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3542 | ASSERT(var != NULL); |
| 3543 | Slot* slot = var->slot(); |
| 3544 | ASSERT(slot != NULL); |
| 3545 | |
| 3546 | // Evaluate the right-hand side. |
| 3547 | if (node->is_compound()) { |
| 3548 | // For a compound assignment the right-hand side is a binary operation |
| 3549 | // between the current property value and the actual right-hand side. |
| 3550 | LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
| 3551 | |
| 3552 | // Perform the binary operation. |
| 3553 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3554 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3555 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3556 | SmiOperation(node->binary_op(), |
| 3557 | literal->handle(), |
| 3558 | false, |
| 3559 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3560 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3561 | GenerateInlineSmi inline_smi = |
| 3562 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3563 | if (literal != NULL) { |
| 3564 | ASSERT(!literal->handle()->IsSmi()); |
| 3565 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3566 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3567 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3568 | GenericBinaryOperation(node->binary_op(), |
| 3569 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3570 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3571 | } |
| 3572 | } else { |
| 3573 | Load(node->value()); |
| 3574 | } |
| 3575 | |
| 3576 | // Perform the assignment. |
| 3577 | if (var->mode() != Variable::CONST || node->op() == Token::INIT_CONST) { |
| 3578 | CodeForSourcePosition(node->position()); |
| 3579 | StoreToSlot(slot, |
| 3580 | node->op() == Token::INIT_CONST ? CONST_INIT : NOT_CONST_INIT); |
| 3581 | } |
| 3582 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) { |
| 3587 | #ifdef DEBUG |
| 3588 | int original_height = frame_->height(); |
| 3589 | #endif |
| 3590 | Comment cmnt(masm(), "[ Named Property Assignment"); |
| 3591 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3592 | Property* prop = node->target()->AsProperty(); |
| 3593 | ASSERT(var == NULL || (prop == NULL && var->is_global())); |
| 3594 | |
| 3595 | // Initialize name and evaluate the receiver sub-expression if necessary. If |
| 3596 | // the receiver is trivial it is not placed on the stack at this point, but |
| 3597 | // loaded whenever actually needed. |
| 3598 | Handle<String> name; |
| 3599 | bool is_trivial_receiver = false; |
| 3600 | if (var != NULL) { |
| 3601 | name = var->name(); |
| 3602 | } else { |
| 3603 | Literal* lit = prop->key()->AsLiteral(); |
| 3604 | ASSERT_NOT_NULL(lit); |
| 3605 | name = Handle<String>::cast(lit->handle()); |
| 3606 | // Do not materialize the receiver on the frame if it is trivial. |
| 3607 | is_trivial_receiver = prop->obj()->IsTrivial(); |
| 3608 | if (!is_trivial_receiver) Load(prop->obj()); |
| 3609 | } |
| 3610 | |
| 3611 | // Change to slow case in the beginning of an initialization block to |
| 3612 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3613 | if (node->starts_initialization_block()) { |
| 3614 | // Initialization block consists of assignments of the form expr.x = ..., so |
| 3615 | // this will never be an assignment to a variable, so there must be a |
| 3616 | // receiver object. |
| 3617 | ASSERT_EQ(NULL, var); |
| 3618 | if (is_trivial_receiver) { |
| 3619 | Load(prop->obj()); |
| 3620 | } else { |
| 3621 | frame_->Dup(); |
| 3622 | } |
| 3623 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3624 | } |
| 3625 | |
| 3626 | // Change to fast case at the end of an initialization block. To prepare for |
| 3627 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3628 | // converted back to fast case after the assignment. |
| 3629 | if (node->ends_initialization_block() && !is_trivial_receiver) { |
| 3630 | frame_->Dup(); |
| 3631 | } |
| 3632 | |
| 3633 | // Stack layout: |
| 3634 | // [tos] : receiver (only materialized if non-trivial) |
| 3635 | // [tos+1] : receiver if at the end of an initialization block |
| 3636 | |
| 3637 | // Evaluate the right-hand side. |
| 3638 | if (node->is_compound()) { |
| 3639 | // For a compound assignment the right-hand side is a binary operation |
| 3640 | // between the current property value and the actual right-hand side. |
| 3641 | if (is_trivial_receiver) { |
| 3642 | Load(prop->obj()); |
| 3643 | } else if (var != NULL) { |
| 3644 | LoadGlobal(); |
| 3645 | } else { |
| 3646 | frame_->Dup(); |
| 3647 | } |
| 3648 | EmitNamedLoad(name, var != NULL); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3649 | |
| 3650 | // Perform the binary operation. |
| 3651 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3652 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3653 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3654 | SmiOperation(node->binary_op(), |
| 3655 | literal->handle(), |
| 3656 | false, |
| 3657 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3658 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3659 | GenerateInlineSmi inline_smi = |
| 3660 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3661 | if (literal != NULL) { |
| 3662 | ASSERT(!literal->handle()->IsSmi()); |
| 3663 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3664 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3665 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3666 | GenericBinaryOperation(node->binary_op(), |
| 3667 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3668 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3669 | } |
| 3670 | } else { |
| 3671 | // For non-compound assignment just load the right-hand side. |
| 3672 | Load(node->value()); |
| 3673 | } |
| 3674 | |
| 3675 | // Stack layout: |
| 3676 | // [tos] : value |
| 3677 | // [tos+1] : receiver (only materialized if non-trivial) |
| 3678 | // [tos+2] : receiver if at the end of an initialization block |
| 3679 | |
| 3680 | // Perform the assignment. It is safe to ignore constants here. |
| 3681 | ASSERT(var == NULL || var->mode() != Variable::CONST); |
| 3682 | ASSERT_NE(Token::INIT_CONST, node->op()); |
| 3683 | if (is_trivial_receiver) { |
| 3684 | // Load the receiver and swap with the value. |
| 3685 | Load(prop->obj()); |
| 3686 | Register t0 = frame_->PopToRegister(); |
| 3687 | Register t1 = frame_->PopToRegister(t0); |
| 3688 | frame_->EmitPush(t0); |
| 3689 | frame_->EmitPush(t1); |
| 3690 | } |
| 3691 | CodeForSourcePosition(node->position()); |
| 3692 | bool is_contextual = (var != NULL); |
| 3693 | EmitNamedStore(name, is_contextual); |
| 3694 | frame_->EmitPush(r0); |
| 3695 | |
| 3696 | // Change to fast case at the end of an initialization block. |
| 3697 | if (node->ends_initialization_block()) { |
| 3698 | ASSERT_EQ(NULL, var); |
| 3699 | // The argument to the runtime call is the receiver. |
| 3700 | if (is_trivial_receiver) { |
| 3701 | Load(prop->obj()); |
| 3702 | } else { |
| 3703 | // A copy of the receiver is below the value of the assignment. Swap |
| 3704 | // the receiver and the value of the assignment expression. |
| 3705 | Register t0 = frame_->PopToRegister(); |
| 3706 | Register t1 = frame_->PopToRegister(t0); |
| 3707 | frame_->EmitPush(t0); |
| 3708 | frame_->EmitPush(t1); |
| 3709 | } |
| 3710 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3711 | } |
| 3712 | |
| 3713 | // Stack layout: |
| 3714 | // [tos] : result |
| 3715 | |
| 3716 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3717 | } |
| 3718 | |
| 3719 | |
| 3720 | void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) { |
| 3721 | #ifdef DEBUG |
| 3722 | int original_height = frame_->height(); |
| 3723 | #endif |
| 3724 | Comment cmnt(masm_, "[ Keyed Property Assignment"); |
| 3725 | Property* prop = node->target()->AsProperty(); |
| 3726 | ASSERT_NOT_NULL(prop); |
| 3727 | |
| 3728 | // Evaluate the receiver subexpression. |
| 3729 | Load(prop->obj()); |
| 3730 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3731 | WriteBarrierCharacter wb_info; |
| 3732 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3733 | // Change to slow case in the beginning of an initialization block to |
| 3734 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3735 | if (node->starts_initialization_block()) { |
| 3736 | frame_->Dup(); |
| 3737 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3738 | } |
| 3739 | |
| 3740 | // Change to fast case at the end of an initialization block. To prepare for |
| 3741 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3742 | // converted back to fast case after the assignment. |
| 3743 | if (node->ends_initialization_block()) { |
| 3744 | frame_->Dup(); |
| 3745 | } |
| 3746 | |
| 3747 | // Evaluate the key subexpression. |
| 3748 | Load(prop->key()); |
| 3749 | |
| 3750 | // Stack layout: |
| 3751 | // [tos] : key |
| 3752 | // [tos+1] : receiver |
| 3753 | // [tos+2] : receiver if at the end of an initialization block |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3754 | // |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3755 | // Evaluate the right-hand side. |
| 3756 | if (node->is_compound()) { |
| 3757 | // For a compound assignment the right-hand side is a binary operation |
| 3758 | // between the current property value and the actual right-hand side. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3759 | // Duplicate receiver and key for loading the current property value. |
| 3760 | frame_->Dup2(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3761 | EmitKeyedLoad(); |
| 3762 | frame_->EmitPush(r0); |
| 3763 | |
| 3764 | // Perform the binary operation. |
| 3765 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3766 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3767 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3768 | SmiOperation(node->binary_op(), |
| 3769 | literal->handle(), |
| 3770 | false, |
| 3771 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3772 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3773 | GenerateInlineSmi inline_smi = |
| 3774 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3775 | if (literal != NULL) { |
| 3776 | ASSERT(!literal->handle()->IsSmi()); |
| 3777 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3778 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3779 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3780 | GenericBinaryOperation(node->binary_op(), |
| 3781 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3782 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3783 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3784 | wb_info = node->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3785 | } else { |
| 3786 | // For non-compound assignment just load the right-hand side. |
| 3787 | Load(node->value()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3788 | wb_info = node->value()->AsLiteral() != NULL ? |
| 3789 | NEVER_NEWSPACE : |
| 3790 | (node->value()->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | // Stack layout: |
| 3794 | // [tos] : value |
| 3795 | // [tos+1] : key |
| 3796 | // [tos+2] : receiver |
| 3797 | // [tos+3] : receiver if at the end of an initialization block |
| 3798 | |
| 3799 | // Perform the assignment. It is safe to ignore constants here. |
| 3800 | ASSERT(node->op() != Token::INIT_CONST); |
| 3801 | CodeForSourcePosition(node->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3802 | EmitKeyedStore(prop->key()->type(), wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3803 | frame_->EmitPush(r0); |
| 3804 | |
| 3805 | // Stack layout: |
| 3806 | // [tos] : result |
| 3807 | // [tos+1] : receiver if at the end of an initialization block |
| 3808 | |
| 3809 | // Change to fast case at the end of an initialization block. |
| 3810 | if (node->ends_initialization_block()) { |
| 3811 | // The argument to the runtime call is the extra copy of the receiver, |
| 3812 | // which is below the value of the assignment. Swap the receiver and |
| 3813 | // the value of the assignment expression. |
| 3814 | Register t0 = frame_->PopToRegister(); |
| 3815 | Register t1 = frame_->PopToRegister(t0); |
| 3816 | frame_->EmitPush(t1); |
| 3817 | frame_->EmitPush(t0); |
| 3818 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3819 | } |
| 3820 | |
| 3821 | // Stack layout: |
| 3822 | // [tos] : result |
| 3823 | |
| 3824 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3828 | void CodeGenerator::VisitAssignment(Assignment* node) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3829 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3830 | #ifdef DEBUG |
| 3831 | int original_height = frame_->height(); |
| 3832 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3833 | Comment cmnt(masm_, "[ Assignment"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3834 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3835 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3836 | Property* prop = node->target()->AsProperty(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3837 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3838 | if (var != NULL && !var->is_global()) { |
| 3839 | EmitSlotAssignment(node); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3840 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3841 | } else if ((prop != NULL && prop->key()->IsPropertyName()) || |
| 3842 | (var != NULL && var->is_global())) { |
| 3843 | // Properties whose keys are property names and global variables are |
| 3844 | // treated as named property references. We do not need to consider |
| 3845 | // global 'this' because it is not a valid left-hand side. |
| 3846 | EmitNamedPropertyAssignment(node); |
| 3847 | |
| 3848 | } else if (prop != NULL) { |
| 3849 | // Other properties (including rewritten parameters for a function that |
| 3850 | // uses arguments) are keyed property assignments. |
| 3851 | EmitKeyedPropertyAssignment(node); |
| 3852 | |
| 3853 | } else { |
| 3854 | // Invalid left-hand side. |
| 3855 | Load(node->target()); |
| 3856 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
| 3857 | // The runtime call doesn't actually return but the code generator will |
| 3858 | // still generate code and expects a certain frame height. |
| 3859 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3860 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3861 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
| 3864 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3865 | void CodeGenerator::VisitThrow(Throw* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3866 | #ifdef DEBUG |
| 3867 | int original_height = frame_->height(); |
| 3868 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3869 | Comment cmnt(masm_, "[ Throw"); |
| 3870 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3871 | Load(node->exception()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3872 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3873 | frame_->CallRuntime(Runtime::kThrow, 1); |
| 3874 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3875 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3876 | } |
| 3877 | |
| 3878 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3879 | void CodeGenerator::VisitProperty(Property* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3880 | #ifdef DEBUG |
| 3881 | int original_height = frame_->height(); |
| 3882 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3883 | Comment cmnt(masm_, "[ Property"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3884 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3885 | { Reference property(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3886 | property.GetValue(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3887 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3888 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3892 | void CodeGenerator::VisitCall(Call* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3893 | #ifdef DEBUG |
| 3894 | int original_height = frame_->height(); |
| 3895 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3896 | Comment cmnt(masm_, "[ Call"); |
| 3897 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3898 | Expression* function = node->expression(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3899 | ZoneList<Expression*>* args = node->arguments(); |
| 3900 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3901 | // Standard function call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3902 | // Check if the function is a variable or a property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3903 | Variable* var = function->AsVariableProxy()->AsVariable(); |
| 3904 | Property* property = function->AsProperty(); |
| 3905 | |
| 3906 | // ------------------------------------------------------------------------ |
| 3907 | // Fast-case: Use inline caching. |
| 3908 | // --- |
| 3909 | // According to ECMA-262, section 11.2.3, page 44, the function to call |
| 3910 | // must be resolved after the arguments have been evaluated. The IC code |
| 3911 | // automatically handles this by loading the arguments before the function |
| 3912 | // is resolved in cache misses (this also holds for megamorphic calls). |
| 3913 | // ------------------------------------------------------------------------ |
| 3914 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3915 | if (var != NULL && var->is_possibly_eval()) { |
| 3916 | // ---------------------------------- |
| 3917 | // JavaScript example: 'eval(arg)' // eval is not known to be shadowed |
| 3918 | // ---------------------------------- |
| 3919 | |
| 3920 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 3921 | // resolve the function we need to call and the receiver of the |
| 3922 | // call. Then we call the resolved function using the given |
| 3923 | // arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3924 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3925 | // Prepare stack for call to resolved function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3926 | Load(function); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3927 | |
| 3928 | // Allocate a frame slot for the receiver. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3929 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3930 | |
| 3931 | // Load the arguments. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3932 | int arg_count = args->length(); |
| 3933 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3934 | Load(args->at(i)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3935 | } |
| 3936 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3937 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 3938 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3939 | // If we know that eval can only be shadowed by eval-introduced |
| 3940 | // variables we attempt to load the global eval function directly |
| 3941 | // in generated code. If we succeed, there is no need to perform a |
| 3942 | // context lookup in the runtime system. |
| 3943 | JumpTarget done; |
| 3944 | if (var->slot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3945 | ASSERT(var->slot()->type() == Slot::LOOKUP); |
| 3946 | JumpTarget slow; |
| 3947 | // Prepare the stack for the call to |
| 3948 | // ResolvePossiblyDirectEvalNoLookup by pushing the loaded |
| 3949 | // function, the first argument to the eval call and the |
| 3950 | // receiver. |
| 3951 | LoadFromGlobalSlotCheckExtensions(var->slot(), |
| 3952 | NOT_INSIDE_TYPEOF, |
| 3953 | &slow); |
| 3954 | frame_->EmitPush(r0); |
| 3955 | if (arg_count > 0) { |
| 3956 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3957 | frame_->EmitPush(r1); |
| 3958 | } else { |
| 3959 | frame_->EmitPush(r2); |
| 3960 | } |
| 3961 | __ ldr(r1, frame_->Receiver()); |
| 3962 | frame_->EmitPush(r1); |
| 3963 | |
| 3964 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEvalNoLookup, 3); |
| 3965 | |
| 3966 | done.Jump(); |
| 3967 | slow.Bind(); |
| 3968 | } |
| 3969 | |
| 3970 | // Prepare the stack for the call to ResolvePossiblyDirectEval by |
| 3971 | // pushing the loaded function, the first argument to the eval |
| 3972 | // call and the receiver. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3973 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); |
| 3974 | frame_->EmitPush(r1); |
| 3975 | if (arg_count > 0) { |
| 3976 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3977 | frame_->EmitPush(r1); |
| 3978 | } else { |
| 3979 | frame_->EmitPush(r2); |
| 3980 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3981 | __ ldr(r1, frame_->Receiver()); |
| 3982 | frame_->EmitPush(r1); |
| 3983 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3984 | // Resolve the call. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3985 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3986 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3987 | // If we generated fast-case code bind the jump-target where fast |
| 3988 | // and slow case merge. |
| 3989 | if (done.is_linked()) done.Bind(); |
| 3990 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3991 | // Touch up stack with the right values for the function and the receiver. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3992 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3993 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3994 | |
| 3995 | // Call the function. |
| 3996 | CodeForSourcePosition(node->position()); |
| 3997 | |
| 3998 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3999 | CallFunctionStub call_function(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 4000 | frame_->CallStub(&call_function, arg_count + 1); |
| 4001 | |
| 4002 | __ ldr(cp, frame_->Context()); |
| 4003 | // Remove the function from the stack. |
| 4004 | frame_->Drop(); |
| 4005 | frame_->EmitPush(r0); |
| 4006 | |
| 4007 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4008 | // ---------------------------------- |
| 4009 | // JavaScript example: 'foo(1, 2, 3)' // foo is global |
| 4010 | // ---------------------------------- |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4011 | // Pass the global object as the receiver and let the IC stub |
| 4012 | // patch the stack to use the global proxy as 'this' in the |
| 4013 | // invoked function. |
| 4014 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4015 | |
| 4016 | // Load the arguments. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4017 | int arg_count = args->length(); |
| 4018 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4019 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4020 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4021 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4022 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4023 | // Setup the name register and call the IC initialization code. |
| 4024 | __ mov(r2, Operand(var->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4025 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4026 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4027 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4028 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET_CONTEXT, |
| 4029 | arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4030 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4031 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4032 | |
| 4033 | } else if (var != NULL && var->slot() != NULL && |
| 4034 | var->slot()->type() == Slot::LOOKUP) { |
| 4035 | // ---------------------------------- |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4036 | // JavaScript examples: |
| 4037 | // |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4038 | // with (obj) foo(1, 2, 3) // foo may be in obj. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4039 | // |
| 4040 | // function f() {}; |
| 4041 | // function g() { |
| 4042 | // eval(...); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4043 | // f(); // f could be in extension object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4044 | // } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4045 | // ---------------------------------- |
| 4046 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4047 | JumpTarget slow, done; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4048 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4049 | // Generate fast case for loading functions from slots that |
| 4050 | // correspond to local/global variables or arguments unless they |
| 4051 | // are shadowed by eval-introduced bindings. |
| 4052 | EmitDynamicLoadFromSlotFastCase(var->slot(), |
| 4053 | NOT_INSIDE_TYPEOF, |
| 4054 | &slow, |
| 4055 | &done); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4056 | |
| 4057 | slow.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4058 | // Load the function |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4059 | frame_->EmitPush(cp); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4060 | frame_->EmitPush(Operand(var->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4061 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4062 | // r0: slot value; r1: receiver |
| 4063 | |
| 4064 | // Load the receiver. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4065 | frame_->EmitPush(r0); // function |
| 4066 | frame_->EmitPush(r1); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4067 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4068 | // If fast case code has been generated, emit code to push the |
| 4069 | // function and receiver and have the slow path jump around this |
| 4070 | // code. |
| 4071 | if (done.is_linked()) { |
| 4072 | JumpTarget call; |
| 4073 | call.Jump(); |
| 4074 | done.Bind(); |
| 4075 | frame_->EmitPush(r0); // function |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4076 | LoadGlobalReceiver(VirtualFrame::scratch0()); // receiver |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4077 | call.Bind(); |
| 4078 | } |
| 4079 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4080 | // Call the function. At this point, everything is spilled but the |
| 4081 | // function and receiver are in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4082 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4083 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4084 | |
| 4085 | } else if (property != NULL) { |
| 4086 | // Check if the key is a literal string. |
| 4087 | Literal* literal = property->key()->AsLiteral(); |
| 4088 | |
| 4089 | if (literal != NULL && literal->handle()->IsSymbol()) { |
| 4090 | // ------------------------------------------------------------------ |
| 4091 | // JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)' |
| 4092 | // ------------------------------------------------------------------ |
| 4093 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4094 | Handle<String> name = Handle<String>::cast(literal->handle()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4095 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4096 | if (ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION && |
| 4097 | name->IsEqualTo(CStrVector("apply")) && |
| 4098 | args->length() == 2 && |
| 4099 | args->at(1)->AsVariableProxy() != NULL && |
| 4100 | args->at(1)->AsVariableProxy()->IsArguments()) { |
| 4101 | // Use the optimized Function.prototype.apply that avoids |
| 4102 | // allocating lazily allocated arguments objects. |
| 4103 | CallApplyLazy(property->obj(), |
| 4104 | args->at(0), |
| 4105 | args->at(1)->AsVariableProxy(), |
| 4106 | node->position()); |
| 4107 | |
| 4108 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4109 | Load(property->obj()); // Receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4110 | // Load the arguments. |
| 4111 | int arg_count = args->length(); |
| 4112 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4113 | Load(args->at(i)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4116 | VirtualFrame::SpilledScope spilled_scope(frame_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4117 | // Set the name register and call the IC initialization code. |
| 4118 | __ mov(r2, Operand(name)); |
| 4119 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4120 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
| 4121 | CodeForSourcePosition(node->position()); |
| 4122 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4123 | __ ldr(cp, frame_->Context()); |
| 4124 | frame_->EmitPush(r0); |
| 4125 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4126 | |
| 4127 | } else { |
| 4128 | // ------------------------------------------- |
| 4129 | // JavaScript example: 'array[index](1, 2, 3)' |
| 4130 | // ------------------------------------------- |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4131 | Load(property->obj()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4132 | if (property->is_synthetic()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4133 | Load(property->key()); |
| 4134 | EmitKeyedLoad(); |
| 4135 | // Put the function below the receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4136 | // Use the global receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4137 | frame_->EmitPush(r0); // Function. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4138 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4139 | // Call the function. |
| 4140 | CallWithArguments(args, RECEIVER_MIGHT_BE_VALUE, node->position()); |
| 4141 | frame_->EmitPush(r0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4142 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4143 | // Load the arguments. |
| 4144 | int arg_count = args->length(); |
| 4145 | for (int i = 0; i < arg_count; i++) { |
| 4146 | Load(args->at(i)); |
| 4147 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4148 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4149 | // Set the name register and call the IC initialization code. |
| 4150 | Load(property->key()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4151 | frame_->SpillAll(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4152 | frame_->EmitPop(r2); // Function name. |
| 4153 | |
| 4154 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4155 | Handle<Code> stub = ComputeKeyedCallInitialize(arg_count, in_loop); |
| 4156 | CodeForSourcePosition(node->position()); |
| 4157 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4158 | __ ldr(cp, frame_->Context()); |
| 4159 | frame_->EmitPush(r0); |
| 4160 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4161 | } |
| 4162 | |
| 4163 | } else { |
| 4164 | // ---------------------------------- |
| 4165 | // JavaScript example: 'foo(1, 2, 3)' // foo is not global |
| 4166 | // ---------------------------------- |
| 4167 | |
| 4168 | // Load the function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4169 | Load(function); |
| 4170 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4171 | // Pass the global proxy as the receiver. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4172 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4173 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4174 | // Call the function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4175 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4176 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4177 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4178 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4182 | void CodeGenerator::VisitCallNew(CallNew* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4183 | #ifdef DEBUG |
| 4184 | int original_height = frame_->height(); |
| 4185 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4186 | Comment cmnt(masm_, "[ CallNew"); |
| 4187 | |
| 4188 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 4189 | // expression in new calls must be evaluated before the |
| 4190 | // arguments. This is different from ordinary calls, where the |
| 4191 | // actual function to call is resolved after the arguments have been |
| 4192 | // evaluated. |
| 4193 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4194 | // Push constructor on the stack. If it's not a function it's used as |
| 4195 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 4196 | // ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4197 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4198 | |
| 4199 | // Push the arguments ("left-to-right") on the stack. |
| 4200 | ZoneList<Expression*>* args = node->arguments(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4201 | int arg_count = args->length(); |
| 4202 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4203 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4204 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4205 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4206 | // Spill everything from here to simplify the implementation. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4207 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4208 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4209 | // Load the argument count into r0 and the function into r1 as per |
| 4210 | // calling convention. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4211 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4212 | __ ldr(r1, frame_->ElementAt(arg_count)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4213 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4214 | // Call the construct call builtin that handles allocation and |
| 4215 | // constructor invocation. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4216 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4217 | Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4218 | frame_->CallCodeObject(ic, RelocInfo::CONSTRUCT_CALL, arg_count + 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4219 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4220 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4221 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4225 | void CodeGenerator::GenerateClassOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4226 | Register scratch = VirtualFrame::scratch0(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4227 | JumpTarget null, function, leave, non_function_constructor; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4228 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4229 | // Load the object into register. |
| 4230 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4231 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4232 | Register tos = frame_->PopToRegister(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4233 | |
| 4234 | // If the object is a smi, we return null. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4235 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4236 | null.Branch(eq); |
| 4237 | |
| 4238 | // Check that the object is a JS object but take special care of JS |
| 4239 | // functions to make sure they have 'Function' as their class. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4240 | __ CompareObjectType(tos, tos, scratch, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4241 | null.Branch(lt); |
| 4242 | |
| 4243 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 4244 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 4245 | // LAST_JS_OBJECT_TYPE. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 4246 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 4247 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4248 | __ cmp(scratch, Operand(JS_FUNCTION_TYPE)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4249 | function.Branch(eq); |
| 4250 | |
| 4251 | // Check if the constructor in the map is a function. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4252 | __ ldr(tos, FieldMemOperand(tos, Map::kConstructorOffset)); |
| 4253 | __ CompareObjectType(tos, scratch, scratch, JS_FUNCTION_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4254 | non_function_constructor.Branch(ne); |
| 4255 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4256 | // The tos register now contains the constructor function. Grab the |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4257 | // instance class name from there. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4258 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kSharedFunctionInfoOffset)); |
| 4259 | __ ldr(tos, |
| 4260 | FieldMemOperand(tos, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 4261 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4262 | leave.Jump(); |
| 4263 | |
| 4264 | // Functions have class 'Function'. |
| 4265 | function.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4266 | __ mov(tos, Operand(Factory::function_class_symbol())); |
| 4267 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4268 | leave.Jump(); |
| 4269 | |
| 4270 | // Objects with a non-function constructor have class 'Object'. |
| 4271 | non_function_constructor.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4272 | __ mov(tos, Operand(Factory::Object_symbol())); |
| 4273 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4274 | leave.Jump(); |
| 4275 | |
| 4276 | // Non-JS objects have class null. |
| 4277 | null.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4278 | __ LoadRoot(tos, Heap::kNullValueRootIndex); |
| 4279 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4280 | |
| 4281 | // All done. |
| 4282 | leave.Bind(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| 4285 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4286 | void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4287 | Register scratch = VirtualFrame::scratch0(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4288 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4289 | |
| 4290 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4291 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4292 | Register tos = frame_->PopToRegister(); // tos contains object. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4293 | // if (object->IsSmi()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4294 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4295 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4296 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4297 | __ CompareObjectType(tos, scratch, scratch, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4298 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4299 | // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4300 | __ ldr(tos, FieldMemOperand(tos, JSValue::kValueOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4301 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4302 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4303 | } |
| 4304 | |
| 4305 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4306 | void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4307 | Register scratch1 = VirtualFrame::scratch0(); |
| 4308 | Register scratch2 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4309 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4310 | |
| 4311 | ASSERT(args->length() == 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4312 | Load(args->at(0)); // Load the object. |
| 4313 | Load(args->at(1)); // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4314 | Register value = frame_->PopToRegister(); |
| 4315 | Register object = frame_->PopToRegister(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4316 | // if (object->IsSmi()) return object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4317 | __ tst(object, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4318 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4319 | // It is a heap object - get map. If (!object->IsJSValue()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4320 | __ CompareObjectType(object, scratch1, scratch1, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4321 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4322 | // Store the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4323 | __ str(value, FieldMemOperand(object, JSValue::kValueOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4324 | // Update the write barrier. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4325 | __ RecordWrite(object, |
| 4326 | Operand(JSValue::kValueOffset - kHeapObjectTag), |
| 4327 | scratch1, |
| 4328 | scratch2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4329 | // Leave. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4330 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4331 | frame_->EmitPush(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4332 | } |
| 4333 | |
| 4334 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4335 | void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4336 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4337 | Load(args->at(0)); |
| 4338 | Register reg = frame_->PopToRegister(); |
| 4339 | __ tst(reg, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4340 | cc_reg_ = eq; |
| 4341 | } |
| 4342 | |
| 4343 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4344 | void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) { |
| 4345 | // See comment in CodeGenerator::GenerateLog in codegen-ia32.cc. |
| 4346 | ASSERT_EQ(args->length(), 3); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4347 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4348 | if (ShouldGenerateLog(args->at(0))) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4349 | Load(args->at(1)); |
| 4350 | Load(args->at(2)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4351 | frame_->CallRuntime(Runtime::kLog, 2); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4352 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4353 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4354 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4358 | void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4359 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4360 | Load(args->at(0)); |
| 4361 | Register reg = frame_->PopToRegister(); |
| 4362 | __ tst(reg, Operand(kSmiTagMask | 0x80000000u)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4363 | cc_reg_ = eq; |
| 4364 | } |
| 4365 | |
| 4366 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4367 | // Generates the Math.pow method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4368 | void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) { |
| 4369 | ASSERT(args->length() == 2); |
| 4370 | Load(args->at(0)); |
| 4371 | Load(args->at(1)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4372 | |
| 4373 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4374 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4375 | frame_->EmitPush(r0); |
| 4376 | } else { |
| 4377 | CpuFeatures::Scope scope(VFP3); |
| 4378 | JumpTarget runtime, done; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4379 | Label exponent_nonsmi, base_nonsmi, powi, not_minus_half, allocate_return; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4380 | |
| 4381 | Register scratch1 = VirtualFrame::scratch0(); |
| 4382 | Register scratch2 = VirtualFrame::scratch1(); |
| 4383 | |
| 4384 | // Get base and exponent to registers. |
| 4385 | Register exponent = frame_->PopToRegister(); |
| 4386 | Register base = frame_->PopToRegister(exponent); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4387 | Register heap_number_map = no_reg; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4388 | |
| 4389 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4390 | // jump target label so the frame needs to be established before that. |
| 4391 | ASSERT(runtime.entry_frame() == NULL); |
| 4392 | runtime.set_entry_frame(frame_); |
| 4393 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4394 | __ BranchOnNotSmi(exponent, &exponent_nonsmi); |
| 4395 | __ BranchOnNotSmi(base, &base_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4396 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4397 | heap_number_map = r6; |
| 4398 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4399 | |
| 4400 | // Exponent is a smi and base is a smi. Get the smi value into vfp register |
| 4401 | // d1. |
| 4402 | __ SmiToDoubleVFPRegister(base, d1, scratch1, s0); |
| 4403 | __ b(&powi); |
| 4404 | |
| 4405 | __ bind(&base_nonsmi); |
| 4406 | // Exponent is smi and base is non smi. Get the double value from the base |
| 4407 | // into vfp register d1. |
| 4408 | __ ObjectToDoubleVFPRegister(base, d1, |
| 4409 | scratch1, scratch2, heap_number_map, s0, |
| 4410 | runtime.entry_label()); |
| 4411 | |
| 4412 | __ bind(&powi); |
| 4413 | |
| 4414 | // Load 1.0 into d0. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4415 | __ vmov(d0, 1.0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4416 | |
| 4417 | // Get the absolute untagged value of the exponent and use that for the |
| 4418 | // calculation. |
| 4419 | __ mov(scratch1, Operand(exponent, ASR, kSmiTagSize), SetCC); |
| 4420 | __ rsb(scratch1, scratch1, Operand(0), LeaveCC, mi); // Negate if negative. |
| 4421 | __ vmov(d2, d0, mi); // 1.0 needed in d2 later if exponent is negative. |
| 4422 | |
| 4423 | // Run through all the bits in the exponent. The result is calculated in d0 |
| 4424 | // and d1 holds base^(bit^2). |
| 4425 | Label more_bits; |
| 4426 | __ bind(&more_bits); |
| 4427 | __ mov(scratch1, Operand(scratch1, LSR, 1), SetCC); |
| 4428 | __ vmul(d0, d0, d1, cs); // Multiply with base^(bit^2) if bit is set. |
| 4429 | __ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done. |
| 4430 | __ b(ne, &more_bits); |
| 4431 | |
| 4432 | // If exponent is positive we are done. |
| 4433 | __ cmp(exponent, Operand(0)); |
| 4434 | __ b(ge, &allocate_return); |
| 4435 | |
| 4436 | // If exponent is negative result is 1/result (d2 already holds 1.0 in that |
| 4437 | // case). However if d0 has reached infinity this will not provide the |
| 4438 | // correct result, so call runtime if that is the case. |
| 4439 | __ mov(scratch2, Operand(0x7FF00000)); |
| 4440 | __ mov(scratch1, Operand(0)); |
| 4441 | __ vmov(d1, scratch1, scratch2); // Load infinity into d1. |
| 4442 | __ vcmp(d0, d1); |
| 4443 | __ vmrs(pc); |
| 4444 | runtime.Branch(eq); // d0 reached infinity. |
| 4445 | __ vdiv(d0, d2, d0); |
| 4446 | __ b(&allocate_return); |
| 4447 | |
| 4448 | __ bind(&exponent_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4449 | // Special handling of raising to the power of -0.5 and 0.5. First check |
| 4450 | // that the value is a heap number and that the lower bits (which for both |
| 4451 | // values are zero). |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4452 | heap_number_map = r6; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4453 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4454 | __ ldr(scratch1, FieldMemOperand(exponent, HeapObject::kMapOffset)); |
| 4455 | __ ldr(scratch2, FieldMemOperand(exponent, HeapNumber::kMantissaOffset)); |
| 4456 | __ cmp(scratch1, heap_number_map); |
| 4457 | runtime.Branch(ne); |
| 4458 | __ tst(scratch2, scratch2); |
| 4459 | runtime.Branch(ne); |
| 4460 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4461 | // Load the higher bits (which contains the floating point exponent). |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4462 | __ ldr(scratch1, FieldMemOperand(exponent, HeapNumber::kExponentOffset)); |
| 4463 | |
| 4464 | // Compare exponent with -0.5. |
| 4465 | __ cmp(scratch1, Operand(0xbfe00000)); |
| 4466 | __ b(ne, ¬_minus_half); |
| 4467 | |
| 4468 | // Get the double value from the base into vfp register d0. |
| 4469 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4470 | scratch1, scratch2, heap_number_map, s0, |
| 4471 | runtime.entry_label(), |
| 4472 | AVOID_NANS_AND_INFINITIES); |
| 4473 | |
| 4474 | // Load 1.0 into d2. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4475 | __ vmov(d2, 1.0); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4476 | |
| 4477 | // Calculate the reciprocal of the square root. 1/sqrt(x) = sqrt(1/x). |
| 4478 | __ vdiv(d0, d2, d0); |
| 4479 | __ vsqrt(d0, d0); |
| 4480 | |
| 4481 | __ b(&allocate_return); |
| 4482 | |
| 4483 | __ bind(¬_minus_half); |
| 4484 | // Compare exponent with 0.5. |
| 4485 | __ cmp(scratch1, Operand(0x3fe00000)); |
| 4486 | runtime.Branch(ne); |
| 4487 | |
| 4488 | // Get the double value from the base into vfp register d0. |
| 4489 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4490 | scratch1, scratch2, heap_number_map, s0, |
| 4491 | runtime.entry_label(), |
| 4492 | AVOID_NANS_AND_INFINITIES); |
| 4493 | __ vsqrt(d0, d0); |
| 4494 | |
| 4495 | __ bind(&allocate_return); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4496 | Register scratch3 = r5; |
| 4497 | __ AllocateHeapNumberWithValue(scratch3, d0, scratch1, scratch2, |
| 4498 | heap_number_map, runtime.entry_label()); |
| 4499 | __ mov(base, scratch3); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4500 | done.Jump(); |
| 4501 | |
| 4502 | runtime.Bind(); |
| 4503 | |
| 4504 | // Push back the arguments again for the runtime call. |
| 4505 | frame_->EmitPush(base); |
| 4506 | frame_->EmitPush(exponent); |
| 4507 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4508 | __ Move(base, r0); |
| 4509 | |
| 4510 | done.Bind(); |
| 4511 | frame_->EmitPush(base); |
| 4512 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
| 4515 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4516 | // Generates the Math.sqrt method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4517 | void CodeGenerator::GenerateMathSqrt(ZoneList<Expression*>* args) { |
| 4518 | ASSERT(args->length() == 1); |
| 4519 | Load(args->at(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4520 | |
| 4521 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4522 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4523 | frame_->EmitPush(r0); |
| 4524 | } else { |
| 4525 | CpuFeatures::Scope scope(VFP3); |
| 4526 | JumpTarget runtime, done; |
| 4527 | |
| 4528 | Register scratch1 = VirtualFrame::scratch0(); |
| 4529 | Register scratch2 = VirtualFrame::scratch1(); |
| 4530 | |
| 4531 | // Get the value from the frame. |
| 4532 | Register tos = frame_->PopToRegister(); |
| 4533 | |
| 4534 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4535 | // jump target label so the frame needs to be established before that. |
| 4536 | ASSERT(runtime.entry_frame() == NULL); |
| 4537 | runtime.set_entry_frame(frame_); |
| 4538 | |
| 4539 | Register heap_number_map = r6; |
| 4540 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4541 | |
| 4542 | // Get the double value from the heap number into vfp register d0. |
| 4543 | __ ObjectToDoubleVFPRegister(tos, d0, |
| 4544 | scratch1, scratch2, heap_number_map, s0, |
| 4545 | runtime.entry_label()); |
| 4546 | |
| 4547 | // Calculate the square root of d0 and place result in a heap number object. |
| 4548 | __ vsqrt(d0, d0); |
| 4549 | __ AllocateHeapNumberWithValue( |
| 4550 | tos, d0, scratch1, scratch2, heap_number_map, runtime.entry_label()); |
| 4551 | done.Jump(); |
| 4552 | |
| 4553 | runtime.Bind(); |
| 4554 | // Push back the argument again for the runtime call. |
| 4555 | frame_->EmitPush(tos); |
| 4556 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4557 | __ Move(tos, r0); |
| 4558 | |
| 4559 | done.Bind(); |
| 4560 | frame_->EmitPush(tos); |
| 4561 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4565 | class DeferredStringCharCodeAt : public DeferredCode { |
| 4566 | public: |
| 4567 | DeferredStringCharCodeAt(Register object, |
| 4568 | Register index, |
| 4569 | Register scratch, |
| 4570 | Register result) |
| 4571 | : result_(result), |
| 4572 | char_code_at_generator_(object, |
| 4573 | index, |
| 4574 | scratch, |
| 4575 | result, |
| 4576 | &need_conversion_, |
| 4577 | &need_conversion_, |
| 4578 | &index_out_of_range_, |
| 4579 | STRING_INDEX_IS_NUMBER) {} |
| 4580 | |
| 4581 | StringCharCodeAtGenerator* fast_case_generator() { |
| 4582 | return &char_code_at_generator_; |
| 4583 | } |
| 4584 | |
| 4585 | virtual void Generate() { |
| 4586 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4587 | char_code_at_generator_.GenerateSlow(masm(), call_helper); |
| 4588 | |
| 4589 | __ bind(&need_conversion_); |
| 4590 | // Move the undefined value into the result register, which will |
| 4591 | // trigger conversion. |
| 4592 | __ LoadRoot(result_, Heap::kUndefinedValueRootIndex); |
| 4593 | __ jmp(exit_label()); |
| 4594 | |
| 4595 | __ bind(&index_out_of_range_); |
| 4596 | // When the index is out of range, the spec requires us to return |
| 4597 | // NaN. |
| 4598 | __ LoadRoot(result_, Heap::kNanValueRootIndex); |
| 4599 | __ jmp(exit_label()); |
| 4600 | } |
| 4601 | |
| 4602 | private: |
| 4603 | Register result_; |
| 4604 | |
| 4605 | Label need_conversion_; |
| 4606 | Label index_out_of_range_; |
| 4607 | |
| 4608 | StringCharCodeAtGenerator char_code_at_generator_; |
| 4609 | }; |
| 4610 | |
| 4611 | |
| 4612 | // This generates code that performs a String.prototype.charCodeAt() call |
| 4613 | // or returns a smi in order to trigger conversion. |
| 4614 | void CodeGenerator::GenerateStringCharCodeAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4615 | Comment(masm_, "[ GenerateStringCharCodeAt"); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4616 | ASSERT(args->length() == 2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4617 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4618 | Load(args->at(0)); |
| 4619 | Load(args->at(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4620 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4621 | Register index = frame_->PopToRegister(); |
| 4622 | Register object = frame_->PopToRegister(index); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4623 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4624 | // We need two extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4625 | Register scratch = VirtualFrame::scratch0(); |
| 4626 | Register result = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4627 | |
| 4628 | DeferredStringCharCodeAt* deferred = |
| 4629 | new DeferredStringCharCodeAt(object, |
| 4630 | index, |
| 4631 | scratch, |
| 4632 | result); |
| 4633 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4634 | deferred->BindExit(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4635 | frame_->EmitPush(result); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
| 4638 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4639 | class DeferredStringCharFromCode : public DeferredCode { |
| 4640 | public: |
| 4641 | DeferredStringCharFromCode(Register code, |
| 4642 | Register result) |
| 4643 | : char_from_code_generator_(code, result) {} |
| 4644 | |
| 4645 | StringCharFromCodeGenerator* fast_case_generator() { |
| 4646 | return &char_from_code_generator_; |
| 4647 | } |
| 4648 | |
| 4649 | virtual void Generate() { |
| 4650 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4651 | char_from_code_generator_.GenerateSlow(masm(), call_helper); |
| 4652 | } |
| 4653 | |
| 4654 | private: |
| 4655 | StringCharFromCodeGenerator char_from_code_generator_; |
| 4656 | }; |
| 4657 | |
| 4658 | |
| 4659 | // Generates code for creating a one-char string from a char code. |
| 4660 | void CodeGenerator::GenerateStringCharFromCode(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4661 | Comment(masm_, "[ GenerateStringCharFromCode"); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4662 | ASSERT(args->length() == 1); |
| 4663 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4664 | Load(args->at(0)); |
| 4665 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4666 | Register result = frame_->GetTOSRegister(); |
| 4667 | Register code = frame_->PopToRegister(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4668 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4669 | DeferredStringCharFromCode* deferred = new DeferredStringCharFromCode( |
| 4670 | code, result); |
| 4671 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4672 | deferred->BindExit(); |
| 4673 | frame_->EmitPush(result); |
| 4674 | } |
| 4675 | |
| 4676 | |
| 4677 | class DeferredStringCharAt : public DeferredCode { |
| 4678 | public: |
| 4679 | DeferredStringCharAt(Register object, |
| 4680 | Register index, |
| 4681 | Register scratch1, |
| 4682 | Register scratch2, |
| 4683 | Register result) |
| 4684 | : result_(result), |
| 4685 | char_at_generator_(object, |
| 4686 | index, |
| 4687 | scratch1, |
| 4688 | scratch2, |
| 4689 | result, |
| 4690 | &need_conversion_, |
| 4691 | &need_conversion_, |
| 4692 | &index_out_of_range_, |
| 4693 | STRING_INDEX_IS_NUMBER) {} |
| 4694 | |
| 4695 | StringCharAtGenerator* fast_case_generator() { |
| 4696 | return &char_at_generator_; |
| 4697 | } |
| 4698 | |
| 4699 | virtual void Generate() { |
| 4700 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4701 | char_at_generator_.GenerateSlow(masm(), call_helper); |
| 4702 | |
| 4703 | __ bind(&need_conversion_); |
| 4704 | // Move smi zero into the result register, which will trigger |
| 4705 | // conversion. |
| 4706 | __ mov(result_, Operand(Smi::FromInt(0))); |
| 4707 | __ jmp(exit_label()); |
| 4708 | |
| 4709 | __ bind(&index_out_of_range_); |
| 4710 | // When the index is out of range, the spec requires us to return |
| 4711 | // the empty string. |
| 4712 | __ LoadRoot(result_, Heap::kEmptyStringRootIndex); |
| 4713 | __ jmp(exit_label()); |
| 4714 | } |
| 4715 | |
| 4716 | private: |
| 4717 | Register result_; |
| 4718 | |
| 4719 | Label need_conversion_; |
| 4720 | Label index_out_of_range_; |
| 4721 | |
| 4722 | StringCharAtGenerator char_at_generator_; |
| 4723 | }; |
| 4724 | |
| 4725 | |
| 4726 | // This generates code that performs a String.prototype.charAt() call |
| 4727 | // or returns a smi in order to trigger conversion. |
| 4728 | void CodeGenerator::GenerateStringCharAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4729 | Comment(masm_, "[ GenerateStringCharAt"); |
| 4730 | ASSERT(args->length() == 2); |
| 4731 | |
| 4732 | Load(args->at(0)); |
| 4733 | Load(args->at(1)); |
| 4734 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4735 | Register index = frame_->PopToRegister(); |
| 4736 | Register object = frame_->PopToRegister(index); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4737 | |
| 4738 | // We need three extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4739 | Register scratch1 = VirtualFrame::scratch0(); |
| 4740 | Register scratch2 = VirtualFrame::scratch1(); |
| 4741 | // Use r6 without notifying the virtual frame. |
| 4742 | Register result = r6; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4743 | |
| 4744 | DeferredStringCharAt* deferred = |
| 4745 | new DeferredStringCharAt(object, |
| 4746 | index, |
| 4747 | scratch1, |
| 4748 | scratch2, |
| 4749 | result); |
| 4750 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4751 | deferred->BindExit(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4752 | frame_->EmitPush(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4756 | void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4757 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4758 | Load(args->at(0)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4759 | JumpTarget answer; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4760 | // We need the CC bits to come out as not_equal in the case where the |
| 4761 | // object is a smi. This can't be done with the usual test opcode so |
| 4762 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4763 | Register possible_array = frame_->PopToRegister(); |
| 4764 | Register scratch = VirtualFrame::scratch0(); |
| 4765 | __ and_(scratch, possible_array, Operand(kSmiTagMask)); |
| 4766 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4767 | answer.Branch(ne); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4768 | // It is a heap object - get the map. Check if the object is a JS array. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4769 | __ CompareObjectType(possible_array, scratch, scratch, JS_ARRAY_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4770 | answer.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4771 | cc_reg_ = eq; |
| 4772 | } |
| 4773 | |
| 4774 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4775 | void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4776 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4777 | Load(args->at(0)); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4778 | JumpTarget answer; |
| 4779 | // We need the CC bits to come out as not_equal in the case where the |
| 4780 | // object is a smi. This can't be done with the usual test opcode so |
| 4781 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4782 | Register possible_regexp = frame_->PopToRegister(); |
| 4783 | Register scratch = VirtualFrame::scratch0(); |
| 4784 | __ and_(scratch, possible_regexp, Operand(kSmiTagMask)); |
| 4785 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4786 | answer.Branch(ne); |
| 4787 | // It is a heap object - get the map. Check if the object is a regexp. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4788 | __ CompareObjectType(possible_regexp, scratch, scratch, JS_REGEXP_TYPE); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4789 | answer.Bind(); |
| 4790 | cc_reg_ = eq; |
| 4791 | } |
| 4792 | |
| 4793 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4794 | void CodeGenerator::GenerateIsObject(ZoneList<Expression*>* args) { |
| 4795 | // This generates a fast version of: |
| 4796 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4797 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4798 | Load(args->at(0)); |
| 4799 | Register possible_object = frame_->PopToRegister(); |
| 4800 | __ tst(possible_object, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4801 | false_target()->Branch(eq); |
| 4802 | |
| 4803 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4804 | __ cmp(possible_object, ip); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4805 | true_target()->Branch(eq); |
| 4806 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4807 | Register map_reg = VirtualFrame::scratch0(); |
| 4808 | __ ldr(map_reg, FieldMemOperand(possible_object, HeapObject::kMapOffset)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4809 | // Undetectable objects behave like undefined when tested with typeof. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4810 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 4811 | __ tst(possible_object, Operand(1 << Map::kIsUndetectable)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4812 | false_target()->Branch(ne); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4813 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4814 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 4815 | __ cmp(possible_object, Operand(FIRST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4816 | false_target()->Branch(lt); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4817 | __ cmp(possible_object, Operand(LAST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4818 | cc_reg_ = le; |
| 4819 | } |
| 4820 | |
| 4821 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 4822 | void CodeGenerator::GenerateIsSpecObject(ZoneList<Expression*>* args) { |
| 4823 | // This generates a fast version of: |
| 4824 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp' || |
| 4825 | // typeof(arg) == function). |
| 4826 | // It includes undetectable objects (as opposed to IsObject). |
| 4827 | ASSERT(args->length() == 1); |
| 4828 | Load(args->at(0)); |
| 4829 | Register value = frame_->PopToRegister(); |
| 4830 | __ tst(value, Operand(kSmiTagMask)); |
| 4831 | false_target()->Branch(eq); |
| 4832 | // Check that this is an object. |
| 4833 | __ ldr(value, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 4834 | __ ldrb(value, FieldMemOperand(value, Map::kInstanceTypeOffset)); |
| 4835 | __ cmp(value, Operand(FIRST_JS_OBJECT_TYPE)); |
| 4836 | cc_reg_ = ge; |
| 4837 | } |
| 4838 | |
| 4839 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4840 | // Deferred code to check whether the String JavaScript object is safe for using |
| 4841 | // default value of. This code is called after the bit caching this information |
| 4842 | // in the map has been checked with the map for the object in the map_result_ |
| 4843 | // register. On return the register map_result_ contains 1 for true and 0 for |
| 4844 | // false. |
| 4845 | class DeferredIsStringWrapperSafeForDefaultValueOf : public DeferredCode { |
| 4846 | public: |
| 4847 | DeferredIsStringWrapperSafeForDefaultValueOf(Register object, |
| 4848 | Register map_result, |
| 4849 | Register scratch1, |
| 4850 | Register scratch2) |
| 4851 | : object_(object), |
| 4852 | map_result_(map_result), |
| 4853 | scratch1_(scratch1), |
| 4854 | scratch2_(scratch2) { } |
| 4855 | |
| 4856 | virtual void Generate() { |
| 4857 | Label false_result; |
| 4858 | |
| 4859 | // Check that map is loaded as expected. |
| 4860 | if (FLAG_debug_code) { |
| 4861 | __ ldr(ip, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4862 | __ cmp(map_result_, ip); |
| 4863 | __ Assert(eq, "Map not in expected register"); |
| 4864 | } |
| 4865 | |
| 4866 | // Check for fast case object. Generate false result for slow case object. |
| 4867 | __ ldr(scratch1_, FieldMemOperand(object_, JSObject::kPropertiesOffset)); |
| 4868 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 4869 | __ LoadRoot(ip, Heap::kHashTableMapRootIndex); |
| 4870 | __ cmp(scratch1_, ip); |
| 4871 | __ b(eq, &false_result); |
| 4872 | |
| 4873 | // Look for valueOf symbol in the descriptor array, and indicate false if |
| 4874 | // found. The type is not checked, so if it is a transition it is a false |
| 4875 | // negative. |
| 4876 | __ ldr(map_result_, |
| 4877 | FieldMemOperand(map_result_, Map::kInstanceDescriptorsOffset)); |
| 4878 | __ ldr(scratch2_, FieldMemOperand(map_result_, FixedArray::kLengthOffset)); |
| 4879 | // map_result_: descriptor array |
| 4880 | // scratch2_: length of descriptor array |
| 4881 | // Calculate the end of the descriptor array. |
| 4882 | STATIC_ASSERT(kSmiTag == 0); |
| 4883 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4884 | STATIC_ASSERT(kPointerSize == 4); |
| 4885 | __ add(scratch1_, |
| 4886 | map_result_, |
| 4887 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4888 | __ add(scratch1_, |
| 4889 | scratch1_, |
| 4890 | Operand(scratch2_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4891 | |
| 4892 | // Calculate location of the first key name. |
| 4893 | __ add(map_result_, |
| 4894 | map_result_, |
| 4895 | Operand(FixedArray::kHeaderSize - kHeapObjectTag + |
| 4896 | DescriptorArray::kFirstIndex * kPointerSize)); |
| 4897 | // Loop through all the keys in the descriptor array. If one of these is the |
| 4898 | // symbol valueOf the result is false. |
| 4899 | Label entry, loop; |
| 4900 | // The use of ip to store the valueOf symbol asumes that it is not otherwise |
| 4901 | // used in the loop below. |
| 4902 | __ mov(ip, Operand(Factory::value_of_symbol())); |
| 4903 | __ jmp(&entry); |
| 4904 | __ bind(&loop); |
| 4905 | __ ldr(scratch2_, MemOperand(map_result_, 0)); |
| 4906 | __ cmp(scratch2_, ip); |
| 4907 | __ b(eq, &false_result); |
| 4908 | __ add(map_result_, map_result_, Operand(kPointerSize)); |
| 4909 | __ bind(&entry); |
| 4910 | __ cmp(map_result_, Operand(scratch1_)); |
| 4911 | __ b(ne, &loop); |
| 4912 | |
| 4913 | // Reload map as register map_result_ was used as temporary above. |
| 4914 | __ ldr(map_result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4915 | |
| 4916 | // If a valueOf property is not found on the object check that it's |
| 4917 | // prototype is the un-modified String prototype. If not result is false. |
| 4918 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kPrototypeOffset)); |
| 4919 | __ tst(scratch1_, Operand(kSmiTagMask)); |
| 4920 | __ b(eq, &false_result); |
| 4921 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 4922 | __ ldr(scratch2_, |
| 4923 | CodeGenerator::ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 4924 | __ ldr(scratch2_, |
| 4925 | FieldMemOperand(scratch2_, GlobalObject::kGlobalContextOffset)); |
| 4926 | __ ldr(scratch2_, |
| 4927 | CodeGenerator::ContextOperand( |
| 4928 | scratch2_, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 4929 | __ cmp(scratch1_, scratch2_); |
| 4930 | __ b(ne, &false_result); |
| 4931 | |
| 4932 | // Set the bit in the map to indicate that it has been checked safe for |
| 4933 | // default valueOf and set true result. |
| 4934 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 4935 | __ orr(scratch1_, |
| 4936 | scratch1_, |
| 4937 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 4938 | __ str(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 4939 | __ mov(map_result_, Operand(1)); |
| 4940 | __ jmp(exit_label()); |
| 4941 | __ bind(&false_result); |
| 4942 | // Set false result. |
| 4943 | __ mov(map_result_, Operand(0)); |
| 4944 | } |
| 4945 | |
| 4946 | private: |
| 4947 | Register object_; |
| 4948 | Register map_result_; |
| 4949 | Register scratch1_; |
| 4950 | Register scratch2_; |
| 4951 | }; |
| 4952 | |
| 4953 | |
| 4954 | void CodeGenerator::GenerateIsStringWrapperSafeForDefaultValueOf( |
| 4955 | ZoneList<Expression*>* args) { |
| 4956 | ASSERT(args->length() == 1); |
| 4957 | Load(args->at(0)); |
| 4958 | Register obj = frame_->PopToRegister(); // Pop the string wrapper. |
| 4959 | if (FLAG_debug_code) { |
| 4960 | __ AbortIfSmi(obj); |
| 4961 | } |
| 4962 | |
| 4963 | // Check whether this map has already been checked to be safe for default |
| 4964 | // valueOf. |
| 4965 | Register map_result = VirtualFrame::scratch0(); |
| 4966 | __ ldr(map_result, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 4967 | __ ldrb(ip, FieldMemOperand(map_result, Map::kBitField2Offset)); |
| 4968 | __ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 4969 | true_target()->Branch(ne); |
| 4970 | |
| 4971 | // We need an additional two scratch registers for the deferred code. |
| 4972 | Register scratch1 = VirtualFrame::scratch1(); |
| 4973 | // Use r6 without notifying the virtual frame. |
| 4974 | Register scratch2 = r6; |
| 4975 | |
| 4976 | DeferredIsStringWrapperSafeForDefaultValueOf* deferred = |
| 4977 | new DeferredIsStringWrapperSafeForDefaultValueOf( |
| 4978 | obj, map_result, scratch1, scratch2); |
| 4979 | deferred->Branch(eq); |
| 4980 | deferred->BindExit(); |
| 4981 | __ tst(map_result, Operand(map_result)); |
| 4982 | cc_reg_ = ne; |
| 4983 | } |
| 4984 | |
| 4985 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4986 | void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { |
| 4987 | // This generates a fast version of: |
| 4988 | // (%_ClassOf(arg) === 'Function') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4989 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4990 | Load(args->at(0)); |
| 4991 | Register possible_function = frame_->PopToRegister(); |
| 4992 | __ tst(possible_function, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4993 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4994 | Register map_reg = VirtualFrame::scratch0(); |
| 4995 | Register scratch = VirtualFrame::scratch1(); |
| 4996 | __ CompareObjectType(possible_function, map_reg, scratch, JS_FUNCTION_TYPE); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4997 | cc_reg_ = eq; |
| 4998 | } |
| 4999 | |
| 5000 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5001 | void CodeGenerator::GenerateIsUndetectableObject(ZoneList<Expression*>* args) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5002 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5003 | Load(args->at(0)); |
| 5004 | Register possible_undetectable = frame_->PopToRegister(); |
| 5005 | __ tst(possible_undetectable, Operand(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5006 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5007 | Register scratch = VirtualFrame::scratch0(); |
| 5008 | __ ldr(scratch, |
| 5009 | FieldMemOperand(possible_undetectable, HeapObject::kMapOffset)); |
| 5010 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5011 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5012 | cc_reg_ = ne; |
| 5013 | } |
| 5014 | |
| 5015 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5016 | void CodeGenerator::GenerateIsConstructCall(ZoneList<Expression*>* args) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5017 | ASSERT(args->length() == 0); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5018 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5019 | Register scratch0 = VirtualFrame::scratch0(); |
| 5020 | Register scratch1 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5021 | // Get the frame pointer for the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5022 | __ ldr(scratch0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5023 | |
| 5024 | // Skip the arguments adaptor frame if it exists. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5025 | __ ldr(scratch1, |
| 5026 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5027 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5028 | __ ldr(scratch0, |
| 5029 | MemOperand(scratch0, StandardFrameConstants::kCallerFPOffset), eq); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5030 | |
| 5031 | // Check the marker in the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5032 | __ ldr(scratch1, |
| 5033 | MemOperand(scratch0, StandardFrameConstants::kMarkerOffset)); |
| 5034 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5035 | cc_reg_ = eq; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5036 | } |
| 5037 | |
| 5038 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5039 | void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5040 | ASSERT(args->length() == 0); |
| 5041 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5042 | Register tos = frame_->GetTOSRegister(); |
| 5043 | Register scratch0 = VirtualFrame::scratch0(); |
| 5044 | Register scratch1 = VirtualFrame::scratch1(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5045 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5046 | // Check if the calling frame is an arguments adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5047 | __ ldr(scratch0, |
| 5048 | MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5049 | __ ldr(scratch1, |
| 5050 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5051 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5052 | |
| 5053 | // Get the number of formal parameters. |
| 5054 | __ mov(tos, Operand(Smi::FromInt(scope()->num_parameters())), LeaveCC, ne); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5055 | |
| 5056 | // Arguments adaptor case: Read the arguments length from the |
| 5057 | // adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5058 | __ ldr(tos, |
| 5059 | MemOperand(scratch0, ArgumentsAdaptorFrameConstants::kLengthOffset), |
| 5060 | eq); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5061 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5062 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5066 | void CodeGenerator::GenerateArguments(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5067 | ASSERT(args->length() == 1); |
| 5068 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5069 | // Satisfy contract with ArgumentsAccessStub: |
| 5070 | // Load the key into r1 and the formal parameters count into r0. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5071 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5072 | frame_->PopToR1(); |
| 5073 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5074 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5075 | |
| 5076 | // Call the shared stub to get to arguments[key]. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5077 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5078 | frame_->CallStub(&stub, 0); |
| 5079 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5080 | } |
| 5081 | |
| 5082 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5083 | void CodeGenerator::GenerateRandomHeapNumber( |
| 5084 | ZoneList<Expression*>* args) { |
| 5085 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5086 | ASSERT(args->length() == 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5087 | |
| 5088 | Label slow_allocate_heapnumber; |
| 5089 | Label heapnumber_allocated; |
| 5090 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5091 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 5092 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5093 | __ jmp(&heapnumber_allocated); |
| 5094 | |
| 5095 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5096 | // Allocate a heap number. |
| 5097 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5098 | __ mov(r4, Operand(r0)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5099 | |
| 5100 | __ bind(&heapnumber_allocated); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5101 | |
| 5102 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 5103 | // by computing: |
| 5104 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 5105 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5106 | __ PrepareCallCFunction(0, r1); |
| 5107 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 5108 | |
| 5109 | CpuFeatures::Scope scope(VFP3); |
| 5110 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 5111 | // Create this constant using mov/orr to avoid PC relative load. |
| 5112 | __ mov(r1, Operand(0x41000000)); |
| 5113 | __ orr(r1, r1, Operand(0x300000)); |
| 5114 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 5115 | __ vmov(d7, r0, r1); |
| 5116 | // Move 0x4130000000000000 to VFP. |
| 5117 | __ mov(r0, Operand(0)); |
| 5118 | __ vmov(d8, r0, r1); |
| 5119 | // Subtract and store the result in the heap number. |
| 5120 | __ vsub(d7, d7, d8); |
| 5121 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 5122 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 5123 | frame_->EmitPush(r4); |
| 5124 | } else { |
| 5125 | __ mov(r0, Operand(r4)); |
| 5126 | __ PrepareCallCFunction(1, r1); |
| 5127 | __ CallCFunction( |
| 5128 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 5129 | frame_->EmitPush(r0); |
| 5130 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5134 | void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { |
| 5135 | ASSERT_EQ(2, args->length()); |
| 5136 | |
| 5137 | Load(args->at(0)); |
| 5138 | Load(args->at(1)); |
| 5139 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5140 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5141 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5142 | frame_->CallStub(&stub, 2); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5143 | frame_->EmitPush(r0); |
| 5144 | } |
| 5145 | |
| 5146 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5147 | void CodeGenerator::GenerateSubString(ZoneList<Expression*>* args) { |
| 5148 | ASSERT_EQ(3, args->length()); |
| 5149 | |
| 5150 | Load(args->at(0)); |
| 5151 | Load(args->at(1)); |
| 5152 | Load(args->at(2)); |
| 5153 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5154 | SubStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5155 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5156 | frame_->CallStub(&stub, 3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5157 | frame_->EmitPush(r0); |
| 5158 | } |
| 5159 | |
| 5160 | |
| 5161 | void CodeGenerator::GenerateStringCompare(ZoneList<Expression*>* args) { |
| 5162 | ASSERT_EQ(2, args->length()); |
| 5163 | |
| 5164 | Load(args->at(0)); |
| 5165 | Load(args->at(1)); |
| 5166 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5167 | StringCompareStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5168 | frame_->SpillAll(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5169 | frame_->CallStub(&stub, 2); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5170 | frame_->EmitPush(r0); |
| 5171 | } |
| 5172 | |
| 5173 | |
| 5174 | void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) { |
| 5175 | ASSERT_EQ(4, args->length()); |
| 5176 | |
| 5177 | Load(args->at(0)); |
| 5178 | Load(args->at(1)); |
| 5179 | Load(args->at(2)); |
| 5180 | Load(args->at(3)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5181 | RegExpExecStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5182 | frame_->SpillAll(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5183 | frame_->CallStub(&stub, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5184 | frame_->EmitPush(r0); |
| 5185 | } |
| 5186 | |
| 5187 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5188 | void CodeGenerator::GenerateRegExpConstructResult(ZoneList<Expression*>* args) { |
| 5189 | // No stub. This code only occurs a few times in regexp.js. |
| 5190 | const int kMaxInlineLength = 100; |
| 5191 | ASSERT_EQ(3, args->length()); |
| 5192 | Load(args->at(0)); // Size of array, smi. |
| 5193 | Load(args->at(1)); // "index" property value. |
| 5194 | Load(args->at(2)); // "input" property value. |
| 5195 | { |
| 5196 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5197 | Label slowcase; |
| 5198 | Label done; |
| 5199 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 5200 | STATIC_ASSERT(kSmiTag == 0); |
| 5201 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5202 | __ tst(r1, Operand(kSmiTagMask)); |
| 5203 | __ b(ne, &slowcase); |
| 5204 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5205 | __ b(hi, &slowcase); |
| 5206 | // Smi-tagging is equivalent to multiplying by 2. |
| 5207 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5208 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5209 | // Elements: [Map][Length][..elements..] |
| 5210 | // Size of JSArray with two in-object properties and the header of a |
| 5211 | // FixedArray. |
| 5212 | int objects_size = |
| 5213 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5214 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5215 | __ add(r2, r5, Operand(objects_size)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 5216 | __ AllocateInNewSpace( |
| 5217 | r2, // In: Size, in words. |
| 5218 | r0, // Out: Start of allocation (tagged). |
| 5219 | r3, // Scratch register. |
| 5220 | r4, // Scratch register. |
| 5221 | &slowcase, |
| 5222 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5223 | // r0: Start of allocated area, object-tagged. |
| 5224 | // r1: Number of elements in array, as smi. |
| 5225 | // r5: Number of elements, untagged. |
| 5226 | |
| 5227 | // Set JSArray map to global.regexp_result_map(). |
| 5228 | // Set empty properties FixedArray. |
| 5229 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5230 | // Interleave operations for better latency. |
| 5231 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5232 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
| 5233 | __ mov(r4, Operand(Factory::empty_fixed_array())); |
| 5234 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 5235 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5236 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5237 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5238 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5239 | |
| 5240 | // Set input, index and length fields from arguments. |
| 5241 | __ ldm(ia_w, sp, static_cast<RegList>(r2.bit() | r4.bit())); |
| 5242 | __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset)); |
| 5243 | __ add(sp, sp, Operand(kPointerSize)); |
| 5244 | __ str(r4, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5245 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
| 5246 | |
| 5247 | // Fill out the elements FixedArray. |
| 5248 | // r0: JSArray, tagged. |
| 5249 | // r3: FixedArray, tagged. |
| 5250 | // r5: Number of elements in array, untagged. |
| 5251 | |
| 5252 | // Set map. |
| 5253 | __ mov(r2, Operand(Factory::fixed_array_map())); |
| 5254 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5255 | // Set FixedArray length. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5256 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5257 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5258 | // Fill contents of fixed-array with the-hole. |
| 5259 | __ mov(r2, Operand(Factory::the_hole_value())); |
| 5260 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5261 | // Fill fixed array elements with hole. |
| 5262 | // r0: JSArray, tagged. |
| 5263 | // r2: the hole. |
| 5264 | // r3: Start of elements in FixedArray. |
| 5265 | // r5: Number of elements to fill. |
| 5266 | Label loop; |
| 5267 | __ tst(r5, Operand(r5)); |
| 5268 | __ bind(&loop); |
| 5269 | __ b(le, &done); // Jump if r1 is negative or zero. |
| 5270 | __ sub(r5, r5, Operand(1), SetCC); |
| 5271 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5272 | __ jmp(&loop); |
| 5273 | |
| 5274 | __ bind(&slowcase); |
| 5275 | __ CallRuntime(Runtime::kRegExpConstructResult, 3); |
| 5276 | |
| 5277 | __ bind(&done); |
| 5278 | } |
| 5279 | frame_->Forget(3); |
| 5280 | frame_->EmitPush(r0); |
| 5281 | } |
| 5282 | |
| 5283 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5284 | void CodeGenerator::GenerateRegExpCloneResult(ZoneList<Expression*>* args) { |
| 5285 | ASSERT_EQ(1, args->length()); |
| 5286 | |
| 5287 | Load(args->at(0)); |
| 5288 | frame_->PopToR0(); |
| 5289 | { |
| 5290 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5291 | |
| 5292 | Label done; |
| 5293 | Label call_runtime; |
| 5294 | __ BranchOnSmi(r0, &done); |
| 5295 | |
| 5296 | // Load JSRegExp map into r1. Check that argument object has this map. |
| 5297 | // Arguments to this function should be results of calling RegExp exec, |
| 5298 | // which is either an unmodified JSRegExpResult or null. Anything not having |
| 5299 | // the unmodified JSRegExpResult map is returned unmodified. |
| 5300 | // This also ensures that elements are fast. |
| 5301 | |
| 5302 | __ ldr(r1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5303 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalContextOffset)); |
| 5304 | __ ldr(r1, ContextOperand(r1, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5305 | __ ldr(ip, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5306 | __ cmp(r1, Operand(ip)); |
| 5307 | __ b(ne, &done); |
| 5308 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5309 | if (FLAG_debug_code) { |
| 5310 | __ LoadRoot(r2, Heap::kEmptyFixedArrayRootIndex); |
| 5311 | __ ldr(ip, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5312 | __ cmp(ip, r2); |
| 5313 | __ Check(eq, "JSRegExpResult: default map but non-empty properties."); |
| 5314 | } |
| 5315 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5316 | // All set, copy the contents to a new object. |
| 5317 | __ AllocateInNewSpace(JSRegExpResult::kSize, |
| 5318 | r2, |
| 5319 | r3, |
| 5320 | r4, |
| 5321 | &call_runtime, |
| 5322 | NO_ALLOCATION_FLAGS); |
| 5323 | // Store RegExpResult map as map of allocated object. |
| 5324 | ASSERT(JSRegExpResult::kSize == 6 * kPointerSize); |
| 5325 | // Copy all fields (map is already in r1) from (untagged) r0 to r2. |
| 5326 | // Change map of elements array (ends up in r4) to be a FixedCOWArray. |
| 5327 | __ bic(r0, r0, Operand(kHeapObjectTagMask)); |
| 5328 | __ ldm(ib, r0, r3.bit() | r4.bit() | r5.bit() | r6.bit() | r7.bit()); |
| 5329 | __ stm(ia, r2, |
| 5330 | r1.bit() | r3.bit() | r4.bit() | r5.bit() | r6.bit() | r7.bit()); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5331 | ASSERT(JSRegExp::kElementsOffset == 2 * kPointerSize); |
| 5332 | // Check whether elements array is empty fixed array, and otherwise make |
| 5333 | // it copy-on-write (it never should be empty unless someone is messing |
| 5334 | // with the arguments to the runtime function). |
| 5335 | __ LoadRoot(ip, Heap::kEmptyFixedArrayRootIndex); |
| 5336 | __ add(r0, r2, Operand(kHeapObjectTag)); // Tag result and move it to r0. |
| 5337 | __ cmp(r4, ip); |
| 5338 | __ b(eq, &done); |
| 5339 | __ LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 5340 | __ str(ip, FieldMemOperand(r4, HeapObject::kMapOffset)); |
| 5341 | __ b(&done); |
| 5342 | __ bind(&call_runtime); |
| 5343 | __ push(r0); |
| 5344 | __ CallRuntime(Runtime::kRegExpCloneResult, 1); |
| 5345 | __ bind(&done); |
| 5346 | } |
| 5347 | frame_->EmitPush(r0); |
| 5348 | } |
| 5349 | |
| 5350 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5351 | class DeferredSearchCache: public DeferredCode { |
| 5352 | public: |
| 5353 | DeferredSearchCache(Register dst, Register cache, Register key) |
| 5354 | : dst_(dst), cache_(cache), key_(key) { |
| 5355 | set_comment("[ DeferredSearchCache"); |
| 5356 | } |
| 5357 | |
| 5358 | virtual void Generate(); |
| 5359 | |
| 5360 | private: |
| 5361 | Register dst_, cache_, key_; |
| 5362 | }; |
| 5363 | |
| 5364 | |
| 5365 | void DeferredSearchCache::Generate() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 5366 | __ Push(cache_, key_); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5367 | __ CallRuntime(Runtime::kGetFromCache, 2); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5368 | __ Move(dst_, r0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5369 | } |
| 5370 | |
| 5371 | |
| 5372 | void CodeGenerator::GenerateGetFromCache(ZoneList<Expression*>* args) { |
| 5373 | ASSERT_EQ(2, args->length()); |
| 5374 | |
| 5375 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 5376 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 5377 | |
| 5378 | Handle<FixedArray> jsfunction_result_caches( |
| 5379 | Top::global_context()->jsfunction_result_caches()); |
| 5380 | if (jsfunction_result_caches->length() <= cache_id) { |
| 5381 | __ Abort("Attempt to use undefined cache."); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5382 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5383 | return; |
| 5384 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5385 | |
| 5386 | Load(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5387 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5388 | frame_->PopToR1(); |
| 5389 | frame_->SpillAll(); |
| 5390 | Register key = r1; // Just poped to r1 |
| 5391 | Register result = r0; // Free, as frame has just been spilled. |
| 5392 | Register scratch1 = VirtualFrame::scratch0(); |
| 5393 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5394 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5395 | __ ldr(scratch1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5396 | __ ldr(scratch1, |
| 5397 | FieldMemOperand(scratch1, GlobalObject::kGlobalContextOffset)); |
| 5398 | __ ldr(scratch1, |
| 5399 | ContextOperand(scratch1, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
| 5400 | __ ldr(scratch1, |
| 5401 | FieldMemOperand(scratch1, FixedArray::OffsetOfElementAt(cache_id))); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5402 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5403 | DeferredSearchCache* deferred = |
| 5404 | new DeferredSearchCache(result, scratch1, key); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5405 | |
| 5406 | const int kFingerOffset = |
| 5407 | FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 5408 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5409 | __ ldr(result, FieldMemOperand(scratch1, kFingerOffset)); |
| 5410 | // result now holds finger offset as a smi. |
| 5411 | __ add(scratch2, scratch1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5412 | // scratch2 now points to the start of fixed array elements. |
| 5413 | __ ldr(result, |
| 5414 | MemOperand( |
| 5415 | scratch2, result, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 5416 | // Note side effect of PreIndex: scratch2 now points to the key of the pair. |
| 5417 | __ cmp(key, result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5418 | deferred->Branch(ne); |
| 5419 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5420 | __ ldr(result, MemOperand(scratch2, kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5421 | |
| 5422 | deferred->BindExit(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5423 | frame_->EmitPush(result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5427 | void CodeGenerator::GenerateNumberToString(ZoneList<Expression*>* args) { |
| 5428 | ASSERT_EQ(args->length(), 1); |
| 5429 | |
| 5430 | // Load the argument on the stack and jump to the runtime. |
| 5431 | Load(args->at(0)); |
| 5432 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5433 | NumberToStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5434 | frame_->SpillAll(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5435 | frame_->CallStub(&stub, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5436 | frame_->EmitPush(r0); |
| 5437 | } |
| 5438 | |
| 5439 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5440 | class DeferredSwapElements: public DeferredCode { |
| 5441 | public: |
| 5442 | DeferredSwapElements(Register object, Register index1, Register index2) |
| 5443 | : object_(object), index1_(index1), index2_(index2) { |
| 5444 | set_comment("[ DeferredSwapElements"); |
| 5445 | } |
| 5446 | |
| 5447 | virtual void Generate(); |
| 5448 | |
| 5449 | private: |
| 5450 | Register object_, index1_, index2_; |
| 5451 | }; |
| 5452 | |
| 5453 | |
| 5454 | void DeferredSwapElements::Generate() { |
| 5455 | __ push(object_); |
| 5456 | __ push(index1_); |
| 5457 | __ push(index2_); |
| 5458 | __ CallRuntime(Runtime::kSwapElements, 3); |
| 5459 | } |
| 5460 | |
| 5461 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5462 | void CodeGenerator::GenerateSwapElements(ZoneList<Expression*>* args) { |
| 5463 | Comment cmnt(masm_, "[ GenerateSwapElements"); |
| 5464 | |
| 5465 | ASSERT_EQ(3, args->length()); |
| 5466 | |
| 5467 | Load(args->at(0)); |
| 5468 | Load(args->at(1)); |
| 5469 | Load(args->at(2)); |
| 5470 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5471 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5472 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5473 | Register index2 = r2; |
| 5474 | Register index1 = r1; |
| 5475 | Register object = r0; |
| 5476 | Register tmp1 = r3; |
| 5477 | Register tmp2 = r4; |
| 5478 | |
| 5479 | frame_->EmitPop(index2); |
| 5480 | frame_->EmitPop(index1); |
| 5481 | frame_->EmitPop(object); |
| 5482 | |
| 5483 | DeferredSwapElements* deferred = |
| 5484 | new DeferredSwapElements(object, index1, index2); |
| 5485 | |
| 5486 | // Fetch the map and check if array is in fast case. |
| 5487 | // Check that object doesn't require security checks and |
| 5488 | // has no indexed interceptor. |
| 5489 | __ CompareObjectType(object, tmp1, tmp2, FIRST_JS_OBJECT_TYPE); |
| 5490 | deferred->Branch(lt); |
| 5491 | __ ldrb(tmp2, FieldMemOperand(tmp1, Map::kBitFieldOffset)); |
| 5492 | __ tst(tmp2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask)); |
| 5493 | deferred->Branch(nz); |
| 5494 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5495 | // Check the object's elements are in fast case and writable. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5496 | __ ldr(tmp1, FieldMemOperand(object, JSObject::kElementsOffset)); |
| 5497 | __ ldr(tmp2, FieldMemOperand(tmp1, HeapObject::kMapOffset)); |
| 5498 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 5499 | __ cmp(tmp2, ip); |
| 5500 | deferred->Branch(ne); |
| 5501 | |
| 5502 | // Smi-tagging is equivalent to multiplying by 2. |
| 5503 | STATIC_ASSERT(kSmiTag == 0); |
| 5504 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5505 | |
| 5506 | // Check that both indices are smis. |
| 5507 | __ mov(tmp2, index1); |
| 5508 | __ orr(tmp2, tmp2, index2); |
| 5509 | __ tst(tmp2, Operand(kSmiTagMask)); |
| 5510 | deferred->Branch(nz); |
| 5511 | |
| 5512 | // Bring the offsets into the fixed array in tmp1 into index1 and |
| 5513 | // index2. |
| 5514 | __ mov(tmp2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5515 | __ add(index1, tmp2, Operand(index1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5516 | __ add(index2, tmp2, Operand(index2, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5517 | |
| 5518 | // Swap elements. |
| 5519 | Register tmp3 = object; |
| 5520 | object = no_reg; |
| 5521 | __ ldr(tmp3, MemOperand(tmp1, index1)); |
| 5522 | __ ldr(tmp2, MemOperand(tmp1, index2)); |
| 5523 | __ str(tmp3, MemOperand(tmp1, index2)); |
| 5524 | __ str(tmp2, MemOperand(tmp1, index1)); |
| 5525 | |
| 5526 | Label done; |
| 5527 | __ InNewSpace(tmp1, tmp2, eq, &done); |
| 5528 | // Possible optimization: do a check that both values are Smis |
| 5529 | // (or them and test against Smi mask.) |
| 5530 | |
| 5531 | __ mov(tmp2, tmp1); |
| 5532 | RecordWriteStub recordWrite1(tmp1, index1, tmp3); |
| 5533 | __ CallStub(&recordWrite1); |
| 5534 | |
| 5535 | RecordWriteStub recordWrite2(tmp2, index2, tmp3); |
| 5536 | __ CallStub(&recordWrite2); |
| 5537 | |
| 5538 | __ bind(&done); |
| 5539 | |
| 5540 | deferred->BindExit(); |
| 5541 | __ LoadRoot(tmp1, Heap::kUndefinedValueRootIndex); |
| 5542 | frame_->EmitPush(tmp1); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5546 | void CodeGenerator::GenerateCallFunction(ZoneList<Expression*>* args) { |
| 5547 | Comment cmnt(masm_, "[ GenerateCallFunction"); |
| 5548 | |
| 5549 | ASSERT(args->length() >= 2); |
| 5550 | |
| 5551 | int n_args = args->length() - 2; // for receiver and function. |
| 5552 | Load(args->at(0)); // receiver |
| 5553 | for (int i = 0; i < n_args; i++) { |
| 5554 | Load(args->at(i + 1)); |
| 5555 | } |
| 5556 | Load(args->at(n_args + 1)); // function |
| 5557 | frame_->CallJSFunction(n_args); |
| 5558 | frame_->EmitPush(r0); |
| 5559 | } |
| 5560 | |
| 5561 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5562 | void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) { |
| 5563 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5564 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5565 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5566 | TranscendentalCacheStub stub(TranscendentalCache::SIN); |
| 5567 | frame_->SpillAllButCopyTOSToR0(); |
| 5568 | frame_->CallStub(&stub, 1); |
| 5569 | } else { |
| 5570 | frame_->CallRuntime(Runtime::kMath_sin, 1); |
| 5571 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5572 | frame_->EmitPush(r0); |
| 5573 | } |
| 5574 | |
| 5575 | |
| 5576 | void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) { |
| 5577 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5578 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5579 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5580 | TranscendentalCacheStub stub(TranscendentalCache::COS); |
| 5581 | frame_->SpillAllButCopyTOSToR0(); |
| 5582 | frame_->CallStub(&stub, 1); |
| 5583 | } else { |
| 5584 | frame_->CallRuntime(Runtime::kMath_cos, 1); |
| 5585 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5586 | frame_->EmitPush(r0); |
| 5587 | } |
| 5588 | |
| 5589 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5590 | void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5591 | ASSERT(args->length() == 2); |
| 5592 | |
| 5593 | // Load the two objects into registers and perform the comparison. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5594 | Load(args->at(0)); |
| 5595 | Load(args->at(1)); |
| 5596 | Register lhs = frame_->PopToRegister(); |
| 5597 | Register rhs = frame_->PopToRegister(lhs); |
| 5598 | __ cmp(lhs, rhs); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5599 | cc_reg_ = eq; |
| 5600 | } |
| 5601 | |
| 5602 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5603 | void CodeGenerator::GenerateIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 5604 | ASSERT(args->length() == 2); |
| 5605 | |
| 5606 | // Load the two objects into registers and perform the comparison. |
| 5607 | Load(args->at(0)); |
| 5608 | Load(args->at(1)); |
| 5609 | Register right = frame_->PopToRegister(); |
| 5610 | Register left = frame_->PopToRegister(right); |
| 5611 | Register tmp = frame_->scratch0(); |
| 5612 | Register tmp2 = frame_->scratch1(); |
| 5613 | |
| 5614 | // Jumps to done must have the eq flag set if the test is successful |
| 5615 | // and clear if the test has failed. |
| 5616 | Label done; |
| 5617 | |
| 5618 | // Fail if either is a non-HeapObject. |
| 5619 | __ cmp(left, Operand(right)); |
| 5620 | __ b(eq, &done); |
| 5621 | __ and_(tmp, left, Operand(right)); |
| 5622 | __ eor(tmp, tmp, Operand(kSmiTagMask)); |
| 5623 | __ tst(tmp, Operand(kSmiTagMask)); |
| 5624 | __ b(ne, &done); |
| 5625 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 5626 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 5627 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 5628 | __ b(ne, &done); |
| 5629 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 5630 | __ cmp(tmp, Operand(tmp2)); |
| 5631 | __ b(ne, &done); |
| 5632 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 5633 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 5634 | __ cmp(tmp, tmp2); |
| 5635 | __ bind(&done); |
| 5636 | cc_reg_ = eq; |
| 5637 | } |
| 5638 | |
| 5639 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame^] | 5640 | void CodeGenerator::GenerateHasCachedArrayIndex(ZoneList<Expression*>* args) { |
| 5641 | ASSERT(args->length() == 1); |
| 5642 | Load(args->at(0)); |
| 5643 | Register value = frame_->PopToRegister(); |
| 5644 | Register tmp = frame_->scratch0(); |
| 5645 | __ ldr(tmp, FieldMemOperand(value, String::kHashFieldOffset)); |
| 5646 | __ tst(tmp, Operand(String::kContainsCachedArrayIndexMask)); |
| 5647 | cc_reg_ = eq; |
| 5648 | } |
| 5649 | |
| 5650 | |
| 5651 | void CodeGenerator::GenerateGetCachedArrayIndex(ZoneList<Expression*>* args) { |
| 5652 | ASSERT(args->length() == 1); |
| 5653 | Load(args->at(0)); |
| 5654 | Register value = frame_->PopToRegister(); |
| 5655 | |
| 5656 | __ ldr(value, FieldMemOperand(value, String::kHashFieldOffset)); |
| 5657 | __ IndexFromHash(value, value); |
| 5658 | frame_->EmitPush(value); |
| 5659 | } |
| 5660 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5661 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5662 | void CodeGenerator::VisitCallRuntime(CallRuntime* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5663 | #ifdef DEBUG |
| 5664 | int original_height = frame_->height(); |
| 5665 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5666 | if (CheckForInlineRuntimeCall(node)) { |
| 5667 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 5668 | (!has_cc() && frame_->height() == original_height + 1)); |
| 5669 | return; |
| 5670 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5671 | |
| 5672 | ZoneList<Expression*>* args = node->arguments(); |
| 5673 | Comment cmnt(masm_, "[ CallRuntime"); |
| 5674 | Runtime::Function* function = node->function(); |
| 5675 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5676 | if (function == NULL) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5677 | // Prepare stack for calling JS runtime function. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5678 | // Push the builtins object found in the current global object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5679 | Register scratch = VirtualFrame::scratch0(); |
| 5680 | __ ldr(scratch, GlobalObject()); |
| 5681 | Register builtins = frame_->GetTOSRegister(); |
| 5682 | __ ldr(builtins, FieldMemOperand(scratch, GlobalObject::kBuiltinsOffset)); |
| 5683 | frame_->EmitPush(builtins); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5684 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5685 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5686 | // Push the arguments ("left-to-right"). |
| 5687 | int arg_count = args->length(); |
| 5688 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5689 | Load(args->at(i)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5690 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5691 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5692 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5693 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5694 | if (function == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5695 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5696 | __ mov(r2, Operand(node->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5697 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 5698 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5699 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5700 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5701 | frame_->EmitPush(r0); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5702 | } else { |
| 5703 | // Call the C runtime function. |
| 5704 | frame_->CallRuntime(function, arg_count); |
| 5705 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5706 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5707 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5711 | void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5712 | #ifdef DEBUG |
| 5713 | int original_height = frame_->height(); |
| 5714 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5715 | Comment cmnt(masm_, "[ UnaryOperation"); |
| 5716 | |
| 5717 | Token::Value op = node->op(); |
| 5718 | |
| 5719 | if (op == Token::NOT) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5720 | LoadCondition(node->expression(), false_target(), true_target(), true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5721 | // LoadCondition may (and usually does) leave a test and branch to |
| 5722 | // be emitted by the caller. In that case, negate the condition. |
| 5723 | if (has_cc()) cc_reg_ = NegateCondition(cc_reg_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5724 | |
| 5725 | } else if (op == Token::DELETE) { |
| 5726 | Property* property = node->expression()->AsProperty(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5727 | Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5728 | if (property != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5729 | Load(property->obj()); |
| 5730 | Load(property->key()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5731 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5732 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5733 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5734 | } else if (variable != NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5735 | Slot* slot = variable->slot(); |
| 5736 | if (variable->is_global()) { |
| 5737 | LoadGlobal(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5738 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5739 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5740 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5741 | |
| 5742 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 5743 | // lookup the context holding the named variable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5744 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5745 | frame_->EmitPush(Operand(variable->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5746 | frame_->CallRuntime(Runtime::kLookupContext, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5747 | // r0: context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5748 | frame_->EmitPush(r0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5749 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5750 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5751 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5752 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5753 | } else { |
| 5754 | // Default: Result of deleting non-global, not dynamically |
| 5755 | // introduced variables is false. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5756 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5757 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5758 | |
| 5759 | } else { |
| 5760 | // Default: Result of deleting expressions is true. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5761 | Load(node->expression()); // may have side-effects |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5762 | frame_->Drop(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5763 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5764 | } |
| 5765 | |
| 5766 | } else if (op == Token::TYPEOF) { |
| 5767 | // Special case for loading the typeof expression; see comment on |
| 5768 | // LoadTypeofExpression(). |
| 5769 | LoadTypeofExpression(node->expression()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5770 | frame_->CallRuntime(Runtime::kTypeof, 1); |
| 5771 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5772 | |
| 5773 | } else { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5774 | bool can_overwrite = node->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5775 | UnaryOverwriteMode overwrite = |
| 5776 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
| 5777 | |
| 5778 | bool no_negative_zero = node->expression()->no_negative_zero(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5779 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5780 | switch (op) { |
| 5781 | case Token::NOT: |
| 5782 | case Token::DELETE: |
| 5783 | case Token::TYPEOF: |
| 5784 | UNREACHABLE(); // handled above |
| 5785 | break; |
| 5786 | |
| 5787 | case Token::SUB: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5788 | frame_->PopToR0(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5789 | GenericUnaryOpStub stub( |
| 5790 | Token::SUB, |
| 5791 | overwrite, |
| 5792 | no_negative_zero ? kIgnoreNegativeZero : kStrictNegativeZero); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5793 | frame_->CallStub(&stub, 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5794 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5795 | break; |
| 5796 | } |
| 5797 | |
| 5798 | case Token::BIT_NOT: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5799 | Register tos = frame_->PopToRegister(); |
| 5800 | JumpTarget not_smi_label; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5801 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5802 | // Smi check. |
| 5803 | __ tst(tos, Operand(kSmiTagMask)); |
| 5804 | not_smi_label.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5805 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5806 | __ mvn(tos, Operand(tos)); |
| 5807 | __ bic(tos, tos, Operand(kSmiTagMask)); // Bit-clear inverted smi-tag. |
| 5808 | frame_->EmitPush(tos); |
| 5809 | // The fast case is the first to jump to the continue label, so it gets |
| 5810 | // to decide the virtual frame layout. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5811 | continue_label.Jump(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5812 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5813 | not_smi_label.Bind(); |
| 5814 | frame_->SpillAll(); |
| 5815 | __ Move(r0, tos); |
| 5816 | GenericUnaryOpStub stub(Token::BIT_NOT, overwrite); |
| 5817 | frame_->CallStub(&stub, 0); |
| 5818 | frame_->EmitPush(r0); |
| 5819 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5820 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5821 | break; |
| 5822 | } |
| 5823 | |
| 5824 | case Token::VOID: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5825 | frame_->Drop(); |
| 5826 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5827 | break; |
| 5828 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5829 | case Token::ADD: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5830 | Register tos = frame_->Peek(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5831 | // Smi check. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5832 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5833 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5834 | continue_label.Branch(eq); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5835 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5836 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5837 | frame_->EmitPush(r0); |
| 5838 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5839 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5840 | break; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5841 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5842 | default: |
| 5843 | UNREACHABLE(); |
| 5844 | } |
| 5845 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5846 | ASSERT(!has_valid_frame() || |
| 5847 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5848 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5852 | void CodeGenerator::VisitCountOperation(CountOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5853 | #ifdef DEBUG |
| 5854 | int original_height = frame_->height(); |
| 5855 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5856 | Comment cmnt(masm_, "[ CountOperation"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5857 | VirtualFrame::RegisterAllocationScope scope(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5858 | |
| 5859 | bool is_postfix = node->is_postfix(); |
| 5860 | bool is_increment = node->op() == Token::INC; |
| 5861 | |
| 5862 | Variable* var = node->expression()->AsVariableProxy()->AsVariable(); |
| 5863 | bool is_const = (var != NULL && var->mode() == Variable::CONST); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5864 | bool is_slot = (var != NULL && var->mode() == Variable::VAR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5865 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5866 | if (!is_const && is_slot && type_info(var->slot()).IsSmi()) { |
| 5867 | // The type info declares that this variable is always a Smi. That |
| 5868 | // means it is a Smi both before and after the increment/decrement. |
| 5869 | // Lets make use of that to make a very minimal count. |
| 5870 | Reference target(this, node->expression(), !is_const); |
| 5871 | ASSERT(!target.is_illegal()); |
| 5872 | target.GetValue(); // Pushes the value. |
| 5873 | Register value = frame_->PopToRegister(); |
| 5874 | if (is_postfix) frame_->EmitPush(value); |
| 5875 | if (is_increment) { |
| 5876 | __ add(value, value, Operand(Smi::FromInt(1))); |
| 5877 | } else { |
| 5878 | __ sub(value, value, Operand(Smi::FromInt(1))); |
| 5879 | } |
| 5880 | frame_->EmitPush(value); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5881 | target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5882 | if (is_postfix) frame_->Pop(); |
| 5883 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 5884 | return; |
| 5885 | } |
| 5886 | |
| 5887 | // If it's a postfix expression and its result is not ignored and the |
| 5888 | // reference is non-trivial, then push a placeholder on the stack now |
| 5889 | // to hold the result of the expression. |
| 5890 | bool placeholder_pushed = false; |
| 5891 | if (!is_slot && is_postfix) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5892 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5893 | placeholder_pushed = true; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5894 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5895 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5896 | // A constant reference is not saved to, so a constant reference is not a |
| 5897 | // compound assignment reference. |
| 5898 | { Reference target(this, node->expression(), !is_const); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5899 | if (target.is_illegal()) { |
| 5900 | // Spoof the virtual frame to have the expected height (one higher |
| 5901 | // than on entry). |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5902 | if (!placeholder_pushed) frame_->EmitPush(Operand(Smi::FromInt(0))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5903 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5904 | return; |
| 5905 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5906 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5907 | // This pushes 0, 1 or 2 words on the object to be used later when updating |
| 5908 | // the target. It also pushes the current value of the target. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5909 | target.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5910 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5911 | JumpTarget slow; |
| 5912 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5913 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5914 | Register value = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5915 | |
| 5916 | // Postfix: Store the old value as the result. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5917 | if (placeholder_pushed) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5918 | frame_->SetElementAt(value, target.size()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5919 | } else if (is_postfix) { |
| 5920 | frame_->EmitPush(value); |
| 5921 | __ mov(VirtualFrame::scratch0(), value); |
| 5922 | value = VirtualFrame::scratch0(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5923 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5924 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5925 | // Check for smi operand. |
| 5926 | __ tst(value, Operand(kSmiTagMask)); |
| 5927 | slow.Branch(ne); |
| 5928 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5929 | // Perform optimistic increment/decrement. |
| 5930 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5931 | __ add(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5932 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5933 | __ sub(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | // If the increment/decrement didn't overflow, we're done. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5937 | exit.Branch(vc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5938 | |
| 5939 | // Revert optimistic increment/decrement. |
| 5940 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5941 | __ sub(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5942 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5943 | __ add(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5944 | } |
| 5945 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5946 | // Slow case: Convert to number. At this point the |
| 5947 | // value to be incremented is in the value register.. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5948 | slow.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5949 | |
| 5950 | // Convert the operand to a number. |
| 5951 | frame_->EmitPush(value); |
| 5952 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5953 | { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5954 | VirtualFrame::SpilledScope spilled(frame_); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5955 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5956 | |
| 5957 | if (is_postfix) { |
| 5958 | // Postfix: store to result (on the stack). |
| 5959 | __ str(r0, frame_->ElementAt(target.size())); |
| 5960 | } |
| 5961 | |
| 5962 | // Compute the new value. |
| 5963 | frame_->EmitPush(r0); |
| 5964 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
| 5965 | if (is_increment) { |
| 5966 | frame_->CallRuntime(Runtime::kNumberAdd, 2); |
| 5967 | } else { |
| 5968 | frame_->CallRuntime(Runtime::kNumberSub, 2); |
| 5969 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5970 | } |
| 5971 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5972 | __ Move(value, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5973 | // Store the new value in the target if not const. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5974 | // At this point the answer is in the value register. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5975 | exit.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5976 | frame_->EmitPush(value); |
| 5977 | // Set the target with the result, leaving the result on |
| 5978 | // top of the stack. Removes the target from the stack if |
| 5979 | // it has a non-zero size. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5980 | if (!is_const) target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
| 5983 | // Postfix: Discard the new value and use the old. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5984 | if (is_postfix) frame_->Pop(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5985 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5989 | void CodeGenerator::GenerateLogicalBooleanOperation(BinaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5990 | // According to ECMA-262 section 11.11, page 58, the binary logical |
| 5991 | // operators must yield the result of one of the two expressions |
| 5992 | // before any ToBoolean() conversions. This means that the value |
| 5993 | // produced by a && or || operator is not necessarily a boolean. |
| 5994 | |
| 5995 | // NOTE: If the left hand side produces a materialized value (not in |
| 5996 | // the CC register), we force the right hand side to do the |
| 5997 | // same. This is necessary because we may have to branch to the exit |
| 5998 | // after evaluating the left hand side (due to the shortcut |
| 5999 | // semantics), but the compiler must (statically) know if the result |
| 6000 | // of compiling the binary operation is materialized or not. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6001 | if (node->op() == Token::AND) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6002 | JumpTarget is_true; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6003 | LoadCondition(node->left(), &is_true, false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6004 | if (has_valid_frame() && !has_cc()) { |
| 6005 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6006 | JumpTarget pop_and_continue; |
| 6007 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6008 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6009 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6010 | // Avoid popping the result if it converts to 'false' using the |
| 6011 | // standard ToBoolean() conversion as described in ECMA-262, |
| 6012 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6013 | ToBoolean(&pop_and_continue, &exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6014 | Branch(false, &exit); |
| 6015 | |
| 6016 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6017 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6018 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6019 | |
| 6020 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6021 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6022 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6023 | |
| 6024 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6025 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6026 | } else if (has_cc() || is_true.is_linked()) { |
| 6027 | // The left-hand side is either (a) partially compiled to |
| 6028 | // control flow with a final branch left to emit or (b) fully |
| 6029 | // compiled to control flow and possibly true. |
| 6030 | if (has_cc()) { |
| 6031 | Branch(false, false_target()); |
| 6032 | } |
| 6033 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6034 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6035 | } else { |
| 6036 | // Nothing to do. |
| 6037 | ASSERT(!has_valid_frame() && !has_cc() && !is_true.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6038 | } |
| 6039 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6040 | } else { |
| 6041 | ASSERT(node->op() == Token::OR); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6042 | JumpTarget is_false; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6043 | LoadCondition(node->left(), true_target(), &is_false, false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6044 | if (has_valid_frame() && !has_cc()) { |
| 6045 | // The left-hand side result is on top of the virtual frame. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6046 | JumpTarget pop_and_continue; |
| 6047 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6048 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6049 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6050 | // Avoid popping the result if it converts to 'true' using the |
| 6051 | // standard ToBoolean() conversion as described in ECMA-262, |
| 6052 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6053 | ToBoolean(&exit, &pop_and_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6054 | Branch(true, &exit); |
| 6055 | |
| 6056 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6057 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6058 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6059 | |
| 6060 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6061 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6062 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6063 | |
| 6064 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6065 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6066 | } else if (has_cc() || is_false.is_linked()) { |
| 6067 | // The left-hand side is either (a) partially compiled to |
| 6068 | // control flow with a final branch left to emit or (b) fully |
| 6069 | // compiled to control flow and possibly false. |
| 6070 | if (has_cc()) { |
| 6071 | Branch(true, true_target()); |
| 6072 | } |
| 6073 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6074 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6075 | } else { |
| 6076 | // Nothing to do. |
| 6077 | ASSERT(!has_valid_frame() && !has_cc() && !is_false.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6078 | } |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6079 | } |
| 6080 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6081 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6082 | |
| 6083 | void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) { |
| 6084 | #ifdef DEBUG |
| 6085 | int original_height = frame_->height(); |
| 6086 | #endif |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6087 | Comment cmnt(masm_, "[ BinaryOperation"); |
| 6088 | |
| 6089 | if (node->op() == Token::AND || node->op() == Token::OR) { |
| 6090 | GenerateLogicalBooleanOperation(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6091 | } else { |
| 6092 | // Optimize for the case where (at least) one of the expressions |
| 6093 | // is a literal small integer. |
| 6094 | Literal* lliteral = node->left()->AsLiteral(); |
| 6095 | Literal* rliteral = node->right()->AsLiteral(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6096 | // NOTE: The code below assumes that the slow cases (calls to runtime) |
| 6097 | // never return a constant/immutable object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6098 | bool overwrite_left = node->left()->ResultOverwriteAllowed(); |
| 6099 | bool overwrite_right = node->right()->ResultOverwriteAllowed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6100 | |
| 6101 | if (rliteral != NULL && rliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6102 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6103 | Load(node->left()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6104 | if (frame_->KnownSmiAt(0)) overwrite_left = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6105 | SmiOperation(node->op(), |
| 6106 | rliteral->handle(), |
| 6107 | false, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6108 | overwrite_left ? OVERWRITE_LEFT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6109 | } else if (lliteral != NULL && lliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6110 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6111 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6112 | if (frame_->KnownSmiAt(0)) overwrite_right = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6113 | SmiOperation(node->op(), |
| 6114 | lliteral->handle(), |
| 6115 | true, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6116 | overwrite_right ? OVERWRITE_RIGHT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6117 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6118 | GenerateInlineSmi inline_smi = |
| 6119 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 6120 | if (lliteral != NULL) { |
| 6121 | ASSERT(!lliteral->handle()->IsSmi()); |
| 6122 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6123 | } |
| 6124 | if (rliteral != NULL) { |
| 6125 | ASSERT(!rliteral->handle()->IsSmi()); |
| 6126 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6127 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6128 | VirtualFrame::RegisterAllocationScope scope(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6129 | OverwriteMode overwrite_mode = NO_OVERWRITE; |
| 6130 | if (overwrite_left) { |
| 6131 | overwrite_mode = OVERWRITE_LEFT; |
| 6132 | } else if (overwrite_right) { |
| 6133 | overwrite_mode = OVERWRITE_RIGHT; |
| 6134 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6135 | Load(node->left()); |
| 6136 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6137 | GenericBinaryOperation(node->op(), overwrite_mode, inline_smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6138 | } |
| 6139 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6140 | ASSERT(!has_valid_frame() || |
| 6141 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6142 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6143 | } |
| 6144 | |
| 6145 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6146 | void CodeGenerator::VisitThisFunction(ThisFunction* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6147 | #ifdef DEBUG |
| 6148 | int original_height = frame_->height(); |
| 6149 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6150 | frame_->EmitPush(MemOperand(frame_->Function())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6151 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6152 | } |
| 6153 | |
| 6154 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6155 | void CodeGenerator::VisitCompareOperation(CompareOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6156 | #ifdef DEBUG |
| 6157 | int original_height = frame_->height(); |
| 6158 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6159 | Comment cmnt(masm_, "[ CompareOperation"); |
| 6160 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6161 | VirtualFrame::RegisterAllocationScope nonspilled_scope(this); |
| 6162 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6163 | // Get the expressions from the node. |
| 6164 | Expression* left = node->left(); |
| 6165 | Expression* right = node->right(); |
| 6166 | Token::Value op = node->op(); |
| 6167 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6168 | // To make typeof testing for natives implemented in JavaScript really |
| 6169 | // efficient, we generate special code for expressions of the form: |
| 6170 | // 'typeof <expression> == <string>'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6171 | UnaryOperation* operation = left->AsUnaryOperation(); |
| 6172 | if ((op == Token::EQ || op == Token::EQ_STRICT) && |
| 6173 | (operation != NULL && operation->op() == Token::TYPEOF) && |
| 6174 | (right->AsLiteral() != NULL && |
| 6175 | right->AsLiteral()->handle()->IsString())) { |
| 6176 | Handle<String> check(String::cast(*right->AsLiteral()->handle())); |
| 6177 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6178 | // Load the operand, move it to a register. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6179 | LoadTypeofExpression(operation->expression()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6180 | Register tos = frame_->PopToRegister(); |
| 6181 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6182 | Register scratch = VirtualFrame::scratch0(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6183 | |
| 6184 | if (check->Equals(Heap::number_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6185 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6186 | true_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6187 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6188 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6189 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6190 | cc_reg_ = eq; |
| 6191 | |
| 6192 | } else if (check->Equals(Heap::string_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6193 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6194 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6195 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6196 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6197 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6198 | // It can be an undetectable string object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6199 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6200 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6201 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6202 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6203 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6204 | __ ldrb(scratch, FieldMemOperand(tos, Map::kInstanceTypeOffset)); |
| 6205 | __ cmp(scratch, Operand(FIRST_NONSTRING_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6206 | cc_reg_ = lt; |
| 6207 | |
| 6208 | } else if (check->Equals(Heap::boolean_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6209 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6210 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6211 | true_target()->Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6212 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6213 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6214 | cc_reg_ = eq; |
| 6215 | |
| 6216 | } else if (check->Equals(Heap::undefined_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6217 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6218 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6219 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6220 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6221 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6222 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6223 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6224 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6225 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6226 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6227 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6228 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6229 | |
| 6230 | cc_reg_ = eq; |
| 6231 | |
| 6232 | } else if (check->Equals(Heap::function_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6233 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6234 | false_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6235 | Register map_reg = scratch; |
| 6236 | __ CompareObjectType(tos, map_reg, tos, JS_FUNCTION_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6237 | true_target()->Branch(eq); |
| 6238 | // Regular expressions are callable so typeof == 'function'. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6239 | __ CompareInstanceType(map_reg, tos, JS_REGEXP_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6240 | cc_reg_ = eq; |
| 6241 | |
| 6242 | } else if (check->Equals(Heap::object_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6243 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6244 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6245 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6246 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6247 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6248 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6249 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6250 | Register map_reg = scratch; |
| 6251 | __ CompareObjectType(tos, map_reg, tos, JS_REGEXP_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6252 | false_target()->Branch(eq); |
| 6253 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6254 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6255 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 6256 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6257 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6258 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6259 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6260 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 6261 | __ cmp(tos, Operand(FIRST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6262 | false_target()->Branch(lt); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6263 | __ cmp(tos, Operand(LAST_JS_OBJECT_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6264 | cc_reg_ = le; |
| 6265 | |
| 6266 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6267 | // Uncommon case: typeof testing against a string literal that is |
| 6268 | // never returned from the typeof operator. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6269 | false_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6270 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6271 | ASSERT(!has_valid_frame() || |
| 6272 | (has_cc() && frame_->height() == original_height)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6273 | return; |
| 6274 | } |
| 6275 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6276 | switch (op) { |
| 6277 | case Token::EQ: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6278 | Comparison(eq, left, right, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6279 | break; |
| 6280 | |
| 6281 | case Token::LT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6282 | Comparison(lt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6283 | break; |
| 6284 | |
| 6285 | case Token::GT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6286 | Comparison(gt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6287 | break; |
| 6288 | |
| 6289 | case Token::LTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6290 | Comparison(le, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6291 | break; |
| 6292 | |
| 6293 | case Token::GTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6294 | Comparison(ge, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6295 | break; |
| 6296 | |
| 6297 | case Token::EQ_STRICT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6298 | Comparison(eq, left, right, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6299 | break; |
| 6300 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6301 | case Token::IN: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6302 | Load(left); |
| 6303 | Load(right); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6304 | frame_->InvokeBuiltin(Builtins::IN, CALL_JS, 2); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6305 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6306 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6307 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6308 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6309 | case Token::INSTANCEOF: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6310 | Load(left); |
| 6311 | Load(right); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6312 | InstanceofStub stub; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6313 | frame_->CallStub(&stub, 2); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6314 | // At this point if instanceof succeeded then r0 == 0. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6315 | __ tst(r0, Operand(r0)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6316 | cc_reg_ = eq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6317 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6318 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6319 | |
| 6320 | default: |
| 6321 | UNREACHABLE(); |
| 6322 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6323 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 6324 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6325 | } |
| 6326 | |
| 6327 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6328 | void CodeGenerator::VisitCompareToNull(CompareToNull* node) { |
| 6329 | #ifdef DEBUG |
| 6330 | int original_height = frame_->height(); |
| 6331 | #endif |
| 6332 | Comment cmnt(masm_, "[ CompareToNull"); |
| 6333 | |
| 6334 | Load(node->expression()); |
| 6335 | Register tos = frame_->PopToRegister(); |
| 6336 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 6337 | __ cmp(tos, ip); |
| 6338 | |
| 6339 | // The 'null' value is only equal to 'undefined' if using non-strict |
| 6340 | // comparisons. |
| 6341 | if (!node->is_strict()) { |
| 6342 | true_target()->Branch(eq); |
| 6343 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 6344 | __ cmp(tos, Operand(ip)); |
| 6345 | true_target()->Branch(eq); |
| 6346 | |
| 6347 | __ tst(tos, Operand(kSmiTagMask)); |
| 6348 | false_target()->Branch(eq); |
| 6349 | |
| 6350 | // It can be an undetectable object. |
| 6351 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6352 | __ ldrb(tos, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6353 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6354 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
| 6355 | } |
| 6356 | |
| 6357 | cc_reg_ = eq; |
| 6358 | ASSERT(has_cc() && frame_->height() == original_height); |
| 6359 | } |
| 6360 | |
| 6361 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6362 | class DeferredReferenceGetNamedValue: public DeferredCode { |
| 6363 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6364 | explicit DeferredReferenceGetNamedValue(Register receiver, |
| 6365 | Handle<String> name) |
| 6366 | : receiver_(receiver), name_(name) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6367 | set_comment("[ DeferredReferenceGetNamedValue"); |
| 6368 | } |
| 6369 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6370 | virtual void Generate(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6371 | |
| 6372 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6373 | Register receiver_; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6374 | Handle<String> name_; |
| 6375 | }; |
| 6376 | |
| 6377 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6378 | // Convention for this is that on entry the receiver is in a register that |
| 6379 | // is not used by the stack. On exit the answer is found in that same |
| 6380 | // register and the stack has the same height. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6381 | void DeferredReferenceGetNamedValue::Generate() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6382 | #ifdef DEBUG |
| 6383 | int expected_height = frame_state()->frame()->height(); |
| 6384 | #endif |
| 6385 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6386 | copied_frame.SpillAll(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6387 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6388 | Register scratch1 = VirtualFrame::scratch0(); |
| 6389 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6390 | ASSERT(!receiver_.is(scratch1) && !receiver_.is(scratch2)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6391 | __ DecrementCounter(&Counters::named_load_inline, 1, scratch1, scratch2); |
| 6392 | __ IncrementCounter(&Counters::named_load_inline_miss, 1, scratch1, scratch2); |
| 6393 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6394 | // Ensure receiver in r0 and name in r2 to match load ic calling convention. |
| 6395 | __ Move(r0, receiver_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6396 | __ mov(r2, Operand(name_)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6397 | |
| 6398 | // The rest of the instructions in the deferred code must be together. |
| 6399 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6400 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 6401 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6402 | // The call must be followed by a nop(1) instruction to indicate that the |
| 6403 | // in-object has been inlined. |
| 6404 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6405 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6406 | // At this point the answer is in r0. We move it to the expected register |
| 6407 | // if necessary. |
| 6408 | __ Move(receiver_, r0); |
| 6409 | |
| 6410 | // Now go back to the frame that we entered with. This will not overwrite |
| 6411 | // the receiver register since that register was not in use when we came |
| 6412 | // in. The instructions emitted by this merge are skipped over by the |
| 6413 | // inline load patching mechanism when looking for the branch instruction |
| 6414 | // that tells it where the code to patch is. |
| 6415 | copied_frame.MergeTo(frame_state()->frame()); |
| 6416 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6417 | // Block the constant pool for one more instruction after leaving this |
| 6418 | // constant pool block scope to include the branch instruction ending the |
| 6419 | // deferred code. |
| 6420 | __ BlockConstPoolFor(1); |
| 6421 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6422 | ASSERT_EQ(expected_height, frame_state()->frame()->height()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6426 | class DeferredReferenceGetKeyedValue: public DeferredCode { |
| 6427 | public: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6428 | DeferredReferenceGetKeyedValue(Register key, Register receiver) |
| 6429 | : key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6430 | set_comment("[ DeferredReferenceGetKeyedValue"); |
| 6431 | } |
| 6432 | |
| 6433 | virtual void Generate(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6434 | |
| 6435 | private: |
| 6436 | Register key_; |
| 6437 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6438 | }; |
| 6439 | |
| 6440 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6441 | // Takes key and register in r0 and r1 or vice versa. Returns result |
| 6442 | // in r0. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6443 | void DeferredReferenceGetKeyedValue::Generate() { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6444 | ASSERT((key_.is(r0) && receiver_.is(r1)) || |
| 6445 | (key_.is(r1) && receiver_.is(r0))); |
| 6446 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6447 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6448 | copied_frame.SpillAll(); |
| 6449 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6450 | Register scratch1 = VirtualFrame::scratch0(); |
| 6451 | Register scratch2 = VirtualFrame::scratch1(); |
| 6452 | __ DecrementCounter(&Counters::keyed_load_inline, 1, scratch1, scratch2); |
| 6453 | __ IncrementCounter(&Counters::keyed_load_inline_miss, 1, scratch1, scratch2); |
| 6454 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6455 | // Ensure key in r0 and receiver in r1 to match keyed load ic calling |
| 6456 | // convention. |
| 6457 | if (key_.is(r1)) { |
| 6458 | __ Swap(r0, r1, ip); |
| 6459 | } |
| 6460 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6461 | // The rest of the instructions in the deferred code must be together. |
| 6462 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6463 | // Call keyed load IC. It has the arguments key and receiver in r0 and r1. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6464 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 6465 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6466 | // The call must be followed by a nop instruction to indicate that the |
| 6467 | // keyed load has been inlined. |
| 6468 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6469 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6470 | // Now go back to the frame that we entered with. This will not overwrite |
| 6471 | // the receiver or key registers since they were not in use when we came |
| 6472 | // in. The instructions emitted by this merge are skipped over by the |
| 6473 | // inline load patching mechanism when looking for the branch instruction |
| 6474 | // that tells it where the code to patch is. |
| 6475 | copied_frame.MergeTo(frame_state()->frame()); |
| 6476 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6477 | // Block the constant pool for one more instruction after leaving this |
| 6478 | // constant pool block scope to include the branch instruction ending the |
| 6479 | // deferred code. |
| 6480 | __ BlockConstPoolFor(1); |
| 6481 | } |
| 6482 | } |
| 6483 | |
| 6484 | |
| 6485 | class DeferredReferenceSetKeyedValue: public DeferredCode { |
| 6486 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6487 | DeferredReferenceSetKeyedValue(Register value, |
| 6488 | Register key, |
| 6489 | Register receiver) |
| 6490 | : value_(value), key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6491 | set_comment("[ DeferredReferenceSetKeyedValue"); |
| 6492 | } |
| 6493 | |
| 6494 | virtual void Generate(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6495 | |
| 6496 | private: |
| 6497 | Register value_; |
| 6498 | Register key_; |
| 6499 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6500 | }; |
| 6501 | |
| 6502 | |
| 6503 | void DeferredReferenceSetKeyedValue::Generate() { |
| 6504 | Register scratch1 = VirtualFrame::scratch0(); |
| 6505 | Register scratch2 = VirtualFrame::scratch1(); |
| 6506 | __ DecrementCounter(&Counters::keyed_store_inline, 1, scratch1, scratch2); |
| 6507 | __ IncrementCounter( |
| 6508 | &Counters::keyed_store_inline_miss, 1, scratch1, scratch2); |
| 6509 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6510 | // Ensure value in r0, key in r1 and receiver in r2 to match keyed store ic |
| 6511 | // calling convention. |
| 6512 | if (value_.is(r1)) { |
| 6513 | __ Swap(r0, r1, ip); |
| 6514 | } |
| 6515 | ASSERT(receiver_.is(r2)); |
| 6516 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6517 | // The rest of the instructions in the deferred code must be together. |
| 6518 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6519 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6520 | // r1 and r2. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6521 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 6522 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6523 | // The call must be followed by a nop instruction to indicate that the |
| 6524 | // keyed store has been inlined. |
| 6525 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6526 | |
| 6527 | // Block the constant pool for one more instruction after leaving this |
| 6528 | // constant pool block scope to include the branch instruction ending the |
| 6529 | // deferred code. |
| 6530 | __ BlockConstPoolFor(1); |
| 6531 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6532 | } |
| 6533 | |
| 6534 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6535 | class DeferredReferenceSetNamedValue: public DeferredCode { |
| 6536 | public: |
| 6537 | DeferredReferenceSetNamedValue(Register value, |
| 6538 | Register receiver, |
| 6539 | Handle<String> name) |
| 6540 | : value_(value), receiver_(receiver), name_(name) { |
| 6541 | set_comment("[ DeferredReferenceSetNamedValue"); |
| 6542 | } |
| 6543 | |
| 6544 | virtual void Generate(); |
| 6545 | |
| 6546 | private: |
| 6547 | Register value_; |
| 6548 | Register receiver_; |
| 6549 | Handle<String> name_; |
| 6550 | }; |
| 6551 | |
| 6552 | |
| 6553 | // Takes value in r0, receiver in r1 and returns the result (the |
| 6554 | // value) in r0. |
| 6555 | void DeferredReferenceSetNamedValue::Generate() { |
| 6556 | // Record the entry frame and spill. |
| 6557 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6558 | copied_frame.SpillAll(); |
| 6559 | |
| 6560 | // Ensure value in r0, receiver in r1 to match store ic calling |
| 6561 | // convention. |
| 6562 | ASSERT(value_.is(r0) && receiver_.is(r1)); |
| 6563 | __ mov(r2, Operand(name_)); |
| 6564 | |
| 6565 | // The rest of the instructions in the deferred code must be together. |
| 6566 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6567 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6568 | // r1 and r2. |
| 6569 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 6570 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6571 | // The call must be followed by a nop instruction to indicate that the |
| 6572 | // named store has been inlined. |
| 6573 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6574 | |
| 6575 | // Go back to the frame we entered with. The instructions |
| 6576 | // generated by this merge are skipped over by the inline store |
| 6577 | // patching mechanism when looking for the branch instruction that |
| 6578 | // tells it where the code to patch is. |
| 6579 | copied_frame.MergeTo(frame_state()->frame()); |
| 6580 | |
| 6581 | // Block the constant pool for one more instruction after leaving this |
| 6582 | // constant pool block scope to include the branch instruction ending the |
| 6583 | // deferred code. |
| 6584 | __ BlockConstPoolFor(1); |
| 6585 | } |
| 6586 | } |
| 6587 | |
| 6588 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6589 | // Consumes the top of stack (the receiver) and pushes the result instead. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6590 | void CodeGenerator::EmitNamedLoad(Handle<String> name, bool is_contextual) { |
| 6591 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6592 | Comment cmnt(masm(), "[ Load from named Property"); |
| 6593 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6594 | frame_->CallLoadIC(name, |
| 6595 | is_contextual |
| 6596 | ? RelocInfo::CODE_TARGET_CONTEXT |
| 6597 | : RelocInfo::CODE_TARGET); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6598 | frame_->EmitPush(r0); // Push answer. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6599 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6600 | // Inline the in-object property case. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6601 | Comment cmnt(masm(), "[ Inlined named property load"); |
| 6602 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6603 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6604 | // having it in the instruction stream below where patching will occur. |
| 6605 | __ IncrementCounter(&Counters::named_load_inline, 1, |
| 6606 | frame_->scratch0(), frame_->scratch1()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6607 | |
| 6608 | // The following instructions are the inlined load of an in-object property. |
| 6609 | // Parts of this code is patched, so the exact instructions generated needs |
| 6610 | // to be fixed. Therefore the instruction pool is blocked when generating |
| 6611 | // this code |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6612 | |
| 6613 | // Load the receiver from the stack. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6614 | Register receiver = frame_->PopToRegister(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6615 | |
| 6616 | DeferredReferenceGetNamedValue* deferred = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6617 | new DeferredReferenceGetNamedValue(receiver, name); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6618 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6619 | #ifdef DEBUG |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6620 | int kInlinedNamedLoadInstructions = 7; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6621 | Label check_inlined_codesize; |
| 6622 | masm_->bind(&check_inlined_codesize); |
| 6623 | #endif |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6624 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6625 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6626 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6627 | __ tst(receiver, Operand(kSmiTagMask)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6628 | deferred->Branch(eq); |
| 6629 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6630 | Register scratch = VirtualFrame::scratch0(); |
| 6631 | Register scratch2 = VirtualFrame::scratch1(); |
| 6632 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6633 | // Check the map. The null map used below is patched by the inline cache |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6634 | // code. Therefore we can't use a LoadRoot call. |
| 6635 | __ ldr(scratch, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6636 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6637 | __ cmp(scratch, scratch2); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6638 | deferred->Branch(ne); |
| 6639 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6640 | // Initially use an invalid index. The index will be patched by the |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6641 | // inline cache code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6642 | __ ldr(receiver, MemOperand(receiver, 0)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6643 | |
| 6644 | // Make sure that the expected number of instructions are generated. |
| 6645 | ASSERT_EQ(kInlinedNamedLoadInstructions, |
| 6646 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6649 | deferred->BindExit(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6650 | // At this point the receiver register has the result, either from the |
| 6651 | // deferred code or from the inlined code. |
| 6652 | frame_->EmitPush(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6653 | } |
| 6654 | } |
| 6655 | |
| 6656 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6657 | void CodeGenerator::EmitNamedStore(Handle<String> name, bool is_contextual) { |
| 6658 | #ifdef DEBUG |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6659 | int expected_height = frame()->height() - (is_contextual ? 1 : 2); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6660 | #endif |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6661 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6662 | Result result; |
| 6663 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6664 | frame()->CallStoreIC(name, is_contextual); |
| 6665 | } else { |
| 6666 | // Inline the in-object property case. |
| 6667 | JumpTarget slow, done; |
| 6668 | |
| 6669 | // Get the value and receiver from the stack. |
| 6670 | frame()->PopToR0(); |
| 6671 | Register value = r0; |
| 6672 | frame()->PopToR1(); |
| 6673 | Register receiver = r1; |
| 6674 | |
| 6675 | DeferredReferenceSetNamedValue* deferred = |
| 6676 | new DeferredReferenceSetNamedValue(value, receiver, name); |
| 6677 | |
| 6678 | // Check that the receiver is a heap object. |
| 6679 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6680 | deferred->Branch(eq); |
| 6681 | |
| 6682 | // The following instructions are the part of the inlined |
| 6683 | // in-object property store code which can be patched. Therefore |
| 6684 | // the exact number of instructions generated must be fixed, so |
| 6685 | // the constant pool is blocked while generating this code. |
| 6686 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6687 | Register scratch0 = VirtualFrame::scratch0(); |
| 6688 | Register scratch1 = VirtualFrame::scratch1(); |
| 6689 | |
| 6690 | // Check the map. Initially use an invalid map to force a |
| 6691 | // failure. The map check will be patched in the runtime system. |
| 6692 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6693 | |
| 6694 | #ifdef DEBUG |
| 6695 | Label check_inlined_codesize; |
| 6696 | masm_->bind(&check_inlined_codesize); |
| 6697 | #endif |
| 6698 | __ mov(scratch0, Operand(Factory::null_value())); |
| 6699 | __ cmp(scratch0, scratch1); |
| 6700 | deferred->Branch(ne); |
| 6701 | |
| 6702 | int offset = 0; |
| 6703 | __ str(value, MemOperand(receiver, offset)); |
| 6704 | |
| 6705 | // Update the write barrier and record its size. We do not use |
| 6706 | // the RecordWrite macro here because we want the offset |
| 6707 | // addition instruction first to make it easy to patch. |
| 6708 | Label record_write_start, record_write_done; |
| 6709 | __ bind(&record_write_start); |
| 6710 | // Add offset into the object. |
| 6711 | __ add(scratch0, receiver, Operand(offset)); |
| 6712 | // Test that the object is not in the new space. We cannot set |
| 6713 | // region marks for new space pages. |
| 6714 | __ InNewSpace(receiver, scratch1, eq, &record_write_done); |
| 6715 | // Record the actual write. |
| 6716 | __ RecordWriteHelper(receiver, scratch0, scratch1); |
| 6717 | __ bind(&record_write_done); |
| 6718 | // Clobber all input registers when running with the debug-code flag |
| 6719 | // turned on to provoke errors. |
| 6720 | if (FLAG_debug_code) { |
| 6721 | __ mov(receiver, Operand(BitCast<int32_t>(kZapValue))); |
| 6722 | __ mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 6723 | __ mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
| 6724 | } |
| 6725 | // Check that this is the first inlined write barrier or that |
| 6726 | // this inlined write barrier has the same size as all the other |
| 6727 | // inlined write barriers. |
| 6728 | ASSERT((inlined_write_barrier_size_ == -1) || |
| 6729 | (inlined_write_barrier_size_ == |
| 6730 | masm()->InstructionsGeneratedSince(&record_write_start))); |
| 6731 | inlined_write_barrier_size_ = |
| 6732 | masm()->InstructionsGeneratedSince(&record_write_start); |
| 6733 | |
| 6734 | // Make sure that the expected number of instructions are generated. |
| 6735 | ASSERT_EQ(GetInlinedNamedStoreInstructionsAfterPatch(), |
| 6736 | masm()->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6737 | } |
| 6738 | deferred->BindExit(); |
| 6739 | } |
| 6740 | ASSERT_EQ(expected_height, frame()->height()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6744 | void CodeGenerator::EmitKeyedLoad() { |
| 6745 | if (loop_nesting() == 0) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6746 | Comment cmnt(masm_, "[ Load from keyed property"); |
| 6747 | frame_->CallKeyedLoadIC(); |
| 6748 | } else { |
| 6749 | // Inline the keyed load. |
| 6750 | Comment cmnt(masm_, "[ Inlined load from keyed property"); |
| 6751 | |
| 6752 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6753 | // having it in the instruction stream below where patching will occur. |
| 6754 | __ IncrementCounter(&Counters::keyed_load_inline, 1, |
| 6755 | frame_->scratch0(), frame_->scratch1()); |
| 6756 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6757 | // Load the key and receiver from the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6758 | bool key_is_known_smi = frame_->KnownSmiAt(0); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6759 | Register key = frame_->PopToRegister(); |
| 6760 | Register receiver = frame_->PopToRegister(key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6761 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6762 | // The deferred code expects key and receiver in registers. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6763 | DeferredReferenceGetKeyedValue* deferred = |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6764 | new DeferredReferenceGetKeyedValue(key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6765 | |
| 6766 | // Check that the receiver is a heap object. |
| 6767 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6768 | deferred->Branch(eq); |
| 6769 | |
| 6770 | // The following instructions are the part of the inlined load keyed |
| 6771 | // property code which can be patched. Therefore the exact number of |
| 6772 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6773 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6774 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6775 | Register scratch1 = VirtualFrame::scratch0(); |
| 6776 | Register scratch2 = VirtualFrame::scratch1(); |
| 6777 | // Check the map. The null map used below is patched by the inline cache |
| 6778 | // code. |
| 6779 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6780 | |
| 6781 | // Check that the key is a smi. |
| 6782 | if (!key_is_known_smi) { |
| 6783 | __ tst(key, Operand(kSmiTagMask)); |
| 6784 | deferred->Branch(ne); |
| 6785 | } |
| 6786 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6787 | #ifdef DEBUG |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6788 | Label check_inlined_codesize; |
| 6789 | masm_->bind(&check_inlined_codesize); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6790 | #endif |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6791 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6792 | __ cmp(scratch1, scratch2); |
| 6793 | deferred->Branch(ne); |
| 6794 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6795 | // Get the elements array from the receiver. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6796 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6797 | __ AssertFastElements(scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6798 | |
| 6799 | // Check that key is within bounds. Use unsigned comparison to handle |
| 6800 | // negative keys. |
| 6801 | __ ldr(scratch2, FieldMemOperand(scratch1, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6802 | __ cmp(scratch2, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6803 | deferred->Branch(ls); // Unsigned less equal. |
| 6804 | |
| 6805 | // Load and check that the result is not the hole (key is a smi). |
| 6806 | __ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex); |
| 6807 | __ add(scratch1, |
| 6808 | scratch1, |
| 6809 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6810 | __ ldr(scratch1, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6811 | MemOperand(scratch1, key, LSL, |
| 6812 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6813 | __ cmp(scratch1, scratch2); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6814 | deferred->Branch(eq); |
| 6815 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6816 | __ mov(r0, scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6817 | // Make sure that the expected number of instructions are generated. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6818 | ASSERT_EQ(GetInlinedKeyedLoadInstructionsAfterPatch(), |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6819 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6820 | } |
| 6821 | |
| 6822 | deferred->BindExit(); |
| 6823 | } |
| 6824 | } |
| 6825 | |
| 6826 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6827 | void CodeGenerator::EmitKeyedStore(StaticType* key_type, |
| 6828 | WriteBarrierCharacter wb_info) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6829 | // Generate inlined version of the keyed store if the code is in a loop |
| 6830 | // and the key is likely to be a smi. |
| 6831 | if (loop_nesting() > 0 && key_type->IsLikelySmi()) { |
| 6832 | // Inline the keyed store. |
| 6833 | Comment cmnt(masm_, "[ Inlined store to keyed property"); |
| 6834 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6835 | Register scratch1 = VirtualFrame::scratch0(); |
| 6836 | Register scratch2 = VirtualFrame::scratch1(); |
| 6837 | Register scratch3 = r3; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6838 | |
| 6839 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6840 | // having it in the instruction stream below where patching will occur. |
| 6841 | __ IncrementCounter(&Counters::keyed_store_inline, 1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6842 | scratch1, scratch2); |
| 6843 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6844 | |
| 6845 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6846 | // Load the value, key and receiver from the stack. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6847 | bool value_is_harmless = frame_->KnownSmiAt(0); |
| 6848 | if (wb_info == NEVER_NEWSPACE) value_is_harmless = true; |
| 6849 | bool key_is_smi = frame_->KnownSmiAt(1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6850 | Register value = frame_->PopToRegister(); |
| 6851 | Register key = frame_->PopToRegister(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6852 | VirtualFrame::SpilledScope spilled(frame_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6853 | Register receiver = r2; |
| 6854 | frame_->EmitPop(receiver); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6855 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6856 | #ifdef DEBUG |
| 6857 | bool we_remembered_the_write_barrier = value_is_harmless; |
| 6858 | #endif |
| 6859 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6860 | // The deferred code expects value, key and receiver in registers. |
| 6861 | DeferredReferenceSetKeyedValue* deferred = |
| 6862 | new DeferredReferenceSetKeyedValue(value, key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6863 | |
| 6864 | // Check that the value is a smi. As this inlined code does not set the |
| 6865 | // write barrier it is only possible to store smi values. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6866 | if (!value_is_harmless) { |
| 6867 | // If the value is not likely to be a Smi then let's test the fixed array |
| 6868 | // for new space instead. See below. |
| 6869 | if (wb_info == LIKELY_SMI) { |
| 6870 | __ tst(value, Operand(kSmiTagMask)); |
| 6871 | deferred->Branch(ne); |
| 6872 | #ifdef DEBUG |
| 6873 | we_remembered_the_write_barrier = true; |
| 6874 | #endif |
| 6875 | } |
| 6876 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6877 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6878 | if (!key_is_smi) { |
| 6879 | // Check that the key is a smi. |
| 6880 | __ tst(key, Operand(kSmiTagMask)); |
| 6881 | deferred->Branch(ne); |
| 6882 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6883 | |
| 6884 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6885 | __ tst(receiver, Operand(kSmiTagMask)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6886 | deferred->Branch(eq); |
| 6887 | |
| 6888 | // Check that the receiver is a JSArray. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6889 | __ CompareObjectType(receiver, scratch1, scratch1, JS_ARRAY_TYPE); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6890 | deferred->Branch(ne); |
| 6891 | |
| 6892 | // Check that the key is within bounds. Both the key and the length of |
| 6893 | // the JSArray are smis. Use unsigned comparison to handle negative keys. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6894 | __ ldr(scratch1, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 6895 | __ cmp(scratch1, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6896 | deferred->Branch(ls); // Unsigned less equal. |
| 6897 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6898 | // Get the elements array from the receiver. |
| 6899 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 6900 | if (!value_is_harmless && wb_info != LIKELY_SMI) { |
| 6901 | Label ok; |
| 6902 | __ and_(scratch2, scratch1, Operand(ExternalReference::new_space_mask())); |
| 6903 | __ cmp(scratch2, Operand(ExternalReference::new_space_start())); |
| 6904 | __ tst(value, Operand(kSmiTagMask), ne); |
| 6905 | deferred->Branch(ne); |
| 6906 | #ifdef DEBUG |
| 6907 | we_remembered_the_write_barrier = true; |
| 6908 | #endif |
| 6909 | } |
| 6910 | // Check that the elements array is not a dictionary. |
| 6911 | __ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6912 | // The following instructions are the part of the inlined store keyed |
| 6913 | // property code which can be patched. Therefore the exact number of |
| 6914 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6915 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6916 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6917 | #ifdef DEBUG |
| 6918 | Label check_inlined_codesize; |
| 6919 | masm_->bind(&check_inlined_codesize); |
| 6920 | #endif |
| 6921 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6922 | // Read the fixed array map from the constant pool (not from the root |
| 6923 | // array) so that the value can be patched. When debugging, we patch this |
| 6924 | // comparison to always fail so that we will hit the IC call in the |
| 6925 | // deferred code which will allow the debugger to break for fast case |
| 6926 | // stores. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6927 | __ mov(scratch3, Operand(Factory::fixed_array_map())); |
| 6928 | __ cmp(scratch2, scratch3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6929 | deferred->Branch(ne); |
| 6930 | |
| 6931 | // Store the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6932 | __ add(scratch1, scratch1, |
| 6933 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 6934 | __ str(value, |
| 6935 | MemOperand(scratch1, key, LSL, |
| 6936 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6937 | |
| 6938 | // Make sure that the expected number of instructions are generated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6939 | ASSERT_EQ(kInlinedKeyedStoreInstructionsAfterPatch, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6940 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6941 | } |
| 6942 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6943 | ASSERT(we_remembered_the_write_barrier); |
| 6944 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6945 | deferred->BindExit(); |
| 6946 | } else { |
| 6947 | frame()->CallKeyedStoreIC(); |
| 6948 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6949 | } |
| 6950 | |
| 6951 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6952 | #ifdef DEBUG |
| 6953 | bool CodeGenerator::HasValidEntryRegisters() { return true; } |
| 6954 | #endif |
| 6955 | |
| 6956 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6957 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6958 | #define __ ACCESS_MASM(masm) |
| 6959 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6960 | Handle<String> Reference::GetName() { |
| 6961 | ASSERT(type_ == NAMED); |
| 6962 | Property* property = expression_->AsProperty(); |
| 6963 | if (property == NULL) { |
| 6964 | // Global variable reference treated as a named property reference. |
| 6965 | VariableProxy* proxy = expression_->AsVariableProxy(); |
| 6966 | ASSERT(proxy->AsVariable() != NULL); |
| 6967 | ASSERT(proxy->AsVariable()->is_global()); |
| 6968 | return proxy->name(); |
| 6969 | } else { |
| 6970 | Literal* raw_name = property->key()->AsLiteral(); |
| 6971 | ASSERT(raw_name != NULL); |
| 6972 | return Handle<String>(String::cast(*raw_name->handle())); |
| 6973 | } |
| 6974 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6975 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6976 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6977 | void Reference::DupIfPersist() { |
| 6978 | if (persist_after_get_) { |
| 6979 | switch (type_) { |
| 6980 | case KEYED: |
| 6981 | cgen_->frame()->Dup2(); |
| 6982 | break; |
| 6983 | case NAMED: |
| 6984 | cgen_->frame()->Dup(); |
| 6985 | // Fall through. |
| 6986 | case UNLOADED: |
| 6987 | case ILLEGAL: |
| 6988 | case SLOT: |
| 6989 | // Do nothing. |
| 6990 | ; |
| 6991 | } |
| 6992 | } else { |
| 6993 | set_unloaded(); |
| 6994 | } |
| 6995 | } |
| 6996 | |
| 6997 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6998 | void Reference::GetValue() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6999 | ASSERT(cgen_->HasValidEntryRegisters()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7000 | ASSERT(!is_illegal()); |
| 7001 | ASSERT(!cgen_->has_cc()); |
| 7002 | MacroAssembler* masm = cgen_->masm(); |
| 7003 | Property* property = expression_->AsProperty(); |
| 7004 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7005 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
| 7008 | switch (type_) { |
| 7009 | case SLOT: { |
| 7010 | Comment cmnt(masm, "[ Load from Slot"); |
| 7011 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
| 7012 | ASSERT(slot != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7013 | DupIfPersist(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7014 | cgen_->LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7015 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7016 | } |
| 7017 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7018 | case NAMED: { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7019 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 7020 | bool is_global = var != NULL; |
| 7021 | ASSERT(!is_global || var->is_global()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7022 | Handle<String> name = GetName(); |
| 7023 | DupIfPersist(); |
| 7024 | cgen_->EmitNamedLoad(name, is_global); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7025 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7026 | } |
| 7027 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7028 | case KEYED: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7029 | ASSERT(property != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7030 | DupIfPersist(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7031 | cgen_->EmitKeyedLoad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7032 | cgen_->frame()->EmitPush(r0); |
| 7033 | break; |
| 7034 | } |
| 7035 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7036 | default: |
| 7037 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7038 | } |
| 7039 | } |
| 7040 | |
| 7041 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7042 | void Reference::SetValue(InitState init_state, WriteBarrierCharacter wb_info) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7043 | ASSERT(!is_illegal()); |
| 7044 | ASSERT(!cgen_->has_cc()); |
| 7045 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 7046 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7047 | Property* property = expression_->AsProperty(); |
| 7048 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7049 | cgen_->CodeForSourcePosition(property->position()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7050 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7051 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7052 | switch (type_) { |
| 7053 | case SLOT: { |
| 7054 | Comment cmnt(masm, "[ Store to Slot"); |
| 7055 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7056 | cgen_->StoreToSlot(slot, init_state); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7057 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7058 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7059 | } |
| 7060 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7061 | case NAMED: { |
| 7062 | Comment cmnt(masm, "[ Store to named Property"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7063 | cgen_->EmitNamedStore(GetName(), false); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7064 | frame->EmitPush(r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 7065 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7066 | break; |
| 7067 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7068 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7069 | case KEYED: { |
| 7070 | Comment cmnt(masm, "[ Store to keyed Property"); |
| 7071 | Property* property = expression_->AsProperty(); |
| 7072 | ASSERT(property != NULL); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7073 | cgen_->CodeForSourcePosition(property->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7074 | cgen_->EmitKeyedStore(property->key()->type(), wb_info); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7075 | frame->EmitPush(r0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7076 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7077 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7078 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7079 | |
| 7080 | default: |
| 7081 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7082 | } |
| 7083 | } |
| 7084 | |
| 7085 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7086 | const char* GenericBinaryOpStub::GetName() { |
| 7087 | if (name_ != NULL) return name_; |
| 7088 | const int len = 100; |
| 7089 | name_ = Bootstrapper::AllocateAutoDeletedArray(len); |
| 7090 | if (name_ == NULL) return "OOM"; |
| 7091 | const char* op_name = Token::Name(op_); |
| 7092 | const char* overwrite_name; |
| 7093 | switch (mode_) { |
| 7094 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 7095 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 7096 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 7097 | default: overwrite_name = "UnknownOverwrite"; break; |
| 7098 | } |
| 7099 | |
| 7100 | OS::SNPrintF(Vector<char>(name_, len), |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7101 | "GenericBinaryOpStub_%s_%s%s_%s", |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7102 | op_name, |
| 7103 | overwrite_name, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7104 | specialized_on_rhs_ ? "_ConstantRhs" : "", |
| 7105 | BinaryOpIC::GetName(runtime_operands_type_)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7106 | return name_; |
| 7107 | } |
| 7108 | |
| 7109 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7110 | #undef __ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7111 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7112 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7113 | |
| 7114 | #endif // V8_TARGET_ARCH_ARM |