Search in sources :

Example 1 with AgreeNode

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

the class AgreeProgramToSimulationProgram method populateMetadata.

private static void populateMetadata(final SimulationProgramBuilder builder, final AgreeProgram agreeProgram, final Program lustreProgram, final AgreeRenaming agreeRenaming, final Map<String, EObject> refMap) {
    // Exclude inputs that are used internally by AGREE.
    for (final VarDecl vd : lustreProgram.getMainNode().inputs) {
        if (vd instanceof AgreeVar) {
            final AgreeVar agreeVar = (AgreeVar) vd;
            if (agreeVar.compInst != null) {
                final FeatureInstance featureInstance = agreeVar.featInst;
                // Use the name as provided by the instance object path unless it is not available
                final String variableName;
                if (featureInstance != null) {
                    variableName = featureInstance.getFullName();
                } else {
                    final String[] idSegs = vd.id.split("__");
                    variableName = idSegs[idSegs.length - 1];
                }
                builder.addSimulationVariable(new SimulationVariable(agreeVar.compInst, variableName, vd.id, vd.type, featureInstance, agreeVar.reference));
            }
        }
    }
    // Add mappings from component instances to agree nodes
    builder.addMapping(agreeProgram.topNode.compInst, agreeProgram.topNode);
    for (final AgreeNode n : agreeProgram.agreeNodes) {
        builder.addMapping(n.compInst, n);
    }
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) VarDecl(jkind.lustre.VarDecl) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Example 2 with AgreeNode

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

the class CreateLocalVariablesForPropertyExpressions method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
    // Build mappings between Agree Statements, expressions, and Agree Nodes
    final Map<Expr, AgreeStatement> exprToStatementMap = new HashMap<>();
    final Map<AgreeStatement, AgreeNode> agreeStatementToAgreeNodeMap = new HashMap<>();
    for (final AgreeNode agreeNode : program.getAllAgreeNodes()) {
        for (final AgreeStatement statement : agreeNode.assertions) {
            if (statement.reference instanceof AssertStatement) {
                exprToStatementMap.put(statement.expr, statement);
                agreeStatementToAgreeNodeMap.put(statement, agreeNode);
            }
        }
        for (final AgreeStatement statement : agreeNode.assumptions) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
        for (final AgreeStatement statement : agreeNode.guarantees) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
    }
    // Create local variables for assert statements, assumptions, and guarantees
    final ProgramBuilder lustreBuilder = new ProgramBuilder(lustreProgram).clearNodes();
    for (final Node lustreNode : lustreProgram.nodes) {
        lustreBuilder.addNode(VariableCreator.transform(lustreNode, exprToStatementMap, agreeStatementToAgreeNodeMap));
    }
    builder.setLustreProgram(lustreBuilder.build());
    return builder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) 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) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) RecordExpr(jkind.lustre.RecordExpr) HashMap(java.util.HashMap) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement)

Example 3 with AgreeNode

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

the class AGREESimulationStateElementFactory method createVariableStateElements.

private static List<AGREESimulationStateElement> createVariableStateElements(final AGREESimulationStateElement parent, final SimulationProgramType programType, final ComponentInstance componentInstance, final TimingModel parentTimingModel, final Map<ComponentInstance, Collection<SimulationVariable>> componentInstanceToVariablesMap, final Map<String, jkind.lustre.Type> typeIdToTypeMap, final Map<ComponentInstance, AgreeNode> componentInstanceToAgreeNodeMap, boolean includeSubcomponents) {
    assert componentInstance != null;
    assert componentInstanceToVariablesMap != null;
    assert typeIdToTypeMap != null;
    final List<AGREESimulationStateElement> elements = new ArrayList<AGREESimulationStateElement>();
    // Get the timing model for the component instance
    final AgreeNode agreeNode = componentInstanceToAgreeNodeMap.get(componentInstance);
    final TimingModel timingModel = agreeNode == null ? null : agreeNode.timing;
    // Create elements for subcomponents
    if (includeSubcomponents) {
        for (final ComponentInstance child : componentInstance.getComponentInstances()) {
            final AGREESimulationStateElement newElement = new AGREESimulationStateElement(parent, child.getFullName(), edu.uah.rsesc.aadlsimulator.VariableType.NONE, null, child, child.getSubcomponent(), false);
            newElement.setChildren(createVariableStateElements(newElement, programType, child, timingModel, componentInstanceToVariablesMap, typeIdToTypeMap, componentInstanceToAgreeNodeMap, programType.isMonolithic()));
            elements.add(newElement);
        }
    }
    // Create elements for simulation variables
    final Collection<SimulationVariable> variables = componentInstanceToVariablesMap.get(componentInstance);
    if (variables != null) {
        final boolean showClockVariables = parentTimingModel == TimingModel.ASYNC;
        for (SimulationVariable var : variables) {
            final boolean isClock = var.getLustreId().endsWith(AgreeASTBuilder.clockIDSuffix);
            boolean hidden = (var.getLustreId().contains("___") || var.getLustreId().startsWith("_")) && (!isClock || !showClockVariables);
            addChildElementsForVariable(elements, parent, var.getName(), var.getType(), new IdExpr(var.getLustreId()), typeIdToTypeMap, var.getFeatureInstance(), var.getDeclarativeReference(), hidden);
        }
    }
    return elements;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) IdExpr(jkind.lustre.IdExpr) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) ArrayList(java.util.ArrayList) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SimulationVariable(edu.uah.rsesc.aadlsimulator.agree.SimulationVariable)

Example 4 with AgreeNode

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

the class AgreeASTPrettyprinter method visit.

@Override
public Void visit(AgreeProgram program) {
    if (program.containsRealTimePatterns) {
        write("-- Program contains real-time patterns");
        newline();
        newline();
    }
    write("-- Program top-level node is: " + program.topNode.id);
    newline();
    newline();
    if (!program.globalTypes.isEmpty()) {
        for (Type type : program.globalTypes) {
            String name = "dummy";
            if (type instanceof RecordType) {
                name = ((RecordType) type).id;
            } else if (type instanceof EnumType) {
                name = ((EnumType) type).id;
            }
            TypeDef typeDef = new TypeDef(Location.NULL, name, type);
            typeDef.accept(this);
            newline();
        }
        newline();
    }
    if (!program.globalLustreNodes.isEmpty()) {
        Iterator<Node> iterator = program.globalLustreNodes.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    if (!program.uninterpretedFunctions.isEmpty()) {
        Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
        while (iterator.hasNext()) {
            iterator.next().accept(this);
            newline();
            if (iterator.hasNext()) {
                newline();
            }
        }
        newline();
    }
    Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
    while (iterator.hasNext()) {
        iterator.next().accept(this);
        newline();
        if (iterator.hasNext()) {
            newline();
        }
    }
    newline();
    return null;
}
Also used : Function(jkind.lustre.Function) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) EnumType(jkind.lustre.EnumType) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) RecordType(jkind.lustre.RecordType) TypeDef(jkind.lustre.TypeDef) EnumType(jkind.lustre.EnumType) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)

Example 5 with AgreeNode

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

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