00001
00021 #include "io.h"
00022
00026
00027 static int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk );
00028
00032
00044 int Io_WritePla( Abc_Ntk_t * pNtk, char * pFileName )
00045 {
00046 Abc_Ntk_t * pExdc;
00047 FILE * pFile;
00048
00049 assert( Abc_NtkIsSopNetlist(pNtk) );
00050 assert( Abc_NtkLevel(pNtk) == 1 );
00051
00052 pFile = fopen( pFileName, "w" );
00053 if ( pFile == NULL )
00054 {
00055 fprintf( stdout, "Io_WritePla(): Cannot open the output file.\n" );
00056 return 0;
00057 }
00058 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
00059
00060 Io_WritePlaOne( pFile, pNtk );
00061
00062 pExdc = Abc_NtkExdc( pNtk );
00063 if ( pExdc )
00064 printf( "Io_WritePla: EXDC is not written (warning).\n" );
00065
00066 fclose( pFile );
00067 return 1;
00068 }
00069
00081 int Io_WritePlaOne( FILE * pFile, Abc_Ntk_t * pNtk )
00082 {
00083 ProgressBar * pProgress;
00084 Abc_Obj_t * pNode, * pFanin, * pDriver;
00085 char * pCubeIn, * pCubeOut, * pCube;
00086 int i, k, nProducts, nInputs, nOutputs, nFanins;
00087
00088 nProducts = 0;
00089 Abc_NtkForEachCo( pNtk, pNode, i )
00090 {
00091 pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
00092 if ( !Abc_ObjIsNode(pDriver) )
00093 {
00094 nProducts++;
00095 continue;
00096 }
00097 if ( Abc_NodeIsConst(pDriver) )
00098 {
00099 if ( Abc_NodeIsConst1(pDriver) )
00100 nProducts++;
00101 continue;
00102 }
00103 nProducts += Abc_SopGetCubeNum(pDriver->pData);
00104 }
00105
00106
00107 nInputs = Abc_NtkCiNum(pNtk);
00108 nOutputs = Abc_NtkCoNum(pNtk);
00109 pCubeIn = ALLOC( char, nInputs + 1 );
00110 pCubeOut = ALLOC( char, nOutputs + 1 );
00111 memset( pCubeIn, '-', nInputs ); pCubeIn[nInputs] = 0;
00112 memset( pCubeOut, '0', nOutputs ); pCubeOut[nOutputs] = 0;
00113
00114
00115 fprintf( pFile, ".i %d\n", nInputs );
00116 fprintf( pFile, ".o %d\n", nOutputs );
00117 fprintf( pFile, ".ilb" );
00118 Abc_NtkForEachCi( pNtk, pNode, i )
00119 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pNode)) );
00120 fprintf( pFile, "\n" );
00121 fprintf( pFile, ".ob" );
00122 Abc_NtkForEachCo( pNtk, pNode, i )
00123 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pNode)) );
00124 fprintf( pFile, "\n" );
00125 fprintf( pFile, ".p %d\n", nProducts );
00126
00127
00128 Abc_NtkForEachCi( pNtk, pNode, i )
00129 pNode->pCopy = (Abc_Obj_t *)i;
00130
00131
00132 pProgress = Extra_ProgressBarStart( stdout, nOutputs );
00133 Abc_NtkForEachCo( pNtk, pNode, i )
00134 {
00135
00136 if ( i - 1 >= 0 )
00137 pCubeOut[i-1] = '0';
00138 pCubeOut[i] = '1';
00139
00140
00141 pDriver = Abc_ObjFanin0Ntk( Abc_ObjFanin0(pNode) );
00142 if ( !Abc_ObjIsNode(pDriver) )
00143 {
00144 assert( Abc_ObjIsCi(pDriver) );
00145 pCubeIn[(int)pDriver->pCopy] = '1' - Abc_ObjFaninC0(pNode);
00146 fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
00147 pCubeIn[(int)pDriver->pCopy] = '-';
00148 continue;
00149 }
00150 if ( Abc_NodeIsConst(pDriver) )
00151 {
00152 if ( Abc_NodeIsConst1(pDriver) )
00153 fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
00154 continue;
00155 }
00156
00157
00158 assert( !Abc_SopIsComplement( pDriver->pData ) );
00159
00160
00161 nFanins = Abc_ObjFaninNum(pDriver);
00162 Abc_SopForEachCube( pDriver->pData, nFanins, pCube )
00163 {
00164 Abc_ObjForEachFanin( pDriver, pFanin, k )
00165 {
00166 pFanin = Abc_ObjFanin0Ntk(pFanin);
00167 assert( (int)pFanin->pCopy < nInputs );
00168 pCubeIn[(int)pFanin->pCopy] = pCube[k];
00169 }
00170 fprintf( pFile, "%s %s\n", pCubeIn, pCubeOut );
00171 }
00172
00173 Abc_ObjForEachFanin( pDriver, pFanin, k )
00174 {
00175 pFanin = Abc_ObjFanin0Ntk(pFanin);
00176 assert( Abc_ObjIsCi(pFanin) );
00177 pCubeIn[(int)pFanin->pCopy] = '-';
00178 }
00179 Extra_ProgressBarUpdate( pProgress, i, NULL );
00180 }
00181 Extra_ProgressBarStop( pProgress );
00182 fprintf( pFile, ".e\n" );
00183
00184
00185 Abc_NtkForEachCi( pNtk, pNode, i )
00186 pNode->pCopy = NULL;
00187 free( pCubeIn );
00188 free( pCubeOut );
00189 return 1;
00190 }
00191
00192
00196
00197