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

Side by Side 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 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 library dart2js.unsugar_cps;
2
3 import '../../cps_ir/cps_ir_nodes.dart';
4
5 // TODO(karlklose): share the [ParentVisitor].
6 import '../../cps_ir/optimizers.dart';
7 import '../../constants/expressions.dart';
8 import '../../constants/values.dart';
9
10 /// Rewrites the initial CPS IR to make Dart semantics explicit and inserts
11 /// special nodes that respect JavaScript behavior.
12 ///
13 /// Performs the following rewrites:
14 /// - rewrite [IsTrue] in a [Branch] to do boolean conversion.
15 class UnsugarVisitor extends RecursiveVisitor {
16 const UnsugarVisitor();
17
18 void rewrite(FunctionDefinition function) {
19 // Set all parent pointers.
20 new ParentVisitor().visit(function);
21 visit(function);
22 }
23
24 @override
25 visit(Node node) {
26 Node result = node.accept(this);
27 return result != null ? result : node;
28 }
29
30 Constant get trueConstant {
31 return new Constant(
32 new PrimitiveConstantExpression(
33 new TrueConstantValue()));
34 }
35
36 processBranch(Branch node) {
37 // TODO(karlklose): implement the checked mode part of boolean conversion.
38 InteriorNode parent = node.parent;
39 IsTrue condition = node.condition;
40 Primitive t = trueConstant;
41 Primitive i = new Identical(condition.value.definition, t);
42 LetPrim newNode = new LetPrim(t,
43 new LetPrim(i,
44 new Branch(new IsTrue(i),
45 node.trueContinuation.definition,
46 node.falseContinuation.definition)));
47 condition.value.unlink();
48 node.trueContinuation.unlink();
49 node.falseContinuation.unlink();
50 parent.body = newNode;
51 }
52 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/task.dart ('k') | pkg/compiler/lib/src/tree_ir/tree_ir_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698