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 17 matching lines...) Expand all Loading... |
28 #ifndef V8_JUMP_TARGET_H_ | 28 #ifndef V8_JUMP_TARGET_H_ |
29 #define V8_JUMP_TARGET_H_ | 29 #define V8_JUMP_TARGET_H_ |
30 | 30 |
31 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
32 | 32 |
33 // Forward declarations. | 33 // Forward declarations. |
34 class FrameElement; | 34 class FrameElement; |
35 class Result; | 35 class Result; |
36 class VirtualFrame; | 36 class VirtualFrame; |
37 | 37 |
38 | |
39 // ------------------------------------------------------------------------- | 38 // ------------------------------------------------------------------------- |
40 // Jump targets | 39 // Jump targets |
41 // | 40 // |
42 // A jump target is an abstraction of a basic-block entry in generated | 41 // A jump target is an abstraction of a basic-block entry in generated |
43 // code. It collects all the virtual frames reaching the block by | 42 // code. It collects all the virtual frames reaching the block by |
44 // forward jumps and pairs them with labels for the merge code along | 43 // forward jumps and pairs them with labels for the merge code along |
45 // all forward-reaching paths. When bound, an expected frame for the | 44 // all forward-reaching paths. When bound, an expected frame for the |
46 // block is determined and code is generated to merge to the expected | 45 // block is determined and code is generated to merge to the expected |
47 // frame. For backward jumps, the merge code is generated at the edge | 46 // frame. For backward jumps, the merge code is generated at the edge |
48 // leaving the predecessor block. | 47 // leaving the predecessor block. |
(...skipping 12 matching lines...) Expand all Loading... |
61 // code and to provide access to a current frame. | 60 // code and to provide access to a current frame. |
62 explicit JumpTarget(CodeGenerator* cgen, | 61 explicit JumpTarget(CodeGenerator* cgen, |
63 Directionality direction = FORWARD_ONLY); | 62 Directionality direction = FORWARD_ONLY); |
64 | 63 |
65 // Construct a jump target without a code generator. A code | 64 // Construct a jump target without a code generator. A code |
66 // generator must be supplied before using the jump target as a | 65 // generator must be supplied before using the jump target as a |
67 // label. This is useful, eg, when break targets are embedded in | 66 // label. This is useful, eg, when break targets are embedded in |
68 // AST nodes. | 67 // AST nodes. |
69 JumpTarget(); | 68 JumpTarget(); |
70 | 69 |
| 70 virtual ~JumpTarget() {} |
| 71 |
71 // Supply a code generator and directionality to an already | 72 // Supply a code generator and directionality to an already |
72 // constructed jump target. This function expects to be given a | 73 // constructed jump target. This function expects to be given a |
73 // non-null code generator, and to be called only when the code | 74 // non-null code generator, and to be called only when the code |
74 // generator is not yet set. | 75 // generator is not yet set. |
75 virtual void Initialize(CodeGenerator* cgen, | 76 virtual void Initialize(CodeGenerator* cgen, |
76 Directionality direction = FORWARD_ONLY); | 77 Directionality direction = FORWARD_ONLY); |
77 | 78 |
78 // Treat the jump target as a fresh one. The state is reset. | 79 // Treat the jump target as a fresh one. The state is reset. |
79 void Unuse(); | 80 void Unuse(); |
80 | 81 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 void DoBranch(Condition cc, Hint hint); | 193 void DoBranch(Condition cc, Hint hint); |
193 void DoBind(int mergable_elements); | 194 void DoBind(int mergable_elements); |
194 | 195 |
195 private: | 196 private: |
196 static bool compiling_deferred_code_; | 197 static bool compiling_deferred_code_; |
197 | 198 |
198 // Add a virtual frame reaching this labeled block via a forward jump, | 199 // Add a virtual frame reaching this labeled block via a forward jump, |
199 // and a corresponding merge code label. | 200 // and a corresponding merge code label. |
200 void AddReachingFrame(VirtualFrame* frame); | 201 void AddReachingFrame(VirtualFrame* frame); |
201 | 202 |
202 // Compute a frame to use for entry to this block. Mergable elements | 203 // Perform initialization required during entry frame computation |
203 // is as described for the Bind function. | 204 // after setting the virtual frame element at index in frame to be |
| 205 // target. |
| 206 inline void InitializeEntryElement(int index, FrameElement* target); |
| 207 |
| 208 // Compute a frame to use for entry to this block. Mergable |
| 209 // elements is as described for the Bind function. |
204 void ComputeEntryFrame(int mergable_elements); | 210 void ComputeEntryFrame(int mergable_elements); |
205 | 211 |
206 DISALLOW_COPY_AND_ASSIGN(JumpTarget); | 212 DISALLOW_COPY_AND_ASSIGN(JumpTarget); |
207 }; | 213 }; |
208 | 214 |
209 | 215 |
210 // ------------------------------------------------------------------------- | 216 // ------------------------------------------------------------------------- |
211 // Break targets | 217 // Break targets |
212 // | 218 // |
213 // A break target is a jump target that can be used to break out of a | 219 // A break target is a jump target that can be used to break out of a |
214 // statement that keeps extra state on the stack (eg, for/in or | 220 // statement that keeps extra state on the stack (eg, for/in or |
215 // try/finally). They know the expected stack height at the target | 221 // try/finally). They know the expected stack height at the target |
216 // and will drop state from nested statements as part of merging. | 222 // and will drop state from nested statements as part of merging. |
217 // | 223 // |
218 // Break targets are used for return, break, and continue targets. | 224 // Break targets are used for return, break, and continue targets. |
219 | 225 |
220 class BreakTarget : public JumpTarget { | 226 class BreakTarget : public JumpTarget { |
221 public: | 227 public: |
222 // Construct a break target without a code generator. A code | 228 // Construct a break target without a code generator. A code |
223 // generator must be supplied before using the break target as a | 229 // generator must be supplied before using the break target as a |
224 // label. This is useful, eg, when break targets are embedded in AST | 230 // label. This is useful, eg, when break targets are embedded in AST |
225 // nodes. | 231 // nodes. |
226 BreakTarget() {} | 232 BreakTarget() {} |
227 | 233 |
| 234 virtual ~BreakTarget() {} |
| 235 |
228 // Supply a code generator, expected expression stack height, and | 236 // Supply a code generator, expected expression stack height, and |
229 // directionality to an already constructed break target. This | 237 // directionality to an already constructed break target. This |
230 // function expects to be given a non-null code generator, and to be | 238 // function expects to be given a non-null code generator, and to be |
231 // called only when the code generator is not yet set. | 239 // called only when the code generator is not yet set. |
232 virtual void Initialize(CodeGenerator* cgen, | 240 virtual void Initialize(CodeGenerator* cgen, |
233 Directionality direction = FORWARD_ONLY); | 241 Directionality direction = FORWARD_ONLY); |
234 | 242 |
235 // Copy the state of this break target to the destination. The | 243 // Copy the state of this break target to the destination. The |
236 // lists of forward-reaching frames and merge-point labels are | 244 // lists of forward-reaching frames and merge-point labels are |
237 // copied. All virtual frame pointers are copied, not the | 245 // copied. All virtual frame pointers are copied, not the |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 // representing the formerly shadowing target. | 288 // representing the formerly shadowing target. |
281 | 289 |
282 class ShadowTarget : public BreakTarget { | 290 class ShadowTarget : public BreakTarget { |
283 public: | 291 public: |
284 // Construct a shadow jump target. After construction the shadow | 292 // Construct a shadow jump target. After construction the shadow |
285 // target object holds the state of the original target, and the | 293 // target object holds the state of the original target, and the |
286 // original target is actually a fresh one that intercepts control | 294 // original target is actually a fresh one that intercepts control |
287 // flow intended for the shadowed one. | 295 // flow intended for the shadowed one. |
288 explicit ShadowTarget(BreakTarget* shadowed); | 296 explicit ShadowTarget(BreakTarget* shadowed); |
289 | 297 |
| 298 virtual ~ShadowTarget() {} |
| 299 |
290 // End shadowing. After shadowing ends, the original jump target | 300 // End shadowing. After shadowing ends, the original jump target |
291 // again gives access to the formerly shadowed target and the shadow | 301 // again gives access to the formerly shadowed target and the shadow |
292 // target object gives access to the formerly shadowing target. | 302 // target object gives access to the formerly shadowing target. |
293 void StopShadowing(); | 303 void StopShadowing(); |
294 | 304 |
295 // During shadowing, the currently shadowing target. After | 305 // During shadowing, the currently shadowing target. After |
296 // shadowing, the target that was shadowed. | 306 // shadowing, the target that was shadowed. |
297 BreakTarget* other_target() const { return other_target_; } | 307 BreakTarget* other_target() const { return other_target_; } |
298 | 308 |
299 private: | 309 private: |
300 // During shadowing, the currently shadowing target. After | 310 // During shadowing, the currently shadowing target. After |
301 // shadowing, the target that was shadowed. | 311 // shadowing, the target that was shadowed. |
302 BreakTarget* other_target_; | 312 BreakTarget* other_target_; |
303 | 313 |
304 #ifdef DEBUG | 314 #ifdef DEBUG |
305 bool is_shadowing_; | 315 bool is_shadowing_; |
306 #endif | 316 #endif |
307 | 317 |
308 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); | 318 DISALLOW_COPY_AND_ASSIGN(ShadowTarget); |
309 }; | 319 }; |
310 | 320 |
311 | 321 |
312 } } // namespace v8::internal | 322 } } // namespace v8::internal |
313 | 323 |
314 #endif // V8_JUMP_TARGET_H_ | 324 #endif // V8_JUMP_TARGET_H_ |
OLD | NEW |