Search in sources :

Example 16 with AgreeProgram

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

the class AgreePatternTranslator method translate.

public static AgreeProgram translate(AgreeProgram program) {
    List<Node> patternLustreNodes = new ArrayList<>();
    // reset the static variable before refreshing its values in translateNode call
    containsRealTimePatterns = false;
    AgreeNode topNode = new AgreePatternTranslator().translateNode(program.topNode, true);
    List<AgreeNode> agreeNodes = gatherNodes(topNode);
    patternLustreNodes.addAll(program.globalLustreNodes);
    return new AgreeProgram(agreeNodes, patternLustreNodes, program.uninterpretedFunctions, program.globalTypes, topNode, containsRealTimePatterns);
}
Also used : 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 17 with AgreeProgram

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

the class AgreeMakeClockedLustreNodes method translate.

public static AgreeProgram translate(AgreeProgram program) {
    AgreeMakeClockedLustreNodes visitor = new AgreeMakeClockedLustreNodes(program);
    List<Node> nodeList = new ArrayList<>();
    for (Node node : program.globalLustreNodes) {
        nodeList.add(node);
        nodeList.add(visitor.getClockedNode(node.id));
    }
    return new AgreeProgram(program.agreeNodes, nodeList, program.uninterpretedFunctions, program.globalTypes, program.topNode);
}
Also used : Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)

Example 18 with AgreeProgram

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

Example 19 with AgreeProgram

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

the class LustreAstBuilder method getConsistencyChecks.

public static List<Pair<String, Program>> getConsistencyChecks(AgreeProgram agreeProgram) {
    List<Pair<String, Program>> programs = new ArrayList<>();
    List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
    nodes = new ArrayList<>();
    uninterpretedFcns = new ArrayList<>();
    Node topConsist = getConsistencyLustreNode(agreeProgram.topNode, false);
    // we don't want node lemmas to show up in the consistency check
    for (Node node : agreeProgram.globalLustreNodes) {
        nodes.add(removeProperties(node));
    }
    nodes.add(topConsist);
    nodes.add(getHistNode());
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
    Program topConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topConsist.id).build();
    // String topComponentName = agreeProgram.topNode.id.replace("_Instance", "");
    // programs.add(Tuples.create(topComponentName + " consistent", topConsistProg));
    programs.add(Tuples.create("This component consistent", topConsistProg));
    for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
        nodes = new ArrayList<>();
        subNode = flattenAgreeNode(agreeProgram, subNode, "_TOP__");
        Node subConsistNode = getConsistencyLustreNode(subNode, true);
        for (Node node : agreeProgram.globalLustreNodes) {
            nodes.add(removeProperties(node));
        }
        nodes.add(subConsistNode);
        nodes.add(getHistNode());
        nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
        Program subConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(subConsistNode.id).build();
        programs.add(Tuples.create(subNode.id + " consistent", subConsistProg));
    }
    nodes = new ArrayList<>();
    // agreeProgram = translate(agreeProgram);
    AgreeNode compositionNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
    Node topCompositionConsist = getConsistencyLustreNode(compositionNode, true);
    for (Node node : agreeProgram.globalLustreNodes) {
        nodes.add(removeProperties(node));
    }
    // nodes.addAll(agreeProgram.globalLustreNodes);
    nodes.add(topCompositionConsist);
    nodes.add(getHistNode());
    nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
    Program topCompositConsistProg = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(topCompositionConsist.id).build();
    programs.add(Tuples.create("Component composition consistent", topCompositConsistProg));
    return programs;
}
Also used : Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) TypeDef(jkind.lustre.TypeDef) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) Pair(org.eclipse.xtext.util.Pair)

Example 20 with AgreeProgram

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

the class AGREESimulationEngineFactoryHelper method createSimulationEngine.

public static SimulationEngine createSimulationEngine(final SystemInstance systemInstance, final ExceptionHandler exceptionHandler, final SimulationProgramType type) {
    Objects.requireNonNull(systemInstance, "systemInstance must not be null");
    Objects.requireNonNull(exceptionHandler, "exceptionHandler must not be null");
    // Check that the component type is compatible
    if (!isCompatible(systemInstance.getComponentImplementation())) {
        final ComponentType componentType = systemInstance.getComponentClassifier().getType();
        throw new RuntimeException(componentType.getName() + " does not contain an AGREE annex subclause.");
    }
    final AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(systemInstance, type.isMonolithic());
    final SimulationProgram simulationProgram = AgreeProgramToSimulationProgram.transform(agreeProgram, type);
    final Simulation simulation = new Simulation(simulationProgram);
    return new AGREESimulationEngine(simulation, systemInstance, exceptionHandler);
}
Also used : AgreeProgramToSimulationProgram(edu.uah.rsesc.aadlsimulator.agree.transformation.AgreeProgramToSimulationProgram) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) ComponentType(org.osate.aadl2.ComponentType) Simulation(edu.uah.rsesc.aadlsimulator.agree.sim.Simulation) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)

Aggregations

AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)21 Program (jkind.lustre.Program)15 AgreeASTBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder)11 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)10 Node (jkind.lustre.Node)10 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)9 ArrayList (java.util.ArrayList)9 EphemeralImplementationUtil (com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil)5 TypeDef (jkind.lustre.TypeDef)5 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)5 IStatus (org.eclipse.core.runtime.IStatus)5 Status (org.eclipse.core.runtime.Status)5 ComponentImplementation (org.osate.aadl2.ComponentImplementation)5 SystemInstance (org.osate.aadl2.instance.SystemInstance)5 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)4 AnalysisResult (jkind.api.results.AnalysisResult)4 CompositeAnalysisResult (jkind.api.results.CompositeAnalysisResult)4 IHandlerService (org.eclipse.ui.handlers.IHandlerService)4 Pair (org.eclipse.xtext.util.Pair)4 ComponentType (org.osate.aadl2.ComponentType)4