OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. | 51 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. |
52 public: | 52 public: |
53 // Forward-only jump targets can only be reached by forward CFG edges. | 53 // Forward-only jump targets can only be reached by forward CFG edges. |
54 enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; | 54 enum Directionality { FORWARD_ONLY, BIDIRECTIONAL }; |
55 | 55 |
56 // Construct a jump target with a given code generator used to generate | 56 // Construct a jump target with a given code generator used to generate |
57 // code and to provide access to a current frame. | 57 // code and to provide access to a current frame. |
58 explicit JumpTarget(CodeGenerator* cgen, | 58 explicit JumpTarget(CodeGenerator* cgen, |
59 Directionality direction = FORWARD_ONLY); | 59 Directionality direction = FORWARD_ONLY); |
60 | 60 |
| 61 // Construct a jump target without a code generator. A code |
| 62 // generator must be supplied before using the jump target as a |
| 63 // label. This is useful, eg, when break targets are embedded in |
| 64 // AST nodes. |
| 65 JumpTarget(); |
| 66 |
| 67 // Supply a code generator and directionality to an already |
| 68 // constructed jump target. This function expects to be given a |
| 69 // non-null code generator, and to be called only when the code |
| 70 // generator is not yet set. |
| 71 virtual void Initialize(CodeGenerator* cgen, |
| 72 Directionality direction = FORWARD_ONLY); |
| 73 |
61 virtual ~JumpTarget() { Unuse(); } | 74 virtual ~JumpTarget() { Unuse(); } |
62 | 75 |
| 76 // Treat the jump target as a fresh one. The state is reset and |
| 77 // pointed-to virtual frames are deallocated. There should be no |
| 78 // dangling jumps to the target. |
| 79 void Unuse(); |
| 80 |
| 81 // Reset the internal state of this jump target. Pointed-to virtual |
| 82 // frames are not deallocated and dangling jumps to the target are |
| 83 // left dangling. |
| 84 void Reset(); |
| 85 |
63 // Accessors. | 86 // Accessors. |
64 CodeGenerator* code_generator() const { return cgen_; } | 87 CodeGenerator* code_generator() const { return cgen_; } |
65 | 88 |
66 Label* entry_label() { return &entry_label_; } | 89 Label* entry_label() { return &entry_label_; } |
67 | 90 |
68 VirtualFrame* entry_frame() const { return entry_frame_; } | 91 VirtualFrame* entry_frame() const { return entry_frame_; } |
69 void set_entry_frame(VirtualFrame* frame) { | 92 void set_entry_frame(VirtualFrame* frame) { |
70 entry_frame_ = frame; | 93 entry_frame_ = frame; |
71 } | 94 } |
72 | 95 |
73 void make_bidirectional() { direction_ = BIDIRECTIONAL; } | 96 void make_bidirectional() { direction_ = BIDIRECTIONAL; } |
74 | 97 |
75 // Predicates testing the state of the encapsulated label. | 98 // Predicates testing the state of the encapsulated label. |
76 bool is_bound() const { return is_bound_; } | 99 bool is_bound() const { return is_bound_; } |
77 bool is_linked() const { return is_linked_; } | 100 bool is_linked() const { return is_linked_; } |
78 bool is_unused() const { return !is_bound() && !is_linked(); } | 101 bool is_unused() const { return !is_bound() && !is_linked(); } |
79 | 102 |
80 // Treat the jump target as a fresh one. The expected frame if any | |
81 // will be deallocated and there should be no dangling jumps to the | |
82 // target (thus no reaching frames). | |
83 void Unuse(); | |
84 | |
85 // Reset the internal state of this jump target. Pointed-to virtual | |
86 // frames are not deallocated and dangling jumps to the target are | |
87 // left dangling. | |
88 void Reset(); | |
89 | |
90 // Emit a jump to the target. There must be a current frame at the | 103 // Emit a jump to the target. There must be a current frame at the |
91 // jump and there will be no current frame after the jump. | 104 // jump and there will be no current frame after the jump. |
92 void Jump(); | 105 virtual void Jump(); |
93 void Jump(Result* arg); | 106 void Jump(Result* arg); |
94 void Jump(Result* arg0, Result* arg1); | 107 void Jump(Result* arg0, Result* arg1); |
95 void Jump(Result* arg0, Result* arg1, Result* arg2); | 108 void Jump(Result* arg0, Result* arg1, Result* arg2); |
96 | 109 |
97 // Emit a conditional branch to the target. There must be a current | 110 // Emit a conditional branch to the target. There must be a current |
98 // frame at the branch. The current frame will fall through to the | 111 // frame at the branch. The current frame will fall through to the |
99 // code after the branch. | 112 // code after the branch. |
100 void Branch(Condition cc, Hint hint = no_hint); | 113 virtual void Branch(Condition cc, Hint hint = no_hint); |
101 void Branch(Condition cc, Result* arg, Hint hint = no_hint); | 114 void Branch(Condition cc, Result* arg, Hint hint = no_hint); |
102 void Branch(Condition cc, Result* arg0, Result* arg1, Hint hint = no_hint); | 115 void Branch(Condition cc, Result* arg0, Result* arg1, Hint hint = no_hint); |
103 void Branch(Condition cc, | 116 void Branch(Condition cc, |
104 Result* arg0, | 117 Result* arg0, |
105 Result* arg1, | 118 Result* arg1, |
106 Result* arg2, | 119 Result* arg2, |
107 Hint hint = no_hint); | 120 Hint hint = no_hint); |
108 void Branch(Condition cc, | 121 void Branch(Condition cc, |
109 Result* arg0, | 122 Result* arg0, |
110 Result* arg1, | 123 Result* arg1, |
111 Result* arg2, | 124 Result* arg2, |
112 Result* arg3, | 125 Result* arg3, |
113 Hint hint = no_hint); | 126 Hint hint = no_hint); |
114 | 127 |
115 // Bind a jump target. If there is no current frame at the binding | 128 // Bind a jump target. If there is no current frame at the binding |
116 // site, there must be at least one frame reaching via a forward | 129 // site, there must be at least one frame reaching via a forward |
117 // jump. | 130 // jump. |
118 // | 131 // |
119 // The number of mergable elements is a number of frame elements | 132 // The number of mergable elements is a number of frame elements |
120 // counting from the top down which must be "mergable" (not | 133 // counting from the top down which must be "mergable" (not |
121 // constants or copies) in the entry frame at the jump target. | 134 // constants or copies) in the entry frame at the jump target. |
122 // Backward jumps to the target must contain the same constants and | 135 // Backward jumps to the target must contain the same constants and |
123 // sharing as the entry frame, except for the mergable elements. | 136 // sharing as the entry frame, except for the mergable elements. |
124 // | 137 // |
125 // A mergable elements argument of kAllElements indicates that all | 138 // A mergable elements argument of kAllElements indicates that all |
126 // frame elements must be mergable. Mergable elements are ignored | 139 // frame elements must be mergable. Mergable elements are ignored |
127 // completely for forward-only jump targets. | 140 // completely for forward-only jump targets. |
128 void Bind(int mergable_elements = kAllElements); | 141 virtual void Bind(int mergable_elements = kAllElements); |
129 void Bind(Result* arg, int mergable_elements = kAllElements); | 142 void Bind(Result* arg, int mergable_elements = kAllElements); |
130 void Bind(Result* arg0, Result* arg1, int mergable_elements = kAllElements); | 143 void Bind(Result* arg0, Result* arg1, int mergable_elements = kAllElements); |
131 void Bind(Result* arg0, | 144 void Bind(Result* arg0, |
132 Result* arg1, | 145 Result* arg1, |
133 Result* arg2, | 146 Result* arg2, |
134 int mergable_elements = kAllElements); | 147 int mergable_elements = kAllElements); |
135 void Bind(Result* arg0, | 148 void Bind(Result* arg0, |
136 Result* arg1, | 149 Result* arg1, |
137 Result* arg2, | 150 Result* arg2, |
138 Result* arg3, | 151 Result* arg3, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // and will drop state from nested statements as part of merging. | 215 // and will drop state from nested statements as part of merging. |
203 // | 216 // |
204 // Break targets are used for return, break, and continue targets. | 217 // Break targets are used for return, break, and continue targets. |
205 | 218 |
206 class BreakTarget : public JumpTarget { | 219 class BreakTarget : public JumpTarget { |
207 public: | 220 public: |
208 // Construct a break target without a code generator. A code | 221 // Construct a break target without a code generator. A code |
209 // generator must be supplied before using the break target as a | 222 // generator must be supplied before using the break target as a |
210 // label. This is useful, eg, when break targets are embedded in AST | 223 // label. This is useful, eg, when break targets are embedded in AST |
211 // nodes. | 224 // nodes. |
212 BreakTarget(); | 225 BreakTarget() {} |
213 | 226 |
214 // Supply a code generator and directionality to an already | 227 // Supply a code generator, expected expression stack height, and |
215 // constructed jump target. This function expects to be given a | 228 // directionality to an already constructed break target. This |
216 // non-null code generator, and to be called only when the code | 229 // function expects to be given a non-null code generator, and to be |
217 // generator is not yet set. | 230 // called only when the code generator is not yet set. |
218 void Initialize(CodeGenerator* cgen, | 231 virtual void Initialize(CodeGenerator* cgen, |
219 Directionality direction = FORWARD_ONLY); | 232 Directionality direction = FORWARD_ONLY); |
220 | 233 |
221 // Copy the state of this break target to the destination. The | 234 // Copy the state of this break target to the destination. The |
222 // lists of forward-reaching frames and merge-point labels are | 235 // lists of forward-reaching frames and merge-point labels are |
223 // copied. All virtual frame pointers are copied, not the | 236 // copied. All virtual frame pointers are copied, not the |
224 // pointed-to frames. The previous state of the destination is | 237 // pointed-to frames. The previous state of the destination is |
225 // overwritten, without deallocating pointed-to virtual frames. | 238 // overwritten, without deallocating pointed-to virtual frames. |
226 void CopyTo(BreakTarget* destination); | 239 void CopyTo(BreakTarget* destination); |
227 | 240 |
| 241 // Emit a jump to the target. There must be a current frame at the |
| 242 // jump and there will be no current frame after the jump. |
| 243 virtual void Jump(); |
| 244 |
| 245 // Emit a conditional branch to the target. There must be a current |
| 246 // frame at the branch. The current frame will fall through to the |
| 247 // code after the branch. |
| 248 virtual void Branch(Condition cc, Hint hint = no_hint); |
| 249 |
| 250 // Bind a break target. If there is no current frame at the binding |
| 251 // site, there must be at least one frame reaching via a forward |
| 252 // jump. |
| 253 virtual void Bind(int mergable_elements = kAllElements); |
| 254 |
| 255 // Setter for expected height. |
| 256 void set_expected_height(int expected) { expected_height_ = expected; } |
| 257 |
228 private: | 258 private: |
| 259 // The expected height of the expression stack where the target will |
| 260 // be bound, statically known at initialization time. |
| 261 int expected_height_; |
| 262 |
229 DISALLOW_COPY_AND_ASSIGN(BreakTarget); | 263 DISALLOW_COPY_AND_ASSIGN(BreakTarget); |
230 }; | 264 }; |
231 | 265 |
232 | 266 |
233 // ------------------------------------------------------------------------- | 267 // ------------------------------------------------------------------------- |
234 // Shadow break targets | 268 // Shadow break targets |
235 // | 269 // |
236 // A shadow break target represents a break target that is temporarily | 270 // A shadow break target represents a break target that is temporarily |
237 // shadowed by another one (represented by the original during | 271 // shadowed by another one (represented by the original during |
238 // shadowing). They are used to catch jumps to labels in certain | 272 // shadowing). They are used to catch jumps to labels in certain |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 bool is_shadowing_; | 305 bool is_shadowing_; |
272 #endif | 306 #endif |
273 | 307 |
274 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); | 308 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); |
275 }; | 309 }; |
276 | 310 |
277 | 311 |
278 } } // namespace v8::internal | 312 } } // namespace v8::internal |
279 | 313 |
280 #endif // V8_JUMP_TARGET_H_ | 314 #endif // V8_JUMP_TARGET_H_ |
OLD | NEW |