Search in sources :

Example 1 with CaseIntermediate

use of org.candle.decompiler.intermediate.code.CaseIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphFactory method visitMultiBranchIntermediate.

@Override
public void visitMultiBranchIntermediate(MultiBranchIntermediate line) {
    Select select = (Select) line.getInstruction().getInstruction();
    Set<Case> cases = new HashSet<Case>();
    InstructionHandle[] handles = select.getTargets();
    int[] matches = select.getMatchs();
    for (int i = 0, j = handles.length; i < j; i++) {
        InstructionHandle ih = handles[i];
        int match = matches[i];
        Resolved resolved = new Resolved(line.getInstruction(), BasicType.INT, "" + match);
        Case caseEntry = new Case(line.getInstruction(), ih, resolved);
        cases.add(caseEntry);
    }
    if (select.getTarget() != null) {
        DefaultCase defaultCase = new DefaultCase(line.getInstruction(), select.getTarget());
        line.setDefaultCase(defaultCase);
    }
    //now, create the graph.
    line.setCases(cases);
    //now, create the graph.
    igc.getGraph().addVertex(line);
    if (line.getDefaultCase() != null) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), line.getDefaultCase());
        igc.getGraph().addVertex(si);
        //add an edge.
        igc.getGraph().addEdge(line, si);
        //add edge from outcome to edge.
        LOG.debug(si);
        AbstractIntermediate target = ilc.getNext(line.getDefaultCase().getTarget().getPosition());
        LOG.debug("TargeT:" + target);
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
    for (Case caseVal : line.getCases()) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), caseVal);
        igc.getGraph().addVertex(si);
        //add an edge.
        igc.getGraph().addEdge(line, si);
        //add edge from outcome to edge.
        AbstractIntermediate target = ilc.getNext(caseVal.getTarget().getPosition());
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase) Select(org.apache.bcel.generic.Select) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate) Resolved(org.candle.decompiler.intermediate.expression.Resolved) InstructionHandle(org.apache.bcel.generic.InstructionHandle) HashSet(java.util.HashSet) Case(org.candle.decompiler.intermediate.expression.Case) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase)

Example 2 with CaseIntermediate

use of org.candle.decompiler.intermediate.code.CaseIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphContext method getCases.

public List<CaseIntermediate> getCases(SwitchIntermediate si) {
    List<AbstractIntermediate> intermediate = Graphs.successorListOf(graph, si);
    List<CaseIntermediate> switchCases = new LinkedList<CaseIntermediate>();
    for (AbstractIntermediate i : intermediate) {
        if (i instanceof CaseIntermediate) {
            switchCases.add((CaseIntermediate) i);
        }
    }
    Collections.sort(switchCases, new CaseIntermediateComparator());
    return switchCases;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CaseIntermediateComparator(org.candle.decompiler.intermediate.code.CaseIntermediateComparator) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate) LinkedList(java.util.LinkedList)

Example 3 with CaseIntermediate

use of org.candle.decompiler.intermediate.code.CaseIntermediate in project candle-decompiler by bradsdavis.

the class BlockVisitor method visitSwitchIntermediate.

@Override
public void visitSwitchIntermediate(SwitchIntermediate line) {
    if (seen.contains(line)) {
        //do nothing.
        return;
    } else {
        seen.add(line);
    }
    SwitchBlock switchBlock = new SwitchBlock(line);
    current.addChild(switchBlock);
    current = switchBlock;
    List<CaseIntermediate> cases = igc.getCases(line);
    for (CaseIntermediate switchCase : cases) {
        switchCase.accept(this);
        //reset current to switch
        current = switchBlock;
    }
}
Also used : SwitchBlock(org.candle.decompiler.ast.swtch.SwitchBlock) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate)

Example 4 with CaseIntermediate

use of org.candle.decompiler.intermediate.code.CaseIntermediate in project candle-decompiler by bradsdavis.

the class CaseEndRangeIntermediateVisitor method visitCaseIntermediate.

@Override
public void visitCaseIntermediate(CaseIntermediate line) {
    SwitchIntermediate si = (SwitchIntermediate) igc.getSinglePredecessor(line);
    List<CaseIntermediate> switchCases = igc.getCases(si);
    int position = line.getBlockRange().getStart().getPosition();
    CaseIntermediate next = findNextCase(switchCases, position);
    if (next != null) {
        line.getBlockRange().setEnd(next.getBlockRange().getStart().getPrev());
    } else {
        //we should get the end from the parent.
        line.getBlockRange().setEnd(si.getBlockRange().getEnd());
    }
}
Also used : SwitchIntermediate(org.candle.decompiler.intermediate.code.SwitchIntermediate) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate)

Aggregations

CaseIntermediate (org.candle.decompiler.intermediate.code.CaseIntermediate)4 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 InstructionHandle (org.apache.bcel.generic.InstructionHandle)1 Select (org.apache.bcel.generic.Select)1 SwitchBlock (org.candle.decompiler.ast.swtch.SwitchBlock)1 CaseIntermediateComparator (org.candle.decompiler.intermediate.code.CaseIntermediateComparator)1 SwitchIntermediate (org.candle.decompiler.intermediate.code.SwitchIntermediate)1 Case (org.candle.decompiler.intermediate.expression.Case)1 DefaultCase (org.candle.decompiler.intermediate.expression.DefaultCase)1 Resolved (org.candle.decompiler.intermediate.expression.Resolved)1