Search in sources :

Example 36 with UnaryExpr

use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.

the class AgreeCalendarUtils method getDFANode.

public static Node getDFANode(String name, int synchrony) {
    if (synchrony <= 0) {
        throw new AgreeException("Attempt to use quasi-synchrony of value: " + synchrony);
    }
    // VarDecl rVar = new VarDecl("_r",
    // new SubrangeIntType(BigInteger.valueOf(-synchrony),
    // BigInteger.valueOf(synchrony)));
    VarDecl rVar = new VarDecl("_r", NamedType.INT);
    IdExpr r = new IdExpr(rVar.id);
    VarDecl rIsBoundedVar = new VarDecl("_r_is_bounded", NamedType.BOOL);
    IdExpr rIsBounded = new IdExpr(rIsBoundedVar.id);
    VarDecl outVar = new VarDecl("_out", NamedType.BOOL);
    IdExpr out = new IdExpr(outVar.id);
    VarDecl clkVar0 = new VarDecl("_clk0", NamedType.BOOL);
    IdExpr p = new IdExpr(clkVar0.id);
    VarDecl clkVar1 = new VarDecl("_clk1", NamedType.BOOL);
    IdExpr q = new IdExpr(clkVar1.id);
    List<VarDecl> inputs = new ArrayList<>();
    inputs.add(clkVar0);
    inputs.add(clkVar1);
    List<VarDecl> outputs = new ArrayList<>();
    outputs.add(outVar);
    List<VarDecl> locals = new ArrayList<>();
    locals.add(rVar);
    locals.add(rIsBoundedVar);
    Expr intZeroExpr = new IntExpr(BigInteger.ZERO);
    Expr intOneExpr = new IntExpr(BigInteger.ONE);
    Expr intNegOneExpr = new IntExpr(BigInteger.valueOf(-1));
    Expr intSyncValExpr = new IntExpr(BigInteger.valueOf(synchrony));
    Expr intNegSyncValxpr = new IntExpr(BigInteger.valueOf(-synchrony));
    // (0 -> pre r)
    Expr rPreExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, new UnaryExpr(UnaryOp.PRE, r));
    // (0 -> pre r) < 0
    Expr rPreLTExpr = new BinaryExpr(rPreExpr, BinaryOp.LESS, intZeroExpr);
    // (0 -> pre r) > 0
    Expr rPreGTExpr = new BinaryExpr(rPreExpr, BinaryOp.GREATER, intZeroExpr);
    // (0 -> pre r) + 1
    Expr rPrePlus = new BinaryExpr(rPreExpr, BinaryOp.PLUS, intOneExpr);
    // (0 -> pre r) - 1
    Expr rPreMinus = new BinaryExpr(rPreExpr, BinaryOp.MINUS, intOneExpr);
    // if (0 -> pre r) < 0 then 1 else ((0 -> pre r) + 1)
    Expr ifExpr0 = new IfThenElseExpr(rPreLTExpr, intOneExpr, rPrePlus);
    // if (0 -> pre r) > 0 then -1 else ((0 -> pre r) - 1)
    Expr ifExpr1 = new IfThenElseExpr(rPreGTExpr, intNegOneExpr, rPreMinus);
    // if q then (if (0 -> pre r) > 0 then -1 else ((0 -> pre r) - 1)) else
    // (0 -> pre r)
    Expr ifExprClk1 = new IfThenElseExpr(q, ifExpr1, rPreExpr);
    // if p then (if (0 -> pre r) < 0 then 1 else ((0 -> pre r) + 1))
    // else if q then (if (0 -> pre r) > 0 then -1 else ((0 -> pre r) - 1))
    // else (0 -> pre r);
    Expr ifExprClk0 = new IfThenElseExpr(p, ifExpr0, ifExprClk1);
    // if p and q then 0
    // else if p then (if (0 -> pre r) < 0 then 1 else ((0 -> pre r) + 1))
    // else if q then (if (0 -> pre r) > 0 then -1 else ((0 -> pre r) - 1))
    // else (0 -> pre r);
    Expr rExpr = new IfThenElseExpr(new BinaryExpr(p, BinaryOp.AND, q), intZeroExpr, ifExprClk0);
    // ((0 -> pre r) >= 2 and p)
    Expr condExpr0 = new BinaryExpr(new BinaryExpr(rPreExpr, BinaryOp.GREATEREQUAL, intSyncValExpr), BinaryOp.AND, p);
    // ((0 -> pre r) <= -2 and q)
    Expr condExpr1 = new BinaryExpr(new BinaryExpr(rPreExpr, BinaryOp.LESSEQUAL, intNegSyncValxpr), BinaryOp.AND, q);
    // not (((0 -> pre r) >= 2 and p) or ((0 -> pre r) <= -2 and q))
    Expr outExpr = new UnaryExpr(UnaryOp.NOT, new BinaryExpr(condExpr0, BinaryOp.OR, condExpr1));
    // r <= 2 and r >= -2
    Expr rIsBoundedExpr = new BinaryExpr(new BinaryExpr(r, BinaryOp.LESSEQUAL, intSyncValExpr), BinaryOp.AND, new BinaryExpr(r, BinaryOp.GREATEREQUAL, intNegSyncValxpr));
    List<Equation> equations = new ArrayList<>();
    equations.add(new Equation(r, rExpr));
    equations.add(new Equation(rIsBounded, rIsBoundedExpr));
    equations.add(new Equation(out, outExpr));
    // TODO we used to have the subnode property in here, but it messes up kind2
    List<String> properties = new ArrayList<>();
    // properties.add(rIsBounded.id);
    NodeBuilder builder = new NodeBuilder(name);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) IntExpr(jkind.lustre.IntExpr)

Aggregations

UnaryExpr (jkind.lustre.UnaryExpr)36 BinaryExpr (jkind.lustre.BinaryExpr)34 IdExpr (jkind.lustre.IdExpr)34 Expr (jkind.lustre.Expr)32 BoolExpr (jkind.lustre.BoolExpr)29 NodeCallExpr (jkind.lustre.NodeCallExpr)29 IfThenElseExpr (jkind.lustre.IfThenElseExpr)24 Equation (jkind.lustre.Equation)21 IntExpr (jkind.lustre.IntExpr)18 VarDecl (jkind.lustre.VarDecl)17 NodeBuilder (jkind.lustre.builders.NodeBuilder)15 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 ArrayList (java.util.ArrayList)11 RealExpr (jkind.lustre.RealExpr)11 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)6 Node (jkind.lustre.Node)6 RecordAccessExpr (jkind.lustre.RecordAccessExpr)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)4 CondactExpr (jkind.lustre.CondactExpr)4