use of jkind.lustre.VarDecl 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();
}
Aggregations