00001
00021 #include "abc.h"
00022
00026
00030
00042 static inline void Vec_IntPushMem( Extra_MmStep_t * pMemMan, Vec_Int_t * p, int Entry )
00043 {
00044 if ( p->nSize == p->nCap )
00045 {
00046 int * pArray;
00047 int i;
00048
00049 if ( p->nSize == 0 )
00050 p->nCap = 1;
00051 if ( pMemMan )
00052 pArray = (int *)Extra_MmStepEntryFetch( pMemMan, p->nCap * 8 );
00053 else
00054 pArray = ALLOC( int, p->nCap * 2 );
00055 if ( p->pArray )
00056 {
00057 for ( i = 0; i < p->nSize; i++ )
00058 pArray[i] = p->pArray[i];
00059 if ( pMemMan )
00060 Extra_MmStepEntryRecycle( pMemMan, (char *)p->pArray, p->nCap * 4 );
00061 else
00062 free( p->pArray );
00063 }
00064 p->nCap *= 2;
00065 p->pArray = pArray;
00066 }
00067 p->pArray[p->nSize++] = Entry;
00068 }
00069
00081 void Abc_ObjAddFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFanin )
00082 {
00083 Abc_Obj_t * pFaninR = Abc_ObjRegular(pFanin);
00084 assert( !Abc_ObjIsComplement(pObj) );
00085 assert( pObj->pNtk == pFaninR->pNtk );
00086 assert( pObj->Id >= 0 && pFaninR->Id >= 0 );
00087 Vec_IntPushMem( pObj->pNtk->pMmStep, &pObj->vFanins, pFaninR->Id );
00088 Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninR->vFanouts, pObj->Id );
00089 if ( Abc_ObjIsComplement(pFanin) )
00090 Abc_ObjSetFaninC( pObj, Abc_ObjFaninNum(pObj)-1 );
00091 if ( Abc_ObjIsNet(pObj) && Abc_ObjFaninNum(pObj) > 1 )
00092 {
00093 int x = 0;
00094 }
00095
00096
00097 }
00098
00099
00111 void Abc_ObjDeleteFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFanin )
00112 {
00113 assert( !Abc_ObjIsComplement(pObj) );
00114 assert( !Abc_ObjIsComplement(pFanin) );
00115 assert( pObj->pNtk == pFanin->pNtk );
00116 assert( pObj->Id >= 0 && pFanin->Id >= 0 );
00117 if ( !Vec_IntRemove( &pObj->vFanins, pFanin->Id ) )
00118 {
00119 printf( "The obj %d is not found among the fanins of obj %d ...\n", pFanin->Id, pObj->Id );
00120 return;
00121 }
00122 if ( !Vec_IntRemove( &pFanin->vFanouts, pObj->Id ) )
00123 {
00124 printf( "The obj %d is not found among the fanouts of obj %d ...\n", pObj->Id, pFanin->Id );
00125 return;
00126 }
00127 }
00128
00129
00141 void Abc_ObjRemoveFanins( Abc_Obj_t * pObj )
00142 {
00143 Vec_Int_t * vFaninsOld;
00144 Abc_Obj_t * pFanin;
00145 int k;
00146
00147 vFaninsOld = &pObj->vFanins;
00148 for ( k = vFaninsOld->nSize - 1; k >= 0; k-- )
00149 {
00150 pFanin = Abc_NtkObj( pObj->pNtk, vFaninsOld->pArray[k] );
00151 Abc_ObjDeleteFanin( pObj, pFanin );
00152 }
00153 pObj->fCompl0 = 0;
00154 pObj->fCompl1 = 0;
00155 assert( vFaninsOld->nSize == 0 );
00156 }
00157
00172 void Abc_ObjPatchFanin( Abc_Obj_t * pObj, Abc_Obj_t * pFaninOld, Abc_Obj_t * pFaninNew )
00173 {
00174 Abc_Obj_t * pFaninNewR = Abc_ObjRegular(pFaninNew);
00175 int iFanin;
00176 assert( !Abc_ObjIsComplement(pObj) );
00177 assert( !Abc_ObjIsComplement(pFaninOld) );
00178 assert( pFaninOld != pFaninNewR );
00179
00180
00181 assert( pObj->pNtk == pFaninOld->pNtk );
00182 assert( pObj->pNtk == pFaninNewR->pNtk );
00183 if ( (iFanin = Vec_IntFind( &pObj->vFanins, pFaninOld->Id )) == -1 )
00184 {
00185 printf( "Node %s is not among", Abc_ObjName(pFaninOld) );
00186 printf( " the fanins of node %s...\n", Abc_ObjName(pObj) );
00187 return;
00188 }
00189
00190
00191
00192
00193 Vec_IntWriteEntry( &pObj->vFanins, iFanin, pFaninNewR->Id );
00194
00195
00196
00197 if ( Abc_ObjIsComplement(pFaninNew) )
00198 Abc_ObjXorFaninC( pObj, iFanin );
00199
00200
00201
00202
00203 if ( !Vec_IntRemove( &pFaninOld->vFanouts, pObj->Id ) )
00204 {
00205 printf( "Node %s is not among", Abc_ObjName(pObj) );
00206 printf( " the fanouts of its old fanin %s...\n", Abc_ObjName(pFaninOld) );
00207
00208 }
00209 Vec_IntPushMem( pObj->pNtk->pMmStep, &pFaninNewR->vFanouts, pObj->Id );
00210 }
00211
00223 Abc_Obj_t * Abc_ObjInsertBetween( Abc_Obj_t * pNodeIn, Abc_Obj_t * pNodeOut, Abc_ObjType_t Type )
00224 {
00225 Abc_Obj_t * pNodeNew;
00226 int iFanoutIndex, iFaninIndex;
00227
00228 if ( (iFanoutIndex = Vec_IntFind( &pNodeIn->vFanouts, pNodeOut->Id )) == -1 )
00229 {
00230 printf( "Node %s is not among", Abc_ObjName(pNodeOut) );
00231 printf( " the fanouts of node %s...\n", Abc_ObjName(pNodeIn) );
00232 return NULL;
00233 }
00234
00235 if ( (iFaninIndex = Vec_IntFind( &pNodeOut->vFanins, pNodeIn->Id )) == -1 )
00236 {
00237 printf( "Node %s is not among", Abc_ObjName(pNodeIn) );
00238 printf( " the fanins of node %s...\n", Abc_ObjName(pNodeOut) );
00239 return NULL;
00240 }
00241
00242 pNodeNew = Abc_NtkCreateObj( pNodeIn->pNtk, Type );
00243
00244 Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanins, pNodeIn->Id );
00245 Vec_IntPushMem( pNodeNew->pNtk->pMmStep, &pNodeNew->vFanouts, pNodeOut->Id );
00246
00247 Vec_IntWriteEntry( &pNodeIn->vFanouts, iFanoutIndex, pNodeNew->Id );
00248
00249 Vec_IntWriteEntry( &pNodeOut->vFanins, iFaninIndex, pNodeNew->Id );
00250 return pNodeNew;
00251 }
00252
00264 void Abc_ObjTransferFanout( Abc_Obj_t * pNodeFrom, Abc_Obj_t * pNodeTo )
00265 {
00266 Vec_Ptr_t * vFanouts;
00267 int nFanoutsOld, i;
00268 assert( !Abc_ObjIsComplement(pNodeFrom) );
00269 assert( !Abc_ObjIsComplement(pNodeTo) );
00270 assert( !Abc_ObjIsPo(pNodeFrom) && !Abc_ObjIsPo(pNodeTo) );
00271 assert( pNodeFrom->pNtk == pNodeTo->pNtk );
00272 assert( pNodeFrom != pNodeTo );
00273 assert( Abc_ObjFanoutNum(pNodeFrom) > 0 );
00274
00275 nFanoutsOld = Abc_ObjFanoutNum(pNodeTo);
00276 vFanouts = Vec_PtrAlloc( nFanoutsOld );
00277 Abc_NodeCollectFanouts( pNodeFrom, vFanouts );
00278
00279 for ( i = 0; i < vFanouts->nSize; i++ )
00280 Abc_ObjPatchFanin( vFanouts->pArray[i], pNodeFrom, pNodeTo );
00281 assert( Abc_ObjFanoutNum(pNodeFrom) == 0 );
00282 assert( Abc_ObjFanoutNum(pNodeTo) == nFanoutsOld + vFanouts->nSize );
00283 Vec_PtrFree( vFanouts );
00284 }
00285
00297 void Abc_ObjReplace( Abc_Obj_t * pNodeOld, Abc_Obj_t * pNodeNew )
00298 {
00299 assert( !Abc_ObjIsComplement(pNodeOld) );
00300 assert( !Abc_ObjIsComplement(pNodeNew) );
00301 assert( pNodeOld->pNtk == pNodeNew->pNtk );
00302 assert( pNodeOld != pNodeNew );
00303 assert( Abc_ObjFanoutNum(pNodeOld) > 0 );
00304
00305 Abc_ObjTransferFanout( pNodeOld, pNodeNew );
00306
00307 Abc_NtkDeleteObj_rec( pNodeOld, 1 );
00308 }
00309
00321 int Abc_ObjFanoutFaninNum( Abc_Obj_t * pFanout, Abc_Obj_t * pFanin )
00322 {
00323 Abc_Obj_t * pObj;
00324 int i;
00325 Abc_ObjForEachFanin( pFanout, pObj, i )
00326 if ( pObj == pFanin )
00327 return i;
00328 return -1;
00329 }
00330
00331
00335
00336