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

Side by Side Diff: pkg/compiler/lib/src/js_backend/backend.dart

Issue 716823002: Set up a stub pipline for using the new cps-based ir to generate js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of js_backend; 5 part of js_backend;
6 6
7 const VERBOSE_OPTIMIZER_HINTS = false; 7 const VERBOSE_OPTIMIZER_HINTS = false;
8 8
9 class JavaScriptItemCompilationContext extends ItemCompilationContext { 9 class JavaScriptItemCompilationContext extends ItemCompilationContext {
10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 LibraryElement internalLibrary; 90 LibraryElement internalLibrary;
91 91
92 92
93 /// Set of classes that need to be considered for reflection although not 93 /// Set of classes that need to be considered for reflection although not
94 /// otherwise visible during resolution. 94 /// otherwise visible during resolution.
95 Iterable<ClassElement> get classesRequiredForReflection { 95 Iterable<ClassElement> get classesRequiredForReflection {
96 // TODO(herhut): Clean this up when classes needed for rti are tracked. 96 // TODO(herhut): Clean this up when classes needed for rti are tracked.
97 return [closureClass, jsIndexableClass]; 97 return [closureClass, jsIndexableClass];
98 } 98 }
99 99
100 SsaBuilderTask builder; 100 SsaBuilderTask ssaBuilder;
101 CodeGenTask cpsBuilder;
101 SsaOptimizerTask optimizer; 102 SsaOptimizerTask optimizer;
102 SsaCodeGeneratorTask generator; 103 SsaCodeGeneratorTask generator;
103 CodeEmitterTask emitter; 104 CodeEmitterTask emitter;
104 105
105 /** 106 /**
106 * The generated code as a js AST for compiled methods. 107 * The generated code as a js AST for compiled methods.
107 */ 108 */
108 Map<Element, jsAst.Expression> get generatedCode { 109 Map<Element, jsAst.Expression> get generatedCode {
109 return compiler.enqueuer.codegen.generatedCode; 110 return compiler.enqueuer.codegen.generatedCode;
110 } 111 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 */ 324 */
324 final Set<ClassElement> specialOperatorEqClasses = new Set<ClassElement>(); 325 final Set<ClassElement> specialOperatorEqClasses = new Set<ClassElement>();
325 326
326 /** 327 /**
327 * A set of members that are called from subclasses via super. 328 * A set of members that are called from subclasses via super.
328 */ 329 */
329 final Set<FunctionElement> aliasedSuperMembers = 330 final Set<FunctionElement> aliasedSuperMembers =
330 new Setlet<FunctionElement>(); 331 new Setlet<FunctionElement>();
331 332
332 List<CompilerTask> get tasks { 333 List<CompilerTask> get tasks {
333 return <CompilerTask>[builder, optimizer, generator, emitter]; 334 return <CompilerTask>[ssaBuilder, optimizer, generator, emitter];
334 } 335 }
335 336
336 final RuntimeTypes rti; 337 final RuntimeTypes rti;
337 338
338 /// Holds the method "disableTreeShaking" in js_mirrors when 339 /// Holds the method "disableTreeShaking" in js_mirrors when
339 /// dart:mirrors has been loaded. 340 /// dart:mirrors has been loaded.
340 FunctionElement disableTreeShakingMarker; 341 FunctionElement disableTreeShakingMarker;
341 342
342 /// Holds the method "preserveNames" in js_mirrors when 343 /// Holds the method "preserveNames" in js_mirrors when
343 /// dart:mirrors has been loaded. 344 /// dart:mirrors has been loaded.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 JavaScriptResolutionCallbacks resolutionCallbacks; 439 JavaScriptResolutionCallbacks resolutionCallbacks;
439 440
440 JavaScriptBackend(Compiler compiler, bool generateSourceMap) 441 JavaScriptBackend(Compiler compiler, bool generateSourceMap)
441 : namer = determineNamer(compiler), 442 : namer = determineNamer(compiler),
442 oneShotInterceptors = new Map<String, Selector>(), 443 oneShotInterceptors = new Map<String, Selector>(),
443 interceptedElements = new Map<String, Set<Element>>(), 444 interceptedElements = new Map<String, Set<Element>>(),
444 rti = new RuntimeTypes(compiler), 445 rti = new RuntimeTypes(compiler),
445 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 446 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
446 super(compiler) { 447 super(compiler) {
447 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); 448 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap);
448 builder = new SsaBuilderTask(this); 449 ssaBuilder = new SsaBuilderTask(this);
449 optimizer = new SsaOptimizerTask(this); 450 optimizer = new SsaOptimizerTask(this);
450 generator = new SsaCodeGeneratorTask(this); 451 generator = new SsaCodeGeneratorTask(this);
452 cpsBuilder = Compiler.USE_CPS_IR
453 ? new CodeGenTask(compiler)
floitsch 2014/11/12 11:03:20 I prefer "Codegen", but I can see why the "G" shou
sigurdm 2014/11/13 08:29:42 It is renamed to CodeGenerator in the next CL.
454 : null;
451 typeVariableHandler = new TypeVariableHandler(this); 455 typeVariableHandler = new TypeVariableHandler(this);
452 customElementsAnalysis = new CustomElementsAnalysis(this); 456 customElementsAnalysis = new CustomElementsAnalysis(this);
453 constantCompilerTask = new JavaScriptConstantTask(compiler); 457 constantCompilerTask = new JavaScriptConstantTask(compiler);
454 resolutionCallbacks = new JavaScriptResolutionCallbacks(this); 458 resolutionCallbacks = new JavaScriptResolutionCallbacks(this);
455 } 459 }
456 460
457 ConstantSystem get constantSystem => constants.constantSystem; 461 ConstantSystem get constantSystem => constants.constantSystem;
458 462
459 /// Returns constant environment for the JavaScript interpretation of the 463 /// Returns constant environment for the JavaScript interpretation of the
460 /// constants. 464 /// constants.
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 // the checked setter. 1200 // the checked setter.
1197 if (Elements.isStaticOrTopLevel(element)) return; 1201 if (Elements.isStaticOrTopLevel(element)) return;
1198 } else { 1202 } else {
1199 // If the constant-handler was not able to produce a result we have to 1203 // If the constant-handler was not able to produce a result we have to
1200 // go through the builder (below) to generate the lazy initializer for 1204 // go through the builder (below) to generate the lazy initializer for
1201 // the static variable. 1205 // the static variable.
1202 // We also need to register the use of the cyclic-error helper. 1206 // We also need to register the use of the cyclic-error helper.
1203 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper()); 1207 compiler.enqueuer.codegen.registerStaticUse(getCyclicThrowHelper());
1204 } 1208 }
1205 } 1209 }
1206 HGraph graph = builder.build(work); 1210 jsAst.Expression code;
floitsch 2014/11/12 11:03:20 Alternatively we could: - have one "CodegenTask" i
sigurdm 2014/11/13 08:29:41 Done.
1207 optimizer.optimize(work, graph); 1211 if (Compiler.USE_CPS_IR) {
1208 jsAst.Expression code = generator.generateCode(work, graph); 1212 if(!work.element.isGenerativeConstructorBody &&
1213 work.element.enclosingClass is! ClosureClassElement) {
1214 // First try to compile with the new backend.
1215 // Will return null if it failed to compile.
1216 code = cpsBuilder.build(work);
1217 }
1218 }
1219 if (code == null) {
1220 HGraph graph = ssaBuilder.build(work);
1221 optimizer.optimize(work, graph);
1222 code = generator.generateCode(work, graph);
1223 }
1209 generatedCode[element] = code; 1224 generatedCode[element] = code;
1210 } 1225 }
1211 1226
1212 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) { 1227 native.NativeEnqueuer nativeResolutionEnqueuer(Enqueuer world) {
1213 return new native.NativeResolutionEnqueuer(world, compiler); 1228 return new native.NativeResolutionEnqueuer(world, compiler);
1214 } 1229 }
1215 1230
1216 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) { 1231 native.NativeEnqueuer nativeCodegenEnqueuer(Enqueuer world) {
1217 return new native.NativeCodegenEnqueuer(world, compiler, emitter); 1232 return new native.NativeCodegenEnqueuer(world, compiler, emitter);
1218 } 1233 }
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2461 } 2476 }
2462 } 2477 }
2463 2478
2464 /// Records that [constant] is used by the element behind [registry]. 2479 /// Records that [constant] is used by the element behind [registry].
2465 class Dependency { 2480 class Dependency {
2466 final ConstantValue constant; 2481 final ConstantValue constant;
2467 final Element annotatedElement; 2482 final Element annotatedElement;
2468 2483
2469 const Dependency(this.constant, this.annotatedElement); 2484 const Dependency(this.constant, this.annotatedElement);
2470 } 2485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698