#include <stdio.h>
#include <assert.h>
#include "signals.hh"
#include "sigtype.hh"
#include "sigtyperules.hh"
#include "sigorderrules.hh"
#include "sigprint.hh"
#include "simplify.hh"
#include "num.hh"
#include "xtended.hh"
#include <map>
#include "normalize.hh"
Go to the source code of this file.
Functions | |
static Tree | simplification (Tree sig) |
static Tree | sigMap (Tree key, tfun f, Tree t) |
static Tree | traced_simplification (Tree sig) |
Tree | simplify (Tree sig) |
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. |
Definition at line 218 of file simplify.cpp.
References isSigGen(), isSigRDTbl(), isSigTable(), isSigWRTbl(), sigDocAccessTbl(), sigDocConstantTbl(), and sigDocWriteTbl().
Referenced by docTableConvertion().
00219 { 00220 Tree tbl, tbl2, id, id2, size, igen, isig, ridx, widx, wsig; 00221 00222 if (isSigRDTbl(sig, tbl, ridx)) { 00223 // we are in a table to convert 00224 if (isSigTable(tbl, id, size, igen)) { 00225 // it's a read only table 00226 assert(isSigGen(igen, isig)); 00227 return sigDocAccessTbl(sigDocConstantTbl(size,isig),ridx); 00228 } else { 00229 // it's a read write table 00230 assert(isSigWRTbl(tbl,id,tbl2,widx,wsig)); 00231 assert(isSigTable(tbl2, id2, size, igen)); 00232 assert(isSigGen(igen, isig)); 00233 00234 return sigDocAccessTbl(sigDocWriteTbl(size,isig,widx,wsig),ridx); 00235 } 00236 00237 } else { 00238 // nothing to convert 00239 return sig; 00240 } 00241 }
Definition at line 210 of file simplify.cpp.
References docTableConverter(), and sigMap().
Referenced by mapPrepareEqSig().
00211 { 00212 return sigMap(DOCTABLES, docTableConverter, sig); 00213 }
Definition at line 154 of file simplify.cpp.
References CTree::arity(), CTree::branch(), getProperty(), isNil(), isRec(), nil, CTree::node(), rec(), setProperty(), and tree().
Referenced by docTableConvertion(), and simplify().
00155 { 00156 //printf("start sigMap\n"); 00157 Tree p,id,body; 00158 00159 if (getProperty(t, key, p)) { 00160 00161 return (isNil(p)) ? t : p; // truc pour eviter les boucles 00162 00163 } else if (isRec(t, id, body)) { 00164 00165 setProperty(t, key, nil); // avoid infinite loop 00166 return rec(id, sigMap(key, f, body)); 00167 00168 } else { 00169 00170 Tree r1=nil; 00171 switch (t->arity()) { 00172 00173 case 0 : 00174 r1 = t; 00175 break; 00176 case 1 : 00177 r1 = tree(t->node(), sigMap(key,f,t->branch(0))); 00178 break; 00179 case 2 : 00180 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1))); 00181 break; 00182 case 3 : 00183 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)), 00184 sigMap(key,f,t->branch(2))); 00185 break; 00186 case 4 : 00187 r1 = tree(t->node(), sigMap(key,f,t->branch(0)), sigMap(key,f,t->branch(1)), 00188 sigMap(key,f,t->branch(2)), sigMap(key,f,t->branch(3))); 00189 break; 00190 } 00191 Tree r2 = f(r1); 00192 if (r2 == t) { 00193 setProperty(t, key, nil); 00194 } else { 00195 setProperty(t, key, r2); 00196 } 00197 return r2; 00198 } 00199 }
Definition at line 80 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().
00081 { 00082 assert(sig); 00083 int opnum; 00084 Tree t1, t2; 00085 00086 xtended* xt = (xtended*) getUserData(sig); 00087 // primitive elements 00088 if (xt) 00089 { 00090 //return 3; 00091 vector<Tree> args; 00092 for (int i=0; i<sig->arity(); i++) { args.push_back( sig->branch(i) ); } 00093 return xt->computeSigOutput(args); 00094 00095 } else if (isSigBinOp(sig, &opnum, t1, t2)) { 00096 00097 BinOp* op = gBinOpTable[opnum]; 00098 00099 Node n1 = t1->node(); 00100 Node n2 = t2->node(); 00101 00102 if (isNum(n1) && isNum(n2)) return tree(op->compute(n1,n2)); 00103 00104 else if (op->isLeftNeutral(n1)) return t2; 00105 00106 else if (op->isRightNeutral(n2)) return t1; 00107 00108 else return normalizeAddTerm(sig); 00109 00110 } else if (isSigDelay1(sig, t1)) { 00111 00112 return normalizeDelay1Term (t1); 00113 00114 } else if (isSigFixDelay(sig, t1, t2)) { 00115 00116 return normalizeFixedDelayTerm (t1, t2); 00117 00118 } else if (isSigIntCast(sig, t1)) { 00119 00120 Tree tx; 00121 int i; 00122 double x; 00123 Node n1 = t1->node(); 00124 00125 if (isInt(n1, &i)) return t1; 00126 if (isDouble(n1, &x)) return tree(int(x)); 00127 if (isSigIntCast(t1, tx)) return t1; 00128 00129 return sig; 00130 00131 } else if (isSigFloatCast(sig, t1)) { 00132 00133 Tree tx; 00134 int i; 00135 double x; 00136 Node n1 = t1->node(); 00137 00138 if (isInt(n1, &i)) return tree(double(i)); 00139 if (isDouble(n1, &x)) return t1; 00140 if (isSigFloatCast(t1, tx)) return t1; 00141 00142 return sig; 00143 00144 } else { 00145 00146 return sig; 00147 } 00148 }
Definition at line 72 of file simplify.cpp.
References sigMap(), and traced_simplification().
Referenced by eval2double(), eval2int(), isBoxNumeric(), mapPrepareEqSig(), normalizeFixedDelayTerm(), ScalarCompiler::prepare(), and replaceBoxNumeric().
00073 { 00074 return sigMap(SIMPLIFIED, traced_simplification, sig); 00075 }
Definition at line 46 of file simplify.cpp.
References simplification(), and TABBER.
Referenced by simplify().
00047 { 00048 assert(sig); 00049 #ifdef TRACE 00050 cerr << ++TABBER << "Start simplification of : " << *sig << endl; 00051 /* 00052 fprintf(stderr, "\nStart simplification of : "); 00053 printSignal(sig, stderr); 00054 fprintf(stderr, "\n"); 00055 */ 00056 #endif 00057 Tree r = simplification(sig); 00058 assert(r!=0); 00059 #ifdef TRACE 00060 cerr << --TABBER << "Simplification of : " << *sig << " Returns : " << *r << endl; 00061 /* 00062 fprintf(stderr, "Simplification of : "); 00063 printSignal(sig, stderr); 00064 fprintf(stderr, " -> "); 00065 printSignal(r, stderr); 00066 fprintf(stderr, "\n"); 00067 */ 00068 #endif 00069 return r; 00070 }
Converts regular tables into doc tables in order to facilitate the mathematical documentation generation.
Definition at line 206 of file simplify.cpp.
Tree SIMPLIFIED = tree(symbol("sigSimplifiedProp")) |
Definition at line 41 of file simplify.cpp.