Annotate a signal expression with recursivness information. More...
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "recursivness.hh"
Go to the source code of this file.
Functions | |
static int | annotate (Tree env, Tree sig) |
Annotate a signal with recursivness. | |
static int | position (Tree env, Tree t, int p) |
return the position of a signal in the current recursive environment | |
void | recursivnessAnnotation (Tree sig) |
Annotate a signal with recursivness. | |
int | getRecursivness (Tree sig) |
Return the recursivness of a previously annotated signal. |
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.
Annotate a signal with recursivness.
env | the current environment | |
sig | signal to annotate |
Definition at line 81 of file recursivness.cpp.
References position().
Referenced by recursivnessAnnotation().
00082 { 00083 Tree tr, var, body; 00084 00085 if (getProperty(sig, RECURSIVNESS, tr)) { 00086 return tree2int(tr); // already annotated 00087 } else if (isRec(sig, var, body)) { 00088 int p = position(env, sig); 00089 if (p > 0) { 00090 return p; // we are inside \x.(...) 00091 } else { 00092 int r = annotate(cons(sig, env), body) - 1; 00093 if (r<0) r=0; 00094 setProperty(sig, RECURSIVNESS, tree(r)); 00095 return r; 00096 } 00097 } else { 00098 int rmax = 0; 00099 vector<Tree> v; getSubSignals(sig, v); 00100 for (unsigned int i=0; i<v.size(); i++) { 00101 int r = annotate(env, v[i]); 00102 if (r>rmax) rmax=r; 00103 } 00104 setProperty(sig, RECURSIVNESS, tree(rmax)); 00105 return rmax; 00106 } 00107 }
int getRecursivness | ( | Tree | sig | ) |
Return the recursivness of a previously annotated signal.
An error is generated if the signal has no recursivness property
sig | signal |
Definition at line 64 of file recursivness.cpp.
Referenced by OccMarkup::incOcc().
00065 { 00066 Tree tr; 00067 if ( ! getProperty(sig, RECURSIVNESS, tr)) { 00068 cerr << "Error in getRecursivness of " << *sig << endl; 00069 exit(1); 00070 } 00071 return tree2int(tr); 00072 }
return the position of a signal in the current recursive environment
env | the current recursive environment of the signal | |
t | signal we want to know the position |
Definition at line 117 of file recursivness.cpp.
Referenced by annotate().
00118 { 00119 if (isNil(env)) return 0; // was not in the environment 00120 if (hd(env) == t) return p; 00121 else return position (tl(env), t, p+1); 00122 }
void recursivnessAnnotation | ( | Tree | sig | ) |
Annotate a signal with recursivness.
Should be used before calling getRecursivness
sig | signal to annotate |
Definition at line 51 of file recursivness.cpp.
References annotate().
00052 { 00053 annotate(nil, sig); 00054 }