| 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 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common/codegen.dart' show CodegenWorkItem; | 7 import '../common/codegen.dart' show CodegenWorkItem; |
| 8 import '../common/tasks.dart' show CompilerTask; | 8 import '../common/tasks.dart' show CompilerTask; |
| 9 import '../compiler.dart'; | 9 import '../compiler.dart'; |
| 10 import '../diagnostics/spannable.dart'; |
| 10 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 11 import '../io/source_information.dart'; | 12 import '../io/source_information.dart'; |
| 12 import '../js_backend/backend.dart' show JavaScriptBackend; | 13 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 13 import '../kernel/kernel.dart'; | 14 import '../kernel/kernel.dart'; |
| 14 import '../kernel/kernel_visitor.dart'; | 15 import '../kernel/kernel_visitor.dart'; |
| 15 import '../resolution/tree_elements.dart'; | 16 import '../resolution/tree_elements.dart'; |
| 16 import 'graph_builder.dart'; | 17 import 'graph_builder.dart'; |
| 17 import 'locals_handler.dart'; | 18 import 'locals_handler.dart'; |
| 18 import 'nodes.dart'; | 19 import 'nodes.dart'; |
| 19 | 20 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 localsHandler.startFunction(functionElement, resolvedAst.node); | 110 localsHandler.startFunction(functionElement, resolvedAst.node); |
| 110 close(new HGoto()).addSuccessor(block); | 111 close(new HGoto()).addSuccessor(block); |
| 111 | 112 |
| 112 open(block); | 113 open(block); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void closeFunction() { | 116 void closeFunction() { |
| 116 if (!isAborted()) closeAndGotoExit(new HGoto()); | 117 if (!isAborted()) closeAndGotoExit(new HGoto()); |
| 117 graph.finalize(); | 118 graph.finalize(); |
| 118 } | 119 } |
| 120 |
| 121 @override |
| 122 void visitBlock(ir.Block block) { |
| 123 assert(!isAborted()); |
| 124 for (ir.Statement statement in block.statements) { |
| 125 statement.accept(this); |
| 126 if (!isReachable) { |
| 127 // The block has been aborted by a return or a throw. |
| 128 if (stack.isNotEmpty) { |
| 129 compiler.reporter.internalError( |
| 130 NO_LOCATION_SPANNABLE, 'Non-empty instruction stack.'); |
| 131 } |
| 132 return; |
| 133 } |
| 134 } |
| 135 assert(!current.isClosed()); |
| 136 if (stack.isNotEmpty) { |
| 137 compiler.reporter |
| 138 .internalError(NO_LOCATION_SPANNABLE, 'Non-empty instruction stack'); |
| 139 } |
| 140 } |
| 141 |
| 142 @override |
| 143 void visitReturnStatement(ir.ReturnStatement returnStatement) { |
| 144 HInstruction value; |
| 145 if (returnStatement.expression == null) { |
| 146 value = graph.addConstantNull(compiler); |
| 147 } else { |
| 148 returnStatement.expression.accept(this); |
| 149 value = pop(); |
| 150 // TODO(het): Check or trust the type of value |
| 151 } |
| 152 // TODO(het): Add source information |
| 153 // TODO(het): Set a return value instead of closing the function when we |
| 154 // support inlining. |
| 155 closeAndGotoExit(new HReturn(value, null)); |
| 156 } |
| 157 |
| 158 @override |
| 159 void visitIntLiteral(ir.IntLiteral intLiteral) { |
| 160 stack.add(graph.addConstantInt(intLiteral.value, compiler)); |
| 161 } |
| 119 } | 162 } |
| OLD | NEW |