OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library kernel.round_trip; | 4 library kernel.round_trip; |
5 | 5 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'package:kernel/binary/ast_from_binary.dart'; | 8 import 'package:kernel/binary/ast_from_binary.dart'; |
9 import 'package:kernel/binary/ast_to_binary.dart'; | 9 import 'package:kernel/binary/ast_to_binary.dart'; |
10 import 'package:kernel/binary/loader.dart'; | |
11 import 'package:kernel/kernel.dart'; | 10 import 'package:kernel/kernel.dart'; |
12 | 11 |
13 const String usage = ''' | 12 const String usage = ''' |
14 Usage: round_trip.dart FILE.dill | 13 Usage: round_trip.dart FILE.dill |
15 | 14 |
16 Deserialize and serialize the given program and check that the resulting byte | 15 Deserialize and serialize the given program and check that the resulting byte |
17 sequence is identical to the original. | 16 sequence is identical to the original. |
18 '''; | 17 '''; |
19 | 18 |
20 void main(List<String> args) { | 19 void main(List<String> args) { |
21 if (args.length != 1) { | 20 if (args.length != 1) { |
22 print(usage); | 21 print(usage); |
23 exit(1); | 22 exit(1); |
24 } | 23 } |
25 testRoundTrip(new File(args[0]).readAsBytesSync()); | 24 testRoundTrip(new File(args[0]).readAsBytesSync()); |
26 } | 25 } |
27 | 26 |
28 void testRoundTrip(List<int> bytes) { | 27 void testRoundTrip(List<int> bytes) { |
29 var loader = new BinaryLoader(new Repository()); | 28 var program = new Program(); |
30 var program = new BinaryBuilder(loader, bytes).readProgramFile(); | 29 new BinaryBuilder(bytes).readSingleFileProgram(program); |
31 new BinaryPrinterWithExpectedOutput(bytes).writeProgramFile(program); | 30 new BinaryPrinterWithExpectedOutput(bytes).writeProgramFile(program); |
32 } | 31 } |
33 | 32 |
34 class DummyStreamConsumer extends StreamConsumer<List<int>> { | 33 class DummyStreamConsumer extends StreamConsumer<List<int>> { |
35 @override | 34 @override |
36 Future addStream(Stream<List<int>> stream) async => null; | 35 Future addStream(Stream<List<int>> stream) async => null; |
37 | 36 |
38 @override | 37 @override |
39 Future close() async => null; | 38 Future close() async => null; |
40 } | 39 } |
(...skipping 26 matching lines...) Expand all Loading... |
67 'Expected ${show(expected)} but found ${show(byte)}'; | 66 'Expected ${show(expected)} but found ${show(byte)}'; |
68 } | 67 } |
69 ++offset; | 68 ++offset; |
70 } | 69 } |
71 | 70 |
72 @override | 71 @override |
73 void writeBytes(List<int> bytes) { | 72 void writeBytes(List<int> bytes) { |
74 bytes.forEach(writeByte); | 73 bytes.forEach(writeByte); |
75 } | 74 } |
76 } | 75 } |
OLD | NEW |