src/base/io/ioReadBench.c File Reference

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

Go to the source code of this file.

Functions

static Abc_Ntk_tIo_ReadBenchNetwork (Extra_FileReader_t *p)
Abc_Ntk_tIo_ReadBench (char *pFileName, int fCheck)
void Io_ReadBenchInit (Abc_Ntk_t *pNtk, char *pFileName)

Function Documentation

Abc_Ntk_t* Io_ReadBench ( char *  pFileName,
int  fCheck 
)

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Reads the network from a BENCH file.]

Description []

SideEffects []

SeeAlso []

Definition at line 44 of file ioReadBench.c.

00045 {
00046     Extra_FileReader_t * p;
00047     Abc_Ntk_t * pNtk;
00048 
00049     // start the file
00050     p = Extra_FileReaderAlloc( pFileName, "#", "\n\r", " \t,()=" );
00051     if ( p == NULL )
00052         return NULL;
00053 
00054     // read the network
00055     pNtk = Io_ReadBenchNetwork( p );
00056     Extra_FileReaderFree( p );
00057     if ( pNtk == NULL )
00058         return NULL;
00059 
00060     // make sure that everything is okay with the network structure
00061     if ( fCheck && !Abc_NtkCheckRead( pNtk ) )
00062     {
00063         printf( "Io_ReadBench: The network check has failed.\n" );
00064         Abc_NtkDelete( pNtk );
00065         return NULL;
00066     }
00067     return pNtk;
00068 }

void Io_ReadBenchInit ( Abc_Ntk_t pNtk,
char *  pFileName 
)

Function*************************************************************

Synopsis [Reads initial state in BENCH format.]

Description []

SideEffects []

SeeAlso []

Definition at line 307 of file ioReadBench.c.

00308 {
00309     char pBuffer[1000];
00310     FILE * pFile;
00311     char * pToken;
00312     Abc_Obj_t * pObj;
00313     int Num;
00314     pFile = fopen( pFileName, "r" );
00315     if ( pFile == NULL )
00316     {
00317         printf( "Io_ReadBenchInit(): Failed to open file \"%s\".\n", pFileName );
00318         return;
00319     }
00320     while ( fgets( pBuffer, 999, pFile ) )
00321     {
00322         pToken = strtok( pBuffer, " \n\t\r" );
00323         // find the latch output
00324         Num = Nm_ManFindIdByName( pNtk->pManName, pToken, ABC_OBJ_BO );
00325         if ( Num < 0 )
00326         {
00327             printf( "Io_ReadBenchInit(): Cannot find register with output %s.\n", pToken );
00328             continue;
00329         }
00330         pObj = Abc_ObjFanin0( Abc_NtkObj( pNtk, Num ) );
00331         if ( !Abc_ObjIsLatch(pObj) )
00332         {
00333             printf( "Io_ReadBenchInit(): The signal is not a register output %s.\n", pToken );
00334             continue;
00335         }
00336         // assign the new init state
00337         pToken = strtok( NULL, " \n\t\r" );
00338         if ( pToken[0] == '0' )
00339             Abc_LatchSetInit0( pObj );
00340         else if ( pToken[0] == '1' )
00341             Abc_LatchSetInit1( pObj );
00342         else if ( pToken[0] == '2' )
00343             Abc_LatchSetInitDc( pObj );
00344         else
00345         {
00346             printf( "Io_ReadBenchInit(): The signal %s has unknown initial value (%s).\n", 
00347                 Abc_ObjName(Abc_ObjFanout0(pObj)), pToken );
00348             continue;
00349         }
00350     }
00351     fclose( pFile );
00352 }

Abc_Ntk_t * Io_ReadBenchNetwork ( Extra_FileReader_t p  )  [static]

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

FileName [ioReadBench.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to read BENCH files.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

] DECLARATIONS ///

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 81 of file ioReadBench.c.

