| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 KernelLibraryBuilder, | 81 KernelLibraryBuilder, |
| 82 KernelNamedTypeBuilder, | 82 KernelNamedTypeBuilder, |
| 83 KernelProcedureBuilder, | 83 KernelProcedureBuilder, |
| 84 LibraryBuilder, | 84 LibraryBuilder, |
| 85 MixinApplicationBuilder, | 85 MixinApplicationBuilder, |
| 86 NamedMixinApplicationBuilder, | 86 NamedMixinApplicationBuilder, |
| 87 NamedTypeBuilder, | 87 NamedTypeBuilder, |
| 88 TypeBuilder, | 88 TypeBuilder, |
| 89 TypeVariableBuilder; | 89 TypeVariableBuilder; |
| 90 | 90 |
| 91 import 'verifier.dart' show verifyProgram; |
| 92 |
| 91 class KernelTarget extends TargetImplementation { | 93 class KernelTarget extends TargetImplementation { |
| 92 final DillTarget dillTarget; | 94 final DillTarget dillTarget; |
| 93 | 95 |
| 94 /// Shared with [CompilerContext]. | 96 /// Shared with [CompilerContext]. |
| 95 final Map<String, Source> uriToSource; | 97 final Map<String, Source> uriToSource; |
| 96 | 98 |
| 97 SourceLoader<Library> loader; | 99 SourceLoader<Library> loader; |
| 98 Program program; | 100 Program program; |
| 99 | 101 |
| 100 final List errors = []; | 102 final List errors = []; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 String message = error.format(); | 209 String message = error.format(); |
| 208 print(message); | 210 print(message); |
| 209 errors.add(message); | 211 errors.add(message); |
| 210 } | 212 } |
| 211 program = erroneousProgram(isFullProgram); | 213 program = erroneousProgram(isFullProgram); |
| 212 return uri == null | 214 return uri == null |
| 213 ? new Future<Program>.value(program) | 215 ? new Future<Program>.value(program) |
| 214 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); | 216 : writeLinkedProgram(uri, program, isFullProgram: isFullProgram); |
| 215 } | 217 } |
| 216 | 218 |
| 217 Future<Program> writeProgram(Uri uri) async { | 219 Future<Program> writeProgram(Uri uri, |
| 220 {bool dumpIr: false, bool verify: false}) async { |
| 218 if (loader.first == null) return null; | 221 if (loader.first == null) return null; |
| 219 if (errors.isNotEmpty) { | 222 if (errors.isNotEmpty) { |
| 220 return handleInputError(uri, null, isFullProgram: true); | 223 return handleInputError(uri, null, isFullProgram: true); |
| 221 } | 224 } |
| 222 try { | 225 try { |
| 223 loader.computeHierarchy(program); | 226 loader.computeHierarchy(program); |
| 224 await loader.buildBodies(); | 227 await loader.buildBodies(); |
| 225 loader.finishStaticInvocations(); | 228 loader.finishStaticInvocations(); |
| 226 finishAllConstructors(); | 229 finishAllConstructors(); |
| 227 loader.finishNativeMethods(); | 230 loader.finishNativeMethods(); |
| 228 transformMixinApplications(); | 231 transformMixinApplications(); |
| 229 // TODO(ahe): Don't call this from two different places. | 232 // TODO(ahe): Don't call this from two different places. |
| 230 setup_builtin_library.transformProgram(program); | 233 setup_builtin_library.transformProgram(program); |
| 231 otherTransformations(); | 234 otherTransformations(); |
| 235 if (dumpIr) this.dumpIr(); |
| 236 if (verify) this.verify(); |
| 232 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); | 237 errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format())); |
| 233 if (errors.isNotEmpty) { | 238 if (errors.isNotEmpty) { |
| 234 return handleInputError(uri, null, isFullProgram: true); | 239 return handleInputError(uri, null, isFullProgram: true); |
| 235 } | 240 } |
| 236 if (uri == null) return program; | 241 if (uri == null) return program; |
| 237 return await writeLinkedProgram(uri, program, isFullProgram: true); | 242 return await writeLinkedProgram(uri, program, isFullProgram: true); |
| 238 } on InputError catch (e) { | 243 } on InputError catch (e) { |
| 239 return handleInputError(uri, e, isFullProgram: true); | 244 return handleInputError(uri, e, isFullProgram: true); |
| 240 } catch (e, s) { | 245 } catch (e, s) { |
| 241 return reportCrash(e, s, loader?.currentUriForCrashReporting); | 246 return reportCrash(e, s, loader?.currentUriForCrashReporting); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 ticker.logMs("Transformed async methods"); | 621 ticker.logMs("Transformed async methods"); |
| 617 } | 622 } |
| 618 | 623 |
| 619 void dumpIr() { | 624 void dumpIr() { |
| 620 StringBuffer sb = new StringBuffer(); | 625 StringBuffer sb = new StringBuffer(); |
| 621 for (Library library in loader.libraries) { | 626 for (Library library in loader.libraries) { |
| 622 Printer printer = new Printer(sb); | 627 Printer printer = new Printer(sb); |
| 623 printer.writeLibraryFile(library); | 628 printer.writeLibraryFile(library); |
| 624 } | 629 } |
| 625 print("$sb"); | 630 print("$sb"); |
| 631 ticker.logMs("Dumped IR"); |
| 632 } |
| 633 |
| 634 void verify() { |
| 635 errors.addAll(verifyProgram(program)); |
| 636 ticker.logMs("Verified program"); |
| 626 } | 637 } |
| 627 } | 638 } |
| 628 | 639 |
| 629 bool isSuperinitializerOrInvalid(Initializer initializer) { | 640 bool isSuperinitializerOrInvalid(Initializer initializer) { |
| 630 return initializer is SuperInitializer || initializer is InvalidInitializer; | 641 return initializer is SuperInitializer || initializer is InvalidInitializer; |
| 631 } | 642 } |
| 632 | 643 |
| 633 bool isRedirectingGenerativeConstructor(Constructor constructor) { | 644 bool isRedirectingGenerativeConstructor(Constructor constructor) { |
| 634 List<Initializer> initializers = constructor.initializers; | 645 List<Initializer> initializers = constructor.initializers; |
| 635 return initializers.length == 1 && | 646 return initializers.length == 1 && |
| (...skipping 10 matching lines...) Expand all Loading... |
| 646 } | 657 } |
| 647 for (Constructor constructor in superclass.constructors) { | 658 for (Constructor constructor in superclass.constructors) { |
| 648 if (constructor.name.name.isEmpty) { | 659 if (constructor.name.name.isEmpty) { |
| 649 return constructor.function.requiredParameterCount == 0 | 660 return constructor.function.requiredParameterCount == 0 |
| 650 ? constructor | 661 ? constructor |
| 651 : null; | 662 : null; |
| 652 } | 663 } |
| 653 } | 664 } |
| 654 return null; | 665 return null; |
| 655 } | 666 } |
| OLD | NEW |