Search in sources :

Example 11 with BoolExpr

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

the class LustreAstBuilder method getLustreNode.

protected static Node getLustreNode(AgreeNode agreeNode, String nodePrefix) {
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<Expr> assertions = new ArrayList<>();
    List<String> ivcs = agreeNode.getivcElements();
    List<String> properties = new ArrayList<>();
    // add assumption history variable
    IdExpr assumHist = new IdExpr(assumeHistSufix);
    inputs.add(new AgreeVar(assumHist.id, NamedType.BOOL, null, agreeNode.compInst, null));
    int i = 0;
    for (AgreeStatement statement : agreeNode.assumptions) {
        String inputName = assumeSuffix + i++;
        inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
        IdExpr assumeId = new IdExpr(inputName);
        assertions.add(new BinaryExpr(assumeId, BinaryOp.EQUAL, statement.expr));
    }
    int j = 0;
    for (AgreeStatement statement : agreeNode.lemmas) {
        String inputName = lemmaSuffix + j++;
        inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
        properties.add(inputName);
        IdExpr lemmaId = new IdExpr(inputName);
        assertions.add(new BinaryExpr(lemmaId, BinaryOp.EQUAL, statement.expr));
    }
    int k = 0;
    Expr guarConjExpr = new BoolExpr(true);
    for (AgreeStatement statement : agreeNode.guarantees) {
        String inputName = guarSuffix + k++;
        locals.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
        IdExpr guarId = new IdExpr(inputName);
        equations.add(new Equation(guarId, statement.expr));
        if (agreeNode.getFaultTreeFlag() == false) {
            ivcs.add(guarId.id);
        } else {
            // check if it's leaf node
            if (!agreeNode.compInst.getComponentInstances().isEmpty()) {
                ivcs.add(guarId.id);
            }
        }
        guarConjExpr = LustreExprFactory.makeANDExpr(guarId, guarConjExpr);
    }
    // assert that if the assumptions have held historically, then the
    // gurantees hold
    assertions.add(new BinaryExpr(assumHist, BinaryOp.IMPLIES, guarConjExpr));
    for (AgreeStatement statement : agreeNode.assertions) {
        assertions.add(statement.expr);
    }
    // create properties for the patterns
    int l = 0;
    for (AgreeStatement patternPropState : agreeNode.patternProps) {
        String patternVarName = patternPropSuffix + l++;
        inputs.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, agreeNode.compInst, null));
        assertions.add(new BinaryExpr(new IdExpr(patternVarName), BinaryOp.EQUAL, patternPropState.expr));
    }
    Expr assertExpr = new BoolExpr(true);
    for (Expr expr : assertions) {
        assertExpr = LustreExprFactory.makeANDExpr(expr, assertExpr);
    }
    String outputName = "__ASSERT";
    List<VarDecl> outputs = new ArrayList<>();
    outputs.add(new VarDecl(outputName, NamedType.BOOL));
    equations.add(new Equation(new IdExpr(outputName), assertExpr));
    // gather the remaining inputs
    for (AgreeVar var : agreeNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.outputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.locals) {
        locals.add(var);
    }
    for (AgreeEquation equation : agreeNode.localEquations) {
        equations.add(equation);
    }
    NodeBuilder builder = new NodeBuilder(nodePrefix + agreeNode.id);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addIvcs(ivcs);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) 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) VarDecl(jkind.lustre.VarDecl)

Example 12 with BoolExpr

use of jkind.lustre.BoolExpr 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 13 with BoolExpr

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

the class LustreContractAstBuilder method flattenAgreeNodeKindContract.

