Search in sources :

Example 26 with AgreeVar

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

the class RenamingVisitor method visit.

@Override
public Void visit(VarDecl e) {
    if (isFunction) {
        renaming.addUninterpretedFnIONames(e.id);
        return null;
    }
    if (e instanceof AgreeVar) {
        AgreeVar var = (AgreeVar) e;
        String category = getCategory(rootInstance, var);
        String refStr = getReferenceStr(var);
        if (isMainNode && var.reference != null) {
            // TODO: the means of detecting whether this is a consistency analysis is a hack. Fix it.
            if ((var.reference instanceof AssumeStatement || (nodeName.contains("consistency") && var.reference instanceof GuaranteeStatement)) && category != null && category.equals("")) {
                renaming.addSupportRename(var.id, var.id);
                renaming.addSupportRefString(var.id, refStr);
                renaming.getRefMap().put(refStr, var.reference);
            } else {
                renaming.addExplicitRename(var.id, refStr);
                renaming.addToRefMap(var.id, var.reference);
            }
        } else if (var.reference instanceof GuaranteeStatement) {
            renaming.addSupportRename(nodeName + "." + var.id, category + "." + var.id);
            renaming.addSupportRefString(nodeName + "." + var.id, refStr);
            renaming.getRefMap().put(refStr, var.reference);
        } else {
            return null;
        }
        if (category != null && !layout.getCategories().contains(category)) {
            layout.addCategory(category);
        }
        layout.addElement(category, refStr, SigType.INPUT);
    }
    return null;
}
Also used : GuaranteeStatement(com.rockwellcollins.atc.agree.agree.GuaranteeStatement) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 27 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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 28 with AgreeVar

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

the class LinearizationAgreeASTVisitor method visit.

@Override
public Expr visit(NodeCallExpr e) {
    // If the call is to a linearization, generate ephemeral
    // var and constraint then substitute an id expr to the ephemeral
    // var for the fn call.
    String linCallDef = linearizationMap.get(e.node);
    if (linCallDef != null) {
        AgreeVar ephemeral = new AgreeVar(ephemeralBaseName + Integer.toString(ephemeralIndex), jkind.lustre.NamedType.REAL, null, contextStack.peek().componentInstance, null);
        ++ephemeralIndex;
        List<Expr> args = visitExprs(e.args);
        args.add(new jkind.lustre.IdExpr(ephemeral.id));
        jkind.lustre.NodeCallExpr constraintExpr = new jkind.lustre.NodeCallExpr(linCallDef, args);
        contextStack.peek().addedVars.add(ephemeral);
        contextStack.peek().liftedConstraintExprs.add(constraintExpr);
        return new jkind.lustre.IdExpr(ephemeral.id);
    }
    return new NodeCallExpr(e.location, e.node, visitExprs(e.args));
}
Also used : NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 29 with AgreeVar

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

the class AsymFaultASTBuilder method createInputForCommNode.

/**
 * Creates local input for comm node and collects fault node arguments and adds
 * the needed ones to the inputs for this node.
 *
 * @param agreeNode AgreeNode with these faults associated.
 * @param newNode NodeBuilder for this comm node.
 * @param faults List of faults on the agree node.
 * @param type Type of output of agree node.
 * @param nodeName Name of this comm node.
 * @return NodeBuilder with all inputs added.
 */
