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

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

Issue 1229913002: dart2js: add FragmentEmitter for startup-emitter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comment. Created 5 years, 5 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
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../../constants/values.dart' show ConstantValue, FunctionConstantValue; 7 import '../../constants/values.dart' show ConstantValue, FunctionConstantValue;
8 import '../../dart2jslib.dart' show Compiler; 8 import '../../dart2jslib.dart' show Compiler;
9 import '../../elements/elements.dart' show ClassElement, FunctionElement; 9 import '../../elements/elements.dart' show ClassElement, FunctionElement;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 17 matching lines...) Expand all
28 LEAF_TAGS, 28 LEAF_TAGS,
29 MANGLED_GLOBAL_NAMES, 29 MANGLED_GLOBAL_NAMES,
30 METADATA, 30 METADATA,
31 NATIVE_SUPERCLASS_TAG_NAME, 31 NATIVE_SUPERCLASS_TAG_NAME,
32 TYPE_TO_INTERCEPTOR_MAP, 32 TYPE_TO_INTERCEPTOR_MAP,
33 TYPES; 33 TYPES;
34 34
35 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode; 35 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
36 import '../model.dart'; 36 import '../model.dart';
37 37
38 part 'fragment_emitter.dart';
39
38 class ModelEmitter { 40 class ModelEmitter {
39 final Compiler compiler; 41 final Compiler compiler;
40 final Namer namer; 42 final Namer namer;
41 ConstantEmitter constantEmitter; 43 ConstantEmitter constantEmitter;
42 final NativeEmitter nativeEmitter; 44 final NativeEmitter nativeEmitter;
43 45
44 JavaScriptBackend get backend => compiler.backend; 46 JavaScriptBackend get backend => compiler.backend;
45 47
46 /// For deferred loading we communicate the initializers via this global var. 48 /// For deferred loading we communicate the initializers via this global var.
47 static const String deferredInitializersGlobal = 49 static const String deferredInitializersGlobal =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // We are only interested in the "isInlined" part, but it does not hurt to 119 // We are only interested in the "isInlined" part, but it does not hurt to
118 // test for the other predicates. 120 // test for the other predicates.
119 if (isConstantInlinedOrAlreadyEmitted(value)) { 121 if (isConstantInlinedOrAlreadyEmitted(value)) {
120 return constantEmitter.generate(value); 122 return constantEmitter.generate(value);
121 } 123 }
122 return js.js('#.#', [namer.globalObjectForConstant(value), 124 return js.js('#.#', [namer.globalObjectForConstant(value),
123 namer.constantName(value)]); 125 namer.constantName(value)]);
124 } 126 }
125 127
126 int emitProgram(Program program) { 128 int emitProgram(Program program) {
127 // TODO(floitsch): implement. 129 List<Fragment> fragments = program.fragments;
128 throw new UnimplementedError("startup-emitter.emitProgram"); 130 MainFragment mainFragment = fragments.first;
131
132 int totalSize = 0;
133
134 FragmentEmitter fragmentEmitter =
135 new FragmentEmitter(compiler, namer, backend, constantEmitter, this);
136
137 // We have to emit the deferred fragments first, since we need their
138 // deferred hash (which depends on the output) when emitting the main
139 // fragment.
140 List<js.Expression> fragmentsCode = fragments.skip(1).map(
141 (DeferredFragment deferredFragment) {
142 js.Expression types =
143 program.metadataTypesForOutputUnit(deferredFragment.outputUnit);
144 return fragmentEmitter.emitDeferredFragment(
145 deferredFragment, types, program.holders);
146 }).toList();
147
148 js.Statement mainAst = fragmentEmitter.emitMainFragment(program);
149
150 js.TokenCounter counter = new js.TokenCounter();
151 fragmentsCode.forEach(counter.countTokens);
152 counter.countTokens(mainAst);
153
154 program.finalizers.forEach((js.TokenFinalizer f) => f.finalizeTokens());
155
156 for (int i = 0; i < fragmentsCode.length; ++i) {
157 String code = js.prettyPrint(fragmentsCode[i], compiler).getText();
158 totalSize += code.length;
159 compiler.outputProvider(fragments[i+1].outputFileName, deferredExtension)
160 ..add(code)
161 ..close();
162 }
163
164 String mainCode = js.prettyPrint(mainAst, compiler).getText();
165 compiler.outputProvider(mainFragment.outputFileName, 'js')
166 ..add(buildGeneratedBy(compiler))
167 ..add(mainCode)
168 ..close();
169 totalSize += mainCode.length;
170
171 return totalSize;
172 }
173
174 String buildGeneratedBy(compiler) {
175 var suffix = '';
176 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
177 return '// Generated by dart2js (fast startup), '
178 'the Dart to JavaScript compiler$suffix.\n';
129 } 179 }
130 } 180 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698