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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1175973005: dart2js cps: Introduce some built-in operators in type propagation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Status files 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator;
10 import '../../js/js.dart' as js; 11 import '../../js/js.dart' as js;
11 import '../../elements/elements.dart'; 12 import '../../elements/elements.dart';
12 import '../../io/source_information.dart' show SourceInformation; 13 import '../../io/source_information.dart' show SourceInformation;
13 import '../../util/maplet.dart'; 14 import '../../util/maplet.dart';
14 import '../../constants/values.dart'; 15 import '../../constants/values.dart';
15 import '../../dart2jslib.dart'; 16 import '../../dart2jslib.dart';
16 import '../../dart_types.dart'; 17 import '../../dart_types.dart';
17 18
18 class CodegenBailout { 19 class CodegenBailout {
19 final tree_ir.Node node; 20 final tree_ir.Node node;
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 [visitExpression(node.target), index]); 689 [visitExpression(node.target), index]);
689 } 690 }
690 } 691 }
691 692
692 @override 693 @override
693 js.Expression visitTypeExpression(tree_ir.TypeExpression node) { 694 js.Expression visitTypeExpression(tree_ir.TypeExpression node) {
694 List<js.Expression> arguments = visitExpressionList(node.arguments); 695 List<js.Expression> arguments = visitExpressionList(node.arguments);
695 return glue.generateTypeRepresentation(node.dartType, arguments); 696 return glue.generateTypeRepresentation(node.dartType, arguments);
696 } 697 }
697 698
699 @override
700 js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) {
701 List<js.Expression> args = visitExpressionList(node.arguments);
702 switch (node.operator) {
703 case BuiltinOperator.NumAdd:
704 return new js.Binary('+', args[0], args[1]);
705 case BuiltinOperator.NumSubtract:
706 return new js.Binary('-', args[0], args[1]);
707 case BuiltinOperator.NumMultiply:
708 return new js.Binary('*', args[0], args[1]);
709 case BuiltinOperator.NumAnd:
710 return js.js('(# & #) >>> 0', <js.Expression>[args[0], args[1]]);
711 case BuiltinOperator.NumOr:
712 return js.js('(# | #) >>> 0', <js.Expression>[args[0], args[1]]);
713 case BuiltinOperator.NumXor:
714 return js.js('(# ^ #) >>> 0', <js.Expression>[args[0], args[1]]);
715 case BuiltinOperator.NumLt:
716 return new js.Binary('<', args[0], args[1]);
717 case BuiltinOperator.NumLe:
718 return new js.Binary('<=', args[0], args[1]);
719 case BuiltinOperator.NumGt:
720 return new js.Binary('>', args[0], args[1]);
721 case BuiltinOperator.NumGe:
722 return new js.Binary('>=', args[0], args[1]);
723 case BuiltinOperator.StrictEq:
724 return new js.Binary('===', args[0], args[1]);
725 case BuiltinOperator.StrictNeq:
726 return new js.Binary('!==', args[0], args[1]);
727 case BuiltinOperator.LooseEq:
728 return new js.Binary('==', args[0], args[1]);
729 case BuiltinOperator.LooseNeq:
730 return new js.Binary('!=', args[0], args[1]);
731 case BuiltinOperator.IsFalsy:
732 return new js.Prefix('!', args[0]);
733 }
734 }
735
698 visitFunctionExpression(tree_ir.FunctionExpression node) { 736 visitFunctionExpression(tree_ir.FunctionExpression node) {
699 // FunctionExpressions are currently unused. 737 // FunctionExpressions are currently unused.
700 // We might need them if we want to emit raw JS nested functions. 738 // We might need them if we want to emit raw JS nested functions.
701 throw 'FunctionExpressions should not be used'; 739 throw 'FunctionExpressions should not be used';
702 } 740 }
703 } 741 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/type_propagation.dart ('k') | pkg/compiler/lib/src/js_backend/codegen/task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698