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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations