use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.
the class LustreAstBuilder method getClockExpr.
protected static Expr getClockExpr(AgreeNode agreeNode, AgreeNode subNode) {
IdExpr clockId = new IdExpr(subNode.clockVar.id);
switch(agreeNode.timing) {
case SYNC:
return new BoolExpr(true);
case ASYNC:
return clockId;
case LATCHED:
Expr preClock = new UnaryExpr(UnaryOp.PRE, clockId);
Expr notClock = new UnaryExpr(UnaryOp.NOT, clockId);
Expr andExpr = new BinaryExpr(preClock, BinaryOp.AND, notClock);
Expr clockExpr = new BinaryExpr(new BoolExpr(false), BinaryOp.ARROW, andExpr);
return clockExpr;
default:
throw new AgreeException("unhandled timing type: '" + agreeNode.timing + "");
}
}
use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.
the class LustreAstBuilder method getConsistencyLustreNode.
protected static Node getConsistencyLustreNode(AgreeNode agreeNode, boolean withAssertions) {
final String stuffPrefix = "__STUFF";
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<>();
Expr stuffConj = new BoolExpr(true);
int stuffAssumptionIndex = 0;
for (AgreeStatement assumption : agreeNode.assumptions) {
AgreeVar stuffAssumptionVar = new AgreeVar(stuffPrefix + assumeSuffix + stuffAssumptionIndex++, NamedType.BOOL, assumption.reference, agreeNode.compInst, null);
locals.add(stuffAssumptionVar);
ivcs.add(stuffAssumptionVar.id);
IdExpr stuffAssumptionId = new IdExpr(stuffAssumptionVar.id);
equations.add(new Equation(stuffAssumptionId, assumption.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssumptionId);
}
int stuffGuaranteeIndex = 0;
for (AgreeStatement guarantee : agreeNode.guarantees) {
AgreeVar stuffGuaranteeVar = new AgreeVar(stuffPrefix + guarSuffix + stuffGuaranteeIndex++, NamedType.BOOL, guarantee.reference, agreeNode.compInst, null);
locals.add(stuffGuaranteeVar);
ivcs.add(stuffGuaranteeVar.id);
IdExpr stuffGuaranteeId = new IdExpr(stuffGuaranteeVar.id);
equations.add(new Equation(stuffGuaranteeId, guarantee.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffGuaranteeId);
}
if (withAssertions) {
equations.addAll(agreeNode.localEquations);
} else {
for (AgreeEquation eq : agreeNode.localEquations) {
if (AgreeUtils.referenceIsInContract(eq.reference, agreeNode.compInst)) {
equations.add(eq);
}
}
}
// TODO should we include lemmas in the consistency check?
// for(AgreeStatement guarantee : agreeNode.lemmas){
// histConj = new BinaryExpr(histConj, BinaryOp.AND, guarantee.expr);
// }
int stuffAssertionIndex = 0;
if (withAssertions) {
for (AgreeStatement assertion : agreeNode.assertions) {
AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
locals.add(stuffAssertionVar);
IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
equations.add(new Equation(stuffAssertionId, assertion.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
}
} else {
// equations and type equations. That would clear this up.
for (AgreeStatement assertion : agreeNode.assertions) {
if (AgreeUtils.referenceIsInContract(assertion.reference, agreeNode.compInst)) {
AgreeVar stuffAssertionVar = new AgreeVar(stuffPrefix + assertSuffix + stuffAssertionIndex++, NamedType.BOOL, assertion.reference, null, null);
locals.add(stuffAssertionVar);
IdExpr stuffAssertionId = new IdExpr(stuffAssertionVar.id);
equations.add(new Equation(stuffAssertionId, assertion.expr));
stuffConj = LustreExprFactory.makeANDExpr(stuffConj, stuffAssertionId);
}
}
}
// add realtime constraints
Set<AgreeVar> eventTimes = new HashSet<>();
if (withAssertions) {
eventTimes.addAll(agreeNode.eventTimes);
} else {
for (AgreeVar eventVar : agreeNode.eventTimes) {
if (AgreeUtils.referenceIsInContract(eventVar.reference, agreeNode.compInst)) {
eventTimes.add(eventVar);
}
}
}
assertions.add(AgreeRealtimeCalendarBuilder.getTimeConstraint(eventTimes));
for (AgreeVar var : agreeNode.inputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.outputs) {
inputs.add(var);
}
for (AgreeVar var : agreeNode.locals) {
if (withAssertions) {
locals.add(var);
} else {
if (AgreeUtils.referenceIsInContract(var.reference, agreeNode.compInst)) {
locals.add(var);
}
}
}
EObject classifier = agreeNode.compInst.getComponentClassifier();
AgreeVar countVar = new AgreeVar("__COUNT", NamedType.INT, null, null, null);
AgreeVar stuffVar = new AgreeVar(stuffPrefix, NamedType.BOOL, null, null, null);
AgreeVar histVar = new AgreeVar("__HIST", NamedType.BOOL, null, null, null);
AgreeVar propVar = new AgreeVar("__PROP", NamedType.BOOL, classifier, agreeNode.compInst, null);
locals.add(countVar);
locals.add(stuffVar);
locals.add(histVar);
locals.add(propVar);
IdExpr countId = new IdExpr(countVar.id);
IdExpr stuffId = new IdExpr(stuffVar.id);
IdExpr histId = new IdExpr(histVar.id);
IdExpr propId = new IdExpr(propVar.id);
equations.add(new Equation(stuffId, stuffConj));
Expr histExpr = new UnaryExpr(UnaryOp.PRE, histId);
histExpr = LustreExprFactory.makeANDExpr(histExpr, stuffId);
histExpr = new BinaryExpr(stuffId, BinaryOp.ARROW, histExpr);
equations.add(new Equation(histId, histExpr));
Expr countExpr = new UnaryExpr(UnaryOp.PRE, countId);
countExpr = new BinaryExpr(countExpr, BinaryOp.PLUS, new IntExpr(BigInteger.ONE));
countExpr = new BinaryExpr(new IntExpr(BigInteger.ZERO), BinaryOp.ARROW, countExpr);
equations.add(new Equation(countId, countExpr));
IPreferenceStore prefs = Activator.getDefault().getPreferenceStore();
int consistDetph = prefs.getInt(PreferenceConstants.PREF_CONSIST_DEPTH);
Expr propExpr = new BinaryExpr(countId, BinaryOp.EQUAL, new IntExpr(BigInteger.valueOf(consistDetph)));
propExpr = new BinaryExpr(propExpr, BinaryOp.AND, histId);
equations.add(new Equation(propId, new UnaryExpr(UnaryOp.NOT, propExpr)));
properties.add(propId.id);
NodeBuilder builder = new NodeBuilder("consistency");
builder.addInputs(inputs);
builder.addLocals(locals);
builder.addEquations(equations);
builder.addProperties(properties);
builder.addAssertions(assertions);
builder.addIvcs(ivcs);
Node node = builder.build();
return node;
}
use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.
the class LustreAstBuilder method getHistNode.
protected static Node getHistNode() {
NodeBuilder builder = new NodeBuilder(historyNodeName);
builder.addInput(new VarDecl("input", NamedType.BOOL));
builder.addOutput(new VarDecl("hist", NamedType.BOOL));
IdExpr histId = new IdExpr("hist");
IdExpr inputId = new IdExpr("input");
Expr preHist = new UnaryExpr(UnaryOp.PRE, histId);
Expr histExpr = new BinaryExpr(preHist, BinaryOp.AND, inputId);
histExpr = new BinaryExpr(inputId, BinaryOp.ARROW, histExpr);
builder.addEquation(new Equation(histId, histExpr));
return builder.build();
}
use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.
the class AgreeRealtimeCalendarBuilder method getRiseNode.
private static Node getRiseNode() {
NodeBuilder builder = new NodeBuilder(RISE_NODE_NAME);
builder.addInput(new VarDecl("input", NamedType.BOOL));
builder.addOutput(new VarDecl("output", NamedType.BOOL));
IdExpr inputId = new IdExpr("input");
IdExpr outputId = new IdExpr("output");
Expr outputExpr = new UnaryExpr(UnaryOp.NOT, inputId);
outputExpr = new UnaryExpr(UnaryOp.PRE, outputExpr);
outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, inputId);
outputExpr = new BinaryExpr(inputId, BinaryOp.ARROW, outputExpr);
builder.addEquation(new Equation(outputId, outputExpr));
return builder.build();
}
use of jkind.lustre.UnaryExpr in project AGREE by loonwerks.
the class SimulationFrameResults method eval.
private Value eval(final Expr lustreExpr) {
if (lustreExpr instanceof BoolExpr) {
return BooleanValue.fromBoolean(((BoolExpr) lustreExpr).value);
} else if (lustreExpr instanceof IntExpr) {
return new IntegerValue(((IntExpr) lustreExpr).value);
} else if (lustreExpr instanceof RealExpr) {
final RealExpr realExpr = (RealExpr) lustreExpr;
return new RealValue(BigFraction.valueOf(realExpr.value));
} else if (lustreExpr instanceof BinaryExpr) {
final BinaryExpr binaryExpr = (BinaryExpr) lustreExpr;
final Value leftValue = eval(binaryExpr.left);
final Value rightValue = eval(binaryExpr.right);
if (leftValue == null || rightValue == null) {
return null;
}
return leftValue.applyBinaryOp(binaryExpr.op, rightValue);
} else if (lustreExpr instanceof UnaryExpr) {
final UnaryExpr unaryExpr = (UnaryExpr) lustreExpr;
final Value operandValue = eval(unaryExpr.expr);
if (operandValue == null) {
return null;
}
return operandValue.applyUnaryOp(unaryExpr.op);
}
return null;
}
Aggregations