src/base/io/ioReadBaf.c File Reference

#include "io.h"
Include dependency graph for ioReadBaf.c:

Go to the source code of this file.

Functions

Abc_Ntk_tIo_ReadBaf (char *pFileName, int fCheck)

Function Documentation

Abc_Ntk_t* Io_ReadBaf ( char *  pFileName,
int  fCheck 
)

CFile****************************************************************

FileName [ioReadBaf.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to read AIG in the binary format.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
ioReadBaf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] DECLARATIONS /// FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Reads the AIG in the binary format.]

Description []

SideEffects []

SeeAlso []

Definition at line 42 of file ioReadBaf.c.

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     // read the file into the buffer
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     // skip the comments (comment lines begin with '#' and end with '\n')
00061     for ( pCur = pContents; *pCur == '#'; )
00062         while ( *pCur++ != '\n' );
00063 
00064     // read the name
00065     pName = pCur;             while ( *pCur++ );
00066     // read the number of inputs
00067     nInputs = atoi( pCur );   while ( *pCur++ );
00068     // read the number of outputs
00069     nOutputs = atoi( pCur );  while ( *pCur++ );
00070     // read the number of latches
00071     nLatches = atoi( pCur );  while ( *pCur++ );
00072     // read the number of nodes
00073     nAnds = atoi( pCur );     while ( *pCur++ );
00074 
00075     // allocate the empty AIG
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     // prepare the array of nodes
00081     vNodes = Vec_PtrAlloc( 1 + nInputs + nLatches + nAnds );
00082     Vec_PtrPush( vNodes, Abc_AigConst1(pNtkNew) );
00083 
00084     // create the PIs
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     // create the POs
00092     for ( i = 0; i < nOutputs; i++ )
00093     {
00094         pObj = Abc_NtkCreatePo(pNtkNew);   
00095         Abc_ObjAssignName( pObj, pCur, NULL );  while ( *pCur++ ); 
00096     }
00097     // create the latches
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     // get the pointer to the beginning of the node array
00115     pBufferNode = (int *)(pContents + (nFileSize - (2 * nAnds + nOutputs + nLatches) * sizeof(int)) );
00116     // make sure we are at the place where the nodes begin
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     // create the AND gates
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     // read the POs
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     // remove the extra nodes
00153 //    Abc_AigCleanup( pNtkNew->pManFunc );
00154 
00155     // check the result
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 }


Generated on Tue Jan 5 12:18:45 2010 for abc70930 by  doxygen 1.6.1