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

Unified Diff: pkg/compiler/lib/src/js_emitter/program_builder/collector.dart

Issue 1227643003: dart2js: Move most of the code_emitter_task code into the program-builder. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Upload 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
Index: pkg/compiler/lib/src/js_emitter/program_builder/collector.dart
diff --git a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart b/pkg/compiler/lib/src/js_emitter/program_builder/collector.dart
similarity index 63%
copy from pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
copy to pkg/compiler/lib/src/js_emitter/program_builder/collector.dart
index b8fa032d80e5530d90643eef59232bdb439b2655..eb8326de31aba227af0bf448c7ba72c31b05e72d 100644
--- a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
+++ b/pkg/compiler/lib/src/js_emitter/program_builder/collector.dart
@@ -1,10 +1,8 @@
-// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-part of dart2js.js_emitter;
-
-const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter");
+part of dart2js.js_emitter.program_builder;
/**
* Generates the code for all used classes in the program. Static fields (even
@@ -12,14 +10,16 @@ const USE_LAZY_EMITTER = const bool.fromEnvironment("dart2js.use.lazy.emitter");
*
* The code for the containing (used) methods must exist in the `universe`.
*/
-class CodeEmitterTask extends CompilerTask {
+class Collector {
// TODO(floitsch): the code-emitter task should not need a namer.
final Namer namer;
- final TypeTestRegistry typeTestRegistry;
- NativeEmitter nativeEmitter;
- MetadataCollector metadataCollector;
- OldEmitter oldEmitter;
- Emitter emitter;
+ final Compiler compiler;
+ final Set<ClassElement> rtiNeededClasses;
+ final Emitter emitter;
+ // TODO(floitsch): remove this field.
+ // The field is untyped, because we don't want to import the full emitter
+ // class.
+ final oldEmitter;
final Set<ClassElement> neededClasses = new Set<ClassElement>();
Set<ClassElement> classesOnlyNeededForRti;
@@ -41,98 +41,12 @@ class CodeEmitterTask extends CompilerTask {
final List<ClassElement> nativeClassesAndSubclasses = <ClassElement>[];
- /// Records if a type variable is read dynamically for type tests.
- final Set<TypeVariableElement> readTypeVariables =
- new Set<TypeVariableElement>();
-
List<TypedefElement> typedefsNeededForReflection;
JavaScriptBackend get backend => compiler.backend;
- CodeEmitterTask(Compiler compiler, Namer namer, bool generateSourceMap)
- : super(compiler),
- this.namer = namer,
- this.typeTestRegistry = new TypeTestRegistry(compiler) {
- nativeEmitter = new NativeEmitter(this);
- oldEmitter = new OldEmitter(compiler, namer, generateSourceMap, this);
- emitter = USE_LAZY_EMITTER
- ? new lazy_js_emitter.Emitter(compiler, namer, nativeEmitter)
- : oldEmitter;
- metadataCollector = new MetadataCollector(compiler, emitter);
- }
-
- String get name => 'Code emitter';
-
- /// Returns the closure expression of a static function.
- jsAst.Expression isolateStaticClosureAccess(FunctionElement element) {
- return emitter.isolateStaticClosureAccess(element);
- }
-
- /// Returns the JS function that must be invoked to get the value of the
- /// lazily initialized static.
- jsAst.Expression isolateLazyInitializerAccess(FieldElement element) {
- return emitter.isolateLazyInitializerAccess(element);
- }
-
- /// Returns the JS code for accessing the embedded [global].
- jsAst.Expression generateEmbeddedGlobalAccess(String global) {
- return emitter.generateEmbeddedGlobalAccess(global);
- }
-
- /// Returns the JS code for accessing the given [constant].
- jsAst.Expression constantReference(ConstantValue constant) {
- return emitter.constantReference(constant);
- }
-
- jsAst.Expression staticFieldAccess(FieldElement e) {
- return emitter.staticFieldAccess(e);
- }
-
- /// Returns the JS function representing the given function.
- ///
- /// The function must be invoked and can not be used as closure.
- jsAst.Expression staticFunctionAccess(FunctionElement e) {
- return emitter.staticFunctionAccess(e);
- }
-
- /// Returns the JS constructor of the given element.
- ///
- /// The returned expression must only be used in a JS `new` expression.
- jsAst.Expression constructorAccess(ClassElement e) {
- return emitter.constructorAccess(e);
- }
-
- /// Returns the JS prototype of the given class [e].
- jsAst.Expression prototypeAccess(ClassElement e,
- {bool hasBeenInstantiated: false}) {
- return emitter.prototypeAccess(e, hasBeenInstantiated);
- }
-
- /// Returns the JS prototype of the given interceptor class [e].
- jsAst.Expression interceptorPrototypeAccess(ClassElement e) {
- return jsAst.js('#.prototype', interceptorClassAccess(e));
- }
-
- /// Returns the JS constructor of the given interceptor class [e].
- jsAst.Expression interceptorClassAccess(ClassElement e) {
- return emitter.interceptorClassAccess(e);
- }
-
- /// Returns the JS expression representing the type [e].
- ///
- /// The given type [e] might be a Typedef.
- jsAst.Expression typeAccess(Element e) {
- return emitter.typeAccess(e);
- }
-
- /// Returns the JS template for the given [builtin].
- jsAst.Template builtinTemplateFor(JsBuiltin builtin) {
- return emitter.templateForBuiltin(builtin);
- }
-
- void registerReadTypeVariable(TypeVariableElement element) {
- readTypeVariables.add(element);
- }
+ Collector(this.compiler, this.namer, this.rtiNeededClasses,
+ this.emitter, this.oldEmitter);
Set<ClassElement> computeInterceptorsReferencedFromConstants() {
Set<ClassElement> classes = new Set<ClassElement>();
@@ -217,8 +131,8 @@ class CodeEmitterTask extends CompilerTask {
backend.retainMetadataOf(cls);
oldEmitter.classEmitter.visitFields(cls, false,
(Element member,
- jsAst.Name name,
- jsAst.Name accessorName,
+ js.Name name,
+ js.Name accessorName,
bool needsGetter,
bool needsSetter,
bool needsCheckedSetter) {
@@ -254,7 +168,7 @@ class CodeEmitterTask extends CompilerTask {
}
/// Compute all the classes and typedefs that must be emitted.
- void computeNeededDeclarations(Set<ClassElement> rtiNeededClasses) {
+ void computeNeededDeclarations() {
// Compute needed typedefs.
typedefsNeededForReflection = Elements.sortedByPosition(
compiler.world.allTypedefs
@@ -365,8 +279,8 @@ class CodeEmitterTask extends CompilerTask {
.where(compiler.codegenWorld.allReferencedStaticFields.contains);
for (Element element in Elements.sortedByPosition(staticNonFinalFields)) {
List<VariableElement> list = outputStaticNonFinalFieldLists.putIfAbsent(
- compiler.deferredLoadTask.outputUnitForElement(element),
- () => new List<VariableElement>());
+ compiler.deferredLoadTask.outputUnitForElement(element),
+ () => new List<VariableElement>());
list.add(element);
}
}
@@ -383,79 +297,11 @@ class CodeEmitterTask extends CompilerTask {
neededClasses.forEach(addSurroundingLibraryToSet);
}
- void computeAllNeededEntities() {
- // Compute the required type checks to know which classes need a
- // 'is$' method.
- typeTestRegistry.computeRequiredTypeChecks();
- // Compute the classes needed by RTI.
- Set<ClassElement> rtiClasses = typeTestRegistry.computeRtiNeededClasses();
-
- computeNeededDeclarations(rtiClasses);
+ void collect() {
+ computeNeededDeclarations();
computeNeededConstants();
computeNeededStatics();
computeNeededStaticNonFinalFields();
computeNeededLibraries();
}
-
- int assembleProgram() {
- return measure(() {
- emitter.invalidateCaches();
-
- computeAllNeededEntities();
-
- ProgramBuilder programBuilder = new ProgramBuilder(compiler, namer, this);
- return emitter.emitProgram(programBuilder);
- });
- }
-}
-
-abstract class Emitter {
- /// Uses the [programBuilder] to generate a model of the program, emits
- /// the program, and returns the size of the generated output.
- int emitProgram(ProgramBuilder programBuilder);
-
- /// Returns the JS function that must be invoked to get the value of the
- /// lazily initialized static.
- jsAst.Expression isolateLazyInitializerAccess(FieldElement element);
-
- /// Returns the closure expression of a static function.
- jsAst.Expression isolateStaticClosureAccess(FunctionElement element);
-
- /// Returns the JS code for accessing the embedded [global].
- jsAst.Expression generateEmbeddedGlobalAccess(String global);
-
- /// Returns the JS function representing the given function.
- ///
- /// The function must be invoked and can not be used as closure.
- jsAst.Expression staticFunctionAccess(FunctionElement element);
-
- jsAst.Expression staticFieldAccess(FieldElement element);
-
- /// Returns the JS constructor of the given element.
- ///
- /// The returned expression must only be used in a JS `new` expression.
- jsAst.Expression constructorAccess(ClassElement e);
-
- /// Returns the JS prototype of the given class [e].
- jsAst.Expression prototypeAccess(ClassElement e, bool hasBeenInstantiated);
-
- /// Returns the JS constructor of the given interceptor class [e].
- jsAst.Expression interceptorClassAccess(ClassElement e);
-
- /// Returns the JS expression representing the type [e].
- jsAst.Expression typeAccess(Element e);
-
- /// Returns the JS expression representing a function that returns 'null'
- jsAst.Expression generateFunctionThatReturnsNull();
-
- int compareConstants(ConstantValue a, ConstantValue b);
- bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant);
-
- /// Returns the JS code for accessing the given [constant].
- jsAst.Expression constantReference(ConstantValue constant);
-
- /// Returns the JS template for the given [builtin].
- jsAst.Template templateForBuiltin(JsBuiltin builtin);
-
- void invalidateCaches();
-}
+}

Powered by Google App Engine
This is Rietveld 408576698