00001
00021 #include "abc.h"
00022
00026
00030
00042 Abc_Lib_t * Abc_LibCreate( char * pName )
00043 {
00044 Abc_Lib_t * p;
00045 p = ALLOC( Abc_Lib_t, 1 );
00046 memset( p, 0, sizeof(Abc_Lib_t) );
00047 p->pName = Extra_UtilStrsav( pName );
00048 p->tModules = st_init_table( strcmp, st_strhash );
00049 p->vTops = Vec_PtrAlloc( 100 );
00050 p->vModules = Vec_PtrAlloc( 100 );
00051 p->pManFunc = Hop_ManStart();
00052 p->pLibrary = NULL;
00053 return p;
00054 }
00055
00067 void Abc_LibFree( Abc_Lib_t * pLib, Abc_Ntk_t * pNtkSave )
00068 {
00069 Abc_Ntk_t * pNtk;
00070 int i;
00071 if ( pLib->pName )
00072 free( pLib->pName );
00073 if ( pLib->pManFunc )
00074 Hop_ManStop( pLib->pManFunc );
00075 if ( pLib->tModules )
00076 st_free_table( pLib->tModules );
00077 if ( pLib->vModules )
00078 {
00079 Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
00080 {
00081
00082 if ( pNtk == pNtkSave )
00083 continue;
00084 pNtk->pManFunc = NULL;
00085 pNtk->pDesign = NULL;
00086 Abc_NtkDelete( pNtk );
00087 }
00088 Vec_PtrFree( pLib->vModules );
00089 }
00090 if ( pLib->vTops )
00091 Vec_PtrFree( pLib->vTops );
00092 free( pLib );
00093 }
00094
00106 Abc_Lib_t * Abc_LibDupBlackboxes( Abc_Lib_t * pLib, Abc_Ntk_t * pNtkSave )
00107 {
00108 Abc_Lib_t * pLibNew;
00109 Abc_Ntk_t * pNtkTemp;
00110 int i;
00111 assert( Vec_PtrSize(pLib->vTops) > 0 );
00112 assert( Vec_PtrSize(pLib->vModules) > 1 );
00113 pLibNew = Abc_LibCreate( pLib->pName );
00114
00115 Vec_PtrPush( pLibNew->vTops, pNtkSave );
00116 Vec_PtrPush( pLibNew->vModules, pNtkSave );
00117 Vec_PtrForEachEntry( pLib->vModules, pNtkTemp, i )
00118 if ( Abc_NtkHasBlackbox( pNtkTemp ) )
00119 Vec_PtrPush( pLibNew->vModules, Abc_NtkDup(pNtkTemp) );
00120 return pLibNew;
00121 }
00122
00123
00135 void Abc_LibPrint( Abc_Lib_t * pLib )
00136 {
00137 Abc_Ntk_t * pNtk;
00138 Abc_Obj_t * pObj;
00139 int i, k;
00140 printf( "Models of design %s:\n", pLib->pName );
00141 Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
00142 {
00143 printf( "%2d : %20s ", i+1, pNtk->pName );
00144 printf( "nd = %6d lat = %6d whitebox = %3d blackbox = %3d\n",
00145 Abc_NtkNodeNum(pNtk), Abc_NtkLatchNum(pNtk),
00146 Abc_NtkWhiteboxNum(pNtk), Abc_NtkBlackboxNum(pNtk) );
00147 if ( Abc_NtkBlackboxNum(pNtk) == 0 )
00148 continue;
00149 Abc_NtkForEachWhitebox( pNtk, pObj, k )
00150 printf( " %20s (whitebox)\n", Abc_NtkName(pObj->pData) );
00151 Abc_NtkForEachBlackbox( pNtk, pObj, k )
00152 printf( " %20s (blackbox)\n", Abc_NtkName(pObj->pData) );
00153 }
00154 }
00155
00167 int Abc_LibAddModel( Abc_Lib_t * pLib, Abc_Ntk_t * pNtk )
00168 {
00169 if ( st_is_member( pLib->tModules, (char *)pNtk->pName ) )
00170 return 0;
00171 st_insert( pLib->tModules, (char *)pNtk->pName, (char *)pNtk );
00172 Vec_PtrPush( pLib->vModules, pNtk );
00173 pNtk->pDesign = pLib;
00174 return 1;
00175 }
00176
00188 Abc_Ntk_t * Abc_LibFindModelByName( Abc_Lib_t * pLib, char * pName )
00189 {
00190 Abc_Ntk_t * pNtk;
00191 if ( !st_is_member( pLib->tModules, (char *)pName ) )
00192 return NULL;
00193 st_lookup( pLib->tModules, (char *)pName, (char **)&pNtk );
00194 return pNtk;
00195 }
00196
00208 Abc_Ntk_t * Abc_LibDeriveRoot( Abc_Lib_t * pLib )
00209 {
00210 Abc_Ntk_t * pNtk;
00211 if ( Vec_PtrSize(pLib->vModules) > 1 )
00212 {
00213 printf( "The design includes more than one module and is currently not used.\n" );
00214 return NULL;
00215 }
00216 pNtk = Vec_PtrEntry( pLib->vModules, 0 ); Vec_PtrClear( pLib->vModules );
00217 pNtk->pManFunc = pLib->pManFunc; pLib->pManFunc = NULL;
00218 return pNtk;
00219 }
00220
00232 int Abc_LibFindTopLevelModels( Abc_Lib_t * pLib )
00233 {
00234 Abc_Ntk_t * pNtk, * pNtkBox;
00235 Abc_Obj_t * pObj;
00236 int i, k;
00237 assert( Vec_PtrSize( pLib->vModules ) > 0 );
00238
00239 Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
00240 pNtk->fHieVisited = 0;
00241
00242 Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
00243 {
00244 Abc_NtkForEachBox( pNtk, pObj, k )
00245 {
00246 if ( Abc_ObjIsLatch(pObj) )
00247 continue;
00248 if ( pObj->pData == NULL )
00249 continue;
00250 pNtkBox = pObj->pData;
00251 pNtkBox->fHieVisited = 1;
00252 }
00253 }
00254
00255 Vec_PtrClear( pLib->vTops );
00256 Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
00257 {
00258 if ( pNtk->fHieVisited == 0 )
00259 Vec_PtrPush( pLib->vTops, pNtk );
00260 else
00261 pNtk->fHieVisited = 0;
00262 }
00263 return Vec_PtrSize( pLib->vTops );
00264 }
00265
00266
00278 int Abc_LibDeriveBlackBoxes( Abc_Ntk_t * pNtk, Abc_Lib_t * pLib )
00279 {
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318 return 0;
00319 }
00320
00332 void Abc_NodeStrashUsingNetwork_rec( Abc_Ntk_t * pNtkAig, Abc_Obj_t * pObj )
00333 {
00334 Abc_Obj_t * pFanin;
00335 int i;
00336 assert( !Abc_ObjIsNet(pObj) );
00337 if ( pObj->pCopy )
00338 return;
00339
00340 Abc_ObjForEachFanin( pObj, pFanin, i )
00341 Abc_NodeStrashUsingNetwork_rec( pNtkAig, Abc_ObjFanin0Ntk(Abc_ObjFanin0(pObj)) );
00342
00343 pObj->pCopy = Abc_NodeStrash( pNtkAig, pObj, 0 );
00344
00345 Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
00346 }
00347
00359 void Abc_NodeStrashUsingNetwork( Abc_Ntk_t * pNtkAig, Abc_Obj_t * pBox )
00360 {
00361 Abc_Ntk_t * pNtkGate;
00362 Abc_Obj_t * pObj;
00363 unsigned * pPolarity;
00364 int i, fCompl;
00365 assert( Abc_ObjIsBox(pBox) );
00366 pNtkGate = pBox->pData;
00367 pPolarity = (unsigned *)pBox->pNext;
00368 assert( Abc_NtkIsNetlist(pNtkGate) );
00369 assert( Abc_NtkLatchNum(pNtkGate) == 0 );
00370 Abc_NtkCleanCopy( pNtkGate );
00371
00372 Abc_NtkForEachPi( pNtkGate, pObj, i )
00373 {
00374 fCompl = (pPolarity && Abc_InfoHasBit(pPolarity, i));
00375 pObj->pCopy = Abc_ObjNotCond( Abc_ObjFanin(pBox,i)->pCopy, fCompl );
00376 Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
00377 }
00378
00379 Abc_NtkForEachPo( pNtkGate, pObj, i )
00380 {
00381 Abc_NodeStrashUsingNetwork_rec( pNtkAig, Abc_ObjFanin0Ntk(Abc_ObjFanin0(pObj)) );
00382 Abc_ObjFanout(pBox,i)->pCopy = Abc_ObjFanin0(pObj)->pCopy;
00383 }
00384
00385 }
00386
00398 Abc_Ntk_t * Abc_LibDeriveAig( Abc_Ntk_t * pNtk, Abc_Lib_t * pLib )
00399 {
00400 ProgressBar * pProgress;
00401 Vec_Ptr_t * vNodes;
00402 Abc_Ntk_t * pNtkAig;
00403 Abc_Obj_t * pObj;
00404 int i, nBoxes;
00405
00406 assert( Abc_NtkIsNetlist(pNtk) );
00407 nBoxes = Abc_LibDeriveBlackBoxes( pNtk, pLib );
00408 if ( nBoxes )
00409 printf( "Detected and transformed %d black boxes.\n", nBoxes );
00410
00411 pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG );
00412
00413 Abc_NtkForEachCi( pNtk, pObj, i )
00414 Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
00415
00416 vNodes = Abc_NtkDfs( pNtk, 0 );
00417 pProgress = Extra_ProgressBarStart( stdout, Vec_PtrSize(vNodes) );
00418 Vec_PtrForEachEntry( vNodes, pObj, i )
00419 {
00420 Extra_ProgressBarUpdate( pProgress, i, NULL );
00421 if ( Abc_ObjIsNode(pObj) )
00422 {
00423 pObj->pCopy = Abc_NodeStrash( pNtkAig, pObj, 0 );
00424 Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
00425 continue;
00426 }
00427 Abc_NodeStrashUsingNetwork( pNtkAig, pObj );
00428 }
00429 Extra_ProgressBarStop( pProgress );
00430 Vec_PtrFree( vNodes );
00431
00432 if ( pNtk->pData )
00433 {
00434 Extra_MmFlexStop( pNtk->pData );
00435 pNtk->pData = NULL;
00436 }
00437
00438
00439 Abc_NtkForEachCo( pNtk, pObj, i )
00440 Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pObj)->pCopy );
00441 Abc_AigCleanup( pNtkAig->pManFunc );
00442
00443 if ( !Abc_NtkCheck( pNtkAig ) )
00444 {
00445 printf( "Abc_LibDeriveAig: The network check has failed.\n" );
00446 return 0;
00447 }
00448 return pNtkAig;
00449 }
00450
00454
00455