use of de.mirkosertic.bytecoder.ssa.InvocationExpression in project Bytecoder by mirkosertic.
the class OpenCLWriter method writeExpressions.
private void writeExpressions(ExpressionList aList) {
for (Expression theExpression : aList.toList()) {
if (options.isDebugOutput()) {
String theComment = theExpression.getComment();
if (theComment != null && !theComment.isEmpty()) {
print("// ");
println(theComment);
}
}
if (theExpression instanceof VariableAssignmentExpression) {
VariableAssignmentExpression theInit = (VariableAssignmentExpression) theExpression;
Variable theVariable = theInit.getVariable();
Value theValue = theInit.getValue();
if (theVariable.resolveType().isObject() && theValue instanceof InvocationExpression) {
print(toType(theVariable.resolveType(), false));
print(" ");
print(theVariable.getName());
print("_temp = ");
printValue(theValue);
println(";");
print(theVariable.getName());
print(" = &");
print(theVariable.getName());
println("_temp;");
} else {
print(theVariable.getName());
print(" = ");
printValue(theValue);
println(";");
}
} else if (theExpression instanceof ArrayStoreExpression) {
ArrayStoreExpression theStore = (ArrayStoreExpression) theExpression;
List<Value> theIncomingData = theStore.incomingDataFlows();
Value theArray = theIncomingData.get(0);
Value theIndex = theIncomingData.get(1);
Value theValue = theIncomingData.get(2);
printValue(theArray);
print("[");
printValue(theIndex);
print("] = ");
printValue(theValue);
println(";");
} else if (theExpression instanceof IFExpression) {
IFExpression theE = (IFExpression) theExpression;
print("if ");
printValue(theE.incomingDataFlows().get(0));
println(" {");
withDeeperIndent().writeExpressions(theE.getExpressions());
println("}");
} else if (theExpression instanceof BreakExpression) {
BreakExpression theBreak = (BreakExpression) theExpression;
if (theBreak.isSetLabelRequired()) {
print("$__label__ = ");
print(theBreak.jumpTarget().getAddress());
println(";");
}
if (!theBreak.isSilent()) {
print("goto $");
print(theBreak.blockToBreak().name());
println("_next;");
}
} else if (theExpression instanceof ContinueExpression) {
ContinueExpression theContinue = (ContinueExpression) theExpression;
print("$__label__ = ");
print(theContinue.jumpTarget().getAddress());
println(";");
print("goto $");
print(theContinue.labelToReturnTo().name());
println(";");
} else if (theExpression instanceof ReturnExpression) {
println("return;");
} else if (theExpression instanceof PutFieldExpression) {
PutFieldExpression thePutField = (PutFieldExpression) theExpression;
List<Value> theIncomingData = thePutField.incomingDataFlows();
Value theTarget = theIncomingData.get(0);
BytecodeFieldRefConstant theField = thePutField.getField();
Value thevalue = theIncomingData.get(1);
printValue(theTarget);
printInstanceFieldReference(theField);
print(" = ");
printValue(thevalue);
println(";");
} else if (theExpression instanceof ReturnValueExpression) {
ReturnValueExpression theReturn = (ReturnValueExpression) theExpression;
List<Value> theIncomingData = theReturn.incomingDataFlows();
print("return ");
printValue(theIncomingData.get(0));
println(";");
} else {
throw new IllegalArgumentException("Not supported. " + theExpression);
}
}
}
Aggregations