| 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 import 'dart:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
| 8 | 8 |
| 9 import '../closure.dart'; | 9 import '../closure.dart'; |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 import '../universe/selector.dart' show Selector; | 36 import '../universe/selector.dart' show Selector; |
| 37 import '../universe/side_effects.dart' show SideEffects; | 37 import '../universe/side_effects.dart' show SideEffects; |
| 38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; | 38 import '../universe/use.dart' show DynamicUse, StaticUse, TypeUse; |
| 39 import '../util/util.dart'; | 39 import '../util/util.dart'; |
| 40 import '../world.dart' show ClassWorld; | 40 import '../world.dart' show ClassWorld; |
| 41 import 'codegen.dart'; | 41 import 'codegen.dart'; |
| 42 import 'nodes.dart'; | 42 import 'nodes.dart'; |
| 43 import 'optimize.dart'; | 43 import 'optimize.dart'; |
| 44 import 'types.dart'; | 44 import 'types.dart'; |
| 45 | 45 |
| 46 class SsaFunctionCompiler implements FunctionCompiler { | |
| 47 final SsaCodeGeneratorTask generator; | |
| 48 final SsaBuilderTask builder; | |
| 49 final SsaOptimizerTask optimizer; | |
| 50 final JavaScriptBackend backend; | |
| 51 | |
| 52 SsaFunctionCompiler(JavaScriptBackend backend, | |
| 53 SourceInformationStrategy sourceInformationFactory) | |
| 54 : generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory), | |
| 55 builder = new SsaBuilderTask(backend, sourceInformationFactory), | |
| 56 optimizer = new SsaOptimizerTask(backend), | |
| 57 backend = backend; | |
| 58 | |
| 59 /// Generates JavaScript code for `work.element`. | |
| 60 /// Using the ssa builder, optimizer and codegenerator. | |
| 61 js.Fun compile(CodegenWorkItem work) { | |
| 62 HGraph graph = builder.build(work); | |
| 63 optimizer.optimize(work, graph); | |
| 64 Element element = work.element; | |
| 65 js.Expression result = generator.generateCode(work, graph); | |
| 66 if (element is FunctionElement) { | |
| 67 result = backend.rewriteAsync(element, result); | |
| 68 } | |
| 69 return result; | |
| 70 } | |
| 71 | |
| 72 Iterable<CompilerTask> get tasks { | |
| 73 return <CompilerTask>[builder, optimizer, generator]; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 /// A synthetic local variable only used with the SSA graph. | 46 /// A synthetic local variable only used with the SSA graph. |
| 78 /// | 47 /// |
| 79 /// For instance used for holding return value of function or the exception of a | 48 /// For instance used for holding return value of function or the exception of a |
| 80 /// try-catch statement. | 49 /// try-catch statement. |
| 81 class SyntheticLocal extends Local { | 50 class SyntheticLocal extends Local { |
| 82 final String name; | 51 final String name; |
| 83 final ExecutableElement executableContext; | 52 final ExecutableElement executableContext; |
| 84 | 53 |
| 85 // Avoid slow Object.hashCode. | 54 // Avoid slow Object.hashCode. |
| 86 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); | 55 final int hashCode = _nextHashCode = (_nextHashCode + 1).toUnsigned(30); |
| (...skipping 8550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8637 const _LoopTypeVisitor(); | 8606 const _LoopTypeVisitor(); |
| 8638 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; | 8607 int visitNode(ast.Node node) => HLoopBlockInformation.NOT_A_LOOP; |
| 8639 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; | 8608 int visitWhile(ast.While node) => HLoopBlockInformation.WHILE_LOOP; |
| 8640 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; | 8609 int visitFor(ast.For node) => HLoopBlockInformation.FOR_LOOP; |
| 8641 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; | 8610 int visitDoWhile(ast.DoWhile node) => HLoopBlockInformation.DO_WHILE_LOOP; |
| 8642 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8611 int visitAsyncForIn(ast.AsyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 8643 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; | 8612 int visitSyncForIn(ast.SyncForIn node) => HLoopBlockInformation.FOR_IN_LOOP; |
| 8644 int visitSwitchStatement(ast.SwitchStatement node) => | 8613 int visitSwitchStatement(ast.SwitchStatement node) => |
| 8645 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; | 8614 HLoopBlockInformation.SWITCH_CONTINUE_LOOP; |
| 8646 } | 8615 } |
| OLD | NEW |