Search in sources :

Example 1 with AgreeNodeBuilder

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

the class AgreeASTMapVisitor method visit.

@Override
public AgreeNode visit(AgreeNode e) {
    String id = e.id;
    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) {
        assertions.add(this.visit(stmt));
    }
    List<AgreeStatement> assumptions = new ArrayList<>();
    for (AgreeStatement stmt : e.assumptions) {
        assumptions.add(this.visit(stmt));
    }
    List<AgreeStatement> guarantees = new ArrayList<>();
    for (AgreeStatement stmt : e.guarantees) {
        guarantees.add(this.visit(stmt));
    }
    List<AgreeStatement> lemmas = new ArrayList<>();
    for (AgreeStatement stmt : e.lemmas) {
        lemmas.add(this.visit(stmt));
    }
    List<AgreeStatement> patternProps = new ArrayList<>();
    for (AgreeStatement stmt : e.patternProps) {
        patternProps.add(this.visit(stmt));
    }
    List<AgreeEquation> localEqs = new ArrayList<>();
    for (AgreeEquation eq : e.localEquations) {
        localEqs.add(this.visit(eq));
    }
    Expr clockConstraint = e.clockConstraint.accept(this);
    Expr initialConstraint = e.initialConstraint.accept(this);
    AgreeVar clockVar = this.visit(e.clockVar);
    EObject reference = e.reference;
    TimingModel timing = e.timing;
    // ComponentInstance compinst = e.compInst;
    AgreeNodeBuilder builder = new AgreeNodeBuilder(id);
    builder.addInput(inputs);
    builder.addOutput(outputs);
    builder.addLocal(locals);
    builder.addConnection(connections);
    builder.addSubNode(subNodes);
    builder.addAssertion(assertions);
    builder.addAssumption(assumptions);
    builder.addGuarantee(guarantees);
    builder.addLemma(lemmas);
    builder.addLocalEquation(localEqs);
    builder.addPatternProp(patternProps);
    builder.setClockConstraint(clockConstraint);
    builder.setInitialConstraint(initialConstraint);
    builder.setClockVar(clockVar);
    builder.setReference(reference);
    builder.setTiming(timing);
    builder.setCompInst(e.compInst);
    builder.addTimeFall(e.timeFallMap);
    builder.addTimeRise(e.timeRiseMap);
    builder.addTimeOf(e.timeOfMap);
    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) ArrayList(java.util.ArrayList) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) EObject(org.eclipse.emf.ecore.EObject) AgreeConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeConnection) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)

Example 2 with AgreeNodeBuilder

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

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

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

the class AddFaultsToNodeVisitor method visit.

