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

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

Issue 1185633003: cps-ir: Support foreign code. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update test expectations. Created 5 years, 6 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
OLDNEW
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 /// Generate code using the cps-based IR pipeline. 5 /// Generate code using the cps-based IR pipeline.
6 library code_generator_task; 6 library code_generator_task;
7 7
8 import 'glue.dart'; 8 import 'glue.dart';
9 import 'codegen.dart'; 9 import 'codegen.dart';
10 import 'unsugar.dart'; 10 import 'unsugar.dart';
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 SourceInformationFactory sourceInformationFactory) 50 SourceInformationFactory sourceInformationFactory)
51 : fallbackCompiler = 51 : fallbackCompiler =
52 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory), 52 new ssa.SsaFunctionCompiler(backend, sourceInformationFactory),
53 this.sourceInformationFactory = sourceInformationFactory, 53 this.sourceInformationFactory = sourceInformationFactory,
54 constantSystem = backend.constantSystem, 54 constantSystem = backend.constantSystem,
55 compiler = compiler, 55 compiler = compiler,
56 glue = new Glue(compiler); 56 glue = new Glue(compiler);
57 57
58 String get name => 'CPS Ir pipeline'; 58 String get name => 'CPS Ir pipeline';
59 59
60 /// Generates JavaScript code for `work.element`. First tries to use the 60 /// Generates JavaScript code for `work.element`.
61 /// Cps Ir -> tree ir -> js pipeline, and if that fails due to language
62 /// features not implemented it will fall back to the ssa pipeline (for
63 /// platform code) or will cancel compilation (for user code).
64 js.Fun compile(CodegenWorkItem work) { 61 js.Fun compile(CodegenWorkItem work) {
65 AstElement element = work.element; 62 AstElement element = work.element;
66 JavaScriptBackend backend = compiler.backend; 63 JavaScriptBackend backend = compiler.backend;
67 return compiler.withCurrentElement(element, () { 64 return compiler.withCurrentElement(element, () {
68 if (element.library.isPlatformLibrary ||
69 element.library == backend.interceptorsLibrary) {
70 compiler.log('Using SSA compiler for platform element $element');
71 return fallbackCompiler.compile(work);
72 }
73 try { 65 try {
66 ClassElement cls = element.enclosingClass;
67 String name = element.name;
68 String className = cls == null ? null : cls.name;
69 LibraryElement library = element.library;
70 String libraryName = library == null ? null : library.toString();
71 // TODO(karlklose): remove this fallback.
72 // Fallback for a few functions that we know require try-finally and
73 // switch.
74 if (element.isNative ||
75 element.isPatched ||
76 libraryName == 'origin library(dart:typed_data)' ||
77 // Using switch or try-finally.
78 library.isInternalLibrary && name == 'unwrapException' ||
79 library.isPlatformLibrary && className == 'IterableBase' ||
80 library.isInternalLibrary && className == 'Closure' ||
81 libraryName == 'origin library(dart:collection)' &&
82 name == 'mapToString' ||
83 libraryName == 'library(dart:html)' && name == 'sanitizeNode' ||
84 className == '_IsolateContext' ||
85 className == 'IsolateNatives' ||
86 className == '_Deserializer' ||
87 name == '_rootRun' ||
88 name == '_microtaskLoopEntry') {
89 compiler.log('Using SSA compiler for platform element $element');
90 return fallbackCompiler.compile(work);
91 }
92
74 if (tracer != null) { 93 if (tracer != null) {
75 tracer.traceCompilation(element.name, null); 94 tracer.traceCompilation(element.name, null);
76 } 95 }
77 cps.FunctionDefinition cpsFunction = compileToCpsIR(element); 96 cps.FunctionDefinition cpsFunction = compileToCpsIR(element);
78 cpsFunction = optimizeCpsIR(cpsFunction); 97 cpsFunction = optimizeCpsIR(cpsFunction);
79 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction); 98 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction);
80 treeFunction = optimizeTreeIR(treeFunction); 99 treeFunction = optimizeTreeIR(treeFunction);
81 return compileToJavaScript(work, treeFunction); 100 return compileToJavaScript(work, treeFunction);
82 } on CodegenBailout catch (e) { 101 } on CodegenBailout catch (e) {
83 String message = "Unable to compile $element with the new compiler.\n" 102 String message = "Unable to compile $element with the new compiler.\n"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // TODO(sigurdm): Make a better list of tasks. 232 // TODO(sigurdm): Make a better list of tasks.
214 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); 233 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks);
215 } 234 }
216 235
217 js.Node attachPosition(js.Node node, AstElement element) { 236 js.Node attachPosition(js.Node node, AstElement element) {
218 return node.withSourceInformation( 237 return node.withSourceInformation(
219 sourceInformationFactory.forContext(element) 238 sourceInformationFactory.forContext(element)
220 .buildDeclaration(element)); 239 .buildDeclaration(element));
221 } 240 }
222 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698