Search in sources :

Example 26 with UnaryExpr

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

the class LustreAstBuilder method getClockExpr.

protected static Expr getClockExpr(AgreeNode agreeNode, AgreeNode subNode) {
    IdExpr clockId = new IdExpr(subNode.clockVar.id);
    switch(agreeNode.timing) {
        case SYNC:
            return new BoolExpr(true);
        case ASYNC:
            return clockId;
        case LATCHED:
            Expr preClock = new UnaryExpr(UnaryOp.PRE, clockId);
            Expr notClock = new UnaryExpr(UnaryOp.NOT, clockId);
            Expr andExpr = new BinaryExpr(preClock, BinaryOp.AND, notClock);
            Expr clockExpr = new BinaryExpr(new BoolExpr(false), BinaryOp.ARROW, andExpr);
            return clockExpr;
        default:
            throw new AgreeException("unhandled timing type: '" + agreeNode.timing + "");
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) 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) BinaryExpr(jkind.lustre.BinaryExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) UnaryExpr(jkind.lustre.UnaryExpr)

Example 27 with UnaryExpr

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

the class LustreAstBuilder method getConsistencyLustreNode.

protected static Node getConsistencyLustreNode(AgreeNode agreeNode, boolean withAssertions) {
    final String stuffPrefix = "__STUFF";
    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<>();
    Expr stuffConj = new BoolExpr(true);
    int stuffAssumptionIndex = 0;
    for (AgreeStatement assumption : agreeNode.assumptions) {
        AgreeVar stuffAssumptionVar = new AgreeVar(stuffPrefix + assumeSuffix + stuffAssumptionIndex++, NamedType.BOOL, assumption.reference, agreeNode.compInst, null);
        locals.add(stuffAssumptionVar);
        ivcs.add(stuffAssumptionVar.id);
        IdExpr stuffAssumptionId = new IdExpr(stuffAssumptionVar.id);
        equations.add(new Equation(stuffAssumptionId, assumption.expr));
        stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssumptionId);
    }
    int stuffGuaranteeIndex = 0;
    for (AgreeStatement guarantee : agreeNode.guarantees) {
        AgreeVar stuffGuaranteeVar = new AgreeVar(stuffPrefix + guarSuffix + stuffGuaranteeIndex++, NamedType.BOOL, guarantee.reference, agreeNode.compInst, null);
        locals.add(stuffGuaranteeVar);
        ivcs.add(stuffGuaranteeVar.id);
        IdExpr stuffGuaranteeId = new IdExpr(stuffGuaranteeVar.id);
        equations.add(new Equation(stuffGuaranteeId, guarantee.expr));
        stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffGuaranteeId);
    }
    if (withAssertions) {
        equations.addAll(agreeNode.localEquations);
    } else {
        for (AgreeEquation eq : agreeNode.localEquations) {
            if (AgreeUtils.referenceIsInContract(eq.reference, agreeNode.compInst)) {
                equations.add(eq);
            }
        }
    }
    // TODO should we include lemmas in the consistency check?
    // for(AgreeStatement guarantee : agreeNode.lemmas){
    // histConj = new BinaryExpr(histConj, BinaryOp.AND, guarantee.expr);
    // }
    int stuffAssertionIndex = 0;
    if (withAssertions) {
        for (AgreeStatement assertion : agreeNode.assertions) {
            AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
            locals.add(stuffAssertionVar);
            IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
            equations.add(new Equation(stuffAssertionId, assertion.expr));
            stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
        }
    } else {
        // equations  and type equations. That would clear this up.
        for (AgreeStatement assertion : agreeNode.assertions) {
            if (AgreeUtils.referenceIsInContract(assertion.reference, agreeNode.compInst)) {
                AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
                locals.add(stuffAssertionVar);
                IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
                equations.add(new Equation(stuffAssertionId, assertion.expr));
                stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
            }
        }
    }
    // add realtime constraints
    Set<AgreeVar> eventTimes = new HashSet<>();
    if (withAssertions) {
        eventTimes.addAll(agreeNode.eventTimes);
    } else {
        for (AgreeVar eventVar : agreeNode.eventTimes) {
            if (AgreeUtils.referenceIsInContract(eventVar.reference, agreeNode.compInst)) {
                eventTimes.add(eventVar);
            }
        }
    }
    assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(eventTimes));
    for (AgreeVar var : agreeNode.inputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.outputs) {
        inputs.add(var);
    }
    for (AgreeVar var : agreeNode.locals) {
        if (withAssertions) {
            locals.add(var);
        } else {
            if (AgreeUtils.referenceIsInContract(var.reference, agreeNode.compInst)) {
                locals.add(var);
            }
        }
    }
    EObject classifier = agreeNode.compInst.getComponentClassifier();
    AgreeVar countVar = new AgreeVar("__COUNT", NamedType.INT, null, null, null);
    AgreeVar stuffVar = new AgreeVar(stuffPrefix, NamedType.BOOL, null, null, null);
    AgreeVar histVar = new AgreeVar("__HIST", NamedType.BOOL, null, null, null);
    AgreeVar propVar = new AgreeVar("__PROP", NamedType.BOOL, classifier, agreeNode.compInst, null);
    locals.add(countVar);
    locals.add(stuffVar);
    locals.add(histVar);
    locals.add(propVar);
    IdExpr countId = new IdExpr(countVar.id);
    IdExpr stuffId = new IdExpr(stuffVar.id);
    IdExpr histId = new IdExpr(histVar.id);
    IdExpr propId = new IdExpr(propVar.id);
    equations.add(new Equation(stuffId, stuffConj));
    Expr histExpr = new UnaryExpr(UnaryOp.PRE, histId);
    histExpr = LustreExprFactory.makeANDExpr(histExpr, stuffId);
    histExpr = new BinaryExpr(stuffId, BinaryOp.ARROW, histExpr);
    equations.add(new Equation(histId, histExpr));
    Expr countExpr = new UnaryExpr(UnaryOp.PRE, countId);
    countExpr = new BinaryExpr(countExpr, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
    countExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, countExpr);
    equations.add(new Equation(countId, countExpr));
    IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
    int consistDetph = prefs.getInt(PreferenceConstants.PREF_CONSIST_DEPTH);
    Expr propExpr = new BinaryExpr(countId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(consistDetph)));
    propExpr = new BinaryExpr(propExpr, BinaryOp.AND, histId);
    equations.add(new Equation(propId, new UnaryExpr(UnaryOp.NOT, propExpr)));
    properties.add(propId.id);
    NodeBuilder builder = new NodeBuilder("consistency");
    builder.addInputs(inputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    builder.addAssertions(assertions);
    builder.addIvcs(ivcs);
    Node node = builder.build();
    return node;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Node(jkind.lustre.Node) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) 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) EObject(org.eclipse.emf.ecore.EObject) IntExpr(jkind.lustre.IntExpr) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) HashSet(java.util.HashSet)

