Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart

Issue 1185633003: cps-ir: Support foreign code. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Update test expectations. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_nodes; 4 library dart2js.ir_nodes;
5 5
6 import '../constants/expressions.dart'; 6 import '../constants/expressions.dart';
7 import '../constants/values.dart' as values show ConstantValue; 7 import '../constants/values.dart' as values show ConstantValue;
8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType;
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../io/source_information.dart' show SourceInformation; 10 import '../io/source_information.dart' show SourceInformation;
11 import '../universe/universe.dart' show Selector, SelectorKind; 11 import '../universe/universe.dart' show Selector, SelectorKind;
12 12
13 import 'builtin_operator.dart'; 13 import 'builtin_operator.dart';
14 export 'builtin_operator.dart'; 14 export 'builtin_operator.dart';
15 15
16 // These imports are only used for the JavaScript specific nodes. If we want to
17 // support more than one native backend, we should probably create better
18 // abstractions for native code and its type and effect system.
19 import '../js/js.dart' as js show Template;
20 import '../native/native.dart' as native show NativeBehavior;
21 import '../types/types.dart' as types show TypeMask;
22
16 abstract class Node { 23 abstract class Node {
17 /// A pointer to the parent node. Is null until set by optimization passes. 24 /// A pointer to the parent node. Is null until set by optimization passes.
18 Node parent; 25 Node parent;
19 26
20 accept(Visitor visitor); 27 accept(Visitor visitor);
21 } 28 }
22 29
23 /// Expressions can be evaluated, and may diverge, throw, and/or have 30 /// Expressions can be evaluated, and may diverge, throw, and/or have
24 /// side-effects. 31 /// side-effects.
25 /// 32 ///
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 class CreateInvocationMirror extends Primitive { 726 class CreateInvocationMirror extends Primitive {
720 final Selector selector; 727 final Selector selector;
721 final List<Reference<Primitive>> arguments; 728 final List<Reference<Primitive>> arguments;
722 729
723 CreateInvocationMirror(this.selector, List<Primitive> arguments) 730 CreateInvocationMirror(this.selector, List<Primitive> arguments)
724 : this.arguments = _referenceList(arguments); 731 : this.arguments = _referenceList(arguments);
725 732
726 accept(Visitor visitor) => visitor.visitCreateInvocationMirror(this); 733 accept(Visitor visitor) => visitor.visitCreateInvocationMirror(this);
727 } 734 }
728 735
736 class ForeignCode extends Expression {
737 final js.Template codeTemplate;
738 final types.TypeMask type;
739 final List<Reference<Primitive>> arguments;
740 final native.NativeBehavior nativeBehavior;
741 final FunctionElement dependency;
742
743 /// The continuation, if the foreign code is not a JavaScript 'throw',
744 /// otherwise null.
745 final Reference<Continuation> continuation;
746
747 ForeignCode(this.codeTemplate, this.type, List<Primitive> arguments,
748 this.nativeBehavior, {Continuation continuation, this.dependency})
749 : arguments = _referenceList(arguments),
750 continuation = continuation == null ? null
751 : new Reference<Continuation>(continuation);
752
753 accept(Visitor visitor) => visitor.visitForeignCode(this);
754 }
755
729 class Constant extends Primitive { 756 class Constant extends Primitive {
730 final ConstantExpression expression; 757 final ConstantExpression expression;
731 final values.ConstantValue value; 758 final values.ConstantValue value;
732 759
733 Constant(this.expression, this.value); 760 Constant(this.expression, this.value);
734 761
735 accept(Visitor visitor) => visitor.visitConstant(this); 762 accept(Visitor visitor) => visitor.visitConstant(this);
736 } 763 }
737 764
738 class LiteralList extends Primitive { 765 class LiteralList extends Primitive {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 T visitCreateBox(CreateBox node); 980 T visitCreateBox(CreateBox node);
954 T visitReifyRuntimeType(ReifyRuntimeType node); 981 T visitReifyRuntimeType(ReifyRuntimeType node);
955 T visitReadTypeVariable(ReadTypeVariable node); 982 T visitReadTypeVariable(ReadTypeVariable node);
956 T visitTypeExpression(TypeExpression node); 983 T visitTypeExpression(TypeExpression node);
957 T visitCreateInvocationMirror(CreateInvocationMirror node); 984 T visitCreateInvocationMirror(CreateInvocationMirror node);
958 T visitTypeTest(TypeTest node); 985 T visitTypeTest(TypeTest node);
959 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); 986 T visitApplyBuiltinOperator(ApplyBuiltinOperator node);
960 987
961 // Conditions. 988 // Conditions.
962 T visitIsTrue(IsTrue node); 989 T visitIsTrue(IsTrue node);
990
991 // Support for literal foreign code.
992 T visitForeignCode(ForeignCode node);
963 } 993 }
964 994
965 /// Recursively visits the entire CPS term, and calls abstract `process*` 995 /// Recursively visits the entire CPS term, and calls abstract `process*`
966 /// (i.e. `processLetPrim`) functions in pre-order. 996 /// (i.e. `processLetPrim`) functions in pre-order.
967 class RecursiveVisitor implements Visitor { 997 class RecursiveVisitor implements Visitor {
968 const RecursiveVisitor(); 998 const RecursiveVisitor();
969 999
970 visit(Node node) => node.accept(this); 1000 visit(Node node) => node.accept(this);
971 1001
972 processReference(Reference ref) {} 1002 processReference(Reference ref) {}
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 processCreateInvocationMirror(node); 1268 processCreateInvocationMirror(node);
1239 node.arguments.forEach(processReference); 1269 node.arguments.forEach(processReference);
1240 } 1270 }
1241 1271
1242 processApplyBuiltinOperator(ApplyBuiltinOperator node) {} 1272 processApplyBuiltinOperator(ApplyBuiltinOperator node) {}
1243 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { 1273 visitApplyBuiltinOperator(ApplyBuiltinOperator node) {
1244 processApplyBuiltinOperator(node); 1274 processApplyBuiltinOperator(node);
1245 node.arguments.forEach(processReference); 1275 node.arguments.forEach(processReference);
1246 } 1276 }
1247 1277
1278 processForeignCode(ForeignCode node) {}
1279 visitForeignCode(ForeignCode node) {
1280 processForeignCode(node);
1281 if (node.continuation != null) {
1282 processReference(node.continuation);
1283 }
1284 node.arguments.forEach(processReference);
1285 }
1286
1248 processUnreachable(Unreachable node) {} 1287 processUnreachable(Unreachable node) {}
1249 visitUnreachable(Unreachable node) { 1288 visitUnreachable(Unreachable node) {
1250 processUnreachable(node); 1289 processUnreachable(node);
1251 } 1290 }
1252 } 1291 }
1253 1292
1254 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 1293 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
1255 class RemovalVisitor extends RecursiveVisitor { 1294 class RemovalVisitor extends RecursiveVisitor {
1256 const RemovalVisitor(); 1295 const RemovalVisitor();
1257 1296
1258 processReference(Reference reference) { 1297 processReference(Reference reference) {
1259 reference.unlink(); 1298 reference.unlink();
1260 } 1299 }
1261 1300
1262 static void remove(Node node) { 1301 static void remove(Node node) {
1263 (const RemovalVisitor()).visit(node); 1302 (const RemovalVisitor()).visit(node);
1264 } 1303 }
1265 } 1304 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698