00001
00021 #include "rwt.h"
00022 #include "deco.h"
00023
00027
00028 static Dec_Graph_t * Rwt_NodePreprocess( Rwt_Man_t * p, Rwt_Node_t * pNode );
00029 static Dec_Edge_t Rwt_TravCollect_rec( Rwt_Man_t * p, Rwt_Node_t * pNode, Dec_Graph_t * pGraph );
00030
00034
00046 void Rwt_ManPreprocess( Rwt_Man_t * p )
00047 {
00048 Dec_Graph_t * pGraph;
00049 Rwt_Node_t * pNode;
00050 int i, k;
00051
00052 p->pMapInv = ALLOC( unsigned short, 222 );
00053 memset( p->pMapInv, 0, sizeof(unsigned short) * 222 );
00054 p->vClasses = Vec_VecStart( 222 );
00055 for ( i = 0; i < p->nFuncs; i++ )
00056 {
00057 if ( p->pTable[i] == NULL )
00058 continue;
00059
00060 for ( pNode = p->pTable[i]; pNode; pNode = pNode->pNext )
00061 {
00062 assert( pNode->uTruth == p->pTable[i]->uTruth );
00063 assert( p->pMap[pNode->uTruth] >= 0 && p->pMap[pNode->uTruth] < 222 );
00064 Vec_VecPush( p->vClasses, p->pMap[pNode->uTruth], pNode );
00065 p->pMapInv[ p->pMap[pNode->uTruth] ] = p->puCanons[pNode->uTruth];
00066 }
00067 }
00068
00069 Vec_VecForEachEntry( p->vClasses, pNode, i, k )
00070 {
00071 pGraph = Rwt_NodePreprocess( p, pNode );
00072 pNode->pNext = (Rwt_Node_t *)pGraph;
00073
00074 }
00075 }
00076
00088 Dec_Graph_t * Rwt_NodePreprocess( Rwt_Man_t * p, Rwt_Node_t * pNode )
00089 {
00090 Dec_Graph_t * pGraph;
00091 Dec_Edge_t eRoot;
00092 assert( !Rwt_IsComplement(pNode) );
00093
00094 if ( pNode->uTruth == 0 )
00095 return Dec_GraphCreateConst0();
00096
00097 if ( pNode->uTruth == 0x00FF )
00098 return Dec_GraphCreateLeaf( 3, 4, 1 );
00099
00100 pGraph = Dec_GraphCreate( 4 );
00101
00102 Rwt_ManIncTravId( p );
00103 eRoot = Rwt_TravCollect_rec( p, pNode, pGraph );
00104 Dec_GraphSetRoot( pGraph, eRoot );
00105 return pGraph;
00106 }
00107
00119 Dec_Edge_t Rwt_TravCollect_rec( Rwt_Man_t * p, Rwt_Node_t * pNode, Dec_Graph_t * pGraph )
00120 {
00121 Dec_Edge_t eNode0, eNode1, eNode;
00122
00123 if ( pNode->fUsed )
00124 return Dec_EdgeCreate( pNode->Id - 1, 0 );
00125
00126 if ( pNode->TravId == p->nTravIds )
00127 return Dec_IntToEdge( pNode->Volume );
00128 pNode->TravId = p->nTravIds;
00129
00130 eNode0 = Rwt_TravCollect_rec( p, Rwt_Regular(pNode->p0), pGraph );
00131 if ( Rwt_IsComplement(pNode->p0) )
00132 eNode0.fCompl = !eNode0.fCompl;
00133 eNode1 = Rwt_TravCollect_rec( p, Rwt_Regular(pNode->p1), pGraph );
00134 if ( Rwt_IsComplement(pNode->p1) )
00135 eNode1.fCompl = !eNode1.fCompl;
00136
00137 if ( pNode->fExor )
00138 eNode = Dec_GraphAddNodeXor( pGraph, eNode0, eNode1, 0 );
00139 else
00140 eNode = Dec_GraphAddNodeAnd( pGraph, eNode0, eNode1 );
00141
00142 pNode->Volume = Dec_EdgeToInt( eNode );
00143 return eNode;
00144 }
00145
00149
00150