Search in sources :

Example 1 with IdRewriter

use of com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter in project AGREE by loonwerks.

the class LustreContractAstBuilder method addInitConstraint.

protected static void addInitConstraint(AgreeNode agreeNode, List<AgreeVar> outputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    if (agreeNode.timing != TimingModel.SYNC) {
        String tickedName = subAgreeNode.id + "___TICKED";
        outputs.add(new AgreeVar(tickedName, NamedType.BOOL, null, agreeNode.compInst, null));
        Expr tickedId = new IdExpr(tickedName);
        Expr preTicked = new UnaryExpr(UnaryOp.PRE, tickedId);
        Expr tickedOrPre = new BinaryExpr(clockExpr, BinaryOp.OR, preTicked);
        Expr initOrTicked = new BinaryExpr(clockExpr, BinaryOp.ARROW, tickedOrPre);
        Expr tickedEq = new BinaryExpr(tickedId, BinaryOp.EQUAL, initOrTicked);
        assertions.add(new AgreeStatement("", tickedEq, null));
        // we have two re-write the ids in the initial expressions
        IdRewriter rewriter = id -> new IdExpr(prefix + id.id);
        Expr newInit = subAgreeNode.initialConstraint.accept(new IdRewriteVisitor(rewriter));
        Expr initConstr = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, newInit);
        assertions.add(new AgreeStatement("", initConstr, null));
        // we also need to add hold expressions for the assumptions and
        // lemmas
        Expr assumeLemmaTrue = new BoolExpr(true);
        for (VarDecl lustreVar : lustreNode.inputs) {
            AgreeVar var = (AgreeVar) lustreVar;
            if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
                assumeLemmaTrue = new BinaryExpr(assumeLemmaTrue, BinaryOp.AND, new IdExpr(prefix + var.id));
            }
        }
        assumeLemmaTrue = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, assumeLemmaTrue);
        assertions.add(new AgreeStatement("", assumeLemmaTrue, null));
    }
}
Also used : IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) Program(jkind.lustre.Program) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeBuilder(jkind.lustre.builders.NodeBuilder) CondactExpr(jkind.lustre.CondactExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) Expr(jkind.lustre.Expr) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BinaryOp(jkind.lustre.BinaryOp) UnaryOp(jkind.lustre.UnaryOp) IdExpr(jkind.lustre.IdExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) Contract(jkind.lustre.Contract) NamedType(jkind.lustre.NamedType) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Equation(jkind.lustre.Equation) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) Node(jkind.lustre.Node) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) TypeDef(jkind.lustre.TypeDef) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) BinaryExpr(jkind.lustre.BinaryExpr) IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) UnaryExpr(jkind.lustre.UnaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl)

Aggregations

AssumeStatement (com.rockwellcollins.atc.agree.agree.AssumeStatement)1 LemmaStatement (com.rockwellcollins.atc.agree.agree.LemmaStatement)1 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)1 AgreeUtils (com.rockwellcollins.atc.agree.analysis.AgreeUtils)1 AgreeASTBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder)1 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)1 TimingModel (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel)1 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)1 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)1 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)1 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)1 IdRewriteVisitor (com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor)1 IdRewriter (com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BinaryExpr (jkind.lustre.BinaryExpr)1 BinaryOp (jkind.lustre.BinaryOp)1 BoolExpr (jkind.lustre.BoolExpr)1 CondactExpr (jkind.lustre.CondactExpr)1 Contract (jkind.lustre.Contract)1