FAUST compiler  0.9.9.6b8
Functions | Variables
recursivness.cpp File Reference

Annotate a signal expression with recursivness information. More...

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "recursivness.hh"
#include "property.hh"
#include "signals.hh"
#include "ppsig.hh"
#include "set"
Include dependency graph for recursivness.cpp:

Go to the source code of this file.

Functions

static int annotate (Tree env, Tree sig)
 Annotate a signal with recursivness. More...
 
static int position (Tree env, Tree t, int p)
 return the position of a signal in the current recursive environment More...
 
void recursivnessAnnotation (Tree sig)
 Annotate a signal with recursivness. More...
 
int getRecursivness (Tree sig)
 Return the recursivness of a previously annotated signal. More...
 
Tree symlistVisit (Tree sig, set< Tree > &visited)
 
Tree symlist (Tree sig)
 

Variables

Tree RECURSIVNESS = tree(symbol("RecursivnessProp"))
 
property< TreeSymListProp
 return the set of recursive symbols appearing in a signal. More...
 

Detailed Description

Annotate a signal expression with recursivness information.

Recursiveness indicates the amount of recursive dependencies of a signal. A closed signal has a recursivness of 0 because is has no recursive dependencies. This means that the succesive samples of this signal can be computed in parallel. In a signal of type .(...F(x)...), F(x) has a recursivness of 1. In a signal of type .(... .(...F(x)...G(y)...)...) F(x) has a recursivness of 2 while G(y) has a recursivness of 1.

Definition in file recursivness.cpp.

Function Documentation

static int annotate ( Tree  env,
Tree  sig 
)
static

Annotate a signal with recursivness.

Parameters
envthe current environment
sigsignal to annotate
Returns
recursivness of the signal

Definition at line 89 of file recursivness.cpp.

References cons(), getProperty(), getSubSignals(), isRec(), position(), RECURSIVNESS, setProperty(), tree(), and tree2int().

Referenced by recursivnessAnnotation().

90 {
91  Tree tr, var, body;
92 
93  if (getProperty(sig, RECURSIVNESS, tr)) {
94  return tree2int(tr); // already annotated
95  } else if (isRec(sig, var, body)) {
96  int p = position(env, sig);
97  if (p > 0) {
98  return p; // we are inside \x.(...)
99  } else {
100  int r = annotate(cons(sig, env), body) - 1;
101  if (r<0) r=0;
102  setProperty(sig, RECURSIVNESS, tree(r));
103  return r;
104  }
105  } else {
106  int rmax = 0;
107  vector<Tree> v; getSubSignals(sig, v);
108  for (unsigned int i=0; i<v.size(); i++) {
109  int r = annotate(env, v[i]);
110  if (r>rmax) rmax=r;
111  }
112  setProperty(sig, RECURSIVNESS, tree(rmax));
113  return rmax;
114  }
115 }
static int position(Tree env, Tree t, int p=1)
return the position of a signal in the current recursive environment
Tree cons(Tree a, Tree b)
Definition: list.hh:124
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
static int annotate(Tree env, Tree sig)
Annotate a signal with recursivness.
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree tree(const Node &n)
Definition: tree.hh:186
Tree RECURSIVNESS
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
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
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

int getRecursivness ( Tree  sig)

Return the recursivness of a previously annotated signal.

An error is generated if the signal has no recursivness property

Parameters
sigsignal
Returns
recursivness of the signal

Definition at line 72 of file recursivness.cpp.

References getProperty(), RECURSIVNESS, and tree2int().

Referenced by OccMarkup::incOcc().

73 {
74  Tree tr;
75  if ( ! getProperty(sig, RECURSIVNESS, tr)) {
76  cerr << "Error in getRecursivness of " << *sig << endl;
77  exit(1);
78  }
79  return tree2int(tr);
80 }
int tree2int(Tree t)
if t has a node of type int, return it otherwise error
Definition: tree.cpp:230
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree RECURSIVNESS
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

static int position ( Tree  env,
Tree  t,
int  p 
)
static

return the position of a signal in the current recursive environment

