Search in sources :

Example 6 with BytecodeResolvedFields

use of de.mirkosertic.bytecoder.core.BytecodeResolvedFields in project Bytecoder by mirkosertic.

the class WASMSSAWriter method writePutFieldExpression.

private void writePutFieldExpression(PutFieldExpression aExpression) {
    WASMMemoryLayouter.MemoryLayout theLayout = memoryLayouter.layoutFor(BytecodeObjectTypeRef.fromUtf8Constant(aExpression.getField().getClassIndex().getClassConstant().getConstant()));
    int theMemoryOffset = theLayout.offsetForInstanceMember(aExpression.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aExpression.getField().getClassIndex().getClassConstant().getConstant()));
    BytecodeResolvedFields theInstanceFields = theLinkedClass.resolvedFields();
    BytecodeResolvedFields.FieldEntry theField = theInstanceFields.fieldByName(aExpression.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
    switch(TypeRef.toType(theField.getValue().getTypeRef()).resolve()) {
        case DOUBLE:
        case FLOAT:
            print("(f32.store offset=");
            break;
        default:
            print("(i32.store offset=");
            break;
    }
    print(theMemoryOffset);
    println();
    List<Value> theIncomingData = aExpression.incomingDataFlows();
    WASMSSAWriter theChild = withDeeperIndent();
    theChild.writeValue(theIncomingData.get(0));
    theChild.writeValue(theIncomingData.get(1));
    println(")");
}
Also used : StringValue(de.mirkosertic.bytecoder.ssa.StringValue) ByteValue(de.mirkosertic.bytecoder.ssa.ByteValue) Value(de.mirkosertic.bytecoder.ssa.Value) ClassReferenceValue(de.mirkosertic.bytecoder.ssa.ClassReferenceValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) NullValue(de.mirkosertic.bytecoder.ssa.NullValue) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) ShortValue(de.mirkosertic.bytecoder.ssa.ShortValue) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass) BytecodeResolvedFields(de.mirkosertic.bytecoder.core.BytecodeResolvedFields)

Example 7 with BytecodeResolvedFields

use of de.mirkosertic.bytecoder.core.BytecodeResolvedFields in project Bytecoder by mirkosertic.

the class WASMSSAWriter method writeGetFieldValue.

private void writeGetFieldValue(GetFieldExpression aValue) {
    BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
    WASMMemoryLayouter.MemoryLayout theLayout = memoryLayouter.layoutFor(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
    int theMemoryOffset = theLayout.offsetForInstanceMember(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
    String theFieldName = aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue();
    BytecodeResolvedFields theInstanceFields = theLinkedClass.resolvedFields();
    BytecodeResolvedFields.FieldEntry theField = theInstanceFields.fieldByName(theFieldName);
    if (theField.getValue().getAccessFlags().isStatic()) {
        throw new IllegalStateException("Field " + theFieldName + " is static!");
    }
    switch(TypeRef.toType(theField.getValue().getTypeRef()).resolve()) {
        case DOUBLE:
        case FLOAT:
            print("(f32.load offset=");
            break;
        default:
            print("(i32.load offset=");
            break;
    }
    print(theMemoryOffset);
    println();
    WASMSSAWriter theChild = withDeeperIndent();
    theChild.writeValue(aValue.incomingDataFlows().get(0));
    println(")");
}
Also used : BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass) BytecodeResolvedFields(de.mirkosertic.bytecoder.core.BytecodeResolvedFields)

Example 8 with BytecodeResolvedFields

use of de.mirkosertic.bytecoder.core.BytecodeResolvedFields in project Bytecoder by mirkosertic.

the class OpenCLCompileBackend method fillInputOutputs.

private void fillInputOutputs(BytecodeLinkerContext aContext, BytecodeLinkedClass aKernelClass, ExpressionList aExpressionList, OpenCLInputOutputs aInputOutputs) {
    BytecodeResolvedFields theInstanceFields = aKernelClass.resolvedFields();
    theInstanceFields.streamForInstanceFields().forEach(aEntry -> {
        aInputOutputs.registerReadFrom(aEntry);
        aInputOutputs.registerWriteTo(aEntry);
    });
}
Also used : BytecodeResolvedFields(de.mirkosertic.bytecoder.core.BytecodeResolvedFields)

Aggregations

BytecodeResolvedFields (de.mirkosertic.bytecoder.core.BytecodeResolvedFields)8 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)6 StringValue (de.mirkosertic.bytecoder.ssa.StringValue)3 ConstantPool (de.mirkosertic.bytecoder.backend.ConstantPool)2 BytecodeArrayTypeRef (de.mirkosertic.bytecoder.core.BytecodeArrayTypeRef)2 BytecodeImportedLink (de.mirkosertic.bytecoder.core.BytecodeImportedLink)2 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)2 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)2 BytecodeObjectTypeRef (de.mirkosertic.bytecoder.core.BytecodeObjectTypeRef)2 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)2 BytecodeTypeRef (de.mirkosertic.bytecoder.core.BytecodeTypeRef)2 Relooper (de.mirkosertic.bytecoder.relooper.Relooper)2 Program (de.mirkosertic.bytecoder.ssa.Program)2 ProgramGenerator (de.mirkosertic.bytecoder.ssa.ProgramGenerator)2 Variable (de.mirkosertic.bytecoder.ssa.Variable)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Export (de.mirkosertic.bytecoder.api.Export)1