Search in sources :

Example 21 with Node

use of jkind.lustre.Node in project AGREE by loonwerks.

the class MATLABFunctionHandler method runJob.

@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
    Classifier classifier = getOutermostClassifier(root);
    if (!(classifier instanceof ComponentType)) {
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
    }
    ComponentType ct = (ComponentType) classifier;
    ComponentImplementation ci = null;
    EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
    try {
        SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
        ComponentType sysType = AgreeUtils.getInstanceType(si);
        EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
        if (annexSubClauses.size() == 0) {
            throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
        }
        // Get Agree program
        AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
        if (agreeProgram.containsRealTimePatterns) {
            throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
        }
        // Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
        // and variable declarations sorted so they are declared before use
        Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
        // Translate Lustre Node to MATLAB Function AST
        MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
        ModelInfo info = getModelInfo(ct);
        if (info == null) {
            // return;
            return Status.CANCEL_STATUS;
        }
        String dirStr = info.outputDirPath;
        if (dirStr == null || dirStr.isEmpty()) {
            // return;
            return Status.CANCEL_STATUS;
        }
        boolean exportContractsPressed = info.exportPressed;
        boolean genImplPressed = info.generatePressed;
        boolean genVerificationPressed = info.updatePressed;
        boolean verifySubsysPressed = info.verifyPressed;
        String matlabFuncScriptName = matlabFunction.name + ".m";
        if (genImplPressed) {
            // Write MATLAB script to generate subsystem in the selected
            // output folder
            String subsysName = "";
            if (info.subsystemName.equals("")) {
                subsysName = sysType.getName();
            } else {
                subsysName = info.subsystemName;
            }
            MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
            String implMdlScriptName = "generate_" + subsysName + ".m";
            // generate the script to create the impl model file into the path specified for the model
            File implMdlFile = new File(info.implMdlPath);
            String implMdlDir = implMdlFile.getParent();
            if (implMdlDir != null) {
                Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
                writeToFile(implMdlScriptPath, implMdlScript.toString());
            }
        }
        if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
            Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
            // Write MATLAB function code into the specified file in the
            // selected output folder
            writeToFile(matlabFuncScriptPath, matlabFunction.toString());
            if (genVerificationPressed || verifySubsysPressed) {
                // Create Simulink Model Update script into the output
                // folder
                MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
                String verifMdlScriptName = matlabFunction.name + "_Observer.m";
                Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
                writeToFile(verifMdlScriptPath, verifMdlScript.toString());
            }
        }
        // return;
        return Status.OK_STATUS;
    } catch (Throwable e) {
        String messages = getNestedMessages(e);
        e.printStackTrace();
        Dialog.showError("AGREE Error", e.toString());
        // return;
        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
    } finally {
        if (ci != null) {
            ci.eResource().getContents().remove(ci);
        }
        implUtil.cleanup();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Path(java.nio.file.Path) ComponentType(org.osate.aadl2.ComponentType) Node(jkind.lustre.Node) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) Classifier(org.osate.aadl2.Classifier) MATLABPrimaryFunction(com.rockwellcollins.atc.agree.codegen.ast.MATLABPrimaryFunction) EphemeralImplementationUtil(com.rockwellcollins.atc.agree.analysis.EphemeralImplementationUtil) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) SystemInstance(org.osate.aadl2.instance.SystemInstance) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) File(java.io.File) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 22 with Node

use of jkind.lustre.Node in project AGREE by loonwerks.

the class GenerateUfcObligationsVisitor method constructNewNode.

/**
 * Method for constructing new programs using the UFC obligations.
 */
private Node constructNewNode(Node existing, ObligationSet obs) {
    List<VarDecl> locals = new ArrayList<>(existing.locals);
    List<Equation> equations = new ArrayList<>(existing.equations);
    // List<String> properties = new ArrayList<>(existing.properties);
    // Change: MWW 5/6: Don't really want existing properties here.
    List<String> properties = new ArrayList<>();
    /* writing the TCG obligations back as trap properties by negating them... */
    for (int i = 0; i < obs.positivePolarity.size(); i++) {
        String varName = TRAP_PROP_PREFIX + i;
        Obligation ob = obs.positivePolarity.get(i);
        locals.add(new VarDecl(varName, NamedType.BOOL));
        equations.add(new Equation(new IdExpr(varName), new UnaryExpr(UnaryOp.NOT, ob.getObligationExpr())));
        properties.add(varName);
        // renaming information
        if (renaming != null) {
            renaming.addRenaming(varName, ob.getEqAssignId(), ob.getTestedCondition().toString(), new HashSet<Obligation>(Arrays.asList(ob)));
        }
        System.out.println("Renaming: mapping " + varName + " --> " + ob.getEqAssignId());
    }
    Node newNode = new Node(existing.id, existing.inputs, existing.outputs, locals, equations, properties, existing.assertions, null, null, new ArrayList<String>());
    return newNode;
}
Also used : Obligation(com.rockwellcollins.atc.tcg.obligations.ufc.Obligation) IdExpr(jkind.lustre.IdExpr) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) UnaryExpr(jkind.lustre.UnaryExpr) VarDecl(jkind.lustre.VarDecl)

