00001
00021 #include "abc.h"
00022 #include "abcInt.h"
00023 #include "main.h"
00024 #include "mio.h"
00025
00029
00033
00045 Abc_Ntk_t * Abc_NtkAlloc( Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan )
00046 {
00047 Abc_Ntk_t * pNtk;
00048 pNtk = ALLOC( Abc_Ntk_t, 1 );
00049 memset( pNtk, 0, sizeof(Abc_Ntk_t) );
00050 pNtk->ntkType = Type;
00051 pNtk->ntkFunc = Func;
00052
00053 pNtk->vObjs = Vec_PtrAlloc( 100 );
00054 pNtk->vAsserts = Vec_PtrAlloc( 100 );
00055 pNtk->vPios = Vec_PtrAlloc( 100 );
00056 pNtk->vPis = Vec_PtrAlloc( 100 );
00057 pNtk->vPos = Vec_PtrAlloc( 100 );
00058 pNtk->vCis = Vec_PtrAlloc( 100 );
00059 pNtk->vCos = Vec_PtrAlloc( 100 );
00060 pNtk->vBoxes = Vec_PtrAlloc( 100 );
00061
00062 pNtk->pMmObj = fUseMemMan? Extra_MmFixedStart( sizeof(Abc_Obj_t) ) : NULL;
00063 pNtk->pMmStep = fUseMemMan? Extra_MmStepStart( ABC_NUM_STEPS ) : NULL;
00064
00065 pNtk->nTravIds = 1;
00066
00067 if ( Abc_NtkIsStrash(pNtk) )
00068 pNtk->pManFunc = Abc_AigAlloc( pNtk );
00069 else if ( Abc_NtkHasSop(pNtk) || Abc_NtkHasBlifMv(pNtk) )
00070 pNtk->pManFunc = Extra_MmFlexStart();
00071 else if ( Abc_NtkHasBdd(pNtk) )
00072 pNtk->pManFunc = Cudd_Init( 20, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 );
00073 else if ( Abc_NtkHasAig(pNtk) )
00074 pNtk->pManFunc = Hop_ManStart();
00075 else if ( Abc_NtkHasMapping(pNtk) )
00076 pNtk->pManFunc = Abc_FrameReadLibGen();
00077 else if ( !Abc_NtkHasBlackbox(pNtk) )
00078 assert( 0 );
00079
00080 pNtk->pManName = Nm_ManCreate( 200 );
00081
00082 pNtk->vAttrs = Vec_PtrStart( VEC_ATTR_TOTAL_NUM );
00083 return pNtk;
00084 }
00085
00097 Abc_Ntk_t * Abc_NtkStartFrom( Abc_Ntk_t * pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func )
00098 {
00099 Abc_Ntk_t * pNtkNew;
00100 Abc_Obj_t * pObj;
00101 int fCopyNames, i;
00102 if ( pNtk == NULL )
00103 return NULL;
00104
00105 fCopyNames = ( Type != ABC_NTK_NETLIST );
00106
00107 pNtkNew = Abc_NtkAlloc( Type, Func, 1 );
00108
00109 pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
00110 pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec);
00111
00112 Abc_NtkCleanCopy( pNtk );
00113
00114 if ( Abc_NtkIsStrash(pNtk) && Abc_NtkIsStrash(pNtkNew) )
00115 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00116
00117 Abc_NtkForEachPi( pNtk, pObj, i )
00118 Abc_NtkDupObj( pNtkNew, pObj, fCopyNames );
00119 Abc_NtkForEachPo( pNtk, pObj, i )
00120 Abc_NtkDupObj( pNtkNew, pObj, fCopyNames );
00121 Abc_NtkForEachAssert( pNtk, pObj, i )
00122 Abc_NtkDupObj( pNtkNew, pObj, fCopyNames );
00123 Abc_NtkForEachBox( pNtk, pObj, i )
00124 Abc_NtkDupBox( pNtkNew, pObj, fCopyNames );
00125
00126
00127 Abc_ManTimeDup( pNtk, pNtkNew );
00128
00129 assert( Abc_NtkCiNum(pNtk) == Abc_NtkCiNum(pNtkNew) );
00130 assert( Abc_NtkCoNum(pNtk) == Abc_NtkCoNum(pNtkNew) );
00131 assert( Abc_NtkLatchNum(pNtk) == Abc_NtkLatchNum(pNtkNew) );
00132 return pNtkNew;
00133 }
00134
00146 Abc_Ntk_t * Abc_NtkStartFromNoLatches( Abc_Ntk_t * pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func )
00147 {
00148 Abc_Ntk_t * pNtkNew;
00149 Abc_Obj_t * pObj;
00150 int i;
00151 if ( pNtk == NULL )
00152 return NULL;
00153 assert( Type != ABC_NTK_NETLIST );
00154
00155 pNtkNew = Abc_NtkAlloc( Type, Func, 1 );
00156
00157 pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
00158 pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec);
00159
00160 Abc_NtkCleanCopy( pNtk );
00161
00162 if ( Abc_NtkIsStrash(pNtk) && Abc_NtkIsStrash(pNtkNew) )
00163 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00164
00165 Abc_NtkForEachPi( pNtk, pObj, i )
00166 Abc_NtkDupObj( pNtkNew, pObj, 1 );
00167 Abc_NtkForEachPo( pNtk, pObj, i )
00168 Abc_NtkDupObj( pNtkNew, pObj, 1 );
00169 Abc_NtkForEachAssert( pNtk, pObj, i )
00170 Abc_NtkDupObj( pNtkNew, pObj, 1 );
00171 Abc_NtkForEachBox( pNtk, pObj, i )
00172 {
00173 if ( Abc_ObjIsLatch(pObj) )
00174 continue;
00175 Abc_NtkDupBox(pNtkNew, pObj, 1);
00176 }
00177
00178
00179 Abc_ManTimeDup( pNtk, pNtkNew );
00180
00181 assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkNew) );
00182 assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkNew) );
00183 return pNtkNew;
00184 }
00185
00197 void Abc_NtkFinalize( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew )
00198 {
00199 Abc_Obj_t * pObj, * pDriver, * pDriverNew;
00200 int i;
00201
00202 Abc_NtkForEachCo( pNtk, pObj, i )
00203 {
00204 pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pObj) );
00205 pDriverNew = Abc_ObjNotCond(pDriver->pCopy, Abc_ObjFaninC0(pObj));
00206 Abc_ObjAddFanin( pObj->pCopy, pDriverNew );
00207 }
00208 }
00209
00221 Abc_Ntk_t * Abc_NtkStartRead( char * pName )
00222 {
00223 Abc_Ntk_t * pNtkNew;
00224
00225 pNtkNew = Abc_NtkAlloc( ABC_NTK_NETLIST, ABC_FUNC_SOP, 1 );
00226
00227 pNtkNew->pName = Extra_FileNameGeneric(pName);
00228 pNtkNew->pSpec = Extra_UtilStrsav(pName);
00229 if ( pNtkNew->pName == NULL || strlen(pNtkNew->pName) == 0 )
00230 {
00231 FREE( pNtkNew->pName );
00232 pNtkNew->pName = Extra_UtilStrsav("unknown");
00233 }
00234 return pNtkNew;
00235 }
00236
00248 void Abc_NtkFinalizeRead( Abc_Ntk_t * pNtk )
00249 {
00250 Abc_Obj_t * pBox, * pObj, * pTerm, * pNet;
00251 int i;
00252 if ( Abc_NtkHasBlackbox(pNtk) && Abc_NtkBoxNum(pNtk) == 0 )
00253 {
00254 pBox = Abc_NtkCreateBlackbox(pNtk);
00255 Abc_NtkForEachPi( pNtk, pObj, i )
00256 {
00257 pTerm = Abc_NtkCreateBi(pNtk);
00258 Abc_ObjAddFanin( pTerm, Abc_ObjFanout0(pObj) );
00259 Abc_ObjAddFanin( pBox, pTerm );
00260 }
00261 Abc_NtkForEachPo( pNtk, pObj, i )
00262 {
00263 pTerm = Abc_NtkCreateBo(pNtk);
00264 Abc_ObjAddFanin( pTerm, pBox );
00265 Abc_ObjAddFanin( Abc_ObjFanin0(pObj), pTerm );
00266 }
00267 return;
00268 }
00269 assert( Abc_NtkIsNetlist(pNtk) );
00270
00271
00272 pNet = Abc_NtkFindNet( pNtk, "1\'b0" );
00273 if ( pNet )
00274 {
00275 if ( Abc_ObjFanoutNum(pNet) == 0 )
00276 Abc_NtkDeleteObj(pNet);
00277 else if ( Abc_ObjFaninNum(pNet) == 0 )
00278 Abc_ObjAddFanin( pNet, Abc_NtkCreateNodeConst0(pNtk) );
00279 }
00280
00281 pNet = Abc_NtkFindNet( pNtk, "1\'b1" );
00282 if ( pNet )
00283 {
00284 if ( Abc_ObjFanoutNum(pNet) == 0 )
00285 Abc_NtkDeleteObj(pNet);
00286 else if ( Abc_ObjFaninNum(pNet) == 0 )
00287 Abc_ObjAddFanin( pNet, Abc_NtkCreateNodeConst1(pNtk) );
00288 }
00289
00290 Abc_NtkFixNonDrivenNets( pNtk );
00291
00292
00293 Abc_NtkOrderCisCos( pNtk );
00294 }
00295
00307 Abc_Ntk_t * Abc_NtkDup( Abc_Ntk_t * pNtk )
00308 {
00309 Abc_Ntk_t * pNtkNew;
00310 Abc_Obj_t * pObj, * pFanin;
00311 int i, k;
00312 if ( pNtk == NULL )
00313 return NULL;
00314
00315 pNtkNew = Abc_NtkStartFrom( pNtk, pNtk->ntkType, pNtk->ntkFunc );
00316
00317 if ( Abc_NtkIsStrash(pNtk) )
00318 {
00319
00320 Abc_AigForEachAnd( pNtk, pObj, i )
00321 pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
00322
00323 Abc_AigForEachAnd( pNtk, pObj, i )
00324 if ( pObj->pData )
00325 pObj->pCopy->pData = ((Abc_Obj_t *)pObj->pData)->pCopy;
00326
00327 Abc_NtkForEachCo( pNtk, pObj, i )
00328 Abc_ObjAddFanin( pObj->pCopy, Abc_ObjChild0Copy(pObj) );
00329
00330 if ( Abc_NtkNodeNum(pNtk) != Abc_NtkNodeNum(pNtkNew) )
00331 printf( "Warning: Structural hashing during duplication reduced %d nodes (this is a minor bug).\n",
00332 Abc_NtkNodeNum(pNtk) - Abc_NtkNodeNum(pNtkNew) );
00333 }
00334 else
00335 {
00336
00337 Abc_NtkForEachObj( pNtk, pObj, i )
00338 if ( pObj->pCopy == NULL )
00339 Abc_NtkDupObj(pNtkNew, pObj, 0);
00340
00341 Abc_NtkForEachObj( pNtk, pObj, i )
00342 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
00343 Abc_ObjForEachFanin( pObj, pFanin, k )
00344 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00345 }
00346
00347 if ( pNtk->pExdc )
00348 pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
00349 if ( !Abc_NtkCheck( pNtkNew ) )
00350 fprintf( stdout, "Abc_NtkDup(): Network check has failed.\n" );
00351 pNtk->pCopy = pNtkNew;
00352 return pNtkNew;
00353 }
00354
00366 Abc_Ntk_t * Abc_NtkDouble( Abc_Ntk_t * pNtk )
00367 {
00368 char Buffer[500];
00369 Abc_Ntk_t * pNtkNew;
00370 Abc_Obj_t * pObj, * pFanin;
00371 int i, k;
00372 assert( Abc_NtkIsLogic(pNtk) );
00373
00374
00375 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
00376 sprintf( Buffer, "%s%s", pNtk->pName, "_2x" );
00377 pNtkNew->pName = Extra_UtilStrsav(Buffer);
00378
00379
00380 Abc_NtkCleanCopy( pNtk );
00381
00382 Abc_NtkForEachPi( pNtk, pObj, i )
00383 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00384 Abc_NtkForEachPo( pNtk, pObj, i )
00385 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00386 Abc_NtkForEachAssert( pNtk, pObj, i )
00387 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00388 Abc_NtkForEachBox( pNtk, pObj, i )
00389 Abc_NtkDupBox( pNtkNew, pObj, 0 );
00390
00391
00392 Abc_NtkForEachObj( pNtk, pObj, i )
00393 if ( pObj->pCopy == NULL )
00394 Abc_NtkDupObj(pNtkNew, pObj, 0);
00395
00396 Abc_NtkForEachObj( pNtk, pObj, i )
00397 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
00398 Abc_ObjForEachFanin( pObj, pFanin, k )
00399 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00400
00401
00402 Abc_NtkCleanCopy( pNtk );
00403
00404 Abc_NtkForEachPi( pNtk, pObj, i )
00405 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00406 Abc_NtkForEachPo( pNtk, pObj, i )
00407 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00408 Abc_NtkForEachAssert( pNtk, pObj, i )
00409 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00410 Abc_NtkForEachBox( pNtk, pObj, i )
00411 Abc_NtkDupBox( pNtkNew, pObj, 0 );
00412
00413
00414 Abc_NtkForEachObj( pNtk, pObj, i )
00415 if ( pObj->pCopy == NULL )
00416 Abc_NtkDupObj(pNtkNew, pObj, 0);
00417
00418 Abc_NtkForEachObj( pNtk, pObj, i )
00419 if ( !Abc_ObjIsBox(pObj) && !Abc_ObjIsBo(pObj) )
00420 Abc_ObjForEachFanin( pObj, pFanin, k )
00421 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00422
00423
00424 Abc_NtkForEachCi( pNtk, pObj, i )
00425 {
00426 Abc_ObjAssignName( Abc_NtkCi(pNtkNew, i), "1_", Abc_ObjName(pObj) );
00427 Abc_ObjAssignName( Abc_NtkCi(pNtkNew, Abc_NtkCiNum(pNtk) + i), "2_", Abc_ObjName(pObj) );
00428 }
00429 Abc_NtkForEachCo( pNtk, pObj, i )
00430 {
00431 Abc_ObjAssignName( Abc_NtkCo(pNtkNew, i), "1_", Abc_ObjName(pObj) );
00432 Abc_ObjAssignName( Abc_NtkCo(pNtkNew, Abc_NtkCoNum(pNtk) + i), "2_", Abc_ObjName(pObj) );
00433 }
00434
00435
00436 if ( !Abc_NtkCheck( pNtkNew ) )
00437 fprintf( stdout, "Abc_NtkDup(): Network check has failed.\n" );
00438 return pNtkNew;
00439 }
00440
00452 Abc_Ntk_t * Abc_NtkAttachBottom( Abc_Ntk_t * pNtkTop, Abc_Ntk_t * pNtkBottom )
00453 {
00454 Abc_Obj_t * pObj, * pFanin, * pBuffer;
00455 Vec_Ptr_t * vNodes;
00456 int i, k;
00457 assert( pNtkBottom != NULL );
00458 if ( pNtkTop == NULL )
00459 return pNtkBottom;
00460
00461 assert( Abc_NtkPiNum(pNtkTop) == Abc_NtkCiNum(pNtkTop) );
00462 assert( Abc_NtkPiNum(pNtkBottom) == Abc_NtkCiNum(pNtkBottom) );
00463
00464 assert( Abc_NtkPoNum(pNtkBottom) == Abc_NtkPiNum(pNtkTop) );
00465 assert( Abc_NtkPiNum(pNtkBottom) < Abc_NtkPiNum(pNtkTop) );
00466
00467 Abc_NtkForEachPi( pNtkTop, pObj, i )
00468 {
00469 pBuffer = Abc_NtkCreateNodeBuf( pNtkTop, NULL );
00470 Abc_ObjTransferFanout( pObj, pBuffer );
00471 Abc_NtkPo(pNtkBottom, i)->pCopy = pBuffer;
00472 }
00473
00474 for ( i = Abc_NtkPiNum(pNtkTop) - 1; i >= Abc_NtkPiNum(pNtkBottom); i-- )
00475 Abc_NtkDeleteObj( Abc_NtkPi(pNtkTop, i) );
00476 assert( Abc_NtkPiNum(pNtkBottom) == Abc_NtkPiNum(pNtkTop) );
00477
00478 Abc_NtkForEachPi( pNtkBottom, pObj, i )
00479 Abc_NtkPi(pNtkBottom, i)->pCopy = Abc_NtkPi(pNtkTop, i);
00480
00481 vNodes = Abc_NtkDfs( pNtkBottom, 0 );
00482 Vec_PtrForEachEntry( vNodes, pObj, i )
00483 {
00484 Abc_NtkDupObj(pNtkTop, pObj, 0);
00485 Abc_ObjForEachFanin( pObj, pFanin, k )
00486 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00487 }
00488 Vec_PtrFree( vNodes );
00489
00490 Abc_NtkForEachPo( pNtkBottom, pObj, i )
00491 Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pObj)->pCopy );
00492
00493 Abc_NtkDelete( pNtkBottom );
00494
00495 if ( !Abc_NtkCheck( pNtkTop ) )
00496 fprintf( stdout, "Abc_NtkAttachBottom(): Network check has failed.\n" );
00497 return pNtkTop;
00498 }
00499
00511 Abc_Ntk_t * Abc_NtkCreateCone( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode, char * pNodeName, int fUseAllCis )
00512 {
00513 Abc_Ntk_t * pNtkNew;
00514 Vec_Ptr_t * vNodes;
00515 Abc_Obj_t * pObj, * pFanin, * pNodeCoNew;
00516 char Buffer[1000];
00517 int i, k;
00518
00519 assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsStrash(pNtk) );
00520 assert( Abc_ObjIsNode(pNode) );
00521
00522
00523 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
00524
00525 sprintf( Buffer, "%s_%s", pNtk->pName, pNodeName );
00526 pNtkNew->pName = Extra_UtilStrsav(Buffer);
00527
00528
00529 if ( Abc_NtkIsStrash(pNtk) )
00530 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00531
00532
00533 vNodes = Abc_NtkDfsNodes( pNtk, &pNode, 1 );
00534
00535 Abc_NtkForEachCi( pNtk, pObj, i )
00536 {
00537 if ( fUseAllCis || Abc_NodeIsTravIdCurrent(pObj) )
00538 {
00539 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
00540 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00541 }
00542 }
00543
00544 pNodeCoNew = Abc_NtkCreatePo( pNtkNew );
00545 Abc_ObjAssignName( pNodeCoNew, pNodeName, NULL );
00546
00547 Vec_PtrForEachEntry( vNodes, pObj, i )
00548 {
00549
00550 if ( Abc_NtkIsStrash(pNtk) )
00551 {
00552 pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
00553 }
00554 else
00555 {
00556 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00557 Abc_ObjForEachFanin( pObj, pFanin, k )
00558 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00559 }
00560 }
00561
00562 Abc_ObjAddFanin( pNodeCoNew, pNode->pCopy );
00563 Vec_PtrFree( vNodes );
00564
00565 if ( !Abc_NtkCheck( pNtkNew ) )
00566 fprintf( stdout, "Abc_NtkCreateCone(): Network check has failed.\n" );
00567 return pNtkNew;
00568 }
00569
00581 Abc_Ntk_t * Abc_NtkCreateConeArray( Abc_Ntk_t * pNtk, Vec_Ptr_t * vRoots, int fUseAllCis )
00582 {
00583 Abc_Ntk_t * pNtkNew;
00584 Vec_Ptr_t * vNodes;
00585 Abc_Obj_t * pObj, * pFanin, * pNodeCoNew;
00586 char Buffer[1000];
00587 int i, k;
00588
00589 assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsStrash(pNtk) );
00590
00591
00592 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
00593
00594 sprintf( Buffer, "%s_part", pNtk->pName );
00595 pNtkNew->pName = Extra_UtilStrsav(Buffer);
00596
00597
00598 if ( Abc_NtkIsStrash(pNtk) )
00599 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00600
00601
00602 vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)Vec_PtrArray(vRoots), Vec_PtrSize(vRoots) );
00603
00604
00605 Abc_NtkForEachCi( pNtk, pObj, i )
00606 {
00607 if ( fUseAllCis || Abc_NodeIsTravIdCurrent(pObj) )
00608 {
00609 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
00610 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00611 }
00612 }
00613
00614
00615 Vec_PtrForEachEntry( vNodes, pObj, i )
00616 {
00617
00618 if ( Abc_NtkIsStrash(pNtk) )
00619 {
00620 pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
00621 }
00622 else
00623 {
00624 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00625 Abc_ObjForEachFanin( pObj, pFanin, k )
00626 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00627 }
00628 }
00629 Vec_PtrFree( vNodes );
00630
00631
00632 Vec_PtrForEachEntry( vRoots, pObj, i )
00633 {
00634
00635 pNodeCoNew = Abc_NtkCreatePo( pNtkNew );
00636
00637 if ( Abc_ObjIsCo(pObj) )
00638 Abc_ObjAddFanin( pNodeCoNew, Abc_ObjChild0Copy(pObj) );
00639 else
00640 Abc_ObjAddFanin( pNodeCoNew, pObj->pCopy );
00641
00642 Abc_ObjAssignName( pNodeCoNew, Abc_ObjName(pObj), NULL );
00643 }
00644
00645 if ( !Abc_NtkCheck( pNtkNew ) )
00646 fprintf( stdout, "Abc_NtkCreateConeArray(): Network check has failed.\n" );
00647 return pNtkNew;
00648 }
00649
00661 void Abc_NtkAppendToCone( Abc_Ntk_t * pNtkNew, Abc_Ntk_t * pNtk, Vec_Ptr_t * vRoots )
00662 {
00663 Vec_Ptr_t * vNodes;
00664 Abc_Obj_t * pObj;
00665 int i, iNodeId;
00666
00667 assert( Abc_NtkIsStrash(pNtkNew) );
00668 assert( Abc_NtkIsStrash(pNtk) );
00669
00670
00671 vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)Vec_PtrArray(vRoots), Vec_PtrSize(vRoots) );
00672
00673
00674 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00675
00676
00677 Abc_NtkForEachCi( pNtk, pObj, i )
00678 {
00679
00680 if ( !Abc_NodeIsTravIdCurrent(pObj) )
00681 continue;
00682
00683 iNodeId = Nm_ManFindIdByNameTwoTypes( pNtkNew->pManName, Abc_ObjName(pObj), ABC_OBJ_PI, ABC_OBJ_BO );
00684 if ( iNodeId == -1 )
00685 {
00686 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
00687 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00688 }
00689 else
00690 pObj->pCopy = Abc_NtkObj( pNtkNew, iNodeId );
00691 }
00692
00693
00694 Vec_PtrForEachEntry( vNodes, pObj, i )
00695 pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
00696 Vec_PtrFree( vNodes );
00697
00698
00699 if ( !Abc_NtkCheck( pNtkNew ) )
00700 fprintf( stdout, "Abc_NtkAppendToCone(): Network check has failed.\n" );
00701 }
00702
00714 Abc_Ntk_t * Abc_NtkCreateMffc( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode, char * pNodeName )
00715 {
00716 Abc_Ntk_t * pNtkNew;
00717 Abc_Obj_t * pObj, * pFanin, * pNodeCoNew;
00718 Vec_Ptr_t * vCone, * vSupp;
00719 char Buffer[1000];
00720 int i, k;
00721
00722 assert( Abc_NtkIsLogic(pNtk) || Abc_NtkIsStrash(pNtk) );
00723 assert( Abc_ObjIsNode(pNode) );
00724
00725
00726 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
00727
00728 sprintf( Buffer, "%s_%s", pNtk->pName, pNodeName );
00729 pNtkNew->pName = Extra_UtilStrsav(Buffer);
00730
00731
00732 if ( Abc_NtkIsStrash(pNtk) )
00733 Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
00734
00735
00736 vCone = Vec_PtrAlloc( 100 );
00737 vSupp = Vec_PtrAlloc( 100 );
00738 Abc_NodeDeref_rec( pNode );
00739 Abc_NodeMffsConeSupp( pNode, vCone, vSupp );
00740 Abc_NodeRef_rec( pNode );
00741
00742 Vec_PtrForEachEntry( vSupp, pObj, i )
00743 {
00744 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
00745 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00746 }
00747
00748 pNodeCoNew = Abc_NtkCreatePo( pNtkNew );
00749 Abc_ObjAssignName( pNodeCoNew, pNodeName, NULL );
00750
00751 Vec_PtrForEachEntry( vCone, pObj, i )
00752 {
00753
00754 if ( Abc_NtkIsStrash(pNtk) )
00755 {
00756 pObj->pCopy = Abc_AigAnd( pNtkNew->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) );
00757 }
00758 else
00759 {
00760 Abc_NtkDupObj( pNtkNew, pObj, 0 );
00761 Abc_ObjForEachFanin( pObj, pFanin, k )
00762 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
00763 }
00764 }
00765
00766 Abc_ObjAddFanin( pNodeCoNew, pNode->pCopy );
00767 Vec_PtrFree( vCone );
00768 Vec_PtrFree( vSupp );
00769
00770 if ( !Abc_NtkCheck( pNtkNew ) )
00771 fprintf( stdout, "Abc_NtkCreateMffc(): Network check has failed.\n" );
00772 return pNtkNew;
00773 }
00774
00786 Abc_Ntk_t * Abc_NtkCreateTarget( Abc_Ntk_t * pNtk, Vec_Ptr_t * vRoots, Vec_Int_t * vValues )
00787 {
00788 Vec_Ptr_t * vNodes;
00789 Abc_Ntk_t * pNtkNew;
00790 Abc_Obj_t * pObj, * pFinal, * pOther, * pNodePo;
00791 int i;
00792
00793 assert( Abc_NtkIsLogic(pNtk) );
00794
00795
00796 Abc_NtkCleanCopy( pNtk );
00797 pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
00798 pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
00799
00800
00801 vNodes = Abc_NtkDfsNodes( pNtk, (Abc_Obj_t **)vRoots->pArray, vRoots->nSize );
00802
00803 Abc_NtkForEachCi( pNtk, pObj, i )
00804 {
00805 pObj->pCopy = Abc_NtkCreatePi(pNtkNew);
00806 Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
00807 }
00808
00809 Vec_PtrForEachEntry( vNodes, pObj, i )
00810 pObj->pCopy = Abc_NodeStrash( pNtkNew, pObj, 0 );
00811 Vec_PtrFree( vNodes );
00812
00813
00814 pFinal = Abc_AigConst1( pNtkNew );
00815 Vec_PtrForEachEntry( vRoots, pObj, i )
00816 {
00817 if ( Abc_ObjIsCo(pObj) )
00818 pOther = Abc_ObjFanin0(pObj)->pCopy;
00819 else
00820 pOther = pObj->pCopy;
00821 if ( Vec_IntEntry(vValues, i) == 0 )
00822 pOther = Abc_ObjNot(pOther);
00823 pFinal = Abc_AigAnd( pNtkNew->pManFunc, pFinal, pOther );
00824 }
00825
00826
00827 pNodePo = Abc_NtkCreatePo( pNtkNew );
00828 Abc_ObjAddFanin( pNodePo, pFinal );
00829 Abc_ObjAssignName( pNodePo, "miter", NULL );
00830 if ( !Abc_NtkCheck( pNtkNew ) )
00831 fprintf( stdout, "Abc_NtkCreateTarget(): Network check has failed.\n" );
00832 return pNtkNew;
00833 }
00834
00846 Abc_Ntk_t * Abc_NtkCreateFromNode( Abc_Ntk_t * pNtk, Abc_Obj_t * pNode )
00847 {
00848 Abc_Ntk_t * pNtkNew;
00849 Abc_Obj_t * pFanin, * pNodePo;
00850 int i;
00851
00852 pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 );
00853 pNtkNew->pName = Extra_UtilStrsav(Abc_ObjName(pNode));
00854
00855 Abc_ObjForEachFanin( pNode, pFanin, i )
00856 {
00857 pFanin->pCopy = Abc_NtkCreatePi( pNtkNew );
00858 Abc_ObjAssignName( pFanin->pCopy, Abc_ObjName(pFanin), NULL );
00859 }
00860
00861 pNode->pCopy = Abc_NtkDupObj( pNtkNew, pNode, 0 );
00862 Abc_ObjForEachFanin( pNode, pFanin, i )
00863 Abc_ObjAddFanin( pNode->pCopy, pFanin->pCopy );
00864
00865 pNodePo = Abc_NtkCreatePo( pNtkNew );
00866 Abc_ObjAddFanin( pNodePo, pNode->pCopy );
00867 Abc_ObjAssignName( pNodePo, Abc_ObjName(pNode), NULL );
00868 if ( !Abc_NtkCheck( pNtkNew ) )
00869 fprintf( stdout, "Abc_NtkCreateFromNode(): Network check has failed.\n" );
00870 return pNtkNew;
00871 }
00872
00884 Abc_Ntk_t * Abc_NtkCreateWithNode( char * pSop )
00885 {
00886 Abc_Ntk_t * pNtkNew;
00887 Abc_Obj_t * pFanin, * pNode, * pNodePo;
00888 Vec_Ptr_t * vNames;
00889 int i, nVars;
00890
00891 pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_SOP, 1 );
00892 pNtkNew->pName = Extra_UtilStrsav("ex");
00893
00894 Vec_PtrPush( pNtkNew->vObjs, NULL );
00895 nVars = Abc_SopGetVarNum( pSop );
00896 vNames = Abc_NodeGetFakeNames( nVars );
00897 for ( i = 0; i < nVars; i++ )
00898 Abc_ObjAssignName( Abc_NtkCreatePi(pNtkNew), Vec_PtrEntry(vNames, i), NULL );
00899 Abc_NodeFreeNames( vNames );
00900
00901 pNode = Abc_NtkCreateNode( pNtkNew );
00902 Abc_NtkForEachPi( pNtkNew, pFanin, i )
00903 Abc_ObjAddFanin( pNode, pFanin );
00904 pNode->pData = Abc_SopRegister( pNtkNew->pManFunc, pSop );
00905
00906 pNodePo = Abc_NtkCreatePo(pNtkNew);
00907 Abc_ObjAddFanin( pNodePo, pNode );
00908 Abc_ObjAssignName( pNodePo, "F", NULL );
00909 if ( !Abc_NtkCheck( pNtkNew ) )
00910 fprintf( stdout, "Abc_NtkCreateWithNode(): Network check has failed.\n" );
00911 return pNtkNew;
00912 }
00913
00925 void Abc_NtkDelete( Abc_Ntk_t * pNtk )
00926 {
00927 Abc_Obj_t * pObj;
00928 void * pAttrMan;
00929 int TotalMemory, i;
00930 int LargePiece = (4 << ABC_NUM_STEPS);
00931 if ( pNtk == NULL )
00932 return;
00933
00934 if ( pNtk->pHaig )
00935 Abc_NtkHaigStop( pNtk );
00936
00937 if ( pNtk->pExdc )
00938 Abc_NtkDelete( pNtk->pExdc );
00939
00940 if ( Abc_NtkHasBdd(pNtk) )
00941 {
00942 Abc_NtkForEachNode( pNtk, pObj, i )
00943 Cudd_RecursiveDeref( pNtk->pManFunc, pObj->pData );
00944 }
00945
00946 Abc_NtkForEachObj( pNtk, pObj, i )
00947 {
00948
00949 if ( pNtk->pMmObj && pObj->vFanouts.nCap * 4 > LargePiece )
00950 FREE( pObj->vFanouts.pArray );
00951
00952
00953 assert( pObj->fMarkA == 0 );
00954 assert( pObj->fMarkB == 0 );
00955 assert( pObj->fMarkC == 0 );
00956 }
00957
00958 if ( pNtk->pMmStep == NULL )
00959 {
00960 Abc_NtkForEachObj( pNtk, pObj, i )
00961 {
00962 FREE( pObj->vFanouts.pArray );
00963 FREE( pObj->vFanins.pArray );
00964 }
00965 }
00966 if ( pNtk->pMmObj == NULL )
00967 {
00968 Abc_NtkForEachObj( pNtk, pObj, i )
00969 free( pObj );
00970 }
00971
00972
00973 Vec_PtrFree( pNtk->vPios );
00974 Vec_PtrFree( pNtk->vPis );
00975 Vec_PtrFree( pNtk->vPos );
00976 Vec_PtrFree( pNtk->vCis );
00977 Vec_PtrFree( pNtk->vCos );
00978 Vec_PtrFree( pNtk->vAsserts );
00979 Vec_PtrFree( pNtk->vObjs );
00980 Vec_PtrFree( pNtk->vBoxes );
00981 if ( pNtk->vLevelsR ) Vec_IntFree( pNtk->vLevelsR );
00982 if ( pNtk->pModel ) free( pNtk->pModel );
00983 TotalMemory = 0;
00984 TotalMemory += pNtk->pMmObj? Extra_MmFixedReadMemUsage(pNtk->pMmObj) : 0;
00985 TotalMemory += pNtk->pMmStep? Extra_MmStepReadMemUsage(pNtk->pMmStep) : 0;
00986
00987
00988 if ( pNtk->pMmObj )
00989 Extra_MmFixedStop( pNtk->pMmObj );
00990 if ( pNtk->pMmStep )
00991 Extra_MmStepStop ( pNtk->pMmStep );
00992
00993 Nm_ManFree( pNtk->pManName );
00994
00995 if ( pNtk->pManTime )
00996 Abc_ManTimeStop( pNtk->pManTime );
00997
00998 if ( Abc_NtkIsStrash(pNtk) )
00999 Abc_AigFree( pNtk->pManFunc );
01000 else if ( Abc_NtkHasSop(pNtk) || Abc_NtkHasBlifMv(pNtk) )
01001 Extra_MmFlexStop( pNtk->pManFunc );
01002 else if ( Abc_NtkHasBdd(pNtk) )
01003 Extra_StopManager( pNtk->pManFunc );
01004 else if ( Abc_NtkHasAig(pNtk) )
01005 { if ( pNtk->pManFunc ) Hop_ManStop( pNtk->pManFunc ); }
01006 else if ( Abc_NtkHasMapping(pNtk) )
01007 pNtk->pManFunc = NULL;
01008 else if ( !Abc_NtkHasBlackbox(pNtk) )
01009 assert( 0 );
01010
01011 if ( pNtk->pDesign )
01012 {
01013 Abc_LibFree( pNtk->pDesign, pNtk );
01014 pNtk->pDesign = NULL;
01015 }
01016
01017
01018
01019 Vec_PtrForEachEntry( pNtk->vAttrs, pAttrMan, i )
01020 if ( pAttrMan )
01021 {
01022
01023 Vec_AttFree( pAttrMan, 1 );
01024 }
01025 Vec_PtrFree( pNtk->vAttrs );
01026 FREE( pNtk->pName );
01027 FREE( pNtk->pSpec );
01028 free( pNtk );
01029 }
01030
01042 void Abc_NtkFixNonDrivenNets( Abc_Ntk_t * pNtk )
01043 {
01044 Vec_Ptr_t * vNets;
01045 Abc_Obj_t * pNet, * pNode;
01046 int i;
01047
01048 if ( Abc_NtkNodeNum(pNtk) == 0 && Abc_NtkBoxNum(pNtk) == 0 )
01049 return;
01050
01051
01052 vNets = Vec_PtrAlloc( 100 );
01053 Abc_NtkForEachNet( pNtk, pNet, i )
01054 {
01055 if ( Abc_ObjFaninNum(pNet) > 0 )
01056 continue;
01057
01058 pNode = Abc_NtkCreateNodeConst0( pNtk );
01059
01060 Abc_ObjAddFanin( pNet, pNode );
01061
01062 Vec_PtrPush( vNets, pNet );
01063 }
01064
01065
01066 if ( vNets->nSize > 0 )
01067 {
01068 printf( "Warning: Constant-0 drivers added to %d non-driven nets in network \"%s\":\n", Vec_PtrSize(vNets), pNtk->pName );
01069 Vec_PtrForEachEntry( vNets, pNet, i )
01070 {
01071 printf( "%s%s", (i? ", ": ""), Abc_ObjName(pNet) );
01072 if ( i == 3 )
01073 {
01074 if ( Vec_PtrSize(vNets) > 3 )
01075 printf( " ..." );
01076 break;
01077 }
01078 }
01079 printf( "\n" );
01080 }
01081 Vec_PtrFree( vNets );
01082 }
01083
01084
01096 void Abc_NtkMakeComb( Abc_Ntk_t * pNtk )
01097 {
01098 Abc_Obj_t * pObj;
01099 int i;
01100
01101 if ( Abc_NtkIsComb(pNtk) )
01102 return;
01103
01104 assert( !Abc_NtkIsNetlist(pNtk) );
01105 assert( Abc_NtkHasOnlyLatchBoxes(pNtk) );
01106
01107
01108
01109 Vec_PtrForEachEntryReverse( pNtk->vBoxes, pObj, i )
01110 Abc_NtkDeleteObj( pObj );
01111 assert( Abc_NtkLatchNum(pNtk) == 0 );
01112 assert( Abc_NtkBoxNum(pNtk) == 0 );
01113
01114
01115 Vec_PtrClear( pNtk->vPis );
01116 Abc_NtkForEachCi( pNtk, pObj, i )
01117 {
01118 if ( Abc_ObjIsBo(pObj) )
01119 {
01120 pObj->Type = ABC_OBJ_PI;
01121 pNtk->nObjCounts[ABC_OBJ_PI]++;
01122 pNtk->nObjCounts[ABC_OBJ_BO]--;
01123 }
01124 Vec_PtrPush( pNtk->vPis, pObj );
01125 }
01126 assert( Abc_NtkBoNum(pNtk) == 0 );
01127
01128
01129 Vec_PtrClear( pNtk->vPos );
01130 Abc_NtkForEachCo( pNtk, pObj, i )
01131 {
01132 if ( Abc_ObjIsBi(pObj) )
01133 {
01134 pObj->Type = ABC_OBJ_PO;
01135 pNtk->nObjCounts[ABC_OBJ_PO]++;
01136 pNtk->nObjCounts[ABC_OBJ_BI]--;
01137 }
01138 Vec_PtrPush( pNtk->vPos, pObj );
01139 }
01140 assert( Abc_NtkBiNum(pNtk) == 0 );
01141
01142 if ( !Abc_NtkCheck( pNtk ) )
01143 fprintf( stdout, "Abc_NtkMakeComb(): Network check has failed.\n" );
01144 }
01145
01146
01158 Abc_Ntk_t * Abc_NtkTrim( Abc_Ntk_t * pNtk )
01159 {
01160 Abc_Obj_t * pObj;
01161 int i, k, m;
01162
01163
01164 k = m = 0;
01165 Abc_NtkForEachCo( pNtk, pObj, i )
01166 {
01167 if ( Abc_ObjIsPo(pObj) )
01168 {
01169
01170 if ( Abc_ObjFaninNum(Abc_ObjFanin0(pObj)) == 0 )
01171 {
01172 Abc_ObjDeleteFanin( pObj, Abc_ObjFanin0(pObj) );
01173 if ( Abc_ObjFanoutNum(Abc_ObjFanin0(pObj)) == 0 && !Abc_ObjIsPi(Abc_ObjFanin0(pObj)) )
01174 Abc_NtkDeleteObj_rec( Abc_ObjFanin0(pObj), 1 );
01175 pNtk->vObjs->pArray[pObj->Id] = NULL;
01176 pObj->Id = (1<<26)-1;
01177 pNtk->nObjCounts[pObj->Type]--;
01178 pNtk->nObjs--;
01179 Abc_ObjRecycle( pObj );
01180 continue;
01181 }
01182
01183 if ( Abc_ObjFaninNum(Abc_ObjFanin0(pObj)) == 1 )
01184 {
01185 if ( Abc_ObjIsPi(Abc_ObjFanin0(Abc_ObjFanin0(pObj))) )
01186 {
01187 Abc_ObjDeleteFanin( pObj, Abc_ObjFanin0(pObj) );
01188 if ( Abc_ObjFanoutNum(Abc_ObjFanin0(pObj)) == 0 )
01189 Abc_NtkDeleteObj_rec( Abc_ObjFanin0(pObj), 1 );
01190 pNtk->vObjs->pArray[pObj->Id] = NULL;
01191 pObj->Id = (1<<26)-1;
01192 pNtk->nObjCounts[pObj->Type]--;
01193 pNtk->nObjs--;
01194 Abc_ObjRecycle( pObj );
01195 continue;
01196 }
01197 }
01198 Vec_PtrWriteEntry( pNtk->vPos, m++, pObj );
01199 }
01200 Vec_PtrWriteEntry( pNtk->vCos, k++, pObj );
01201 }
01202 Vec_PtrShrink( pNtk->vPos, m );
01203 Vec_PtrShrink( pNtk->vCos, k );
01204
01205
01206 k = m = 0;
01207 Abc_NtkForEachCi( pNtk, pObj, i )
01208 {
01209 if ( Abc_ObjIsPi(pObj) )
01210 {
01211 if ( Abc_ObjFanoutNum(pObj) == 0 )
01212 {
01213 pNtk->vObjs->pArray[pObj->Id] = NULL;
01214 pObj->Id = (1<<26)-1;
01215 pNtk->nObjCounts[pObj->Type]--;
01216 pNtk->nObjs--;
01217 Abc_ObjRecycle( pObj );
01218 continue;
01219 }
01220 Vec_PtrWriteEntry( pNtk->vPis, m++, pObj );
01221 }
01222 Vec_PtrWriteEntry( pNtk->vCis, k++, pObj );
01223 }
01224 Vec_PtrShrink( pNtk->vPis, m );
01225 Vec_PtrShrink( pNtk->vCis, k );
01226
01227 return Abc_NtkDup( pNtk );
01228 }
01229
01230
01234
01235