abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteEqn.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioWriteEqn.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to write equation representation of the network.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioWriteEqn.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 
30 static void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk );
31 static void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk );
32 static void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk );
33 static int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk );
34 
35 ////////////////////////////////////////////////////////////////////////
36 /// FUNCTION DEFINITIONS ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41  Synopsis [Writes the logic network in the equation format.]
42 
43  Description []
44 
45  SideEffects []
46 
47  SeeAlso []
48 
49 ***********************************************************************/
50 void Io_WriteEqn( Abc_Ntk_t * pNtk, char * pFileName )
51 {
52  FILE * pFile;
53 
54  assert( Abc_NtkIsAigNetlist(pNtk) );
55  if ( Abc_NtkLatchNum(pNtk) > 0 )
56  printf( "Warning: only combinational portion is being written.\n" );
57 
58  // check that the names are fine for the EQN format
59  if ( !Io_NtkWriteEqnCheck(pNtk) )
60  return;
61 
62  // start the output stream
63  pFile = fopen( pFileName, "w" );
64  if ( pFile == NULL )
65  {
66  fprintf( stdout, "Io_WriteEqn(): Cannot open the output file \"%s\".\n", pFileName );
67  return;
68  }
69  fprintf( pFile, "# Equations for \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
70 
71  // write the equations for the network
72  Io_NtkWriteEqnOne( pFile, pNtk );
73  fprintf( pFile, "\n" );
74  fclose( pFile );
75 }
76 
77 /**Function*************************************************************
78 
79  Synopsis [Write one network.]
80 
81  Description []
82 
83  SideEffects []
84 
85  SeeAlso []
86 
87 ***********************************************************************/
88 void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk )
89 {
90  Vec_Vec_t * vLevels;
91  ProgressBar * pProgress;
92  Abc_Obj_t * pNode, * pFanin;
93  int i, k;
94 
95  // write the PIs
96  fprintf( pFile, "INORDER =" );
97  Io_NtkWriteEqnCis( pFile, pNtk );
98  fprintf( pFile, ";\n" );
99 
100  // write the POs
101  fprintf( pFile, "OUTORDER =" );
102  Io_NtkWriteEqnCos( pFile, pNtk );
103  fprintf( pFile, ";\n" );
104 
105  // write each internal node
106  vLevels = Vec_VecAlloc( 10 );
107  pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
108  Abc_NtkForEachNode( pNtk, pNode, i )
109  {
110  Extra_ProgressBarUpdate( pProgress, i, NULL );
111  fprintf( pFile, "%s = ", Abc_ObjName(Abc_ObjFanout0(pNode)) );
112  // set the input names
113  Abc_ObjForEachFanin( pNode, pFanin, k )
114  Hop_IthVar((Hop_Man_t *)pNtk->pManFunc, k)->pData = Abc_ObjName(pFanin);
115  // write the formula
116  Hop_ObjPrintEqn( pFile, (Hop_Obj_t *)pNode->pData, vLevels, 0 );
117  fprintf( pFile, ";\n" );
118  }
119  Extra_ProgressBarStop( pProgress );
120  Vec_VecFree( vLevels );
121 }
122 
123 
124 /**Function*************************************************************
125 
126  Synopsis [Writes the primary input list.]
127 
128  Description []
129 
130  SideEffects []
131 
132  SeeAlso []
133 
134 ***********************************************************************/
135 void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk )
136 {
137  Abc_Obj_t * pTerm, * pNet;
138  int LineLength;
139  int AddedLength;
140  int NameCounter;
141  int i;
142 
143  LineLength = 9;
144  NameCounter = 0;
145 
146  Abc_NtkForEachCi( pNtk, pTerm, i )
147  {
148  pNet = Abc_ObjFanout0(pTerm);
149  // get the line length after this name is written
150  AddedLength = strlen(Abc_ObjName(pNet)) + 1;
151  if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
152  { // write the line extender
153  fprintf( pFile, " \n" );
154  // reset the line length
155  LineLength = 0;
156  NameCounter = 0;
157  }
158  fprintf( pFile, " %s", Abc_ObjName(pNet) );
159  LineLength += AddedLength;
160  NameCounter++;
161  }
162 }
163 
164 /**Function*************************************************************
165 
166  Synopsis [Writes the primary input list.]
167 
168  Description []
169 
170  SideEffects []
171 
172  SeeAlso []
173 
174 ***********************************************************************/
175 void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk )
176 {
177  Abc_Obj_t * pTerm, * pNet;
178  int LineLength;
179  int AddedLength;
180  int NameCounter;
181  int i;
182 
183  LineLength = 10;
184  NameCounter = 0;
185 
186  Abc_NtkForEachCo( pNtk, pTerm, i )
187  {
188  pNet = Abc_ObjFanin0(pTerm);
189  // get the line length after this name is written
190  AddedLength = strlen(Abc_ObjName(pNet)) + 1;
191  if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
192  { // write the line extender
193  fprintf( pFile, " \n" );
194  // reset the line length
195  LineLength = 0;
196  NameCounter = 0;
197  }
198  fprintf( pFile, " %s", Abc_ObjName(pNet) );
199  LineLength += AddedLength;
200  NameCounter++;
201  }
202 }
203 
204 /**Function*************************************************************
205 
206  Synopsis [Make sure the network does not have offending names.]
207 
208  Description []
209 
210  SideEffects []
211 
212  SeeAlso []
213 
214 ***********************************************************************/
216 {
217  Abc_Obj_t * pObj;
218  char * pName = NULL;
219  int i, k, Length;
220  int RetValue = 1;
221 
222  // make sure the network does not have proper names, such as "0" or "1" or containing parantheses
223  Abc_NtkForEachObj( pNtk, pObj, i )
224  {
225  pName = Nm_ManFindNameById(pNtk->pManName, i);
226  if ( pName == NULL )
227  continue;
228  Length = strlen(pName);
229  if ( pName[0] == '0' || pName[0] == '1' )
230  {
231  RetValue = 0;
232  break;
233  }
234  for ( k = 0; k < Length; k++ )
235  if ( pName[k] == '(' || pName[k] == ')' || pName[k] == '!' || pName[k] == '*' || pName[k] == '+' )
236  {
237  RetValue = 0;
238  break;
239  }
240  if ( k < Length )
241  break;
242  }
243  if ( RetValue == 0 )
244  {
245  printf( "The network cannot be written in the EQN format because object %d has name \"%s\".\n", i, pName );
246  printf( "Consider renaming the objects using command \"short_names\" and trying again.\n" );
247  }
248  return RetValue;
249 }
250 
251 ////////////////////////////////////////////////////////////////////////
252 /// END OF FILE ///
253 ////////////////////////////////////////////////////////////////////////
254 
255 
257 
static Vec_Vec_t * Vec_VecAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecVec.h:145
Nm_Man_t * pManName
Definition: abc.h:160
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static ABC_NAMESPACE_IMPL_START void Io_NtkWriteEqnOne(FILE *pFile, Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteEqn.c:88
static void Io_NtkWriteEqnCos(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:175
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
void Io_WriteEqn(Abc_Ntk_t *pNtk, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteEqn.c:50
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
Definition: hop.h:65
static void Io_NtkWriteEqnCis(FILE *pFile, Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:135
void * pManFunc
Definition: abc.h:191
DECLARATIONS ///.
#define IO_WRITE_LINE_LENGTH
MACRO DEFINITIONS ///.
Definition: ioAbc.h:71
static int Abc_NtkIsAigNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:261
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition: nmApi.c:199
void * pData
Definition: hop.h:68
void Extra_ProgressBarStop(ProgressBar *p)
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition: abc.h:461
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
#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
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition: hop.h:49
char * pName
Definition: abc.h:158
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition: hopOper.c:63
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Hop_ObjPrintEqn(FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
Definition: hopUtil.c:322
static int Io_NtkWriteEqnCheck(Abc_Ntk_t *pNtk)
Definition: ioWriteEqn.c:215