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

Function Documentation

static Tree docTableConverter ( Tree  sig  )  [static]

Definition at line 326 of file simplify.cpp.

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

Referenced by docTableConvertion().

00327 {
00328     Tree tbl, tbl2, id, id2, size, igen, isig, ridx, widx, wsig;
00329 
00330     if (isSigRDTbl(sig, tbl, ridx)) {
00331         // we are in a table to convert
00332         if (isSigTable(tbl, id, size, igen)) {
00333             // it's a read only table
00334             assert(isSigGen(igen, isig));
00335             return sigDocAccessTbl(sigDocConstantTbl(size,isig),ridx);
00336         } else {
00337             // it's a read write table
00338             assert(isSigWRTbl(tbl,id,tbl2,widx,wsig));
00339             assert(isSigTable(tbl2, id2, size, igen));
00340             assert(isSigGen(igen, isig));
00341 
00342             return sigDocAccessTbl(sigDocWriteTbl(size,isig,widx,wsig),ridx);
00343         }
00344 
00345     } else {
00346         // nothing to convert
00347         return sig;
00348     }
00349 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree docTableConvertion ( Tree  sig  ) 

Definition at line 317 of file simplify.cpp.

References docTableConverter(), NULLENV, and sigMapRename().

Referenced by mapPrepareEqSig().

00318 {
00319     Tree r  = sigMapRename(DOCTABLES, NULLENV, docTableConverter, sig);
00320     return r;
00321 }

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 159 of file simplify.cpp.

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

Referenced by simplify().

00160 {
00161     //printf("start sigMap\n");
00162     Tree p,id,body;
00163 
00164     if (getProperty(t, key, p)) {
00165 
00166         return (isNil(p)) ? t : p;  // truc pour eviter les boucles
00167 
00168     } else if (isRec(t, id, body)) {
00169 
00170         setProperty(t, key, nil);   // avoid infinite loop
00171         return rec(id, sigMap(key, f, body));
00172 
00173     } else {
00174 
00175         Tree r1=nil;
00176         switch (t->arity()) {
00177 
00178             case 0 :
00179                 r1 = t;
00180                 break;
00181             case 1 :
00182                 r1 = tree(t->node(), sigMap(key,f,t->branch(0)));
00183                 break;
00184             case 2 :
00185                 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)));
00186                 break;
00187             case 3 :
00188                 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)),
00189                                            sigMap(key,f,t->branch(2)));
00190                 break;
00191             case 4 :
00192                 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)),
00193                                            sigMap(key,f,t->branch(2)), sigMap(key,f,t->branch(3)));
00194                 break;
00195         }
00196         Tree r2 = f(r1);
00197         if (r2 == t) {
00198             setProperty(t, key, nil);
00199         } else {
00200             setProperty(t, key, r2);
00201         }
00202         return r2;
00203     }
00204 }

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 215 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().

00216 {
00217     //printf("start sigMap\n");
00218     Tree p,id,body;
00219 
00220     if (getProperty(t, key, p)) {
00221 
00222         return (isNil(p)) ? t : p;  // truc pour eviter les boucles
00223 
00224     } else if (isRec(t, id, body)) {
00225 
00226         assert(isRef(t,id)); // controle temporaire
00227 
00228         Tree id2;
00229         if (searchEnv(id, id2, env)) {
00230             // déjà en cours de visite de cette recursion
00231             return ref(id2);
00232         } else {
00233             // premiere visite de cette recursion
00234             id2 = tree(Node(unique("renamed")));
00235             Tree body2 = sigMapRename(key, pushEnv(id, id2, env), f, body);
00236             return rec(id2,body2);
00237         }
00238 
00239     } else {
00240 
00241         Tree r1=nil;
00242         switch (t->arity()) {
00243 
00244             case 0 :
00245                 r1 = t;
00246                 break;
00247             case 1 :
00248                 r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)));
00249                 break;
00250             case 2 :
00251                 r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
00252                                         sigMapRename(key,env,f,t->branch(1)));
00253                 break;
00254             case 3 :
00255                 r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
00256                                         sigMapRename(key,env,f,t->branch(1)),
00257                                         sigMapRename(key,env,f,t->branch(2)));
00258                 break;
00259             case 4 :
00260                 r1 = tree(t->node(),    sigMapRename(key,env,f,t->branch(0)),
00261                                         sigMapRename(key,env,f,t->branch(1)),
00262                                         sigMapRename(key,env,f,t->branch(2)),
00263                                         sigMapRename(key,env,f,t->branch(3)));
00264                 break;
00265         }
00266         Tree r2 = f(r1);
00267         if (r2 == t) {
00268             setProperty(t, key, nil);
00269         } else {
00270             setProperty(t, key, r2);
00271         }
00272         return r2;
00273     }
00274 }

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 83 of file simplify.cpp.

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

