OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
| 6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
| 7 |
| 8 #include "src/interpreter/bytecode-array-builder.h" |
| 9 |
| 10 #include "src/zone-containers.h" |
| 11 |
| 12 namespace v8 { |
| 13 namespace internal { |
| 14 namespace interpreter { |
| 15 |
| 16 class ControlFlowBuilder BASE_EMBEDDED { |
| 17 public: |
| 18 explicit ControlFlowBuilder(BytecodeArrayBuilder* builder) |
| 19 : builder_(builder) {} |
| 20 virtual ~ControlFlowBuilder() {} |
| 21 |
| 22 protected: |
| 23 BytecodeArrayBuilder* builder() const { return builder_; } |
| 24 |
| 25 private: |
| 26 BytecodeArrayBuilder* builder_; |
| 27 |
| 28 DISALLOW_COPY_AND_ASSIGN(ControlFlowBuilder); |
| 29 }; |
| 30 |
| 31 // A class to help with co-ordinating break and continue statements with |
| 32 // their loop. |
| 33 // TODO(oth): add support for TF branch/merge info. |
| 34 class LoopBuilder : public ControlFlowBuilder { |
| 35 public: |
| 36 explicit LoopBuilder(BytecodeArrayBuilder* builder) |
| 37 : ControlFlowBuilder(builder), |
| 38 continue_sites_(builder->zone()), |
| 39 break_sites_(builder->zone()) {} |
| 40 ~LoopBuilder(); |
| 41 |
| 42 // These methods should be called by the LoopBuilder owner before |
| 43 // destruction to update sites that emit jumps for break/continue. |
| 44 void SetContinueTarget(const BytecodeLabel& continue_target); |
| 45 void SetBreakTarget(const BytecodeLabel& break_target); |
| 46 |
| 47 // These methods are called when visiting break and continue |
| 48 // statements in the AST. Inserts a jump to a unbound label that is |
| 49 // patched when the corresponding SetContinueTarget/SetBreakTarget |
| 50 // is called. |
| 51 void Break() { EmitJump(&break_sites_); } |
| 52 void Continue() { EmitJump(&continue_sites_); } |
| 53 |
| 54 private: |
| 55 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site); |
| 56 void EmitJump(ZoneVector<BytecodeLabel>* labels); |
| 57 |
| 58 // Unbound labels that identify jumps for continue/break statements |
| 59 // in the code. |
| 60 ZoneVector<BytecodeLabel> continue_sites_; |
| 61 ZoneVector<BytecodeLabel> break_sites_; |
| 62 }; |
| 63 |
| 64 } // namespace interpreter |
| 65 } // namespace internal |
| 66 } // namespace v8 |
| 67 |
| 68 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
OLD | NEW |