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.kernel_target; | 5 library fasta.kernel_target; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import 'dart:io' show File, IOSink; | 9 import 'dart:io' show File, IOSink; |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 LibraryBuilder, | 84 LibraryBuilder, |
85 MemberBuilder, | 85 MemberBuilder, |
86 MixinApplicationBuilder, | 86 MixinApplicationBuilder, |
87 NamedMixinApplicationBuilder, | 87 NamedMixinApplicationBuilder, |
88 NamedTypeBuilder, | 88 NamedTypeBuilder, |
89 TypeBuilder, | 89 TypeBuilder, |
90 TypeVariableBuilder; | 90 TypeVariableBuilder; |
91 | 91 |
92 import 'verifier.dart' show verifyProgram; | 92 import 'verifier.dart' show verifyProgram; |
93 | 93 |
94 class KernelTarget extends TargetImplementation { | 94 class KernelTarget extends TargetImplementation { |
ahe
2017/04/27 11:48:31
Would it make sense to have two subclasses of this
Siggi Cherem (dart-lang)
2017/04/28 21:37:20
Done. Thanks for the suggestion. I made the change
| |
95 final bool strongMode; | 95 final bool strongMode; |
96 | 96 |
97 final DillTarget dillTarget; | 97 final DillTarget dillTarget; |
98 | 98 |
99 /// Shared with [CompilerContext]. | 99 /// Shared with [CompilerContext]. |
100 final Map<String, Source> uriToSource; | 100 final Map<String, Source> uriToSource; |
101 | 101 |
102 SourceLoader<Library> loader; | 102 SourceLoader<Library> loader; |
103 Program program; | 103 Program program; |
104 | 104 |
105 final List errors = []; | 105 final List errors = []; |
106 | 106 |
107 final TypeBuilder dynamicType = | 107 final TypeBuilder dynamicType = |
108 new KernelNamedTypeBuilder("dynamic", null, -1, null); | 108 new KernelNamedTypeBuilder("dynamic", null, -1, null); |
109 | 109 |
110 KernelTarget( | 110 KernelTarget(DillTarget dillTarget, TranslateUri uriTranslator, |
111 DillTarget dillTarget, TranslateUri uriTranslator, this.strongMode, | 111 this.strongMode, bool forDart2js, |
112 [Map<String, Source> uriToSource]) | 112 [Map<String, Source> uriToSource]) |
113 : dillTarget = dillTarget, | 113 : dillTarget = dillTarget, |
114 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, | 114 uriToSource = uriToSource ?? CompilerContext.current.uriToSource, |
115 super(dillTarget.ticker, uriTranslator) { | 115 super(dillTarget.ticker, uriTranslator, forDart2js) { |
116 resetCrashReporting(); | 116 resetCrashReporting(); |
117 loader = createLoader(); | 117 loader = createLoader(); |
118 } | 118 } |
119 | 119 |
120 void addError(file, int charOffset, String message) { | 120 void addError(file, int charOffset, String message) { |
121 Uri uri = file is String ? Uri.parse(file) : file; | 121 Uri uri = file is String ? Uri.parse(file) : file; |
122 InputError error = new InputError(uri, charOffset, message); | 122 InputError error = new InputError(uri, charOffset, message); |
123 print(error.format()); | 123 print(error.format()); |
124 errors.add(error); | 124 errors.add(error); |
125 } | 125 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 {bool dumpIr: false, bool verify: false}) async { | 263 {bool dumpIr: false, bool verify: false}) async { |
264 if (loader.first == null) return null; | 264 if (loader.first == null) return null; |
265 if (errors.isNotEmpty) { | 265 if (errors.isNotEmpty) { |
266 return handleInputError(uri, null, isFullProgram: true); | 266 return handleInputError(uri, null, isFullProgram: true); |
267 } | 267 } |
268 try { | 268 try { |
269 await loader.buildBodies(); | 269 await loader.buildBodies(); |
270 loader.finishStaticInvocations(); | 270 loader.finishStaticInvocations(); |
271 finishAllConstructors(); | 271 finishAllConstructors(); |
272 loader.finishNativeMethods(); | 272 loader.finishNativeMethods(); |
273 transformMixinApplications(); | 273 if (forVm) { |
274 // TODO(ahe): Don't call this from two different places. | 274 transformMixinApplications(); |
275 setup_builtin_library.transformProgram(program); | 275 // TODO(ahe): Don't call this from two different places. |
276 otherTransformations(); | 276 setup_builtin_library.transformProgram(program); |
277 otherTransformations(); | |
278 } | |
277 if (dumpIr) this.dumpIr(); | 279 if (dumpIr) this.dumpIr(); |
278 if (verify) this.verify(); | 280 if (verify) this.verify(); |
279 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); | 281 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); |
280 if (errors.isNotEmpty) { | 282 if (errors.isNotEmpty) { |
281 return handleInputError(uri, null, isFullProgram: true); | 283 return handleInputError(uri, null, isFullProgram: true); |
282 } | 284 } |
283 if (uri == null) return program; | 285 if (uri == null) return program; |
284 return await writeLinkedProgram(uri, program, isFullProgram: true); | 286 return await writeLinkedProgram(uri, program, isFullProgram: true); |
285 } on InputError catch (e) { | 287 } on InputError catch (e) { |
286 return handleInputError(uri, e, isFullProgram: true); | 288 return handleInputError(uri, e, isFullProgram: true); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 // that used when there's no fileUri on an element. Instead, ensure all | 383 // that used when there's no fileUri on an element. Instead, ensure all |
382 // elements have a fileUri. | 384 // elements have a fileUri. |
383 uriToSource[""] = new Source(<int>[0], const <int>[]); | 385 uriToSource[""] = new Source(<int>[0], const <int>[]); |
384 Program program = new Program(libraries, uriToSource); | 386 Program program = new Program(libraries, uriToSource); |
385 if (loader.first != null) { | 387 if (loader.first != null) { |
386 Builder builder = loader.first.lookup("main", -1, null); | 388 Builder builder = loader.first.lookup("main", -1, null); |
387 if (builder is KernelProcedureBuilder) { | 389 if (builder is KernelProcedureBuilder) { |
388 program.mainMethod = builder.procedure; | 390 program.mainMethod = builder.procedure; |
389 } | 391 } |
390 } | 392 } |
391 if (errors.isEmpty || dillTarget.isLoaded) { | 393 if (forVm && (errors.isEmpty || dillTarget.isLoaded)) { |
392 setup_builtin_library.transformProgram(program); | 394 setup_builtin_library.transformProgram(program); |
393 } | 395 } |
394 ticker.logMs("Linked program"); | 396 ticker.logMs("Linked program"); |
395 return program; | 397 return program; |
396 } | 398 } |
397 | 399 |
398 Future<Program> writeLinkedProgram(Uri uri, Program program, | 400 Future<Program> writeLinkedProgram(Uri uri, Program program, |
399 {bool isFullProgram}) async { | 401 {bool isFullProgram}) async { |
400 File output = new File.fromUri(uri); | 402 File output = new File.fromUri(uri); |
401 IOSink sink = output.openWrite(); | 403 IOSink sink = output.openWrite(); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 } | 719 } |
718 for (Constructor constructor in superclass.constructors) { | 720 for (Constructor constructor in superclass.constructors) { |
719 if (constructor.name.name.isEmpty) { | 721 if (constructor.name.name.isEmpty) { |
720 return constructor.function.requiredParameterCount == 0 | 722 return constructor.function.requiredParameterCount == 0 |
721 ? constructor | 723 ? constructor |
722 : null; | 724 : null; |
723 } | 725 } |
724 } | 726 } |
725 return null; | 727 return null; |
726 } | 728 } |
OLD | NEW |