Example 23 with Node

use of jkind.lustre.Node in project AGREE by loonwerks.

the class GenerateUfcObligationsVisitor method visit.

// under the covers stuff...not meant to be called by 'user'.
@Override
public ObligationSet visit(Program program) {
    typeReconstructor = new TypeReconstructor(program);
    Iterator<Node> iterator = program.nodes.iterator();
    while (iterator.hasNext()) {
        iterator.next().accept(this);
    }
    return null;
}
Also used : TypeReconstructor(jkind.lustre.visitors.TypeReconstructor) Node(jkind.lustre.Node)

Example 24 with Node

use of jkind.lustre.Node in project AMASE by loonwerks.

the class AsymFaultASTBuilder method createCommNodes.

/**
 * Method creates comm nodes (one for each connection). Each comm node has all
 * fault node calls, mutual exclusion, and other fault information within.
 * If a particular fault is active, it is active in all comm nodes and no other
 * fault is active at the same time.
 *
 * @param senderConnections list of connection instance ends that
 * 		  describe sender connections.
 * @param senderOutput Output that faults are connected to.
 * @param faults All faults defined on that output.
 */
private void createCommNodes(List<ConnectionInstanceEnd> senderConnections, DataPortImpl senderOutput, List<Fault> faults) {
    // For loop goes through the connections
    // and creates a commNode specific for each connection.
    // The faults are passed into the creation method (addFaultsToCommNode).
    String nodeName = "";
    // Get list of connections from parent component that senderOutput is connected to.
    String searchFor = senderOutput.getFullName();
    // Name of sender component (the one with the fanned output)
    String compName = this.agreeNode.compInst.getName();
    List<String> commNodeNamesInput = new ArrayList<>();
    List<String> commNodeNames = new ArrayList<>();
    for (int i = 0; i < senderConnections.size(); i++) {
        nodeName = "asym_node_" + i + "__" + compName + "__" + searchFor;
        Node commNode = addFaultsToCommNode(this.agreeNode, faults, senderOutput, nodeName, i);
        commNodeNamesInput.add(nodeName + "__input");
        commNodeNames.add(nodeName);
        // Make map from comm node to connections
        mapCommNodeOutputToConnections.put(nodeName + "__output", senderConnections.get(i));
        // 4. Add node to lustre
        this.addGlobalLustreNode(commNode);
    }
    // Output of sender component used to build lustre main asserts
    String senderOut = this.agreeNode.id + "__" + searchFor;
    super.mapAsymCompOutputToCommNodeIn.put(senderOut, commNodeNamesInput);
    super.mapCompNameToCommNodes.put(compName, commNodeNames);
}
Also used : AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList)

Example 25 with Node

use of jkind.lustre.Node in project AMASE by loonwerks.

the class AddFaultDriverGuardAssertionVisitor method visit.

@Override
public Node visit(Node node) {
    if (nodeId.equals(node.id)) {
        List<Expr> assertions = Lists.newArrayList(node.assertions);
        Expr expr = new IdExpr(faultDriverIds.get(0));
        for (int i = 1; i < faultDriverIds.size(); ++i) {
            expr = new BinaryExpr(expr, BinaryOp.AND, new IdExpr(faultDriverIds.get(i)));
        }
        assertions.add(new UnaryExpr(UnaryOp.NOT, expr));
        return new Node(node.location, node.id, node.inputs, node.outputs, node.locals, node.equations, node.properties, assertions, node.realizabilityInputs, node.contract, node.ivc);
    }
    return node;
}
Also used : BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) UnaryExpr(jkind.lustre.UnaryExpr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Node(jkind.lustre.Node) UnaryExpr(jkind.lustre.UnaryExpr)

Aggregations

Node (jkind.lustre.Node)46 ArrayList (java.util.ArrayList)28 IdExpr (jkind.lustre.IdExpr)24 UnaryExpr (jkind.lustre.UnaryExpr)20 BinaryExpr (jkind.lustre.BinaryExpr)19 Expr (jkind.lustre.Expr)19 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)18 NodeCallExpr (jkind.lustre.NodeCallExpr)17 BoolExpr (jkind.lustre.BoolExpr)16 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)12 Equation (jkind.lustre.Equation)12 Program (jkind.lustre.Program)12 VarDecl (jkind.lustre.VarDecl)12 NodeBuilder (jkind.lustre.builders.NodeBuilder)12 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)11 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)11 IfThenElseExpr (jkind.lustre.IfThenElseExpr)10 IntExpr (jkind.lustre.IntExpr)10 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)8