blob: bad1ff910958279b9c9eea5538a3c858d07a0ba9 [file] [log] [blame]
// Copyright (c) 2017, 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 'dart:async' show Future;
import 'package:kernel/kernel.dart' show Program;
import 'package:kernel/target/targets.dart' show Target;
import '../api_prototype/compiler_options.dart'
show CompilerOptions, ErrorHandler;
import '../api_prototype/file_system.dart' show FileSystem;
import '../base/processed_options.dart' show ProcessedOptions;
import '../fasta/compiler_context.dart' show CompilerContext;
import '../fasta/fasta_codes.dart' show messageMissingMain, noLength;
import '../fasta/severity.dart' show Severity;
import '../kernel_generator_impl.dart' show generateKernelInternal;
import 'compiler_state.dart' show InitializedCompilerState;
export 'compiler_state.dart' show InitializedCompilerState;
InitializedCompilerState initializeCompiler(InitializedCompilerState oldState,
Target target, Uri sdkUri, Uri packagesFileUri) {
if (oldState != null &&
oldState.options.packagesFileUri == packagesFileUri &&
oldState.options.linkedDependencies[0] == sdkUri) {
return oldState;
CompilerOptions options = new CompilerOptions() = target
..strongMode = target.strongMode
..linkedDependencies = [sdkUri]
..packagesFileUri = packagesFileUri;
ProcessedOptions processedOpts = new ProcessedOptions(options, false, []);
return new InitializedCompilerState(options, processedOpts);
Future<Program> compile(InitializedCompilerState state, bool verbose,
FileSystem fileSystem, ErrorHandler onError, Uri input) async {
CompilerOptions options = state.options;
..onError = onError
..verbose = verbose
..fileSystem = fileSystem;
ProcessedOptions processedOpts = state.processedOpts;
var compilerResult = await CompilerContext.runWithOptions(processedOpts,
(CompilerContext context) async {
var compilerResult = await generateKernelInternal();
Program program = compilerResult?.program;
if (program == null) return null;
if (program.mainMethod == null) {
messageMissingMain.withLocation(input, -1, noLength), Severity.error);
return null;
return compilerResult;
return compilerResult?.program;