Search in sources :

Example 6 with MATLABExpr

use of com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr in project AGREE by loonwerks.

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(BinaryExpr e) {
    MATLABExpr leftExpr = e.left.accept(this);
    String opName = e.op.name();
    String opFuncStr = e.op.toString();
    MATLABBinaryOp op = MATLABBinaryOp.fromName(opName);
    MATLABExpr rightExpr = e.right.accept(this);
    if (op == null) {
        if (opName.equals("INT_DIVIDE")) {
            MATLABType type = null;
            switch(LustreToMATLABTranslator.intTypeStr) {
                case PreferenceConstants.INT_INT8:
                    type = new MATLABInt8Type();
                    break;
                case PreferenceConstants.INT_UINT8:
                    type = new MATLABUInt8Type();
                    break;
                case PreferenceConstants.INT_INT16:
                    type = new MATLABInt16Type();
                    break;
                case PreferenceConstants.INT_UINT16:
                    type = new MATLABUInt16Type();
                    break;
                case PreferenceConstants.INT_INT32:
                    type = new MATLABInt32Type();
                    break;
                case PreferenceConstants.INT_UINT32:
                    type = new MATLABUInt32Type();
                    break;
                case PreferenceConstants.INT_INT64:
                    type = new MATLABInt64Type();
                    break;
                case PreferenceConstants.INT_UINT64:
                    type = new MATLABUInt64Type();
                    break;
                default:
                    throw new IllegalArgumentException("Unknown int type: " + LustreToMATLABTranslator.intTypeStr);
            }
            MATLABTypeCastExpr castLeftExpr = new MATLABTypeCastExpr(type, leftExpr);
            MATLABTypeCastExpr castRightExpr = new MATLABTypeCastExpr(type, rightExpr);
            MATLABBinaryOp castOp = MATLABBinaryOp.fromName("DIVIDE");
            return new MATLABBinaryExpr(castLeftExpr, castOp, castRightExpr);
        } else {
            String functionName = null;
            if (opName.equals("IMPLIES")) {
                functionName = "impliesFunction";
                // mark that this function is getting called
                functionMap.get(functionName).functionCalled = true;
                return new MATLABBinaryFunctionCall(functionMap.get(functionName).name, leftExpr, rightExpr);
            } else if (opName.equals("ARROW")) {
                functionName = "arrowFunction";
                // mark that this function is getting called
                functionMap.get(functionName).functionCalled = true;
                String firstTimeVar = ((MATLABArrowFunction) functionMap.get(functionName)).firstTimeVar;
                // no duplicate addition
                if (!persistentVarMap.containsKey(firstTimeVar)) {
                    persistentVarMap.put(firstTimeVar, new MATLABBoolExpr(false));
                    persistentVarInits.add(new MATLABFirstTimeVarInit(firstTimeVar));
                }
                return new MATLABArrowFunctionCall(functionMap.get(functionName).name, firstTimeVar, leftExpr, rightExpr);
            } else if (opName.equals("EQUAL")) {
                return new MATLABBinaryFunctionCall("isequal", leftExpr, rightExpr);
            } else {
                return new MATLABBinaryFunctionCall(opFuncStr, leftExpr, rightExpr);
            }
        }
    } else {
        return new MATLABBinaryExpr(leftExpr, op, rightExpr);
    }
}
Also used : MATLABInt16Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt16Type) MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) MATLABBinaryExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr) MATLABUInt64Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt64Type) MATLABInt32Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt32Type) MATLABUInt16Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt16Type) MATLABType(com.rockwellcollins.atc.agree.codegen.ast.MATLABType) MATLABTypeCastExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr) MATLABBinaryFunctionCall(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryFunctionCall) MATLABInt8Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt8Type) MATLABInt64Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABInt64Type) MATLABArrowFunctionCall(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrowFunctionCall) MATLABFirstTimeVarInit(com.rockwellcollins.atc.agree.codegen.ast.MATLABFirstTimeVarInit) MATLABUInt32Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt32Type) MATLABUInt8Type(com.rockwellcollins.atc.agree.codegen.ast.MATLABUInt8Type) MATLABBinaryOp(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryOp) MATLABBoolExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)

Example 7 with MATLABExpr

use of com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr in project AGREE by loonwerks.

the class LustreToMATLABExprVisitor method visit.

@Override
public MATLABExpr visit(IfThenElseExpr e) {
    MATLABExpr cond = e.cond.accept(this);
    MATLABExpr ifExpr = e.thenExpr.accept(this);
    MATLABExpr elseExpr = e.elseExpr.accept(this);
    functionMap.get("ifFunction").functionCalled = true;
    return new MATLABIfFunctionCall(cond, ifExpr, elseExpr);
}
Also used : MATLABExpr(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr) MATLABIfFunctionCall(com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIfFunctionCall)

Aggregations

MATLABExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABExpr)7 MATLABType (com.rockwellcollins.atc.agree.codegen.ast.MATLABType)5 MATLABIdExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIdExpr)5 MATLABLocalBusVarInit (com.rockwellcollins.atc.agree.codegen.ast.MATLABLocalBusVarInit)3 MATLABBinaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBinaryExpr)3 MATLABBoolExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBoolExpr)3 MATLABBusElementExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABBusElementExpr)3 MATLABTypeCastExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeCastExpr)3 MATLABTypeInitExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABTypeInitExpr)3 MATLABUnaryExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABUnaryExpr)3 TreeMap (java.util.TreeMap)3 Expr (jkind.lustre.Expr)3 MATLABArrayAccessExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABArrayAccessExpr)2 MATLABDoubleExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABDoubleExpr)2 MATLABIntExpr (com.rockwellcollins.atc.agree.codegen.ast.expr.MATLABIntExpr)2 Entry (java.util.Map.Entry)2 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 ArrayExpr (jkind.lustre.ArrayExpr)2 ArrayUpdateExpr (jkind.lustre.ArrayUpdateExpr)2 BinaryExpr (jkind.lustre.BinaryExpr)2