diff --git a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java index b018b1b4fc..a851a90b6c 100644 --- a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java +++ b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java @@ -787,7 +787,8 @@ protected boolean isMergeable( } // if we are here the datastructure should have managed that the next if is true.. final List sBlockPredecessors = followingBlock.getPredecessors(); - if (sBlockPredecessors.size() > 1 || (sBlockPredecessors.size()==1 && sBlockPredecessors.get(0) != firstBlock)) { + if (sBlockPredecessors.size() > 1 + || (sBlockPredecessors.size() == 1 && sBlockPredecessors.get(0) != firstBlock)) { return false; } // check if the same traps are applied to both blocks @@ -1128,7 +1129,7 @@ public BasicBlock insertBefore( } } - private void checkAndResetStartingStmt(Stmt beforeStmt, List stmts){ + private void checkAndResetStartingStmt(Stmt beforeStmt, List stmts) { if (beforeStmt == getStartingStmt()) { setStartingStmt(stmts.get(0)); } diff --git a/sootup.interceptors/src/main/java/sootup/interceptors/StaticSingleAssignmentFormer.java b/sootup.interceptors/src/main/java/sootup/interceptors/StaticSingleAssignmentFormer.java index f4fe58a4c2..0741b653e0 100644 --- a/sootup.interceptors/src/main/java/sootup/interceptors/StaticSingleAssignmentFormer.java +++ b/sootup.interceptors/src/main/java/sootup/interceptors/StaticSingleAssignmentFormer.java @@ -99,7 +99,7 @@ public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) // delete meaningless phiStmts and add other phiStmts into stmtGraph addPhiStmts(blockToPhiStmts, stmtGraph, blockToDefs); - //some blocks are modified, so DominanceFinder must be updated for building dominance tree + // some blocks are modified, so DominanceFinder must be updated for building dominance tree DominanceTree tree = new DominanceTree(new DominanceFinder(stmtGraph)); Map> localToNameStack = new HashMap<>(); @@ -312,14 +312,14 @@ private void addPhiStmts( } for (FallsThroughStmt phi : phis) { BasicBlock updatedBlock = blockGraph.insertBefore(block.getHead(), phi); - if(!updatedBlock.equals(block)){ + if (!updatedBlock.equals(block)) { old2UpdatedBlock.put(block, updatedBlock); } } } - //update new blocks in blockToPhiStmts - if(!old2UpdatedBlock.isEmpty()){ - for(BasicBlock oldB : old2UpdatedBlock.keySet()){ + // update new blocks in blockToPhiStmts + if (!old2UpdatedBlock.isEmpty()) { + for (BasicBlock oldB : old2UpdatedBlock.keySet()) { Set phis = blockToPhiStmts.get(oldB); blockToPhiStmts.remove(oldB); blockToPhiStmts.put(old2UpdatedBlock.get(oldB), phis); diff --git a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/StaticSingleAssignmentFormerTest.java b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/StaticSingleAssignmentFormerTest.java index 7b803a841b..345130b985 100644 --- a/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/StaticSingleAssignmentFormerTest.java +++ b/sootup.java.bytecode.frontend/src/test/java/sootup/java/bytecode/frontend/interceptors/StaticSingleAssignmentFormerTest.java @@ -51,9 +51,12 @@ public class StaticSingleAssignmentFormerTest { Local stack4 = JavaJimple.newLocal("stack4", refType); JIdentityStmt startingStmt = JavaJimple.newIdentityStmt(l0, identityRef, noStmtPositionInfo); - JAssignStmt assign1tol1 = JavaJimple.newAssignStmt(l1, IntConstant.getInstance(1), noStmtPositionInfo); - JAssignStmt assign1tol2 = JavaJimple.newAssignStmt(l2, IntConstant.getInstance(2), noStmtPositionInfo); - JAssignStmt assign0tol3 = JavaJimple.newAssignStmt(l3, IntConstant.getInstance(0), noStmtPositionInfo); + JAssignStmt assign1tol1 = + JavaJimple.newAssignStmt(l1, IntConstant.getInstance(1), noStmtPositionInfo); + JAssignStmt assign1tol2 = + JavaJimple.newAssignStmt(l2, IntConstant.getInstance(2), noStmtPositionInfo); + JAssignStmt assign0tol3 = + JavaJimple.newAssignStmt(l3, IntConstant.getInstance(0), noStmtPositionInfo); BranchingStmt ifStmt = JavaJimple.newIfStmt( JavaJimple.newLtExpr(l3, IntConstant.getInstance(100)), noStmtPositionInfo); @@ -86,43 +89,43 @@ public void testSSA() { ssa.interceptBody(builder, new JavaView(Collections.emptyList())); System.out.println(builder.build()); String expectedBodyString = - "{\n" + - " Test l0, l0#0;\n" + - " int l1, l1#1, l2, l2#10, l2#2, l2#4, l2#6, l2#8, l3, l3#11, l3#3, l3#5, l3#7, l3#9;\n" + - "\n" + - "\n" + - " l0#0 := @this: Test;\n" + - " l1#1 = 1;\n" + - " l2#2 = 2;\n" + - " l3#3 = 0;\n" + - "\n" + - " label1:\n" + - " l2#4 = phi(l2#2, l2#10);\n" + - " l3#5 = phi(l3#3, l3#11);\n" + - "\n" + - " if l3#5 < 100 goto label2;\n" + - "\n" + - " return l2#4;\n" + - "\n" + - " label2:\n" + - " if l2#4 < 20 goto label3;\n" + - " l2#8 = l3#5;\n" + - " l3#9 = l3#5 + 2;\n" + - "\n" + - " goto label4;\n" + - "\n" + - " label3:\n" + - " l2#6 = l1#1;\n" + - " l3#7 = l3#5 + 1;\n" + - "\n" + - " goto label4;\n" + - "\n" + - " label4:\n" + - " l2#10 = phi(l2#6, l2#8);\n" + - " l3#11 = phi(l3#7, l3#9);\n" + - "\n" + - " goto label1;\n" + - "}\n"; + "{\n" + + " Test l0, l0#0;\n" + + " int l1, l1#1, l2, l2#10, l2#2, l2#4, l2#6, l2#8, l3, l3#11, l3#3, l3#5, l3#7, l3#9;\n" + + "\n" + + "\n" + + " l0#0 := @this: Test;\n" + + " l1#1 = 1;\n" + + " l2#2 = 2;\n" + + " l3#3 = 0;\n" + + "\n" + + " label1:\n" + + " l2#4 = phi(l2#2, l2#10);\n" + + " l3#5 = phi(l3#3, l3#11);\n" + + "\n" + + " if l3#5 < 100 goto label2;\n" + + "\n" + + " return l2#4;\n" + + "\n" + + " label2:\n" + + " if l2#4 < 20 goto label3;\n" + + " l2#8 = l3#5;\n" + + " l3#9 = l3#5 + 2;\n" + + "\n" + + " goto label4;\n" + + "\n" + + " label3:\n" + + " l2#6 = l1#1;\n" + + " l3#7 = l3#5 + 1;\n" + + "\n" + + " goto label4;\n" + + "\n" + + " label4:\n" + + " l2#10 = phi(l2#6, l2#8);\n" + + " l3#11 = phi(l3#7, l3#9);\n" + + "\n" + + " goto label1;\n" + + "}\n"; assertEquals(expectedBodyString, builder.build().toString()); } @@ -218,32 +221,32 @@ public void testTrappedSSA() { private Body.BodyBuilder createBody() { MutableBlockStmtGraph graph = new MutableBlockStmtGraph(); - //Block0 + // Block0 graph.setStartingStmt(startingStmt); graph.putEdge(startingStmt, assign1tol1); graph.putEdge(assign1tol1, assign1tol2); graph.putEdge(assign1tol2, assign0tol3); - //block1 + // block1 graph.putEdge(assign0tol3, ifStmt); - //block2 - graph.putEdge(ifStmt,JIfStmt.TRUE_BRANCH_IDX, ifStmt2); + // block2 + graph.putEdge(ifStmt, JIfStmt.TRUE_BRANCH_IDX, ifStmt2); - //block3 - graph.putEdge(ifStmt,JIfStmt.FALSE_BRANCH_IDX, returnStmt); + // block3 + graph.putEdge(ifStmt, JIfStmt.FALSE_BRANCH_IDX, returnStmt); - //block4 + // block4 graph.putEdge(ifStmt2, JIfStmt.TRUE_BRANCH_IDX, assignl1tol2); graph.putEdge(assignl1tol2, assignl3plus1tol3); graph.putEdge(assignl3plus1tol3, gotoStmt1); - //block 5 + // block 5 graph.putEdge(ifStmt2, JIfStmt.FALSE_BRANCH_IDX, assignl3tol2); graph.putEdge(assignl3tol2, assignl3plus2tol3); graph.putEdge(assignl3plus2tol3, gotoStmt2); - //block 6 + // block 6 graph.putEdge(gotoStmt1, JGotoStmt.BRANCH_IDX, goTo); graph.putEdge(gotoStmt2, JGotoStmt.BRANCH_IDX, goTo); graph.putEdge(goTo, JGotoStmt.BRANCH_IDX, ifStmt);