Search in sources :

Example 1 with Program

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

the class InlineNodeCalls method transform.

public static SimulationProgram transform(final SimulationProgram program) {
    final Program lustreProgram = program.getLustreProgram();
    final InlineNodeCalls inliner = new InlineNodeCalls(Util.getNodeTable(lustreProgram.nodes));
    Node main = lustreProgram.getMainNode();
    // Build a single node that contains the result of inlining of all node calls
    final NodeBuilder nodeBuilder = new NodeBuilder(main);
    nodeBuilder.clearAssertions();
    nodeBuilder.addAssertions(inliner.visitExprs(main.assertions));
    nodeBuilder.clearEquations();
    nodeBuilder.addEquations(inliner.visitEquationsQueue(main.equations));
    nodeBuilder.addLocals(inliner.newLocals);
    nodeBuilder.addProperties(inliner.newProperties);
    // Build a new program
    final ProgramBuilder programBuilder = new ProgramBuilder(lustreProgram);
    programBuilder.clearNodes();
    programBuilder.addNode(nodeBuilder.build());
    // Build the simulation program
    final SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
    simulationProgramBuilder.setLustreProgram(programBuilder.build());
    return simulationProgramBuilder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 2 with Program

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

the class RemoveProperties 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 SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
    final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
    lustreProgramBuilder.clearNodes();
    final Node node = lustreProgram.getMainNode();
    final NodeBuilder nodeBuilder = new NodeBuilder(node);
    nodeBuilder.clearProperties();
    // Add the new node to the new lustre program
    lustreProgramBuilder.addNode(nodeBuilder.build());
    simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
    return simulationProgramBuilder.build();
}
Also used : SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) Program(jkind.lustre.Program) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 3 with Program

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

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

the class ReplacePreOperator 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 SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
    final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
    lustreProgramBuilder.clearNodes();
    final ReplacePreOperator visitor = new ReplacePreOperator();
    final NodeBuilder nodeBuilder = new NodeBuilder(visitor.visit(lustreProgram).getMainNode());
    // Add additional inputs, returns, expressions, etc
    nodeBuilder.addInputs(visitor.newInputs);
    nodeBuilder.addOutputs(visitor.newOutputs);
    nodeBuilder.addEquations(visitor.newEquations);
    lustreProgramBuilder.addNode(nodeBuilder.build());
    simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
    simulationProgramBuilder.addCarryVariables(visitor.newCarryVariables);
    return simulationProgramBuilder.build();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 5 with Program

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

the class AgreeProgramToSimulationProgram method transform.

public static SimulationProgram transform(final AgreeProgram agreeProgram, final SimulationProgramType type) {
    Objects.requireNonNull(agreeProgram, "agreeProgram must not be null");
    // Build a Component Instance to AgreeNode map
    final Program lustreProgram = LustreAstBuilder.getAssumeGuaranteeLustreProgram(agreeProgram);
    final AgreeRenaming agreeRenaming = new AgreeRenaming();
    final AgreeLayout layout = new AgreeLayout();
    RenamingVisitor.addRenamings(lustreProgram, agreeRenaming, agreeProgram.topNode.compInst, layout);
    SimulationProgram program;
    try {
        final SimulationProgramBuilder builder = new SimulationProgramBuilder(type, agreeProgram.topNode.compInst, lustreProgram, agreeRenaming);
        populateMetadata(builder, agreeProgram, lustreProgram, agreeRenaming, agreeRenaming.getRefMap());
        program = builder.build();
    } catch (final Exception ex) {
        throw new AGREESimulatorException(lustreProgram, ex);
    }
    try {
        program = CreateLocalVariablesForPropertyExpressions.transform(program);
        program = RemovePropertySatisficationRequirements.transform(program);
        program = RemoveCondacts.transform(program);
        program = InlineNodeCalls.transform(program);
        program = ReplaceFollowedByOperator.transform(program);
        program = ReplacePreOperator.transform(program);
        program = CreateSimulationProperties.transform(program);
        program = RemoveProperties.transform(program);
        program = CreateSimulationGuarantee.transform(program);
    } catch (final Exception ex) {
        throw new AGREESimulatorException(program.getLustreProgram(), ex);
    }
    return program;
}
Also used : SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) AgreeProgram(com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram) AgreeRenaming(com.rockwellcollins.atc.agree.analysis.AgreeRenaming) AgreeLayout(com.rockwellcollins.atc.agree.analysis.AgreeLayout) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException) AGREESimulatorException(edu.uah.rsesc.aadlsimulator.agree.sim.AGREESimulatorException)

Aggregations

Program (jkind.lustre.Program)30 AgreeProgram (com.rockwellcollins.atc.agree.analysis.ast.AgreeProgram)18 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)12 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)11 Node (jkind.lustre.Node)11 AgreeASTBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeASTBuilder)9 NodeBuilder (jkind.lustre.builders.NodeBuilder)9 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)8 IdExpr (jkind.lustre.IdExpr)8 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)7 ArrayList (java.util.ArrayList)7 BinaryExpr (jkind.lustre.BinaryExpr)7 Expr (jkind.lustre.Expr)7 SimulationProgramBuilder (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder)6 Equation (jkind.lustre.Equation)6 VarDecl (jkind.lustre.VarDecl)6 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)5 JKindException (jkind.JKindException)5 JKindApi (jkind.api.JKindApi)5 KindApi (jkind.api.KindApi)5