| OLD | NEW |
| 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 Loading... |
| 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`. | 60 /// Generates JavaScript code for `work.element`. First tries to use the |
| 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). |
| 61 js.Fun compile(CodegenWorkItem work) { | 64 js.Fun compile(CodegenWorkItem work) { |
| 62 AstElement element = work.element; | 65 AstElement element = work.element; |
| 63 JavaScriptBackend backend = compiler.backend; | 66 JavaScriptBackend backend = compiler.backend; |
| 64 return compiler.withCurrentElement(element, () { | 67 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 } |
| 65 try { | 73 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 libraryName == 'origin library(dart:typed_data)' || | |
| 76 // switch | |
| 77 library.isInternalLibrary && name == 'unwrapException' || | |
| 78 // try-finally | |
| 79 library.isPlatformLibrary && className == 'IterableBase' || | |
| 80 library.isInternalLibrary && className == 'Closure' || | |
| 81 | |
| 82 libraryName == 'origin library(dart:collection)' && | |
| 83 name == 'mapToString' || | |
| 84 libraryName == 'library(dart:html)' && name == 'sanitizeNode') { | |
| 85 compiler.log('Using SSA compiler for platform element $element'); | |
| 86 return fallbackCompiler.compile(work); | |
| 87 } | |
| 88 | |
| 89 if (tracer != null) { | 74 if (tracer != null) { |
| 90 tracer.traceCompilation(element.name, null); | 75 tracer.traceCompilation(element.name, null); |
| 91 } | 76 } |
| 92 cps.FunctionDefinition cpsFunction = compileToCpsIR(element); | 77 cps.FunctionDefinition cpsFunction = compileToCpsIR(element); |
| 93 cpsFunction = optimizeCpsIR(cpsFunction); | 78 cpsFunction = optimizeCpsIR(cpsFunction); |
| 94 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction); | 79 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction); |
| 95 treeFunction = optimizeTreeIR(treeFunction); | 80 treeFunction = optimizeTreeIR(treeFunction); |
| 96 return compileToJavaScript(work, treeFunction); | 81 return compileToJavaScript(work, treeFunction); |
| 97 } on CodegenBailout catch (e) { | 82 } on CodegenBailout catch (e) { |
| 98 String message = "Unable to compile $element with the new compiler.\n" | 83 String message = "Unable to compile $element with the new compiler.\n" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // TODO(sigurdm): Make a better list of tasks. | 213 // TODO(sigurdm): Make a better list of tasks. |
| 229 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); | 214 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); |
| 230 } | 215 } |
| 231 | 216 |
| 232 js.Node attachPosition(js.Node node, AstElement element) { | 217 js.Node attachPosition(js.Node node, AstElement element) { |
| 233 return node.withSourceInformation( | 218 return node.withSourceInformation( |
| 234 sourceInformationFactory.forContext(element) | 219 sourceInformationFactory.forContext(element) |
| 235 .buildDeclaration(element)); | 220 .buildDeclaration(element)); |
| 236 } | 221 } |
| 237 } | 222 } |
| OLD | NEW |