Chromium Code Reviews| 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 String get name => 'SSA builder'; |
|
Siggi Cherem (dart-lang)
2017/06/15 23:10:49
delete?
Johnni Winther
2017/06/16 11:06:44
Done.
| |
| 120 | 120 |
| 121 SsaAstBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | 121 SsaAstBuilder(CompilerTask task, JavaScriptBackend backend, |
| 122 this.sourceInformationFactory) | |
| 122 : emitter = backend.emitter, | 123 : emitter = backend.emitter, |
| 123 super(backend); | 124 super(task, backend); |
| 124 | 125 |
| 125 DiagnosticReporter get reporter => backend.reporter; | 126 DiagnosticReporter get reporter => backend.reporter; |
| 126 | 127 |
| 127 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { | 128 HGraph build(ElementCodegenWorkItem work, ClosedWorld closedWorld) { |
| 128 return measure(() { | 129 return task.measure(() { |
| 129 if (handleConstantField(work, closedWorld)) { | 130 if (handleConstantField(work, closedWorld)) { |
| 130 // No code is generated for `work.element`. | 131 // No code is generated for `work.element`. |
| 131 return null; | 132 return null; |
| 132 } | 133 } |
| 133 MemberElement element = work.element.implementation; | 134 MemberElement element = work.element.implementation; |
| 134 return reporter.withCurrentElement(element, () { | 135 return reporter.withCurrentElement(element, () { |
| 135 SsaBuilder builder = new SsaBuilder( | 136 SsaAstGraphBuilder builder = new SsaAstGraphBuilder( |
| 136 work.element.implementation, | 137 work.element.implementation, |
| 137 work.resolvedAst, | 138 work.resolvedAst, |
| 138 work.registry, | 139 work.registry, |
| 139 backend, | 140 backend, |
| 140 closedWorld, | 141 closedWorld, |
| 141 emitter.nativeEmitter, | 142 emitter.nativeEmitter, |
| 142 sourceInformationFactory); | 143 sourceInformationFactory); |
| 143 HGraph graph = builder.build(); | 144 HGraph graph = builder.build(); |
| 144 | 145 |
| 145 // Default arguments are handled elsewhere, but we must ensure | 146 // Default arguments are handled elsewhere, but we must ensure |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 172 } | 173 } |
| 173 return graph; | 174 return graph; |
| 174 }); | 175 }); |
| 175 }); | 176 }); |
| 176 } | 177 } |
| 177 } | 178 } |
| 178 | 179 |
| 179 /** | 180 /** |
| 180 * This class builds SSA nodes for functions represented in AST. | 181 * This class builds SSA nodes for functions represented in AST. |
| 181 */ | 182 */ |
| 182 class SsaBuilder extends ast.Visitor | 183 class SsaAstGraphBuilder extends ast.Visitor |
| 183 with | 184 with |
| 184 BaseImplementationOfCompoundsMixin, | 185 BaseImplementationOfCompoundsMixin, |
| 185 BaseImplementationOfSetIfNullsMixin, | 186 BaseImplementationOfSetIfNullsMixin, |
| 186 BaseImplementationOfSuperIndexSetIfNullMixin, | 187 BaseImplementationOfSuperIndexSetIfNullMixin, |
| 187 SemanticSendResolvedMixin, | 188 SemanticSendResolvedMixin, |
| 188 NewBulkMixin, | 189 NewBulkMixin, |
| 189 ErrorBulkMixin, | 190 ErrorBulkMixin, |
| 190 GraphBuilder | 191 GraphBuilder |
| 191 implements SemanticSendVisitor { | 192 implements SemanticSendVisitor { |
| 192 /// The element for which this SSA builder is being used. | 193 /// 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); | 252 element.asyncMarker == AsyncMarker.ASYNC); |
| 252 } | 253 } |
| 253 | 254 |
| 254 /// Handles the building of loops. | 255 /// Handles the building of loops. |
| 255 LoopHandler<ast.Node> loopHandler; | 256 LoopHandler<ast.Node> loopHandler; |
| 256 | 257 |
| 257 /// Handles type check building. | 258 /// Handles type check building. |
| 258 TypeBuilder typeBuilder; | 259 TypeBuilder typeBuilder; |
| 259 | 260 |
| 260 // TODO(sigmund): make most args optional | 261 // TODO(sigmund): make most args optional |
| 261 SsaBuilder( | 262 SsaAstGraphBuilder( |
| 262 this.target, | 263 this.target, |
| 263 this.resolvedAst, | 264 this.resolvedAst, |
| 264 this.registry, | 265 this.registry, |
| 265 JavaScriptBackend backend, | 266 JavaScriptBackend backend, |
| 266 this.closedWorld, | 267 this.closedWorld, |
| 267 this.nativeEmitter, | 268 this.nativeEmitter, |
| 268 SourceInformationStrategy sourceInformationFactory) | 269 SourceInformationStrategy sourceInformationFactory) |
| 269 : this.infoReporter = backend.compiler.dumpInfoTask, | 270 : this.infoReporter = backend.compiler.dumpInfoTask, |
| 270 this.backend = backend, | 271 this.backend = backend, |
| 271 this.constantSystem = backend.constantSystem, | 272 this.constantSystem = backend.constantSystem, |
| (...skipping 6318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6590 generateRuntimeError(node, error.message); | 6591 generateRuntimeError(node, error.message); |
| 6591 } | 6592 } |
| 6592 } | 6593 } |
| 6593 | 6594 |
| 6594 /** | 6595 /** |
| 6595 * Visitor that handles generation of string literals (LiteralString, | 6596 * Visitor that handles generation of string literals (LiteralString, |
| 6596 * StringInterpolation), and otherwise delegates to the given visitor for | 6597 * StringInterpolation), and otherwise delegates to the given visitor for |
| 6597 * non-literal subexpressions. | 6598 * non-literal subexpressions. |
| 6598 */ | 6599 */ |
| 6599 class StringBuilderVisitor extends ast.Visitor { | 6600 class StringBuilderVisitor extends ast.Visitor { |
| 6600 final SsaBuilder builder; | 6601 final SsaAstGraphBuilder builder; |
| 6601 final ast.Node diagnosticNode; | 6602 final ast.Node diagnosticNode; |
| 6602 | 6603 |
| 6603 /** | 6604 /** |
| 6604 * The string value generated so far. | 6605 * The string value generated so far. |
| 6605 */ | 6606 */ |
| 6606 HInstruction result = null; | 6607 HInstruction result = null; |
| 6607 | 6608 |
| 6608 StringBuilderVisitor(this.builder, this.diagnosticNode); | 6609 StringBuilderVisitor(this.builder, this.diagnosticNode); |
| 6609 | 6610 |
| 6610 void visit(ast.Node node) { | 6611 void visit(ast.Node node) { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6875 this.oldReturnLocal, | 6876 this.oldReturnLocal, |
| 6876 this.oldReturnType, | 6877 this.oldReturnType, |
| 6877 this.oldResolvedAst, | 6878 this.oldResolvedAst, |
| 6878 this.oldStack, | 6879 this.oldStack, |
| 6879 this.oldLocalsHandler, | 6880 this.oldLocalsHandler, |
| 6880 this.inTryStatement, | 6881 this.inTryStatement, |
| 6881 this.allFunctionsCalledOnce, | 6882 this.allFunctionsCalledOnce, |
| 6882 this.oldElementInferenceResults) | 6883 this.oldElementInferenceResults) |
| 6883 : super(function); | 6884 : super(function); |
| 6884 } | 6885 } |
| OLD | NEW |