00001
00021 #include "io.h"
00022
00026
00027 static int Io_WriteBenchCheckNames( Abc_Ntk_t * pNtk );
00028
00029 static int Io_WriteBenchOne( FILE * pFile, Abc_Ntk_t * pNtk );
00030 static int Io_WriteBenchOneNode( FILE * pFile, Abc_Obj_t * pNode );
00031
00032 static int Io_WriteBenchLutOne( FILE * pFile, Abc_Ntk_t * pNtk );
00033 static int Io_WriteBenchLutOneNode( FILE * pFile, Abc_Obj_t * pNode, Vec_Int_t * vTruth );
00034
00038
00050 int Io_WriteBench( Abc_Ntk_t * pNtk, char * pFileName )
00051 {
00052 Abc_Ntk_t * pExdc;
00053 FILE * pFile;
00054 assert( Abc_NtkIsSopNetlist(pNtk) );
00055 if ( !Io_WriteBenchCheckNames(pNtk) )
00056 {
00057 fprintf( stdout, "Io_WriteBench(): Signal names in this benchmark contain parantheses making them impossible to reproduce in the BENCH format. Use \"short_names\".\n" );
00058 return 0;
00059 }
00060 pFile = fopen( pFileName, "w" );
00061 if ( pFile == NULL )
00062 {
00063 fprintf( stdout, "Io_WriteBench(): Cannot open the output file.\n" );
00064 return 0;
00065 }
00066 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00067
00068 Io_WriteBenchOne( pFile, pNtk );
00069
00070 pExdc = Abc_NtkExdc( pNtk );
00071 if ( pExdc )
00072 printf( "Io_WriteBench: EXDC is not written (warning).\n" );
00073
00074 fclose( pFile );
00075 return 1;
00076 }
00077
00089 int Io_WriteBenchOne( FILE * pFile, Abc_Ntk_t * pNtk )
00090 {
00091 ProgressBar * pProgress;
00092 Abc_Obj_t * pNode;
00093 int i;
00094
00095
00096 Abc_NtkForEachPi( pNtk, pNode, i )
00097 fprintf( pFile, "INPUT(%s)\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00098 Abc_NtkForEachPo( pNtk, pNode, i )
00099 fprintf( pFile, "OUTPUT(%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00100 Abc_NtkForEachLatch( pNtk, pNode, i )
00101 fprintf( pFile, "%-11s = DFF(%s)\n",
00102 Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode))), Abc_ObjName(Abc_ObjFanin0(Abc_ObjFanin0(pNode))) );
00103
00104
00105 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00106 Abc_NtkForEachNode( pNtk, pNode, i )
00107 {
00108 Extra_ProgressBarUpdate( pProgress, i, NULL );
00109 Io_WriteBenchOneNode( pFile, pNode );
00110 }
00111 Extra_ProgressBarStop( pProgress );
00112 return 1;
00113 }
00114
00115
00127 int Io_WriteBenchOneNode( FILE * pFile, Abc_Obj_t * pNode )
00128 {
00129 int nFanins;
00130
00131 assert( Abc_ObjIsNode(pNode) );
00132 nFanins = Abc_ObjFaninNum(pNode);
00133 if ( nFanins == 0 )
00134 {
00135 assert( Abc_NodeIsConst1(pNode) );
00136 fprintf( pFile, "%-11s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00137 fprintf( pFile, " = vdd\n" );
00138 }
00139 else if ( nFanins == 1 )
00140 {
00141 if ( Abc_NodeIsBuf(pNode) )
00142 {
00143 fprintf( pFile, "%-11s = BUFF(", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00144 fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00145 }
00146 else
00147 {
00148 fprintf( pFile, "%-11s = NOT(", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00149 fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00150 }
00151 }
00152 else
00153 {
00154 fprintf( pFile, "%-11s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00155 fprintf( pFile, " = AND(%s, ", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00156 fprintf( pFile, "%s)\n", Abc_ObjName(Abc_ObjFanin1(pNode)) );
00157 }
00158 return 1;
00159 }
00160
00172 int Io_WriteBenchLut( Abc_Ntk_t * pNtk, char * pFileName )
00173 {
00174 Abc_Ntk_t * pExdc;
00175 FILE * pFile;
00176 assert( Abc_NtkIsAigNetlist(pNtk) );
00177 if ( !Io_WriteBenchCheckNames(pNtk) )
00178 {
00179 fprintf( stdout, "Io_WriteBenchLut(): Signal names in this benchmark contain parantheses making them impossible to reproduce in the BENCH format. Use \"short_names\".\n" );
00180 return 0;
00181 }
00182 pFile = fopen( pFileName, "w" );
00183 if ( pFile == NULL )
00184 {
00185 fprintf( stdout, "Io_WriteBench(): Cannot open the output file.\n" );
00186 return 0;
00187 }
00188 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00189
00190 Io_WriteBenchLutOne( pFile, pNtk );
00191
00192 pExdc = Abc_NtkExdc( pNtk );
00193 if ( pExdc )
00194 printf( "Io_WriteBench: EXDC is not written (warning).\n" );
00195
00196 fclose( pFile );
00197 return 1;
00198 }
00199
00211 int Io_WriteBenchLutOne( FILE * pFile, Abc_Ntk_t * pNtk )
00212 {
00213 ProgressBar * pProgress;
00214 Abc_Obj_t * pNode;
00215 Vec_Int_t * vMemory;
00216 int i;
00217
00218
00219 Abc_NtkForEachPi( pNtk, pNode, i )
00220 fprintf( pFile, "INPUT(%s)\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00221 Abc_NtkForEachPo( pNtk, pNode, i )
00222 fprintf( pFile, "OUTPUT(%s)\n", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00223 Abc_NtkForEachLatch( pNtk, pNode, i )
00224 fprintf( pFile, "%-11s = DFFRSE( %s, gnd, gnd, gnd, gnd )\n",
00225 Abc_ObjName(Abc_ObjFanout0(Abc_ObjFanout0(pNode))), Abc_ObjName(Abc_ObjFanin0(Abc_ObjFanin0(pNode))) );
00226
00227
00228 vMemory = Vec_IntAlloc( 10000 );
00229 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00230 Abc_NtkForEachNode( pNtk, pNode, i )
00231 {
00232 Extra_ProgressBarUpdate( pProgress, i, NULL );
00233 Io_WriteBenchLutOneNode( pFile, pNode, vMemory );
00234 }
00235 Extra_ProgressBarStop( pProgress );
00236 Vec_IntFree( vMemory );
00237 return 1;
00238 }
00239
00240
00252 int Io_WriteBenchLutOneNode( FILE * pFile, Abc_Obj_t * pNode, Vec_Int_t * vTruth )
00253 {
00254 Abc_Obj_t * pFanin;
00255 unsigned * pTruth;
00256 int i, nFanins;
00257 assert( Abc_ObjIsNode(pNode) );
00258 nFanins = Abc_ObjFaninNum(pNode);
00259 assert( nFanins <= 8 );
00260
00261 pTruth = Abc_ConvertAigToTruth( pNode->pNtk->pManFunc, Hop_Regular(pNode->pData), nFanins, vTruth, 0 );
00262 if ( Hop_IsComplement(pNode->pData) )
00263 Extra_TruthNot( pTruth, pTruth, nFanins );
00264
00265 if ( Extra_TruthIsConst0(pTruth, nFanins) )
00266 {
00267 fprintf( pFile, "%-11s = gnd\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00268 return 1;
00269 }
00270 if ( Extra_TruthIsConst1(pTruth, nFanins) )
00271 {
00272 fprintf( pFile, "%-11s = vdd\n", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00273 return 1;
00274 }
00275 if ( nFanins == 1 )
00276 {
00277 fprintf( pFile, "%-11s = LUT 0x%d ( %s )\n",
00278 Abc_ObjName(Abc_ObjFanout0(pNode)),
00279 Abc_NodeIsBuf(pNode)? 2 : 1,
00280 Abc_ObjName(Abc_ObjFanin0(pNode)) );
00281 return 1;
00282 }
00283
00284 fprintf( pFile, "%-11s = LUT 0x", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00285 Extra_PrintHexadecimal( pFile, pTruth, nFanins );
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300 fprintf( pFile, " (" );
00301 Abc_ObjForEachFanin( pNode, pFanin, i )
00302 fprintf( pFile, " %s%s", Abc_ObjName(pFanin), ((i==nFanins-1)? "" : ",") );
00303 fprintf( pFile, " )\n" );
00304 return 1;
00305 }
00306
00307
00319 int Io_WriteBenchCheckNames( Abc_Ntk_t * pNtk )
00320 {
00321 Abc_Obj_t * pObj;
00322 char * pName;
00323 int i;
00324 Abc_NtkForEachObj( pNtk, pObj, i )
00325 for ( pName = Nm_ManFindNameById(pNtk->pManName, i); pName && *pName; pName++ )
00326 if ( *pName == '(' || *pName == ')' )
00327 return 0;
00328 return 1;
00329 }
00330
00334
00335