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

Unified Diff: pkg/kernel/lib/kernel.dart

Issue 2784303003: Allow dartk to print out binary Kernel IR results to stdout if requested. (Closed)
Patch Set: . Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/kernel.dart
diff --git a/pkg/kernel/lib/kernel.dart b/pkg/kernel/lib/kernel.dart
index 361f59aaa265445c0a472feb4138df8e821c00b3..16eb86adeb78ff1e1eab6c80bf0fdb9f384cde04 100644
--- a/pkg/kernel/lib/kernel.dart
+++ b/pkg/kernel/lib/kernel.dart
@@ -29,13 +29,21 @@ Program loadProgramFromBinary(String path, [Program program]) {
}
Future writeProgramToBinary(Program program, String path) {
- var sink = new File(path).openWrite();
+ var sink;
+ if (path == 'null' || path == 'stdout') {
+ sink = new _ByteBuffer();
asgerf 2017/03/31 08:40:16 Is the wrapper necessary? Could you try this inst
Emily Fortuna 2017/03/31 17:46:55 Ah, that's MUCH better. I didn't know about that.
+ } else {
+ sink = new File(path).openWrite();
+ }
+
var future;
try {
new BinaryPrinter(sink).writeProgramFile(program);
} finally {
future = sink.close();
}
+
+ if (sink is _ByteBuffer) print(sink.takeBytes());
asgerf 2017/03/31 08:40:16 Calling toString on a List<int> normally emits som
Emily Fortuna 2017/03/31 17:46:56 touche. No I hadn't actually tested consuming this
return future;
}
@@ -60,3 +68,25 @@ void writeProgramToText(Program program,
new File(path).writeAsStringSync('$buffer');
}
}
+
+/// Silly wrapper around BytesBuilder that conforms to the Sink interface.
Johnni Winther 2017/03/31 06:38:35 'Silly' -> 'Simple'
Emily Fortuna 2017/03/31 17:46:56 Acknowledged.
+class _ByteBuffer implements Sink<List<int>> {
+ BytesBuilder _builder;
+ bool _open;
+
+ _ByteBuffer()
+ : _open = true,
+ _builder = new BytesBuilder();
asgerf 2017/03/31 08:40:16 You can pass `copy: false` to the BytesBuilder her
Emily Fortuna 2017/03/31 17:46:56 No longer needed once I took this out.
+
+ void add(List<int> data) {
+ if (_open) {
+ _builder.add(data);
+ }
+ }
+
+ void close() {
+ _open = false;
+ }
+
+ List<int> takeBytes() => _builder.takeBytes();
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698