OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 library fasta.compile_platform; | 5 library fasta.compile_platform; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:io' show exitCode; | 9 import 'dart:io' show exitCode, File; |
| 10 |
| 11 import '../../compiler_options.dart' show CompilerOptions; |
| 12 |
| 13 import '../base/processed_options.dart' show ProcessedOptions; |
| 14 |
| 15 import '../kernel_generator_impl.dart' show generateKernel; |
10 | 16 |
11 import 'compiler_command_line.dart' show CompilerCommandLine; | 17 import 'compiler_command_line.dart' show CompilerCommandLine; |
12 | 18 |
13 import 'compiler_context.dart' show CompilerContext; | 19 import 'compiler_context.dart' show CompilerContext; |
14 | 20 |
15 import 'dill/dill_target.dart' show DillTarget; | |
16 | |
17 import 'errors.dart' show InputError; | 21 import 'errors.dart' show InputError; |
18 | 22 |
19 import 'kernel/kernel_target.dart' show KernelTarget; | 23 import 'kernel/utils.dart' show writeProgramToFile; |
20 | |
21 import 'kernel/utils.dart' show printProgramText, writeProgramToFile; | |
22 | 24 |
23 import 'ticker.dart' show Ticker; | 25 import 'ticker.dart' show Ticker; |
24 | 26 |
25 import 'translate_uri.dart' show TranslateUri; | |
26 | |
27 const int iterations = const int.fromEnvironment("iterations", defaultValue: 1); | 27 const int iterations = const int.fromEnvironment("iterations", defaultValue: 1); |
28 | 28 |
29 Future mainEntryPoint(List<String> arguments) async { | 29 Future mainEntryPoint(List<String> arguments) async { |
30 for (int i = 0; i < iterations; i++) { | 30 for (int i = 0; i < iterations; i++) { |
31 if (i > 0) { | 31 if (i > 0) { |
32 print("\n"); | 32 print("\n"); |
33 } | 33 } |
34 try { | 34 try { |
35 await compilePlatform(arguments); | 35 await compilePlatform(arguments); |
36 } on InputError catch (e) { | 36 } on InputError catch (e) { |
(...skipping 12 matching lines...) Expand all Loading... |
49 Uri fullOutput = Uri.base.resolveUri(new Uri.file(c.options.arguments[1])); | 49 Uri fullOutput = Uri.base.resolveUri(new Uri.file(c.options.arguments[1])); |
50 Uri outlineOutput = | 50 Uri outlineOutput = |
51 Uri.base.resolveUri(new Uri.file(c.options.arguments[2])); | 51 Uri.base.resolveUri(new Uri.file(c.options.arguments[2])); |
52 return compilePlatformInternal( | 52 return compilePlatformInternal( |
53 c, ticker, patchedSdk, fullOutput, outlineOutput); | 53 c, ticker, patchedSdk, fullOutput, outlineOutput); |
54 }); | 54 }); |
55 } | 55 } |
56 | 56 |
57 Future compilePlatformInternal(CompilerContext c, Ticker ticker, Uri patchedSdk, | 57 Future compilePlatformInternal(CompilerContext c, Ticker ticker, Uri patchedSdk, |
58 Uri fullOutput, Uri outlineOutput) async { | 58 Uri fullOutput, Uri outlineOutput) async { |
59 if (c.options.strongMode) { | 59 var options = new CompilerOptions() |
| 60 ..strongMode = c.options.strongMode |
| 61 ..sdkRoot = patchedSdk |
| 62 ..packagesFileUri = c.options.packages |
| 63 ..compileSdk = true |
| 64 ..chaseDependencies = true |
| 65 ..target = c.options.target |
| 66 ..debugDump = c.options.dumpIr |
| 67 ..verify = c.options.verify |
| 68 ..verbose = c.options.verbose; |
| 69 |
| 70 if (options.strongMode) { |
60 print("Note: strong mode support is preliminary and may not work."); | 71 print("Note: strong mode support is preliminary and may not work."); |
61 } | 72 } |
62 ticker.isVerbose = c.options.verbose; | 73 if (options.verbose) { |
63 Uri deps = Uri.base.resolveUri(new Uri.file("${fullOutput.toFilePath()}.d")); | |
64 ticker.logMs("Parsed arguments"); | |
65 if (ticker.isVerbose) { | |
66 print("Generating outline of $patchedSdk into $outlineOutput"); | 74 print("Generating outline of $patchedSdk into $outlineOutput"); |
67 print("Compiling $patchedSdk to $fullOutput"); | 75 print("Compiling $patchedSdk to $fullOutput"); |
68 } | 76 } |
69 | 77 |
70 TranslateUri uriTranslator = await TranslateUri | 78 var result = await generateKernel( |
71 .parse(c.fileSystem, patchedSdk, packages: c.options.packages); | 79 new ProcessedOptions(options, false, [Uri.parse('dart:core')]), |
72 ticker.logMs("Read packages file"); | 80 buildSummary: true, |
73 | 81 buildProgram: true); |
74 DillTarget dillTarget = | 82 new File.fromUri(outlineOutput).writeAsBytesSync(result.summary); |
75 new DillTarget(ticker, uriTranslator, c.options.target); | |
76 KernelTarget kernelTarget = | |
77 new KernelTarget(c.fileSystem, dillTarget, uriTranslator, c.uriToSource); | |
78 | |
79 kernelTarget.read(Uri.parse("dart:core")); | |
80 await dillTarget.buildOutlines(); | |
81 var outline = await kernelTarget.buildOutlines(); | |
82 | |
83 await writeProgramToFile(outline, outlineOutput); | |
84 ticker.logMs("Wrote outline to ${outlineOutput.toFilePath()}"); | 83 ticker.logMs("Wrote outline to ${outlineOutput.toFilePath()}"); |
85 | 84 await writeProgramToFile(result.program, fullOutput); |
86 if (exitCode != 0) return null; | |
87 | |
88 var program = await kernelTarget.buildProgram(verify: c.options.verify); | |
89 if (c.options.dumpIr) printProgramText(program); | |
90 await writeProgramToFile(program, fullOutput); | |
91 ticker.logMs("Wrote program to ${fullOutput.toFilePath()}"); | 85 ticker.logMs("Wrote program to ${fullOutput.toFilePath()}"); |
92 await kernelTarget.writeDepsFile(fullOutput, deps); | |
93 } | 86 } |
OLD | NEW |