|
FAUST compiler
0.9.9.6b8
|
00001 #include <stdio.h> 00002 #include <assert.h> 00003 #include "tlib.hh" 00004 #include "signals.hh" 00005 #include "sigprint.hh" 00006 #include "ppsig.hh" 00007 #include "simplify.hh" 00008 #include "normalize.hh" 00009 #include "sigorderrules.hh" 00010 #include <map> 00011 #include <list> 00012 00013 #include "mterm.hh" 00014 #include "aterm.hh" 00015 00016 #if 0 00017 static void countAddTerm (map<Tree,Tree>& M, Tree t, bool invflag); 00018 static void incTermCount (map<Tree,int>& M, Tree t, bool invflag); 00019 static Tree buildPowTerm (Tree f, int q); 00020 static Tree simplifyingReorganizingMul(Tree t1, Tree t2); 00021 static Tree reorganizingMul(Tree k, Tree t); 00022 static void factorizeAddTerm(map<Tree,Tree>& M); 00023 #endif 00024 00025 #undef TRACE 00026 00032 Tree normalizeAddTerm(Tree t) 00033 { 00034 #ifdef TRACE 00035 cerr << "START normalizeAddTerm : " << ppsig(t) << endl; 00036 #endif 00037 00038 aterm A(t); 00039 //cerr << "ATERM IS : " << A << endl; 00040 mterm D = A.greatestDivisor(); 00041 while (D.isNotZero() && D.complexity() > 0) { 00042 //cerr << "GREAT DIV : " << D << endl; 00043 A = A.factorize(D); 00044 D = A.greatestDivisor(); 00045 } 00046 return A.normalizedTree(); 00047 } 00048 00049 00059 Tree normalizeDelay1Term(Tree s) 00060 { 00061 return normalizeFixedDelayTerm(s, tree(1)); 00062 } 00063 00064 00081 Tree normalizeFixedDelayTerm(Tree s, Tree d) 00082 { 00083 Tree x, y, r; 00084 int i; 00085 00086 if (isZero(d) && ! isProj(s, &i, r)) { 00087 00088 return s; 00089 00090 } else if (isZero(s)) { 00091 00092 return s; 00093 00094 } else if (isSigMul(s, x, y)) { 00095 00096 if (getSigOrder(x) < 2) { 00097 return /*simplify*/(sigMul(x,normalizeFixedDelayTerm(y,d))); 00098 } else if (getSigOrder(y) < 2) { 00099 return /*simplify*/(sigMul(y,normalizeFixedDelayTerm(x,d))); 00100 } else { 00101 return sigFixDelay(s,d); 00102 } 00103 00104 } else if (isSigDiv(s, x, y)) { 00105 00106 if (getSigOrder(y) < 2) { 00107 return /*simplify*/(sigDiv(normalizeFixedDelayTerm(x,d),y)); 00108 } else { 00109 return sigFixDelay(s,d); 00110 } 00111 00112 } else if (isSigFixDelay(s, x, y)) { 00113 // (x@n)@m = x@(n+m) 00114 // return sigFixDelay(x,tree(tree2int(d)+tree2int(y))); 00115 return normalizeFixedDelayTerm(x,simplify(sigAdd(d,y))); 00116 00117 } else { 00118 00119 return sigFixDelay(s,d); 00120 } 00121 } 00122
1.8.0