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

Variables

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

Function Documentation

static string edgeattr ( Type  t)
static

Convert a signal type into edge attributes.

Definition at line 131 of file sigToGraph.cpp.

References kInt, kSamp, and kVect.

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

132 {
133  string s;
134 
135  // nature
136  if (t->nature()==kInt) {
137  s += " color=\"blue\"";
138  } else {
139  s += " color=\"red\"";
140  }
141 
142  // vectorability
143  if (t->vectorability()==kVect && t->variability()==kSamp) {
144  s += " style=\"bold\"";
145  }
146  return s;
147 }
Definition: sigtype.hh:58
Definition: sigtype.hh:54
Definition: sigtype.hh:56

Here is the caller graph for this function:

static string nodeattr ( Type  t)
static

Convert a signal type into node attributes.

Definition at line 153 of file sigToGraph.cpp.

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

Referenced by recdraw().

154 {
155  string s = edgeattr(t);
156 
157  // variability
158  if (t->variability()==kKonst) {
159  s += " shape=\"box\"";
160  } else if (t->variability()==kBlock) {
161  s += " shape=\"hexagon\"";
162  } else if (t->variability()==kSamp) {
163  s += " shape=\"ellipse\"";
164  }
165 
166  return s;
167 }
static string edgeattr(Type t)
Convert a signal type into edge attributes.
Definition: sigToGraph.cpp:131
Definition: sigtype.hh:56

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().

77 {
78  //cerr << ++TABBER << "ENTER REC DRAW OF " << sig << "$" << *sig << endl;
79  vector<Tree> subsig;
80  int n;
81 
82  if (drawn.count(sig) == 0) {
83  drawn.insert(sig);
84  if (isList(sig)) {
85  do {
86  recdraw(hd(sig), drawn, fout);
87  sig = tl(sig);
88  } while (isList(sig));
89  } else {
90  // draw the node
91  fout << 'S' << sig << "[label=\"" << sigLabel(sig) << "\""
92  << nodeattr(getCertifiedSigType(sig)) << "];"
93  << endl;
94 
95  // draw the subsignals
96  n = getSubSignals(sig, subsig);
97  if (n > 0) {
98  if (n==1 && isList(subsig[0])) {
99  Tree id, body;
100  assert(isRec(sig,id,body));
101  if (!isRec(sig,id,body)) {
102  }
103  // special recursion case, recreate a vector of subsignals instead of the
104  // list provided by getSubSignal
105  Tree L = subsig[0];
106  subsig.clear();
107  n = 0;
108  do {
109  subsig.push_back(hd(L));
110  L = tl(L);
111  n += 1;
112  } while (isList(L));
113  }
114 
115  for (int i=0; i<n; i++) {
116  recdraw(subsig[i], drawn, fout);
117  fout << 'S' << subsig[i] << " -> " << 'S' << sig
118  << "[" << edgeattr(getCertifiedSigType(subsig[i])) << "];"
119  << endl;
120  }
121  }
122  }
123  }
124  //cerr << --TABBER << "EXIT REC DRAW OF " << sig << endl;
125 }
static string sigLabel(Tree sig)
return the label of a signal as a string
Definition: sigToGraph.cpp:184
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
static string edgeattr(Type t)
Convert a signal type into edge attributes.
Definition: sigToGraph.cpp:131
static void recdraw(Tree sig, set< Tree > &drawn, ofstream &fout)
Draw recursively a signal.
Definition: sigToGraph.cpp:76
bool isList(Tree l)
Definition: list.hh:138
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
static string nodeattr(Type t)
Convert a signal type into node attributes.
Definition: sigToGraph.cpp:153
Tree tl(Tree l)
Definition: list.hh:134
int getSubSignals(Tree sig, vector< Tree > &vsigs, bool visitgen=true)
Extract the sub signals of a signal expression, that is not necesseraly all the subtrees.
Definition: subsignals.cpp:12

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 184 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(), isSigWaveform(), isSigWRTbl(), xtended::name(), and name().

Referenced by recdraw().

