Search in sources :

Example 1 with IntermediateGraphContext

use of org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext in project candle-decompiler by bradsdavis.

the class ClassIntermediateVisitor method visitMethod.

@Override
public void visitMethod(Method obj) {
    MethodGen methodGenerator = new MethodGen(obj, this.javaClass.getClassName(), this.constantPool);
    LOG.debug("Processing MethodInvocation: " + methodGenerator.toString());
    IntermediateContext intermediateContext = new IntermediateContext(this.javaClass, methodGenerator);
    InstructionList instructions = methodGenerator.getInstructionList();
    instructions.setPositions(true);
    InstructionGraphFactory igf = new InstructionGraphFactory(instructions, methodGenerator.getExceptionHandlers());
    InstructionGraphContext igc = igf.process();
    List<InstructionGraphEnhancer> iges = new ArrayList<InstructionGraphEnhancer>();
    iges.add(new InstructionGraphWriter(igc, "before.dot"));
    iges.add(new SplitInstructionEnhancer(igc));
    iges.add(new ConditionEdgeEnhancer(igc));
    iges.add(new ExceptionEdgeEnhancer(igc, methodGenerator.getExceptionHandlers()));
    iges.add(new InstructionToIntermediateEnhancer(igc, intermediateContext));
    iges.add(new BackEdgeEnhancer(igc));
    iges.add(new LoopHeader(igc));
    iges.add(new ContinuousLoop(igc));
    iges.add(new NonIntermediateEliminator(igc));
    iges.add(new InstructionGraphWriter(igc, "after.dot"));
    for (InstructionGraphEnhancer ige : iges) {
        ige.process();
    }
    IntermediateGraphTransformer igt = new IntermediateGraphTransformer(igc);
    IntermediateGraphContext interGraphContext = igt.getIntermediateGraphContext();
    processIntermediate(interGraphContext);
    MethodBlock method = extractMethodSignature(methodGenerator);
    BlockVisitor iv = new BlockVisitor(interGraphContext, method);
    iv.process();
    classBlock.addChild(method);
    method.setParent(classBlock);
}
Also used : InstructionGraphEnhancer(org.candle.decompiler.instruction.graph.enhancer.InstructionGraphEnhancer) IntermediateGraphTransformer(org.candle.decompiler.intermediate.graph.IntermediateGraphTransformer) MethodBlock(org.candle.decompiler.ast.MethodBlock) BackEdgeEnhancer(org.candle.decompiler.instruction.graph.enhancer.BackEdgeEnhancer) InstructionGraphWriter(org.candle.decompiler.instruction.graph.enhancer.InstructionGraphWriter) InstructionList(org.apache.bcel.generic.InstructionList) ContinuousLoop(org.candle.decompiler.instruction.graph.enhancer.ContinuousLoop) ArrayList(java.util.ArrayList) MethodGen(org.apache.bcel.generic.MethodGen) SplitInstructionEnhancer(org.candle.decompiler.instruction.graph.enhancer.SplitInstructionEnhancer) InstructionToIntermediateEnhancer(org.candle.decompiler.instruction.graph.enhancer.InstructionToIntermediateEnhancer) InstructionGraphContext(org.candle.decompiler.instruction.graph.InstructionGraphContext) IntermediateGraphContext(org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext) ConditionEdgeEnhancer(org.candle.decompiler.instruction.graph.enhancer.ConditionEdgeEnhancer) InstructionGraphFactory(org.candle.decompiler.instruction.graph.InstructionGraphFactory) NonIntermediateEliminator(org.candle.decompiler.instruction.graph.enhancer.NonIntermediateEliminator) ExceptionEdgeEnhancer(org.candle.decompiler.instruction.graph.enhancer.ExceptionEdgeEnhancer) LoopHeader(org.candle.decompiler.instruction.graph.enhancer.LoopHeader) BlockVisitor(org.candle.decompiler.ast.BlockVisitor)

Example 2 with IntermediateGraphContext

use of org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext in project candle-decompiler by bradsdavis.

the class IntermediateGraphTransformer method getIntermediateGraphContext.

