Search in sources :

Example 6 with IfThenElseExpr

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

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

the class AgreeMakeClockedLustreNodes method getClockedNode.

private Node getClockedNode(String node) {
    Node clockedNode = clockedNodeMap.get(node);
    if (clockedNode == null) {
        Node originalNode = null;
        for (Node progNode : origProgram.globalLustreNodes) {
            if (progNode.id == node) {
                originalNode = progNode;
                break;
            }
        }
        NodeBuilder builder = new NodeBuilder(originalNode);
        builder.setId(clockedNodePrefix + originalNode.id);
        builder.clearEquations();
        builder.clearInputs();
        builder.addInput(new VarDecl(clockVarName, NamedType.BOOL));
        builder.addInput(new VarDecl(initVarName, NamedType.BOOL));
        builder.addInputs(originalNode.inputs);
        AgreeMakeClockedLustreNodes visitor = new AgreeMakeClockedLustreNodes(this, originalNode);
        for (Equation eq : originalNode.equations) {
            Expr newExpr = eq.expr.accept(visitor);
            // this will make an unguarded pre expression, but any non initialized
            // outputs should be masked by the init expression in the calling agree node
            newExpr = new IfThenElseExpr(new IdExpr(clockVarName), newExpr, new UnaryExpr(UnaryOp.PRE, eq.lhs.get(0)));
            builder.addEquation(new Equation(eq.lhs, newExpr));
            clockedNodeMap.putAll(visitor.clockedNodeMap);
        }
        builder.addLocals(visitor.stateVars);
        builder.addEquations(visitor.stateVarEqs);
        clockedNode = builder.build();
        clockedNodeMap.put(node, clockedNode);
    }
    return clockedNode;
}
Also used : BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) Node(jkind.lustre.Node) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 8 with IfThenElseExpr

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

the class AgreePatternTranslator method translateCauseCondtionPattern.

