use of jkind.lustre.NodeCallExpr in project AGREE by loonwerks.
the class AgreeASTBuilder method getSynchConstraint.
private Expr getSynchConstraint(SynchStatement spec, List<AgreeNode> subNodes) {
int val1 = Integer.decode(spec.getVal());
if (val1 == 0) {
return new BoolExpr(true);
}
List<Expr> clockIds = new ArrayList<>();
Expr clockAssertion;
for (AgreeNode subNode : subNodes) {
clockIds.add(new IdExpr(subNode.clockVar.id));
}
String dfaPrefix = getObjectLocationPrefix(spec);
if (spec.getVal2() == null) {
Node dfaNode = AgreeCalendarUtils.getDFANode(dfaPrefix + "__DFA_NODE", val1);
Node calNode = AgreeCalendarUtils.getCalendarNode(dfaPrefix + "__CALENDAR_NODE", dfaNode.id, clockIds.size());
// we do not need to make copies of the nodes if they exist
if (!nodeNameExists(dfaNode.id)) {
if (nodeNameExists(calNode.id)) {
throw new AgreeException("The calander node should not exist if the dfa node does not exist");
}
addToNodeList(dfaNode);
addToNodeList(calNode);
}
clockAssertion = new NodeCallExpr(calNode.id, clockIds);
} else {
int val2 = Integer.decode(spec.getVal2());
String nodeName = "__calendar_node_" + val1 + "_" + val2;
nodeName = dfaPrefix + nodeName;
Node calNode = AgreeCalendarUtils.getMNCalendar(nodeName, val1, val2);
if (!nodeNameExists(calNode.id)) {
addToNodeList(calNode);
}
clockAssertion = new BoolExpr(true);
int i, j;
for (i = 0; i < clockIds.size(); i++) {
Expr clock1 = clockIds.get(i);
for (j = i + 1; j < clockIds.size(); j++) {
Expr clock2 = clockIds.get(j);
NodeCallExpr nodeCall = new NodeCallExpr(nodeName, clock1, clock2);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
nodeCall = new NodeCallExpr(nodeName, clock2, clock1);
clockAssertion = LustreExprFactory.makeANDExpr(clockAssertion, nodeCall);
}
}
}
return clockAssertion;
}
use of jkind.lustre.NodeCallExpr in project AGREE by loonwerks.
the class LustreAstBuilder method addNodeCall.
protected static void addNodeCall(AgreeNode agreeNode, List<AgreeStatement> assertions, String prefix, Expr clockExpr, Node lustreNode) {
List<Expr> inputIds = new ArrayList<>();
for (VarDecl var : lustreNode.inputs) {
String suffix = "";
// if this component implementation is using the latched semantics
if (agreeNode.timing == TimingModel.LATCHED) {
EObject ref = ((AgreeVar) var).reference;
if (ref instanceof DataPortImpl && ((DataPortImpl) ref).isIn() || (ref instanceof EventDataPortImpl && ((EventDataPortImpl) ref).isIn() || (ref instanceof Arg && ref.eContainer() instanceof InputStatement))) {
suffix = AgreeInlineLatchedConnections.LATCHED_SUFFIX;
}
}
inputIds.add(new IdExpr(prefix + var.id + suffix));
}
if (agreeNode.timing == TimingModel.ASYNC || agreeNode.timing == TimingModel.LATCHED) {
// the clock expr should be the last input to the node
inputIds.set(inputIds.size() - 1, clockExpr);
}
Expr condactExpr = new NodeCallExpr(lustreNode.id, inputIds);
AgreeStatement condactCall = new AgreeStatement("", condactExpr, null);
assertions.add(condactCall);
}
use of jkind.lustre.NodeCallExpr 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.NodeCallExpr 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.NodeCallExpr in project AGREE by loonwerks.
the class AgreePatternTranslator method getTimeRise.
private AgreeVar getTimeRise(String varName, AgreeNodeBuilder builder, EObject reference) {
Map<String, AgreeVar> timeRiseMap = builder.build().timeRiseMap;
if (timeRiseMap.containsKey(varName)) {
return timeRiseMap.get(varName);
}
AgreeVar timeRise = new AgreeVar(varName + RISE_SUFFIX, NamedType.REAL, reference);
builder.addOutput(timeRise);
Expr rise = new NodeCallExpr(AgreeRealtimeCalendarBuilder.RISE_NODE_NAME, new IdExpr(varName));
Expr timeVarExpr = expr("timeRise = (if rise then time else (-1.0 -> pre timeRise))", to("timeRise", timeRise), to("rise", rise), to("time", timeExpr));
builder.addAssertion(new AgreeStatement(null, timeVarExpr, reference));
Expr lemmaExpr = expr("timeRise <= time and timeRise >= -1.0", to("timeRise", timeRise), to("time", timeExpr));
// add this assertion to help with proofs (it should always be true)
builder.addAssertion(new AgreeStatement("", lemmaExpr, reference));
builder.addTimeRise(varName, timeRise);
return timeRise;
}
Aggregations