use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class IfLowerRangeVisitor method visitIfIntermediate.
@Override
public void visitIfIntermediate(IfIntermediate line) {
AbstractIntermediate l = igc.getTrueTarget(line);
InstructionHandle lower = l.getInstruction();
line.getBlockRange().setStart(lower);
// upper range...
AbstractIntermediate u = igc.getFalseTarget(line);
NullIntermediate nullIntermediate = new NullIntermediate(u.getInstruction().getPrev());
AbstractIntermediate ai = igc.getOrderedIntermediate().floor(nullIntermediate);
if (ai != null) {
line.getBlockRange().setEnd(ai.getInstruction());
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class WhileRangeVisitor method visitWhileIntermediate.
@Override
public void visitWhileIntermediate(WhileIntermediate line) {
AbstractIntermediate falseTarget = igc.getFalseTarget(line);
AbstractIntermediate trueTarget = igc.getTrueTarget(line);
line.getBlockRange().setStart(trueTarget.getInstruction());
line.getBlockRange().setEnd(falseTarget.getInstruction().getPrev());
super.visitWhileIntermediate(line);
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class ConditionToWhileLoop method visitBooleanBranchIntermediate.
@Override
public void visitBooleanBranchIntermediate(BooleanBranchIntermediate line) {
List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), line);
CycleDetector<AbstractIntermediate, IntermediateEdge> cycleDetector = new CycleDetector<AbstractIntermediate, IntermediateEdge>(igc.getGraph());
if (!cycleDetector.detectCyclesContainingVertex(line)) {
return;
}
// first, determine if the condition has two incoming lines.
if (predecessors.size() >= 2) {
// check to see that 1 predecessor is a GOTO.
TreeSet<GoToIntermediate> incomingGotoNonNested = new TreeSet<GoToIntermediate>(new IntermediateComparator());
TreeSet<GoToIntermediate> incomingGotoNested = new TreeSet<GoToIntermediate>(new IntermediateComparator());
GoToIntermediate nestedLine = null;
AbstractIntermediate otherLine = null;
// classify.
for (AbstractIntermediate predecessor : predecessors) {
// check to see if 1 is GOTO.
if (predecessor instanceof GoToIntermediate) {
if (isNested(line, predecessor)) {
incomingGotoNested.add((GoToIntermediate) predecessor);
} else {
incomingGotoNonNested.add((GoToIntermediate) predecessor);
}
continue;
} else {
otherLine = predecessor;
}
}
// if there are more than one GOTO statements that are not-nested, return.
if (incomingGotoNonNested.size() > 1) {
return;
}
nestedLine = getCandidateGoto(incomingGotoNonNested, incomingGotoNested);
// stop if both conditions aren't met.
if (nestedLine == null || otherLine == null) {
return;
}
// check to validate that the GOTO instruction is less than the other incoming...
if (comparator.before(otherLine, line)) {
// take the lower condition...
BranchHandle refHandle = null;
if (comparator.before(nestedLine, line)) {
refHandle = (BranchHandle) nestedLine.getInstruction();
} else {
refHandle = (BranchHandle) line.getInstruction();
}
WhileIntermediate whileIntermediate = new WhileIntermediate(refHandle, line);
// add this to the graph.
this.igc.getGraph().addVertex(whileIntermediate);
// get the incoming from the goto...
igc.redirectPredecessors(nestedLine, whileIntermediate);
igc.redirectSuccessors(line, whileIntermediate);
// now, create line from other to while.
this.igc.getGraph().addEdge(otherLine, whileIntermediate);
// now, remove the GOTO and Conditional Vertex from graph.
igc.getGraph().removeVertex(nestedLine);
igc.getGraph().removeVertex(line);
// now, the other GOTO lines coming in should all be CONTINUE statements...
for (GoToIntermediate gotoIntermediate : incomingGotoNested) {
Continue continueExpression = new Continue(gotoIntermediate.getInstruction());
StatementIntermediate continueIntermediate = new StatementIntermediate(gotoIntermediate.getInstruction(), continueExpression);
// add the node...
igc.getGraph().addVertex(continueIntermediate);
igc.redirectPredecessors(gotoIntermediate, continueIntermediate);
// remove vertex.
igc.getGraph().removeVertex(gotoIntermediate);
// now, add line to the loop.
igc.getGraph().addEdge(continueIntermediate, whileIntermediate);
}
updateEdges(whileIntermediate);
}
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class RemoveCaseToCaseEdge method visitCaseIntermediate.
@Override
public void visitCaseIntermediate(CaseIntermediate line) {
// find successor of Case...
AbstractIntermediate ai = igc.getSingleSuccessor(line);
// find the previous node...
Set<AbstractIntermediate> predecessors = new HashSet<AbstractIntermediate>(Graphs.predecessorListOf(igc.getGraph(), ai));
predecessors.remove(line);
// remove line.
for (AbstractIntermediate predecessor : predecessors) {
// remove line...
igc.getGraph().removeEdge(predecessor, ai);
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate 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);
}
Aggregations