use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class OpenCLWriter method printInvokeStatic.
private void printInvokeStatic(InvokeStaticMethodExpression aValue) {
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aValue.getClassName());
BytecodeResolvedMethods theMethods = theLinkedClass.resolvedMethods();
AtomicBoolean theFound = new AtomicBoolean(false);
theMethods.stream().forEach(aMethodMapsEntry -> {
BytecodeMethod theMethod = aMethodMapsEntry.getValue();
if (Objects.equals(theMethod.getName().stringValue(), aValue.getMethodName()) && theMethod.getSignature().metchesExactlyTo(aValue.getSignature())) {
BytecodeAnnotation theAnnotation = theMethod.getAttributes().getAnnotationByType(OpenCLFunction.class.getName());
if (theAnnotation == null) {
throw new IllegalArgumentException("Annotation @OpenCLFunction required for static method " + aValue.getMethodName());
}
String theMethodName = theAnnotation.getElementValueByName("value").stringValue();
BytecodeMethodSignature theSignature = aValue.getSignature();
print(theMethodName);
print("(");
List<Value> theArguments = aValue.incomingDataFlows();
for (int i = 0; i < theArguments.size(); i++) {
if (i > 0) {
print(",");
}
if (!theSignature.getArguments()[i].isPrimitive()) {
print("*");
}
printValue(theArguments.get(i));
}
print(")");
theFound.set(true);
}
});
if (!theFound.get()) {
throw new IllegalArgumentException("Not supported method : " + aValue.getMethodName());
}
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class OpenCLWriter method printGetFieldValue.
private void printGetFieldValue(GetFieldExpression aValue) {
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
if (theLinkedClass == kernelClass) {
print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
} else {
Value theValue = aValue.incomingDataFlows().get(0);
if (theValue instanceof Variable && ((Variable) theValue).isSynthetic()) {
print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
} else {
printValue(theValue);
printInstanceFieldReference(aValue.getField());
}
}
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeDirectMethodInvokeValue.
private void writeDirectMethodInvokeValue(DirectInvokeMethodExpression aValue) {
List<Value> theIncomingData = aValue.incomingDataFlows();
Value theTarget = theIncomingData.get(0);
List<Value> theValues = theIncomingData.subList(1, theIncomingData.size());
print("(call $");
print(WASMWriterUtils.toMethodName(aValue.getClazz(), aValue.getMethodName(), aValue.getSignature()));
print(" ");
writeValue(theTarget);
for (Value theValue : theValues) {
print(" ");
writeValue(theValue);
}
print(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeTableSwitchExpression.
private void writeTableSwitchExpression(TableSwitchExpression aExpression) {
println("(block $tableswitch");
Value theValue = aExpression.incomingDataFlows().get(0);
WASMSSAWriter theChild1 = withDeeperIndent();
theChild1.println("(block $label$0");
WASMSSAWriter theChild2 = theChild1.withDeeperIndent();
theChild2.println("(block $label$1");
WASMSSAWriter theChild3 = theChild2.withDeeperIndent();
theChild3.print("(br_if $label$1 (i32.lt_s ");
theChild3.writeValue(theValue);
theChild3.print(" (i32.const ");
theChild3.print(aExpression.getLowValue());
theChild3.println(")))");
theChild3.print("(br_if $label$0 (i32.le_s ");
theChild3.writeValue(theValue);
theChild3.print(" (i32.const ");
theChild3.print(aExpression.getHighValue());
theChild3.println(")))");
theChild3.writeExpressionList(aExpression.getDefaultExpressions());
theChild3.println();
theChild3.println("(br $tableswitch)");
theChild2.println(")");
theChild1.println(")");
WASMSSAWriter theChild4 = withDeeperIndent();
// For each statement
for (Map.Entry<Long, ExpressionList> theEntry : aExpression.getOffsets().entrySet()) {
theChild4.print("(block $switch_");
theChild4.print(theEntry.getKey());
theChild4.println();
WASMSSAWriter theChild5 = theChild4.withDeeperIndent();
theChild5.print("(br_if $switch_");
theChild5.print(theEntry.getKey());
theChild5.print(" (i32.ne (i32.const ");
theChild5.print(theEntry.getKey());
theChild5.print(") (i32.sub ");
theChild5.writeValue(theValue);
theChild5.print(" (i32.const ");
theChild5.print(aExpression.getLowValue());
theChild5.print("))))");
theChild5.println();
theChild5.writeExpressionList(theEntry.getValue());
theChild5.println();
theChild4.println(")");
}
println(")");
println("(unreachable)");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeTypeConversion.
private void writeTypeConversion(TypeConversionExpression aValue) {
TypeRef theTargetType = aValue.resolveType();
Value theSource = aValue.incomingDataFlows().get(0);
if (Objects.equals(theTargetType.resolve(), theSource.resolveType().resolve())) {
// No conversion needed!
writeValue(theSource);
return;
}
switch(theSource.resolveType().resolve()) {
case DOUBLE:
case FLOAT:
{
// Convert floating point to something else
switch(aValue.resolveType().resolve()) {
case DOUBLE:
case FLOAT:
{
// No conversion needed
writeValue(theSource);
return;
}
case INT:
case SHORT:
case BYTE:
case LONG:
case CHAR:
{
// Convert f32 to i32
print("(i32.trunc_s/f32 ");
writeValue(theSource);
print(")");
return;
}
default:
throw new IllegalStateException("target type " + aValue.resolveType() + " not supported!");
}
}
case INT:
case LONG:
case BYTE:
case SHORT:
case CHAR:
{
// Convert floating point to something else
switch(aValue.resolveType().resolve()) {
case DOUBLE:
case FLOAT:
{
// Convert i32 to f32
print("(f32.convert_s/i32 ");
writeValue(theSource);
print(")");
return;
}
case INT:
case SHORT:
case BYTE:
case LONG:
case CHAR:
{
// No conversion needed
writeValue(theSource);
return;
}
default:
throw new IllegalStateException("target type " + aValue.resolveType() + " not supported!");
}
}
default:
throw new IllegalStateException("Conversion of " + theSource.resolveType() + " not supported!");
}
}
Aggregations