// ////////////////////////////////////////////////////////////////
// 
// AGREE NODE TRAVERSAL STARTS HERE.
// 
// /////////////////////////////////////////////////////////////////
@Override
public AgreeNode visit(AgreeNode node) {
    Map<String, List<Pair>> parentFaultyVarsExpr = faultyVarsExpr;
    boolean isTop = (node == this.topNode);
    // Gather non-hardware (dependent) faults
    List<Fault> faults = gatherFaults(globalLustreNodes, node, isTop);
    // Gather HW faults
    List<HWFault> hwFaults = gatherHWFaults(globalLustreNodes, node, isTop);
    // Rename var names in faults: fault_varName
    faults = renameFaultEqs(faults);
    if (faultMap.containsKey(node.compInst) || hwfaultMap.containsKey(node.compInst)) {
        throw new SafetyException("Node: " + node.id + " has been visited twice.");
    }
    faultMap.put(node.compInst, faults);
    hwfaultMap.put(node.compInst, hwFaults);
    faultyVarsExpr = gatherFaultyOutputs(faults, node);
    // this will traverse through the child nodes
    node = super.visit(node);
    AgreeNodeBuilder nb = new AgreeNodeBuilder(node);
    // Change this nodes flag to reflect fault tree generation or not.
    if (AddFaultsToAgree.getIsGenMCS()) {
        nb.setFaultTreeFlag(true);
    }
    // If asymmetric, only add fault triggers to agree node.
    for (Fault f : faults) {
        if ((f.propType == null) || (f.propType.getPty() instanceof symmetric)) {
            addFaultInputs(f, nb);
            addFaultLocalEqsAndAsserts(f, nb);
        } else {
            addFaultInputs(f, nb);
        }
    }
    addHWFaultInputs(hwFaults, nb);
    addToMutualExclusionList();
    addNominalVars(node, nb);
    addFaultNodeEqs(faults, nb);
    if (isTop) {
        topNodeVisit(nb, node);
    }
    node = nb.build();
    faultyVarsExpr = parentFaultyVarsExpr;
    // for asymmetric faults.
    if (!this.mapSenderToReceiver.isEmpty() && isTop) {
        SafetyNodeBuilder sb = changeTopNodeAsymConnections(nb, node);
        return sb.build();
    } else {
        return node;
    }
}
Also used : SafetyNodeBuilder(edu.umn.cs.crisys.safety.analysis.ast.SafetyNodeBuilder) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) 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) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) HWFault(edu.umn.cs.crisys.safety.analysis.transform.HWFault) edu.umn.cs.crisys.safety.safety.asymmetric(edu.umn.cs.crisys.safety.safety.asymmetric) edu.umn.cs.crisys.safety.safety.symmetric(edu.umn.cs.crisys.safety.safety.symmetric)

Example 5 with AgreeNodeBuilder

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

the class AgreePatternTranslator method translateNode.

private AgreeNode translateNode(AgreeNode node, boolean isTopNode) {
    AgreeNodeBuilder builder = new AgreeNodeBuilder(node);
    // this has to be done first because the pattern translation
    // for guarantees/lemmas/assumptions add additional assertions
    builder.clearAssertions();
    createTimeFunctions(node, builder);
    for (AgreeStatement statement : node.assertions) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, false);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addAssertion(statement);
    }
    builder.clearGuarantees();
    for (AgreeStatement statement : node.guarantees) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addGuarantee(statement);
    }
    builder.clearLemmas();
    for (AgreeStatement statement : node.lemmas) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addLemma(statement);
    }
    builder.clearAssumptions();
    for (AgreeStatement statement : node.assumptions) {
        if (statement instanceof AgreePattern) {
            containsRealTimePatterns = true;
            Expr transExpr = translatePattern((AgreePattern) statement, builder, !isTopNode);
            statement = new AgreeStatement(statement.string, transExpr, statement.reference);
        }
        builder.addAssumption(statement);
    }
    builder.clearSubNodes();
    for (AgreeNode subNode : node.subNodes) {
        builder.addSubNode(new AgreePatternTranslator().translateNode(subNode, false));
    }
    builder.addInput(new AgreeVar(timeExpr.id, NamedType.REAL, null, node.compInst, null));
    return builder.build();
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) 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) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)7 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)6 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)5 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)5 ArrayList (java.util.ArrayList)5 Expr (jkind.lustre.Expr)5 IdExpr (jkind.lustre.IdExpr)4 NodeCallExpr (jkind.lustre.NodeCallExpr)4 BinaryExpr (jkind.lustre.BinaryExpr)3 BoolExpr (jkind.lustre.BoolExpr)3 UnaryExpr (jkind.lustre.UnaryExpr)3 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)2 AgreeConnection (com.rockwellcollins.atc.agree.analysis.ast.AgreeConnection)2 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)2 Node (jkind.lustre.Node)2 TimingModel (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel)1 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)1 SafetyNodeBuilder (edu.umn.cs.crisys.safety.analysis.ast.SafetyNodeBuilder)1 BaseFault (edu.umn.cs.crisys.safety.analysis.transform.BaseFault)1 Fault (edu.umn.cs.crisys.safety.analysis.transform.Fault)1