OLD | NEW |
---|---|
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Partial test that the closed world computed from [WorldImpact]s derived from | 5 // Partial test that the closed world computed from [WorldImpact]s derived from |
6 // kernel is equivalent to the original computed from resolution. | 6 // kernel is equivalent to the original computed from resolution. |
7 library dart2js.kernel.compiler_helper; | 7 library dart2js.kernel.compiler_helper; |
8 | 8 |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 import 'dart:io'; | |
10 | 11 |
11 import 'package:compiler/src/commandline_options.dart'; | 12 import 'package:compiler/src/commandline_options.dart'; |
12 import 'package:compiler/src/common.dart'; | 13 import 'package:compiler/src/common.dart'; |
13 import 'package:compiler/src/common/names.dart'; | 14 import 'package:compiler/src/common/names.dart'; |
14 import 'package:compiler/src/common/tasks.dart'; | 15 import 'package:compiler/src/common/tasks.dart'; |
15 import 'package:compiler/src/compiler.dart'; | 16 import 'package:compiler/src/compiler.dart'; |
16 import 'package:compiler/src/elements/elements.dart'; | 17 import 'package:compiler/src/elements/elements.dart'; |
17 import 'package:compiler/src/kernel/element_map.dart'; | 18 import 'package:compiler/src/kernel/element_map.dart'; |
18 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 19 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
19 import 'package:compiler/src/library_loader.dart'; | 20 import 'package:compiler/src/library_loader.dart'; |
20 import 'package:compiler/src/universe/world_builder.dart'; | 21 import 'package:compiler/src/universe/world_builder.dart'; |
21 import 'package:compiler/src/util/util.dart'; | 22 import 'package:compiler/src/util/util.dart'; |
22 import 'package:expect/expect.dart'; | 23 import 'package:expect/expect.dart'; |
23 import 'package:kernel/ast.dart' as ir; | 24 import 'package:kernel/ast.dart' as ir; |
24 import '../memory_compiler.dart'; | 25 import '../memory_compiler.dart'; |
26 import '../../../../pkg/compiler/tool/generate_kernel.dart' as generate; | |
25 | 27 |
26 typedef Future<Compiler> CompileFunction(); | 28 typedef Future<Compiler> CompileFunction(); |
27 | 29 |
28 /// Create multiple compilations for a list of [sources]. | 30 /// Create multiple compilations for a list of [sources]. |
29 /// | 31 /// |
30 /// This methods speeds up testing kernel based compilation by creating the IR | 32 /// This methods speeds up testing kernel based compilation by creating the IR |
31 /// nodes for all [sources] at the same time. The returned list of | 33 /// nodes for all [sources] at the same time. The returned list of |
32 /// [CompileFunction]s compiles one of the [source] at a time using the kernel | 34 /// [CompileFunction]s compiles one of the [source] at a time using the kernel |
33 /// based compiler. | 35 /// based compiler. |
34 /// | 36 /// |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 129 |
128 MemoryDillLibraryLoaderTask(KernelToElementMap elementMap, | 130 MemoryDillLibraryLoaderTask(KernelToElementMap elementMap, |
129 DiagnosticReporter reporter, Measurer measurer, this.program) | 131 DiagnosticReporter reporter, Measurer measurer, this.program) |
130 : super(elementMap, null, null, reporter, measurer); | 132 : super(elementMap, null, null, reporter, measurer); |
131 | 133 |
132 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 134 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
133 {bool skipFileWithPartOfTag: false}) async { | 135 {bool skipFileWithPartOfTag: false}) async { |
134 return createLoadedLibraries(program); | 136 return createLoadedLibraries(program); |
135 } | 137 } |
136 } | 138 } |
139 | |
140 Future<Compiler> compileWithDill( | |
141 Uri entryPoint, Map<String, String> memorySourceFiles, | |
142 {bool printSteps: false}) async { | |
143 if (memorySourceFiles.isNotEmpty) { | |
144 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); | |
145 if (printSteps) { | |
146 print('--- create temp directory $dir -------------------------------'); | |
147 } | |
148 memorySourceFiles.forEach((String name, String source) { | |
149 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); | |
150 }); | |
151 entryPoint = dir.uri.resolve(entryPoint.path); | |
152 } | |
153 if (printSteps) { | |
154 print('---- generate dill -----------------------------------------------'); | |
155 } | |
156 | |
157 Uri dillFile = Uri.parse('$entryPoint.dill'); | |
158 /*ProcessResult processResult = await Process.runSync( | |
Siggi Cherem (dart-lang)
2017/05/05 17:55:57
delete comment?
| |
159 'pkg/compiler/tool/generate_kernel', | |
160 ['--platform=out/ReleaseX64/patched_dart2js_sdk/platform.dill', | |
161 '$entryPoint']); | |
162 if (processResult.exitCode != 0) { | |
163 print(processResult.stderr); | |
164 exit(processResult.exitCode); | |
165 }*/ | |
166 await generate.main([ | |
167 '--platform=out/ReleaseX64/patched_dart2js_sdk/platform.dill', | |
168 '$entryPoint' | |
169 ]); | |
170 | |
171 if (printSteps) { | |
172 print('---- closed world from dill $dillFile ----------------------------'); | |
173 } | |
174 Compiler compiler = compilerFor(entryPoint: dillFile, options: [ | |
175 Flags.analyzeOnly, | |
176 Flags.enableAssertMessage, | |
177 Flags.loadFromDill | |
178 ]); | |
179 ElementResolutionWorldBuilder.useInstantiationMap = true; | |
180 compiler.resolution.retainCachesForTesting = true; | |
181 await compiler.run(dillFile); | |
182 return compiler; | |
183 } | |
OLD | NEW |