Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: src/x64/codegen-x64.h

Issue 487017: Refactor Reference so that SetValue and GetValue pop the reference state. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 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
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
56 Reference(CodeGenerator* cgen,
57 Expression* expression,
58 bool persist_after_get = false);
58 ~Reference(); 59 ~Reference();
59 60
60 Expression* expression() const { return expression_; } 61 Expression* expression() const { return expression_; }
61 Type type() const { return type_; } 62 Type type() const { return type_; }
62 void set_type(Type value) { 63 void set_type(Type value) {
63 ASSERT(type_ == ILLEGAL); 64 ASSERT_EQ(ILLEGAL, type_);
64 type_ = value; 65 type_ = value;
65 } 66 }
66 67
68 void set_unloaded() {
69 ASSERT_NE(ILLEGAL, type_);
70 ASSERT_NE(UNLOADED, type_);
71 type_ = UNLOADED;
72 }
67 // The size the reference takes up on the stack. 73 // The size the reference takes up on the stack.
68 int size() const { return (type_ == ILLEGAL) ? 0 : type_; } 74 int size() const {
75 return (type_ < SLOT) ? 0 : type_;
76 }
69 77
70 bool is_illegal() const { return type_ == ILLEGAL; } 78 bool is_illegal() const { return type_ == ILLEGAL; }
71 bool is_slot() const { return type_ == SLOT; } 79 bool is_slot() const { return type_ == SLOT; }
72 bool is_property() const { return type_ == NAMED || type_ == KEYED; } 80 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
81 bool is_unloaded() const { return type_ == UNLOADED; }
73 82
74 // Return the name. Only valid for named property references. 83 // Return the name. Only valid for named property references.
75 Handle<String> GetName(); 84 Handle<String> GetName();
76 85
77 // Generate code to push the value of the reference on top of the 86 // 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 87 // 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. 88 // the expression stack, and it is consumed by the call unless the
89 // reference is for a compound assignment.
90 // If the reference is not consumed, it is left in place under its value.
80 void GetValue(); 91 void GetValue();
81 92
82 // Like GetValue except that the slot is expected to be written to before 93 // 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, 94 // being read from again. The value of the reference may be invalidated,
84 // causing subsequent attempts to read it to fail. 95 // causing subsequent attempts to read it to fail.
85 void TakeValue(); 96 void TakeValue();
86 97
87 // Generate code to store the value on top of the expression stack in the 98 // 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 99 // 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 100 // on the expression stack. The value is stored in the location specified
90 // reference intact below it) to support chained assignments. 101 // by the reference, and is left on top of the stack, after the reference
102 // is popped from beneath it (unloaded).
91 void SetValue(InitState init_state); 103 void SetValue(InitState init_state);
92 104
93 private: 105 private:
94 CodeGenerator* cgen_; 106 CodeGenerator* cgen_;
95 Expression* expression_; 107 Expression* expression_;
96 Type type_; 108 Type type_;
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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void LoadFromSlot(Slot* slot, TypeofState typeof_state); 428 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
416 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state); 429 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
417 Result LoadFromGlobalSlotCheckExtensions(Slot* slot, 430 Result LoadFromGlobalSlotCheckExtensions(Slot* slot,
418 TypeofState typeof_state, 431 TypeofState typeof_state,
419 JumpTarget* slow); 432 JumpTarget* slow);
420 433
421 // Store the value on top of the expression stack into a slot, leaving the 434 // Store the value on top of the expression stack into a slot, leaving the
422 // value in place. 435 // value in place.
423 void StoreToSlot(Slot* slot, InitState init_state); 436 void StoreToSlot(Slot* slot, InitState init_state);
424 437
438 // Load a property of an object, returning it in a Result.
439 // The object and the property name are passed on the stack, and
440 // not changed.
441 Result EmitKeyedLoad(bool is_global);
442
425 // Special code for typeof expressions: Unfortunately, we must 443 // Special code for typeof expressions: Unfortunately, we must
426 // be careful when loading the expression in 'typeof' 444 // be careful when loading the expression in 'typeof'
427 // expressions. We are not allowed to throw reference errors for 445 // expressions. We are not allowed to throw reference errors for
428 // non-existing properties of the global object, so we must make it 446 // non-existing properties of the global object, so we must make it
429 // look like an explicit property access, instead of an access 447 // look like an explicit property access, instead of an access
430 // through the context chain. 448 // through the context chain.
431 void LoadTypeofExpression(Expression* x); 449 void LoadTypeofExpression(Expression* x);
432 450
433 // Translate the value on top of the frame into control flow to the 451 // Translate the value on top of the frame into control flow to the
434 // control destination. 452 // control destination.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 static const int kMaxSmiInlinedBits = 16; 489 static const int kMaxSmiInlinedBits = 16;
472 bool IsUnsafeSmi(Handle<Object> value); 490 bool IsUnsafeSmi(Handle<Object> value);
473 // Load an integer constant x into a register target using 491 // Load an integer constant x into a register target using
474 // at most 16 bits of user-controlled data per assembly operation. 492 // at most 16 bits of user-controlled data per assembly operation.
475 void LoadUnsafeSmi(Register target, Handle<Object> value); 493 void LoadUnsafeSmi(Register target, Handle<Object> value);
476 494
477 void CallWithArguments(ZoneList<Expression*>* arguments, 495 void CallWithArguments(ZoneList<Expression*>* arguments,
478 CallFunctionFlags flags, 496 CallFunctionFlags flags,
479 int position); 497 int position);
480 498
481 // Use an optimized version of Function.prototype.apply that avoid 499 // An optimized implementation of expressions of the form
482 // allocating the arguments object and just copies the arguments 500 // x.apply(y, arguments). We call x the applicand and y the receiver.
483 // from the stack. 501 // The optimization avoids allocating an arguments object if possible.
484 void CallApplyLazy(Property* apply, 502 void CallApplyLazy(Expression* applicand,
485 Expression* receiver, 503 Expression* receiver,
486 VariableProxy* arguments, 504 VariableProxy* arguments,
487 int position); 505 int position);
488 506
489 void CheckStack(); 507 void CheckStack();
490 508
491 struct InlineRuntimeLUT { 509 struct InlineRuntimeLUT {
492 void (CodeGenerator::*method)(ZoneList<Expression*>*); 510 void (CodeGenerator::*method)(ZoneList<Expression*>*);
493 const char* name; 511 const char* name;
494 }; 512 };
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 Major MajorKey() { return StringCompare; } 808 Major MajorKey() { return StringCompare; }
791 int MinorKey() { return 0; } 809 int MinorKey() { return 0; }
792 810
793 void Generate(MacroAssembler* masm); 811 void Generate(MacroAssembler* masm);
794 }; 812 };
795 813
796 814
797 } } // namespace v8::internal 815 } } // namespace v8::internal
798 816
799 #endif // V8_X64_CODEGEN_X64_H_ 817 #endif // V8_X64_CODEGEN_X64_H_
OLDNEW
« no previous file with comments | « src/ia32/codegen-ia32.cc ('k') | src/x64/codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698