00001
00021 #include "abc.h"
00022 #include "io.h"
00023
00027
00028 static stmm_table * Abc_NtkDressDeriveMapping( Abc_Ntk_t * pNtk );
00029 static void Abc_NtkDressTransferNames( Abc_Ntk_t * pNtk, stmm_table * tMapping, int fVerbose );
00030
00031 extern Abc_Ntk_t * Abc_NtkIvyFraig( Abc_Ntk_t * pNtk, int nConfLimit, int fDoSparse, int fProve, int fTransfer, int fVerbose );
00032
00036
00048 void Abc_NtkDress( Abc_Ntk_t * pNtkLogic, char * pFileName, int fVerbose )
00049 {
00050 Abc_Ntk_t * pNtkOrig, * pNtkLogicOrig;
00051 Abc_Ntk_t * pMiter, * pMiterFraig;
00052 stmm_table * tMapping;
00053
00054 assert( Abc_NtkIsLogic(pNtkLogic) );
00055
00056
00057 pNtkOrig = Io_ReadNetlist( pFileName, Io_ReadFileType(pFileName), 1 );
00058 if ( pNtkOrig == NULL )
00059 return;
00060 assert( Abc_NtkIsNetlist(pNtkOrig) );
00061
00062 Abc_NtkCleanCopy(pNtkLogic);
00063 Abc_NtkCleanCopy(pNtkOrig);
00064
00065
00066 pNtkLogicOrig = Abc_NtkToLogic( pNtkOrig );
00067
00068 if ( !Abc_NtkCompareSignals( pNtkLogic, pNtkLogicOrig, 1, 1 ) )
00069 {
00070 Abc_NtkDelete( pNtkOrig );
00071 Abc_NtkDelete( pNtkLogicOrig );
00072 return;
00073 }
00074
00075
00076 pMiter = Abc_NtkStrash( pNtkLogic, 1, 0, 0 );
00077
00078
00079 Abc_NtkAppend( pMiter, pNtkLogicOrig, 1 );
00080 Abc_NtkTransferCopy( pNtkOrig );
00081 Abc_NtkDelete( pNtkLogicOrig );
00082
00083 if ( fVerbose )
00084 {
00085 printf( "After mitering:\n" );
00086 printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
00087 printf( "Orig: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkOrig), Abc_NtkCountCopy(pNtkOrig) );
00088 }
00089
00090
00091 pMiterFraig = Abc_NtkIvyFraig( pMiter, 100, 1, 0, 1, 0 );
00092
00093 Abc_NtkTransferCopy( pNtkLogic );
00094 Abc_NtkTransferCopy( pNtkOrig );
00095 Abc_NtkDelete( pMiter );
00096
00097 if ( fVerbose )
00098 {
00099 printf( "After fraiging:\n" );
00100 printf( "Logic: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkLogic), Abc_NtkCountCopy(pNtkLogic) );
00101 printf( "Orig: Nodes = %5d. Copy = %5d. \n", Abc_NtkNodeNum(pNtkOrig), Abc_NtkCountCopy(pNtkOrig) );
00102 }
00103
00104
00105 tMapping = Abc_NtkDressDeriveMapping( pNtkOrig );
00106
00107
00108 Abc_NtkDressTransferNames( pNtkLogic, tMapping, fVerbose );
00109
00110
00111 stmm_free_table( tMapping );
00112 Abc_NtkDelete( pMiterFraig );
00113 Abc_NtkDelete( pNtkOrig );
00114 }
00115
00127 stmm_table * Abc_NtkDressDeriveMapping( Abc_Ntk_t * pNtk )
00128 {
00129 stmm_table * tResult;
00130 Abc_Obj_t * pNode, * pNodeMap, * pNodeFraig;
00131 int i;
00132 assert( Abc_NtkIsNetlist(pNtk) );
00133 tResult = stmm_init_table(stmm_ptrcmp,stmm_ptrhash);
00134 Abc_NtkForEachNode( pNtk, pNode, i )
00135 {
00136
00137 pNodeFraig = Abc_ObjRegular(pNode->pCopy);
00138
00139 if ( stmm_is_member( tResult, (char *)pNodeFraig ) )
00140 continue;
00141
00142 pNodeMap = Abc_ObjNotCond( pNode, Abc_ObjIsComplement(pNode->pCopy) );
00143
00144 stmm_insert( tResult, (char *)pNodeFraig, (char *)pNodeMap );
00145 }
00146 return tResult;
00147 }
00148
00160 void Abc_NtkDressTransferNames( Abc_Ntk_t * pNtk, stmm_table * tMapping, int fVerbose )
00161 {
00162 Abc_Obj_t * pNet, * pNode, * pNodeMap, * pNodeFraig;
00163 char * pName;
00164 int i, Counter = 0, CounterInv = 0, CounterInit = stmm_count(tMapping);
00165 assert( Abc_NtkIsLogic(pNtk) );
00166 Abc_NtkForEachNode( pNtk, pNode, i )
00167 {
00168
00169 pName = Nm_ManFindNameById( pNtk->pManName, pNode->Id );
00170 if ( pName != NULL )
00171 continue;
00172
00173 pNodeFraig = Abc_ObjRegular(pNode->pCopy);
00174
00175 if ( !stmm_lookup( tMapping, (char *)pNodeFraig, (char **)&pNodeMap ) )
00176 continue;
00177
00178 pNodeMap = Abc_ObjNotCond( pNodeMap, Abc_ObjIsComplement(pNode->pCopy) );
00179
00180 pNet = Abc_ObjFanout0(Abc_ObjRegular(pNodeMap));
00181 pName = Nm_ManFindNameById( pNet->pNtk->pManName, pNet->Id );
00182 assert( pName != NULL );
00183
00184 if ( Abc_ObjIsComplement(pNodeMap) )
00185 {
00186 Abc_ObjAssignName( pNode, pName, "_inv" );
00187 CounterInv++;
00188 }
00189 else
00190 {
00191 Abc_ObjAssignName( pNode, pName, NULL );
00192 Counter++;
00193 }
00194
00195 stmm_delete( tMapping, (char **)&pNodeFraig, (char **)&pNodeMap );
00196 }
00197 if ( fVerbose )
00198 {
00199 printf( "Total number of names collected = %5d.\n", CounterInit );
00200 printf( "Total number of names assigned = %5d. (Dir = %5d. Compl = %5d.)\n",
00201 Counter + CounterInv, Counter, CounterInv );
00202 }
00203 }
00204
00208
00209