|
|
@ -40,7 +40,6 @@ public class CreateExpression { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static boolean transform(InstructionContainer ic, |
|
|
|
public static boolean transform(InstructionContainer ic, |
|
|
|
StructuredBlock last) { |
|
|
|
StructuredBlock last) { |
|
|
|
|
|
|
|
|
|
|
|
int params = ic.getInstruction().getOperandCount(); |
|
|
|
int params = ic.getInstruction().getOperandCount(); |
|
|
|
if (params == 0) |
|
|
|
if (params == 0) |
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -65,31 +64,42 @@ public class CreateExpression { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Expression lastExpression = null; |
|
|
|
Expression lastExpression = null; |
|
|
|
for (int i = params;;) { |
|
|
|
for (int i = params;;) { |
|
|
|
|
|
|
|
|
|
|
|
if (!(sequBlock.subBlocks[0] instanceof InstructionBlock)) |
|
|
|
if (i >= 2 && sequBlock.subBlocks[0] instanceof SpecialBlock) { |
|
|
|
return false; |
|
|
|
/* Transform (this is for string += under jikes) |
|
|
|
|
|
|
|
* PUSH arg2 |
|
|
|
Expression expr = |
|
|
|
* PUSH arg1 |
|
|
|
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); |
|
|
|
* SWAP |
|
|
|
|
|
|
|
*/ |
|
|
|
if (!expr.isVoid()) { |
|
|
|
SpecialBlock swap = (SpecialBlock) sequBlock.subBlocks[0]; |
|
|
|
if (--i == 0) |
|
|
|
if (swap.type != SpecialBlock.SWAP) |
|
|
|
break; |
|
|
|
return false; |
|
|
|
} else if (lastExpression == null |
|
|
|
/* XXX check if swapping is possible */ |
|
|
|
|| !(expr.getOperator() |
|
|
|
} else { |
|
|
|
instanceof CombineableOperator) |
|
|
|
if (!(sequBlock.subBlocks[0] instanceof InstructionBlock)) |
|
|
|
|| lastExpression.canCombine(expr) <= 0) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
|
|
Expression expr = |
|
|
|
if (expr.getOperandCount() > 0) |
|
|
|
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); |
|
|
|
/* This is a not fully resolved expression in the |
|
|
|
|
|
|
|
* middle, we must not touch it. */ |
|
|
|
if (!expr.isVoid()) { |
|
|
|
return false; |
|
|
|
if (--i == 0) |
|
|
|
|
|
|
|
break; |
|
|
|
lastExpression = expr; |
|
|
|
} else if (lastExpression == null |
|
|
|
|
|
|
|
|| !(expr.getOperator() |
|
|
|
if (!(sequBlock.outer instanceof SequentialBlock)) |
|
|
|
instanceof CombineableOperator) |
|
|
|
return false; |
|
|
|
|| 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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastExpression = expr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!(sequBlock.outer instanceof SequentialBlock)) |
|
|
|
|
|
|
|
return false; |
|
|
|
sequBlock = (SequentialBlock) sequBlock.outer; |
|
|
|
sequBlock = (SequentialBlock) sequBlock.outer; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -97,17 +107,38 @@ public class CreateExpression { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
Expression[] exprs = new Expression[params]; |
|
|
|
Expression[] exprs = new Expression[params]; |
|
|
|
sequBlock = (SequentialBlock) last.outer; |
|
|
|
sequBlock = (SequentialBlock) last.outer; |
|
|
|
|
|
|
|
int swapping = 0; |
|
|
|
for (int i=params; ;) { |
|
|
|
for (int i=params; ;) { |
|
|
|
|
|
|
|
|
|
|
|
Expression expr = |
|
|
|
if (sequBlock.subBlocks[0] instanceof SpecialBlock) { |
|
|
|
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); |
|
|
|
// This must be a swap (see above).
|
|
|
|
|
|
|
|
swapping = 1; |
|
|
|
if (!expr.isVoid()) { |
|
|
|
|
|
|
|
exprs[--i] = expr; |
|
|
|
} else { |
|
|
|
if (i == 0) |
|
|
|
Expression expr = |
|
|
|
break; |
|
|
|
((InstructionBlock) sequBlock.subBlocks[0]).getInstruction(); |
|
|
|
} else |
|
|
|
|
|
|
|
exprs[i] = exprs[i].combine(expr); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sequBlock = (SequentialBlock)sequBlock.outer; |
|
|
|
sequBlock = (SequentialBlock)sequBlock.outer; |
|
|
|
} |
|
|
|
} |
|
|
|