185 {
186  int i;
187  double r;
188  Tree x, y, z, c, type, name, file, ff, largs, id, le, sel, var, label;
189 
190  xtended* p = (xtended*) getUserData(sig);
191 
192  stringstream fout;
193 
194  if (p) { fout << p->name(); }
195  else if ( isSigInt(sig, &i) ) { fout << i; }
196  else if ( isSigReal(sig, &r) ) { fout << r; }
197  else if ( isSigWaveform(sig)) { fout << "waveform"; }
198 
199  else if ( isSigInput(sig, &i) ) { fout << "INPUT_" << i; }
200  else if ( isSigOutput(sig, &i, x) ) { fout << "OUTPUT_" << i; }
201 
202  else if ( isSigDelay1(sig, x) ) { fout << "mem"; }
203  else if ( isSigFixDelay(sig, x, y) ) { fout << "@"; }
204  else if ( isSigPrefix(sig, x, y) ) { fout << "prefix"; }
205  else if ( isSigIota(sig, x) ) { fout << "iota"; }
206  else if ( isSigBinOp(sig, &i, x, y) ) { fout << binopname[i]; }
207  else if ( isSigFFun(sig, ff, largs) ) { fout << "ffunction:" << *ff; }
208  else if ( isSigFConst(sig, type, name, file) ) { fout << *name; }
209  else if ( isSigFVar(sig, type, name, file) ) { fout << *name; }
210 
211  else if ( isSigTable(sig, id, x, y) ) { fout << "table:" << id; }
212  else if ( isSigWRTbl(sig, id, x, y, z) ) { fout << "write:" << id; }
213  else if ( isSigRDTbl(sig, x, y) ) { fout << "read"; }
214 
215 
216 
217  else if ( isSigSelect2(sig, sel, x, y) ) { fout << "select2"; }
218  else if ( isSigSelect3(sig, sel, x, y, z) ) { fout << "select3"; }
219 
220  else if ( isSigGen(sig, x) ) { fout << "generator"; }
221 
222  else if ( isProj(sig, &i, x) ) { fout << "Proj" << i; }
223  else if ( isRec(sig, var, le) ) { fout << "REC " << *var; }
224 
225  else if ( isSigIntCast(sig, x) ) { fout << "int"; }
226  else if ( isSigFloatCast(sig, x) ) { fout << "float"; }
227 #if 0
228  else if ( isSigButton(sig, label) ) { fout << "button \"" << *label << '"'; }
229  else if ( isSigCheckbox(sig, label) ) { fout << "checkbox \"" << *label << '"'; }
230  else if ( isSigVSlider(sig, label,c,x,y,z) ) { fout << "vslider \"" << *label << '"'; }
231  else if ( isSigHSlider(sig, label,c,x,y,z) ) { fout << "hslider \"" << *label << '"'; }
232  else if ( isSigNumEntry(sig, label,c,x,y,z) ) { fout << "nentry \"" << *label << '"'; }
233 
234  else if ( isSigVBargraph(sig, label,x,y,z) ) { fout << "vbargraph \"" << *label << '"'; }
235  else if ( isSigHBargraph(sig, label,x,y,z) ) { fout << "hbargraph \"" << *label << '"'; }
236 #else
237  else if ( isSigButton(sig, label) ) { fout << "button"; }
238  else if ( isSigCheckbox(sig, label) ) { fout << "checkbox"; }
239  else if ( isSigVSlider(sig, label,c,x,y,z) ) { fout << "vslider"; }
240  else if ( isSigHSlider(sig, label,c,x,y,z) ) { fout << "hslider"; }
241  else if ( isSigNumEntry(sig, label,c,x,y,z) ) { fout << "nentry"; }
242 
243  else if ( isSigVBargraph(sig, label,x,y,z) ) { fout << "vbargraph"; }
244  else if ( isSigHBargraph(sig, label,x,y,z) ) { fout << "hbargraph"; }
245 #endif
246  else if ( isSigAttach(sig, x, y) ) { fout << "attach"; }
247 
248  else {
249  cerr << "ERROR, unrecognized signal : " << *sig << endl;
250  exit(1);
251  }
252 
253  return fout.str();
254 }
bool isSigHSlider(Tree s)
Definition: signals.cpp:217
bool isSigRDTbl(Tree s, Tree &t, Tree &i)
Definition: signals.cpp:77
bool isSigFConst(Tree s)
Definition: signals.cpp:138
bool isSigPrefix(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:66
bool isSigCheckbox(Tree s)
Definition: signals.cpp:205
bool isSigFFun(Tree s, Tree &ff, Tree &largs)
Definition: signals.cpp:133
bool isSigNumEntry(Tree s)
Definition: signals.cpp:257
bool isSigSelect2(Tree t, Tree &selector, Tree &s1, Tree &s2)
Definition: signals.cpp:116
bool isSigIota(Tree t, Tree &t0)
Definition: signals.cpp:70
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool isSigInput(Tree t, int *i)
Definition: signals.cpp:48
bool isSigFixDelay(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:62
const char * name()
Definition: xtended.hh:25
bool isSigVBargraph(Tree s)
Definition: signals.cpp:285
bool isSigSelect3(Tree t, Tree &selector, Tree &s1, Tree &s2, Tree &s3)
Definition: signals.cpp:119
bool isSigVSlider(Tree s)
Definition: signals.cpp:237
bool isSigGen(Tree t, Tree &x)
Definition: signals.cpp:91
static const char * binopname[]
translate signal binary operations into strings
Definition: sigToGraph.cpp:173
bool isSigReal(Tree t, double *r)
Definition: signals.cpp:44
bool isSigHBargraph(Tree s)
Definition: signals.cpp:279
bool isSigTable(Tree t, Tree &id, Tree &n, Tree &sig)
Definition: signals.cpp:85
bool isSigBinOp(Tree s, int *op, Tree &x, Tree &y)
Definition: signals.cpp:126
bool isSigAttach(Tree t, Tree &t0, Tree &t1)
Definition: signals.cpp:291
bool isSigWRTbl(Tree u, Tree &id, Tree &t, Tree &i, Tree &s)
Definition: signals.cpp:81
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
bool isSigWaveform(Tree s)
Definition: signals.cpp:211
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
bool isSigInt(Tree t, int *i)
Definition: signals.cpp:41
bool isSigDelay1(Tree t, Tree &t0)
Definition: signals.cpp:58
bool isSigFloatCast(Tree t)
Definition: signals.cpp:187
bool isSigFVar(Tree s)
Definition: signals.cpp:144
void * getUserData(Symbol *sym)
Returns user data.
Definition: symbol.hh:100
bool isSigIntCast(Tree t)
Definition: signals.cpp:184
bool isProj(Tree t, int *i, Tree &rgroup)
Definition: signals.cpp:151
bool isSigOutput(Tree t, int *i, Tree &t0)
Definition: signals.cpp:52
bool isSigButton(Tree s)
Definition: signals.cpp:199

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().

51 {
52  set<Tree> alreadyDrawn;
53 
54  fout << "strict digraph loopgraph {\n"
55  << " rankdir=LR; node [fontsize=10];"
56  << endl;
57  int out = 0;
58  while (isList(L)) {
59  recdraw(hd(L), alreadyDrawn, fout);
60 
61  fout << "OUTPUT_" << out << "[color=\"red2\" style=\"filled\" fillcolor=\"pink\"];" << endl;
62  fout << 'S' << hd(L) << " -> " << "OUTPUT_" << out++ << "[" << edgeattr(getCertifiedSigType(hd(L))) << "];" << endl;
63  L = tl(L);
64  }
65 
66  fout << "}" << endl;
67 }
Tree hd(Tree l)
Definition: list.hh:133
static string edgeattr(Type t)
Convert a signal type into edge attributes.
Definition: sigToGraph.cpp:131
static void recdraw(Tree sig, set< Tree > &drawn, ofstream &fout)
Draw recursively a signal.
Definition: sigToGraph.cpp:76
bool isList(Tree l)
Definition: list.hh:138
Type getCertifiedSigType(Tree sig)
Retrieve the type of sig and check it exists.
Tree tl(Tree l)
Definition: list.hh:134

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 173 of file sigToGraph.cpp.

Referenced by sigLabel().