Search in sources :

Example 1 with AgreeProgram

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

the class AgreeProgramToSimulationProgram method transform.

public static SimulationProgram transform(final AgreeProgram agreeProgram, final SimulationProgramType type) {
    Objects.requireNonNull(agreeProgram, "agreeProgram must not be null");
    // Build a Component Instance to AgreeNode map
    final Program lustreProgram = LustreAstBuilder.getAssumeGuaranteeLustreProgram(agreeProgram);
    final AgreeRenaming agreeRenaming = new AgreeRenaming();
    final AgreeLayout layout = new AgreeLayout();
    RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, agreeProgram.topNode.compInst, layout);
    SimulationProgram program;
    try {
        final SimulationProgramBuilder builder = new SimulationProgramBuilder(type, agreeProgram.topNode.compInst, lustreProgram, agreeRenaming);
        populateMetadata(builder, agreeProgram, lustreProgram, agreeRenaming, agreeRenaming.getRefMap());
        program = builder.build();
    } catch (final Exception ex) {
        throw new AGREESimulatorException(lustreProgram, ex);
    }
    try {
        program = CreateLocalVariablesForPropertyExpressions.transform(program);
        program = RemovePropertySatisficationRequirements.transform(program);
        program = RemoveCondacts.transform(program);
        program = InlineNodeCalls.transform(program);
        program = ReplaceFollowedByOperator.transform(program);
        program = ReplacePreOperator.transform(program);
        program = CreateSimulationProperties.transform(program);
        program = RemoveProperties.transform(program);
        program = CreateSimulationGuarantee.transform(program);
    } catch (final Exception ex) {
        throw new AGREESimulatorException(program.getLustreProgram(), ex);
    }
    return program;
}
Also used : SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException)

Example 2 with AgreeProgram

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

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

the class VerifyHandler method runJob.

@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
    EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
    // this flag is set by the rerun handler to prevent clearing the advice map
    if (!calledFromRerun) {
        rerunAdviceMap.clear();
    }
    calledFromRerun = false;
    disableRerunHandler();
    handlerService = getWindow().getService(IHandlerService.class);
    try {
        // Make sure the user selected a component implementation
        ComponentImplementation ci = getComponentImplementation(root, implUtil);
        SystemInstance si = getSysInstance(ci, implUtil);
        AnalysisResult result;
        CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
        if (isRecursive()) {
            if (AgreeUtils.usingKind2()) {
                throw new AgreeException("Kind2 only supports monolithic verification");
            }
            result = buildAnalysisResult(ci.getName(), si);
            wrapper.addChild(result);
            result = wrapper;
        } else if (isRealizability()) {
            AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
            Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
            wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
            result = wrapper;
        } else {
            CompositeAnalysisResult wrapperTop = new CompositeAnalysisResult("Verification for " + ci.getName());
            wrapVerificationResult(si, wrapperTop);
            wrapper.addChild(wrapperTop);
            result = wrapper;
        }
        showView(result, linker);
        return doAnalysis(ci, monitor);
    } catch (Throwable e) {
        String messages = getNestedMessages(e);
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
    } finally {
        implUtil.cleanup();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Program(jkind.lustre.Program) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AnalysisResult(jkind.api.results.AnalysisResult) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) IHandlerService(org.eclipse.ui.handlers.IHandlerService) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) CompositeAnalysisResult(jkind.api.results.CompositeAnalysisResult) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 4 with AgreeProgram

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

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

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