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; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 JavaScriptBackend get backend => compiler.backend; | 79 JavaScriptBackend get backend => compiler.backend; |
80 | 80 |
81 @override | 81 @override |
82 TreeElements get elements => resolvedAst.elements; | 82 TreeElements get elements => resolvedAst.elements; |
83 | 83 |
84 SourceInformationBuilder sourceInformationBuilder; | 84 SourceInformationBuilder sourceInformationBuilder; |
85 KernelAstAdapter astAdapter; | 85 KernelAstAdapter astAdapter; |
86 LoopHandler<ir.Node> loopHandler; | 86 LoopHandler<ir.Node> loopHandler; |
87 TypeBuilder typeBuilder; | 87 TypeBuilder typeBuilder; |
88 | 88 |
89 final Map<ir.VariableDeclaration, HInstruction> letBindings = | |
90 <ir.VariableDeclaration, HInstruction>{}; | |
91 | |
89 KernelSsaBuilder( | 92 KernelSsaBuilder( |
90 this.targetElement, | 93 this.targetElement, |
91 this.resolvedAst, | 94 this.resolvedAst, |
92 Compiler compiler, | 95 Compiler compiler, |
93 this.registry, | 96 this.registry, |
94 SourceInformationStrategy sourceInformationFactory, | 97 SourceInformationStrategy sourceInformationFactory, |
95 Kernel kernel) { | 98 Kernel kernel) { |
96 this.compiler = compiler; | 99 this.compiler = compiler; |
97 this.loopHandler = new KernelLoopHandler(this); | 100 this.loopHandler = new KernelLoopHandler(this); |
98 typeBuilder = new TypeBuilder(this); | 101 typeBuilder = new TypeBuilder(this); |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 void visitPropertyGet(ir.PropertyGet propertyGet) { | 935 void visitPropertyGet(ir.PropertyGet propertyGet) { |
933 propertyGet.receiver.accept(this); | 936 propertyGet.receiver.accept(this); |
934 HInstruction receiver = pop(); | 937 HInstruction receiver = pop(); |
935 | 938 |
936 _pushDynamicInvocation(propertyGet, astAdapter.typeOfGet(propertyGet), | 939 _pushDynamicInvocation(propertyGet, astAdapter.typeOfGet(propertyGet), |
937 <HInstruction>[receiver]); | 940 <HInstruction>[receiver]); |
938 } | 941 } |
939 | 942 |
940 @override | 943 @override |
941 void visitVariableGet(ir.VariableGet variableGet) { | 944 void visitVariableGet(ir.VariableGet variableGet) { |
945 ir.VariableDeclaration variable = variableGet.variable; | |
946 HInstruction letBinding = letBindings[variable]; | |
947 if (letBinding != null) { | |
948 stack.add(letBinding); | |
949 return; | |
950 } | |
951 | |
942 Local local = astAdapter.getLocal(variableGet.variable); | 952 Local local = astAdapter.getLocal(variableGet.variable); |
943 stack.add(localsHandler.readLocal(local)); | 953 stack.add(localsHandler.readLocal(local)); |
944 } | 954 } |
945 | 955 |
946 @override | 956 @override |
957 void visitPropertySet(ir.PropertySet propertySet) { | |
958 propertySet.receiver.accept(this); | |
959 HInstruction receiver = pop(); | |
960 propertySet.value.accept(this); | |
961 HInstruction value = pop(); | |
962 | |
963 _pushDynamicInvocation(propertySet, astAdapter.typeOfSet(propertySet), | |
964 <HInstruction>[receiver, value]); | |
asgerf
2016/11/24 09:44:32
PropertySet should evaluate to its right-hand side
sra1
2016/11/24 23:53:52
Done.
| |
965 } | |
966 | |
967 @override | |
947 void visitVariableSet(ir.VariableSet variableSet) { | 968 void visitVariableSet(ir.VariableSet variableSet) { |
948 variableSet.value.accept(this); | 969 variableSet.value.accept(this); |
949 HInstruction value = pop(); | 970 HInstruction value = pop(); |
950 _visitLocalSetter(variableSet.variable, value); | 971 _visitLocalSetter(variableSet.variable, value); |
951 } | 972 } |
952 | 973 |
953 @override | 974 @override |
954 void visitVariableDeclaration(ir.VariableDeclaration declaration) { | 975 void visitVariableDeclaration(ir.VariableDeclaration declaration) { |
955 Local local = astAdapter.getLocal(declaration); | 976 Local local = astAdapter.getLocal(declaration); |
956 if (declaration.initializer == null) { | 977 if (declaration.initializer == null) { |
(...skipping 20 matching lines...) Expand all Loading... | |
977 value.sourceElement = local; | 998 value.sourceElement = local; |
978 } | 999 } |
979 | 1000 |
980 stack.add(value); | 1001 stack.add(value); |
981 localsHandler.updateLocal( | 1002 localsHandler.updateLocal( |
982 local, | 1003 local, |
983 typeBuilder.potentiallyCheckOrTrustType( | 1004 typeBuilder.potentiallyCheckOrTrustType( |
984 value, astAdapter.getDartType(variable.type))); | 1005 value, astAdapter.getDartType(variable.type))); |
985 } | 1006 } |
986 | 1007 |
1008 @override | |
1009 void visitLet(ir.Let let) { | |
1010 ir.VariableDeclaration variable = let.variable; | |
1011 variable.initializer.accept(this); | |
1012 HInstruction initializedValue = pop(); | |
1013 // TODO(sra): Apply inferred type information. | |
1014 letBindings[variable] = initializedValue; | |
1015 let.body.accept(this); | |
1016 } | |
1017 | |
987 // TODO(het): Also extract type arguments | 1018 // TODO(het): Also extract type arguments |
988 /// Extracts the list of instructions for the expressions in the arguments. | 1019 /// Extracts the list of instructions for the expressions in the arguments. |
989 List<HInstruction> _visitArguments(ir.Arguments arguments) { | 1020 List<HInstruction> _visitArguments(ir.Arguments arguments) { |
990 List<HInstruction> result = <HInstruction>[]; | 1021 List<HInstruction> result = <HInstruction>[]; |
991 | 1022 |
992 for (ir.Expression argument in arguments.positional) { | 1023 for (ir.Expression argument in arguments.positional) { |
993 argument.accept(this); | 1024 argument.accept(this); |
994 result.add(pop()); | 1025 result.add(pop()); |
995 } | 1026 } |
996 for (ir.NamedExpression argument in arguments.named) { | 1027 for (ir.NamedExpression argument in arguments.named) { |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); | 1477 push(new HInvokeDynamicSetter(selector, mask, null, inputs, type)); |
1447 } else { | 1478 } else { |
1448 push(new HInvokeDynamicMethod( | 1479 push(new HInvokeDynamicMethod( |
1449 selector, mask, inputs, type, isIntercepted)); | 1480 selector, mask, inputs, type, isIntercepted)); |
1450 } | 1481 } |
1451 } | 1482 } |
1452 | 1483 |
1453 // TODO(het): Decide when to inline | 1484 // TODO(het): Decide when to inline |
1454 @override | 1485 @override |
1455 void visitMethodInvocation(ir.MethodInvocation invocation) { | 1486 void visitMethodInvocation(ir.MethodInvocation invocation) { |
1487 print('visitMethodInvocation ${invocation}'); | |
asgerf
2016/11/24 09:44:32
Stray print
sra1
2016/11/24 23:53:52
Done.
| |
1488 | |
1456 invocation.receiver.accept(this); | 1489 invocation.receiver.accept(this); |
1457 HInstruction receiver = pop(); | 1490 HInstruction receiver = pop(); |
1458 | 1491 |
1459 _pushDynamicInvocation( | 1492 _pushDynamicInvocation( |
1460 invocation, | 1493 invocation, |
1461 astAdapter.typeOfInvocation(invocation), | 1494 astAdapter.typeOfInvocation(invocation), |
1462 <HInstruction>[receiver] | 1495 <HInstruction>[receiver] |
1463 ..addAll(_visitArguments(invocation.arguments))); | 1496 ..addAll(_visitArguments(invocation.arguments))); |
1464 } | 1497 } |
1465 | 1498 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1553 push(new HNot(popBoolified(), backend.boolType)); | 1586 push(new HNot(popBoolified(), backend.boolType)); |
1554 } | 1587 } |
1555 | 1588 |
1556 @override | 1589 @override |
1557 void visitStringConcatenation(ir.StringConcatenation stringConcat) { | 1590 void visitStringConcatenation(ir.StringConcatenation stringConcat) { |
1558 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); | 1591 KernelStringBuilder stringBuilder = new KernelStringBuilder(this); |
1559 stringConcat.accept(stringBuilder); | 1592 stringConcat.accept(stringBuilder); |
1560 stack.add(stringBuilder.result); | 1593 stack.add(stringBuilder.result); |
1561 } | 1594 } |
1562 } | 1595 } |
OLD | NEW |