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.
86 lines
3.6 KiB
86 lines
3.6 KiB
package jode;
|
|
import sun.tools.java.Type;
|
|
|
|
public class CreateConstantArray implements Transformation {
|
|
|
|
public InstructionHeader transform(InstructionHeader ih) {
|
|
Expression[] consts;
|
|
int count;
|
|
Type type;
|
|
try {
|
|
if (ih.getInstruction() instanceof DupOperator)
|
|
/* this is not the end of the array assign */
|
|
return null;
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
ArrayStoreOperator store =
|
|
(ArrayStoreOperator) ih.getInstruction();
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
Expression lastconst = (Expression) ih.getInstruction();
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
Expression lastindexexpr = (Expression) ih.getInstruction();
|
|
ConstOperator lastindexop =
|
|
(ConstOperator) lastindexexpr.getOperator();
|
|
if (!MyType.isOfType(lastindexop.getType(), MyType.tInt))
|
|
return null;
|
|
int lastindex = Integer.parseInt(lastindexop.getValue());
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
DupOperator dup = (DupOperator) ih.getInstruction();
|
|
if (dup.getDepth() != 0 ||
|
|
dup.getCount() != store.getLValueType().stackSize())
|
|
return null;
|
|
consts = new Expression[lastindex+1];
|
|
consts[lastindex] = lastconst;
|
|
count = 1;
|
|
while (lastindex-- > 0) {
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
ArrayStoreOperator store2 =
|
|
(ArrayStoreOperator) ih.getInstruction();
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
lastconst = (Expression) ih.getInstruction();
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
Expression indexexpr = (Expression) ih.getInstruction();
|
|
ConstOperator indexop =
|
|
(ConstOperator) indexexpr.getOperator();
|
|
if (!MyType.isOfType(indexop.getType(), MyType.tUInt))
|
|
return null;
|
|
int index = Integer.parseInt(indexop.getValue());
|
|
if (index > lastindex)
|
|
return null;
|
|
while (index < lastindex) {
|
|
consts[lastindex] = new Expression
|
|
(new ConstOperator(MyType.tUnknown, ""),
|
|
new Expression[0]);
|
|
lastindex--;
|
|
}
|
|
consts[lastindex] = lastconst;
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
dup = (DupOperator) ih.getInstruction();
|
|
if (dup.getDepth() != 0 ||
|
|
dup.getCount() != store.getLValueType().stackSize())
|
|
return null;
|
|
count++;
|
|
}
|
|
ih = ih.getSimpleUniquePredecessor();
|
|
Expression newArrayExpr = (Expression) ih.getInstruction();
|
|
NewArrayOperator newArrayOp =
|
|
(NewArrayOperator) newArrayExpr.getOperator();
|
|
type = newArrayOp.getType();
|
|
if (newArrayOp.getOperandCount() != 1)
|
|
return null;
|
|
Expression countexpr =
|
|
(Expression) newArrayExpr.getSubExpressions()[0];
|
|
ConstOperator countop =
|
|
(ConstOperator) countexpr.getOperator();
|
|
if (!MyType.isOfType(countop.getType(), MyType.tUInt))
|
|
return null;
|
|
if (Integer.parseInt(countop.getValue()) != consts.length)
|
|
return null;
|
|
} catch (NullPointerException ex) {
|
|
return null;
|
|
} catch (ClassCastException ex) {
|
|
return null;
|
|
}
|
|
Operator op = new ConstantArrayOperator(type, consts.length);
|
|
return ih.combine(4*count+1, new Expression(op, consts));
|
|
}
|
|
}
|
|
|