use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class LustreAstBuilder method getLustreNode.
protected static Node getLustreNode(AgreeNode agreeNode, String nodePrefix) {
List<VarDecl> inputs = new ArrayList<>();
List<VarDecl> locals = new ArrayList<>();
List<Equation> equations = new ArrayList<>();
List<Expr> assertions = new ArrayList<>();
List<String> ivcs = agreeNode.getivcElements();
List<String> properties = new ArrayList<>();
// add assumption history variable
IdExpr assumHist = new IdExpr(assumeHistSufix);
inputs.add(new AgreeVar(assumHist.id, NamedType.BOOL, null, agreeNode.compInst, null));
int i = 0;
for (AgreeStatement statement : agreeNode.assumptions) {
String inputName = assumeSuffix + i++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr assumeId = new IdExpr(inputName);
assertions.add(new BinaryExpr(assumeId, BinaryOp.EQUAL, statement.expr));
}
int j = 0;
for (AgreeStatement statement : agreeNode.lemmas) {
String inputName = lemmaSuffix + j++;
inputs.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
properties.add(inputName);
IdExpr lemmaId = new IdExpr(inputName);
assertions.add(new BinaryExpr(lemmaId, BinaryOp.EQUAL, statement.expr));
}
int k = 0;
Expr guarConjExpr = new BoolExpr(true);
for (AgreeStatement statement : agreeNode.guarantees) {
String inputName = guarSuffix + k++;
locals.add(new AgreeVar(inputName, NamedType.BOOL, statement.reference, agreeNode.compInst, null));
IdExpr guarId = new IdExpr(inputName);
equations.add(new Equation(guarId, statement.expr));
if (agreeNode.getFaultTreeFlag() == false) {
ivcs.add(guarId.id);
} else {
// check if it's leaf node
if (!agreeNode.compInst.getComponentInstances().isEmpty()) {
ivcs.add(guarId.id);
}
}
guarConjExpr = LustreExprFactory.makeANDExpr(guarId, guarConjExpr);
}
// assert that if the assumptions have held historically, then the
// gurantees hold
assertions.add(new BinaryExpr(assumHist, BinaryOp.IMPLIES, guarConjExpr));
for (AgreeStatement statement : agreeNode.assertions) {
assertions.add(statement.expr);
}
// create properties for the patterns
int l = 0;
for (AgreeStatement patternPropState : agreeNode.patternProps) {
String patternVarName = patternPropSuffix + l++;
inputs.add(new AgreeVar(patternVarName, NamedType.BOOL, patternPropState, agreeNode.compInst, null));
assertions.add(new BinaryExpr(new IdExpr(patternVarName), BinaryOp.EQUAL, patternPropState.expr));
}
Expr assertExpr = new BoolExpr(true);
for (Expr expr : assertions) {
assertExpr = LustreExprFactory.makeANDExpr(expr, assertExpr);
}
String outputName = "__ASSERT";
List<VarDecl> outputs = new ArrayList<>();
outputs.add(new VarDecl(outputName, NamedType.BOOL));
equations.add(new Equation(new IdExpr(outputName), assertExpr));
// gather the remaining inputs
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.locals) {
locals.add(var);
}
for (AgreeEquation equation : agreeNode.localEquations) {
equations.add(equation);
}
NodeBuilder builder = new NodeBuilder(nodePrefix + agreeNode.id);
builder.addInputs(inputs);
builder.addOutputs(outputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addIvcs(ivcs);
return builder.build();
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class LustreAstBuilder method addHistoricalAssumptionConstraint.
private static void addHistoricalAssumptionConstraint(AgreeNode agreeNode, String prefix, Expr clockExpr, List<AgreeStatement> assertions, Node lustreNode) {
Expr assumConj = new BoolExpr(true);
for (VarDecl lustreVar : lustreNode.inputs) {
AgreeVar var = (AgreeVar) lustreVar;
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
Expr varId = new IdExpr(prefix + var.id);
assumConj = LustreExprFactory.makeANDExpr(varId, assumConj);
}
}
// assumConj = new BinaryExpr(clockExpr, BinaryOp.IMPLIES, assumConj);
Expr histCall = new NodeCallExpr(historyNodeName, assumConj);
Expr assertExpr = new BinaryExpr(new IdExpr(prefix + assumeSuffix + "__HIST"), BinaryOp.EQUAL, histCall);
assertions.add(new AgreeStatement("", assertExpr, null));
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class LustreContractAstBuilder method flattenAgreeNodeKindContract.
protected static AgreeNode flattenAgreeNodeKindContract(AgreeNode agreeNode, String nodePrefix) {
List<AgreeVar> inputs = new ArrayList<>();
List<AgreeVar> outputs = new ArrayList<>();
List<AgreeVar> locals = new ArrayList<>();
List<AgreeStatement> assertions = new ArrayList<>();
Expr someoneTicks = null;
for (AgreeNode subAgreeNode : agreeNode.subNodes) {
String prefix = subAgreeNode.id + AgreeASTBuilder.dotChar;
Expr clockExpr = getClockExpr(agreeNode, subAgreeNode);
if (someoneTicks == null) {
someoneTicks = clockExpr;
} else {
someoneTicks = new BinaryExpr(someoneTicks, BinaryOp.OR, clockExpr);
}
AgreeNode flatNode = flattenAgreeNodeKindContract(subAgreeNode, nodePrefix + subAgreeNode.id + AgreeASTBuilder.dotChar);
Node lustreNode = addSubNodeLustre(agreeNode, nodePrefix, flatNode);
addInputsAndOutputs(inputs, outputs, flatNode, lustreNode, prefix);
addCondactCall(agreeNode, nodePrefix, inputs, assertions, flatNode, prefix, clockExpr, lustreNode);
// addClockHolds(agreeNode, assertions, flatNode, clockExpr, prefix,
// lustreNode);
addInitConstraint(agreeNode, outputs, assertions, flatNode, prefix, clockExpr, lustreNode);
}
if (agreeNode.timing == TimingModel.ASYNC) {
if (someoneTicks == null) {
throw new AgreeException("Somehow we generated a clock constraint without any clocks");
}
assertions.add(new AgreeStatement("someone ticks", someoneTicks, null));
}
addConnectionConstraints(agreeNode, assertions);
// add any clock constraints
assertions.addAll(agreeNode.assertions);
assertions.add(new AgreeStatement("", agreeNode.clockConstraint, null));
inputs.addAll(agreeNode.inputs);
outputs.addAll(agreeNode.outputs);
locals.addAll(agreeNode.locals);
AgreeNodeBuilder builder = new AgreeNodeBuilder(agreeNode.id);
builder.addInput(inputs);
builder.addOutput(outputs);
builder.addLocal(locals);
builder.addLocalEquation(agreeNode.localEquations);
builder.addSubNode(agreeNode.subNodes);
builder.addAssertion(assertions);
builder.addAssumption(agreeNode.assumptions);
builder.addGuarantee(agreeNode.guarantees);
builder.addLemma(agreeNode.lemmas);
builder.addPatternProp(agreeNode.patternProps);
builder.setClockConstraint(new BoolExpr(true));
builder.setInitialConstraint(agreeNode.initialConstraint);
builder.setClockVar(agreeNode.clockVar);
builder.setReference(agreeNode.reference);
builder.setTiming(null);
builder.addEventTime(agreeNode.eventTimes);
builder.setCompInst(agreeNode.compInst);
return builder.build();
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class LustreContractAstBuilder method addInitConstraint.
protected static void addInitConstraint(AgreeNode agreeNode, List<AgreeVar> outputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
if (agreeNode.timing != TimingModel.SYNC) {
String tickedName = subAgreeNode.id + "___TICKED";
outputs.add(new AgreeVar(tickedName, NamedType.BOOL, null, agreeNode.compInst, null));
Expr tickedId = new IdExpr(tickedName);
Expr preTicked = new UnaryExpr(UnaryOp.PRE, tickedId);
Expr tickedOrPre = new BinaryExpr(clockExpr, BinaryOp.OR, preTicked);
Expr initOrTicked = new BinaryExpr(clockExpr, BinaryOp.ARROW, tickedOrPre);
Expr tickedEq = new BinaryExpr(tickedId, BinaryOp.EQUAL, initOrTicked);
assertions.add(new AgreeStatement("", tickedEq, null));
// we have two re-write the ids in the initial expressions
IdRewriter rewriter = id -> new IdExpr(prefix + id.id);
Expr newInit = subAgreeNode.initialConstraint.accept(new IdRewriteVisitor(rewriter));
Expr initConstr = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, newInit);
assertions.add(new AgreeStatement("", initConstr, null));
// we also need to add hold expressions for the assumptions and
// lemmas
Expr assumeLemmaTrue = new BoolExpr(true);
for (VarDecl lustreVar : lustreNode.inputs) {
AgreeVar var = (AgreeVar) lustreVar;
if (var.reference instanceof AssumeStatement || var.reference instanceof LemmaStatement) {
assumeLemmaTrue = new BinaryExpr(assumeLemmaTrue, BinaryOp.AND, new IdExpr(prefix + var.id));
}
}
assumeLemmaTrue = new BinaryExpr(new UnaryExpr(UnaryOp.NOT, tickedId), BinaryOp.IMPLIES, assumeLemmaTrue);
assertions.add(new AgreeStatement("", assumeLemmaTrue, null));
}
}
use of jkind.lustre.BoolExpr in project AGREE by loonwerks.
the class AgreeRealtimeCalendarBuilder method getTimeConstraint.
public static Expr getTimeConstraint(Set<AgreeVar> events) {
IdExpr timeId = AgreePatternTranslator.timeExpr;
Expr preTime = new UnaryExpr(UnaryOp.PRE, timeId);
Expr nodeCall = new BinaryExpr(timeId, BinaryOp.MINUS, preTime);
for (AgreeVar eventVar : events) {
Expr event = new IdExpr(eventVar.id);
BinaryExpr timeChange = new BinaryExpr(event, BinaryOp.MINUS, timeId);
Expr preTimeChange = new UnaryExpr(UnaryOp.PRE, timeChange);
nodeCall = new NodeCallExpr(MIN_POS_NODE_NAME, preTimeChange, nodeCall);
}
nodeCall = new BinaryExpr(preTime, BinaryOp.PLUS, nodeCall);
Expr timeExpr = new BinaryExpr(timeId, BinaryOp.EQUAL, nodeCall);
timeExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, timeExpr);
Expr timeGrtPreTime = new BinaryExpr(timeId, BinaryOp.GREATER, preTime);
Expr timeInitZero = new BinaryExpr(timeId, BinaryOp.EQUAL, new RealExpr(BigDecimal.ZERO));
timeInitZero = new BinaryExpr(timeInitZero, BinaryOp.ARROW, timeGrtPreTime);
return new BinaryExpr(timeInitZero, BinaryOp.AND, timeExpr);
}
Aggregations