00001
00021 #include "ivy.h"
00022
00026
00027
00028 static inline Ivy_Obj_t * Ivy_ObjNextFanout( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00029 {
00030 assert( !Ivy_IsComplement(pObj) );
00031 assert( !Ivy_IsComplement(pFanout) );
00032 if ( pFanout == NULL )
00033 return NULL;
00034 if ( Ivy_ObjFanin0(pFanout) == pObj )
00035 return pFanout->pNextFan0;
00036 assert( Ivy_ObjFanin1(pFanout) == pObj );
00037 return pFanout->pNextFan1;
00038 }
00039
00040
00041 static inline Ivy_Obj_t * Ivy_ObjPrevFanout( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00042 {
00043 assert( !Ivy_IsComplement(pObj) );
00044 assert( !Ivy_IsComplement(pFanout) );
00045 if ( pFanout == NULL )
00046 return NULL;
00047 if ( Ivy_ObjFanin0(pFanout) == pObj )
00048 return pFanout->pPrevFan0;
00049 assert( Ivy_ObjFanin1(pFanout) == pObj );
00050 return pFanout->pPrevFan1;
00051 }
00052
00053
00054 static inline Ivy_Obj_t ** Ivy_ObjNextFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00055 {
00056 assert( !Ivy_IsComplement(pObj) );
00057 assert( !Ivy_IsComplement(pFanout) );
00058 if ( Ivy_ObjFanin0(pFanout) == pObj )
00059 return &pFanout->pNextFan0;
00060 assert( Ivy_ObjFanin1(pFanout) == pObj );
00061 return &pFanout->pNextFan1;
00062 }
00063
00064
00065 static inline Ivy_Obj_t ** Ivy_ObjPrevFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00066 {
00067 assert( !Ivy_IsComplement(pObj) );
00068 assert( !Ivy_IsComplement(pFanout) );
00069 if ( Ivy_ObjFanin0(pFanout) == pObj )
00070 return &pFanout->pPrevFan0;
00071 assert( Ivy_ObjFanin1(pFanout) == pObj );
00072 return &pFanout->pPrevFan1;
00073 }
00074
00075
00076 static inline Ivy_Obj_t ** Ivy_ObjPrevNextFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00077 {
00078 Ivy_Obj_t * pTemp;
00079 assert( !Ivy_IsComplement(pObj) );
00080 assert( !Ivy_IsComplement(pFanout) );
00081 pTemp = Ivy_ObjPrevFanout(pObj, pFanout);
00082 if ( pTemp == NULL )
00083 return &pObj->pFanout;
00084 if ( Ivy_ObjFanin0(pTemp) == pObj )
00085 return &pTemp->pNextFan0;
00086 assert( Ivy_ObjFanin1(pTemp) == pObj );
00087 return &pTemp->pNextFan1;
00088 }
00089
00090
00091 static inline Ivy_Obj_t ** Ivy_ObjNextPrevFanoutPlace( Ivy_Obj_t * pObj, Ivy_Obj_t * pFanout )
00092 {
00093 Ivy_Obj_t * pTemp;
00094 assert( !Ivy_IsComplement(pObj) );
00095 assert( !Ivy_IsComplement(pFanout) );
00096 pTemp = Ivy_ObjNextFanout(pObj, pFanout);
00097 if ( pTemp == NULL )
00098 return NULL;
00099 if ( Ivy_ObjFanin0(pTemp) == pObj )
00100 return &pTemp->pPrevFan0;
00101 assert( Ivy_ObjFanin1(pTemp) == pObj );
00102 return &pTemp->pPrevFan1;
00103 }
00104
00105
00106 #define Ivy_ObjForEachFanoutInt( pObj, pFanout ) \
00107 for ( pFanout = (pObj)->pFanout; pFanout; \
00108 pFanout = Ivy_ObjNextFanout(pObj, pFanout) )
00109
00110
00111 #define Ivy_ObjForEachFanoutIntSafe( pObj, pFanout, pFanout2 ) \
00112 for ( pFanout = (pObj)->pFanout, \
00113 pFanout2 = Ivy_ObjNextFanout(pObj, pFanout); \
00114 pFanout; \
00115 pFanout = pFanout2, \
00116 pFanout2 = Ivy_ObjNextFanout(pObj, pFanout) )
00117
00121
00133 void Ivy_ManStartFanout( Ivy_Man_t * p )
00134 {
00135 Ivy_Obj_t * pObj;
00136 int i;
00137 assert( !p->fFanout );
00138 p->fFanout = 1;
00139 Ivy_ManForEachObj( p, pObj, i )
00140 {
00141 if ( Ivy_ObjFanin0(pObj) )
00142 Ivy_ObjAddFanout( p, Ivy_ObjFanin0(pObj), pObj );
00143 if ( Ivy_ObjFanin1(pObj) )
00144 Ivy_ObjAddFanout( p, Ivy_ObjFanin1(pObj), pObj );
00145 }
00146 }
00147
00159 void Ivy_ManStopFanout( Ivy_Man_t * p )
00160 {
00161 Ivy_Obj_t * pObj;
00162 int i;
00163 assert( p->fFanout );
00164 p->fFanout = 0;
00165 Ivy_ManForEachObj( p, pObj, i )
00166 pObj->pFanout = pObj->pNextFan0 = pObj->pNextFan1 = pObj->pPrevFan0 = pObj->pPrevFan1 = NULL;
00167 }
00168
00180 void Ivy_ObjAddFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanout )
00181 {
00182 assert( p->fFanout );
00183 if ( pFanin->pFanout )
00184 {
00185 *Ivy_ObjNextFanoutPlace(pFanin, pFanout) = pFanin->pFanout;
00186 *Ivy_ObjPrevFanoutPlace(pFanin, pFanin->pFanout) = pFanout;
00187 }
00188 pFanin->pFanout = pFanout;
00189 }
00190
00202 void Ivy_ObjDeleteFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanout )
00203 {
00204 Ivy_Obj_t ** ppPlace1, ** ppPlace2, ** ppPlaceN;
00205 assert( pFanin->pFanout != NULL );
00206
00207 ppPlace1 = Ivy_ObjNextFanoutPlace(pFanin, pFanout);
00208 ppPlaceN = Ivy_ObjPrevNextFanoutPlace(pFanin, pFanout);
00209 assert( *ppPlaceN == pFanout );
00210 if ( ppPlaceN )
00211 *ppPlaceN = *ppPlace1;
00212
00213 ppPlace2 = Ivy_ObjPrevFanoutPlace(pFanin, pFanout);
00214 ppPlaceN = Ivy_ObjNextPrevFanoutPlace(pFanin, pFanout);
00215 assert( ppPlaceN == NULL || *ppPlaceN == pFanout );
00216 if ( ppPlaceN )
00217 *ppPlaceN = *ppPlace2;
00218
00219 *ppPlace1 = NULL;
00220 *ppPlace2 = NULL;
00221 }
00222
00234 void Ivy_ObjPatchFanout( Ivy_Man_t * p, Ivy_Obj_t * pFanin, Ivy_Obj_t * pFanoutOld, Ivy_Obj_t * pFanoutNew )
00235 {
00236 Ivy_Obj_t ** ppPlace;
00237 ppPlace = Ivy_ObjPrevNextFanoutPlace(pFanin, pFanoutOld);
00238 assert( *ppPlace == pFanoutOld );
00239 if ( ppPlace )
00240 *ppPlace = pFanoutNew;
00241 ppPlace = Ivy_ObjNextPrevFanoutPlace(pFanin, pFanoutOld);
00242 assert( ppPlace == NULL || *ppPlace == pFanoutOld );
00243 if ( ppPlace )
00244 *ppPlace = pFanoutNew;
00245
00246 }
00247
00259 void Ivy_ObjCollectFanouts( Ivy_Man_t * p, Ivy_Obj_t * pObj, Vec_Ptr_t * vArray )
00260 {
00261 Ivy_Obj_t * pFanout;
00262 assert( p->fFanout );
00263 assert( !Ivy_IsComplement(pObj) );
00264 Vec_PtrClear( vArray );
00265 Ivy_ObjForEachFanoutInt( pObj, pFanout )
00266 Vec_PtrPush( vArray, pFanout );
00267 }
00268
00280 Ivy_Obj_t * Ivy_ObjReadFirstFanout( Ivy_Man_t * p, Ivy_Obj_t * pObj )
00281 {
00282 return pObj->pFanout;
00283 }
00284
00296 int Ivy_ObjFanoutNum( Ivy_Man_t * p, Ivy_Obj_t * pObj )
00297 {
00298 Ivy_Obj_t * pFanout;
00299 int Counter = 0;
00300 Ivy_ObjForEachFanoutInt( pObj, pFanout )
00301 Counter++;
00302 return Counter;
00303 }
00304
00308
00309