use of jkind.lustre.TypeDef in project AGREE by loonwerks.
the class AgreeASTPrettyprinter method visit.
@Override
public Void visit(AgreeProgram program) {
if (program.containsRealTimePatterns) {
write("-- Program contains real-time patterns");
newline();
newline();
}
write("-- Program top-level node is: " + program.topNode.id);
newline();
newline();
if (!program.globalTypes.isEmpty()) {
for (Type type : program.globalTypes) {
String name = "dummy";
if (type instanceof RecordType) {
name = ((RecordType) type).id;
} else if (type instanceof EnumType) {
name = ((EnumType) type).id;
}
TypeDef typeDef = new TypeDef(Location.NULL, name, type);
typeDef.accept(this);
newline();
}
newline();
}
if (!program.globalLustreNodes.isEmpty()) {
Iterator<Node> iterator = program.globalLustreNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
if (!program.uninterpretedFunctions.isEmpty()) {
Iterator<Function> iterator = program.uninterpretedFunctions.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
}
Iterator<AgreeNode> iterator = program.agreeNodes.iterator();
while (iterator.hasNext()) {
iterator.next().accept(this);
newline();
if (iterator.hasNext()) {
newline();
}
}
newline();
return null;
}
use of jkind.lustre.TypeDef in project AGREE by loonwerks.
the class AgreeNodeToLustreContract method translate.
public static Node translate(AgreeNode agreeNode, AgreeProgram agreeProgram) {
List<Node> nodes = new ArrayList<>();
nodes.addAll(agreeProgram.globalLustreNodes);
// this node needs to be the last in the list
// so that it is set as the main node in the program
nodes.add(translateNode(agreeNode));
List<TypeDef> types = new ArrayList<>();
for (Type type : agreeProgram.globalTypes) {
RecordType recType = (RecordType) type;
types.add(new TypeDef(recType.id, type));
}
Program program = new ProgramBuilder().addTypes(types).addNodes(nodes).build();
program = InlineNodeCalls.program(program);
program = FlattenPres.program(program);
Node main = DistributePres.node(program.getMainNode());
main = OrderEquations.node(main);
return main;
}
use of jkind.lustre.TypeDef in project AGREE by loonwerks.
the class LustreAstBuilder method getRealizabilityLustreProgram.
// private static AgreeProgram translate(AgreeProgram program){
// return AgreeInlineLatchedConnections.translate(program);
// }
public static Program getRealizabilityLustreProgram(AgreeProgram agreeProgram) {
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
List<Expr> assertions = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<VarDecl> inputs = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<String> properties = new ArrayList<>();
AgreeNode topNode = agreeProgram.topNode;
for (AgreeStatement assumption : topNode.assumptions) {
assertions.add(assumption.expr);
}
int i = 0;
for (AgreeStatement guarantee : topNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, topNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
List<String> inputStrs = new ArrayList<>();
for (AgreeVar var : topNode.inputs) {
inputs.add(var);
inputStrs.add(var.id);
}
for (AgreeVar var : topNode.outputs) {
inputs.add(var);
}
// and type equations. This would clear this up
for (AgreeStatement statement : topNode.assertions) {
if (AgreeUtils.referenceIsInContract(statement, topNode.compInst)) {
// this is a strange hack we have to do. we have to make
// equation and property
// statements not assertions. They should all be binary
// expressions with an
// equals operator. We will need to removing their corresponding
// variable
// from the inputs and add them to the local variables
BinaryExpr binExpr;
IdExpr varId;
try {
binExpr = (BinaryExpr) statement.expr;
varId = (IdExpr) binExpr.left;
} catch (ClassCastException e) {
// some equation variables are assertions for
// subrange types. do not translate these to
// local equations. Just add them to assertions
assertions.add(statement.expr);
continue;
}
boolean found = false;
int index;
for (index = 0; index < inputs.size(); index++) {
VarDecl var = inputs.get(index);
if (var.id.equals(varId.id)) {
found = true;
break;
}
}
if (!found || binExpr.op != BinaryOp.EQUAL) {
throw new AgreeException("Something went very wrong with the lustre generation in the realizability analysis");
}
locals.add(inputs.remove(index));
equations.add(new Equation(varId, binExpr.right));
}
}
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.setRealizabilityInputs(inputStrs);
Node main = builder.build();
List<Node> nodes = new ArrayList<>();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
List<Function> uFunctions = new ArrayList<>();
uFunctions.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uFunctions).addNodes(nodes).setMain(main.id).build();
return program;
}
use of jkind.lustre.TypeDef 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.TypeDef in project AGREE by loonwerks.
the class LustreAstBuilder method getAssumeGuaranteeLustreProgram.
public static Program getAssumeGuaranteeLustreProgram(AgreeProgram agreeProgram) {
nodes = new ArrayList<>();
uninterpretedFcns = new ArrayList<>();
AgreeNode flatNode = flattenAgreeNode(agreeProgram, agreeProgram.topNode, "_TOP__");
List<Expr> assertions = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<VarDecl> inputs = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<String> properties = new ArrayList<>();
List<String> ivcs = new ArrayList<>();
int j = 0;
for (AgreeStatement assumption : flatNode.assumptions) {
String assumName = assumeSuffix + j++;
locals.add(new AgreeVar(assumName, NamedType.BOOL, assumption.reference, flatNode.compInst, null));
IdExpr assumId = new IdExpr(assumName);
equations.add(new Equation(assumId, assumption.expr));
assertions.add(assumId);
// Else add the defined ivc list.
if (flatNode.getFaultTreeFlag() == false) {
ivcs.add(assumId.id);
}
}
for (AgreeStatement assertion : flatNode.assertions) {
assertions.add(assertion.expr);
}
// add assumption and monolithic lemmas first (helps with proving)
for (AgreeVar var : flatNode.outputs) {
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
properties.add(var.id);
}
inputs.add(var);
}
// add property that all assumption history is true
Expr assumeConj = new BoolExpr(true);
for (AgreeNode subNode : agreeProgram.topNode.subNodes) {
assumeConj = new BinaryExpr(new IdExpr(subNode.id + "__" + assumeHistSufix), BinaryOp.AND, assumeConj);
}
AgreeVar assumeHistVar = new AgreeVar(assumeHistSufix, NamedType.BOOL, agreeProgram.topNode.compInst.getComponentClassifier(), agreeProgram.topNode.compInst, null);
locals.add(assumeHistVar);
equations.add(new Equation(new IdExpr(assumeHistVar.id), assumeConj));
properties.add(assumeHistVar.id);
int k = 0;
for (AgreeStatement patternPropState : flatNode.patternProps) {
String patternVarName = patternPropSuffix + k++;
locals.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(patternVarName), patternPropState.expr));
properties.add(patternVarName);
}
int lemmaCount = 0;
for (AgreeStatement lemma : flatNode.lemmas) {
String lemmaName = lemmaSuffix + lemmaCount++;
locals.add(new AgreeVar(lemmaName, NamedType.BOOL, lemma.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(lemmaName), lemma.expr));
properties.add(lemmaName);
}
int i = 0;
for (AgreeStatement guarantee : flatNode.guarantees) {
String guarName = guarSuffix + i++;
locals.add(new AgreeVar(guarName, NamedType.BOOL, guarantee.reference, flatNode.compInst, null));
equations.add(new Equation(new IdExpr(guarName), guarantee.expr));
properties.add(guarName);
}
if (flatNode.getFaultTreeFlag()) {
ivcs.addAll(agreeProgram.topNode.getivcElements());
}
for (AgreeVar var : flatNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : flatNode.locals) {
locals.add(var);
}
equations.addAll(flatNode.localEquations);
assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(flatNode.eventTimes));
NodeBuilder builder = new NodeBuilder("main");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.addIvcs(ivcs);
Node main = builder.build();
nodes.add(main);
nodes.addAll(agreeProgram.globalLustreNodes);
nodes.add(getHistNode());
// add realtime constraint nodes
nodes.addAll(AgreeRealtimeCalendarBuilder.getRealTimeNodes());
List<TypeDef> types = AgreeUtils.getLustreTypes(agreeProgram);
uninterpretedFcns.addAll(agreeProgram.uninterpretedFunctions);
Program program = new ProgramBuilder().addTypes(types).addFunctions(uninterpretedFcns).addNodes(nodes).setMain(main.id).build();
return program;
}
Aggregations