00001
00021 #include "io.h"
00022
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00069
00081 void Io_WriteBaf( Abc_Ntk_t * pNtk, char * pFileName )
00082 {
00083 ProgressBar * pProgress;
00084 FILE * pFile;
00085 Abc_Obj_t * pObj;
00086 int i, nNodes, nAnds, nBufferSize;
00087 unsigned * pBufferNode;
00088 assert( Abc_NtkIsStrash(pNtk) );
00089
00090 pFile = fopen( pFileName, "wb" );
00091 if ( pFile == NULL )
00092 {
00093 fprintf( stdout, "Io_WriteBaf(): Cannot open the output file \"%s\".\n", pFileName );
00094 return;
00095 }
00096
00097
00098 fprintf( pFile, "# BAF (Binary Aig Format) for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00099
00100
00101 fprintf( pFile, "%s%c", pNtk->pName, 0 );
00102
00103 fprintf( pFile, "%d%c", Abc_NtkPiNum(pNtk), 0 );
00104
00105 fprintf( pFile, "%d%c", Abc_NtkPoNum(pNtk), 0 );
00106
00107 fprintf( pFile, "%d%c", Abc_NtkLatchNum(pNtk), 0 );
00108
00109 fprintf( pFile, "%d%c", Abc_NtkNodeNum(pNtk), 0 );
00110
00111
00112 Abc_NtkForEachPi( pNtk, pObj, i )
00113 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00114
00115 Abc_NtkForEachPo( pNtk, pObj, i )
00116 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00117
00118 Abc_NtkForEachLatch( pNtk, pObj, i )
00119 {
00120 fprintf( pFile, "%s%c", Abc_ObjName(pObj), 0 );
00121 fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanin0(pObj)), 0 );
00122 fprintf( pFile, "%s%c", Abc_ObjName(Abc_ObjFanout0(pObj)), 0 );
00123 }
00124
00125
00126 Abc_NtkCleanCopy( pNtk );
00127 nNodes = 1;
00128 Abc_NtkForEachCi( pNtk, pObj, i )
00129 pObj->pCopy = (void *)nNodes++;
00130 Abc_AigForEachAnd( pNtk, pObj, i )
00131 pObj->pCopy = (void *)nNodes++;
00132
00133
00134 nAnds = 0;
00135 nBufferSize = Abc_NtkNodeNum(pNtk) * 2 + Abc_NtkCoNum(pNtk);
00136 pBufferNode = ALLOC( int, nBufferSize );
00137 pProgress = Extra_ProgressBarStart( stdout, nBufferSize );
00138 Abc_AigForEachAnd( pNtk, pObj, i )
00139 {
00140 Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
00141 pBufferNode[nAnds++] = (((int)Abc_ObjFanin0(pObj)->pCopy) << 1) | Abc_ObjFaninC0(pObj);
00142 pBufferNode[nAnds++] = (((int)Abc_ObjFanin1(pObj)->pCopy) << 1) | Abc_ObjFaninC1(pObj);
00143 }
00144
00145
00146 Abc_NtkForEachCo( pNtk, pObj, i )
00147 {
00148 Extra_ProgressBarUpdate( pProgress, nAnds, NULL );
00149 pBufferNode[nAnds] = (((int)Abc_ObjFanin0(pObj)->pCopy) << 1) | Abc_ObjFaninC0(pObj);
00150 if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
00151 pBufferNode[nAnds] = (pBufferNode[nAnds] << 2) | ((unsigned)Abc_ObjData(Abc_ObjFanout0(pObj)) & 3);
00152 nAnds++;
00153 }
00154 Extra_ProgressBarStop( pProgress );
00155 assert( nBufferSize == nAnds );
00156
00157
00158 fwrite( pBufferNode, 1, sizeof(int) * nBufferSize, pFile );
00159 fclose( pFile );
00160 free( pBufferNode );
00161 }
00162
00163
00167
00168