use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class RedundantAssignmentOptimizer method visit.
@Override
protected void visit(ControlFlowGraph aGraph, ExpressionList aList, Expression aExpression, BytecodeLinkerContext aLinkerContext) {
// Check if a variable assignment is before the current expression
Expression theBefore = aList.predecessorOf(aExpression);
if (theBefore instanceof VariableAssignmentExpression) {
VariableAssignmentExpression theAssignment = (VariableAssignmentExpression) theBefore;
Variable theVariable = theAssignment.getVariable();
Value theValue = theAssignment.getValue();
// Check if there is only one data flow
List<Edge> theDataEdges = theVariable.outgoingEdges(DataFlowEdgeType.filter()).collect(Collectors.toList());
if (theDataEdges.size() == 1) {
List<Value> theIncomingData = aExpression.incomingDataFlows();
if (theIncomingData.contains(theVariable)) {
aExpression.replaceIncomingDataEdge(theVariable, theValue);
aList.remove(theAssignment);
aGraph.getProgram().deleteVariable(theVariable);
}
}
}
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(DirectInvokeMethodExpression aValue) {
String theMethodName = aValue.getMethodName();
BytecodeMethodSignature theSignature = aValue.getSignature();
List<Value> theIncomingData = aValue.incomingDataFlows();
Value theTarget = theIncomingData.get(0);
List<Value> theArguments = theIncomingData.subList(1, theIncomingData.size());
if (!"<init>".equals(theMethodName)) {
print(theTarget);
print(".");
print(JSWriterUtils.toMethodName(theMethodName, theSignature));
} else {
print(JSWriterUtils.toClassName(aValue.getClazz()));
print(".");
print(JSWriterUtils.toMethodName(theMethodName, theSignature));
}
print("(");
print(theTarget);
for (Value theArgument : theArguments) {
print(",");
print(theArgument);
}
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(NegatedExpression aValue) {
Value theValue = aValue.incomingDataFlows().get(0);
print("(-");
print(theValue);
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(CompareExpression aValue) {
List<Value> theIncomingData = aValue.incomingDataFlows();
Value theVariable1 = theIncomingData.get(0);
Value theVariable2 = theIncomingData.get(1);
print("(");
print(theVariable1);
print(" > ");
print(theVariable2);
print(" ? 1 ");
print(" : (");
print(theVariable1);
print(" < ");
print(theVariable2);
print(" ? -1 : 0))");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(FixedBinaryExpression aValue) {
Value theValue1 = aValue.incomingDataFlows().get(0);
print(theValue1);
switch(aValue.getOperator()) {
case ISNONNULL:
print(" != null ");
break;
case ISZERO:
print(" == 0 ");
break;
case ISNULL:
print(" == null ");
break;
default:
throw new IllegalStateException("Unsupported operator : " + aValue.getOperator());
}
}
Aggregations