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 'dart:collection'; | 5 import 'dart:collection'; |
6 | 6 |
7 import 'package:js_runtime/shared/embedded_names.dart'; | 7 import 'package:js_runtime/shared/embedded_names.dart'; |
8 | 8 |
9 import '../closure.dart'; | 9 import '../closure.dart'; |
10 import '../common.dart'; | 10 import '../common.dart'; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 import 'jump_handler.dart'; | 47 import 'jump_handler.dart'; |
48 import 'locals_handler.dart'; | 48 import 'locals_handler.dart'; |
49 import 'loop_handler.dart'; | 49 import 'loop_handler.dart'; |
50 import 'nodes.dart'; | 50 import 'nodes.dart'; |
51 import 'optimize.dart'; | 51 import 'optimize.dart'; |
52 import 'ssa.dart'; | 52 import 'ssa.dart'; |
53 import 'ssa_branch_builder.dart'; | 53 import 'ssa_branch_builder.dart'; |
54 import 'type_builder.dart'; | 54 import 'type_builder.dart'; |
55 import 'types.dart'; | 55 import 'types.dart'; |
56 | 56 |
57 abstract class SsaAstBuilderBase extends CompilerTask | 57 abstract class SsaAstBuilderBase implements SsaBuilder { |
58 implements SsaBuilderTask { | 58 final CompilerTask task; |
59 final JavaScriptBackend backend; | 59 final JavaScriptBackend backend; |
60 | 60 |
61 SsaAstBuilderBase(this.backend) : super(backend.compiler.measurer); | 61 SsaAstBuilderBase(this.task, this.backend); |
62 | 62 |
63 /// Handle field initializer of `work.element`. Returns `true` if no code | 63 /// Handle field initializer of `work.element`. Returns `true` if no code |
64 /// is needed for the field. | 64 /// is needed for the field. |
65 /// | 65 /// |
66 /// If `work.element` is a field with a constant initializer, the value is | 66 /// If `work.element` is a field with a constant initializer, the value is |
67 /// registered with the world impact. Otherwise the cyclic-throw helper is | 67 /// registered with the world impact. Otherwise the cyclic-throw helper is |
68 /// registered for the lazy value computation. | 68 /// registered for the lazy value computation. |
69 /// | 69 /// |
70 /// If the field is constant, no code is needed for the field and the method | 70 /// If the field is constant, no code is needed for the field and the method |
71 /// return `true`. | 71 /// return `true`. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // We also need to register the use of the cyclic-error helper. | 105 // We also need to register the use of the cyclic-error helper. |
106 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( | 106 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( |
107 closedWorld.commonElements.cyclicThrowHelper, | 107 closedWorld.commonElements.cyclicThrowHelper, |
108 CallStructure.ONE_ARG)); | 108 CallStructure.ONE_ARG)); |
109 } | 109 } |
110 } | 110 } |
111 return false; | 111 return false; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 class SsaAstBuilderTask extends SsaAstBuilderBase { | 115 class SsaAstBuilder extends SsaAstBuilderBase { |
116 final CodeEmitterTask emitter; | 116 final CodeEmitterTask emitter; |
117 final SourceInformationStrategy sourceInformationFactory; | 117 final SourceInformationStrategy sourceInformationFactory; |
118 | 118 |
119 String get name => 'SSA builder'; | 119 SsaAstBuilder(CompilerTask task, JavaScriptBackend backend, |
120 | 120 this.sourceInformationFactory) |
121 SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | |
122 : emitter = backend.emitter, | 121 : emitter = backend.emitter, |
123 super(backend); | 122 super(task, backend); |
124 | 123 |
125 DiagnosticReporter get reporter => backend.reporter; | 124 DiagnosticReporter get reporter => backend.reporter; |
126 | 125 |
127 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 126 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { |
128 return measure(() { | 127 return task.measure(() { |
129 if (handleConstantField(work, closedWorld)) { | 128 if (handleConstantField(work, closedWorld)) { |
130 // No code is generated for `work.element`. | 129 // No code is generated for `work.element`. |
131 return null; | 130 return null; |
132 } | 131 } |
133 MemberElement element = work.element.implementation; | 132 MemberElement element = work.element.implementation; |
134 return reporter.withCurrentElement(element, () { | 133 return reporter.withCurrentElement(element, () { |
135 SsaBuilder builder = new SsaBuilder( | 134 SsaAstGraphBuilder builder = new SsaAstGraphBuilder( |
136 work.element.implementation, | 135 work.element.implementation, |
137 work.resolvedAst, | 136 work.resolvedAst, |
138 work.registry, | 137 work.registry, |
139 backend, | 138 backend, |
140 closedWorld, | 139 closedWorld, |
141 emitter.nativeEmitter, | 140 emitter.nativeEmitter, |
142 sourceInformationFactory); | 141 sourceInformationFactory); |
143 HGraph graph = builder.build(); | 142 HGraph graph = builder.build(); |
144 | 143 |
145 // Default arguments are handled elsewhere, but we must ensure | 144 // Default arguments are handled elsewhere, but we must ensure |
(...skipping 26 matching lines...) Expand all Loading... |
172 } | 171 } |
173 return graph; | 172 return graph; |
174 }); | 173 }); |
175 }); | 174 }); |
176 } | 175 } |
177 } | 176 } |
178 | 177 |
179 /** | 178 /** |
180 * This class builds SSA nodes for functions represented in AST. | 179 * This class builds SSA nodes for functions represented in AST. |
181 */ | 180 */ |
182 class SsaBuilder extends ast.Visitor | 181 class SsaAstGraphBuilder extends ast.Visitor |
183 with | 182 with |
184 BaseImplementationOfCompoundsMixin, | 183 BaseImplementationOfCompoundsMixin, |
185 BaseImplementationOfSetIfNullsMixin, | 184 BaseImplementationOfSetIfNullsMixin, |
186 BaseImplementationOfSuperIndexSetIfNullMixin, | 185 BaseImplementationOfSuperIndexSetIfNullMixin, |
187 SemanticSendResolvedMixin, | 186 SemanticSendResolvedMixin, |
188 NewBulkMixin, | 187 NewBulkMixin, |
189 ErrorBulkMixin, | 188 ErrorBulkMixin, |
190 GraphBuilder | 189 GraphBuilder |
191 implements SemanticSendVisitor { | 190 implements SemanticSendVisitor { |
192 /// The element for which this SSA builder is being used. | 191 /// The element for which this SSA builder is being used. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 element.asyncMarker == AsyncMarker.ASYNC); | 250 element.asyncMarker == AsyncMarker.ASYNC); |
252 } | 251 } |
253 | 252 |
254 /// Handles the building of loops. | 253 /// Handles the building of loops. |
255 LoopHandler<ast.Node> loopHandler; | 254 LoopHandler<ast.Node> loopHandler; |
256 | 255 |
257 /// Handles type check building. | 256 /// Handles type check building. |
258 TypeBuilder typeBuilder; | 257 TypeBuilder typeBuilder; |
259 | 258 |
260 // TODO(sigmund): make most args optional | 259 // TODO(sigmund): make most args optional |
261 SsaBuilder( | 260 SsaAstGraphBuilder( |
262 this.target, | 261 this.target, |
263 this.resolvedAst, | 262 this.resolvedAst, |
264 this.registry, | 263 this.registry, |
265 JavaScriptBackend backend, | 264 JavaScriptBackend backend, |
266 this.closedWorld, | 265 this.closedWorld, |
267 this.nativeEmitter, | 266 this.nativeEmitter, |
268 SourceInformationStrategy sourceInformationFactory) | 267 SourceInformationStrategy sourceInformationFactory) |
269 : this.infoReporter = backend.compiler.dumpInfoTask, | 268 : this.infoReporter = backend.compiler.dumpInfoTask, |
270 this.backend = backend, | 269 this.backend = backend, |
271 this.constantSystem = backend.constantSystem, | 270 this.constantSystem = backend.constantSystem, |
(...skipping 6318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6590 generateRuntimeError(node, error.message); | 6589 generateRuntimeError(node, error.message); |
6591 } | 6590 } |
6592 } | 6591 } |
6593 | 6592 |
6594 /** | 6593 /** |
6595 * Visitor that handles generation of string literals (LiteralString, | 6594 * Visitor that handles generation of string literals (LiteralString, |
6596 * StringInterpolation), and otherwise delegates to the given visitor for | 6595 * StringInterpolation), and otherwise delegates to the given visitor for |
6597 * non-literal subexpressions. | 6596 * non-literal subexpressions. |
6598 */ | 6597 */ |
6599 class StringBuilderVisitor extends ast.Visitor { | 6598 class StringBuilderVisitor extends ast.Visitor { |
6600 final SsaBuilder builder; | 6599 final SsaAstGraphBuilder builder; |
6601 final ast.Node diagnosticNode; | 6600 final ast.Node diagnosticNode; |
6602 | 6601 |
6603 /** | 6602 /** |
6604 * The string value generated so far. | 6603 * The string value generated so far. |
6605 */ | 6604 */ |
6606 HInstruction result = null; | 6605 HInstruction result = null; |
6607 | 6606 |
6608 StringBuilderVisitor(this.builder, this.diagnosticNode); | 6607 StringBuilderVisitor(this.builder, this.diagnosticNode); |
6609 | 6608 |
6610 void visit(ast.Node node) { | 6609 void visit(ast.Node node) { |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6875 this.oldReturnLocal, | 6874 this.oldReturnLocal, |
6876 this.oldReturnType, | 6875 this.oldReturnType, |
6877 this.oldResolvedAst, | 6876 this.oldResolvedAst, |
6878 this.oldStack, | 6877 this.oldStack, |
6879 this.oldLocalsHandler, | 6878 this.oldLocalsHandler, |
6880 this.inTryStatement, | 6879 this.inTryStatement, |
6881 this.allFunctionsCalledOnce, | 6880 this.allFunctionsCalledOnce, |
6882 this.oldElementInferenceResults) | 6881 this.oldElementInferenceResults) |
6883 : super(function); | 6882 : super(function); |
6884 } | 6883 } |
OLD | NEW |