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

Side by Side Diff: runtime/tools/kernel-service.dart

Issue 2483373002: Add Kernel Isolate (Closed)
Patch Set: wip Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This is an interface to the Dart Kernel parser and Kernel binary generator.
6 // It is used by the kernel-isolate to load Dart source code and generate
7 // Kernel binary format.
8
9 import 'dart:isolate';
10 import 'dart:async';
11 import "dart:io";
12 import "dart:typed_data";
13
14 import 'package:kernel/binary/ast_to_binary.dart';
15 import 'package:kernel/analyzer/loader.dart';
16 import 'package:kernel/kernel.dart';
17 import 'package:kernel/target/targets.dart';
18
19 bool verbose = false;
20
21 final RawReceivePort scriptLoadPort = new RawReceivePort();
22
23
24 bool checkIsFile(String path) {
25 var stat = new File(path).statSync();
26 switch (stat.type) {
27 case FileSystemEntityType.DIRECTORY:
28 return false;
29 case FileSystemEntityType.NOT_FOUND:
30 return false;
31 }
32 return true;
33 }
34
35 class DataSink implements StreamSink<List<int>> {
36 var buffer = [];
37 add(List<int> data) {
38 buffer.addAll(data);
39 }
40 close() {
41 // Nothing to do.
42 }
43 }
44
45
46 List writeProgramToBuffer(Program program) {
47 var sink = new DataSink();
48 try {
49 new BinaryPrinter(sink).writeProgramFile(program);
50 } finally {
51 sink.close();
52 }
53 return new Uint8List.fromList(sink.buffer);
54 }
55
56
57 Future parseScript(Map options, String fileName) async {
58 String packagePath = options['packages'];
59 String sdkPath = options['sdk'];
60
61 if (!checkIsFile(fileName)) {
62 throw "Input file '$fileName' does not exist.";
63 }
64
65 Target target = getTarget("vm", new TargetFlags(strongMode: false));
66 DartOptions dartOptions = new DartOptions(
67 strongMode: false,
68 strongModeSdk: false,
69 sdk: sdkPath,
70 packagePath: packagePath,
71 customUriMappings: {},
72 declaredVariables: {});
73 DartLoader loader =
74 await new DartLoaderBatch().getLoader(new Repository(), dartOptions);
75 var program = loader.loadProgram(fileName, target: target);
76
77 var errors = loader.errors;
78 if (errors.isNotEmpty) {
79 throw loader.errors.first;
80 }
81
82 // Link program into one file, cf. --link option in dartk
83 target.transformProgram(program);
84
85 return writeProgramToBuffer(program);
86 }
87
88
89 _processLoadRequest(request) {
90 if (verbose) {
91 print("FROM DART KERNEL: load request: $request");
92 }
93 int tag = request[0];
94 SendPort sp = request[1];
95 String inputFileUrl = request[2];
96 Uri uri = Uri.parse(inputFileUrl);
97
98 var options = {
99 "sdk": "/src/d2/sdk/xcodebuild/DebugX64/patched_sdk",
100 "packages": "/src/d2/sdk/.packages",
101 };
102 var parsingDone = parseScript(options, uri.path);
103
104 parsingDone
105 .then((data) {
106 var msg = new List(5);
107 msg[0] = tag;
108 msg[1] = inputFileUrl;
109 msg[2] = inputFileUrl;
110 msg[3] = null;
111 msg[4] = data;
112 sp.send(msg);
113 return;
114 })
115 .catchError((e) {
116 var msg = new List(5);
117 msg[0] = -tag;
118 msg[1] = inputFileUrl;
119 msg[2] = inputFileUrl;
120 msg[3] = null;
121 msg[4] = e;
122 sp.send(msg);
123 });
124 }
125
126
127 main() {
128 scriptLoadPort.handler = _processLoadRequest;
129 Timer.run(() {});
130 return scriptLoadPort;
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698