00082 {
00083     ProgressBar * pProgress;
00084     Vec_Ptr_t * vTokens;
00085     Abc_Ntk_t * pNtk;
00086     Abc_Obj_t * pNode, * pNet;
00087     Vec_Str_t * vString;
00088     unsigned uTruth[8];
00089     char * pType, ** ppNames, * pString;
00090     int iLine, nNames, nDigits, fLutsPresent = 0;
00091     
00092     // allocate the empty network
00093     pNtk = Abc_NtkStartRead( Extra_FileReaderGetFileName(p) );
00094 
00095     // go through the lines of the file
00096     vString = Vec_StrAlloc( 100 );
00097     pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) );
00098     for ( iLine = 0; vTokens = Extra_FileReaderGetTokens(p); iLine++ )
00099     {
00100         Extra_ProgressBarUpdate( pProgress, Extra_FileReaderGetCurPosition(p), NULL );
00101 
00102         if ( vTokens->nSize == 1 )
00103         {
00104             printf( "%s: Wrong input file format.\n", Extra_FileReaderGetFileName(p) );
00105             Vec_StrFree( vString );
00106             Abc_NtkDelete( pNtk );
00107             return NULL;
00108         }
00109 
00110         // get the type of the line
00111         if ( strncmp( vTokens->pArray[0], "INPUT", 5 ) == 0 )
00112             Io_ReadCreatePi( pNtk, vTokens->pArray[1] );
00113         else if ( strncmp( vTokens->pArray[0], "OUTPUT", 5 ) == 0 )
00114             Io_ReadCreatePo( pNtk, vTokens->pArray[1] );
00115         else 
00116         {
00117             // get the node name and the node type
00118             pType = vTokens->pArray[1];
00119             if ( strncmp(pType, "DFF", 3) == 0 ) // works for both DFF and DFFRSE
00120             {
00121                 pNode = Io_ReadCreateLatch( pNtk, vTokens->pArray[2], vTokens->pArray[0] );
00122 //                Abc_LatchSetInit0( pNode );
00123                 if ( pType[3] == '0' )
00124                     Abc_LatchSetInit0( pNode );
00125                 else if ( pType[3] == '1' )
00126                     Abc_LatchSetInit1( pNode );
00127                 else
00128                     Abc_LatchSetInitDc( pNode );
00129             }
00130             else if ( strcmp(pType, "LUT") == 0 )
00131             {
00132                 fLutsPresent = 1;
00133                 ppNames = (char **)vTokens->pArray + 3;
00134                 nNames  = vTokens->nSize - 3;
00135                 // check the number of inputs
00136                 if ( nNames > 8 )
00137                 {
00138                     printf( "%s: Currently cannot read truth tables with more than 8 inputs (%d).\n", Extra_FileReaderGetFileName(p), nNames );
00139                     Vec_StrFree( vString );
00140                     Abc_NtkDelete( pNtk );
00141                     return NULL;
00142                 }
00143                 // get the hex string
00144                 pString = vTokens->pArray[2];
00145                 if ( strncmp( pString, "0x", 2 ) )
00146                 {
00147                     printf( "%s: The LUT signature (%s) does not look like a hexadecimal beginning with \"0x\".\n", Extra_FileReaderGetFileName(p), pString );
00148                     Vec_StrFree( vString );
00149                     Abc_NtkDelete( pNtk );
00150                     return NULL;
00151                 }
00152                 pString += 2;
00153                 // pad the string with zero's if needed
00154                 nDigits = (1 << nNames) / 4;
00155                 if ( nDigits == 0 )
00156                     nDigits = 1;
00157                 if ( strlen(pString) < (unsigned)nDigits )
00158                 {
00159                     Vec_StrFill( vString, nDigits - strlen(pString), '0' );
00160                     Vec_StrPrintStr( vString, pString );
00161                     Vec_StrPush( vString, 0 );
00162                     pString = Vec_StrArray( vString );
00163                 }
00164                 // read the hex number from the string
00165                 if ( !Extra_ReadHexadecimal( uTruth, pString, nNames ) )
00166                 {
00167                     printf( "%s: Reading hexadecimal number (%s) has failed.\n", Extra_FileReaderGetFileName(p), pString );
00168                     Vec_StrFree( vString );
00169                     Abc_NtkDelete( pNtk );
00170                     return NULL;
00171                 }
00172                 // check if the node is a constant node
00173                 if ( Extra_TruthIsConst0(uTruth, nNames) )
00174                 {
00175                     pNode = Io_ReadCreateNode( pNtk, vTokens->pArray[0], ppNames, 0 );
00176                     Abc_ObjSetData( pNode, Abc_SopRegister( pNtk->pManFunc, " 0\n" ) );
00177                 }
00178                 else if ( Extra_TruthIsConst1(uTruth, nNames) )
00179                 {
00180                     pNode = Io_ReadCreateNode( pNtk, vTokens->pArray[0], ppNames, 0 );
00181                     Abc_ObjSetData( pNode, Abc_SopRegister( pNtk->pManFunc, " 1\n" ) );
00182                 }
00183                 else
00184                 {
00185                     // create the node
00186                     pNode = Io_ReadCreateNode( pNtk, vTokens->pArray[0], ppNames, nNames );
00187                     assert( nNames > 0 );
00188                     if ( nNames > 1 )
00189                         Abc_ObjSetData( pNode, Abc_SopCreateFromTruth(pNtk->pManFunc, nNames, uTruth) );
00190                     else if ( pString[0] == '2' )
00191                         Abc_ObjSetData( pNode, Abc_SopCreateBuf(pNtk->pManFunc) );
00192                     else if ( pString[0] == '1' )
00193                         Abc_ObjSetData( pNode, Abc_SopCreateInv(pNtk->pManFunc) );
00194                     else
00195                     {
00196                         printf( "%s: Reading truth table (%s) of single-input node has failed.\n", Extra_FileReaderGetFileName(p), pString );
00197                         Vec_StrFree( vString );
00198                         Abc_NtkDelete( pNtk );
00199                         return NULL;
00200                     }
00201                 }
00202             }
00203             else
00204             {
00205                 // create a new node and add it to the network
00206                 ppNames = (char **)vTokens->pArray + 2;
00207                 nNames  = vTokens->nSize - 2;
00208                 pNode = Io_ReadCreateNode( pNtk, vTokens->pArray[0], ppNames, nNames );
00209                 // assign the cover
00210                 if ( strcmp(pType, "AND") == 0 )
00211                     Abc_ObjSetData( pNode, Abc_SopCreateAnd(pNtk->pManFunc, nNames, NULL) );
00212                 else if ( strcmp(pType, "OR") == 0 )
00213                     Abc_ObjSetData( pNode, Abc_SopCreateOr(pNtk->pManFunc, nNames, NULL) );
00214                 else if ( strcmp(pType, "NAND") == 0 )
00215                     Abc_ObjSetData( pNode, Abc_SopCreateNand(pNtk->pManFunc, nNames) );
00216                 else if ( strcmp(pType, "NOR") == 0 )
00217                     Abc_ObjSetData( pNode, Abc_SopCreateNor(pNtk->pManFunc, nNames) );
00218                 else if ( strcmp(pType, "XOR") == 0 )
00219                     Abc_ObjSetData( pNode, Abc_SopCreateXor(pNtk->pManFunc, nNames) );
00220                 else if ( strcmp(pType, "NXOR") == 0 || strcmp(pType, "XNOR") == 0 )
00221                     Abc_ObjSetData( pNode, Abc_SopCreateNxor(pNtk->pManFunc, nNames) );
00222                 else if ( strncmp(pType, "BUF", 3) == 0 )
00223                     Abc_ObjSetData( pNode, Abc_SopCreateBuf(pNtk->pManFunc) );
00224                 else if ( strcmp(pType, "NOT") == 0 )
00225                     Abc_ObjSetData( pNode, Abc_SopCreateInv(pNtk->pManFunc) );
00226                 else if ( strncmp(pType, "MUX", 3) == 0 )
00227                     Abc_ObjSetData( pNode, Abc_SopRegister(pNtk->pManFunc, "1-0 1\n-11 1\n") );
00228                 else if ( strncmp(pType, "gnd", 3) == 0 )
00229                     Abc_ObjSetData( pNode, Abc_SopRegister( pNtk->pManFunc, " 0\n" ) );
00230                 else if ( strncmp(pType, "vdd", 3) == 0 )
00231                     Abc_ObjSetData( pNode, Abc_SopRegister( pNtk->pManFunc, " 1\n" ) );
00232                 else
00233                 {
00234                     printf( "Io_ReadBenchNetwork(): Cannot determine gate type \"%s\" in line %d.\n", pType, Extra_FileReaderGetLineNumber(p, 0) );
00235                     Vec_StrFree( vString );
00236                     Abc_NtkDelete( pNtk );
00237                     return NULL;
00238                 }
00239             }
00240         }
00241     }
00242     Extra_ProgressBarStop( pProgress );
00243     Vec_StrFree( vString );
00244 
00245     // check if constant 0 is present
00246     if ( (pNet = Abc_NtkFindNet( pNtk, "gnd" )) )
00247     {
00248         if ( Abc_ObjFaninNum(pNet) == 0 )
00249             Io_ReadCreateConst( pNtk, "gnd", 0 );
00250     }
00251     if ( (pNet = Abc_NtkFindNet( pNtk, "1" )) )
00252     {
00253         if ( Abc_ObjFaninNum(pNet) == 0 )
00254         {
00255             printf( "Io_ReadBenchNetwork(): Adding constant 0 fanin to non-driven net \"1\".\n" );
00256             Io_ReadCreateConst( pNtk, "1", 0 );
00257         }
00258     }
00259     // check if constant 1 is present
00260     if ( (pNet = Abc_NtkFindNet( pNtk, "vdd" )) )
00261     {
00262         if ( Abc_ObjFaninNum(pNet) == 0 )
00263             Io_ReadCreateConst( pNtk, "vdd", 1 );
00264     }
00265     if ( (pNet = Abc_NtkFindNet( pNtk, "2" )) )
00266     {
00267         if ( Abc_ObjFaninNum(pNet) == 0 )
00268         {
00269             printf( "Io_ReadBenchNetwork(): Adding constant 1 fanin to non-driven net \"2\".\n" );
00270             Io_ReadCreateConst( pNtk, "2", 1 );
00271         }
00272     }
00273 
00274     Abc_NtkFinalizeRead( pNtk );
00275 
00276     // if LUTs are present, collapse the truth tables into cubes
00277     if ( fLutsPresent )
00278     {
00279         if ( !Abc_NtkToBdd(pNtk) )
00280         {
00281             printf( "Io_ReadBenchNetwork(): Converting to BDD has failed.\n" );
00282             Abc_NtkDelete( pNtk );
00283             return NULL;
00284         }
00285         if ( !Abc_NtkToSop(pNtk, 0) )
00286         {
00287             printf( "Io_ReadBenchNetwork(): Converting to SOP has failed.\n" );
00288             Abc_NtkDelete( pNtk );
00289             return NULL;
00290         }
00291     }
00292     return pNtk;
00293 }


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