lot of changes for new early operand merging

now also detects 1.0 as ++ or --


git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@431 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 25e2f38ce9
commit 7c30104a69
  1. 100
      jode/jode/flow/CreatePrePostIncExpression.java

@ -31,13 +31,21 @@ public class CreatePrePostIncExpression {
public static boolean createLocalPrePostInc(InstructionContainer ic, public static boolean createLocalPrePostInc(InstructionContainer ic,
StructuredBlock last) { StructuredBlock last) {
/* Situations:
*
* PUSH local_x -> PUSH local_x++
* IINC local_x, +/-1
*
* IINC local_x, +/-1
* PUSH local_x -> PUSH ++local_x
*/
if (last.outer instanceof SequentialBlock if (!(last.outer instanceof SequentialBlock)
&& last.outer.getSubBlocks()[0] instanceof InstructionBlock) { || !(last.outer.getSubBlocks()[0] instanceof InstructionBlock))
return false;
Expression instr1 = ((InstructionBlock) Expression instr1 = ((InstructionBlock)
last.outer.getSubBlocks()[0]) last.outer.getSubBlocks()[0]).getInstruction();
.getInstruction();
Expression instr2 = ic.getInstruction(); Expression instr2 = ic.getInstruction();
IIncOperator iinc; IIncOperator iinc;
@ -81,79 +89,73 @@ public class CreatePrePostIncExpression {
last.replace(last.outer); last.replace(last.outer);
return true; return true;
} }
return false;
}
public static boolean createPostInc(InstructionContainer ic, public static boolean createPostInc(InstructionContainer ic,
StructuredBlock last) { StructuredBlock last) {
/* Situation: /* Situation:
* *
* PUSH load/storeOps PUSH load/storeOps * PUSH load/storeOps (optional/
* DUP load/storeOps PUSH store++/-- * not checked) PUSH load/storeOps
* load (unresolved) * DUP load/storeOps (optional) PUSH store++/--
* DUP -> * PUSH load(stack)
* PUSH +/-1 * DUP_X(storeOps count) ->
* IADD/SUB * store(stack) = stack_0 +/- 1
* store (unresolved)
*
* load (no params) -> PUSH store++/--
* DUP
* PUSH +/-1
* store IADD/SUB
*/ */
if (!(ic.getInstruction().getOperator() instanceof StoreInstruction) if (!(ic.getInstruction() instanceof ComplexExpression)
|| !(ic.getInstruction().getOperator() instanceof StoreInstruction)
|| !(ic.getInstruction().isVoid())) || !(ic.getInstruction().isVoid()))
return false; return false;
ComplexExpression storeExpr = (ComplexExpression) ic.getInstruction();
StoreInstruction store = StoreInstruction store =
(StoreInstruction) ic.getInstruction().getOperator(); (StoreInstruction) ic.getInstruction().getOperator();
/* Make sure that the lvalue part of the store is
if (!(last.outer instanceof SequentialBlock)) * not yet resolved (and not that the rvalue part
return false; * should also have 1 remaining operand)
SequentialBlock sb = (SequentialBlock)last.outer; */
int storeParams = store.getLValueOperandCount();
Expression binOp; if (storeExpr.getOperandCount() != storeParams + 1
if (store.getLValueOperandCount() == 0) { || !(storeExpr.getSubExpressions()[storeParams]
if (!(ic.getInstruction() instanceof ComplexExpression)) instanceof ComplexExpression))
return false; return false;
binOp = ((ComplexExpression) ic.getInstruction()) if (storeParams > 0) {
.getSubExpressions()[0]; for (int i=0; i< storeParams; i++) {
} else { if (!(storeExpr.getSubExpressions()[i] instanceof NopOperator))
if (!(sb.subBlocks[0] instanceof InstructionBlock)
|| !(sb.outer instanceof SequentialBlock))
return false; return false;
binOp = ((InstructionBlock) sb.subBlocks[0])
.getInstruction();
sb = (SequentialBlock) sb.outer;
} }
if (!(binOp instanceof BinaryOperator)) }
ComplexExpression binExpr = (ComplexExpression)
storeExpr.getSubExpressions()[storeParams];
if (!(binExpr instanceof ComplexExpression)
|| !(binExpr.getOperator() instanceof BinaryOperator)
|| !(binExpr.getSubExpressions()[0] instanceof NopOperator)
|| !(binExpr.getSubExpressions()[1] instanceof ConstOperator))
return false; return false;
BinaryOperator binOp = (BinaryOperator) binExpr.getOperator();
ConstOperator constOp = (ConstOperator) binExpr.getSubExpressions()[1];
int op; int op;
if (binOp.getOperator().getOperatorIndex() == store.ADD_OP) if (binOp.getOperatorIndex() == store.ADD_OP)
op = Operator.INC_OP; op = Operator.INC_OP;
else if (binOp.getOperator().getOperatorIndex() == store.NEG_OP) else if (binOp.getOperatorIndex() == store.NEG_OP)
op = Operator.DEC_OP; op = Operator.DEC_OP;
else else
return false; return false;
if (!(sb.subBlocks[0] instanceof InstructionBlock)) if (constOp.getValue().equals("-1")
return false; || constOp.getValue().equals("-1.0"))
InstructionBlock ib = (InstructionBlock) sb.subBlocks[0];
if (!(ib.getInstruction() instanceof ConstOperator))
return false;
ConstOperator constOp = (ConstOperator) ib.getInstruction();
if (constOp.getValue().equals("-1"))
op ^= 1; op ^= 1;
else if (!constOp.getValue().equals("1")) else if (!constOp.getValue().equals("1")
&& !constOp.getValue().equals("-1.0"))
return false; return false;
if (!(sb.outer instanceof SequentialBlock)) if (!(last.outer instanceof SequentialBlock))
return false; return false;
sb = (SequentialBlock) sb.outer; SequentialBlock sb = (SequentialBlock)last.outer;
if (!(sb.subBlocks[0] instanceof SpecialBlock)) if (!(sb.subBlocks[0] instanceof SpecialBlock))
return false; return false;
@ -168,7 +170,7 @@ public class CreatePrePostIncExpression {
sb = (SequentialBlock) sb.outer; sb = (SequentialBlock) sb.outer;
if (!(sb.subBlocks[0] instanceof InstructionBlock)) if (!(sb.subBlocks[0] instanceof InstructionBlock))
return false; return false;
ib = (InstructionBlock) sb.subBlocks[0]; InstructionBlock ib = (InstructionBlock) sb.subBlocks[0];
if (!(ib.getInstruction() instanceof Operator) if (!(ib.getInstruction() instanceof Operator)
|| !store.matches((Operator) ib.getInstruction())) || !store.matches((Operator) ib.getInstruction()))

Loading…
Cancel
Save