Mirror of the JODE repository
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
jode/jode/jode/expr/CreatePostIncExpression.java

99 lines
3.4 KiB

package jode;
import sun.tools.java.Type;
public class CreatePostIncExpression implements Transformation {
public InstructionHeader transform(InstructionHeader ih)
{
InstructionHeader next = createLocalPostInc(ih);
if (next != null)
return next;
return createPostInc(ih);
}
public InstructionHeader createLocalPostInc(InstructionHeader ih) {
IIncOperator iinc;
int op;
Type type;
try {
Expression iincExpr = (Expression) ih.getInstruction();
iinc = (IIncOperator) iincExpr.getOperator();
if (iinc.getOperator() == iinc.ADD_OP + iinc.OPASSIGN_OP)
op = Operator.INC_OP;
else if (iinc.getOperator() == iinc.NEG_OP + iinc.OPASSIGN_OP)
op = Operator.DEC_OP;
else
return null;
if (!iinc.getValue().equals("1") &&
!iinc.getValue().equals("-1"))
return null;
if (iinc.getValue().equals("-1"))
op ^= 1;
ih = ih.getSimpleUniquePredecessor();
Expression loadExpr = (Expression) ih.getInstruction();
LocalLoadOperator load =
(LocalLoadOperator)loadExpr.getOperator();
if (!iinc.matches(load))
return null;
type = MyType.intersection(load.getType(), MyType.tUInt);
} catch (NullPointerException ex) {
return null;
} catch (ClassCastException ex) {
return null;
}
Operator postop = new LocalPostFixOperator(type, op, iinc);
return ih.combine(2, postop);
}
public InstructionHeader createPostInc(InstructionHeader ih) {
StoreInstruction store;
int op;
Type type;
try {
store = (StoreInstruction) ih.getInstruction();
if (store.getLValueOperandCount() == 0)
return null;
ih = ih.getSimpleUniquePredecessor();
BinaryOperator binOp = (BinaryOperator) ih.getInstruction();
if (binOp.getOperator() == store.ADD_OP)
op = Operator.INC_OP;
else if (store.getOperator() == store.NEG_OP)
op = Operator.DEC_OP;
else
return null;
ih = ih.getSimpleUniquePredecessor();
Expression expr = (Expression) ih.getInstruction();
ConstOperator constOp = (ConstOperator) expr.getOperator();
if (!constOp.getValue().equals("1") &&
!constOp.getValue().equals("-1"))
return null;
if (constOp.getValue().equals("-1"))
op ^= 1;
ih = ih.getSimpleUniquePredecessor();
DupOperator dup = (DupOperator) ih.getInstruction();
if (dup.getCount() != store.getLValueType().stackSize() ||
dup.getDepth() != store.getLValueOperandCount())
return null;
ih = ih.getSimpleUniquePredecessor();
Operator load = (Operator) ih.getInstruction();
if (!store.matches(load))
return null;
ih = ih.getSimpleUniquePredecessor();
DupOperator dup2 = (DupOperator) ih.getInstruction();
if (dup2.getCount() != store.getLValueOperandCount() ||
dup2.getDepth() != 0)
return null;
type = MyType.intersection(load.getType(), store.getLValueType());
} catch (NullPointerException ex) {
return null;
} catch (ClassCastException ex) {
return null;
}
Operator postop = new PostFixOperator(type, op, store);
return ih.combine(6, postop);
}
}