abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioReadEqn.c File Reference
#include "ioAbc.h"

Go to the source code of this file.

Functions

static
ABC_NAMESPACE_IMPL_START
Abc_Ntk_t
Io_ReadEqnNetwork (Extra_FileReader_t *p)
 DECLARATIONS ///. More...
 
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 DEFINITIONS ///. More...
 

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 50 of file ioReadEqn.c.

51 {
53  Abc_Ntk_t * pNtk;
54 
55  // start the file
56  p = Extra_FileReaderAlloc( pFileName, "#", ";", "=" );
57  if ( p == NULL )
58  return NULL;
59 
60  // read the network
61  pNtk = Io_ReadEqnNetwork( p );
63  if ( pNtk == NULL )
64  return NULL;
65 
66  // make sure that everything is okay with the network structure
67  if ( fCheck && !Abc_NtkCheckRead( pNtk ) )
68  {
69  printf( "Io_ReadEqn: The network check has failed.\n" );
70  Abc_NtkDelete( pNtk );
71  return NULL;
72  }
73  return pNtk;
74 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Extra_FileReaderFree(Extra_FileReader_t *p)
Extra_FileReader_t * Extra_FileReaderAlloc(char *pFileName, char *pCharsComment, char *pCharsStop, char *pCharsClean)
FUNCTION DEFINITIONS ///.
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
Definition: abcCheck.c:77
static ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Io_ReadEqnNetwork(Extra_FileReader_t *p)
DECLARATIONS ///.
Definition: ioReadEqn.c:87
Abc_Ntk_t * Io_ReadEqnNetwork ( Extra_FileReader_t p)
static

DECLARATIONS ///.

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

]

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 87 of file ioReadEqn.c.

