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

Uses colors to analyze dependencies among sub expressions. More...

#include "colorize.h"
#include "signals.hh"
Include dependency graph for colorize.cpp:

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"))

Detailed Description

Uses colors to analyze dependencies among sub expressions.

Definition in file colorize.cpp.


Function Documentation

void addColor ( Tree  exp,
int  color 
) [static]

a color to the colors of exp

Add a color to the colorset of exp.

Create an empty coloset if needed.

Parameters:
sigthe signal we want to color
colorthe 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);
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
}

Here is the caller graph for this function:

static void clearColors ( Tree  exp) [static]

remove the color property of exp

Count the number of colors of exp.

Parameters:
expthe expression we want to count the colors
Returns:
the number of elements in the color set or 0

Definition at line 203 of file colorize.cpp.

References getColorProperty().

Referenced by uncolorize().

{
    set<int>* cset = getColorProperty(exp);
    if (cset != 0) {
        cset->clear();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void colorize ( Tree  exp,
int  color 
) [static]

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);
    }   
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int colorsCount ( Tree  exp) [static]

returns the number of colors of exp

Count the number of colors of exp.

Parameters:
expthe expression we want to count the colors
Returns:
the number of elements in the color set or 0

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();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

set<int>* getColorProperty ( Tree  sig)

retrieve the color-set property of sig

Parameters:
sigthe 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);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool hasColor ( Tree  exp,
int  color 
) [static]

true if exp is already colored with color

Test if exp as color in its colorset.

Parameters:
sigthe signal we want to test
colorthe color to test
Returns:
true if color is member of the colorset of sig

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();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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);
        }
    }   
}

Here is the call graph for this function:

Here is the caller graph for this function:

void setColorProperty ( Tree  sig,
set< int > *  colorset 
)

set the color-set property of sig

Parameters:
sigthe signal we want to type
tthe 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));
}

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
expsset of expressions to analyze
postresulting set of post expressions
preresulting 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);
    }
}

Here is the call graph for this function:

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]);
    }   
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Tree COLORPROPERTY = tree(symbol("ColorProperty"))

Definition at line 118 of file colorize.cpp.

Referenced by getColorProperty(), and setColorProperty().