Files
sdk/pkg/kernel/lib/target/targets.dart
T
Asger Feldthaus 8bfc4b47c0 Implement canonical name scheme in kernel.
This adds a class CanonicalName that can represent a library, class,
or member.  All references now go through a Reference object, which is
linked to both the AST node and its CanonicalName, so either can be
created first.

dartk now accepts multiple input files:
- If multiple dart files are given, they are all compiled.
- If multiple binaries are given, they are linked together.
Mixed dart and binary input is not supported by dartk.

dartk now has a flag --include-sdk which includes the entire SDK in
the output.  This is so the SDK can be compiled alone and then linked.

Example of compiling separately and then linking:
  dartk foo.dart -o foo.dill
  dartk main.dart -o main.dill
  dartk --include-sdk -o sdk.dill
  dartk main.dill foo.dill sdk.dill --target=vm --link -o program.dill

dartk still has incredibly slow cold start due to the analyzer loading
the dart sdk, so this does not actually speed things up at the moment.

BUG=
R=ahe@google.com, kmillikin@google.com, kustermann@google.com, sigmund@google.com

Review-Url: https://codereview.chromium.org/2665723002 .
2017-02-23 14:12:10 +01:00

97 lines
3.2 KiB
Dart

// 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.
library kernel.target.targets;
import '../ast.dart';
import '../core_types.dart';
import '../transformations/treeshaker.dart' show ProgramRoot;
import 'flutter.dart';
import 'vm.dart';
import 'vmcc.dart';
import 'vmreify.dart';
final List<String> targetNames = targets.keys.toList();
class TargetFlags {
bool strongMode;
bool treeShake;
List<ProgramRoot> programRoots;
Uri kernelRuntime;
TargetFlags(
{this.strongMode: false,
this.treeShake: false,
this.programRoots: const <ProgramRoot>[],
this.kernelRuntime});
}
typedef Target _TargetBuilder(TargetFlags flags);
final Map<String, _TargetBuilder> targets = <String, _TargetBuilder>{
'none': (TargetFlags flags) => new NoneTarget(flags),
'vm': (TargetFlags flags) => new VmTarget(flags),
'vmcc': (TargetFlags flags) => new VmClosureConvertedTarget(flags),
'vmreify': (TargetFlags flags) => new VmGenericTypesReifiedTarget(flags),
'flutter': (TargetFlags flags) => new FlutterTarget(flags),
};
Target getTarget(String name, TargetFlags flags) {
var builder = targets[name];
if (builder == null) return null;
return builder(flags);
}
/// A target provides backend-specific options for generating kernel IR.
abstract class Target {
String get name;
/// A list of URIs of required libraries, not including dart:core.
///
/// Libraries will be loaded in order.
List<String> get extraRequiredLibraries => <String>[];
/// Additional declared variables implied by this target.
///
/// These can also be passed on the command-line of form `-D<name>=<value>`,
/// and those provided on the command-line take precedence over those defined
/// by the target.
Map<String, String> get extraDeclaredVariables => const <String, String>{};
/// Classes from the SDK whose interface is required for the modular
/// transformations.
Map<String, List<String>> get requiredSdkClasses => CoreTypes.requiredClasses;
bool get strongMode;
/// If true, the SDK should be loaded in strong mode.
bool get strongModeSdk => strongMode;
/// Perform target-specific modular transformations.
///
/// These transformations should not be whole-program transformations. They
/// should expect that the program will contain external libraries.
void performModularTransformations(Program program);
/// Perform target-specific whole-program transformations.
///
/// These transformations should be optimizations and not required for
/// correctness. Everything should work if a simple and fast linker chooses
/// not to apply these transformations.
void performGlobalTransformations(Program program);
String toString() => 'Target($name)';
}
class NoneTarget extends Target {
final TargetFlags flags;
NoneTarget(this.flags);
bool get strongMode => flags.strongMode;
String get name => 'none';
List<String> get extraRequiredLibraries => <String>[];
void performModularTransformations(Program program) {}
void performGlobalTransformations(Program program) {}
}