// this method registers a timeout and creates an event that is true iff the
// condition
// holds during the given interval. This is meant to essentially translate a
// condition
// pattern to a purely event based pattern. it returns an IdExpr
// corresponding to the
// event that triggers when the condition is held for the interval
private IdExpr translateCauseCondtionPattern(AgreeCauseEffectPattern pattern, IdExpr causeId, AgreeNodeBuilder builder) {
    AgreeVar causeRiseTimeVar = getTimeRise(causeId.id, builder, pattern);
    AgreeVar causeFallTimeVar = getTimeFall(causeId.id, builder, pattern);
    AgreeVar causeHeldVar = new AgreeVar(CAUSE_CONDITION_HELD_PREFIX + causeId.id, NamedType.BOOL, pattern);
    AgreeVar causeHeldTimeoutVar = new AgreeVar(CAUSE_CONDITION_TIMEOUT_PREFIX + causeId.id, NamedType.REAL, pattern);
    builder.addLocal(causeHeldVar);
    builder.addInput(causeHeldTimeoutVar);
    IdExpr causeFallTimeId = new IdExpr(causeFallTimeVar.id);
    IdExpr causeHeldId = new IdExpr(causeHeldVar.id);
    IdExpr causeRiseTimeId = new IdExpr(causeRiseTimeVar.id);
    IdExpr causeHeldTimeoutId = new IdExpr(causeHeldTimeoutVar.id);
    {
        // timeout = if causeRiseTime > -1 and causeRiseTime > causeFallTime
        // then
        // causeRiseTime + h
        // else
        // -1
        Expr posRise = new BinaryExpr(causeRiseTimeId, BinaryOp.GREATER, NEG_ONE);
        Expr gtFall = new BinaryExpr(causeRiseTimeId, BinaryOp.GREATER, causeFallTimeId);
        Expr cond = new BinaryExpr(posRise, BinaryOp.AND, gtFall);
        Expr heldTime = new BinaryExpr(causeRiseTimeId, BinaryOp.PLUS, pattern.causeInterval.high);
        Expr ifExpr = new IfThenElseExpr(cond, heldTime, NEG_ONE);
        // builder.addLocalEquation(new AgreeEquation(causeHeldTimeoutId,
        // ifExpr, pattern));
        builder.addAssertion(new AgreeStatement(null, new BinaryExpr(causeHeldTimeoutId, BinaryOp.EQUAL, ifExpr), pattern));
        builder.addEventTime(causeHeldTimeoutVar);
    }
    {
        // causeHeld = (t = causeHeldTimeout)
        Expr causeHeldExpr = new BinaryExpr(timeExpr, BinaryOp.EQUAL, causeHeldTimeoutId);
        builder.addLocalEquation(new AgreeEquation(causeHeldId, causeHeldExpr, pattern));
    }
    return causeHeldId;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 9 with IfThenElseExpr

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

the class AgreePatternTranslator method translatePatternConstraint.

private Expr translatePatternConstraint(AgreeSporadicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
    AgreeVar jitterVar = new AgreeVar(JITTER_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar periodVar = new AgreeVar(PERIOD_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar timeoutVar = new AgreeVar(TIMEOUT_PREFIX + patternIndex, NamedType.REAL, varReference);
    builder.addOutput(jitterVar);
    builder.addOutput(periodVar);
    builder.addOutput(timeoutVar);
    IdExpr jitterId = new IdExpr(jitterVar.id);
    IdExpr periodId = new IdExpr(periodVar.id);
    IdExpr timeoutId = new IdExpr(timeoutVar.id);
    builder.addEventTime(timeoutVar);
    // -j <= jitter <= j
    Expr jitterLow = new BinaryExpr(new UnaryExpr(UnaryOp.NEGATIVE, pattern.jitter), BinaryOp.LESSEQUAL, jitterId);
    Expr jitterHigh = new BinaryExpr(jitterId, BinaryOp.LESSEQUAL, pattern.jitter);
    builder.addAssertion(new AgreeStatement(null, new BinaryExpr(jitterLow, BinaryOp.AND, jitterHigh), pattern.reference));
    // pnext >= 0 -> if pre ((pnext + jitter) = t) then pnext >= p +
    // pre(pnext) else pre(pnext)
    Expr prePNext = new UnaryExpr(UnaryOp.PRE, periodId);
    Expr pNextInit = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO));
    Expr pNextCond = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    pNextCond = new BinaryExpr(pNextCond, BinaryOp.EQUAL, timeExpr);
    pNextCond = new UnaryExpr(UnaryOp.PRE, pNextCond);
    Expr pNextThen = new BinaryExpr(pattern.period, BinaryOp.PLUS, prePNext);
    pNextThen = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, pNextThen);
    Expr pNextHold = new BinaryExpr(periodId, BinaryOp.EQUAL, prePNext);
    Expr pNextIf = new IfThenElseExpr(pNextCond, pNextThen, pNextHold);
    Expr pNext = new BinaryExpr(pNextInit, BinaryOp.ARROW, pNextIf);
    builder.addAssertion(new AgreeStatement(null, pNext, pattern.reference));
    // timeout = pnext + jitter
    Expr timeoutExpr = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    timeoutExpr = new BinaryExpr(timeoutId, BinaryOp.EQUAL, timeoutExpr);
    builder.addAssertion(new AgreeStatement(null, timeoutExpr, pattern.reference));
    // event = (t = timeout)
    Expr eventExpr = new BinaryExpr(timeExpr, BinaryOp.EQUAL, timeoutId);
    eventExpr = new BinaryExpr(pattern.event, BinaryOp.EQUAL, eventExpr);
    return eventExpr;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 10 with IfThenElseExpr

use of jkind.lustre.IfThenElseExpr in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method addAsymFaultAssertions.

/**
 * Method adds assertions associated with the asym fault event. Adds triggers
 * for the communication node faults: __fault__trigger__Sender__fault_1 : bool;
 * Adds trigger expression linking fault of sender node to the comm node
 * behavior: output = if __fault__trigger__Sender__fault_1 then
 * Sender__fault_1__node__val_out else __fault__nominal__output
 *
 * @param nb NodeBuilder that will have these assertions added.
 */
private void addAsymFaultAssertions(AgreeNodeBuilder nb) {
    // List of idExpr holding dep ids and list for indep ids
    List<Expr> triggerList = new ArrayList<>();
    for (Fault fault : mapAsymFaultToCommNodes.keySet()) {
        for (String nodeName : mapAsymFaultToCommNodes.get(fault)) {
            // Create trigger statements for each of the faults comm nodes
            IdExpr trigger = new IdExpr(nodeName + "__fault__trigger__" + fault.id);
            triggerList.add(trigger);
        }
        // Create trigger expression that links fault of sender node to comm node
        // trigger.
        String compName = mapAsymFaultToCompName.get(fault);
        IdExpr trigger = new IdExpr(compName + "__fault__trigger__" + fault.id);
        Expr bigOrExpr = buildBigOrExpr(triggerList, 0);
        Expr notBigOrExpr = new UnaryExpr(UnaryOp.NOT, bigOrExpr);
        Expr ifThenElse = new IfThenElseExpr(trigger, bigOrExpr, notBigOrExpr);
        nb.addAssertion(new AgreeStatement("", ifThenElse, this.topNode.reference));
        triggerList.clear();
    }
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) RecordAccessExpr(jkind.lustre.RecordAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) ArrayList(java.util.ArrayList) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) BaseFault(edu.umn.cs.crisys.safety.analysis.transform.BaseFault) Fault(edu.umn.cs.crisys.safety.analysis.transform.Fault) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)17 IdExpr (jkind.lustre.IdExpr)17 IfThenElseExpr (jkind.lustre.IfThenElseExpr)17 Expr (jkind.lustre.Expr)16 UnaryExpr (jkind.lustre.UnaryExpr)16 NodeCallExpr (jkind.lustre.NodeCallExpr)15 BoolExpr (jkind.lustre.BoolExpr)14 Equation (jkind.lustre.Equation)11 VarDecl (jkind.lustre.VarDecl)11 NodeBuilder (jkind.lustre.builders.NodeBuilder)11 IntExpr (jkind.lustre.IntExpr)9 ArrayList (java.util.ArrayList)8 RealExpr (jkind.lustre.RealExpr)5 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)4 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)4 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)2 RecordAccessExpr (jkind.lustre.RecordAccessExpr)2 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1