OLD | NEW |
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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
(...skipping 21 matching lines...) Expand all Loading... |
32 final SourceInformationStrategy sourceInformationFactory; | 32 final SourceInformationStrategy sourceInformationFactory; |
33 | 33 |
34 SsaCodeGeneratorTask(JavaScriptBackend backend, this.sourceInformationFactory) | 34 SsaCodeGeneratorTask(JavaScriptBackend backend, this.sourceInformationFactory) |
35 : this.backend = backend, | 35 : this.backend = backend, |
36 super(backend.compiler); | 36 super(backend.compiler); |
37 | 37 |
38 String get name => 'SSA code generator'; | 38 String get name => 'SSA code generator'; |
39 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; | 39 NativeEmitter get nativeEmitter => backend.emitter.nativeEmitter; |
40 | 40 |
41 js.Fun buildJavaScriptFunction( | 41 js.Fun buildJavaScriptFunction( |
42 FunctionElement element, List<js.Parameter> parameters, js.Block body) { | 42 ResolvedAst resolvedAst, List<js.Parameter> parameters, js.Block body) { |
| 43 FunctionElement element = resolvedAst.element; |
43 js.AsyncModifier asyncModifier = element.asyncMarker.isAsync | 44 js.AsyncModifier asyncModifier = element.asyncMarker.isAsync |
44 ? (element.asyncMarker.isYielding | 45 ? (element.asyncMarker.isYielding |
45 ? const js.AsyncModifier.asyncStar() | 46 ? const js.AsyncModifier.asyncStar() |
46 : const js.AsyncModifier.async()) | 47 : const js.AsyncModifier.async()) |
47 : (element.asyncMarker.isYielding | 48 : (element.asyncMarker.isYielding |
48 ? const js.AsyncModifier.syncStar() | 49 ? const js.AsyncModifier.syncStar() |
49 : const js.AsyncModifier.sync()); | 50 : const js.AsyncModifier.sync()); |
50 | 51 |
51 return new js.Fun(parameters, body, asyncModifier: asyncModifier) | 52 return new js.Fun(parameters, body, asyncModifier: asyncModifier) |
52 .withSourceInformation(sourceInformationFactory | 53 .withSourceInformation(sourceInformationFactory |
53 .createBuilderForContext(element) | 54 .createBuilderForContext(resolvedAst.element) |
54 .buildDeclaration(element)); | 55 .buildDeclaration(resolvedAst)); |
55 } | 56 } |
56 | 57 |
57 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { | 58 js.Expression generateCode(CodegenWorkItem work, HGraph graph) { |
58 if (work.element.isField) { | 59 if (work.element.isField) { |
59 return generateLazyInitializer(work, graph); | 60 return generateLazyInitializer(work, graph); |
60 } else { | 61 } else { |
61 return generateMethod(work, graph); | 62 return generateMethod(work, graph); |
62 } | 63 } |
63 } | 64 } |
64 | 65 |
65 js.Expression generateLazyInitializer(work, graph) { | 66 js.Expression generateLazyInitializer(CodegenWorkItem work, HGraph graph) { |
66 return measure(() { | 67 return measure(() { |
67 compiler.tracer.traceGraph("codegen", graph); | 68 compiler.tracer.traceGraph("codegen", graph); |
68 SourceInformation sourceInformation = sourceInformationFactory | 69 SourceInformation sourceInformation = sourceInformationFactory |
69 .createBuilderForContext(work.element) | 70 .createBuilderForContext(work.element) |
70 .buildDeclaration(work.element); | 71 .buildDeclaration(work.resolvedAst); |
71 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); | 72 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); |
72 codegen.visitGraph(graph); | 73 codegen.visitGraph(graph); |
73 return new js.Fun(codegen.parameters, codegen.body) | 74 return new js.Fun(codegen.parameters, codegen.body) |
74 .withSourceInformation(sourceInformation); | 75 .withSourceInformation(sourceInformation); |
75 }); | 76 }); |
76 } | 77 } |
77 | 78 |
78 js.Expression generateMethod(CodegenWorkItem work, HGraph graph) { | 79 js.Expression generateMethod(CodegenWorkItem work, HGraph graph) { |
79 return measure(() { | 80 return measure(() { |
80 FunctionElement element = work.element; | 81 FunctionElement element = work.element; |
81 if (element.asyncMarker != AsyncMarker.SYNC) { | 82 if (element.asyncMarker != AsyncMarker.SYNC) { |
82 work.registry.registerAsyncMarker(element); | 83 work.registry.registerAsyncMarker(element); |
83 } | 84 } |
84 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); | 85 SsaCodeGenerator codegen = new SsaCodeGenerator(backend, work); |
85 codegen.visitGraph(graph); | 86 codegen.visitGraph(graph); |
86 compiler.tracer.traceGraph("codegen", graph); | 87 compiler.tracer.traceGraph("codegen", graph); |
87 return buildJavaScriptFunction(element, codegen.parameters, codegen.body); | 88 return buildJavaScriptFunction( |
| 89 work.resolvedAst, codegen.parameters, codegen.body); |
88 }); | 90 }); |
89 } | 91 } |
90 } | 92 } |
91 | 93 |
92 typedef void EntityAction(Entity element); | 94 typedef void EntityAction(Entity element); |
93 | 95 |
94 class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { | 96 class SsaCodeGenerator implements HVisitor, HBlockInformationVisitor { |
95 /** | 97 /** |
96 * Returned by [expressionType] to tell how code can be generated for | 98 * Returned by [expressionType] to tell how code can be generated for |
97 * a subgraph. | 99 * a subgraph. |
(...skipping 2794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2892 registry.registerStaticUse(new StaticUse.staticInvoke( | 2894 registry.registerStaticUse(new StaticUse.staticInvoke( |
2893 helper, new CallStructure.unnamed(argumentCount))); | 2895 helper, new CallStructure.unnamed(argumentCount))); |
2894 return backend.emitter.staticFunctionAccess(helper); | 2896 return backend.emitter.staticFunctionAccess(helper); |
2895 } | 2897 } |
2896 | 2898 |
2897 @override | 2899 @override |
2898 void visitRef(HRef node) { | 2900 void visitRef(HRef node) { |
2899 visit(node.value); | 2901 visit(node.value); |
2900 } | 2902 } |
2901 } | 2903 } |
OLD | NEW |