Search in sources :

Example 6 with Expr

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

use of jkind.lustre.Expr 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)

Example 8 with Expr

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

the class FrameAssertionHelper method addNextFrameAssertions.

/**
 * Adds the frame specific assertions for the next frame to an assertion collection. Does not add assertions related to property enablement.
 * @param program
 * @param lastResults
 * @param assertions is the collection to which assertions will be added.
 */
public static void addNextFrameAssertions(final SimulationProgram program, final SimulationFrameResults lastResults, final Collection<Expr> assertions) {
    if (lastResults == null) {
        for (final Expr c : program.getInitialConstraints()) {
            assertions.add(c);
        }
    } else {
        for (final CarryVariable cv : program.getCarryVariables()) {
            final Value value = lastResults.getValue(cv.getOutputVariableExpression().toString());
            if (value == null) {
                throw new RuntimeException("Unable to get value for: " + cv.getOutputVariableExpression().toString());
            }
            final Expr valueExpression = valueToExpr(value);
            assertions.add(new BinaryExpr(cv.getInputVariableExpression(), BinaryOp.EQUAL, valueExpression));
        }
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealValue(jkind.lustre.values.RealValue) TupleValue(jkind.lustre.values.TupleValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) CarryVariable(edu.uah.rsesc.aadlsimulator.agree.CarryVariable)

Example 9 with Expr

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

the class CreateLocalVariablesForPropertyExpressions method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    final SimulationProgramBuilder builder = new SimulationProgramBuilder(program);
    // Build mappings between Agree Statements, expressions, and Agree Nodes
    final Map<Expr, AgreeStatement> exprToStatementMap = new HashMap<>();
    final Map<AgreeStatement, AgreeNode> agreeStatementToAgreeNodeMap = new HashMap<>();
    for (final AgreeNode agreeNode : program.getAllAgreeNodes()) {
        for (final AgreeStatement statement : agreeNode.assertions) {
            if (statement.reference instanceof AssertStatement) {
                exprToStatementMap.put(statement.expr, statement);
                agreeStatementToAgreeNodeMap.put(statement, agreeNode);
            }
        }
        for (final AgreeStatement statement : agreeNode.assumptions) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
        for (final AgreeStatement statement : agreeNode.guarantees) {
            exprToStatementMap.put(statement.expr, statement);
            agreeStatementToAgreeNodeMap.put(statement, agreeNode);
        }
    }
    // Create local variables for assert statements, assumptions, and guarantees
    final ProgramBuilder lustreBuilder = new ProgramBuilder(lustreProgram).clearNodes();
    for (final Node lustreNode : lustreProgram.nodes) {
        lustreBuilder.addNode(VariableCreator.transform(lustreNode, exprToStatementMap, agreeStatementToAgreeNodeMap));
    }
    builder.setLustreProgram(lustreBuilder.build());
    return builder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) CondactExpr(jkind.lustre.CondactExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) RecordExpr(jkind.lustre.RecordExpr) HashMap(java.util.HashMap) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AgreeNode(com.rockwellcollins.atc.agree.analysis.ast.AgreeNode) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AssertStatement(com.rockwellcollins.atc.agree.agree.AssertStatement)

Example 10 with Expr

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

the class AGREESimulationState method createEvaluator.

private Evaluator createEvaluator(final Collection<Expr> constraints, final Set<SimulationProperty> disabledProperties) {
    try {
        final SimulationFrameResults lastFrameResults = frameInfos.size() == 0 ? null : frameInfos.get(frameInfos.size() - 1).getFrameResults();
        final List<Expr> assertions = new ArrayList<Expr>();
        FrameAssertionHelper.addNextFrameAssertions(simulationProgram, lastFrameResults, assertions);
        assertions.addAll(constraints);
        // Add assertions for property enablement variables
        for (final SimulationProperty simProp : simulationProgram.getSimulationProperties()) {
            if (simProp.getEnablementVariableId() != null) {
                assertions.add(new BinaryExpr(new IdExpr(simProp.getEnablementVariableId()), BinaryOp.EQUAL, new BoolExpr(disabledProperties.contains(simProp) ? false : true)));
            }
        }
        // Create the new evaluator
        return new Evaluator(baseEvaluator, assertions);
    } catch (EvaluationException ex) {
        return null;
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) SimulationFrameResults(edu.uah.rsesc.aadlsimulator.agree.sim.SimulationFrameResults) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) Expr(jkind.lustre.Expr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) EvaluationException(edu.uah.rsesc.aadlsimulator.agree.eval.EvaluationException) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator)

Aggregations

Expr (jkind.lustre.Expr)156 IdExpr (jkind.lustre.IdExpr)150 BinaryExpr (jkind.lustre.BinaryExpr)140 NodeCallExpr (jkind.lustre.NodeCallExpr)132 BoolExpr (jkind.lustre.BoolExpr)129 UnaryExpr (jkind.lustre.UnaryExpr)119 IfThenElseExpr (jkind.lustre.IfThenElseExpr)106 IntExpr (jkind.lustre.IntExpr)95 RecordAccessExpr (jkind.lustre.RecordAccessExpr)79 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)67 RealExpr (jkind.lustre.RealExpr)67 TupleExpr (jkind.lustre.TupleExpr)64 ArrayList (java.util.ArrayList)61 ArrayExpr (jkind.lustre.ArrayExpr)50 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)49 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)45 CastExpr (jkind.lustre.CastExpr)45 Equation (jkind.lustre.Equation)45 FunctionCallExpr (jkind.lustre.FunctionCallExpr)44 VarDecl (jkind.lustre.VarDecl)36