OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ | 5 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ | 6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
7 | 7 |
8 #include "src/interpreter/bytecode-array-builder.h" | 8 #include "src/interpreter/bytecode-array-builder.h" |
9 | 9 |
10 #include "src/interpreter/bytecode-label.h" | 10 #include "src/interpreter/bytecode-label.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 private: | 26 private: |
27 BytecodeArrayBuilder* builder_; | 27 BytecodeArrayBuilder* builder_; |
28 | 28 |
29 DISALLOW_COPY_AND_ASSIGN(ControlFlowBuilder); | 29 DISALLOW_COPY_AND_ASSIGN(ControlFlowBuilder); |
30 }; | 30 }; |
31 | 31 |
32 class BreakableControlFlowBuilder : public ControlFlowBuilder { | 32 class BreakableControlFlowBuilder : public ControlFlowBuilder { |
33 public: | 33 public: |
34 explicit BreakableControlFlowBuilder(BytecodeArrayBuilder* builder) | 34 explicit BreakableControlFlowBuilder(BytecodeArrayBuilder* builder) |
35 : ControlFlowBuilder(builder), | 35 : ControlFlowBuilder(builder), break_labels_(builder->zone()) {} |
36 break_sites_(builder->zone()) {} | |
37 virtual ~BreakableControlFlowBuilder(); | 36 virtual ~BreakableControlFlowBuilder(); |
38 | 37 |
39 // This method should be called by the control flow owner before | 38 // This method should be called by the control flow owner before |
40 // destruction to update sites that emit jumps for break. | 39 // destruction to update sites that emit jumps for break. |
41 void SetBreakTarget(const BytecodeLabel& break_target); | 40 void BindBreakTarget(); |
42 | 41 |
43 // This method is called when visiting break statements in the AST. | 42 // This method is called when visiting break statements in the AST. |
44 // Inserts a jump to a unbound label that is patched when the corresponding | 43 // Inserts a jump to an unbound label that is patched when the corresponding |
45 // SetBreakTarget is called. | 44 // BindBreakTarget is called. |
46 void Break() { EmitJump(&break_sites_); } | 45 void Break() { EmitJump(&break_labels_); } |
47 void BreakIfTrue() { EmitJumpIfTrue(&break_sites_); } | 46 void BreakIfTrue() { EmitJumpIfTrue(&break_labels_); } |
48 void BreakIfFalse() { EmitJumpIfFalse(&break_sites_); } | 47 void BreakIfFalse() { EmitJumpIfFalse(&break_labels_); } |
49 void BreakIfUndefined() { EmitJumpIfUndefined(&break_sites_); } | 48 void BreakIfUndefined() { EmitJumpIfUndefined(&break_labels_); } |
50 void BreakIfNull() { EmitJumpIfNull(&break_sites_); } | 49 void BreakIfNull() { EmitJumpIfNull(&break_labels_); } |
50 | |
51 BytecodeLabels* break_labels() { return &break_labels_; } | |
51 | 52 |
52 protected: | 53 protected: |
53 void EmitJump(ZoneVector<BytecodeLabel>* labels); | 54 void EmitJump(BytecodeLabels* labels); |
54 void EmitJump(ZoneVector<BytecodeLabel>* labels, int index); | 55 void EmitJumpIfTrue(BytecodeLabels* labels); |
55 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels); | 56 void EmitJumpIfFalse(BytecodeLabels* labels); |
56 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels, int index); | 57 void EmitJumpIfUndefined(BytecodeLabels* labels); |
57 void EmitJumpIfFalse(ZoneVector<BytecodeLabel>* labels); | 58 void EmitJumpIfNull(BytecodeLabels* labels); |
58 void EmitJumpIfFalse(ZoneVector<BytecodeLabel>* labels, int index); | |
59 void EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* labels); | |
60 void EmitJumpIfNull(ZoneVector<BytecodeLabel>* labels); | |
61 | |
62 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site); | |
63 | 59 |
64 // Unbound labels that identify jumps for break statements in the code. | 60 // Unbound labels that identify jumps for break statements in the code. |
65 ZoneVector<BytecodeLabel> break_sites_; | 61 BytecodeLabels break_labels_; |
66 }; | 62 }; |
67 | 63 |
68 | 64 |
69 // Class to track control flow for block statements (which can break in JS). | 65 // Class to track control flow for block statements (which can break in JS). |
70 class BlockBuilder final : public BreakableControlFlowBuilder { | 66 class BlockBuilder final : public BreakableControlFlowBuilder { |
71 public: | 67 public: |
72 explicit BlockBuilder(BytecodeArrayBuilder* builder) | 68 explicit BlockBuilder(BytecodeArrayBuilder* builder) |
73 : BreakableControlFlowBuilder(builder) {} | 69 : BreakableControlFlowBuilder(builder) {} |
74 | 70 |
75 void EndBlock(); | 71 void EndBlock(); |
76 | 72 |
77 private: | 73 private: |
78 BytecodeLabel block_end_; | 74 BytecodeLabel block_end_; |
79 }; | 75 }; |
80 | 76 |
81 | 77 |
82 // A class to help with co-ordinating break and continue statements with | 78 // A class to help with co-ordinating break and continue statements with |
83 // their loop. | 79 // their loop. |
84 class LoopBuilder final : public BreakableControlFlowBuilder { | 80 class LoopBuilder final : public BreakableControlFlowBuilder { |
85 public: | 81 public: |
86 explicit LoopBuilder(BytecodeArrayBuilder* builder) | 82 explicit LoopBuilder(BytecodeArrayBuilder* builder) |
87 : BreakableControlFlowBuilder(builder), | 83 : BreakableControlFlowBuilder(builder), |
88 continue_sites_(builder->zone()) {} | 84 continue_labels_(builder->zone()), |
85 header_labels_(builder->zone()) {} | |
89 ~LoopBuilder(); | 86 ~LoopBuilder(); |
90 | 87 |
91 void LoopHeader(ZoneVector<BytecodeLabel>* additional_labels); | 88 void LoopHeader(ZoneVector<BytecodeLabel>* additional_labels); |
92 void JumpToHeader(); | 89 void JumpToHeader(); |
93 void JumpToHeaderIfTrue(); | 90 void JumpToHeaderIfTrue(); |
94 void SetContinueTarget(); | 91 void BindContinueTarget(); |
95 void EndLoop(); | 92 void EndLoop(); |
96 | 93 |
97 // This method is called when visiting continue statements in the AST. | 94 // This method is called when visiting continue statements in the AST. |
98 // Inserts a jump to an unbound label that is patched when SetContinueTarget | 95 // Inserts a jump to an unbound label that is patched when BindContinueTarget |
99 // is called. | 96 // is called. |
100 void Continue() { EmitJump(&continue_sites_); } | 97 void Continue() { EmitJump(&continue_labels_); } |
101 void ContinueIfTrue() { EmitJumpIfTrue(&continue_sites_); } | 98 void ContinueIfTrue() { EmitJumpIfTrue(&continue_labels_); } |
102 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_sites_); } | 99 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_labels_); } |
103 void ContinueIfNull() { EmitJumpIfNull(&continue_sites_); } | 100 void ContinueIfNull() { EmitJumpIfNull(&continue_labels_); } |
101 | |
102 BytecodeLabels* header_labels() { return &header_labels_; } | |
103 BytecodeLabels* continue_labels() { return &continue_labels_; } | |
104 | 104 |
105 private: | 105 private: |
106 BytecodeLabel loop_header_; | 106 BytecodeLabel loop_header_; |
107 BytecodeLabel loop_end_; | |
108 | 107 |
109 // Unbound labels that identify jumps for continue statements in the code. | 108 // Unbound labels that identify jumps for continue statements in the code. |
rmcilroy
2016/08/17 16:20:43
update comment to mention header labels.
klaasb
2016/08/18 11:40:00
Done.
| |
110 ZoneVector<BytecodeLabel> continue_sites_; | 109 BytecodeLabels continue_labels_; |
110 BytecodeLabels header_labels_; | |
111 }; | 111 }; |
112 | 112 |
113 | 113 |
114 // A class to help with co-ordinating break statements with their switch. | 114 // A class to help with co-ordinating break statements with their switch. |
115 class SwitchBuilder final : public BreakableControlFlowBuilder { | 115 class SwitchBuilder final : public BreakableControlFlowBuilder { |
116 public: | 116 public: |
117 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases) | 117 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases) |
118 : BreakableControlFlowBuilder(builder), | 118 : BreakableControlFlowBuilder(builder), |
119 case_sites_(builder->zone()) { | 119 case_sites_(builder->zone()) { |
120 case_sites_.resize(number_of_cases); | 120 case_sites_.resize(number_of_cases); |
121 } | 121 } |
122 ~SwitchBuilder(); | 122 ~SwitchBuilder(); |
123 | 123 |
124 // This method should be called by the SwitchBuilder owner when the case | 124 // This method should be called by the SwitchBuilder owner when the case |
125 // statement with |index| is emitted to update the case jump site. | 125 // statement with |index| is emitted to update the case jump site. |
126 void SetCaseTarget(int index); | 126 void SetCaseTarget(int index); |
127 | 127 |
128 // This method is called when visiting case comparison operation for |index|. | 128 // This method is called when visiting case comparison operation for |index|. |
129 // Inserts a JumpIfTrue to a unbound label that is patched when the | 129 // Inserts a JumpIfTrue to a unbound label that is patched when the |
130 // corresponding SetCaseTarget is called. | 130 // corresponding SetCaseTarget is called. |
131 void Case(int index) { EmitJumpIfTrue(&case_sites_, index); } | 131 void Case(int index) { builder()->JumpIfTrue(&case_sites_.at(index)); } |
132 | 132 |
133 // This method is called when all cases comparisons have been emitted if there | 133 // This method is called when all cases comparisons have been emitted if there |
134 // is a default case statement. Inserts a Jump to a unbound label that is | 134 // is a default case statement. Inserts a Jump to a unbound label that is |
135 // patched when the corresponding SetCaseTarget is called. | 135 // patched when the corresponding SetCaseTarget is called. |
136 void DefaultAt(int index) { EmitJump(&case_sites_, index); } | 136 void DefaultAt(int index) { builder()->Jump(&case_sites_.at(index)); } |
137 | 137 |
138 private: | 138 private: |
139 // Unbound labels that identify jumps for case statements in the code. | 139 // Unbound labels that identify jumps for case statements in the code. |
140 ZoneVector<BytecodeLabel> case_sites_; | 140 ZoneVector<BytecodeLabel> case_sites_; |
141 }; | 141 }; |
142 | 142 |
143 | 143 |
144 // A class to help with co-ordinating control flow in try-catch statements. | 144 // A class to help with co-ordinating control flow in try-catch statements. |
145 class TryCatchBuilder final : public ControlFlowBuilder { | 145 class TryCatchBuilder final : public ControlFlowBuilder { |
146 public: | 146 public: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 void BeginHandler(); | 178 void BeginHandler(); |
179 void BeginFinally(); | 179 void BeginFinally(); |
180 void EndFinally(); | 180 void EndFinally(); |
181 | 181 |
182 private: | 182 private: |
183 int handler_id_; | 183 int handler_id_; |
184 HandlerTable::CatchPrediction catch_prediction_; | 184 HandlerTable::CatchPrediction catch_prediction_; |
185 BytecodeLabel handler_; | 185 BytecodeLabel handler_; |
186 | 186 |
187 // Unbound labels that identify jumps to the finally block in the code. | 187 // Unbound labels that identify jumps to the finally block in the code. |
188 ZoneVector<BytecodeLabel> finalization_sites_; | 188 BytecodeLabels finalization_sites_; |
189 }; | 189 }; |
190 | 190 |
191 } // namespace interpreter | 191 } // namespace interpreter |
192 } // namespace internal | 192 } // namespace internal |
193 } // namespace v8 | 193 } // namespace v8 |
194 | 194 |
195 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ | 195 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ |
OLD | NEW |