use of jkind.lustre.IdExpr 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.IdExpr in project AGREE by loonwerks.
the class InlineNodeCalls method visitNodeCallExpr.
public List<IdExpr> visitNodeCallExpr(NodeCallExpr e) {
String prefix = newPrefix(e.node);
Node node = nodeTable.get(getOriginalName(e));
Map<String, IdExpr> translation = getTranslation(prefix, node);
createInputEquations(node.inputs, e.args, translation);
createAssignmentEquations(prefix, node.equations, translation);
accumulateProperties(node.properties, translation);
List<IdExpr> result = new ArrayList<>();
for (VarDecl decl : node.outputs) {
result.add(translation.get(decl.id));
}
return result;
}
use of jkind.lustre.IdExpr 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.IdExpr in project AGREE by loonwerks.
the class RemoveCondacts method clockNodeCalls.
private Node clockNodeCalls(Node node, final IdExpr clock) {
return (Node) node.accept(new AstMapVisitor() {
@Override
public Expr visit(NodeCallExpr e) {
List<Expr> args = new ArrayList<>();
args.add(clock);
args.addAll(visitExprs(e.args));
Node clocked = createClockedNode(e.node);
return new NodeCallExpr(clocked.id, args);
}
@Override
public Expr visit(CondactExpr e) {
NodeCallExpr call = (NodeCallExpr) super.visit(e.call);
List<Expr> args = new ArrayList<>();
args.add(new BinaryExpr(e.clock.accept(this), BinaryOp.AND, clock));
args.addAll(e.call.args);
args.addAll(visitExprs(e.args));
Node condact = createCondactNode(call.node);
return new NodeCallExpr(condact.id, args);
}
});
}
use of jkind.lustre.IdExpr 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();
}
Aggregations