Search in sources :

Example 6 with IntermediateEdge

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

the class InstructionGraphWriter method process.

@Override
public void process() {
    if (directory == null) {
        return;
    }
    File a = new File(directory.getAbsolutePath() + File.separator + name);
    LOG.debug("Instruction Graph: " + a.getAbsolutePath());
    Writer x;
    try {
        x = new FileWriter(a);
        DOTExporter<InstructionHandle, IntermediateEdge> f = new DOTExporter<InstructionHandle, IntermediateEdge>(new IntegerNameProvider<InstructionHandle>(), new InstructionLabelProvider(), new IntermediateEdgeProvider(), null, new InstructionEdgeAttributeProvider());
        f.export(x, igc.getGraph());
    } catch (IOException e) {
        e.printStackTrace();
    }
    LOG.debug("End Instruction Graph ======");
}
Also used : DOTExporter(org.jgrapht.ext.DOTExporter) InstructionLabelProvider(org.candle.decompiler.instruction.graph.vertex.InstructionLabelProvider) IntermediateEdgeProvider(org.candle.decompiler.intermediate.graph.edge.IntermediateEdgeProvider) FileWriter(java.io.FileWriter) InstructionEdgeAttributeProvider(org.candle.decompiler.instruction.graph.edge.InstructionEdgeAttributeProvider) IOException(java.io.IOException) File(java.io.File) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) FileWriter(java.io.FileWriter) Writer(java.io.Writer) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 7 with IntermediateEdge

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

the class InstructionToIntermediateEnhancer method process.

@Override
public void process() {
    GraphIterator<InstructionHandle, IntermediateEdge> iterator = new DepthFirstIterator<InstructionHandle, IntermediateEdge>(igc.getGraph());
    iterator.addTraversalListener(new InstructionTransversalListener(igc, intermediateContext));
    while (iterator.hasNext()) {
        iterator.next();
    }
}
Also used : DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) InstructionTransversalListener(org.candle.decompiler.instruction.intermediate.InstructionTransversalListener) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 8 with IntermediateEdge

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

the class BackEdgeEnhancer method process.

@Override
public void process(InstructionHandle ih) {
    List<InstructionHandle> successors = Graphs.successorListOf(igc.getGraph(), ih);
    for (InstructionHandle successor : successors) {
        IntermediateEdge ie = igc.getGraph().getEdge(ih, successor);
        // color back...
        int t1 = ih.getPosition();
        int t2 = successor.getPosition();
        if (t2 < t1) {
            ie.setType(EdgeType.BACK);
        }
    }
}
Also used : IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 9 with IntermediateEdge

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

the class ContinuousLoop method process.

@Override
public void process(InstructionHandle ih) {
    List<InstructionHandle> preds = Graphs.predecessorListOf(igc.getGraph(), ih);
    // only more than one predecessor.
    if (preds.size() < 2) {
        return;
    }
    for (InstructionHandle pred : preds) {
        IntermediateEdge ie = igc.getGraph().getEdge(pred, ih);
        if (ie.getType() == EdgeType.BACK) {
            if (!igc.hasIntermediate(ih)) {
                // this is probably a while(true);
                ContinuousWhileIntermediate cwi = new ContinuousWhileIntermediate(ih);
                igc.addIntermediate(ih, cwi);
                break;
            }
        }
    }
}
Also used : ContinuousWhileIntermediate(org.candle.decompiler.intermediate.code.loop.ContinuousWhileIntermediate) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 10 with IntermediateEdge

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

the class LoopHeader method process.

@Override
public void process(InstructionHandle ih) {
    // check to see whether a predecessor is a back edge.
    List<InstructionHandle> preds = Graphs.predecessorListOf(igc.getGraph(), ih);
    // only more than one predecessor.
    if (preds.size() < 2) {
        return;
    }
    for (InstructionHandle pred : preds) {
        IntermediateEdge ie = igc.getGraph().getEdge(pred, ih);
        if (ie.getType() == EdgeType.BACK) {
            LOG.debug("Has back edge.");
            splitLoopHeader(ih);
            break;
        }
    }
}
Also used : IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)19 InstructionHandle (org.apache.bcel.generic.InstructionHandle)11 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)6 File (java.io.File)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 Writer (java.io.Writer)3 TreeSet (java.util.TreeSet)3 BranchHandle (org.apache.bcel.generic.BranchHandle)3 InstructionEdgeAttributeProvider (org.candle.decompiler.instruction.graph.edge.InstructionEdgeAttributeProvider)3 IntermediateEdgeProvider (org.candle.decompiler.intermediate.graph.edge.IntermediateEdgeProvider)3 DOTExporter (org.jgrapht.ext.DOTExporter)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 InstructionLabelProvider (org.candle.decompiler.instruction.graph.vertex.InstructionLabelProvider)2 GoToIntermediate (org.candle.decompiler.intermediate.code.GoToIntermediate)2 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)2 ListenableDirectedGraph (org.jgrapht.graph.ListenableDirectedGraph)2 BreadthFirstIterator (org.jgrapht.traverse.BreadthFirstIterator)2 CodeExceptionGen (org.apache.bcel.generic.CodeExceptionGen)1