00001
00021 #include "io.h"
00022 #include "main.h"
00023 #include "mio.h"
00024
00028
00029 static void Io_NtkWrite( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
00030 static void Io_NtkWriteOne( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
00031 static void Io_NtkWritePis( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
00032 static void Io_NtkWritePos( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches );
00033 static void Io_NtkWriteSubckt( FILE * pFile, Abc_Obj_t * pNode );
00034 static void Io_NtkWriteAsserts( FILE * pFile, Abc_Ntk_t * pNtk );
00035 static void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length );
00036 static void Io_NtkWriteNodeFanins( FILE * pFile, Abc_Obj_t * pNode );
00037 static void Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length );
00038 static void Io_NtkWriteLatch( FILE * pFile, Abc_Obj_t * pLatch );
00039
00043
00055 void Io_WriteBlifLogic( Abc_Ntk_t * pNtk, char * FileName, int fWriteLatches )
00056 {
00057 Abc_Ntk_t * pNtkTemp;
00058
00059 pNtkTemp = Abc_NtkToNetlist(pNtk);
00060 if ( pNtkTemp == NULL )
00061 {
00062 fprintf( stdout, "Writing BLIF has failed.\n" );
00063 return;
00064 }
00065 Io_WriteBlif( pNtkTemp, FileName, fWriteLatches );
00066 Abc_NtkDelete( pNtkTemp );
00067 }
00068
00080 void Io_WriteBlif( Abc_Ntk_t * pNtk, char * FileName, int fWriteLatches )
00081 {
00082 FILE * pFile;
00083 Abc_Ntk_t * pNtkTemp;
00084 int i;
00085 assert( Abc_NtkIsNetlist(pNtk) );
00086
00087 pFile = fopen( FileName, "w" );
00088 if ( pFile == NULL )
00089 {
00090 fprintf( stdout, "Io_WriteBlif(): Cannot open the output file.\n" );
00091 return;
00092 }
00093 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00094
00095 Io_NtkWrite( pFile, pNtk, fWriteLatches );
00096
00097 assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
00098
00099 if ( Abc_NtkBlackboxNum(pNtk) > 0 )
00100 {
00101 Vec_PtrForEachEntry( pNtk->pDesign->vModules, pNtkTemp, i )
00102 {
00103 if ( pNtkTemp == pNtk )
00104 continue;
00105 fprintf( pFile, "\n\n" );
00106 Io_NtkWrite( pFile, pNtkTemp, fWriteLatches );
00107 }
00108 }
00109 fclose( pFile );
00110 }
00111
00123 void Io_NtkWrite( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches )
00124 {
00125 Abc_Ntk_t * pExdc;
00126 assert( Abc_NtkIsNetlist(pNtk) );
00127
00128 fprintf( pFile, ".model %s\n", Abc_NtkName(pNtk) );
00129
00130 Io_NtkWriteOne( pFile, pNtk, fWriteLatches );
00131
00132 pExdc = Abc_NtkExdc( pNtk );
00133 if ( pExdc )
00134 {
00135 fprintf( pFile, "\n" );
00136 fprintf( pFile, ".exdc\n" );
00137 Io_NtkWriteOne( pFile, pExdc, fWriteLatches );
00138 }
00139
00140 fprintf( pFile, ".end\n" );
00141 }
00142
00154 void Io_NtkWriteOne( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches )
00155 {
00156 ProgressBar * pProgress;
00157 Abc_Obj_t * pNode, * pLatch;
00158 int i, Length;
00159
00160
00161 fprintf( pFile, ".inputs" );
00162 Io_NtkWritePis( pFile, pNtk, fWriteLatches );
00163 fprintf( pFile, "\n" );
00164
00165
00166 fprintf( pFile, ".outputs" );
00167 Io_NtkWritePos( pFile, pNtk, fWriteLatches );
00168 fprintf( pFile, "\n" );
00169
00170
00171 if ( Abc_NtkAssertNum(pNtk) )
00172 {
00173 fprintf( pFile, ".asserts" );
00174 Io_NtkWriteAsserts( pFile, pNtk );
00175 fprintf( pFile, "\n" );
00176 }
00177
00178
00179 if ( Abc_NtkHasBlackbox( pNtk ) )
00180 {
00181 fprintf( pFile, ".blackbox\n" );
00182 return;
00183 }
00184
00185
00186 Io_WriteTimingInfo( pFile, pNtk );
00187
00188
00189 if ( fWriteLatches && !Abc_NtkIsComb(pNtk) )
00190 {
00191 fprintf( pFile, "\n" );
00192 Abc_NtkForEachLatch( pNtk, pLatch, i )
00193 Io_NtkWriteLatch( pFile, pLatch );
00194 fprintf( pFile, "\n" );
00195 }
00196
00197
00198 assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
00199 if ( Abc_NtkBlackboxNum(pNtk) > 0 )
00200 {
00201 fprintf( pFile, "\n" );
00202 Abc_NtkForEachBlackbox( pNtk, pNode, i )
00203 Io_NtkWriteSubckt( pFile, pNode );
00204 fprintf( pFile, "\n" );
00205 }
00206
00207
00208 Length = Abc_NtkHasMapping(pNtk)? Mio_LibraryReadGateNameMax(pNtk->pManFunc) : 0;
00209 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00210 Abc_NtkForEachNode( pNtk, pNode, i )
00211 {
00212 Extra_ProgressBarUpdate( pProgress, i, NULL );
00213 Io_NtkWriteNode( pFile, pNode, Length );
00214 }
00215 Extra_ProgressBarStop( pProgress );
00216 }
00217
00218
00230 void Io_NtkWritePis( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches )
00231 {
00232 Abc_Obj_t * pTerm, * pNet;
00233 int LineLength;
00234 int AddedLength;
00235 int NameCounter;
00236 int i;
00237
00238 LineLength = 7;
00239 NameCounter = 0;
00240
00241 if ( fWriteLatches )
00242 {
00243 Abc_NtkForEachPi( pNtk, pTerm, i )
00244 {
00245 pNet = Abc_ObjFanout0(pTerm);
00246
00247 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00248 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00249 {
00250 fprintf( pFile, " \\\n" );
00251
00252 LineLength = 0;
00253 NameCounter = 0;
00254 }
00255 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00256 LineLength += AddedLength;
00257 NameCounter++;
00258 }
00259 }
00260 else
00261 {
00262 Abc_NtkForEachCi( pNtk, pTerm, i )
00263 {
00264 pNet = Abc_ObjFanout0(pTerm);
00265
00266 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00267 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00268 {
00269 fprintf( pFile, " \\\n" );
00270
00271 LineLength = 0;
00272 NameCounter = 0;
00273 }
00274 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00275 LineLength += AddedLength;
00276 NameCounter++;
00277 }
00278 }
00279 }
00280
00292 void Io_NtkWritePos( FILE * pFile, Abc_Ntk_t * pNtk, int fWriteLatches )
00293 {
00294 Abc_Obj_t * pTerm, * pNet;
00295 int LineLength;
00296 int AddedLength;
00297 int NameCounter;
00298 int i;
00299
00300 LineLength = 8;
00301 NameCounter = 0;
00302
00303 if ( fWriteLatches )
00304 {
00305 Abc_NtkForEachPo( pNtk, pTerm, i )
00306 {
00307 pNet = Abc_ObjFanin0(pTerm);
00308
00309 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00310 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00311 {
00312 fprintf( pFile, " \\\n" );
00313
00314 LineLength = 0;
00315 NameCounter = 0;
00316 }
00317 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00318 LineLength += AddedLength;
00319 NameCounter++;
00320 }
00321 }
00322 else
00323 {
00324 Abc_NtkForEachCo( pNtk, pTerm, i )
00325 {
00326 if ( Abc_ObjIsAssert(pTerm) )
00327 continue;
00328 pNet = Abc_ObjFanin0(pTerm);
00329
00330 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00331 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00332 {
00333 fprintf( pFile, " \\\n" );
00334
00335 LineLength = 0;
00336 NameCounter = 0;
00337 }
00338 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00339 LineLength += AddedLength;
00340 NameCounter++;
00341 }
00342 }
00343 }
00344
00356 void Io_NtkWriteAsserts( FILE * pFile, Abc_Ntk_t * pNtk )
00357 {
00358 Abc_Obj_t * pTerm, * pNet;
00359 int LineLength;
00360 int AddedLength;
00361 int NameCounter;
00362 int i;
00363
00364 LineLength = 8;
00365 NameCounter = 0;
00366
00367 Abc_NtkForEachAssert( pNtk, pTerm, i )
00368 {
00369 pNet = Abc_ObjFanin0(pTerm);
00370
00371 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00372 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00373 {
00374 fprintf( pFile, " \\\n" );
00375
00376 LineLength = 0;
00377 NameCounter = 0;
00378 }
00379 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00380 LineLength += AddedLength;
00381 NameCounter++;
00382 }
00383 }
00384
00396 void Io_NtkWriteSubckt( FILE * pFile, Abc_Obj_t * pNode )
00397 {
00398 Abc_Ntk_t * pModel = pNode->pData;
00399 Abc_Obj_t * pTerm;
00400 int i;
00401
00402
00403 fprintf( pFile, ".subckt %s", Abc_NtkName(pModel) );
00404
00405 Abc_NtkForEachPi( pModel, pTerm, i )
00406 {
00407 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00408 pTerm = Abc_ObjFanin( pNode, i );
00409 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00410 }
00411 Abc_NtkForEachPo( pModel, pTerm, i )
00412 {
00413 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
00414 pTerm = Abc_ObjFanout( pNode, i );
00415 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
00416 }
00417 fprintf( pFile, "\n" );
00418 }
00419
00431 void Io_NtkWriteLatch( FILE * pFile, Abc_Obj_t * pLatch )
00432 {
00433 Abc_Obj_t * pNetLi, * pNetLo;
00434 int Reset;
00435 pNetLi = Abc_ObjFanin0( Abc_ObjFanin0(pLatch) );
00436 pNetLo = Abc_ObjFanout0( Abc_ObjFanout0(pLatch) );
00437 Reset = (int)Abc_ObjData( pLatch );
00438
00439 fprintf( pFile, ".latch" );
00440 fprintf( pFile, " %10s", Abc_ObjName(pNetLi) );
00441 fprintf( pFile, " %10s", Abc_ObjName(pNetLo) );
00442 fprintf( pFile, " %d\n", Reset-1 );
00443 }
00444
00445
00457 void Io_NtkWriteNode( FILE * pFile, Abc_Obj_t * pNode, int Length )
00458 {
00459 if ( Abc_NtkHasMapping(pNode->pNtk) )
00460 {
00461
00462 fprintf( pFile, ".gate" );
00463 Io_NtkWriteNodeGate( pFile, pNode, Length );
00464 fprintf( pFile, "\n" );
00465 }
00466 else
00467 {
00468
00469 fprintf( pFile, ".names" );
00470 Io_NtkWriteNodeFanins( pFile, pNode );
00471 fprintf( pFile, "\n" );
00472
00473 fprintf( pFile, "%s", Abc_ObjData(pNode) );
00474 }
00475 }
00476
00488 void Io_NtkWriteNodeGate( FILE * pFile, Abc_Obj_t * pNode, int Length )
00489 {
00490 Mio_Gate_t * pGate = pNode->pData;
00491 Mio_Pin_t * pGatePin;
00492 int i;
00493
00494 fprintf( pFile, " %-*s ", Length, Mio_GateReadName(pGate) );
00495 for ( pGatePin = Mio_GateReadPins(pGate), i = 0; pGatePin; pGatePin = Mio_PinReadNext(pGatePin), i++ )
00496 fprintf( pFile, "%s=%s ", Mio_PinReadName(pGatePin), Abc_ObjName( Abc_ObjFanin(pNode,i) ) );
00497 assert ( i == Abc_ObjFaninNum(pNode) );
00498 fprintf( pFile, "%s=%s", Mio_GateReadOutName(pGate), Abc_ObjName( Abc_ObjFanout0(pNode) ) );
00499 }
00500
00512 void Io_NtkWriteNodeFanins( FILE * pFile, Abc_Obj_t * pNode )
00513 {
00514 Abc_Obj_t * pNet;
00515 int LineLength;
00516 int AddedLength;
00517 int NameCounter;
00518 char * pName;
00519 int i;
00520
00521 LineLength = 6;
00522 NameCounter = 0;
00523 Abc_ObjForEachFanin( pNode, pNet, i )
00524 {
00525
00526 pName = Abc_ObjName(pNet);
00527
00528 AddedLength = strlen(pName) + 1;
00529 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00530 {
00531 fprintf( pFile, " \\\n" );
00532
00533 LineLength = 0;
00534 NameCounter = 0;
00535 }
00536 fprintf( pFile, " %s", pName );
00537 LineLength += AddedLength;
00538 NameCounter++;
00539 }
00540
00541
00542 pName = Abc_ObjName(Abc_ObjFanout0(pNode));
00543
00544 AddedLength = strlen(pName) + 1;
00545 if ( NameCounter && LineLength + AddedLength > 75 )
00546 {
00547 fprintf( pFile, " \\\n" );
00548
00549 LineLength = 0;
00550 NameCounter = 0;
00551 }
00552 fprintf( pFile, " %s", pName );
00553 }
00554
00566 void Io_WriteTimingInfo( FILE * pFile, Abc_Ntk_t * pNtk )
00567 {
00568 Abc_Obj_t * pNode;
00569 Abc_Time_t * pTime, * pTimeDef;
00570 int i;
00571
00572 if ( pNtk->pManTime == NULL )
00573 return;
00574
00575 pTimeDef = Abc_NtkReadDefaultArrival( pNtk );
00576 fprintf( pFile, ".default_input_arrival %g %g\n", pTimeDef->Rise, pTimeDef->Fall );
00577 Abc_NtkForEachPi( pNtk, pNode, i )
00578 {
00579 pTime = Abc_NodeReadArrival(pNode);
00580 if ( pTime->Rise == pTimeDef->Rise && pTime->Fall == pTimeDef->Fall )
00581 continue;
00582 fprintf( pFile, ".input_arrival %s %g %g\n", Abc_ObjName(pNode), pTime->Rise, pTime->Fall );
00583 }
00584 }
00585
00586
00590
00591