Search in sources :

Example 6 with NodeCallExpr

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

the class AgreeASTBuilder method getSynchConstraint.

private Expr getSynchConstraint(SynchStatement spec, List<AgreeNode> subNodes) {
    int val1 = Integer.decode(spec.getVal());
    if (val1 == 0) {
        return new BoolExpr(true);
    }
    List<Expr> clockIds = new ArrayList<>();
    Expr clockAssertion;
    for (AgreeNode subNode : subNodes) {
        clockIds.add(new IdExpr(subNode.clockVar.id));
    }
    String dfaPrefix = getObjectLocationPrefix(spec);
    if (spec.getVal2() == null) {
        Node dfaNode = AgreeCalendarUtils.getDFANode(dfaPrefix + "__DFA_NODE", val1);
        Node calNode = AgreeCalendarUtils.getCalendarNode(dfaPrefix + "__CALENDAR_NODE", dfaNode.id, clockIds.size());
        // we do not need to make copies of the nodes if they exist
        if (!nodeNameExists(dfaNode.id)) {
            if (nodeNameExists(calNode.id)) {
                throw new AgreeException("The calander node should not exist if the dfa node does not exist");
            }
            addToNodeList(dfaNode);
            addToNodeList(calNode);
        }
        clockAssertion = new NodeCallExpr(calNode.id, clockIds);
    } else {
        int val2 = Integer.decode(spec.getVal2());
        String nodeName = "__calendar_node_" + val1 + "_" + val2;
        nodeName = dfaPrefix + nodeName;
        Node calNode = AgreeCalendarUtils.getMNCalendar(nodeName, val1, val2);
        if (!nodeNameExists(calNode.id)) {
            addToNodeList(calNode);
        }
        clockAssertion = new BoolExpr(true);
        int i, j;
        for (i = 0; i < clockIds.size(); i++) {
            Expr clock1 = clockIds.get(i);
            for (j = i + 1; j < clockIds.size(); j++) {
                Expr clock2 = clockIds.get(j);
                NodeCallExpr nodeCall = new NodeCallExpr(nodeName, clock1, clock2);
                clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
                nodeCall = new NodeCallExpr(nodeName, clock2, clock1);
                clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
            }
        }
    }
    return clockAssertion;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 7 with NodeCallExpr

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

the class LustreAstBuilder method addNodeCall.

protected static void addNodeCall(AgreeNode agreeNode, List<AgreeStatement> assertions, String prefix, Expr clockExpr, Node lustreNode) {
    List<Expr> inputIds = new ArrayList<>();
    for (VarDecl var : lustreNode.inputs) {
        String suffix = "";
        // if this component implementation is using the latched semantics
        if (agreeNode.timing == TimingModel.LATCHED) {
            EObject ref = ((AgreeVar) var).reference;
            if (ref instanceof DataPortImpl && ((DataPortImpl) ref).isIn() || (ref instanceof EventDataPortImpl && ((EventDataPortImpl) ref).isIn() || (ref instanceof Arg && ref.eContainer() instanceof InputStatement))) {
                suffix = AgreeInlineLatchedConnections.LATCHED_SUFFIX;
            }
        }
        inputIds.add(new IdExpr(prefix + var.id + suffix));
    }
    if (agreeNode.timing == TimingModel.ASYNC || agreeNode.timing == TimingModel.LATCHED) {
        // the clock expr should be the last input to the node
        inputIds.set(inputIds.size() - 1, clockExpr);
    }
    Expr condactExpr = new NodeCallExpr(lustreNode.id, inputIds);
    AgreeStatement condactCall = new AgreeStatement("", condactExpr, null);
    assertions.add(condactCall);
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) EventDataPortImpl(org.osate.aadl2.impl.EventDataPortImpl) DataPortImpl(org.osate.aadl2.impl.DataPortImpl) ArrayList(java.util.ArrayList) EventDataPortImpl(org.osate.aadl2.impl.EventDataPortImpl) 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) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) EObject(org.eclipse.emf.ecore.EObject) Arg(com.rockwellcollins.atc.agree.agree.Arg) InputStatement(com.rockwellcollins.atc.agree.agree.InputStatement)

Example 8 with NodeCallExpr

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

the class LustreAstBuilder method addHistoricalAssumptionConstraint.

