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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
index 5048fe5f5cb7ea9024cd7c2a60ab652a034bcafa..9797dbb60f546d8fd3ce5080dd46d55ac10955cf 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
@@ -35,6 +35,8 @@ import 'package:js_runtime/shared/embedded_names.dart' show
import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
import '../model.dart';
+part 'fragment_emitter.dart';
+
class ModelEmitter {
final Compiler compiler;
final Namer namer;
@@ -124,7 +126,55 @@ class ModelEmitter {
}
int emitProgram(Program program) {
- // TODO(floitsch): implement.
- throw new UnimplementedError("startup-emitter.emitProgram");
+ List<Fragment> fragments = program.fragments;
+ MainFragment mainFragment = fragments.first;
+
+ int totalSize = 0;
+
+ FragmentEmitter fragmentEmitter =
+ new FragmentEmitter(compiler, namer, backend, constantEmitter, this);
+
+ // We have to emit the deferred fragments first, since we need their
+ // deferred hash (which depends on the output) when emitting the main
+ // fragment.
+ List<js.Expression> fragmentsCode = fragments.skip(1).map(
+ (DeferredFragment deferredFragment) {
+ js.Expression types =
+ program.metadataTypesForOutputUnit(deferredFragment.outputUnit);
+ return fragmentEmitter.emitDeferredFragment(
+ deferredFragment, types, program.holders);
+ }).toList();
+
+ js.Statement mainAst = fragmentEmitter.emitMainFragment(program);
+
+ js.TokenCounter counter = new js.TokenCounter();
+ fragmentsCode.forEach(counter.countTokens);
+ counter.countTokens(mainAst);
+
+ program.finalizers.forEach((js.TokenFinalizer f) => f.finalizeTokens());
+
+ for (int i = 0; i < fragmentsCode.length; ++i) {
+ String code = js.prettyPrint(fragmentsCode[i], compiler).getText();
+ totalSize += code.length;
+ compiler.outputProvider(fragments[i+1].outputFileName, deferredExtension)
+ ..add(code)
+ ..close();
+ }
+
+ String mainCode = js.prettyPrint(mainAst, compiler).getText();
+ compiler.outputProvider(mainFragment.outputFileName, 'js')
+ ..add(buildGeneratedBy(compiler))
+ ..add(mainCode)
+ ..close();
+ totalSize += mainCode.length;
+
+ return totalSize;
+ }
+
+ String buildGeneratedBy(compiler) {
+ var suffix = '';
+ if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
+ return '// Generated by dart2js (fast startup), '
+ 'the Dart to JavaScript compiler$suffix.\n';
}
}
« 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