Search in sources :

Example 1 with AgreeEquation

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

the class AgreeASTPrettyprinter method visit.

@Override
public Void visit(AgreeNode node) {
    write("agree node ");
    write(node.id);
    write("(");
    newline();
    agreeVarDecls(node.inputs);
    newline();
    write(") returns (");
    newline();
    agreeVarDecls(node.outputs);
    newline();
    write(");");
    newline();
    if (!node.locals.isEmpty()) {
        write("var");
        newline();
        agreeVarDecls(node.locals);
        write(";");
        newline();
    }
    if (node.id.equals(main)) {
        write("  --%MAIN;");
        newline();
    }
    write("let");
    newline();
    if (!node.connections.isEmpty()) {
        for (AgreeConnection connection : node.connections) {
            connection(connection);
        }
        newline();
    }
    write("  children {");
    for (AgreeNode subNode : node.subNodes) {
        write(subNode.id);
        write(" ");
    }
    write("  }");
    newline();
    newline();
    statementList("assertions", node.assertions);
    statementList("assumptions", node.assumptions);
    statementList("guarantees", node.guarantees);
    statementList("lemmas", node.lemmas);
    statementList("pattern props", node.patternProps);
    for (AgreeEquation equation : node.localEquations) {
        write("  ");
        visit(equation);
        newline();
        newline();
    }
    if (node.clockConstraint != null) {
        write("  clock constraint: ");
        node.clockConstraint.accept(this);
        newline();
    }
    if (node.initialConstraint != null) {
        write("  initial constraint: ");
        node.initialConstraint.accept(this);
        newline();
    }
    if (node.clockVar != null) {
        write("  clock variable: ");
        visit(node.clockVar);
        newline();
    }
    write("  timing model: " + node.timing);
    newline();
    write("  -- TBD: event models to go along with timing model");
    newline();
    newline();
    write("tel;");
    return null;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeConnection(com.rockwellcollins.atc.agree.analysis.ast.AgreeConnection) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)

Example 2 with AgreeEquation

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

the class AgreeInlineLatchedConnections method addLatchedInputEqs.

private void addLatchedInputEqs(AgreeNodeBuilder builder, AgreeNode subNode) {
    for (AgreeVar var : subNode.inputs) {
        AgreeVar latchVar = new AgreeVar(subNode.id + "__" + var.id + LATCHED_SUFFIX, var.type, var.reference, var.compInst, var.featInst);
        builder.addLocal(latchVar);
        Expr clockExpr = new IdExpr(subNode.id + AgreeASTBuilder.clockIDSuffix);
        String sourceVarName = subNode.id + "__" + var.id;
        Equation latchEq = equation("latchVar = " + sourceVarName + " -> if (pre (not clockVar)) and clockVar then " + sourceVarName + " else pre latchVar;", to("latchVar", latchVar), to("clockVar", clockExpr));
        builder.addLocalEquation(new AgreeEquation(latchEq, null));
    }
}
Also used : Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 3 with AgreeEquation

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

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

the class AgreeASTMapVisitor method visit.

@Override
public AgreeEquation visit(AgreeEquation agreeEquation) {
    EObject reference = agreeEquation.reference;
    List<IdExpr> lhs = new ArrayList<>();
    for (IdExpr e : agreeEquation.lhs) {
        lhs.add((IdExpr) e.accept(this));
    }
    Expr rhs = agreeEquation.expr.accept(this);
    return new AgreeEquation(lhs, rhs, reference);
}
Also used : IdExpr(jkind.lustre.IdExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)

Example 5 with AgreeEquation

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation 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)

Aggregations

AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 IdExpr (jkind.lustre.IdExpr)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 Expr (jkind.lustre.Expr)12 NodeCallExpr (jkind.lustre.NodeCallExpr)10 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 UnaryExpr (jkind.lustre.UnaryExpr)9 ArrayList (java.util.ArrayList)7 IfThenElseExpr (jkind.lustre.IfThenElseExpr)6 Equation (jkind.lustre.Equation)5 RealExpr (jkind.lustre.RealExpr)5 EObject (org.eclipse.emf.ecore.EObject)5 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)4 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)4 IntExpr (jkind.lustre.IntExpr)4 HashSet (java.util.HashSet)3 BinaryOp (jkind.lustre.BinaryOp)3 VarDecl (jkind.lustre.VarDecl)3