Search in sources :

Example 21 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class LinearizationAgreeASTVisitor method visit.

@Override
public AgreeNode visit(AgreeNode e) {
    List<AgreeVar> inputs = new ArrayList<>();
    for (AgreeVar input : e.inputs) {
        inputs.add(this.visit(input));
    }
    List<AgreeVar> outputs = new ArrayList<>();
    for (AgreeVar output : e.outputs) {
        outputs.add(this.visit(output));
    }
    List<AgreeVar> locals = new ArrayList<>();
    for (AgreeVar local : e.locals) {
        locals.add(this.visit(local));
    }
    // Note that nodes and connections contain cross-references to each
    // other. But, valid model structure requires that connections
    // refer only to features on the this node and the sub-nodes. Thus,
    // we may visit the sub-nodes first, and then use the result of that
    // in visiting the connections.
    // 
    List<AgreeNode> subNodes = new ArrayList<>();
    for (AgreeNode subnode : e.subNodes) {
        subNodes.add(this.visit(subnode));
    }
    List<AgreeConnection> connections = new ArrayList<>();
    for (AgreeConnection conn : e.connections) {
        connections.add(this.visit(conn));
    }
    List<AgreeStatement> assertions = new ArrayList<>();
    for (AgreeStatement stmt : e.assertions) {
        if (stmt.expr != null) {
            LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.AND);
            outputs.addAll(linResult.addedLocals);
            assertions.addAll(linResult.liftedConstraints);
            assertions.add(linResult.linearizedStatement);
        } else {
            assertions.add(stmt);
        }
    }
    List<AgreeStatement> assumptions = new ArrayList<>();
    for (AgreeStatement stmt : e.assumptions) {
        if (stmt.expr != null) {
            LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.AND);
            outputs.addAll(linResult.addedLocals);
            assertions.addAll(linResult.liftedConstraints);
            assumptions.add(linResult.linearizedStatement);
        } else {
            assumptions.add(stmt);
        }
    }
    List<AgreeStatement> guarantees = new ArrayList<>();
    for (AgreeStatement stmt : e.guarantees) {
        if (stmt.expr != null) {
            LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.IMPLIES);
            outputs.addAll(linResult.addedLocals);
            guarantees.addAll(linResult.liftedConstraints);
            guarantees.add(linResult.linearizedStatement);
        } else {
            guarantees.add(stmt);
        }
    }
    List<AgreeStatement> lemmas = new ArrayList<>();
    for (AgreeStatement stmt : e.lemmas) {
        if (stmt.expr != null) {
            LinearizationResult linResult = linearizeStatement(e, stmt, jkind.lustre.BinaryOp.IMPLIES);
            outputs.addAll(linResult.addedLocals);
            assertions.addAll(linResult.liftedConstraints);
            lemmas.add(linResult.linearizedStatement);
        } else {
            lemmas.add(stmt);
        }
    }
    Expr clockConstraint = e.clockConstraint.accept(this);
    Expr initialConstraint = e.initialConstraint.accept(this);
    AgreeVar clockVar = this.visit(e.clockVar);
    AgreeNodeBuilder builder = new AgreeNodeBuilder(e);
    builder.clearInputs();
    builder.addInput(inputs);
    builder.clearOutputs();
    builder.addOutput(outputs);
    builder.clearLocals();
    builder.addLocal(locals);
    builder.clearConnections();
    builder.addConnection(connections);
    builder.clearSubNodes();
    builder.addSubNode(subNodes);
    builder.clearAssertions();
    builder.addAssertion(assertions);
    builder.clearAssumptions();
    builder.addAssumption(assumptions);
    builder.clearGuarantees();
    builder.addGuarantee(guarantees);
    builder.clearLemmas();
    builder.addLemma(lemmas);
    builder.setClockConstraint(clockConstraint);
    builder.setInitialConstraint(initialConstraint);
    builder.setClockVar(clockVar);
    AgreeNode result = builder.build();
    visitedNodes.put(e.compInst, result);
    return result;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) ArrayList(java.util.ArrayList) AgreeConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeConnection) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 22 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.

