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

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: 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 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..b752a21a540e29dae94df820edd83dc87ef1e4c7 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.NumAdd:
+ return new js.Binary('+', args[0], args[1]);
+ case BuiltinOperator.NumSubtract:
+ 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]]);
+ 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.
« 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