use of jkind.lustre.Equation in project AGREE by loonwerks.
the class InlineNodeCalls method createAssignmentEquations.
private void createAssignmentEquations(final String prefix, List<Equation> equations, Map<String, IdExpr> translation) {
SubstitutionVisitor substitution = new SubstitutionVisitor(translation) {
@Override
public Expr visit(NodeCallExpr e) {
return new NodeCallExpr(e.location, prefix + e.node, visitExprs(e.args));
}
};
for (Equation eq : equations) {
List<IdExpr> lhs = new ArrayList<>();
for (IdExpr idExpr : eq.lhs) {
lhs.add(translation.get(idExpr.id));
}
Expr expr = eq.expr.accept(substitution);
queue.add(new Equation(eq.location, lhs, expr));
}
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class InlineNodeCalls method createInputEquations.
private void createInputEquations(List<VarDecl> inputs, List<Expr> args, Map<String, IdExpr> translation) {
for (int i = 0; i < inputs.size(); i++) {
IdExpr idExpr = translation.get(inputs.get(i).id);
Expr arg = args.get(i);
queue.add(new Equation(idExpr, arg));
}
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class RemoveCondacts method clockOutputs.
private Node clockOutputs(Node node, IdExpr clock) {
NodeBuilder builder = new NodeBuilder(node);
builder.clearOutputs();
builder.addLocals(node.outputs);
for (VarDecl output : node.outputs) {
VarDecl dflt = new VarDecl(output.id + namePrefix + "default", output.type);
builder.addInput(dflt);
VarDecl clocked = new VarDecl(output.id + namePrefix + "clocked", output.type);
builder.addOutput(clocked);
// clocked = if clock then output else (default -> pre clocked)
Equation eq = new Equation(new IdExpr(clocked.id), new IfThenElseExpr(clock, new IdExpr(output.id), new BinaryExpr(new IdExpr(dflt.id), BinaryOp.ARROW, new UnaryExpr(UnaryOp.PRE, new IdExpr(clocked.id)))));
builder.addEquation(eq);
}
return builder.build();
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class RemoveCondacts method clockProperties.
private Node clockProperties(Node node, final IdExpr clock) {
NodeBuilder builder = new NodeBuilder(node);
builder.clearProperties();
for (String property : node.properties) {
VarDecl clocked = new VarDecl(property + namePrefix + "clocked_property", NamedType.BOOL);
builder.addLocal(clocked);
// clocked_property = clock => property
builder.addEquation(new Equation(new IdExpr(clocked.id), new BinaryExpr(clock, BinaryOp.IMPLIES, new IdExpr(property))));
builder.addProperty(clocked.id);
}
return builder.build();
}
use of jkind.lustre.Equation in project AGREE by loonwerks.
the class RemoveCondacts method clockArrowsAndPres.
private Node clockArrowsAndPres(Node node, final IdExpr clock) {
final VarDecl init = new VarDecl(namePrefix + "init", NamedType.BOOL);
final List<Equation> preEquations = new ArrayList<>();
final List<VarDecl> preLocals = new ArrayList<>();
node = (Node) node.accept(new AstMapVisitor() {
private int counter = 0;
@Override
public Expr visit(BinaryExpr e) {
if (e.op == BinaryOp.ARROW) {
return new IfThenElseExpr(new IdExpr(init.id), e.left.accept(this), e.right.accept(this));
} else {
return super.visit(e);
}
}
@Override
public Expr visit(UnaryExpr e) {
if (e.op == UnaryOp.PRE) {
String state = namePrefix + "state" + counter++;
Type type = e.expr.accept(typeReconstructor);
preLocals.add(new VarDecl(state, type));
// state = if clock then expr else pre state
preEquations.add(new Equation(new IdExpr(state), new IfThenElseExpr(clock, e.expr.accept(this), new UnaryExpr(UnaryOp.PRE, new IdExpr(state)))));
return new UnaryExpr(UnaryOp.PRE, new IdExpr(state));
} else {
return super.visit(e);
}
}
});
NodeBuilder builder = new NodeBuilder(node);
builder.addLocals(preLocals);
builder.addLocal(init);
builder.addEquations(preEquations);
// init = true -> if pre clock then false else pre init
builder.addEquation(new Equation(new IdExpr(init.id), new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, new IfThenElseExpr(new UnaryExpr(UnaryOp.PRE, clock), new BoolExpr(false), new UnaryExpr(UnaryOp.PRE, new IdExpr(init.id))))));
return builder.build();
}
Aggregations