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

Unified Diff: pkg/compiler/lib/src/serialization/task.dart

Issue 1975153002: Support (de)serialization from command-line (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 7 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 | « pkg/compiler/lib/src/serialization/system.dart ('k') | pkg/compiler/lib/src/source_file_provider.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/serialization/task.dart
diff --git a/pkg/compiler/lib/src/serialization/task.dart b/pkg/compiler/lib/src/serialization/task.dart
index 6ca46364572e9a320f28523e61f030321fc8ac84..f0cd00e270eaaa073ddafb66c5d6807fa4c8bd63 100644
--- a/pkg/compiler/lib/src/serialization/task.dart
+++ b/pkg/compiler/lib/src/serialization/task.dart
@@ -4,7 +4,7 @@
library dart2js.serialization.task;
-import 'dart:async' show Future;
+import 'dart:async' show EventSink, Future;
import '../common/resolution.dart' show ResolutionImpact, ResolutionWorkItem;
import '../common/tasks.dart' show CompilerTask;
import '../common/work.dart' show ItemCompilationContext;
@@ -12,6 +12,9 @@ import '../compiler.dart' show Compiler;
import '../elements/elements.dart';
import '../enqueue.dart' show ResolutionEnqueuer;
import '../universe/world_impact.dart' show WorldImpact;
+import 'json_serializer.dart';
+import 'serialization.dart';
+import 'system.dart';
/// A deserializer that can load a library element by reading it's information
/// from a serialized form.
@@ -75,6 +78,48 @@ class SerializationTask extends CompilerTask implements LibraryDeserializer {
ResolvedAst getResolvedAst(ExecutableElement element) {
return deserializer != null ? deserializer.getResolvedAst(element) : null;
}
+
+ Serializer createSerializer(Iterable<LibraryElement> libraries) {
+ return measure(() {
+ assert(supportSerialization);
+
+ Serializer serializer = new Serializer();
+ SerializerPlugin backendSerializer =
+ compiler.backend.serialization.serializer;
+ serializer.plugins.add(backendSerializer);
+ serializer.plugins.add(new ResolutionImpactSerializer(
+ compiler.resolution, backendSerializer));
+ serializer.plugins.add(new ResolvedAstSerializerPlugin(
+ compiler.resolution, backendSerializer));
+
+ for (LibraryElement library in libraries) {
+ serializer.serialize(library);
+ }
+ return serializer;
+ });
+ }
+
+ void serializeToSink(
+ EventSink<String> sink, Iterable<LibraryElement> libraries) {
+ measure(() {
+ sink
+ ..add(createSerializer(libraries)
+ .toText(const JsonSerializationEncoder()))
+ ..close();
+ });
+ }
+
+ void deserializeFromText(String serializedData) {
+ measure(() {
+ Deserializer dataDeserializer = new Deserializer.fromText(
+ new DeserializationContext(),
+ serializedData,
+ const JsonSerializationDecoder());
+ dataDeserializer.plugins.add(compiler.backend.serialization.deserializer);
+ deserializer = new DeserializerSystemImpl(
+ compiler, dataDeserializer, compiler.backend.impactTransformer);
+ });
+ }
}
/// A [ResolutionWorkItem] for a deserialized element.
« no previous file with comments | « pkg/compiler/lib/src/serialization/system.dart ('k') | pkg/compiler/lib/src/source_file_provider.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698