ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteBlifMv.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22#include "base/main/main.h"
23#include "map/mio/mio.h"
24
26
27
31
32static void Io_NtkWriteBlifMv( FILE * pFile, Abc_Ntk_t * pNtk );
33static void Io_NtkWriteBlifMvOne( FILE * pFile, Abc_Ntk_t * pNtk );
34static void Io_NtkWriteBlifMvPis( FILE * pFile, Abc_Ntk_t * pNtk );
35static void Io_NtkWriteBlifMvPos( FILE * pFile, Abc_Ntk_t * pNtk );
36static void Io_NtkWriteBlifMvAsserts( FILE * pFile, Abc_Ntk_t * pNtk );
37static void Io_NtkWriteBlifMvNodeFanins( FILE * pFile, Abc_Obj_t * pNode );
38static void Io_NtkWriteBlifMvNode( FILE * pFile, Abc_Obj_t * pNode );
39static void Io_NtkWriteBlifMvLatch( FILE * pFile, Abc_Obj_t * pLatch );
40static void Io_NtkWriteBlifMvSubckt( FILE * pFile, Abc_Obj_t * pNode );
41static void Io_NtkWriteBlifMvValues( FILE * pFile, Abc_Obj_t * pNode );
42
46
58void Io_WriteBlifMv( Abc_Ntk_t * pNtk, char * FileName )
59{
60 FILE * pFile;
61 Abc_Ntk_t * pNtkTemp;
62 int i;
63 assert( Abc_NtkIsNetlist(pNtk) );
64 assert( Abc_NtkHasBlifMv(pNtk) );
65 // start writing the file
66 pFile = fopen( FileName, "w" );
67 if ( pFile == NULL )
68 {
69 fprintf( stdout, "Io_WriteBlifMv(): Cannot open the output file.\n" );
70 return;
71 }
72 fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
73 // write the master network
74 Io_NtkWriteBlifMv( pFile, pNtk );
75 // write the remaining networks
76 if ( pNtk->pDesign )
77 {
78 Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pNtkTemp, i )
79 {
80 if ( pNtkTemp == pNtk )
81 continue;
82 fprintf( pFile, "\n\n" );
83 Io_NtkWriteBlifMv( pFile, pNtkTemp );
84 }
85 }
86 fclose( pFile );
87}
88
100void Io_NtkWriteBlifMv( FILE * pFile, Abc_Ntk_t * pNtk )
101{
102 assert( Abc_NtkIsNetlist(pNtk) );
103 // write the model name
104 fprintf( pFile, ".model %s\n", Abc_NtkName(pNtk) );
105 // write the network
106 Io_NtkWriteBlifMvOne( pFile, pNtk );
107 // write EXDC network if it exists
108 if ( Abc_NtkExdc(pNtk) )
109 printf( "Io_NtkWriteBlifMv(): EXDC is not written.\n" );
110 // finalize the file
111 fprintf( pFile, ".end\n\n\n" );
112}
113
125void Io_NtkWriteBlifMvOne( FILE * pFile, Abc_Ntk_t * pNtk )
126{
127 ProgressBar * pProgress;
128 Abc_Obj_t * pNode, * pTerm, * pLatch;
129 int i;
130
131 // write the PIs
132 fprintf( pFile, ".inputs" );
133 Io_NtkWriteBlifMvPis( pFile, pNtk );
134 fprintf( pFile, "\n" );
135
136 // write the POs
137 fprintf( pFile, ".outputs" );
138 Io_NtkWriteBlifMvPos( pFile, pNtk );
139 fprintf( pFile, "\n" );
140
141 // write the MV directives
142 fprintf( pFile, "\n" );
143 Abc_NtkForEachCi( pNtk, pTerm, i )
144 if ( Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) > 2 )
145 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanout0(pTerm)) );
146 Abc_NtkForEachCo( pNtk, pTerm, i )
147 if ( Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) > 2 )
148 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanin0(pTerm)), Abc_ObjMvVarNum(Abc_ObjFanin0(pTerm)) );
149
150 // write the blackbox
151 if ( Abc_NtkHasBlackbox( pNtk ) )
152 {
153 fprintf( pFile, ".blackbox\n" );
154 return;
155 }
156
157 // write the timing info
158// Io_WriteTimingInfo( pFile, pNtk );
159
160 // write the latches
161 if ( !Abc_NtkIsComb(pNtk) )
162 {
163 fprintf( pFile, "\n" );
164 Abc_NtkForEachLatch( pNtk, pLatch, i )
165 Io_NtkWriteBlifMvLatch( pFile, pLatch );
166 fprintf( pFile, "\n" );
167 }
168/*
169 // write the subcircuits
170 assert( Abc_NtkWhiteboxNum(pNtk) == 0 );
171 if ( Abc_NtkBlackboxNum(pNtk) > 0 )
172 {
173 fprintf( pFile, "\n" );
174 Abc_NtkForEachBlackbox( pNtk, pNode, i )
175 Io_NtkWriteBlifMvSubckt( pFile, pNode );
176 fprintf( pFile, "\n" );
177 }
178*/
179 if ( Abc_NtkBlackboxNum(pNtk) > 0 || Abc_NtkWhiteboxNum(pNtk) > 0 )
180 {
181 fprintf( pFile, "\n" );
182 Abc_NtkForEachBox( pNtk, pNode, i )
183 {
184 if ( Abc_ObjIsLatch(pNode) )
185 continue;
186 Io_NtkWriteBlifMvSubckt( pFile, pNode );
187 }
188 fprintf( pFile, "\n" );
189 }
190
191 // write each internal node
192 pProgress = Extra_ProgressBarStart( stdout, Abc_NtkObjNumMax(pNtk) );
193 Abc_NtkForEachNode( pNtk, pNode, i )
194 {
195 Extra_ProgressBarUpdate( pProgress, i, NULL );
196 Io_NtkWriteBlifMvNode( pFile, pNode );
197 }
198 Extra_ProgressBarStop( pProgress );
199}
200
201
213void Io_NtkWriteBlifMvPis( FILE * pFile, Abc_Ntk_t * pNtk )
214{
215 Abc_Obj_t * pTerm, * pNet;
216 int LineLength;
217 int AddedLength;
218 int NameCounter;
219 int i;
220
221 LineLength = 7;
222 NameCounter = 0;
223
224 Abc_NtkForEachPi( pNtk, pTerm, i )
225 {
226 pNet = Abc_ObjFanout0(pTerm);
227 // get the line length after this name is written
228 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
229 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
230 { // write the line extender
231 fprintf( pFile, " \\\n" );
232 // reset the line length
233 LineLength = 0;
234 NameCounter = 0;
235 }
236 fprintf( pFile, " %s", Abc_ObjName(pNet) );
237 LineLength += AddedLength;
238 NameCounter++;
239 }
240}
241
253void Io_NtkWriteBlifMvPos( FILE * pFile, Abc_Ntk_t * pNtk )
254{
255 Abc_Obj_t * pTerm, * pNet;
256 int LineLength;
257 int AddedLength;
258 int NameCounter;
259 int i;
260
261 LineLength = 8;
262 NameCounter = 0;
263
264 Abc_NtkForEachPo( pNtk, pTerm, i )
265 {
266 pNet = Abc_ObjFanin0(pTerm);
267 // get the line length after this name is written
268 AddedLength = strlen(Abc_ObjName(pNet)) + 1;
269 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
270 { // write the line extender
271 fprintf( pFile, " \\\n" );
272 // reset the line length
273 LineLength = 0;
274 NameCounter = 0;
275 }
276 fprintf( pFile, " %s", Abc_ObjName(pNet) );
277 LineLength += AddedLength;
278 NameCounter++;
279 }
280}
281
293void Io_NtkWriteBlifMvLatch( FILE * pFile, Abc_Obj_t * pLatch )
294{
295 Abc_Obj_t * pNetLi, * pNetLo;
296 int Reset;
297 pNetLi = Abc_ObjFanin0( Abc_ObjFanin0(pLatch) );
298 pNetLo = Abc_ObjFanout0( Abc_ObjFanout0(pLatch) );
299 Reset = (int)(ABC_PTRUINT_T)Abc_ObjData( pLatch );
300 // write the latch line
301 fprintf( pFile, ".latch" );
302 fprintf( pFile, " %10s", Abc_ObjName(pNetLi) );
303 fprintf( pFile, " %10s", Abc_ObjName(pNetLo) );
304 fprintf( pFile, "\n" );
305 // write the reset node
306 fprintf( pFile, ".reset %s\n", Abc_ObjName(pNetLo) );
307 fprintf( pFile, "%d\n", Reset-1 );
308}
309
321void Io_NtkWriteBlifMvSubckt( FILE * pFile, Abc_Obj_t * pNode )
322{
323 Abc_Ntk_t * pModel = (Abc_Ntk_t *)pNode->pData;
324 Abc_Obj_t * pTerm;
325 int i;
326 // write the MV directives
327 fprintf( pFile, "\n" );
328 Abc_ObjForEachFanin( pNode, pTerm, i )
329 if ( Abc_ObjMvVarNum(pTerm) > 2 )
330 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
331 Abc_ObjForEachFanout( pNode, pTerm, i )
332 if ( Abc_ObjMvVarNum(pTerm) > 2 )
333 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pTerm), Abc_ObjMvVarNum(pTerm) );
334 // write the subcircuit
335 fprintf( pFile, ".subckt %s %s", Abc_NtkName(pModel), Abc_ObjName(pNode) );
336 // write pairs of the formal=actual names
337 Abc_NtkForEachPi( pModel, pTerm, i )
338 {
339 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
340 pTerm = Abc_ObjFanin( pNode, i );
341 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
342 }
343 Abc_NtkForEachPo( pModel, pTerm, i )
344 {
345 fprintf( pFile, " %s", Abc_ObjName(Abc_ObjFanin0(pTerm)) );
346 pTerm = Abc_ObjFanout( pNode, i );
347 fprintf( pFile, "=%s", Abc_ObjName(Abc_ObjFanout0(pTerm)) );
348 }
349 fprintf( pFile, "\n" );
350}
351
352
364void Io_NtkWriteBlifMvNode( FILE * pFile, Abc_Obj_t * pNode )
365{
366 Abc_Obj_t * pFanin;
367 char * pCur;
368 int nValues, iFanin, i;
369
370 // write .mv directives for the fanins
371 fprintf( pFile, "\n" );
372 Abc_ObjForEachFanin( pNode, pFanin, i )
373 {
374// nValues = atoi(pCur);
375 nValues = Abc_ObjMvVarNum( pFanin );
376 if ( nValues > 2 )
377 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(pFanin), nValues );
378// while ( *pCur++ != ' ' );
379 }
380
381 // write .mv directives for the node
382// nValues = atoi(pCur);
383 nValues = Abc_ObjMvVarNum( Abc_ObjFanout0(pNode) );
384 if ( nValues > 2 )
385 fprintf( pFile, ".mv %s %d\n", Abc_ObjName(Abc_ObjFanout0(pNode)), nValues );
386// while ( *pCur++ != '\n' );
387
388 // write the .names line
389 fprintf( pFile, ".table" );
390 Io_NtkWriteBlifMvNodeFanins( pFile, pNode );
391 fprintf( pFile, "\n" );
392
393 // write the cubes
394 pCur = (char *)Abc_ObjData(pNode);
395 if ( *pCur == 'd' )
396 {
397 fprintf( pFile, ".default " );
398 pCur++;
399 }
400 // write the literals
401 for ( ; *pCur; pCur++ )
402 {
403 fprintf( pFile, "%c", *pCur );
404 if ( *pCur != '=' )
405 continue;
406 // get the number
407 iFanin = atoi( pCur+1 );
408 fprintf( pFile, "%s", Abc_ObjName(Abc_ObjFanin(pNode,iFanin)) );
409 // scroll on to the next symbol
410 while ( *pCur != ' ' && *pCur != '\n' )
411 pCur++;
412 pCur--;
413 }
414}
415
427void Io_NtkWriteBlifMvNodeFanins( FILE * pFile, Abc_Obj_t * pNode )
428{
429 Abc_Obj_t * pNet;
430 int LineLength;
431 int AddedLength;
432 int NameCounter;
433 char * pName;
434 int i;
435
436 LineLength = 6;
437 NameCounter = 0;
438 Abc_ObjForEachFanin( pNode, pNet, i )
439 {
440 // get the fanin name
441 pName = Abc_ObjName(pNet);
442 // get the line length after the fanin name is written
443 AddedLength = strlen(pName) + 1;
444 if ( NameCounter && LineLength + AddedLength + 3 > IO_WRITE_LINE_LENGTH )
445 { // write the line extender
446 fprintf( pFile, " \\\n" );
447 // reset the line length
448 LineLength = 0;
449 NameCounter = 0;
450 }
451 fprintf( pFile, " %s", pName );
452 LineLength += AddedLength;
453 NameCounter++;
454 }
455
456 // get the output name
457 pName = Abc_ObjName(Abc_ObjFanout0(pNode));
458 // get the line length after the output name is written
459 AddedLength = strlen(pName) + 1;
460 if ( NameCounter && LineLength + AddedLength > 75 )
461 { // write the line extender
462 fprintf( pFile, " \\\n" );
463 // reset the line length
464 LineLength = 0;
465 NameCounter = 0;
466 }
467 fprintf( pFile, " %s", pName );
468}
469
473
474
476
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition abc.h:520
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition abc.h:500
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
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_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define Abc_NtkForEachBox(pNtk, pObj, i)
Definition abc.h:498
#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 ///.
#define IO_WRITE_LINE_LENGTH
MACRO DEFINITIONS ///.
Definition ioAbc.h:75
void Io_WriteBlifMv(Abc_Ntk_t *pNtk, char *FileName)
FUNCTION DEFINITIONS ///.
Vec_Ptr_t * vModules
Definition abc.h:225
char * pName
Definition abc.h:158
Abc_Des_t * pDesign
Definition abc.h:180
void * pData
Definition abc.h:145
#define assert(ex)
Definition util_old.h:213
int strlen()
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55