Files
sdk/pkg/kernel/bin/split.dart
T
Jens Johansen 3692c0285a [kernel] Allow ast_to_text to print 'partial' dills
Currently we produce 'partial dills' for the VM when compiling through
kernel, i.e. we only include the user-code and whatever canonical names
the user refers to. That's perfectly fine for the VM as it always loads
the platform.dill file too.

We cannot currently print it though.
(Technically we should be able to concatenate it with platform.dill and
print that).

This CL allows us to print these partial dills without concatenating
anything first.

Bug:
Change-Id: I7d5f12332e16623d02531ad46e2dc103222f59e9
Reviewed-on: https://dart-review.googlesource.com/19002
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2017-11-17 11:02:33 +00:00

43 lines
1.3 KiB
Dart
Executable File

#!/usr/bin/env dart
// 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';
import 'dart:io';
import 'package:kernel/ast.dart';
import 'package:kernel/binary/ast_to_binary.dart';
import 'package:kernel/binary/limited_ast_to_binary.dart';
import 'package:kernel/kernel.dart';
main(args) async {
Program binary = loadProgramFromBinary(args[0]);
int part = 1;
binary.libraries.forEach((lib) => lib.isExternal = true);
for (int i = 0; i < binary.libraries.length; ++i) {
Library lib = binary.libraries[i];
if (lib.name?.startsWith("dart.") == true ||
lib.name == "builtin" ||
lib.name == "nativewrappers") continue;
lib.isExternal = false;
String path = args[0] + ".part${part++}.dill";
await writeProgramToFile(binary, path);
print("Wrote $path");
lib.isExternal = true;
}
}
Future<Null> writeProgramToFile(Program program, String path) async {
File output = new File(path);
IOSink sink = output.openWrite();
try {
BinaryPrinter printer =
new LimitedBinaryPrinter(sink, (lib) => !lib.isExternal, false);
printer.writeProgramFile(program);
} finally {
await sink.close();
}
}