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.ast_to_binary; | 4 library kernel.ast_to_binary; |
5 | 5 |
6 import '../ast.dart'; | 6 import '../ast.dart'; |
7 import '../import_table.dart'; | 7 import '../import_table.dart'; |
8 import 'tag.dart'; | 8 import 'tag.dart'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 visitTypeParameter(TypeParameter node) { | 1012 visitTypeParameter(TypeParameter node) { |
1013 writeStringReference(node.name ?? ''); | 1013 writeStringReference(node.name ?? ''); |
1014 writeNode(node.bound); | 1014 writeNode(node.bound); |
1015 } | 1015 } |
1016 | 1016 |
1017 defaultNode(Node node) { | 1017 defaultNode(Node node) { |
1018 throw 'Unsupported node: $node'; | 1018 throw 'Unsupported node: $node'; |
1019 } | 1019 } |
1020 } | 1020 } |
1021 | 1021 |
| 1022 /// A [LibraryFilteringBinaryPrinter] can write a subset of libraries. |
| 1023 /// |
| 1024 /// This printer writes a Kernel binary but includes only libraries that match a |
| 1025 /// predicate. |
| 1026 class LibraryFilteringBinaryPrinter extends BinaryPrinter { |
| 1027 final Function predicate; |
| 1028 |
| 1029 LibraryFilteringBinaryPrinter( |
| 1030 Sink<List<int>> sink, bool predicate(Library library)) |
| 1031 : predicate = predicate, |
| 1032 super(sink); |
| 1033 |
| 1034 void writeProgramFile(Program program) { |
| 1035 program.computeCanonicalNames(); |
| 1036 writeMagicWord(Tag.ProgramFile); |
| 1037 _stringIndexer.scanProgram(program); |
| 1038 writeStringTable(_stringIndexer); |
| 1039 writeUriToSource(program); |
| 1040 writeLinkTable(program); |
| 1041 writeList(program.libraries.where(predicate), writeNode); |
| 1042 writeMemberReference(program.mainMethod, allowNull: true); |
| 1043 _flush(); |
| 1044 } |
| 1045 } |
| 1046 |
1022 class VariableIndexer { | 1047 class VariableIndexer { |
1023 final Map<VariableDeclaration, int> index = <VariableDeclaration, int>{}; | 1048 final Map<VariableDeclaration, int> index = <VariableDeclaration, int>{}; |
1024 final List<int> scopes = <int>[]; | 1049 final List<int> scopes = <int>[]; |
1025 int stackHeight = 0; | 1050 int stackHeight = 0; |
1026 | 1051 |
1027 void declare(VariableDeclaration node) { | 1052 void declare(VariableDeclaration node) { |
1028 index[node] = stackHeight++; | 1053 index[node] = stackHeight++; |
1029 } | 1054 } |
1030 | 1055 |
1031 void pushScope() { | 1056 void pushScope() { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 void flush() { | 1333 void flush() { |
1309 _sink.add(_buffer.sublist(0, length)); | 1334 _sink.add(_buffer.sublist(0, length)); |
1310 _buffer = new Uint8List(SIZE); | 1335 _buffer = new Uint8List(SIZE); |
1311 length = 0; | 1336 length = 0; |
1312 } | 1337 } |
1313 | 1338 |
1314 void flushAndDestroy() { | 1339 void flushAndDestroy() { |
1315 _sink.add(_buffer.sublist(0, length)); | 1340 _sink.add(_buffer.sublist(0, length)); |
1316 } | 1341 } |
1317 } | 1342 } |
OLD | NEW |