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