OLD | NEW |
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 library dart2js.new_js_emitter.model_emitter; | 5 library dart2js.new_js_emitter.model_emitter; |
6 | 6 |
7 import '../../dart2jslib.dart' show Compiler; | 7 import '../../dart2jslib.dart' show Compiler; |
8 import '../../js/js.dart' as js; | 8 import '../../js/js.dart' as js; |
9 import '../../js_backend/js_backend.dart' show | 9 import '../../js_backend/js_backend.dart' show |
10 JavaScriptBackend, | 10 JavaScriptBackend, |
(...skipping 20 matching lines...) Expand all Loading... |
31 r"$__dart_deferred_initializers__"; | 31 r"$__dart_deferred_initializers__"; |
32 | 32 |
33 static const String deferredExtension = "part.js"; | 33 static const String deferredExtension = "part.js"; |
34 | 34 |
35 ModelEmitter(Compiler compiler, Namer namer) | 35 ModelEmitter(Compiler compiler, Namer namer) |
36 : this.compiler = compiler, | 36 : this.compiler = compiler, |
37 this.namer = namer, | 37 this.namer = namer, |
38 constantEmitter = | 38 constantEmitter = |
39 new ConstantEmitter(compiler, namer, makeConstantListTemplate); | 39 new ConstantEmitter(compiler, namer, makeConstantListTemplate); |
40 | 40 |
41 void emitProgram(Program program) { | 41 int emitProgram(Program program) { |
42 List<Output> outputs = program.outputs; | 42 List<Output> outputs = program.outputs; |
43 MainOutput mainUnit = outputs.first; | 43 MainOutput mainUnit = outputs.first; |
44 js.Statement mainAst = emitMainUnit(program); | 44 js.Statement mainAst = emitMainUnit(program); |
45 String mainCode = js.prettyPrint(mainAst, compiler).getText(); | 45 String mainCode = js.prettyPrint(mainAst, compiler).getText(); |
46 compiler.outputProvider(mainUnit.outputFileName, 'js') | 46 compiler.outputProvider(mainUnit.outputFileName, 'js') |
47 ..add(buildGeneratedBy(compiler)) | 47 ..add(buildGeneratedBy(compiler)) |
48 ..add(mainCode) | 48 ..add(mainCode) |
49 ..close(); | 49 ..close(); |
50 compiler.assembledCode = mainCode; | 50 int totalSize = mainCode.length; |
51 | 51 |
52 outputs.skip(1).forEach((DeferredOutput deferredUnit) { | 52 outputs.skip(1).forEach((DeferredOutput deferredUnit) { |
53 js.Expression ast = emitDeferredUnit(deferredUnit, mainUnit.holders); | 53 js.Expression ast = emitDeferredUnit(deferredUnit, mainUnit.holders); |
54 String code = js.prettyPrint(ast, compiler).getText(); | 54 String code = js.prettyPrint(ast, compiler).getText(); |
| 55 totalSize += code.length; |
55 compiler.outputProvider(deferredUnit.outputFileName, deferredExtension) | 56 compiler.outputProvider(deferredUnit.outputFileName, deferredExtension) |
56 ..add(code) | 57 ..add(code) |
57 ..close(); | 58 ..close(); |
58 }); | 59 }); |
| 60 return totalSize; |
59 } | 61 } |
60 | 62 |
61 js.LiteralString unparse(Compiler compiler, js.Expression value) { | 63 js.LiteralString unparse(Compiler compiler, js.Expression value) { |
62 String text = js.prettyPrint(value, compiler).getText(); | 64 String text = js.prettyPrint(value, compiler).getText(); |
63 if (value is js.Fun) text = '($text)'; | 65 if (value is js.Fun) text = '($text)'; |
64 return js.js.escapedString(text); | 66 return js.js.escapedString(text); |
65 } | 67 } |
66 | 68 |
67 String buildGeneratedBy(compiler) { | 69 String buildGeneratedBy(compiler) { |
68 var suffix = ''; | 70 var suffix = ''; |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 546 |
545 var end = Date.now(); | 547 var end = Date.now(); |
546 print('Setup: ' + (end - start) + ' ms.'); | 548 print('Setup: ' + (end - start) + ' ms.'); |
547 | 549 |
548 #main(); // Start main. | 550 #main(); // Start main. |
549 | 551 |
550 }(Date.now(), #code) | 552 }(Date.now(), #code) |
551 }"""; | 553 }"""; |
552 | 554 |
553 } | 555 } |
OLD | NEW |