Search in sources :

Example 16 with BinaryExpr

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

the class AgreeCalendarUtils method queueCircleNode.

public static Node queueCircleNode(String nodeName, Type type, int queueSize) {
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<IdExpr> els = new ArrayList<>();
    List<Equation> eqs = new ArrayList<>();
    String elBase = "el";
    IdExpr elemIn = new IdExpr("el_in");
    IdExpr elemOut = new IdExpr("el_out");
    IdExpr insert = new IdExpr("insert");
    IdExpr remove = new IdExpr("remove");
    IdExpr output = new IdExpr("output");
    IdExpr input = new IdExpr("input");
    IdExpr numEls = new IdExpr("num_els");
    inputs.add(new VarDecl(input.id, type));
    inputs.add(new VarDecl(elemIn.id, NamedType.BOOL));
    inputs.add(new VarDecl(elemOut.id, NamedType.BOOL));
    outputs.add(new VarDecl(numEls.id, NamedType.INT));
    outputs.add(new VarDecl(output.id, type));
    locals.add(new VarDecl(insert.id, NamedType.INT));
    locals.add(new VarDecl(remove.id, NamedType.INT));
    for (int i = 0; i < queueSize; i++) {
        IdExpr el = new IdExpr(elBase + i);
        els.add(el);
        locals.add(new VarDecl(el.id, type));
    }
    // equations for insert
    Expr preInsert = new UnaryExpr(UnaryOp.PRE, insert);
    Expr preInsertMore = new BinaryExpr(preInsert, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    Expr insertIf0 = new IfThenElseExpr(elemIn, preInsertMore, preInsert);
    Expr insertIfCond = new BinaryExpr(preInsert, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(queueSize - 1)));
    insertIfCond = new BinaryExpr(elemIn, BinaryOp.AND, insertIfCond);
    Expr insertIf1 = new IfThenElseExpr(insertIfCond, new IntExpr(BigInteger.ZERO), insertIf0);
    Expr insertIf2 = new IfThenElseExpr(elemIn, new IntExpr(BigInteger.ONE), new IntExpr(BigInteger.ZERO));
    Expr insertExpr = new BinaryExpr(insertIf2, BinaryOp.ARROW, insertIf1);
    Equation insertEq = new Equation(insert, insertExpr);
    eqs.add(insertEq);
    // equations for remove
    Expr preRemove = new UnaryExpr(UnaryOp.PRE, remove);
    Expr preRemoveMore = new BinaryExpr(preRemove, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    Expr removeIf0 = new IfThenElseExpr(elemOut, preRemoveMore, preRemove);
    Expr removeIfCond = new BinaryExpr(preRemove, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(queueSize - 1)));
    removeIfCond = new BinaryExpr(elemOut, BinaryOp.AND, removeIfCond);
    Expr removeExpr = new IfThenElseExpr(removeIfCond, new IntExpr(BigInteger.ZERO), removeIf0);
    removeExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, removeExpr);
    Equation removeEq = new Equation(remove, removeExpr);
    eqs.add(removeEq);
    Expr preElemIn = new UnaryExpr(UnaryOp.PRE, elemIn);
    Expr preElemOut = new UnaryExpr(UnaryOp.PRE, elemOut);
    Expr preNumEls = new UnaryExpr(UnaryOp.PRE, numEls);
    Expr preNumElsMore = new BinaryExpr(preNumEls, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    Expr preNumElsLessExpr = new BinaryExpr(preNumEls, BinaryOp.MINUS, new IntExpr(BigInteger.ONE));
    Expr numElsIf0 = new IfThenElseExpr(preElemIn, preNumElsMore, preNumEls);
    Expr numElsExpr = new IfThenElseExpr(preElemOut, preNumElsLessExpr, numElsIf0);
    numElsExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, numElsExpr);
    Equation numElsEq = new Equation(numEls, numElsExpr);
    eqs.add(numElsEq);
    // equation for the output
    Expr outputExpr = els.get(queueSize - 1);
    for (int i = 0; i < queueSize - 1; i++) {
        Expr cond = new BinaryExpr(preRemove, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(i)));
        outputExpr = new IfThenElseExpr(cond, els.get(i), outputExpr);
    }
    outputExpr = new BinaryExpr(els.get(0), BinaryOp.ARROW, outputExpr);
    Equation outputEq = new Equation(output, outputExpr);
    eqs.add(outputEq);
    // equations for each queue element
    for (int i = 0; i < queueSize; i++) {
        Expr preEl = new UnaryExpr(UnaryOp.PRE, els.get(i));
        Expr cond = new UnaryExpr(UnaryOp.PRE, insert);
        cond = new BinaryExpr(cond, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(i)));
        cond = new BinaryExpr(elemIn, BinaryOp.AND, cond);
        Expr elemIfExpr = new IfThenElseExpr(cond, input, preEl);
        Expr elExpr = new BinaryExpr(input, BinaryOp.ARROW, elemIfExpr);
        Equation elEq = new Equation(els.get(i), elExpr);
        eqs.add(elEq);
    }
    // queue properties:
    List<String> props = new ArrayList<>();
    // don't remove more than are present:
    // Expr propExpr0 = new BinaryExpr(preRemove, BinaryOp.EQUAL,
    // preInsert);
    // Expr propExpr1 = new BinaryExpr(remove, BinaryOp.EQUAL, preRemove);
    // Expr propImpl = new BinaryExpr(propExpr0, BinaryOp.IMPLIES,
    // propExpr1);
    // Expr propArrow = new BinaryExpr(remove, BinaryOp.LESSEQUAL, insert);
    // propArrow = new BinaryExpr(propArrow, BinaryOp.ARROW, propImpl);
    Expr propExpr = new BinaryExpr(numEls, BinaryOp.GREATEREQUAL, new IntExpr(BigInteger.ZERO));
    IdExpr propId0 = new IdExpr("__REMOVE_LTE_INSERT_" + nodeName);
    locals.add(new VarDecl(propId0.id, NamedType.BOOL));
    Equation propEq0 = new Equation(propId0, propExpr);
    eqs.add(propEq0);
    props.add(propId0.id);
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(eqs);
    builder.addProperties(props);
    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)