Referenced by traced_simplification().

00084 {
00085     assert(sig);
00086     int     opnum;
00087     Tree    t1, t2;
00088 
00089     xtended* xt = (xtended*) getUserData(sig);
00090     // primitive elements
00091     if (xt)
00092     {
00093         //return 3;
00094         vector<Tree> args;
00095         for (int i=0; i<sig->arity(); i++) { args.push_back( sig->branch(i) ); }
00096         return xt->computeSigOutput(args);
00097 
00098     } else if (isSigBinOp(sig, &opnum, t1, t2)) {
00099 
00100         BinOp* op = gBinOpTable[opnum];
00101 
00102         Node n1 = t1->node();
00103         Node n2 = t2->node();
00104 
00105         if (isNum(n1) && isNum(n2))         return tree(op->compute(n1,n2));
00106 
00107         else if (op->isLeftNeutral(n1))     return t2;
00108 
00109         else if (op->isRightNeutral(n2))    return t1;
00110 
00111         else                                return normalizeAddTerm(sig);
00112 
00113     } else if (isSigDelay1(sig, t1)) {
00114         
00115         return normalizeDelay1Term (t1);
00116 
00117     } else if (isSigFixDelay(sig, t1, t2)) {
00118 
00119         return normalizeFixedDelayTerm (t1, t2);
00120 
00121     } else if (isSigIntCast(sig, t1)) {
00122 
00123         Tree    tx;
00124         int     i;
00125         double  x;
00126         Node    n1 = t1->node();
00127 
00128         if (isInt(n1, &i))          return t1; 
00129         if (isDouble(n1, &x))       return tree(int(x));
00130         if (isSigIntCast(t1, tx))   return t1;
00131         
00132         return sig;
00133 
00134     } else if (isSigFloatCast(sig, t1)) {
00135 
00136         Tree    tx;
00137         int     i;
00138         double  x;
00139         Node    n1 = t1->node();
00140 
00141         if (isInt(n1, &i))              return tree(double(i));
00142         if (isDouble(n1, &x))           return t1;
00143         if (isSigFloatCast(t1, tx))     return t1;
00144         
00145         return sig;
00146 
00147     } else {
00148 
00149         return sig;
00150     }
00151 }

Here is the call graph for this function:

Here is the caller graph for this function:

Tree simplify ( Tree  sig  ) 

Definition at line 75 of file simplify.cpp.

References sigMap(), and traced_simplification().

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

00076 {
00077     return sigMap(SIMPLIFIED, traced_simplification, sig);
00078 }

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 49 of file simplify.cpp.

References simplification(), and TABBER.

Referenced by simplify().

00050 {
00051     assert(sig);
00052 #ifdef TRACE
00053     cerr << ++TABBER << "Start simplification of : " << *sig << endl;
00054     /*
00055     fprintf(stderr, "\nStart simplification of : ");
00056     printSignal(sig, stderr);
00057     fprintf(stderr, "\n");
00058     */
00059 #endif
00060     Tree r = simplification(sig);
00061     assert(r!=0);
00062 #ifdef TRACE
00063     cerr << --TABBER << "Simplification of : " << *sig << " Returns : " << *r << endl;
00064     /*
00065     fprintf(stderr, "Simplification of : ");
00066     printSignal(sig, stderr);
00067     fprintf(stderr, " -> ");
00068     printSignal(r, stderr);
00069     fprintf(stderr, "\n");
00070     */
00071 #endif
00072     return r;
00073 }

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 313 of file simplify.cpp.

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

Definition at line 44 of file simplify.cpp.

Generated on Thu Jul 15 15:47:27 2010 for FAUST compiler by  doxygen 1.6.3