private static void addHistoricalAssumptionConstraint(AgreeNode agreeNode, String prefix, Expr clockExpr, List<AgreeStatement> assertions, Node lustreNode) {
    Expr assumConj = new BoolExpr(true);
    for (VarDecl lustreVar : lustreNode.inputs) {
        AgreeVar var = (AgreeVar) lustreVar;
        if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
            Expr varId = new IdExpr(prefix + var.id);
            assumConj = LustreExprFactory.makeANDExpr(varId, assumConj);
        }
    }
    // assumConj = new BinaryExpr(clockExpr, BinaryOp.IMPLIES, assumConj);
    Expr histCall = new NodeCallExpr(historyNodeName, assumConj);
    Expr assertExpr = new BinaryExpr(new IdExpr(prefix + assumeSuffix + "__HIST"), BinaryOp.EQUAL, histCall);
    assertions.add(new AgreeStatement("", assertExpr, null));
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) 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) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 9 with NodeCallExpr

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

the class LustreContractAstBuilder method addCondactCall.

protected static void addCondactCall(AgreeNode agreeNode, String nodePrefix, List<AgreeVar> inputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    List<Expr> inputIds = new ArrayList<>();
    List<Expr> initOutputsVals = new ArrayList<>();
    List<IdExpr> nodeOutputIds = new ArrayList<>();
    for (VarDecl var : lustreNode.inputs) {
        inputIds.add(new IdExpr(prefix + var.id));
    }
    for (VarDecl var : lustreNode.outputs) {
        AgreeVar outputVar = (AgreeVar) var;
        String dummyName = prefix + var.id + "__DUMMY";
        AgreeVar dummyVar = new AgreeVar(dummyName, outputVar.type, outputVar.reference, outputVar.compInst, outputVar.featInst);
        if (!inputs.contains(dummyVar)) {
            inputs.add(dummyVar);
        }
        initOutputsVals.add(new IdExpr(dummyName));
        nodeOutputIds.add(new IdExpr(prefix + var.id));
    }
    if (agreeNode.timing == TimingModel.LATCHED) {
        throw new AgreeException("check how we do this in the generic lustre translation now" + " to make sure that it is correct");
    }
    Expr condactExpr = new CondactExpr(clockExpr, new NodeCallExpr(lustreNode.id, inputIds), initOutputsVals);
    Expr condactOutput;
    if (nodeOutputIds.size() > 1) {
        condactOutput = new TupleExpr(nodeOutputIds);
    } else {
        condactOutput = nodeOutputIds.get(0);
    }
    Expr condactCall = new BinaryExpr(condactOutput, BinaryOp.EQUAL, condactExpr);
    assertions.add(new AgreeStatement("", condactCall, null));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) CondactExpr(jkind.lustre.CondactExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) TupleExpr(jkind.lustre.TupleExpr) 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) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException)

Example 10 with NodeCallExpr

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

the class AgreePatternTranslator method getTimeRise.

private AgreeVar getTimeRise(String varName, AgreeNodeBuilder builder, EObject reference) {
    Map<String, AgreeVar> timeRiseMap = builder.build().timeRiseMap;
    if (timeRiseMap.containsKey(varName)) {
        return timeRiseMap.get(varName);
    }
    AgreeVar timeRise = new AgreeVar(varName + RISE_SUFFIX, NamedType.REAL, reference);
    builder.addOutput(timeRise);
    Expr rise = new NodeCallExpr(AgreeRealtimeCalendarBuilder.RISE_NODE_NAME, new IdExpr(varName));
    Expr timeVarExpr = expr("timeRise = (if rise then time else (-1.0 -> pre timeRise))", to("timeRise", timeRise), to("rise", rise), to("time", timeExpr));
    builder.addAssertion(new AgreeStatement(null, timeVarExpr, reference));
    Expr lemmaExpr = expr("timeRise <= time and timeRise >= -1.0", to("timeRise", timeRise), to("time", timeExpr));
    // add this assertion to help with proofs (it should always be true)
    builder.addAssertion(new AgreeStatement("", lemmaExpr, reference));
    builder.addTimeRise(varName, timeRise);
    return timeRise;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

NodeCallExpr (jkind.lustre.NodeCallExpr)21 Expr (jkind.lustre.Expr)20 IdExpr (jkind.lustre.IdExpr)20 BinaryExpr (jkind.lustre.BinaryExpr)17 BoolExpr (jkind.lustre.BoolExpr)16 UnaryExpr (jkind.lustre.UnaryExpr)15 ArrayList (java.util.ArrayList)13 IfThenElseExpr (jkind.lustre.IfThenElseExpr)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)9 IntExpr (jkind.lustre.IntExpr)7 RecordAccessExpr (jkind.lustre.RecordAccessExpr)7 TupleExpr (jkind.lustre.TupleExpr)7 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)6 Node (jkind.lustre.Node)6 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)5 RealExpr (jkind.lustre.RealExpr)5 CondactExpr (jkind.lustre.CondactExpr)4 VarDecl (jkind.lustre.VarDecl)4 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)3 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)3