use of jkind.lustre.Contract 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.Contract in project AGREE by loonwerks.
the class LustreContractAstBuilder method getLustreNode.
protected static Node getLustreNode(AgreeNode agreeNode, String nodePrefix) {
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> outputs = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<Expr> assertions = new ArrayList<>();
List<Expr> requires = new ArrayList<>();
List<Expr> ensures = new ArrayList<>();
for (AgreeStatement statement : agreeNode.assumptions) {
requires.add(statement.expr);
}
for (AgreeStatement statement : agreeNode.lemmas) {
ensures.add(statement.expr);
}
for (AgreeStatement statement : agreeNode.guarantees) {
ensures.add(statement.expr);
}
for (AgreeStatement statement : agreeNode.assertions) {
assertions.add(statement.expr);
if (AgreeUtils.referenceIsInContract(statement.reference, agreeNode.compInst)) {
ensures.add(statement.expr);
}
}
// gather the remaining inputs
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
outputs.add(var);
}
// Contract contract = new Contract(nodePrefix + agreeNode.id, requires, ensures);
Contract contract = new Contract(requires, ensures);
NodeBuilder builder = new NodeBuilder(nodePrefix + agreeNode.id);
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addAssertions(assertions);
builder.setContract(contract);
return builder.build();
}
Aggregations