Search in sources :

Example 21 with VarDecl

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

the class LustreAstBuilder method addHistoricalAssumptionConstraint.

private static void addHistoricalAssumptionConstraint(AgreeNode agreeNode, String prefix, Expr clockExpr, List<AgreeStatement> assertions, Node lustreNode) {
    Expr assumConj = new BoolExpr(true);
    for (VarDecl lustreVar : lustreNode.inputs) {
        AgreeVar var = (AgreeVar) lustreVar;
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            Expr varId = new IdExpr(prefix + var.id);
            assumConj = LustreExprFactory.makeANDExpr(varId, assumConj);
        }
    }
    // assumConj = new BinaryExpr(clockExpr, BinaryOp.IMPLIES, assumConj);
    Expr histCall = new NodeCallExpr(historyNodeName, assumConj);
    Expr assertExpr = new BinaryExpr(new IdExpr(prefix + assumeSuffix + "__HIST"), BinaryOp.EQUAL, histCall);
    assertions.add(new AgreeStatement("", assertExpr, null));
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 22 with VarDecl

use of jkind.lustre.VarDecl 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)

Example 23 with VarDecl

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

the class LustreContractAstBuilder method addCondactCall.

protected static void addCondactCall(AgreeNode agreeNode, String nodePrefix, List<AgreeVar> inputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    List<Expr> inputIds = new ArrayList<>();
    List<Expr> initOutputsVals = new ArrayList<>();
    List<IdExpr> nodeOutputIds = new ArrayList<>();
    for (VarDecl var : lustreNode.inputs) {
        inputIds.add(new IdExpr(prefix + var.id));
    }
    for (VarDecl var : lustreNode.outputs) {
        AgreeVar outputVar = (AgreeVar) var;
        String dummyName = prefix + var.id + "__DUMMY";
        AgreeVar dummyVar = new AgreeVar(dummyName, outputVar.type, outputVar.reference, outputVar.compInst, outputVar.featInst);
        if (!inputs.contains(dummyVar)) {
            inputs.add(dummyVar);
        }
        initOutputsVals.add(new IdExpr(dummyName));
        nodeOutputIds.add(new IdExpr(prefix + var.id));
    }
    if (agreeNode.timing == TimingModel.LATCHED) {
        throw new AgreeException("check how we do this in the generic lustre translation now" + " to make sure that it is correct");
    }
    Expr condactExpr = new CondactExpr(clockExpr, new NodeCallExpr(lustreNode.id, inputIds), initOutputsVals);
    Expr condactOutput;
    if (nodeOutputIds.size() > 1) {
        condactOutput = new TupleExpr(nodeOutputIds);
    } else {
        condactOutput = nodeOutputIds.get(0);
    }
    Expr condactCall = new BinaryExpr(condactOutput, BinaryOp.EQUAL, condactExpr);
    assertions.add(new AgreeStatement("", condactCall, null));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) CondactExpr(jkind.lustre.CondactExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TupleExpr(jkind.lustre.TupleExpr) 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) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 24 with VarDecl

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

the class LustreContractAstBuilder method getContractLustreProgram.

public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<Expr> requires = new ArrayList<>();
    List<Expr> ensures = new ArrayList<>();
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    for (AgreeStatement assumption : flatNode.assumptions) {
        requires.add(assumption.expr);
    }
    for (AgreeStatement guarantee : flatNode.lemmas) {
        ensures.add(guarantee.expr);
    }
    for (AgreeStatement guarantee : flatNode.guarantees) {
        ensures.add(guarantee.expr);
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        outputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            throw new AgreeException("This shouldn't happen");
        }
    }
    Contract contract = new Contract(requires, ensures);
    NodeBuilder builder = new NodeBuilder("_TOP");
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setContract(contract);
    Node main = builder.build();
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(main);
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TypeDef(jkind.lustre.TypeDef) 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) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Contract(jkind.lustre.Contract)

Example 25 with VarDecl

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

the class AgreeRealtimeCalendarBuilder method getFallNode.

private static Node getFallNode() {
    NodeBuilder builder = new NodeBuilder(FALL_NODE_NAME);
    builder.addInput(new VarDecl("input", NamedType.BOOL));
    builder.addOutput(new VarDecl("output", NamedType.BOOL));
    IdExpr inputId = new IdExpr("input");
    IdExpr outputId = new IdExpr("output");
    Expr outputExpr = new UnaryExpr(UnaryOp.PRE, inputId);
    Expr notInput = new UnaryExpr(UnaryOp.NOT, inputId);
    outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, notInput);
    outputExpr = new BinaryExpr(notInput, BinaryOp.ARROW, outputExpr);
    builder.addEquation(new Equation(outputId, outputExpr));
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr)

Aggregations

VarDecl (jkind.lustre.VarDecl)51 IdExpr (jkind.lustre.IdExpr)43 BinaryExpr (jkind.lustre.BinaryExpr)36 Equation (jkind.lustre.Equation)35 Expr (jkind.lustre.Expr)35 UnaryExpr (jkind.lustre.UnaryExpr)31 NodeBuilder (jkind.lustre.builders.NodeBuilder)31 NodeCallExpr (jkind.lustre.NodeCallExpr)30 BoolExpr (jkind.lustre.BoolExpr)29 ArrayList (java.util.ArrayList)28 IfThenElseExpr (jkind.lustre.IfThenElseExpr)19 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)18 IntExpr (jkind.lustre.IntExpr)18 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)12 Node (jkind.lustre.Node)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)8 NamedType (jkind.lustre.NamedType)8 TupleExpr (jkind.lustre.TupleExpr)8 Program (jkind.lustre.Program)7 Type (jkind.lustre.Type)7