OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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_COMPILER_CONTROL_BUILDERS_H_ | 5 #ifndef V8_COMPILER_CONTROL_BUILDERS_H_ |
6 #define V8_COMPILER_CONTROL_BUILDERS_H_ | 6 #define V8_COMPILER_CONTROL_BUILDERS_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/compiler/graph-builder.h" | 10 #include "src/compiler/graph-builder.h" |
11 #include "src/compiler/node.h" | 11 #include "src/compiler/node.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 namespace compiler { | 15 namespace compiler { |
16 | 16 |
17 // Base class for all control builders. Also provides a common interface for | 17 // Base class for all control builders. Also provides a common interface for |
18 // control builders to handle 'break' and 'continue' statements when they are | 18 // control builders to handle 'break' statements when they are used to model |
19 // used to model breakable statements. | 19 // breakable statements. |
20 class ControlBuilder { | 20 class ControlBuilder { |
21 public: | 21 public: |
22 explicit ControlBuilder(StructuredGraphBuilder* builder) | 22 explicit ControlBuilder(StructuredGraphBuilder* builder) |
23 : builder_(builder) {} | 23 : builder_(builder) {} |
24 virtual ~ControlBuilder() {} | 24 virtual ~ControlBuilder() {} |
25 | 25 |
26 // Interface for break and continue. | 26 // Interface for break. |
27 virtual void Break() { UNREACHABLE(); } | 27 virtual void Break() { UNREACHABLE(); } |
28 virtual void Continue() { UNREACHABLE(); } | |
29 | 28 |
30 protected: | 29 protected: |
31 typedef StructuredGraphBuilder Builder; | 30 typedef StructuredGraphBuilder Builder; |
32 typedef StructuredGraphBuilder::Environment Environment; | 31 typedef StructuredGraphBuilder::Environment Environment; |
33 | 32 |
34 Zone* zone() const { return builder_->local_zone(); } | 33 Zone* zone() const { return builder_->local_zone(); } |
35 Environment* environment() { return builder_->environment(); } | 34 Environment* environment() { return builder_->environment(); } |
36 void set_environment(Environment* env) { builder_->set_environment(env); } | 35 void set_environment(Environment* env) { builder_->set_environment(env); } |
37 | 36 |
38 Builder* builder_; | 37 Builder* builder_; |
(...skipping 24 matching lines...) Expand all Loading... |
63 class LoopBuilder FINAL : public ControlBuilder { | 62 class LoopBuilder FINAL : public ControlBuilder { |
64 public: | 63 public: |
65 explicit LoopBuilder(StructuredGraphBuilder* builder) | 64 explicit LoopBuilder(StructuredGraphBuilder* builder) |
66 : ControlBuilder(builder), | 65 : ControlBuilder(builder), |
67 loop_environment_(NULL), | 66 loop_environment_(NULL), |
68 continue_environment_(NULL), | 67 continue_environment_(NULL), |
69 break_environment_(NULL) {} | 68 break_environment_(NULL) {} |
70 | 69 |
71 // Primitive control commands. | 70 // Primitive control commands. |
72 void BeginLoop(BitVector* assigned, bool is_osr = false); | 71 void BeginLoop(BitVector* assigned, bool is_osr = false); |
| 72 void Continue(); |
73 void EndBody(); | 73 void EndBody(); |
74 void EndLoop(); | 74 void EndLoop(); |
75 | 75 |
76 // Primitive support for break and continue. | 76 // Primitive support for break. |
77 void Continue() FINAL; | |
78 void Break() FINAL; | 77 void Break() FINAL; |
79 | 78 |
80 // Compound control commands for conditional break. | 79 // Compound control commands for conditional break. |
81 void BreakUnless(Node* condition); | 80 void BreakUnless(Node* condition); |
82 void BreakWhen(Node* condition); | 81 void BreakWhen(Node* condition); |
83 | 82 |
84 private: | 83 private: |
85 Environment* loop_environment_; // Environment of the loop header. | 84 Environment* loop_environment_; // Environment of the loop header. |
86 Environment* continue_environment_; // Environment after the loop body. | 85 Environment* continue_environment_; // Environment after the loop body. |
87 Environment* break_environment_; // Environment after the loop exits. | 86 Environment* break_environment_; // Environment after the loop exits. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 void BeginBlock(); | 130 void BeginBlock(); |
132 void EndBlock(); | 131 void EndBlock(); |
133 | 132 |
134 // Primitive support for break. | 133 // Primitive support for break. |
135 void Break() FINAL; | 134 void Break() FINAL; |
136 | 135 |
137 private: | 136 private: |
138 Environment* break_environment_; // Environment after the block exits. | 137 Environment* break_environment_; // Environment after the block exits. |
139 }; | 138 }; |
140 | 139 |
| 140 |
| 141 // Tracks control flow for a try-catch statement. |
| 142 class TryCatchBuilder FINAL : public ControlBuilder { |
| 143 public: |
| 144 explicit TryCatchBuilder(StructuredGraphBuilder* builder) |
| 145 : ControlBuilder(builder), |
| 146 catch_environment_(NULL), |
| 147 exit_environment_(NULL), |
| 148 exception_node_(NULL) {} |
| 149 |
| 150 // Primitive control commands. |
| 151 void BeginTry(); |
| 152 void Throw(Node* exception); |
| 153 void EndTry(); |
| 154 void EndCatch(); |
| 155 |
| 156 // Returns the exception value inside the 'catch' body. |
| 157 Node* GetExceptionNode() const { return exception_node_; } |
| 158 |
| 159 private: |
| 160 Environment* catch_environment_; // Environment for the 'catch' body. |
| 161 Environment* exit_environment_; // Environment after the statement. |
| 162 Node* exception_node_; // Node for exception in 'catch' body. |
| 163 }; |
| 164 |
| 165 |
| 166 // Tracks control flow for a try-finally statement. |
| 167 class TryFinallyBuilder FINAL : public ControlBuilder { |
| 168 public: |
| 169 explicit TryFinallyBuilder(StructuredGraphBuilder* builder) |
| 170 : ControlBuilder(builder), |
| 171 finally_environment_(NULL), |
| 172 token_node_(NULL) {} |
| 173 |
| 174 // Primitive control commands. |
| 175 void BeginTry(); |
| 176 void LeaveTry(Node* token); |
| 177 void EndTry(Node* token); |
| 178 void EndFinally(); |
| 179 |
| 180 // Returns the dispatch token value inside the 'finally' body. |
| 181 Node* GetDispatchTokenNode() const { return token_node_; } |
| 182 |
| 183 private: |
| 184 Environment* finally_environment_; // Environment for the 'finally' body. |
| 185 Node* token_node_; // Node for token in 'finally' body. |
| 186 }; |
| 187 |
| 188 |
141 } // namespace compiler | 189 } // namespace compiler |
142 } // namespace internal | 190 } // namespace internal |
143 } // namespace v8 | 191 } // namespace v8 |
144 | 192 |
145 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ | 193 #endif // V8_COMPILER_CONTROL_BUILDERS_H_ |
OLD | NEW |