abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioReadEdif.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioReadEdif.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedure to read ISCAS benchmarks in EDIF.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioReadEdif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Reads the network from an EDIF file.]
39 
40  Description [Works only for the ISCAS benchmarks.]
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 Abc_Ntk_t * Io_ReadEdif( char * pFileName, int fCheck )
48 {
50  Abc_Ntk_t * pNtk;
51 
52  printf( "Currently this parser does not work!\n" );
53  return NULL;
54 
55  // start the file
56  p = Extra_FileReaderAlloc( pFileName, "#", "\n\r", " \t()" );
57  if ( p == NULL )
58  return NULL;
59 
60  // read the network
61  pNtk = Io_ReadEdifNetwork( 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_ReadEdif: The network check has failed.\n" );
70  Abc_NtkDelete( pNtk );
71  return NULL;
72  }
73  return pNtk;
74 }
75 /**Function*************************************************************
76 
77  Synopsis []
78 
79  Description []
80 
81  SideEffects []
82 
83  SeeAlso []
84 
85 ***********************************************************************/
87 {
88  ProgressBar * pProgress;
89  Vec_Ptr_t * vTokens;
90  Abc_Ntk_t * pNtk;
91  Abc_Obj_t * pNet, * pObj, * pFanout;
92  char * pGateName, * pNetName;
93  int fTokensReady, iLine, i;
94 
95  // read the first line
96  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
97  if ( strcmp( (char *)vTokens->pArray[0], "edif" ) != 0 )
98  {
99  printf( "%s: Wrong input file format.\n", Extra_FileReaderGetFileName(p) );
100  return NULL;
101  }
102 
103  // allocate the empty network
105 
106  // go through the lines of the file
107  fTokensReady = 0;
108  pProgress = Extra_ProgressBarStart( stdout, Extra_FileReaderGetFileSize(p) );
109  for ( iLine = 1; fTokensReady || (vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p)); iLine++ )
110  {
112 
113  // get the type of the line
114  fTokensReady = 0;
115  if ( strcmp( (char *)vTokens->pArray[0], "instance" ) == 0 )
116  {
117  pNetName = (char *)vTokens->pArray[1];
118  pNet = Abc_NtkFindOrCreateNet( pNtk, pNetName );
119  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
120  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
121  pGateName = (char *)vTokens->pArray[1];
122  if ( strncmp( pGateName, "Flip", 4 ) == 0 )
123  {
124  pObj = Abc_NtkCreateLatch( pNtk );
125  Abc_LatchSetInit0( pObj );
126  }
127  else
128  {
129  pObj = Abc_NtkCreateNode( pNtk );
130 // pObj->pData = Abc_NtkRegisterName( pNtk, pGateName );
131  pObj->pData = Extra_UtilStrsav( pGateName ); // memory leak!!!
132  }
133  Abc_ObjAddFanin( pNet, pObj );
134  }
135  else if ( strcmp( (char *)vTokens->pArray[0], "net" ) == 0 )
136  {
137  pNetName = (char *)vTokens->pArray[1];
138  if ( strcmp( pNetName, "CK" ) == 0 || strcmp( pNetName, "RESET" ) == 0 )
139  continue;
140  if ( strcmp( pNetName + strlen(pNetName) - 4, "_out" ) == 0 )
141  pNetName[strlen(pNetName) - 4] = 0;
142  pNet = Abc_NtkFindNet( pNtk, pNetName );
143  assert( pNet );
144  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
145  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
146  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
147  while ( strcmp( (char *)vTokens->pArray[0], "portRef" ) == 0 )
148  {
149  if ( strcmp( pNetName, (char *)vTokens->pArray[3] ) != 0 )
150  {
151  pFanout = Abc_NtkFindNet( pNtk, (char *)vTokens->pArray[3] );
152  Abc_ObjAddFanin( Abc_ObjFanin0(pFanout), pNet );
153  }
154  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
155  }
156  fTokensReady = 1;
157  }
158  else if ( strcmp( (char *)vTokens->pArray[0], "library" ) == 0 )
159  {
160  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
161  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
162  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
163  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
164  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
165  while ( strcmp( (char *)vTokens->pArray[0], "port" ) == 0 )
166  {
167  pNetName = (char *)vTokens->pArray[1];
168  if ( strcmp( pNetName, "CK" ) == 0 || strcmp( pNetName, "RESET" ) == 0 )
169  {
170  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
171  continue;
172  }
173  if ( strcmp( pNetName + strlen(pNetName) - 3, "_PO" ) == 0 )
174  pNetName[strlen(pNetName) - 3] = 0;
175  if ( strcmp( (char *)vTokens->pArray[3], "INPUT" ) == 0 )
176  Io_ReadCreatePi( pNtk, (char *)vTokens->pArray[1] );
177  else if ( strcmp( (char *)vTokens->pArray[3], "OUTPUT" ) == 0 )
178  Io_ReadCreatePo( pNtk, (char *)vTokens->pArray[1] );
179  else
180  {
181  printf( "%s (line %d): Wrong interface specification.\n", Extra_FileReaderGetFileName(p), iLine );
182  Abc_NtkDelete( pNtk );
183  return NULL;
184  }
185  vTokens = (Vec_Ptr_t *)Extra_FileReaderGetTokens(p);
186  }
187  }
188  else if ( strcmp( (char *)vTokens->pArray[0], "design" ) == 0 )
189  {
190  ABC_FREE( pNtk->pName );
191  pNtk->pName = (char *)Extra_UtilStrsav( (char *)vTokens->pArray[3] );
192  break;
193  }
194  }
195  Extra_ProgressBarStop( pProgress );
196 
197  // assign logic functions
198  Abc_NtkForEachNode( pNtk, pObj, i )
199  {
200  if ( strncmp( (char *)pObj->pData, "And", 3 ) == 0 )
201  Abc_ObjSetData( pObj, Abc_SopCreateAnd((Mem_Flex_t *)pNtk->pManFunc, Abc_ObjFaninNum(pObj), NULL) );
202  else if ( strncmp( (char *)pObj->pData, "Or", 2 ) == 0 )
203  Abc_ObjSetData( pObj, Abc_SopCreateOr((Mem_Flex_t *)pNtk->pManFunc, Abc_ObjFaninNum(pObj), NULL) );
204  else if ( strncmp( (char *)pObj->pData, "Nand", 4 ) == 0 )
206  else if ( strncmp( (char *)pObj->pData, "Nor", 3 ) == 0 )
208  else if ( strncmp( (char *)pObj->pData, "Exor", 4 ) == 0 )
210  else if ( strncmp( (char *)pObj->pData, "Exnor", 5 ) == 0 )
212  else if ( strncmp( (char *)pObj->pData, "Inv", 3 ) == 0 )
214  else if ( strncmp( (char *)pObj->pData, "Buf", 3 ) == 0 )
216  else
217  {
218  printf( "%s: Unknown gate type \"%s\".\n", Extra_FileReaderGetFileName(p), (char*)pObj->pData );
219  Abc_NtkDelete( pNtk );
220  return NULL;
221  }
222  }
223  // check if constants have been added
224 // if ( pNet = Abc_NtkFindNet( pNtk, "VDD" ) )
225 // Io_ReadCreateConst( pNtk, "VDD", 1 );
226 // if ( pNet = Abc_NtkFindNet( pNtk, "GND" ) )
227 // Io_ReadCreateConst( pNtk, "GND", 0 );
228 
229  Abc_NtkFinalizeRead( pNtk );
230  return pNtk;
231 }
232 
233 ////////////////////////////////////////////////////////////////////////
234 /// END OF FILE ///
235 ////////////////////////////////////////////////////////////////////////
236 
237 
238 
240 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Io_ReadEdifNetwork(Extra_FileReader_t *p)
DECLARATIONS ///.
Definition: ioReadEdif.c:86
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * Extra_FileReaderGetFileName(Extra_FileReader_t *p)
ABC_DLL char * Abc_SopCreateAnd(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition: abcSop.c:162
ABC_DLL char * Abc_SopCreateInv(Mem_Flex_t *pMan)
Definition: abcSop.c:345
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void Extra_FileReaderFree(Extra_FileReader_t *p)
ABC_DLL void Abc_NtkFinalizeRead(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:360
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL char * Abc_SopCreateNand(Mem_Flex_t *pMan, int nVars)
Definition: abcSop.c:184
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
static void Abc_ObjSetData(Abc_Obj_t *pObj, void *pData)
Definition: abc.h:343
char * Extra_UtilStrsav(const char *s)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL char * Abc_SopCreateBuf(Mem_Flex_t *pMan)
Definition: abcSop.c:361
int strcmp()
void * pManFunc
Definition: abc.h:191
DECLARATIONS ///.
Abc_Obj_t * Io_ReadCreatePi(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:610
ABC_DLL Abc_Ntk_t * Abc_NtkStartRead(char *pName)
Definition: abcNtk.c:333
ABC_DLL char * Abc_SopCreateNxor(Mem_Flex_t *pMan, int nVars)
Definition: abcSop.c:311
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
Definition: abcCheck.c:77
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_DLL Abc_Obj_t * Abc_NtkFindNet(Abc_Ntk_t *pNtk, char *pName)
Definition: abcObj.c:507
if(last==0)
Definition: sparse_int.h:34
ABC_DLL char * Abc_SopCreateXor(Mem_Flex_t *pMan, int nVars)
Definition: abcSop.c:274
static Abc_Obj_t * Abc_NtkCreateLatch(Abc_Ntk_t *pNtk)
Definition: abc.h:309
void Extra_ProgressBarStop(ProgressBar *p)
ABC_DLL Abc_Obj_t * Abc_NtkFindOrCreateNet(Abc_Ntk_t *pNtk, char *pName)
Definition: abcObj.c:579
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_DLL char * Abc_SopCreateNor(Mem_Flex_t *pMan, int nVars)
Definition: abcSop.c:253
void * Extra_FileReaderGetTokens(Extra_FileReader_t *p)
int Extra_FileReaderGetFileSize(Extra_FileReader_t *p)
#define ABC_FREE(obj)
Definition: abc_global.h:232
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int strncmp()
#define assert(ex)
Definition: util_old.h:213
static void Extra_ProgressBarUpdate(ProgressBar *p, int nItemsCur, char *pString)
Definition: extra.h:243
int strlen()
void * pData
Definition: abc.h:145
Abc_Obj_t * Io_ReadCreatePo(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:635
static void Abc_LatchSetInit0(Abc_Obj_t *pLatch)
Definition: abc.h:418
ABC_DLL char * Abc_SopCreateOr(Mem_Flex_t *pMan, int nVars, int *pfCompl)
Definition: abcSop.c:206
char * pName
Definition: abc.h:158
int Extra_FileReaderGetCurPosition(Extra_FileReader_t *p)
Abc_Ntk_t * Io_ReadEdif(char *pFileName, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadEdif.c:47