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

Side by Side Diff: src/arm/codegen-arm.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 | « no previous file | src/arm/codegen-arm.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 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
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 // Generate code to push the value of a reference on top of the expression 92 // Generate code to pop a reference, push the value of the reference,
83 // stack and then spill the stack frame. This function is used temporarily 93 // and then spill the stack frame.
84 // while the code generator is being transformed.
85 inline void GetValueAndSpill(); 94 inline void GetValueAndSpill();
86 95
87 // Generate code to store the value on top of the expression stack in the 96 // 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 97 // 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 98 // on the expression stack. The value is stored in the location specified
90 // reference intact below it) to support chained assignments. 99 // by the reference, and is left on top of the stack, after the reference
100 // is popped from beneath it (unloaded).
91 void SetValue(InitState init_state); 101 void SetValue(InitState init_state);
92 102
93 private: 103 private:
94 CodeGenerator* cgen_; 104 CodeGenerator* cgen_;
95 Expression* expression_; 105 Expression* expression_;
96 Type type_; 106 Type type_;
107 // Keep the reference on the stack after get, so it can be used by set later.
108 bool persist_after_get_;
97 }; 109 };
98 110
99 111
100 // ------------------------------------------------------------------------- 112 // -------------------------------------------------------------------------
101 // Code generation state 113 // Code generation state
102 114
103 // The state is passed down the AST by the code generator (and back up, in 115 // The state is passed down the AST by the code generator (and back up, in
104 // the form of the state of the label pair). It is threaded through the 116 // the form of the state of the label pair). It is threaded through the
105 // call stack. Constructing a state implicitly pushes it on the owning code 117 // call stack. Constructing a state implicitly pushes it on the owning code
106 // generator's stack of states, and destroying one implicitly pops it. 118 // generator's stack of states, and destroying one implicitly pops it.
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // unconditional jumps to the control targets). 279 // unconditional jumps to the control targets).
268 inline void LoadConditionAndSpill(Expression* expression, 280 inline void LoadConditionAndSpill(Expression* expression,
269 JumpTarget* true_target, 281 JumpTarget* true_target,
270 JumpTarget* false_target, 282 JumpTarget* false_target,
271 bool force_control); 283 bool force_control);
272 284
273 // Read a value from a slot and leave it on top of the expression stack. 285 // Read a value from a slot and leave it on top of the expression stack.
274 void LoadFromSlot(Slot* slot, TypeofState typeof_state); 286 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
275 // Store the value on top of the stack to a slot. 287 // Store the value on top of the stack to a slot.
276 void StoreToSlot(Slot* slot, InitState init_state); 288 void StoreToSlot(Slot* slot, InitState init_state);
289 // Load a keyed property, leaving it in r0. The receiver and key are
290 // passed on the stack, and remain there.
291 void EmitKeyedLoad(bool is_global);
277 292
278 void LoadFromGlobalSlotCheckExtensions(Slot* slot, 293 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
279 TypeofState typeof_state, 294 TypeofState typeof_state,
280 Register tmp, 295 Register tmp,
281 Register tmp2, 296 Register tmp2,
282 JumpTarget* slow); 297 JumpTarget* slow);
283 298
284 // Special code for typeof expressions: Unfortunately, we must 299 // Special code for typeof expressions: Unfortunately, we must
285 // be careful when loading the expression in 'typeof' 300 // be careful when loading the expression in 'typeof'
286 // expressions. We are not allowed to throw reference errors for 301 // expressions. We are not allowed to throw reference errors for
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 Major MajorKey() { return StringCompare; } 545 Major MajorKey() { return StringCompare; }
531 int MinorKey() { return 0; } 546 int MinorKey() { return 0; }
532 547
533 void Generate(MacroAssembler* masm); 548 void Generate(MacroAssembler* masm);
534 }; 549 };
535 550
536 551
537 } } // namespace v8::internal 552 } } // namespace v8::internal
538 553
539 #endif // V8_ARM_CODEGEN_ARM_H_ 554 #endif // V8_ARM_CODEGEN_ARM_H_
OLDNEW
« no previous file with comments | « no previous file | src/arm/codegen-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698