Search in sources :

Example 1 with BinaryExpr

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

the class RemoveCondacts method clockNodeCalls.

private Node clockNodeCalls(Node node, final IdExpr clock) {
    return (Node) node.accept(new AstMapVisitor() {

        @Override
        public Expr visit(NodeCallExpr e) {
            List<Expr> args = new ArrayList<>();
            args.add(clock);
            args.addAll(visitExprs(e.args));
            Node clocked = createClockedNode(e.node);
            return new NodeCallExpr(clocked.id, args);
        }

        @Override
        public Expr visit(CondactExpr e) {
            NodeCallExpr call = (NodeCallExpr) super.visit(e.call);
            List<Expr> args = new ArrayList<>();
            args.add(new BinaryExpr(e.clock.accept(this), BinaryOp.AND, clock));
            args.addAll(e.call.args);
            args.addAll(visitExprs(e.args));
            Node condact = createCondactNode(call.node);
            return new NodeCallExpr(condact.id, args);
        }
    });
}
Also used : AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) CondactExpr(jkind.lustre.CondactExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Node(jkind.lustre.Node) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList)

Example 2 with BinaryExpr

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

the class RemoveCondacts method clockOutputs.

private Node clockOutputs(Node node, IdExpr clock) {
    NodeBuilder builder = new NodeBuilder(node);
    builder.clearOutputs();
    builder.addLocals(node.outputs);
    for (VarDecl output : node.outputs) {
        VarDecl dflt = new VarDecl(output.id + namePrefix + "default", output.type);
        builder.addInput(dflt);
        VarDecl clocked = new VarDecl(output.id + namePrefix + "clocked", output.type);
        builder.addOutput(clocked);
        // clocked = if clock then output else (default -> pre clocked)
        Equation eq = new Equation(new IdExpr(clocked.id), new IfThenElseExpr(clock, new IdExpr(output.id), new BinaryExpr(new IdExpr(dflt.id), BinaryOp.ARROW, new UnaryExpr(UnaryOp.PRE, new IdExpr(clocked.id)))));
        builder.addEquation(eq);
    }
    return builder.build();
}
Also used : 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) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 3 with BinaryExpr

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

the class RemoveCondacts method clockProperties.

private Node clockProperties(Node node, final IdExpr clock) {
    NodeBuilder builder = new NodeBuilder(node);
    builder.clearProperties();
    for (String property : node.properties) {
        VarDecl clocked = new VarDecl(property + namePrefix + "clocked_property", NamedType.BOOL);
        builder.addLocal(clocked);
        // clocked_property = clock => property
        builder.addEquation(new Equation(new IdExpr(clocked.id), new BinaryExpr(clock, BinaryOp.IMPLIES, new IdExpr(property))));
        builder.addProperty(clocked.id);
    }
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 4 with BinaryExpr

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

the class RemoveCondacts method clockArrowsAndPres.

private Node clockArrowsAndPres(Node node, final IdExpr clock) {
    final VarDecl init = new VarDecl(namePrefix + "init", NamedType.BOOL);
    final List<Equation> preEquations = new ArrayList<>();
    final List<VarDecl> preLocals = new ArrayList<>();
    node = (Node) node.accept(new AstMapVisitor() {

        private int counter = 0;

        @Override
        public Expr visit(BinaryExpr e) {
            if (e.op == BinaryOp.ARROW) {
                return new IfThenElseExpr(new IdExpr(init.id), e.left.accept(this), e.right.accept(this));
            } else {
                return super.visit(e);
            }
        }

        @Override
        public Expr visit(UnaryExpr e) {
            if (e.op == UnaryOp.PRE) {
                String state = namePrefix + "state" + counter++;
                Type type = e.expr.accept(typeReconstructor);
                preLocals.add(new VarDecl(state, type));
                // state = if clock then expr else pre state
                preEquations.add(new Equation(new IdExpr(state), new IfThenElseExpr(clock, e.expr.accept(this), new UnaryExpr(UnaryOp.PRE, new IdExpr(state)))));
                return new UnaryExpr(UnaryOp.PRE, new IdExpr(state));
            } else {
                return super.visit(e);
            }
        }
    });
    NodeBuilder builder = new NodeBuilder(node);
    builder.addLocals(preLocals);
    builder.addLocal(init);
    builder.addEquations(preEquations);
    // init = true -> if pre clock then false else pre init
    builder.addEquation(new Equation(new IdExpr(init.id), new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, new IfThenElseExpr(new UnaryExpr(UnaryOp.PRE, clock), new BoolExpr(false), new UnaryExpr(UnaryOp.PRE, new IdExpr(init.id))))));
    return builder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) VarDecl(jkind.lustre.VarDecl)

Example 5 with BinaryExpr

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

the class ReplaceFollowedByOperator method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    if (lustreProgram.nodes.size() != 1) {
        throw new IllegalArgumentException("Only lustre programs with exactly one node are supported");
    }
    final ReplaceFollowedByOperator visitor = new ReplaceFollowedByOperator();
    final NodeBuilder nodeBuilder = new NodeBuilder(visitor.visit(lustreProgram.getMainNode()));
    // Create variable for the step number
    nodeBuilder.addInput(new VarDecl(stepVariableId, NamedType.INT));
    // Add an output for the next step number
    nodeBuilder.addOutput(new VarDecl(nextStepVariableId, NamedType.INT));
    nodeBuilder.addEquation(new Equation(new IdExpr(nextStepVariableId), new BinaryExpr(new IdExpr(stepVariableId), BinaryOp.PLUS, new IntExpr(1))));
    // Create the new lustre program using the new node
    final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
    lustreProgramBuilder.clearNodes();
    lustreProgramBuilder.addNode(nodeBuilder.build());
    // Create the simulation program
    final SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
    final Expr stepVariableExpr = new IdExpr(stepVariableId);
    // Ensure that the initial step is greater than the first step when simulating inductive counterexamples
    final int initialStepValue = program.getType().isInductive() ? firstStepValue + 1 : firstStepValue;
    simulationProgramBuilder.addInitialConstraint(new BinaryExpr(stepVariableExpr, BinaryOp.EQUAL, new IntExpr(initialStepValue)));
    simulationProgramBuilder.addCarryVariable(new CarryVariable(stepVariableExpr, new IdExpr(nextStepVariableId)));
    simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
    return simulationProgramBuilder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) CarryVariable(edu.uah.rsesc.aadlsimulator.agree.CarryVariable) NodeBuilder(jkind.lustre.builders.NodeBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) IntExpr(jkind.lustre.IntExpr)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)86 IdExpr (jkind.lustre.IdExpr)80 Expr (jkind.lustre.Expr)74 BoolExpr (jkind.lustre.BoolExpr)71 NodeCallExpr (jkind.lustre.NodeCallExpr)62 UnaryExpr (jkind.lustre.UnaryExpr)61 IfThenElseExpr (jkind.lustre.IfThenElseExpr)48 IntExpr (jkind.lustre.IntExpr)48 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)31 ArrayList (java.util.ArrayList)29 RecordAccessExpr (jkind.lustre.RecordAccessExpr)29 RealExpr (jkind.lustre.RealExpr)27 Equation (jkind.lustre.Equation)26 VarDecl (jkind.lustre.VarDecl)26 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)25 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)23 NodeBuilder (jkind.lustre.builders.NodeBuilder)22 TupleExpr (jkind.lustre.TupleExpr)20 ArrayExpr (jkind.lustre.ArrayExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11