| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void writeMagicWord(int value) { | 65 void writeMagicWord(int value) { |
| 66 writeByte((value >> 24) & 0xFF); | 66 writeByte((value >> 24) & 0xFF); |
| 67 writeByte((value >> 16) & 0xFF); | 67 writeByte((value >> 16) & 0xFF); |
| 68 writeByte((value >> 8) & 0xFF); | 68 writeByte((value >> 8) & 0xFF); |
| 69 writeByte(value & 0xFF); | 69 writeByte(value & 0xFF); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void writeRawString(List<int> utf8Bytes) { |
| 73 writeUInt30(utf8Bytes.length); |
| 74 writeBytes(utf8Bytes); |
| 75 } |
| 76 |
| 72 void writeStringTableEntry(String string) { | 77 void writeStringTableEntry(String string) { |
| 73 List<int> utf8Bytes = const Utf8Encoder().convert(string); | 78 List<int> utf8Bytes = const Utf8Encoder().convert(string); |
| 74 writeUInt30(utf8Bytes.length); | 79 writeUInt30(utf8Bytes.length); |
| 75 writeBytes(utf8Bytes); | 80 writeBytes(utf8Bytes); |
| 76 } | 81 } |
| 77 | 82 |
| 78 void writeStringTable(StringIndexer indexer) { | 83 void writeStringTable(StringIndexer indexer) { |
| 79 writeUInt30(indexer.numberOfStrings); | 84 writeUInt30(indexer.numberOfStrings); |
| 80 for (var entry in indexer.entries) { | 85 for (var entry in indexer.entries) { |
| 81 writeStringTableEntry(entry.value); | 86 writeStringTableEntry(entry.value); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 _flush(); | 169 _flush(); |
| 165 } | 170 } |
| 166 | 171 |
| 167 void writeUriToSource(Program program) { | 172 void writeUriToSource(Program program) { |
| 168 program.uriToSource.keys.forEach((uri) { | 173 program.uriToSource.keys.forEach((uri) { |
| 169 _sourceUriIndexer.put(uri); | 174 _sourceUriIndexer.put(uri); |
| 170 }); | 175 }); |
| 171 writeStringTable(_sourceUriIndexer); | 176 writeStringTable(_sourceUriIndexer); |
| 172 for (int i = 0; i < _sourceUriIndexer.entries.length; i++) { | 177 for (int i = 0; i < _sourceUriIndexer.entries.length; i++) { |
| 173 String uri = _sourceUriIndexer.entries[i].value; | 178 String uri = _sourceUriIndexer.entries[i].value; |
| 174 Source source = program.uriToSource[uri] ?? new Source([], ''); | 179 Source source = program.uriToSource[uri] ?? new Source([], const <int>[]); |
| 175 String sourceCode = source.source; | 180 writeRawString(source.source); |
| 176 writeStringTableEntry(sourceCode); | |
| 177 List<int> lineStarts = source.lineStarts; | 181 List<int> lineStarts = source.lineStarts; |
| 178 writeUInt30(lineStarts.length); | 182 writeUInt30(lineStarts.length); |
| 179 int previousLineStart = 0; | 183 int previousLineStart = 0; |
| 180 lineStarts.forEach((lineStart) { | 184 lineStarts.forEach((lineStart) { |
| 181 writeUInt30(lineStart - previousLineStart); | 185 writeUInt30(lineStart - previousLineStart); |
| 182 previousLineStart = lineStart; | 186 previousLineStart = lineStart; |
| 183 }); | 187 }); |
| 184 } | 188 } |
| 185 } | 189 } |
| 186 | 190 |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 void flush() { | 1273 void flush() { |
| 1270 _sink.add(_buffer.sublist(0, length)); | 1274 _sink.add(_buffer.sublist(0, length)); |
| 1271 _buffer = new Uint8List(SIZE); | 1275 _buffer = new Uint8List(SIZE); |
| 1272 length = 0; | 1276 length = 0; |
| 1273 } | 1277 } |
| 1274 | 1278 |
| 1275 void flushAndDestroy() { | 1279 void flushAndDestroy() { |
| 1276 _sink.add(_buffer.sublist(0, length)); | 1280 _sink.add(_buffer.sublist(0, length)); |
| 1277 } | 1281 } |
| 1278 } | 1282 } |
| OLD | NEW |