00001
00021 #include "abc.h"
00022
00026
00027 static Hop_Man_t * Abc_NtkToMini( Abc_Ntk_t * pNtk );
00028 static Abc_Ntk_t * Abc_NtkFromMini( Abc_Ntk_t * pNtkOld, Hop_Man_t * pMan );
00029
00033
00045 Abc_Ntk_t * Abc_NtkMiniBalance( Abc_Ntk_t * pNtk )
00046 {
00047 Abc_Ntk_t * pNtkAig;
00048 Hop_Man_t * pMan, * pTemp;
00049 assert( Abc_NtkIsStrash(pNtk) );
00050
00051 pMan = Abc_NtkToMini( pNtk );
00052 if ( pMan == NULL )
00053 return NULL;
00054 if ( !Hop_ManCheck( pMan ) )
00055 {
00056 printf( "AIG check has failed.\n" );
00057 Hop_ManStop( pMan );
00058 return NULL;
00059 }
00060
00061 Hop_ManPrintStats( pMan );
00062
00063 pMan = Hop_ManBalance( pTemp = pMan, 1 );
00064 Hop_ManStop( pTemp );
00065 Hop_ManPrintStats( pMan );
00066
00067 pNtkAig = Abc_NtkFromMini( pNtk, pMan );
00068 if ( pNtkAig == NULL )
00069 return NULL;
00070 Hop_ManStop( pMan );
00071
00072 if ( !Abc_NtkCheck( pNtkAig ) )
00073 {
00074 printf( "Abc_NtkStrash: The network check has failed.\n" );
00075 Abc_NtkDelete( pNtkAig );
00076 return NULL;
00077 }
00078 return pNtkAig;
00079 }
00080
00092 Hop_Man_t * Abc_NtkToMini( Abc_Ntk_t * pNtk )
00093 {
00094 Hop_Man_t * pMan;
00095 Abc_Obj_t * pObj;
00096 int i;
00097
00098 pMan = Hop_ManStart();
00099
00100 Abc_AigConst1(pNtk)->pCopy = (Abc_Obj_t *)Hop_ManConst1(pMan);
00101 Abc_NtkForEachCi( pNtk, pObj, i )
00102 pObj->pCopy = (Abc_Obj_t *)Hop_ObjCreatePi(pMan);
00103
00104 Abc_NtkForEachNode( pNtk, pObj, i )
00105 pObj->pCopy = (Abc_Obj_t *)Hop_And( pMan, (Hop_Obj_t *)Abc_ObjChild0Copy(pObj), (Hop_Obj_t *)Abc_ObjChild1Copy(pObj) );
00106
00107 Abc_NtkForEachCo( pNtk, pObj, i )
00108 Hop_ObjCreatePo( pMan, (Hop_Obj_t *)Abc_ObjChild0Copy(pObj) );
00109 Hop_ManCleanup( pMan );
00110 return pMan;
00111 }
00112
00124 Abc_Ntk_t * Abc_NtkFromMini( Abc_Ntk_t * pNtk, Hop_Man_t * pMan )
00125 {
00126 Vec_Ptr_t * vNodes;
00127 Abc_Ntk_t * pNtkNew;
00128 Hop_Obj_t * pObj;
00129 int i;
00130
00131 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG );
00132
00133 Hop_ManConst1(pMan)->pData = Abc_AigConst1(pNtkNew);
00134 Hop_ManForEachPi( pMan, pObj, i )
00135 pObj->pData = Abc_NtkCi(pNtkNew, i);
00136
00137 vNodes = Hop_ManDfs( pMan );
00138 Vec_PtrForEachEntry( vNodes, pObj, i )
00139 pObj->pData = Abc_AigAnd( pNtkNew->pManFunc, (Abc_Obj_t *)Hop_ObjChild0Copy(pObj), (Abc_Obj_t *)Hop_ObjChild1Copy(pObj) );
00140 Vec_PtrFree( vNodes );
00141
00142 Hop_ManForEachPo( pMan, pObj, i )
00143 Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, i), (Abc_Obj_t *)Hop_ObjChild0Copy(pObj) );
00144 if ( !Abc_NtkCheck( pNtkNew ) )
00145 fprintf( stdout, "Abc_NtkFromMini(): Network check has failed.\n" );
00146 return pNtkNew;
00147 }
00148
00152
00153