ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteEqn.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22
24
25
29
30static void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk );
31static void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk );
32static void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk );
33static int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk );
34
38
50void 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
88char * Io_NamePrepro( char * pName )
89{
90 return strncmp(pName, "new_", 4) ? pName : pName + 4;
91}
92void Io_NtkWriteEqnOne( FILE * pFile, Abc_Ntk_t * pNtk )
93{
94 Vec_Vec_t * vLevels;
95 ProgressBar * pProgress;
96 Abc_Obj_t * pNode, * pFanin;
97 int i, k;
98
99 // write the PIs
100 fprintf( pFile, "INORDER =" );
101 Io_NtkWriteEqnCis( pFile, pNtk );
102 fprintf( pFile, ";\n" );
103
104 // write the POs
105 fprintf( pFile, "OUTORDER =" );
106 Io_NtkWriteEqnCos( pFile, pNtk );
107 fprintf( pFile, ";\n" );
108
109 // write each internal node
110 vLevels = Vec_VecAlloc( 10 );
111 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
112 Abc_NtkForEachNode( pNtk, pNode, i )
113 {
114 Extra_ProgressBarUpdate( pProgress, i, NULL );
115 fprintf( pFile, "%s = ", Io_NamePrepro( Abc_ObjName(Abc_ObjFanout0(pNode)) ) );
116 // set the input names
117 Abc_ObjForEachFanin( pNode, pFanin, k )
118 Hop_IthVar((Hop_Man_t *)pNtk->pManFunc, k)->pData = Io_NamePrepro( Abc_ObjName(pFanin) );
119 // write the formula
120 Hop_ObjPrintEqn( pFile, (Hop_Obj_t *)pNode->pData, vLevels, 0 );
121 fprintf( pFile, ";\n" );
122 }
123 Extra_ProgressBarStop( pProgress );
124 Vec_VecFree( vLevels );
125}
126
127
139void Io_NtkWriteEqnCis( FILE * pFile, Abc_Ntk_t * pNtk )
140{
141 Abc_Obj_t * pTerm, * pNet;
142 int LineLength;
143 int AddedLength;
144 int NameCounter;
145 int i;
146
147 LineLength = 9;
148 NameCounter = 0;
149
150 Abc_NtkForEachCi( pNtk, pTerm, i )
151 {
152 pNet = Abc_ObjFanout0(pTerm);
153 // get the line length after this name is written
154 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
155 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
156 { // write the line extender
157 fprintf( pFile, " \n" );
158 // reset the line length
159 LineLength = 0;
160 NameCounter = 0;
161 }
162 fprintf( pFile, " %s", Abc_ObjName(pNet) );
163 LineLength += AddedLength;
164 NameCounter++;
165 }
166}
167
179void Io_NtkWriteEqnCos( FILE * pFile, Abc_Ntk_t * pNtk )
180{
181 Abc_Obj_t * pTerm, * pNet;
182 int LineLength;
183 int AddedLength;
184 int NameCounter;
185 int i;
186
187 LineLength = 10;
188 NameCounter = 0;
189
190 Abc_NtkForEachCo( pNtk, pTerm, i )
191 {
192 pNet = Abc_ObjFanin0(pTerm);
193 // get the line length after this name is written
194 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
195 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
196 { // write the line extender
197 fprintf( pFile, " \n" );
198 // reset the line length
199 LineLength = 0;
200 NameCounter = 0;
201 }
202 fprintf( pFile, " %s", Abc_ObjName(pNet) );
203 LineLength += AddedLength;
204 NameCounter++;
205 }
206}
207
219int Io_NtkWriteEqnCheck( Abc_Ntk_t * pNtk )
220{
221 Abc_Obj_t * pObj;
222 char * pName = NULL;
223 int i, k, Length;
224 int RetValue = 1;
225
226 // make sure the network does not have proper names, such as "0" or "1" or containing parentheses
227 Abc_NtkForEachObj( pNtk, pObj, i )
228 {
229 pName = Nm_ManFindNameById(pNtk->pManName, i);
230 if ( pName == NULL )
231 continue;
232 Length = strlen(pName);
233 if ( pName[0] == '0' || pName[0] == '1' )
234 {
235 RetValue = 0;
236 break;
237 }
238 for ( k = 0; k < Length; k++ )
239 if ( pName[k] == '(' || pName[k] == ')' || pName[k] == '!' || pName[k] == '*' || pName[k] == '+' )
240 {
241 RetValue = 0;
242 break;
243 }
244 if ( k < Length )
245 break;
246 }
247 if ( RetValue == 0 )
248 {
249 printf( "The network cannot be written in the EQN format because object %d has name \"%s\".\n", i, pName );
250 printf( "Consider renaming the objects using command \"short_names\" and trying again.\n" );
251 }
252 return RetValue;
253}
254
258
259
261
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
void Extra_ProgressBarStop(ProgressBar *p)
char * Extra_TimeStamp()
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
Hop_Obj_t * Hop_IthVar(Hop_Man_t *p, int i)
FUNCTION DEFINITIONS ///.
Definition hopOper.c:63
void Hop_ObjPrintEqn(FILE *pFile, Hop_Obj_t *pObj, Vec_Vec_t *vLevels, int Level)
Definition hopUtil.c:322
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
#define IO_WRITE_LINE_LENGTH
MACRO DEFINITIONS ///.
Definition ioAbc.h:75
char * Io_NamePrepro(char *pName)
Definition ioWriteEqn.c:88
void Io_WriteEqn(Abc_Ntk_t *pNtk, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition ioWriteEqn.c:50
char * Nm_ManFindNameById(Nm_Man_t *p, int ObjId)
Definition nmApi.c:199
char * pName
Definition abc.h:158
void * pManFunc
Definition abc.h:191
Nm_Man_t * pManName
Definition abc.h:160
void * pData
Definition abc.h:145
void * pData
Definition hop.h:68
#define assert(ex)
Definition util_old.h:213
int strncmp()
int strlen()
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition vecVec.h:42