the class AsymFaultASTBuilder method addSafetyEqStmts.

/**
 * Add any safety eq stmts to the main assert for this node.
 *
 * @param node NodeBuilder for this lustre node
 * @param fault Fault associated with the sender component
 * @param assertExpr  The main assert stmt linking the output to the fault val out
 */
private Expr addSafetyEqStmts(NodeBuilder node, List<Fault> faults, Expr assertExpr) {
    List<AgreeStatement> safetyEqList = new ArrayList<AgreeStatement>();
    // Collect all safetyEq stmts in one list
    for (Fault f : faults) {
        safetyEqList.addAll(f.safetyEqAsserts);
    }
    if (!safetyEqList.isEmpty()) {
        // Build and expression with all expr in list
        Expr safetyEqExpr = super.buildBigAndExpr(safetyEqList, 0);
        BinaryExpr finalExpr2 = new BinaryExpr(safetyEqExpr, BinaryOp.AND, assertExpr);
        return finalExpr2;
    } else {
        return assertExpr;
    }
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList)

Example 23 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method mapFaultActiveToNodeInterface.

/**
 * Method links trigger with indep/dep active stmt.
 *
 * Ex: assert (Sender__fault__trigger__Sender__fault_1 =
 * (__fault__independently__active__Sender__Sender__fault_1 or
 * __fault__dependently__active__Sender__Sender__fault_1));
 *
 * @param f       Fault
 * @param path    path of fault (where in program it is located)
 * @param base
 * @param builder Node builder that will have these assertions added
 */
public void mapFaultActiveToNodeInterface(Fault f, List<String> path, String base, AgreeNodeBuilder builder) {
    String interfaceVarId = addPathDelimiters(path, this.createFaultNodeTriggerId(f.id));
    String indepentlyActiveVarId = this.createFaultIndependentActiveId(base);
    String depentlyActiveVarId = this.createFaultDependentActiveId(base);
    // for the counterexample layout
    for (String str : path) {
        mapFaultToPath.put(f, str);
    }
    Expr equate = new BinaryExpr(new IdExpr(interfaceVarId), BinaryOp.EQUAL, new BinaryExpr(new IdExpr(indepentlyActiveVarId), BinaryOp.OR, new IdExpr(depentlyActiveVarId)));
    builder.addAssertion(new AgreeStatement("", equate, f.faultStatement));
}
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) BinaryExpr(jkind.lustre.BinaryExpr)

Example 24 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method constrainFaultActive.

/**
 * Method constrains hardware faults to be permanent.
 *
 * @param hwf      HardwareFault to be constrained.
 * @param nameBase Name of fault.
 * @param builder  AgreeNodeBuilder will have assertions added.
 */
public void constrainFaultActive(HWFault hwf, String nameBase, AgreeNodeBuilder builder) {
    IdExpr independentlyActiveExpr = new IdExpr(this.createFaultIndependentActiveId(nameBase));
    IdExpr dependentlyActiveExpr = new IdExpr(this.createFaultDependentActiveId(nameBase));
    IdExpr independentEventExpr = new IdExpr(this.createFaultEventId(nameBase));
    List<Expr> faultExprs = new ArrayList<>();
    // collect the list of source faults in the propagations
    // whose target fault is the current fault
    // the names of those source faults are created through
    // createFaultIndependentActiveId
    getSrcFaultExprList(hwf, faultExprs);
    // create a disjunction of the source faults as the triggering event
    // for the dependent fault
    Expr dependentEventExpr = buildFaultDisjunctionExpr(faultExprs, 0);
    Expr assertIndependentExpr;
    Expr assertDependentExpr;
    TemporalConstraint tc = hwf.duration.getTc();
    if (tc instanceof PermanentConstraint) {
        assertIndependentExpr = createPermanentExpr(independentlyActiveExpr, independentEventExpr);
        assertDependentExpr = createPermanentExpr(dependentlyActiveExpr, dependentEventExpr);
    } else if (tc instanceof TransientConstraint) {
        System.out.println("WARNING: ignoring duration on transient faults");
        assertIndependentExpr = createTransientExpr(independentlyActiveExpr, independentEventExpr);
        assertDependentExpr = createTransientExpr(dependentlyActiveExpr, dependentEventExpr);
    } else {
        throw new SafetyException("Unknown constraint type during translation of fault " + hwf.id + ". Constraint must be 'permanent'.");
    }
    builder.addAssertion(new AgreeStatement("", assertIndependentExpr, hwf.hwFaultStatement));
    builder.addAssertion(new AgreeStatement("", assertDependentExpr, hwf.hwFaultStatement));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) 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) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) ArrayList(java.util.ArrayList) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException)

