|
FAUST compiler
0.9.9.6b8
|
Uses colors to analyze dependencies among sub expressions. More...

Go to the source code of this file.
Functions | |
| static int | allocateColor (Tree exp) |
| allocate a new unique color for exp | |
| static void | colorize (Tree exp, int color) |
| add color information to exp and all its subtrees | |
| static void | uncolorize (Tree exp) |
| remove color information | |
| static void | listMultiColoredExp (Tree exp, set< Tree > &lst) |
| list multicolored subexpressions of exp | |
| void | splitDependance (const set< Tree > &exps, set< Tree > &post, set< Tree > &pre) |
| Analyze a set of expressions to discover its dependencies that is subexpressions common to at least two of these expressions. | |
| static void | addColor (Tree exp, int color) |
| a color to the colors of exp | |
| static bool | hasColor (Tree exp, int color) |
| true if exp is already colored with color | |
| static int | colorsCount (Tree exp) |
| returns the number of colors of exp | |
| static void | clearColors (Tree exp) |
| remove the color property of exp | |
| void | setColorProperty (Tree sig, set< int > *colorset) |
| set the color-set property of sig | |
| set< int > * | getColorProperty (Tree sig) |
| retrieve the color-set property of sig | |
Variables | |
| Tree | COLORPROPERTY = tree(symbol("ColorProperty")) |
Uses colors to analyze dependencies among sub expressions.
Definition in file colorize.cpp.
a color to the colors of exp
Add a color to the colorset of exp.
Create an empty coloset if needed.
| sig | the signal we want to color |
| color | the color used |
Definition at line 154 of file colorize.cpp.
References getColorProperty(), and setColorProperty().
Referenced by colorize().
{
set<int>* cset = getColorProperty(exp);
if (cset == 0) {
cset = new set<int>();
setColorProperty(exp, cset);
}
cset->insert(color);
}


| int allocateColor | ( | Tree | exp | ) | [static] |
allocate a new unique color for exp
Allocate a unique color (an integer) for an expression.
by converting its address into an integer
Definition at line 59 of file colorize.cpp.
Referenced by splitDependance().
{
// return int(exp);
static map<Tree,int> colorMap;
static int nextFreeColor = 1;
int& color = colorMap[exp];
if (!color)
color = nextFreeColor++;
return color;
}

| static void clearColors | ( | Tree | exp | ) | [static] |
remove the color property of exp
Count the number of colors of exp.
| exp | the expression we want to count the colors |
Definition at line 203 of file colorize.cpp.
References getColorProperty().
Referenced by uncolorize().
{
set<int>* cset = getColorProperty(exp);
if (cset != 0) {
cset->clear();
}
}


add color information to exp and all its subtrees
Add a color to all the expression tree.
Definition at line 73 of file colorize.cpp.
References addColor(), getSubSignals(), and hasColor().
Referenced by splitDependance().
{
if (! hasColor(exp, color)) {
addColor(exp, color);
vector<Tree> v;
int n = getSubSignals(exp, v, false);
for (int i=0; i<n; i++) colorize(v[i], color);
}
}


| static int colorsCount | ( | Tree | exp | ) | [static] |
returns the number of colors of exp
Count the number of colors of exp.
| exp | the expression we want to count the colors |
Definition at line 187 of file colorize.cpp.
References getColorProperty().
Referenced by listMultiColoredExp(), and uncolorize().
{
set<int>* cset = getColorProperty(exp);
if (cset==0) {
return 0;
} else {
return cset->size();
}
}


| set<int>* getColorProperty | ( | Tree | sig | ) |
retrieve the color-set property of sig
| sig | the signal we want to know the color-set property |
Definition at line 135 of file colorize.cpp.
References COLORPROPERTY, getProperty(), and tree2ptr().
Referenced by addColor(), clearColors(), colorsCount(), and hasColor().
{
Tree tt;
if (!getProperty(sig, COLORPROPERTY, tt)) {
return 0;
} else {
return (set<int>*)tree2ptr(tt);
}
}


true if exp is already colored with color
Test if exp as color in its colorset.
| sig | the signal we want to test |
| color | the color to test |
Definition at line 171 of file colorize.cpp.
References getColorProperty().
Referenced by colorize().
{
set<int>* cset = getColorProperty(exp);
if (cset==0) {
return false;
} else {
return cset->find(color) != cset->end();
}
}


| void listMultiColoredExp | ( | Tree | exp, |
| set< Tree > & | lst | ||
| ) | [static] |
list multicolored subexpressions of exp
Make a set of the multicolored sub-expressions.
Definition at line 99 of file colorize.cpp.
References colorsCount(), and getSubSignals().
Referenced by splitDependance().
{
assert(colorsCount(exp) > 0);
if (colorsCount(exp) > 1) {
// we have found a multicolored expression
lst.insert(exp);
} else {
// it is a monocolored expression
// we search its subexpressions
vector<Tree> v;
int n = getSubSignals(exp, v, false);
for (int i=0; i<n; i++) {
listMultiColoredExp(v[i], lst);
}
}
}


| void setColorProperty | ( | Tree | sig, |
| set< int > * | colorset | ||
| ) |
set the color-set property of sig
| sig | the signal we want to type |
| t | the type of the signal |
Definition at line 125 of file colorize.cpp.
References COLORPROPERTY, setProperty(), and tree().
Referenced by addColor().
{
setProperty(sig, COLORPROPERTY, tree((void*)colorset));
}


| void splitDependance | ( | const set< Tree > & | exps, |
| set< Tree > & | post, | ||
| set< Tree > & | pre | ||
| ) |
Analyze a set of expressions to discover its dependencies that is subexpressions common to at least two of these expressions.
| exps | set of expressions to analyze |
| post | resulting set of post expressions |
| pre | resulting set of pre expressions |
Definition at line 28 of file colorize.cpp.
References allocateColor(), colorize(), listMultiColoredExp(), and uncolorize().
{
set<Tree>::const_iterator e;
for (e= exps.begin(); e != exps.end(); e++) {
colorize(*e, allocateColor(*e));
}
pre.clear();
for (e = exps.begin(); e != exps.end(); e++) {
listMultiColoredExp(*e, pre);
}
post.clear();
set_difference(exps.begin(), exps.end(), pre.begin(), pre.end(), inserter(post, post.begin()));
for (e = exps.begin(); e != exps.end(); e++) {
uncolorize(*e);
}
}

| void uncolorize | ( | Tree | exp | ) | [static] |
remove color information
Remove the colors of an expression tree.
Definition at line 86 of file colorize.cpp.
References clearColors(), colorsCount(), and getSubSignals().
Referenced by splitDependance().
{
if (colorsCount(exp) > 0) {
clearColors(exp);
vector<Tree> v;
int n = getSubSignals(exp, v, false);
for (int i=0; i<n; i++) uncolorize(v[i]);
}
}


| Tree COLORPROPERTY = tree(symbol("ColorProperty")) |
Definition at line 118 of file colorize.cpp.
Referenced by getColorProperty(), and setColorProperty().
1.8.0