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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

Issue 1271953003: dart2js: Add a header to the output of the startup emitter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 dart2js.js_emitter.startup_emitter.model_emitter; 5 library dart2js.js_emitter.startup_emitter.model_emitter;
6 6
7 import 'dart:convert' show JsonEncoder; 7 import 'dart:convert' show JsonEncoder;
8 8
9 import '../../common.dart'; 9 import '../../common.dart';
10 10
(...skipping 16 matching lines...) Expand all
27 JavaScriptBackend, 27 JavaScriptBackend,
28 Namer, 28 Namer,
29 ConstantEmitter; 29 ConstantEmitter;
30 30
31 import '../../util/util.dart' show 31 import '../../util/util.dart' show
32 NO_LOCATION_SPANNABLE; 32 NO_LOCATION_SPANNABLE;
33 33
34 import '../../util/uri_extras.dart' show 34 import '../../util/uri_extras.dart' show
35 relativize; 35 relativize;
36 36
37 import '../headers.dart';
37 import '../js_emitter.dart' show AstContainer, NativeEmitter; 38 import '../js_emitter.dart' show AstContainer, NativeEmitter;
38 39
39 import 'package:js_runtime/shared/embedded_names.dart' show 40 import 'package:js_runtime/shared/embedded_names.dart' show
40 CLASS_FIELDS_EXTRACTOR, 41 CLASS_FIELDS_EXTRACTOR,
41 CLASS_ID_EXTRACTOR, 42 CLASS_ID_EXTRACTOR,
42 CREATE_NEW_ISOLATE, 43 CREATE_NEW_ISOLATE,
43 DEFERRED_INITIALIZED, 44 DEFERRED_INITIALIZED,
44 DEFERRED_LIBRARY_URIS, 45 DEFERRED_LIBRARY_URIS,
45 DEFERRED_LIBRARY_HASHES, 46 DEFERRED_LIBRARY_HASHES,
46 GET_TYPE_FROM_NAME, 47 GET_TYPE_FROM_NAME,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 212
212 if (compiler.deferredMapUri != null) { 213 if (compiler.deferredMapUri != null) {
213 writeDeferredMap(); 214 writeDeferredMap();
214 } 215 }
215 216
216 // Return the total program size. 217 // Return the total program size.
217 return outputBuffers.values.fold(0, (a, b) => a + b.length); 218 return outputBuffers.values.fold(0, (a, b) => a + b.length);
218 } 219 }
219 220
220 /// Generates a simple header that provides the compiler's build id. 221 /// Generates a simple header that provides the compiler's build id.
221 String buildGeneratedBy(compiler) { 222 String buildGeneratedBy() {
222 var suffix = ''; 223 return new jsAst.Comment(generatedBy(compiler));
Siggi Cherem (dart-lang) 2015/08/04 16:42:48 should we add an argument to generatedBy so we can
floitsch 2015/08/05 11:46:50 I added a 'flavor' argument to 'generatedBy'. That
Siggi Cherem (dart-lang) 2015/08/05 15:53:36 I have a feeling that all flags might be too noisy
223 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
224 return '// Generated by dart2js (fast startup), '
225 'the Dart to JavaScript compiler$suffix.\n';
226 } 224 }
227 225
228 /// Writes all deferred fragment's code into files. 226 /// Writes all deferred fragment's code into files.
229 /// 227 ///
230 /// Returns a map from fragment to its hashcode (as used for the deferred 228 /// Returns a map from fragment to its hashcode (as used for the deferred
231 /// library code). 229 /// library code).
232 /// 230 ///
233 /// Updates the shared [outputBuffers] field with the output. 231 /// Updates the shared [outputBuffers] field with the output.
234 Map<DeferredFragment, String> writeDeferredFragments( 232 Map<DeferredFragment, String> writeDeferredFragments(
235 Map<DeferredFragment, js.Expression> fragmentsCode) { 233 Map<DeferredFragment, js.Expression> fragmentsCode) {
(...skipping 15 matching lines...) Expand all
251 if (shouldGenerateSourceMap) { 249 if (shouldGenerateSourceMap) {
252 lineColumnCollector = new LineColumnCollector(); 250 lineColumnCollector = new LineColumnCollector();
253 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; 251 codeOutputListeners = <CodeOutputListener>[lineColumnCollector];
254 } 252 }
255 253
256 CodeOutput mainOutput = new StreamCodeOutput( 254 CodeOutput mainOutput = new StreamCodeOutput(
257 compiler.outputProvider('', 'js'), 255 compiler.outputProvider('', 'js'),
258 codeOutputListeners); 256 codeOutputListeners);
259 outputBuffers[fragment] = mainOutput; 257 outputBuffers[fragment] = mainOutput;
260 258
261 mainOutput.addBuffer(js.prettyPrint(code, compiler, 259 js.Program program = new js.Program([
260 new js.Comment(generatedBy(compiler)),
261 new js.Comment(HOOKS_API_USAGE),
262 code]);
263
264 mainOutput.addBuffer(js.prettyPrint(program, compiler,
262 monitor: compiler.dumpInfoTask)); 265 monitor: compiler.dumpInfoTask));
263 266
264 if (shouldGenerateSourceMap) { 267 if (shouldGenerateSourceMap) {
265 mainOutput.add( 268 mainOutput.add(
266 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri)); 269 generateSourceMapTag(compiler.sourceMapUri, compiler.outputUri));
267 } 270 }
268 271
269 mainOutput.close(); 272 mainOutput.close();
270 273
271 if (shouldGenerateSourceMap) { 274 if (shouldGenerateSourceMap) {
(...skipping 28 matching lines...) Expand all
300 303
301 // The [code] contains the function that must be invoked when the deferred 304 // The [code] contains the function that must be invoked when the deferred
302 // hunk is loaded. 305 // hunk is loaded.
303 // That function must be in a map from its hashcode to the function. Since 306 // That function must be in a map from its hashcode to the function. Since
304 // we don't know the hash before we actually emit the code we store the 307 // we don't know the hash before we actually emit the code we store the
305 // function in a temporary field first: 308 // function in a temporary field first:
306 // 309 //
307 // deferredInitializer.current = <pretty-printed code>; 310 // deferredInitializer.current = <pretty-printed code>;
308 // deferredInitializer[<hash>] = deferredInitializer.current; 311 // deferredInitializer[<hash>] = deferredInitializer.current;
309 312
310 output.add('\n${deferredInitializersGlobal}.current = '); 313 js.Program program = new js.Program([
314 new js.Comment(generatedBy(compiler)),
315 js.js.statement('$deferredInitializersGlobal.current = #', code)]);
311 316
312 output.addBuffer(js.prettyPrint(code, compiler, 317 output.addBuffer(js.prettyPrint(program, compiler,
313 monitor: compiler.dumpInfoTask)); 318 monitor: compiler.dumpInfoTask));
314 319
315 // Make a unique hash of the code (before the sourcemaps are added) 320 // Make a unique hash of the code (before the sourcemaps are added)
316 // This will be used to retrieve the initializing function from the global 321 // This will be used to retrieve the initializing function from the global
317 // variable. 322 // variable.
318 String hash = hasher.getHash(); 323 String hash = hasher.getHash();
319 324
320 // Now we copy the deferredInitializer.current into its correct hash. 325 // Now we copy the deferredInitializer.current into its correct hash.
321 output.add('\n${deferredInitializersGlobal}["$hash"] = ' 326 output.add('\n${deferredInitializersGlobal}["$hash"] = '
322 '${deferredInitializersGlobal}.current'); 327 '${deferredInitializersGlobal}.current');
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Json does not support comments, so we embed the explanation in the 394 // Json does not support comments, so we embed the explanation in the
390 // data. 395 // data.
391 mapping["_comment"] = "This mapping shows which compiled `.js` files are " 396 mapping["_comment"] = "This mapping shows which compiled `.js` files are "
392 "needed for a given deferred library import."; 397 "needed for a given deferred library import.";
393 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); 398 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap());
394 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map') 399 compiler.outputProvider(compiler.deferredMapUri.path, 'deferred_map')
395 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) 400 ..add(const JsonEncoder.withIndent(" ").convert(mapping))
396 ..close(); 401 ..close();
397 } 402 }
398 } 403 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698