| 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 '../compiler.dart'; | 5 import '../compiler.dart'; |
| 6 import '../elements/elements.dart'; | 6 import '../elements/elements.dart'; |
| 7 import '../js_backend/js_backend.dart'; |
| 7 import '../resolution/tree_elements.dart'; | 8 import '../resolution/tree_elements.dart'; |
| 8 import '../types/types.dart'; | 9 import '../types/types.dart'; |
| 9 | |
| 10 import 'jump_handler.dart'; | 10 import 'jump_handler.dart'; |
| 11 import 'locals_handler.dart'; | 11 import 'locals_handler.dart'; |
| 12 import 'nodes.dart'; | 12 import 'nodes.dart'; |
| 13 | 13 |
| 14 /// Base class for objects that build up an SSA graph. | 14 /// Base class for objects that build up an SSA graph. |
| 15 /// | 15 /// |
| 16 /// This contains helpers for building the graph and tracking information about | 16 /// This contains helpers for building the graph and tracking information about |
| 17 /// the current state of the graph being built. | 17 /// the current state of the graph being built. |
| 18 abstract class GraphBuilder { | 18 abstract class GraphBuilder { |
| 19 /// Holds the resulting SSA graph. | 19 /// Holds the resulting SSA graph. |
| 20 final HGraph graph = new HGraph(); | 20 final HGraph graph = new HGraph(); |
| 21 | 21 |
| 22 // TODO(het): remove this | 22 // TODO(het): remove this |
| 23 /// A reference to the compiler. | 23 /// A reference to the compiler. |
| 24 Compiler compiler; | 24 Compiler compiler; |
| 25 | 25 |
| 26 /// The JavaScript backend we are targeting in this compilation. |
| 27 JavaScriptBackend get backend; |
| 28 |
| 26 /// The tree elements for the element being built into an SSA graph. | 29 /// The tree elements for the element being built into an SSA graph. |
| 27 TreeElements get elements; | 30 TreeElements get elements; |
| 28 | 31 |
| 29 /// Used to track the locals while building the graph. | 32 /// Used to track the locals while building the graph. |
| 30 LocalsHandler localsHandler; | 33 LocalsHandler localsHandler; |
| 31 | 34 |
| 32 /// A stack of instructions. | 35 /// A stack of instructions. |
| 33 /// | 36 /// |
| 34 /// We build the SSA graph by simulating a stack machine. | 37 /// We build the SSA graph by simulating a stack machine. |
| 35 List<HInstruction> stack = <HInstruction>[]; | 38 List<HInstruction> stack = <HInstruction>[]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 HInstruction pop() { | 54 HInstruction pop() { |
| 52 return stack.removeLast(); | 55 return stack.removeLast(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 /// Pops the most recent instruction from the stack and 'boolifies' it. | 58 /// Pops the most recent instruction from the stack and 'boolifies' it. |
| 56 /// | 59 /// |
| 57 /// Boolification is checking if the value is '=== true'. | 60 /// Boolification is checking if the value is '=== true'. |
| 58 HInstruction popBoolified(); | 61 HInstruction popBoolified(); |
| 59 | 62 |
| 60 /// Pushes a boolean checking [expression] against null. | 63 /// Pushes a boolean checking [expression] against null. |
| 61 pushCheckNull(HInstruction expression); | 64 pushCheckNull(HInstruction expression) { |
| 65 push(new HIdentity( |
| 66 expression, graph.addConstantNull(compiler), null, backend.boolType)); |
| 67 } |
| 62 | 68 |
| 63 void dup() { | 69 void dup() { |
| 64 stack.add(stack.last); | 70 stack.add(stack.last); |
| 65 } | 71 } |
| 66 | 72 |
| 67 HBasicBlock _current; | 73 HBasicBlock _current; |
| 68 | 74 |
| 69 /// The current block to add instructions to. Might be null, if we are | 75 /// The current block to add instructions to. Might be null, if we are |
| 70 /// visiting dead code, but see [isReachable]. | 76 /// visiting dead code, but see [isReachable]. |
| 71 HBasicBlock get current => _current; | 77 HBasicBlock get current => _current; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { | 162 HSubGraphBlockInformation wrapStatementGraph(SubGraph statements) { |
| 157 if (statements == null) return null; | 163 if (statements == null) return null; |
| 158 return new HSubGraphBlockInformation(statements); | 164 return new HSubGraphBlockInformation(statements); |
| 159 } | 165 } |
| 160 | 166 |
| 161 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { | 167 HSubExpressionBlockInformation wrapExpressionGraph(SubExpression expression) { |
| 162 if (expression == null) return null; | 168 if (expression == null) return null; |
| 163 return new HSubExpressionBlockInformation(expression); | 169 return new HSubExpressionBlockInformation(expression); |
| 164 } | 170 } |
| 165 } | 171 } |
| OLD | NEW |