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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 785303003: Add option for outputting a deferred loading mapping. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 5 years, 11 months 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 1442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 } 1453 }
1454 }''', 1454 }''',
1455 {"constructorName": constructorName, 1455 {"constructorName": constructorName,
1456 "constructorNameString": js.string(constructorName), 1456 "constructorNameString": js.string(constructorName),
1457 "hasIsolateSupport": hasIsolateSupport, 1457 "hasIsolateSupport": hasIsolateSupport,
1458 "fieldNamesArray": fieldNamesArray})); 1458 "fieldNamesArray": fieldNamesArray}));
1459 1459
1460 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); 1460 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName));
1461 } 1461 }
1462 1462
1463 /// Extracts the output name of the compiler's outputUri.
1464 String deferredPartFileName(OutputUnit outputUnit,
1465 {bool addExtension: true}) {
1466 String outPath = compiler.outputUri != null
1467 ? compiler.outputUri.path
1468 : "out";
1469 String outName = outPath.substring(outPath.lastIndexOf('/') + 1);
1470 String extension = addExtension ? ".part.js" : "";
1471 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) {
1472 return "$outName$extension";
1473 } else {
1474 String name = outputUnit.name;
1475 return "${outName}_$name$extension";
1476 }
1477 }
1478
1479 void emitLibraries(Iterable<LibraryElement> libraries) { 1463 void emitLibraries(Iterable<LibraryElement> libraries) {
1480 if (libraries.isEmpty) return; 1464 if (libraries.isEmpty) return;
1481 1465
1482 // TODO(karlklose): document what kinds of fields this loop adds to the 1466 // TODO(karlklose): document what kinds of fields this loop adds to the
1483 // library class builder. 1467 // library class builder.
1484 for (LibraryElement element in libraries) { 1468 for (LibraryElement element in libraries) {
1485 LibraryElement library = element; 1469 LibraryElement library = element;
1486 ClassBuilder builder = new ClassBuilder(library, namer); 1470 ClassBuilder builder = new ClassBuilder(library, namer);
1487 if (classEmitter.emitFields(library, builder, emitStatics: true)) { 1471 if (classEmitter.emitFields(library, builder, emitStatics: true)) {
1488 jsAst.ObjectInitializer initializer = builder.toObjectInitializer(); 1472 jsAst.ObjectInitializer initializer = builder.toObjectInitializer();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 } 1710 }
1727 1711
1728 // Constants in checked mode call into RTI code to set type information 1712 // Constants in checked mode call into RTI code to set type information
1729 // which may need getInterceptor (and one-shot interceptor) methods, so 1713 // which may need getInterceptor (and one-shot interceptor) methods, so
1730 // we have to make sure that [emitGetInterceptorMethods] and 1714 // we have to make sure that [emitGetInterceptorMethods] and
1731 // [emitOneShotInterceptors] have been called. 1715 // [emitOneShotInterceptors] have been called.
1732 emitCompileTimeConstants(mainBuffer, mainOutputUnit); 1716 emitCompileTimeConstants(mainBuffer, mainOutputUnit);
1733 1717
1734 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes); 1718 emitDeferredBoilerPlate(mainBuffer, deferredLoadHashes);
1735 1719
1720 if (compiler.deferredMapUri != null) {
1721 outputDeferredMap();
1722 }
1723
1736 // Static field initializations require the classes and compile-time 1724 // Static field initializations require the classes and compile-time
1737 // constants to be set up. 1725 // constants to be set up.
1738 emitStaticNonFinalFieldInitializations(mainBuffer, mainOutputUnit); 1726 emitStaticNonFinalFieldInitializations(mainBuffer, mainOutputUnit);
1739 interceptorEmitter.emitInterceptedNames(mainBuffer); 1727 interceptorEmitter.emitInterceptedNames(mainBuffer);
1740 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer); 1728 interceptorEmitter.emitMapTypeToInterceptor(mainBuffer);
1741 emitLazilyInitializedStaticFields(mainBuffer); 1729 emitLazilyInitializedStaticFields(mainBuffer);
1742 1730
1743 mainBuffer.writeln(); 1731 mainBuffer.writeln();
1744 mainBuffer.write(nativeBuffer); 1732 mainBuffer.write(nativeBuffer);
1745 1733
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2086 Map<String, List<String>> deferredLibraryUris = 2074 Map<String, List<String>> deferredLibraryUris =
2087 new Map<String, List<String>>(); 2075 new Map<String, List<String>>();
2088 Map<String, List<String>> deferredLibraryHashes = 2076 Map<String, List<String>> deferredLibraryHashes =
2089 new Map<String, List<String>>(); 2077 new Map<String, List<String>>();
2090 compiler.deferredLoadTask.hunksToLoad.forEach( 2078 compiler.deferredLoadTask.hunksToLoad.forEach(
2091 (String loadId, List<OutputUnit>outputUnits) { 2079 (String loadId, List<OutputUnit>outputUnits) {
2092 List<String> uris = new List<String>(); 2080 List<String> uris = new List<String>();
2093 List<String> hashes = new List<String>(); 2081 List<String> hashes = new List<String>();
2094 deferredLibraryHashes[loadId] = new List<String>(); 2082 deferredLibraryHashes[loadId] = new List<String>();
2095 for (OutputUnit outputUnit in outputUnits) { 2083 for (OutputUnit outputUnit in outputUnits) {
2096 uris.add(deferredPartFileName(outputUnit)); 2084 uris.add(backend.outputFileName("${outputUnit.name}.part.js"));
floitsch 2015/01/05 15:46:19 no. backend.deferredPartFileName(...)
sigurdm 2015/01/06 09:02:20 Done.
2097 hashes.add(deferredLoadHashes[outputUnit]); 2085 hashes.add(deferredLoadHashes[outputUnit]);
2098 } 2086 }
2099 2087
2100 deferredLibraryUris[loadId] = uris; 2088 deferredLibraryUris[loadId] = uris;
2101 deferredLibraryHashes[loadId] = hashes; 2089 deferredLibraryHashes[loadId] = hashes;
2102 }); 2090 });
2103 2091
2104 void emitMapping(String name, Map<String, List<String>> mapping) { 2092 void emitMapping(String name, Map<String, List<String>> mapping) {
2105 List<jsAst.Property> properties = new List<jsAst.Property>(); 2093 List<jsAst.Property> properties = new List<jsAst.Property>();
2106 mapping.forEach((String key, List<String> values) { 2094 mapping.forEach((String key, List<String> values) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2205 } 2193 }
2206 2194
2207 // Make a unique hash of the code (before the sourcemaps are added) 2195 // Make a unique hash of the code (before the sourcemaps are added)
2208 // This will be used to retrieve the initializing function from the global 2196 // This will be used to retrieve the initializing function from the global
2209 // variable. 2197 // variable.
2210 String hash = hashOfString(outputBuffer.getText()); 2198 String hash = hashOfString(outputBuffer.getText());
2211 2199
2212 outputBuffer.write('${deferredInitializers}["$hash"]$_=$_' 2200 outputBuffer.write('${deferredInitializers}["$hash"]$_=$_'
2213 '${deferredInitializers}.current$N'); 2201 '${deferredInitializers}.current$N');
2214 2202
2215 String partPrefix = deferredPartFileName(outputUnit, addExtension: false); 2203 String partPrefix =
2204 backend.outputFileName(outputUnit.name);
2216 if (generateSourceMap) { 2205 if (generateSourceMap) {
2217 Uri mapUri, partUri; 2206 Uri mapUri, partUri;
2218 Uri sourceMapUri = compiler.sourceMapUri; 2207 Uri sourceMapUri = compiler.sourceMapUri;
2219 Uri outputUri = compiler.outputUri; 2208 Uri outputUri = compiler.outputUri;
2220 2209
2221 String partName = "$partPrefix.part"; 2210 String partName = "$partPrefix.part";
2222 2211
2223 if (sourceMapUri != null) { 2212 if (sourceMapUri != null) {
2224 String mapFileName = partName + ".js.map"; 2213 String mapFileName = partName + ".js.map";
2225 List<String> mapSegments = sourceMapUri.pathSegments.toList(); 2214 List<String> mapSegments = sourceMapUri.pathSegments.toList();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 SourceFile compiledFile = new StringSourceFile(null, code); 2252 SourceFile compiledFile = new StringSourceFile(null, code);
2264 SourceMapBuilder sourceMapBuilder = 2253 SourceMapBuilder sourceMapBuilder =
2265 new SourceMapBuilder(sourceMapUri, fileUri, compiledFile); 2254 new SourceMapBuilder(sourceMapUri, fileUri, compiledFile);
2266 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 2255 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
2267 String sourceMap = sourceMapBuilder.build(); 2256 String sourceMap = sourceMapBuilder.build();
2268 compiler.outputProvider(name, 'js.map') 2257 compiler.outputProvider(name, 'js.map')
2269 ..add(sourceMap) 2258 ..add(sourceMap)
2270 ..close(); 2259 ..close();
2271 } 2260 }
2272 2261
2262 void outputDeferredMap() {
2263 Map<String, dynamic> mapping = new Map();
floitsch 2015/01/05 15:46:19 new Map<String, dynamic>
sigurdm 2015/01/06 09:02:20 Done.
2264 // Json does not support comments, so we embed the explanation in the
2265 // data.
2266 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
2267 "needed for a given deferred library import.";
2268 mapping.addAll(compiler.deferredLoadTask.getDeferredMap());
2269 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map')
2270 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
2271 ..close();
2272 }
2273
2273 void invalidateCaches() { 2274 void invalidateCaches() {
2274 if (!compiler.hasIncrementalSupport) return; 2275 if (!compiler.hasIncrementalSupport) return;
2275 if (cachedElements.isEmpty) return; 2276 if (cachedElements.isEmpty) return;
2276 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2277 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2277 if (element.isInstanceMember) { 2278 if (element.isInstanceMember) {
2278 cachedClassBuilders.remove(element.enclosingClass); 2279 cachedClassBuilders.remove(element.enclosingClass);
2279 2280
2280 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2281 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2281 2282
2282 } 2283 }
2283 } 2284 }
2284 } 2285 }
2285 } 2286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698