Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: pkg/front_end/tool/_fasta/dump_partial.dart

Issue 2985113002: Add dump-partial tool. (Closed)
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/front_end/tool/fasta » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Utility to dump a truncated .dill file generated by the incremental kernel
6 /// generator or by the VM's kernel service.
7 import 'dart:io';
8 import 'package:kernel/kernel.dart';
9 import 'package:front_end/src/fasta/kernel/utils.dart';
10
11 main(List<String> args) {
12 if (args.length == 0) {
13 print('usage: pkg/front_end/tool/fasta dump_partial '
14 'partial.dill [extra1.dill] ... [extraN.dill]');
15 exitCode = 1;
16 }
17
18 var program = _loadProgram(args);
19 writeProgramToText(program);
20 }
21
22 /// Creates a program that contains all of the context code marked as external,
23 /// and all libraries defined in partial.dill as they are written in that file.
24 Program _loadProgram(List<String> args) {
25 List<int> partialInput = new File(args[0]).readAsBytesSync();
26
27 var context = new Program();
28 for (var i = 1; i < args.length; i++) {
29 loadProgramFromBinary(args[i], context);
30 }
31
32 Set<Uri> libraries = _definedLibraries(partialInput, context);
33
34 // By default `package:kernel/binary/ast_from_binary.dart` merges the contents
35 // of libraries that are mentioned in more than one .dill file. In order to
36 // keep the contents of partial.dill intact, we build a new context that
37 // excludes those libraries defined in partial.dill.
38 List<int> contextBytes = serializeProgram(context,
39 filter: (l) => !libraries.contains(l.importUri));
40 var program = new Program();
41 loadProgramFromBytes(contextBytes, program);
42 _updateIsExternal(program, true);
43 loadProgramFromBytes(partialInput, program);
44 return program;
45 }
46
47 /// Compute the set of libraries defined in [partialDill].
48 ///
49 /// The [context] program contains all other libraries that may be needed to
50 /// properly deserialize partialDill.
51 ///
52 /// Note: This function will mutate [context] in place.
53 // TODO(sigmund): simplify and get rid of [context]. We could do that with a
54 // custom deserialization, but it will be easier to do once .dill has
55 // random-access support.
56 Set<Uri> _definedLibraries(List<int> partialDill, Program context) {
57 _updateIsExternal(context, true);
58
59 // This implicitly sets `isExternal = false` on all libraries defined in the
60 // partial.dill file.
61 loadProgramFromBytes(partialDill, context);
62 var result = context.libraries
63 .where((l) => !l.isExternal)
64 .map((l) => l.importUri)
65 .toSet();
66 _updateIsExternal(context, false);
67 return result;
68 }
69
70 void _updateIsExternal(Program program, bool toValue) {
71 program.libraries.forEach((lib) => lib.isExternal = toValue);
72 }
OLDNEW
« no previous file with comments | « no previous file | pkg/front_end/tool/fasta » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698