use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(InvokeStaticMethodExpression aValue) {
String theMethodName = aValue.getMethodName();
BytecodeMethodSignature theSignature = aValue.getSignature();
List<Value> theVariables = aValue.incomingDataFlows();
print(JSWriterUtils.toClassName(aValue.getClassName()));
print(".");
print(JSWriterUtils.toMethodName(theMethodName, theSignature));
print("(");
for (int i = 0; i < theVariables.size(); i++) {
if (i > 0) {
print(",");
}
print(theVariables.get(i));
}
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(NewArrayExpression aValue) {
BytecodeTypeRef theType = aValue.getType();
Value theLength = aValue.incomingDataFlows().get(0);
Object theDefaultValue = theType.defaultValue();
String theStrDefault = theDefaultValue != null ? theDefaultValue.toString() : "null";
print("bytecoder.newArray(");
print(theLength);
print(",");
print(theStrDefault);
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class JSSSAWriter method print.
private void print(TypeConversionExpression aValue) {
TypeRef theTargetType = aValue.resolveType();
Value theValue = aValue.incomingDataFlows().get(0);
switch(theTargetType.resolve()) {
case FLOAT:
print(theValue);
break;
case DOUBLE:
print(theValue);
break;
default:
print("Math.floor(");
print(theValue);
print(")");
break;
}
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class OpenCLWriter method printCompareExpression.
private void printCompareExpression(CompareExpression aExpression) {
List<Value> theIncomingData = aExpression.incomingDataFlows();
Value theVariable1 = theIncomingData.get(0);
Value theVariable2 = theIncomingData.get(1);
print("(");
printValue(theVariable1);
print(" > ");
printValue(theVariable2);
print(" ? 1 ");
print(" : (");
printValue(theVariable1);
print(" < ");
printValue(theVariable2);
print(" ? -1 : 0))");
}
use of de.mirkosertic.bytecoder.ssa.Value 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