use of jkind.lustre.Equation in project AGREE by loonwerks.
the class LustreAstBuilder method getHist.
protected static Equation getHist(IdExpr histId, Expr expr) {
Expr preHist = new UnaryExpr(UnaryOp.PRE, histId);
Expr preAndNow = LustreExprFactory.makeANDExpr(preHist, expr);
return new Equation(histId, new BinaryExpr(expr, BinaryOp.ARROW, preAndNow));
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class LustreContractAstBuilder method getContractLustreProgram.
public static Program getContractLustreProgram(AgreeProgram agreeProgram) {
nodes = new ArrayList<>();
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
AgreeNode flatNode = flattenAgreeNodeKindContract(agreeProgram.topNode, "_TOP__");
List<Expr> assertions = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> outputs = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<String> properties = new ArrayList<>();
List<Expr> requires = new ArrayList<>();
List<Expr> ensures = new ArrayList<>();
for (AgreeStatement assertion : flatNode.assertions) {
assertions.add(assertion.expr);
}
for (AgreeStatement assumption : flatNode.assumptions) {
requires.add(assumption.expr);
}
for (AgreeStatement guarantee : flatNode.lemmas) {
ensures.add(guarantee.expr);
}
for (AgreeStatement guarantee : flatNode.guarantees) {
ensures.add(guarantee.expr);
}
for (AgreeVar var : flatNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : flatNode.outputs) {
outputs.add(var);
}
for (AgreeVar var : flatNode.outputs) {
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
throw new AgreeException("This shouldn't happen");
}
}
Contract contract = new Contract(requires, ensures);
NodeBuilder builder = new NodeBuilder("_TOP");
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.setContract(contract);
Node main = builder.build();
nodes.addAll(agreeProgram.globalLustreNodes);
nodes.add(main);
Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).setMain(main.id).build();
return program;
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class AgreeRealtimeCalendarBuilder method getFallNode.
private static Node getFallNode() {
NodeBuilder builder = new NodeBuilder(FALL_NODE_NAME);
builder.addInput(new VarDecl("input", NamedType.BOOL));
builder.addOutput(new VarDecl("output", NamedType.BOOL));
IdExpr inputId = new IdExpr("input");
IdExpr outputId = new IdExpr("output");
Expr outputExpr = new UnaryExpr(UnaryOp.PRE, inputId);
Expr notInput = new UnaryExpr(UnaryOp.NOT, inputId);
outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, notInput);
outputExpr = new BinaryExpr(notInput, BinaryOp.ARROW, outputExpr);
builder.addEquation(new Equation(outputId, outputExpr));
return builder.build();
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class GenerateUfcObligationsVisitor method constructNewNode.
/**
* Method for constructing new programs using the UFC obligations.
*/
private Node constructNewNode(Node existing, ObligationSet obs) {
List<VarDecl> locals = new ArrayList<>(existing.locals);
List<Equation> equations = new ArrayList<>(existing.equations);
// List<String> properties = new ArrayList<>(existing.properties);
// Change: MWW 5/6: Don't really want existing properties here.
List<String> properties = new ArrayList<>();
/* writing the TCG obligations back as trap properties by negating them... */
for (int i = 0; i < obs.positivePolarity.size(); i++) {
String varName = TRAP_PROP_PREFIX + i;
Obligation ob = obs.positivePolarity.get(i);
locals.add(new VarDecl(varName, NamedType.BOOL));
equations.add(new Equation(new IdExpr(varName), new UnaryExpr(UnaryOp.NOT, ob.getObligationExpr())));
properties.add(varName);
// renaming information
if (renaming != null) {
renaming.addRenaming(varName, ob.getEqAssignId(), ob.getTestedCondition().toString(), new HashSet<Obligation>(Arrays.asList(ob)));
}
System.out.println("Renaming: mapping " + varName + " --> " + ob.getEqAssignId());
}
Node newNode = new Node(existing.id, existing.inputs, existing.outputs, locals, equations, properties, existing.assertions, null, null, new ArrayList<String>());
return newNode;
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class GenerateUfcObligationsVisitor method visit.
@Override
public ObligationSet visit(Node node) {
typeReconstructor.setNodeContext(node);
if (node.id.equals(initialProgram.main) || !this.generateForMainNodeObligationsOnly) {
typeReconstructor.setNodeContext(node);
currentNode = node;
ObligationSet allExprs = new ObligationSet();
for (Equation equation : node.equations) {
allExprs.addAll(equation.accept(this));
}
for (Expr assertion : node.assertions) {
allExprs.addAll(assertion(assertion));
}
if (!node.properties.isEmpty()) {
for (String property : node.properties) {
allExprs.addAll(property(property));
}
}
obligations.put(node, allExprs);
currentNode = null;
} else {
obligations.put(node, new ObligationSet());
}
return null;
}
Aggregations