OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ | 5 #ifndef VM_FLOW_GRAPH_BUILDER_H_ |
6 #define VM_FLOW_GRAPH_BUILDER_H_ | 6 #define VM_FLOW_GRAPH_BUILDER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/ast.h" | 9 #include "vm/ast.h" |
10 #include "vm/growable_array.h" | 10 #include "vm/growable_array.h" |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // TargetEntryInstr*. | 268 // TargetEntryInstr*. |
269 // | 269 // |
270 // To distinguish between the graphs with only nonlocal exits and graphs | 270 // To distinguish between the graphs with only nonlocal exits and graphs |
271 // with both true and false exits, there are a pair of TargetEntryInstr**: | 271 // with both true and false exits, there are a pair of TargetEntryInstr**: |
272 // | 272 // |
273 // - Both NULL: only non-local exits, truly closed | 273 // - Both NULL: only non-local exits, truly closed |
274 // - Neither NULL: true and false successors at the given addresses | 274 // - Neither NULL: true and false successors at the given addresses |
275 // | 275 // |
276 // We expect that AstNode in test contexts either have only nonlocal exits | 276 // We expect that AstNode in test contexts either have only nonlocal exits |
277 // or else control flow has both true and false successors. | 277 // or else control flow has both true and false successors. |
| 278 // |
| 279 // The node_id and token_index are used in checked mode to verify that the |
| 280 // condition of the test is of type bool. |
278 class TestGraphVisitor : public ValueGraphVisitor { | 281 class TestGraphVisitor : public ValueGraphVisitor { |
279 public: | 282 public: |
280 TestGraphVisitor(FlowGraphBuilder* owner, intptr_t temp_index) | 283 TestGraphVisitor(FlowGraphBuilder* owner, |
| 284 intptr_t temp_index, |
| 285 intptr_t condition_node_id, |
| 286 intptr_t condition_token_index) |
281 : ValueGraphVisitor(owner, temp_index), | 287 : ValueGraphVisitor(owner, temp_index), |
282 true_successor_address_(NULL), | 288 true_successor_address_(NULL), |
283 false_successor_address_(NULL) { | 289 false_successor_address_(NULL), |
| 290 condition_node_id_(condition_node_id), |
| 291 condition_token_index_(condition_token_index) { |
284 } | 292 } |
285 | 293 |
286 // Visit functions overridden by this class. | 294 // Visit functions overridden by this class. |
287 virtual void VisitLiteralNode(LiteralNode* node); | 295 virtual void VisitLiteralNode(LiteralNode* node); |
288 virtual void VisitLoadLocalNode(LoadLocalNode* node); | 296 virtual void VisitLoadLocalNode(LoadLocalNode* node); |
289 | 297 |
290 TargetEntryInstr** true_successor_address() const { | 298 TargetEntryInstr** true_successor_address() const { |
291 ASSERT(true_successor_address_ != NULL); | 299 ASSERT(true_successor_address_ != NULL); |
292 return true_successor_address_; | 300 return true_successor_address_; |
293 } | 301 } |
294 TargetEntryInstr** false_successor_address() const { | 302 TargetEntryInstr** false_successor_address() const { |
295 ASSERT(false_successor_address_ != NULL); | 303 ASSERT(false_successor_address_ != NULL); |
296 return false_successor_address_; | 304 return false_successor_address_; |
297 } | 305 } |
298 | 306 |
| 307 intptr_t condition_node_id() const { return condition_node_id_; } |
| 308 intptr_t condition_token_index() const { return condition_token_index_; } |
| 309 |
299 private: | 310 private: |
300 // Construct and concatenate a Branch instruction to this graph fragment. | 311 // Construct and concatenate a Branch instruction to this graph fragment. |
301 // Closes the fragment and sets the output parameters. | 312 // Closes the fragment and sets the output parameters. |
302 virtual void ReturnValue(Value* value); | 313 virtual void ReturnValue(Value* value); |
303 | 314 |
304 // Specify a computation as the final result. Adds a Bind instruction to | 315 // Specify a computation as the final result. Adds a Bind instruction to |
305 // the graph and branches on its value. | 316 // the graph and branches on its value. |
306 virtual void ReturnComputation(Computation* computation) { | 317 virtual void ReturnComputation(Computation* computation) { |
307 AddInstruction(new BindInstr(temp_index(), computation)); | 318 AddInstruction(new BindInstr(temp_index(), computation)); |
308 ReturnValue(new TempVal(temp_index())); | 319 ReturnValue(new TempVal(temp_index())); |
309 } | 320 } |
310 | 321 |
311 // Output parameters. | 322 // Output parameters. |
312 TargetEntryInstr** true_successor_address_; | 323 TargetEntryInstr** true_successor_address_; |
313 TargetEntryInstr** false_successor_address_; | 324 TargetEntryInstr** false_successor_address_; |
| 325 |
| 326 intptr_t condition_node_id_; |
| 327 intptr_t condition_token_index_; |
314 }; | 328 }; |
315 | 329 |
316 } // namespace dart | 330 } // namespace dart |
317 | 331 |
318 #endif // VM_FLOW_GRAPH_BUILDER_H_ | 332 #endif // VM_FLOW_GRAPH_BUILDER_H_ |
OLD | NEW |