Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/compiler.dart

Issue 11304021: Add NativeEnqueuer to work with the Enqueuer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review fixes Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * If true, print a warning for each method that was resolved, but not 8 * If true, print a warning for each method that was resolved, but not
9 * compiled. 9 * compiled.
10 */ 10 */
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 : this.constantSystem = constantSystem; 67 : this.constantSystem = constantSystem;
68 68
69 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) { 69 void enqueueAllTopLevelFunctions(LibraryElement lib, Enqueuer world) {
70 lib.forEachExport((Element e) { 70 lib.forEachExport((Element e) {
71 if (e.isFunction()) world.addToWorkList(e); 71 if (e.isFunction()) world.addToWorkList(e);
72 }); 72 });
73 } 73 }
74 74
75 void enqueueHelpers(Enqueuer world); 75 void enqueueHelpers(Enqueuer world);
76 void codegen(WorkItem work); 76 void codegen(WorkItem work);
77 void processNativeClasses(Enqueuer world, 77
78 Collection<LibraryElement> libraries); 78 // The backend determines the native resolution enqueuer, with a no-op
79 // default, so tools like dart2dart can ignore the native classes.
80 native.NativeEnqueuer nativeResolutionEnqueuer(world) {
81 return new native.NativeEnqueuer();
82 }
83 native.NativeEnqueuer nativeCodegenEnqueuer(world) {
84 return new native.NativeEnqueuer();
85 }
86
79 void assembleProgram(); 87 void assembleProgram();
80 List<CompilerTask> get tasks; 88 List<CompilerTask> get tasks;
81 89
82 // TODO(ahe,karlklose): rename this? 90 // TODO(ahe,karlklose): rename this?
83 void dumpInferredTypes() {} 91 void dumpInferredTypes() {}
84 92
85 ItemCompilationContext createItemCompilationContext() { 93 ItemCompilationContext createItemCompilationContext() {
86 return new ItemCompilationContext(); 94 return new ItemCompilationContext();
87 } 95 }
88 96
89 SourceString getCheckedModeHelper(DartType type) => null; 97 SourceString getCheckedModeHelper(DartType type) => null;
90 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} 98 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {}
91 99
92 Element getInterceptor(Selector selector); 100 Element getInterceptor(Selector selector);
93 } 101 }
94 102
95 abstract class Compiler implements DiagnosticListener { 103 abstract class Compiler implements DiagnosticListener {
96 final Map<String, LibraryElement> libraries; 104 final Map<String, LibraryElement> libraries;
97 int nextFreeClassId = 0; 105 int nextFreeClassId = 0;
98 World world; 106 World world;
99 String assembledCode; 107 String assembledCode;
100 Types types; 108 Types types;
101 109
102 final bool enableMinification; 110 final bool enableMinification;
103 final bool enableTypeAssertions; 111 final bool enableTypeAssertions;
104 final bool enableUserAssertions; 112 final bool enableUserAssertions;
105 final bool enableConcreteTypeInference; 113 final bool enableConcreteTypeInference;
114 final bool enableNativeLiveTypeAnalysis;
106 115
107 bool disableInlining = false; 116 bool disableInlining = false;
108 117
109 final Tracer tracer; 118 final Tracer tracer;
110 119
111 CompilerTask measuredTask; 120 CompilerTask measuredTask;
112 Element _currentElement; 121 Element _currentElement;
113 LibraryElement coreLibrary; 122 LibraryElement coreLibrary;
114 LibraryElement isolateLibrary; 123 LibraryElement isolateLibrary;
115 LibraryElement jsHelperLibrary; 124 LibraryElement jsHelperLibrary;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 212
204 bool compilationFailed = false; 213 bool compilationFailed = false;
205 214
206 bool hasCrashed = false; 215 bool hasCrashed = false;
207 216
208 Compiler({this.tracer: const Tracer(), 217 Compiler({this.tracer: const Tracer(),
209 this.enableTypeAssertions: false, 218 this.enableTypeAssertions: false,
210 this.enableUserAssertions: false, 219 this.enableUserAssertions: false,
211 this.enableConcreteTypeInference: false, 220 this.enableConcreteTypeInference: false,
212 this.enableMinification: false, 221 this.enableMinification: false,
222 this.enableNativeLiveTypeAnalysis: false,
213 bool emitJavaScript: true, 223 bool emitJavaScript: true,
214 bool generateSourceMap: true, 224 bool generateSourceMap: true,
215 bool disallowUnsafeEval: false, 225 bool disallowUnsafeEval: false,
216 List<String> strips: const []}) 226 List<String> strips: const []})
217 : libraries = new Map<String, LibraryElement>(), 227 : libraries = new Map<String, LibraryElement>(),
218 progress = new Stopwatch() { 228 progress = new Stopwatch() {
219 progress.start(); 229 progress.start();
220 world = new World(this); 230 world = new World(this);
221 scanner = new ScannerTask(this); 231 scanner = new ScannerTask(this);
222 dietParser = new DietParserTask(this); 232 dietParser = new DietParserTask(this);
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 reportFatalError('Could not find $MAIN', mainApp); 518 reportFatalError('Could not find $MAIN', mainApp);
509 } else { 519 } else {
510 if (!main.isFunction()) reportFatalError('main is not a function', main); 520 if (!main.isFunction()) reportFatalError('main is not a function', main);
511 FunctionElement mainMethod = main; 521 FunctionElement mainMethod = main;
512 FunctionSignature parameters = mainMethod.computeSignature(this); 522 FunctionSignature parameters = mainMethod.computeSignature(this);
513 parameters.forEachParameter((Element parameter) { 523 parameters.forEachParameter((Element parameter) {
514 reportFatalError('main cannot have parameters', parameter); 524 reportFatalError('main cannot have parameters', parameter);
515 }); 525 });
516 } 526 }
517 527
528 enqueuer.resolution.nativeEnqueuer =
529 backend.nativeResolutionEnqueuer(enqueuer.resolution);
ngeoffray 2012/11/15 12:49:57 The reason why I asked about why not initializing
530 enqueuer.codegen.nativeEnqueuer =
531 backend.nativeCodegenEnqueuer(enqueuer.codegen);
532
518 log('Resolving...'); 533 log('Resolving...');
519 phase = PHASE_RESOLVING; 534 phase = PHASE_RESOLVING;
520 backend.enqueueHelpers(enqueuer.resolution); 535 backend.enqueueHelpers(enqueuer.resolution);
521 processQueue(enqueuer.resolution, main); 536 processQueue(enqueuer.resolution, main);
522 log('Resolved ${enqueuer.resolution.resolvedElements.length} elements.'); 537 enqueuer.resolution.logSummary(log);
523 538
524 if (compilationFailed) return; 539 if (compilationFailed) return;
525 540
526 log('Inferring types...'); 541 log('Inferring types...');
527 typesTask.onResolutionComplete(main); 542 typesTask.onResolutionComplete(main);
528 543
529 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution 544 // TODO(ahe): Remove this line. Eventually, enqueuer.resolution
530 // should know this. 545 // should know this.
531 world.populate(); 546 world.populate();
532 547
533 log('Compiling...'); 548 log('Compiling...');
534 phase = PHASE_COMPILING; 549 phase = PHASE_COMPILING;
535 processQueue(enqueuer.codegen, main); 550 processQueue(enqueuer.codegen, main);
536 log('Compiled ${codegenWorld.generatedCode.length} methods.'); 551 enqueuer.codegen.logSummary(log);
537 552
538 if (compilationFailed) return; 553 if (compilationFailed) return;
539 554
540 backend.assembleProgram(); 555 backend.assembleProgram();
541 556
542 checkQueues(); 557 checkQueues();
543 } 558 }
544 559
545 void processQueue(Enqueuer world, Element main) { 560 void processQueue(Enqueuer world, Element main) {
546 backend.processNativeClasses(world, libraries.values); 561 world.nativeEnqueuer.processNativeClasses(libraries.values);
547 world.addToWorkList(main); 562 world.addToWorkList(main);
548 progress.reset(); 563 progress.reset();
549 world.forEach((WorkItem work) { 564 world.forEach((WorkItem work) {
550 withCurrentElement(work.element, () => work.run(this, world)); 565 withCurrentElement(work.element, () => work.run(this, world));
551 }); 566 });
552 world.queueIsClosed = true; 567 world.queueIsClosed = true;
553 if (compilationFailed) return; 568 if (compilationFailed) return;
554 assert(world.checkNoEnqueuedInvokedInstanceMethods()); 569 assert(world.checkNoEnqueuedInvokedInstanceMethods());
555 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) { 570 if (DUMP_INFERRED_TYPES && phase == PHASE_COMPILING) {
556 backend.dumpInferredTypes(); 571 backend.dumpInferredTypes();
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 // TODO(johnniwinther): Use [spannable] and [message] to provide better 918 // TODO(johnniwinther): Use [spannable] and [message] to provide better
904 // information on assertion errors. 919 // information on assertion errors.
905 if (condition is Function){ 920 if (condition is Function){
906 condition = condition(); 921 condition = condition();
907 } 922 }
908 if (spannable == null || !condition) { 923 if (spannable == null || !condition) {
909 throw new SpannableAssertionFailure(spannable, message); 924 throw new SpannableAssertionFailure(spannable, message);
910 } 925 }
911 return true; 926 return true;
912 } 927 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698