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

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

Issue 2558673002: 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
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
kasperl 2016/12/08 11:44:27 Why is this not just stored in a local variable in
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
36 void checkSdkDirectory(String path) {
kasperl 2016/12/08 11:44:27 bool
37 var stat = new File(path).statSync();
38 switch (stat.type) {
39 case FileSystemEntityType.DIRECTORY:
40 case FileSystemEntityType.LINK:
41 return true;
42 default:
43 return false;
44 }
45 }
46
47
48 class DataSink implements StreamSink<List<int>> {
49 var buffer = [];
kasperl 2016/12/08 11:44:27 There is a lot of copying of the bytes produced by
50 add(List<int> data) {
51 buffer.addAll(data);
52 }
53 close() {
54 // Nothing to do.
55 }
56 }
57
58
59 List writeProgramToBuffer(Program program) {
60 var sink = new DataSink();
61 try {
62 new BinaryPrinter(sink).writeProgramFile(program);
63 } finally {
64 sink.close();
65 }
66 return new Uint8List.fromList(sink.buffer);
67 }
68
69
70 Future parseScript(Uri fileName, String packageConfig, String sdkPath) async {
71
kasperl 2016/12/08 11:44:27 Remove empty line.
72 if (!checkIsFile(fileName.path)) {
73 throw "Input file '${fileName.path}' does not exist.";
74 }
75
76 if (!checkSdkDirectory(sdkPath)) {
77 throw "Patched sdk directory not found at $sdkPath";
78 }
79
80 Target target = getTarget("vm", new TargetFlags(strongMode: false));
81 DartOptions dartOptions = new DartOptions(
82 strongMode: false,
83 strongModeSdk: false,
84 sdk: sdkPath,
85 packagePath: packageConfig,
86 customUriMappings: {},
87 declaredVariables: {});
88 DartLoader loader =
89 await new DartLoaderBatch().getLoader(new Repository(), dartOptions);
90 var program = loader.loadProgram(fileName, target: target);
91
92 var errors = loader.errors;
93 if (errors.isNotEmpty) {
94 throw loader.errors.first;
95 }
96
97 // Link program into one file, cf. --link option in dartk
kasperl 2016/12/08 11:44:27 Terminate comment with .
98 target.transformProgram(program);
99
100 return writeProgramToBuffer(program);
101 }
102
103
104 _processLoadRequest(request) {
105 if (verbose) {
106 print("FROM DART KERNEL: load request: $request");
107 print("FROM DART KERNEL: package: ${Platform.packageConfig}");
108 print("FROM DART KERNEL: exec: ${Platform.resolvedExecutable}");
109 }
110 int tag = request[0];
111 SendPort sp = request[1];
112 String inputFileUrl = request[2];
113 Uri scriptUri = Uri.parse(inputFileUrl);
114 Uri packagesUri = Uri.parse(Platform.packageConfig ?? ".packages");
115 Uri patched_sdk = Uri.parse(Platform.resolvedExecutable).resolve("patched_sdk" );
kasperl 2016/12/08 11:44:27 Long line. patched_sdk -> patchedSdk
116
117 var parsingDone = parseScript(scriptUri, packagesUri.path, patched_sdk.path);
118
119 parsingDone
120 .then((data) {
121 var msg = new List(5);
kasperl 2016/12/08 11:44:27 sp.send([tag, inputFileUrl, inputFileUrl, null, da
122 msg[0] = tag;
123 msg[1] = inputFileUrl;
124 msg[2] = inputFileUrl;
125 msg[3] = null;
126 msg[4] = data;
127 sp.send(msg);
128 return;
kasperl 2016/12/08 11:44:27 What's the intent with this return?
129 })
130 .catchError((e) {
131 var msg = new List(5);
kasperl 2016/12/08 11:44:27 sp.send([-tag, inputFileUrl, inputFileUrl, null, e
132 msg[0] = -tag;
133 msg[1] = inputFileUrl;
134 msg[2] = inputFileUrl;
135 msg[3] = null;
136 msg[4] = e.toString();
137 sp.send(msg);
138 });
139 }
140
141
142 main() {
143 scriptLoadPort.handler = _processLoadRequest;
144 Timer.run(() {});
145 return scriptLoadPort;
146 }
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698