Search in sources :

Example 6 with NodeBuilder

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

use of jkind.lustre.builders.NodeBuilder in project AGREE by loonwerks.

the class RemovePropertySatisficationRequirements method transform.

// private final static String assumeBaseId = "__ASSUME";
public static SimulationProgram transform(final SimulationProgram program) {
    final SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
    final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(program.getLustreProgram());
    lustreProgramBuilder.clearNodes();
    for (final Node node : program.getLustreProgram().nodes) {
        final NodeBuilder nodeBuilder = new NodeBuilder(new AstMapVisitor() {

            @Override
            public Node visit(final Node n) {
                return super.visit(n);
            }

            @Override
            public Equation visit(final Equation e) {
                // Force the assumption conjunction to be true
                if (e.lhs.size() == 1 && e.lhs.get(0).id.equals(assumptionConjunctionId)) {
                    return new Equation(new IdExpr(assumptionConjunctionId), new BoolExpr(true));
                }
                final Equation result = super.visit(e);
                return result;
            }
        }.visit(node));
        lustreProgramBuilder.addNode(nodeBuilder.build());
    }
    simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
    return simulationProgramBuilder.build();
}
Also used : BoolExpr(jkind.lustre.BoolExpr) AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) Node(jkind.lustre.Node) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Example 8 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder 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 9 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder 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 10 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder in project AGREE by loonwerks.

the class AgreeASTBuilder method caseFnDef.

@Override
public Expr caseFnDef(FnDef fnDef) {
    String nodeName = AgreeUtils.getNodeName(fnDef).replace("::", "__");
    for (Node node : globalNodes) {
        if (node.id.equals(nodeName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(fnDef.getArgs(), null);
    Expr bodyExpr = doSwitch(fnDef.getExpr());
    // EGM: array-backend
    // Type outType = getNamedType(AgreeTypeUtils.getTypeName(fnDef.getType(), typeMap, globalTypes));
    Type outType = symbolTable.updateLustreTypeMap(AgreeTypeSystem.typeDefFromType(fnDef.getType()));
    if (outType != null) {
        VarDecl outVar = new VarDecl("_outvar", outType);
        List<VarDecl> outputs = Collections.singletonList(outVar);
        Equation eq = new Equation(new IdExpr("_outvar"), bodyExpr);
        List<Equation> eqs = Collections.singletonList(eq);
        NodeBuilder builder = new NodeBuilder(nodeName);
        builder.addInputs(inputs);
        builder.addOutputs(outputs);
        builder.addEquations(eqs);
        Node node = builder.build();
        addToNodeList(node);
    }
    return null;
}
Also used : ConnectionType(com.rockwellcollins.atc.agree.analysis.ast.AgreeAADLConnection.ConnectionType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FeatureGroupType(org.osate.aadl2.FeatureGroupType) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) Node(jkind.lustre.Node) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder)

Aggregations

NodeBuilder (jkind.lustre.builders.NodeBuilder)37 Equation (jkind.lustre.Equation)30 VarDecl (jkind.lustre.VarDecl)30 IdExpr (jkind.lustre.IdExpr)29 BinaryExpr (jkind.lustre.BinaryExpr)28 Expr (jkind.lustre.Expr)26 UnaryExpr (jkind.lustre.UnaryExpr)24 BoolExpr (jkind.lustre.BoolExpr)23 NodeCallExpr (jkind.lustre.NodeCallExpr)22 ArrayList (java.util.ArrayList)18 IfThenElseExpr (jkind.lustre.IfThenElseExpr)17 IntExpr (jkind.lustre.IntExpr)15 Node (jkind.lustre.Node)11 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)10 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)10 Program (jkind.lustre.Program)9 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)8 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)7 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)5