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