00001
00021 #include "io.h"
00022 #include "main.h"
00023 #include "mio.h"
00024
00028
00029 static void Io_NtkWriteBlifMv( FILE * pFile, Abc_Ntk_t * pNtk );
00030 static void Io_NtkWriteBlifMvOne( FILE * pFile, Abc_Ntk_t * pNtk );
00031 static void Io_NtkWriteBlifMvPis( FILE * pFile, Abc_Ntk_t * pNtk );
00032 static void Io_NtkWriteBlifMvPos( FILE * pFile, Abc_Ntk_t * pNtk );
00033 static void Io_NtkWriteBlifMvAsserts( FILE * pFile, Abc_Ntk_t * pNtk );
00034 static void Io_NtkWriteBlifMvNodeFanins( FILE * pFile, Abc_Obj_t * pNode );
00035 static void Io_NtkWriteBlifMvNode( FILE * pFile, Abc_Obj_t * pNode );
00036 static void Io_NtkWriteBlifMvLatch( FILE * pFile, Abc_Obj_t * pLatch );
00037 static void Io_NtkWriteBlifMvSubckt( FILE * pFile, Abc_Obj_t * pNode );
00038 static void Io_NtkWriteBlifMvValues( FILE * pFile, Abc_Obj_t * pNode );
00039
00043
00055 void Io_WriteBlifMv( Abc_Ntk_t * pNtk, char * FileName )
00056 {
00057 FILE * pFile;
00058 Abc_Ntk_t * pNtkTemp;
00059 int i;
00060 assert( Abc_NtkIsNetlist(pNtk) );
00061 assert( Abc_NtkHasBlifMv(pNtk) );
00062
00063 pFile = fopen( FileName, "w" );
00064 if ( pFile == NULL )
00065 {
00066 fprintf( stdout, "Io_WriteBlifMv(): Cannot open the output file.\n" );
00067 return;
00068 }
00069 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00070
00071 Io_NtkWriteBlifMv( pFile, pNtk );
00072
00073 if ( pNtk->pDesign )
00074 {
00075 Vec_PtrForEachEntry( pNtk->pDesign->vModules, pNtkTemp, i )
00076 {
00077 if ( pNtkTemp == pNtk )
00078 continue;
00079 fprintf( pFile, "\n\n" );
00080 Io_NtkWriteBlifMv( pFile, pNtkTemp );
00081 }
00082 }
00083 fclose( pFile );
00084 }
00085
00097 void Io_NtkWriteBlifMv( FILE * pFile, Abc_Ntk_t * pNtk )
00098 {
00099 assert( Abc_NtkIsNetlist(pNtk) );
00100
00101 fprintf( pFile, ".model %s\n", Abc_NtkName(pNtk) );
00102
00103 Io_NtkWriteBlifMvOne( pFile, pNtk );
00104
00105 if ( Abc_NtkExdc(pNtk) )
00106 printf( "Io_NtkWriteBlifMv(): EXDC is not written.\n" );
00107
00108 fprintf( pFile, ".end\n\n\n" );
00109 }
00110
00122 void Io_NtkWriteBlifMvOne( FILE * pFile, Abc_Ntk_t * pNtk )
00123 {
00124 ProgressBar * pProgress;
00125 Abc_Obj_t * pNode, * pTerm, * pLatch;
00126 int i;
00127
00128
00129 fprintf( pFile, ".inputs" );
00130 Io_NtkWriteBlifMvPis( pFile, pNtk );
00131 fprintf( pFile, "\n" );
00132
00133
00134 fprintf( pFile, ".outputs" );
00135 Io_NtkWriteBlifMvPos( pFile, pNtk );
00136 fprintf( pFile, "\n" );
00137
00138
00139 if ( Abc_NtkAssertNum(pNtk) )
00140 {
00141 fprintf( pFile, ".asserts" );
00142 Io_NtkWriteBlifMvAsserts( pFile, pNtk );
00143 fprintf( pFile, "\n" );
00144 }
00145
00146
00147 fprintf( pFile, "\n" );
00148 Abc_NtkForEachCi( pNtk, pTerm, i )
00149 if ( Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) > 2 )
00150 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) );
00151 Abc_NtkForEachCo( pNtk, pTerm, i )
00152 if ( Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) > 2 )
00153 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanin0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) );
00154
00155
00156 if ( Abc_NtkHasBlackbox( pNtk ) )
00157 {
00158 fprintf( pFile, ".blackbox\n" );
00159 return;
00160 }
00161
00162
00163
00164
00165
00166 if ( !Abc_NtkIsComb(pNtk) )
00167 {
00168 fprintf( pFile, "\n" );
00169 Abc_NtkForEachLatch( pNtk, pLatch, i )
00170 Io_NtkWriteBlifMvLatch( pFile, pLatch );
00171 fprintf( pFile, "\n" );
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 if ( Abc_NtkBlackboxNum(pNtk) > 0 || Abc_NtkWhiteboxNum(pNtk) > 0 )
00185 {
00186 fprintf( pFile, "\n" );
00187 Abc_NtkForEachBox( pNtk, pNode, i )
00188 {
00189 if ( Abc_ObjIsLatch(pNode) )
00190 continue;
00191 Io_NtkWriteBlifMvSubckt( pFile, pNode );
00192 }
00193 fprintf( pFile, "\n" );
00194 }
00195
00196
00197 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00198 Abc_NtkForEachNode( pNtk, pNode, i )
00199 {
00200 Extra_ProgressBarUpdate( pProgress, i, NULL );
00201 Io_NtkWriteBlifMvNode( pFile, pNode );
00202 }
00203 Extra_ProgressBarStop( pProgress );
00204 }
00205
00206
00218 void Io_NtkWriteBlifMvPis( FILE * pFile, Abc_Ntk_t * pNtk )
00219 {
00220 Abc_Obj_t * pTerm, * pNet;
00221 int LineLength;
00222 int AddedLength;
00223 int NameCounter;
00224 int i;
00225
00226 LineLength = 7;
00227 NameCounter = 0;
00228
00229 Abc_NtkForEachPi( pNtk, pTerm, i )
00230 {
00231 pNet = Abc_ObjFanout0(pTerm);
00232
00233 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00234 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00235 {
00236 fprintf( pFile, " \\\n" );
00237
00238 LineLength = 0;
00239 NameCounter = 0;
00240 }
00241 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00242 LineLength += AddedLength;
00243 NameCounter++;
00244 }
00245 }
00246
00258 void Io_NtkWriteBlifMvPos( FILE * pFile, Abc_Ntk_t * pNtk )
00259 {
00260 Abc_Obj_t * pTerm, * pNet;
00261 int LineLength;
00262 int AddedLength;
00263 int NameCounter;
00264 int i;
00265
00266 LineLength = 8;
00267 NameCounter = 0;
00268
00269 Abc_NtkForEachPo( pNtk, pTerm, i )
00270 {
00271 pNet = Abc_ObjFanin0(pTerm);
00272
00273 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00274 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00275 {
00276 fprintf( pFile, " \\\n" );
00277
00278 LineLength = 0;
00279 NameCounter = 0;
00280 }
00281 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00282 LineLength += AddedLength;
00283 NameCounter++;
00284 }
00285 }
00286
00298 void Io_NtkWriteBlifMvAsserts( FILE * pFile, Abc_Ntk_t * pNtk )
00299 {
00300 Abc_Obj_t * pTerm, * pNet;
00301 int LineLength;
00302 int AddedLength;
00303 int NameCounter;
00304 int i;
00305
00306 LineLength = 8;
00307 NameCounter = 0;
00308
00309 Abc_NtkForEachAssert( pNtk, pTerm, i )
00310 {
00311 pNet = Abc_ObjFanin0(pTerm);
00312
00313 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00314 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00315 {
00316 fprintf( pFile, " \\\n" );
00317
00318 LineLength = 0;
00319 NameCounter = 0;
00320 }
00321 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00322 LineLength += AddedLength;
00323 NameCounter++;
00324 }
00325 }
00326
00338 void Io_NtkWriteBlifMvLatch( FILE * pFile, Abc_Obj_t * pLatch )
00339 {
00340 Abc_Obj_t * pNetLi, * pNetLo;
00341 int Reset;
00342 pNetLi = Abc_ObjFanin0( Abc_ObjFanin0(pLatch) );
00343 pNetLo = Abc_ObjFanout0( Abc_ObjFanout0(pLatch) );
00344 Reset = (int)Abc_ObjData( pLatch );
00345
00346 fprintf( pFile, ".latch" );
00347 fprintf( pFile, " %10s", Abc_ObjName(pNetLi) );
00348 fprintf( pFile, " %10s", Abc_ObjName(pNetLo) );
00349 fprintf( pFile, "\n" );
00350
00351 fprintf( pFile, ".reset %s\n", Abc_ObjName(pNetLo) );
00352 fprintf( pFile, "%d\n", Reset-1 );
00353 }
00354
00366 void Io_NtkWriteBlifMvSubckt( FILE * pFile, Abc_Obj_t * pNode )
00367 {
00368 Abc_Ntk_t * pModel = pNode->pData;
00369 Abc_Obj_t * pTerm;
00370 int i;
00371
00372 fprintf( pFile, "\n" );
00373 Abc_ObjForEachFanin( pNode, pTerm, i )
00374 if ( Abc_ObjMvVarNum(pTerm) > 2 )
00375 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
00376 Abc_ObjForEachFanout( pNode, pTerm, i )
00377 if ( Abc_ObjMvVarNum(pTerm) > 2 )
00378 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
00379
00380 fprintf( pFile, ".subckt %s %s", Abc_NtkName(pModel), Abc_ObjName(pNode) );
00381
00382 Abc_NtkForEachPi( pModel, pTerm, i )
00383 {
00384 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00385 pTerm = Abc_ObjFanin( pNode, i );
00386 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00387 }
00388 Abc_NtkForEachPo( pModel, pTerm, i )
00389 {
00390 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00391 pTerm = Abc_ObjFanout( pNode, i );
00392 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00393 }
00394 fprintf( pFile, "\n" );
00395 }
00396
00397
00409 void Io_NtkWriteBlifMvNode( FILE * pFile, Abc_Obj_t * pNode )
00410 {
00411 Abc_Obj_t * pFanin;
00412 char * pCur;
00413 int nValues, iFanin, i;
00414
00415
00416 fprintf( pFile, "\n" );
00417 Abc_ObjForEachFanin( pNode, pFanin, i )
00418 {
00419
00420 nValues = Abc_ObjMvVarNum( pFanin );
00421 if ( nValues > 2 )
00422 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pFanin), nValues );
00423
00424 }
00425
00426
00427
00428 nValues = Abc_ObjMvVarNum( Abc_ObjFanout0(pNode) );
00429 if ( nValues > 2 )
00430 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pNode)), nValues );
00431
00432
00433
00434 fprintf( pFile, ".table" );
00435 Io_NtkWriteBlifMvNodeFanins( pFile, pNode );
00436 fprintf( pFile, "\n" );
00437
00438
00439 pCur = Abc_ObjData(pNode);
00440 if ( *pCur == 'd' )
00441 {
00442 fprintf( pFile, ".default " );
00443 pCur++;
00444 }
00445
00446 for ( ; *pCur; pCur++ )
00447 {
00448 fprintf( pFile, "%c", *pCur );
00449 if ( *pCur != '=' )
00450 continue;
00451
00452 iFanin = atoi( pCur+1 );
00453 fprintf( pFile, "%s", Abc_ObjName(Abc_ObjFanin(pNode,iFanin)) );
00454
00455 while ( *pCur != ' ' && *pCur != '\n' )
00456 pCur++;
00457 pCur--;
00458 }
00459 }
00460
00472 void Io_NtkWriteBlifMvNodeFanins( FILE * pFile, Abc_Obj_t * pNode )
00473 {
00474 Abc_Obj_t * pNet;
00475 int LineLength;
00476 int AddedLength;
00477 int NameCounter;
00478 char * pName;
00479 int i;
00480
00481 LineLength = 6;
00482 NameCounter = 0;
00483 Abc_ObjForEachFanin( pNode, pNet, i )
00484 {
00485
00486 pName = Abc_ObjName(pNet);
00487
00488 AddedLength = strlen(pName) + 1;
00489 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00490 {
00491 fprintf( pFile, " \\\n" );
00492
00493 LineLength = 0;
00494 NameCounter = 0;
00495 }
00496 fprintf( pFile, " %s", pName );
00497 LineLength += AddedLength;
00498 NameCounter++;
00499 }
00500
00501
00502 pName = Abc_ObjName(Abc_ObjFanout0(pNode));
00503
00504 AddedLength = strlen(pName) + 1;
00505 if ( NameCounter && LineLength + AddedLength > 75 )
00506 {
00507 fprintf( pFile, " \\\n" );
00508
00509 LineLength = 0;
00510 NameCounter = 0;
00511 }
00512 fprintf( pFile, " %s", pName );
00513 }
00514
00518
00519