| 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 |
| 8 import 'locals_handler.dart'; |
| 7 import 'nodes.dart'; | 9 import 'nodes.dart'; |
| 8 | 10 |
| 9 /// Base class for objects that build up an SSA graph. | 11 /// Base class for objects that build up an SSA graph. |
| 10 /// | 12 /// |
| 11 /// This contains helpers for building the graph and tracking information about | 13 /// This contains helpers for building the graph and tracking information about |
| 12 /// the current state of the graph being built. | 14 /// the current state of the graph being built. |
| 13 abstract class GraphBuilder { | 15 abstract class GraphBuilder { |
| 14 /// Holds the resulting SSA graph. | 16 /// Holds the resulting SSA graph. |
| 15 final HGraph graph = new HGraph(); | 17 final HGraph graph = new HGraph(); |
| 16 | 18 |
| 19 /// Used to track the locals while building the graph. |
| 20 LocalsHandler localsHandler; |
| 21 |
| 17 /// A stack of instructions. | 22 /// A stack of instructions. |
| 18 /// | 23 /// |
| 19 /// We build the SSA graph by simulating a stack machine. | 24 /// We build the SSA graph by simulating a stack machine. |
| 20 List<HInstruction> stack = <HInstruction>[]; | 25 List<HInstruction> stack = <HInstruction>[]; |
| 21 | 26 |
| 22 void push(HInstruction instruction) { | 27 void push(HInstruction instruction) { |
| 23 add(instruction); | 28 add(instruction); |
| 24 stack.add(instruction); | 29 stack.add(instruction); |
| 25 } | 30 } |
| 26 | 31 |
| 27 HInstruction pop() { | 32 HInstruction pop() { |
| 28 return stack.removeLast(); | 33 return stack.removeLast(); |
| 29 } | 34 } |
| 30 | 35 |
| 36 /// Pops the most recent instruction from the stack and 'boolifies' it. |
| 37 /// |
| 38 /// Boolification is checking if the value is '=== true'. |
| 39 HInstruction popBoolified(); |
| 40 |
| 41 /// Pushes a boolean checking [expression] against null. |
| 42 pushCheckNull(HInstruction expression); |
| 43 |
| 31 void dup() { | 44 void dup() { |
| 32 stack.add(stack.last); | 45 stack.add(stack.last); |
| 33 } | 46 } |
| 34 | 47 |
| 35 HBasicBlock _current; | 48 HBasicBlock _current; |
| 36 | 49 |
| 37 /// The current block to add instructions to. Might be null, if we are | 50 /// The current block to add instructions to. Might be null, if we are |
| 38 /// visiting dead code, but see [isReachable]. | 51 /// visiting dead code, but see [isReachable]. |
| 39 HBasicBlock get current => _current; | 52 HBasicBlock get current => _current; |
| 40 | 53 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 HParameterValue result = new HParameterValue(parameter, type); | 127 HParameterValue result = new HParameterValue(parameter, type); |
| 115 if (lastAddedParameter == null) { | 128 if (lastAddedParameter == null) { |
| 116 graph.entry.addBefore(graph.entry.first, result); | 129 graph.entry.addBefore(graph.entry.first, result); |
| 117 } else { | 130 } else { |
| 118 graph.entry.addAfter(lastAddedParameter, result); | 131 graph.entry.addAfter(lastAddedParameter, result); |
| 119 } | 132 } |
| 120 lastAddedParameter = result; | 133 lastAddedParameter = result; |
| 121 return result; | 134 return result; |
| 122 } | 135 } |
| 123 } | 136 } |
| OLD | NEW |