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

Unified Diff: pkg/compiler/lib/src/js_backend/codegen/unsugar.dart

Issue 735253003: Add CPS IR transformation to make the JavaScript backend specific semantics explicit in the tree. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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/unsugar.dart
diff --git a/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1dc36271993f9d524509042924fcb36f4bda2a09
--- /dev/null
+++ b/pkg/compiler/lib/src/js_backend/codegen/unsugar.dart
@@ -0,0 +1,52 @@
+library dart2js.unsugar_cps;
+
+import '../../cps_ir/cps_ir_nodes.dart';
+
+// TODO(karlklose): share the [ParentVisitor].
+import '../../cps_ir/optimizers.dart';
+import '../../constants/expressions.dart';
+import '../../constants/values.dart';
+
+/// Rewrites the initial CPS IR to make Dart semantics explicit and inserts
+/// special nodes that respect JavaScript behavior.
+///
+/// Performs the following rewrites:
+/// - rewrite [IsTrue] in a [Branch] to do boolean conversion.
+class UnsugarVisitor extends RecursiveVisitor {
+ const UnsugarVisitor();
+
+ void rewrite(FunctionDefinition function) {
+ // Set all parent pointers.
+ new ParentVisitor().visit(function);
+ visit(function);
+ }
+
+ @override
+ visit(Node node) {
+ Node result = node.accept(this);
+ return result != null ? result : node;
+ }
+
+ Constant get trueConstant {
+ return new Constant(
+ new PrimitiveConstantExpression(
+ new TrueConstantValue()));
+ }
+
+ processBranch(Branch node) {
+ // TODO(karlklose): implement the checked mode part of boolean conversion.
+ InteriorNode parent = node.parent;
+ IsTrue condition = node.condition;
+ Primitive t = trueConstant;
+ Primitive i = new Identical(condition.value.definition, t);
+ LetPrim newNode = new LetPrim(t,
+ new LetPrim(i,
+ new Branch(new IsTrue(i),
+ node.trueContinuation.definition,
+ node.falseContinuation.definition)));
+ condition.value.unlink();
+ node.trueContinuation.unlink();
+ node.falseContinuation.unlink();
+ parent.body = newNode;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698