Search in sources :

Example 1 with InvocationExpression

use of de.mirkosertic.bytecoder.ssa.InvocationExpression 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);
        }
    }
}
Also used : Variable(de.mirkosertic.bytecoder.ssa.Variable) InvocationExpression(de.mirkosertic.bytecoder.ssa.InvocationExpression) IFExpression(de.mirkosertic.bytecoder.ssa.IFExpression) PutFieldExpression(de.mirkosertic.bytecoder.ssa.PutFieldExpression) BreakExpression(de.mirkosertic.bytecoder.ssa.BreakExpression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) ReturnValueExpression(de.mirkosertic.bytecoder.ssa.ReturnValueExpression) ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) ArrayStoreExpression(de.mirkosertic.bytecoder.ssa.ArrayStoreExpression) ContinueExpression(de.mirkosertic.bytecoder.ssa.ContinueExpression) InvokeVirtualMethodExpression(de.mirkosertic.bytecoder.ssa.InvokeVirtualMethodExpression) TypeConversionExpression(de.mirkosertic.bytecoder.ssa.TypeConversionExpression) CompareExpression(de.mirkosertic.bytecoder.ssa.CompareExpression) DirectInvokeMethodExpression(de.mirkosertic.bytecoder.ssa.DirectInvokeMethodExpression) InvocationExpression(de.mirkosertic.bytecoder.ssa.InvocationExpression) VariableAssignmentExpression(de.mirkosertic.bytecoder.ssa.VariableAssignmentExpression) InvokeStaticMethodExpression(de.mirkosertic.bytecoder.ssa.InvokeStaticMethodExpression) ReturnExpression(de.mirkosertic.bytecoder.ssa.ReturnExpression) ReturnValueExpression(de.mirkosertic.bytecoder.ssa.ReturnValueExpression) ArrayStoreExpression(de.mirkosertic.bytecoder.ssa.ArrayStoreExpression) BinaryExpression(de.mirkosertic.bytecoder.ssa.BinaryExpression) GetFieldExpression(de.mirkosertic.bytecoder.ssa.GetFieldExpression) ContinueExpression(de.mirkosertic.bytecoder.ssa.ContinueExpression) IFExpression(de.mirkosertic.bytecoder.ssa.IFExpression) ArrayEntryExpression(de.mirkosertic.bytecoder.ssa.ArrayEntryExpression) Expression(de.mirkosertic.bytecoder.ssa.Expression) PutFieldExpression(de.mirkosertic.bytecoder.ssa.PutFieldExpression) BreakExpression(de.mirkosertic.bytecoder.ssa.BreakExpression) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) Value(de.mirkosertic.bytecoder.ssa.Value) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) ExpressionList(de.mirkosertic.bytecoder.ssa.ExpressionList) List(java.util.List) BytecodeFieldRefConstant(de.mirkosertic.bytecoder.core.BytecodeFieldRefConstant)

Aggregations

BytecodeFieldRefConstant (de.mirkosertic.bytecoder.core.BytecodeFieldRefConstant)1 ArrayEntryExpression (de.mirkosertic.bytecoder.ssa.ArrayEntryExpression)1 ArrayStoreExpression (de.mirkosertic.bytecoder.ssa.ArrayStoreExpression)1 BinaryExpression (de.mirkosertic.bytecoder.ssa.BinaryExpression)1 BreakExpression (de.mirkosertic.bytecoder.ssa.BreakExpression)1 CompareExpression (de.mirkosertic.bytecoder.ssa.CompareExpression)1 ContinueExpression (de.mirkosertic.bytecoder.ssa.ContinueExpression)1 DirectInvokeMethodExpression (de.mirkosertic.bytecoder.ssa.DirectInvokeMethodExpression)1 DoubleValue (de.mirkosertic.bytecoder.ssa.DoubleValue)1 Expression (de.mirkosertic.bytecoder.ssa.Expression)1 ExpressionList (de.mirkosertic.bytecoder.ssa.ExpressionList)1 FloatValue (de.mirkosertic.bytecoder.ssa.FloatValue)1 GetFieldExpression (de.mirkosertic.bytecoder.ssa.GetFieldExpression)1 IFExpression (de.mirkosertic.bytecoder.ssa.IFExpression)1 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)1 InvocationExpression (de.mirkosertic.bytecoder.ssa.InvocationExpression)1 InvokeStaticMethodExpression (de.mirkosertic.bytecoder.ssa.InvokeStaticMethodExpression)1 InvokeVirtualMethodExpression (de.mirkosertic.bytecoder.ssa.InvokeVirtualMethodExpression)1 LongValue (de.mirkosertic.bytecoder.ssa.LongValue)1 PutFieldExpression (de.mirkosertic.bytecoder.ssa.PutFieldExpression)1