public IntermediateGraphContext getIntermediateGraphContext() {
    Map<InstructionHandle, AbstractIntermediate> nodeMapping = new HashMap<InstructionHandle, AbstractIntermediate>();
    ListenableDirectedGraph<AbstractIntermediate, IntermediateEdge> intermediateGraph = new ListenableDirectedGraph<AbstractIntermediate, IntermediateEdge>(IntermediateEdge.class);
    // walk the instruction graph and generate the intermediate graph.  start by walking and adding all vertices.  Then, add the connections between the vertices.
    for (InstructionHandle ih : igc.getGraph().vertexSet()) {
        if (igc.hasIntermediate(ih)) {
            AbstractIntermediate vertex = igc.getIntermediateFromInstruction(ih);
            intermediateGraph.addVertex(vertex);
            nodeMapping.put(ih, vertex);
        }
    }
    // now, add the links.
    for (InstructionHandle ih : igc.getGraph().vertexSet()) {
        AbstractIntermediate nodeIntermediate = nodeMapping.get(ih);
        if (nodeIntermediate == null) {
            LOG.warn("This shouldn't be...");
            continue;
        }
        List<InstructionHandle> predecessors = igc.getPredecessors(ih);
        List<InstructionHandle> successors = igc.getSuccessors(ih);
        for (InstructionHandle predecessor : predecessors) {
            // find it's AbstractIntermediate.
            AbstractIntermediate predIntermediate = nodeMapping.get(predecessor);
            if (predIntermediate == null) {
                // then something is wrong.
                LOG.warn("This shouldn't be...");
                continue;
            }
            IntermediateEdge insEdge = igc.getGraph().getEdge(predecessor, ih);
            // add an edge to the intermediate graph.
            if (intermediateGraph.containsEdge(predIntermediate, nodeIntermediate)) {
                continue;
            }
            intermediateGraph.addEdge(predIntermediate, nodeIntermediate, (IntermediateEdge) insEdge.clone());
        }
        for (InstructionHandle successor : successors) {
            // find it's AbstractIntermediate.
            AbstractIntermediate successorIntermediate = nodeMapping.get(successor);
            if (successorIntermediate == null) {
                LOG.warn("This shouldn't be...");
                continue;
            }
            if (intermediateGraph.containsEdge(nodeIntermediate, successorIntermediate)) {
                continue;
            }
            IntermediateEdge insEdge = igc.getGraph().getEdge(ih, successor);
            // add an edge to the intermediate graph.
            intermediateGraph.addEdge(nodeIntermediate, successorIntermediate, (IntermediateEdge) insEdge.clone());
        }
    }
    return new IntermediateGraphContext(intermediateGraph);
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) HashMap(java.util.HashMap) IntermediateGraphContext(org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext) ListenableDirectedGraph(org.jgrapht.graph.ListenableDirectedGraph) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

IntermediateGraphContext (org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 InstructionList (org.apache.bcel.generic.InstructionList)1 MethodGen (org.apache.bcel.generic.MethodGen)1 BlockVisitor (org.candle.decompiler.ast.BlockVisitor)1 MethodBlock (org.candle.decompiler.ast.MethodBlock)1 InstructionGraphContext (org.candle.decompiler.instruction.graph.InstructionGraphContext)1 InstructionGraphFactory (org.candle.decompiler.instruction.graph.InstructionGraphFactory)1 BackEdgeEnhancer (org.candle.decompiler.instruction.graph.enhancer.BackEdgeEnhancer)1 ConditionEdgeEnhancer (org.candle.decompiler.instruction.graph.enhancer.ConditionEdgeEnhancer)1 ContinuousLoop (org.candle.decompiler.instruction.graph.enhancer.ContinuousLoop)1 ExceptionEdgeEnhancer (org.candle.decompiler.instruction.graph.enhancer.ExceptionEdgeEnhancer)1 InstructionGraphEnhancer (org.candle.decompiler.instruction.graph.enhancer.InstructionGraphEnhancer)1 InstructionGraphWriter (org.candle.decompiler.instruction.graph.enhancer.InstructionGraphWriter)1 InstructionToIntermediateEnhancer (org.candle.decompiler.instruction.graph.enhancer.InstructionToIntermediateEnhancer)1 LoopHeader (org.candle.decompiler.instruction.graph.enhancer.LoopHeader)1 NonIntermediateEliminator (org.candle.decompiler.instruction.graph.enhancer.NonIntermediateEliminator)1 SplitInstructionEnhancer (org.candle.decompiler.instruction.graph.enhancer.SplitInstructionEnhancer)1