use of org.apache.bcel.generic.InstructionHandle 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);
}
}
}
use of org.apache.bcel.generic.InstructionHandle 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;
}
}
}
}
use of org.apache.bcel.generic.InstructionHandle 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 ======");
}
use of org.apache.bcel.generic.InstructionHandle 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;
}
}
}
use of org.apache.bcel.generic.InstructionHandle in project jop by jop-devel.
the class FindUsedConstants method find.
private void find(Method method) {
MethodGen mg = new MethodGen(method, clazz.getClassName(), cpool);
InstructionList il = mg.getInstructionList();
InstructionFinder f = new InstructionFinder(il);
// find instructions that access the constant pool
// collect all indices to constants in ClassInfo
String cpInstr = "CPInstruction";
for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
InstructionHandle[] match = (InstructionHandle[]) it.next();
InstructionHandle first = match[0];
CPInstruction ii = (CPInstruction) first.getInstruction();
int idx = ii.getIndex();
Constant co = cpool.getConstant(idx);
int len = 1;
switch(co.getTag()) {
case Constants.CONSTANT_Long:
case Constants.CONSTANT_Double:
len = 2;
break;
}
// we don't need the field references in the cpool anymore
if (co.getTag() != Constants.CONSTANT_Fieldref) {
getCli().addUsedConst(idx, len);
}
// also modify the index!
// Constant cnst = cpool.getConstant(ii.getIndex());
// int newIndex = addConstant(cnst);
//System.out.println(ii+" -> "+newIndex);
// ii.setIndex(newIndex);
}
il.dispose();
CodeExceptionGen[] et = mg.getExceptionHandlers();
for (int i = 0; i < et.length; i++) {
ObjectType ctype = et[i].getCatchType();
if (ctype != null) {
getCli().addUsedConst(cpool.lookupClass(ctype.getClassName()), 1);
}
}
}
Aggregations