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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/js_backend/codegen/codegen.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
index 9a05a589e8227ad157530bf829e44da0241278ef..508159e49ade08e154664e821f7d69e9d68dd2d2 100644
--- a/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
+++ b/pkg/compiler/lib/src/js_backend/codegen/codegen.dart
@@ -7,6 +7,7 @@ library code_generator;
import 'glue.dart';
import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
+import '../../tree_ir/tree_ir_nodes.dart' show BuiltinOperator;
import '../../js/js.dart' as js;
import '../../elements/elements.dart';
import '../../io/source_information.dart' show SourceInformation;
@@ -695,6 +696,43 @@ class CodeGenerator extends tree_ir.StatementVisitor
return glue.generateTypeRepresentation(node.dartType, arguments);
}
+ @override
+ js.Expression visitApplyBuiltinOperator(tree_ir.ApplyBuiltinOperator node) {
+ List<js.Expression> args = visitExpressionList(node.arguments);
+ switch (node.operator) {
+ case BuiltinOperator.NumPlus:
+ return new js.Binary('+', args[0], args[1]);
+ case BuiltinOperator.NumMinus:
+ return new js.Binary('-', args[0], args[1]);
+ case BuiltinOperator.NumMultiply:
+ return new js.Binary('*', args[0], args[1]);
+ case BuiltinOperator.NumAnd:
+ return js.js('(# & #) >>> 0', <js.Expression>[args[0], args[1]]);
sra1 2015/06/10 21:07:37 We don't always need the >>> 0. SSA has the type a
asgerf 2015/06/11 11:16:40 We should definitely have the same in the CPS pipe
+ case BuiltinOperator.NumOr:
+ return js.js('(# | #) >>> 0', <js.Expression>[args[0], args[1]]);
+ case BuiltinOperator.NumXor:
+ return js.js('(# ^ #) >>> 0', <js.Expression>[args[0], args[1]]);
+ case BuiltinOperator.NumLt:
+ return new js.Binary('<', args[0], args[1]);
+ case BuiltinOperator.NumLe:
+ return new js.Binary('<=', args[0], args[1]);
+ case BuiltinOperator.NumGt:
+ return new js.Binary('>', args[0], args[1]);
+ case BuiltinOperator.NumGe:
+ return new js.Binary('>=', args[0], args[1]);
+ case BuiltinOperator.StrictEq:
+ return new js.Binary('===', args[0], args[1]);
+ case BuiltinOperator.StrictNeq:
+ return new js.Binary('!==', args[0], args[1]);
+ case BuiltinOperator.LooseEq:
+ return new js.Binary('==', args[0], args[1]);
+ case BuiltinOperator.LooseNeq:
+ return new js.Binary('!=', args[0], args[1]);
+ case BuiltinOperator.IsFalsy:
+ return new js.Prefix('!', args[0]);
+ }
+ }
+
visitFunctionExpression(tree_ir.FunctionExpression node) {
// FunctionExpressions are currently unused.
// We might need them if we want to emit raw JS nested functions.

Powered by Google App Engine
This is Rietveld 408576698