ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 | |
| 30 | #include "bootstrapper.h" |
| 31 | #include "codegen-inl.h" |
| 32 | #include "debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 33 | #include "scopes.h" |
| 34 | #include "runtime.h" |
| 35 | |
| 36 | namespace v8 { namespace internal { |
| 37 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 38 | #define __ masm_-> |
| 39 | |
| 40 | // ------------------------------------------------------------------------- |
| 41 | // VirtualFrame implementation. |
| 42 | |
| 43 | VirtualFrame::VirtualFrame(CodeGenerator* cgen) { |
| 44 | ASSERT(cgen->scope() != NULL); |
| 45 | |
| 46 | masm_ = cgen->masm(); |
| 47 | frame_local_count_ = cgen->scope()->num_stack_slots(); |
| 48 | parameter_count_ = cgen->scope()->num_parameters(); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void VirtualFrame::Enter() { |
| 53 | Comment cmnt(masm_, "[ Enter JS frame"); |
| 54 | #ifdef DEBUG |
| 55 | { Label done, fail; |
| 56 | __ tst(r1, Operand(kSmiTagMask)); |
| 57 | __ b(eq, &fail); |
| 58 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 59 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 60 | __ cmp(r2, Operand(JS_FUNCTION_TYPE)); |
| 61 | __ b(eq, &done); |
| 62 | __ bind(&fail); |
| 63 | __ stop("CodeGenerator::EnterJSFrame - r1 not a function"); |
| 64 | __ bind(&done); |
| 65 | } |
| 66 | #endif // DEBUG |
| 67 | |
| 68 | __ stm(db_w, sp, r1.bit() | cp.bit() | fp.bit() | lr.bit()); |
| 69 | // Adjust FP to point to saved FP. |
| 70 | __ add(fp, sp, Operand(2 * kPointerSize)); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void VirtualFrame::Exit() { |
| 75 | Comment cmnt(masm_, "[ Exit JS frame"); |
| 76 | // Drop the execution stack down to the frame pointer and restore the caller |
| 77 | // frame pointer and return address. |
| 78 | __ mov(sp, fp); |
| 79 | __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | void VirtualFrame::AllocateLocals() { |
| 84 | if (frame_local_count_ > 0) { |
| 85 | Comment cmnt(masm_, "[ Allocate space for locals"); |
| 86 | // Initialize stack slots with 'undefined' value. |
| 87 | __ mov(ip, Operand(Factory::undefined_value())); |
| 88 | for (int i = 0; i < frame_local_count_; i++) { |
| 89 | __ push(ip); |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | void VirtualFrame::Drop(int count) { |
| 96 | ASSERT(count >= 0); |
| 97 | if (count > 0) { |
| 98 | __ add(sp, sp, Operand(count * kPointerSize)); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | void VirtualFrame::Pop() { Drop(1); } |
| 104 | |
| 105 | |
| 106 | void VirtualFrame::Pop(Register reg) { |
| 107 | __ pop(reg); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void VirtualFrame::Push(Register reg) { |
| 112 | __ push(reg); |
| 113 | } |
| 114 | |
| 115 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 116 | // ------------------------------------------------------------------------- |
| 117 | // CodeGenState implementation. |
| 118 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 119 | CodeGenState::CodeGenState(CodeGenerator* owner) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 120 | : owner_(owner), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 121 | typeof_state_(NOT_INSIDE_TYPEOF), |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 122 | true_target_(NULL), |
| 123 | false_target_(NULL), |
| 124 | previous_(NULL) { |
| 125 | owner_->set_state(this); |
| 126 | } |
| 127 | |
| 128 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 129 | CodeGenState::CodeGenState(CodeGenerator* owner, |
| 130 | TypeofState typeof_state, |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 131 | Label* true_target, |
| 132 | Label* false_target) |
| 133 | : owner_(owner), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 134 | typeof_state_(typeof_state), |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 135 | true_target_(true_target), |
| 136 | false_target_(false_target), |
| 137 | previous_(owner->state()) { |
| 138 | owner_->set_state(this); |
| 139 | } |
| 140 | |
| 141 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 142 | CodeGenState::~CodeGenState() { |
| 143 | ASSERT(owner_->state() == this); |
| 144 | owner_->set_state(previous_); |
| 145 | } |
| 146 | |
| 147 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 148 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 149 | // CodeGenerator implementation |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 150 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 151 | CodeGenerator::CodeGenerator(int buffer_size, Handle<Script> script, |
| 152 | bool is_eval) |
| 153 | : is_eval_(is_eval), |
| 154 | script_(script), |
| 155 | deferred_(8), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | masm_(new MacroAssembler(NULL, buffer_size)), |
| 157 | scope_(NULL), |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 158 | frame_(NULL), |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 159 | cc_reg_(al), |
| 160 | state_(NULL), |
| 161 | break_stack_height_(0) { |
| 162 | } |
| 163 | |
| 164 | |
| 165 | // Calling conventions: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 166 | // r0: the number of arguments |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 167 | // fp: frame pointer |
| 168 | // sp: stack pointer |
| 169 | // pp: caller's parameter pointer |
| 170 | // cp: callee's context |
| 171 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 172 | void CodeGenerator::GenCode(FunctionLiteral* fun) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | ZoneList<Statement*>* body = fun->body(); |
| 174 | |
| 175 | // Initialize state. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 176 | ASSERT(scope_ == NULL); |
| 177 | scope_ = fun->scope(); |
| 178 | ASSERT(frame_ == NULL); |
| 179 | VirtualFrame virtual_frame(this); |
| 180 | frame_ = &virtual_frame; |
| 181 | cc_reg_ = al; |
| 182 | { |
| 183 | CodeGenState state(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 184 | |
| 185 | // Entry |
| 186 | // stack: function, receiver, arguments, return address |
| 187 | // r0: number of arguments |
| 188 | // sp: stack pointer |
| 189 | // fp: frame pointer |
| 190 | // pp: caller's parameter pointer |
| 191 | // cp: callee's context |
| 192 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 193 | frame_->Enter(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | // tos: code slot |
| 195 | #ifdef DEBUG |
| 196 | if (strlen(FLAG_stop_at) > 0 && |
| 197 | fun->name()->IsEqualTo(CStrVector(FLAG_stop_at))) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 198 | __ stop("stop-at"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 199 | } |
| 200 | #endif |
| 201 | |
| 202 | // Allocate space for locals and initialize them. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 203 | frame_->AllocateLocals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 204 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 205 | if (scope_->num_heap_slots() > 0) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 206 | // Allocate local context. |
| 207 | // Get outer context and create a new context based on it. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 208 | __ ldr(r0, frame_->Function()); |
| 209 | frame_->Push(r0); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 210 | __ CallRuntime(Runtime::kNewContext, 1); // r0 holds the result |
| 211 | |
| 212 | if (kDebug) { |
| 213 | Label verified_true; |
| 214 | __ cmp(r0, Operand(cp)); |
| 215 | __ b(eq, &verified_true); |
| 216 | __ stop("NewContext: r0 is expected to be the same as cp"); |
| 217 | __ bind(&verified_true); |
| 218 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 220 | __ str(cp, frame_->Context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 221 | } |
| 222 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 223 | // TODO(1241774): Improve this code: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 224 | // 1) only needed if we have a context |
| 225 | // 2) no need to recompute context ptr every single time |
| 226 | // 3) don't copy parameter operand code from SlotOperand! |
| 227 | { |
| 228 | Comment cmnt2(masm_, "[ copy context parameters into .context"); |
| 229 | |
| 230 | // Note that iteration order is relevant here! If we have the same |
| 231 | // parameter twice (e.g., function (x, y, x)), and that parameter |
| 232 | // needs to be copied into the context, it must be the last argument |
| 233 | // passed to the parameter that needs to be copied. This is a rare |
| 234 | // case so we don't check for it, instead we rely on the copying |
| 235 | // order: such a parameter is copied repeatedly into the same |
| 236 | // context location and thus the last value is what is seen inside |
| 237 | // the function. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 238 | for (int i = 0; i < scope_->num_parameters(); i++) { |
| 239 | Variable* par = scope_->parameter(i); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 240 | Slot* slot = par->slot(); |
| 241 | if (slot != NULL && slot->type() == Slot::CONTEXT) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 242 | ASSERT(!scope_->is_global_scope()); // no parameters in global scope |
| 243 | __ ldr(r1, frame_->Parameter(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | // Loads r2 with context; used below in RecordWrite. |
| 245 | __ str(r1, SlotOperand(slot, r2)); |
| 246 | // Load the offset into r3. |
| 247 | int slot_offset = |
| 248 | FixedArray::kHeaderSize + slot->index() * kPointerSize; |
| 249 | __ mov(r3, Operand(slot_offset)); |
| 250 | __ RecordWrite(r2, r3, r1); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 255 | // Store the arguments object. This must happen after context |
| 256 | // initialization because the arguments object may be stored in the |
| 257 | // context. |
| 258 | if (scope_->arguments() != NULL) { |
| 259 | ASSERT(scope_->arguments_shadow() != NULL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 260 | Comment cmnt(masm_, "[ allocate arguments object"); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 261 | { Reference shadow_ref(this, scope_->arguments_shadow()); |
| 262 | { Reference arguments_ref(this, scope_->arguments()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 263 | ArgumentsAccessStub stub(ArgumentsAccessStub::NEW_OBJECT); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 264 | __ ldr(r2, frame_->Function()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 265 | // The receiver is below the arguments, the return address, |
| 266 | // and the frame pointer on the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 267 | const int kReceiverDisplacement = 2 + scope_->num_parameters(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 268 | __ add(r1, fp, Operand(kReceiverDisplacement * kPointerSize)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 269 | __ mov(r0, Operand(Smi::FromInt(scope_->num_parameters()))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 270 | __ stm(db_w, sp, r0.bit() | r1.bit() | r2.bit()); |
| 271 | __ CallStub(&stub); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 272 | frame_->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 273 | arguments_ref.SetValue(NOT_CONST_INIT); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 274 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 275 | shadow_ref.SetValue(NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 276 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 277 | frame_->Pop(); // Value is no longer needed. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | } |
| 279 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 280 | // Generate code to 'execute' declarations and initialize functions |
| 281 | // (source elements). In case of an illegal redeclaration we need to |
| 282 | // handle that instead of processing the declarations. |
| 283 | if (scope_->HasIllegalRedeclaration()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 284 | Comment cmnt(masm_, "[ illegal redeclarations"); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 285 | scope_->VisitIllegalRedeclaration(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | } else { |
| 287 | Comment cmnt(masm_, "[ declarations"); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 288 | ProcessDeclarations(scope_->declarations()); |
| 289 | // Bail out if a stack-overflow exception occurred when processing |
| 290 | // declarations. |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 291 | if (HasStackOverflow()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 292 | } |
| 293 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 294 | if (FLAG_trace) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 295 | __ CallRuntime(Runtime::kTraceEnter, 0); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 296 | // Ignore the return value. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 297 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 298 | CheckStack(); |
| 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 | 3bf7b91 | 2008-11-17 09:09:45 +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 | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 310 | __ 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 |
| 314 | VisitStatements(body); |
| 315 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // exit |
| 319 | // r0: result |
| 320 | // sp: stack pointer |
| 321 | // fp: frame pointer |
| 322 | // pp: parameter pointer |
| 323 | // cp: callee's context |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 324 | __ mov(r0, Operand(Factory::undefined_value())); |
| 325 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | __ bind(&function_return_); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 327 | if (FLAG_trace) { |
| 328 | // Push the return value on the stack as the parameter. |
| 329 | // Runtime::TraceExit returns the parameter as it is. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 330 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 331 | __ CallRuntime(Runtime::kTraceExit, 1); |
| 332 | } |
| 333 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 334 | // Tear down the frame which will restore the caller's frame pointer and the |
| 335 | // link register. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 336 | frame_->Exit(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 338 | __ add(sp, sp, Operand((scope_->num_parameters() + 1) * kPointerSize)); |
| 339 | __ mov(pc, lr); |
| 340 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 341 | // Code generation state must be reset. |
| 342 | scope_ = NULL; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 343 | frame_ = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | ASSERT(!has_cc()); |
| 345 | ASSERT(state_ == NULL); |
| 346 | } |
| 347 | |
| 348 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 349 | MemOperand CodeGenerator::SlotOperand(Slot* slot, Register tmp) { |
| 350 | // Currently, this assertion will fail if we try to assign to |
| 351 | // a constant variable that is constant because it is read-only |
| 352 | // (such as the variable referring to a named function expression). |
| 353 | // We need to implement assignments to read-only variables. |
| 354 | // Ideally, we should do this during AST generation (by converting |
| 355 | // such assignments into expression statements); however, in general |
| 356 | // we may not be able to make the decision until past AST generation, |
| 357 | // that is when the entire program is known. |
| 358 | ASSERT(slot != NULL); |
| 359 | int index = slot->index(); |
| 360 | switch (slot->type()) { |
| 361 | case Slot::PARAMETER: |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 362 | return frame_->Parameter(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 363 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 364 | case Slot::LOCAL: |
| 365 | return frame_->Local(index); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 366 | |
| 367 | case Slot::CONTEXT: { |
| 368 | // Follow the context chain if necessary. |
| 369 | ASSERT(!tmp.is(cp)); // do not overwrite context register |
| 370 | Register context = cp; |
| 371 | int chain_length = scope()->ContextChainLength(slot->var()->scope()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 372 | for (int i = 0; i < chain_length; i++) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 373 | // Load the closure. |
| 374 | // (All contexts, even 'with' contexts, have a closure, |
| 375 | // and it is the same for all contexts inside a function. |
| 376 | // There is no need to go to the function context first.) |
| 377 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 378 | // Load the function context (which is the incoming, outer context). |
| 379 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 380 | context = tmp; |
| 381 | } |
| 382 | // We may have a 'with' context now. Get the function context. |
| 383 | // (In fact this mov may never be the needed, since the scope analysis |
| 384 | // may not permit a direct context access in this case and thus we are |
| 385 | // always at a function context. However it is safe to dereference be- |
| 386 | // cause the function context of a function context is itself. Before |
| 387 | // deleting this mov we should try to create a counter-example first, |
| 388 | // though...) |
| 389 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
| 390 | return ContextOperand(tmp, index); |
| 391 | } |
| 392 | |
| 393 | default: |
| 394 | UNREACHABLE(); |
| 395 | return MemOperand(r0, 0); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 400 | MemOperand CodeGenerator::ContextSlotOperandCheckExtensions(Slot* slot, |
| 401 | Register tmp, |
| 402 | Register tmp2, |
| 403 | Label* slow) { |
| 404 | ASSERT(slot->type() == Slot::CONTEXT); |
| 405 | int index = slot->index(); |
| 406 | Register context = cp; |
| 407 | for (Scope* s = scope(); s != slot->var()->scope(); s = s->outer_scope()) { |
| 408 | if (s->num_heap_slots() > 0) { |
| 409 | if (s->calls_eval()) { |
| 410 | // Check that extension is NULL. |
| 411 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 412 | __ tst(tmp2, tmp2); |
| 413 | __ b(ne, slow); |
| 414 | } |
| 415 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 416 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 417 | context = tmp; |
| 418 | } |
| 419 | } |
| 420 | // Check that last extension is NULL. |
| 421 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 422 | __ tst(tmp2, tmp2); |
| 423 | __ b(ne, slow); |
| 424 | __ ldr(tmp, ContextOperand(context, Context::FCONTEXT_INDEX)); |
| 425 | return ContextOperand(tmp, index); |
| 426 | } |
| 427 | |
| 428 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 429 | // Loads a value on TOS. If it is a boolean value, the result may have been |
| 430 | // (partially) translated into branches, or it may have set the condition |
| 431 | // code register. If force_cc is set, the value is forced to set the |
| 432 | // condition code register and no value is pushed. If the condition code |
| 433 | // register was set, has_cc() is true and cc_reg_ contains the condition to |
| 434 | // test for 'true'. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 435 | void CodeGenerator::LoadCondition(Expression* x, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 436 | TypeofState typeof_state, |
| 437 | Label* true_target, |
| 438 | Label* false_target, |
| 439 | bool force_cc) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 440 | ASSERT(!has_cc()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 441 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 442 | { CodeGenState new_state(this, typeof_state, true_target, false_target); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 443 | Visit(x); |
| 444 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 445 | if (force_cc && !has_cc()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 446 | // Convert the TOS value to a boolean in the condition code register. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 447 | // Visiting an expression may possibly choose neither (a) to leave a |
| 448 | // value in the condition code register nor (b) to leave a value in TOS |
| 449 | // (eg, by compiling to only jumps to the targets). In that case the |
| 450 | // code generated by ToBoolean is wrong because it assumes the value of |
| 451 | // the expression in TOS. So long as there is always a value in TOS or |
| 452 | // the condition code register when control falls through to here (there |
| 453 | // is), the code generated by ToBoolean is dead and therefore safe. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 454 | ToBoolean(true_target, false_target); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 455 | } |
| 456 | ASSERT(has_cc() || !force_cc); |
| 457 | } |
| 458 | |
| 459 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 460 | void CodeGenerator::Load(Expression* x, TypeofState typeof_state) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | Label true_target; |
| 462 | Label false_target; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 463 | LoadCondition(x, typeof_state, &true_target, &false_target, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | |
| 465 | if (has_cc()) { |
| 466 | // convert cc_reg_ into a bool |
| 467 | Label loaded, materialize_true; |
| 468 | __ b(cc_reg_, &materialize_true); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 469 | __ mov(r0, Operand(Factory::false_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 470 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | __ b(&loaded); |
| 472 | __ bind(&materialize_true); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 473 | __ mov(r0, Operand(Factory::true_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 474 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | __ bind(&loaded); |
| 476 | cc_reg_ = al; |
| 477 | } |
| 478 | |
| 479 | if (true_target.is_linked() || false_target.is_linked()) { |
| 480 | // we have at least one condition value |
| 481 | // that has been "translated" into a branch, |
| 482 | // thus it needs to be loaded explicitly again |
| 483 | Label loaded; |
| 484 | __ b(&loaded); // don't lose current TOS |
| 485 | bool both = true_target.is_linked() && false_target.is_linked(); |
| 486 | // reincarnate "true", if necessary |
| 487 | if (true_target.is_linked()) { |
| 488 | __ bind(&true_target); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 489 | __ mov(r0, Operand(Factory::true_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 490 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 491 | } |
| 492 | // if both "true" and "false" need to be reincarnated, |
| 493 | // jump across code for "false" |
| 494 | if (both) |
| 495 | __ b(&loaded); |
| 496 | // reincarnate "false", if necessary |
| 497 | if (false_target.is_linked()) { |
| 498 | __ bind(&false_target); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 499 | __ mov(r0, Operand(Factory::false_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 500 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | } |
| 502 | // everything is loaded at this point |
| 503 | __ bind(&loaded); |
| 504 | } |
| 505 | ASSERT(!has_cc()); |
| 506 | } |
| 507 | |
| 508 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 509 | void CodeGenerator::LoadGlobal() { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 510 | __ ldr(r0, GlobalObject()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 511 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 515 | void CodeGenerator::LoadGlobalReceiver(Register scratch) { |
| 516 | __ ldr(scratch, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 517 | __ ldr(scratch, |
| 518 | FieldMemOperand(scratch, GlobalObject::kGlobalReceiverOffset)); |
| 519 | frame_->Push(scratch); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | // TODO(1241834): Get rid of this function in favor of just using Load, now |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 524 | // that we have the INSIDE_TYPEOF typeof state. => Need to handle global |
| 525 | // variables w/o reference errors elsewhere. |
| 526 | void CodeGenerator::LoadTypeofExpression(Expression* x) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | Variable* variable = x->AsVariableProxy()->AsVariable(); |
| 528 | if (variable != NULL && !variable->is_this() && variable->is_global()) { |
| 529 | // NOTE: This is somewhat nasty. We force the compiler to load |
| 530 | // the variable as if through '<global>.<variable>' to make sure we |
| 531 | // do not get reference errors. |
| 532 | Slot global(variable, Slot::CONTEXT, Context::GLOBAL_INDEX); |
| 533 | Literal key(variable->name()); |
| 534 | // TODO(1241834): Fetch the position from the variable instead of using |
| 535 | // no position. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 536 | Property property(&global, &key, RelocInfo::kNoPosition); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | Load(&property); |
| 538 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 539 | Load(x, INSIDE_TYPEOF); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 544 | Reference::Reference(CodeGenerator* cgen, Expression* expression) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 545 | : cgen_(cgen), expression_(expression), type_(ILLEGAL) { |
| 546 | cgen->LoadReference(this); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | Reference::~Reference() { |
| 551 | cgen_->UnloadReference(this); |
| 552 | } |
| 553 | |
| 554 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 555 | void CodeGenerator::LoadReference(Reference* ref) { |
| 556 | Comment cmnt(masm_, "[ LoadReference"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 557 | Expression* e = ref->expression(); |
| 558 | Property* property = e->AsProperty(); |
| 559 | Variable* var = e->AsVariableProxy()->AsVariable(); |
| 560 | |
| 561 | if (property != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 562 | // The expression is either a property or a variable proxy that rewrites |
| 563 | // to a property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 564 | Load(property->obj()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 565 | // We use a named reference if the key is a literal symbol, unless it is |
| 566 | // a string that can be legally parsed as an integer. This is because |
| 567 | // otherwise we will not get into the slow case code that handles [] on |
| 568 | // String objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 569 | Literal* literal = property->key()->AsLiteral(); |
| 570 | uint32_t dummy; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 571 | if (literal != NULL && |
| 572 | literal->handle()->IsSymbol() && |
| 573 | !String::cast(*(literal->handle()))->AsArrayIndex(&dummy)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 574 | ref->set_type(Reference::NAMED); |
| 575 | } else { |
| 576 | Load(property->key()); |
| 577 | ref->set_type(Reference::KEYED); |
| 578 | } |
| 579 | } else if (var != NULL) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 580 | // The expression is a variable proxy that does not rewrite to a |
| 581 | // property. Global variables are treated as named property references. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | if (var->is_global()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | LoadGlobal(); |
| 584 | ref->set_type(Reference::NAMED); |
| 585 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 586 | ASSERT(var->slot() != NULL); |
| 587 | ref->set_type(Reference::SLOT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | } |
| 589 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 590 | // Anything else is a runtime error. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 591 | Load(e); |
| 592 | __ CallRuntime(Runtime::kThrowReferenceError, 1); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 597 | void CodeGenerator::UnloadReference(Reference* ref) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 598 | // Pop a reference from the stack while preserving TOS. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 599 | Comment cmnt(masm_, "[ UnloadReference"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 600 | int size = ref->size(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 601 | if (size > 0) { |
| 602 | frame_->Pop(r0); |
| 603 | frame_->Drop(size); |
| 604 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 609 | // ECMA-262, section 9.2, page 30: ToBoolean(). Convert the given |
| 610 | // register to a boolean in the condition code register. The code |
| 611 | // may jump to 'false_target' in case the register converts to 'false'. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 612 | void CodeGenerator::ToBoolean(Label* true_target, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 613 | Label* false_target) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 614 | // Note: The generated code snippet does not change stack variables. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 615 | // Only the condition code should be set. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 616 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 617 | |
| 618 | // Fast case checks |
| 619 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 620 | // Check if the value is 'false'. |
| 621 | __ cmp(r0, Operand(Factory::false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | __ b(eq, false_target); |
| 623 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 624 | // Check if the value is 'true'. |
| 625 | __ cmp(r0, Operand(Factory::true_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | __ b(eq, true_target); |
| 627 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 628 | // Check if the value is 'undefined'. |
| 629 | __ cmp(r0, Operand(Factory::undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | __ b(eq, false_target); |
| 631 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 632 | // Check if the value is a smi. |
| 633 | __ cmp(r0, Operand(Smi::FromInt(0))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | __ b(eq, false_target); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 635 | __ tst(r0, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | __ b(eq, true_target); |
| 637 | |
| 638 | // Slow case: call the runtime. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 639 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 640 | __ CallRuntime(Runtime::kToBool, 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 641 | // Convert the result (r0) to a condition code. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | __ cmp(r0, Operand(Factory::false_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | |
| 644 | cc_reg_ = ne; |
| 645 | } |
| 646 | |
| 647 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 648 | class GetPropertyStub : public CodeStub { |
| 649 | public: |
| 650 | GetPropertyStub() { } |
| 651 | |
| 652 | private: |
| 653 | Major MajorKey() { return GetProperty; } |
| 654 | int MinorKey() { return 0; } |
| 655 | void Generate(MacroAssembler* masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 656 | }; |
| 657 | |
| 658 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 659 | class SetPropertyStub : public CodeStub { |
| 660 | public: |
| 661 | SetPropertyStub() { } |
| 662 | |
| 663 | private: |
| 664 | Major MajorKey() { return SetProperty; } |
| 665 | int MinorKey() { return 0; } |
| 666 | void Generate(MacroAssembler* masm); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 667 | }; |
| 668 | |
| 669 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 670 | class GenericBinaryOpStub : public CodeStub { |
| 671 | public: |
| 672 | explicit GenericBinaryOpStub(Token::Value op) : op_(op) { } |
| 673 | |
| 674 | private: |
| 675 | Token::Value op_; |
| 676 | |
| 677 | Major MajorKey() { return GenericBinaryOp; } |
| 678 | int MinorKey() { return static_cast<int>(op_); } |
| 679 | void Generate(MacroAssembler* masm); |
| 680 | |
| 681 | const char* GetName() { |
| 682 | switch (op_) { |
| 683 | case Token::ADD: return "GenericBinaryOpStub_ADD"; |
| 684 | case Token::SUB: return "GenericBinaryOpStub_SUB"; |
| 685 | case Token::MUL: return "GenericBinaryOpStub_MUL"; |
| 686 | case Token::DIV: return "GenericBinaryOpStub_DIV"; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 687 | case Token::BIT_OR: return "GenericBinaryOpStub_BIT_OR"; |
| 688 | case Token::BIT_AND: return "GenericBinaryOpStub_BIT_AND"; |
| 689 | case Token::BIT_XOR: return "GenericBinaryOpStub_BIT_XOR"; |
| 690 | case Token::SAR: return "GenericBinaryOpStub_SAR"; |
| 691 | case Token::SHL: return "GenericBinaryOpStub_SHL"; |
| 692 | case Token::SHR: return "GenericBinaryOpStub_SHR"; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 693 | default: return "GenericBinaryOpStub"; |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | #ifdef DEBUG |
| 698 | void Print() { PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_)); } |
| 699 | #endif |
| 700 | }; |
| 701 | |
| 702 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 703 | class InvokeBuiltinStub : public CodeStub { |
| 704 | public: |
| 705 | enum Kind { Inc, Dec, ToNumber }; |
| 706 | InvokeBuiltinStub(Kind kind, int argc) : kind_(kind), argc_(argc) { } |
| 707 | |
| 708 | private: |
| 709 | Kind kind_; |
| 710 | int argc_; |
| 711 | |
| 712 | Major MajorKey() { return InvokeBuiltin; } |
| 713 | int MinorKey() { return (argc_ << 3) | static_cast<int>(kind_); } |
| 714 | void Generate(MacroAssembler* masm); |
| 715 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 716 | #ifdef DEBUG |
| 717 | void Print() { |
| 718 | PrintF("InvokeBuiltinStub (kind %d, argc, %d)\n", |
| 719 | static_cast<int>(kind_), |
| 720 | argc_); |
| 721 | } |
| 722 | #endif |
| 723 | }; |
| 724 | |
| 725 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 726 | void CodeGenerator::GenericBinaryOperation(Token::Value op) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 727 | // sp[0] : y |
| 728 | // sp[1] : x |
| 729 | // result : r0 |
| 730 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 731 | // Stub is entered with a call: 'return address' is in lr. |
| 732 | switch (op) { |
| 733 | case Token::ADD: // fall through. |
| 734 | case Token::SUB: // fall through. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 735 | case Token::MUL: |
| 736 | case Token::BIT_OR: |
| 737 | case Token::BIT_AND: |
| 738 | case Token::BIT_XOR: |
| 739 | case Token::SHL: |
| 740 | case Token::SHR: |
| 741 | case Token::SAR: { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 742 | frame_->Pop(r0); // r0 : y |
| 743 | frame_->Pop(r1); // r1 : x |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 744 | GenericBinaryOpStub stub(op); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 745 | __ CallStub(&stub); |
| 746 | break; |
| 747 | } |
| 748 | |
| 749 | case Token::DIV: { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 750 | __ mov(r0, Operand(1)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 751 | __ InvokeBuiltin(Builtins::DIV, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | |
| 755 | case Token::MOD: { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 756 | __ mov(r0, Operand(1)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 757 | __ InvokeBuiltin(Builtins::MOD, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 758 | break; |
| 759 | } |
| 760 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 761 | case Token::COMMA: |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 762 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 763 | // simply discard left value |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 764 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 765 | break; |
| 766 | |
| 767 | default: |
| 768 | // Other cases should have been handled before this point. |
| 769 | UNREACHABLE(); |
| 770 | break; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 775 | class DeferredInlinedSmiOperation: public DeferredCode { |
| 776 | public: |
| 777 | DeferredInlinedSmiOperation(CodeGenerator* generator, Token::Value op, |
| 778 | int value, bool reversed) : |
| 779 | DeferredCode(generator), op_(op), value_(value), reversed_(reversed) { |
| 780 | set_comment("[ DeferredInlinedSmiOperation"); |
| 781 | } |
| 782 | |
| 783 | virtual void Generate() { |
| 784 | switch (op_) { |
| 785 | case Token::ADD: { |
| 786 | if (reversed_) { |
| 787 | // revert optimistic add |
| 788 | __ sub(r0, r0, Operand(Smi::FromInt(value_))); |
| 789 | __ mov(r1, Operand(Smi::FromInt(value_))); // x |
| 790 | } else { |
| 791 | // revert optimistic add |
| 792 | __ sub(r1, r0, Operand(Smi::FromInt(value_))); |
| 793 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 794 | } |
| 795 | break; |
| 796 | } |
| 797 | |
| 798 | case Token::SUB: { |
| 799 | if (reversed_) { |
| 800 | // revert optimistic sub |
| 801 | __ rsb(r0, r0, Operand(Smi::FromInt(value_))); |
| 802 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 803 | } else { |
| 804 | __ add(r1, r0, Operand(Smi::FromInt(value_))); |
| 805 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 806 | } |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | case Token::BIT_OR: |
| 811 | case Token::BIT_XOR: |
| 812 | case Token::BIT_AND: { |
| 813 | if (reversed_) { |
| 814 | __ mov(r1, Operand(Smi::FromInt(value_))); |
| 815 | } else { |
| 816 | __ mov(r1, Operand(r0)); |
| 817 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 818 | } |
| 819 | break; |
| 820 | } |
| 821 | |
| 822 | case Token::SHL: |
| 823 | case Token::SHR: |
| 824 | case Token::SAR: { |
| 825 | if (!reversed_) { |
| 826 | __ mov(r1, Operand(r0)); |
| 827 | __ mov(r0, Operand(Smi::FromInt(value_))); |
| 828 | } else { |
| 829 | UNREACHABLE(); // should have been handled in SmiOperation |
| 830 | } |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | default: |
| 835 | // other cases should have been handled before this point. |
| 836 | UNREACHABLE(); |
| 837 | break; |
| 838 | } |
| 839 | |
| 840 | GenericBinaryOpStub igostub(op_); |
| 841 | __ CallStub(&igostub); |
| 842 | } |
| 843 | |
| 844 | private: |
| 845 | Token::Value op_; |
| 846 | int value_; |
| 847 | bool reversed_; |
| 848 | }; |
| 849 | |
| 850 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 851 | void CodeGenerator::SmiOperation(Token::Value op, |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 852 | Handle<Object> value, |
| 853 | bool reversed) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 854 | // NOTE: This is an attempt to inline (a bit) more of the code for |
| 855 | // some possible smi operations (like + and -) when (at least) one |
| 856 | // of the operands is a literal smi. With this optimization, the |
| 857 | // performance of the system is increased by ~15%, and the generated |
| 858 | // code size is increased by ~1% (measured on a combination of |
| 859 | // different benchmarks). |
| 860 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 861 | // sp[0] : operand |
| 862 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 863 | int int_value = Smi::cast(*value)->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | |
| 865 | Label exit; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 866 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 867 | |
| 868 | switch (op) { |
| 869 | case Token::ADD: { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 870 | DeferredCode* deferred = |
| 871 | new DeferredInlinedSmiOperation(this, op, int_value, reversed); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 873 | __ add(r0, r0, Operand(value), SetCC); |
| 874 | __ b(vs, deferred->enter()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 875 | __ tst(r0, Operand(kSmiTagMask)); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 876 | __ b(ne, deferred->enter()); |
| 877 | __ bind(deferred->exit()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 878 | break; |
| 879 | } |
| 880 | |
| 881 | case Token::SUB: { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 882 | DeferredCode* deferred = |
| 883 | new DeferredInlinedSmiOperation(this, op, int_value, reversed); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 884 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 885 | if (!reversed) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 886 | __ sub(r0, r0, Operand(value), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 887 | } else { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 888 | __ rsb(r0, r0, Operand(value), SetCC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 889 | } |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 890 | __ b(vs, deferred->enter()); |
| 891 | __ tst(r0, Operand(kSmiTagMask)); |
| 892 | __ b(ne, deferred->enter()); |
| 893 | __ bind(deferred->exit()); |
| 894 | break; |
| 895 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 896 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 897 | case Token::BIT_OR: |
| 898 | case Token::BIT_XOR: |
| 899 | case Token::BIT_AND: { |
| 900 | DeferredCode* deferred = |
| 901 | new DeferredInlinedSmiOperation(this, op, int_value, reversed); |
| 902 | __ tst(r0, Operand(kSmiTagMask)); |
| 903 | __ b(ne, deferred->enter()); |
| 904 | switch (op) { |
| 905 | case Token::BIT_OR: __ orr(r0, r0, Operand(value)); break; |
| 906 | case Token::BIT_XOR: __ eor(r0, r0, Operand(value)); break; |
| 907 | case Token::BIT_AND: __ and_(r0, r0, Operand(value)); break; |
| 908 | default: UNREACHABLE(); |
| 909 | } |
| 910 | __ bind(deferred->exit()); |
| 911 | break; |
| 912 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 914 | case Token::SHL: |
| 915 | case Token::SHR: |
| 916 | case Token::SAR: { |
| 917 | if (reversed) { |
| 918 | __ mov(ip, Operand(value)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 919 | frame_->Push(ip); |
| 920 | frame_->Push(r0); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 921 | GenericBinaryOperation(op); |
| 922 | |
| 923 | } else { |
| 924 | int shift_value = int_value & 0x1f; // least significant 5 bits |
| 925 | DeferredCode* deferred = |
| 926 | new DeferredInlinedSmiOperation(this, op, shift_value, false); |
| 927 | __ tst(r0, Operand(kSmiTagMask)); |
| 928 | __ b(ne, deferred->enter()); |
| 929 | __ mov(r2, Operand(r0, ASR, kSmiTagSize)); // remove tags |
| 930 | switch (op) { |
| 931 | case Token::SHL: { |
| 932 | __ mov(r2, Operand(r2, LSL, shift_value)); |
| 933 | // check that the *unsigned* result fits in a smi |
| 934 | __ add(r3, r2, Operand(0x40000000), SetCC); |
| 935 | __ b(mi, deferred->enter()); |
| 936 | break; |
| 937 | } |
| 938 | case Token::SHR: { |
| 939 | // LSR by immediate 0 means shifting 32 bits. |
| 940 | if (shift_value != 0) { |
| 941 | __ mov(r2, Operand(r2, LSR, shift_value)); |
| 942 | } |
| 943 | // check that the *unsigned* result fits in a smi |
| 944 | // neither of the two high-order bits can be set: |
| 945 | // - 0x80000000: high bit would be lost when smi tagging |
| 946 | // - 0x40000000: this number would convert to negative when |
| 947 | // smi tagging these two cases can only happen with shifts |
| 948 | // by 0 or 1 when handed a valid smi |
| 949 | __ and_(r3, r2, Operand(0xc0000000), SetCC); |
| 950 | __ b(ne, deferred->enter()); |
| 951 | break; |
| 952 | } |
| 953 | case Token::SAR: { |
| 954 | if (shift_value != 0) { |
| 955 | // ASR by immediate 0 means shifting 32 bits. |
| 956 | __ mov(r2, Operand(r2, ASR, shift_value)); |
| 957 | } |
| 958 | break; |
| 959 | } |
| 960 | default: UNREACHABLE(); |
| 961 | } |
| 962 | __ mov(r0, Operand(r2, LSL, kSmiTagSize)); |
| 963 | __ bind(deferred->exit()); |
| 964 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | break; |
| 966 | } |
| 967 | |
| 968 | default: |
| 969 | if (!reversed) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 970 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 971 | __ mov(r0, Operand(value)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 972 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 973 | } else { |
| 974 | __ mov(ip, Operand(value)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 975 | frame_->Push(ip); |
| 976 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 977 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 978 | GenericBinaryOperation(op); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 979 | break; |
| 980 | } |
| 981 | |
| 982 | __ bind(&exit); |
| 983 | } |
| 984 | |
| 985 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 986 | void CodeGenerator::Comparison(Condition cc, bool strict) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 987 | // sp[0] : y |
| 988 | // sp[1] : x |
| 989 | // result : cc register |
| 990 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 991 | // Strict only makes sense for equality comparisons. |
| 992 | ASSERT(!strict || cc == eq); |
| 993 | |
| 994 | Label exit, smi; |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 995 | // Implement '>' and '<=' by reversal to obtain ECMA-262 conversion order. |
| 996 | if (cc == gt || cc == le) { |
| 997 | cc = ReverseCondition(cc); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 998 | frame_->Pop(r1); |
| 999 | frame_->Pop(r0); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1000 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1001 | frame_->Pop(r0); |
| 1002 | frame_->Pop(r1); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1003 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1004 | __ orr(r2, r0, Operand(r1)); |
| 1005 | __ tst(r2, Operand(kSmiTagMask)); |
| 1006 | __ b(eq, &smi); |
| 1007 | |
| 1008 | // Perform non-smi comparison by runtime call. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1009 | frame_->Push(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1010 | |
| 1011 | // Figure out which native to call and setup the arguments. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1012 | Builtins::JavaScript native; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1013 | int argc; |
| 1014 | if (cc == eq) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1015 | native = strict ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1016 | argc = 1; |
| 1017 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1018 | native = Builtins::COMPARE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1019 | int ncr; // NaN compare result |
| 1020 | if (cc == lt || cc == le) { |
| 1021 | ncr = GREATER; |
| 1022 | } else { |
| 1023 | ASSERT(cc == gt || cc == ge); // remaining cases |
| 1024 | ncr = LESS; |
| 1025 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1026 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1027 | __ mov(r0, Operand(Smi::FromInt(ncr))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1028 | argc = 2; |
| 1029 | } |
| 1030 | |
| 1031 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1032 | // tagged as a small integer. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1033 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1034 | __ mov(r0, Operand(argc)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1035 | __ InvokeBuiltin(native, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1036 | __ cmp(r0, Operand(0)); |
| 1037 | __ b(&exit); |
| 1038 | |
| 1039 | // test smi equality by pointer comparison. |
| 1040 | __ bind(&smi); |
| 1041 | __ cmp(r1, Operand(r0)); |
| 1042 | |
| 1043 | __ bind(&exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1044 | cc_reg_ = cc; |
| 1045 | } |
| 1046 | |
| 1047 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1048 | class CallFunctionStub: public CodeStub { |
| 1049 | public: |
| 1050 | explicit CallFunctionStub(int argc) : argc_(argc) {} |
| 1051 | |
| 1052 | void Generate(MacroAssembler* masm); |
| 1053 | |
| 1054 | private: |
| 1055 | int argc_; |
| 1056 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1057 | #if defined(DEBUG) |
| 1058 | void Print() { PrintF("CallFunctionStub (argc %d)\n", argc_); } |
| 1059 | #endif // defined(DEBUG) |
| 1060 | |
| 1061 | Major MajorKey() { return CallFunction; } |
| 1062 | int MinorKey() { return argc_; } |
| 1063 | }; |
| 1064 | |
| 1065 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1066 | // Call the function on the stack with the given arguments. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1067 | void CodeGenerator::CallWithArguments(ZoneList<Expression*>* args, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1068 | int position) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1069 | // Push the arguments ("left-to-right") on the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1070 | for (int i = 0; i < args->length(); i++) { |
| 1071 | Load(args->at(i)); |
| 1072 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1073 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1074 | // Record the position for debugging purposes. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1075 | CodeForSourcePosition(position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1076 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1077 | // Use the shared code stub to call the function. |
| 1078 | CallFunctionStub call_function(args->length()); |
| 1079 | __ CallStub(&call_function); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1080 | |
| 1081 | // Restore context and pop function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1082 | __ ldr(cp, frame_->Context()); |
| 1083 | frame_->Pop(); // discard the TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1087 | void CodeGenerator::Branch(bool if_true, Label* L) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1088 | ASSERT(has_cc()); |
| 1089 | Condition cc = if_true ? cc_reg_ : NegateCondition(cc_reg_); |
| 1090 | __ b(cc, L); |
| 1091 | cc_reg_ = al; |
| 1092 | } |
| 1093 | |
| 1094 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1095 | void CodeGenerator::CheckStack() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1096 | if (FLAG_check_stack) { |
| 1097 | Comment cmnt(masm_, "[ check stack"); |
| 1098 | StackCheckStub stub; |
| 1099 | __ CallStub(&stub); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1104 | void CodeGenerator::VisitBlock(Block* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1105 | Comment cmnt(masm_, "[ Block"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1106 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | node->set_break_stack_height(break_stack_height_); |
| 1108 | VisitStatements(node->statements()); |
| 1109 | __ bind(node->break_target()); |
| 1110 | } |
| 1111 | |
| 1112 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1113 | void CodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1114 | __ mov(r0, Operand(pairs)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1115 | frame_->Push(r0); |
| 1116 | frame_->Push(cp); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1117 | __ mov(r0, Operand(Smi::FromInt(is_eval() ? 1 : 0))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1118 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | __ CallRuntime(Runtime::kDeclareGlobals, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1120 | // The result is discarded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1124 | void CodeGenerator::VisitDeclaration(Declaration* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1125 | Comment cmnt(masm_, "[ Declaration"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1126 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1127 | Variable* var = node->proxy()->var(); |
| 1128 | ASSERT(var != NULL); // must have been resolved |
| 1129 | Slot* slot = var->slot(); |
| 1130 | |
| 1131 | // If it was not possible to allocate the variable at compile time, |
| 1132 | // we need to "declare" it at runtime to make sure it actually |
| 1133 | // exists in the local context. |
| 1134 | if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 1135 | // Variables with a "LOOKUP" slot were introduced as non-locals |
| 1136 | // during variable resolution and must have mode DYNAMIC. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1137 | ASSERT(var->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1138 | // For now, just do a runtime call. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1139 | frame_->Push(cp); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1140 | __ mov(r0, Operand(var->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1141 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1142 | // Declaration nodes are always declared in only two modes. |
| 1143 | ASSERT(node->mode() == Variable::VAR || node->mode() == Variable::CONST); |
| 1144 | PropertyAttributes attr = node->mode() == Variable::VAR ? NONE : READ_ONLY; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1145 | __ mov(r0, Operand(Smi::FromInt(attr))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1146 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1147 | // Push initial value, if any. |
| 1148 | // Note: For variables we must not push an initial value (such as |
| 1149 | // 'undefined') because we may have a (legal) redeclaration and we |
| 1150 | // must not destroy the current value. |
| 1151 | if (node->mode() == Variable::CONST) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1152 | __ mov(r0, Operand(Factory::the_hole_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1153 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1154 | } else if (node->fun() != NULL) { |
| 1155 | Load(node->fun()); |
| 1156 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1157 | __ mov(r0, Operand(0)); // no initial value! |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1158 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1159 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1160 | __ CallRuntime(Runtime::kDeclareContextSlot, 4); |
| 1161 | // Ignore the return value (declarations are statements). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1162 | return; |
| 1163 | } |
| 1164 | |
| 1165 | ASSERT(!var->is_global()); |
| 1166 | |
| 1167 | // If we have a function or a constant, we need to initialize the variable. |
| 1168 | Expression* val = NULL; |
| 1169 | if (node->mode() == Variable::CONST) { |
| 1170 | val = new Literal(Factory::the_hole_value()); |
| 1171 | } else { |
| 1172 | val = node->fun(); // NULL if we don't have a function |
| 1173 | } |
| 1174 | |
| 1175 | if (val != NULL) { |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 1176 | { |
| 1177 | // Set initial value. |
| 1178 | Reference target(this, node->proxy()); |
| 1179 | Load(val); |
| 1180 | target.SetValue(NOT_CONST_INIT); |
| 1181 | // The reference is removed from the stack (preserving TOS) when |
| 1182 | // it goes out of scope. |
| 1183 | } |
| 1184 | // Get rid of the assigned value (declarations are statements). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1185 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1190 | void CodeGenerator::VisitExpressionStatement(ExpressionStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1191 | Comment cmnt(masm_, "[ ExpressionStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1192 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1193 | Expression* expression = node->expression(); |
| 1194 | expression->MarkAsStatement(); |
| 1195 | Load(expression); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1196 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1200 | void CodeGenerator::VisitEmptyStatement(EmptyStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1201 | Comment cmnt(masm_, "// EmptyStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1202 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1203 | // nothing to do |
| 1204 | } |
| 1205 | |
| 1206 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1207 | void CodeGenerator::VisitIfStatement(IfStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1208 | Comment cmnt(masm_, "[ IfStatement"); |
| 1209 | // Generate different code depending on which |
| 1210 | // parts of the if statement are present or not. |
| 1211 | bool has_then_stm = node->HasThenStatement(); |
| 1212 | bool has_else_stm = node->HasElseStatement(); |
| 1213 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1214 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1215 | |
| 1216 | Label exit; |
| 1217 | if (has_then_stm && has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1218 | Comment cmnt(masm_, "[ IfThenElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1219 | Label then; |
| 1220 | Label else_; |
| 1221 | // if (cond) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1222 | LoadCondition(node->condition(), NOT_INSIDE_TYPEOF, &then, &else_, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1223 | Branch(false, &else_); |
| 1224 | // then |
| 1225 | __ bind(&then); |
| 1226 | Visit(node->then_statement()); |
| 1227 | __ b(&exit); |
| 1228 | // else |
| 1229 | __ bind(&else_); |
| 1230 | Visit(node->else_statement()); |
| 1231 | |
| 1232 | } else if (has_then_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1233 | Comment cmnt(masm_, "[ IfThen"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1234 | ASSERT(!has_else_stm); |
| 1235 | Label then; |
| 1236 | // if (cond) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1237 | LoadCondition(node->condition(), NOT_INSIDE_TYPEOF, &then, &exit, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | Branch(false, &exit); |
| 1239 | // then |
| 1240 | __ bind(&then); |
| 1241 | Visit(node->then_statement()); |
| 1242 | |
| 1243 | } else if (has_else_stm) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1244 | Comment cmnt(masm_, "[ IfElse"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1245 | ASSERT(!has_then_stm); |
| 1246 | Label else_; |
| 1247 | // if (!cond) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1248 | LoadCondition(node->condition(), NOT_INSIDE_TYPEOF, &exit, &else_, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | Branch(true, &exit); |
| 1250 | // else |
| 1251 | __ bind(&else_); |
| 1252 | Visit(node->else_statement()); |
| 1253 | |
| 1254 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1255 | Comment cmnt(masm_, "[ If"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1256 | ASSERT(!has_then_stm && !has_else_stm); |
| 1257 | // if (cond) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1258 | LoadCondition(node->condition(), NOT_INSIDE_TYPEOF, &exit, &exit, false); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1259 | if (has_cc()) { |
| 1260 | cc_reg_ = al; |
| 1261 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1262 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | // end |
| 1267 | __ bind(&exit); |
| 1268 | } |
| 1269 | |
| 1270 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1271 | void CodeGenerator::CleanStack(int num_bytes) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1272 | ASSERT(num_bytes % kPointerSize == 0); |
| 1273 | frame_->Drop(num_bytes / kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1277 | void CodeGenerator::VisitContinueStatement(ContinueStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1278 | Comment cmnt(masm_, "[ ContinueStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1279 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1280 | CleanStack(break_stack_height_ - node->target()->break_stack_height()); |
| 1281 | __ b(node->target()->continue_target()); |
| 1282 | } |
| 1283 | |
| 1284 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1285 | void CodeGenerator::VisitBreakStatement(BreakStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1286 | Comment cmnt(masm_, "[ BreakStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1287 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1288 | CleanStack(break_stack_height_ - node->target()->break_stack_height()); |
| 1289 | __ b(node->target()->break_target()); |
| 1290 | } |
| 1291 | |
| 1292 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1293 | void CodeGenerator::VisitReturnStatement(ReturnStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1294 | Comment cmnt(masm_, "[ ReturnStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1295 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1296 | Load(node->expression()); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1297 | // Move the function result into r0. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1298 | frame_->Pop(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1299 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1300 | __ b(&function_return_); |
| 1301 | } |
| 1302 | |
| 1303 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1304 | void CodeGenerator::VisitWithEnterStatement(WithEnterStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1305 | Comment cmnt(masm_, "[ WithEnterStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1306 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1307 | Load(node->expression()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1308 | if (node->is_catch_block()) { |
| 1309 | __ CallRuntime(Runtime::kPushCatchContext, 1); |
| 1310 | } else { |
| 1311 | __ CallRuntime(Runtime::kPushContext, 1); |
| 1312 | } |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1313 | if (kDebug) { |
| 1314 | Label verified_true; |
| 1315 | __ cmp(r0, Operand(cp)); |
| 1316 | __ b(eq, &verified_true); |
| 1317 | __ stop("PushContext: r0 is expected to be the same as cp"); |
| 1318 | __ bind(&verified_true); |
| 1319 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1320 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1321 | __ str(cp, frame_->Context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1325 | void CodeGenerator::VisitWithExitStatement(WithExitStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1326 | Comment cmnt(masm_, "[ WithExitStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1327 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1328 | // Pop context. |
| 1329 | __ ldr(cp, ContextOperand(cp, Context::PREVIOUS_INDEX)); |
| 1330 | // Update context local. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1331 | __ str(cp, frame_->Context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1335 | int CodeGenerator::FastCaseSwitchMaxOverheadFactor() { |
| 1336 | return kFastSwitchMaxOverheadFactor; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1339 | int CodeGenerator::FastCaseSwitchMinCaseCount() { |
| 1340 | return kFastSwitchMinCaseCount; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1344 | void CodeGenerator::GenerateFastCaseSwitchJumpTable( |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1345 | SwitchStatement* node, |
| 1346 | int min_index, |
| 1347 | int range, |
| 1348 | Label* fail_label, |
| 1349 | Vector<Label*> case_targets, |
| 1350 | Vector<Label> case_labels) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1351 | |
| 1352 | ASSERT(kSmiTag == 0 && kSmiTagSize <= 2); |
| 1353 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1354 | frame_->Pop(r0); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1355 | |
| 1356 | // Test for a Smi value in a HeapNumber. |
| 1357 | Label is_smi; |
| 1358 | __ tst(r0, Operand(kSmiTagMask)); |
| 1359 | __ b(eq, &is_smi); |
| 1360 | __ ldr(r1, MemOperand(r0, HeapObject::kMapOffset - kHeapObjectTag)); |
| 1361 | __ ldrb(r1, MemOperand(r1, Map::kInstanceTypeOffset - kHeapObjectTag)); |
| 1362 | __ cmp(r1, Operand(HEAP_NUMBER_TYPE)); |
| 1363 | __ b(ne, fail_label); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1364 | frame_->Push(r0); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1365 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 1366 | __ bind(&is_smi); |
| 1367 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1368 | if (min_index != 0) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1369 | // Small positive numbers can be immediate operands. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1370 | if (min_index < 0) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1371 | // If min_index is Smi::kMinValue, -min_index is not a Smi. |
| 1372 | if (Smi::IsValid(-min_index)) { |
| 1373 | __ add(r0, r0, Operand(Smi::FromInt(-min_index))); |
| 1374 | } else { |
| 1375 | __ add(r0, r0, Operand(Smi::FromInt(-min_index - 1))); |
| 1376 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
| 1377 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1378 | } else { |
| 1379 | __ sub(r0, r0, Operand(Smi::FromInt(min_index))); |
| 1380 | } |
| 1381 | } |
| 1382 | __ tst(r0, Operand(0x80000000 | kSmiTagMask)); |
| 1383 | __ b(ne, fail_label); |
| 1384 | __ cmp(r0, Operand(Smi::FromInt(range))); |
| 1385 | __ b(ge, fail_label); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 1386 | __ SmiJumpTable(r0, case_targets); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1387 | |
| 1388 | GenerateFastCaseSwitchCases(node, case_labels); |
| 1389 | } |
| 1390 | |
| 1391 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1392 | void CodeGenerator::VisitSwitchStatement(SwitchStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | Comment cmnt(masm_, "[ SwitchStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1394 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1395 | node->set_break_stack_height(break_stack_height_); |
| 1396 | |
| 1397 | Load(node->tag()); |
| 1398 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1399 | if (TryGenerateFastCaseSwitchStatement(node)) { |
| 1400 | return; |
| 1401 | } |
| 1402 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1403 | Label next, fall_through, default_case; |
| 1404 | ZoneList<CaseClause*>* cases = node->cases(); |
| 1405 | int length = cases->length(); |
| 1406 | |
| 1407 | for (int i = 0; i < length; i++) { |
| 1408 | CaseClause* clause = cases->at(i); |
| 1409 | |
| 1410 | Comment cmnt(masm_, "[ case clause"); |
| 1411 | |
| 1412 | if (clause->is_default()) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1413 | // Continue matching cases. The program will execute the default case's |
| 1414 | // statements if it does not match any of the cases. |
| 1415 | __ b(&next); |
| 1416 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1417 | // Bind the default case label, so we can branch to it when we |
| 1418 | // have compared against all other cases. |
| 1419 | ASSERT(default_case.is_unused()); // at most one default clause |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1420 | __ bind(&default_case); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1421 | } else { |
| 1422 | __ bind(&next); |
| 1423 | next.Unuse(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1424 | __ ldr(r0, frame_->Top()); |
| 1425 | frame_->Push(r0); // duplicate TOS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1426 | Load(clause->label()); |
| 1427 | Comparison(eq, true); |
| 1428 | Branch(false, &next); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1431 | // Entering the case statement for the first time. Remove the switch value |
| 1432 | // from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1433 | frame_->Pop(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1434 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1435 | // Generate code for the body. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1436 | // This is also the target for the fall through from the previous case's |
| 1437 | // statements which has to skip over the matching code and the popping of |
| 1438 | // the switch value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1439 | __ bind(&fall_through); |
| 1440 | fall_through.Unuse(); |
| 1441 | VisitStatements(clause->statements()); |
| 1442 | __ b(&fall_through); |
| 1443 | } |
| 1444 | |
| 1445 | __ bind(&next); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1446 | // Reached the end of the case statements without matching any of the cases. |
| 1447 | if (default_case.is_bound()) { |
| 1448 | // A default case exists -> execute its statements. |
| 1449 | __ b(&default_case); |
| 1450 | } else { |
| 1451 | // Remove the switch value from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1452 | frame_->Pop(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1453 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1454 | |
| 1455 | __ bind(&fall_through); |
| 1456 | __ bind(node->break_target()); |
| 1457 | } |
| 1458 | |
| 1459 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1460 | void CodeGenerator::VisitLoopStatement(LoopStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1461 | Comment cmnt(masm_, "[ LoopStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1462 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1463 | node->set_break_stack_height(break_stack_height_); |
| 1464 | |
| 1465 | // simple condition analysis |
| 1466 | enum { ALWAYS_TRUE, ALWAYS_FALSE, DONT_KNOW } info = DONT_KNOW; |
| 1467 | if (node->cond() == NULL) { |
| 1468 | ASSERT(node->type() == LoopStatement::FOR_LOOP); |
| 1469 | info = ALWAYS_TRUE; |
| 1470 | } else { |
| 1471 | Literal* lit = node->cond()->AsLiteral(); |
| 1472 | if (lit != NULL) { |
| 1473 | if (lit->IsTrue()) { |
| 1474 | info = ALWAYS_TRUE; |
| 1475 | } else if (lit->IsFalse()) { |
| 1476 | info = ALWAYS_FALSE; |
| 1477 | } |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | Label loop, entry; |
| 1482 | |
| 1483 | // init |
| 1484 | if (node->init() != NULL) { |
| 1485 | ASSERT(node->type() == LoopStatement::FOR_LOOP); |
| 1486 | Visit(node->init()); |
| 1487 | } |
| 1488 | if (node->type() != LoopStatement::DO_LOOP && info != ALWAYS_TRUE) { |
| 1489 | __ b(&entry); |
| 1490 | } |
| 1491 | |
| 1492 | // body |
| 1493 | __ bind(&loop); |
| 1494 | Visit(node->body()); |
| 1495 | |
| 1496 | // next |
| 1497 | __ bind(node->continue_target()); |
| 1498 | if (node->next() != NULL) { |
| 1499 | // Record source position of the statement as this code which is after the |
| 1500 | // code for the body actually belongs to the loop statement and not the |
| 1501 | // body. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1502 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1503 | ASSERT(node->type() == LoopStatement::FOR_LOOP); |
| 1504 | Visit(node->next()); |
| 1505 | } |
| 1506 | |
| 1507 | // cond |
| 1508 | __ bind(&entry); |
| 1509 | switch (info) { |
| 1510 | case ALWAYS_TRUE: |
| 1511 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
| 1512 | __ b(&loop); |
| 1513 | break; |
| 1514 | case ALWAYS_FALSE: |
| 1515 | break; |
| 1516 | case DONT_KNOW: |
| 1517 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
| 1518 | LoadCondition(node->cond(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1519 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1520 | &loop, |
| 1521 | node->break_target(), |
| 1522 | true); |
| 1523 | Branch(true, &loop); |
| 1524 | break; |
| 1525 | } |
| 1526 | |
| 1527 | // exit |
| 1528 | __ bind(node->break_target()); |
| 1529 | } |
| 1530 | |
| 1531 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1532 | void CodeGenerator::VisitForInStatement(ForInStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1533 | Comment cmnt(masm_, "[ ForInStatement"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1534 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1535 | |
| 1536 | // We keep stuff on the stack while the body is executing. |
| 1537 | // Record it, so that a break/continue crossing this statement |
| 1538 | // can restore the stack. |
| 1539 | const int kForInStackSize = 5 * kPointerSize; |
| 1540 | break_stack_height_ += kForInStackSize; |
| 1541 | node->set_break_stack_height(break_stack_height_); |
| 1542 | |
| 1543 | Label loop, next, entry, cleanup, exit, primitive, jsobject; |
| 1544 | Label filter_key, end_del_check, fixed_array, non_string; |
| 1545 | |
| 1546 | // Get the object to enumerate over (converted to JSObject). |
| 1547 | Load(node->enumerable()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1548 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1549 | |
| 1550 | // Both SpiderMonkey and kjs ignore null and undefined in contrast |
| 1551 | // to the specification. 12.6.4 mandates a call to ToObject. |
| 1552 | __ cmp(r0, Operand(Factory::undefined_value())); |
| 1553 | __ b(eq, &exit); |
| 1554 | __ cmp(r0, Operand(Factory::null_value())); |
| 1555 | __ b(eq, &exit); |
| 1556 | |
| 1557 | // Stack layout in body: |
| 1558 | // [iteration counter (Smi)] |
| 1559 | // [length of array] |
| 1560 | // [FixedArray] |
| 1561 | // [Map or 0] |
| 1562 | // [Object] |
| 1563 | |
| 1564 | // Check if enumerable is already a JSObject |
| 1565 | __ tst(r0, Operand(kSmiTagMask)); |
| 1566 | __ b(eq, &primitive); |
| 1567 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 1568 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 1569 | __ cmp(r1, Operand(FIRST_JS_OBJECT_TYPE)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1570 | __ b(hs, &jsobject); |
| 1571 | |
| 1572 | __ bind(&primitive); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1573 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1574 | __ mov(r0, Operand(0)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1575 | __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1576 | |
| 1577 | |
| 1578 | __ bind(&jsobject); |
| 1579 | |
| 1580 | // Get the set of properties (as a FixedArray or Map). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1581 | frame_->Push(r0); // duplicate the object being enumerated |
| 1582 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1583 | __ CallRuntime(Runtime::kGetPropertyNamesFast, 1); |
| 1584 | |
| 1585 | // If we got a Map, we can do a fast modification check. |
| 1586 | // Otherwise, we got a FixedArray, and we have to do a slow check. |
| 1587 | __ mov(r2, Operand(r0)); |
| 1588 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 1589 | __ cmp(r1, Operand(Factory::meta_map())); |
| 1590 | __ b(ne, &fixed_array); |
| 1591 | |
| 1592 | // Get enum cache |
| 1593 | __ mov(r1, Operand(r0)); |
| 1594 | __ ldr(r1, FieldMemOperand(r1, Map::kInstanceDescriptorsOffset)); |
| 1595 | __ ldr(r1, FieldMemOperand(r1, DescriptorArray::kEnumerationIndexOffset)); |
| 1596 | __ ldr(r2, |
| 1597 | FieldMemOperand(r1, DescriptorArray::kEnumCacheBridgeCacheOffset)); |
| 1598 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1599 | frame_->Push(r0); // map |
| 1600 | frame_->Push(r2); // enum cache bridge cache |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1601 | __ ldr(r0, FieldMemOperand(r2, FixedArray::kLengthOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1602 | __ mov(r0, Operand(r0, LSL, kSmiTagSize)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1603 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1604 | __ mov(r0, Operand(Smi::FromInt(0))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1605 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | __ b(&entry); |
| 1607 | |
| 1608 | |
| 1609 | __ bind(&fixed_array); |
| 1610 | |
| 1611 | __ mov(r1, Operand(Smi::FromInt(0))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1612 | frame_->Push(r1); // insert 0 in place of Map |
| 1613 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1614 | |
| 1615 | // 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] | 1616 | __ ldr(r0, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1617 | __ mov(r0, Operand(r0, LSL, kSmiTagSize)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1618 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1619 | __ mov(r0, Operand(Smi::FromInt(0))); // init index |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1620 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1621 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1622 | __ b(&entry); |
| 1623 | |
| 1624 | // Body. |
| 1625 | __ bind(&loop); |
| 1626 | Visit(node->body()); |
| 1627 | |
| 1628 | // Next. |
| 1629 | __ bind(node->continue_target()); |
| 1630 | __ bind(&next); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1631 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1632 | __ add(r0, r0, Operand(Smi::FromInt(1))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1633 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1634 | |
| 1635 | // Condition. |
| 1636 | __ bind(&entry); |
| 1637 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1638 | // sp[0] : index |
| 1639 | // sp[1] : array/enum cache length |
| 1640 | // sp[2] : array or enum cache |
| 1641 | // sp[3] : 0 or map |
| 1642 | // sp[4] : enumerable |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1643 | __ ldr(r0, frame_->Element(0)); // load the current count |
| 1644 | __ ldr(r1, frame_->Element(1)); // load the length |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1645 | __ cmp(r0, Operand(r1)); // compare to the array length |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1646 | __ b(hs, &cleanup); |
| 1647 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1648 | __ ldr(r0, frame_->Element(0)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1649 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1650 | // Get the i'th entry of the array. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1651 | __ ldr(r2, frame_->Element(2)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1652 | __ add(r2, r2, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 1653 | __ ldr(r3, MemOperand(r2, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 1654 | |
| 1655 | // Get Map or 0. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1656 | __ ldr(r2, frame_->Element(3)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1657 | // Check if this (still) matches the map of the enumerable. |
| 1658 | // If not, we have to filter the key. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1659 | __ ldr(r1, frame_->Element(4)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1660 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 1661 | __ cmp(r1, Operand(r2)); |
| 1662 | __ b(eq, &end_del_check); |
| 1663 | |
| 1664 | // Convert the entry to a string (or null if it isn't a property anymore). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1665 | __ ldr(r0, frame_->Element(4)); // push enumerable |
| 1666 | frame_->Push(r0); |
| 1667 | frame_->Push(r3); // push entry |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1668 | __ mov(r0, Operand(1)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1669 | __ InvokeBuiltin(Builtins::FILTER_KEY, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1670 | __ mov(r3, Operand(r0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1671 | |
| 1672 | // If the property has been removed while iterating, we just skip it. |
| 1673 | __ cmp(r3, Operand(Factory::null_value())); |
| 1674 | __ b(eq, &next); |
| 1675 | |
| 1676 | |
| 1677 | __ bind(&end_del_check); |
| 1678 | |
| 1679 | // Store the entry in the 'each' expression and take another spin in the loop. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1680 | // r3: i'th entry of the enum cache (or string there of) |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1681 | frame_->Push(r3); // push entry |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1682 | { Reference each(this, node->each()); |
| 1683 | if (!each.is_illegal()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1684 | if (each.size() > 0) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1685 | __ ldr(r0, frame_->Element(each.size())); |
| 1686 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1687 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1688 | // If the reference was to a slot we rely on the convenient property |
| 1689 | // that it doesn't matter whether a value (eg, r3 pushed above) is |
| 1690 | // right on top of or right underneath a zero-sized reference. |
| 1691 | each.SetValue(NOT_CONST_INIT); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1692 | if (each.size() > 0) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1693 | // It's safe to pop the value lying on top of the reference before |
| 1694 | // unloading the reference itself (which preserves the top of stack, |
| 1695 | // ie, now the topmost value of the non-zero sized reference), since |
| 1696 | // we will discard the top of stack after unloading the reference |
| 1697 | // anyway. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1698 | frame_->Pop(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1699 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | } |
| 1701 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1702 | // Discard the i'th entry pushed above or else the remainder of the |
| 1703 | // reference, whichever is currently on top of the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1704 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1705 | CheckStack(); // TODO(1222600): ignore if body contains calls. |
| 1706 | __ jmp(&loop); |
| 1707 | |
| 1708 | // Cleanup. |
| 1709 | __ bind(&cleanup); |
| 1710 | __ bind(node->break_target()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1711 | frame_->Drop(5); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1712 | |
| 1713 | // Exit. |
| 1714 | __ bind(&exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1715 | |
| 1716 | break_stack_height_ -= kForInStackSize; |
| 1717 | } |
| 1718 | |
| 1719 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1720 | void CodeGenerator::VisitTryCatch(TryCatch* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1721 | Comment cmnt(masm_, "[ TryCatch"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1722 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1723 | |
| 1724 | Label try_block, exit; |
| 1725 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1726 | __ bl(&try_block); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1727 | // --- Catch block --- |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1728 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1729 | |
| 1730 | // Store the caught exception in the catch variable. |
| 1731 | { Reference ref(this, node->catch_var()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1732 | ASSERT(ref.is_slot()); |
| 1733 | // Here we make use of the convenient property that it doesn't matter |
| 1734 | // whether a value is immediately on top of or underneath a zero-sized |
| 1735 | // reference. |
| 1736 | ref.SetValue(NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | // Remove the exception from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1740 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1741 | |
| 1742 | VisitStatements(node->catch_block()->statements()); |
| 1743 | __ b(&exit); |
| 1744 | |
| 1745 | |
| 1746 | // --- Try block --- |
| 1747 | __ bind(&try_block); |
| 1748 | |
| 1749 | __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); |
| 1750 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1751 | // Shadow the labels for all escapes from the try block, including |
| 1752 | // returns. During shadowing, the original label is hidden as the |
| 1753 | // LabelShadow and operations on the original actually affect the |
| 1754 | // shadowing label. |
| 1755 | // |
| 1756 | // We should probably try to unify the escaping labels and the return |
| 1757 | // label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1758 | int nof_escapes = node->escaping_labels()->length(); |
| 1759 | List<LabelShadow*> shadows(1 + nof_escapes); |
| 1760 | shadows.Add(new LabelShadow(&function_return_)); |
| 1761 | for (int i = 0; i < nof_escapes; i++) { |
| 1762 | shadows.Add(new LabelShadow(node->escaping_labels()->at(i))); |
| 1763 | } |
| 1764 | |
| 1765 | // Generate code for the statements in the try block. |
| 1766 | VisitStatements(node->try_block()->statements()); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1767 | // Discard the code slot from the handler. |
| 1768 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1769 | |
| 1770 | // Stop the introduced shadowing and count the number of required unlinks. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1771 | // After shadowing stops, the original labels are unshadowed and the |
| 1772 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1773 | int nof_unlinks = 0; |
| 1774 | for (int i = 0; i <= nof_escapes; i++) { |
| 1775 | shadows[i]->StopShadowing(); |
| 1776 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 1777 | } |
| 1778 | |
| 1779 | // Unlink from try chain. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1780 | // The code slot has already been discarded, so the next index is |
| 1781 | // adjusted by 1. |
| 1782 | const int kNextIndex = |
| 1783 | (StackHandlerConstants::kNextOffset / kPointerSize) - 1; |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1784 | __ ldr(r1, frame_->Element(kNextIndex)); // read next_sp |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1785 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 1786 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1787 | // The code slot has already been dropped from the handler. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1788 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1789 | if (nof_unlinks > 0) __ b(&exit); |
| 1790 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1791 | // Generate unlink code for the (formerly) shadowing labels that have been |
| 1792 | // jumped to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1793 | for (int i = 0; i <= nof_escapes; i++) { |
| 1794 | if (shadows[i]->is_linked()) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1795 | // Unlink from try chain; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1796 | __ bind(shadows[i]); |
| 1797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1798 | // Reload sp from the top handler, because some statements that we |
| 1799 | // break from (eg, for...in) may have left stuff on the stack. |
| 1800 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 1801 | __ ldr(sp, MemOperand(r3)); |
| 1802 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1803 | __ ldr(r1, frame_->Element(kNextIndex)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | __ str(r1, MemOperand(r3)); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1805 | // The code slot has already been dropped from the handler. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1806 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1807 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1808 | __ b(shadows[i]->original_label()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | __ bind(&exit); |
| 1813 | } |
| 1814 | |
| 1815 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1816 | void CodeGenerator::VisitTryFinally(TryFinally* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1817 | Comment cmnt(masm_, "[ TryFinally"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1818 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1819 | |
| 1820 | // State: Used to keep track of reason for entering the finally |
| 1821 | // block. Should probably be extended to hold information for |
| 1822 | // break/continue from within the try block. |
| 1823 | enum { FALLING, THROWING, JUMPING }; |
| 1824 | |
| 1825 | Label exit, unlink, try_block, finally_block; |
| 1826 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1827 | __ bl(&try_block); |
| 1828 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1829 | frame_->Push(r0); // save exception object on the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1830 | // In case of thrown exceptions, this is where we continue. |
| 1831 | __ mov(r2, Operand(Smi::FromInt(THROWING))); |
| 1832 | __ b(&finally_block); |
| 1833 | |
| 1834 | |
| 1835 | // --- Try block --- |
| 1836 | __ bind(&try_block); |
| 1837 | |
| 1838 | __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); |
| 1839 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1840 | // Shadow the labels for all escapes from the try block, including |
| 1841 | // returns. Shadowing hides the original label as the LabelShadow and |
| 1842 | // operations on the original actually affect the shadowing label. |
| 1843 | // |
| 1844 | // We should probably try to unify the escaping labels and the return |
| 1845 | // label. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1846 | int nof_escapes = node->escaping_labels()->length(); |
| 1847 | List<LabelShadow*> shadows(1 + nof_escapes); |
| 1848 | shadows.Add(new LabelShadow(&function_return_)); |
| 1849 | for (int i = 0; i < nof_escapes; i++) { |
| 1850 | shadows.Add(new LabelShadow(node->escaping_labels()->at(i))); |
| 1851 | } |
| 1852 | |
| 1853 | // Generate code for the statements in the try block. |
| 1854 | VisitStatements(node->try_block()->statements()); |
| 1855 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1856 | // Stop the introduced shadowing and count the number of required unlinks. |
| 1857 | // After shadowing stops, the original labels are unshadowed and the |
| 1858 | // LabelShadows represent the formerly shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1859 | int nof_unlinks = 0; |
| 1860 | for (int i = 0; i <= nof_escapes; i++) { |
| 1861 | shadows[i]->StopShadowing(); |
| 1862 | if (shadows[i]->is_linked()) nof_unlinks++; |
| 1863 | } |
| 1864 | |
| 1865 | // Set the state on the stack to FALLING. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1866 | __ mov(r0, Operand(Factory::undefined_value())); // fake TOS |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1867 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1868 | __ mov(r2, Operand(Smi::FromInt(FALLING))); |
| 1869 | if (nof_unlinks > 0) __ b(&unlink); |
| 1870 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1871 | // Generate code to set the state for the (formerly) shadowing labels that |
| 1872 | // have been jumped to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1873 | for (int i = 0; i <= nof_escapes; i++) { |
| 1874 | if (shadows[i]->is_linked()) { |
| 1875 | __ bind(shadows[i]); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1876 | if (shadows[i]->original_label() == &function_return_) { |
| 1877 | // If this label shadowed the function return, materialize the |
| 1878 | // return value on the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1879 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1880 | } else { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1881 | // Fake TOS for labels that shadowed breaks and continues. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1882 | __ mov(r0, Operand(Factory::undefined_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1883 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1884 | } |
| 1885 | __ mov(r2, Operand(Smi::FromInt(JUMPING + i))); |
| 1886 | __ b(&unlink); |
| 1887 | } |
| 1888 | } |
| 1889 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1890 | // Unlink from try chain; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1891 | __ bind(&unlink); |
| 1892 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1893 | frame_->Pop(r0); // Preserve TOS result in r0 across stack manipulation. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1894 | // Reload sp from the top handler, because some statements that we |
| 1895 | // break from (eg, for...in) may have left stuff on the stack. |
| 1896 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 1897 | __ ldr(sp, MemOperand(r3)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1898 | const int kNextIndex = (StackHandlerConstants::kNextOffset |
| 1899 | + StackHandlerConstants::kAddressDisplacement) |
| 1900 | / kPointerSize; |
| 1901 | __ ldr(r1, frame_->Element(kNextIndex)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1902 | __ str(r1, MemOperand(r3)); |
| 1903 | ASSERT(StackHandlerConstants::kCodeOffset == 0); // first field is code |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1904 | // The stack pointer was restored to just below the code slot (the |
| 1905 | // topmost slot) of the handler, so all but the code slot need to be |
| 1906 | // dropped. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1907 | frame_->Drop(StackHandlerConstants::kSize / kPointerSize - 1); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1908 | // Restore result to TOS. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1909 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1910 | |
| 1911 | // --- Finally block --- |
| 1912 | __ bind(&finally_block); |
| 1913 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1914 | // Push the state on the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1915 | frame_->Push(r2); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1916 | |
| 1917 | // We keep two elements on the stack - the (possibly faked) result |
| 1918 | // and the state - while evaluating the finally block. Record it, so |
| 1919 | // that a break/continue crossing this statement can restore the |
| 1920 | // stack. |
| 1921 | const int kFinallyStackSize = 2 * kPointerSize; |
| 1922 | break_stack_height_ += kFinallyStackSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1923 | |
| 1924 | // Generate code for the statements in the finally block. |
| 1925 | VisitStatements(node->finally_block()->statements()); |
| 1926 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1927 | // Restore state and return value or faked TOS. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1928 | frame_->Pop(r2); |
| 1929 | frame_->Pop(r0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 1930 | break_stack_height_ -= kFinallyStackSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1931 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1932 | // Generate code to jump to the right destination for all used (formerly) |
| 1933 | // shadowing labels. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1934 | for (int i = 0; i <= nof_escapes; i++) { |
| 1935 | if (shadows[i]->is_bound()) { |
| 1936 | __ cmp(r2, Operand(Smi::FromInt(JUMPING + i))); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 1937 | __ b(eq, shadows[i]->original_label()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | // Check if we need to rethrow the exception. |
| 1942 | __ cmp(r2, Operand(Smi::FromInt(THROWING))); |
| 1943 | __ b(ne, &exit); |
| 1944 | |
| 1945 | // Rethrow exception. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1946 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1947 | __ CallRuntime(Runtime::kReThrow, 1); |
| 1948 | |
| 1949 | // Done. |
| 1950 | __ bind(&exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1954 | void CodeGenerator::VisitDebuggerStatement(DebuggerStatement* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1955 | Comment cmnt(masm_, "[ DebuggerStatament"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 1956 | CodeForStatement(node); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 1957 | __ CallRuntime(Runtime::kDebugBreak, 0); |
| 1958 | // Ignore the return value. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1962 | void CodeGenerator::InstantiateBoilerplate(Handle<JSFunction> boilerplate) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1963 | ASSERT(boilerplate->IsBoilerplate()); |
| 1964 | |
| 1965 | // Push the boilerplate on the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 1966 | __ mov(r0, Operand(boilerplate)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1967 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1968 | |
| 1969 | // Create a new closure. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1970 | frame_->Push(cp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1971 | __ CallRuntime(Runtime::kNewClosure, 2); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 1972 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1976 | void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1977 | Comment cmnt(masm_, "[ FunctionLiteral"); |
| 1978 | |
| 1979 | // Build the function boilerplate and instantiate it. |
| 1980 | Handle<JSFunction> boilerplate = BuildBoilerplate(node); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1981 | // Check for stack-overflow exception. |
| 1982 | if (HasStackOverflow()) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1983 | InstantiateBoilerplate(boilerplate); |
| 1984 | } |
| 1985 | |
| 1986 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1987 | void CodeGenerator::VisitFunctionBoilerplateLiteral( |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | FunctionBoilerplateLiteral* node) { |
| 1989 | Comment cmnt(masm_, "[ FunctionBoilerplateLiteral"); |
| 1990 | InstantiateBoilerplate(node->boilerplate()); |
| 1991 | } |
| 1992 | |
| 1993 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1994 | void CodeGenerator::VisitConditional(Conditional* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1995 | Comment cmnt(masm_, "[ Conditional"); |
| 1996 | Label then, else_, exit; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1997 | LoadCondition(node->condition(), NOT_INSIDE_TYPEOF, &then, &else_, true); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1998 | Branch(false, &else_); |
| 1999 | __ bind(&then); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2000 | Load(node->then_expression(), typeof_state()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2001 | __ b(&exit); |
| 2002 | __ bind(&else_); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2003 | Load(node->else_expression(), typeof_state()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2004 | __ bind(&exit); |
| 2005 | } |
| 2006 | |
| 2007 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2008 | void CodeGenerator::LoadFromSlot(Slot* slot, TypeofState typeof_state) { |
| 2009 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2010 | ASSERT(slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2011 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2012 | Label slow, done; |
| 2013 | |
| 2014 | // Generate fast-case code for variables that might be shadowed by |
| 2015 | // eval-introduced variables. Eval is used a lot without |
| 2016 | // introducing variables. In those cases, we do not want to |
| 2017 | // perform a runtime call for all variables in the scope |
| 2018 | // containing the eval. |
| 2019 | if (slot->var()->mode() == Variable::DYNAMIC_GLOBAL) { |
| 2020 | LoadFromGlobalSlotCheckExtensions(slot, typeof_state, r1, r2, &slow); |
| 2021 | __ b(&done); |
| 2022 | |
| 2023 | } else if (slot->var()->mode() == Variable::DYNAMIC_LOCAL) { |
| 2024 | Slot* potential_slot = slot->var()->local_if_not_shadowed()->slot(); |
| 2025 | // Only generate the fast case for locals that rewrite to slots. |
| 2026 | // This rules out argument loads. |
| 2027 | if (potential_slot != NULL) { |
| 2028 | __ ldr(r0, |
| 2029 | ContextSlotOperandCheckExtensions(potential_slot, |
| 2030 | r1, |
| 2031 | r2, |
| 2032 | &slow)); |
| 2033 | __ b(&done); |
| 2034 | } |
| 2035 | } |
| 2036 | |
| 2037 | __ bind(&slow); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2038 | frame_->Push(cp); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2039 | __ mov(r0, Operand(slot->var()->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2040 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2041 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2042 | if (typeof_state == INSIDE_TYPEOF) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2043 | __ CallRuntime(Runtime::kLoadContextSlotNoReferenceError, 2); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2044 | } else { |
| 2045 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2046 | } |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2047 | |
| 2048 | __ bind(&done); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2049 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2050 | |
| 2051 | } else { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2052 | // Note: We would like to keep the assert below, but it fires because of |
| 2053 | // some nasty code in LoadTypeofExpression() which should be removed... |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2054 | // ASSERT(!slot->var()->is_dynamic()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2056 | // Special handling for locals allocated in registers. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2057 | __ ldr(r0, SlotOperand(slot, r2)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2058 | frame_->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2059 | if (slot->var()->mode() == Variable::CONST) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2060 | // Const slots may contain 'the hole' value (the constant hasn't been |
| 2061 | // initialized yet) which needs to be converted into the 'undefined' |
| 2062 | // value. |
| 2063 | Comment cmnt(masm_, "[ Unhole const"); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2064 | frame_->Pop(r0); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2065 | __ cmp(r0, Operand(Factory::the_hole_value())); |
| 2066 | __ mov(r0, Operand(Factory::undefined_value()), LeaveCC, eq); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2067 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 2073 | void CodeGenerator::LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 2074 | TypeofState typeof_state, |
| 2075 | Register tmp, |
| 2076 | Register tmp2, |
| 2077 | Label* slow) { |
| 2078 | // Check that no extension objects have been created by calls to |
| 2079 | // eval from the current scope to the global scope. |
| 2080 | Register context = cp; |
| 2081 | Scope* s = scope(); |
| 2082 | while (s != NULL) { |
| 2083 | if (s->num_heap_slots() > 0) { |
| 2084 | if (s->calls_eval()) { |
| 2085 | // Check that extension is NULL. |
| 2086 | __ ldr(tmp2, ContextOperand(context, Context::EXTENSION_INDEX)); |
| 2087 | __ tst(tmp2, tmp2); |
| 2088 | __ b(ne, slow); |
| 2089 | } |
| 2090 | // Load next context in chain. |
| 2091 | __ ldr(tmp, ContextOperand(context, Context::CLOSURE_INDEX)); |
| 2092 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 2093 | context = tmp; |
| 2094 | } |
| 2095 | // If no outer scope calls eval, we do not need to check more |
| 2096 | // context extensions. |
| 2097 | if (!s->outer_scope_calls_eval() || s->is_eval_scope()) break; |
| 2098 | s = s->outer_scope(); |
| 2099 | } |
| 2100 | |
| 2101 | if (s->is_eval_scope()) { |
| 2102 | Label next, fast; |
| 2103 | if (!context.is(tmp)) __ mov(tmp, Operand(context)); |
| 2104 | __ bind(&next); |
| 2105 | // Terminate at global context. |
| 2106 | __ ldr(tmp2, FieldMemOperand(tmp, HeapObject::kMapOffset)); |
| 2107 | __ cmp(tmp2, Operand(Factory::global_context_map())); |
| 2108 | __ b(eq, &fast); |
| 2109 | // Check that extension is NULL. |
| 2110 | __ ldr(tmp2, ContextOperand(tmp, Context::EXTENSION_INDEX)); |
| 2111 | __ tst(tmp2, tmp2); |
| 2112 | __ b(ne, slow); |
| 2113 | // Load next context in chain. |
| 2114 | __ ldr(tmp, ContextOperand(tmp, Context::CLOSURE_INDEX)); |
| 2115 | __ ldr(tmp, FieldMemOperand(tmp, JSFunction::kContextOffset)); |
| 2116 | __ b(&next); |
| 2117 | __ bind(&fast); |
| 2118 | } |
| 2119 | |
| 2120 | // All extension objects were empty and it is safe to use a global |
| 2121 | // load IC call. |
| 2122 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 2123 | // Load the global object. |
| 2124 | LoadGlobal(); |
| 2125 | // Setup the name register. |
| 2126 | __ mov(r2, Operand(slot->var()->name())); |
| 2127 | // Call IC stub. |
| 2128 | if (typeof_state == INSIDE_TYPEOF) { |
| 2129 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 2130 | } else { |
| 2131 | __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 2132 | } |
| 2133 | |
| 2134 | // Pop the global object. The result is in r0. |
| 2135 | frame_->Pop(); |
| 2136 | } |
| 2137 | |
| 2138 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2139 | void CodeGenerator::VisitSlot(Slot* node) { |
| 2140 | Comment cmnt(masm_, "[ Slot"); |
| 2141 | LoadFromSlot(node, typeof_state()); |
| 2142 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2143 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2144 | |
| 2145 | void CodeGenerator::VisitVariableProxy(VariableProxy* node) { |
| 2146 | Comment cmnt(masm_, "[ VariableProxy"); |
| 2147 | |
| 2148 | Variable* var = node->var(); |
| 2149 | Expression* expr = var->rewrite(); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2150 | if (expr != NULL) { |
| 2151 | Visit(expr); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2152 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2153 | ASSERT(var->is_global()); |
| 2154 | Reference ref(this, node); |
| 2155 | ref.GetValue(typeof_state()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2156 | } |
| 2157 | } |
| 2158 | |
| 2159 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2160 | void CodeGenerator::VisitLiteral(Literal* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2161 | Comment cmnt(masm_, "[ Literal"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2162 | __ mov(r0, Operand(node->handle())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2163 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2167 | void CodeGenerator::VisitRegExpLiteral(RegExpLiteral* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2168 | Comment cmnt(masm_, "[ RexExp Literal"); |
| 2169 | |
| 2170 | // Retrieve the literal array and check the allocated entry. |
| 2171 | |
| 2172 | // Load the function of this activation. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2173 | __ ldr(r1, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2174 | |
| 2175 | // Load the literals array of the function. |
| 2176 | __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); |
| 2177 | |
| 2178 | // Load the literal at the ast saved index. |
| 2179 | int literal_offset = |
| 2180 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
| 2181 | __ ldr(r2, FieldMemOperand(r1, literal_offset)); |
| 2182 | |
| 2183 | Label done; |
| 2184 | __ cmp(r2, Operand(Factory::undefined_value())); |
| 2185 | __ b(ne, &done); |
| 2186 | |
| 2187 | // If the entry is undefined we call the runtime system to computed |
| 2188 | // the literal. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2189 | frame_->Push(r1); // literal array (0) |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2190 | __ mov(r0, Operand(Smi::FromInt(node->literal_index()))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2191 | frame_->Push(r0); // literal index (1) |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2192 | __ mov(r0, Operand(node->pattern())); // RegExp pattern (2) |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2193 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2194 | __ mov(r0, Operand(node->flags())); // RegExp flags (3) |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2195 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2196 | __ CallRuntime(Runtime::kMaterializeRegExpLiteral, 4); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2197 | __ mov(r2, Operand(r0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2198 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2199 | __ bind(&done); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2200 | // Push the literal. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2201 | frame_->Push(r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | |
| 2205 | // This deferred code stub will be used for creating the boilerplate |
| 2206 | // by calling Runtime_CreateObjectLiteral. |
| 2207 | // Each created boilerplate is stored in the JSFunction and they are |
| 2208 | // therefore context dependent. |
| 2209 | class ObjectLiteralDeferred: public DeferredCode { |
| 2210 | public: |
| 2211 | ObjectLiteralDeferred(CodeGenerator* generator, ObjectLiteral* node) |
| 2212 | : DeferredCode(generator), node_(node) { |
| 2213 | set_comment("[ ObjectLiteralDeferred"); |
| 2214 | } |
| 2215 | virtual void Generate(); |
| 2216 | private: |
| 2217 | ObjectLiteral* node_; |
| 2218 | }; |
| 2219 | |
| 2220 | |
| 2221 | void ObjectLiteralDeferred::Generate() { |
| 2222 | // If the entry is undefined we call the runtime system to computed |
| 2223 | // the literal. |
| 2224 | |
| 2225 | // Literal array (0). |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2226 | __ push(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2227 | // Literal index (1). |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2228 | __ mov(r0, Operand(Smi::FromInt(node_->literal_index()))); |
| 2229 | __ push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2230 | // Constant properties (2). |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2231 | __ mov(r0, Operand(node_->constant_properties())); |
| 2232 | __ push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2233 | __ CallRuntime(Runtime::kCreateObjectLiteralBoilerplate, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2234 | __ mov(r2, Operand(r0)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2238 | void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2239 | Comment cmnt(masm_, "[ ObjectLiteral"); |
| 2240 | |
| 2241 | ObjectLiteralDeferred* deferred = new ObjectLiteralDeferred(this, node); |
| 2242 | |
| 2243 | // Retrieve the literal array and check the allocated entry. |
| 2244 | |
| 2245 | // Load the function of this activation. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2246 | __ ldr(r1, frame_->Function()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2247 | |
| 2248 | // Load the literals array of the function. |
| 2249 | __ ldr(r1, FieldMemOperand(r1, JSFunction::kLiteralsOffset)); |
| 2250 | |
| 2251 | // Load the literal at the ast saved index. |
| 2252 | int literal_offset = |
| 2253 | FixedArray::kHeaderSize + node->literal_index() * kPointerSize; |
| 2254 | __ ldr(r2, FieldMemOperand(r1, literal_offset)); |
| 2255 | |
| 2256 | // Check whether we need to materialize the object literal boilerplate. |
| 2257 | // If so, jump to the deferred code. |
| 2258 | __ cmp(r2, Operand(Factory::undefined_value())); |
| 2259 | __ b(eq, deferred->enter()); |
| 2260 | __ bind(deferred->exit()); |
| 2261 | |
| 2262 | // Push the object literal boilerplate. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2263 | frame_->Push(r2); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2264 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | // Clone the boilerplate object. |
| 2266 | __ CallRuntime(Runtime::kCloneObjectLiteralBoilerplate, 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2267 | frame_->Push(r0); // save the result |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2268 | // r0: cloned object literal |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2269 | |
| 2270 | for (int i = 0; i < node->properties()->length(); i++) { |
| 2271 | ObjectLiteral::Property* property = node->properties()->at(i); |
| 2272 | Literal* key = property->key(); |
| 2273 | Expression* value = property->value(); |
| 2274 | switch (property->kind()) { |
| 2275 | case ObjectLiteral::Property::CONSTANT: break; |
| 2276 | case ObjectLiteral::Property::COMPUTED: // fall through |
| 2277 | case ObjectLiteral::Property::PROTOTYPE: { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2278 | frame_->Push(r0); // dup the result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2279 | Load(key); |
| 2280 | Load(value); |
| 2281 | __ CallRuntime(Runtime::kSetProperty, 3); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2282 | // restore r0 |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2283 | __ ldr(r0, frame_->Top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2284 | break; |
| 2285 | } |
| 2286 | case ObjectLiteral::Property::SETTER: { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2287 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2288 | Load(key); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2289 | __ mov(r0, Operand(Smi::FromInt(1))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2290 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2291 | Load(value); |
| 2292 | __ CallRuntime(Runtime::kDefineAccessor, 4); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2293 | __ ldr(r0, frame_->Top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2294 | break; |
| 2295 | } |
| 2296 | case ObjectLiteral::Property::GETTER: { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2297 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2298 | Load(key); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2299 | __ mov(r0, Operand(Smi::FromInt(0))); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2300 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2301 | Load(value); |
| 2302 | __ CallRuntime(Runtime::kDefineAccessor, 4); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2303 | __ ldr(r0, frame_->Top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2304 | break; |
| 2305 | } |
| 2306 | } |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2311 | void CodeGenerator::VisitArrayLiteral(ArrayLiteral* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2312 | Comment cmnt(masm_, "[ ArrayLiteral"); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2313 | |
| 2314 | // Call runtime to create the array literal. |
| 2315 | __ mov(r0, Operand(node->literals())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2316 | frame_->Push(r0); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2317 | // Load the function of this frame. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2318 | __ ldr(r0, frame_->Function()); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2319 | __ ldr(r0, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2320 | frame_->Push(r0); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2321 | __ CallRuntime(Runtime::kCreateArrayLiteral, 2); |
| 2322 | |
| 2323 | // Push the resulting array literal on the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2324 | frame_->Push(r0); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2325 | |
| 2326 | // Generate code to set the elements in the array that are not |
| 2327 | // literals. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2328 | for (int i = 0; i < node->values()->length(); i++) { |
| 2329 | Expression* value = node->values()->at(i); |
| 2330 | |
| 2331 | // If value is literal the property value is already |
| 2332 | // set in the boilerplate object. |
| 2333 | if (value->AsLiteral() == NULL) { |
| 2334 | // The property must be set by generated code. |
| 2335 | Load(value); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2336 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2337 | |
| 2338 | // Fetch the object literal |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2339 | __ ldr(r1, frame_->Top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2340 | // Get the elements array. |
| 2341 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 2342 | |
| 2343 | // Write to the indexed properties array. |
| 2344 | int offset = i * kPointerSize + Array::kHeaderSize; |
| 2345 | __ str(r0, FieldMemOperand(r1, offset)); |
| 2346 | |
| 2347 | // Update the write barrier for the array address. |
| 2348 | __ mov(r3, Operand(offset)); |
| 2349 | __ RecordWrite(r1, r3, r2); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2350 | } |
| 2351 | } |
| 2352 | } |
| 2353 | |
| 2354 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2355 | void CodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* node) { |
| 2356 | // Call runtime routine to allocate the catch extension object and |
| 2357 | // assign the exception value to the catch variable. |
| 2358 | Comment cmnt(masm_, "[CatchExtensionObject "); |
| 2359 | Load(node->key()); |
| 2360 | Load(node->value()); |
| 2361 | __ CallRuntime(Runtime::kCreateCatchExtensionObject, 2); |
| 2362 | frame_->Push(r0); |
| 2363 | } |
| 2364 | |
| 2365 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2366 | void CodeGenerator::VisitAssignment(Assignment* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2367 | Comment cmnt(masm_, "[ Assignment"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2368 | CodeForStatement(node); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2369 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2370 | Reference target(this, node->target()); |
| 2371 | if (target.is_illegal()) return; |
| 2372 | |
| 2373 | if (node->op() == Token::ASSIGN || |
| 2374 | node->op() == Token::INIT_VAR || |
| 2375 | node->op() == Token::INIT_CONST) { |
| 2376 | Load(node->value()); |
| 2377 | |
| 2378 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2379 | target.GetValue(NOT_INSIDE_TYPEOF); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2380 | Literal* literal = node->value()->AsLiteral(); |
| 2381 | if (literal != NULL && literal->handle()->IsSmi()) { |
| 2382 | SmiOperation(node->binary_op(), literal->handle(), false); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2383 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2384 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2385 | } else { |
| 2386 | Load(node->value()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2387 | GenericBinaryOperation(node->binary_op()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2388 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
| 2392 | Variable* var = node->target()->AsVariableProxy()->AsVariable(); |
| 2393 | if (var != NULL && |
| 2394 | (var->mode() == Variable::CONST) && |
| 2395 | node->op() != Token::INIT_VAR && node->op() != Token::INIT_CONST) { |
| 2396 | // Assignment ignored - leave the value on the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2397 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2398 | } else { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2399 | CodeForSourcePosition(node->position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2400 | if (node->op() == Token::INIT_CONST) { |
| 2401 | // Dynamic constant initializations must use the function context |
| 2402 | // and initialize the actual constant declared. Dynamic variable |
| 2403 | // initializations are simply assignments and use SetValue. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2404 | target.SetValue(CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2405 | } else { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2406 | target.SetValue(NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2407 | } |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2412 | void CodeGenerator::VisitThrow(Throw* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2413 | Comment cmnt(masm_, "[ Throw"); |
| 2414 | |
| 2415 | Load(node->exception()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2416 | CodeForSourcePosition(node->position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2417 | __ CallRuntime(Runtime::kThrow, 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2418 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| 2421 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2422 | void CodeGenerator::VisitProperty(Property* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2423 | Comment cmnt(masm_, "[ Property"); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2424 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2425 | Reference property(this, node); |
| 2426 | property.GetValue(typeof_state()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2430 | void CodeGenerator::VisitCall(Call* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2431 | Comment cmnt(masm_, "[ Call"); |
| 2432 | |
| 2433 | ZoneList<Expression*>* args = node->arguments(); |
| 2434 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2435 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2436 | // Standard function call. |
| 2437 | |
| 2438 | // Check if the function is a variable or a property. |
| 2439 | Expression* function = node->expression(); |
| 2440 | Variable* var = function->AsVariableProxy()->AsVariable(); |
| 2441 | Property* property = function->AsProperty(); |
| 2442 | |
| 2443 | // ------------------------------------------------------------------------ |
| 2444 | // Fast-case: Use inline caching. |
| 2445 | // --- |
| 2446 | // According to ECMA-262, section 11.2.3, page 44, the function to call |
| 2447 | // must be resolved after the arguments have been evaluated. The IC code |
| 2448 | // automatically handles this by loading the arguments before the function |
| 2449 | // is resolved in cache misses (this also holds for megamorphic calls). |
| 2450 | // ------------------------------------------------------------------------ |
| 2451 | |
| 2452 | if (var != NULL && !var->is_this() && var->is_global()) { |
| 2453 | // ---------------------------------- |
| 2454 | // JavaScript example: 'foo(1, 2, 3)' // foo is global |
| 2455 | // ---------------------------------- |
| 2456 | |
| 2457 | // Push the name of the function and the receiver onto the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2458 | __ mov(r0, Operand(var->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2459 | frame_->Push(r0); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2460 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2461 | // Pass the global object as the receiver and let the IC stub |
| 2462 | // patch the stack to use the global proxy as 'this' in the |
| 2463 | // invoked function. |
| 2464 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2465 | |
| 2466 | // Load the arguments. |
| 2467 | for (int i = 0; i < args->length(); i++) Load(args->at(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | |
| 2469 | // Setup the receiver register and call the IC initialization code. |
| 2470 | Handle<Code> stub = ComputeCallInitialize(args->length()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2471 | CodeForSourcePosition(node->position()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2472 | __ Call(stub, RelocInfo::CODE_TARGET_CONTEXT); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2473 | __ ldr(cp, frame_->Context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2474 | // Remove the function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2475 | frame_->Pop(); |
| 2476 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2477 | |
| 2478 | } else if (var != NULL && var->slot() != NULL && |
| 2479 | var->slot()->type() == Slot::LOOKUP) { |
| 2480 | // ---------------------------------- |
| 2481 | // JavaScript example: 'with (obj) foo(1, 2, 3)' // foo is in obj |
| 2482 | // ---------------------------------- |
| 2483 | |
| 2484 | // Load the function |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2485 | frame_->Push(cp); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2486 | __ mov(r0, Operand(var->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2487 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2488 | __ CallRuntime(Runtime::kLoadContextSlot, 2); |
| 2489 | // r0: slot value; r1: receiver |
| 2490 | |
| 2491 | // Load the receiver. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2492 | frame_->Push(r0); // function |
| 2493 | frame_->Push(r1); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2494 | |
| 2495 | // Call the function. |
| 2496 | CallWithArguments(args, node->position()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2497 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2498 | |
| 2499 | } else if (property != NULL) { |
| 2500 | // Check if the key is a literal string. |
| 2501 | Literal* literal = property->key()->AsLiteral(); |
| 2502 | |
| 2503 | if (literal != NULL && literal->handle()->IsSymbol()) { |
| 2504 | // ------------------------------------------------------------------ |
| 2505 | // JavaScript example: 'object.foo(1, 2, 3)' or 'map["key"](1, 2, 3)' |
| 2506 | // ------------------------------------------------------------------ |
| 2507 | |
| 2508 | // Push the name of the function and the receiver onto the stack. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2509 | __ mov(r0, Operand(literal->handle())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2510 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2511 | Load(property->obj()); |
| 2512 | |
| 2513 | // Load the arguments. |
| 2514 | for (int i = 0; i < args->length(); i++) Load(args->at(i)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2515 | |
| 2516 | // Set the receiver register and call the IC initialization code. |
| 2517 | Handle<Code> stub = ComputeCallInitialize(args->length()); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2518 | CodeForSourcePosition(node->position()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2519 | __ Call(stub, RelocInfo::CODE_TARGET); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2520 | __ ldr(cp, frame_->Context()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2521 | |
| 2522 | // Remove the function from the stack. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2523 | frame_->Pop(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2524 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2525 | frame_->Push(r0); // push after get rid of function from the stack |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2526 | |
| 2527 | } else { |
| 2528 | // ------------------------------------------- |
| 2529 | // JavaScript example: 'array[index](1, 2, 3)' |
| 2530 | // ------------------------------------------- |
| 2531 | |
| 2532 | // Load the function to call from the property through a reference. |
| 2533 | Reference ref(this, property); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2534 | ref.GetValue(NOT_INSIDE_TYPEOF); // receiver |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2535 | |
| 2536 | // Pass receiver to called function. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2537 | __ ldr(r0, frame_->Element(ref.size())); |
| 2538 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2539 | // Call the function. |
| 2540 | CallWithArguments(args, node->position()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2541 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | } else { |
| 2545 | // ---------------------------------- |
| 2546 | // JavaScript example: 'foo(1, 2, 3)' // foo is not global |
| 2547 | // ---------------------------------- |
| 2548 | |
| 2549 | // Load the function. |
| 2550 | Load(function); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2551 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2552 | // Pass the global proxy as the receiver. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2553 | LoadGlobalReceiver(r0); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2554 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2555 | // Call the function. |
| 2556 | CallWithArguments(args, node->position()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2557 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2562 | void CodeGenerator::VisitCallEval(CallEval* node) { |
| 2563 | Comment cmnt(masm_, "[ CallEval"); |
| 2564 | |
| 2565 | // In a call to eval, we first call %ResolvePossiblyDirectEval to resolve |
| 2566 | // the function we need to call and the receiver of the call. |
| 2567 | // Then we call the resolved function using the given arguments. |
| 2568 | |
| 2569 | ZoneList<Expression*>* args = node->arguments(); |
| 2570 | Expression* function = node->expression(); |
| 2571 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2572 | CodeForStatement(node); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2573 | |
| 2574 | // Prepare stack for call to resolved function. |
| 2575 | Load(function); |
| 2576 | __ mov(r2, Operand(Factory::undefined_value())); |
| 2577 | __ push(r2); // Slot for receiver |
| 2578 | for (int i = 0; i < args->length(); i++) { |
| 2579 | Load(args->at(i)); |
| 2580 | } |
| 2581 | |
| 2582 | // Prepare stack for call to ResolvePossiblyDirectEval. |
| 2583 | __ ldr(r1, MemOperand(sp, args->length() * kPointerSize + kPointerSize)); |
| 2584 | __ push(r1); |
| 2585 | if (args->length() > 0) { |
| 2586 | __ ldr(r1, MemOperand(sp, args->length() * kPointerSize)); |
| 2587 | __ push(r1); |
| 2588 | } else { |
| 2589 | __ push(r2); |
| 2590 | } |
| 2591 | |
| 2592 | // Resolve the call. |
| 2593 | __ CallRuntime(Runtime::kResolvePossiblyDirectEval, 2); |
| 2594 | |
| 2595 | // Touch up stack with the right values for the function and the receiver. |
| 2596 | __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize)); |
| 2597 | __ str(r1, MemOperand(sp, (args->length() + 1) * kPointerSize)); |
| 2598 | __ ldr(r1, FieldMemOperand(r0, FixedArray::kHeaderSize + kPointerSize)); |
| 2599 | __ str(r1, MemOperand(sp, args->length() * kPointerSize)); |
| 2600 | |
| 2601 | // Call the function. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2602 | CodeForSourcePosition(node->position()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2603 | |
| 2604 | CallFunctionStub call_function(args->length()); |
| 2605 | __ CallStub(&call_function); |
| 2606 | |
| 2607 | __ ldr(cp, frame_->Context()); |
| 2608 | // Remove the function from the stack. |
| 2609 | frame_->Pop(); |
| 2610 | frame_->Push(r0); |
| 2611 | } |
| 2612 | |
| 2613 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2614 | void CodeGenerator::VisitCallNew(CallNew* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2615 | Comment cmnt(masm_, "[ CallNew"); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2616 | CodeForStatement(node); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2617 | |
| 2618 | // According to ECMA-262, section 11.2.2, page 44, the function |
| 2619 | // expression in new calls must be evaluated before the |
| 2620 | // arguments. This is different from ordinary calls, where the |
| 2621 | // actual function to call is resolved after the arguments have been |
| 2622 | // evaluated. |
| 2623 | |
| 2624 | // Compute function to call and use the global object as the |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2625 | // receiver. There is no need to use the global proxy here because |
| 2626 | // it will always be replaced with a newly allocated object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2627 | Load(node->expression()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2628 | LoadGlobal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | |
| 2630 | // Push the arguments ("left-to-right") on the stack. |
| 2631 | ZoneList<Expression*>* args = node->arguments(); |
| 2632 | for (int i = 0; i < args->length(); i++) Load(args->at(i)); |
| 2633 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2634 | // r0: the number of arguments. |
| 2635 | __ mov(r0, Operand(args->length())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2636 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2637 | // Load the function into r1 as per calling convention. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2638 | __ ldr(r1, frame_->Element(args->length() + 1)); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2639 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2640 | // Call the construct call builtin that handles allocation and |
| 2641 | // constructor invocation. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2642 | CodeForSourcePosition(node->position()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2643 | __ Call(Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)), |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2644 | RelocInfo::CONSTRUCT_CALL); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2645 | |
| 2646 | // Discard old TOS value and push r0 on the stack (same as Pop(), push(r0)). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2647 | __ str(r0, frame_->Top()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2651 | void CodeGenerator::GenerateValueOf(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2652 | ASSERT(args->length() == 1); |
| 2653 | Label leave; |
| 2654 | Load(args->at(0)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2655 | frame_->Pop(r0); // r0 contains object. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2656 | // if (object->IsSmi()) return the object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2657 | __ tst(r0, Operand(kSmiTagMask)); |
| 2658 | __ b(eq, &leave); |
| 2659 | // It is a heap object - get map. |
| 2660 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2661 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2662 | // if (!object->IsJSValue()) return the object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2663 | __ cmp(r1, Operand(JS_VALUE_TYPE)); |
| 2664 | __ b(ne, &leave); |
| 2665 | // Load the value. |
| 2666 | __ ldr(r0, FieldMemOperand(r0, JSValue::kValueOffset)); |
| 2667 | __ bind(&leave); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2668 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2672 | void CodeGenerator::GenerateSetValueOf(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2673 | ASSERT(args->length() == 2); |
| 2674 | Label leave; |
| 2675 | Load(args->at(0)); // Load the object. |
| 2676 | Load(args->at(1)); // Load the value. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2677 | frame_->Pop(r0); // r0 contains value |
| 2678 | frame_->Pop(r1); // r1 contains object |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2679 | // if (object->IsSmi()) return object. |
| 2680 | __ tst(r1, Operand(kSmiTagMask)); |
| 2681 | __ b(eq, &leave); |
| 2682 | // It is a heap object - get map. |
| 2683 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 2684 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 2685 | // if (!object->IsJSValue()) return object. |
| 2686 | __ cmp(r2, Operand(JS_VALUE_TYPE)); |
| 2687 | __ b(ne, &leave); |
| 2688 | // Store the value. |
| 2689 | __ str(r0, FieldMemOperand(r1, JSValue::kValueOffset)); |
| 2690 | // Update the write barrier. |
| 2691 | __ mov(r2, Operand(JSValue::kValueOffset - kHeapObjectTag)); |
| 2692 | __ RecordWrite(r1, r2, r3); |
| 2693 | // Leave. |
| 2694 | __ bind(&leave); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2695 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2699 | void CodeGenerator::GenerateIsSmi(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2700 | ASSERT(args->length() == 1); |
| 2701 | Load(args->at(0)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2702 | frame_->Pop(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2703 | __ tst(r0, Operand(kSmiTagMask)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2704 | cc_reg_ = eq; |
| 2705 | } |
| 2706 | |
| 2707 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2708 | void CodeGenerator::GenerateLog(ZoneList<Expression*>* args) { |
| 2709 | // See comment in CodeGenerator::GenerateLog in codegen-ia32.cc. |
| 2710 | ASSERT_EQ(args->length(), 3); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2711 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2712 | if (ShouldGenerateLog(args->at(0))) { |
| 2713 | Load(args->at(1)); |
| 2714 | Load(args->at(2)); |
| 2715 | __ CallRuntime(Runtime::kLog, 2); |
| 2716 | } |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 2717 | #endif |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 2718 | __ mov(r0, Operand(Factory::undefined_value())); |
| 2719 | frame_->Push(r0); |
| 2720 | } |
| 2721 | |
| 2722 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2723 | void CodeGenerator::GenerateIsNonNegativeSmi(ZoneList<Expression*>* args) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 2724 | ASSERT(args->length() == 1); |
| 2725 | Load(args->at(0)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2726 | frame_->Pop(r0); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 2727 | __ tst(r0, Operand(kSmiTagMask | 0x80000000)); |
| 2728 | cc_reg_ = eq; |
| 2729 | } |
| 2730 | |
| 2731 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2732 | // This should generate code that performs a charCodeAt() call or returns |
| 2733 | // undefined in order to trigger the slow case, Runtime_StringCharCodeAt. |
| 2734 | // It is not yet implemented on ARM, so it always goes to the slow case. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2735 | void CodeGenerator::GenerateFastCharCodeAt(ZoneList<Expression*>* args) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2736 | ASSERT(args->length() == 2); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2737 | __ mov(r0, Operand(Factory::undefined_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2738 | frame_->Push(r0); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2742 | void CodeGenerator::GenerateIsArray(ZoneList<Expression*>* args) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2743 | ASSERT(args->length() == 1); |
| 2744 | Load(args->at(0)); |
| 2745 | Label answer; |
| 2746 | // We need the CC bits to come out as not_equal in the case where the |
| 2747 | // object is a smi. This can't be done with the usual test opcode so |
| 2748 | // we use XOR to get the right CC bits. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2749 | frame_->Pop(r0); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2750 | __ and_(r1, r0, Operand(kSmiTagMask)); |
| 2751 | __ eor(r1, r1, Operand(kSmiTagMask), SetCC); |
| 2752 | __ b(ne, &answer); |
| 2753 | // It is a heap object - get the map. |
| 2754 | __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 2755 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 2756 | // Check if the object is a JS array or not. |
| 2757 | __ cmp(r1, Operand(JS_ARRAY_TYPE)); |
| 2758 | __ bind(&answer); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2759 | cc_reg_ = eq; |
| 2760 | } |
| 2761 | |
| 2762 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2763 | void CodeGenerator::GenerateArgumentsLength(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2764 | ASSERT(args->length() == 0); |
| 2765 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2766 | // Seed the result with the formal parameters count, which will be used |
| 2767 | // in case no arguments adaptor frame is found below the current frame. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2768 | __ mov(r0, Operand(Smi::FromInt(scope_->num_parameters()))); |
| 2769 | |
| 2770 | // Call the shared stub to get to the arguments.length. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2771 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_LENGTH); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2772 | __ CallStub(&stub); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2773 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2777 | void CodeGenerator::GenerateArgumentsAccess(ZoneList<Expression*>* args) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2778 | ASSERT(args->length() == 1); |
| 2779 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2780 | // Satisfy contract with ArgumentsAccessStub: |
| 2781 | // Load the key into r1 and the formal parameters count into r0. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2782 | Load(args->at(0)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2783 | frame_->Pop(r1); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2784 | __ mov(r0, Operand(Smi::FromInt(scope_->num_parameters()))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2785 | |
| 2786 | // Call the shared stub to get to arguments[key]. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 2787 | ArgumentsAccessStub stub(ArgumentsAccessStub::READ_ELEMENT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2788 | __ CallStub(&stub); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2789 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2793 | void CodeGenerator::GenerateObjectEquals(ZoneList<Expression*>* args) { |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2794 | ASSERT(args->length() == 2); |
| 2795 | |
| 2796 | // Load the two objects into registers and perform the comparison. |
| 2797 | Load(args->at(0)); |
| 2798 | Load(args->at(1)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2799 | frame_->Pop(r0); |
| 2800 | frame_->Pop(r1); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2801 | __ cmp(r0, Operand(r1)); |
| 2802 | cc_reg_ = eq; |
| 2803 | } |
| 2804 | |
| 2805 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2806 | void CodeGenerator::VisitCallRuntime(CallRuntime* node) { |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2807 | if (CheckForInlineRuntimeCall(node)) return; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2808 | |
| 2809 | ZoneList<Expression*>* args = node->arguments(); |
| 2810 | Comment cmnt(masm_, "[ CallRuntime"); |
| 2811 | Runtime::Function* function = node->function(); |
| 2812 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2813 | if (function != NULL) { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2814 | // Push the arguments ("left-to-right"). |
| 2815 | for (int i = 0; i < args->length(); i++) Load(args->at(i)); |
| 2816 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2817 | // Call the C runtime function. |
| 2818 | __ CallRuntime(function, args->length()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2819 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2820 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2821 | } else { |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2822 | // Prepare stack for calling JS runtime function. |
| 2823 | __ mov(r0, Operand(node->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2824 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2825 | // Push the builtins object found in the current global object. |
| 2826 | __ ldr(r1, GlobalObject()); |
| 2827 | __ ldr(r0, FieldMemOperand(r1, GlobalObject::kBuiltinsOffset)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2828 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2829 | |
| 2830 | for (int i = 0; i < args->length(); i++) Load(args->at(i)); |
| 2831 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2832 | // Call the JS runtime function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | Handle<Code> stub = ComputeCallInitialize(args->length()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2834 | __ Call(stub, RelocInfo::CODE_TARGET); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2835 | __ ldr(cp, frame_->Context()); |
| 2836 | frame_->Pop(); |
| 2837 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2842 | void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2843 | Comment cmnt(masm_, "[ UnaryOperation"); |
| 2844 | |
| 2845 | Token::Value op = node->op(); |
| 2846 | |
| 2847 | if (op == Token::NOT) { |
| 2848 | LoadCondition(node->expression(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2849 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2850 | false_target(), |
| 2851 | true_target(), |
| 2852 | true); |
| 2853 | cc_reg_ = NegateCondition(cc_reg_); |
| 2854 | |
| 2855 | } else if (op == Token::DELETE) { |
| 2856 | Property* property = node->expression()->AsProperty(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2857 | Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2858 | if (property != NULL) { |
| 2859 | Load(property->obj()); |
| 2860 | Load(property->key()); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2861 | __ mov(r0, Operand(1)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2862 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2863 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2864 | } else if (variable != NULL) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2865 | Slot* slot = variable->slot(); |
| 2866 | if (variable->is_global()) { |
| 2867 | LoadGlobal(); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2868 | __ mov(r0, Operand(variable->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2869 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2870 | __ mov(r0, Operand(1)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2871 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2872 | |
| 2873 | } else if (slot != NULL && slot->type() == Slot::LOOKUP) { |
| 2874 | // lookup the context holding the named variable |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2875 | frame_->Push(cp); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2876 | __ mov(r0, Operand(variable->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2877 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2878 | __ CallRuntime(Runtime::kLookupContext, 2); |
| 2879 | // r0: context |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2880 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2881 | __ mov(r0, Operand(variable->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2882 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2883 | __ mov(r0, Operand(1)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2884 | __ InvokeBuiltin(Builtins::DELETE, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2885 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2886 | } else { |
| 2887 | // Default: Result of deleting non-global, not dynamically |
| 2888 | // introduced variables is false. |
| 2889 | __ mov(r0, Operand(Factory::false_value())); |
| 2890 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2891 | |
| 2892 | } else { |
| 2893 | // Default: Result of deleting expressions is true. |
| 2894 | Load(node->expression()); // may have side-effects |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2895 | frame_->Pop(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2896 | __ mov(r0, Operand(Factory::true_value())); |
| 2897 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2898 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2899 | |
| 2900 | } else if (op == Token::TYPEOF) { |
| 2901 | // Special case for loading the typeof expression; see comment on |
| 2902 | // LoadTypeofExpression(). |
| 2903 | LoadTypeofExpression(node->expression()); |
| 2904 | __ CallRuntime(Runtime::kTypeof, 1); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2905 | frame_->Push(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2906 | |
| 2907 | } else { |
| 2908 | Load(node->expression()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2909 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2910 | switch (op) { |
| 2911 | case Token::NOT: |
| 2912 | case Token::DELETE: |
| 2913 | case Token::TYPEOF: |
| 2914 | UNREACHABLE(); // handled above |
| 2915 | break; |
| 2916 | |
| 2917 | case Token::SUB: { |
| 2918 | UnarySubStub stub; |
| 2919 | __ CallStub(&stub); |
| 2920 | break; |
| 2921 | } |
| 2922 | |
| 2923 | case Token::BIT_NOT: { |
| 2924 | // smi check |
| 2925 | Label smi_label; |
| 2926 | Label continue_label; |
| 2927 | __ tst(r0, Operand(kSmiTagMask)); |
| 2928 | __ b(eq, &smi_label); |
| 2929 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2930 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2931 | __ mov(r0, Operand(0)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2932 | __ InvokeBuiltin(Builtins::BIT_NOT, CALL_JS); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2933 | |
| 2934 | __ b(&continue_label); |
| 2935 | __ bind(&smi_label); |
| 2936 | __ mvn(r0, Operand(r0)); |
| 2937 | __ bic(r0, r0, Operand(kSmiTagMask)); // bit-clear inverted smi-tag |
| 2938 | __ bind(&continue_label); |
| 2939 | break; |
| 2940 | } |
| 2941 | |
| 2942 | case Token::VOID: |
| 2943 | // since the stack top is cached in r0, popping and then |
| 2944 | // pushing a value can be done by just writing to r0. |
| 2945 | __ mov(r0, Operand(Factory::undefined_value())); |
| 2946 | break; |
| 2947 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2948 | case Token::ADD: { |
| 2949 | // Smi check. |
| 2950 | Label continue_label; |
| 2951 | __ tst(r0, Operand(kSmiTagMask)); |
| 2952 | __ b(eq, &continue_label); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2953 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2954 | __ mov(r0, Operand(0)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2955 | __ InvokeBuiltin(Builtins::TO_NUMBER, CALL_JS); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2956 | __ bind(&continue_label); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2957 | break; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2958 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2959 | default: |
| 2960 | UNREACHABLE(); |
| 2961 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2962 | frame_->Push(r0); // r0 has result |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2963 | } |
| 2964 | } |
| 2965 | |
| 2966 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2967 | void CodeGenerator::VisitCountOperation(CountOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2968 | Comment cmnt(masm_, "[ CountOperation"); |
| 2969 | |
| 2970 | bool is_postfix = node->is_postfix(); |
| 2971 | bool is_increment = node->op() == Token::INC; |
| 2972 | |
| 2973 | Variable* var = node->expression()->AsVariableProxy()->AsVariable(); |
| 2974 | bool is_const = (var != NULL && var->mode() == Variable::CONST); |
| 2975 | |
| 2976 | // Postfix: Make room for the result. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2977 | if (is_postfix) { |
| 2978 | __ mov(r0, Operand(0)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2979 | frame_->Push(r0); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 2980 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2981 | |
| 2982 | { Reference target(this, node->expression()); |
| 2983 | if (target.is_illegal()) return; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2984 | target.GetValue(NOT_INSIDE_TYPEOF); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2985 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2986 | |
| 2987 | Label slow, exit; |
| 2988 | |
| 2989 | // Load the value (1) into register r1. |
| 2990 | __ mov(r1, Operand(Smi::FromInt(1))); |
| 2991 | |
| 2992 | // Check for smi operand. |
| 2993 | __ tst(r0, Operand(kSmiTagMask)); |
| 2994 | __ b(ne, &slow); |
| 2995 | |
| 2996 | // Postfix: Store the old value as the result. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 2997 | if (is_postfix) { |
| 2998 | __ str(r0, frame_->Element(target.size())); |
| 2999 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3000 | |
| 3001 | // Perform optimistic increment/decrement. |
| 3002 | if (is_increment) { |
| 3003 | __ add(r0, r0, Operand(r1), SetCC); |
| 3004 | } else { |
| 3005 | __ sub(r0, r0, Operand(r1), SetCC); |
| 3006 | } |
| 3007 | |
| 3008 | // If the increment/decrement didn't overflow, we're done. |
| 3009 | __ b(vc, &exit); |
| 3010 | |
| 3011 | // Revert optimistic increment/decrement. |
| 3012 | if (is_increment) { |
| 3013 | __ sub(r0, r0, Operand(r1)); |
| 3014 | } else { |
| 3015 | __ add(r0, r0, Operand(r1)); |
| 3016 | } |
| 3017 | |
| 3018 | // Slow case: Convert to number. |
| 3019 | __ bind(&slow); |
| 3020 | |
| 3021 | // Postfix: Convert the operand to a number and store it as the result. |
| 3022 | if (is_postfix) { |
| 3023 | InvokeBuiltinStub stub(InvokeBuiltinStub::ToNumber, 2); |
| 3024 | __ CallStub(&stub); |
| 3025 | // Store to result (on the stack). |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3026 | __ str(r0, frame_->Element(target.size())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | // Compute the new value by calling the right JavaScript native. |
| 3030 | if (is_increment) { |
| 3031 | InvokeBuiltinStub stub(InvokeBuiltinStub::Inc, 1); |
| 3032 | __ CallStub(&stub); |
| 3033 | } else { |
| 3034 | InvokeBuiltinStub stub(InvokeBuiltinStub::Dec, 1); |
| 3035 | __ CallStub(&stub); |
| 3036 | } |
| 3037 | |
| 3038 | // Store the new value in the target if not const. |
| 3039 | __ bind(&exit); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3040 | frame_->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3041 | if (!is_const) target.SetValue(NOT_CONST_INIT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3042 | } |
| 3043 | |
| 3044 | // Postfix: Discard the new value and use the old. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3045 | if (is_postfix) frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3049 | void CodeGenerator::VisitBinaryOperation(BinaryOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3050 | Comment cmnt(masm_, "[ BinaryOperation"); |
| 3051 | Token::Value op = node->op(); |
| 3052 | |
| 3053 | // According to ECMA-262 section 11.11, page 58, the binary logical |
| 3054 | // operators must yield the result of one of the two expressions |
| 3055 | // before any ToBoolean() conversions. This means that the value |
| 3056 | // produced by a && or || operator is not necessarily a boolean. |
| 3057 | |
| 3058 | // NOTE: If the left hand side produces a materialized value (not in |
| 3059 | // the CC register), we force the right hand side to do the |
| 3060 | // same. This is necessary because we may have to branch to the exit |
| 3061 | // after evaluating the left hand side (due to the shortcut |
| 3062 | // semantics), but the compiler must (statically) know if the result |
| 3063 | // of compiling the binary operation is materialized or not. |
| 3064 | |
| 3065 | if (op == Token::AND) { |
| 3066 | Label is_true; |
| 3067 | LoadCondition(node->left(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3068 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3069 | &is_true, |
| 3070 | false_target(), |
| 3071 | false); |
| 3072 | if (has_cc()) { |
| 3073 | Branch(false, false_target()); |
| 3074 | |
| 3075 | // Evaluate right side expression. |
| 3076 | __ bind(&is_true); |
| 3077 | LoadCondition(node->right(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3078 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3079 | true_target(), |
| 3080 | false_target(), |
| 3081 | false); |
| 3082 | |
| 3083 | } else { |
| 3084 | Label pop_and_continue, exit; |
| 3085 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3086 | __ ldr(r0, frame_->Top()); // dup the stack top |
| 3087 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3088 | // Avoid popping the result if it converts to 'false' using the |
| 3089 | // standard ToBoolean() conversion as described in ECMA-262, |
| 3090 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3091 | ToBoolean(&pop_and_continue, &exit); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3092 | Branch(false, &exit); |
| 3093 | |
| 3094 | // Pop the result of evaluating the first part. |
| 3095 | __ bind(&pop_and_continue); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3096 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3097 | |
| 3098 | // Evaluate right side expression. |
| 3099 | __ bind(&is_true); |
| 3100 | Load(node->right()); |
| 3101 | |
| 3102 | // Exit (always with a materialized value). |
| 3103 | __ bind(&exit); |
| 3104 | } |
| 3105 | |
| 3106 | } else if (op == Token::OR) { |
| 3107 | Label is_false; |
| 3108 | LoadCondition(node->left(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3109 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3110 | true_target(), |
| 3111 | &is_false, |
| 3112 | false); |
| 3113 | if (has_cc()) { |
| 3114 | Branch(true, true_target()); |
| 3115 | |
| 3116 | // Evaluate right side expression. |
| 3117 | __ bind(&is_false); |
| 3118 | LoadCondition(node->right(), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3119 | NOT_INSIDE_TYPEOF, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3120 | true_target(), |
| 3121 | false_target(), |
| 3122 | false); |
| 3123 | |
| 3124 | } else { |
| 3125 | Label pop_and_continue, exit; |
| 3126 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3127 | __ ldr(r0, frame_->Top()); |
| 3128 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3129 | // Avoid popping the result if it converts to 'true' using the |
| 3130 | // standard ToBoolean() conversion as described in ECMA-262, |
| 3131 | // section 9.2, page 30. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3132 | ToBoolean(&exit, &pop_and_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3133 | Branch(true, &exit); |
| 3134 | |
| 3135 | // Pop the result of evaluating the first part. |
| 3136 | __ bind(&pop_and_continue); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3137 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3138 | |
| 3139 | // Evaluate right side expression. |
| 3140 | __ bind(&is_false); |
| 3141 | Load(node->right()); |
| 3142 | |
| 3143 | // Exit (always with a materialized value). |
| 3144 | __ bind(&exit); |
| 3145 | } |
| 3146 | |
| 3147 | } else { |
| 3148 | // Optimize for the case where (at least) one of the expressions |
| 3149 | // is a literal small integer. |
| 3150 | Literal* lliteral = node->left()->AsLiteral(); |
| 3151 | Literal* rliteral = node->right()->AsLiteral(); |
| 3152 | |
| 3153 | if (rliteral != NULL && rliteral->handle()->IsSmi()) { |
| 3154 | Load(node->left()); |
| 3155 | SmiOperation(node->op(), rliteral->handle(), false); |
| 3156 | |
| 3157 | } else if (lliteral != NULL && lliteral->handle()->IsSmi()) { |
| 3158 | Load(node->right()); |
| 3159 | SmiOperation(node->op(), lliteral->handle(), true); |
| 3160 | |
| 3161 | } else { |
| 3162 | Load(node->left()); |
| 3163 | Load(node->right()); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3164 | GenericBinaryOperation(node->op()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3165 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3166 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3167 | } |
| 3168 | } |
| 3169 | |
| 3170 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3171 | void CodeGenerator::VisitThisFunction(ThisFunction* node) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3172 | __ ldr(r0, frame_->Function()); |
| 3173 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3177 | void CodeGenerator::VisitCompareOperation(CompareOperation* node) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3178 | Comment cmnt(masm_, "[ CompareOperation"); |
| 3179 | |
| 3180 | // Get the expressions from the node. |
| 3181 | Expression* left = node->left(); |
| 3182 | Expression* right = node->right(); |
| 3183 | Token::Value op = node->op(); |
| 3184 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3185 | // To make null checks efficient, we check if either left or right is the |
| 3186 | // literal 'null'. If so, we optimize the code by inlining a null check |
| 3187 | // instead of calling the (very) general runtime routine for checking |
| 3188 | // equality. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3189 | if (op == Token::EQ || op == Token::EQ_STRICT) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3190 | bool left_is_null = |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3191 | left->AsLiteral() != NULL && left->AsLiteral()->IsNull(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3192 | bool right_is_null = |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3193 | right->AsLiteral() != NULL && right->AsLiteral()->IsNull(); |
| 3194 | // The 'null' value can only be equal to 'null' or 'undefined'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3195 | if (left_is_null || right_is_null) { |
| 3196 | Load(left_is_null ? right : left); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3197 | frame_->Pop(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3198 | __ cmp(r0, Operand(Factory::null_value())); |
| 3199 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3200 | // The 'null' value is only equal to 'undefined' if using non-strict |
| 3201 | // comparisons. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3202 | if (op != Token::EQ_STRICT) { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3203 | __ b(eq, true_target()); |
| 3204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3205 | __ cmp(r0, Operand(Factory::undefined_value())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3206 | __ b(eq, true_target()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3207 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3208 | __ tst(r0, Operand(kSmiTagMask)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3209 | __ b(eq, false_target()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3210 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3211 | // It can be an undetectable object. |
| 3212 | __ ldr(r0, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 3213 | __ ldrb(r0, FieldMemOperand(r0, Map::kBitFieldOffset)); |
| 3214 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 3215 | __ cmp(r0, Operand(1 << Map::kIsUndetectable)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3218 | cc_reg_ = eq; |
| 3219 | return; |
| 3220 | } |
| 3221 | } |
| 3222 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3223 | // To make typeof testing for natives implemented in JavaScript really |
| 3224 | // efficient, we generate special code for expressions of the form: |
| 3225 | // 'typeof <expression> == <string>'. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3226 | UnaryOperation* operation = left->AsUnaryOperation(); |
| 3227 | if ((op == Token::EQ || op == Token::EQ_STRICT) && |
| 3228 | (operation != NULL && operation->op() == Token::TYPEOF) && |
| 3229 | (right->AsLiteral() != NULL && |
| 3230 | right->AsLiteral()->handle()->IsString())) { |
| 3231 | Handle<String> check(String::cast(*right->AsLiteral()->handle())); |
| 3232 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3233 | // Load the operand, move it to register r1. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3234 | LoadTypeofExpression(operation->expression()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3235 | frame_->Pop(r1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3236 | |
| 3237 | if (check->Equals(Heap::number_symbol())) { |
| 3238 | __ tst(r1, Operand(kSmiTagMask)); |
| 3239 | __ b(eq, true_target()); |
| 3240 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3241 | __ cmp(r1, Operand(Factory::heap_number_map())); |
| 3242 | cc_reg_ = eq; |
| 3243 | |
| 3244 | } else if (check->Equals(Heap::string_symbol())) { |
| 3245 | __ tst(r1, Operand(kSmiTagMask)); |
| 3246 | __ b(eq, false_target()); |
| 3247 | |
| 3248 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3249 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3250 | // It can be an undetectable string object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3251 | __ ldrb(r2, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3252 | __ and_(r2, r2, Operand(1 << Map::kIsUndetectable)); |
| 3253 | __ cmp(r2, Operand(1 << Map::kIsUndetectable)); |
| 3254 | __ b(eq, false_target()); |
| 3255 | |
| 3256 | __ ldrb(r2, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 3257 | __ cmp(r2, Operand(FIRST_NONSTRING_TYPE)); |
| 3258 | cc_reg_ = lt; |
| 3259 | |
| 3260 | } else if (check->Equals(Heap::boolean_symbol())) { |
| 3261 | __ cmp(r1, Operand(Factory::true_value())); |
| 3262 | __ b(eq, true_target()); |
| 3263 | __ cmp(r1, Operand(Factory::false_value())); |
| 3264 | cc_reg_ = eq; |
| 3265 | |
| 3266 | } else if (check->Equals(Heap::undefined_symbol())) { |
| 3267 | __ cmp(r1, Operand(Factory::undefined_value())); |
| 3268 | __ b(eq, true_target()); |
| 3269 | |
| 3270 | __ tst(r1, Operand(kSmiTagMask)); |
| 3271 | __ b(eq, false_target()); |
| 3272 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3273 | // It can be an undetectable object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3274 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3275 | __ ldrb(r2, FieldMemOperand(r1, Map::kBitFieldOffset)); |
| 3276 | __ and_(r2, r2, Operand(1 << Map::kIsUndetectable)); |
| 3277 | __ cmp(r2, Operand(1 << Map::kIsUndetectable)); |
| 3278 | |
| 3279 | cc_reg_ = eq; |
| 3280 | |
| 3281 | } else if (check->Equals(Heap::function_symbol())) { |
| 3282 | __ tst(r1, Operand(kSmiTagMask)); |
| 3283 | __ b(eq, false_target()); |
| 3284 | __ ldr(r1, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3285 | __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 3286 | __ cmp(r1, Operand(JS_FUNCTION_TYPE)); |
| 3287 | cc_reg_ = eq; |
| 3288 | |
| 3289 | } else if (check->Equals(Heap::object_symbol())) { |
| 3290 | __ tst(r1, Operand(kSmiTagMask)); |
| 3291 | __ b(eq, false_target()); |
| 3292 | |
| 3293 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3294 | __ cmp(r1, Operand(Factory::null_value())); |
| 3295 | __ b(eq, true_target()); |
| 3296 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3297 | // It can be an undetectable object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3298 | __ ldrb(r1, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 3299 | __ and_(r1, r1, Operand(1 << Map::kIsUndetectable)); |
| 3300 | __ cmp(r1, Operand(1 << Map::kIsUndetectable)); |
| 3301 | __ b(eq, false_target()); |
| 3302 | |
| 3303 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 3304 | __ cmp(r2, Operand(FIRST_JS_OBJECT_TYPE)); |
| 3305 | __ b(lt, false_target()); |
| 3306 | __ cmp(r2, Operand(LAST_JS_OBJECT_TYPE)); |
| 3307 | cc_reg_ = le; |
| 3308 | |
| 3309 | } else { |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3310 | // Uncommon case: typeof testing against a string literal that is |
| 3311 | // never returned from the typeof operator. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3312 | __ b(false_target()); |
| 3313 | } |
| 3314 | return; |
| 3315 | } |
| 3316 | |
| 3317 | Load(left); |
| 3318 | Load(right); |
| 3319 | switch (op) { |
| 3320 | case Token::EQ: |
| 3321 | Comparison(eq, false); |
| 3322 | break; |
| 3323 | |
| 3324 | case Token::LT: |
| 3325 | Comparison(lt); |
| 3326 | break; |
| 3327 | |
| 3328 | case Token::GT: |
| 3329 | Comparison(gt); |
| 3330 | break; |
| 3331 | |
| 3332 | case Token::LTE: |
| 3333 | Comparison(le); |
| 3334 | break; |
| 3335 | |
| 3336 | case Token::GTE: |
| 3337 | Comparison(ge); |
| 3338 | break; |
| 3339 | |
| 3340 | case Token::EQ_STRICT: |
| 3341 | Comparison(eq, true); |
| 3342 | break; |
| 3343 | |
| 3344 | case Token::IN: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3345 | __ mov(r0, Operand(1)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3346 | __ InvokeBuiltin(Builtins::IN, CALL_JS); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3347 | frame_->Push(r0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3348 | break; |
| 3349 | |
| 3350 | case Token::INSTANCEOF: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 3351 | __ mov(r0, Operand(1)); // not counting receiver |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3352 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_JS); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3353 | __ tst(r0, Operand(r0)); |
| 3354 | cc_reg_ = eq; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3355 | break; |
| 3356 | |
| 3357 | default: |
| 3358 | UNREACHABLE(); |
| 3359 | } |
| 3360 | } |
| 3361 | |
| 3362 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3363 | #undef __ |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3364 | #define __ masm-> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3365 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3366 | Handle<String> Reference::GetName() { |
| 3367 | ASSERT(type_ == NAMED); |
| 3368 | Property* property = expression_->AsProperty(); |
| 3369 | if (property == NULL) { |
| 3370 | // Global variable reference treated as a named property reference. |
| 3371 | VariableProxy* proxy = expression_->AsVariableProxy(); |
| 3372 | ASSERT(proxy->AsVariable() != NULL); |
| 3373 | ASSERT(proxy->AsVariable()->is_global()); |
| 3374 | return proxy->name(); |
| 3375 | } else { |
| 3376 | Literal* raw_name = property->key()->AsLiteral(); |
| 3377 | ASSERT(raw_name != NULL); |
| 3378 | return Handle<String>(String::cast(*raw_name->handle())); |
| 3379 | } |
| 3380 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3381 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3382 | |
| 3383 | void Reference::GetValue(TypeofState typeof_state) { |
| 3384 | ASSERT(!is_illegal()); |
| 3385 | ASSERT(!cgen_->has_cc()); |
| 3386 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3387 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3388 | Property* property = expression_->AsProperty(); |
| 3389 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3390 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | switch (type_) { |
| 3394 | case SLOT: { |
| 3395 | Comment cmnt(masm, "[ Load from Slot"); |
| 3396 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
| 3397 | ASSERT(slot != NULL); |
| 3398 | cgen_->LoadFromSlot(slot, typeof_state); |
| 3399 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3400 | } |
| 3401 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3402 | case NAMED: { |
| 3403 | // TODO(1241834): Make sure that this it is safe to ignore the |
| 3404 | // distinction between expressions in a typeof and not in a typeof. If |
| 3405 | // there is a chance that reference errors can be thrown below, we |
| 3406 | // must distinguish between the two kinds of loads (typeof expression |
| 3407 | // loads must not throw a reference error). |
| 3408 | Comment cmnt(masm, "[ Load from named Property"); |
| 3409 | // Setup the name register. |
| 3410 | Handle<String> name(GetName()); |
| 3411 | __ mov(r2, Operand(name)); |
| 3412 | Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); |
| 3413 | |
| 3414 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
| 3415 | if (var != NULL) { |
| 3416 | ASSERT(var->is_global()); |
| 3417 | __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 3418 | } else { |
| 3419 | __ Call(ic, RelocInfo::CODE_TARGET); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3420 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3421 | frame->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3422 | break; |
| 3423 | } |
| 3424 | |
| 3425 | case KEYED: { |
| 3426 | // TODO(1241834): Make sure that this it is safe to ignore the |
| 3427 | // distinction between expressions in a typeof and not in a typeof. |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3428 | |
| 3429 | // TODO(181): Implement inlined version of array indexing once |
| 3430 | // loop nesting is properly tracked on ARM. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3431 | Comment cmnt(masm, "[ Load from keyed Property"); |
| 3432 | ASSERT(property != NULL); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3433 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedLoadIC_Initialize)); |
| 3434 | |
| 3435 | Variable* var = expression_->AsVariableProxy()->AsVariable(); |
| 3436 | if (var != NULL) { |
| 3437 | ASSERT(var->is_global()); |
| 3438 | __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 3439 | } else { |
| 3440 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 3441 | } |
| 3442 | frame->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3443 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3444 | } |
| 3445 | |
| 3446 | default: |
| 3447 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3448 | } |
| 3449 | } |
| 3450 | |
| 3451 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3452 | void Reference::SetValue(InitState init_state) { |
| 3453 | ASSERT(!is_illegal()); |
| 3454 | ASSERT(!cgen_->has_cc()); |
| 3455 | MacroAssembler* masm = cgen_->masm(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3456 | VirtualFrame* frame = cgen_->frame(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3457 | Property* property = expression_->AsProperty(); |
| 3458 | if (property != NULL) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3459 | cgen_->CodeForSourcePosition(property->position()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3460 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3461 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3462 | switch (type_) { |
| 3463 | case SLOT: { |
| 3464 | Comment cmnt(masm, "[ Store to Slot"); |
| 3465 | Slot* slot = expression_->AsVariableProxy()->AsVariable()->slot(); |
| 3466 | ASSERT(slot != NULL); |
| 3467 | if (slot->type() == Slot::LOOKUP) { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 3468 | ASSERT(slot->var()->is_dynamic()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3469 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3470 | // For now, just do a runtime call. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3471 | frame->Push(cp); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3472 | __ mov(r0, Operand(slot->var()->name())); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3473 | frame->Push(r0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3474 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3475 | if (init_state == CONST_INIT) { |
| 3476 | // Same as the case for a normal store, but ignores attribute |
| 3477 | // (e.g. READ_ONLY) of context slot so that we can initialize |
| 3478 | // const properties (introduced via eval("const foo = (some |
| 3479 | // expr);")). Also, uses the current function context instead of |
| 3480 | // the top context. |
| 3481 | // |
| 3482 | // Note that we must declare the foo upon entry of eval(), via a |
| 3483 | // context slot declaration, but we cannot initialize it at the |
| 3484 | // same time, because the const declaration may be at the end of |
| 3485 | // the eval code (sigh...) and the const variable may have been |
| 3486 | // used before (where its value is 'undefined'). Thus, we can only |
| 3487 | // do the initialization when we actually encounter the expression |
| 3488 | // and when the expression operands are defined and valid, and |
| 3489 | // thus we need the split into 2 operations: declaration of the |
| 3490 | // context slot followed by initialization. |
| 3491 | __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); |
| 3492 | } else { |
| 3493 | __ CallRuntime(Runtime::kStoreContextSlot, 3); |
| 3494 | } |
| 3495 | // Storing a variable must keep the (new) value on the expression |
| 3496 | // stack. This is necessary for compiling assignment expressions. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3497 | frame->Push(r0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3498 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3499 | } else { |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame^] | 3500 | ASSERT(!slot->var()->is_dynamic()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3501 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3502 | Label exit; |
| 3503 | if (init_state == CONST_INIT) { |
| 3504 | ASSERT(slot->var()->mode() == Variable::CONST); |
| 3505 | // Only the first const initialization must be executed (the slot |
| 3506 | // still contains 'the hole' value). When the assignment is |
| 3507 | // executed, the code is identical to a normal store (see below). |
| 3508 | Comment cmnt(masm, "[ Init const"); |
| 3509 | __ ldr(r2, cgen_->SlotOperand(slot, r2)); |
| 3510 | __ cmp(r2, Operand(Factory::the_hole_value())); |
| 3511 | __ b(ne, &exit); |
| 3512 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3513 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3514 | // We must execute the store. Storing a variable must keep the |
| 3515 | // (new) value on the stack. This is necessary for compiling |
| 3516 | // assignment expressions. |
| 3517 | // |
| 3518 | // Note: We will reach here even with slot->var()->mode() == |
| 3519 | // Variable::CONST because of const declarations which will |
| 3520 | // initialize consts to 'the hole' value and by doing so, end up |
| 3521 | // calling this code. r2 may be loaded with context; used below in |
| 3522 | // RecordWrite. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3523 | frame->Pop(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3524 | __ str(r0, cgen_->SlotOperand(slot, r2)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3525 | frame->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3526 | if (slot->type() == Slot::CONTEXT) { |
| 3527 | // Skip write barrier if the written value is a smi. |
| 3528 | __ tst(r0, Operand(kSmiTagMask)); |
| 3529 | __ b(eq, &exit); |
| 3530 | // r2 is loaded with context when calling SlotOperand above. |
| 3531 | int offset = FixedArray::kHeaderSize + slot->index() * kPointerSize; |
| 3532 | __ mov(r3, Operand(offset)); |
| 3533 | __ RecordWrite(r2, r3, r1); |
| 3534 | } |
| 3535 | // If we definitely did not jump over the assignment, we do not need |
| 3536 | // to bind the exit label. Doing so can defeat peephole |
| 3537 | // optimization. |
| 3538 | if (init_state == CONST_INIT || slot->type() == Slot::CONTEXT) { |
| 3539 | __ bind(&exit); |
| 3540 | } |
| 3541 | } |
| 3542 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3543 | } |
| 3544 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3545 | case NAMED: { |
| 3546 | Comment cmnt(masm, "[ Store to named Property"); |
| 3547 | // Call the appropriate IC code. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3548 | frame->Pop(r0); // value |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3549 | // Setup the name register. |
| 3550 | Handle<String> name(GetName()); |
| 3551 | __ mov(r2, Operand(name)); |
| 3552 | Handle<Code> ic(Builtins::builtin(Builtins::StoreIC_Initialize)); |
| 3553 | __ Call(ic, RelocInfo::CODE_TARGET); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3554 | frame->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3555 | break; |
| 3556 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3557 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3558 | case KEYED: { |
| 3559 | Comment cmnt(masm, "[ Store to keyed Property"); |
| 3560 | Property* property = expression_->AsProperty(); |
| 3561 | ASSERT(property != NULL); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 3562 | cgen_->CodeForSourcePosition(property->position()); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 3563 | |
| 3564 | // Call IC code. |
| 3565 | Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Initialize)); |
| 3566 | // TODO(1222589): Make the IC grab the values from the stack. |
| 3567 | frame->Pop(r0); // value |
| 3568 | __ Call(ic, RelocInfo::CODE_TARGET); |
| 3569 | frame->Push(r0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3570 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3571 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3572 | |
| 3573 | default: |
| 3574 | UNREACHABLE(); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | |
| 3578 | |
| 3579 | void GetPropertyStub::Generate(MacroAssembler* masm) { |
| 3580 | // sp[0]: key |
| 3581 | // sp[1]: receiver |
| 3582 | Label slow, fast; |
| 3583 | // Get the key and receiver object from the stack. |
| 3584 | __ ldm(ia, sp, r0.bit() | r1.bit()); |
| 3585 | // Check that the key is a smi. |
| 3586 | __ tst(r0, Operand(kSmiTagMask)); |
| 3587 | __ b(ne, &slow); |
| 3588 | __ mov(r0, Operand(r0, ASR, kSmiTagSize)); |
| 3589 | // Check that the object isn't a smi. |
| 3590 | __ tst(r1, Operand(kSmiTagMask)); |
| 3591 | __ b(eq, &slow); |
| 3592 | |
| 3593 | // Check that the object is some kind of JS object EXCEPT JS Value type. |
| 3594 | // In the case that the object is a value-wrapper object, |
| 3595 | // we enter the runtime system to make sure that indexing into string |
| 3596 | // objects work as intended. |
| 3597 | ASSERT(JS_OBJECT_TYPE > JS_VALUE_TYPE); |
| 3598 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3599 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 3600 | __ cmp(r2, Operand(JS_OBJECT_TYPE)); |
| 3601 | __ b(lt, &slow); |
| 3602 | |
| 3603 | // Get the elements array of the object. |
| 3604 | __ ldr(r1, FieldMemOperand(r1, JSObject::kElementsOffset)); |
| 3605 | // Check that the object is in fast mode (not dictionary). |
| 3606 | __ ldr(r3, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 3607 | __ cmp(r3, Operand(Factory::hash_table_map())); |
| 3608 | __ b(eq, &slow); |
| 3609 | // Check that the key (index) is within bounds. |
| 3610 | __ ldr(r3, FieldMemOperand(r1, Array::kLengthOffset)); |
| 3611 | __ cmp(r0, Operand(r3)); |
| 3612 | __ b(lo, &fast); |
| 3613 | |
| 3614 | // Slow case: Push extra copies of the arguments (2). |
| 3615 | __ bind(&slow); |
| 3616 | __ ldm(ia, sp, r0.bit() | r1.bit()); |
| 3617 | __ stm(db_w, sp, r0.bit() | r1.bit()); |
| 3618 | // Do tail-call to runtime routine. |
| 3619 | __ TailCallRuntime(ExternalReference(Runtime::kGetProperty), 2); |
| 3620 | |
| 3621 | // Fast case: Do the load. |
| 3622 | __ bind(&fast); |
| 3623 | __ add(r3, r1, Operand(Array::kHeaderSize - kHeapObjectTag)); |
| 3624 | __ ldr(r0, MemOperand(r3, r0, LSL, kPointerSizeLog2)); |
| 3625 | __ cmp(r0, Operand(Factory::the_hole_value())); |
| 3626 | // In case the loaded value is the_hole we have to consult GetProperty |
| 3627 | // to ensure the prototype chain is searched. |
| 3628 | __ b(eq, &slow); |
| 3629 | |
| 3630 | __ StubReturn(1); |
| 3631 | } |
| 3632 | |
| 3633 | |
| 3634 | void SetPropertyStub::Generate(MacroAssembler* masm) { |
| 3635 | // r0 : value |
| 3636 | // sp[0] : key |
| 3637 | // sp[1] : receiver |
| 3638 | |
| 3639 | Label slow, fast, array, extra, exit; |
| 3640 | // Get the key and the object from the stack. |
| 3641 | __ ldm(ia, sp, r1.bit() | r3.bit()); // r1 = key, r3 = receiver |
| 3642 | // Check that the key is a smi. |
| 3643 | __ tst(r1, Operand(kSmiTagMask)); |
| 3644 | __ b(ne, &slow); |
| 3645 | // Check that the object isn't a smi. |
| 3646 | __ tst(r3, Operand(kSmiTagMask)); |
| 3647 | __ b(eq, &slow); |
| 3648 | // Get the type of the object from its map. |
| 3649 | __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 3650 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 3651 | // Check if the object is a JS array or not. |
| 3652 | __ cmp(r2, Operand(JS_ARRAY_TYPE)); |
| 3653 | __ b(eq, &array); |
| 3654 | // Check that the object is some kind of JS object. |
| 3655 | __ cmp(r2, Operand(FIRST_JS_OBJECT_TYPE)); |
| 3656 | __ b(lt, &slow); |
| 3657 | |
| 3658 | |
| 3659 | // Object case: Check key against length in the elements array. |
| 3660 | __ ldr(r3, FieldMemOperand(r3, JSObject::kElementsOffset)); |
| 3661 | // Check that the object is in fast mode (not dictionary). |
| 3662 | __ ldr(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 3663 | __ cmp(r2, Operand(Factory::hash_table_map())); |
| 3664 | __ b(eq, &slow); |
| 3665 | // Untag the key (for checking against untagged length in the fixed array). |
| 3666 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); |
| 3667 | // Compute address to store into and check array bounds. |
| 3668 | __ add(r2, r3, Operand(Array::kHeaderSize - kHeapObjectTag)); |
| 3669 | __ add(r2, r2, Operand(r1, LSL, kPointerSizeLog2)); |
| 3670 | __ ldr(ip, FieldMemOperand(r3, Array::kLengthOffset)); |
| 3671 | __ cmp(r1, Operand(ip)); |
| 3672 | __ b(lo, &fast); |
| 3673 | |
| 3674 | |
| 3675 | // Slow case: Push extra copies of the arguments (3). |
| 3676 | __ bind(&slow); |
| 3677 | __ ldm(ia, sp, r1.bit() | r3.bit()); // r0 == value, r1 == key, r3 == object |
| 3678 | __ stm(db_w, sp, r0.bit() | r1.bit() | r3.bit()); |
| 3679 | // Do tail-call to runtime routine. |
| 3680 | __ TailCallRuntime(ExternalReference(Runtime::kSetProperty), 3); |
| 3681 | |
| 3682 | |
| 3683 | // Extra capacity case: Check if there is extra capacity to |
| 3684 | // perform the store and update the length. Used for adding one |
| 3685 | // element to the array by writing to array[array.length]. |
| 3686 | // r0 == value, r1 == key, r2 == elements, r3 == object |
| 3687 | __ bind(&extra); |
| 3688 | __ b(ne, &slow); // do not leave holes in the array |
| 3689 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); // untag |
| 3690 | __ ldr(ip, FieldMemOperand(r2, Array::kLengthOffset)); |
| 3691 | __ cmp(r1, Operand(ip)); |
| 3692 | __ b(hs, &slow); |
| 3693 | __ mov(r1, Operand(r1, LSL, kSmiTagSize)); // restore tag |
| 3694 | __ add(r1, r1, Operand(1 << kSmiTagSize)); // and increment |
| 3695 | __ str(r1, FieldMemOperand(r3, JSArray::kLengthOffset)); |
| 3696 | __ mov(r3, Operand(r2)); |
| 3697 | // NOTE: Computing the address to store into must take the fact |
| 3698 | // that the key has been incremented into account. |
| 3699 | int displacement = Array::kHeaderSize - kHeapObjectTag - |
| 3700 | ((1 << kSmiTagSize) * 2); |
| 3701 | __ add(r2, r2, Operand(displacement)); |
| 3702 | __ add(r2, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 3703 | __ b(&fast); |
| 3704 | |
| 3705 | |
| 3706 | // Array case: Get the length and the elements array from the JS |
| 3707 | // array. Check that the array is in fast mode; if it is the |
| 3708 | // length is always a smi. |
| 3709 | // r0 == value, r3 == object |
| 3710 | __ bind(&array); |
| 3711 | __ ldr(r2, FieldMemOperand(r3, JSObject::kElementsOffset)); |
| 3712 | __ ldr(r1, FieldMemOperand(r2, HeapObject::kMapOffset)); |
| 3713 | __ cmp(r1, Operand(Factory::hash_table_map())); |
| 3714 | __ b(eq, &slow); |
| 3715 | |
| 3716 | // Check the key against the length in the array, compute the |
| 3717 | // address to store into and fall through to fast case. |
| 3718 | __ ldr(r1, MemOperand(sp)); |
| 3719 | // r0 == value, r1 == key, r2 == elements, r3 == object. |
| 3720 | __ ldr(ip, FieldMemOperand(r3, JSArray::kLengthOffset)); |
| 3721 | __ cmp(r1, Operand(ip)); |
| 3722 | __ b(hs, &extra); |
| 3723 | __ mov(r3, Operand(r2)); |
| 3724 | __ add(r2, r2, Operand(Array::kHeaderSize - kHeapObjectTag)); |
| 3725 | __ add(r2, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 3726 | |
| 3727 | |
| 3728 | // Fast case: Do the store. |
| 3729 | // r0 == value, r2 == address to store into, r3 == elements |
| 3730 | __ bind(&fast); |
| 3731 | __ str(r0, MemOperand(r2)); |
| 3732 | // Skip write barrier if the written value is a smi. |
| 3733 | __ tst(r0, Operand(kSmiTagMask)); |
| 3734 | __ b(eq, &exit); |
| 3735 | // Update write barrier for the elements array address. |
| 3736 | __ sub(r1, r2, Operand(r3)); |
| 3737 | __ RecordWrite(r3, r1, r2); |
| 3738 | __ bind(&exit); |
| 3739 | __ StubReturn(1); |
| 3740 | } |
| 3741 | |
| 3742 | |
| 3743 | void GenericBinaryOpStub::Generate(MacroAssembler* masm) { |
| 3744 | // r1 : x |
| 3745 | // r0 : y |
| 3746 | // result : r0 |
| 3747 | |
| 3748 | switch (op_) { |
| 3749 | case Token::ADD: { |
| 3750 | Label slow, exit; |
| 3751 | // fast path |
| 3752 | __ orr(r2, r1, Operand(r0)); // r2 = x | y; |
| 3753 | __ add(r0, r1, Operand(r0), SetCC); // add y optimistically |
| 3754 | // go slow-path in case of overflow |
| 3755 | __ b(vs, &slow); |
| 3756 | // go slow-path in case of non-smi operands |
| 3757 | ASSERT(kSmiTag == 0); // adjust code below |
| 3758 | __ tst(r2, Operand(kSmiTagMask)); |
| 3759 | __ b(eq, &exit); |
| 3760 | // slow path |
| 3761 | __ bind(&slow); |
| 3762 | __ sub(r0, r0, Operand(r1)); // revert optimistic add |
| 3763 | __ push(r1); |
| 3764 | __ push(r0); |
| 3765 | __ mov(r0, Operand(1)); // set number of arguments |
| 3766 | __ InvokeBuiltin(Builtins::ADD, JUMP_JS); |
| 3767 | // done |
| 3768 | __ bind(&exit); |
| 3769 | break; |
| 3770 | } |
| 3771 | |
| 3772 | case Token::SUB: { |
| 3773 | Label slow, exit; |
| 3774 | // fast path |
| 3775 | __ orr(r2, r1, Operand(r0)); // r2 = x | y; |
| 3776 | __ sub(r3, r1, Operand(r0), SetCC); // subtract y optimistically |
| 3777 | // go slow-path in case of overflow |
| 3778 | __ b(vs, &slow); |
| 3779 | // go slow-path in case of non-smi operands |
| 3780 | ASSERT(kSmiTag == 0); // adjust code below |
| 3781 | __ tst(r2, Operand(kSmiTagMask)); |
| 3782 | __ mov(r0, Operand(r3), LeaveCC, eq); // conditionally set r0 to result |
| 3783 | __ b(eq, &exit); |
| 3784 | // slow path |
| 3785 | __ bind(&slow); |
| 3786 | __ push(r1); |
| 3787 | __ push(r0); |
| 3788 | __ mov(r0, Operand(1)); // set number of arguments |
| 3789 | __ InvokeBuiltin(Builtins::SUB, JUMP_JS); |
| 3790 | // done |
| 3791 | __ bind(&exit); |
| 3792 | break; |
| 3793 | } |
| 3794 | |
| 3795 | case Token::MUL: { |
| 3796 | Label slow, exit; |
| 3797 | // tag check |
| 3798 | __ orr(r2, r1, Operand(r0)); // r2 = x | y; |
| 3799 | ASSERT(kSmiTag == 0); // adjust code below |
| 3800 | __ tst(r2, Operand(kSmiTagMask)); |
| 3801 | __ b(ne, &slow); |
| 3802 | // remove tag from one operand (but keep sign), so that result is smi |
| 3803 | __ mov(ip, Operand(r0, ASR, kSmiTagSize)); |
| 3804 | // do multiplication |
| 3805 | __ smull(r3, r2, r1, ip); // r3 = lower 32 bits of ip*r1 |
| 3806 | // go slow on overflows (overflow bit is not set) |
| 3807 | __ mov(ip, Operand(r3, ASR, 31)); |
| 3808 | __ cmp(ip, Operand(r2)); // no overflow if higher 33 bits are identical |
| 3809 | __ b(ne, &slow); |
| 3810 | // go slow on zero result to handle -0 |
| 3811 | __ tst(r3, Operand(r3)); |
| 3812 | __ mov(r0, Operand(r3), LeaveCC, ne); |
| 3813 | __ b(ne, &exit); |
| 3814 | // slow case |
| 3815 | __ bind(&slow); |
| 3816 | __ push(r1); |
| 3817 | __ push(r0); |
| 3818 | __ mov(r0, Operand(1)); // set number of arguments |
| 3819 | __ InvokeBuiltin(Builtins::MUL, JUMP_JS); |
| 3820 | // done |
| 3821 | __ bind(&exit); |
| 3822 | break; |
| 3823 | } |
| 3824 | |
| 3825 | case Token::BIT_OR: |
| 3826 | case Token::BIT_AND: |
| 3827 | case Token::BIT_XOR: { |
| 3828 | Label slow, exit; |
| 3829 | // tag check |
| 3830 | __ orr(r2, r1, Operand(r0)); // r2 = x | y; |
| 3831 | ASSERT(kSmiTag == 0); // adjust code below |
| 3832 | __ tst(r2, Operand(kSmiTagMask)); |
| 3833 | __ b(ne, &slow); |
| 3834 | switch (op_) { |
| 3835 | case Token::BIT_OR: __ orr(r0, r0, Operand(r1)); break; |
| 3836 | case Token::BIT_AND: __ and_(r0, r0, Operand(r1)); break; |
| 3837 | case Token::BIT_XOR: __ eor(r0, r0, Operand(r1)); break; |
| 3838 | default: UNREACHABLE(); |
| 3839 | } |
| 3840 | __ b(&exit); |
| 3841 | __ bind(&slow); |
| 3842 | __ push(r1); // restore stack |
| 3843 | __ push(r0); |
| 3844 | __ mov(r0, Operand(1)); // 1 argument (not counting receiver). |
| 3845 | switch (op_) { |
| 3846 | case Token::BIT_OR: |
| 3847 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_JS); |
| 3848 | break; |
| 3849 | case Token::BIT_AND: |
| 3850 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_JS); |
| 3851 | break; |
| 3852 | case Token::BIT_XOR: |
| 3853 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_JS); |
| 3854 | break; |
| 3855 | default: |
| 3856 | UNREACHABLE(); |
| 3857 | } |
| 3858 | __ bind(&exit); |
| 3859 | break; |
| 3860 | } |
| 3861 | |
| 3862 | case Token::SHL: |
| 3863 | case Token::SHR: |
| 3864 | case Token::SAR: { |
| 3865 | Label slow, exit; |
| 3866 | // tag check |
| 3867 | __ orr(r2, r1, Operand(r0)); // r2 = x | y; |
| 3868 | ASSERT(kSmiTag == 0); // adjust code below |
| 3869 | __ tst(r2, Operand(kSmiTagMask)); |
| 3870 | __ b(ne, &slow); |
| 3871 | // remove tags from operands (but keep sign) |
| 3872 | __ mov(r3, Operand(r1, ASR, kSmiTagSize)); // x |
| 3873 | __ mov(r2, Operand(r0, ASR, kSmiTagSize)); // y |
| 3874 | // use only the 5 least significant bits of the shift count |
| 3875 | __ and_(r2, r2, Operand(0x1f)); |
| 3876 | // perform operation |
| 3877 | switch (op_) { |
| 3878 | case Token::SAR: |
| 3879 | __ mov(r3, Operand(r3, ASR, r2)); |
| 3880 | // no checks of result necessary |
| 3881 | break; |
| 3882 | |
| 3883 | case Token::SHR: |
| 3884 | __ mov(r3, Operand(r3, LSR, r2)); |
| 3885 | // check that the *unsigned* result fits in a smi |
| 3886 | // neither of the two high-order bits can be set: |
| 3887 | // - 0x80000000: high bit would be lost when smi tagging |
| 3888 | // - 0x40000000: this number would convert to negative when |
| 3889 | // smi tagging these two cases can only happen with shifts |
| 3890 | // by 0 or 1 when handed a valid smi |
| 3891 | __ and_(r2, r3, Operand(0xc0000000), SetCC); |
| 3892 | __ b(ne, &slow); |
| 3893 | break; |
| 3894 | |
| 3895 | case Token::SHL: |
| 3896 | __ mov(r3, Operand(r3, LSL, r2)); |
| 3897 | // check that the *signed* result fits in a smi |
| 3898 | __ add(r2, r3, Operand(0x40000000), SetCC); |
| 3899 | __ b(mi, &slow); |
| 3900 | break; |
| 3901 | |
| 3902 | default: UNREACHABLE(); |
| 3903 | } |
| 3904 | // tag result and store it in r0 |
| 3905 | ASSERT(kSmiTag == 0); // adjust code below |
| 3906 | __ mov(r0, Operand(r3, LSL, kSmiTagSize)); |
| 3907 | __ b(&exit); |
| 3908 | // slow case |
| 3909 | __ bind(&slow); |
| 3910 | __ push(r1); // restore stack |
| 3911 | __ push(r0); |
| 3912 | __ mov(r0, Operand(1)); // 1 argument (not counting receiver). |
| 3913 | switch (op_) { |
| 3914 | case Token::SAR: __ InvokeBuiltin(Builtins::SAR, JUMP_JS); break; |
| 3915 | case Token::SHR: __ InvokeBuiltin(Builtins::SHR, JUMP_JS); break; |
| 3916 | case Token::SHL: __ InvokeBuiltin(Builtins::SHL, JUMP_JS); break; |
| 3917 | default: UNREACHABLE(); |
| 3918 | } |
| 3919 | __ bind(&exit); |
| 3920 | break; |
| 3921 | } |
| 3922 | |
| 3923 | default: UNREACHABLE(); |
| 3924 | } |
| 3925 | __ Ret(); |
| 3926 | } |
| 3927 | |
| 3928 | |
| 3929 | void StackCheckStub::Generate(MacroAssembler* masm) { |
| 3930 | Label within_limit; |
| 3931 | __ mov(ip, Operand(ExternalReference::address_of_stack_guard_limit())); |
| 3932 | __ ldr(ip, MemOperand(ip)); |
| 3933 | __ cmp(sp, Operand(ip)); |
| 3934 | __ b(hs, &within_limit); |
| 3935 | // Do tail-call to runtime routine. |
| 3936 | __ push(r0); |
| 3937 | __ TailCallRuntime(ExternalReference(Runtime::kStackGuard), 1); |
| 3938 | __ bind(&within_limit); |
| 3939 | |
| 3940 | __ StubReturn(1); |
| 3941 | } |
| 3942 | |
| 3943 | |
| 3944 | void UnarySubStub::Generate(MacroAssembler* masm) { |
| 3945 | Label undo; |
| 3946 | Label slow; |
| 3947 | Label done; |
| 3948 | |
| 3949 | // Enter runtime system if the value is not a smi. |
| 3950 | __ tst(r0, Operand(kSmiTagMask)); |
| 3951 | __ b(ne, &slow); |
| 3952 | |
| 3953 | // Enter runtime system if the value of the expression is zero |
| 3954 | // to make sure that we switch between 0 and -0. |
| 3955 | __ cmp(r0, Operand(0)); |
| 3956 | __ b(eq, &slow); |
| 3957 | |
| 3958 | // The value of the expression is a smi that is not zero. Try |
| 3959 | // optimistic subtraction '0 - value'. |
| 3960 | __ rsb(r1, r0, Operand(0), SetCC); |
| 3961 | __ b(vs, &slow); |
| 3962 | |
| 3963 | // If result is a smi we are done. |
| 3964 | __ tst(r1, Operand(kSmiTagMask)); |
| 3965 | __ mov(r0, Operand(r1), LeaveCC, eq); // conditionally set r0 to result |
| 3966 | __ b(eq, &done); |
| 3967 | |
| 3968 | // Enter runtime system. |
| 3969 | __ bind(&slow); |
| 3970 | __ push(r0); |
| 3971 | __ mov(r0, Operand(0)); // set number of arguments |
| 3972 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_JS); |
| 3973 | |
| 3974 | __ bind(&done); |
| 3975 | __ StubReturn(1); |
| 3976 | } |
| 3977 | |
| 3978 | |
| 3979 | void InvokeBuiltinStub::Generate(MacroAssembler* masm) { |
| 3980 | __ push(r0); |
| 3981 | __ mov(r0, Operand(0)); // set number of arguments |
| 3982 | switch (kind_) { |
| 3983 | case ToNumber: __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_JS); break; |
| 3984 | case Inc: __ InvokeBuiltin(Builtins::INC, JUMP_JS); break; |
| 3985 | case Dec: __ InvokeBuiltin(Builtins::DEC, JUMP_JS); break; |
| 3986 | default: UNREACHABLE(); |
| 3987 | } |
| 3988 | __ StubReturn(argc_); |
| 3989 | } |
| 3990 | |
| 3991 | |
| 3992 | void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) { |
| 3993 | // r0 holds exception |
| 3994 | ASSERT(StackHandlerConstants::kSize == 6 * kPointerSize); // adjust this code |
| 3995 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 3996 | __ ldr(sp, MemOperand(r3)); |
| 3997 | __ pop(r2); // pop next in chain |
| 3998 | __ str(r2, MemOperand(r3)); |
| 3999 | // restore parameter- and frame-pointer and pop state. |
| 4000 | __ ldm(ia_w, sp, r3.bit() | pp.bit() | fp.bit()); |
| 4001 | // Before returning we restore the context from the frame pointer if not NULL. |
| 4002 | // The frame pointer is NULL in the exception handler of a JS entry frame. |
| 4003 | __ cmp(fp, Operand(0)); |
| 4004 | // Set cp to NULL if fp is NULL. |
| 4005 | __ mov(cp, Operand(0), LeaveCC, eq); |
| 4006 | // Restore cp otherwise. |
| 4007 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 4008 | if (kDebug && FLAG_debug_code) __ mov(lr, Operand(pc)); |
| 4009 | __ pop(pc); |
| 4010 | } |
| 4011 | |
| 4012 | |
| 4013 | void CEntryStub::GenerateThrowOutOfMemory(MacroAssembler* masm) { |
| 4014 | // Fetch top stack handler. |
| 4015 | __ mov(r3, Operand(ExternalReference(Top::k_handler_address))); |
| 4016 | __ ldr(r3, MemOperand(r3)); |
| 4017 | |
| 4018 | // Unwind the handlers until the ENTRY handler is found. |
| 4019 | Label loop, done; |
| 4020 | __ bind(&loop); |
| 4021 | // Load the type of the current stack handler. |
| 4022 | const int kStateOffset = StackHandlerConstants::kAddressDisplacement + |
| 4023 | StackHandlerConstants::kStateOffset; |
| 4024 | __ ldr(r2, MemOperand(r3, kStateOffset)); |
| 4025 | __ cmp(r2, Operand(StackHandler::ENTRY)); |
| 4026 | __ b(eq, &done); |
| 4027 | // Fetch the next handler in the list. |
| 4028 | const int kNextOffset = StackHandlerConstants::kAddressDisplacement + |
| 4029 | StackHandlerConstants::kNextOffset; |
| 4030 | __ ldr(r3, MemOperand(r3, kNextOffset)); |
| 4031 | __ jmp(&loop); |
| 4032 | __ bind(&done); |
| 4033 | |
| 4034 | // Set the top handler address to next handler past the current ENTRY handler. |
| 4035 | __ ldr(r0, MemOperand(r3, kNextOffset)); |
| 4036 | __ mov(r2, Operand(ExternalReference(Top::k_handler_address))); |
| 4037 | __ str(r0, MemOperand(r2)); |
| 4038 | |
| 4039 | // Set external caught exception to false. |
| 4040 | __ mov(r0, Operand(false)); |
| 4041 | ExternalReference external_caught(Top::k_external_caught_exception_address); |
| 4042 | __ mov(r2, Operand(external_caught)); |
| 4043 | __ str(r0, MemOperand(r2)); |
| 4044 | |
| 4045 | // Set pending exception and r0 to out of memory exception. |
| 4046 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 4047 | __ mov(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 4048 | __ mov(r2, Operand(ExternalReference(Top::k_pending_exception_address))); |
| 4049 | __ str(r0, MemOperand(r2)); |
| 4050 | |
| 4051 | // Restore the stack to the address of the ENTRY handler |
| 4052 | __ mov(sp, Operand(r3)); |
| 4053 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4054 | // Stack layout at this point. See also PushTryHandler |
| 4055 | // r3, sp -> next handler |
| 4056 | // state (ENTRY) |
| 4057 | // pp |
| 4058 | // fp |
| 4059 | // lr |
| 4060 | |
| 4061 | // Discard ENTRY state (r2 is not used), and restore parameter- |
| 4062 | // and frame-pointer and pop state. |
| 4063 | __ ldm(ia_w, sp, r2.bit() | r3.bit() | pp.bit() | fp.bit()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4064 | // Before returning we restore the context from the frame pointer if not NULL. |
| 4065 | // The frame pointer is NULL in the exception handler of a JS entry frame. |
| 4066 | __ cmp(fp, Operand(0)); |
| 4067 | // Set cp to NULL if fp is NULL. |
| 4068 | __ mov(cp, Operand(0), LeaveCC, eq); |
| 4069 | // Restore cp otherwise. |
| 4070 | __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset), ne); |
| 4071 | if (kDebug && FLAG_debug_code) __ mov(lr, Operand(pc)); |
| 4072 | __ pop(pc); |
| 4073 | } |
| 4074 | |
| 4075 | |
| 4076 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4077 | Label* throw_normal_exception, |
| 4078 | Label* throw_out_of_memory_exception, |
| 4079 | StackFrame::Type frame_type, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4080 | bool do_gc, |
| 4081 | bool always_allocate) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4082 | // r0: result parameter for PerformGC, if any |
| 4083 | // r4: number of arguments including receiver (C callee-saved) |
| 4084 | // r5: pointer to builtin function (C callee-saved) |
| 4085 | // r6: pointer to the first argument (C callee-saved) |
| 4086 | |
| 4087 | if (do_gc) { |
| 4088 | // Passing r0. |
| 4089 | __ Call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4090 | } |
| 4091 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4092 | ExternalReference scope_depth = |
| 4093 | ExternalReference::heap_always_allocate_scope_depth(); |
| 4094 | if (always_allocate) { |
| 4095 | __ mov(r0, Operand(scope_depth)); |
| 4096 | __ ldr(r1, MemOperand(r0)); |
| 4097 | __ add(r1, r1, Operand(1)); |
| 4098 | __ str(r1, MemOperand(r0)); |
| 4099 | } |
| 4100 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4101 | // Call C built-in. |
| 4102 | // r0 = argc, r1 = argv |
| 4103 | __ mov(r0, Operand(r4)); |
| 4104 | __ mov(r1, Operand(r6)); |
| 4105 | |
| 4106 | // TODO(1242173): To let the GC traverse the return address of the exit |
| 4107 | // frames, we need to know where the return address is. Right now, |
| 4108 | // we push it on the stack to be able to find it again, but we never |
| 4109 | // restore from it in case of changes, which makes it impossible to |
| 4110 | // support moving the C entry code stub. This should be fixed, but currently |
| 4111 | // this is OK because the CEntryStub gets generated so early in the V8 boot |
| 4112 | // sequence that it is not moving ever. |
| 4113 | __ add(lr, pc, Operand(4)); // compute return address: (pc + 8) + 4 |
| 4114 | __ push(lr); |
| 4115 | #if !defined(__arm__) |
| 4116 | // Notify the simulator of the transition to C code. |
| 4117 | __ swi(assembler::arm::call_rt_r5); |
| 4118 | #else /* !defined(__arm__) */ |
| 4119 | __ mov(pc, Operand(r5)); |
| 4120 | #endif /* !defined(__arm__) */ |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4121 | |
| 4122 | if (always_allocate) { |
| 4123 | // It's okay to clobber r2 and r3 here. Don't mess with r0 and r1 |
| 4124 | // though (contain the result). |
| 4125 | __ mov(r2, Operand(scope_depth)); |
| 4126 | __ ldr(r3, MemOperand(r2)); |
| 4127 | __ sub(r3, r3, Operand(1)); |
| 4128 | __ str(r3, MemOperand(r2)); |
| 4129 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4130 | |
| 4131 | // check for failure result |
| 4132 | Label failure_returned; |
| 4133 | ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4134 | // Lower 2 bits of r2 are 0 iff r0 has failure tag. |
| 4135 | __ add(r2, r0, Operand(1)); |
| 4136 | __ tst(r2, Operand(kFailureTagMask)); |
| 4137 | __ b(eq, &failure_returned); |
| 4138 | |
| 4139 | // Exit C frame and return. |
| 4140 | // r0:r1: result |
| 4141 | // sp: stack pointer |
| 4142 | // fp: frame pointer |
| 4143 | // pp: caller's parameter pointer pp (restored as C callee-saved) |
| 4144 | __ LeaveExitFrame(frame_type); |
| 4145 | |
| 4146 | // check if we should retry or throw exception |
| 4147 | Label retry; |
| 4148 | __ bind(&failure_returned); |
| 4149 | ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4150 | __ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
| 4151 | __ b(eq, &retry); |
| 4152 | |
| 4153 | Label continue_exception; |
| 4154 | // If the returned failure is EXCEPTION then promote Top::pending_exception(). |
| 4155 | __ cmp(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
| 4156 | __ b(ne, &continue_exception); |
| 4157 | |
| 4158 | // Retrieve the pending exception and clear the variable. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4159 | __ mov(ip, Operand(ExternalReference::the_hole_value_location())); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4160 | __ ldr(r3, MemOperand(ip)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4161 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4162 | __ ldr(r0, MemOperand(ip)); |
| 4163 | __ str(r3, MemOperand(ip)); |
| 4164 | |
| 4165 | __ bind(&continue_exception); |
| 4166 | // Special handling of out of memory exception. |
| 4167 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 4168 | __ cmp(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 4169 | __ b(eq, throw_out_of_memory_exception); |
| 4170 | |
| 4171 | // Handle normal exception. |
| 4172 | __ jmp(throw_normal_exception); |
| 4173 | |
| 4174 | __ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying |
| 4175 | } |
| 4176 | |
| 4177 | |
| 4178 | void CEntryStub::GenerateBody(MacroAssembler* masm, bool is_debug_break) { |
| 4179 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 4180 | // r0: number of arguments including receiver |
| 4181 | // r1: pointer to builtin function |
| 4182 | // fp: frame pointer (restored after C call) |
| 4183 | // sp: stack pointer (restored as callee's pp after C call) |
| 4184 | // cp: current context (C callee-saved) |
| 4185 | // pp: caller's parameter pointer pp (C callee-saved) |
| 4186 | |
| 4187 | // NOTE: Invocations of builtins may return failure objects |
| 4188 | // instead of a proper result. The builtin entry handles |
| 4189 | // this by performing a garbage collection and retrying the |
| 4190 | // builtin once. |
| 4191 | |
| 4192 | StackFrame::Type frame_type = is_debug_break |
| 4193 | ? StackFrame::EXIT_DEBUG |
| 4194 | : StackFrame::EXIT; |
| 4195 | |
| 4196 | // Enter the exit frame that transitions from JavaScript to C++. |
| 4197 | __ EnterExitFrame(frame_type); |
| 4198 | |
| 4199 | // r4: number of arguments (C callee-saved) |
| 4200 | // r5: pointer to builtin function (C callee-saved) |
| 4201 | // r6: pointer to first argument (C callee-saved) |
| 4202 | |
| 4203 | Label throw_out_of_memory_exception; |
| 4204 | Label throw_normal_exception; |
| 4205 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4206 | // Call into the runtime system. Collect garbage before the call if |
| 4207 | // running with --gc-greedy set. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4208 | if (FLAG_gc_greedy) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4209 | Failure* failure = Failure::RetryAfterGC(0); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4210 | __ mov(r0, Operand(reinterpret_cast<intptr_t>(failure))); |
| 4211 | } |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4212 | GenerateCore(masm, &throw_normal_exception, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4213 | &throw_out_of_memory_exception, |
| 4214 | frame_type, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4215 | FLAG_gc_greedy, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4216 | false); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4217 | |
| 4218 | // Do space-specific GC and retry runtime call. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4219 | GenerateCore(masm, |
| 4220 | &throw_normal_exception, |
| 4221 | &throw_out_of_memory_exception, |
| 4222 | frame_type, |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4223 | true, |
| 4224 | false); |
| 4225 | |
| 4226 | // Do full GC and retry runtime call one final time. |
| 4227 | Failure* failure = Failure::InternalError(); |
| 4228 | __ mov(r0, Operand(reinterpret_cast<int32_t>(failure))); |
| 4229 | GenerateCore(masm, |
| 4230 | &throw_normal_exception, |
| 4231 | &throw_out_of_memory_exception, |
| 4232 | frame_type, |
| 4233 | true, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4234 | true); |
| 4235 | |
| 4236 | __ bind(&throw_out_of_memory_exception); |
| 4237 | GenerateThrowOutOfMemory(masm); |
| 4238 | // control flow for generated will not return. |
| 4239 | |
| 4240 | __ bind(&throw_normal_exception); |
| 4241 | GenerateThrowTOS(masm); |
| 4242 | } |
| 4243 | |
| 4244 | |
| 4245 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 4246 | // r0: code entry |
| 4247 | // r1: function |
| 4248 | // r2: receiver |
| 4249 | // r3: argc |
| 4250 | // [sp+0]: argv |
| 4251 | |
| 4252 | Label invoke, exit; |
| 4253 | |
| 4254 | // Called from C, so do not pop argc and args on exit (preserve sp) |
| 4255 | // No need to save register-passed args |
| 4256 | // Save callee-saved registers (incl. cp, pp, and fp), sp, and lr |
| 4257 | __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| 4258 | |
| 4259 | // Get address of argv, see stm above. |
| 4260 | // r0: code entry |
| 4261 | // r1: function |
| 4262 | // r2: receiver |
| 4263 | // r3: argc |
| 4264 | __ add(r4, sp, Operand((kNumCalleeSaved + 1)*kPointerSize)); |
| 4265 | __ ldr(r4, MemOperand(r4)); // argv |
| 4266 | |
| 4267 | // Push a frame with special values setup to mark it as an entry frame. |
| 4268 | // r0: code entry |
| 4269 | // r1: function |
| 4270 | // r2: receiver |
| 4271 | // r3: argc |
| 4272 | // r4: argv |
| 4273 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4274 | __ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 4275 | __ mov(r7, Operand(~ArgumentsAdaptorFrame::SENTINEL)); |
| 4276 | __ mov(r6, Operand(Smi::FromInt(marker))); |
| 4277 | __ mov(r5, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 4278 | __ ldr(r5, MemOperand(r5)); |
| 4279 | __ stm(db_w, sp, r5.bit() | r6.bit() | r7.bit() | r8.bit()); |
| 4280 | |
| 4281 | // Setup frame pointer for the frame to be pushed. |
| 4282 | __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 4283 | |
| 4284 | // Call a faked try-block that does the invoke. |
| 4285 | __ bl(&invoke); |
| 4286 | |
| 4287 | // Caught exception: Store result (exception) in the pending |
| 4288 | // exception field in the JSEnv and return a failure sentinel. |
| 4289 | // Coming in here the fp will be invalid because the PushTryHandler below |
| 4290 | // sets it to 0 to signal the existence of the JSEntry frame. |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4291 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4292 | __ str(r0, MemOperand(ip)); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4293 | __ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4294 | __ b(&exit); |
| 4295 | |
| 4296 | // Invoke: Link this frame into the handler chain. |
| 4297 | __ bind(&invoke); |
| 4298 | // Must preserve r0-r4, r5-r7 are available. |
| 4299 | __ PushTryHandler(IN_JS_ENTRY, JS_ENTRY_HANDLER); |
| 4300 | // If an exception not caught by another handler occurs, this handler returns |
| 4301 | // control to the code after the bl(&invoke) above, which restores all |
| 4302 | // kCalleeSaved registers (including cp, pp and fp) to their saved values |
| 4303 | // before returning a failure to C. |
| 4304 | |
| 4305 | // Clear any pending exceptions. |
| 4306 | __ mov(ip, Operand(ExternalReference::the_hole_value_location())); |
| 4307 | __ ldr(r5, MemOperand(ip)); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 4308 | __ mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4309 | __ str(r5, MemOperand(ip)); |
| 4310 | |
| 4311 | // Invoke the function by calling through JS entry trampoline builtin. |
| 4312 | // Notice that we cannot store a reference to the trampoline code directly in |
| 4313 | // this stub, because runtime stubs are not traversed when doing GC. |
| 4314 | |
| 4315 | // Expected registers by Builtins::JSEntryTrampoline |
| 4316 | // r0: code entry |
| 4317 | // r1: function |
| 4318 | // r2: receiver |
| 4319 | // r3: argc |
| 4320 | // r4: argv |
| 4321 | if (is_construct) { |
| 4322 | ExternalReference construct_entry(Builtins::JSConstructEntryTrampoline); |
| 4323 | __ mov(ip, Operand(construct_entry)); |
| 4324 | } else { |
| 4325 | ExternalReference entry(Builtins::JSEntryTrampoline); |
| 4326 | __ mov(ip, Operand(entry)); |
| 4327 | } |
| 4328 | __ ldr(ip, MemOperand(ip)); // deref address |
| 4329 | |
| 4330 | // Branch and link to JSEntryTrampoline |
| 4331 | __ mov(lr, Operand(pc)); |
| 4332 | __ add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 4333 | |
| 4334 | // Unlink this frame from the handler chain. When reading the |
| 4335 | // address of the next handler, there is no need to use the address |
| 4336 | // displacement since the current stack pointer (sp) points directly |
| 4337 | // to the stack handler. |
| 4338 | __ ldr(r3, MemOperand(sp, StackHandlerConstants::kNextOffset)); |
| 4339 | __ mov(ip, Operand(ExternalReference(Top::k_handler_address))); |
| 4340 | __ str(r3, MemOperand(ip)); |
| 4341 | // No need to restore registers |
| 4342 | __ add(sp, sp, Operand(StackHandlerConstants::kSize)); |
| 4343 | |
| 4344 | __ bind(&exit); // r0 holds result |
| 4345 | // Restore the top frame descriptors from the stack. |
| 4346 | __ pop(r3); |
| 4347 | __ mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
| 4348 | __ str(r3, MemOperand(ip)); |
| 4349 | |
| 4350 | // Reset the stack to the callee saved registers. |
| 4351 | __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 4352 | |
| 4353 | // Restore callee-saved registers and return. |
| 4354 | #ifdef DEBUG |
| 4355 | if (FLAG_debug_code) __ mov(lr, Operand(pc)); |
| 4356 | #endif |
| 4357 | __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 4358 | } |
| 4359 | |
| 4360 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4361 | void ArgumentsAccessStub::GenerateReadLength(MacroAssembler* masm) { |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4362 | // Check if the calling frame is an arguments adaptor frame. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4363 | Label adaptor; |
| 4364 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4365 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4366 | __ cmp(r3, Operand(ArgumentsAdaptorFrame::SENTINEL)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4367 | __ b(eq, &adaptor); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4368 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4369 | // Nothing to do: The formal number of parameters has already been |
| 4370 | // passed in register r0 by calling function. Just return it. |
| 4371 | __ mov(pc, lr); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4372 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4373 | // Arguments adaptor case: Read the arguments length from the |
| 4374 | // adaptor frame and return it. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4375 | __ bind(&adaptor); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4376 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4377 | __ mov(pc, lr); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
| 4380 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4381 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 4382 | // The displacement is the offset of the last parameter (if any) |
| 4383 | // relative to the frame pointer. |
| 4384 | static const int kDisplacement = |
| 4385 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4386 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4387 | // Check that the key is a smi. |
| 4388 | Label slow; |
| 4389 | __ tst(r1, Operand(kSmiTagMask)); |
| 4390 | __ b(ne, &slow); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4391 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4392 | // Check if the calling frame is an arguments adaptor frame. |
| 4393 | Label adaptor; |
| 4394 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4395 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4396 | __ cmp(r3, Operand(ArgumentsAdaptorFrame::SENTINEL)); |
| 4397 | __ b(eq, &adaptor); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4398 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4399 | // Check index against formal parameters count limit passed in |
| 4400 | // through register eax. Use unsigned comparison to get negative |
| 4401 | // check for free. |
| 4402 | __ cmp(r1, r0); |
| 4403 | __ b(cs, &slow); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4404 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4405 | // Read the argument from the stack and return it. |
| 4406 | __ sub(r3, r0, r1); |
| 4407 | __ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4408 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4409 | __ mov(pc, lr); |
| 4410 | |
| 4411 | // Arguments adaptor case: Check index against actual arguments |
| 4412 | // limit found in the arguments adaptor frame. Use unsigned |
| 4413 | // comparison to get negative check for free. |
| 4414 | __ bind(&adaptor); |
| 4415 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4416 | __ cmp(r1, r0); |
| 4417 | __ b(cs, &slow); |
| 4418 | |
| 4419 | // Read the argument from the adaptor frame and return it. |
| 4420 | __ sub(r3, r0, r1); |
| 4421 | __ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4422 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 4423 | __ mov(pc, lr); |
| 4424 | |
| 4425 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 4426 | // by calling the runtime system. |
| 4427 | __ bind(&slow); |
| 4428 | __ push(r1); |
| 4429 | __ TailCallRuntime(ExternalReference(Runtime::kGetArgumentsProperty), 1); |
| 4430 | } |
| 4431 | |
| 4432 | |
| 4433 | void ArgumentsAccessStub::GenerateNewObject(MacroAssembler* masm) { |
| 4434 | // Check if the calling frame is an arguments adaptor frame. |
| 4435 | Label runtime; |
| 4436 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4437 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4438 | __ cmp(r3, Operand(ArgumentsAdaptorFrame::SENTINEL)); |
| 4439 | __ b(ne, &runtime); |
| 4440 | |
| 4441 | // Patch the arguments.length and the parameters pointer. |
| 4442 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4443 | __ str(r0, MemOperand(sp, 0 * kPointerSize)); |
| 4444 | __ add(r3, r2, Operand(r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4445 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4446 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4447 | |
| 4448 | // Do the runtime call to allocate the arguments object. |
| 4449 | __ bind(&runtime); |
| 4450 | __ TailCallRuntime(ExternalReference(Runtime::kNewArgumentsFast), 3); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | |
| 4454 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
| 4455 | Label slow; |
| 4456 | // Get the function to call from the stack. |
| 4457 | // function, receiver [, arguments] |
| 4458 | __ ldr(r1, MemOperand(sp, (argc_ + 1) * kPointerSize)); |
| 4459 | |
| 4460 | // Check that the function is really a JavaScript function. |
| 4461 | // r1: pushed function (to be verified) |
| 4462 | __ tst(r1, Operand(kSmiTagMask)); |
| 4463 | __ b(eq, &slow); |
| 4464 | // Get the map of the function object. |
| 4465 | __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 4466 | __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset)); |
| 4467 | __ cmp(r2, Operand(JS_FUNCTION_TYPE)); |
| 4468 | __ b(ne, &slow); |
| 4469 | |
| 4470 | // Fast-case: Invoke the function now. |
| 4471 | // r1: pushed function |
| 4472 | ParameterCount actual(argc_); |
| 4473 | __ InvokeFunction(r1, actual, JUMP_FUNCTION); |
| 4474 | |
| 4475 | // Slow-case: Non-function called. |
| 4476 | __ bind(&slow); |
| 4477 | __ mov(r0, Operand(argc_)); // Setup the number of arguments. |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 4478 | __ mov(r2, Operand(0)); |
| 4479 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
| 4480 | __ Jump(Handle<Code>(Builtins::builtin(Builtins::ArgumentsAdaptorTrampoline)), |
| 4481 | RelocInfo::CODE_TARGET); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | |
| 4485 | #undef __ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4486 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4487 | } } // namespace v8::internal |