Search in sources :

Example 1 with IdExpr

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));
    }
}
Also used : SubstitutionVisitor(jkind.translation.SubstitutionVisitor) IdExpr(jkind.lustre.IdExpr) TupleExpr(jkind.lustre.TupleExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation)

Example 2 with IdExpr

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;
}
Also used : IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList)

Example 3 with IdExpr

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));
    }
}
Also used : IdExpr(jkind.lustre.IdExpr) TupleExpr(jkind.lustre.TupleExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) Equation(jkind.lustre.Equation)

Example 4 with IdExpr

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);
        }
    });
}
Also used : AstMapVisitor(jkind.lustre.visitors.AstMapVisitor) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) CondactExpr(jkind.lustre.CondactExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) CondactExpr(jkind.lustre.CondactExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Node(jkind.lustre.Node) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList)

Example 5 with IdExpr

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();
}
Also used : IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Aggregations

IdExpr (jkind.lustre.IdExpr)133 BinaryExpr (jkind.lustre.BinaryExpr)96 Expr (jkind.lustre.Expr)95 BoolExpr (jkind.lustre.BoolExpr)82 NodeCallExpr (jkind.lustre.NodeCallExpr)81 UnaryExpr (jkind.lustre.UnaryExpr)75 IfThenElseExpr (jkind.lustre.IfThenElseExpr)64 IntExpr (jkind.lustre.IntExpr)53 ArrayList (java.util.ArrayList)52 Equation (jkind.lustre.Equation)46 VarDecl (jkind.lustre.VarDecl)41 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)38 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)37 RecordAccessExpr (jkind.lustre.RecordAccessExpr)37 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)29 RealExpr (jkind.lustre.RealExpr)29 NodeBuilder (jkind.lustre.builders.NodeBuilder)29 TupleExpr (jkind.lustre.TupleExpr)25 ArrayExpr (jkind.lustre.ArrayExpr)14 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)13