FAUST compiler  0.9.9.6b8
Functions | Variables
simplify.cpp File Reference
#include <stdio.h>
#include <assert.h>
#include "list.hh"
#include "signals.hh"
#include "sigtype.hh"
#include "recursivness.hh"
#include "sigtyperules.hh"
#include "sigorderrules.hh"
#include "sigprint.hh"
#include "ppsig.hh"
#include "simplify.hh"
#include "num.hh"
#include "xtended.hh"
#include <map>
#include "compatibility.hh"
#include "normalize.hh"
Include dependency graph for simplify.cpp:

Go to the source code of this file.

Functions

static Tree simplification (Tree sig)
static Tree sigMap (Tree key, tfun f, Tree t)
 Recursively transform a graph by applying a function f.
static Tree traced_simplification (Tree sig)
Tree simplify (Tree sig)
static Tree sigMapRename (Tree key, Tree env, tfun f, Tree t)
 Like SigMap, recursively transform a graph by applying a function f.
static Tree docTableConverter (Tree sig)
Tree docTableConvertion (Tree sig)

Variables

Tree SIMPLIFIED = tree(symbol("sigSimplifiedProp"))
Tree DOCTABLES = tree(symbol("DocTablesProp"))
 Converts regular tables into doc tables in order to facilitate the mathematical documentation generation.
static Tree NULLENV = tree(symbol("NullRenameEnv"))

Function Documentation

static Tree docTableConverter ( Tree  sig) [static]

Definition at line 356 of file simplify.cpp.

References isSigGen(), isSigRDTbl(), isSigTable(), isSigWRTbl(), sigDocAccessTbl(), sigDocConstantTbl(), and sigDocWriteTbl().

Referenced by docTableConvertion().

{
    Tree tbl, tbl2, id, id2, size, igen, isig, ridx, widx, wsig;

    if (isSigRDTbl(sig, tbl, ridx)) {
        // we are in a table to convert
        if (isSigTable(tbl, id, size, igen)) {
            // it's a read only table
            assert(isSigGen(igen, isig));
            return sigDocAccessTbl(sigDocConstantTbl(size,isig),ridx);
        } else {
            // it's a read write table
            assert(isSigWRTbl(tbl,id,tbl2,widx,wsig));
            assert(isSigTable(tbl2, id2, size, igen));
            assert(isSigGen(igen, isig));

            return sigDocAccessTbl(sigDocWriteTbl(size,isig,widx,wsig),ridx);
        }

    } else {
        // nothing to convert
        return sig;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 347 of file simplify.cpp.

References docTableConverter(), and sigMapRename().

Referenced by mapPrepareEqSig().

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree sigMap ( Tree  key,
tfun  f,
Tree  t 
) [static]

Recursively transform a graph by applying a function f.

map(f, foo[t1..tn]) = f(foo[map(f,t1)..map(f,tn)])

Definition at line 187 of file simplify.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), isRec(), nil, CTree::node(), rec(), setProperty(), and tree().

Referenced by simplify().

{
    //printf("start sigMap\n");
    Tree p,id,body;

    if (getProperty(t, key, p)) {

        return (isNil(p)) ? t : p;  // truc pour eviter les boucles

    } else if (isRec(t, id, body)) {

        setProperty(t, key, nil);   // avoid infinite loop
        return rec(id, sigMap(key, f, body));

    } else {

        Tree r1=nil;
        switch (t->arity()) {

            case 0 :
                r1 = t;
                break;
            case 1 :
                r1 = tree(t->node(), sigMap(key,f,t->branch(0)));
                break;
            case 2 :
                r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)));
                break;
            case 3 :
                r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)),
                                           sigMap(key,f,t->branch(2)));
                break;
            case 4 :
                r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)),
                                           sigMap(key,f,t->branch(2)), sigMap(key,f,t->branch(3)));
                break;
        }
        Tree r2 = f(r1);
        if (r2 == t) {
            setProperty(t, key, nil);
        } else {
            setProperty(t, key, r2);
        }
        return r2;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree sigMapRename ( Tree  key,
Tree  env,
tfun  f,
Tree  t 
) [static]

Like SigMap, recursively transform a graph by applying a function f.

But here recursive trees are also renamed. map(f, foo[t1..tn]) = f(foo[map(f,t1)..map(f,tn)])

Definition at line 243 of file simplify.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), isRec(), isRef(), nil, CTree::node(), pushEnv(), rec(), ref(), searchEnv(), setProperty(), tree(), and unique().

Referenced by docTableConvertion().

{
    //printf("start sigMap\n");
    Tree p,id,body;

    if (getProperty(t, key, p)) {

        return (isNil(p)) ? t : p;  // truc pour eviter les boucles

    } else if (isRec(t, id, body)) {

        assert(isRef(t,id)); // controle temporaire

        Tree id2;
        if (searchEnv(id, id2, env)) {
            // déjà en cours de visite de cette recursion
            return ref(id2);
        } else {
            // premiere visite de cette recursion
            id2 = tree(Node(unique("renamed")));
            Tree body2 = sigMapRename(key, pushEnv(id, id2, env), f, body);
            return rec(id2,body2);
        }

    } else {

        Tree r1=nil;
        switch (t->arity()) {

            case 0 :
                r1 = t;
                break;
            case 1 :
                r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)));
                break;
            case 2 :
                r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
                                        sigMapRename(key,env,f,t->branch(1)));
                break;
            case 3 :
                r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
                                        sigMapRename(key,env,f,t->branch(1)),
                                        sigMapRename(key,env,f,t->branch(2)));
                break;
            case 4 :
                r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
                                        sigMapRename(key,env,f,t->branch(1)),
                                        sigMapRename(key,env,f,t->branch(2)),
                                        sigMapRename(key,env,f,t->branch(3)));
                break;
        }
        Tree r2 = f(r1);
        if (r2 == t) {
            setProperty(t, key, nil);
        } else {
            setProperty(t, key, r2);
        }
        return r2;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree simplification ( Tree  sig) [static]

