use of de.mirkosertic.bytecoder.ssa.BinaryExpression in project Bytecoder by mirkosertic.
the class RedundantAssignmentOptimizerTest method testBinaryOptimization.
@Test
public void testBinaryOptimization() {
Program theProgram = new Program();
ControlFlowGraph theGraph = new ControlFlowGraph(theProgram);
RegionNode theStart = theGraph.createAt(BytecodeOpcodeAddress.START_AT_ZERO, RegionNode.BlockType.NORMAL);
ExpressionList theExpressions = theStart.getExpressions();
Variable theVariable1 = new Variable(TypeRef.Native.INT, "var1");
Variable theVariable2 = new Variable(TypeRef.Native.INT, "var2");
IntegerValue theInt1 = new IntegerValue(10);
theVariable1.initializeWith(theInt1);
theExpressions.add(new VariableAssignmentExpression(theVariable1, theInt1));
IntegerValue theInt2 = new IntegerValue(20);
theVariable2.initializeWith(theInt2);
theExpressions.add(new VariableAssignmentExpression(theVariable2, theInt2));
Variable theVariable3 = new Variable(TypeRef.Native.INT, "var3");
BinaryExpression theBinary = new BinaryExpression(TypeRef.Native.INT, theVariable1, BinaryExpression.Operator.ADD, theVariable2);
theVariable3.initializeWith(theBinary);
theExpressions.add(new VariableAssignmentExpression(theVariable3, theBinary));
theExpressions.add(new ReturnValueExpression(theVariable3));
RedundantAssignmentOptimizer theOptimizer = new RedundantAssignmentOptimizer();
theOptimizer.optimize(theGraph, null);
System.out.println(theExpressions);
}
use of de.mirkosertic.bytecoder.ssa.BinaryExpression in project Bytecoder by mirkosertic.
the class OpenCLWriter method printValue.
private void printValue(Value aValue) {
if (aValue instanceof Variable) {
Variable theVariable = (Variable) aValue;
print(theVariable.getName());
} else if (aValue instanceof InvokeVirtualMethodExpression) {
printInvokeVirtual((InvokeVirtualMethodExpression) aValue);
} else if (aValue instanceof InvokeStaticMethodExpression) {
printInvokeStatic((InvokeStaticMethodExpression) aValue);
} else if (aValue instanceof GetFieldExpression) {
printGetFieldValue((GetFieldExpression) aValue);
} else if (aValue instanceof ArrayEntryExpression) {
printArrayEntryValue((ArrayEntryExpression) aValue);
} else if (aValue instanceof BinaryExpression) {
printBinaryValue((BinaryExpression) aValue);
} else if (aValue instanceof IntegerValue) {
printIntegerValue((IntegerValue) aValue);
} else if (aValue instanceof LongValue) {
printLongValue((LongValue) aValue);
} else if (aValue instanceof FloatValue) {
printFloatValue((FloatValue) aValue);
} else if (aValue instanceof DoubleValue) {
printDoubleValue((DoubleValue) aValue);
} else if (aValue instanceof TypeConversionExpression) {
printTypeConversionValue((TypeConversionExpression) aValue);
} else if (aValue instanceof CompareExpression) {
printCompareExpression((CompareExpression) aValue);
} else if (aValue instanceof DirectInvokeMethodExpression) {
printDirectInvokeMethodExpression((DirectInvokeMethodExpression) aValue);
} else {
throw new IllegalArgumentException("Not supported : " + aValue);
}
}
Aggregations