Parameters
envthe current recursive environment of the signal
tsignal we want to know the position
Returns
the position in the recursive environment

Definition at line 125 of file recursivness.cpp.

References hd(), isNil(), and tl().

Referenced by annotate().

126 {
127  if (isNil(env)) return 0; // was not in the environment
128  if (hd(env) == t) return p;
129  else return position (tl(env), t, p+1);
130 }
static int position(Tree env, Tree t, int p=1)
return the position of a signal in the current recursive environment
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

void recursivnessAnnotation ( Tree  sig)

Annotate a signal with recursivness.

Should be used before calling getRecursivness

Parameters
sigsignal to annotate

Definition at line 59 of file recursivness.cpp.

References annotate(), and nil.

Referenced by DocCompiler::annotate(), ScalarCompiler::prepare(), and ScalarCompiler::prepare2().

60 {
61  annotate(nil, sig);
62 }
static int annotate(Tree env, Tree sig)
Annotate a signal with recursivness.
Tree nil
Definition: list.cpp:116

Here is the call graph for this function:

Here is the caller graph for this function:

Tree symlist ( Tree  sig)

Definition at line 174 of file recursivness.cpp.

References property< Tree >::get(), property< Tree >::set(), SymListProp, and symlistVisit().

Referenced by Klass::closeLoop(), and typeAnnotation().

175 {
176  Tree S;
177  if (!SymListProp.get(sig, S)) {
178  set<Tree> visited;
179  S = symlistVisit(sig, visited);
180  SymListProp.set(sig, S);
181  }
182  //cerr << "SYMLIST " << *S << " OF " << ppsig(sig) << endl;
183  return S;
184 }
Tree symlistVisit(Tree sig, set< Tree > &visited)
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool get(Tree t, Tree &data)
Definition: property.hh:67
property< Tree > SymListProp
return the set of recursive symbols appearing in a signal.
void set(Tree t, Tree data)
Definition: property.hh:62

Here is the call graph for this function:

Here is the caller graph for this function:

Tree symlistVisit ( Tree  sig,
set< Tree > &  visited 
)

Definition at line 146 of file recursivness.cpp.

References property< Tree >::get(), getSubSignals(), isRec(), len(), nil, nth(), setUnion(), singleton(), and SymListProp.

Referenced by symlist().

147 {
148  Tree S;
149  if (SymListProp.get(sig, S)) {
150  return S;
151  } else if ( visited.count(sig) > 0 ){
152  return nil;
153  } else {
154  visited.insert(sig);
155  Tree id, body;
156  if (isRec(sig, id, body)) {
157  Tree U = singleton(sig);
158  for (int i=0; i<len(body); i++) {
159  U = setUnion(U, symlistVisit(nth(body,i), visited));
160  }
161  return U;
162  } else {
163  vector<Tree> subsigs;
164  int n = getSubSignals(sig, subsigs, true); // il faut visiter aussi les tables
165  Tree U = nil;
166  for (int i=0; i<n; i++) {
167  U = setUnion(U, symlistVisit(subsigs[i], visited));
168  }
169  return U;
170  }
171  }
172 }
Tree symlistVisit(Tree sig, set< Tree > &visited)
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
bool get(Tree t, Tree &data)
Definition: property.hh:67
Tree setUnion(Tree A, Tree B)
Definition: list.cpp:317
Tree singleton(Tree e)
Definition: list.cpp:302
property< Tree > SymListProp
return the set of recursive symbols appearing in a signal.
bool isRec(Tree t, Tree &body)
is t a de Bruijn recursive tree
Tree nil
Definition: list.cpp:116
int len(Tree l)
Definition: list.cpp:198
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
Tree nth(Tree l, int i)
Definition: list.cpp:182

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

Tree RECURSIVNESS = tree(symbol("RecursivnessProp"))

Definition at line 50 of file recursivness.cpp.

Referenced by annotate(), and getRecursivness().

property<Tree> SymListProp

return the set of recursive symbols appearing in a signal.

Parameters
sigthe signal to analyze
Returns
the set of symbols

Definition at line 144 of file recursivness.cpp.

Referenced by symlist(), and symlistVisit().