00001
00021 #include "io.h"
00022
00026
00027 static void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk );
00028 static void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk );
00029 static void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk );
00030 static int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk );
00031
00035
00047 void Io_WriteEqn( Abc_Ntk_t * pNtk, char * pFileName )
00048 {
00049 FILE * pFile;
00050
00051 assert( Abc_NtkIsAigNetlist(pNtk) );
00052 if ( Abc_NtkLatchNum(pNtk) > 0 )
00053 printf( "Warning: only combinational portion is being written.\n" );
00054
00055
00056 if ( !Io_NtkWriteEqnCheck(pNtk) )
00057 return;
00058
00059
00060 pFile = fopen( pFileName, "w" );
00061 if ( pFile == NULL )
00062 {
00063 fprintf( stdout, "Io_WriteEqn(): Cannot open the output file \"%s\".\n", pFileName );
00064 return;
00065 }
00066 fprintf( pFile, "# Equations for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00067
00068
00069 Io_NtkWriteEqnOne( pFile, pNtk );
00070 fprintf( pFile, "\n" );
00071 fclose( pFile );
00072 }
00073
00085 void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk )
00086 {
00087 Vec_Vec_t * vLevels;
00088 ProgressBar * pProgress;
00089 Abc_Obj_t * pNode, * pFanin;
00090 int i, k;
00091
00092
00093 fprintf( pFile, "INORDER =" );
00094 Io_NtkWriteEqnCis( pFile, pNtk );
00095 fprintf( pFile, ";\n" );
00096
00097
00098 fprintf( pFile, "OUTORDER =" );
00099 Io_NtkWriteEqnCos( pFile, pNtk );
00100 fprintf( pFile, ";\n" );
00101
00102
00103 vLevels = Vec_VecAlloc( 10 );
00104 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
00105 Abc_NtkForEachNode( pNtk, pNode, i )
00106 {
00107 Extra_ProgressBarUpdate( pProgress, i, NULL );
00108 fprintf( pFile, "%s = ", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00109
00110 Abc_ObjForEachFanin( pNode, pFanin, k )
00111 Hop_IthVar(pNtk->pManFunc, k)->pData = Abc_ObjName(pFanin);
00112
00113 Hop_ObjPrintEqn( pFile, pNode->pData, vLevels, 0 );
00114 fprintf( pFile, ";\n" );
00115 }
00116 Extra_ProgressBarStop( pProgress );
00117 Vec_VecFree( vLevels );
00118 }
00119
00120
00132 void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk )
00133 {
00134 Abc_Obj_t * pTerm, * pNet;
00135 int LineLength;
00136 int AddedLength;
00137 int NameCounter;
00138 int i;
00139
00140 LineLength = 9;
00141 NameCounter = 0;
00142
00143 Abc_NtkForEachCi( pNtk, pTerm, i )
00144 {
00145 pNet = Abc_ObjFanout0(pTerm);
00146
00147 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00148 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00149 {
00150 fprintf( pFile, " \n" );
00151
00152 LineLength = 0;
00153 NameCounter = 0;
00154 }
00155 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00156 LineLength += AddedLength;
00157 NameCounter++;
00158 }
00159 }
00160
00172 void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk )
00173 {
00174 Abc_Obj_t * pTerm, * pNet;
00175 int LineLength;
00176 int AddedLength;
00177 int NameCounter;
00178 int i;
00179
00180 LineLength = 10;
00181 NameCounter = 0;
00182
00183 Abc_NtkForEachCo( pNtk, pTerm, i )
00184 {
00185 pNet = Abc_ObjFanin0(pTerm);
00186
00187 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
00188 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
00189 {
00190 fprintf( pFile, " \n" );
00191
00192 LineLength = 0;
00193 NameCounter = 0;
00194 }
00195 fprintf( pFile, " %s", Abc_ObjName(pNet) );
00196 LineLength += AddedLength;
00197 NameCounter++;
00198 }
00199 }
00200
00212 int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk )
00213 {
00214 Abc_Obj_t * pObj;
00215 char * pName;
00216 int i, k, Length;
00217 int RetValue = 1;
00218
00219
00220 Abc_NtkForEachObj( pNtk, pObj, i )
00221 {
00222 pName = Nm_ManFindNameById(pNtk->pManName, i);
00223 if ( pName == NULL )
00224 continue;
00225 Length = strlen(pName);
00226 if ( pName[0] == '0' || pName[0] == '1' )
00227 {
00228 RetValue = 0;
00229 break;
00230 }
00231 for ( k = 0; k < Length; k++ )
00232 if ( pName[k] == '(' || pName[k] == ')' || pName[k] == '!' || pName[k] == '*' || pName[k] == '+' )
00233 {
00234 RetValue = 0;
00235 break;
00236 }
00237 if ( k < Length )
00238 break;
00239 }
00240 if ( RetValue == 0 )
00241 {
00242 printf( "The network cannot be written in the EQN format because object %d has name \"%s\".\n", i, pName );
00243 printf( "Consider renaming the objects using command \"short_names\" and trying again.\n" );
00244 }
00245 return RetValue;
00246 }
00247
00251
00252