simplified, using addOperand and adding Operands one by one

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@396 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent e51d2718bb
commit c9f013f201
  1. 122
      jode/jode/flow/CreateExpression.java

@ -44,120 +44,56 @@ public class CreateExpression {
if (params == 0)
return false;
ComplexExpression parent = null;
Expression inner = ic.getInstruction();
while (inner instanceof ComplexExpression) {
parent = (ComplexExpression)inner;
inner = parent.getSubExpressions()[0];
}
if (!(inner instanceof Operator))
return false;
Operator op = (Operator)inner;
if (!(last.outer instanceof SequentialBlock))
return false;
SequentialBlock sequBlock = (SequentialBlock)last.outer;
/* First check if Expression can be created, but do nothing yet.
*/
Expression lastExpression = null;
for (int i = params;;) {
Expression lastExpression = ic.getInstruction();
while (true) {
if (!(sequBlock.subBlocks[0] instanceof InstructionBlock))
return false;
if (i >= 2 && sequBlock.subBlocks[0] instanceof SpecialBlock) {
/* Transform (this is for string += under jikes)
* PUSH arg2
* PUSH arg1
* SWAP
*/
SpecialBlock swap = (SpecialBlock) sequBlock.subBlocks[0];
if (swap.type != SpecialBlock.SWAP)
return false;
/* XXX check if swapping is possible */
} else {
if (!(sequBlock.subBlocks[0] instanceof InstructionBlock))
return false;
Expression expr =
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (!expr.isVoid()) {
if (--i == 0)
break;
} else if (lastExpression == null
|| !(expr.getOperator()
instanceof CombineableOperator)
|| lastExpression.canCombine(expr) <= 0)
return false;
if (expr.getOperandCount() > 0)
/* This is a not fully resolved expression in the
* middle, we must not touch it. */
return false;
Expression expr =
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
lastExpression = expr;
}
if (!expr.isVoid())
break;
if (expr.getOperandCount() > 0
|| !(expr.getOperator() instanceof CombineableOperator)
|| lastExpression.canCombine(expr) <= 0)
return false;
lastExpression = expr;
if (!(sequBlock.outer instanceof SequentialBlock))
return false;
sequBlock = (SequentialBlock) sequBlock.outer;
}
}
/* Now, do the combination. Everything must succeed now.
*/
Expression[] exprs = new Expression[params];
sequBlock = (SequentialBlock) last.outer;
int swapping = 0;
for (int i=params; ;) {
lastExpression = ic.getInstruction();
while (true) {
if (sequBlock.subBlocks[0] instanceof SpecialBlock) {
// This must be a swap (see above).
swapping = 1;
} else {
Expression expr =
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (!expr.isVoid()) {
if (swapping == 1) {
// We start swapping:
i--;
swapping = 2;
} else if (swapping == 2) {
// We continue swapping:
i += 2;
swapping = 3;
} else if (swapping == 3) {
// Now we end swapping:
i--;
swapping = 0;
}
exprs[--i] = expr;
if (i == 0 && swapping == 0
|| i == 1 && swapping == 3)
break;
} else
exprs[i] = exprs[i].combine(expr);
Expression expr =
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction();
if (!expr.isVoid()) {
lastExpression = lastExpression.addOperand(expr);
break;
}
lastExpression = lastExpression.combine(expr);
sequBlock = (SequentialBlock)sequBlock.outer;
}
if(Decompiler.isVerbose)
if(Decompiler.isVerbose && lastExpression.getOperandCount() == 0)
Decompiler.err.print('x');
Expression newExpr;
if (params == 1 && op instanceof NopOperator) {
exprs[0].setType(op.getType());
newExpr = exprs[0];
} else
newExpr = new ComplexExpression(op, exprs);
if (parent != null)
parent.setSubExpressions(0, newExpr);
else
ic.setInstruction(newExpr);
ic.setInstruction(lastExpression);
ic.moveDefinitions(sequBlock, last);
last.replace(sequBlock);
return true;

Loading…
Cancel
Save