Search in sources :

Example 6 with AgreeNode

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

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

the class AgreeASTMapVisitor method visit.

@Override
public AgreeProgram visit(AgreeProgram e) {
    List<AgreeNode> agreeNodes = new ArrayList<>();
    for (AgreeNode node : e.agreeNodes) {
        AgreeNode visitedNode = visitedNodes.get(node.compInst);
        if (visitedNode == null) {
            visitedNode = this.visit(node);
        }
        agreeNodes.add(visitedNode);
    }
    List<Node> globalLustreNodes = new ArrayList<>();
    for (Node node : e.globalLustreNodes) {
        globalLustreNodes.add(this.visit(node));
    }
    List<Function> uninterpretedFunctions = new ArrayList<>();
    for (Function function : e.uninterpretedFunctions) {
        uninterpretedFunctions.add(this.visit(function));
    }
    List<jkind.lustre.Type> globalTypes = new ArrayList<>();
    for (Type ty : e.globalTypes) {
        globalTypes.add(ty.accept(lustreTypeMapVisitor));
    }
    AgreeNode topNode = this.visit(e.topNode);
    return new AgreeProgram(agreeNodes, globalLustreNodes, uninterpretedFunctions, globalTypes, topNode);
}
Also used : Function(jkind.lustre.Function) Type(jkind.lustre.Type) ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)

Example 8 with AgreeNode

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

the class AgreeNodeToLustreContract method translate.

public static Node translate(AgreeNode agreeNode, AgreeProgram agreeProgram) {
    List<Node> nodes = new ArrayList<>();
    nodes.addAll(agreeProgram.globalLustreNodes);
    // this node needs to be the last in the list
    // so that it is set as the main node in the program
    nodes.add(translateNode(agreeNode));
    List<TypeDef> types = new ArrayList<>();
    for (Type type : agreeProgram.globalTypes) {
        RecordType recType = (RecordType) type;
        types.add(new TypeDef(recType.id, type));
    }
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).build();
    program = InlineNodeCalls.program(program);
    program = FlattenPres.program(program);
    Node main = DistributePres.node(program.getMainNode());
    main = OrderEquations.node(main);
    return main;
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) TypeDef(jkind.lustre.TypeDef) RecordType(jkind.lustre.RecordType) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList)

Example 9 with AgreeNode

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

the class LustreAstBuilder method getRealizabilityLustreProgram.

// private static AgreeProgram translate(AgreeProgram program){
// return AgreeInlineLatchedConnections.translate(program);
// }
public static Program getRealizabilityLustreProgram(AgreeProgram agreeProgram) {
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    AgreeNode topNode = agreeProgram.topNode;
    for (AgreeStatement assumption : topNode.assumptions) {
        assertions.add(assumption.expr);
    }
    int i = 0;
    for (AgreeStatement guarantee : topNode.guarantees) {
        String guarName = guarSuffix + i++;
        locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, topNode.compInst, null));
        equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
        properties.add(guarName);
    }
    List<String> inputStrs = new ArrayList<>();
    for (AgreeVar var : topNode.inputs) {
        inputs.add(var);
        inputStrs.add(var.id);
    }
    for (AgreeVar var : topNode.outputs) {
        inputs.add(var);
    }
    // and type equations. This would clear this up
    for (AgreeStatement statement : topNode.assertions) {
        if (AgreeUtils.referenceIsInContract(statement, topNode.compInst)) {
            // this is a strange hack we have to do. we have to make
            // equation and property
            // statements not assertions. They should all be binary
            // expressions with an
            // equals operator. We will need to removing their corresponding
            // variable
            // from the inputs and add them to the local variables
            BinaryExpr binExpr;
            IdExpr varId;
            try {
                binExpr = (BinaryExpr) statement.expr;
                varId = (IdExpr) binExpr.left;
            } catch (ClassCastException e) {
                // some equation variables are assertions for
                // subrange types. do not translate these to
                // local equations. Just add them to assertions
                assertions.add(statement.expr);
                continue;
            }
            boolean found = false;
            int index;
            for (index = 0; index < inputs.size(); index++) {
                VarDecl var = inputs.get(index);
                if (var.id.equals(varId.id)) {
                    found = true;
                    break;
                }
            }
            if (!found || binExpr.op != BinaryOp.EQUAL) {
                throw new AgreeException("Something went very wrong with the lustre generation in the realizability analysis");
            }
            locals.add(inputs.remove(index));
            equations.add(new Equation(varId, binExpr.right));
        }
    }
    NodeBuilder builder = new NodeBuilder("main");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setRealizabilityInputs(inputStrs);
    Node main = builder.build();
    List<Node> nodes = new ArrayList<>();
    nodes.add(main);
    nodes.addAll(agreeProgram.globalLustreNodes);
    List<Function> uFunctions = new ArrayList<>();
    uFunctions.addAll(agreeProgram.uninterpretedFunctions);
    Program program = new ProgramBuilder().addTypes(types).addFunctions(uFunctions).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) Function(jkind.lustre.Function) TypeDef(jkind.lustre.TypeDef) VarDecl(jkind.lustre.VarDecl) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) 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) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 10 with AgreeNode

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

Aggregations

AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)30 ArrayList (java.util.ArrayList)17 Node (jkind.lustre.Node)15 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)13 IdExpr (jkind.lustre.IdExpr)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)11 Expr (jkind.lustre.Expr)11 NodeCallExpr (jkind.lustre.NodeCallExpr)10 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 UnaryExpr (jkind.lustre.UnaryExpr)9 Program (jkind.lustre.Program)7 TypeDef (jkind.lustre.TypeDef)7 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)7 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)6 VarDecl (jkind.lustre.VarDecl)6 Equation (jkind.lustre.Equation)5