00001
00021 #include "abc.h"
00022
00026
00030
00045 char * Abc_ObjName( Abc_Obj_t * pObj )
00046 {
00047 return Nm_ManCreateUniqueName( pObj->pNtk->pManName, pObj->Id );
00048 }
00049
00065 char * Abc_ObjAssignName( Abc_Obj_t * pObj, char * pName, char * pSuffix )
00066 {
00067 assert( pName != NULL );
00068 return Nm_ManStoreIdName( pObj->pNtk->pManName, pObj->Id, pObj->Type, pName, pSuffix );
00069 }
00070
00082 char * Abc_ObjNameSuffix( Abc_Obj_t * pObj, char * pSuffix )
00083 {
00084 static char Buffer[500];
00085 sprintf( Buffer, "%s%s", Abc_ObjName(pObj), pSuffix );
00086 return Buffer;
00087 }
00088
00100 char * Abc_ObjNameDummy( char * pPrefix, int Num, int nDigits )
00101 {
00102 static char Buffer[100];
00103 sprintf( Buffer, "%s%0*d", pPrefix, nDigits, Num );
00104 return Buffer;
00105 }
00106
00118 void Abc_NtkTrasferNames( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
00119 {
00120 Abc_Obj_t * pObj;
00121 int i;
00122 assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkNew) );
00123 assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkNew) );
00124 assert( Abc_NtkBoxNum(pNtk) == Abc_NtkBoxNum(pNtkNew) );
00125 assert( Abc_NtkAssertNum(pNtk) == Abc_NtkAssertNum(pNtkNew) );
00126 assert( Nm_ManNumEntries(pNtk->pManName) > 0 );
00127 assert( Nm_ManNumEntries(pNtkNew->pManName) == 0 );
00128
00129 Abc_NtkForEachCi( pNtk, pObj, i )
00130 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanout0Ntk(pObj)), NULL );
00131 Abc_NtkForEachCo( pNtk, pObj, i )
00132 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanin0Ntk(pObj)), NULL );
00133 Abc_NtkForEachBox( pNtk, pObj, i )
00134 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00135 }
00136
00148 void Abc_NtkTrasferNamesNoLatches( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
00149 {
00150 Abc_Obj_t * pObj;
00151 int i;
00152 assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkNew) );
00153 assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkNew) );
00154 assert( Abc_NtkAssertNum(pNtk) == Abc_NtkAssertNum(pNtkNew) );
00155 assert( Nm_ManNumEntries(pNtk->pManName) > 0 );
00156 assert( Nm_ManNumEntries(pNtkNew->pManName) == 0 );
00157
00158 Abc_NtkForEachCi( pNtk, pObj, i )
00159 if ( Abc_ObjFaninNum(pObj) == 0 || !Abc_ObjIsLatch(Abc_ObjFanin0(pObj)) )
00160 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanout0Ntk(pObj)), NULL );
00161 Abc_NtkForEachCo( pNtk, pObj, i )
00162 if ( Abc_ObjFanoutNum(pObj) == 0 || !Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
00163 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(Abc_ObjFanin0Ntk(pObj)), NULL );
00164 Abc_NtkForEachBox( pNtk, pObj, i )
00165 if ( !Abc_ObjIsLatch(pObj) )
00166 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00167 }
00168
00180 Vec_Ptr_t * Abc_NodeGetFaninNames( Abc_Obj_t * pNode )
00181 {
00182 Vec_Ptr_t * vNodes;
00183 Abc_Obj_t * pFanin;
00184 int i;
00185 vNodes = Vec_PtrAlloc( 100 );
00186 Abc_ObjForEachFanin( pNode, pFanin, i )
00187 Vec_PtrPush( vNodes, Extra_UtilStrsav(Abc_ObjName(pFanin)) );
00188 return vNodes;
00189 }
00190
00202 Vec_Ptr_t * Abc_NodeGetFakeNames( int nNames )
00203 {
00204 Vec_Ptr_t * vNames;
00205 char Buffer[5];
00206 int i;
00207
00208 vNames = Vec_PtrAlloc( nNames );
00209 for ( i = 0; i < nNames; i++ )
00210 {
00211 if ( nNames < 26 )
00212 {
00213 Buffer[0] = 'a' + i;
00214 Buffer[1] = 0;
00215 }
00216 else
00217 {
00218 Buffer[0] = 'a' + i%26;
00219 Buffer[1] = '0' + i/26;
00220 Buffer[2] = 0;
00221 }
00222 Vec_PtrPush( vNames, Extra_UtilStrsav(Buffer) );
00223 }
00224 return vNames;
00225 }
00226
00238 void Abc_NodeFreeNames( Vec_Ptr_t * vNames )
00239 {
00240 int i;
00241 if ( vNames == NULL )
00242 return;
00243 for ( i = 0; i < vNames->nSize; i++ )
00244 free( vNames->pArray[i] );
00245 Vec_PtrFree( vNames );
00246 }
00247
00259 char ** Abc_NtkCollectCioNames( Abc_Ntk_t * pNtk, int fCollectCos )
00260 {
00261 Abc_Obj_t * pObj;
00262 char ** ppNames;
00263 int i;
00264 if ( fCollectCos )
00265 {
00266 ppNames = ALLOC( char *, Abc_NtkCoNum(pNtk) );
00267 Abc_NtkForEachCo( pNtk, pObj, i )
00268 ppNames[i] = Abc_ObjName(pObj);
00269 }
00270 else
00271 {
00272 ppNames = ALLOC( char *, Abc_NtkCiNum(pNtk) );
00273 Abc_NtkForEachCi( pNtk, pObj, i )
00274 ppNames[i] = Abc_ObjName(pObj);
00275 }
00276 return ppNames;
00277 }
00278
00290 int Abc_NodeCompareNames( Abc_Obj_t ** pp1, Abc_Obj_t ** pp2 )
00291 {
00292 int Diff = strcmp( (char *)(*pp1)->pCopy, (char *)(*pp2)->pCopy );
00293 if ( Diff < 0 )
00294 return -1;
00295 if ( Diff > 0 )
00296 return 1;
00297 return 0;
00298 }
00299
00311 void Abc_NtkOrderObjsByName( Abc_Ntk_t * pNtk, int fComb )
00312 {
00313 Abc_Obj_t * pObj;
00314 int i;
00315 assert( Abc_NtkAssertNum(pNtk) == 0 );
00316 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
00317
00318 Abc_NtkForEachPi( pNtk, pObj, i )
00319 pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(pObj);
00320 Abc_NtkForEachPo( pNtk, pObj, i )
00321 pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(pObj);
00322 Abc_NtkForEachBox( pNtk, pObj, i )
00323 pObj->pCopy = (Abc_Obj_t *)Abc_ObjName(Abc_ObjFanout0(pObj));
00324
00325 qsort( (void *)Vec_PtrArray(pNtk->vPis), Vec_PtrSize(pNtk->vPis), sizeof(Abc_Obj_t *),
00326 (int (*)(const void *, const void *)) Abc_NodeCompareNames );
00327 qsort( (void *)Vec_PtrArray(pNtk->vPos), Vec_PtrSize(pNtk->vPos), sizeof(Abc_Obj_t *),
00328 (int (*)(const void *, const void *)) Abc_NodeCompareNames );
00329
00330 if ( fComb )
00331 qsort( (void *)Vec_PtrArray(pNtk->vBoxes), Vec_PtrSize(pNtk->vBoxes), sizeof(Abc_Obj_t *),
00332 (int (*)(const void *, const void *)) Abc_NodeCompareNames );
00333
00334 Abc_NtkOrderCisCos( pNtk );
00335
00336 Abc_NtkForEachPi( pNtk, pObj, i )
00337 pObj->pCopy = NULL;
00338 Abc_NtkForEachPo( pNtk, pObj, i )
00339 pObj->pCopy = NULL;
00340 Abc_NtkForEachBox( pNtk, pObj, i )
00341 pObj->pCopy = NULL;
00342 }
00343
00355 void Abc_NtkAddDummyPiNames( Abc_Ntk_t * pNtk )
00356 {
00357 Abc_Obj_t * pObj;
00358 int nDigits, i;
00359 nDigits = Extra_Base10Log( Abc_NtkPiNum(pNtk) );
00360 Abc_NtkForEachPi( pNtk, pObj, i )
00361 Abc_ObjAssignName( pObj, Abc_ObjNameDummy("pi", i, nDigits), NULL );
00362 }
00363
00375 void Abc_NtkAddDummyPoNames( Abc_Ntk_t * pNtk )
00376 {
00377 Abc_Obj_t * pObj;
00378 int nDigits, i;
00379 nDigits = Extra_Base10Log( Abc_NtkPoNum(pNtk) );
00380 Abc_NtkForEachPo( pNtk, pObj, i )
00381 Abc_ObjAssignName( pObj, Abc_ObjNameDummy("po", i, nDigits), NULL );
00382 }
00383
00395 void Abc_NtkAddDummyAssertNames( Abc_Ntk_t * pNtk )
00396 {
00397 Abc_Obj_t * pObj;
00398 int nDigits, i;
00399 nDigits = Extra_Base10Log( Abc_NtkAssertNum(pNtk) );
00400 Abc_NtkForEachAssert( pNtk, pObj, i )
00401 Abc_ObjAssignName( pObj, Abc_ObjNameDummy("a", i, nDigits), NULL );
00402 }
00403
00415 void Abc_NtkAddDummyBoxNames( Abc_Ntk_t * pNtk )
00416 {
00417 Abc_Obj_t * pObj;
00418 int nDigits, i;
00419 assert( !Abc_NtkIsNetlist(pNtk) );
00420 nDigits = Extra_Base10Log( Abc_NtkLatchNum(pNtk) );
00421 Abc_NtkForEachLatch( pNtk, pObj, i )
00422 {
00423 Abc_ObjAssignName( pObj, Abc_ObjNameDummy("l", i, nDigits), NULL );
00424 Abc_ObjAssignName( Abc_ObjFanin0(pObj), Abc_ObjNameDummy("li", i, nDigits), NULL );
00425 Abc_ObjAssignName( Abc_ObjFanout0(pObj), Abc_ObjNameDummy("lo", i, nDigits), NULL );
00426 }
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440 }
00441
00453 void Abc_NtkShortNames( Abc_Ntk_t * pNtk )
00454 {
00455 Nm_ManFree( pNtk->pManName );
00456 pNtk->pManName = Nm_ManCreate( Abc_NtkCiNum(pNtk) + Abc_NtkCoNum(pNtk) + Abc_NtkBoxNum(pNtk) );
00457 Abc_NtkAddDummyPiNames( pNtk );
00458 Abc_NtkAddDummyPoNames( pNtk );
00459 Abc_NtkAddDummyAssertNames( pNtk );
00460 Abc_NtkAddDummyBoxNames( pNtk );
00461 }
00462
00466
00467