Example 25 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method addTopLevelMaxFaultOccurrenceConstraint.

/**
 * Method adds count constraints to top level assertions.
 *
 * @param maxFaults No. of faults allowed in count.
 * @param topNode   This node (main)
 * @param builder   node builder will have constraints added.
 */
public void addTopLevelMaxFaultOccurrenceConstraint(int maxFaults, AgreeNode topNode, AgreeNodeBuilder builder) {
    // add a global fault count
    String id = "__fault__global_count";
    builder.addInput(new AgreeVar(id, NamedType.INT, topNode.reference));
    // assign it.
    List<Expr> sumExprs = new ArrayList<>();
    // getFaultCountExprList(topNode, new ArrayList<>(), sumExprs);
    getFaultCountExprList(topNode, sumExprs);
    Expr faultCountExpr = buildFaultCountExpr(sumExprs, 0);
    Expr equate = new BinaryExpr(new IdExpr(id), BinaryOp.EQUAL, faultCountExpr);
    builder.addAssertion(new AgreeStatement("", equate, topNode.reference));
    // add assertions that the mutually exclusive fault activations
    for (FaultPair curPair : mutualExclusiveFaults) {
        // assert that the pair cannot both be true
        // get fault triggers
        String ft1Trigger = this.getMainNodeFaultIndepStr(curPair.ft1);
        String ft2Trigger = this.getMainNodeFaultIndepStr(curPair.ft2);
        Expr ft1False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft1Trigger));
        Expr ft2False = new UnaryExpr(UnaryOp.NOT, new IdExpr(ft2Trigger));
        Expr ft1FalseOrft2False = new BinaryExpr(ft1False, BinaryOp.OR, ft2False);
        builder.addAssertion(new AgreeStatement("", ft1FalseOrft2False, topNode.reference));
    }
    // assert that the value is <= maxFaults
    Expr lessEqual = new BinaryExpr(new IdExpr(id), BinaryOp.LESSEQUAL, new IntExpr(maxFaults));
    builder.addAssertion(new AgreeStatement("", lessEqual, topNode.reference));
}
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) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) IntExpr(jkind.lustre.IntExpr) UnaryExpr(jkind.lustre.UnaryExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)56 IdExpr (jkind.lustre.IdExpr)50 Expr (jkind.lustre.Expr)49 BinaryExpr (jkind.lustre.BinaryExpr)47 NodeCallExpr (jkind.lustre.NodeCallExpr)45 BoolExpr (jkind.lustre.BoolExpr)44 UnaryExpr (jkind.lustre.UnaryExpr)40 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)39 IfThenElseExpr (jkind.lustre.IfThenElseExpr)28 ArrayList (java.util.ArrayList)25 IntExpr (jkind.lustre.IntExpr)23 RecordAccessExpr (jkind.lustre.RecordAccessExpr)19 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)15 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 RealExpr (jkind.lustre.RealExpr)13 VarDecl (jkind.lustre.VarDecl)13 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11 Equation (jkind.lustre.Equation)11 TupleExpr (jkind.lustre.TupleExpr)11