Improve loops parsing

This commit is contained in:
Skylot
2013-03-28 23:42:35 +04:00
parent 772c664d47
commit 3bd11fa562
2 changed files with 23 additions and 10 deletions
@@ -92,6 +92,9 @@ public class MarkTryCatchRegions extends AbstractRegionVisitor {
if (tryBlocksMap.isEmpty())
return;
if (!(region instanceof Region))
return;
// search dominator blocks in this region (don't need to go deeper)
for (BlockNode dominator : tryBlocksMap.keySet()) {
if (region.getSubBlocks().contains(dominator)) {
@@ -147,21 +147,31 @@ public class RegionMaker {
InsnNode insn = exit.getInstructions().get(0);
if (insn.getType() == InsnType.IF) {
boolean found = true;
ifnode = (IfNode) insn;
condBlock = exit;
loopRegion = new LoopRegion(curRegion, condBlock, condBlock == loop.getEnd());
if (!loopRegion.isConditionAtEnd() && condBlock != loop.getStart()
&& condBlock.getPredecessors().contains(loopStart)) {
loopRegion.setPreCondition(loopStart);
// if we can't merge pre-condition this is not correct header
if (!loopRegion.checkPreCondition()) {
ifnode = null;
loopRegion = null;
// try another exit
continue;
if (loopRegion.isConditionAtEnd()) {
// TODO: add some checks
} else {
if (condBlock != loop.getStart()) {
if (condBlock.getPredecessors().contains(loopStart)) {
loopRegion.setPreCondition(loopStart);
// if we can't merge pre-condition this is not correct header
found = loopRegion.checkPreCondition();
} else {
found = false;
}
}
}
break;
if (!found) {
ifnode = null;
loopRegion = null;
condBlock = null;
// try another exit
} else
break;
}
}