FAUST compiler  0.9.9.6b8
Functions | Variables
sigToGraph.cpp File Reference
#include <stdio.h>
#include <set>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include "signals.hh"
#include "sigtype.hh"
#include "sigtyperules.hh"
#include "xtended.hh"
#include "sigToGraph.hh"
Include dependency graph for sigToGraph.cpp:

Go to the source code of this file.

Functions

static void recdraw (Tree sig, set< Tree > &drawn, ofstream &fout)
 Draw recursively a signal.
static string nodeattr (Type t)
 Convert a signal type into node attributes.
static string edgeattr (Type t)
 Convert a signal type into edge attributes.
static string sigLabel (Tree sig)
 return the label of a signal as a string
void sigToGraph (Tree L, ofstream &fout)
 Draw a list of signals as a directed graph using graphviz's dot language.

Variables

static const char * binopname []
 translate signal binary operations into strings

Function Documentation

static string edgeattr ( Type  t) [static]

Convert a signal type into edge attributes.

Definition at line 129 of file sigToGraph.cpp.

References kInt, kSamp, and kVect.

Referenced by nodeattr(), recdraw(), and sigToGraph().

{
    string s;

    // nature
    if (t->nature()==kInt) {
        s += " color=\"blue\"";
    } else {
        s += " color=\"red\"";
    }

    // vectorability
    if (t->vectorability()==kVect && t->variability()==kSamp) {
        s += " style=\"bold\"";
    }
    return s;
}

Here is the caller graph for this function:

static string nodeattr ( Type  t) [static]

Convert a signal type into node attributes.

Definition at line 151 of file sigToGraph.cpp.

References edgeattr(), kBlock, kKonst, and kSamp.

Referenced by recdraw().