Example 17 with BinaryExpr

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

the class AgreeCalendarUtils method getSingleTick.

public static Expr getSingleTick(List<Expr> clocks) {
    Expr returnExpr = new BoolExpr(false);
    for (Expr clock0 : clocks) {
        Expr tickExpr = clock0;
        for (Expr clock1 : clocks) {
            if (clock0 != clock1) {
                Expr notClock1 = new UnaryExpr(UnaryOp.NOT, clock1);
                tickExpr = new BinaryExpr(tickExpr, BinaryOp.AND, notClock1);
            }
        }
        returnExpr = new BinaryExpr(tickExpr, BinaryOp.OR, returnExpr);
    }
    return returnExpr;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr)

Example 18 with BinaryExpr

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

the class AgreeNodeToLustreContract method nodeAssertsToEqs.

private static List<Equation> nodeAssertsToEqs(AgreeNode agreeNode) {
    List<Equation> eqs = new ArrayList<>();
    for (AgreeStatement statement : agreeNode.assertions) {
        if (AgreeUtils.referenceIsInContract(statement.reference, agreeNode.compInst)) {
            BinaryExpr expr = (BinaryExpr) statement.expr;
            if ((expr.op != BinaryOp.EQUAL)) {
                throw new AgreeException("Unexpected expression type in AGREE AST asssertion");
            }
            Expr leftExpr = expr.left;
            Expr rightExpr = expr.right;
            List<IdExpr> ids = new ArrayList<>();
            if (leftExpr instanceof TupleExpr) {
                TupleExpr tuple = (TupleExpr) leftExpr;
                for (Expr element : tuple.elements) {
                    ids.add((IdExpr) element);
                }
            } else {
                ids.add((IdExpr) leftExpr);
            }
            eqs.add(new Equation(ids, rightExpr));
        }
    }
    return eqs;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) BinaryExpr(jkind.lustre.BinaryExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) TupleExpr(jkind.lustre.TupleExpr)

Example 19 with BinaryExpr

use of jkind.lustre.BinaryExpr 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 20 with BinaryExpr

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

the class LustreAstBuilder method addTimeEvents.

private static void addTimeEvents(Set<AgreeVar> timeEvents, AgreeNode flatNode, String prefix, List<AgreeStatement> assertions) {
    for (AgreeVar event : flatNode.eventTimes) {
        timeEvents.add(new AgreeVar(prefix + event.id, event.type, event.reference, event.compInst, null));
    }
    // set the time variable to be equal
    IdExpr timeId = AgreePatternTranslator.timeExpr;
    assertions.add(new AgreeStatement("", new BinaryExpr(timeId, BinaryOp.EQUAL, new IdExpr(prefix + timeId.id)), null));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)86 IdExpr (jkind.lustre.IdExpr)80 Expr (jkind.lustre.Expr)74 BoolExpr (jkind.lustre.BoolExpr)71 NodeCallExpr (jkind.lustre.NodeCallExpr)62 UnaryExpr (jkind.lustre.UnaryExpr)61 IfThenElseExpr (jkind.lustre.IfThenElseExpr)48 IntExpr (jkind.lustre.IntExpr)48 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)31 ArrayList (java.util.ArrayList)29 RecordAccessExpr (jkind.lustre.RecordAccessExpr)29 RealExpr (jkind.lustre.RealExpr)27 Equation (jkind.lustre.Equation)26 VarDecl (jkind.lustre.VarDecl)26 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)25 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)23 NodeBuilder (jkind.lustre.builders.NodeBuilder)22 TupleExpr (jkind.lustre.TupleExpr)20 ArrayExpr (jkind.lustre.ArrayExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11