Search in sources :

Example 1 with ConditionEdge

use of org.candle.decompiler.intermediate.graph.edge.ConditionEdge in project candle-decompiler by bradsdavis.

the class ConditionEdgeEnhancer method process.

@Override
public void process(InstructionHandle ih) {
    if (ih instanceof BranchHandle) {
        //ok, now we need to replace existing successor edges appropriately.
        BranchHandle bh = (BranchHandle) ih;
        List<InstructionHandle> successors = igc.getSuccessors(ih);
        TreeSet<InstructionHandle> orderedSuccessors = new TreeSet<InstructionHandle>(new InstructionComparator());
        orderedSuccessors.addAll(successors);
        if (successors.size() == 2) {
            //lowest will be true condition.... 
            IntermediateEdge truePath = igc.getGraph().getEdge(ih, orderedSuccessors.first());
            ConditionEdge trueCondition = createConditionalEdge(truePath, true);
            igc.getGraph().removeEdge(truePath);
            igc.getGraph().addEdge(ih, orderedSuccessors.first(), trueCondition);
            //highest will be false condition....
            IntermediateEdge falsePath = igc.getGraph().getEdge(ih, orderedSuccessors.last());
            ConditionEdge falseCondition = createConditionalEdge(falsePath, false);
            igc.getGraph().removeEdge(falsePath);
            igc.getGraph().addEdge(ih, orderedSuccessors.last(), falseCondition);
        }
    }
}
Also used : InstructionComparator(org.candle.decompiler.instruction.graph.vertex.InstructionComparator) TreeSet(java.util.TreeSet) BranchHandle(org.apache.bcel.generic.BranchHandle) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle) ConditionEdge(org.candle.decompiler.intermediate.graph.edge.ConditionEdge)

Example 2 with ConditionEdge

use of org.candle.decompiler.intermediate.graph.edge.ConditionEdge in project candle-decompiler by bradsdavis.

the class ConditionEdgeEnhancer method createConditionalEdge.

public ConditionEdge createConditionalEdge(IntermediateEdge ie, boolean condition) {
    ConditionEdge ce = new ConditionEdge();
    ce.setCondition(condition);
    ce.setType(ie.getType());
    ce.getAttributes().putAll(ie.getAttributes());
    return ce;
}
Also used : ConditionEdge(org.candle.decompiler.intermediate.graph.edge.ConditionEdge)

Aggregations

ConditionEdge (org.candle.decompiler.intermediate.graph.edge.ConditionEdge)2 TreeSet (java.util.TreeSet)1 BranchHandle (org.apache.bcel.generic.BranchHandle)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 InstructionComparator (org.candle.decompiler.instruction.graph.vertex.InstructionComparator)1 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)1