Search in sources :

Example 41 with IdExpr

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

the class LustreContractAstBuilder method addInitConstraint.

protected static void addInitConstraint(AgreeNode agreeNode, List<AgreeVar> outputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
    if (agreeNode.timing != TimingModel.SYNC) {
        String tickedName = subAgreeNode.id + "___TICKED";
        outputs.add(new AgreeVar(tickedName, NamedType.BOOL, null, agreeNode.compInst, null));
        Expr tickedId = new IdExpr(tickedName);
        Expr preTicked = new UnaryExpr(UnaryOp.PRE, tickedId);
        Expr tickedOrPre = new BinaryExpr(clockExpr, BinaryOp.OR, preTicked);
        Expr initOrTicked = new BinaryExpr(clockExpr, BinaryOp.ARROW, tickedOrPre);
        Expr tickedEq = new BinaryExpr(tickedId, BinaryOp.EQUAL, initOrTicked);
        assertions.add(new AgreeStatement("", tickedEq, null));
        // we have two re-write the ids in the initial expressions
        IdRewriter rewriter = id -> new IdExpr(prefix + id.id);
        Expr newInit = subAgreeNode.initialConstraint.accept(new IdRewriteVisitor(rewriter));
        Expr initConstr = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, newInit);
        assertions.add(new AgreeStatement("", initConstr, null));
        // we also need to add hold expressions for the assumptions and
        // lemmas
        Expr assumeLemmaTrue = new BoolExpr(true);
        for (VarDecl lustreVar : lustreNode.inputs) {
            AgreeVar var = (AgreeVar) lustreVar;
            if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
                assumeLemmaTrue = new BinaryExpr(assumeLemmaTrue, BinaryOp.AND, new IdExpr(prefix + var.id));
            }
        }
        assumeLemmaTrue = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, assumeLemmaTrue);
        assertions.add(new AgreeStatement("", assumeLemmaTrue, null));
    }
}
Also used : IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) Program(jkind.lustre.Program) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeBuilder(jkind.lustre.builders.NodeBuilder) CondactExpr(jkind.lustre.CondactExpr) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) Expr(jkind.lustre.Expr) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BinaryOp(jkind.lustre.BinaryOp) UnaryOp(jkind.lustre.UnaryOp) IdExpr(jkind.lustre.IdExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) Contract(jkind.lustre.Contract) NamedType(jkind.lustre.NamedType) TimingModel(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode.TimingModel) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) Equation(jkind.lustre.Equation) AgreeNodeBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) Node(jkind.lustre.Node) List(java.util.List) AgreeUtils(com.rockwellcollins.atc.agree.analysis.AgreeUtils) NodeCallExpr(jkind.lustre.NodeCallExpr) VarDecl(jkind.lustre.VarDecl) TypeDef(jkind.lustre.TypeDef) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeASTBuilder(com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder) BoolExpr(jkind.lustre.BoolExpr) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) AssumeStatement(com.rockwellcollins.atc.agree.agree.AssumeStatement) IdRewriteVisitor(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriteVisitor) BinaryExpr(jkind.lustre.BinaryExpr) IdRewriter(com.rockwellcollins.atc.agree.analysis.lustre.visitors.IdRewriter) UnaryExpr(jkind.lustre.UnaryExpr) LemmaStatement(com.rockwellcollins.atc.agree.agree.LemmaStatement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) 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)

Example 42 with IdExpr

use of jkind.lustre.IdExpr 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 43 with IdExpr

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

the class AgreePatternBuilder method caseSporadicStatement.

@Override
public AgreeStatement caseSporadicStatement(SporadicStatement object) {
    IdExpr event = (IdExpr) builder.doSwitch(object.getEvent());
    com.rockwellcollins.atc.agree.agree.Expr jitter = object.getJitter();
    Expr jitterExpr = null;
    if (jitter != null) {
        jitterExpr = builder.doSwitch(jitter);
    }
    Expr iat = builder.doSwitch(object.getIat());
    return new AgreeSporadicPattern(str, ref, event, iat, jitterExpr);
}
Also used : IdExpr(jkind.lustre.IdExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr)

Example 44 with IdExpr

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

the class AgreePatternBuilder method caseWhenOccursStatment.

@Override
public AgreeStatement caseWhenOccursStatment(WhenOccursStatment object) {
    IdExpr condition = (IdExpr) builder.doSwitch(object.getCondition());
    IdExpr effect = (IdExpr) builder.doSwitch(object.getEvent());
    Expr timesExpr = builder.doSwitch(object.getTimes());
    boolean exclusive = object.getExcl() != null;
    if (!(timesExpr instanceof IntExpr)) {
        throw new AgreeException("Expected an integer literal in 'When Occurs' pattern");
    }
    BigInteger times = ((IntExpr) timesExpr).value;
    AgreePatternInterval interval = getIntervalType(object.getInterval());
    return new AgreeTimesPattern(str, ref, exclusive, condition, effect, interval, null, TriggerType.CONDITION, TriggerType.CONDITION, times, null);
}
Also used : IdExpr(jkind.lustre.IdExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BigInteger(java.math.BigInteger) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IntExpr(jkind.lustre.IntExpr)

Example 45 with IdExpr

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

the class AgreePatternBuilder method caseWheneverOccursStatement.

@Override
public AgreeStatement caseWheneverOccursStatement(WheneverOccursStatement object) {
    IdExpr cause = (IdExpr) builder.doSwitch(object.getCause());
    IdExpr effect = (IdExpr) builder.doSwitch(object.getEffect());
    boolean exclusive = object.getExcl() != null;
    AgreePatternInterval effectInterval = getIntervalType(object.getInterval());
    return new AgreeCauseEffectPattern(str, ref, exclusive, cause, effect, null, effectInterval, TriggerType.EVENT, TriggerType.EVENT);
}
Also used : IdExpr(jkind.lustre.IdExpr)

Aggregations

IdExpr (jkind.lustre.IdExpr)133 BinaryExpr (jkind.lustre.BinaryExpr)96 Expr (jkind.lustre.Expr)95 BoolExpr (jkind.lustre.BoolExpr)82 NodeCallExpr (jkind.lustre.NodeCallExpr)81 UnaryExpr (jkind.lustre.UnaryExpr)75 IfThenElseExpr (jkind.lustre.IfThenElseExpr)64 IntExpr (jkind.lustre.IntExpr)53 ArrayList (java.util.ArrayList)52 Equation (jkind.lustre.Equation)46 VarDecl (jkind.lustre.VarDecl)41 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)38 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)37 RecordAccessExpr (jkind.lustre.RecordAccessExpr)37 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)29 RealExpr (jkind.lustre.RealExpr)29 NodeBuilder (jkind.lustre.builders.NodeBuilder)29 TupleExpr (jkind.lustre.TupleExpr)25 ArrayExpr (jkind.lustre.ArrayExpr)14 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)13