Index: pkg/kernel/lib/binary/ast_to_binary.dart |
diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart |
index cfc65fffe9b4a7063ccb11c6161f4bffa892750d..95ad03729800295347a08087aa5058622d86ef96 100644 |
--- a/pkg/kernel/lib/binary/ast_to_binary.dart |
+++ b/pkg/kernel/lib/binary/ast_to_binary.dart |
@@ -1019,6 +1019,31 @@ class BinaryPrinter extends Visitor { |
} |
} |
+/// A [LibraryFilteringBinaryPrinter] can write a subset of libraries. |
+/// |
+/// This printer writes a Kernel binary but includes only libraries that match a |
+/// predicate. |
+class LibraryFilteringBinaryPrinter extends BinaryPrinter { |
+ final Function predicate; |
+ |
+ LibraryFilteringBinaryPrinter( |
+ Sink<List<int>> sink, bool predicate(Library library)) |
+ : predicate = predicate, |
+ super(sink); |
+ |
+ void writeProgramFile(Program program) { |
+ program.computeCanonicalNames(); |
+ writeMagicWord(Tag.ProgramFile); |
+ _stringIndexer.scanProgram(program); |
+ writeStringTable(_stringIndexer); |
+ writeUriToSource(program); |
+ writeLinkTable(program); |
+ writeList(program.libraries.where(predicate), writeNode); |
+ writeMemberReference(program.mainMethod, allowNull: true); |
+ _flush(); |
+ } |
+} |
+ |
class VariableIndexer { |
final Map<VariableDeclaration, int> index = <VariableDeclaration, int>{}; |
final List<int> scopes = <int>[]; |