src/base/io/ioReadEqn.c File Reference

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

Go to the source code of this file.

Functions

static Abc_Ntk_tIo_ReadEqnNetwork (Extra_FileReader_t *p)
static void Io_ReadEqnStrCompact (char *pStr)
static int Io_ReadEqnStrFind (Vec_Ptr_t *vTokens, char *pName)
static void Io_ReadEqnStrCutAt (char *pStr, char *pStop, int fUniqueOnly, Vec_Ptr_t *vTokens)
Abc_Ntk_tIo_ReadEqn (char *pFileName, int fCheck)

Function Documentation

Abc_Ntk_t* Io_ReadEqn ( char *  pFileName,
int  fCheck 
)

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

Synopsis [Reads the network from a BENCH file.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file ioReadEqn.c.

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

Abc_Ntk_t * Io_ReadEqnNetwork ( Extra_FileReader_t p  )  [static]

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

FileName [ioReadEqn.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Command processing package.]

Synopsis [Procedures to read equation format files.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

] DECLARATIONS ///

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 84 of file ioReadEqn.c.

00085 {
00086     ProgressBar * pProgress;
00087     Vec_Ptr_t * vTokens;
00088     Vec_Ptr_t * vVars;
00089     Abc_Ntk_t * pNtk;
00090     Abc_Obj_t * pNode;
00091     char * pNodeName, * pFormula, * pFormulaCopy, * pVarName;
00092     int iLine, i;
00093     
00094     // allocate the empty network
00095     pNtk = Abc_NtkAlloc( ABC_NTK_NETLIST, ABC_FUNC_AIG, 1 );
00096     // set the specs
00097     pNtk->pName = Extra_FileNameGeneric(Extra_FileReaderGetFileName(p));
00098     pNtk->pSpec = Extra_UtilStrsav(Extra_FileReaderGetFileName(p));
00099 
00100     // go through the lines of the file
00101     vVars  = Vec_PtrAlloc( 100 );
00102     pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) );
00103     for ( iLine = 0; vTokens = Extra_FileReaderGetTokens(p); iLine++ )
00104     {
00105         Extra_ProgressBarUpdate( pProgress, Extra_FileReaderGetCurPosition(p), NULL );
00106 
00107         // check if the first token contains anything
00108         Io_ReadEqnStrCompact( vTokens->pArray[0] );
00109         if ( strlen(vTokens->pArray[0]) == 0 )
00110             break;
00111 
00112         // if the number of tokens is different from two, error
00113         if ( vTokens->nSize != 2 )
00114         {
00115             printf( "%s: Wrong input file format.\n", Extra_FileReaderGetFileName(p) );
00116             Abc_NtkDelete( pNtk );
00117             return NULL;
00118         }
00119 
00120         // get the type of the line
00121         if ( strncmp( vTokens->pArray[0], "INORDER", 7 ) == 0 )
00122         {
00123             Io_ReadEqnStrCutAt( vTokens->pArray[1], " \n\r\t", 0, vVars );
00124             Vec_PtrForEachEntry( vVars, pVarName, i )
00125                 Io_ReadCreatePi( pNtk, pVarName );
00126         }
00127         else if ( strncmp( vTokens->pArray[0], "OUTORDER", 8 ) == 0 )
00128         {
00129             Io_ReadEqnStrCutAt( vTokens->pArray[1], " \n\r\t", 0, vVars );
00130             Vec_PtrForEachEntry( vVars, pVarName, i )
00131                 Io_ReadCreatePo( pNtk, pVarName );
00132         }
00133         else 
00134         {
00135             extern Hop_Obj_t * Parse_FormulaParserEqn( FILE * pOutput, char * pFormInit, Vec_Ptr_t * vVarNames, Hop_Man_t * pMan );
00136 
00137             // get hold of the node name and its formula
00138             pNodeName = vTokens->pArray[0];
00139             pFormula  = vTokens->pArray[1];
00140             // compact the formula 
00141             Io_ReadEqnStrCompact( pFormula );
00142 
00143             // consider the case of the constant node
00144             if ( pFormula[1] == 0 && (pFormula[0] == '0' || pFormula[0] == '1') )
00145             {
00146                 pFormulaCopy = NULL;
00147                 Vec_PtrClear( vVars );
00148             }
00149             else
00150             {
00151                 // make a copy of formula for names
00152                 pFormulaCopy = Extra_UtilStrsav( pFormula );
00153                 // find the names of the fanins of this node
00154                 Io_ReadEqnStrCutAt( pFormulaCopy, "!*+()", 1, vVars );
00155             }
00156             // create the node
00157             pNode = Io_ReadCreateNode( pNtk, pNodeName, (char **)Vec_PtrArray(vVars), Vec_PtrSize(vVars) );
00158             // derive the function
00159             pNode->pData = Parse_FormulaParserEqn( stdout, pFormula, vVars, pNtk->pManFunc );
00160             // remove the cubes
00161             FREE( pFormulaCopy );
00162         }
00163     }
00164     Extra_ProgressBarStop( pProgress );
00165     Vec_PtrFree( vVars );
00166     Abc_NtkFinalizeRead( pNtk );
00167     return pNtk;
00168 }

void Io_ReadEqnStrCompact ( char *  pStr  )  [static]

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

Synopsis [Compacts the string by throwing away space-like chars.]

Description []

SideEffects []

SeeAlso []

Definition at line 183 of file ioReadEqn.c.

00184 {
00185     char * pCur, * pNew;
00186     for ( pNew = pCur = pStr; *pCur; pCur++ )
00187         if ( !(*pCur == ' ' || *pCur == '\n' || *pCur == '\r' || *pCur == '\t') )
00188             *pNew++ = *pCur;
00189     *pNew = 0;
00190 }

void Io_ReadEqnStrCutAt ( char *  pStr,
char *  pStop,
int  fUniqueOnly,
Vec_Ptr_t vTokens 
) [static]

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

Synopsis [Cuts the string into pieces using stop chars.]

Description []

SideEffects []

SeeAlso []

Definition at line 224 of file ioReadEqn.c.

00225 {
00226     char * pToken;
00227     Vec_PtrClear( vTokens );
00228     for ( pToken = strtok( pStr, pStop ); pToken; pToken = strtok( NULL, pStop ) )
00229         if ( !fUniqueOnly || Io_ReadEqnStrFind( vTokens, pToken ) == -1 )
00230             Vec_PtrPush( vTokens, pToken );
00231 }

int Io_ReadEqnStrFind ( Vec_Ptr_t vTokens,
char *  pName 
) [static]

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

Synopsis [Determines unique variables in the string.]

Description []

SideEffects []

SeeAlso []

Definition at line 203 of file ioReadEqn.c.

00204 {
00205     char * pToken;
00206     int i;
00207     Vec_PtrForEachEntry( vTokens, pToken, i )
00208         if ( strcmp( pToken, pName ) == 0 )
00209             return i;
00210     return -1;
00211 }


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