88 {
89  ProgressBar * pProgress;
90  Vec_Ptr_t * vTokens;
91  Vec_Ptr_t * vVars;
92  Abc_Ntk_t * pNtk;
93  Abc_Obj_t * pNode;
94  char * pNodeName, * pFormula, * pFormulaCopy, * pVarName;
95  int iLine, i;
96 
97  // allocate the empty network
99  // set the specs
102 
103  // go through the lines of the file
104  vVars = Vec_PtrAlloc( 100 );
105  pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) );
106  for ( iLine = 0; (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p)); iLine++ )
107  {
109 
110  // check if the first token contains anything
111  Io_ReadEqnStrCompact( (char *)vTokens->pArray[0] );
112  if ( strlen((char *)vTokens->pArray[0]) == 0 )
113  break;
114 
115  // if the number of tokens is different from two, error
116  if ( vTokens->nSize != 2 )
117  {
118  printf( "%s: Wrong input file format.\n", Extra_FileReaderGetFileName(p) );
119  Abc_NtkDelete( pNtk );
120  return NULL;
121  }
122 
123  // get the type of the line
124  if ( strncmp( (char *)vTokens->pArray[0], "INORDER", 7 ) == 0 )
125  {
126  Io_ReadEqnStrCutAt( (char *)vTokens->pArray[1], " \n\r\t", 0, vVars );
127  Vec_PtrForEachEntry( char *, vVars, pVarName, i )
128  Io_ReadCreatePi( pNtk, pVarName );
129  }
130  else if ( strncmp( (char *)vTokens->pArray[0], "OUTORDER", 8 ) == 0 )
131  {
132  Io_ReadEqnStrCutAt( (char *)vTokens->pArray[1], " \n\r\t", 0, vVars );
133  Vec_PtrForEachEntry( char *, vVars, pVarName, i )
134  Io_ReadCreatePo( pNtk, pVarName );
135  }
136  else
137  {
138  extern Hop_Obj_t * Parse_FormulaParserEqn( FILE * pOutput, char * pFormInit, Vec_Ptr_t * vVarNames, Hop_Man_t * pMan );
139 
140  // get hold of the node name and its formula
141  pNodeName = (char *)vTokens->pArray[0];
142  pFormula = (char *)vTokens->pArray[1];
143  // compact the formula
144  Io_ReadEqnStrCompact( pFormula );
145 
146  // consider the case of the constant node
147  if ( pFormula[1] == 0 && (pFormula[0] == '0' || pFormula[0] == '1') )
148  {
149  pFormulaCopy = NULL;
150  Vec_PtrClear( vVars );
151  }
152  else
153  {
154  // make a copy of formula for names
155  pFormulaCopy = Extra_UtilStrsav( pFormula );
156  // find the names of the fanins of this node
157  Io_ReadEqnStrCutAt( pFormulaCopy, "!*+()", 1, vVars );
158  }
159  // create the node
160  pNode = Io_ReadCreateNode( pNtk, pNodeName, (char **)Vec_PtrArray(vVars), Vec_PtrSize(vVars) );
161  // derive the function
162  pNode->pData = Parse_FormulaParserEqn( stdout, pFormula, vVars, (Hop_Man_t *)pNtk->pManFunc );
163  // remove the cubes
164  ABC_FREE( pFormulaCopy );
165  }
166  }
167  Extra_ProgressBarStop( pProgress );
168  Vec_PtrFree( vVars );
169  Abc_NtkFinalizeRead( pNtk );
170  return pNtk;
171 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Io_ReadEqnStrCutAt(char *pStr, char *pStop, int fUniqueOnly, Vec_Ptr_t *vTokens)
Definition: ioReadEqn.c:227
char * Extra_FileReaderGetFileName(Extra_FileReader_t *p)
ABC_DLL void Abc_NtkFinalizeRead(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:360
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Definition: hop.h:65
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
char * Extra_UtilStrsav(const char *s)
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
DECLARATIONS ///.
Abc_Obj_t * Io_ReadCreatePi(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:610
char * Extra_FileNameGeneric(char *FileName)
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
void Extra_ProgressBarStop(ProgressBar *p)
char * pSpec
Definition: abc.h:159
void * Extra_FileReaderGetTokens(Extra_FileReader_t *p)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Hop_Obj_t * Parse_FormulaParserEqn(FILE *pOutput, char *pFormInit, Vec_Ptr_t *vVarNames, Hop_Man_t *pMan)
FUNCTION DEFINITIONS ///.
Definition: parseEqn.c:72
int Extra_FileReaderGetFileSize(Extra_FileReader_t *p)
#define ABC_FREE(obj)
Definition: abc_global.h:232
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int strncmp()
Abc_Obj_t * Io_ReadCreateNode(Abc_Ntk_t *pNtk, char *pNameOut, char *pNamesIn[], int nInputs)
Definition: ioUtil.c:725
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
int strlen()
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Abc_Obj_t * Io_ReadCreatePo(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:635
static void ** Vec_PtrArray(Vec_Ptr_t *p)
Definition: vecPtr.h:279
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
char * pName
Definition: abc.h:158
static void Io_ReadEqnStrCompact(char *pStr)
Definition: ioReadEqn.c:186
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Extra_FileReaderGetCurPosition(Extra_FileReader_t *p)
void Io_ReadEqnStrCompact ( char *  pStr)
static

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 186 of file ioReadEqn.c.

187 {
188  char * pCur, * pNew;
189  for ( pNew = pCur = pStr; *pCur; pCur++ )
190  if ( !(*pCur == ' ' || *pCur == '\n' || *pCur == '\r' || *pCur == '\t') )
191  *pNew++ = *pCur;
192  *pNew = 0;
193 }
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 227 of file ioReadEqn.c.

228 {
229  char * pToken;
230  Vec_PtrClear( vTokens );
231  for ( pToken = strtok( pStr, pStop ); pToken; pToken = strtok( NULL, pStop ) )
232  if ( !fUniqueOnly || Io_ReadEqnStrFind( vTokens, pToken ) == -1 )
233  Vec_PtrPush( vTokens, pToken );
234 }
char * strtok()
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
static int Io_ReadEqnStrFind(Vec_Ptr_t *vTokens, char *pName)
Definition: ioReadEqn.c:206
int Io_ReadEqnStrFind ( Vec_Ptr_t vTokens,
char *  pName 
)
static

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

Synopsis [Determines unique variables in the string.]

Description []

SideEffects []

SeeAlso []

Definition at line 206 of file ioReadEqn.c.

207 {
208  char * pToken;
209  int i;
210  Vec_PtrForEachEntry( char *, vTokens, pToken, i )
211  if ( strcmp( pToken, pName ) == 0 )
212  return i;
213  return -1;
214 }
int strcmp()
if(last==0)
Definition: sparse_int.h:34
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55