Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 8 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 9 import '../common/names.dart'; | 9 import '../common/names.dart'; |
| 10 import '../common/tasks.dart' show CompilerTask; | 10 import '../common/tasks.dart' show CompilerTask; |
| 11 import '../compiler.dart'; | 11 import '../compiler.dart'; |
| 12 import '../dart_types.dart'; | 12 import '../dart_types.dart'; |
| 13 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
| 14 import '../io/source_information.dart'; | 14 import '../io/source_information.dart'; |
| 15 import '../js_backend/backend.dart' show JavaScriptBackend; | 15 import '../js_backend/backend.dart' show JavaScriptBackend; |
| 16 import '../kernel/kernel.dart'; | 16 import '../kernel/kernel.dart'; |
| 17 import '../resolution/tree_elements.dart'; | 17 import '../resolution/tree_elements.dart'; |
| 18 import '../tree/dartstring.dart'; | 18 import '../tree/dartstring.dart'; |
| 19 import '../tree/tree.dart' as ast; | |
| 19 import '../types/masks.dart'; | 20 import '../types/masks.dart'; |
| 20 import '../universe/call_structure.dart' show CallStructure; | 21 import '../universe/call_structure.dart' show CallStructure; |
| 21 import '../universe/selector.dart'; | 22 import '../universe/selector.dart'; |
| 22 import '../universe/use.dart' show TypeUse; | 23 import '../universe/use.dart' show TypeUse; |
| 23 import 'graph_builder.dart'; | 24 import 'graph_builder.dart'; |
| 24 import 'kernel_ast_adapter.dart'; | 25 import 'kernel_ast_adapter.dart'; |
| 25 import 'kernel_string_builder.dart'; | 26 import 'kernel_string_builder.dart'; |
| 26 import 'locals_handler.dart'; | 27 import 'locals_handler.dart'; |
| 27 import 'loop_handler.dart'; | 28 import 'loop_handler.dart'; |
| 28 import 'nodes.dart'; | 29 import 'nodes.dart'; |
| 29 import 'ssa_branch_builder.dart'; | 30 import 'ssa_branch_builder.dart'; |
| 30 import 'type_builder.dart'; | 31 import 'type_builder.dart'; |
| 32 import 'types.dart' show TypeMaskFactory; | |
| 31 | 33 |
| 32 class SsaKernelBuilderTask extends CompilerTask { | 34 class SsaKernelBuilderTask extends CompilerTask { |
| 33 final JavaScriptBackend backend; | 35 final JavaScriptBackend backend; |
| 34 final SourceInformationStrategy sourceInformationFactory; | 36 final SourceInformationStrategy sourceInformationFactory; |
| 35 | 37 |
| 36 String get name => 'SSA kernel builder'; | 38 String get name => 'SSA kernel builder'; |
| 37 | 39 |
| 38 SsaKernelBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) | 40 SsaKernelBuilderTask(JavaScriptBackend backend, this.sourceInformationFactory) |
| 39 : backend = backend, | 41 : backend = backend, |
| 40 super(backend.compiler.measurer); | 42 super(backend.compiler.measurer); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 } | 201 } |
| 200 | 202 |
| 201 /// Returns the current source element. | 203 /// Returns the current source element. |
| 202 /// | 204 /// |
| 203 /// The returned element is a declaration element. | 205 /// The returned element is a declaration element. |
| 204 // TODO(efortuna): Update this when we implement inlining. | 206 // TODO(efortuna): Update this when we implement inlining. |
| 205 @override | 207 @override |
| 206 Element get sourceElement => astAdapter.getElement(target); | 208 Element get sourceElement => astAdapter.getElement(target); |
| 207 | 209 |
| 208 @override | 210 @override |
| 211 void pushInvokeStatic(MethodElement element, List<HInstruction> arguments, | |
|
Harry Terkelsen
2016/11/15 22:44:48
This class should not have any methods with Elemen
Emily Fortuna
2016/11/16 01:53:44
Thank you, I intended to get rid of this, but got
| |
| 212 {TypeMask typeMask, | |
| 213 InterfaceType instanceType, | |
| 214 SourceInformation sourceInformation, | |
| 215 // TODO(efortuna): Leaving this part of the signature for consistency with | |
| 216 // builder.dart. Remove this parameter once we are no longer using | |
| 217 // builder.dart. | |
| 218 ast.Node location}) { | |
| 219 assert(element.isDeclaration); | |
| 220 // TODO(efortuna): try to inline method. | |
| 221 | |
| 222 if (typeMask == null) { | |
| 223 typeMask = | |
| 224 TypeMaskFactory.inferredReturnTypeForElement(element, compiler); | |
| 225 } | |
| 226 bool targetCanThrow = !compiler.closedWorld.getCannotThrow(element); | |
| 227 // TODO(5346): Try to avoid the need for calling [declaration] before | |
|
Harry Terkelsen
2016/11/15 22:44:48
this TODO makes no sense to me?
Emily Fortuna
2016/11/16 01:53:44
Agreed.... it was copied from builder.dart. Is it
| |
| 228 var instruction; | |
| 229 if (backend.isJsInterop(element)) { | |
| 230 // TODO(efortuna): Implement JS Introp function. | |
| 231 } else { | |
| 232 // creating an [HInvokeStatic]. | |
| 233 instruction = new HInvokeStatic(element, arguments, typeMask, | |
| 234 targetCanThrow: targetCanThrow) | |
| 235 ..sourceInformation = sourceInformation; | |
| 236 // TODO(efortuna): Test if we have any inlined instantiations here. | |
| 237 instruction.sideEffects = | |
| 238 compiler.closedWorld.getSideEffectsOfElement(element); | |
| 239 } | |
| 240 // TODO(efortuna): Attach source information if available from location. | |
| 241 push(instruction); | |
| 242 } | |
| 243 | |
| 244 @override | |
| 209 void visitBlock(ir.Block block) { | 245 void visitBlock(ir.Block block) { |
| 210 assert(!isAborted()); | 246 assert(!isAborted()); |
| 211 for (ir.Statement statement in block.statements) { | 247 for (ir.Statement statement in block.statements) { |
| 212 statement.accept(this); | 248 statement.accept(this); |
| 213 if (!isReachable) { | 249 if (!isReachable) { |
| 214 // The block has been aborted by a return or a throw. | 250 // The block has been aborted by a return or a throw. |
| 215 if (stack.isNotEmpty) { | 251 if (stack.isNotEmpty) { |
| 216 compiler.reporter.internalError( | 252 compiler.reporter.internalError( |
| 217 NO_LOCATION_SPANNABLE, 'Non-empty instruction stack.'); | 253 NO_LOCATION_SPANNABLE, 'Non-empty instruction stack.'); |
| 218 } | 254 } |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 stack.add(graph.addConstant( | 571 stack.add(graph.addConstant( |
| 536 astAdapter.getConstantForSymbol(symbolLiteral), compiler)); | 572 astAdapter.getConstantForSymbol(symbolLiteral), compiler)); |
| 537 registry?.registerConstSymbol(symbolLiteral.value); | 573 registry?.registerConstSymbol(symbolLiteral.value); |
| 538 } | 574 } |
| 539 | 575 |
| 540 @override | 576 @override |
| 541 void visitNullLiteral(ir.NullLiteral nullLiteral) { | 577 void visitNullLiteral(ir.NullLiteral nullLiteral) { |
| 542 stack.add(graph.addConstantNull(compiler)); | 578 stack.add(graph.addConstantNull(compiler)); |
| 543 } | 579 } |
| 544 | 580 |
| 581 HInstruction setRtiIfNeeded(HInstruction object, ir.ListLiteral listLiteral) { | |
| 582 InterfaceType type = localsHandler | |
| 583 .substInContext(elements.getType(astAdapter.getNode(listLiteral))); | |
| 584 if (!backend.classNeedsRti(type.element) || type.treatAsRaw) { | |
| 585 return object; | |
| 586 } | |
| 587 List<HInstruction> arguments = <HInstruction>[]; | |
| 588 for (DartType argument in type.typeArguments) { | |
| 589 arguments.add(typeBuilder.analyzeTypeArgument(argument, sourceElement)); | |
| 590 } | |
| 591 // TODO(15489): Register at codegen. | |
| 592 registry?.registerInstantiation(type); | |
| 593 return callSetRuntimeTypeInfoWithTypeArguments(type, arguments, object); | |
| 594 } | |
| 595 | |
| 545 @override | 596 @override |
| 546 void visitListLiteral(ir.ListLiteral listLiteral) { | 597 void visitListLiteral(ir.ListLiteral listLiteral) { |
| 547 HInstruction listInstruction; | 598 HInstruction listInstruction; |
| 548 if (listLiteral.isConst) { | 599 if (listLiteral.isConst) { |
| 549 listInstruction = | 600 listInstruction = |
| 550 graph.addConstant(astAdapter.getConstantFor(listLiteral), compiler); | 601 graph.addConstant(astAdapter.getConstantFor(listLiteral), compiler); |
| 551 } else { | 602 } else { |
| 552 List<HInstruction> elements = <HInstruction>[]; | 603 List<HInstruction> elements = <HInstruction>[]; |
| 553 for (ir.Expression element in listLiteral.expressions) { | 604 for (ir.Expression element in listLiteral.expressions) { |
| 554 element.accept(this); | 605 element.accept(this); |
| 555 elements.add(pop()); | 606 elements.add(pop()); |
| 556 } | 607 } |
| 557 listInstruction = new HLiteralList(elements, backend.extendableArrayType); | 608 listInstruction = new HLiteralList(elements, backend.extendableArrayType); |
| 558 add(listInstruction); | 609 add(listInstruction); |
| 559 // TODO(het): set runtime type info | 610 listInstruction = setRtiIfNeeded(listInstruction, listLiteral); |
| 560 } | 611 } |
| 561 | 612 |
| 562 TypeMask type = astAdapter.typeOfNewList(targetElement, listLiteral); | 613 TypeMask type = astAdapter.typeOfNewList(targetElement, listLiteral); |
| 563 if (!type.containsAll(compiler.closedWorld)) { | 614 if (!type.containsAll(compiler.closedWorld)) { |
| 564 listInstruction.instructionType = type; | 615 listInstruction.instructionType = type; |
| 565 } | 616 } |
| 566 stack.add(listInstruction); | 617 stack.add(listInstruction); |
| 567 } | 618 } |
| 568 | 619 |
| 569 @override | 620 @override |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 863 push(new HNot(popBoolified(), backend.boolType)); | 914 push(new HNot(popBoolified(), backend.boolType)); |
| 864 } | 915 } |
| 865 | 916 |
| 866 @override | 917 @override |
| 867 void visitStringConcatenation(ir.StringConcatenation stringConcat) { | 918 void visitStringConcatenation(ir.StringConcatenation stringConcat) { |
| 868 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); | 919 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); |
| 869 stringConcat.accept(stringBuilder); | 920 stringConcat.accept(stringBuilder); |
| 870 stack.add(stringBuilder.result); | 921 stack.add(stringBuilder.result); |
| 871 } | 922 } |
| 872 } | 923 } |
| OLD | NEW |