Definition at line 84 of file simplify.cpp.

References CTree::arity(), CTree::branch(), BinOp::compute(), xtended::computeSigOutput(), gBinOpTable, getUserData(), gPowPrim, isDouble(), isInt(), BinOp::isLeftNeutral(), isNum(), isOne(), BinOp::isRightNeutral(), isSigBinOp(), isSigDelay1(), isSigFixDelay(), isSigFloatCast(), isSigIntCast(), isSigSelect2(), isSigSelect3(), isZero(), CTree::node(), normalizeAddTerm(), normalizeDelay1Term(), normalizeFixedDelayTerm(), sigSelect2(), and tree().

Referenced by traced_simplification().

{
    assert(sig);
    int     opnum;
    Tree    t1, t2, t3, t4;

    xtended* xt = (xtended*) getUserData(sig);
    // primitive elements
    if (xt)
    {
        //return 3;
        vector<Tree> args;
        for (int i=0; i<sig->arity(); i++) { args.push_back( sig->branch(i) ); }

        // to avoid negative power to further normalization
        if (xt != gPowPrim) {
            return xt->computeSigOutput(args);
        } else {
            return normalizeAddTerm(xt->computeSigOutput(args));
        }

    } else if (isSigBinOp(sig, &opnum, t1, t2)) {

        BinOp* op = gBinOpTable[opnum];

        Node n1 = t1->node();
        Node n2 = t2->node();

        if (isNum(n1) && isNum(n2))         return tree(op->compute(n1,n2));

        else if (op->isLeftNeutral(n1))     return t2;

        else if (op->isRightNeutral(n2))    return t1;

        else                                return normalizeAddTerm(sig);

    } else if (isSigDelay1(sig, t1)) {

        return normalizeDelay1Term (t1);

    } else if (isSigFixDelay(sig, t1, t2)) {

        return normalizeFixedDelayTerm (t1, t2);

    } else if (isSigIntCast(sig, t1)) {

        Tree    tx;
        int     i;
        double  x;
        Node    n1 = t1->node();

        if (isInt(n1, &i))          return t1;
        if (isDouble(n1, &x))       return tree(int(x));
        if (isSigIntCast(t1, tx))   return t1;

        return sig;

    } else if (isSigFloatCast(sig, t1)) {

        Tree    tx;
        int     i;
        double  x;
        Node    n1 = t1->node();

        if (isInt(n1, &i))              return tree(double(i));
        if (isDouble(n1, &x))           return t1;
        if (isSigFloatCast(t1, tx))     return t1;

        return sig;

     } else if (isSigSelect2(sig, t1, t2, t3)){

        Node n1 = t1->node();

        if (isZero(n1)) return t2;
        if (isNum(n1))  return t3;

        if (t2==t3) return t2;

        return sig;

    } else if (isSigSelect3(sig, t1, t2, t3, t4)){

        Node n1 = t1->node();

        if (isZero(n1)) return t2;
        if (isOne(n1))  return t3;
        if (isNum(n1))  return t4;

        if (t3==t4) return simplification(sigSelect2(t1,t2,t3));

        return sig;

    } else {

        return sig;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Tree simplify ( Tree  sig)

Definition at line 76 of file simplify.cpp.

References sigMap(), and traced_simplification().

Referenced by eval2double(), eval2int(), isBoxNumeric(), mapPrepareEqSig(), normalizeFixedDelayTerm(), numericBoxSimplification(), and ScalarCompiler::prepare().

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree traced_simplification ( Tree  sig) [static]

Definition at line 50 of file simplify.cpp.

References simplification(), and TABBER.

Referenced by simplify().

{
    assert(sig);
#ifdef TRACE
    cerr << ++TABBER << "Start simplification of : " << ppsig(sig) << endl;
    /*
    fprintf(stderr, "\nStart simplification of : ");
    printSignal(sig, stderr);
    fprintf(stderr, "\n");
    */
#endif
    Tree r = simplification(sig);
    assert(r!=0);
#ifdef TRACE
    cerr << --TABBER << "Simplification of : " << ppsig(sig) << " Returns : " << ppsig(r) << endl;
    /*
    fprintf(stderr, "Simplification of : ");
    printSignal(sig, stderr);
    fprintf(stderr, " -> ");
    printSignal(r, stderr);
    fprintf(stderr, "\n");
    */
#endif
    return r;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Tree DOCTABLES = tree(symbol("DocTablesProp"))

Converts regular tables into doc tables in order to facilitate the mathematical documentation generation.

Definition at line 341 of file simplify.cpp.

Tree NULLENV = tree(symbol("NullRenameEnv")) [static]

Definition at line 345 of file simplify.cpp.

Tree SIMPLIFIED = tree(symbol("sigSimplifiedProp"))

Definition at line 45 of file simplify.cpp.