| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 36 class RegisterAllocator; | 36 class RegisterAllocator; |
| 37 class RegisterFile; | 37 class RegisterFile; |
| 38 | 38 |
| 39 enum InitState { CONST_INIT, NOT_CONST_INIT }; | 39 enum InitState { CONST_INIT, NOT_CONST_INIT }; |
| 40 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; | 40 enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
| 41 | 41 |
| 42 | 42 |
| 43 // ------------------------------------------------------------------------- | 43 // ------------------------------------------------------------------------- |
| 44 // Reference support | 44 // Reference support |
| 45 | 45 |
| 46 // A reference is a C++ stack-allocated object that keeps an ECMA | 46 // A reference is a C++ stack-allocated object that puts a |
| 47 // reference on the execution stack while in scope. For variables | 47 // reference on the virtual frame. The reference may be consumed |
| 48 // the reference is empty, indicating that it isn't necessary to | 48 // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. |
| 49 // store state on the stack for keeping track of references to those. | 49 // When the lifetime (scope) of a valid reference ends, it must have |
| 50 // For properties, we keep either one (named) or two (indexed) values | 50 // been consumed, and be in state UNLOADED. |
| 51 // on the execution stack to represent the reference. | |
| 52 | |
| 53 class Reference BASE_EMBEDDED { | 51 class Reference BASE_EMBEDDED { |
| 54 public: | 52 public: |
| 55 // The values of the types is important, see size(). | 53 // The values of the types is important, see size(). |
| 56 enum Type { ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; | 54 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; |
| 57 Reference(CodeGenerator* cgen, Expression* expression); | 55 Reference(CodeGenerator* cgen, |
| 56 Expression* expression, |
| 57 bool persist_after_get = false); |
| 58 ~Reference(); | 58 ~Reference(); |
| 59 | 59 |
| 60 Expression* expression() const { return expression_; } | 60 Expression* expression() const { return expression_; } |
| 61 Type type() const { return type_; } | 61 Type type() const { return type_; } |
| 62 void set_type(Type value) { | 62 void set_type(Type value) { |
| 63 ASSERT(type_ == ILLEGAL); | 63 ASSERT_EQ(ILLEGAL, type_); |
| 64 type_ = value; | 64 type_ = value; |
| 65 } | 65 } |
| 66 | 66 |
| 67 void set_unloaded() { |
| 68 ASSERT_NE(ILLEGAL, type_); |
| 69 ASSERT_NE(UNLOADED, type_); |
| 70 type_ = UNLOADED; |
| 71 } |
| 67 // The size the reference takes up on the stack. | 72 // The size the reference takes up on the stack. |
| 68 int size() const { return (type_ == ILLEGAL) ? 0 : type_; } | 73 int size() const { |
| 74 return (type_ < SLOT) ? 0 : type_; |
| 75 } |
| 69 | 76 |
| 70 bool is_illegal() const { return type_ == ILLEGAL; } | 77 bool is_illegal() const { return type_ == ILLEGAL; } |
| 71 bool is_slot() const { return type_ == SLOT; } | 78 bool is_slot() const { return type_ == SLOT; } |
| 72 bool is_property() const { return type_ == NAMED || type_ == KEYED; } | 79 bool is_property() const { return type_ == NAMED || type_ == KEYED; } |
| 80 bool is_unloaded() const { return type_ == UNLOADED; } |
| 73 | 81 |
| 74 // Return the name. Only valid for named property references. | 82 // Return the name. Only valid for named property references. |
| 75 Handle<String> GetName(); | 83 Handle<String> GetName(); |
| 76 | 84 |
| 77 // Generate code to push the value of the reference on top of the | 85 // Generate code to push the value of the reference on top of the |
| 78 // expression stack. The reference is expected to be already on top of | 86 // expression stack. The reference is expected to be already on top of |
| 79 // the expression stack, and it is left in place with its value above it. | 87 // the expression stack, and it is consumed by the call unless the |
| 88 // reference is for a compound assignment. |
| 89 // If the reference is not consumed, it is left in place under its value. |
| 80 void GetValue(); | 90 void GetValue(); |
| 81 | 91 |
| 82 // Like GetValue except that the slot is expected to be written to before | 92 // Like GetValue except that the slot is expected to be written to before |
| 83 // being read from again. Thae value of the reference may be invalidated, | 93 // being read from again. The value of the reference may be invalidated, |
| 84 // causing subsequent attempts to read it to fail. | 94 // causing subsequent attempts to read it to fail. |
| 85 void TakeValue(); | 95 void TakeValue(); |
| 86 | 96 |
| 87 // Generate code to store the value on top of the expression stack in the | 97 // Generate code to store the value on top of the expression stack in the |
| 88 // reference. The reference is expected to be immediately below the value | 98 // reference. The reference is expected to be immediately below the value |
| 89 // on the expression stack. The stored value is left in place (with the | 99 // on the expression stack. The value is stored in the location specified |
| 90 // reference intact below it) to support chained assignments. | 100 // by the reference, and is left on top of the stack, after the reference |
| 101 // is popped from beneath it (unloaded). |
| 91 void SetValue(InitState init_state); | 102 void SetValue(InitState init_state); |
| 92 | 103 |
| 93 private: | 104 private: |
| 94 CodeGenerator* cgen_; | 105 CodeGenerator* cgen_; |
| 95 Expression* expression_; | 106 Expression* expression_; |
| 96 Type type_; | 107 Type type_; |
| 108 // Keep the reference on the stack after get, so it can be used by set later. |
| 109 bool persist_after_get_; |
| 97 }; | 110 }; |
| 98 | 111 |
| 99 | 112 |
| 100 // ------------------------------------------------------------------------- | 113 // ------------------------------------------------------------------------- |
| 101 // Control destinations. | 114 // Control destinations. |
| 102 | 115 |
| 103 // A control destination encapsulates a pair of jump targets and a | 116 // A control destination encapsulates a pair of jump targets and a |
| 104 // flag indicating which one is the preferred fall-through. The | 117 // flag indicating which one is the preferred fall-through. The |
| 105 // preferred fall-through must be unbound, the other may be already | 118 // preferred fall-through must be unbound, the other may be already |
| 106 // bound (ie, a backward target). | 119 // bound (ie, a backward target). |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 void LoadFromSlot(Slot* slot, TypeofState typeof_state); | 426 void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
| 414 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState typeof_state); | 427 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState typeof_state); |
| 415 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, | 428 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 416 TypeofState typeof_state, | 429 TypeofState typeof_state, |
| 417 JumpTarget* slow); | 430 JumpTarget* slow); |
| 418 | 431 |
| 419 // Store the value on top of the expression stack into a slot, leaving the | 432 // Store the value on top of the expression stack into a slot, leaving the |
| 420 // value in place. | 433 // value in place. |
| 421 void StoreToSlot(Slot* slot, InitState init_state); | 434 void StoreToSlot(Slot* slot, InitState init_state); |
| 422 | 435 |
| 436 // Load a property of an object, returning it in a Result. |
| 437 // The object and the property name are passed on the stack, and |
| 438 // not changed. |
| 439 Result EmitKeyedLoad(bool is_global); |
| 440 |
| 423 // Special code for typeof expressions: Unfortunately, we must | 441 // Special code for typeof expressions: Unfortunately, we must |
| 424 // be careful when loading the expression in 'typeof' | 442 // be careful when loading the expression in 'typeof' |
| 425 // expressions. We are not allowed to throw reference errors for | 443 // expressions. We are not allowed to throw reference errors for |
| 426 // non-existing properties of the global object, so we must make it | 444 // non-existing properties of the global object, so we must make it |
| 427 // look like an explicit property access, instead of an access | 445 // look like an explicit property access, instead of an access |
| 428 // through the context chain. | 446 // through the context chain. |
| 429 void LoadTypeofExpression(Expression* x); | 447 void LoadTypeofExpression(Expression* x); |
| 430 | 448 |
| 431 // Translate the value on top of the frame into control flow to the | 449 // Translate the value on top of the frame into control flow to the |
| 432 // control destination. | 450 // control destination. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Load an integer constant x into a register target or into the stack using | 490 // Load an integer constant x into a register target or into the stack using |
| 473 // at most 16 bits of user-controlled data per assembly operation. | 491 // at most 16 bits of user-controlled data per assembly operation. |
| 474 void MoveUnsafeSmi(Register target, Handle<Object> value); | 492 void MoveUnsafeSmi(Register target, Handle<Object> value); |
| 475 void StoreUnsafeSmiToLocal(int offset, Handle<Object> value); | 493 void StoreUnsafeSmiToLocal(int offset, Handle<Object> value); |
| 476 void PushUnsafeSmi(Handle<Object> value); | 494 void PushUnsafeSmi(Handle<Object> value); |
| 477 | 495 |
| 478 void CallWithArguments(ZoneList<Expression*>* arguments, | 496 void CallWithArguments(ZoneList<Expression*>* arguments, |
| 479 CallFunctionFlags flags, | 497 CallFunctionFlags flags, |
| 480 int position); | 498 int position); |
| 481 | 499 |
| 482 // Use an optimized version of Function.prototype.apply that avoid | 500 // An optimized implementation of expressions of the form |
| 483 // allocating the arguments object and just copies the arguments | 501 // x.apply(y, arguments). We call x the applicand and y the receiver. |
| 484 // from the stack. | 502 // The optimization avoids allocating an arguments object if possible. |
| 485 void CallApplyLazy(Property* apply, | 503 void CallApplyLazy(Expression* applicand, |
| 486 Expression* receiver, | 504 Expression* receiver, |
| 487 VariableProxy* arguments, | 505 VariableProxy* arguments, |
| 488 int position); | 506 int position); |
| 489 | 507 |
| 490 void CheckStack(); | 508 void CheckStack(); |
| 491 | 509 |
| 492 struct InlineRuntimeLUT { | 510 struct InlineRuntimeLUT { |
| 493 void (CodeGenerator::*method)(ZoneList<Expression*>*); | 511 void (CodeGenerator::*method)(ZoneList<Expression*>*); |
| 494 const char* name; | 512 const char* name; |
| 495 }; | 513 }; |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 Major MajorKey() { return StringCompare; } | 818 Major MajorKey() { return StringCompare; } |
| 801 int MinorKey() { return 0; } | 819 int MinorKey() { return 0; } |
| 802 | 820 |
| 803 void Generate(MacroAssembler* masm); | 821 void Generate(MacroAssembler* masm); |
| 804 }; | 822 }; |
| 805 | 823 |
| 806 | 824 |
| 807 } } // namespace v8::internal | 825 } } // namespace v8::internal |
| 808 | 826 |
| 809 #endif // V8_IA32_CODEGEN_IA32_H_ | 827 #endif // V8_IA32_CODEGEN_IA32_H_ |
| OLD | NEW |