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

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

Issue 1288013002: dart2js cps: Handle native functions, getters, and setters. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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 21 matching lines...) Expand all
32 import '../../tree_ir/tree_ir_integrity.dart'; 32 import '../../tree_ir/tree_ir_integrity.dart';
33 import '../../cps_ir/cps_ir_nodes_sexpr.dart'; 33 import '../../cps_ir/cps_ir_nodes_sexpr.dart';
34 34
35 class CpsFunctionCompiler implements FunctionCompiler { 35 class CpsFunctionCompiler implements FunctionCompiler {
36 final ConstantSystem constantSystem; 36 final ConstantSystem constantSystem;
37 // TODO(karlklose): remove the compiler. 37 // TODO(karlklose): remove the compiler.
38 final Compiler compiler; 38 final Compiler compiler;
39 final Glue glue; 39 final Glue glue;
40 final SourceInformationStrategy sourceInformationFactory; 40 final SourceInformationStrategy sourceInformationFactory;
41 41
42 // TODO(karlklose,sigurm): remove and update dart-doc of [compile]. 42 // TODO(karlklose,sigurdm): remove and update dart-doc of [compile].
43 final FunctionCompiler fallbackCompiler; 43 final FunctionCompiler fallbackCompiler;
44 44
45 Tracer get tracer => compiler.tracer; 45 Tracer get tracer => compiler.tracer;
46 46
47 IrBuilderTask get irBuilderTask => compiler.irBuilder; 47 IrBuilderTask get irBuilderTask => compiler.irBuilder;
48 48
49 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend, 49 CpsFunctionCompiler(Compiler compiler, JavaScriptBackend backend,
50 SourceInformationStrategy sourceInformationFactory) 50 SourceInformationStrategy 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 JavaScriptBackend get backend => compiler.backend; 60 JavaScriptBackend get backend => compiler.backend;
61 61
62 /// Generates JavaScript code for `work.element`. 62 /// Generates JavaScript code for `work.element`.
63 js.Fun compile(CodegenWorkItem work) { 63 js.Fun compile(CodegenWorkItem work) {
64 AstElement element = work.element; 64 AstElement element = work.element;
65 JavaScriptBackend backend = compiler.backend; 65 JavaScriptBackend backend = compiler.backend;
66 return compiler.withCurrentElement(element, () { 66 return compiler.withCurrentElement(element, () {
67 try { 67 try {
68 // TODO(karlklose): remove this fallback. 68 // TODO(karlklose): remove this fallback when we do not need it for
69 // Fallback for a few functions that we know require try-finally and 69 // testing anymore.
70 // switch. 70 if (false) {
71 if (element.isNative) {
72 compiler.log('Using SSA compiler for platform element $element'); 71 compiler.log('Using SSA compiler for platform element $element');
73 return fallbackCompiler.compile(work); 72 return fallbackCompiler.compile(work);
74 } 73 }
75 74
76 if (tracer != null) { 75 if (tracer != null) {
77 tracer.traceCompilation(element.name, null); 76 tracer.traceCompilation(element.name, null);
78 } 77 }
79 cps.FunctionDefinition cpsFunction = compileToCpsIR(element); 78 cps.FunctionDefinition cpsFunction = compileToCpsIR(element);
80 cpsFunction = optimizeCpsIR(cpsFunction); 79 cpsFunction = optimizeCpsIR(cpsFunction);
81 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction); 80 tree_ir.FunctionDefinition treeFunction = compileToTreeIR(cpsFunction);
(...skipping 11 matching lines...) Expand all
93 throw new CodegenBailout(null, reason); 92 throw new CodegenBailout(null, reason);
94 } 93 }
95 94
96 void traceGraph(String title, var irObject) { 95 void traceGraph(String title, var irObject) {
97 if (tracer != null) { 96 if (tracer != null) {
98 tracer.traceGraph(title, irObject); 97 tracer.traceGraph(title, irObject);
99 } 98 }
100 } 99 }
101 100
102 cps.FunctionDefinition compileToCpsIR(AstElement element) { 101 cps.FunctionDefinition compileToCpsIR(AstElement element) {
103 // TODO(sigurdm): Support these constructs.
104 if (element.isNative) {
105 giveUp('unsupported element kind: ${element.name}:${element.kind}');
106 }
107
108 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element); 102 cps.FunctionDefinition cpsNode = irBuilderTask.buildNode(element);
109 if (cpsNode == null) { 103 if (cpsNode == null) {
110 if (irBuilderTask.bailoutMessage == null) { 104 if (irBuilderTask.bailoutMessage == null) {
111 giveUp('unable to build cps definition of $element'); 105 giveUp('unable to build cps definition of $element');
112 } else { 106 } else {
113 giveUp(irBuilderTask.bailoutMessage); 107 giveUp(irBuilderTask.bailoutMessage);
114 } 108 }
115 } 109 }
116 traceGraph("IR Builder", cpsNode); 110 traceGraph("IR Builder", cpsNode);
117 // Eliminating redundant phis before the unsugaring pass will make it 111 // Eliminating redundant phis before the unsugaring pass will make it
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // TODO(sigurdm): Make a better list of tasks. 223 // TODO(sigurdm): Make a better list of tasks.
230 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks); 224 return <CompilerTask>[irBuilderTask]..addAll(fallbackCompiler.tasks);
231 } 225 }
232 226
233 js.Node attachPosition(js.Node node, AstElement element) { 227 js.Node attachPosition(js.Node node, AstElement element) {
234 return node.withSourceInformation( 228 return node.withSourceInformation(
235 sourceInformationFactory.createBuilderForContext(element) 229 sourceInformationFactory.createBuilderForContext(element)
236 .buildDeclaration(element)); 230 .buildDeclaration(element));
237 } 231 }
238 } 232 }
OLDNEW
« pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('K') | « pkg/compiler/lib/src/dart_types.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698