mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 23:51:47 +00:00
8bfc4b47c0
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 .
76 lines
2.2 KiB
Dart
76 lines
2.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.round_trip;
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import 'package:kernel/binary/ast_from_binary.dart';
|
|
import 'package:kernel/binary/ast_to_binary.dart';
|
|
import 'package:kernel/kernel.dart';
|
|
|
|
const String usage = '''
|
|
Usage: round_trip.dart FILE.dill
|
|
|
|
Deserialize and serialize the given program and check that the resulting byte
|
|
sequence is identical to the original.
|
|
''';
|
|
|
|
void main(List<String> args) {
|
|
if (args.length != 1) {
|
|
print(usage);
|
|
exit(1);
|
|
}
|
|
testRoundTrip(new File(args[0]).readAsBytesSync());
|
|
}
|
|
|
|
void testRoundTrip(List<int> bytes) {
|
|
var program = new Program();
|
|
new BinaryBuilder(bytes).readSingleFileProgram(program);
|
|
new BinaryPrinterWithExpectedOutput(bytes).writeProgramFile(program);
|
|
}
|
|
|
|
class DummyStreamConsumer extends StreamConsumer<List<int>> {
|
|
@override
|
|
Future addStream(Stream<List<int>> stream) async => null;
|
|
|
|
@override
|
|
Future close() async => null;
|
|
}
|
|
|
|
/// Variant of the binary serializer that compares the output against an
|
|
/// existing buffer.
|
|
///
|
|
/// As opposed to comparing binary files directly, when this fails, the stack
|
|
/// trace shows what the serializer was doing when the output started to differ.
|
|
class BinaryPrinterWithExpectedOutput extends BinaryPrinter {
|
|
final List<int> expectedBytes;
|
|
int offset = 0;
|
|
|
|
static const int eof = -1;
|
|
|
|
BinaryPrinterWithExpectedOutput(this.expectedBytes)
|
|
: super(new IOSink(new DummyStreamConsumer()));
|
|
|
|
String show(int byte) {
|
|
if (byte == eof) return 'EOF';
|
|
return '$byte (0x${byte.toRadixString(16).padLeft(2, "0")})';
|
|
}
|
|
|
|
@override
|
|
void writeByte(int byte) {
|
|
if (offset == expectedBytes.length || expectedBytes[offset] != byte) {
|
|
int expected =
|
|
(offset >= expectedBytes.length) ? eof : expectedBytes[offset];
|
|
throw 'At offset $offset: '
|
|
'Expected ${show(expected)} but found ${show(byte)}';
|
|
}
|
|
++offset;
|
|
}
|
|
|
|
@override
|
|
void writeBytes(List<int> bytes) {
|
|
bytes.forEach(writeByte);
|
|
}
|
|
}
|