mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:31:50 +00:00
Add skeleton of SSAKernel function compiler
R=het@google.com Review URL: https://codereview.chromium.org/2269783002 .
This commit is contained in:
parent
b49de12f6c
commit
57f26aeb60
|
@ -39,7 +39,7 @@ import '../js/rewrite_async.dart';
|
|||
import '../js_emitter/js_emitter.dart' show CodeEmitterTask;
|
||||
import '../library_loader.dart' show LibraryLoader, LoadedLibraries;
|
||||
import '../native/native.dart' as native;
|
||||
import '../ssa/builder.dart' show SsaFunctionCompiler;
|
||||
import '../ssa/ssa.dart' show SsaFunctionCompiler;
|
||||
import '../ssa/nodes.dart' show HInstruction;
|
||||
import '../tree/tree.dart';
|
||||
import '../types/types.dart';
|
||||
|
@ -626,8 +626,8 @@ class JavaScriptBackend extends Backend {
|
|||
constantCompilerTask = new JavaScriptConstantTask(compiler);
|
||||
impactTransformer = new JavaScriptImpactTransformer(this);
|
||||
patchResolverTask = new PatchResolverTask(compiler);
|
||||
// TODO(sigmund): pass along the kernel flag.
|
||||
functionCompiler = new SsaFunctionCompiler(this, sourceInformationStrategy);
|
||||
functionCompiler = new SsaFunctionCompiler(
|
||||
this, sourceInformationStrategy, useKernel);
|
||||
serialization = new JavaScriptBackendSerialization(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -43,37 +43,6 @@ import 'nodes.dart';
|
|||
import 'optimize.dart';
|
||||
import 'types.dart';
|
||||
|
||||
class SsaFunctionCompiler implements FunctionCompiler {
|
||||
final SsaCodeGeneratorTask generator;
|
||||
final SsaBuilderTask builder;
|
||||
final SsaOptimizerTask optimizer;
|
||||
final JavaScriptBackend backend;
|
||||
|
||||
SsaFunctionCompiler(JavaScriptBackend backend,
|
||||
SourceInformationStrategy sourceInformationFactory)
|
||||
: generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory),
|
||||
builder = new SsaBuilderTask(backend, sourceInformationFactory),
|
||||
optimizer = new SsaOptimizerTask(backend),
|
||||
backend = backend;
|
||||
|
||||
/// Generates JavaScript code for `work.element`.
|
||||
/// Using the ssa builder, optimizer and codegenerator.
|
||||
js.Fun compile(CodegenWorkItem work) {
|
||||
HGraph graph = builder.build(work);
|
||||
optimizer.optimize(work, graph);
|
||||
Element element = work.element;
|
||||
js.Expression result = generator.generateCode(work, graph);
|
||||
if (element is FunctionElement) {
|
||||
result = backend.rewriteAsync(element, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Iterable<CompilerTask> get tasks {
|
||||
return <CompilerTask>[builder, optimizer, generator];
|
||||
}
|
||||
}
|
||||
|
||||
/// A synthetic local variable only used with the SSA graph.
|
||||
///
|
||||
/// For instance used for holding return value of function or the exception of a
|
||||
|
|
28
pkg/compiler/lib/src/ssa/builder_kernel.dart
Normal file
28
pkg/compiler/lib/src/ssa/builder_kernel.dart
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import '../common/codegen.dart' show CodegenWorkItem;
|
||||
import '../common/tasks.dart' show CompilerTask;
|
||||
import '../io/source_information.dart';
|
||||
import '../js_backend/backend.dart' show JavaScriptBackend, FunctionCompiler;
|
||||
import '../elements/elements.dart';
|
||||
|
||||
import 'nodes.dart';
|
||||
|
||||
class SsaKernelBuilderTask extends CompilerTask {
|
||||
final JavaScriptBackend backend;
|
||||
final SourceInformationStrategy sourceInformationFactory;
|
||||
|
||||
String get name => 'SSA kernel builder';
|
||||
|
||||
SsaKernelBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory)
|
||||
: super(backend.compiler.measurer);
|
||||
|
||||
HGraph build(CodegenWorkItem work) {
|
||||
return measure(() {
|
||||
Element element = work.element.implementation;
|
||||
throw "unimplemented";
|
||||
});
|
||||
}
|
||||
}
|
|
@ -4,4 +4,56 @@
|
|||
|
||||
library ssa;
|
||||
|
||||
export 'builder.dart' show SsaFunctionCompiler;
|
||||
import '../common/codegen.dart' show CodegenWorkItem;
|
||||
import '../common/tasks.dart' show CompilerTask;
|
||||
import '../elements/elements.dart' show Element, FunctionElement;
|
||||
import '../io/source_information.dart';
|
||||
import '../js/js.dart' as js;
|
||||
import '../js_backend/backend.dart' show JavaScriptBackend, FunctionCompiler;
|
||||
|
||||
import 'builder.dart';
|
||||
import 'builder_kernel.dart';
|
||||
import 'codegen.dart';
|
||||
import 'nodes.dart';
|
||||
import 'optimize.dart';
|
||||
import 'types.dart';
|
||||
|
||||
class SsaFunctionCompiler implements FunctionCompiler {
|
||||
final SsaCodeGeneratorTask generator;
|
||||
final SsaBuilderTask builder;
|
||||
final SsaKernelBuilderTask builderKernel;
|
||||
final SsaOptimizerTask optimizer;
|
||||
final JavaScriptBackend backend;
|
||||
final bool useKernel;
|
||||
|
||||
SsaFunctionCompiler(JavaScriptBackend backend,
|
||||
SourceInformationStrategy sourceInformationFactory, this.useKernel)
|
||||
: generator = new SsaCodeGeneratorTask(backend, sourceInformationFactory),
|
||||
builder = new SsaBuilderTask(backend, sourceInformationFactory),
|
||||
builderKernel =
|
||||
new SsaKernelBuilderTask(backend, sourceInformationFactory),
|
||||
optimizer = new SsaOptimizerTask(backend),
|
||||
backend = backend;
|
||||
|
||||
/// Generates JavaScript code for `work.element`.
|
||||
/// Using the ssa builder, optimizer and codegenerator.
|
||||
js.Fun compile(CodegenWorkItem work) {
|
||||
HGraph graph = useKernel ? builderKernel.build(work) : builder.build(work);
|
||||
optimizer.optimize(work, graph);
|
||||
Element element = work.element;
|
||||
js.Expression result = generator.generateCode(work, graph);
|
||||
if (element is FunctionElement) {
|
||||
// TODO(sigmund): replace by kernel transformer when `useKernel` is true.
|
||||
result = backend.rewriteAsync(element, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Iterable<CompilerTask> get tasks {
|
||||
return <CompilerTask>[
|
||||
useKernel ? builderKernel : builder,
|
||||
optimizer,
|
||||
generator
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue