use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeNewMultiArrayValue.
private void writeNewMultiArrayValue(NewMultiArrayExpression aValue) {
List<Value> theDimensions = aValue.incomingDataFlows();
BytecodeTypeRef theType = aValue.getType();
String theMethodName;
switch(theDimensions.size()) {
case 1:
theMethodName = WASMWriterUtils.toMethodName(BytecodeObjectTypeRef.fromRuntimeClass(MemoryManager.class), "newArray", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Address.class), new BytecodeTypeRef[] { BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT }));
break;
case 2:
theMethodName = WASMWriterUtils.toMethodName(BytecodeObjectTypeRef.fromRuntimeClass(MemoryManager.class), "newArray", new BytecodeMethodSignature(BytecodeObjectTypeRef.fromRuntimeClass(Address.class), new BytecodeTypeRef[] { BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT, BytecodePrimitiveTypeRef.INT }));
break;
default:
throw new IllegalStateException("Unsupported number of dimensions : " + theDimensions.size());
}
print("(call $");
print(theMethodName);
// UNUSED argument
print(" (i32.const 0) ");
for (Value theDimension : theDimensions) {
print(" ");
writeValue(theDimension);
}
// We also need the runtime class
print(" (get_global $jlrArray__runtimeClass)");
// Plus the vtable index
print(" (i32.const ");
print(idResolver.resolveVTableMethodByType(BytecodeObjectTypeRef.fromRuntimeClass(Array.class)));
print(")");
println(") ;; new array of type " + theType);
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeArrayStoreExpression.
private void writeArrayStoreExpression(ArrayStoreExpression aExpression) {
List<Value> theIncomingData = aExpression.incomingDataFlows();
Value theArray = theIncomingData.get(0);
Value theIndex = theIncomingData.get(1);
Value theValue = theIncomingData.get(2);
// If the index is a constant, we can precompute the offset.
if (theIndex instanceof IntegerValue) {
int offset = 20 + ((IntegerValue) theIndex).getIntValue() * 4;
switch(aExpression.getArrayType().resolve()) {
case DOUBLE:
case FLOAT:
{
print("(f32.store ");
break;
}
default:
{
print("(i32.store ");
break;
}
}
print("offset=" + offset + " ");
writeValue(theArray);
print(" ");
writeValue(theValue);
println(")");
return;
}
switch(aExpression.getArrayType().resolve()) {
case DOUBLE:
case FLOAT:
{
println("(f32.store offset=20 ");
break;
}
default:
{
println("(i32.store offset=20 ");
break;
}
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.print("(i32.add ");
theChild.writeValue(theArray);
theChild.print(" (i32.mul ");
theChild.writeValue(theIndex);
theChild.print(" (i32.const 4)");
theChild.println("))");
theChild.writeValue(theValue);
theChild.println();
println(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeLookupSwitchExpression.
private void writeLookupSwitchExpression(LookupSwitchExpression aExpression) {
println("(block $outer");
Value theValue = aExpression.incomingDataFlows().get(0);
WASMSSAWriter theChild2 = withDeeperIndent();
// For each statement
for (Map.Entry<Long, ExpressionList> theEntry : aExpression.getPairs().entrySet()) {
theChild2.print("(block $switch_");
theChild2.print(theEntry.getKey());
theChild2.println();
WASMSSAWriter theChild3 = theChild2.withDeeperIndent();
theChild3.print("(br_if $switch_");
theChild3.print(theEntry.getKey());
theChild3.print(" (i32.ne (i32.const ");
theChild3.print(theEntry.getKey());
theChild3.print(") ");
theChild3.writeValue(theValue);
theChild3.print("))");
theChild3.println();
theChild3.writeExpressionList(theEntry.getValue());
theChild3.println();
theChild3.writeExpressionList(theEntry.getValue());
theChild3.println("(br $outer)");
theChild2.println(")");
}
writeExpressionList(aExpression.getDefaultExpressions());
println(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeInvokeVirtualValue.
private void writeInvokeVirtualValue(InvokeVirtualMethodExpression aValue) {
idResolver.registerGlobalType(aValue.getSignature(), false);
print("(call_indirect $t_");
print(WASMWriterUtils.toMethodSignature(aValue.getSignature(), false));
println();
List<Value> theFlows = aValue.incomingDataFlows();
Value theTarget = theFlows.get(0);
List<Value> theVariables = theFlows.subList(1, theFlows.size());
writeValue(theTarget);
println();
for (Value theValue : theVariables) {
writeValue(theValue);
println();
}
WASMSSAWriter theChild = withDeeperIndent();
theChild.println("(call_indirect $t_RESOLVEMETHOD");
WASMSSAWriter theChild2 = theChild.withDeeperIndent();
theChild2.writeValue(theTarget);
theChild2.println();
// This is the method number
theChild2.print("(i32.const ");
BytecodeVirtualMethodIdentifier theMethodIdentifier = linkerContext.getMethodCollection().identifierFor(aValue.getMethodName(), aValue.getSignature());
theChild2.print(theMethodIdentifier.getIdentifier());
theChild2.println(")");
// And this is the pointer into the function table
theChild2.print("(i32.load offset=4 ");
theChild2.writeValue(theTarget);
// This is id of the virtual table method
theChild2.println(")");
theChild.println(")");
println(")");
}
use of de.mirkosertic.bytecoder.ssa.Value in project Bytecoder by mirkosertic.
the class InvokeVirtualOptimizer method visit.
private void visit(VariableAssignmentExpression aExpression, BytecodeLinkerContext aLinkerContext) {
Value theValue = aExpression.getValue();
if (theValue instanceof InvokeVirtualMethodExpression) {
Optional<DirectInvokeMethodExpression> theNewExpression = visit((InvokeVirtualMethodExpression) theValue, aLinkerContext);
theNewExpression.ifPresent(directInvokeMethodExpression -> aExpression.replaceIncomingDataEdge(theValue, directInvokeMethodExpression));
}
}
Aggregations