Example 28 with UnaryExpr

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

the class LustreAstBuilder method getHistNode.

protected static Node getHistNode() {
    NodeBuilder builder = new NodeBuilder(historyNodeName);
    builder.addInput(new VarDecl("input", NamedType.BOOL));
    builder.addOutput(new VarDecl("hist", NamedType.BOOL));
    IdExpr histId = new IdExpr("hist");
    IdExpr inputId = new IdExpr("input");
    Expr preHist = new UnaryExpr(UnaryOp.PRE, histId);
    Expr histExpr = new BinaryExpr(preHist, BinaryOp.AND, inputId);
    histExpr = new BinaryExpr(inputId, BinaryOp.ARROW, histExpr);
    builder.addEquation(new Equation(histId, histExpr));
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) 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) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) NodeBuilder(jkind.lustre.builders.NodeBuilder) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr)

Example 29 with UnaryExpr

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

the class AgreeRealtimeCalendarBuilder method getRiseNode.

private static Node getRiseNode() {
    NodeBuilder builder = new NodeBuilder(RISE_NODE_NAME);
    builder.addInput(new VarDecl("input", NamedType.BOOL));
    builder.addOutput(new VarDecl("output", NamedType.BOOL));
    IdExpr inputId = new IdExpr("input");
    IdExpr outputId = new IdExpr("output");
    Expr outputExpr = new UnaryExpr(UnaryOp.NOT, inputId);
    outputExpr = new UnaryExpr(UnaryOp.PRE, outputExpr);
    outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, inputId);
    outputExpr = new BinaryExpr(inputId, BinaryOp.ARROW, outputExpr);
    builder.addEquation(new Equation(outputId, outputExpr));
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr)

Example 30 with UnaryExpr

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

the class SimulationFrameResults method eval.

private Value eval(final Expr lustreExpr) {
    if (lustreExpr instanceof BoolExpr) {
        return BooleanValue.fromBoolean(((BoolExpr) lustreExpr).value);
    } else if (lustreExpr instanceof IntExpr) {
        return new IntegerValue(((IntExpr) lustreExpr).value);
    } else if (lustreExpr instanceof RealExpr) {
        final RealExpr realExpr = (RealExpr) lustreExpr;
        return new RealValue(BigFraction.valueOf(realExpr.value));
    } else if (lustreExpr instanceof BinaryExpr) {
        final BinaryExpr binaryExpr = (BinaryExpr) lustreExpr;
        final Value leftValue = eval(binaryExpr.left);
        final Value rightValue = eval(binaryExpr.right);
        if (leftValue == null || rightValue == null) {
            return null;
        }
        return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
    } else if (lustreExpr instanceof UnaryExpr) {
        final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
        final Value operandValue = eval(unaryExpr.expr);
        if (operandValue == null) {
            return null;
        }
        return operandValue.applyUnaryOp(unaryExpr.op);
    }
    return null;
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IntegerValue(jkind.lustre.values.IntegerValue) BinaryExpr(jkind.lustre.BinaryExpr) RealValue(jkind.lustre.values.RealValue) IntegerValue(jkind.lustre.values.IntegerValue) Value(jkind.lustre.values.Value) BooleanValue(jkind.lustre.values.BooleanValue) IntExpr(jkind.lustre.IntExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr)

Aggregations

UnaryExpr (jkind.lustre.UnaryExpr)36 BinaryExpr (jkind.lustre.BinaryExpr)34 IdExpr (jkind.lustre.IdExpr)34 Expr (jkind.lustre.Expr)32 BoolExpr (jkind.lustre.BoolExpr)29 NodeCallExpr (jkind.lustre.NodeCallExpr)29 IfThenElseExpr (jkind.lustre.IfThenElseExpr)24 Equation (jkind.lustre.Equation)21 IntExpr (jkind.lustre.IntExpr)18 VarDecl (jkind.lustre.VarDecl)17 NodeBuilder (jkind.lustre.builders.NodeBuilder)15 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 ArrayList (java.util.ArrayList)11 RealExpr (jkind.lustre.RealExpr)11 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)6 Node (jkind.lustre.Node)6 RecordAccessExpr (jkind.lustre.RecordAccessExpr)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)4 CondactExpr (jkind.lustre.CondactExpr)4