Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: pkg/compiler/lib/src/ssa/ssa.dart

Issue 2893293002: Share more logic between the Ssa(Ast)Builder and SsaKernelBuilder (Closed)
Patch Set: Rebased Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/ssa/ssa.dart
diff --git a/pkg/compiler/lib/src/ssa/ssa.dart b/pkg/compiler/lib/src/ssa/ssa.dart
index 191fe70d3fbc64d207acda6a503364a57c1a9c63..b1bbb484bf3c4c05d920abf1a2ea158f152a27d7 100644
--- a/pkg/compiler/lib/src/ssa/ssa.dart
+++ b/pkg/compiler/lib/src/ssa/ssa.dart
@@ -4,6 +4,7 @@
library ssa;
+import '../common/codegen.dart' show CodegenWorkItem;
import '../common/tasks.dart' show CompilerTask;
import '../elements/elements.dart' show Element, FunctionElement;
import '../io/source_information.dart';
@@ -20,27 +21,24 @@ import 'optimize.dart';
class SsaFunctionCompiler implements FunctionCompiler {
final SsaCodeGeneratorTask generator;
- final SsaBuilderTask builder;
- final SsaKernelBuilderTask builderKernel;
+ final SsaBuilderTask _builder;
final SsaOptimizerTask optimizer;
final JavaScriptBackend backend;
- final bool useKernel;
SsaFunctionCompiler(JavaScriptBackend backend,
- SourceInformationStrategy sourceInformationFactory, this.useKernel)
+ SourceInformationStrategy sourceInformationFactory, bool useKernel)
: generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory),
- builder = new SsaBuilderTask(backend, sourceInformationFactory),
- builderKernel =
- new SsaKernelBuilderTask(backend, sourceInformationFactory),
+ _builder = useKernel
+ ? new SsaKernelBuilderTask(backend, sourceInformationFactory)
+ : new SsaAstBuilderTask(backend, sourceInformationFactory),
optimizer = new SsaOptimizerTask(backend),
backend = backend;
/// Generates JavaScript code for `work.element`.
/// Using the ssa builder, optimizer and codegenerator.
js.Fun compile(ElementCodegenWorkItem work, ClosedWorld closedWorld) {
- HGraph graph = useKernel
- ? builderKernel.build(work, closedWorld)
- : builder.build(work, closedWorld);
+ HGraph graph = _builder.build(work, closedWorld);
+ if (graph == null) return null;
optimizer.optimize(work, graph, closedWorld);
Element element = work.element;
js.Expression result = generator.generateCode(work, graph, closedWorld);
@@ -52,10 +50,12 @@ class SsaFunctionCompiler implements FunctionCompiler {
}
Iterable<CompilerTask> get tasks {
- return <CompilerTask>[
- useKernel ? builderKernel : builder,
- optimizer,
- generator
- ];
+ return <CompilerTask>[_builder, optimizer, generator];
}
}
+
+abstract class SsaBuilderTask implements CompilerTask {
+ /// Creates the [HGraph] for [work] or returns `null` if no code is needed
+ /// for [work].
+ HGraph build(CodegenWorkItem work, ClosedWorld closedWorld);
+}

Powered by Google App Engine
This is Rietveld 408576698