| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import '../elements/elements.dart'; | 5 import '../elements/elements.dart'; |
| 6 import '../types/types.dart'; | 6 import '../types/types.dart'; |
| 7 import 'nodes.dart'; | 7 import 'nodes.dart'; |
| 8 | 8 |
| 9 /// Base class for objects that build up an SSA graph. | 9 /// Base class for objects that build up an SSA graph. |
| 10 /// | 10 /// |
| 11 /// This contains helpers for building the graph and tracking information about | 11 /// This contains helpers for building the graph and tracking information about |
| 12 /// the current state of the graph being built. | 12 /// the current state of the graph being built. |
| 13 abstract class GraphBuilder { | 13 abstract class GraphBuilder { |
| 14 /// Holds the resulting SSA graph. | 14 /// Holds the resulting SSA graph. |
| 15 final HGraph graph = new HGraph(); | 15 final HGraph graph = new HGraph(); |
| 16 | 16 |
| 17 /// A stack of instructions. |
| 18 /// |
| 19 /// We build the SSA graph by simulating a stack machine. |
| 20 List<HInstruction> stack = <HInstruction>[]; |
| 21 |
| 22 |
| 23 void push(HInstruction instruction) { |
| 24 add(instruction); |
| 25 stack.add(instruction); |
| 26 } |
| 27 |
| 28 HInstruction pop() { |
| 29 return stack.removeLast(); |
| 30 } |
| 31 |
| 32 void dup() { |
| 33 stack.add(stack.last); |
| 34 } |
| 35 |
| 17 HBasicBlock _current; | 36 HBasicBlock _current; |
| 18 | 37 |
| 19 /// The current block to add instructions to. Might be null, if we are | 38 /// The current block to add instructions to. Might be null, if we are |
| 20 /// visiting dead code, but see [isReachable]. | 39 /// visiting dead code, but see [isReachable]. |
| 21 HBasicBlock get current => _current; | 40 HBasicBlock get current => _current; |
| 22 | 41 |
| 23 void set current(c) { | 42 void set current(c) { |
| 24 isReachable = c != null; | 43 isReachable = c != null; |
| 25 _current = c; | 44 _current = c; |
| 26 } | 45 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 HParameterValue result = new HParameterValue(parameter, type); | 115 HParameterValue result = new HParameterValue(parameter, type); |
| 97 if (lastAddedParameter == null) { | 116 if (lastAddedParameter == null) { |
| 98 graph.entry.addBefore(graph.entry.first, result); | 117 graph.entry.addBefore(graph.entry.first, result); |
| 99 } else { | 118 } else { |
| 100 graph.entry.addAfter(lastAddedParameter, result); | 119 graph.entry.addAfter(lastAddedParameter, result); |
| 101 } | 120 } |
| 102 lastAddedParameter = result; | 121 lastAddedParameter = result; |
| 103 return result; | 122 return result; |
| 104 } | 123 } |
| 105 } | 124 } |
| OLD | NEW |