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

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(String fileName, String packageConfig, String sdkPath) async {
58
59 if (!checkIsFile(fileName)) {
60 throw "Input file '$fileName' does not exist.";
61 }
62
63 Target target = getTarget("vm", new TargetFlags(strongMode: false));
64 DartOptions dartOptions = new DartOptions(
65 strongMode: false,
66 strongModeSdk: false,
67 sdk: sdkPath,
68 packagePath: packageConfig,
69 customUriMappings: {},
70 declaredVariables: {});
71 DartLoader loader =
72 await new DartLoaderBatch().getLoader(new Repository(), dartOptions);
73 var program = loader.loadProgram(fileName, target: target);
74
75 var errors = loader.errors;
76 if (errors.isNotEmpty) {
77 throw loader.errors.first;
78 }
79
80 // Link program into one file, cf. --link option in dartk
81 target.transformProgram(program);
82
83 return writeProgramToBuffer(program);
84 }
85
86
87 _processLoadRequest(request) {
88 if (verbose) {
89 print("FROM DART KERNEL: load request: $request");
90 print("FROM DART KERNEL: package: ${Platform.packageConfig}");
91 print("FROM DART KERNEL: exec: ${Platform.resolvedExecutable}");
92 }
93 int tag = request[0];
94 SendPort sp = request[1];
95 String inputFileUrl = request[2];
96 Uri scriptUri = Uri.parse(inputFileUrl);
97 Uri packagesUri = Uri.parse(Platform.packageConfig ?? ".packages");
98 Uri patched_sdk = Uri.parse(Platform.resolvedExecutable).resolve("patched_sdk" );
99
100 var parsingDone = parseScript(scriptUri.path, packagesUri.path, patched_sdk.pa th);
101
102 parsingDone
103 .then((data) {
104 var msg = new List(5);
105 msg[0] = tag;
106 msg[1] = inputFileUrl;
107 msg[2] = inputFileUrl;
108 msg[3] = null;
109 msg[4] = data;
110 sp.send(msg);
111 return;
112 })
113 .catchError((e) {
114 var msg = new List(5);
115 msg[0] = -tag;
116 msg[1] = inputFileUrl;
117 msg[2] = inputFileUrl;
118 msg[3] = null;
119 msg[4] = e.toString();
120 sp.send(msg);
121 });
122 }
123
124
125 main() {
126 scriptLoadPort.handler = _processLoadRequest;
127 Timer.run(() {});
128 return scriptLoadPort;
129 }
OLDNEW
« runtime/bin/loader.cc ('K') | « 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