use of jkind.lustre.IdExpr 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.IdExpr in project AGREE by loonwerks.
the class LustreContractAstBuilder method addCondactCall.
protected static void addCondactCall(AgreeNode agreeNode, String nodePrefix, List<AgreeVar> inputs, List<AgreeStatement> assertions, AgreeNode subAgreeNode, String prefix, Expr clockExpr, Node lustreNode) {
List<Expr> inputIds = new ArrayList<>();
List<Expr> initOutputsVals = new ArrayList<>();
List<IdExpr> nodeOutputIds = new ArrayList<>();
for (VarDecl var : lustreNode.inputs) {
inputIds.add(new IdExpr(prefix + var.id));
}
for (VarDecl var : lustreNode.outputs) {
AgreeVar outputVar = (AgreeVar) var;
String dummyName = prefix + var.id + "__DUMMY";
AgreeVar dummyVar = new AgreeVar(dummyName, outputVar.type, outputVar.reference, outputVar.compInst, outputVar.featInst);
if (!inputs.contains(dummyVar)) {
inputs.add(dummyVar);
}
initOutputsVals.add(new IdExpr(dummyName));
nodeOutputIds.add(new IdExpr(prefix + var.id));
}
if (agreeNode.timing == TimingModel.LATCHED) {
throw new AgreeException("check how we do this in the generic lustre translation now" + " to make sure that it is correct");
}
Expr condactExpr = new CondactExpr(clockExpr, new NodeCallExpr(lustreNode.id, inputIds), initOutputsVals);
Expr condactOutput;
if (nodeOutputIds.size() > 1) {
condactOutput = new TupleExpr(nodeOutputIds);
} else {
condactOutput = nodeOutputIds.get(0);
}
Expr condactCall = new BinaryExpr(condactOutput, BinaryOp.EQUAL, condactExpr);
assertions.add(new AgreeStatement("", condactCall, null));
}
use of jkind.lustre.IdExpr in project AGREE by loonwerks.
the class AgreePatternBuilder method caseSporadicStatement.
@Override
public AgreeStatement caseSporadicStatement(SporadicStatement object) {
IdExpr event = (IdExpr) builder.doSwitch(object.getEvent());
com.rockwellcollins.atc.agree.agree.Expr jitter = object.getJitter();
Expr jitterExpr = null;
if (jitter != null) {
jitterExpr = builder.doSwitch(jitter);
}
Expr iat = builder.doSwitch(object.getIat());
return new AgreeSporadicPattern(str, ref, event, iat, jitterExpr);
}
use of jkind.lustre.IdExpr in project AGREE by loonwerks.
the class AgreePatternBuilder method caseWhenOccursStatment.
@Override
public AgreeStatement caseWhenOccursStatment(WhenOccursStatment object) {
IdExpr condition = (IdExpr) builder.doSwitch(object.getCondition());
IdExpr effect = (IdExpr) builder.doSwitch(object.getEvent());
Expr timesExpr = builder.doSwitch(object.getTimes());
boolean exclusive = object.getExcl() != null;
if (!(timesExpr instanceof IntExpr)) {
throw new AgreeException("Expected an integer literal in 'When Occurs' pattern");
}
BigInteger times = ((IntExpr) timesExpr).value;
AgreePatternInterval interval = getIntervalType(object.getInterval());
return new AgreeTimesPattern(str, ref, exclusive, condition, effect, interval, null, TriggerType.CONDITION, TriggerType.CONDITION, times, null);
}
use of jkind.lustre.IdExpr in project AGREE by loonwerks.
the class AgreePatternBuilder method caseWheneverOccursStatement.
@Override
public AgreeStatement caseWheneverOccursStatement(WheneverOccursStatement object) {
IdExpr cause = (IdExpr) builder.doSwitch(object.getCause());
IdExpr effect = (IdExpr) builder.doSwitch(object.getEffect());
boolean exclusive = object.getExcl() != null;
AgreePatternInterval effectInterval = getIntervalType(object.getInterval());
return new AgreeCauseEffectPattern(str, ref, exclusive, cause, effect, null, effectInterval, TriggerType.EVENT, TriggerType.EVENT);
}
Aggregations