protected static AgreeNode flattenAgreeNodeKindContract(AgreeNode agreeNode, String nodePrefix) {
    List<AgreeVar> inputs = new ArrayList<>();
    List<AgreeVar> outputs = new ArrayList<>();
    List<AgreeVar> locals = new ArrayList<>();
    List<AgreeStatement> assertions = new ArrayList<>();
    Expr someoneTicks = null;
    for (AgreeNode subAgreeNode : agreeNode.subNodes) {
        String prefix = subAgreeNode.id + AgreeASTBuilder.dotChar;
        Expr clockExpr = getClockExpr(agreeNode, subAgreeNode);
        if (someoneTicks == null) {
            someoneTicks = clockExpr;
        } else {
            someoneTicks = new BinaryExpr(someoneTicks, BinaryOp.OR, clockExpr);
        }
        AgreeNode flatNode = flattenAgreeNodeKindContract(subAgreeNode, nodePrefix + subAgreeNode.id + AgreeASTBuilder.dotChar);
        Node lustreNode = addSubNodeLustre(agreeNode, nodePrefix, flatNode);
        addInputsAndOutputs(inputs, outputs, flatNode, lustreNode, prefix);
        addCondactCall(agreeNode, nodePrefix, inputs, assertions, flatNode, prefix, clockExpr, lustreNode);
        // addClockHolds(agreeNode, assertions, flatNode, clockExpr, prefix,
        // lustreNode);
        addInitConstraint(agreeNode, outputs, assertions, flatNode, prefix, clockExpr, lustreNode);
    }
    if (agreeNode.timing == TimingModel.ASYNC) {
        if (someoneTicks == null) {
            throw new AgreeException("Somehow we generated a clock constraint without any clocks");
        }
        assertions.add(new AgreeStatement("someone ticks", someoneTicks, null));
    }
    addConnectionConstraints(agreeNode, assertions);
    // add any clock constraints
    assertions.addAll(agreeNode.assertions);
    assertions.add(new AgreeStatement("", agreeNode.clockConstraint, null));
    inputs.addAll(agreeNode.inputs);
    outputs.addAll(agreeNode.outputs);
    locals.addAll(agreeNode.locals);
    AgreeNodeBuilder builder = new AgreeNodeBuilder(agreeNode.id);
    builder.addInput(inputs);
    builder.addOutput(outputs);
    builder.addLocal(locals);
    builder.addLocalEquation(agreeNode.localEquations);
    builder.addSubNode(agreeNode.subNodes);
    builder.addAssertion(assertions);
    builder.addAssumption(agreeNode.assumptions);
    builder.addGuarantee(agreeNode.guarantees);
    builder.addLemma(agreeNode.lemmas);
    builder.addPatternProp(agreeNode.patternProps);
    builder.setClockConstraint(new BoolExpr(true));
    builder.setInitialConstraint(agreeNode.initialConstraint);
    builder.setClockVar(agreeNode.clockVar);
    builder.setReference(agreeNode.reference);
    builder.setTiming(null);
    builder.addEventTime(agreeNode.eventTimes);
    builder.setCompInst(agreeNode.compInst);
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BinaryExpr(jkind.lustre.BinaryExpr) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) 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) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)

Example 14 with BoolExpr

use of jkind.lustre.BoolExpr 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 15 with BoolExpr

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

the class AgreeRealtimeCalendarBuilder method getTimeConstraint.

public static Expr getTimeConstraint(Set<AgreeVar> events) {
    IdExpr timeId = AgreePatternTranslator.timeExpr;
    Expr preTime = new UnaryExpr(UnaryOp.PRE, timeId);
    Expr nodeCall = new BinaryExpr(timeId, BinaryOp.MINUS, preTime);
    for (AgreeVar eventVar : events) {
        Expr event = new IdExpr(eventVar.id);
        BinaryExpr timeChange = new BinaryExpr(event, BinaryOp.MINUS, timeId);
        Expr preTimeChange = new UnaryExpr(UnaryOp.PRE, timeChange);
        nodeCall = new NodeCallExpr(MIN_POS_NODE_NAME, preTimeChange, nodeCall);
    }
    nodeCall = new BinaryExpr(preTime, BinaryOp.PLUS, nodeCall);
    Expr timeExpr = new BinaryExpr(timeId, BinaryOp.EQUAL, nodeCall);
    timeExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, timeExpr);
    Expr timeGrtPreTime = new BinaryExpr(timeId, BinaryOp.GREATER, preTime);
    Expr timeInitZero = new BinaryExpr(timeId, BinaryOp.EQUAL, new RealExpr(BigDecimal.ZERO));
    timeInitZero = new BinaryExpr(timeInitZero, BinaryOp.ARROW, timeGrtPreTime);
    return new BinaryExpr(timeInitZero, BinaryOp.AND, timeExpr);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

BoolExpr (jkind.lustre.BoolExpr)33 BinaryExpr (jkind.lustre.BinaryExpr)32 IdExpr (jkind.lustre.IdExpr)31 Expr (jkind.lustre.Expr)27 UnaryExpr (jkind.lustre.UnaryExpr)25 NodeCallExpr (jkind.lustre.NodeCallExpr)24 IntExpr (jkind.lustre.IntExpr)19 IfThenElseExpr (jkind.lustre.IfThenElseExpr)16 ArrayList (java.util.ArrayList)13 RealExpr (jkind.lustre.RealExpr)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 Equation (jkind.lustre.Equation)12 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)10 VarDecl (jkind.lustre.VarDecl)10 NodeBuilder (jkind.lustre.builders.NodeBuilder)10 Node (jkind.lustre.Node)9 TupleExpr (jkind.lustre.TupleExpr)9 RecordAccessExpr (jkind.lustre.RecordAccessExpr)8 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)7 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)6