string += implemented

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@92 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent 58142d1683
commit c25af54827
  1. 193
      jode/jode/flow/CreateAssignExpression.java

@ -23,108 +23,147 @@ import jode.*;
public class CreateAssignExpression implements Transformation{ public class CreateAssignExpression implements Transformation{
public boolean transform(FlowBlock flow) { public boolean transform(FlowBlock flow) {
if (!(flow.lastModified instanceof InstructionContainer)
|| !(flow.lastModified.outer instanceof SequentialBlock)
|| !(((InstructionContainer)flow.lastModified).getInstruction()
instanceof StoreInstruction)
|| !(((InstructionContainer)flow.lastModified).getInstruction()
.isVoid()))
return false;
return (createAssignOp(flow) || createAssignExpression(flow)); return (createAssignOp(flow) || createAssignExpression(flow));
} }
public boolean createAssignOp(FlowBlock flow) { public boolean createAssignOp(FlowBlock flow) {
Expression rightHandSide;
StoreInstruction store; /* Situation:
BinaryOperator binop; *
InstructionContainer lastBlock; * (push loadstoreOps) <- not checked
SequentialBlock opBlock; * sequBlock:
SequentialBlock sequBlock; * dup
boolean isExpression = false; * opBlock:
try { * load(stack) * rightHandSide
InstructionBlock ib; * (optional dup_x)
lastBlock = (InstructionContainer) flow.lastModified; * store(stack)
store = (StoreInstruction) lastBlock.getInstruction(); *
* We transform it to:
opBlock = (SequentialBlock) lastBlock.outer; * (push loadstoreOps)
if (opBlock.subBlocks[1] != lastBlock) * rightHandSide
* store(stack) *= (stack)
*
* If the optional dup is present the store*= becomes non void.
*/
InstructionContainer lastBlock
= (InstructionContainer) flow.lastModified;
SequentialBlock opBlock = (SequentialBlock) lastBlock.outer;
StoreInstruction store
= (StoreInstruction) lastBlock.getInstruction();
boolean isAssignOp = false;
if (opBlock.subBlocks[0] instanceof SpecialBlock) {
SpecialBlock dup = (SpecialBlock) opBlock.subBlocks[0];
if (dup.type != SpecialBlock.DUP
|| dup.depth != store.getLValueOperandCount()
|| dup.count != store.getLValueType().stackSize()
|| !(opBlock.outer instanceof SequentialBlock))
return false; return false;
opBlock = (SequentialBlock) opBlock.outer;
isAssignOp = true;
}
if (opBlock.subBlocks[0] instanceof SpecialBlock) { if (!(opBlock.subBlocks[0] instanceof InstructionBlock))
SpecialBlock dup = (SpecialBlock) opBlock.subBlocks[0]; return false;
if (dup.type != SpecialBlock.DUP
|| dup.depth != store.getLValueOperandCount()
|| dup.count != store.getLValueType().stackSize())
return false;
opBlock = (SequentialBlock) lastBlock.outer;
isExpression = true;
}
ib = (InstructionBlock) opBlock.subBlocks[0]; InstructionBlock ib = (InstructionBlock) opBlock.subBlocks[0];
ComplexExpression binopExpr =
(ComplexExpression) ib.getInstruction(); if (!(opBlock.outer instanceof SequentialBlock)
binop = (BinaryOperator) binopExpr.getOperator(); || !(opBlock.outer.getSubBlocks()[0] instanceof SpecialBlock))
if (binop.getOperatorIndex() < binop.ADD_OP || return false;
binop.getOperatorIndex() >= binop.ASSIGN_OP)
return false; SequentialBlock sequBlock = (SequentialBlock) opBlock.outer;
SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0];
if (dup.type != SpecialBlock.DUP
|| dup.depth != 0
|| dup.count != store.getLValueOperandCount())
return false;
if (!(ib.getInstruction() instanceof ComplexExpression))
return false;
ComplexExpression expr = (ComplexExpression) ib.getInstruction();
int opIndex;
Expression rightHandSide;
if (expr.getOperator() instanceof BinaryOperator) {
BinaryOperator binop = (BinaryOperator) expr.getOperator();
rightHandSide = binopExpr.getSubExpressions()[1]; opIndex = binop.getOperatorIndex();
if (rightHandSide.isVoid())
return false; /* XXX */
Operator load = (Operator) binopExpr.getSubExpressions()[0]; if (opIndex < binop.ADD_OP || opIndex >= binop.ASSIGN_OP
if (!store.matches(load)) || !(expr.getSubExpressions()[0] instanceof Operator)
|| !store.matches((Operator) expr.getSubExpressions()[0]))
return false; return false;
sequBlock = (SequentialBlock) opBlock.outer; rightHandSide = expr.getSubExpressions()[1];
} else {
Expression simple = expr.simplifyString();
rightHandSide = simple;
/* Now search for the leftmost operand ... */
ComplexExpression last = null;
while (simple instanceof ComplexExpression
&& simple.getOperator() instanceof StringAddOperator) {
last = (ComplexExpression) simple;
simple = last.getSubExpressions()[0];
}
SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0]; /* ... check it ... */
if (dup.type != SpecialBlock.DUP if (last == null || !(simple instanceof Operator)
|| dup.depth != 0 || !store.matches((Operator) simple))
|| dup.count != store.getLValueOperandCount())
return false; return false;
} catch (ClassCastException ex) {
return false; /* ... and remove it. */
} catch (NullPointerException ex) { if (last.getParent() != null) {
return false; ((ComplexExpression)last.getParent()).getSubExpressions()[0]
= last.getSubExpressions()[1];
} else
rightHandSide = last.getSubExpressions()[1];
opIndex = Operator.ADD_OP;
} }
((InstructionBlock)opBlock.subBlocks[0]) dup.removeBlock();
.setInstruction(rightHandSide); ib.setInstruction(rightHandSide);
opBlock.moveDefinitions(sequBlock, opBlock);
opBlock.replace(sequBlock); store.setOperatorIndex(store.OPASSIGN_OP+opIndex);
store.setOperatorIndex(store.OPASSIGN_OP+binop.getOperatorIndex()); if (isAssignOp)
store.setLValueType(binop.getType() store.makeNonVoid();
.intersection(store.getLValueType()));
if (isExpression)
lastBlock.setInstruction
(new AssignOperator(store.getOperatorIndex(), store));
else
lastBlock.setInstruction(store);
lastBlock.moveDefinitions(opBlock.subBlocks[1], lastBlock);
lastBlock.replace(opBlock.subBlocks[1]); lastBlock.replace(opBlock.subBlocks[1]);
return true; return true;
} }
public boolean createAssignExpression(FlowBlock flow) { public boolean createAssignExpression(FlowBlock flow) {
StoreInstruction store; /* Situation:
InstructionContainer lastBlock; * sequBlock:
SequentialBlock sequBlock; * dup_X(lvalue_count)
try { * store instruction
lastBlock = (InstructionContainer) flow.lastModified; */
store = (StoreInstruction) lastBlock.getInstruction(); InstructionContainer lastBlock
= (InstructionContainer) flow.lastModified;
sequBlock = (SequentialBlock) lastBlock.outer; SequentialBlock sequBlock = (SequentialBlock) lastBlock.outer;
StoreInstruction store = (StoreInstruction) lastBlock.getInstruction();
if (sequBlock.subBlocks[0] instanceof SpecialBlock) {
SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0]; SpecialBlock dup = (SpecialBlock) sequBlock.subBlocks[0];
if (dup.type != SpecialBlock.DUP if (dup.type != SpecialBlock.DUP
|| dup.depth != store.getLValueOperandCount() || dup.depth != store.getLValueOperandCount()
|| dup.count != store.getLValueType().stackSize()) || dup.count != store.getLValueType().stackSize())
return false; return false;
} catch (NullPointerException ex) {
return false;
} catch (ClassCastException ex) {
return false;
}
lastBlock.setInstruction
(new AssignOperator(store.getOperatorIndex(), store));
lastBlock.moveDefinitions(sequBlock, lastBlock);
lastBlock.replace(sequBlock);
return true;
dup.removeBlock();
store.makeNonVoid();
return true;
}
return false;
} }
} }

Loading…
Cancel
Save