{
    string s = edgeattr(t);

    // variability
    if (t->variability()==kKonst) {
        s += " shape=\"box\"";
    } else if (t->variability()==kBlock) {
        s += " shape=\"hexagon\"";
    } else if (t->variability()==kSamp) {
        s += " shape=\"ellipse\"";
    }

    return s;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void recdraw ( Tree  sig,
set< Tree > &  drawn,
ofstream &  fout 
) [static]

Draw recursively a signal.

Definition at line 76 of file sigToGraph.cpp.

References edgeattr(), getCertifiedSigType(), getSubSignals(), hd(), isList(), isRec(), nodeattr(), sigLabel(), and tl().

Referenced by sigToGraph().

{
    //cerr << ++TABBER << "ENTER REC DRAW OF " << sig << "$" << *sig << endl;
    vector<Tree>    subsig;
    int             n;

    if (drawn.count(sig) == 0) {
        drawn.insert(sig);
        if (isList(sig)) {
            do {
                recdraw(hd(sig), drawn, fout);
                sig = tl(sig);
            } while (isList(sig));
        } else {
            // draw the node
            fout    << 'S' << sig << "[label=\"" << sigLabel(sig) << "\""
                    << nodeattr(getCertifiedSigType(sig)) << "];"
                    << endl;

            // draw the subsignals
            n = getSubSignals(sig, subsig);
            if (n > 0) {
                if (n==1 && isList(subsig[0])) {
                    Tree id, body;
                    assert(isRec(sig,id,body));
                    // special recursion case, recreate a vector of subsignals instead of the
                    // list provided by getSubSignal
                    Tree L = subsig[0];
                    subsig.clear();
                    n = 0;
                    do {
                        subsig.push_back(hd(L));
                        L = tl(L);
                        n += 1;
                    } while (isList(L));
                }

                for (int i=0; i<n; i++) {
                    recdraw(subsig[i], drawn, fout);
                    fout    << 'S' << subsig[i] << " -> " << 'S' << sig
                            << "[" << edgeattr(getCertifiedSigType(subsig[i])) << "];"
                            << endl;
                }
            }
        }
    }
    //cerr << --TABBER << "EXIT REC DRAW OF " << sig << endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string sigLabel ( Tree  sig) [static]

return the label of a signal as a string

Definition at line 182 of file sigToGraph.cpp.

References binopname, getUserData(), isProj(), isRec(), isSigAttach(), isSigBinOp(), isSigButton(), isSigCheckbox(), isSigDelay1(), isSigFConst(), isSigFFun(), isSigFixDelay(), isSigFloatCast(), isSigFVar(), isSigGen(), isSigHBargraph(), isSigHSlider(), isSigInput(), isSigInt(), isSigIntCast(), isSigIota(), isSigNumEntry(), isSigOutput(), isSigPrefix(), isSigRDTbl(), isSigReal(), isSigSelect2(), isSigSelect3(), isSigTable(), isSigVBargraph(), isSigVSlider(), isSigWRTbl(), xtended::name(), and name().

Referenced by recdraw().

{
    int         i;
    double      r;
    Tree        x, y, z, c, type, name, file, ff, largs, id, le, sel, var, label;

    xtended*    p = (xtended*) getUserData(sig);

    stringstream fout;

         if (p)                                     { fout << p->name(); }
    else if ( isSigInt(sig, &i) )                   { fout << i;    }
    else if ( isSigReal(sig, &r) )                  { fout << r;    }
    else if ( isSigInput(sig, &i) )                 { fout << "INPUT_" << i; }
    else if ( isSigOutput(sig, &i, x) )             { fout << "OUTPUT_" << i; }

    else if ( isSigDelay1(sig, x) )                 { fout << "mem";        }
    else if ( isSigFixDelay(sig, x, y) )            { fout << "@";          }
    else if ( isSigPrefix(sig, x, y) )              { fout << "prefix";     }
    else if ( isSigIota(sig, x) )                   { fout << "iota";       }
    else if ( isSigBinOp(sig, &i, x, y) )           { fout << binopname[i]; }
    else if ( isSigFFun(sig, ff, largs) )           { fout << "ffunction:" << *ff; }
    else if ( isSigFConst(sig, type, name, file) )  { fout << *name; }
    else if ( isSigFVar(sig, type, name, file) )    { fout << *name; }

    else if ( isSigTable(sig, id, x, y) )           { fout << "table:" << id;   }
    else if ( isSigWRTbl(sig, id, x, y, z) )        { fout << "write:" << id;   }
    else if ( isSigRDTbl(sig, x, y) )               { fout << "read";   }



    else if ( isSigSelect2(sig, sel, x, y) )        { fout << "select2"; }
    else if ( isSigSelect3(sig, sel, x, y, z) )     { fout << "select3"; }

    else if ( isSigGen(sig, x) )                    { fout << "generator"; }

    else if ( isProj(sig, &i, x) )                  { fout << "Proj" << i;  }
    else if ( isRec(sig, var, le) )                 { fout << "REC " << *var; }

    else if ( isSigIntCast(sig, x) )                { fout << "int"; }
    else if ( isSigFloatCast(sig, x) )              { fout << "float"; }
#if 0
    else if ( isSigButton(sig, label) )             { fout << "button \"" << *label << '"'; }
    else if ( isSigCheckbox(sig, label) )           { fout << "checkbox \"" << *label << '"'; }
    else if ( isSigVSlider(sig, label,c,x,y,z) )    { fout << "vslider \"" << *label << '"';  }
    else if ( isSigHSlider(sig, label,c,x,y,z) )    { fout << "hslider \"" << *label << '"';  }
    else if ( isSigNumEntry(sig, label,c,x,y,z) )   { fout << "nentry \"" << *label << '"';  }

    else if ( isSigVBargraph(sig, label,x,y,z) )    { fout << "vbargraph \"" << *label << '"';  }
    else if ( isSigHBargraph(sig, label,x,y,z) )    { fout << "hbargraph \"" << *label << '"';  }
#else
    else if ( isSigButton(sig, label) )             { fout << "button"; }
    else if ( isSigCheckbox(sig, label) )           { fout << "checkbox"; }
    else if ( isSigVSlider(sig, label,c,x,y,z) )    { fout << "vslider";  }
    else if ( isSigHSlider(sig, label,c,x,y,z) )    { fout << "hslider";  }
    else if ( isSigNumEntry(sig, label,c,x,y,z) )   { fout << "nentry";  }

    else if ( isSigVBargraph(sig, label,x,y,z) )    { fout << "vbargraph";  }
    else if ( isSigHBargraph(sig, label,x,y,z) )    { fout << "hbargraph";  }
#endif
    else if ( isSigAttach(sig, x, y) )              { fout << "attach";     }

    else {
        cerr << "ERROR, unrecognized signal : " << *sig << endl;
        exit(1);
    }

    return fout.str();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void sigToGraph ( Tree  L,
ofstream &  fout 
)

Draw a list of signals as a directed graph using graphviz's dot language.

Draw a list of signals L as a directed graph using graphviz's dot language.

Definition at line 50 of file sigToGraph.cpp.

References edgeattr(), getCertifiedSigType(), hd(), isList(), recdraw(), and tl().

Referenced by ScalarCompiler::prepare().

{
    set<Tree>   alreadyDrawn;

    fout << "strict digraph loopgraph {\n"
         << "    rankdir=LR; node [fontsize=10];"
         << endl;
    int out = 0;
    while (isList(L)) {
        recdraw(hd(L), alreadyDrawn, fout);

        fout << "OUTPUT_" << out << "[color=\"red2\" style=\"filled\" fillcolor=\"pink\"];" << endl;
        fout << 'S' << hd(L) << " -> " << "OUTPUT_" << out++ << "[" << edgeattr(getCertifiedSigType(hd(L))) << "];" << endl;
        L = tl(L);
    }

    fout << "}" << endl;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* binopname[] [static]
Initial value:
 {
        "+", "-", "*", "/", "%",
        "<<", ">>",
        ">", "<", ">=", "<=", "==", "!=",
        "&", "|", "^"
}

translate signal binary operations into strings

Definition at line 171 of file sigToGraph.cpp.

Referenced by sigLabel().