Permalink
Browse files

cfg: fix graph structure

  • Loading branch information...
1 parent c28449f commit da58ee7376cfaaf8eb2e9941ce56524f812a94f4 @indutny committed Sep 27, 2012
Showing with 18 additions and 6 deletions.
  1. +18 −5 lib/spoon/cfg.js
  2. +0 −1 lib/spoon/instruction.js
View
@@ -200,9 +200,6 @@ Cfg.prototype.asyncify = function asyncify(asts, level) {
}
block.successors.forEach(function(succ) {
- // Do not loop back
- if (succ.loop && succ.predecessors[1] === block) return;
-
// All children should be processed too
hasDeclaration[succ.id] = succ;
});
@@ -721,6 +718,10 @@ Cfg.prototype.visitLogical = function visitLogical(ast) {
move1.addArg(phi);
move2.addArg(phi);
+ var afterJoin = this.createBlock();
+ this.goto(afterJoin);
+ this.setCurrentBlock(afterJoin);
+
return phi;
};
@@ -771,9 +772,13 @@ Cfg.prototype.visitIf = function visitIf(ast) {
this.setCurrentBlock(fblock);
this.visit(ast.alternate);
this.goto(join);
- }
- this.setCurrentBlock(join);
+ var afterJoin = this.createBlock();
+ join.goto(afterJoin);
+ this.setCurrentBlock(afterJoin);
+ } else {
+ this.setCurrentBlock(join);
+ }
return null;
};
@@ -944,6 +949,10 @@ Cfg.prototype.visitConditional = function visitConditional(ast) {
move1.addArg(phi);
move2.addArg(phi);
+ var afterJoin = this.createBlock();
+ this.goto(afterJoin);
+ this.setCurrentBlock(afterJoin);
+
return phi;
};
@@ -1077,6 +1086,10 @@ Cfg.prototype.visitTry = function visitTry(ast) {
this.setCurrentBlock(join);
if (ast.finalizer) throw TypeError('Finally is not supported yet');
+ var afterJoin = this.createBlock();
+ this.goto(afterJoin);
+ this.setCurrentBlock(afterJoin);
+
return null;
};
View
@@ -17,7 +17,6 @@ function Instruction(block, type, args) {
if (!(arg instanceof Instruction)) return;
arg.uses.push(this);
}, this);
-
};
instruction.Instruction = Instruction;
instruction.create = function create(block, type, args) {

0 comments on commit da58ee7

Please sign in to comment.