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 | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 33 | #include "code-stubs-arm.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); |
| 1138 | GenericBinaryOperation(op, mode, GENERATE_INLINE_SMI, kUnknownIntValue); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1139 | } |
| 1140 | return; |
| 1141 | } |
| 1142 | |
| 1143 | // We move the top of stack to a register (normally no move is invoved). |
| 1144 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1145 | switch (op) { |
| 1146 | case Token::ADD: { |
| 1147 | DeferredCode* deferred = |
| 1148 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1149 | |
| 1150 | __ add(tos, tos, Operand(value), SetCC); |
| 1151 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1152 | if (!both_sides_are_smi) { |
| 1153 | __ tst(tos, Operand(kSmiTagMask)); |
| 1154 | deferred->Branch(ne); |
| 1155 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1156 | deferred->BindExit(); |
| 1157 | frame_->EmitPush(tos); |
| 1158 | break; |
| 1159 | } |
| 1160 | |
| 1161 | case Token::SUB: { |
| 1162 | DeferredCode* deferred = |
| 1163 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1164 | |
| 1165 | if (reversed) { |
| 1166 | __ rsb(tos, tos, Operand(value), SetCC); |
| 1167 | } else { |
| 1168 | __ sub(tos, tos, Operand(value), SetCC); |
| 1169 | } |
| 1170 | deferred->Branch(vs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1171 | if (!both_sides_are_smi) { |
| 1172 | __ tst(tos, Operand(kSmiTagMask)); |
| 1173 | deferred->Branch(ne); |
| 1174 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1175 | deferred->BindExit(); |
| 1176 | frame_->EmitPush(tos); |
| 1177 | break; |
| 1178 | } |
| 1179 | |
| 1180 | |
| 1181 | case Token::BIT_OR: |
| 1182 | case Token::BIT_XOR: |
| 1183 | case Token::BIT_AND: { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1184 | if (both_sides_are_smi) { |
| 1185 | switch (op) { |
| 1186 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1187 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1188 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1189 | default: UNREACHABLE(); |
| 1190 | } |
| 1191 | frame_->EmitPush(tos, TypeInfo::Smi()); |
| 1192 | } else { |
| 1193 | DeferredCode* deferred = |
| 1194 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
| 1195 | __ tst(tos, Operand(kSmiTagMask)); |
| 1196 | deferred->Branch(ne); |
| 1197 | switch (op) { |
| 1198 | case Token::BIT_OR: __ orr(tos, tos, Operand(value)); break; |
| 1199 | case Token::BIT_XOR: __ eor(tos, tos, Operand(value)); break; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1200 | case Token::BIT_AND: __ And(tos, tos, Operand(value)); break; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1201 | default: UNREACHABLE(); |
| 1202 | } |
| 1203 | deferred->BindExit(); |
| 1204 | TypeInfo result_type = |
| 1205 | (op == Token::BIT_AND) ? TypeInfo::Smi() : TypeInfo::Integer32(); |
| 1206 | frame_->EmitPush(tos, result_type); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1207 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1208 | break; |
| 1209 | } |
| 1210 | |
| 1211 | case Token::SHL: |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1212 | if (reversed) { |
| 1213 | ASSERT(both_sides_are_smi); |
| 1214 | int max_shift = 0; |
| 1215 | int max_result = int_value == 0 ? 1 : int_value; |
| 1216 | while (Smi::IsValid(max_result << 1)) { |
| 1217 | max_shift++; |
| 1218 | max_result <<= 1; |
| 1219 | } |
| 1220 | DeferredCode* deferred = |
| 1221 | new DeferredInlineSmiOperation(op, int_value, true, mode, tos); |
| 1222 | // Mask off the last 5 bits of the shift operand (rhs). This is part |
| 1223 | // of the definition of shift in JS and we know we have a Smi so we |
| 1224 | // can safely do this. The masked version gets passed to the |
| 1225 | // deferred code, but that makes no difference. |
| 1226 | __ and_(tos, tos, Operand(Smi::FromInt(0x1f))); |
| 1227 | __ cmp(tos, Operand(Smi::FromInt(max_shift))); |
| 1228 | deferred->Branch(ge); |
| 1229 | Register scratch = VirtualFrame::scratch0(); |
| 1230 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Untag. |
| 1231 | __ mov(tos, Operand(Smi::FromInt(int_value))); // Load constant. |
| 1232 | __ mov(tos, Operand(tos, LSL, scratch)); // Shift constant. |
| 1233 | deferred->BindExit(); |
| 1234 | TypeInfo result = TypeInfo::Integer32(); |
| 1235 | frame_->EmitPush(tos, result); |
| 1236 | break; |
| 1237 | } |
| 1238 | // Fall through! |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1239 | case Token::SHR: |
| 1240 | case Token::SAR: { |
| 1241 | ASSERT(!reversed); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1242 | int shift_amount = int_value & 0x1f; |
| 1243 | TypeInfo result = TypeInfo::Number(); |
| 1244 | |
| 1245 | if (op == Token::SHR) { |
| 1246 | if (shift_amount > 1) { |
| 1247 | result = TypeInfo::Smi(); |
| 1248 | } else if (shift_amount > 0) { |
| 1249 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1250 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1251 | } else if (op == Token::SAR) { |
| 1252 | if (shift_amount > 0) { |
| 1253 | result = TypeInfo::Smi(); |
| 1254 | } else { |
| 1255 | result = TypeInfo::Integer32(); |
| 1256 | } |
| 1257 | } else { |
| 1258 | ASSERT(op == Token::SHL); |
| 1259 | result = TypeInfo::Integer32(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1260 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1261 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1262 | Register scratch = VirtualFrame::scratch0(); |
| 1263 | Register scratch2 = VirtualFrame::scratch1(); |
| 1264 | int shift_value = int_value & 0x1f; // least significant 5 bits |
| 1265 | DeferredCode* deferred = |
| 1266 | new DeferredInlineSmiOperation(op, shift_value, false, mode, tos); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1267 | uint32_t problematic_mask = kSmiTagMask; |
| 1268 | // For unsigned shift by zero all negative smis are problematic. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1269 | bool skip_smi_test = both_sides_are_smi; |
| 1270 | if (shift_value == 0 && op == Token::SHR) { |
| 1271 | problematic_mask |= 0x80000000; |
| 1272 | skip_smi_test = false; |
| 1273 | } |
| 1274 | if (!skip_smi_test) { |
| 1275 | __ tst(tos, Operand(problematic_mask)); |
| 1276 | deferred->Branch(ne); // Go slow for problematic input. |
| 1277 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1278 | switch (op) { |
| 1279 | case Token::SHL: { |
| 1280 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1281 | int adjusted_shift = shift_value - kSmiTagSize; |
| 1282 | ASSERT(adjusted_shift >= 0); |
| 1283 | if (adjusted_shift != 0) { |
| 1284 | __ mov(scratch, Operand(tos, LSL, adjusted_shift)); |
| 1285 | // Check that the *signed* result fits in a smi. |
| 1286 | __ add(scratch2, scratch, Operand(0x40000000), SetCC); |
| 1287 | deferred->Branch(mi); |
| 1288 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
| 1289 | } else { |
| 1290 | // Check that the *signed* result fits in a smi. |
| 1291 | __ add(scratch2, tos, Operand(0x40000000), SetCC); |
| 1292 | deferred->Branch(mi); |
| 1293 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
| 1294 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1295 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1296 | break; |
| 1297 | } |
| 1298 | case Token::SHR: { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1299 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1300 | __ mov(scratch, Operand(tos, ASR, kSmiTagSize)); // Remove tag. |
| 1301 | // LSR by immediate 0 means shifting 32 bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1302 | __ mov(scratch, Operand(scratch, LSR, shift_value)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1303 | if (shift_value == 1) { |
| 1304 | // check that the *unsigned* result fits in a smi |
| 1305 | // neither of the two high-order bits can be set: |
| 1306 | // - 0x80000000: high bit would be lost when smi tagging |
| 1307 | // - 0x40000000: this number would convert to negative when |
| 1308 | // smi tagging these two cases can only happen with shifts |
| 1309 | // by 0 or 1 when handed a valid smi |
| 1310 | __ tst(scratch, Operand(0xc0000000)); |
| 1311 | deferred->Branch(ne); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1312 | } else { |
| 1313 | ASSERT(shift_value >= 2); |
| 1314 | result = TypeInfo::Smi(); // SHR by at least 2 gives a Smi. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1315 | } |
| 1316 | __ mov(tos, Operand(scratch, LSL, kSmiTagSize)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1317 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1318 | break; |
| 1319 | } |
| 1320 | case Token::SAR: { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1321 | // In the ARM instructions set, ASR by immediate 0 means shifting 32 |
| 1322 | // bits. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1323 | if (shift_value != 0) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1324 | // Do the shift and the tag removal in one operation. If the shift |
| 1325 | // is 31 bits (the highest possible value) then we emit the |
| 1326 | // instruction as a shift by 0 which means shift arithmetically by |
| 1327 | // 32. |
| 1328 | __ mov(tos, Operand(tos, ASR, (kSmiTagSize + shift_value) & 0x1f)); |
| 1329 | // Put tag back. |
| 1330 | __ mov(tos, Operand(tos, LSL, kSmiTagSize)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1331 | // SAR by at least 1 gives a Smi. |
| 1332 | result = TypeInfo::Smi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1333 | } |
| 1334 | break; |
| 1335 | } |
| 1336 | default: UNREACHABLE(); |
| 1337 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1338 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1339 | frame_->EmitPush(tos, result); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1340 | break; |
| 1341 | } |
| 1342 | |
| 1343 | case Token::MOD: { |
| 1344 | ASSERT(!reversed); |
| 1345 | ASSERT(int_value >= 2); |
| 1346 | ASSERT(IsPowerOf2(int_value)); |
| 1347 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1348 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1349 | unsigned mask = (0x80000000u | kSmiTagMask); |
| 1350 | __ tst(tos, Operand(mask)); |
| 1351 | deferred->Branch(ne); // Go to deferred code on non-Smis and negative. |
| 1352 | mask = (int_value << kSmiTagSize) - 1; |
| 1353 | __ and_(tos, tos, Operand(mask)); |
| 1354 | deferred->BindExit(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1355 | // Mod of positive power of 2 Smi gives a Smi if the lhs is an integer. |
| 1356 | frame_->EmitPush( |
| 1357 | tos, |
| 1358 | both_sides_are_smi ? TypeInfo::Smi() : TypeInfo::Number()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | case Token::MUL: { |
| 1363 | ASSERT(IsEasyToMultiplyBy(int_value)); |
| 1364 | DeferredCode* deferred = |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1365 | new DeferredInlineSmiOperation(op, int_value, reversed, mode, tos); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1366 | unsigned max_smi_that_wont_overflow = Smi::kMaxValue / int_value; |
| 1367 | max_smi_that_wont_overflow <<= kSmiTagSize; |
| 1368 | unsigned mask = 0x80000000u; |
| 1369 | while ((mask & max_smi_that_wont_overflow) == 0) { |
| 1370 | mask |= mask >> 1; |
| 1371 | } |
| 1372 | mask |= kSmiTagMask; |
| 1373 | // This does a single mask that checks for a too high value in a |
| 1374 | // conservative way and for a non-Smi. It also filters out negative |
| 1375 | // numbers, unfortunately, but since this code is inline we prefer |
| 1376 | // brevity to comprehensiveness. |
| 1377 | __ tst(tos, Operand(mask)); |
| 1378 | deferred->Branch(ne); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 1379 | InlineMultiplyByKnownInt(masm_, tos, tos, int_value); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1380 | deferred->BindExit(); |
| 1381 | frame_->EmitPush(tos); |
| 1382 | break; |
| 1383 | } |
| 1384 | |
| 1385 | default: |
| 1386 | UNREACHABLE(); |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1392 | void CodeGenerator::Comparison(Condition cc, |
| 1393 | Expression* left, |
| 1394 | Expression* right, |
| 1395 | bool strict) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1396 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1397 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1398 | if (left != NULL) Load(left); |
| 1399 | if (right != NULL) Load(right); |
| 1400 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1401 | // sp[0] : y |
| 1402 | // sp[1] : x |
| 1403 | // result : cc register |
| 1404 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1405 | // Strict only makes sense for equality comparisons. |
| 1406 | ASSERT(!strict || cc == eq); |
| 1407 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1408 | Register lhs; |
| 1409 | Register rhs; |
| 1410 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1411 | bool lhs_is_smi; |
| 1412 | bool rhs_is_smi; |
| 1413 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1414 | // We load the top two stack positions into registers chosen by the virtual |
| 1415 | // 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] | 1416 | // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| 1417 | if (cc == gt || cc == le) { |
| 1418 | cc = ReverseCondition(cc); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1419 | lhs_is_smi = frame_->KnownSmiAt(0); |
| 1420 | rhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1421 | lhs = frame_->PopToRegister(); |
| 1422 | 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] | 1423 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1424 | rhs_is_smi = frame_->KnownSmiAt(0); |
| 1425 | lhs_is_smi = frame_->KnownSmiAt(1); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1426 | rhs = frame_->PopToRegister(); |
| 1427 | 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] | 1428 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1429 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1430 | bool both_sides_are_smi = (lhs_is_smi && rhs_is_smi); |
| 1431 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1432 | ASSERT(rhs.is(r0) || rhs.is(r1)); |
| 1433 | ASSERT(lhs.is(r0) || lhs.is(r1)); |
| 1434 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1435 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1437 | if (!both_sides_are_smi) { |
| 1438 | // Now we have the two sides in r0 and r1. We flush any other registers |
| 1439 | // because the stub doesn't know about register allocation. |
| 1440 | frame_->SpillAll(); |
| 1441 | Register scratch = VirtualFrame::scratch0(); |
| 1442 | Register smi_test_reg; |
| 1443 | if (lhs_is_smi) { |
| 1444 | smi_test_reg = rhs; |
| 1445 | } else if (rhs_is_smi) { |
| 1446 | smi_test_reg = lhs; |
| 1447 | } else { |
| 1448 | __ orr(scratch, lhs, Operand(rhs)); |
| 1449 | smi_test_reg = scratch; |
| 1450 | } |
| 1451 | __ tst(smi_test_reg, Operand(kSmiTagMask)); |
| 1452 | JumpTarget smi; |
| 1453 | smi.Branch(eq); |
| 1454 | |
| 1455 | // Perform non-smi comparison by stub. |
| 1456 | // CompareStub takes arguments in r0 and r1, returns <0, >0 or 0 in r0. |
| 1457 | // 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] | 1458 | CompareStub stub(cc, strict, kBothCouldBeNaN, true, lhs, rhs); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 1459 | frame_->CallStub(&stub, 0); |
| 1460 | __ cmp(r0, Operand(0)); |
| 1461 | exit.Jump(); |
| 1462 | |
| 1463 | smi.Bind(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1466 | // Do smi comparisons by pointer comparison. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 1467 | __ cmp(lhs, Operand(rhs)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1468 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1469 | exit.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1470 | cc_reg_ = cc; |
| 1471 | } |
| 1472 | |
| 1473 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1474 | // Call the function on the stack with the given arguments. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1475 | void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args, |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1476 | CallFunctionFlags flags, |
| 1477 | int position) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1478 | // Push the arguments ("left-to-right") on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1479 | int arg_count = args->length(); |
| 1480 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1481 | Load(args->at(i)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1482 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1483 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1484 | // Record the position for debugging purposes. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1485 | CodeForSourcePosition(position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1487 | // Use the shared code stub to call the function. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1488 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1489 | CallFunctionStub call_function(arg_count, in_loop, flags); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1490 | frame_->CallStub(&call_function, arg_count + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1491 | |
| 1492 | // Restore context and pop function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1493 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1494 | frame_->Drop(); // discard the TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1498 | void CodeGenerator::CallApplyLazy(Expression* applicand, |
| 1499 | Expression* receiver, |
| 1500 | VariableProxy* arguments, |
| 1501 | int position) { |
| 1502 | // An optimized implementation of expressions of the form |
| 1503 | // x.apply(y, arguments). |
| 1504 | // If the arguments object of the scope has not been allocated, |
| 1505 | // and x.apply is Function.prototype.apply, this optimization |
| 1506 | // just copies y and the arguments of the current function on the |
| 1507 | // stack, as receiver and arguments, and calls x. |
| 1508 | // In the implementation comments, we call x the applicand |
| 1509 | // and y the receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1510 | |
| 1511 | ASSERT(ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION); |
| 1512 | ASSERT(arguments->IsArguments()); |
| 1513 | |
| 1514 | // Load applicand.apply onto the stack. This will usually |
| 1515 | // give us a megamorphic load site. Not super, but it works. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1516 | Load(applicand); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1517 | Handle<String> name = Factory::LookupAsciiSymbol("apply"); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 1518 | frame_->Dup(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1519 | frame_->CallLoadIC(name, RelocInfo::CODE_TARGET); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1520 | frame_->EmitPush(r0); |
| 1521 | |
| 1522 | // Load the receiver and the existing arguments object onto the |
| 1523 | // expression stack. Avoid allocating the arguments object here. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1524 | Load(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1525 | LoadFromSlot(scope()->arguments()->var()->slot(), NOT_INSIDE_TYPEOF); |
| 1526 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1527 | // At this point the top two stack elements are probably in registers |
| 1528 | // since they were just loaded. Ensure they are in regs and get the |
| 1529 | // regs. |
| 1530 | Register receiver_reg = frame_->Peek2(); |
| 1531 | Register arguments_reg = frame_->Peek(); |
| 1532 | |
| 1533 | // From now on the frame is spilled. |
| 1534 | frame_->SpillAll(); |
| 1535 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1536 | // Emit the source position information after having loaded the |
| 1537 | // receiver and the arguments. |
| 1538 | CodeForSourcePosition(position); |
| 1539 | // Contents of the stack at this point: |
| 1540 | // sp[0]: arguments object of the current function or the hole. |
| 1541 | // sp[1]: receiver |
| 1542 | // sp[2]: applicand.apply |
| 1543 | // sp[3]: applicand. |
| 1544 | |
| 1545 | // Check if the arguments object has been lazily allocated |
| 1546 | // already. If so, just use that instead of copying the arguments |
| 1547 | // from the stack. This also deals with cases where a local variable |
| 1548 | // named 'arguments' has been introduced. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1549 | JumpTarget slow; |
| 1550 | Label done; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1551 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1552 | __ cmp(ip, arguments_reg); |
| 1553 | slow.Branch(ne); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1554 | |
| 1555 | Label build_args; |
| 1556 | // Get rid of the arguments object probe. |
| 1557 | frame_->Drop(); |
| 1558 | // Stack now has 3 elements on it. |
| 1559 | // Contents of stack at this point: |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1560 | // sp[0]: receiver - in the receiver_reg register. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1561 | // sp[1]: applicand.apply |
| 1562 | // sp[2]: applicand. |
| 1563 | |
| 1564 | // Check that the receiver really is a JavaScript object. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1565 | __ BranchOnSmi(receiver_reg, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1566 | // We allow all JSObjects including JSFunctions. As long as |
| 1567 | // JS_FUNCTION_TYPE is the last instance type and it is right |
| 1568 | // after LAST_JS_OBJECT_TYPE, we do not have to check the upper |
| 1569 | // bound. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 1570 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 1571 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1572 | __ CompareObjectType(receiver_reg, r2, r3, FIRST_JS_OBJECT_TYPE); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1573 | __ b(lt, &build_args); |
| 1574 | |
| 1575 | // Check that applicand.apply is Function.prototype.apply. |
| 1576 | __ ldr(r0, MemOperand(sp, kPointerSize)); |
| 1577 | __ BranchOnSmi(r0, &build_args); |
| 1578 | __ CompareObjectType(r0, r1, r2, JS_FUNCTION_TYPE); |
| 1579 | __ b(ne, &build_args); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1580 | Handle<Code> apply_code(Builtins::builtin(Builtins::FunctionApply)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 1581 | __ ldr(r1, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 1582 | __ sub(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1583 | __ cmp(r1, Operand(apply_code)); |
| 1584 | __ b(ne, &build_args); |
| 1585 | |
| 1586 | // Check that applicand is a function. |
| 1587 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
| 1588 | __ BranchOnSmi(r1, &build_args); |
| 1589 | __ CompareObjectType(r1, r2, r3, JS_FUNCTION_TYPE); |
| 1590 | __ b(ne, &build_args); |
| 1591 | |
| 1592 | // Copy the arguments to this function possibly from the |
| 1593 | // adaptor frame below it. |
| 1594 | Label invoke, adapted; |
| 1595 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 1596 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 1597 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 1598 | __ b(eq, &adapted); |
| 1599 | |
| 1600 | // No arguments adaptor frame. Copy fixed number of arguments. |
| 1601 | __ mov(r0, Operand(scope()->num_parameters())); |
| 1602 | for (int i = 0; i < scope()->num_parameters(); i++) { |
| 1603 | __ ldr(r2, frame_->ParameterAt(i)); |
| 1604 | __ push(r2); |
| 1605 | } |
| 1606 | __ jmp(&invoke); |
| 1607 | |
| 1608 | // Arguments adaptor frame present. Copy arguments from there, but |
| 1609 | // avoid copying too many arguments to avoid stack overflows. |
| 1610 | __ bind(&adapted); |
| 1611 | static const uint32_t kArgumentsLimit = 1 * KB; |
| 1612 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1613 | __ mov(r0, Operand(r0, LSR, kSmiTagSize)); |
| 1614 | __ mov(r3, r0); |
| 1615 | __ cmp(r0, Operand(kArgumentsLimit)); |
| 1616 | __ b(gt, &build_args); |
| 1617 | |
| 1618 | // Loop through the arguments pushing them onto the execution |
| 1619 | // stack. We don't inform the virtual frame of the push, so we don't |
| 1620 | // have to worry about getting rid of the elements from the virtual |
| 1621 | // frame. |
| 1622 | Label loop; |
| 1623 | // r3 is a small non-negative integer, due to the test above. |
| 1624 | __ cmp(r3, Operand(0)); |
| 1625 | __ b(eq, &invoke); |
| 1626 | // Compute the address of the first argument. |
| 1627 | __ add(r2, r2, Operand(r3, LSL, kPointerSizeLog2)); |
| 1628 | __ add(r2, r2, Operand(kPointerSize)); |
| 1629 | __ bind(&loop); |
| 1630 | // Post-decrement argument address by kPointerSize on each iteration. |
| 1631 | __ ldr(r4, MemOperand(r2, kPointerSize, NegPostIndex)); |
| 1632 | __ push(r4); |
| 1633 | __ sub(r3, r3, Operand(1), SetCC); |
| 1634 | __ b(gt, &loop); |
| 1635 | |
| 1636 | // Invoke the function. |
| 1637 | __ bind(&invoke); |
| 1638 | ParameterCount actual(r0); |
| 1639 | __ InvokeFunction(r1, actual, CALL_FUNCTION); |
| 1640 | // Drop applicand.apply and applicand from the stack, and push |
| 1641 | // the result of the function call, but leave the spilled frame |
| 1642 | // unchanged, with 3 elements, so it is correct when we compile the |
| 1643 | // slow-case code. |
| 1644 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 1645 | __ push(r0); |
| 1646 | // Stack now has 1 element: |
| 1647 | // sp[0]: result |
| 1648 | __ jmp(&done); |
| 1649 | |
| 1650 | // Slow-case: Allocate the arguments object since we know it isn't |
| 1651 | // there, and fall-through to the slow-case where we call |
| 1652 | // applicand.apply. |
| 1653 | __ bind(&build_args); |
| 1654 | // Stack now has 3 elements, because we have jumped from where: |
| 1655 | // sp[0]: receiver |
| 1656 | // sp[1]: applicand.apply |
| 1657 | // sp[2]: applicand. |
| 1658 | StoreArgumentsObject(false); |
| 1659 | |
| 1660 | // Stack and frame now have 4 elements. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1661 | slow.Bind(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1662 | |
| 1663 | // Generic computation of x.apply(y, args) with no special optimization. |
| 1664 | // Flip applicand.apply and applicand on the stack, so |
| 1665 | // applicand looks like the receiver of the applicand.apply call. |
| 1666 | // Then process it as a normal function call. |
| 1667 | __ ldr(r0, MemOperand(sp, 3 * kPointerSize)); |
| 1668 | __ ldr(r1, MemOperand(sp, 2 * kPointerSize)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1669 | __ Strd(r0, r1, MemOperand(sp, 2 * kPointerSize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1670 | |
| 1671 | CallFunctionStub call_function(2, NOT_IN_LOOP, NO_CALL_FUNCTION_FLAGS); |
| 1672 | frame_->CallStub(&call_function, 3); |
| 1673 | // The function and its two arguments have been dropped. |
| 1674 | frame_->Drop(); // Drop the receiver as well. |
| 1675 | frame_->EmitPush(r0); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 1676 | frame_->SpillAll(); // A spilled frame is also jumping to label done. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 1677 | // Stack now has 1 element: |
| 1678 | // sp[0]: result |
| 1679 | __ bind(&done); |
| 1680 | |
| 1681 | // Restore the context register after a call. |
| 1682 | __ ldr(cp, frame_->Context()); |
| 1683 | } |
| 1684 | |
| 1685 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1686 | void CodeGenerator::Branch(bool if_true, JumpTarget* target) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1687 | ASSERT(has_cc()); |
| 1688 | Condition cc = if_true ? cc_reg_ : NegateCondition(cc_reg_); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1689 | target->Branch(cc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1690 | cc_reg_ = al; |
| 1691 | } |
| 1692 | |
| 1693 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1694 | void CodeGenerator::CheckStack() { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1695 | frame_->SpillAll(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1696 | Comment cmnt(masm_, "[ check stack"); |
| 1697 | __ LoadRoot(ip, Heap::kStackLimitRootIndex); |
| 1698 | // Put the lr setup instruction in the delay slot. kInstrSize is added to |
| 1699 | // the implicit 8 byte offset that always applies to operations with pc and |
| 1700 | // gives a return address 12 bytes down. |
| 1701 | masm_->add(lr, pc, Operand(Assembler::kInstrSize)); |
| 1702 | masm_->cmp(sp, Operand(ip)); |
| 1703 | StackCheckStub stub; |
| 1704 | // Call the stub if lower. |
| 1705 | masm_->mov(pc, |
| 1706 | Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
| 1707 | RelocInfo::CODE_TARGET), |
| 1708 | LeaveCC, |
| 1709 | lo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1713 | void CodeGenerator::VisitStatements(ZoneList<Statement*>* statements) { |
| 1714 | #ifdef DEBUG |
| 1715 | int original_height = frame_->height(); |
| 1716 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1717 | for (int i = 0; frame_ != NULL && i < statements->length(); i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1718 | Visit(statements->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1719 | } |
| 1720 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 1721 | } |
| 1722 | |
| 1723 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1724 | void CodeGenerator::VisitBlock(Block* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1725 | #ifdef DEBUG |
| 1726 | int original_height = frame_->height(); |
| 1727 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1728 | Comment cmnt(masm_, "[ Block"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1729 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 1730 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1731 | VisitStatements(node->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1732 | if (node->break_target()->is_linked()) { |
| 1733 | node->break_target()->Bind(); |
| 1734 | } |
| 1735 | node->break_target()->Unuse(); |
| 1736 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1740 | void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1741 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1742 | frame_->EmitPush(Operand(pairs)); |
| 1743 | frame_->EmitPush(Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
| 1744 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1745 | frame_->CallRuntime(Runtime::kDeclareGlobals, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1746 | // The result is discarded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1750 | void CodeGenerator::VisitDeclaration(Declaration* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1751 | #ifdef DEBUG |
| 1752 | int original_height = frame_->height(); |
| 1753 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1754 | Comment cmnt(masm_, "[ Declaration"); |
| 1755 | Variable* var = node->proxy()->var(); |
| 1756 | ASSERT(var != NULL); // must have been resolved |
| 1757 | Slot* slot = var->slot(); |
| 1758 | |
| 1759 | // If it was not possible to allocate the variable at compile time, |
| 1760 | // we need to "declare" it at runtime to make sure it actually |
| 1761 | // exists in the local context. |
| 1762 | if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1763 | // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1764 | // during variable resolution and must have mode DYNAMIC. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 1765 | ASSERT(var->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1766 | // For now, just do a runtime call. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1767 | frame_->EmitPush(cp); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1768 | frame_->EmitPush(Operand(var->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | // Declaration nodes are always declared in only two modes. |
| 1770 | ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1771 | PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1772 | frame_->EmitPush(Operand(Smi::FromInt(attr))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1773 | // Push initial value, if any. |
| 1774 | // Note: For variables we must not push an initial value (such as |
| 1775 | // 'undefined') because we may have a (legal) redeclaration and we |
| 1776 | // must not destroy the current value. |
| 1777 | if (node->mode() == Variable::CONST) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1778 | frame_->EmitPushRoot(Heap::kTheHoleValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1779 | } else if (node->fun() != NULL) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1780 | Load(node->fun()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1781 | } else { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1782 | frame_->EmitPush(Operand(0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1783 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1784 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1785 | frame_->CallRuntime(Runtime::kDeclareContextSlot, 4); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1786 | // Ignore the return value (declarations are statements). |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1787 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1788 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1789 | return; |
| 1790 | } |
| 1791 | |
| 1792 | ASSERT(!var->is_global()); |
| 1793 | |
| 1794 | // If we have a function or a constant, we need to initialize the variable. |
| 1795 | Expression* val = NULL; |
| 1796 | if (node->mode() == Variable::CONST) { |
| 1797 | val = new Literal(Factory::the_hole_value()); |
| 1798 | } else { |
| 1799 | val = node->fun(); // NULL if we don't have a function |
| 1800 | } |
| 1801 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1802 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1803 | if (val != NULL) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1804 | WriteBarrierCharacter wb_info = |
| 1805 | val->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
| 1806 | if (val->AsLiteral() != NULL) wb_info = NEVER_NEWSPACE; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1807 | // Set initial value. |
| 1808 | Reference target(this, node->proxy()); |
| 1809 | Load(val); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1810 | target.SetValue(NOT_CONST_INIT, wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1811 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1812 | // Get rid of the assigned value (declarations are statements). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1813 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1814 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1815 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1819 | void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1820 | #ifdef DEBUG |
| 1821 | int original_height = frame_->height(); |
| 1822 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1823 | Comment cmnt(masm_, "[ ExpressionStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1824 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1825 | Expression* expression = node->expression(); |
| 1826 | expression->MarkAsStatement(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1827 | Load(expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1828 | frame_->Drop(); |
| 1829 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1833 | void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1834 | #ifdef DEBUG |
| 1835 | int original_height = frame_->height(); |
| 1836 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1837 | Comment cmnt(masm_, "// EmptyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1838 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1839 | // nothing to do |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1840 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1841 | } |
| 1842 | |
| 1843 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1844 | void CodeGenerator::VisitIfStatement(IfStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1845 | #ifdef DEBUG |
| 1846 | int original_height = frame_->height(); |
| 1847 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1848 | Comment cmnt(masm_, "[ IfStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1849 | // Generate different code depending on which parts of the if statement |
| 1850 | // are present or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1851 | bool has_then_stm = node->HasThenStatement(); |
| 1852 | bool has_else_stm = node->HasElseStatement(); |
| 1853 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1854 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1855 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1856 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1857 | if (has_then_stm && has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1858 | Comment cmnt(masm_, "[ IfThenElse"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1859 | JumpTarget then; |
| 1860 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1861 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1862 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1863 | if (frame_ != NULL) { |
| 1864 | Branch(false, &else_); |
| 1865 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1866 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1867 | if (frame_ != NULL || then.is_linked()) { |
| 1868 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1869 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1870 | } |
| 1871 | if (frame_ != NULL) { |
| 1872 | exit.Jump(); |
| 1873 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1874 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1875 | if (else_.is_linked()) { |
| 1876 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1877 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1878 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1879 | |
| 1880 | } else if (has_then_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1881 | Comment cmnt(masm_, "[ IfThen"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1882 | ASSERT(!has_else_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1883 | JumpTarget then; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1885 | LoadCondition(node->condition(), &then, &exit, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1886 | if (frame_ != NULL) { |
| 1887 | Branch(false, &exit); |
| 1888 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1889 | // then |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1890 | if (frame_ != NULL || then.is_linked()) { |
| 1891 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1892 | Visit(node->then_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1893 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | |
| 1895 | } else if (has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1896 | Comment cmnt(masm_, "[ IfElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1897 | ASSERT(!has_then_stm); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 1898 | JumpTarget else_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1899 | // if (!cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1900 | LoadCondition(node->condition(), &exit, &else_, true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1901 | if (frame_ != NULL) { |
| 1902 | Branch(true, &exit); |
| 1903 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1904 | // else |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1905 | if (frame_ != NULL || else_.is_linked()) { |
| 1906 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1907 | Visit(node->else_statement()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1908 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1909 | |
| 1910 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1911 | Comment cmnt(masm_, "[ If"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1912 | ASSERT(!has_then_stm && !has_else_stm); |
| 1913 | // if (cond) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1914 | LoadCondition(node->condition(), &exit, &exit, false); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1915 | if (frame_ != NULL) { |
| 1916 | if (has_cc()) { |
| 1917 | cc_reg_ = al; |
| 1918 | } else { |
| 1919 | frame_->Drop(); |
| 1920 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | // end |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1925 | if (exit.is_linked()) { |
| 1926 | exit.Bind(); |
| 1927 | } |
| 1928 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1932 | void CodeGenerator::VisitContinueStatement(ContinueStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1933 | Comment cmnt(masm_, "[ ContinueStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1934 | CodeForStatementPosition(node); |
| 1935 | node->target()->continue_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1939 | void CodeGenerator::VisitBreakStatement(BreakStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1940 | Comment cmnt(masm_, "[ BreakStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1941 | CodeForStatementPosition(node); |
| 1942 | node->target()->break_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1946 | void CodeGenerator::VisitReturnStatement(ReturnStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1947 | Comment cmnt(masm_, "[ ReturnStatement"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1948 | |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 1949 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1950 | Load(node->expression()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1951 | frame_->PopToR0(); |
| 1952 | frame_->PrepareForReturn(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1953 | if (function_return_is_shadowed_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1954 | function_return_.Jump(); |
| 1955 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1956 | // Pop the result from the frame and prepare the frame for |
| 1957 | // returning thus making it easier to merge. |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1958 | if (function_return_.is_bound()) { |
| 1959 | // If the function return label is already bound we reuse the |
| 1960 | // code by jumping to the return site. |
| 1961 | function_return_.Jump(); |
| 1962 | } else { |
| 1963 | function_return_.Bind(); |
| 1964 | GenerateReturnSequence(); |
| 1965 | } |
| 1966 | } |
| 1967 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1968 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1969 | |
| 1970 | void CodeGenerator::GenerateReturnSequence() { |
| 1971 | if (FLAG_trace) { |
| 1972 | // Push the return value on the stack as the parameter. |
| 1973 | // Runtime::TraceExit returns the parameter as it is. |
| 1974 | frame_->EmitPush(r0); |
| 1975 | frame_->CallRuntime(Runtime::kTraceExit, 1); |
| 1976 | } |
| 1977 | |
| 1978 | #ifdef DEBUG |
| 1979 | // Add a label for checking the size of the code used for returning. |
| 1980 | Label check_exit_codesize; |
| 1981 | masm_->bind(&check_exit_codesize); |
| 1982 | #endif |
| 1983 | // Make sure that the constant pool is not emitted inside of the return |
| 1984 | // sequence. |
| 1985 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 1986 | // Tear down the frame which will restore the caller's frame pointer and |
| 1987 | // the link register. |
| 1988 | frame_->Exit(); |
| 1989 | |
| 1990 | // Here we use masm_-> instead of the __ macro to avoid the code coverage |
| 1991 | // tool from instrumenting as we rely on the code size here. |
| 1992 | int32_t sp_delta = (scope()->num_parameters() + 1) * kPointerSize; |
| 1993 | masm_->add(sp, sp, Operand(sp_delta)); |
| 1994 | masm_->Jump(lr); |
| 1995 | DeleteFrame(); |
| 1996 | |
| 1997 | #ifdef DEBUG |
| 1998 | // Check that the size of the code used for returning matches what is |
| 1999 | // expected by the debugger. If the sp_delts above cannot be encoded in |
| 2000 | // the add instruction the add will generate two instructions. |
| 2001 | int return_sequence_length = |
| 2002 | masm_->InstructionsGeneratedSince(&check_exit_codesize); |
| 2003 | CHECK(return_sequence_length == |
| 2004 | Assembler::kJSReturnSequenceInstructions || |
| 2005 | return_sequence_length == |
| 2006 | Assembler::kJSReturnSequenceInstructions + 1); |
| 2007 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2008 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2012 | void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2013 | #ifdef DEBUG |
| 2014 | int original_height = frame_->height(); |
| 2015 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2016 | Comment cmnt(masm_, "[ WithEnterStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2017 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2018 | Load(node->expression()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2019 | if (node->is_catch_block()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2020 | frame_->CallRuntime(Runtime::kPushCatchContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2021 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2022 | frame_->CallRuntime(Runtime::kPushContext, 1); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2023 | } |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2024 | #ifdef DEBUG |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2025 | JumpTarget verified_true; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2026 | __ cmp(r0, cp); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2027 | verified_true.Branch(eq); |
| 2028 | __ stop("PushContext: r0 is expected to be the same as cp"); |
| 2029 | verified_true.Bind(); |
| 2030 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2032 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2033 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2037 | void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2038 | #ifdef DEBUG |
| 2039 | int original_height = frame_->height(); |
| 2040 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2041 | Comment cmnt(masm_, "[ WithExitStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2042 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2043 | // Pop context. |
| 2044 | __ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX)); |
| 2045 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2046 | __ str(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2047 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2051 | void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2052 | #ifdef DEBUG |
| 2053 | int original_height = frame_->height(); |
| 2054 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | Comment cmnt(masm_, "[ SwitchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2056 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2057 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2058 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2059 | Load(node->tag()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2060 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2061 | JumpTarget next_test; |
| 2062 | JumpTarget fall_through; |
| 2063 | JumpTarget default_entry; |
| 2064 | JumpTarget default_exit(JumpTarget::BIDIRECTIONAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2065 | ZoneList<CaseClause*>* cases = node->cases(); |
| 2066 | int length = cases->length(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2067 | CaseClause* default_clause = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2068 | |
| 2069 | for (int i = 0; i < length; i++) { |
| 2070 | CaseClause* clause = cases->at(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2071 | if (clause->is_default()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2072 | // Remember the default clause and compile it at the end. |
| 2073 | default_clause = clause; |
| 2074 | continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2077 | Comment cmnt(masm_, "[ Case clause"); |
| 2078 | // Compile the test. |
| 2079 | next_test.Bind(); |
| 2080 | next_test.Unuse(); |
| 2081 | // Duplicate TOS. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2082 | frame_->Dup(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2083 | Comparison(eq, NULL, clause->label(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2084 | Branch(false, &next_test); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2085 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2086 | // Before entering the body from the test, remove the switch value from |
| 2087 | // the stack. |
| 2088 | frame_->Drop(); |
| 2089 | |
| 2090 | // Label the body so that fall through is enabled. |
| 2091 | if (i > 0 && cases->at(i - 1)->is_default()) { |
| 2092 | default_exit.Bind(); |
| 2093 | } else { |
| 2094 | fall_through.Bind(); |
| 2095 | fall_through.Unuse(); |
| 2096 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2097 | VisitStatements(clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2098 | |
| 2099 | // If control flow can fall through from the body, jump to the next body |
| 2100 | // or the end of the statement. |
| 2101 | if (frame_ != NULL) { |
| 2102 | if (i < length - 1 && cases->at(i + 1)->is_default()) { |
| 2103 | default_entry.Jump(); |
| 2104 | } else { |
| 2105 | fall_through.Jump(); |
| 2106 | } |
| 2107 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2110 | // The final "test" removes the switch value. |
| 2111 | next_test.Bind(); |
| 2112 | frame_->Drop(); |
| 2113 | |
| 2114 | // If there is a default clause, compile it. |
| 2115 | if (default_clause != NULL) { |
| 2116 | Comment cmnt(masm_, "[ Default clause"); |
| 2117 | default_entry.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2118 | VisitStatements(default_clause->statements()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2119 | // 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] | 2120 | // it, jump to that case's body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2121 | if (frame_ != NULL && default_exit.is_bound()) { |
| 2122 | default_exit.Jump(); |
| 2123 | } |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2124 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2125 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2126 | if (fall_through.is_linked()) { |
| 2127 | fall_through.Bind(); |
| 2128 | } |
| 2129 | |
| 2130 | if (node->break_target()->is_linked()) { |
| 2131 | node->break_target()->Bind(); |
| 2132 | } |
| 2133 | node->break_target()->Unuse(); |
| 2134 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2138 | void CodeGenerator::VisitDoWhileStatement(DoWhileStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2139 | #ifdef DEBUG |
| 2140 | int original_height = frame_->height(); |
| 2141 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2142 | Comment cmnt(masm_, "[ DoWhileStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2143 | CodeForStatementPosition(node); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2144 | node->break_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2145 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2146 | IncrementLoopNesting(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2147 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2148 | // Label the top of the loop for the backward CFG edge. If the test |
| 2149 | // is always true we can use the continue target, and if the test is |
| 2150 | // always false there is no need. |
| 2151 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2152 | switch (info) { |
| 2153 | case ALWAYS_TRUE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2154 | node->continue_target()->SetExpectedHeight(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2155 | node->continue_target()->Bind(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | case ALWAYS_FALSE: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2158 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2159 | break; |
| 2160 | case DONT_KNOW: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2161 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2162 | body.Bind(); |
| 2163 | break; |
| 2164 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2165 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2166 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2167 | Visit(node->body()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2168 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2169 | // Compile the test. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2170 | switch (info) { |
| 2171 | case ALWAYS_TRUE: |
| 2172 | // If control can fall off the end of the body, jump back to the |
| 2173 | // top. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2174 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2175 | node->continue_target()->Jump(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2176 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2177 | break; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2178 | case ALWAYS_FALSE: |
| 2179 | // If we have a continue in the body, we only have to bind its |
| 2180 | // jump target. |
| 2181 | if (node->continue_target()->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2182 | node->continue_target()->Bind(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2183 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | case DONT_KNOW: |
| 2186 | // We have to compile the test expression if it can be reached by |
| 2187 | // control flow falling out of the body or via continue. |
| 2188 | if (node->continue_target()->is_linked()) { |
| 2189 | node->continue_target()->Bind(); |
| 2190 | } |
| 2191 | if (has_valid_frame()) { |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 2192 | Comment cmnt(masm_, "[ DoWhileCondition"); |
| 2193 | CodeForDoWhileConditionPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2194 | LoadCondition(node->cond(), &body, node->break_target(), true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2195 | if (has_valid_frame()) { |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2196 | // A invalid frame here indicates that control did not |
| 2197 | // fall out of the test expression. |
| 2198 | Branch(true, &body); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2199 | } |
| 2200 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2201 | break; |
| 2202 | } |
| 2203 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2204 | if (node->break_target()->is_linked()) { |
| 2205 | node->break_target()->Bind(); |
| 2206 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2207 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2208 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2209 | } |
| 2210 | |
| 2211 | |
| 2212 | void CodeGenerator::VisitWhileStatement(WhileStatement* node) { |
| 2213 | #ifdef DEBUG |
| 2214 | int original_height = frame_->height(); |
| 2215 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2216 | Comment cmnt(masm_, "[ WhileStatement"); |
| 2217 | CodeForStatementPosition(node); |
| 2218 | |
| 2219 | // If the test is never true and has no side effects there is no need |
| 2220 | // to compile the test or body. |
| 2221 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2222 | if (info == ALWAYS_FALSE) return; |
| 2223 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2224 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2225 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2226 | |
| 2227 | // Label the top of the loop with the continue target for the backward |
| 2228 | // CFG edge. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2229 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2230 | node->continue_target()->Bind(); |
| 2231 | |
| 2232 | if (info == DONT_KNOW) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 2233 | JumpTarget body(JumpTarget::BIDIRECTIONAL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2234 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2235 | if (has_valid_frame()) { |
| 2236 | // A NULL frame indicates that control did not fall out of the |
| 2237 | // test expression. |
| 2238 | Branch(false, node->break_target()); |
| 2239 | } |
| 2240 | if (has_valid_frame() || body.is_linked()) { |
| 2241 | body.Bind(); |
| 2242 | } |
| 2243 | } |
| 2244 | |
| 2245 | if (has_valid_frame()) { |
| 2246 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2247 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2248 | |
| 2249 | // If control flow can fall out of the body, jump back to the top. |
| 2250 | if (has_valid_frame()) { |
| 2251 | node->continue_target()->Jump(); |
| 2252 | } |
| 2253 | } |
| 2254 | if (node->break_target()->is_linked()) { |
| 2255 | node->break_target()->Bind(); |
| 2256 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2257 | DecrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2258 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
| 2259 | } |
| 2260 | |
| 2261 | |
| 2262 | void CodeGenerator::VisitForStatement(ForStatement* node) { |
| 2263 | #ifdef DEBUG |
| 2264 | int original_height = frame_->height(); |
| 2265 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2266 | Comment cmnt(masm_, "[ ForStatement"); |
| 2267 | CodeForStatementPosition(node); |
| 2268 | if (node->init() != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2269 | Visit(node->init()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | // If the test is never true there is no need to compile the test or |
| 2273 | // body. |
| 2274 | ConditionAnalysis info = AnalyzeCondition(node->cond()); |
| 2275 | if (info == ALWAYS_FALSE) return; |
| 2276 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2277 | node->break_target()->SetExpectedHeight(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2278 | IncrementLoopNesting(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2279 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 2280 | // We know that the loop index is a smi if it is not modified in the |
| 2281 | // loop body and it is checked against a constant limit in the loop |
| 2282 | // condition. In this case, we reset the static type information of the |
| 2283 | // loop index to smi before compiling the body, the update expression, and |
| 2284 | // the bottom check of the loop condition. |
| 2285 | TypeInfoCodeGenState type_info_scope(this, |
| 2286 | node->is_fast_smi_loop() ? |
| 2287 | node->loop_variable()->slot() : |
| 2288 | NULL, |
| 2289 | TypeInfo::Smi()); |
| 2290 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2291 | // If there is no update statement, label the top of the loop with the |
| 2292 | // continue target, otherwise with the loop target. |
| 2293 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2294 | if (node->next() == NULL) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2295 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2296 | node->continue_target()->Bind(); |
| 2297 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2298 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2299 | loop.Bind(); |
| 2300 | } |
| 2301 | |
| 2302 | // If the test is always true, there is no need to compile it. |
| 2303 | if (info == DONT_KNOW) { |
| 2304 | JumpTarget body; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2305 | LoadCondition(node->cond(), &body, node->break_target(), true); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2306 | if (has_valid_frame()) { |
| 2307 | Branch(false, node->break_target()); |
| 2308 | } |
| 2309 | if (has_valid_frame() || body.is_linked()) { |
| 2310 | body.Bind(); |
| 2311 | } |
| 2312 | } |
| 2313 | |
| 2314 | if (has_valid_frame()) { |
| 2315 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2316 | Visit(node->body()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2317 | |
| 2318 | if (node->next() == NULL) { |
| 2319 | // If there is no update statement and control flow can fall out |
| 2320 | // of the loop, jump directly to the continue label. |
| 2321 | if (has_valid_frame()) { |
| 2322 | node->continue_target()->Jump(); |
| 2323 | } |
| 2324 | } else { |
| 2325 | // If there is an update statement and control flow can reach it |
| 2326 | // via falling out of the body of the loop or continuing, we |
| 2327 | // compile the update statement. |
| 2328 | if (node->continue_target()->is_linked()) { |
| 2329 | node->continue_target()->Bind(); |
| 2330 | } |
| 2331 | if (has_valid_frame()) { |
| 2332 | // Record source position of the statement as this code which is |
| 2333 | // after the code for the body actually belongs to the loop |
| 2334 | // statement and not the body. |
| 2335 | CodeForStatementPosition(node); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2336 | Visit(node->next()); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2337 | loop.Jump(); |
| 2338 | } |
| 2339 | } |
| 2340 | } |
| 2341 | if (node->break_target()->is_linked()) { |
| 2342 | node->break_target()->Bind(); |
| 2343 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2344 | DecrementLoopNesting(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2345 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2349 | void CodeGenerator::VisitForInStatement(ForInStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2350 | #ifdef DEBUG |
| 2351 | int original_height = frame_->height(); |
| 2352 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | Comment cmnt(masm_, "[ ForInStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2354 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2356 | JumpTarget primitive; |
| 2357 | JumpTarget jsobject; |
| 2358 | JumpTarget fixed_array; |
| 2359 | JumpTarget entry(JumpTarget::BIDIRECTIONAL); |
| 2360 | JumpTarget end_del_check; |
| 2361 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2362 | |
| 2363 | // Get the object to enumerate over (converted to JSObject). |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2364 | Load(node->enumerable()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2365 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2366 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2367 | // Both SpiderMonkey and kjs ignore null and undefined in contrast |
| 2368 | // to the specification. 12.6.4 mandates a call to ToObject. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2369 | frame_->EmitPop(r0); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2370 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 2371 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2372 | exit.Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2373 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2374 | __ cmp(r0, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2375 | exit.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2376 | |
| 2377 | // Stack layout in body: |
| 2378 | // [iteration counter (Smi)] |
| 2379 | // [length of array] |
| 2380 | // [FixedArray] |
| 2381 | // [Map or 0] |
| 2382 | // [Object] |
| 2383 | |
| 2384 | // Check if enumerable is already a JSObject |
| 2385 | __ tst(r0, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2386 | primitive.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2387 | __ CompareObjectType(r0, r1, r1, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2388 | jsobject.Branch(hs); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2389 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2390 | primitive.Bind(); |
| 2391 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2392 | frame_->InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2393 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2394 | jsobject.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2395 | // Get the set of properties (as a FixedArray or Map). |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2396 | // r0: value to be iterated over |
| 2397 | frame_->EmitPush(r0); // Push the object being iterated over. |
| 2398 | |
| 2399 | // Check cache validity in generated code. This is a fast case for |
| 2400 | // the JSObject::IsSimpleEnum cache validity checks. If we cannot |
| 2401 | // guarantee cache validity, call the runtime system to check cache |
| 2402 | // validity or get the property names in a fixed array. |
| 2403 | JumpTarget call_runtime; |
| 2404 | JumpTarget loop(JumpTarget::BIDIRECTIONAL); |
| 2405 | JumpTarget check_prototype; |
| 2406 | JumpTarget use_cache; |
| 2407 | __ mov(r1, Operand(r0)); |
| 2408 | loop.Bind(); |
| 2409 | // Check that there are no elements. |
| 2410 | __ ldr(r2, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 2411 | __ LoadRoot(r4, Heap::kEmptyFixedArrayRootIndex); |
| 2412 | __ cmp(r2, r4); |
| 2413 | call_runtime.Branch(ne); |
| 2414 | // Check that instance descriptors are not empty so that we can |
| 2415 | // check for an enum cache. Leave the map in r3 for the subsequent |
| 2416 | // prototype load. |
| 2417 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2418 | __ ldr(r2, FieldMemOperand(r3, Map::kInstanceDescriptorsOffset)); |
| 2419 | __ LoadRoot(ip, Heap::kEmptyDescriptorArrayRootIndex); |
| 2420 | __ cmp(r2, ip); |
| 2421 | call_runtime.Branch(eq); |
| 2422 | // Check that there in an enum cache in the non-empty instance |
| 2423 | // descriptors. This is the case if the next enumeration index |
| 2424 | // field does not contain a smi. |
| 2425 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumerationIndexOffset)); |
| 2426 | __ tst(r2, Operand(kSmiTagMask)); |
| 2427 | call_runtime.Branch(eq); |
| 2428 | // For all objects but the receiver, check that the cache is empty. |
| 2429 | // r4: empty fixed array root. |
| 2430 | __ cmp(r1, r0); |
| 2431 | check_prototype.Branch(eq); |
| 2432 | __ ldr(r2, FieldMemOperand(r2, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2433 | __ cmp(r2, r4); |
| 2434 | call_runtime.Branch(ne); |
| 2435 | check_prototype.Bind(); |
| 2436 | // Load the prototype from the map and loop if non-null. |
| 2437 | __ ldr(r1, FieldMemOperand(r3, Map::kPrototypeOffset)); |
| 2438 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 2439 | __ cmp(r1, ip); |
| 2440 | loop.Branch(ne); |
| 2441 | // The enum cache is valid. Load the map of the object being |
| 2442 | // iterated over and use the cache for the iteration. |
| 2443 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2444 | use_cache.Jump(); |
| 2445 | |
| 2446 | call_runtime.Bind(); |
| 2447 | // Call the runtime to get the property names for the object. |
| 2448 | 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] | 2449 | frame_->CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2450 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2451 | // If we got a map from the runtime call, we can do a fast |
| 2452 | // modification check. Otherwise, we got a fixed array, and we have |
| 2453 | // to do a slow check. |
| 2454 | // r0: map or fixed array (result from call to |
| 2455 | // Runtime::kGetPropertyNamesFast) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2456 | __ mov(r2, Operand(r0)); |
| 2457 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2458 | __ LoadRoot(ip, Heap::kMetaMapRootIndex); |
| 2459 | __ cmp(r1, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2460 | fixed_array.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2461 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2462 | use_cache.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2463 | // Get enum cache |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2464 | // r0: map (either the result from a call to |
| 2465 | // Runtime::kGetPropertyNamesFast or has been fetched directly from |
| 2466 | // the object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2467 | __ mov(r1, Operand(r0)); |
| 2468 | __ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset)); |
| 2469 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 2470 | __ ldr(r2, |
| 2471 | FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 2472 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2473 | frame_->EmitPush(r0); // map |
| 2474 | frame_->EmitPush(r2); // enum cache bridge cache |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2475 | __ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2476 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2477 | __ mov(r0, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2478 | frame_->EmitPush(r0); |
| 2479 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2480 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2481 | fixed_array.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2482 | __ mov(r1, Operand(Smi::FromInt(0))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2483 | frame_->EmitPush(r1); // insert 0 in place of Map |
| 2484 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2485 | |
| 2486 | // 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] | 2487 | __ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2488 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2489 | __ mov(r0, Operand(Smi::FromInt(0))); // init index |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2490 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2491 | |
| 2492 | // Condition. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2493 | entry.Bind(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2494 | // sp[0] : index |
| 2495 | // sp[1] : array/enum cache length |
| 2496 | // sp[2] : array or enum cache |
| 2497 | // sp[3] : 0 or map |
| 2498 | // sp[4] : enumerable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2499 | // Grab the current frame's height for the break and continue |
| 2500 | // targets only after all the state is pushed on the frame. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2501 | node->break_target()->SetExpectedHeight(); |
| 2502 | node->continue_target()->SetExpectedHeight(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2503 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 2504 | // Load the current count to r0, load the length to r1. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2505 | __ Ldrd(r0, r1, frame_->ElementAt(0)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 2506 | __ cmp(r0, r1); // compare to the array length |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2507 | node->break_target()->Branch(hs); |
| 2508 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2509 | // Get the i'th entry of the array. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2510 | __ ldr(r2, frame_->ElementAt(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2511 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 2512 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 2513 | |
| 2514 | // Get Map or 0. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2515 | __ ldr(r2, frame_->ElementAt(3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2516 | // Check if this (still) matches the map of the enumerable. |
| 2517 | // If not, we have to filter the key. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2518 | __ ldr(r1, frame_->ElementAt(4)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2519 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2520 | __ cmp(r1, Operand(r2)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2521 | end_del_check.Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2522 | |
| 2523 | // 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] | 2524 | __ ldr(r0, frame_->ElementAt(4)); // push enumerable |
| 2525 | frame_->EmitPush(r0); |
| 2526 | frame_->EmitPush(r3); // push entry |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 2527 | frame_->InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS, 2); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2528 | __ mov(r3, Operand(r0), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2529 | // 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] | 2530 | node->continue_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2531 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2532 | end_del_check.Bind(); |
| 2533 | // Store the entry in the 'each' expression and take another spin in the |
| 2534 | // loop. r3: i'th entry of the enum cache (or string there of) |
| 2535 | frame_->EmitPush(r3); // push entry |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2536 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2537 | Reference each(this, node->each()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2538 | if (!each.is_illegal()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2539 | if (each.size() > 0) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2540 | // Loading a reference may leave the frame in an unspilled state. |
| 2541 | frame_->SpillAll(); // Sync stack to memory. |
| 2542 | // Get the value (under the reference on the stack) from memory. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2543 | __ ldr(r0, frame_->ElementAt(each.size())); |
| 2544 | frame_->EmitPush(r0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2545 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2546 | 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] | 2547 | } else { |
| 2548 | // 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] | 2549 | // 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] | 2550 | // right on top of or right underneath a zero-sized reference. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2551 | each.SetValue(NOT_CONST_INIT, UNLIKELY_SMI); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2552 | frame_->Drop(1); // Drop the result of the set operation. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2553 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2554 | } |
| 2555 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2556 | // Body. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2557 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2558 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2559 | Visit(node->body()); |
| 2560 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2561 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2562 | // Next. Reestablish a spilled frame in case we are coming here via |
| 2563 | // a continue in the body. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2564 | node->continue_target()->Bind(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2565 | frame_->SpillAll(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2566 | frame_->EmitPop(r0); |
| 2567 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 2568 | frame_->EmitPush(r0); |
| 2569 | entry.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2570 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2571 | // Cleanup. No need to spill because VirtualFrame::Drop is safe for |
| 2572 | // any frame. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2573 | node->break_target()->Bind(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2574 | frame_->Drop(5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2575 | |
| 2576 | // Exit. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2577 | exit.Bind(); |
| 2578 | node->continue_target()->Unuse(); |
| 2579 | node->break_target()->Unuse(); |
| 2580 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2581 | } |
| 2582 | |
| 2583 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2584 | void CodeGenerator::VisitTryCatchStatement(TryCatchStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2585 | #ifdef DEBUG |
| 2586 | int original_height = frame_->height(); |
| 2587 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2588 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2589 | Comment cmnt(masm_, "[ TryCatchStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2590 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2591 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2592 | JumpTarget try_block; |
| 2593 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2594 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2595 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2596 | // --- Catch block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2597 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2598 | |
| 2599 | // Store the caught exception in the catch variable. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2600 | Variable* catch_var = node->catch_var()->var(); |
| 2601 | ASSERT(catch_var != NULL && catch_var->slot() != NULL); |
| 2602 | StoreToSlot(catch_var->slot(), NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2603 | |
| 2604 | // Remove the exception from the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2605 | frame_->Drop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2606 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2607 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2608 | VisitStatements(node->catch_block()->statements()); |
| 2609 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2610 | if (frame_ != NULL) { |
| 2611 | exit.Jump(); |
| 2612 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2613 | |
| 2614 | |
| 2615 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2616 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2617 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2618 | frame_->PushTryHandler(TRY_CATCH_HANDLER); |
| 2619 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2620 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2621 | // Shadow the labels for all escapes from the try block, including |
| 2622 | // returns. During shadowing, the original label is hidden as the |
| 2623 | // LabelShadow and operations on the original actually affect the |
| 2624 | // shadowing label. |
| 2625 | // |
| 2626 | // We should probably try to unify the escaping labels and the return |
| 2627 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2628 | int nof_escapes = node->escaping_targets()->length(); |
| 2629 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2630 | |
| 2631 | // Add the shadow target for the function return. |
| 2632 | static const int kReturnShadowIndex = 0; |
| 2633 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2634 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2635 | function_return_is_shadowed_ = true; |
| 2636 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2637 | |
| 2638 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2639 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2640 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2644 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2645 | VisitStatements(node->try_block()->statements()); |
| 2646 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2647 | |
| 2648 | // Stop the introduced shadowing and count the number of required unlinks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2649 | // After shadowing stops, the original labels are unshadowed and the |
| 2650 | // LabelShadows represent the formerly shadowing labels. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2651 | bool has_unlinks = false; |
| 2652 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2653 | shadows[i]->StopShadowing(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2654 | has_unlinks = has_unlinks || shadows[i]->is_linked(); |
| 2655 | } |
| 2656 | function_return_is_shadowed_ = function_return_was_shadowed; |
| 2657 | |
| 2658 | // Get an external reference to the handler address. |
| 2659 | ExternalReference handler_address(Top::k_handler_address); |
| 2660 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2661 | // If we can fall off the end of the try block, unlink from try chain. |
| 2662 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2663 | // The next handler address is on top of the frame. Unlink from |
| 2664 | // the handler list and drop the rest of this handler from the |
| 2665 | // frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2666 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2667 | frame_->EmitPop(r1); // r0 can contain the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2668 | __ mov(r3, Operand(handler_address)); |
| 2669 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2670 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2671 | if (has_unlinks) { |
| 2672 | exit.Jump(); |
| 2673 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2676 | // Generate unlink code for the (formerly) shadowing labels that have been |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2677 | // jumped to. Deallocate each shadow target. |
| 2678 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2679 | if (shadows[i]->is_linked()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2680 | // Unlink from try chain; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2681 | shadows[i]->Bind(); |
| 2682 | // Because we can be jumping here (to spilled code) from unspilled |
| 2683 | // code, we need to reestablish a spilled frame at this block. |
| 2684 | frame_->SpillAll(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2685 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2686 | // Reload sp from the top handler, because some statements that we |
| 2687 | // 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] | 2688 | __ mov(r3, Operand(handler_address)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2689 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2690 | frame_->Forget(frame_->height() - handler_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2691 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2692 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2693 | frame_->EmitPop(r1); // r0 can contain the return value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2694 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2695 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2696 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2697 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
| 2698 | frame_->PrepareForReturn(); |
| 2699 | } |
| 2700 | shadows[i]->other_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2701 | } |
| 2702 | } |
| 2703 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2704 | exit.Bind(); |
| 2705 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2709 | void CodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2710 | #ifdef DEBUG |
| 2711 | int original_height = frame_->height(); |
| 2712 | #endif |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 2713 | VirtualFrame::SpilledScope spilled_scope(frame_); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2714 | Comment cmnt(masm_, "[ TryFinallyStatement"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2715 | CodeForStatementPosition(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2716 | |
| 2717 | // State: Used to keep track of reason for entering the finally |
| 2718 | // block. Should probably be extended to hold information for |
| 2719 | // break/continue from within the try block. |
| 2720 | enum { FALLING, THROWING, JUMPING }; |
| 2721 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2722 | JumpTarget try_block; |
| 2723 | JumpTarget finally_block; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2724 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2725 | try_block.Call(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2726 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2727 | frame_->EmitPush(r0); // save exception object on the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2728 | // In case of thrown exceptions, this is where we continue. |
| 2729 | __ mov(r2, Operand(Smi::FromInt(THROWING))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2730 | finally_block.Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2731 | |
| 2732 | // --- Try block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2733 | try_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2734 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2735 | frame_->PushTryHandler(TRY_FINALLY_HANDLER); |
| 2736 | int handler_height = frame_->height(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2737 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2738 | // Shadow the labels for all escapes from the try block, including |
| 2739 | // returns. Shadowing hides the original label as the LabelShadow and |
| 2740 | // operations on the original actually affect the shadowing label. |
| 2741 | // |
| 2742 | // We should probably try to unify the escaping labels and the return |
| 2743 | // label. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2744 | int nof_escapes = node->escaping_targets()->length(); |
| 2745 | List<ShadowTarget*> shadows(1 + nof_escapes); |
| 2746 | |
| 2747 | // Add the shadow target for the function return. |
| 2748 | static const int kReturnShadowIndex = 0; |
| 2749 | shadows.Add(new ShadowTarget(&function_return_)); |
| 2750 | bool function_return_was_shadowed = function_return_is_shadowed_; |
| 2751 | function_return_is_shadowed_ = true; |
| 2752 | ASSERT(shadows[kReturnShadowIndex]->other_target() == &function_return_); |
| 2753 | |
| 2754 | // Add the remaining shadow targets. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2755 | for (int i = 0; i < nof_escapes; i++) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2756 | shadows.Add(new ShadowTarget(node->escaping_targets()->at(i))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | // Generate code for the statements in the try block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2760 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2761 | VisitStatements(node->try_block()->statements()); |
| 2762 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2763 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2764 | // Stop the introduced shadowing and count the number of required unlinks. |
| 2765 | // After shadowing stops, the original labels are unshadowed and the |
| 2766 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2767 | int nof_unlinks = 0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2768 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2769 | shadows[i]->StopShadowing(); |
| 2770 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 2771 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2772 | function_return_is_shadowed_ = function_return_was_shadowed; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2773 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2774 | // Get an external reference to the handler address. |
| 2775 | ExternalReference handler_address(Top::k_handler_address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2776 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2777 | // If we can fall off the end of the try block, unlink from the try |
| 2778 | // chain and set the state on the frame to FALLING. |
| 2779 | if (has_valid_frame()) { |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2780 | // The next handler address is on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2781 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2782 | frame_->EmitPop(r1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2783 | __ mov(r3, Operand(handler_address)); |
| 2784 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2785 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2786 | |
| 2787 | // Fake a top of stack value (unneeded when FALLING) and set the |
| 2788 | // state in r2, then jump around the unlink blocks if any. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2789 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2790 | frame_->EmitPush(r0); |
| 2791 | __ mov(r2, Operand(Smi::FromInt(FALLING))); |
| 2792 | if (nof_unlinks > 0) { |
| 2793 | finally_block.Jump(); |
| 2794 | } |
| 2795 | } |
| 2796 | |
| 2797 | // Generate code to unlink and set the state for the (formerly) |
| 2798 | // shadowing targets that have been jumped to. |
| 2799 | for (int i = 0; i < shadows.length(); i++) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2800 | if (shadows[i]->is_linked()) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2801 | // If we have come from the shadowed return, the return value is |
| 2802 | // in (a non-refcounted reference to) r0. We must preserve it |
| 2803 | // until it is pushed. |
| 2804 | // |
| 2805 | // Because we can be jumping here (to spilled code) from |
| 2806 | // unspilled code, we need to reestablish a spilled frame at |
| 2807 | // this block. |
| 2808 | shadows[i]->Bind(); |
| 2809 | frame_->SpillAll(); |
| 2810 | |
| 2811 | // Reload sp from the top handler, because some statements that |
| 2812 | // we break from (eg, for...in) may have left stuff on the |
| 2813 | // stack. |
| 2814 | __ mov(r3, Operand(handler_address)); |
| 2815 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2816 | frame_->Forget(frame_->height() - handler_height); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2817 | |
| 2818 | // Unlink this handler and drop it from the frame. The next |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2819 | // handler address is currently on top of the frame. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 2820 | STATIC_ASSERT(StackHandlerConstants::kNextOffset == 0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2821 | frame_->EmitPop(r1); |
| 2822 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 2823 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2824 | |
| 2825 | if (i == kReturnShadowIndex) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2826 | // If this label shadowed the function return, materialize the |
| 2827 | // return value on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2828 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2829 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2830 | // Fake TOS for targets that shadowed breaks and continues. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 2831 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2832 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | } |
| 2834 | __ mov(r2, Operand(Smi::FromInt(JUMPING + i))); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2835 | if (--nof_unlinks > 0) { |
| 2836 | // If this is not the last unlink block, jump around the next. |
| 2837 | finally_block.Jump(); |
| 2838 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2839 | } |
| 2840 | } |
| 2841 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2842 | // --- Finally block --- |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2843 | finally_block.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2844 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2845 | // Push the state on the stack. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2846 | frame_->EmitPush(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2847 | |
| 2848 | // We keep two elements on the stack - the (possibly faked) result |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2849 | // and the state - while evaluating the finally block. |
| 2850 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2851 | // Generate code for the statements in the finally block. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2852 | { VirtualFrame::RegisterAllocationScope scope(this); |
| 2853 | VisitStatements(node->finally_block()->statements()); |
| 2854 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2855 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2856 | if (has_valid_frame()) { |
| 2857 | // Restore state and return value or faked TOS. |
| 2858 | frame_->EmitPop(r2); |
| 2859 | frame_->EmitPop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2862 | // Generate code to jump to the right destination for all used |
| 2863 | // formerly shadowing targets. Deallocate each shadow target. |
| 2864 | for (int i = 0; i < shadows.length(); i++) { |
| 2865 | if (has_valid_frame() && shadows[i]->is_bound()) { |
| 2866 | JumpTarget* original = shadows[i]->other_target(); |
| 2867 | __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); |
| 2868 | if (!function_return_is_shadowed_ && i == kReturnShadowIndex) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2869 | JumpTarget skip; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2870 | skip.Branch(ne); |
| 2871 | frame_->PrepareForReturn(); |
| 2872 | original->Jump(); |
| 2873 | skip.Bind(); |
| 2874 | } else { |
| 2875 | original->Branch(eq); |
| 2876 | } |
| 2877 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2878 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2879 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2880 | if (has_valid_frame()) { |
| 2881 | // Check if we need to rethrow the exception. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2882 | JumpTarget exit; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2883 | __ cmp(r2, Operand(Smi::FromInt(THROWING))); |
| 2884 | exit.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2885 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2886 | // Rethrow exception. |
| 2887 | frame_->EmitPush(r0); |
| 2888 | frame_->CallRuntime(Runtime::kReThrow, 1); |
| 2889 | |
| 2890 | // Done. |
| 2891 | exit.Bind(); |
| 2892 | } |
| 2893 | ASSERT(!has_valid_frame() || frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2897 | void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2898 | #ifdef DEBUG |
| 2899 | int original_height = frame_->height(); |
| 2900 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2901 | Comment cmnt(masm_, "[ DebuggerStatament"); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2902 | CodeForStatementPosition(node); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2903 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 2904 | frame_->DebugBreak(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2905 | #endif |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2906 | // Ignore the return value. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2907 | ASSERT(frame_->height() == original_height); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2908 | } |
| 2909 | |
| 2910 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2911 | void CodeGenerator::InstantiateFunction( |
| 2912 | Handle<SharedFunctionInfo> function_info) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2913 | // Use the fast case closure allocation code that allocates in new |
| 2914 | // space for nested functions that don't need literals cloning. |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2915 | if (scope()->is_function_scope() && function_info->num_literals() == 0) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2916 | FastNewClosureStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2917 | frame_->EmitPush(Operand(function_info)); |
| 2918 | frame_->SpillAll(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2919 | frame_->CallStub(&stub, 1); |
| 2920 | frame_->EmitPush(r0); |
| 2921 | } else { |
| 2922 | // Create a new closure. |
| 2923 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2924 | frame_->EmitPush(Operand(function_info)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2925 | frame_->CallRuntime(Runtime::kNewClosure, 2); |
| 2926 | frame_->EmitPush(r0); |
| 2927 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2931 | void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2932 | #ifdef DEBUG |
| 2933 | int original_height = frame_->height(); |
| 2934 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2935 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 2936 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2937 | // Build the function info and instantiate it. |
| 2938 | Handle<SharedFunctionInfo> function_info = |
| 2939 | Compiler::BuildFunctionInfo(node, script(), this); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 2940 | // Check for stack-overflow exception. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2941 | if (HasStackOverflow()) { |
| 2942 | ASSERT(frame_->height() == original_height); |
| 2943 | return; |
| 2944 | } |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2945 | InstantiateFunction(function_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2946 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2950 | void CodeGenerator::VisitSharedFunctionInfoLiteral( |
| 2951 | SharedFunctionInfoLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2952 | #ifdef DEBUG |
| 2953 | int original_height = frame_->height(); |
| 2954 | #endif |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 2955 | Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
| 2956 | InstantiateFunction(node->shared_function_info()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2957 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2961 | void CodeGenerator::VisitConditional(Conditional* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2962 | #ifdef DEBUG |
| 2963 | int original_height = frame_->height(); |
| 2964 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2965 | Comment cmnt(masm_, "[ Conditional"); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2966 | JumpTarget then; |
| 2967 | JumpTarget else_; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2968 | LoadCondition(node->condition(), &then, &else_, true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2969 | if (has_valid_frame()) { |
| 2970 | Branch(false, &else_); |
| 2971 | } |
| 2972 | if (has_valid_frame() || then.is_linked()) { |
| 2973 | then.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2974 | Load(node->then_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2975 | } |
| 2976 | if (else_.is_linked()) { |
| 2977 | JumpTarget exit; |
| 2978 | if (has_valid_frame()) exit.Jump(); |
| 2979 | else_.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2980 | Load(node->else_expression()); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 2981 | if (exit.is_linked()) exit.Bind(); |
| 2982 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2983 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2987 | void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) { |
| 2988 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2989 | ASSERT(slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2990 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 2991 | // JumpTargets do not yet support merging frames so the frame must be |
| 2992 | // spilled when jumping to these targets. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2993 | JumpTarget slow; |
| 2994 | JumpTarget done; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 2995 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 2996 | // Generate fast case for loading from slots that correspond to |
| 2997 | // local/global variables or arguments unless they are shadowed by |
| 2998 | // eval-introduced bindings. |
| 2999 | EmitDynamicLoadFromSlotFastCase(slot, |
| 3000 | typeof_state, |
| 3001 | &slow, |
| 3002 | &done); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3003 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3004 | slow.Bind(); |
| 3005 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3006 | frame_->EmitPush(Operand(slot->var()->name())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3007 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3008 | if (typeof_state == INSIDE_TYPEOF) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3009 | frame_->CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3010 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3011 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3012 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3013 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3014 | done.Bind(); |
| 3015 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3016 | |
| 3017 | } else { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3018 | Register scratch = VirtualFrame::scratch0(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3019 | TypeInfo info = type_info(slot); |
| 3020 | frame_->EmitPush(SlotOperand(slot, scratch), info); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3021 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3022 | if (slot->var()->mode() == Variable::CONST) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3023 | // Const slots may contain 'the hole' value (the constant hasn't been |
| 3024 | // initialized yet) which needs to be converted into the 'undefined' |
| 3025 | // value. |
| 3026 | Comment cmnt(masm_, "[ Unhole const"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3027 | Register tos = frame_->PopToRegister(); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3028 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3029 | __ cmp(tos, ip); |
| 3030 | __ LoadRoot(tos, Heap::kUndefinedValueRootIndex, eq); |
| 3031 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | } |
| 3035 | |
| 3036 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3037 | void CodeGenerator::LoadFromSlotCheckForArguments(Slot* slot, |
| 3038 | TypeofState state) { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3039 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3040 | LoadFromSlot(slot, state); |
| 3041 | |
| 3042 | // Bail out quickly if we're not using lazy arguments allocation. |
| 3043 | if (ArgumentsMode() != LAZY_ARGUMENTS_ALLOCATION) return; |
| 3044 | |
| 3045 | // ... or if the slot isn't a non-parameter arguments slot. |
| 3046 | if (slot->type() == Slot::PARAMETER || !slot->is_arguments()) return; |
| 3047 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3048 | // 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] | 3049 | // stack. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3050 | Register tos = frame_->Peek(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3051 | |
| 3052 | // If the loaded value is the sentinel that indicates that we |
| 3053 | // haven't loaded the arguments object yet, we need to do it now. |
| 3054 | JumpTarget exit; |
| 3055 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3056 | __ cmp(tos, ip); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3057 | exit.Branch(ne); |
| 3058 | frame_->Drop(); |
| 3059 | StoreArgumentsObject(false); |
| 3060 | exit.Bind(); |
| 3061 | } |
| 3062 | |
| 3063 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3064 | void CodeGenerator::StoreToSlot(Slot* slot, InitState init_state) { |
| 3065 | ASSERT(slot != NULL); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3066 | VirtualFrame::RegisterAllocationScope scope(this); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3067 | if (slot->type() == Slot::LOOKUP) { |
| 3068 | ASSERT(slot->var()->is_dynamic()); |
| 3069 | |
| 3070 | // For now, just do a runtime call. |
| 3071 | frame_->EmitPush(cp); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3072 | frame_->EmitPush(Operand(slot->var()->name())); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3073 | |
| 3074 | if (init_state == CONST_INIT) { |
| 3075 | // Same as the case for a normal store, but ignores attribute |
| 3076 | // (e.g. READ_ONLY) of context slot so that we can initialize |
| 3077 | // const properties (introduced via eval("const foo = (some |
| 3078 | // expr);")). Also, uses the current function context instead of |
| 3079 | // the top context. |
| 3080 | // |
| 3081 | // Note that we must declare the foo upon entry of eval(), via a |
| 3082 | // context slot declaration, but we cannot initialize it at the |
| 3083 | // same time, because the const declaration may be at the end of |
| 3084 | // the eval code (sigh...) and the const variable may have been |
| 3085 | // used before (where its value is 'undefined'). Thus, we can only |
| 3086 | // do the initialization when we actually encounter the expression |
| 3087 | // and when the expression operands are defined and valid, and |
| 3088 | // thus we need the split into 2 operations: declaration of the |
| 3089 | // context slot followed by initialization. |
| 3090 | frame_->CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 3091 | } else { |
| 3092 | frame_->CallRuntime(Runtime::kStoreContextSlot, 3); |
| 3093 | } |
| 3094 | // Storing a variable must keep the (new) value on the expression |
| 3095 | // stack. This is necessary for compiling assignment expressions. |
| 3096 | frame_->EmitPush(r0); |
| 3097 | |
| 3098 | } else { |
| 3099 | ASSERT(!slot->var()->is_dynamic()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3100 | Register scratch = VirtualFrame::scratch0(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3101 | Register scratch2 = VirtualFrame::scratch1(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3102 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3103 | // The frame must be spilled when branching to this target. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3104 | JumpTarget exit; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3105 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3106 | if (init_state == CONST_INIT) { |
| 3107 | ASSERT(slot->var()->mode() == Variable::CONST); |
| 3108 | // Only the first const initialization must be executed (the slot |
| 3109 | // still contains 'the hole' value). When the assignment is |
| 3110 | // executed, the code is identical to a normal store (see below). |
| 3111 | Comment cmnt(masm_, "[ Init const"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3112 | __ ldr(scratch, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3113 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3114 | __ cmp(scratch, ip); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3115 | exit.Branch(ne); |
| 3116 | } |
| 3117 | |
| 3118 | // We must execute the store. Storing a variable must keep the |
| 3119 | // (new) value on the stack. This is necessary for compiling |
| 3120 | // assignment expressions. |
| 3121 | // |
| 3122 | // Note: We will reach here even with slot->var()->mode() == |
| 3123 | // Variable::CONST because of const declarations which will |
| 3124 | // initialize consts to 'the hole' value and by doing so, end up |
| 3125 | // calling this code. r2 may be loaded with context; used below in |
| 3126 | // RecordWrite. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3127 | Register tos = frame_->Peek(); |
| 3128 | __ str(tos, SlotOperand(slot, scratch)); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3129 | if (slot->type() == Slot::CONTEXT) { |
| 3130 | // Skip write barrier if the written value is a smi. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3131 | __ tst(tos, Operand(kSmiTagMask)); |
| 3132 | // We don't use tos any more after here. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3133 | exit.Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3134 | // scratch is loaded with context when calling SlotOperand above. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3135 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3136 | // We need an extra register. Until we have a way to do that in the |
| 3137 | // virtual frame we will cheat and ask for a free TOS register. |
| 3138 | Register scratch3 = frame_->GetTOSRegister(); |
| 3139 | __ RecordWrite(scratch, Operand(offset), scratch2, scratch3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3140 | } |
| 3141 | // If we definitely did not jump over the assignment, we do not need |
| 3142 | // to bind the exit label. Doing so can defeat peephole |
| 3143 | // optimization. |
| 3144 | if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) { |
| 3145 | exit.Bind(); |
| 3146 | } |
| 3147 | } |
| 3148 | } |
| 3149 | |
| 3150 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3151 | void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 3152 | TypeofState typeof_state, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3153 | JumpTarget* slow) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3154 | // Check that no extension objects have been created by calls to |
| 3155 | // eval from the current scope to the global scope. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3156 | Register tmp = frame_->scratch0(); |
| 3157 | Register tmp2 = frame_->scratch1(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3158 | Register context = cp; |
| 3159 | Scope* s = scope(); |
| 3160 | while (s != NULL) { |
| 3161 | if (s->num_heap_slots() > 0) { |
| 3162 | if (s->calls_eval()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3163 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3164 | // Check that extension is NULL. |
| 3165 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 3166 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3167 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3168 | } |
| 3169 | // Load next context in chain. |
| 3170 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 3171 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3172 | context = tmp; |
| 3173 | } |
| 3174 | // If no outer scope calls eval, we do not need to check more |
| 3175 | // context extensions. |
| 3176 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 3177 | s = s->outer_scope(); |
| 3178 | } |
| 3179 | |
| 3180 | if (s->is_eval_scope()) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 3181 | frame_->SpillAll(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3182 | Label next, fast; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3183 | __ Move(tmp, context); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3184 | __ bind(&next); |
| 3185 | // Terminate at global context. |
| 3186 | __ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3187 | __ LoadRoot(ip, Heap::kGlobalContextMapRootIndex); |
| 3188 | __ cmp(tmp2, ip); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3189 | __ b(eq, &fast); |
| 3190 | // Check that extension is NULL. |
| 3191 | __ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX)); |
| 3192 | __ tst(tmp2, tmp2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3193 | slow->Branch(ne); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3194 | // Load next context in chain. |
| 3195 | __ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 3196 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 3197 | __ b(&next); |
| 3198 | __ bind(&fast); |
| 3199 | } |
| 3200 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3201 | // Load the global object. |
| 3202 | LoadGlobal(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3203 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3204 | frame_->CallLoadIC(slot->var()->name(), |
| 3205 | typeof_state == INSIDE_TYPEOF |
| 3206 | ? RelocInfo::CODE_TARGET |
| 3207 | : RelocInfo::CODE_TARGET_CONTEXT); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 3208 | } |
| 3209 | |
| 3210 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 3211 | void CodeGenerator::EmitDynamicLoadFromSlotFastCase(Slot* slot, |
| 3212 | TypeofState typeof_state, |
| 3213 | JumpTarget* slow, |
| 3214 | JumpTarget* done) { |
| 3215 | // Generate fast-case code for variables that might be shadowed by |
| 3216 | // eval-introduced variables. Eval is used a lot without |
| 3217 | // introducing variables. In those cases, we do not want to |
| 3218 | // perform a runtime call for all variables in the scope |
| 3219 | // containing the eval. |
| 3220 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3221 | LoadFromGlobalSlotCheckExtensions(slot, typeof_state, slow); |
| 3222 | frame_->SpillAll(); |
| 3223 | done->Jump(); |
| 3224 | |
| 3225 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
| 3226 | frame_->SpillAll(); |
| 3227 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); |
| 3228 | Expression* rewrite = slot->var()->local_if_not_shadowed()->rewrite(); |
| 3229 | if (potential_slot != NULL) { |
| 3230 | // Generate fast case for locals that rewrite to slots. |
| 3231 | __ ldr(r0, |
| 3232 | ContextSlotOperandCheckExtensions(potential_slot, |
| 3233 | r1, |
| 3234 | r2, |
| 3235 | slow)); |
| 3236 | if (potential_slot->var()->mode() == Variable::CONST) { |
| 3237 | __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); |
| 3238 | __ cmp(r0, ip); |
| 3239 | __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 3240 | } |
| 3241 | done->Jump(); |
| 3242 | } else if (rewrite != NULL) { |
| 3243 | // Generate fast case for argument loads. |
| 3244 | Property* property = rewrite->AsProperty(); |
| 3245 | if (property != NULL) { |
| 3246 | VariableProxy* obj_proxy = property->obj()->AsVariableProxy(); |
| 3247 | Literal* key_literal = property->key()->AsLiteral(); |
| 3248 | if (obj_proxy != NULL && |
| 3249 | key_literal != NULL && |
| 3250 | obj_proxy->IsArguments() && |
| 3251 | key_literal->handle()->IsSmi()) { |
| 3252 | // Load arguments object if there are no eval-introduced |
| 3253 | // variables. Then load the argument from the arguments |
| 3254 | // object using keyed load. |
| 3255 | __ ldr(r0, |
| 3256 | ContextSlotOperandCheckExtensions(obj_proxy->var()->slot(), |
| 3257 | r1, |
| 3258 | r2, |
| 3259 | slow)); |
| 3260 | frame_->EmitPush(r0); |
| 3261 | __ mov(r1, Operand(key_literal->handle())); |
| 3262 | frame_->EmitPush(r1); |
| 3263 | EmitKeyedLoad(); |
| 3264 | done->Jump(); |
| 3265 | } |
| 3266 | } |
| 3267 | } |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3272 | void CodeGenerator::VisitSlot(Slot* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3273 | #ifdef DEBUG |
| 3274 | int original_height = frame_->height(); |
| 3275 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3276 | Comment cmnt(masm_, "[ Slot"); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 3277 | LoadFromSlotCheckForArguments(node, NOT_INSIDE_TYPEOF); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3278 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3279 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3280 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3281 | |
| 3282 | void CodeGenerator::VisitVariableProxy(VariableProxy* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3283 | #ifdef DEBUG |
| 3284 | int original_height = frame_->height(); |
| 3285 | #endif |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3286 | Comment cmnt(masm_, "[ VariableProxy"); |
| 3287 | |
| 3288 | Variable* var = node->var(); |
| 3289 | Expression* expr = var->rewrite(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3290 | if (expr != NULL) { |
| 3291 | Visit(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3292 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3293 | ASSERT(var->is_global()); |
| 3294 | Reference ref(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3295 | ref.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3296 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3297 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3301 | void CodeGenerator::VisitLiteral(Literal* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3302 | #ifdef DEBUG |
| 3303 | int original_height = frame_->height(); |
| 3304 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3305 | Comment cmnt(masm_, "[ Literal"); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3306 | Register reg = frame_->GetTOSRegister(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3307 | bool is_smi = node->handle()->IsSmi(); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3308 | __ mov(reg, Operand(node->handle())); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3309 | frame_->EmitPush(reg, is_smi ? TypeInfo::Smi() : TypeInfo::Unknown()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3310 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3314 | void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3315 | #ifdef DEBUG |
| 3316 | int original_height = frame_->height(); |
| 3317 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3318 | Comment cmnt(masm_, "[ RexExp Literal"); |
| 3319 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3320 | Register tmp = VirtualFrame::scratch0(); |
| 3321 | // Free up a TOS register that can be used to push the literal. |
| 3322 | Register literal = frame_->GetTOSRegister(); |
| 3323 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3324 | // Retrieve the literal array and check the allocated entry. |
| 3325 | |
| 3326 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3327 | __ ldr(tmp, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3328 | |
| 3329 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3330 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kLiteralsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3331 | |
| 3332 | // Load the literal at the ast saved index. |
| 3333 | int literal_offset = |
| 3334 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3335 | __ ldr(literal, FieldMemOperand(tmp, literal_offset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3336 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3337 | JumpTarget materialized; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 3338 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3339 | __ cmp(literal, ip); |
| 3340 | // This branch locks the virtual frame at the done label to match the |
| 3341 | // one we have here, where the literal register is not on the stack and |
| 3342 | // nothing is spilled. |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3343 | materialized.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3344 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3345 | // 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] | 3346 | // the literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3347 | // literal array (0) |
| 3348 | frame_->EmitPush(tmp); |
| 3349 | // literal index (1) |
| 3350 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3351 | // RegExp pattern (2) |
| 3352 | frame_->EmitPush(Operand(node->pattern())); |
| 3353 | // RegExp flags (3) |
| 3354 | frame_->EmitPush(Operand(node->flags())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3355 | frame_->CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3356 | __ Move(literal, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3357 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3358 | materialized.Bind(); |
| 3359 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3360 | frame_->EmitPush(literal); |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 3361 | int size = JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; |
| 3362 | frame_->EmitPush(Operand(Smi::FromInt(size))); |
| 3363 | frame_->CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 3364 | // TODO(lrn): Use AllocateInNewSpace macro with fallback to runtime. |
| 3365 | // r0 is newly allocated space. |
| 3366 | |
| 3367 | // Reuse literal variable with (possibly) a new register, still holding |
| 3368 | // the materialized boilerplate. |
| 3369 | literal = frame_->PopToRegister(r0); |
| 3370 | |
| 3371 | __ CopyFields(r0, literal, tmp.bit(), size / kPointerSize); |
| 3372 | |
| 3373 | // Push the clone. |
| 3374 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3375 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3379 | void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3380 | #ifdef DEBUG |
| 3381 | int original_height = frame_->height(); |
| 3382 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3383 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 3384 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3385 | Register literal = frame_->GetTOSRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3386 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3387 | __ ldr(literal, frame_->Function()); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3388 | // Literal array. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3389 | __ ldr(literal, FieldMemOperand(literal, JSFunction::kLiteralsOffset)); |
| 3390 | frame_->EmitPush(literal); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3391 | // Literal index. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3392 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3393 | // Constant properties. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3394 | frame_->EmitPush(Operand(node->constant_properties())); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3395 | // Should the object literal have fast elements? |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3396 | frame_->EmitPush(Operand(Smi::FromInt(node->fast_elements() ? 1 : 0))); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3397 | if (node->depth() > 1) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3398 | frame_->CallRuntime(Runtime::kCreateObjectLiteral, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3399 | } else { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3400 | frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3401 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3402 | frame_->EmitPush(r0); // save the result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3403 | for (int i = 0; i < node->properties()->length(); i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3404 | // At the start of each iteration, the top of stack contains |
| 3405 | // the newly created object literal. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3406 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 3407 | Literal* key = property->key(); |
| 3408 | Expression* value = property->value(); |
| 3409 | switch (property->kind()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3410 | case ObjectLiteral::Property::CONSTANT: |
| 3411 | break; |
| 3412 | case ObjectLiteral::Property::MATERIALIZED_LITERAL: |
| 3413 | if (CompileTimeValue::IsCompileTimeValue(property->value())) break; |
| 3414 | // else fall through |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3415 | case ObjectLiteral::Property::COMPUTED: |
| 3416 | if (key->handle()->IsSymbol()) { |
| 3417 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3418 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3419 | frame_->PopToR0(); |
| 3420 | // Fetch the object literal. |
| 3421 | frame_->SpillAllButCopyTOSToR1(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3422 | __ mov(r2, Operand(key->handle())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3423 | frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); |
| 3424 | break; |
| 3425 | } |
| 3426 | // else fall through |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3427 | case ObjectLiteral::Property::PROTOTYPE: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3428 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3429 | Load(key); |
| 3430 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3431 | frame_->CallRuntime(Runtime::kSetProperty, 3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3432 | break; |
| 3433 | } |
| 3434 | case ObjectLiteral::Property::SETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3435 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3436 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3437 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3438 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3439 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3440 | break; |
| 3441 | } |
| 3442 | case ObjectLiteral::Property::GETTER: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3443 | frame_->Dup(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3444 | Load(key); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3445 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3446 | Load(value); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3447 | frame_->CallRuntime(Runtime::kDefineAccessor, 4); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3448 | break; |
| 3449 | } |
| 3450 | } |
| 3451 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3452 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3456 | void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3457 | #ifdef DEBUG |
| 3458 | int original_height = frame_->height(); |
| 3459 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3460 | Comment cmnt(masm_, "[ ArrayLiteral"); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3461 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3462 | Register tos = frame_->GetTOSRegister(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3463 | // Load the function of this activation. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3464 | __ ldr(tos, frame_->Function()); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3465 | // Load the literals array of the function. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3466 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kLiteralsOffset)); |
| 3467 | frame_->EmitPush(tos); |
| 3468 | frame_->EmitPush(Operand(Smi::FromInt(node->literal_index()))); |
| 3469 | frame_->EmitPush(Operand(node->constant_elements())); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3470 | int length = node->values()->length(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3471 | if (node->constant_elements()->map() == Heap::fixed_cow_array_map()) { |
| 3472 | FastCloneShallowArrayStub stub( |
| 3473 | FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS, length); |
| 3474 | frame_->CallStub(&stub, 3); |
| 3475 | __ IncrementCounter(&Counters::cow_arrays_created_stub, 1, r1, r2); |
| 3476 | } else if (node->depth() > 1) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3477 | frame_->CallRuntime(Runtime::kCreateArrayLiteral, 3); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3478 | } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3479 | frame_->CallRuntime(Runtime::kCreateArrayLiteralShallow, 3); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3480 | } else { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3481 | FastCloneShallowArrayStub stub( |
| 3482 | FastCloneShallowArrayStub::CLONE_ELEMENTS, length); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 3483 | frame_->CallStub(&stub, 3); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3484 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3485 | frame_->EmitPush(r0); // save the result |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3486 | // r0: created object literal |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 3487 | |
| 3488 | // Generate code to set the elements in the array that are not |
| 3489 | // literals. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3490 | for (int i = 0; i < node->values()->length(); i++) { |
| 3491 | Expression* value = node->values()->at(i); |
| 3492 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3493 | // If value is a literal the property value is already set in the |
| 3494 | // boilerplate object. |
| 3495 | if (value->AsLiteral() != NULL) continue; |
| 3496 | // If value is a materialized literal the property value is already set |
| 3497 | // in the boilerplate object if it is simple. |
| 3498 | if (CompileTimeValue::IsCompileTimeValue(value)) continue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3499 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3500 | // The property must be set by generated code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3501 | Load(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3502 | frame_->PopToR0(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3503 | // Fetch the object literal. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3504 | frame_->SpillAllButCopyTOSToR1(); |
| 3505 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3506 | // Get the elements array. |
| 3507 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3508 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3509 | // Write to the indexed properties array. |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3510 | int offset = i * kPointerSize + FixedArray::kHeaderSize; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 3511 | __ str(r0, FieldMemOperand(r1, offset)); |
| 3512 | |
| 3513 | // Update the write barrier for the array address. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 3514 | __ RecordWrite(r1, Operand(offset), r3, r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3515 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3516 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3520 | void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3521 | #ifdef DEBUG |
| 3522 | int original_height = frame_->height(); |
| 3523 | #endif |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3524 | // Call runtime routine to allocate the catch extension object and |
| 3525 | // assign the exception value to the catch variable. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3526 | Comment cmnt(masm_, "[ CatchExtensionObject"); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3527 | Load(node->key()); |
| 3528 | Load(node->value()); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 3529 | frame_->CallRuntime(Runtime::kCreateCatchExtensionObject, 2); |
| 3530 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3531 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3532 | } |
| 3533 | |
| 3534 | |
| 3535 | void CodeGenerator::EmitSlotAssignment(Assignment* node) { |
| 3536 | #ifdef DEBUG |
| 3537 | int original_height = frame_->height(); |
| 3538 | #endif |
| 3539 | Comment cmnt(masm(), "[ Variable Assignment"); |
| 3540 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3541 | ASSERT(var != NULL); |
| 3542 | Slot* slot = var->slot(); |
| 3543 | ASSERT(slot != NULL); |
| 3544 | |
| 3545 | // Evaluate the right-hand side. |
| 3546 | if (node->is_compound()) { |
| 3547 | // For a compound assignment the right-hand side is a binary operation |
| 3548 | // between the current property value and the actual right-hand side. |
| 3549 | LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
| 3550 | |
| 3551 | // Perform the binary operation. |
| 3552 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 3553 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3554 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3555 | SmiOperation(node->binary_op(), |
| 3556 | literal->handle(), |
| 3557 | false, |
| 3558 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3559 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3560 | GenerateInlineSmi inline_smi = |
| 3561 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3562 | if (literal != NULL) { |
| 3563 | ASSERT(!literal->handle()->IsSmi()); |
| 3564 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3565 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3566 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3567 | GenericBinaryOperation(node->binary_op(), |
| 3568 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3569 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3570 | } |
| 3571 | } else { |
| 3572 | Load(node->value()); |
| 3573 | } |
| 3574 | |
| 3575 | // Perform the assignment. |
| 3576 | if (var->mode() != Variable::CONST || node->op() == Token::INIT_CONST) { |
| 3577 | CodeForSourcePosition(node->position()); |
| 3578 | StoreToSlot(slot, |
| 3579 | node->op() == Token::INIT_CONST ? CONST_INIT : NOT_CONST_INIT); |
| 3580 | } |
| 3581 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3582 | } |
| 3583 | |
| 3584 | |
| 3585 | void CodeGenerator::EmitNamedPropertyAssignment(Assignment* node) { |
| 3586 | #ifdef DEBUG |
| 3587 | int original_height = frame_->height(); |
| 3588 | #endif |
| 3589 | Comment cmnt(masm(), "[ Named Property Assignment"); |
| 3590 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3591 | Property* prop = node->target()->AsProperty(); |
| 3592 | ASSERT(var == NULL || (prop == NULL && var->is_global())); |
| 3593 | |
| 3594 | // Initialize name and evaluate the receiver sub-expression if necessary. If |
| 3595 | // the receiver is trivial it is not placed on the stack at this point, but |
| 3596 | // loaded whenever actually needed. |
| 3597 | Handle<String> name; |
| 3598 | bool is_trivial_receiver = false; |
| 3599 | if (var != NULL) { |
| 3600 | name = var->name(); |
| 3601 | } else { |
| 3602 | Literal* lit = prop->key()->AsLiteral(); |
| 3603 | ASSERT_NOT_NULL(lit); |
| 3604 | name = Handle<String>::cast(lit->handle()); |
| 3605 | // Do not materialize the receiver on the frame if it is trivial. |
| 3606 | is_trivial_receiver = prop->obj()->IsTrivial(); |
| 3607 | if (!is_trivial_receiver) Load(prop->obj()); |
| 3608 | } |
| 3609 | |
| 3610 | // Change to slow case in the beginning of an initialization block to |
| 3611 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3612 | if (node->starts_initialization_block()) { |
| 3613 | // Initialization block consists of assignments of the form expr.x = ..., so |
| 3614 | // this will never be an assignment to a variable, so there must be a |
| 3615 | // receiver object. |
| 3616 | ASSERT_EQ(NULL, var); |
| 3617 | if (is_trivial_receiver) { |
| 3618 | Load(prop->obj()); |
| 3619 | } else { |
| 3620 | frame_->Dup(); |
| 3621 | } |
| 3622 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3623 | } |
| 3624 | |
| 3625 | // Change to fast case at the end of an initialization block. To prepare for |
| 3626 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3627 | // converted back to fast case after the assignment. |
| 3628 | if (node->ends_initialization_block() && !is_trivial_receiver) { |
| 3629 | frame_->Dup(); |
| 3630 | } |
| 3631 | |
| 3632 | // Stack layout: |
| 3633 | // [tos] : receiver (only materialized if non-trivial) |
| 3634 | // [tos+1] : receiver if at the end of an initialization block |
| 3635 | |
| 3636 | // Evaluate the right-hand side. |
| 3637 | if (node->is_compound()) { |
| 3638 | // For a compound assignment the right-hand side is a binary operation |
| 3639 | // between the current property value and the actual right-hand side. |
| 3640 | if (is_trivial_receiver) { |
| 3641 | Load(prop->obj()); |
| 3642 | } else if (var != NULL) { |
| 3643 | LoadGlobal(); |
| 3644 | } else { |
| 3645 | frame_->Dup(); |
| 3646 | } |
| 3647 | EmitNamedLoad(name, var != NULL); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3648 | |
| 3649 | // Perform the binary operation. |
| 3650 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 3651 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3652 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3653 | SmiOperation(node->binary_op(), |
| 3654 | literal->handle(), |
| 3655 | false, |
| 3656 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3657 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3658 | GenerateInlineSmi inline_smi = |
| 3659 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3660 | if (literal != NULL) { |
| 3661 | ASSERT(!literal->handle()->IsSmi()); |
| 3662 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3663 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3664 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3665 | GenericBinaryOperation(node->binary_op(), |
| 3666 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3667 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3668 | } |
| 3669 | } else { |
| 3670 | // For non-compound assignment just load the right-hand side. |
| 3671 | Load(node->value()); |
| 3672 | } |
| 3673 | |
| 3674 | // Stack layout: |
| 3675 | // [tos] : value |
| 3676 | // [tos+1] : receiver (only materialized if non-trivial) |
| 3677 | // [tos+2] : receiver if at the end of an initialization block |
| 3678 | |
| 3679 | // Perform the assignment. It is safe to ignore constants here. |
| 3680 | ASSERT(var == NULL || var->mode() != Variable::CONST); |
| 3681 | ASSERT_NE(Token::INIT_CONST, node->op()); |
| 3682 | if (is_trivial_receiver) { |
| 3683 | // Load the receiver and swap with the value. |
| 3684 | Load(prop->obj()); |
| 3685 | Register t0 = frame_->PopToRegister(); |
| 3686 | Register t1 = frame_->PopToRegister(t0); |
| 3687 | frame_->EmitPush(t0); |
| 3688 | frame_->EmitPush(t1); |
| 3689 | } |
| 3690 | CodeForSourcePosition(node->position()); |
| 3691 | bool is_contextual = (var != NULL); |
| 3692 | EmitNamedStore(name, is_contextual); |
| 3693 | frame_->EmitPush(r0); |
| 3694 | |
| 3695 | // Change to fast case at the end of an initialization block. |
| 3696 | if (node->ends_initialization_block()) { |
| 3697 | ASSERT_EQ(NULL, var); |
| 3698 | // The argument to the runtime call is the receiver. |
| 3699 | if (is_trivial_receiver) { |
| 3700 | Load(prop->obj()); |
| 3701 | } else { |
| 3702 | // A copy of the receiver is below the value of the assignment. Swap |
| 3703 | // the receiver and the value of the assignment expression. |
| 3704 | Register t0 = frame_->PopToRegister(); |
| 3705 | Register t1 = frame_->PopToRegister(t0); |
| 3706 | frame_->EmitPush(t0); |
| 3707 | frame_->EmitPush(t1); |
| 3708 | } |
| 3709 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3710 | } |
| 3711 | |
| 3712 | // Stack layout: |
| 3713 | // [tos] : result |
| 3714 | |
| 3715 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 3716 | } |
| 3717 | |
| 3718 | |
| 3719 | void CodeGenerator::EmitKeyedPropertyAssignment(Assignment* node) { |
| 3720 | #ifdef DEBUG |
| 3721 | int original_height = frame_->height(); |
| 3722 | #endif |
| 3723 | Comment cmnt(masm_, "[ Keyed Property Assignment"); |
| 3724 | Property* prop = node->target()->AsProperty(); |
| 3725 | ASSERT_NOT_NULL(prop); |
| 3726 | |
| 3727 | // Evaluate the receiver subexpression. |
| 3728 | Load(prop->obj()); |
| 3729 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3730 | WriteBarrierCharacter wb_info; |
| 3731 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3732 | // Change to slow case in the beginning of an initialization block to |
| 3733 | // avoid the quadratic behavior of repeatedly adding fast properties. |
| 3734 | if (node->starts_initialization_block()) { |
| 3735 | frame_->Dup(); |
| 3736 | frame_->CallRuntime(Runtime::kToSlowProperties, 1); |
| 3737 | } |
| 3738 | |
| 3739 | // Change to fast case at the end of an initialization block. To prepare for |
| 3740 | // that add an extra copy of the receiver to the frame, so that it can be |
| 3741 | // converted back to fast case after the assignment. |
| 3742 | if (node->ends_initialization_block()) { |
| 3743 | frame_->Dup(); |
| 3744 | } |
| 3745 | |
| 3746 | // Evaluate the key subexpression. |
| 3747 | Load(prop->key()); |
| 3748 | |
| 3749 | // Stack layout: |
| 3750 | // [tos] : key |
| 3751 | // [tos+1] : receiver |
| 3752 | // [tos+2] : receiver if at the end of an initialization block |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3753 | // |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3754 | // Evaluate the right-hand side. |
| 3755 | if (node->is_compound()) { |
| 3756 | // For a compound assignment the right-hand side is a binary operation |
| 3757 | // between the current property value and the actual right-hand side. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3758 | // Duplicate receiver and key for loading the current property value. |
| 3759 | frame_->Dup2(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3760 | EmitKeyedLoad(); |
| 3761 | frame_->EmitPush(r0); |
| 3762 | |
| 3763 | // Perform the binary operation. |
| 3764 | Literal* literal = node->value()->AsLiteral(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 3765 | bool overwrite_value = node->value()->ResultOverwriteAllowed(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3766 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 3767 | SmiOperation(node->binary_op(), |
| 3768 | literal->handle(), |
| 3769 | false, |
| 3770 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE); |
| 3771 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3772 | GenerateInlineSmi inline_smi = |
| 3773 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 3774 | if (literal != NULL) { |
| 3775 | ASSERT(!literal->handle()->IsSmi()); |
| 3776 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 3777 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3778 | Load(node->value()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3779 | GenericBinaryOperation(node->binary_op(), |
| 3780 | overwrite_value ? OVERWRITE_RIGHT : NO_OVERWRITE, |
| 3781 | inline_smi); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3782 | } |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3783 | wb_info = node->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3784 | } else { |
| 3785 | // For non-compound assignment just load the right-hand side. |
| 3786 | Load(node->value()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3787 | wb_info = node->value()->AsLiteral() != NULL ? |
| 3788 | NEVER_NEWSPACE : |
| 3789 | (node->value()->type()->IsLikelySmi() ? LIKELY_SMI : UNLIKELY_SMI); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | // Stack layout: |
| 3793 | // [tos] : value |
| 3794 | // [tos+1] : key |
| 3795 | // [tos+2] : receiver |
| 3796 | // [tos+3] : receiver if at the end of an initialization block |
| 3797 | |
| 3798 | // Perform the assignment. It is safe to ignore constants here. |
| 3799 | ASSERT(node->op() != Token::INIT_CONST); |
| 3800 | CodeForSourcePosition(node->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3801 | EmitKeyedStore(prop->key()->type(), wb_info); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3802 | frame_->EmitPush(r0); |
| 3803 | |
| 3804 | // Stack layout: |
| 3805 | // [tos] : result |
| 3806 | // [tos+1] : receiver if at the end of an initialization block |
| 3807 | |
| 3808 | // Change to fast case at the end of an initialization block. |
| 3809 | if (node->ends_initialization_block()) { |
| 3810 | // The argument to the runtime call is the extra copy of the receiver, |
| 3811 | // which is below the value of the assignment. Swap the receiver and |
| 3812 | // the value of the assignment expression. |
| 3813 | Register t0 = frame_->PopToRegister(); |
| 3814 | Register t1 = frame_->PopToRegister(t0); |
| 3815 | frame_->EmitPush(t1); |
| 3816 | frame_->EmitPush(t0); |
| 3817 | frame_->CallRuntime(Runtime::kToFastProperties, 1); |
| 3818 | } |
| 3819 | |
| 3820 | // Stack layout: |
| 3821 | // [tos] : result |
| 3822 | |
| 3823 | ASSERT_EQ(original_height + 1, frame_->height()); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3827 | void CodeGenerator::VisitAssignment(Assignment* node) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3828 | VirtualFrame::RegisterAllocationScope scope(this); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3829 | #ifdef DEBUG |
| 3830 | int original_height = frame_->height(); |
| 3831 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3832 | Comment cmnt(masm_, "[ Assignment"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3833 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3834 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 3835 | Property* prop = node->target()->AsProperty(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3836 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3837 | if (var != NULL && !var->is_global()) { |
| 3838 | EmitSlotAssignment(node); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3839 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3840 | } else if ((prop != NULL && prop->key()->IsPropertyName()) || |
| 3841 | (var != NULL && var->is_global())) { |
| 3842 | // Properties whose keys are property names and global variables are |
| 3843 | // treated as named property references. We do not need to consider |
| 3844 | // global 'this' because it is not a valid left-hand side. |
| 3845 | EmitNamedPropertyAssignment(node); |
| 3846 | |
| 3847 | } else if (prop != NULL) { |
| 3848 | // Other properties (including rewritten parameters for a function that |
| 3849 | // uses arguments) are keyed property assignments. |
| 3850 | EmitKeyedPropertyAssignment(node); |
| 3851 | |
| 3852 | } else { |
| 3853 | // Invalid left-hand side. |
| 3854 | Load(node->target()); |
| 3855 | frame_->CallRuntime(Runtime::kThrowReferenceError, 1); |
| 3856 | // The runtime call doesn't actually return but the code generator will |
| 3857 | // still generate code and expects a certain frame height. |
| 3858 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3859 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3860 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3864 | void CodeGenerator::VisitThrow(Throw* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3865 | #ifdef DEBUG |
| 3866 | int original_height = frame_->height(); |
| 3867 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3868 | Comment cmnt(masm_, "[ Throw"); |
| 3869 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3870 | Load(node->exception()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3871 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3872 | frame_->CallRuntime(Runtime::kThrow, 1); |
| 3873 | frame_->EmitPush(r0); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3874 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3878 | void CodeGenerator::VisitProperty(Property* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3879 | #ifdef DEBUG |
| 3880 | int original_height = frame_->height(); |
| 3881 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3882 | Comment cmnt(masm_, "[ Property"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3883 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3884 | { Reference property(this, node); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 3885 | property.GetValue(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3886 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3887 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3888 | } |
| 3889 | |
| 3890 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3891 | void CodeGenerator::VisitCall(Call* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3892 | #ifdef DEBUG |
| 3893 | int original_height = frame_->height(); |
| 3894 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3895 | Comment cmnt(masm_, "[ Call"); |
| 3896 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3897 | Expression* function = node->expression(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3898 | ZoneList<Expression*>* args = node->arguments(); |
| 3899 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3900 | // Standard function call. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3901 | // Check if the function is a variable or a property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3902 | Variable* var = function->AsVariableProxy()->AsVariable(); |
| 3903 | Property* property = function->AsProperty(); |
| 3904 | |
| 3905 | // ------------------------------------------------------------------------ |
| 3906 | // Fast-case: Use inline caching. |
| 3907 | // --- |
| 3908 | // According to ECMA-262, section 11.2.3, page 44, the function to call |
| 3909 | // must be resolved after the arguments have been evaluated. The IC code |
| 3910 | // automatically handles this by loading the arguments before the function |
| 3911 | // is resolved in cache misses (this also holds for megamorphic calls). |
| 3912 | // ------------------------------------------------------------------------ |
| 3913 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3914 | if (var != NULL && var->is_possibly_eval()) { |
| 3915 | // ---------------------------------- |
| 3916 | // JavaScript example: 'eval(arg)' // eval is not known to be shadowed |
| 3917 | // ---------------------------------- |
| 3918 | |
| 3919 | // In a call to eval, we first call %ResolvePossiblyDirectEval to |
| 3920 | // resolve the function we need to call and the receiver of the |
| 3921 | // call. Then we call the resolved function using the given |
| 3922 | // arguments. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3923 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3924 | // Prepare stack for call to resolved function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3925 | Load(function); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3926 | |
| 3927 | // Allocate a frame slot for the receiver. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3928 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3929 | |
| 3930 | // Load the arguments. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3931 | int arg_count = args->length(); |
| 3932 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3933 | Load(args->at(i)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3936 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 3937 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3938 | // If we know that eval can only be shadowed by eval-introduced |
| 3939 | // variables we attempt to load the global eval function directly |
| 3940 | // in generated code. If we succeed, there is no need to perform a |
| 3941 | // context lookup in the runtime system. |
| 3942 | JumpTarget done; |
| 3943 | if (var->slot() != NULL && var->mode() == Variable::DYNAMIC_GLOBAL) { |
| 3944 | ASSERT(var->slot()->type() == Slot::LOOKUP); |
| 3945 | JumpTarget slow; |
| 3946 | // Prepare the stack for the call to |
| 3947 | // ResolvePossiblyDirectEvalNoLookup by pushing the loaded |
| 3948 | // function, the first argument to the eval call and the |
| 3949 | // receiver. |
| 3950 | LoadFromGlobalSlotCheckExtensions(var->slot(), |
| 3951 | NOT_INSIDE_TYPEOF, |
| 3952 | &slow); |
| 3953 | frame_->EmitPush(r0); |
| 3954 | if (arg_count > 0) { |
| 3955 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3956 | frame_->EmitPush(r1); |
| 3957 | } else { |
| 3958 | frame_->EmitPush(r2); |
| 3959 | } |
| 3960 | __ ldr(r1, frame_->Receiver()); |
| 3961 | frame_->EmitPush(r1); |
| 3962 | |
| 3963 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEvalNoLookup, 3); |
| 3964 | |
| 3965 | done.Jump(); |
| 3966 | slow.Bind(); |
| 3967 | } |
| 3968 | |
| 3969 | // Prepare the stack for the call to ResolvePossiblyDirectEval by |
| 3970 | // pushing the loaded function, the first argument to the eval |
| 3971 | // call and the receiver. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3972 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize + kPointerSize)); |
| 3973 | frame_->EmitPush(r1); |
| 3974 | if (arg_count > 0) { |
| 3975 | __ ldr(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3976 | frame_->EmitPush(r1); |
| 3977 | } else { |
| 3978 | frame_->EmitPush(r2); |
| 3979 | } |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3980 | __ ldr(r1, frame_->Receiver()); |
| 3981 | frame_->EmitPush(r1); |
| 3982 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3983 | // Resolve the call. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3984 | frame_->CallRuntime(Runtime::kResolvePossiblyDirectEval, 3); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3985 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3986 | // If we generated fast-case code bind the jump-target where fast |
| 3987 | // and slow case merge. |
| 3988 | if (done.is_linked()) done.Bind(); |
| 3989 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3990 | // 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] | 3991 | __ str(r0, MemOperand(sp, (arg_count + 1) * kPointerSize)); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3992 | __ str(r1, MemOperand(sp, arg_count * kPointerSize)); |
| 3993 | |
| 3994 | // Call the function. |
| 3995 | CodeForSourcePosition(node->position()); |
| 3996 | |
| 3997 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 3998 | CallFunctionStub call_function(arg_count, in_loop, RECEIVER_MIGHT_BE_VALUE); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 3999 | frame_->CallStub(&call_function, arg_count + 1); |
| 4000 | |
| 4001 | __ ldr(cp, frame_->Context()); |
| 4002 | // Remove the function from the stack. |
| 4003 | frame_->Drop(); |
| 4004 | frame_->EmitPush(r0); |
| 4005 | |
| 4006 | } else if (var != NULL && !var->is_this() && var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4007 | // ---------------------------------- |
| 4008 | // JavaScript example: 'foo(1, 2, 3)' // foo is global |
| 4009 | // ---------------------------------- |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4010 | // Pass the global object as the receiver and let the IC stub |
| 4011 | // patch the stack to use the global proxy as 'this' in the |
| 4012 | // invoked function. |
| 4013 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4014 | |
| 4015 | // Load the arguments. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4016 | int arg_count = args->length(); |
| 4017 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4018 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4019 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4020 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4021 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4022 | // Setup the name register and call the IC initialization code. |
| 4023 | __ mov(r2, Operand(var->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4024 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4025 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4026 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4027 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET_CONTEXT, |
| 4028 | arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4029 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4030 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4031 | |
| 4032 | } else if (var != NULL && var->slot() != NULL && |
| 4033 | var->slot()->type() == Slot::LOOKUP) { |
| 4034 | // ---------------------------------- |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4035 | // JavaScript examples: |
| 4036 | // |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4037 | // with (obj) foo(1, 2, 3) // foo may be in obj. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4038 | // |
| 4039 | // function f() {}; |
| 4040 | // function g() { |
| 4041 | // eval(...); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4042 | // f(); // f could be in extension object. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4043 | // } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4044 | // ---------------------------------- |
| 4045 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4046 | JumpTarget slow, done; |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4047 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4048 | // Generate fast case for loading functions from slots that |
| 4049 | // correspond to local/global variables or arguments unless they |
| 4050 | // are shadowed by eval-introduced bindings. |
| 4051 | EmitDynamicLoadFromSlotFastCase(var->slot(), |
| 4052 | NOT_INSIDE_TYPEOF, |
| 4053 | &slow, |
| 4054 | &done); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4055 | |
| 4056 | slow.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4057 | // Load the function |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4058 | frame_->EmitPush(cp); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4059 | frame_->EmitPush(Operand(var->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4060 | frame_->CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4061 | // r0: slot value; r1: receiver |
| 4062 | |
| 4063 | // Load the receiver. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4064 | frame_->EmitPush(r0); // function |
| 4065 | frame_->EmitPush(r1); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4066 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4067 | // If fast case code has been generated, emit code to push the |
| 4068 | // function and receiver and have the slow path jump around this |
| 4069 | // code. |
| 4070 | if (done.is_linked()) { |
| 4071 | JumpTarget call; |
| 4072 | call.Jump(); |
| 4073 | done.Bind(); |
| 4074 | frame_->EmitPush(r0); // function |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4075 | LoadGlobalReceiver(VirtualFrame::scratch0()); // receiver |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 4076 | call.Bind(); |
| 4077 | } |
| 4078 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4079 | // Call the function. At this point, everything is spilled but the |
| 4080 | // function and receiver are in r0 and r1. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4081 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4082 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4083 | |
| 4084 | } else if (property != NULL) { |
| 4085 | // Check if the key is a literal string. |
| 4086 | Literal* literal = property->key()->AsLiteral(); |
| 4087 | |
| 4088 | if (literal != NULL && literal->handle()->IsSymbol()) { |
| 4089 | // ------------------------------------------------------------------ |
| 4090 | // JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)' |
| 4091 | // ------------------------------------------------------------------ |
| 4092 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4093 | Handle<String> name = Handle<String>::cast(literal->handle()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4094 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4095 | if (ArgumentsMode() == LAZY_ARGUMENTS_ALLOCATION && |
| 4096 | name->IsEqualTo(CStrVector("apply")) && |
| 4097 | args->length() == 2 && |
| 4098 | args->at(1)->AsVariableProxy() != NULL && |
| 4099 | args->at(1)->AsVariableProxy()->IsArguments()) { |
| 4100 | // Use the optimized Function.prototype.apply that avoids |
| 4101 | // allocating lazily allocated arguments objects. |
| 4102 | CallApplyLazy(property->obj(), |
| 4103 | args->at(0), |
| 4104 | args->at(1)->AsVariableProxy(), |
| 4105 | node->position()); |
| 4106 | |
| 4107 | } else { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4108 | Load(property->obj()); // Receiver. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4109 | // Load the arguments. |
| 4110 | int arg_count = args->length(); |
| 4111 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4112 | Load(args->at(i)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4113 | } |
| 4114 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4115 | VirtualFrame::SpilledScope spilled_scope(frame_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 4116 | // Set the name register and call the IC initialization code. |
| 4117 | __ mov(r2, Operand(name)); |
| 4118 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4119 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
| 4120 | CodeForSourcePosition(node->position()); |
| 4121 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4122 | __ ldr(cp, frame_->Context()); |
| 4123 | frame_->EmitPush(r0); |
| 4124 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4125 | |
| 4126 | } else { |
| 4127 | // ------------------------------------------- |
| 4128 | // JavaScript example: 'array[index](1, 2, 3)' |
| 4129 | // ------------------------------------------- |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4130 | Load(property->obj()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4131 | if (property->is_synthetic()) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4132 | Load(property->key()); |
| 4133 | EmitKeyedLoad(); |
| 4134 | // Put the function below the receiver. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4135 | // Use the global receiver. |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4136 | frame_->EmitPush(r0); // Function. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4137 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4138 | // Call the function. |
| 4139 | CallWithArguments(args, RECEIVER_MIGHT_BE_VALUE, node->position()); |
| 4140 | frame_->EmitPush(r0); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4141 | } else { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4142 | // Load the arguments. |
| 4143 | int arg_count = args->length(); |
| 4144 | for (int i = 0; i < arg_count; i++) { |
| 4145 | Load(args->at(i)); |
| 4146 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4147 | |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4148 | // Set the name register and call the IC initialization code. |
| 4149 | Load(property->key()); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4150 | frame_->SpillAll(); |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 4151 | frame_->EmitPop(r2); // Function name. |
| 4152 | |
| 4153 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 4154 | Handle<Code> stub = ComputeKeyedCallInitialize(arg_count, in_loop); |
| 4155 | CodeForSourcePosition(node->position()); |
| 4156 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
| 4157 | __ ldr(cp, frame_->Context()); |
| 4158 | frame_->EmitPush(r0); |
| 4159 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
| 4162 | } else { |
| 4163 | // ---------------------------------- |
| 4164 | // JavaScript example: 'foo(1, 2, 3)' // foo is not global |
| 4165 | // ---------------------------------- |
| 4166 | |
| 4167 | // Load the function. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4168 | Load(function); |
| 4169 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4170 | // Pass the global proxy as the receiver. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4171 | LoadGlobalReceiver(VirtualFrame::scratch0()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4172 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4173 | // Call the function. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4174 | CallWithArguments(args, NO_CALL_FUNCTION_FLAGS, node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4175 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4176 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4177 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4178 | } |
| 4179 | |
| 4180 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4181 | void CodeGenerator::VisitCallNew(CallNew* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4182 | #ifdef DEBUG |
| 4183 | int original_height = frame_->height(); |
| 4184 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4185 | Comment cmnt(masm_, "[ CallNew"); |
| 4186 | |
| 4187 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 4188 | // expression in new calls must be evaluated before the |
| 4189 | // arguments. This is different from ordinary calls, where the |
| 4190 | // actual function to call is resolved after the arguments have been |
| 4191 | // evaluated. |
| 4192 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 4193 | // Push constructor on the stack. If it's not a function it's used as |
| 4194 | // receiver for CALL_NON_FUNCTION, otherwise the value on the stack is |
| 4195 | // ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4196 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4197 | |
| 4198 | // Push the arguments ("left-to-right") on the stack. |
| 4199 | ZoneList<Expression*>* args = node->arguments(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4200 | int arg_count = args->length(); |
| 4201 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4202 | Load(args->at(i)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4203 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4204 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 4205 | // Spill everything from here to simplify the implementation. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4206 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 4207 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 4208 | // Load the argument count into r0 and the function into r1 as per |
| 4209 | // calling convention. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 4210 | __ mov(r0, Operand(arg_count)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 4211 | __ ldr(r1, frame_->ElementAt(arg_count)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4212 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | // Call the construct call builtin that handles allocation and |
| 4214 | // constructor invocation. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4215 | CodeForSourcePosition(node->position()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4216 | Handle<Code> ic(Builtins::builtin(Builtins::JSConstructCall)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4217 | frame_->CallCodeObject(ic, RelocInfo::CONSTRUCT_CALL, arg_count + 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 4218 | frame_->EmitPush(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4219 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4220 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4224 | void CodeGenerator::GenerateClassOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4225 | Register scratch = VirtualFrame::scratch0(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4226 | JumpTarget null, function, leave, non_function_constructor; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4227 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4228 | // Load the object into register. |
| 4229 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4230 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4231 | Register tos = frame_->PopToRegister(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4232 | |
| 4233 | // If the object is a smi, we return null. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4234 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4235 | null.Branch(eq); |
| 4236 | |
| 4237 | // Check that the object is a JS object but take special care of JS |
| 4238 | // functions to make sure they have 'Function' as their class. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4239 | __ CompareObjectType(tos, tos, scratch, FIRST_JS_OBJECT_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4240 | null.Branch(lt); |
| 4241 | |
| 4242 | // As long as JS_FUNCTION_TYPE is the last instance type and it is |
| 4243 | // right after LAST_JS_OBJECT_TYPE, we can avoid checking for |
| 4244 | // LAST_JS_OBJECT_TYPE. |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 4245 | STATIC_ASSERT(LAST_TYPE == JS_FUNCTION_TYPE); |
| 4246 | STATIC_ASSERT(JS_FUNCTION_TYPE == LAST_JS_OBJECT_TYPE + 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4247 | __ cmp(scratch, Operand(JS_FUNCTION_TYPE)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4248 | function.Branch(eq); |
| 4249 | |
| 4250 | // Check if the constructor in the map is a function. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4251 | __ ldr(tos, FieldMemOperand(tos, Map::kConstructorOffset)); |
| 4252 | __ CompareObjectType(tos, scratch, scratch, JS_FUNCTION_TYPE); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4253 | non_function_constructor.Branch(ne); |
| 4254 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4255 | // The tos register now contains the constructor function. Grab the |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4256 | // instance class name from there. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4257 | __ ldr(tos, FieldMemOperand(tos, JSFunction::kSharedFunctionInfoOffset)); |
| 4258 | __ ldr(tos, |
| 4259 | FieldMemOperand(tos, SharedFunctionInfo::kInstanceClassNameOffset)); |
| 4260 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4261 | leave.Jump(); |
| 4262 | |
| 4263 | // Functions have class 'Function'. |
| 4264 | function.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4265 | __ mov(tos, Operand(Factory::function_class_symbol())); |
| 4266 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4267 | leave.Jump(); |
| 4268 | |
| 4269 | // Objects with a non-function constructor have class 'Object'. |
| 4270 | non_function_constructor.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4271 | __ mov(tos, Operand(Factory::Object_symbol())); |
| 4272 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4273 | leave.Jump(); |
| 4274 | |
| 4275 | // Non-JS objects have class null. |
| 4276 | null.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4277 | __ LoadRoot(tos, Heap::kNullValueRootIndex); |
| 4278 | frame_->EmitPush(tos); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4279 | |
| 4280 | // All done. |
| 4281 | leave.Bind(); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4282 | } |
| 4283 | |
| 4284 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4285 | void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4286 | Register scratch = VirtualFrame::scratch0(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4287 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4288 | |
| 4289 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4290 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4291 | Register tos = frame_->PopToRegister(); // tos contains object. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4292 | // if (object->IsSmi()) return the object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4293 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4294 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4295 | // 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] | 4296 | __ CompareObjectType(tos, scratch, scratch, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4297 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4298 | // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4299 | __ ldr(tos, FieldMemOperand(tos, JSValue::kValueOffset)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4300 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4301 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
| 4304 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4305 | void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4306 | Register scratch1 = VirtualFrame::scratch0(); |
| 4307 | Register scratch2 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4308 | JumpTarget leave; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4309 | |
| 4310 | ASSERT(args->length() == 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4311 | Load(args->at(0)); // Load the object. |
| 4312 | Load(args->at(1)); // Load the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4313 | Register value = frame_->PopToRegister(); |
| 4314 | Register object = frame_->PopToRegister(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4315 | // if (object->IsSmi()) return object. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4316 | __ tst(object, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4317 | leave.Branch(eq); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4318 | // 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] | 4319 | __ CompareObjectType(object, scratch1, scratch1, JS_VALUE_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4320 | leave.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4321 | // Store the value. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4322 | __ str(value, FieldMemOperand(object, JSValue::kValueOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4323 | // Update the write barrier. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4324 | __ RecordWrite(object, |
| 4325 | Operand(JSValue::kValueOffset - kHeapObjectTag), |
| 4326 | scratch1, |
| 4327 | scratch2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4328 | // Leave. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4329 | leave.Bind(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4330 | frame_->EmitPush(value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4331 | } |
| 4332 | |
| 4333 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4334 | void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4335 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4336 | Load(args->at(0)); |
| 4337 | Register reg = frame_->PopToRegister(); |
| 4338 | __ tst(reg, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4339 | cc_reg_ = eq; |
| 4340 | } |
| 4341 | |
| 4342 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4343 | void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) { |
| 4344 | // See comment in CodeGenerator::GenerateLog in codegen-ia32.cc. |
| 4345 | ASSERT_EQ(args->length(), 3); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4346 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4347 | if (ShouldGenerateLog(args->at(0))) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4348 | Load(args->at(1)); |
| 4349 | Load(args->at(2)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4350 | frame_->CallRuntime(Runtime::kLog, 2); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4351 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 4352 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4353 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4357 | void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4358 | ASSERT(args->length() == 1); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4359 | Load(args->at(0)); |
| 4360 | Register reg = frame_->PopToRegister(); |
| 4361 | __ tst(reg, Operand(kSmiTagMask | 0x80000000u)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 4362 | cc_reg_ = eq; |
| 4363 | } |
| 4364 | |
| 4365 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4366 | // Generates the Math.pow method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4367 | void CodeGenerator::GenerateMathPow(ZoneList<Expression*>* args) { |
| 4368 | ASSERT(args->length() == 2); |
| 4369 | Load(args->at(0)); |
| 4370 | Load(args->at(1)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4371 | |
| 4372 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4373 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4374 | frame_->EmitPush(r0); |
| 4375 | } else { |
| 4376 | CpuFeatures::Scope scope(VFP3); |
| 4377 | JumpTarget runtime, done; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4378 | Label exponent_nonsmi, base_nonsmi, powi, not_minus_half, allocate_return; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4379 | |
| 4380 | Register scratch1 = VirtualFrame::scratch0(); |
| 4381 | Register scratch2 = VirtualFrame::scratch1(); |
| 4382 | |
| 4383 | // Get base and exponent to registers. |
| 4384 | Register exponent = frame_->PopToRegister(); |
| 4385 | Register base = frame_->PopToRegister(exponent); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4386 | Register heap_number_map = no_reg; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4387 | |
| 4388 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4389 | // jump target label so the frame needs to be established before that. |
| 4390 | ASSERT(runtime.entry_frame() == NULL); |
| 4391 | runtime.set_entry_frame(frame_); |
| 4392 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4393 | __ BranchOnNotSmi(exponent, &exponent_nonsmi); |
| 4394 | __ BranchOnNotSmi(base, &base_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4395 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4396 | heap_number_map = r6; |
| 4397 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4398 | |
| 4399 | // Exponent is a smi and base is a smi. Get the smi value into vfp register |
| 4400 | // d1. |
| 4401 | __ SmiToDoubleVFPRegister(base, d1, scratch1, s0); |
| 4402 | __ b(&powi); |
| 4403 | |
| 4404 | __ bind(&base_nonsmi); |
| 4405 | // Exponent is smi and base is non smi. Get the double value from the base |
| 4406 | // into vfp register d1. |
| 4407 | __ ObjectToDoubleVFPRegister(base, d1, |
| 4408 | scratch1, scratch2, heap_number_map, s0, |
| 4409 | runtime.entry_label()); |
| 4410 | |
| 4411 | __ bind(&powi); |
| 4412 | |
| 4413 | // Load 1.0 into d0. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4414 | __ vmov(d0, 1.0); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4415 | |
| 4416 | // Get the absolute untagged value of the exponent and use that for the |
| 4417 | // calculation. |
| 4418 | __ mov(scratch1, Operand(exponent, ASR, kSmiTagSize), SetCC); |
| 4419 | __ rsb(scratch1, scratch1, Operand(0), LeaveCC, mi); // Negate if negative. |
| 4420 | __ vmov(d2, d0, mi); // 1.0 needed in d2 later if exponent is negative. |
| 4421 | |
| 4422 | // Run through all the bits in the exponent. The result is calculated in d0 |
| 4423 | // and d1 holds base^(bit^2). |
| 4424 | Label more_bits; |
| 4425 | __ bind(&more_bits); |
| 4426 | __ mov(scratch1, Operand(scratch1, LSR, 1), SetCC); |
| 4427 | __ vmul(d0, d0, d1, cs); // Multiply with base^(bit^2) if bit is set. |
| 4428 | __ vmul(d1, d1, d1, ne); // Don't bother calculating next d1 if done. |
| 4429 | __ b(ne, &more_bits); |
| 4430 | |
| 4431 | // If exponent is positive we are done. |
| 4432 | __ cmp(exponent, Operand(0)); |
| 4433 | __ b(ge, &allocate_return); |
| 4434 | |
| 4435 | // If exponent is negative result is 1/result (d2 already holds 1.0 in that |
| 4436 | // case). However if d0 has reached infinity this will not provide the |
| 4437 | // correct result, so call runtime if that is the case. |
| 4438 | __ mov(scratch2, Operand(0x7FF00000)); |
| 4439 | __ mov(scratch1, Operand(0)); |
| 4440 | __ vmov(d1, scratch1, scratch2); // Load infinity into d1. |
| 4441 | __ vcmp(d0, d1); |
| 4442 | __ vmrs(pc); |
| 4443 | runtime.Branch(eq); // d0 reached infinity. |
| 4444 | __ vdiv(d0, d2, d0); |
| 4445 | __ b(&allocate_return); |
| 4446 | |
| 4447 | __ bind(&exponent_nonsmi); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4448 | // Special handling of raising to the power of -0.5 and 0.5. First check |
| 4449 | // that the value is a heap number and that the lower bits (which for both |
| 4450 | // values are zero). |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4451 | heap_number_map = r6; |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4452 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4453 | __ ldr(scratch1, FieldMemOperand(exponent, HeapObject::kMapOffset)); |
| 4454 | __ ldr(scratch2, FieldMemOperand(exponent, HeapNumber::kMantissaOffset)); |
| 4455 | __ cmp(scratch1, heap_number_map); |
| 4456 | runtime.Branch(ne); |
| 4457 | __ tst(scratch2, scratch2); |
| 4458 | runtime.Branch(ne); |
| 4459 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4460 | // Load the higher bits (which contains the floating point exponent). |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4461 | __ ldr(scratch1, FieldMemOperand(exponent, HeapNumber::kExponentOffset)); |
| 4462 | |
| 4463 | // Compare exponent with -0.5. |
| 4464 | __ cmp(scratch1, Operand(0xbfe00000)); |
| 4465 | __ b(ne, ¬_minus_half); |
| 4466 | |
| 4467 | // Get the double value from the base into vfp register d0. |
| 4468 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4469 | scratch1, scratch2, heap_number_map, s0, |
| 4470 | runtime.entry_label(), |
| 4471 | AVOID_NANS_AND_INFINITIES); |
| 4472 | |
| 4473 | // Load 1.0 into d2. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4474 | __ vmov(d2, 1.0); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4475 | |
| 4476 | // Calculate the reciprocal of the square root. 1/sqrt(x) = sqrt(1/x). |
| 4477 | __ vdiv(d0, d2, d0); |
| 4478 | __ vsqrt(d0, d0); |
| 4479 | |
| 4480 | __ b(&allocate_return); |
| 4481 | |
| 4482 | __ bind(¬_minus_half); |
| 4483 | // Compare exponent with 0.5. |
| 4484 | __ cmp(scratch1, Operand(0x3fe00000)); |
| 4485 | runtime.Branch(ne); |
| 4486 | |
| 4487 | // Get the double value from the base into vfp register d0. |
| 4488 | __ ObjectToDoubleVFPRegister(base, d0, |
| 4489 | scratch1, scratch2, heap_number_map, s0, |
| 4490 | runtime.entry_label(), |
| 4491 | AVOID_NANS_AND_INFINITIES); |
| 4492 | __ vsqrt(d0, d0); |
| 4493 | |
| 4494 | __ bind(&allocate_return); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4495 | Register scratch3 = r5; |
| 4496 | __ AllocateHeapNumberWithValue(scratch3, d0, scratch1, scratch2, |
| 4497 | heap_number_map, runtime.entry_label()); |
| 4498 | __ mov(base, scratch3); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4499 | done.Jump(); |
| 4500 | |
| 4501 | runtime.Bind(); |
| 4502 | |
| 4503 | // Push back the arguments again for the runtime call. |
| 4504 | frame_->EmitPush(base); |
| 4505 | frame_->EmitPush(exponent); |
| 4506 | frame_->CallRuntime(Runtime::kMath_pow, 2); |
| 4507 | __ Move(base, r0); |
| 4508 | |
| 4509 | done.Bind(); |
| 4510 | frame_->EmitPush(base); |
| 4511 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4515 | // Generates the Math.sqrt method. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4516 | void CodeGenerator::GenerateMathSqrt(ZoneList<Expression*>* args) { |
| 4517 | ASSERT(args->length() == 1); |
| 4518 | Load(args->at(0)); |
lrn@chromium.org | 32d961d | 2010-06-30 09:09:34 +0000 | [diff] [blame] | 4519 | |
| 4520 | if (!CpuFeatures::IsSupported(VFP3)) { |
| 4521 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4522 | frame_->EmitPush(r0); |
| 4523 | } else { |
| 4524 | CpuFeatures::Scope scope(VFP3); |
| 4525 | JumpTarget runtime, done; |
| 4526 | |
| 4527 | Register scratch1 = VirtualFrame::scratch0(); |
| 4528 | Register scratch2 = VirtualFrame::scratch1(); |
| 4529 | |
| 4530 | // Get the value from the frame. |
| 4531 | Register tos = frame_->PopToRegister(); |
| 4532 | |
| 4533 | // Set the frame for the runtime jump target. The code below jumps to the |
| 4534 | // jump target label so the frame needs to be established before that. |
| 4535 | ASSERT(runtime.entry_frame() == NULL); |
| 4536 | runtime.set_entry_frame(frame_); |
| 4537 | |
| 4538 | Register heap_number_map = r6; |
| 4539 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 4540 | |
| 4541 | // Get the double value from the heap number into vfp register d0. |
| 4542 | __ ObjectToDoubleVFPRegister(tos, d0, |
| 4543 | scratch1, scratch2, heap_number_map, s0, |
| 4544 | runtime.entry_label()); |
| 4545 | |
| 4546 | // Calculate the square root of d0 and place result in a heap number object. |
| 4547 | __ vsqrt(d0, d0); |
| 4548 | __ AllocateHeapNumberWithValue( |
| 4549 | tos, d0, scratch1, scratch2, heap_number_map, runtime.entry_label()); |
| 4550 | done.Jump(); |
| 4551 | |
| 4552 | runtime.Bind(); |
| 4553 | // Push back the argument again for the runtime call. |
| 4554 | frame_->EmitPush(tos); |
| 4555 | frame_->CallRuntime(Runtime::kMath_sqrt, 1); |
| 4556 | __ Move(tos, r0); |
| 4557 | |
| 4558 | done.Bind(); |
| 4559 | frame_->EmitPush(tos); |
| 4560 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4561 | } |
| 4562 | |
| 4563 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4564 | class DeferredStringCharCodeAt : public DeferredCode { |
| 4565 | public: |
| 4566 | DeferredStringCharCodeAt(Register object, |
| 4567 | Register index, |
| 4568 | Register scratch, |
| 4569 | Register result) |
| 4570 | : result_(result), |
| 4571 | char_code_at_generator_(object, |
| 4572 | index, |
| 4573 | scratch, |
| 4574 | result, |
| 4575 | &need_conversion_, |
| 4576 | &need_conversion_, |
| 4577 | &index_out_of_range_, |
| 4578 | STRING_INDEX_IS_NUMBER) {} |
| 4579 | |
| 4580 | StringCharCodeAtGenerator* fast_case_generator() { |
| 4581 | return &char_code_at_generator_; |
| 4582 | } |
| 4583 | |
| 4584 | virtual void Generate() { |
| 4585 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4586 | char_code_at_generator_.GenerateSlow(masm(), call_helper); |
| 4587 | |
| 4588 | __ bind(&need_conversion_); |
| 4589 | // Move the undefined value into the result register, which will |
| 4590 | // trigger conversion. |
| 4591 | __ LoadRoot(result_, Heap::kUndefinedValueRootIndex); |
| 4592 | __ jmp(exit_label()); |
| 4593 | |
| 4594 | __ bind(&index_out_of_range_); |
| 4595 | // When the index is out of range, the spec requires us to return |
| 4596 | // NaN. |
| 4597 | __ LoadRoot(result_, Heap::kNanValueRootIndex); |
| 4598 | __ jmp(exit_label()); |
| 4599 | } |
| 4600 | |
| 4601 | private: |
| 4602 | Register result_; |
| 4603 | |
| 4604 | Label need_conversion_; |
| 4605 | Label index_out_of_range_; |
| 4606 | |
| 4607 | StringCharCodeAtGenerator char_code_at_generator_; |
| 4608 | }; |
| 4609 | |
| 4610 | |
| 4611 | // This generates code that performs a String.prototype.charCodeAt() call |
| 4612 | // or returns a smi in order to trigger conversion. |
| 4613 | void CodeGenerator::GenerateStringCharCodeAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4614 | Comment(masm_, "[ GenerateStringCharCodeAt"); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4615 | ASSERT(args->length() == 2); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4616 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4617 | Load(args->at(0)); |
| 4618 | Load(args->at(1)); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4619 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4620 | Register index = frame_->PopToRegister(); |
| 4621 | Register object = frame_->PopToRegister(index); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4622 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4623 | // We need two extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4624 | Register scratch = VirtualFrame::scratch0(); |
| 4625 | Register result = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4626 | |
| 4627 | DeferredStringCharCodeAt* deferred = |
| 4628 | new DeferredStringCharCodeAt(object, |
| 4629 | index, |
| 4630 | scratch, |
| 4631 | result); |
| 4632 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4633 | deferred->BindExit(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4634 | frame_->EmitPush(result); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
| 4637 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4638 | class DeferredStringCharFromCode : public DeferredCode { |
| 4639 | public: |
| 4640 | DeferredStringCharFromCode(Register code, |
| 4641 | Register result) |
| 4642 | : char_from_code_generator_(code, result) {} |
| 4643 | |
| 4644 | StringCharFromCodeGenerator* fast_case_generator() { |
| 4645 | return &char_from_code_generator_; |
| 4646 | } |
| 4647 | |
| 4648 | virtual void Generate() { |
| 4649 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4650 | char_from_code_generator_.GenerateSlow(masm(), call_helper); |
| 4651 | } |
| 4652 | |
| 4653 | private: |
| 4654 | StringCharFromCodeGenerator char_from_code_generator_; |
| 4655 | }; |
| 4656 | |
| 4657 | |
| 4658 | // Generates code for creating a one-char string from a char code. |
| 4659 | void CodeGenerator::GenerateStringCharFromCode(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4660 | Comment(masm_, "[ GenerateStringCharFromCode"); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4661 | ASSERT(args->length() == 1); |
| 4662 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4663 | Load(args->at(0)); |
| 4664 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4665 | Register result = frame_->GetTOSRegister(); |
| 4666 | Register code = frame_->PopToRegister(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4667 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4668 | DeferredStringCharFromCode* deferred = new DeferredStringCharFromCode( |
| 4669 | code, result); |
| 4670 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4671 | deferred->BindExit(); |
| 4672 | frame_->EmitPush(result); |
| 4673 | } |
| 4674 | |
| 4675 | |
| 4676 | class DeferredStringCharAt : public DeferredCode { |
| 4677 | public: |
| 4678 | DeferredStringCharAt(Register object, |
| 4679 | Register index, |
| 4680 | Register scratch1, |
| 4681 | Register scratch2, |
| 4682 | Register result) |
| 4683 | : result_(result), |
| 4684 | char_at_generator_(object, |
| 4685 | index, |
| 4686 | scratch1, |
| 4687 | scratch2, |
| 4688 | result, |
| 4689 | &need_conversion_, |
| 4690 | &need_conversion_, |
| 4691 | &index_out_of_range_, |
| 4692 | STRING_INDEX_IS_NUMBER) {} |
| 4693 | |
| 4694 | StringCharAtGenerator* fast_case_generator() { |
| 4695 | return &char_at_generator_; |
| 4696 | } |
| 4697 | |
| 4698 | virtual void Generate() { |
| 4699 | VirtualFrameRuntimeCallHelper call_helper(frame_state()); |
| 4700 | char_at_generator_.GenerateSlow(masm(), call_helper); |
| 4701 | |
| 4702 | __ bind(&need_conversion_); |
| 4703 | // Move smi zero into the result register, which will trigger |
| 4704 | // conversion. |
| 4705 | __ mov(result_, Operand(Smi::FromInt(0))); |
| 4706 | __ jmp(exit_label()); |
| 4707 | |
| 4708 | __ bind(&index_out_of_range_); |
| 4709 | // When the index is out of range, the spec requires us to return |
| 4710 | // the empty string. |
| 4711 | __ LoadRoot(result_, Heap::kEmptyStringRootIndex); |
| 4712 | __ jmp(exit_label()); |
| 4713 | } |
| 4714 | |
| 4715 | private: |
| 4716 | Register result_; |
| 4717 | |
| 4718 | Label need_conversion_; |
| 4719 | Label index_out_of_range_; |
| 4720 | |
| 4721 | StringCharAtGenerator char_at_generator_; |
| 4722 | }; |
| 4723 | |
| 4724 | |
| 4725 | // This generates code that performs a String.prototype.charAt() call |
| 4726 | // or returns a smi in order to trigger conversion. |
| 4727 | void CodeGenerator::GenerateStringCharAt(ZoneList<Expression*>* args) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4728 | Comment(masm_, "[ GenerateStringCharAt"); |
| 4729 | ASSERT(args->length() == 2); |
| 4730 | |
| 4731 | Load(args->at(0)); |
| 4732 | Load(args->at(1)); |
| 4733 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4734 | Register index = frame_->PopToRegister(); |
| 4735 | Register object = frame_->PopToRegister(index); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4736 | |
| 4737 | // We need three extra registers. |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 4738 | Register scratch1 = VirtualFrame::scratch0(); |
| 4739 | Register scratch2 = VirtualFrame::scratch1(); |
| 4740 | // Use r6 without notifying the virtual frame. |
| 4741 | Register result = r6; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4742 | |
| 4743 | DeferredStringCharAt* deferred = |
| 4744 | new DeferredStringCharAt(object, |
| 4745 | index, |
| 4746 | scratch1, |
| 4747 | scratch2, |
| 4748 | result); |
| 4749 | deferred->fast_case_generator()->GenerateFast(masm_); |
| 4750 | deferred->BindExit(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 4751 | frame_->EmitPush(result); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4755 | void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4756 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4757 | Load(args->at(0)); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4758 | JumpTarget answer; |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4759 | // We need the CC bits to come out as not_equal in the case where the |
| 4760 | // object is a smi. This can't be done with the usual test opcode so |
| 4761 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4762 | Register possible_array = frame_->PopToRegister(); |
| 4763 | Register scratch = VirtualFrame::scratch0(); |
| 4764 | __ and_(scratch, possible_array, Operand(kSmiTagMask)); |
| 4765 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4766 | answer.Branch(ne); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 4767 | // 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] | 4768 | __ CompareObjectType(possible_array, scratch, scratch, JS_ARRAY_TYPE); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4769 | answer.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4770 | cc_reg_ = eq; |
| 4771 | } |
| 4772 | |
| 4773 | |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4774 | void CodeGenerator::GenerateIsRegExp(ZoneList<Expression*>* args) { |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4775 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4776 | Load(args->at(0)); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4777 | JumpTarget answer; |
| 4778 | // We need the CC bits to come out as not_equal in the case where the |
| 4779 | // object is a smi. This can't be done with the usual test opcode so |
| 4780 | // we use XOR to get the right CC bits. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4781 | Register possible_regexp = frame_->PopToRegister(); |
| 4782 | Register scratch = VirtualFrame::scratch0(); |
| 4783 | __ and_(scratch, possible_regexp, Operand(kSmiTagMask)); |
| 4784 | __ eor(scratch, scratch, Operand(kSmiTagMask), SetCC); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4785 | answer.Branch(ne); |
| 4786 | // 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] | 4787 | __ CompareObjectType(possible_regexp, scratch, scratch, JS_REGEXP_TYPE); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 4788 | answer.Bind(); |
| 4789 | cc_reg_ = eq; |
| 4790 | } |
| 4791 | |
| 4792 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4793 | void CodeGenerator::GenerateIsObject(ZoneList<Expression*>* args) { |
| 4794 | // This generates a fast version of: |
| 4795 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4796 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4797 | Load(args->at(0)); |
| 4798 | Register possible_object = frame_->PopToRegister(); |
| 4799 | __ tst(possible_object, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4800 | false_target()->Branch(eq); |
| 4801 | |
| 4802 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4803 | __ cmp(possible_object, ip); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4804 | true_target()->Branch(eq); |
| 4805 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4806 | Register map_reg = VirtualFrame::scratch0(); |
| 4807 | __ ldr(map_reg, FieldMemOperand(possible_object, HeapObject::kMapOffset)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4808 | // Undetectable objects behave like undefined when tested with typeof. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4809 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 4810 | __ tst(possible_object, Operand(1 << Map::kIsUndetectable)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 4811 | false_target()->Branch(ne); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4812 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4813 | __ ldrb(possible_object, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 4814 | __ cmp(possible_object, Operand(FIRST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4815 | false_target()->Branch(lt); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4816 | __ cmp(possible_object, Operand(LAST_JS_OBJECT_TYPE)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4817 | cc_reg_ = le; |
| 4818 | } |
| 4819 | |
| 4820 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 4821 | void CodeGenerator::GenerateIsSpecObject(ZoneList<Expression*>* args) { |
| 4822 | // This generates a fast version of: |
| 4823 | // (typeof(arg) === 'object' || %_ClassOf(arg) == 'RegExp' || |
| 4824 | // typeof(arg) == function). |
| 4825 | // It includes undetectable objects (as opposed to IsObject). |
| 4826 | ASSERT(args->length() == 1); |
| 4827 | Load(args->at(0)); |
| 4828 | Register value = frame_->PopToRegister(); |
| 4829 | __ tst(value, Operand(kSmiTagMask)); |
| 4830 | false_target()->Branch(eq); |
| 4831 | // Check that this is an object. |
| 4832 | __ ldr(value, FieldMemOperand(value, HeapObject::kMapOffset)); |
| 4833 | __ ldrb(value, FieldMemOperand(value, Map::kInstanceTypeOffset)); |
| 4834 | __ cmp(value, Operand(FIRST_JS_OBJECT_TYPE)); |
| 4835 | cc_reg_ = ge; |
| 4836 | } |
| 4837 | |
| 4838 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4839 | // Deferred code to check whether the String JavaScript object is safe for using |
| 4840 | // default value of. This code is called after the bit caching this information |
| 4841 | // in the map has been checked with the map for the object in the map_result_ |
| 4842 | // register. On return the register map_result_ contains 1 for true and 0 for |
| 4843 | // false. |
| 4844 | class DeferredIsStringWrapperSafeForDefaultValueOf : public DeferredCode { |
| 4845 | public: |
| 4846 | DeferredIsStringWrapperSafeForDefaultValueOf(Register object, |
| 4847 | Register map_result, |
| 4848 | Register scratch1, |
| 4849 | Register scratch2) |
| 4850 | : object_(object), |
| 4851 | map_result_(map_result), |
| 4852 | scratch1_(scratch1), |
| 4853 | scratch2_(scratch2) { } |
| 4854 | |
| 4855 | virtual void Generate() { |
| 4856 | Label false_result; |
| 4857 | |
| 4858 | // Check that map is loaded as expected. |
| 4859 | if (FLAG_debug_code) { |
| 4860 | __ ldr(ip, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4861 | __ cmp(map_result_, ip); |
| 4862 | __ Assert(eq, "Map not in expected register"); |
| 4863 | } |
| 4864 | |
| 4865 | // Check for fast case object. Generate false result for slow case object. |
| 4866 | __ ldr(scratch1_, FieldMemOperand(object_, JSObject::kPropertiesOffset)); |
| 4867 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 4868 | __ LoadRoot(ip, Heap::kHashTableMapRootIndex); |
| 4869 | __ cmp(scratch1_, ip); |
| 4870 | __ b(eq, &false_result); |
| 4871 | |
| 4872 | // Look for valueOf symbol in the descriptor array, and indicate false if |
| 4873 | // found. The type is not checked, so if it is a transition it is a false |
| 4874 | // negative. |
| 4875 | __ ldr(map_result_, |
| 4876 | FieldMemOperand(map_result_, Map::kInstanceDescriptorsOffset)); |
| 4877 | __ ldr(scratch2_, FieldMemOperand(map_result_, FixedArray::kLengthOffset)); |
| 4878 | // map_result_: descriptor array |
| 4879 | // scratch2_: length of descriptor array |
| 4880 | // Calculate the end of the descriptor array. |
| 4881 | STATIC_ASSERT(kSmiTag == 0); |
| 4882 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4883 | STATIC_ASSERT(kPointerSize == 4); |
| 4884 | __ add(scratch1_, |
| 4885 | map_result_, |
| 4886 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4887 | __ add(scratch1_, |
| 4888 | scratch1_, |
| 4889 | Operand(scratch2_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4890 | |
| 4891 | // Calculate location of the first key name. |
| 4892 | __ add(map_result_, |
| 4893 | map_result_, |
| 4894 | Operand(FixedArray::kHeaderSize - kHeapObjectTag + |
| 4895 | DescriptorArray::kFirstIndex * kPointerSize)); |
| 4896 | // Loop through all the keys in the descriptor array. If one of these is the |
| 4897 | // symbol valueOf the result is false. |
| 4898 | Label entry, loop; |
| 4899 | // The use of ip to store the valueOf symbol asumes that it is not otherwise |
| 4900 | // used in the loop below. |
| 4901 | __ mov(ip, Operand(Factory::value_of_symbol())); |
| 4902 | __ jmp(&entry); |
| 4903 | __ bind(&loop); |
| 4904 | __ ldr(scratch2_, MemOperand(map_result_, 0)); |
| 4905 | __ cmp(scratch2_, ip); |
| 4906 | __ b(eq, &false_result); |
| 4907 | __ add(map_result_, map_result_, Operand(kPointerSize)); |
| 4908 | __ bind(&entry); |
| 4909 | __ cmp(map_result_, Operand(scratch1_)); |
| 4910 | __ b(ne, &loop); |
| 4911 | |
| 4912 | // Reload map as register map_result_ was used as temporary above. |
| 4913 | __ ldr(map_result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4914 | |
| 4915 | // If a valueOf property is not found on the object check that it's |
| 4916 | // prototype is the un-modified String prototype. If not result is false. |
| 4917 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kPrototypeOffset)); |
| 4918 | __ tst(scratch1_, Operand(kSmiTagMask)); |
| 4919 | __ b(eq, &false_result); |
| 4920 | __ ldr(scratch1_, FieldMemOperand(scratch1_, HeapObject::kMapOffset)); |
| 4921 | __ ldr(scratch2_, |
| 4922 | CodeGenerator::ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 4923 | __ ldr(scratch2_, |
| 4924 | FieldMemOperand(scratch2_, GlobalObject::kGlobalContextOffset)); |
| 4925 | __ ldr(scratch2_, |
| 4926 | CodeGenerator::ContextOperand( |
| 4927 | scratch2_, Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX)); |
| 4928 | __ cmp(scratch1_, scratch2_); |
| 4929 | __ b(ne, &false_result); |
| 4930 | |
| 4931 | // Set the bit in the map to indicate that it has been checked safe for |
| 4932 | // default valueOf and set true result. |
| 4933 | __ ldr(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 4934 | __ orr(scratch1_, |
| 4935 | scratch1_, |
| 4936 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 4937 | __ str(scratch1_, FieldMemOperand(map_result_, Map::kBitField2Offset)); |
| 4938 | __ mov(map_result_, Operand(1)); |
| 4939 | __ jmp(exit_label()); |
| 4940 | __ bind(&false_result); |
| 4941 | // Set false result. |
| 4942 | __ mov(map_result_, Operand(0)); |
| 4943 | } |
| 4944 | |
| 4945 | private: |
| 4946 | Register object_; |
| 4947 | Register map_result_; |
| 4948 | Register scratch1_; |
| 4949 | Register scratch2_; |
| 4950 | }; |
| 4951 | |
| 4952 | |
| 4953 | void CodeGenerator::GenerateIsStringWrapperSafeForDefaultValueOf( |
| 4954 | ZoneList<Expression*>* args) { |
| 4955 | ASSERT(args->length() == 1); |
| 4956 | Load(args->at(0)); |
| 4957 | Register obj = frame_->PopToRegister(); // Pop the string wrapper. |
| 4958 | if (FLAG_debug_code) { |
| 4959 | __ AbortIfSmi(obj); |
| 4960 | } |
| 4961 | |
| 4962 | // Check whether this map has already been checked to be safe for default |
| 4963 | // valueOf. |
| 4964 | Register map_result = VirtualFrame::scratch0(); |
| 4965 | __ ldr(map_result, FieldMemOperand(obj, HeapObject::kMapOffset)); |
| 4966 | __ ldrb(ip, FieldMemOperand(map_result, Map::kBitField2Offset)); |
| 4967 | __ tst(ip, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 4968 | true_target()->Branch(ne); |
| 4969 | |
| 4970 | // We need an additional two scratch registers for the deferred code. |
| 4971 | Register scratch1 = VirtualFrame::scratch1(); |
| 4972 | // Use r6 without notifying the virtual frame. |
| 4973 | Register scratch2 = r6; |
| 4974 | |
| 4975 | DeferredIsStringWrapperSafeForDefaultValueOf* deferred = |
| 4976 | new DeferredIsStringWrapperSafeForDefaultValueOf( |
| 4977 | obj, map_result, scratch1, scratch2); |
| 4978 | deferred->Branch(eq); |
| 4979 | deferred->BindExit(); |
| 4980 | __ tst(map_result, Operand(map_result)); |
| 4981 | cc_reg_ = ne; |
| 4982 | } |
| 4983 | |
| 4984 | |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4985 | void CodeGenerator::GenerateIsFunction(ZoneList<Expression*>* args) { |
| 4986 | // This generates a fast version of: |
| 4987 | // (%_ClassOf(arg) === 'Function') |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4988 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4989 | Load(args->at(0)); |
| 4990 | Register possible_function = frame_->PopToRegister(); |
| 4991 | __ tst(possible_function, Operand(kSmiTagMask)); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4992 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4993 | Register map_reg = VirtualFrame::scratch0(); |
| 4994 | Register scratch = VirtualFrame::scratch1(); |
| 4995 | __ CompareObjectType(possible_function, map_reg, scratch, JS_FUNCTION_TYPE); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 4996 | cc_reg_ = eq; |
| 4997 | } |
| 4998 | |
| 4999 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5000 | void CodeGenerator::GenerateIsUndetectableObject(ZoneList<Expression*>* args) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5001 | ASSERT(args->length() == 1); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5002 | Load(args->at(0)); |
| 5003 | Register possible_undetectable = frame_->PopToRegister(); |
| 5004 | __ tst(possible_undetectable, Operand(kSmiTagMask)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5005 | false_target()->Branch(eq); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5006 | Register scratch = VirtualFrame::scratch0(); |
| 5007 | __ ldr(scratch, |
| 5008 | FieldMemOperand(possible_undetectable, HeapObject::kMapOffset)); |
| 5009 | __ ldrb(scratch, FieldMemOperand(scratch, Map::kBitFieldOffset)); |
| 5010 | __ tst(scratch, Operand(1 << Map::kIsUndetectable)); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5011 | cc_reg_ = ne; |
| 5012 | } |
| 5013 | |
| 5014 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5015 | void CodeGenerator::GenerateIsConstructCall(ZoneList<Expression*>* args) { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5016 | ASSERT(args->length() == 0); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5017 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5018 | Register scratch0 = VirtualFrame::scratch0(); |
| 5019 | Register scratch1 = VirtualFrame::scratch1(); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5020 | // Get the frame pointer for the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5021 | __ ldr(scratch0, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5022 | |
| 5023 | // Skip the arguments adaptor frame if it exists. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5024 | __ ldr(scratch1, |
| 5025 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5026 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5027 | __ ldr(scratch0, |
| 5028 | MemOperand(scratch0, StandardFrameConstants::kCallerFPOffset), eq); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5029 | |
| 5030 | // Check the marker in the calling frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5031 | __ ldr(scratch1, |
| 5032 | MemOperand(scratch0, StandardFrameConstants::kMarkerOffset)); |
| 5033 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::CONSTRUCT))); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5034 | cc_reg_ = eq; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5038 | void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5039 | ASSERT(args->length() == 0); |
| 5040 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5041 | Register tos = frame_->GetTOSRegister(); |
| 5042 | Register scratch0 = VirtualFrame::scratch0(); |
| 5043 | Register scratch1 = VirtualFrame::scratch1(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5044 | |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5045 | // Check if the calling frame is an arguments adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5046 | __ ldr(scratch0, |
| 5047 | MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 5048 | __ ldr(scratch1, |
| 5049 | MemOperand(scratch0, StandardFrameConstants::kContextOffset)); |
| 5050 | __ cmp(scratch1, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 5051 | |
| 5052 | // Get the number of formal parameters. |
| 5053 | __ mov(tos, Operand(Smi::FromInt(scope()->num_parameters())), LeaveCC, ne); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5054 | |
| 5055 | // Arguments adaptor case: Read the arguments length from the |
| 5056 | // adaptor frame. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5057 | __ ldr(tos, |
| 5058 | MemOperand(scratch0, ArgumentsAdaptorFrameConstants::kLengthOffset), |
| 5059 | eq); |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5060 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5061 | frame_->EmitPush(tos); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 5065 | void CodeGenerator::GenerateArguments(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5066 | ASSERT(args->length() == 1); |
| 5067 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5068 | // Satisfy contract with ArgumentsAccessStub: |
| 5069 | // 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] | 5070 | Load(args->at(0)); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5071 | frame_->PopToR1(); |
| 5072 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5073 | __ mov(r0, Operand(Smi::FromInt(scope()->num_parameters()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5074 | |
| 5075 | // Call the shared stub to get to arguments[key]. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 5076 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5077 | frame_->CallStub(&stub, 0); |
| 5078 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5079 | } |
| 5080 | |
| 5081 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5082 | void CodeGenerator::GenerateRandomHeapNumber( |
| 5083 | ZoneList<Expression*>* args) { |
| 5084 | VirtualFrame::SpilledScope spilled_scope(frame_); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5085 | ASSERT(args->length() == 0); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5086 | |
| 5087 | Label slow_allocate_heapnumber; |
| 5088 | Label heapnumber_allocated; |
| 5089 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5090 | __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex); |
| 5091 | __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5092 | __ jmp(&heapnumber_allocated); |
| 5093 | |
| 5094 | __ bind(&slow_allocate_heapnumber); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 5095 | // Allocate a heap number. |
| 5096 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5097 | __ mov(r4, Operand(r0)); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5098 | |
| 5099 | __ bind(&heapnumber_allocated); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 5100 | |
| 5101 | // Convert 32 random bits in r0 to 0.(32 random bits) in a double |
| 5102 | // by computing: |
| 5103 | // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
| 5104 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5105 | __ PrepareCallCFunction(0, r1); |
| 5106 | __ CallCFunction(ExternalReference::random_uint32_function(), 0); |
| 5107 | |
| 5108 | CpuFeatures::Scope scope(VFP3); |
| 5109 | // 0x41300000 is the top half of 1.0 x 2^20 as a double. |
| 5110 | // Create this constant using mov/orr to avoid PC relative load. |
| 5111 | __ mov(r1, Operand(0x41000000)); |
| 5112 | __ orr(r1, r1, Operand(0x300000)); |
| 5113 | // Move 0x41300000xxxxxxxx (x = random bits) to VFP. |
| 5114 | __ vmov(d7, r0, r1); |
| 5115 | // Move 0x4130000000000000 to VFP. |
| 5116 | __ mov(r0, Operand(0)); |
| 5117 | __ vmov(d8, r0, r1); |
| 5118 | // Subtract and store the result in the heap number. |
| 5119 | __ vsub(d7, d7, d8); |
| 5120 | __ sub(r0, r4, Operand(kHeapObjectTag)); |
| 5121 | __ vstr(d7, r0, HeapNumber::kValueOffset); |
| 5122 | frame_->EmitPush(r4); |
| 5123 | } else { |
| 5124 | __ mov(r0, Operand(r4)); |
| 5125 | __ PrepareCallCFunction(1, r1); |
| 5126 | __ CallCFunction( |
| 5127 | ExternalReference::fill_heap_number_with_random_function(), 1); |
| 5128 | frame_->EmitPush(r0); |
| 5129 | } |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5133 | void CodeGenerator::GenerateStringAdd(ZoneList<Expression*>* args) { |
| 5134 | ASSERT_EQ(2, args->length()); |
| 5135 | |
| 5136 | Load(args->at(0)); |
| 5137 | Load(args->at(1)); |
| 5138 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5139 | StringAddStub stub(NO_STRING_ADD_FLAGS); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5140 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5141 | frame_->CallStub(&stub, 2); |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5142 | frame_->EmitPush(r0); |
| 5143 | } |
| 5144 | |
| 5145 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5146 | void CodeGenerator::GenerateSubString(ZoneList<Expression*>* args) { |
| 5147 | ASSERT_EQ(3, args->length()); |
| 5148 | |
| 5149 | Load(args->at(0)); |
| 5150 | Load(args->at(1)); |
| 5151 | Load(args->at(2)); |
| 5152 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5153 | SubStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5154 | frame_->SpillAll(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5155 | frame_->CallStub(&stub, 3); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5156 | frame_->EmitPush(r0); |
| 5157 | } |
| 5158 | |
| 5159 | |
| 5160 | void CodeGenerator::GenerateStringCompare(ZoneList<Expression*>* args) { |
| 5161 | ASSERT_EQ(2, args->length()); |
| 5162 | |
| 5163 | Load(args->at(0)); |
| 5164 | Load(args->at(1)); |
| 5165 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5166 | StringCompareStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5167 | frame_->SpillAll(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5168 | frame_->CallStub(&stub, 2); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5169 | frame_->EmitPush(r0); |
| 5170 | } |
| 5171 | |
| 5172 | |
| 5173 | void CodeGenerator::GenerateRegExpExec(ZoneList<Expression*>* args) { |
| 5174 | ASSERT_EQ(4, args->length()); |
| 5175 | |
| 5176 | Load(args->at(0)); |
| 5177 | Load(args->at(1)); |
| 5178 | Load(args->at(2)); |
| 5179 | Load(args->at(3)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5180 | RegExpExecStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5181 | frame_->SpillAll(); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5182 | frame_->CallStub(&stub, 4); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5183 | frame_->EmitPush(r0); |
| 5184 | } |
| 5185 | |
| 5186 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5187 | void CodeGenerator::GenerateRegExpConstructResult(ZoneList<Expression*>* args) { |
| 5188 | // No stub. This code only occurs a few times in regexp.js. |
| 5189 | const int kMaxInlineLength = 100; |
| 5190 | ASSERT_EQ(3, args->length()); |
| 5191 | Load(args->at(0)); // Size of array, smi. |
| 5192 | Load(args->at(1)); // "index" property value. |
| 5193 | Load(args->at(2)); // "input" property value. |
| 5194 | { |
| 5195 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5196 | Label slowcase; |
| 5197 | Label done; |
| 5198 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 5199 | STATIC_ASSERT(kSmiTag == 0); |
| 5200 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5201 | __ tst(r1, Operand(kSmiTagMask)); |
| 5202 | __ b(ne, &slowcase); |
| 5203 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 5204 | __ b(hi, &slowcase); |
| 5205 | // Smi-tagging is equivalent to multiplying by 2. |
| 5206 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 5207 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 5208 | // Elements: [Map][Length][..elements..] |
| 5209 | // Size of JSArray with two in-object properties and the header of a |
| 5210 | // FixedArray. |
| 5211 | int objects_size = |
| 5212 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 5213 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 5214 | __ add(r2, r5, Operand(objects_size)); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 5215 | __ AllocateInNewSpace( |
| 5216 | r2, // In: Size, in words. |
| 5217 | r0, // Out: Start of allocation (tagged). |
| 5218 | r3, // Scratch register. |
| 5219 | r4, // Scratch register. |
| 5220 | &slowcase, |
| 5221 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5222 | // r0: Start of allocated area, object-tagged. |
| 5223 | // r1: Number of elements in array, as smi. |
| 5224 | // r5: Number of elements, untagged. |
| 5225 | |
| 5226 | // Set JSArray map to global.regexp_result_map(). |
| 5227 | // Set empty properties FixedArray. |
| 5228 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 5229 | // Interleave operations for better latency. |
| 5230 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5231 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
| 5232 | __ mov(r4, Operand(Factory::empty_fixed_array())); |
| 5233 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 5234 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 5235 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5236 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5237 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5238 | |
| 5239 | // Set input, index and length fields from arguments. |
| 5240 | __ ldm(ia_w, sp, static_cast<RegList>(r2.bit() | r4.bit())); |
| 5241 | __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset)); |
| 5242 | __ add(sp, sp, Operand(kPointerSize)); |
| 5243 | __ str(r4, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 5244 | __ str(r2, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
| 5245 | |
| 5246 | // Fill out the elements FixedArray. |
| 5247 | // r0: JSArray, tagged. |
| 5248 | // r3: FixedArray, tagged. |
| 5249 | // r5: Number of elements in array, untagged. |
| 5250 | |
| 5251 | // Set map. |
| 5252 | __ mov(r2, Operand(Factory::fixed_array_map())); |
| 5253 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 5254 | // Set FixedArray length. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5255 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 5256 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 5257 | // Fill contents of fixed-array with the-hole. |
| 5258 | __ mov(r2, Operand(Factory::the_hole_value())); |
| 5259 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5260 | // Fill fixed array elements with hole. |
| 5261 | // r0: JSArray, tagged. |
| 5262 | // r2: the hole. |
| 5263 | // r3: Start of elements in FixedArray. |
| 5264 | // r5: Number of elements to fill. |
| 5265 | Label loop; |
| 5266 | __ tst(r5, Operand(r5)); |
| 5267 | __ bind(&loop); |
| 5268 | __ b(le, &done); // Jump if r1 is negative or zero. |
| 5269 | __ sub(r5, r5, Operand(1), SetCC); |
| 5270 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 5271 | __ jmp(&loop); |
| 5272 | |
| 5273 | __ bind(&slowcase); |
| 5274 | __ CallRuntime(Runtime::kRegExpConstructResult, 3); |
| 5275 | |
| 5276 | __ bind(&done); |
| 5277 | } |
| 5278 | frame_->Forget(3); |
| 5279 | frame_->EmitPush(r0); |
| 5280 | } |
| 5281 | |
| 5282 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5283 | void CodeGenerator::GenerateRegExpCloneResult(ZoneList<Expression*>* args) { |
| 5284 | ASSERT_EQ(1, args->length()); |
| 5285 | |
| 5286 | Load(args->at(0)); |
| 5287 | frame_->PopToR0(); |
| 5288 | { |
| 5289 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5290 | |
| 5291 | Label done; |
| 5292 | Label call_runtime; |
| 5293 | __ BranchOnSmi(r0, &done); |
| 5294 | |
| 5295 | // Load JSRegExp map into r1. Check that argument object has this map. |
| 5296 | // Arguments to this function should be results of calling RegExp exec, |
| 5297 | // which is either an unmodified JSRegExpResult or null. Anything not having |
| 5298 | // the unmodified JSRegExpResult map is returned unmodified. |
| 5299 | // This also ensures that elements are fast. |
| 5300 | |
| 5301 | __ ldr(r1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5302 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalContextOffset)); |
| 5303 | __ ldr(r1, ContextOperand(r1, Context::REGEXP_RESULT_MAP_INDEX)); |
| 5304 | __ ldr(ip, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5305 | __ cmp(r1, Operand(ip)); |
| 5306 | __ b(ne, &done); |
| 5307 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 5308 | if (FLAG_debug_code) { |
| 5309 | __ LoadRoot(r2, Heap::kEmptyFixedArrayRootIndex); |
| 5310 | __ ldr(ip, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 5311 | __ cmp(ip, r2); |
| 5312 | __ Check(eq, "JSRegExpResult: default map but non-empty properties."); |
| 5313 | } |
| 5314 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5315 | // All set, copy the contents to a new object. |
| 5316 | __ AllocateInNewSpace(JSRegExpResult::kSize, |
| 5317 | r2, |
| 5318 | r3, |
| 5319 | r4, |
| 5320 | &call_runtime, |
| 5321 | NO_ALLOCATION_FLAGS); |
| 5322 | // Store RegExpResult map as map of allocated object. |
| 5323 | ASSERT(JSRegExpResult::kSize == 6 * kPointerSize); |
| 5324 | // Copy all fields (map is already in r1) from (untagged) r0 to r2. |
| 5325 | // Change map of elements array (ends up in r4) to be a FixedCOWArray. |
| 5326 | __ bic(r0, r0, Operand(kHeapObjectTagMask)); |
| 5327 | __ ldm(ib, r0, r3.bit() | r4.bit() | r5.bit() | r6.bit() | r7.bit()); |
| 5328 | __ stm(ia, r2, |
| 5329 | 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] | 5330 | ASSERT(JSRegExp::kElementsOffset == 2 * kPointerSize); |
| 5331 | // Check whether elements array is empty fixed array, and otherwise make |
| 5332 | // it copy-on-write (it never should be empty unless someone is messing |
| 5333 | // with the arguments to the runtime function). |
| 5334 | __ LoadRoot(ip, Heap::kEmptyFixedArrayRootIndex); |
| 5335 | __ add(r0, r2, Operand(kHeapObjectTag)); // Tag result and move it to r0. |
| 5336 | __ cmp(r4, ip); |
| 5337 | __ b(eq, &done); |
| 5338 | __ LoadRoot(ip, Heap::kFixedCOWArrayMapRootIndex); |
| 5339 | __ str(ip, FieldMemOperand(r4, HeapObject::kMapOffset)); |
| 5340 | __ b(&done); |
| 5341 | __ bind(&call_runtime); |
| 5342 | __ push(r0); |
| 5343 | __ CallRuntime(Runtime::kRegExpCloneResult, 1); |
| 5344 | __ bind(&done); |
| 5345 | } |
| 5346 | frame_->EmitPush(r0); |
| 5347 | } |
| 5348 | |
| 5349 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5350 | class DeferredSearchCache: public DeferredCode { |
| 5351 | public: |
| 5352 | DeferredSearchCache(Register dst, Register cache, Register key) |
| 5353 | : dst_(dst), cache_(cache), key_(key) { |
| 5354 | set_comment("[ DeferredSearchCache"); |
| 5355 | } |
| 5356 | |
| 5357 | virtual void Generate(); |
| 5358 | |
| 5359 | private: |
| 5360 | Register dst_, cache_, key_; |
| 5361 | }; |
| 5362 | |
| 5363 | |
| 5364 | void DeferredSearchCache::Generate() { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 5365 | __ Push(cache_, key_); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5366 | __ CallRuntime(Runtime::kGetFromCache, 2); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5367 | __ Move(dst_, r0); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
| 5370 | |
| 5371 | void CodeGenerator::GenerateGetFromCache(ZoneList<Expression*>* args) { |
| 5372 | ASSERT_EQ(2, args->length()); |
| 5373 | |
| 5374 | ASSERT_NE(NULL, args->at(0)->AsLiteral()); |
| 5375 | int cache_id = Smi::cast(*(args->at(0)->AsLiteral()->handle()))->value(); |
| 5376 | |
| 5377 | Handle<FixedArray> jsfunction_result_caches( |
| 5378 | Top::global_context()->jsfunction_result_caches()); |
| 5379 | if (jsfunction_result_caches->length() <= cache_id) { |
| 5380 | __ Abort("Attempt to use undefined cache."); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5381 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5382 | return; |
| 5383 | } |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5384 | |
| 5385 | Load(args->at(1)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5386 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5387 | frame_->PopToR1(); |
| 5388 | frame_->SpillAll(); |
| 5389 | Register key = r1; // Just poped to r1 |
| 5390 | Register result = r0; // Free, as frame has just been spilled. |
| 5391 | Register scratch1 = VirtualFrame::scratch0(); |
| 5392 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5393 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5394 | __ ldr(scratch1, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 5395 | __ ldr(scratch1, |
| 5396 | FieldMemOperand(scratch1, GlobalObject::kGlobalContextOffset)); |
| 5397 | __ ldr(scratch1, |
| 5398 | ContextOperand(scratch1, Context::JSFUNCTION_RESULT_CACHES_INDEX)); |
| 5399 | __ ldr(scratch1, |
| 5400 | FieldMemOperand(scratch1, FixedArray::OffsetOfElementAt(cache_id))); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5401 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5402 | DeferredSearchCache* deferred = |
| 5403 | new DeferredSearchCache(result, scratch1, key); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5404 | |
| 5405 | const int kFingerOffset = |
| 5406 | FixedArray::OffsetOfElementAt(JSFunctionResultCache::kFingerIndex); |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 5407 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5408 | __ ldr(result, FieldMemOperand(scratch1, kFingerOffset)); |
| 5409 | // result now holds finger offset as a smi. |
| 5410 | __ add(scratch2, scratch1, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5411 | // scratch2 now points to the start of fixed array elements. |
| 5412 | __ ldr(result, |
| 5413 | MemOperand( |
| 5414 | scratch2, result, LSL, kPointerSizeLog2 - kSmiTagSize, PreIndex)); |
| 5415 | // Note side effect of PreIndex: scratch2 now points to the key of the pair. |
| 5416 | __ cmp(key, result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5417 | deferred->Branch(ne); |
| 5418 | |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5419 | __ ldr(result, MemOperand(scratch2, kPointerSize)); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5420 | |
| 5421 | deferred->BindExit(); |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5422 | frame_->EmitPush(result); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5426 | void CodeGenerator::GenerateNumberToString(ZoneList<Expression*>* args) { |
| 5427 | ASSERT_EQ(args->length(), 1); |
| 5428 | |
| 5429 | // Load the argument on the stack and jump to the runtime. |
| 5430 | Load(args->at(0)); |
| 5431 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5432 | NumberToStringStub stub; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5433 | frame_->SpillAll(); |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 5434 | frame_->CallStub(&stub, 1); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5435 | frame_->EmitPush(r0); |
| 5436 | } |
| 5437 | |
| 5438 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5439 | class DeferredSwapElements: public DeferredCode { |
| 5440 | public: |
| 5441 | DeferredSwapElements(Register object, Register index1, Register index2) |
| 5442 | : object_(object), index1_(index1), index2_(index2) { |
| 5443 | set_comment("[ DeferredSwapElements"); |
| 5444 | } |
| 5445 | |
| 5446 | virtual void Generate(); |
| 5447 | |
| 5448 | private: |
| 5449 | Register object_, index1_, index2_; |
| 5450 | }; |
| 5451 | |
| 5452 | |
| 5453 | void DeferredSwapElements::Generate() { |
| 5454 | __ push(object_); |
| 5455 | __ push(index1_); |
| 5456 | __ push(index2_); |
| 5457 | __ CallRuntime(Runtime::kSwapElements, 3); |
| 5458 | } |
| 5459 | |
| 5460 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5461 | void CodeGenerator::GenerateSwapElements(ZoneList<Expression*>* args) { |
| 5462 | Comment cmnt(masm_, "[ GenerateSwapElements"); |
| 5463 | |
| 5464 | ASSERT_EQ(3, args->length()); |
| 5465 | |
| 5466 | Load(args->at(0)); |
| 5467 | Load(args->at(1)); |
| 5468 | Load(args->at(2)); |
| 5469 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5470 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5471 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5472 | Register index2 = r2; |
| 5473 | Register index1 = r1; |
| 5474 | Register object = r0; |
| 5475 | Register tmp1 = r3; |
| 5476 | Register tmp2 = r4; |
| 5477 | |
| 5478 | frame_->EmitPop(index2); |
| 5479 | frame_->EmitPop(index1); |
| 5480 | frame_->EmitPop(object); |
| 5481 | |
| 5482 | DeferredSwapElements* deferred = |
| 5483 | new DeferredSwapElements(object, index1, index2); |
| 5484 | |
| 5485 | // Fetch the map and check if array is in fast case. |
| 5486 | // Check that object doesn't require security checks and |
| 5487 | // has no indexed interceptor. |
| 5488 | __ CompareObjectType(object, tmp1, tmp2, FIRST_JS_OBJECT_TYPE); |
| 5489 | deferred->Branch(lt); |
| 5490 | __ ldrb(tmp2, FieldMemOperand(tmp1, Map::kBitFieldOffset)); |
| 5491 | __ tst(tmp2, Operand(KeyedLoadIC::kSlowCaseBitFieldMask)); |
| 5492 | deferred->Branch(nz); |
| 5493 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5494 | // Check the object's elements are in fast case and writable. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5495 | __ ldr(tmp1, FieldMemOperand(object, JSObject::kElementsOffset)); |
| 5496 | __ ldr(tmp2, FieldMemOperand(tmp1, HeapObject::kMapOffset)); |
| 5497 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 5498 | __ cmp(tmp2, ip); |
| 5499 | deferred->Branch(ne); |
| 5500 | |
| 5501 | // Smi-tagging is equivalent to multiplying by 2. |
| 5502 | STATIC_ASSERT(kSmiTag == 0); |
| 5503 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5504 | |
| 5505 | // Check that both indices are smis. |
| 5506 | __ mov(tmp2, index1); |
| 5507 | __ orr(tmp2, tmp2, index2); |
| 5508 | __ tst(tmp2, Operand(kSmiTagMask)); |
| 5509 | deferred->Branch(nz); |
| 5510 | |
| 5511 | // Bring the offsets into the fixed array in tmp1 into index1 and |
| 5512 | // index2. |
| 5513 | __ mov(tmp2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 5514 | __ add(index1, tmp2, Operand(index1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5515 | __ add(index2, tmp2, Operand(index2, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 5516 | |
| 5517 | // Swap elements. |
| 5518 | Register tmp3 = object; |
| 5519 | object = no_reg; |
| 5520 | __ ldr(tmp3, MemOperand(tmp1, index1)); |
| 5521 | __ ldr(tmp2, MemOperand(tmp1, index2)); |
| 5522 | __ str(tmp3, MemOperand(tmp1, index2)); |
| 5523 | __ str(tmp2, MemOperand(tmp1, index1)); |
| 5524 | |
| 5525 | Label done; |
| 5526 | __ InNewSpace(tmp1, tmp2, eq, &done); |
| 5527 | // Possible optimization: do a check that both values are Smis |
| 5528 | // (or them and test against Smi mask.) |
| 5529 | |
| 5530 | __ mov(tmp2, tmp1); |
| 5531 | RecordWriteStub recordWrite1(tmp1, index1, tmp3); |
| 5532 | __ CallStub(&recordWrite1); |
| 5533 | |
| 5534 | RecordWriteStub recordWrite2(tmp2, index2, tmp3); |
| 5535 | __ CallStub(&recordWrite2); |
| 5536 | |
| 5537 | __ bind(&done); |
| 5538 | |
| 5539 | deferred->BindExit(); |
| 5540 | __ LoadRoot(tmp1, Heap::kUndefinedValueRootIndex); |
| 5541 | frame_->EmitPush(tmp1); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5545 | void CodeGenerator::GenerateCallFunction(ZoneList<Expression*>* args) { |
| 5546 | Comment cmnt(masm_, "[ GenerateCallFunction"); |
| 5547 | |
| 5548 | ASSERT(args->length() >= 2); |
| 5549 | |
| 5550 | int n_args = args->length() - 2; // for receiver and function. |
| 5551 | Load(args->at(0)); // receiver |
| 5552 | for (int i = 0; i < n_args; i++) { |
| 5553 | Load(args->at(i + 1)); |
| 5554 | } |
| 5555 | Load(args->at(n_args + 1)); // function |
| 5556 | frame_->CallJSFunction(n_args); |
| 5557 | frame_->EmitPush(r0); |
| 5558 | } |
| 5559 | |
| 5560 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5561 | void CodeGenerator::GenerateMathSin(ZoneList<Expression*>* args) { |
| 5562 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5563 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5564 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5565 | TranscendentalCacheStub stub(TranscendentalCache::SIN); |
| 5566 | frame_->SpillAllButCopyTOSToR0(); |
| 5567 | frame_->CallStub(&stub, 1); |
| 5568 | } else { |
| 5569 | frame_->CallRuntime(Runtime::kMath_sin, 1); |
| 5570 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5571 | frame_->EmitPush(r0); |
| 5572 | } |
| 5573 | |
| 5574 | |
| 5575 | void CodeGenerator::GenerateMathCos(ZoneList<Expression*>* args) { |
| 5576 | ASSERT_EQ(args->length(), 1); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5577 | Load(args->at(0)); |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 5578 | if (CpuFeatures::IsSupported(VFP3)) { |
| 5579 | TranscendentalCacheStub stub(TranscendentalCache::COS); |
| 5580 | frame_->SpillAllButCopyTOSToR0(); |
| 5581 | frame_->CallStub(&stub, 1); |
| 5582 | } else { |
| 5583 | frame_->CallRuntime(Runtime::kMath_cos, 1); |
| 5584 | } |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5585 | frame_->EmitPush(r0); |
| 5586 | } |
| 5587 | |
| 5588 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5589 | void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5590 | ASSERT(args->length() == 2); |
| 5591 | |
| 5592 | // Load the two objects into registers and perform the comparison. |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5593 | Load(args->at(0)); |
| 5594 | Load(args->at(1)); |
| 5595 | Register lhs = frame_->PopToRegister(); |
| 5596 | Register rhs = frame_->PopToRegister(lhs); |
| 5597 | __ cmp(lhs, rhs); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5598 | cc_reg_ = eq; |
| 5599 | } |
| 5600 | |
| 5601 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5602 | void CodeGenerator::GenerateIsRegExpEquivalent(ZoneList<Expression*>* args) { |
| 5603 | ASSERT(args->length() == 2); |
| 5604 | |
| 5605 | // Load the two objects into registers and perform the comparison. |
| 5606 | Load(args->at(0)); |
| 5607 | Load(args->at(1)); |
| 5608 | Register right = frame_->PopToRegister(); |
| 5609 | Register left = frame_->PopToRegister(right); |
| 5610 | Register tmp = frame_->scratch0(); |
| 5611 | Register tmp2 = frame_->scratch1(); |
| 5612 | |
| 5613 | // Jumps to done must have the eq flag set if the test is successful |
| 5614 | // and clear if the test has failed. |
| 5615 | Label done; |
| 5616 | |
| 5617 | // Fail if either is a non-HeapObject. |
| 5618 | __ cmp(left, Operand(right)); |
| 5619 | __ b(eq, &done); |
| 5620 | __ and_(tmp, left, Operand(right)); |
| 5621 | __ eor(tmp, tmp, Operand(kSmiTagMask)); |
| 5622 | __ tst(tmp, Operand(kSmiTagMask)); |
| 5623 | __ b(ne, &done); |
| 5624 | __ ldr(tmp, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 5625 | __ ldrb(tmp2, FieldMemOperand(tmp, Map::kInstanceTypeOffset)); |
| 5626 | __ cmp(tmp2, Operand(JS_REGEXP_TYPE)); |
| 5627 | __ b(ne, &done); |
| 5628 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 5629 | __ cmp(tmp, Operand(tmp2)); |
| 5630 | __ b(ne, &done); |
| 5631 | __ ldr(tmp, FieldMemOperand(left, JSRegExp::kDataOffset)); |
| 5632 | __ ldr(tmp2, FieldMemOperand(right, JSRegExp::kDataOffset)); |
| 5633 | __ cmp(tmp, tmp2); |
| 5634 | __ bind(&done); |
| 5635 | cc_reg_ = eq; |
| 5636 | } |
| 5637 | |
| 5638 | |
| 5639 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5640 | void CodeGenerator::VisitCallRuntime(CallRuntime* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5641 | #ifdef DEBUG |
| 5642 | int original_height = frame_->height(); |
| 5643 | #endif |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5644 | if (CheckForInlineRuntimeCall(node)) { |
| 5645 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 5646 | (!has_cc() && frame_->height() == original_height + 1)); |
| 5647 | return; |
| 5648 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5649 | |
| 5650 | ZoneList<Expression*>* args = node->arguments(); |
| 5651 | Comment cmnt(masm_, "[ CallRuntime"); |
| 5652 | Runtime::Function* function = node->function(); |
| 5653 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5654 | if (function == NULL) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5655 | // Prepare stack for calling JS runtime function. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5656 | // Push the builtins object found in the current global object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5657 | Register scratch = VirtualFrame::scratch0(); |
| 5658 | __ ldr(scratch, GlobalObject()); |
| 5659 | Register builtins = frame_->GetTOSRegister(); |
| 5660 | __ ldr(builtins, FieldMemOperand(scratch, GlobalObject::kBuiltinsOffset)); |
| 5661 | frame_->EmitPush(builtins); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5662 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5663 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5664 | // Push the arguments ("left-to-right"). |
| 5665 | int arg_count = args->length(); |
| 5666 | for (int i = 0; i < arg_count; i++) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5667 | Load(args->at(i)); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5668 | } |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5669 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5670 | VirtualFrame::SpilledScope spilled_scope(frame_); |
| 5671 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5672 | if (function == NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5673 | // Call the JS runtime function. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 5674 | __ mov(r2, Operand(node->name())); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5675 | InLoopFlag in_loop = loop_nesting() > 0 ? IN_LOOP : NOT_IN_LOOP; |
| 5676 | Handle<Code> stub = ComputeCallInitialize(arg_count, in_loop); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5677 | frame_->CallCodeObject(stub, RelocInfo::CODE_TARGET, arg_count + 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5678 | __ ldr(cp, frame_->Context()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5679 | frame_->EmitPush(r0); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 5680 | } else { |
| 5681 | // Call the C runtime function. |
| 5682 | frame_->CallRuntime(function, arg_count); |
| 5683 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5684 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5685 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5689 | void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5690 | #ifdef DEBUG |
| 5691 | int original_height = frame_->height(); |
| 5692 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5693 | Comment cmnt(masm_, "[ UnaryOperation"); |
| 5694 | |
| 5695 | Token::Value op = node->op(); |
| 5696 | |
| 5697 | if (op == Token::NOT) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5698 | LoadCondition(node->expression(), false_target(), true_target(), true); |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5699 | // LoadCondition may (and usually does) leave a test and branch to |
| 5700 | // be emitted by the caller. In that case, negate the condition. |
| 5701 | if (has_cc()) cc_reg_ = NegateCondition(cc_reg_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5702 | |
| 5703 | } else if (op == Token::DELETE) { |
| 5704 | Property* property = node->expression()->AsProperty(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5705 | Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5706 | if (property != NULL) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5707 | Load(property->obj()); |
| 5708 | Load(property->key()); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5709 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5710 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5711 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5712 | } else if (variable != NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5713 | Slot* slot = variable->slot(); |
| 5714 | if (variable->is_global()) { |
| 5715 | LoadGlobal(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5716 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5717 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5718 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5719 | |
| 5720 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 5721 | // lookup the context holding the named variable |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5722 | frame_->EmitPush(cp); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5723 | frame_->EmitPush(Operand(variable->name())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5724 | frame_->CallRuntime(Runtime::kLookupContext, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5725 | // r0: context |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5726 | frame_->EmitPush(r0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5727 | frame_->EmitPush(Operand(variable->name())); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5728 | frame_->InvokeBuiltin(Builtins::DELETE, CALL_JS, 2); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5729 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5730 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5731 | } else { |
| 5732 | // Default: Result of deleting non-global, not dynamically |
| 5733 | // introduced variables is false. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5734 | frame_->EmitPushRoot(Heap::kFalseValueRootIndex); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5735 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5736 | |
| 5737 | } else { |
| 5738 | // Default: Result of deleting expressions is true. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5739 | Load(node->expression()); // may have side-effects |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5740 | frame_->Drop(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5741 | frame_->EmitPushRoot(Heap::kTrueValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5742 | } |
| 5743 | |
| 5744 | } else if (op == Token::TYPEOF) { |
| 5745 | // Special case for loading the typeof expression; see comment on |
| 5746 | // LoadTypeofExpression(). |
| 5747 | LoadTypeofExpression(node->expression()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5748 | frame_->CallRuntime(Runtime::kTypeof, 1); |
| 5749 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5750 | |
| 5751 | } else { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 5752 | bool can_overwrite = node->expression()->ResultOverwriteAllowed(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5753 | UnaryOverwriteMode overwrite = |
| 5754 | can_overwrite ? UNARY_OVERWRITE : UNARY_NO_OVERWRITE; |
| 5755 | |
| 5756 | bool no_negative_zero = node->expression()->no_negative_zero(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5757 | Load(node->expression()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5758 | switch (op) { |
| 5759 | case Token::NOT: |
| 5760 | case Token::DELETE: |
| 5761 | case Token::TYPEOF: |
| 5762 | UNREACHABLE(); // handled above |
| 5763 | break; |
| 5764 | |
| 5765 | case Token::SUB: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5766 | frame_->PopToR0(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 5767 | GenericUnaryOpStub stub( |
| 5768 | Token::SUB, |
| 5769 | overwrite, |
| 5770 | no_negative_zero ? kIgnoreNegativeZero : kStrictNegativeZero); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5771 | frame_->CallStub(&stub, 0); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5772 | frame_->EmitPush(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5773 | break; |
| 5774 | } |
| 5775 | |
| 5776 | case Token::BIT_NOT: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5777 | Register tos = frame_->PopToRegister(); |
| 5778 | JumpTarget not_smi_label; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5779 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5780 | // Smi check. |
| 5781 | __ tst(tos, Operand(kSmiTagMask)); |
| 5782 | not_smi_label.Branch(ne); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5783 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5784 | __ mvn(tos, Operand(tos)); |
| 5785 | __ bic(tos, tos, Operand(kSmiTagMask)); // Bit-clear inverted smi-tag. |
| 5786 | frame_->EmitPush(tos); |
| 5787 | // The fast case is the first to jump to the continue label, so it gets |
| 5788 | // to decide the virtual frame layout. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5789 | continue_label.Jump(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5790 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5791 | not_smi_label.Bind(); |
| 5792 | frame_->SpillAll(); |
| 5793 | __ Move(r0, tos); |
| 5794 | GenericUnaryOpStub stub(Token::BIT_NOT, overwrite); |
| 5795 | frame_->CallStub(&stub, 0); |
| 5796 | frame_->EmitPush(r0); |
| 5797 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5798 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5799 | break; |
| 5800 | } |
| 5801 | |
| 5802 | case Token::VOID: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5803 | frame_->Drop(); |
| 5804 | frame_->EmitPushRoot(Heap::kUndefinedValueRootIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5805 | break; |
| 5806 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5807 | case Token::ADD: { |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5808 | Register tos = frame_->Peek(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5809 | // Smi check. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5810 | JumpTarget continue_label; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5811 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5812 | continue_label.Branch(eq); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5813 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5814 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5815 | frame_->EmitPush(r0); |
| 5816 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5817 | continue_label.Bind(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5818 | break; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5819 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5820 | default: |
| 5821 | UNREACHABLE(); |
| 5822 | } |
| 5823 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5824 | ASSERT(!has_valid_frame() || |
| 5825 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5826 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5830 | void CodeGenerator::VisitCountOperation(CountOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5831 | #ifdef DEBUG |
| 5832 | int original_height = frame_->height(); |
| 5833 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5834 | Comment cmnt(masm_, "[ CountOperation"); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 5835 | VirtualFrame::RegisterAllocationScope scope(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5836 | |
| 5837 | bool is_postfix = node->is_postfix(); |
| 5838 | bool is_increment = node->op() == Token::INC; |
| 5839 | |
| 5840 | Variable* var = node->expression()->AsVariableProxy()->AsVariable(); |
| 5841 | bool is_const = (var != NULL && var->mode() == Variable::CONST); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5842 | bool is_slot = (var != NULL && var->mode() == Variable::VAR); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5843 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5844 | if (!is_const && is_slot && type_info(var->slot()).IsSmi()) { |
| 5845 | // The type info declares that this variable is always a Smi. That |
| 5846 | // means it is a Smi both before and after the increment/decrement. |
| 5847 | // Lets make use of that to make a very minimal count. |
| 5848 | Reference target(this, node->expression(), !is_const); |
| 5849 | ASSERT(!target.is_illegal()); |
| 5850 | target.GetValue(); // Pushes the value. |
| 5851 | Register value = frame_->PopToRegister(); |
| 5852 | if (is_postfix) frame_->EmitPush(value); |
| 5853 | if (is_increment) { |
| 5854 | __ add(value, value, Operand(Smi::FromInt(1))); |
| 5855 | } else { |
| 5856 | __ sub(value, value, Operand(Smi::FromInt(1))); |
| 5857 | } |
| 5858 | frame_->EmitPush(value); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5859 | target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5860 | if (is_postfix) frame_->Pop(); |
| 5861 | ASSERT_EQ(original_height + 1, frame_->height()); |
| 5862 | return; |
| 5863 | } |
| 5864 | |
| 5865 | // If it's a postfix expression and its result is not ignored and the |
| 5866 | // reference is non-trivial, then push a placeholder on the stack now |
| 5867 | // to hold the result of the expression. |
| 5868 | bool placeholder_pushed = false; |
| 5869 | if (!is_slot && is_postfix) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5870 | frame_->EmitPush(Operand(Smi::FromInt(0))); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5871 | placeholder_pushed = true; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5872 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5873 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5874 | // A constant reference is not saved to, so a constant reference is not a |
| 5875 | // compound assignment reference. |
| 5876 | { Reference target(this, node->expression(), !is_const); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5877 | if (target.is_illegal()) { |
| 5878 | // Spoof the virtual frame to have the expected height (one higher |
| 5879 | // than on entry). |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5880 | if (!placeholder_pushed) frame_->EmitPush(Operand(Smi::FromInt(0))); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5881 | ASSERT_EQ(original_height + 1, frame_->height()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5882 | return; |
| 5883 | } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5884 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5885 | // This pushes 0, 1 or 2 words on the object to be used later when updating |
| 5886 | // the target. It also pushes the current value of the target. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 5887 | target.GetValue(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5888 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5889 | JumpTarget slow; |
| 5890 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5891 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5892 | Register value = frame_->PopToRegister(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5893 | |
| 5894 | // Postfix: Store the old value as the result. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5895 | if (placeholder_pushed) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5896 | frame_->SetElementAt(value, target.size()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5897 | } else if (is_postfix) { |
| 5898 | frame_->EmitPush(value); |
| 5899 | __ mov(VirtualFrame::scratch0(), value); |
| 5900 | value = VirtualFrame::scratch0(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 5901 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5902 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5903 | // Check for smi operand. |
| 5904 | __ tst(value, Operand(kSmiTagMask)); |
| 5905 | slow.Branch(ne); |
| 5906 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5907 | // Perform optimistic increment/decrement. |
| 5908 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5909 | __ add(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5910 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5911 | __ sub(value, value, Operand(Smi::FromInt(1)), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | // If the increment/decrement didn't overflow, we're done. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5915 | exit.Branch(vc); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5916 | |
| 5917 | // Revert optimistic increment/decrement. |
| 5918 | if (is_increment) { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5919 | __ sub(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5920 | } else { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5921 | __ add(value, value, Operand(Smi::FromInt(1))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5922 | } |
| 5923 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5924 | // Slow case: Convert to number. At this point the |
| 5925 | // value to be incremented is in the value register.. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5926 | slow.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5927 | |
| 5928 | // Convert the operand to a number. |
| 5929 | frame_->EmitPush(value); |
| 5930 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 5931 | { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5932 | VirtualFrame::SpilledScope spilled(frame_); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 5933 | frame_->InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS, 1); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5934 | |
| 5935 | if (is_postfix) { |
| 5936 | // Postfix: store to result (on the stack). |
| 5937 | __ str(r0, frame_->ElementAt(target.size())); |
| 5938 | } |
| 5939 | |
| 5940 | // Compute the new value. |
| 5941 | frame_->EmitPush(r0); |
| 5942 | frame_->EmitPush(Operand(Smi::FromInt(1))); |
| 5943 | if (is_increment) { |
| 5944 | frame_->CallRuntime(Runtime::kNumberAdd, 2); |
| 5945 | } else { |
| 5946 | frame_->CallRuntime(Runtime::kNumberSub, 2); |
| 5947 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5950 | __ Move(value, r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5951 | // Store the new value in the target if not const. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5952 | // At this point the answer is in the value register. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5953 | exit.Bind(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5954 | frame_->EmitPush(value); |
| 5955 | // Set the target with the result, leaving the result on |
| 5956 | // top of the stack. Removes the target from the stack if |
| 5957 | // it has a non-zero size. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 5958 | if (!is_const) target.SetValue(NOT_CONST_INIT, LIKELY_SMI); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5959 | } |
| 5960 | |
| 5961 | // Postfix: Discard the new value and use the old. |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 5962 | if (is_postfix) frame_->Pop(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5963 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5967 | void CodeGenerator::GenerateLogicalBooleanOperation(BinaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5968 | // According to ECMA-262 section 11.11, page 58, the binary logical |
| 5969 | // operators must yield the result of one of the two expressions |
| 5970 | // before any ToBoolean() conversions. This means that the value |
| 5971 | // produced by a && or || operator is not necessarily a boolean. |
| 5972 | |
| 5973 | // NOTE: If the left hand side produces a materialized value (not in |
| 5974 | // the CC register), we force the right hand side to do the |
| 5975 | // same. This is necessary because we may have to branch to the exit |
| 5976 | // after evaluating the left hand side (due to the shortcut |
| 5977 | // semantics), but the compiler must (statically) know if the result |
| 5978 | // of compiling the binary operation is materialized or not. |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 5979 | if (node->op() == Token::AND) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5980 | JumpTarget is_true; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5981 | LoadCondition(node->left(), &is_true, false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 5982 | if (has_valid_frame() && !has_cc()) { |
| 5983 | // 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] | 5984 | JumpTarget pop_and_continue; |
| 5985 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5986 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5987 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5988 | // Avoid popping the result if it converts to 'false' using the |
| 5989 | // standard ToBoolean() conversion as described in ECMA-262, |
| 5990 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5991 | ToBoolean(&pop_and_continue, &exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5992 | Branch(false, &exit); |
| 5993 | |
| 5994 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5995 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 5996 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5997 | |
| 5998 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5999 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6000 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6001 | |
| 6002 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6003 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6004 | } else if (has_cc() || is_true.is_linked()) { |
| 6005 | // The left-hand side is either (a) partially compiled to |
| 6006 | // control flow with a final branch left to emit or (b) fully |
| 6007 | // compiled to control flow and possibly true. |
| 6008 | if (has_cc()) { |
| 6009 | Branch(false, false_target()); |
| 6010 | } |
| 6011 | is_true.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6012 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6013 | } else { |
| 6014 | // Nothing to do. |
| 6015 | ASSERT(!has_valid_frame() && !has_cc() && !is_true.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6016 | } |
| 6017 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6018 | } else { |
| 6019 | ASSERT(node->op() == Token::OR); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6020 | JumpTarget is_false; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6021 | LoadCondition(node->left(), true_target(), &is_false, false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6022 | if (has_valid_frame() && !has_cc()) { |
| 6023 | // 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] | 6024 | JumpTarget pop_and_continue; |
| 6025 | JumpTarget exit; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6026 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6027 | frame_->Dup(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6028 | // Avoid popping the result if it converts to 'true' using the |
| 6029 | // standard ToBoolean() conversion as described in ECMA-262, |
| 6030 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6031 | ToBoolean(&exit, &pop_and_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6032 | Branch(true, &exit); |
| 6033 | |
| 6034 | // Pop the result of evaluating the first part. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6035 | pop_and_continue.Bind(); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6036 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6037 | |
| 6038 | // Evaluate right side expression. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6039 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6040 | Load(node->right()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6041 | |
| 6042 | // Exit (always with a materialized value). |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6043 | exit.Bind(); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6044 | } else if (has_cc() || is_false.is_linked()) { |
| 6045 | // The left-hand side is either (a) partially compiled to |
| 6046 | // control flow with a final branch left to emit or (b) fully |
| 6047 | // compiled to control flow and possibly false. |
| 6048 | if (has_cc()) { |
| 6049 | Branch(true, true_target()); |
| 6050 | } |
| 6051 | is_false.Bind(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6052 | LoadCondition(node->right(), true_target(), false_target(), false); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6053 | } else { |
| 6054 | // Nothing to do. |
| 6055 | ASSERT(!has_valid_frame() && !has_cc() && !is_false.is_linked()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6056 | } |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6057 | } |
| 6058 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6059 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6060 | |
| 6061 | void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) { |
| 6062 | #ifdef DEBUG |
| 6063 | int original_height = frame_->height(); |
| 6064 | #endif |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 6065 | Comment cmnt(masm_, "[ BinaryOperation"); |
| 6066 | |
| 6067 | if (node->op() == Token::AND || node->op() == Token::OR) { |
| 6068 | GenerateLogicalBooleanOperation(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6069 | } else { |
| 6070 | // Optimize for the case where (at least) one of the expressions |
| 6071 | // is a literal small integer. |
| 6072 | Literal* lliteral = node->left()->AsLiteral(); |
| 6073 | Literal* rliteral = node->right()->AsLiteral(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6074 | // NOTE: The code below assumes that the slow cases (calls to runtime) |
| 6075 | // never return a constant/immutable object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 6076 | bool overwrite_left = node->left()->ResultOverwriteAllowed(); |
| 6077 | bool overwrite_right = node->right()->ResultOverwriteAllowed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6078 | |
| 6079 | if (rliteral != NULL && rliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6080 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6081 | Load(node->left()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6082 | if (frame_->KnownSmiAt(0)) overwrite_left = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6083 | SmiOperation(node->op(), |
| 6084 | rliteral->handle(), |
| 6085 | false, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6086 | overwrite_left ? OVERWRITE_LEFT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6087 | } else if (lliteral != NULL && lliteral->handle()->IsSmi()) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6088 | VirtualFrame::RegisterAllocationScope scope(this); |
| 6089 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6090 | if (frame_->KnownSmiAt(0)) overwrite_right = false; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 6091 | SmiOperation(node->op(), |
| 6092 | lliteral->handle(), |
| 6093 | true, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6094 | overwrite_right ? OVERWRITE_RIGHT : NO_OVERWRITE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6095 | } else { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6096 | GenerateInlineSmi inline_smi = |
| 6097 | loop_nesting() > 0 ? GENERATE_INLINE_SMI : DONT_GENERATE_INLINE_SMI; |
| 6098 | if (lliteral != NULL) { |
| 6099 | ASSERT(!lliteral->handle()->IsSmi()); |
| 6100 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6101 | } |
| 6102 | if (rliteral != NULL) { |
| 6103 | ASSERT(!rliteral->handle()->IsSmi()); |
| 6104 | inline_smi = DONT_GENERATE_INLINE_SMI; |
| 6105 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6106 | VirtualFrame::RegisterAllocationScope scope(this); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6107 | OverwriteMode overwrite_mode = NO_OVERWRITE; |
| 6108 | if (overwrite_left) { |
| 6109 | overwrite_mode = OVERWRITE_LEFT; |
| 6110 | } else if (overwrite_right) { |
| 6111 | overwrite_mode = OVERWRITE_RIGHT; |
| 6112 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6113 | Load(node->left()); |
| 6114 | Load(node->right()); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6115 | GenericBinaryOperation(node->op(), overwrite_mode, inline_smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6116 | } |
| 6117 | } |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 6118 | ASSERT(!has_valid_frame() || |
| 6119 | (has_cc() && frame_->height() == original_height) || |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6120 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6124 | void CodeGenerator::VisitThisFunction(ThisFunction* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6125 | #ifdef DEBUG |
| 6126 | int original_height = frame_->height(); |
| 6127 | #endif |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 6128 | frame_->EmitPush(MemOperand(frame_->Function())); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6129 | ASSERT_EQ(original_height + 1, frame_->height()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6130 | } |
| 6131 | |
| 6132 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6133 | void CodeGenerator::VisitCompareOperation(CompareOperation* node) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6134 | #ifdef DEBUG |
| 6135 | int original_height = frame_->height(); |
| 6136 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6137 | Comment cmnt(masm_, "[ CompareOperation"); |
| 6138 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6139 | VirtualFrame::RegisterAllocationScope nonspilled_scope(this); |
| 6140 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6141 | // Get the expressions from the node. |
| 6142 | Expression* left = node->left(); |
| 6143 | Expression* right = node->right(); |
| 6144 | Token::Value op = node->op(); |
| 6145 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6146 | // To make typeof testing for natives implemented in JavaScript really |
| 6147 | // efficient, we generate special code for expressions of the form: |
| 6148 | // 'typeof <expression> == <string>'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6149 | UnaryOperation* operation = left->AsUnaryOperation(); |
| 6150 | if ((op == Token::EQ || op == Token::EQ_STRICT) && |
| 6151 | (operation != NULL && operation->op() == Token::TYPEOF) && |
| 6152 | (right->AsLiteral() != NULL && |
| 6153 | right->AsLiteral()->handle()->IsString())) { |
| 6154 | Handle<String> check(String::cast(*right->AsLiteral()->handle())); |
| 6155 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6156 | // Load the operand, move it to a register. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6157 | LoadTypeofExpression(operation->expression()); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6158 | Register tos = frame_->PopToRegister(); |
| 6159 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6160 | Register scratch = VirtualFrame::scratch0(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6161 | |
| 6162 | if (check->Equals(Heap::number_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6163 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6164 | true_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6165 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6166 | __ LoadRoot(ip, Heap::kHeapNumberMapRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6167 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6168 | cc_reg_ = eq; |
| 6169 | |
| 6170 | } else if (check->Equals(Heap::string_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6171 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6172 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6173 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6174 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6175 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6176 | // It can be an undetectable string object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6177 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6178 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6179 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6180 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6181 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6182 | __ ldrb(scratch, FieldMemOperand(tos, Map::kInstanceTypeOffset)); |
| 6183 | __ cmp(scratch, Operand(FIRST_NONSTRING_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6184 | cc_reg_ = lt; |
| 6185 | |
| 6186 | } else if (check->Equals(Heap::boolean_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6187 | __ LoadRoot(ip, Heap::kTrueValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6188 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6189 | true_target()->Branch(eq); |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6190 | __ LoadRoot(ip, Heap::kFalseValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6191 | __ cmp(tos, ip); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6192 | cc_reg_ = eq; |
| 6193 | |
| 6194 | } else if (check->Equals(Heap::undefined_symbol())) { |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6195 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6196 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6197 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6198 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6199 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6200 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6201 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6202 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6203 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6204 | __ ldrb(scratch, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6205 | __ and_(scratch, scratch, Operand(1 << Map::kIsUndetectable)); |
| 6206 | __ cmp(scratch, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6207 | |
| 6208 | cc_reg_ = eq; |
| 6209 | |
| 6210 | } else if (check->Equals(Heap::function_symbol())) { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6211 | __ tst(tos, Operand(kSmiTagMask)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6212 | false_target()->Branch(eq); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6213 | Register map_reg = scratch; |
| 6214 | __ CompareObjectType(tos, map_reg, tos, JS_FUNCTION_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6215 | true_target()->Branch(eq); |
| 6216 | // Regular expressions are callable so typeof == 'function'. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6217 | __ CompareInstanceType(map_reg, tos, JS_REGEXP_TYPE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6218 | cc_reg_ = eq; |
| 6219 | |
| 6220 | } else if (check->Equals(Heap::object_symbol())) { |
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 | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 6224 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6225 | __ cmp(tos, ip); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6226 | true_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6227 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6228 | Register map_reg = scratch; |
| 6229 | __ CompareObjectType(tos, map_reg, tos, JS_REGEXP_TYPE); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6230 | false_target()->Branch(eq); |
| 6231 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6232 | // It can be an undetectable object. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6233 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kBitFieldOffset)); |
| 6234 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6235 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6236 | false_target()->Branch(eq); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6237 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6238 | __ ldrb(tos, FieldMemOperand(map_reg, Map::kInstanceTypeOffset)); |
| 6239 | __ cmp(tos, Operand(FIRST_JS_OBJECT_TYPE)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6240 | false_target()->Branch(lt); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 6241 | __ cmp(tos, Operand(LAST_JS_OBJECT_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6242 | cc_reg_ = le; |
| 6243 | |
| 6244 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 6245 | // Uncommon case: typeof testing against a string literal that is |
| 6246 | // never returned from the typeof operator. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6247 | false_target()->Jump(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6248 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6249 | ASSERT(!has_valid_frame() || |
| 6250 | (has_cc() && frame_->height() == original_height)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6251 | return; |
| 6252 | } |
| 6253 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6254 | switch (op) { |
| 6255 | case Token::EQ: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6256 | Comparison(eq, left, right, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6257 | break; |
| 6258 | |
| 6259 | case Token::LT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6260 | Comparison(lt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6261 | break; |
| 6262 | |
| 6263 | case Token::GT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6264 | Comparison(gt, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6265 | break; |
| 6266 | |
| 6267 | case Token::LTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6268 | Comparison(le, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6269 | break; |
| 6270 | |
| 6271 | case Token::GTE: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6272 | Comparison(ge, left, right); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6273 | break; |
| 6274 | |
| 6275 | case Token::EQ_STRICT: |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6276 | Comparison(eq, left, right, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6277 | break; |
| 6278 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6279 | case Token::IN: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6280 | Load(left); |
| 6281 | Load(right); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 6282 | frame_->InvokeBuiltin(Builtins::IN, CALL_JS, 2); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6283 | frame_->EmitPush(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6284 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6285 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6286 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6287 | case Token::INSTANCEOF: { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6288 | Load(left); |
| 6289 | Load(right); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6290 | InstanceofStub stub; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6291 | frame_->CallStub(&stub, 2); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6292 | // At this point if instanceof succeeded then r0 == 0. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 6293 | __ tst(r0, Operand(r0)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6294 | cc_reg_ = eq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6295 | break; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6296 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6297 | |
| 6298 | default: |
| 6299 | UNREACHABLE(); |
| 6300 | } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6301 | ASSERT((has_cc() && frame_->height() == original_height) || |
| 6302 | (!has_cc() && frame_->height() == original_height + 1)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6303 | } |
| 6304 | |
| 6305 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame^] | 6306 | void CodeGenerator::VisitCompareToNull(CompareToNull* node) { |
| 6307 | #ifdef DEBUG |
| 6308 | int original_height = frame_->height(); |
| 6309 | #endif |
| 6310 | Comment cmnt(masm_, "[ CompareToNull"); |
| 6311 | |
| 6312 | Load(node->expression()); |
| 6313 | Register tos = frame_->PopToRegister(); |
| 6314 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 6315 | __ cmp(tos, ip); |
| 6316 | |
| 6317 | // The 'null' value is only equal to 'undefined' if using non-strict |
| 6318 | // comparisons. |
| 6319 | if (!node->is_strict()) { |
| 6320 | true_target()->Branch(eq); |
| 6321 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 6322 | __ cmp(tos, Operand(ip)); |
| 6323 | true_target()->Branch(eq); |
| 6324 | |
| 6325 | __ tst(tos, Operand(kSmiTagMask)); |
| 6326 | false_target()->Branch(eq); |
| 6327 | |
| 6328 | // It can be an undetectable object. |
| 6329 | __ ldr(tos, FieldMemOperand(tos, HeapObject::kMapOffset)); |
| 6330 | __ ldrb(tos, FieldMemOperand(tos, Map::kBitFieldOffset)); |
| 6331 | __ and_(tos, tos, Operand(1 << Map::kIsUndetectable)); |
| 6332 | __ cmp(tos, Operand(1 << Map::kIsUndetectable)); |
| 6333 | } |
| 6334 | |
| 6335 | cc_reg_ = eq; |
| 6336 | ASSERT(has_cc() && frame_->height() == original_height); |
| 6337 | } |
| 6338 | |
| 6339 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6340 | class DeferredReferenceGetNamedValue: public DeferredCode { |
| 6341 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6342 | explicit DeferredReferenceGetNamedValue(Register receiver, |
| 6343 | Handle<String> name) |
| 6344 | : receiver_(receiver), name_(name) { |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6345 | set_comment("[ DeferredReferenceGetNamedValue"); |
| 6346 | } |
| 6347 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6348 | virtual void Generate(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6349 | |
| 6350 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6351 | Register receiver_; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6352 | Handle<String> name_; |
| 6353 | }; |
| 6354 | |
| 6355 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6356 | // Convention for this is that on entry the receiver is in a register that |
| 6357 | // is not used by the stack. On exit the answer is found in that same |
| 6358 | // register and the stack has the same height. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6359 | void DeferredReferenceGetNamedValue::Generate() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6360 | #ifdef DEBUG |
| 6361 | int expected_height = frame_state()->frame()->height(); |
| 6362 | #endif |
| 6363 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6364 | copied_frame.SpillAll(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6365 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6366 | Register scratch1 = VirtualFrame::scratch0(); |
| 6367 | Register scratch2 = VirtualFrame::scratch1(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6368 | ASSERT(!receiver_.is(scratch1) && !receiver_.is(scratch2)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6369 | __ DecrementCounter(&Counters::named_load_inline, 1, scratch1, scratch2); |
| 6370 | __ IncrementCounter(&Counters::named_load_inline_miss, 1, scratch1, scratch2); |
| 6371 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6372 | // Ensure receiver in r0 and name in r2 to match load ic calling convention. |
| 6373 | __ Move(r0, receiver_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6374 | __ mov(r2, Operand(name_)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6375 | |
| 6376 | // The rest of the instructions in the deferred code must be together. |
| 6377 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6378 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 6379 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6380 | // The call must be followed by a nop(1) instruction to indicate that the |
| 6381 | // in-object has been inlined. |
| 6382 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6383 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6384 | // At this point the answer is in r0. We move it to the expected register |
| 6385 | // if necessary. |
| 6386 | __ Move(receiver_, r0); |
| 6387 | |
| 6388 | // Now go back to the frame that we entered with. This will not overwrite |
| 6389 | // the receiver register since that register was not in use when we came |
| 6390 | // in. The instructions emitted by this merge are skipped over by the |
| 6391 | // inline load patching mechanism when looking for the branch instruction |
| 6392 | // that tells it where the code to patch is. |
| 6393 | copied_frame.MergeTo(frame_state()->frame()); |
| 6394 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6395 | // Block the constant pool for one more instruction after leaving this |
| 6396 | // constant pool block scope to include the branch instruction ending the |
| 6397 | // deferred code. |
| 6398 | __ BlockConstPoolFor(1); |
| 6399 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6400 | ASSERT_EQ(expected_height, frame_state()->frame()->height()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6401 | } |
| 6402 | |
| 6403 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6404 | class DeferredReferenceGetKeyedValue: public DeferredCode { |
| 6405 | public: |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6406 | DeferredReferenceGetKeyedValue(Register key, Register receiver) |
| 6407 | : key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6408 | set_comment("[ DeferredReferenceGetKeyedValue"); |
| 6409 | } |
| 6410 | |
| 6411 | virtual void Generate(); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6412 | |
| 6413 | private: |
| 6414 | Register key_; |
| 6415 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6416 | }; |
| 6417 | |
| 6418 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6419 | // Takes key and register in r0 and r1 or vice versa. Returns result |
| 6420 | // in r0. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6421 | void DeferredReferenceGetKeyedValue::Generate() { |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6422 | ASSERT((key_.is(r0) && receiver_.is(r1)) || |
| 6423 | (key_.is(r1) && receiver_.is(r0))); |
| 6424 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6425 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6426 | copied_frame.SpillAll(); |
| 6427 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6428 | Register scratch1 = VirtualFrame::scratch0(); |
| 6429 | Register scratch2 = VirtualFrame::scratch1(); |
| 6430 | __ DecrementCounter(&Counters::keyed_load_inline, 1, scratch1, scratch2); |
| 6431 | __ IncrementCounter(&Counters::keyed_load_inline_miss, 1, scratch1, scratch2); |
| 6432 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6433 | // Ensure key in r0 and receiver in r1 to match keyed load ic calling |
| 6434 | // convention. |
| 6435 | if (key_.is(r1)) { |
| 6436 | __ Swap(r0, r1, ip); |
| 6437 | } |
| 6438 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6439 | // The rest of the instructions in the deferred code must be together. |
| 6440 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 6441 | // 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] | 6442 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 6443 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6444 | // The call must be followed by a nop instruction to indicate that the |
| 6445 | // keyed load has been inlined. |
| 6446 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6447 | |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6448 | // Now go back to the frame that we entered with. This will not overwrite |
| 6449 | // the receiver or key registers since they were not in use when we came |
| 6450 | // in. The instructions emitted by this merge are skipped over by the |
| 6451 | // inline load patching mechanism when looking for the branch instruction |
| 6452 | // that tells it where the code to patch is. |
| 6453 | copied_frame.MergeTo(frame_state()->frame()); |
| 6454 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6455 | // Block the constant pool for one more instruction after leaving this |
| 6456 | // constant pool block scope to include the branch instruction ending the |
| 6457 | // deferred code. |
| 6458 | __ BlockConstPoolFor(1); |
| 6459 | } |
| 6460 | } |
| 6461 | |
| 6462 | |
| 6463 | class DeferredReferenceSetKeyedValue: public DeferredCode { |
| 6464 | public: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6465 | DeferredReferenceSetKeyedValue(Register value, |
| 6466 | Register key, |
| 6467 | Register receiver) |
| 6468 | : value_(value), key_(key), receiver_(receiver) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6469 | set_comment("[ DeferredReferenceSetKeyedValue"); |
| 6470 | } |
| 6471 | |
| 6472 | virtual void Generate(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6473 | |
| 6474 | private: |
| 6475 | Register value_; |
| 6476 | Register key_; |
| 6477 | Register receiver_; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6478 | }; |
| 6479 | |
| 6480 | |
| 6481 | void DeferredReferenceSetKeyedValue::Generate() { |
| 6482 | Register scratch1 = VirtualFrame::scratch0(); |
| 6483 | Register scratch2 = VirtualFrame::scratch1(); |
| 6484 | __ DecrementCounter(&Counters::keyed_store_inline, 1, scratch1, scratch2); |
| 6485 | __ IncrementCounter( |
| 6486 | &Counters::keyed_store_inline_miss, 1, scratch1, scratch2); |
| 6487 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6488 | // Ensure value in r0, key in r1 and receiver in r2 to match keyed store ic |
| 6489 | // calling convention. |
| 6490 | if (value_.is(r1)) { |
| 6491 | __ Swap(r0, r1, ip); |
| 6492 | } |
| 6493 | ASSERT(receiver_.is(r2)); |
| 6494 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6495 | // The rest of the instructions in the deferred code must be together. |
| 6496 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6497 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6498 | // r1 and r2. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6499 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 6500 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6501 | // The call must be followed by a nop instruction to indicate that the |
| 6502 | // keyed store has been inlined. |
| 6503 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6504 | |
| 6505 | // Block the constant pool for one more instruction after leaving this |
| 6506 | // constant pool block scope to include the branch instruction ending the |
| 6507 | // deferred code. |
| 6508 | __ BlockConstPoolFor(1); |
| 6509 | } |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6510 | } |
| 6511 | |
| 6512 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6513 | class DeferredReferenceSetNamedValue: public DeferredCode { |
| 6514 | public: |
| 6515 | DeferredReferenceSetNamedValue(Register value, |
| 6516 | Register receiver, |
| 6517 | Handle<String> name) |
| 6518 | : value_(value), receiver_(receiver), name_(name) { |
| 6519 | set_comment("[ DeferredReferenceSetNamedValue"); |
| 6520 | } |
| 6521 | |
| 6522 | virtual void Generate(); |
| 6523 | |
| 6524 | private: |
| 6525 | Register value_; |
| 6526 | Register receiver_; |
| 6527 | Handle<String> name_; |
| 6528 | }; |
| 6529 | |
| 6530 | |
| 6531 | // Takes value in r0, receiver in r1 and returns the result (the |
| 6532 | // value) in r0. |
| 6533 | void DeferredReferenceSetNamedValue::Generate() { |
| 6534 | // Record the entry frame and spill. |
| 6535 | VirtualFrame copied_frame(*frame_state()->frame()); |
| 6536 | copied_frame.SpillAll(); |
| 6537 | |
| 6538 | // Ensure value in r0, receiver in r1 to match store ic calling |
| 6539 | // convention. |
| 6540 | ASSERT(value_.is(r0) && receiver_.is(r1)); |
| 6541 | __ mov(r2, Operand(name_)); |
| 6542 | |
| 6543 | // The rest of the instructions in the deferred code must be together. |
| 6544 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6545 | // Call keyed store IC. It has the arguments value, key and receiver in r0, |
| 6546 | // r1 and r2. |
| 6547 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 6548 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 6549 | // The call must be followed by a nop instruction to indicate that the |
| 6550 | // named store has been inlined. |
| 6551 | __ nop(PROPERTY_ACCESS_INLINED); |
| 6552 | |
| 6553 | // Go back to the frame we entered with. The instructions |
| 6554 | // generated by this merge are skipped over by the inline store |
| 6555 | // patching mechanism when looking for the branch instruction that |
| 6556 | // tells it where the code to patch is. |
| 6557 | copied_frame.MergeTo(frame_state()->frame()); |
| 6558 | |
| 6559 | // Block the constant pool for one more instruction after leaving this |
| 6560 | // constant pool block scope to include the branch instruction ending the |
| 6561 | // deferred code. |
| 6562 | __ BlockConstPoolFor(1); |
| 6563 | } |
| 6564 | } |
| 6565 | |
| 6566 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6567 | // 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] | 6568 | void CodeGenerator::EmitNamedLoad(Handle<String> name, bool is_contextual) { |
| 6569 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6570 | Comment cmnt(masm(), "[ Load from named Property"); |
| 6571 | // Setup the name register and call load IC. |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6572 | frame_->CallLoadIC(name, |
| 6573 | is_contextual |
| 6574 | ? RelocInfo::CODE_TARGET_CONTEXT |
| 6575 | : RelocInfo::CODE_TARGET); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6576 | frame_->EmitPush(r0); // Push answer. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6577 | } else { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6578 | // Inline the in-object property case. |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6579 | Comment cmnt(masm(), "[ Inlined named property load"); |
| 6580 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6581 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6582 | // having it in the instruction stream below where patching will occur. |
| 6583 | __ IncrementCounter(&Counters::named_load_inline, 1, |
| 6584 | frame_->scratch0(), frame_->scratch1()); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6585 | |
| 6586 | // The following instructions are the inlined load of an in-object property. |
| 6587 | // Parts of this code is patched, so the exact instructions generated needs |
| 6588 | // to be fixed. Therefore the instruction pool is blocked when generating |
| 6589 | // this code |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6590 | |
| 6591 | // Load the receiver from the stack. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6592 | Register receiver = frame_->PopToRegister(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6593 | |
| 6594 | DeferredReferenceGetNamedValue* deferred = |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6595 | new DeferredReferenceGetNamedValue(receiver, name); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6596 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6597 | #ifdef DEBUG |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6598 | int kInlinedNamedLoadInstructions = 7; |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6599 | Label check_inlined_codesize; |
| 6600 | masm_->bind(&check_inlined_codesize); |
| 6601 | #endif |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6602 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6603 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6604 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6605 | __ tst(receiver, Operand(kSmiTagMask)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6606 | deferred->Branch(eq); |
| 6607 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6608 | Register scratch = VirtualFrame::scratch0(); |
| 6609 | Register scratch2 = VirtualFrame::scratch1(); |
| 6610 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6611 | // 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] | 6612 | // code. Therefore we can't use a LoadRoot call. |
| 6613 | __ ldr(scratch, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6614 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6615 | __ cmp(scratch, scratch2); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6616 | deferred->Branch(ne); |
| 6617 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6618 | // 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] | 6619 | // inline cache code. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6620 | __ ldr(receiver, MemOperand(receiver, 0)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6621 | |
| 6622 | // Make sure that the expected number of instructions are generated. |
| 6623 | ASSERT_EQ(kInlinedNamedLoadInstructions, |
| 6624 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6625 | } |
| 6626 | |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6627 | deferred->BindExit(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6628 | // At this point the receiver register has the result, either from the |
| 6629 | // deferred code or from the inlined code. |
| 6630 | frame_->EmitPush(receiver); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6631 | } |
| 6632 | } |
| 6633 | |
| 6634 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6635 | void CodeGenerator::EmitNamedStore(Handle<String> name, bool is_contextual) { |
| 6636 | #ifdef DEBUG |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6637 | int expected_height = frame()->height() - (is_contextual ? 1 : 2); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6638 | #endif |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6639 | |
whesse@chromium.org | ba5a61b | 2010-07-26 11:44:40 +0000 | [diff] [blame] | 6640 | Result result; |
| 6641 | if (is_contextual || scope()->is_global_scope() || loop_nesting() == 0) { |
| 6642 | frame()->CallStoreIC(name, is_contextual); |
| 6643 | } else { |
| 6644 | // Inline the in-object property case. |
| 6645 | JumpTarget slow, done; |
| 6646 | |
| 6647 | // Get the value and receiver from the stack. |
| 6648 | frame()->PopToR0(); |
| 6649 | Register value = r0; |
| 6650 | frame()->PopToR1(); |
| 6651 | Register receiver = r1; |
| 6652 | |
| 6653 | DeferredReferenceSetNamedValue* deferred = |
| 6654 | new DeferredReferenceSetNamedValue(value, receiver, name); |
| 6655 | |
| 6656 | // Check that the receiver is a heap object. |
| 6657 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6658 | deferred->Branch(eq); |
| 6659 | |
| 6660 | // The following instructions are the part of the inlined |
| 6661 | // in-object property store code which can be patched. Therefore |
| 6662 | // the exact number of instructions generated must be fixed, so |
| 6663 | // the constant pool is blocked while generating this code. |
| 6664 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6665 | Register scratch0 = VirtualFrame::scratch0(); |
| 6666 | Register scratch1 = VirtualFrame::scratch1(); |
| 6667 | |
| 6668 | // Check the map. Initially use an invalid map to force a |
| 6669 | // failure. The map check will be patched in the runtime system. |
| 6670 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 6671 | |
| 6672 | #ifdef DEBUG |
| 6673 | Label check_inlined_codesize; |
| 6674 | masm_->bind(&check_inlined_codesize); |
| 6675 | #endif |
| 6676 | __ mov(scratch0, Operand(Factory::null_value())); |
| 6677 | __ cmp(scratch0, scratch1); |
| 6678 | deferred->Branch(ne); |
| 6679 | |
| 6680 | int offset = 0; |
| 6681 | __ str(value, MemOperand(receiver, offset)); |
| 6682 | |
| 6683 | // Update the write barrier and record its size. We do not use |
| 6684 | // the RecordWrite macro here because we want the offset |
| 6685 | // addition instruction first to make it easy to patch. |
| 6686 | Label record_write_start, record_write_done; |
| 6687 | __ bind(&record_write_start); |
| 6688 | // Add offset into the object. |
| 6689 | __ add(scratch0, receiver, Operand(offset)); |
| 6690 | // Test that the object is not in the new space. We cannot set |
| 6691 | // region marks for new space pages. |
| 6692 | __ InNewSpace(receiver, scratch1, eq, &record_write_done); |
| 6693 | // Record the actual write. |
| 6694 | __ RecordWriteHelper(receiver, scratch0, scratch1); |
| 6695 | __ bind(&record_write_done); |
| 6696 | // Clobber all input registers when running with the debug-code flag |
| 6697 | // turned on to provoke errors. |
| 6698 | if (FLAG_debug_code) { |
| 6699 | __ mov(receiver, Operand(BitCast<int32_t>(kZapValue))); |
| 6700 | __ mov(scratch0, Operand(BitCast<int32_t>(kZapValue))); |
| 6701 | __ mov(scratch1, Operand(BitCast<int32_t>(kZapValue))); |
| 6702 | } |
| 6703 | // Check that this is the first inlined write barrier or that |
| 6704 | // this inlined write barrier has the same size as all the other |
| 6705 | // inlined write barriers. |
| 6706 | ASSERT((inlined_write_barrier_size_ == -1) || |
| 6707 | (inlined_write_barrier_size_ == |
| 6708 | masm()->InstructionsGeneratedSince(&record_write_start))); |
| 6709 | inlined_write_barrier_size_ = |
| 6710 | masm()->InstructionsGeneratedSince(&record_write_start); |
| 6711 | |
| 6712 | // Make sure that the expected number of instructions are generated. |
| 6713 | ASSERT_EQ(GetInlinedNamedStoreInstructionsAfterPatch(), |
| 6714 | masm()->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6715 | } |
| 6716 | deferred->BindExit(); |
| 6717 | } |
| 6718 | ASSERT_EQ(expected_height, frame()->height()); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 6719 | } |
| 6720 | |
| 6721 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6722 | void CodeGenerator::EmitKeyedLoad() { |
| 6723 | if (loop_nesting() == 0) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6724 | Comment cmnt(masm_, "[ Load from keyed property"); |
| 6725 | frame_->CallKeyedLoadIC(); |
| 6726 | } else { |
| 6727 | // Inline the keyed load. |
| 6728 | Comment cmnt(masm_, "[ Inlined load from keyed property"); |
| 6729 | |
| 6730 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6731 | // having it in the instruction stream below where patching will occur. |
| 6732 | __ IncrementCounter(&Counters::keyed_load_inline, 1, |
| 6733 | frame_->scratch0(), frame_->scratch1()); |
| 6734 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6735 | // Load the key and receiver from the stack. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6736 | bool key_is_known_smi = frame_->KnownSmiAt(0); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6737 | Register key = frame_->PopToRegister(); |
| 6738 | Register receiver = frame_->PopToRegister(key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6739 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6740 | // The deferred code expects key and receiver in registers. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6741 | DeferredReferenceGetKeyedValue* deferred = |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6742 | new DeferredReferenceGetKeyedValue(key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6743 | |
| 6744 | // Check that the receiver is a heap object. |
| 6745 | __ tst(receiver, Operand(kSmiTagMask)); |
| 6746 | deferred->Branch(eq); |
| 6747 | |
| 6748 | // The following instructions are the part of the inlined load keyed |
| 6749 | // property code which can be patched. Therefore the exact number of |
| 6750 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6751 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6752 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
| 6753 | Register scratch1 = VirtualFrame::scratch0(); |
| 6754 | Register scratch2 = VirtualFrame::scratch1(); |
| 6755 | // Check the map. The null map used below is patched by the inline cache |
| 6756 | // code. |
| 6757 | __ ldr(scratch1, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6758 | |
| 6759 | // Check that the key is a smi. |
| 6760 | if (!key_is_known_smi) { |
| 6761 | __ tst(key, Operand(kSmiTagMask)); |
| 6762 | deferred->Branch(ne); |
| 6763 | } |
| 6764 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6765 | #ifdef DEBUG |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6766 | Label check_inlined_codesize; |
| 6767 | masm_->bind(&check_inlined_codesize); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6768 | #endif |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6769 | __ mov(scratch2, Operand(Factory::null_value())); |
| 6770 | __ cmp(scratch1, scratch2); |
| 6771 | deferred->Branch(ne); |
| 6772 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6773 | // Get the elements array from the receiver. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6774 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 6775 | __ AssertFastElements(scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6776 | |
| 6777 | // Check that key is within bounds. Use unsigned comparison to handle |
| 6778 | // negative keys. |
| 6779 | __ ldr(scratch2, FieldMemOperand(scratch1, FixedArray::kLengthOffset)); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6780 | __ cmp(scratch2, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6781 | deferred->Branch(ls); // Unsigned less equal. |
| 6782 | |
| 6783 | // Load and check that the result is not the hole (key is a smi). |
| 6784 | __ LoadRoot(scratch2, Heap::kTheHoleValueRootIndex); |
| 6785 | __ add(scratch1, |
| 6786 | scratch1, |
| 6787 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6788 | __ ldr(scratch1, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6789 | MemOperand(scratch1, key, LSL, |
| 6790 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6791 | __ cmp(scratch1, scratch2); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6792 | deferred->Branch(eq); |
| 6793 | |
vegorov@chromium.org | dff694e | 2010-05-17 09:10:26 +0000 | [diff] [blame] | 6794 | __ mov(r0, scratch1); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6795 | // Make sure that the expected number of instructions are generated. |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6796 | ASSERT_EQ(GetInlinedKeyedLoadInstructionsAfterPatch(), |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6797 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6798 | } |
| 6799 | |
| 6800 | deferred->BindExit(); |
| 6801 | } |
| 6802 | } |
| 6803 | |
| 6804 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6805 | void CodeGenerator::EmitKeyedStore(StaticType* key_type, |
| 6806 | WriteBarrierCharacter wb_info) { |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6807 | // Generate inlined version of the keyed store if the code is in a loop |
| 6808 | // and the key is likely to be a smi. |
| 6809 | if (loop_nesting() > 0 && key_type->IsLikelySmi()) { |
| 6810 | // Inline the keyed store. |
| 6811 | Comment cmnt(masm_, "[ Inlined store to keyed property"); |
| 6812 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6813 | Register scratch1 = VirtualFrame::scratch0(); |
| 6814 | Register scratch2 = VirtualFrame::scratch1(); |
| 6815 | Register scratch3 = r3; |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6816 | |
| 6817 | // Counter will be decremented in the deferred code. Placed here to avoid |
| 6818 | // having it in the instruction stream below where patching will occur. |
| 6819 | __ IncrementCounter(&Counters::keyed_store_inline, 1, |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6820 | scratch1, scratch2); |
| 6821 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6822 | |
| 6823 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6824 | // Load the value, key and receiver from the stack. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6825 | bool value_is_harmless = frame_->KnownSmiAt(0); |
| 6826 | if (wb_info == NEVER_NEWSPACE) value_is_harmless = true; |
| 6827 | bool key_is_smi = frame_->KnownSmiAt(1); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6828 | Register value = frame_->PopToRegister(); |
| 6829 | Register key = frame_->PopToRegister(value); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 6830 | VirtualFrame::SpilledScope spilled(frame_); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6831 | Register receiver = r2; |
| 6832 | frame_->EmitPop(receiver); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6833 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6834 | #ifdef DEBUG |
| 6835 | bool we_remembered_the_write_barrier = value_is_harmless; |
| 6836 | #endif |
| 6837 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6838 | // The deferred code expects value, key and receiver in registers. |
| 6839 | DeferredReferenceSetKeyedValue* deferred = |
| 6840 | new DeferredReferenceSetKeyedValue(value, key, receiver); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6841 | |
| 6842 | // Check that the value is a smi. As this inlined code does not set the |
| 6843 | // write barrier it is only possible to store smi values. |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6844 | if (!value_is_harmless) { |
| 6845 | // If the value is not likely to be a Smi then let's test the fixed array |
| 6846 | // for new space instead. See below. |
| 6847 | if (wb_info == LIKELY_SMI) { |
| 6848 | __ tst(value, Operand(kSmiTagMask)); |
| 6849 | deferred->Branch(ne); |
| 6850 | #ifdef DEBUG |
| 6851 | we_remembered_the_write_barrier = true; |
| 6852 | #endif |
| 6853 | } |
| 6854 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6855 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6856 | if (!key_is_smi) { |
| 6857 | // Check that the key is a smi. |
| 6858 | __ tst(key, Operand(kSmiTagMask)); |
| 6859 | deferred->Branch(ne); |
| 6860 | } |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6861 | |
| 6862 | // Check that the receiver is a heap object. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6863 | __ tst(receiver, Operand(kSmiTagMask)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6864 | deferred->Branch(eq); |
| 6865 | |
| 6866 | // Check that the receiver is a JSArray. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6867 | __ CompareObjectType(receiver, scratch1, scratch1, JS_ARRAY_TYPE); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6868 | deferred->Branch(ne); |
| 6869 | |
| 6870 | // Check that the key is within bounds. Both the key and the length of |
| 6871 | // 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] | 6872 | __ ldr(scratch1, FieldMemOperand(receiver, JSArray::kLengthOffset)); |
| 6873 | __ cmp(scratch1, key); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6874 | deferred->Branch(ls); // Unsigned less equal. |
| 6875 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6876 | // Get the elements array from the receiver. |
| 6877 | __ ldr(scratch1, FieldMemOperand(receiver, JSObject::kElementsOffset)); |
| 6878 | if (!value_is_harmless && wb_info != LIKELY_SMI) { |
| 6879 | Label ok; |
| 6880 | __ and_(scratch2, scratch1, Operand(ExternalReference::new_space_mask())); |
| 6881 | __ cmp(scratch2, Operand(ExternalReference::new_space_start())); |
| 6882 | __ tst(value, Operand(kSmiTagMask), ne); |
| 6883 | deferred->Branch(ne); |
| 6884 | #ifdef DEBUG |
| 6885 | we_remembered_the_write_barrier = true; |
| 6886 | #endif |
| 6887 | } |
| 6888 | // Check that the elements array is not a dictionary. |
| 6889 | __ ldr(scratch2, FieldMemOperand(scratch1, JSObject::kMapOffset)); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6890 | // The following instructions are the part of the inlined store keyed |
| 6891 | // property code which can be patched. Therefore the exact number of |
| 6892 | // instructions generated need to be fixed, so the constant pool is blocked |
| 6893 | // while generating this code. |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6894 | { Assembler::BlockConstPoolScope block_const_pool(masm_); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6895 | #ifdef DEBUG |
| 6896 | Label check_inlined_codesize; |
| 6897 | masm_->bind(&check_inlined_codesize); |
| 6898 | #endif |
| 6899 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6900 | // Read the fixed array map from the constant pool (not from the root |
| 6901 | // array) so that the value can be patched. When debugging, we patch this |
| 6902 | // comparison to always fail so that we will hit the IC call in the |
| 6903 | // deferred code which will allow the debugger to break for fast case |
| 6904 | // stores. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6905 | __ mov(scratch3, Operand(Factory::fixed_array_map())); |
| 6906 | __ cmp(scratch2, scratch3); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6907 | deferred->Branch(ne); |
| 6908 | |
| 6909 | // Store the value. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6910 | __ add(scratch1, scratch1, |
| 6911 | Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 6912 | __ str(value, |
| 6913 | MemOperand(scratch1, key, LSL, |
| 6914 | kPointerSizeLog2 - (kSmiTagSize + kSmiShiftSize))); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6915 | |
| 6916 | // Make sure that the expected number of instructions are generated. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6917 | ASSERT_EQ(kInlinedKeyedStoreInstructionsAfterPatch, |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6918 | masm_->InstructionsGeneratedSince(&check_inlined_codesize)); |
| 6919 | } |
| 6920 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 6921 | ASSERT(we_remembered_the_write_barrier); |
| 6922 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 6923 | deferred->BindExit(); |
| 6924 | } else { |
| 6925 | frame()->CallKeyedStoreIC(); |
| 6926 | } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6930 | #ifdef DEBUG |
| 6931 | bool CodeGenerator::HasValidEntryRegisters() { return true; } |
| 6932 | #endif |
| 6933 | |
| 6934 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6935 | #undef __ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 6936 | #define __ ACCESS_MASM(masm) |
| 6937 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6938 | Handle<String> Reference::GetName() { |
| 6939 | ASSERT(type_ == NAMED); |
| 6940 | Property* property = expression_->AsProperty(); |
| 6941 | if (property == NULL) { |
| 6942 | // Global variable reference treated as a named property reference. |
| 6943 | VariableProxy* proxy = expression_->AsVariableProxy(); |
| 6944 | ASSERT(proxy->AsVariable() != NULL); |
| 6945 | ASSERT(proxy->AsVariable()->is_global()); |
| 6946 | return proxy->name(); |
| 6947 | } else { |
| 6948 | Literal* raw_name = property->key()->AsLiteral(); |
| 6949 | ASSERT(raw_name != NULL); |
| 6950 | return Handle<String>(String::cast(*raw_name->handle())); |
| 6951 | } |
| 6952 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6953 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6954 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6955 | void Reference::DupIfPersist() { |
| 6956 | if (persist_after_get_) { |
| 6957 | switch (type_) { |
| 6958 | case KEYED: |
| 6959 | cgen_->frame()->Dup2(); |
| 6960 | break; |
| 6961 | case NAMED: |
| 6962 | cgen_->frame()->Dup(); |
| 6963 | // Fall through. |
| 6964 | case UNLOADED: |
| 6965 | case ILLEGAL: |
| 6966 | case SLOT: |
| 6967 | // Do nothing. |
| 6968 | ; |
| 6969 | } |
| 6970 | } else { |
| 6971 | set_unloaded(); |
| 6972 | } |
| 6973 | } |
| 6974 | |
| 6975 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6976 | void Reference::GetValue() { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6977 | ASSERT(cgen_->HasValidEntryRegisters()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6978 | ASSERT(!is_illegal()); |
| 6979 | ASSERT(!cgen_->has_cc()); |
| 6980 | MacroAssembler* masm = cgen_->masm(); |
| 6981 | Property* property = expression_->AsProperty(); |
| 6982 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 6983 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6984 | } |
| 6985 | |
| 6986 | switch (type_) { |
| 6987 | case SLOT: { |
| 6988 | Comment cmnt(masm, "[ Load from Slot"); |
| 6989 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
| 6990 | ASSERT(slot != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6991 | DupIfPersist(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6992 | cgen_->LoadFromSlotCheckForArguments(slot, NOT_INSIDE_TYPEOF); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6993 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 6994 | } |
| 6995 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6996 | case NAMED: { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6997 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
fschneider@chromium.org | 013f3e1 | 2010-04-26 13:27:52 +0000 | [diff] [blame] | 6998 | bool is_global = var != NULL; |
| 6999 | ASSERT(!is_global || var->is_global()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7000 | Handle<String> name = GetName(); |
| 7001 | DupIfPersist(); |
| 7002 | cgen_->EmitNamedLoad(name, is_global); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7003 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7004 | } |
| 7005 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7006 | case KEYED: { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7007 | ASSERT(property != NULL); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 7008 | DupIfPersist(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 7009 | cgen_->EmitKeyedLoad(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 7010 | cgen_->frame()->EmitPush(r0); |
| 7011 | break; |
| 7012 | } |
| 7013 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7014 | default: |
| 7015 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7016 | } |
| 7017 | } |
| 7018 | |
| 7019 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7020 | void Reference::SetValue(InitState init_state, WriteBarrierCharacter wb_info) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7021 | ASSERT(!is_illegal()); |
| 7022 | ASSERT(!cgen_->has_cc()); |
| 7023 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 7024 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7025 | Property* property = expression_->AsProperty(); |
| 7026 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7027 | cgen_->CodeForSourcePosition(property->position()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7028 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7029 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7030 | switch (type_) { |
| 7031 | case SLOT: { |
| 7032 | Comment cmnt(masm, "[ Store to Slot"); |
| 7033 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 7034 | cgen_->StoreToSlot(slot, init_state); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7035 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7036 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7037 | } |
| 7038 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7039 | case NAMED: { |
| 7040 | Comment cmnt(masm, "[ Store to named Property"); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 7041 | cgen_->EmitNamedStore(GetName(), false); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7042 | frame->EmitPush(r0); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 7043 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7044 | break; |
| 7045 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7046 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7047 | case KEYED: { |
| 7048 | Comment cmnt(masm, "[ Store to keyed Property"); |
| 7049 | Property* property = expression_->AsProperty(); |
| 7050 | ASSERT(property != NULL); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 7051 | cgen_->CodeForSourcePosition(property->position()); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 7052 | cgen_->EmitKeyedStore(property->key()->type(), wb_info); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 7053 | frame->EmitPush(r0); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7054 | set_unloaded(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7055 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7056 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 7057 | |
| 7058 | default: |
| 7059 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7060 | } |
| 7061 | } |
| 7062 | |
| 7063 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7064 | const char* GenericBinaryOpStub::GetName() { |
| 7065 | if (name_ != NULL) return name_; |
| 7066 | const int len = 100; |
| 7067 | name_ = Bootstrapper::AllocateAutoDeletedArray(len); |
| 7068 | if (name_ == NULL) return "OOM"; |
| 7069 | const char* op_name = Token::Name(op_); |
| 7070 | const char* overwrite_name; |
| 7071 | switch (mode_) { |
| 7072 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 7073 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 7074 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 7075 | default: overwrite_name = "UnknownOverwrite"; break; |
| 7076 | } |
| 7077 | |
| 7078 | OS::SNPrintF(Vector<char>(name_, len), |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7079 | "GenericBinaryOpStub_%s_%s%s_%s", |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7080 | op_name, |
| 7081 | overwrite_name, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 7082 | specialized_on_rhs_ ? "_ConstantRhs" : "", |
| 7083 | BinaryOpIC::GetName(runtime_operands_type_)); |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 7084 | return name_; |
| 7085 | } |
| 7086 | |
| 7087 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 7088 | #undef __ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7089 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7090 | } } // namespace v8::internal |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 7091 | |
| 7092 | #endif // V8_TARGET_ARCH_ARM |