private NodeBuilder createInputForCommNode(AgreeNode agreeNode, NodeBuilder newNode, List<Fault> faults, Type type, String nodeName) {
    // This list is used to map the fault to the top node locals that
    // will reference this node name with its corresponding inputs and outputs.
    // Hence the AgreeVars that are created are specifically named for this purpose.
    List<AgreeVar> localsForCommNode = new ArrayList<>();
    // Each fault will need to be referenced in order to add ids to the triggers
    // The rest of the inputs will reference the agree node for the AgreeVar
    // reference (linked in counterexample).
    newNode.createInput("input", type);
    AgreeVar var1 = new AgreeVar(nodeName + "__input", type, agreeNode.reference);
    localsForCommNode.add(var1);
    newNode.createInput("output", type);
    AgreeVar var2 = new AgreeVar(nodeName + "__output", type, agreeNode.reference);
    localsForCommNode.add(var2);
    newNode.createInput("__ASSUME__HIST", NamedType.BOOL);
    AgreeVar var3 = new AgreeVar(nodeName + "____ASSUME__HIST", NamedType.BOOL, agreeNode.reference);
    localsForCommNode.add(var3);
    newNode.createInput("time", NamedType.REAL);
    AgreeVar var4 = new AgreeVar(nodeName + "__time", NamedType.REAL, agreeNode.reference);
    localsForCommNode.add(var4);
    newNode.createInput("__fault__nominal__output", type);
    AgreeVar var5 = new AgreeVar(nodeName + "____fault__nominal__output", type, agreeNode.reference);
    localsForCommNode.add(var5);
    // Populate trigger list for use in later assertion for mutual exclusion.
    for (Fault fault : faults) {
        newNode.createInput("__fault__trigger__" + fault.id, NamedType.BOOL);
        AgreeVar var7 = new AgreeVar(nodeName + "__fault__trigger__" + fault.id, NamedType.BOOL, fault.faultStatement);
        localsForCommNode.add(var7);
        IdExpr out = new IdExpr(super.getFaultNodeOutputId(fault));
        IdExpr trigger = new IdExpr("__fault__trigger__" + fault.id);
        TriggerFaultPair triggerPair = new TriggerFaultPair(trigger, out);
        triggerList.add(triggerPair);
    }
    // Since we have a list of faults, this must be done for all faults.
    for (Fault fault : faults) {
        localsForCommNode.addAll(addFaultNodeArgsToList(newNode, fault));
    }
    // Add to map between node and list of locals in lustre
    super.mapCommNodeToInputs.put(nodeName, localsForCommNode);
    return newNode;
}
Also used : IdExpr(jkind.lustre.IdExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 30 with AgreeVar

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

the class FaultASTBuilder method addSafetyEqInterval.

/**
 * Add saftey eq intervals to the safetyEqAsserts and safetyEqVars lists.
 *
 * @param fault	The fault with these interval eq stmts.
 * @param stmt	The IntervalEq statement
 */
private void addSafetyEqInterval(Fault fault, IntervalEq stmt) {
    Expr lhsIdExpr = new IdExpr(stmt.getLhs_int().getName());
    SafetyInterval iv = stmt.getInterv();
    BinaryOp leftOp = ((iv instanceof ClosedSafetyInterval) || (iv instanceof OpenLeftSafetyInterval)) ? BinaryOp.GREATEREQUAL : BinaryOp.GREATER;
    BinaryOp rightOp = ((iv instanceof ClosedSafetyInterval) || (iv instanceof OpenLeftSafetyInterval)) ? BinaryOp.LESSEQUAL : BinaryOp.LESS;
    Expr leftSideExpr = new BinaryExpr(lhsIdExpr, leftOp, builder.doSwitch(iv.getLow()));
    Expr rightSideExpr = new BinaryExpr(lhsIdExpr, rightOp, builder.doSwitch(iv.getHigh()));
    Expr expr = new BinaryExpr(leftSideExpr, BinaryOp.AND, rightSideExpr);
    fault.safetyEqAsserts.add(new AgreeStatement("", expr, stmt));
    // Get type in Lustre/JKind format
    com.rockwellcollins.atc.agree.AgreeTypeSystem.TypeDef typeDef = AgreeTypeSystem.typeDefFromType(stmt.getLhs_int().getType());
    Type type = SafetyUtil.getLustreType(typeDef);
    // Throw exception if type is neither real nor int
    if ((type == null) || (type.toString().equals("bool"))) {
        new SafetyException("Interval statement types can only be real or int. The problem interval is called: " + stmt.getLhs_int().getName() + ".");
    }
    // Add to safetyEqVars list
    fault.safetyEqVars.add(new AgreeVar(stmt.getLhs_int().getName(), type, this.agreeNode.reference, this.agreeNode.compInst));
}
Also used : OpenLeftSafetyInterval(edu.umn.cs.crisys.safety.safety.OpenLeftSafetyInterval) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) AgreeTypeSystem(com.rockwellcollins.atc.agree.AgreeTypeSystem) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) ClosedSafetyInterval(edu.umn.cs.crisys.safety.safety.ClosedSafetyInterval) ClosedSafetyInterval(edu.umn.cs.crisys.safety.safety.ClosedSafetyInterval) OpenLeftSafetyInterval(edu.umn.cs.crisys.safety.safety.OpenLeftSafetyInterval) SafetyInterval(edu.umn.cs.crisys.safety.safety.SafetyInterval) BinaryOp(jkind.lustre.BinaryOp)

Aggregations

AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)69 IdExpr (jkind.lustre.IdExpr)49 Expr (jkind.lustre.Expr)45 NodeCallExpr (jkind.lustre.NodeCallExpr)42 BinaryExpr (jkind.lustre.BinaryExpr)41 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)39 BoolExpr (jkind.lustre.BoolExpr)38 UnaryExpr (jkind.lustre.UnaryExpr)37 ArrayList (java.util.ArrayList)28 IfThenElseExpr (jkind.lustre.IfThenElseExpr)25 VarDecl (jkind.lustre.VarDecl)19 Equation (jkind.lustre.Equation)15 RealExpr (jkind.lustre.RealExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 IntExpr (jkind.lustre.IntExpr)13 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 NodeBuilder (jkind.lustre.builders.NodeBuilder)11 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)9