use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class OpenCLWriter method printArrayEntryValue.
private void printArrayEntryValue(ArrayEntryExpression aValue) {
List<Value> theIncomingData = aValue.incomingDataFlows();
Value theArray = theIncomingData.get(0);
Value theIndex = theIncomingData.get(1);
if (aValue.resolveType().isObject()) {
print("&");
}
printValue(theArray);
print("[");
printValue(theIndex);
print("]");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class OpenCLWriter method printDirectInvokeMethodExpression.
private void printDirectInvokeMethodExpression(DirectInvokeMethodExpression aExpression) {
print(aExpression.getMethodName());
print("(");
List<OpenCLInputOutputs.KernelArgument> theArguments = inputOutputs.arguments();
boolean theFirst = true;
for (int i = 0; i < theArguments.size(); i++) {
theFirst = false;
if (i > 0) {
print(", ");
}
OpenCLInputOutputs.KernelArgument theArgument = theArguments.get(i);
print(theArgument.getField().getValue().getName().stringValue());
}
List<Value> theMethodArguments = aExpression.incomingDataFlows();
for (int i = 1; i < theMethodArguments.size(); i++) {
Value theValue = theMethodArguments.get(i);
if (theFirst) {
theFirst = false;
} else {
print(",");
}
print("&");
printValue(theValue);
}
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeCompareValue.
private void writeCompareValue(CompareExpression aValue) {
List<Value> theIncomingFlows = aValue.incomingDataFlows();
Value theValue1 = theIncomingFlows.get(0);
Value theValue2 = theIncomingFlows.get(1);
TypeRef.Native theValue1Type = theValue1.resolveType().resolve();
TypeRef.Native theValue2Type = theValue2.resolveType().resolve();
if (theValue1Type != theValue2Type) {
throw new IllegalStateException("Does not support mixed types : " + theValue1Type + " -> " + theValue2Type);
}
switch(theValue1Type) {
case DOUBLE:
case FLOAT:
print("(call $compareValueF32 ");
break;
default:
print("(call $compareValueI32 ");
break;
}
writeValue(theValue1);
print(" ");
writeValue(theValue2);
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeNegateValue.
private void writeNegateValue(NegatedExpression aValue) {
Value theValue = aValue.incomingDataFlows().get(0);
switch(theValue.resolveType().resolve()) {
case DOUBLE:
case FLOAT:
{
print("(f32.neg ");
writeValue(theValue);
print(")");
}
break;
default:
print("(i32.mul (i32.const -1) ");
writeValue(theValue);
print(")");
break;
}
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeBinaryValue.
private void writeBinaryValue(BinaryExpression aValue) {
List<Value> theIncomingData = aValue.incomingDataFlows();
Value theValue1 = theIncomingData.get(0);
Value theValue2 = theIncomingData.get(1);
String theType1 = WASMWriterUtils.toType(theValue1.resolveType());
String theType2 = WASMWriterUtils.toType(theValue2.resolveType());
switch(aValue.getOperator()) {
case NOTEQUALS:
{
println("(" + theType1 + ".ne ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case EQUALS:
{
println("(" + theType1 + ".eq ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case LESSTHAN:
{
if ("i32".equals(theType1)) {
println("(" + theType1 + ".lt_s ");
} else {
println("(" + theType1 + ".lt ");
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case LESSTHANOREQUALS:
{
if ("i32".equals(theType1)) {
println("(" + theType1 + ".le_s ");
} else {
println("(" + theType1 + ".le ");
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case GREATEROREQUALS:
{
if ("i32".equals(theType1)) {
println("(" + theType1 + ".ge_s ");
} else {
println("(" + theType1 + ".ge ");
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case GREATERTHAN:
{
if ("i32".equals(theType1)) {
println("(" + theType1 + ".gt_s ");
} else {
println("(" + theType1 + ".gt ");
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case ADD:
{
println("(" + theType1 + ".add ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case MUL:
{
println("(" + theType1 + ".mul");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case DIV:
{
println("(f32.div ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.printVariableNameOrValueAsFloat(theValue1);
theChild.println();
theChild.printVariableNameOrValueAsFloat(theValue2);
theChild.println();
println(")");
break;
}
case REMAINDER:
{
if (theValue1.resolveType().resolve() == TypeRef.Native.INT) {
println("(i32.rem_s ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
print("(call $float_remainder ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
print(")");
break;
}
case SUB:
{
println("(" + theType1 + ".sub ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYXOR:
{
println("(" + theType1 + ".xor ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYOR:
{
println("(" + theType1 + ".or ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYAND:
{
println("(" + theType1 + ".and ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYSHIFTLEFT:
{
println("(" + theType1 + ".shl ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYSHIFTRIGHT:
{
println("(" + theType1 + ".shr_s ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
case BINARYUNSIGNEDSHIFTRIGHT:
{
println("(" + theType1 + ".shr_u ");
WASMSSAWriter theChild = withDeeperIndent();
theChild.writeValue(theValue1);
theChild.println();
theChild.writeValue(theValue2);
theChild.println();
println(")");
break;
}
default:
throw new IllegalStateException("Operator not supported : " + aValue.getOperator());
}
}
Aggregations