Search in sources :

Example 6 with ProgramBuilder

use of jkind.lustre.builders.ProgramBuilder 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 7 with ProgramBuilder

use of jkind.lustre.builders.ProgramBuilder 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 8 with ProgramBuilder

use of jkind.lustre.builders.ProgramBuilder 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 9 with ProgramBuilder

use of jkind.lustre.builders.ProgramBuilder in project AGREE by loonwerks.

the class LustreContractAstBuilder method getContractLustreProgram.

public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
    List<Expr> assertions = new ArrayList<>();
    List<VarDecl> locals = new ArrayList<>();
    List<VarDecl> inputs = new ArrayList<>();
    List<VarDecl> outputs = new ArrayList<>();
    List<Equation> equations = new ArrayList<>();
    List<String> properties = new ArrayList<>();
    List<Expr> requires = new ArrayList<>();
    List<Expr> ensures = new ArrayList<>();
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    for (AgreeStatement assumption : flatNode.assumptions) {
        requires.add(assumption.expr);
    }
    for (AgreeStatement guarantee : flatNode.lemmas) {
        ensures.add(guarantee.expr);
    }
    for (AgreeStatement guarantee : flatNode.guarantees) {
        ensures.add(guarantee.expr);
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        outputs.add(var);
    }
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            throw new AgreeException("This shouldn't happen");
        }
    }
    Contract contract = new Contract(requires, ensures);
    NodeBuilder builder = new NodeBuilder("_TOP");
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.setContract(contract);
    Node main = builder.build();
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(main);
    Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TypeDef(jkind.lustre.TypeDef) 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) VarDecl(jkind.lustre.VarDecl) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) Contract(jkind.lustre.Contract)

Example 10 with ProgramBuilder

use of jkind.lustre.builders.ProgramBuilder in project AGREE by loonwerks.

the class LustreAstBuilder method getAssumeGuaranteeLustreProgram.

public static Program getAssumeGuaranteeLustreProgram(AgreeProgram agreeProgram) {
    nodes = new ArrayList<>();
    uninterpretedFcns = new ArrayList<>();
    AgreeNode flatNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
    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<>();
    List<String> ivcs = new ArrayList<>();
    int j = 0;
    for (AgreeStatement assumption : flatNode.assumptions) {
        String assumName = assumeSuffix + j++;
        locals.add(new AgreeVar(assumName, NamedType.BOOL, assumption.reference, flatNode.compInst, null));
        IdExpr assumId = new IdExpr(assumName);
        equations.add(new Equation(assumId, assumption.expr));
        assertions.add(assumId);
        // Else add the defined ivc list.
        if (flatNode.getFaultTreeFlag() == false) {
            ivcs.add(assumId.id);
        }
    }
    for (AgreeStatement assertion : flatNode.assertions) {
        assertions.add(assertion.expr);
    }
    // add assumption and monolithic lemmas first (helps with proving)
    for (AgreeVar var : flatNode.outputs) {
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            properties.add(var.id);
        }
        inputs.add(var);
    }
    // add property that all assumption history is true
    Expr assumeConj = new BoolExpr(true);
    for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
        assumeConj = new BinaryExpr(new IdExpr(subNode.id + "__" + assumeHistSufix), BinaryOp.AND, assumeConj);
    }
    AgreeVar assumeHistVar = new AgreeVar(assumeHistSufix, NamedType.BOOL, agreeProgram.topNode.compInst.getComponentClassifier(), agreeProgram.topNode.compInst, null);
    locals.add(assumeHistVar);
    equations.add(new Equation(new IdExpr(assumeHistVar.id), assumeConj));
    properties.add(assumeHistVar.id);
    int k = 0;
    for (AgreeStatement patternPropState : flatNode.patternProps) {
        String patternVarName = patternPropSuffix + k++;
        locals.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(patternVarName), patternPropState.expr));
        properties.add(patternVarName);
    }
    int lemmaCount = 0;
    for (AgreeStatement lemma : flatNode.lemmas) {
        String lemmaName = lemmaSuffix + lemmaCount++;
        locals.add(new AgreeVar(lemmaName, NamedType.BOOL, lemma.reference, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(lemmaName), lemma.expr));
        properties.add(lemmaName);
    }
    int i = 0;
    for (AgreeStatement guarantee : flatNode.guarantees) {
        String guarName = guarSuffix + i++;
        locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, flatNode.compInst, null));
        equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
        properties.add(guarName);
    }
    if (flatNode.getFaultTreeFlag()) {
        ivcs.addAll(agreeProgram.topNode.getivcElements());
    }
    for (AgreeVar var : flatNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : flatNode.locals) {
        locals.add(var);
    }
    equations.addAll(flatNode.localEquations);
    assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(flatNode.eventTimes));
    NodeBuilder builder = new NodeBuilder("main");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.addIvcs(ivcs);
    Node main = builder.build();
    nodes.add(main);
    nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(getHistNode());
    // add realtime constraint nodes
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
    Program program = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(main.id).build();
    return program;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) 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) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) 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)

Aggregations

ProgramBuilder (jkind.lustre.builders.ProgramBuilder)13 Program (jkind.lustre.Program)12 Node (jkind.lustre.Node)10 NodeBuilder (jkind.lustre.builders.NodeBuilder)10 IdExpr (jkind.lustre.IdExpr)8 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)7 SimulationProgramBuilder (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder)7 BinaryExpr (jkind.lustre.BinaryExpr)7 Equation (jkind.lustre.Equation)7 Expr (jkind.lustre.Expr)7 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)6 BoolExpr (jkind.lustre.BoolExpr)6 VarDecl (jkind.lustre.VarDecl)6 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)5 ArrayList (java.util.ArrayList)5 TypeDef (jkind.lustre.TypeDef)5 UnaryExpr (jkind.lustre.UnaryExpr)5 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)4 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)4 IntExpr (jkind.lustre.IntExpr)4