00001
00021 #include "io.h"
00022
00026
00030
00042 Abc_Ntk_t * Io_ReadBaf( char * pFileName, int fCheck )
00043 {
00044 ProgressBar * pProgress;
00045 FILE * pFile;
00046 Vec_Ptr_t * vNodes;
00047 Abc_Obj_t * pObj, * pNode0, * pNode1;
00048 Abc_Ntk_t * pNtkNew;
00049 int nInputs, nOutputs, nLatches, nAnds, nFileSize, Num, i;
00050 char * pContents, * pName, * pCur;
00051 unsigned * pBufferNode;
00052
00053
00054 nFileSize = Extra_FileSize( pFileName );
00055 pFile = fopen( pFileName, "rb" );
00056 pContents = ALLOC( char, nFileSize );
00057 fread( pContents, nFileSize, 1, pFile );
00058 fclose( pFile );
00059
00060
00061 for ( pCur = pContents; *pCur == '#'; )
00062 while ( *pCur++ != '\n' );
00063
00064
00065 pName = pCur; while ( *pCur++ );
00066
00067 nInputs = atoi( pCur ); while ( *pCur++ );
00068
00069 nOutputs = atoi( pCur ); while ( *pCur++ );
00070
00071 nLatches = atoi( pCur ); while ( *pCur++ );
00072
00073 nAnds = atoi( pCur ); while ( *pCur++ );
00074
00075
00076 pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
00077 pNtkNew->pName = Extra_UtilStrsav( pName );
00078 pNtkNew->pSpec = Extra_UtilStrsav( pFileName );
00079
00080
00081 vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
00082 Vec_PtrPush( vNodes, Abc_AigConst1(pNtkNew) );
00083
00084
00085 for ( i = 0; i < nInputs; i++ )
00086 {
00087 pObj = Abc_NtkCreatePi(pNtkNew);
00088 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
00089 Vec_PtrPush( vNodes, pObj );
00090 }
00091
00092 for ( i = 0; i < nOutputs; i++ )
00093 {
00094 pObj = Abc_NtkCreatePo(pNtkNew);
00095 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
00096 }
00097
00098 for ( i = 0; i < nLatches; i++ )
00099 {
00100 pObj = Abc_NtkCreateLatch(pNtkNew);
00101 Abc_ObjAssignName( pObj, pCur, NULL ); while ( *pCur++ );
00102
00103 pNode0 = Abc_NtkCreateBi(pNtkNew);
00104 Abc_ObjAssignName( pNode0, pCur, NULL ); while ( *pCur++ );
00105
00106 pNode1 = Abc_NtkCreateBo(pNtkNew);
00107 Abc_ObjAssignName( pNode1, pCur, NULL ); while ( *pCur++ );
00108 Vec_PtrPush( vNodes, pNode1 );
00109
00110 Abc_ObjAddFanin( pObj, pNode0 );
00111 Abc_ObjAddFanin( pNode1, pObj );
00112 }
00113
00114
00115 pBufferNode = (int *)(pContents + (nFileSize - (2 * nAnds + nOutputs + nLatches) * sizeof(int)) );
00116
00117 if ( pBufferNode != (int *)pCur )
00118 {
00119 free( pContents );
00120 Vec_PtrFree( vNodes );
00121 Abc_NtkDelete( pNtkNew );
00122 printf( "Warning: Internal reader error.\n" );
00123 return NULL;
00124 }
00125
00126
00127 pProgress = Extra_ProgressBarStart( stdout, nAnds );
00128 for ( i = 0; i < nAnds; i++ )
00129 {
00130 Extra_ProgressBarUpdate( pProgress, i, NULL );
00131 pNode0 = Abc_ObjNotCond( Vec_PtrEntry(vNodes, pBufferNode[2*i+0] >> 1), pBufferNode[2*i+0] & 1 );
00132 pNode1 = Abc_ObjNotCond( Vec_PtrEntry(vNodes, pBufferNode[2*i+1] >> 1), pBufferNode[2*i+1] & 1 );
00133 Vec_PtrPush( vNodes, Abc_AigAnd(pNtkNew->pManFunc, pNode0, pNode1) );
00134 }
00135 Extra_ProgressBarStop( pProgress );
00136
00137
00138 Abc_NtkForEachCo( pNtkNew, pObj, i )
00139 {
00140 Num = pBufferNode[2*nAnds+i];
00141 if ( Abc_ObjFanoutNum(pObj) > 0 && Abc_ObjIsLatch(Abc_ObjFanout0(pObj)) )
00142 {
00143 Abc_ObjSetData( Abc_ObjFanout0(pObj), (void *)(Num & 3) );
00144 Num >>= 2;
00145 }
00146 pNode0 = Abc_ObjNotCond( Vec_PtrEntry(vNodes, Num >> 1), Num & 1 );
00147 Abc_ObjAddFanin( pObj, pNode0 );
00148 }
00149 free( pContents );
00150 Vec_PtrFree( vNodes );
00151
00152
00153
00154
00155
00156 if ( fCheck && !Abc_NtkCheckRead( pNtkNew ) )
00157 {
00158 printf( "Io_ReadBaf: The network check has failed.\n" );
00159 Abc_NtkDelete( pNtkNew );
00160 return NULL;
00161 }
00162 return pNtkNew;
00163
00164 }
00165
00166
00170
00171