Search in sources :

Example 11 with Program

use of de.mirkosertic.bytecoder.ssa.Program in project Bytecoder by mirkosertic.

the class RelooperTest method testDirectFlow.

@Test
public void testDirectFlow() {
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    theNode1.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(10)));
    RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
    theNode2.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(20)));
    RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
    theNode3.getExpressions().add(new ReturnExpression());
    theNode1.addSuccessor(theNode2);
    theNode2.addSuccessor(theNode3);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 12 with Program

use of de.mirkosertic.bytecoder.ssa.Program in project Bytecoder by mirkosertic.

the class RelooperTest method testSwitchCase.

@Test
public void testSwitchCase() {
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
    theNode2.getExpressions().add(new ReturnExpression());
    RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
    theNode3.getExpressions().add(new ReturnExpression());
    RegionNode theNode4 = theGraph.createAt(new BytecodeOpcodeAddress(30), RegionNode.BlockType.NORMAL);
    theNode4.getExpressions().add(new ReturnExpression());
    theNode1.addSuccessor(theNode2);
    theNode1.addSuccessor(theNode3);
    theNode1.addSuccessor(theNode4);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 13 with Program

use of de.mirkosertic.bytecoder.ssa.Program in project Bytecoder by mirkosertic.

the class RelooperTest method testIf.

@Test
public void testIf() {
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode1 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    theNode1.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(10)));
    RegionNode theNode2 = theGraph.createAt(new BytecodeOpcodeAddress(10), RegionNode.BlockType.NORMAL);
    theNode2.getExpressions().add(new GotoExpression(new BytecodeOpcodeAddress(20)));
    RegionNode theNode3 = theGraph.createAt(new BytecodeOpcodeAddress(20), RegionNode.BlockType.NORMAL);
    theNode3.getExpressions().add(new ReturnExpression());
    theNode1.addSuccessor(theNode2);
    theNode1.addSuccessor(theNode3);
    theNode2.addSuccessor(theNode3);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) Program(de.mirkosertic.bytecoder.ssa.Program) GotoExpression(de.mirkosertic.bytecoder.ssa.GotoExpression) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Example 14 with Program

use of de.mirkosertic.bytecoder.ssa.Program in project Bytecoder by mirkosertic.

the class RelooperTest method testNestedIfs.

@Test
public void testNestedIfs() {
    /**
     *        digraph CFG {
     *            N0 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td><td> V 3</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="4"> Node at 0</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N0 ->    N39;
     *            N0 ->    N8;
     *            N8 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td><td> V 3</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="4"> Node at 8</td></tr><tr><td>X</td><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N8 ->    N19;
     *            N8 ->    N39;
     *            N19 [shape=none, margin=0, label=<<table><tr><td> V 0</td><td> V 1</td><td> V 2</td></tr><tr><td>X</td><td>X</td><td>X</td></tr><tr><td colspan="3"> Node at 19</td></tr><tr><td>X</td><td>X</td><td>X</td></tr><tr><td>REFERENCE</td><td>FLOAT</td><td>FLOAT</td></tr></table>>];
     *            N19 ->    N39;
     *            N39 [shape=none, margin=0, label=<<table><tr><td colspan="0"> Node at 39</td></tr></table>>];
     *        }
     */
    Program theProgram = new Program();
    ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
    RegionNode theNode0 = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
    RegionNode theNode8 = theGraph.createAt(new BytecodeOpcodeAddress(8), RegionNode.BlockType.NORMAL);
    RegionNode theNode19 = theGraph.createAt(new BytecodeOpcodeAddress(19), RegionNode.BlockType.NORMAL);
    RegionNode theNode39 = theGraph.createAt(new BytecodeOpcodeAddress(39), RegionNode.BlockType.NORMAL);
    theNode0.addSuccessor(theNode8);
    theNode0.addSuccessor(theNode39);
    theNode8.addSuccessor(theNode19);
    theNode8.addSuccessor(theNode39);
    theNode19.addSuccessor(theNode39);
    theGraph.calculateReachabilityAndMarkBackEdges();
    Relooper theRelooper = new Relooper();
    Relooper.Block theBlock = theRelooper.reloop(theGraph);
    theRelooper.debugPrint(System.out, theBlock);
}
Also used : Program(de.mirkosertic.bytecoder.ssa.Program) ControlFlowGraph(de.mirkosertic.bytecoder.ssa.ControlFlowGraph) BytecodeOpcodeAddress(de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress) RegionNode(de.mirkosertic.bytecoder.ssa.RegionNode) Test(org.junit.Test)

Aggregations

Program (de.mirkosertic.bytecoder.ssa.Program)14 RegionNode (de.mirkosertic.bytecoder.ssa.RegionNode)11 ControlFlowGraph (de.mirkosertic.bytecoder.ssa.ControlFlowGraph)9 Test (org.junit.Test)9 BytecodeOpcodeAddress (de.mirkosertic.bytecoder.core.BytecodeOpcodeAddress)8 GotoExpression (de.mirkosertic.bytecoder.ssa.GotoExpression)6 ReturnExpression (de.mirkosertic.bytecoder.ssa.ReturnExpression)6 Relooper (de.mirkosertic.bytecoder.relooper.Relooper)5 Variable (de.mirkosertic.bytecoder.ssa.Variable)5 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)4 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)3 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)3 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)3 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)3 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)3 ProgramGenerator (de.mirkosertic.bytecoder.ssa.ProgramGenerator)3 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 ConstantPool (de.mirkosertic.bytecoder.backend.ConstantPool)2 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)2