abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioUtil.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioUtil.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to write the network in BENCH format.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 #include "base/main/main.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 ////////////////////////////////////////////////////////////////////////
32 /// FUNCTION DEFINITIONS ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 /**Function*************************************************************
36 
37  Synopsis [Returns the file type.]
38 
39  Description []
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
46 Io_FileType_t Io_ReadFileType( char * pFileName )
47 {
48  char * pExt;
49  if ( pFileName == NULL )
50  return IO_FILE_NONE;
51  pExt = Extra_FileNameExtension( pFileName );
52  if ( pExt == NULL )
53  return IO_FILE_NONE;
54  if ( !strcmp( pExt, "aig" ) )
55  return IO_FILE_AIGER;
56  if ( !strcmp( pExt, "baf" ) )
57  return IO_FILE_BAF;
58  if ( !strcmp( pExt, "bblif" ) )
59  return IO_FILE_BBLIF;
60  if ( !strcmp( pExt, "blif" ) )
61  return IO_FILE_BLIF;
62  if ( !strcmp( pExt, "bench" ) )
63  return IO_FILE_BENCH;
64  if ( !strcmp( pExt, "cnf" ) )
65  return IO_FILE_CNF;
66  if ( !strcmp( pExt, "dot" ) )
67  return IO_FILE_DOT;
68  if ( !strcmp( pExt, "edif" ) )
69  return IO_FILE_EDIF;
70  if ( !strcmp( pExt, "eqn" ) )
71  return IO_FILE_EQN;
72  if ( !strcmp( pExt, "gml" ) )
73  return IO_FILE_GML;
74  if ( !strcmp( pExt, "list" ) )
75  return IO_FILE_LIST;
76  if ( !strcmp( pExt, "mv" ) )
77  return IO_FILE_BLIFMV;
78  if ( !strcmp( pExt, "pla" ) )
79  return IO_FILE_PLA;
80  if ( !strcmp( pExt, "smv" ) )
81  return IO_FILE_SMV;
82  if ( !strcmp( pExt, "v" ) )
83  return IO_FILE_VERILOG;
84  return IO_FILE_UNKNOWN;
85 }
86 
87 /**Function*************************************************************
88 
89  Synopsis [Read the network from a file.]
90 
91  Description []
92 
93  SideEffects []
94 
95  SeeAlso []
96 
97 ***********************************************************************/
98 Abc_Ntk_t * Io_ReadNetlist( char * pFileName, Io_FileType_t FileType, int fCheck )
99 {
100  FILE * pFile;
101  Abc_Ntk_t * pNtk;
102  if ( FileType == IO_FILE_NONE || FileType == IO_FILE_UNKNOWN )
103  {
104  fprintf( stdout, "Generic file reader requires a known file extension to open \"%s\".\n", pFileName );
105  return NULL;
106  }
107  // check if the file exists
108  pFile = fopen( pFileName, "r" );
109  if ( pFile == NULL )
110  {
111  fprintf( stdout, "Cannot open input file \"%s\". ", pFileName );
112  if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".blif", ".bench", ".pla", ".baf", ".aig" )) )
113  fprintf( stdout, "Did you mean \"%s\"?", pFileName );
114  fprintf( stdout, "\n" );
115  return NULL;
116  }
117  fclose( pFile );
118  // read the AIG
119  if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF || FileType == IO_FILE_BBLIF )
120  {
121  if ( FileType == IO_FILE_AIGER )
122  pNtk = Io_ReadAiger( pFileName, fCheck );
123  else if ( FileType == IO_FILE_BAF )
124  pNtk = Io_ReadBaf( pFileName, fCheck );
125  else // if ( FileType == IO_FILE_BBLIF )
126  pNtk = Io_ReadBblif( pFileName, fCheck );
127  if ( pNtk == NULL )
128  {
129  fprintf( stdout, "Reading AIG from file has failed.\n" );
130  return NULL;
131  }
132  return pNtk;
133  }
134  // read the new netlist
135  if ( FileType == IO_FILE_BLIF )
136 // pNtk = Io_ReadBlif( pFileName, fCheck );
137  pNtk = Io_ReadBlifMv( pFileName, 0, fCheck );
138  else if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV )
139  pNtk = Io_ReadBlifMv( pFileName, 1, fCheck );
140  else if ( FileType == IO_FILE_BENCH )
141  pNtk = Io_ReadBench( pFileName, fCheck );
142  else if ( FileType == IO_FILE_EDIF )
143  pNtk = Io_ReadEdif( pFileName, fCheck );
144  else if ( FileType == IO_FILE_EQN )
145  pNtk = Io_ReadEqn( pFileName, fCheck );
146  else if ( FileType == IO_FILE_PLA )
147  pNtk = Io_ReadPla( pFileName, 0, fCheck );
148  else if ( FileType == IO_FILE_VERILOG )
149  pNtk = Io_ReadVerilog( pFileName, fCheck );
150  else
151  {
152  fprintf( stderr, "Unknown file format.\n" );
153  return NULL;
154  }
155  if ( pNtk == NULL )
156  {
157  fprintf( stdout, "Reading network from file has failed.\n" );
158  return NULL;
159  }
160  if ( fCheck && (Abc_NtkBlackboxNum(pNtk) || Abc_NtkWhiteboxNum(pNtk)) )
161  {
162  int i, fCycle = 0;
163  Abc_Ntk_t * pModel;
164  fprintf( stdout, "Warning: The network contains hierarchy.\n" );
165  Vec_PtrForEachEntry( Abc_Ntk_t *, pNtk->pDesign->vModules, pModel, i )
166  if ( !Abc_NtkIsAcyclicWithBoxes( pModel ) )
167  fCycle = 1;
168  if ( fCycle )
169  {
170  Abc_NtkDelete( pNtk );
171  return NULL;
172  }
173  }
174  return pNtk;
175 }
176 
177 /**Function*************************************************************
178 
179  Synopsis []
180 
181  Description []
182 
183  SideEffects []
184 
185  SeeAlso []
186 
187 ***********************************************************************/
189 {
190  Vec_Ptr_t *tempStore;
191  char *pFormula;
192  int i;
193 
194  if( pNtk && Vec_PtrSize( pNtk->vLtlProperties ) > 0 )
195  {
196  tempStore = Vec_PtrAlloc( Vec_PtrSize( pNtk->vLtlProperties ) );
197  Vec_PtrForEachEntry( char *, pNtk->vLtlProperties, pFormula, i )
198  Vec_PtrPush( tempStore, pFormula );
199  assert( Vec_PtrSize( tempStore ) == Vec_PtrSize( pNtk->vLtlProperties ) );
200  return tempStore;
201  }
202  else
203  return NULL;
204 }
205 
206 /**Function*************************************************************
207 
208  Synopsis []
209 
210  Description []
211 
212  SideEffects []
213 
214  SeeAlso []
215 
216 ***********************************************************************/
217 void updateLtlStoreOfNtk( Abc_Ntk_t *pNtk, Vec_Ptr_t *tempLtlStore )
218 {
219  int i;
220  char *pFormula;
221 
222  assert( tempLtlStore != NULL );
223  Vec_PtrForEachEntry( char *, tempLtlStore, pFormula, i )
224  Vec_PtrPush( pNtk->vLtlProperties, pFormula );
225 }
226 
227 /**Function*************************************************************
228 
229  Synopsis [Read the network from a file.]
230 
231  Description []
232 
233  SideEffects []
234 
235  SeeAlso []
236 
237 ***********************************************************************/
238 Abc_Ntk_t * Io_Read( char * pFileName, Io_FileType_t FileType, int fCheck, int fBarBufs )
239 {
240  Abc_Ntk_t * pNtk, * pTemp;
241  Vec_Ptr_t * vLtl;
242  // get the netlist
243  pNtk = Io_ReadNetlist( pFileName, FileType, fCheck );
244  if ( pNtk == NULL )
245  return NULL;
246  vLtl = temporaryLtlStore( pNtk );
247  if ( !Abc_NtkIsNetlist(pNtk) )
248  return pNtk;
249  // derive barbufs
250  if ( fBarBufs )
251  {
252  pNtk = Abc_NtkToBarBufs( pTemp = pNtk );
253  Abc_NtkDelete( pTemp );
254  assert( Abc_NtkIsLogic(pNtk) );
255  return pNtk;
256  }
257  // flatten logic hierarchy
258  assert( Abc_NtkIsNetlist(pNtk) );
259  if ( Abc_NtkWhiteboxNum(pNtk) > 0 )
260  {
261  pNtk = Abc_NtkFlattenLogicHierarchy( pTemp = pNtk );
262  Abc_NtkDelete( pTemp );
263  if ( pNtk == NULL )
264  {
265  fprintf( stdout, "Flattening logic hierarchy has failed.\n" );
266  return NULL;
267  }
268  }
269  // convert blackboxes
270  if ( Abc_NtkBlackboxNum(pNtk) > 0 )
271  {
272  printf( "Hierarchy reader converted %d instances of blackboxes.\n", Abc_NtkBlackboxNum(pNtk) );
273  pNtk = Abc_NtkConvertBlackboxes( pTemp = pNtk );
274  Abc_NtkDelete( pTemp );
275  if ( pNtk == NULL )
276  {
277  fprintf( stdout, "Converting blackboxes has failed.\n" );
278  return NULL;
279  }
280  }
281  // consider the case of BLIF-MV
282  if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV )
283  {
284  pNtk = Abc_NtkStrashBlifMv( pTemp = pNtk );
285  Abc_NtkDelete( pTemp );
286  if ( pNtk == NULL )
287  {
288  fprintf( stdout, "Converting BLIF-MV to AIG has failed.\n" );
289  return NULL;
290  }
291  return pNtk;
292  }
293  // convert the netlist into the logic network
294  pNtk = Abc_NtkToLogic( pTemp = pNtk );
295  if( vLtl )
296  updateLtlStoreOfNtk( pNtk, vLtl );
297  Abc_NtkDelete( pTemp );
298  if ( pNtk == NULL )
299  {
300  fprintf( stdout, "Converting netlist to logic network after reading has failed.\n" );
301  return NULL;
302  }
303  return pNtk;
304 }
305 
306 /**Function*************************************************************
307 
308  Synopsis [Write the network into file.]
309 
310  Description []
311 
312  SideEffects []
313 
314  SeeAlso []
315 
316 ***********************************************************************/
317 void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType )
318 {
319  Abc_Ntk_t * pNtkTemp, * pNtkCopy;
320  // check if the current network is available
321  if ( pNtk == NULL )
322  {
323  fprintf( stdout, "Empty network.\n" );
324  return;
325  }
326  // check if the file extension if given
327  if ( FileType == IO_FILE_NONE || FileType == IO_FILE_UNKNOWN )
328  {
329  fprintf( stdout, "The generic file writer requires a known file extension.\n" );
330  return;
331  }
332  // write the AIG formats
333  if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF )
334  {
335  if ( !Abc_NtkIsStrash(pNtk) )
336  {
337  fprintf( stdout, "Writing this format is only possible for structurally hashed AIGs.\n" );
338  return;
339  }
340  if ( FileType == IO_FILE_AIGER )
341  Io_WriteAiger( pNtk, pFileName, 1, 0, 0 );
342  else //if ( FileType == IO_FILE_BAF )
343  Io_WriteBaf( pNtk, pFileName );
344  return;
345  }
346  // write non-netlist types
347  if ( FileType == IO_FILE_CNF )
348  {
349  Io_WriteCnf( pNtk, pFileName, 0 );
350  return;
351  }
352  if ( FileType == IO_FILE_DOT )
353  {
354  Io_WriteDot( pNtk, pFileName );
355  return;
356  }
357  if ( FileType == IO_FILE_GML )
358  {
359  Io_WriteGml( pNtk, pFileName );
360  return;
361  }
362  if ( FileType == IO_FILE_BBLIF )
363  {
364  if ( !Abc_NtkIsLogic(pNtk) )
365  {
366  fprintf( stdout, "Writing Binary BLIF is only possible for logic networks.\n" );
367  return;
368  }
369  if ( !Abc_NtkHasSop(pNtk) )
370  Abc_NtkToSop( pNtk, 0 );
371  Io_WriteBblif( pNtk, pFileName );
372  return;
373  }
374 /*
375  if ( FileType == IO_FILE_BLIFMV )
376  {
377  Io_WriteBlifMv( pNtk, pFileName );
378  return;
379  }
380 */
381  // convert logic network into netlist
382  if ( FileType == IO_FILE_PLA )
383  {
384  if ( Abc_NtkLevel(pNtk) > 1 )
385  {
386  fprintf( stdout, "PLA writing is available for collapsed networks.\n" );
387  return;
388  }
389  if ( Abc_NtkIsComb(pNtk) )
390  pNtkTemp = Abc_NtkToNetlist( pNtk );
391  else
392  {
393  fprintf( stdout, "Latches are writen into the PLA file at PI/PO pairs.\n" );
394  pNtkCopy = Abc_NtkDup( pNtk );
395  Abc_NtkMakeComb( pNtkCopy, 0 );
396  pNtkTemp = Abc_NtkToNetlist( pNtk );
397  Abc_NtkDelete( pNtkCopy );
398  }
399  if ( !Abc_NtkToSop( pNtkTemp, 1 ) )
400  return;
401  }
402  else if ( FileType == IO_FILE_BENCH )
403  {
404  if ( !Abc_NtkIsStrash(pNtk) )
405  {
406  fprintf( stdout, "Writing traditional BENCH is available for AIGs only (use \"write_bench\").\n" );
407  return;
408  }
409  pNtkTemp = Abc_NtkToNetlistBench( pNtk );
410  }
411  else if ( FileType == IO_FILE_SMV )
412  {
413  if ( !Abc_NtkIsStrash(pNtk) )
414  {
415  fprintf( stdout, "Writing traditional SMV is available for AIGs only.\n" );
416  return;
417  }
418  pNtkTemp = Abc_NtkToNetlistBench( pNtk );
419  }
420  else
421  pNtkTemp = Abc_NtkToNetlist( pNtk );
422 
423  if ( pNtkTemp == NULL )
424  {
425  fprintf( stdout, "Converting to netlist has failed.\n" );
426  return;
427  }
428 
429  if ( FileType == IO_FILE_BLIF )
430  {
431  if ( !Abc_NtkHasSop(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) )
432  Abc_NtkToSop( pNtkTemp, 0 );
433  Io_WriteBlif( pNtkTemp, pFileName, 1, 0, 0 );
434  }
435  else if ( FileType == IO_FILE_BLIFMV )
436  {
437  if ( !Abc_NtkConvertToBlifMv( pNtkTemp ) )
438  return;
439  Io_WriteBlifMv( pNtkTemp, pFileName );
440  }
441  else if ( FileType == IO_FILE_BENCH )
442  Io_WriteBench( pNtkTemp, pFileName );
443  else if ( FileType == IO_FILE_BOOK )
444  Io_WriteBook( pNtkTemp, pFileName );
445  else if ( FileType == IO_FILE_PLA )
446  Io_WritePla( pNtkTemp, pFileName );
447  else if ( FileType == IO_FILE_EQN )
448  {
449  if ( !Abc_NtkHasAig(pNtkTemp) )
450  Abc_NtkToAig( pNtkTemp );
451  Io_WriteEqn( pNtkTemp, pFileName );
452  }
453  else if ( FileType == IO_FILE_SMV )
454  Io_WriteSmv( pNtkTemp, pFileName );
455  else if ( FileType == IO_FILE_VERILOG )
456  {
457  if ( !Abc_NtkHasAig(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) )
458  Abc_NtkToAig( pNtkTemp );
459  Io_WriteVerilog( pNtkTemp, pFileName );
460  }
461  else
462  fprintf( stderr, "Unknown file format.\n" );
463  Abc_NtkDelete( pNtkTemp );
464 }
465 
466 /**Function*************************************************************
467 
468  Synopsis [Write the network into file.]
469 
470  Description []
471 
472  SideEffects []
473 
474  SeeAlso []
475 
476 ***********************************************************************/
477 void Io_WriteHie( Abc_Ntk_t * pNtk, char * pBaseName, char * pFileName )
478 {
479  Abc_Ntk_t * pNtkTemp, * pNtkResult, * pNtkBase = NULL;
480  int i;
481  // check if the current network is available
482  if ( pNtk == NULL )
483  {
484  fprintf( stdout, "Empty network.\n" );
485  return;
486  }
487 
488  // read the base network
489  assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsLogic(pNtk) );
490  if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIF )
491  pNtkBase = Io_ReadBlifMv( pBaseName, 0, 1 );
492  else if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIFMV )
493  pNtkBase = Io_ReadBlifMv( pBaseName, 1, 1 );
494  else if ( Io_ReadFileType(pBaseName) == IO_FILE_VERILOG )
495  pNtkBase = Io_ReadVerilog( pBaseName, 1 );
496  else
497  fprintf( stderr, "Unknown input file format.\n" );
498  if ( pNtkBase == NULL )
499  return;
500 
501  // flatten logic hierarchy if present
502  if ( Abc_NtkWhiteboxNum(pNtkBase) > 0 && pNtk->nBarBufs == 0 )
503  {
504  pNtkBase = Abc_NtkFlattenLogicHierarchy( pNtkTemp = pNtkBase );
505  Abc_NtkDelete( pNtkTemp );
506  if ( pNtkBase == NULL )
507  return;
508  }
509 
510  // reintroduce the boxes into the netlist
511  if ( pNtk->nBarBufs > 0 )
512  {
513  // derive the netlist
514  pNtkResult = Abc_NtkToNetlist( pNtk );
515  pNtkResult = Abc_NtkFromBarBufs( pNtkBase, pNtkTemp = pNtkResult );
516  Abc_NtkDelete( pNtkTemp );
517  if ( pNtkResult )
518  printf( "Hierarchy writer replaced %d barbufs by hierarchy boundaries.\n", pNtk->nBarBufs );
519  }
520  else if ( Io_ReadFileType(pBaseName) == IO_FILE_BLIFMV )
521  {
522  if ( Abc_NtkBlackboxNum(pNtkBase) > 0 )
523  {
524  printf( "Hierarchy writer does not support BLIF-MV with blackboxes.\n" );
525  Abc_NtkDelete( pNtkBase );
526  return;
527  }
528  // convert the current network to BLIF-MV
529  assert( !Abc_NtkIsNetlist(pNtk) );
530  pNtkResult = Abc_NtkToNetlist( pNtk );
531  if ( !Abc_NtkConvertToBlifMv( pNtkResult ) )
532  {
533  Abc_NtkDelete( pNtkBase );
534  return;
535  }
536  // reintroduce the network
537  pNtkResult = Abc_NtkInsertBlifMv( pNtkBase, pNtkTemp = pNtkResult );
538  Abc_NtkDelete( pNtkTemp );
539  }
540  else if ( Abc_NtkBlackboxNum(pNtkBase) > 0 )
541  {
542  // derive the netlist
543  pNtkResult = Abc_NtkToNetlist( pNtk );
544  pNtkResult = Abc_NtkInsertNewLogic( pNtkBase, pNtkTemp = pNtkResult );
545  Abc_NtkDelete( pNtkTemp );
546  if ( pNtkResult )
547  printf( "Hierarchy writer reintroduced %d instances of blackboxes.\n", Abc_NtkBlackboxNum(pNtkBase) );
548  }
549  else
550  {
551  printf( "Warning: The output network does not contain blackboxes.\n" );
552  pNtkResult = Abc_NtkToNetlist( pNtk );
553  }
554  Abc_NtkDelete( pNtkBase );
555  if ( pNtkResult == NULL )
556  return;
557 
558  // write the resulting network
559  if ( Io_ReadFileType(pFileName) == IO_FILE_BLIF )
560  {
561  if ( pNtkResult->pDesign )
562  {
563  Vec_PtrForEachEntry( Abc_Ntk_t *, pNtkResult->pDesign->vModules, pNtkTemp, i )
564  if ( !Abc_NtkHasSop(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) )
565  Abc_NtkToSop( pNtkTemp, 0 );
566  }
567  else
568  {
569  if ( !Abc_NtkHasSop(pNtkResult) && !Abc_NtkHasMapping(pNtkResult) )
570  Abc_NtkToSop( pNtkResult, 0 );
571  }
572  Io_WriteBlif( pNtkResult, pFileName, 1, 0, 0 );
573  }
574  else if ( Io_ReadFileType(pFileName) == IO_FILE_VERILOG )
575  {
576  if ( pNtkResult->pDesign )
577  {
578  Vec_PtrForEachEntry( Abc_Ntk_t *, pNtkResult->pDesign->vModules, pNtkTemp, i )
579  if ( !Abc_NtkHasAig(pNtkTemp) && !Abc_NtkHasMapping(pNtkTemp) )
580  Abc_NtkToAig( pNtkTemp );
581  }
582  else
583  {
584  if ( !Abc_NtkHasAig(pNtkResult) && !Abc_NtkHasMapping(pNtkResult) )
585  Abc_NtkToAig( pNtkResult );
586  }
587  Io_WriteVerilog( pNtkResult, pFileName );
588  }
589  else if ( Io_ReadFileType(pFileName) == IO_FILE_BLIFMV )
590  {
591  Io_WriteBlifMv( pNtkResult, pFileName );
592  }
593  else
594  fprintf( stderr, "Unknown output file format.\n" );
595 
596  Abc_NtkDelete( pNtkResult );
597 }
598 
599 /**Function*************************************************************
600 
601  Synopsis [Creates PI terminal and net.]
602 
603  Description []
604 
605  SideEffects []
606 
607  SeeAlso []
608 
609 ***********************************************************************/
610 Abc_Obj_t * Io_ReadCreatePi( Abc_Ntk_t * pNtk, char * pName )
611 {
612  Abc_Obj_t * pNet, * pTerm;
613  // get the PI net
614  pNet = Abc_NtkFindNet( pNtk, pName );
615  if ( pNet )
616  printf( "Warning: PI \"%s\" appears twice in the list.\n", pName );
617  pNet = Abc_NtkFindOrCreateNet( pNtk, pName );
618  // add the PI node
619  pTerm = Abc_NtkCreatePi( pNtk );
620  Abc_ObjAddFanin( pNet, pTerm );
621  return pTerm;
622 }
623 
624 /**Function*************************************************************
625 
626  Synopsis [Creates PO terminal and net.]
627 
628  Description []
629 
630  SideEffects []
631 
632  SeeAlso []
633 
634 ***********************************************************************/
635 Abc_Obj_t * Io_ReadCreatePo( Abc_Ntk_t * pNtk, char * pName )
636 {
637  Abc_Obj_t * pNet, * pTerm;
638  // get the PO net
639  pNet = Abc_NtkFindNet( pNtk, pName );
640  if ( pNet && Abc_ObjFaninNum(pNet) == 0 )
641  printf( "Warning: PO \"%s\" appears twice in the list.\n", pName );
642  pNet = Abc_NtkFindOrCreateNet( pNtk, pName );
643  // add the PO node
644  pTerm = Abc_NtkCreatePo( pNtk );
645  Abc_ObjAddFanin( pTerm, pNet );
646  return pTerm;
647 }
648 
649 /**Function*************************************************************
650 
651  Synopsis [Create a latch with the given input/output.]
652 
653  Description [By default, the latch value is unknown (ABC_INIT_NONE).]
654 
655  SideEffects []
656 
657  SeeAlso []
658 
659 ***********************************************************************/
660 Abc_Obj_t * Io_ReadCreateLatch( Abc_Ntk_t * pNtk, char * pNetLI, char * pNetLO )
661 {
662  Abc_Obj_t * pLatch, * pTerm, * pNet;
663  // get the LI net
664  pNet = Abc_NtkFindOrCreateNet( pNtk, pNetLI );
665  // add the BO terminal
666  pTerm = Abc_NtkCreateBi( pNtk );
667  Abc_ObjAddFanin( pTerm, pNet );
668  // add the latch box
669  pLatch = Abc_NtkCreateLatch( pNtk );
670  Abc_ObjAddFanin( pLatch, pTerm );
671  // add the BI terminal
672  pTerm = Abc_NtkCreateBo( pNtk );
673  Abc_ObjAddFanin( pTerm, pLatch );
674  // get the LO net
675  pNet = Abc_NtkFindOrCreateNet( pNtk, pNetLO );
676  Abc_ObjAddFanin( pNet, pTerm );
677  // set latch name
678  Abc_ObjAssignName( pLatch, pNetLO, "L" );
679  return pLatch;
680 }
681 
682 /**Function*************************************************************
683 
684  Synopsis [Create the reset latch with data=1 and init=0.]
685 
686  Description []
687 
688  SideEffects []
689 
690  SeeAlso []
691 
692 ***********************************************************************/
694 {
695  Abc_Obj_t * pLatch, * pNode;
696  Abc_Obj_t * pNetLI, * pNetLO;
697  // create latch with 0 init value
698 // pLatch = Io_ReadCreateLatch( pNtk, "_resetLI_", "_resetLO_" );
699  pNetLI = Abc_NtkCreateNet( pNtk );
700  pNetLO = Abc_NtkCreateNet( pNtk );
701  Abc_ObjAssignName( pNetLI, Abc_ObjName(pNetLI), NULL );
702  Abc_ObjAssignName( pNetLO, Abc_ObjName(pNetLO), NULL );
703  pLatch = Io_ReadCreateLatch( pNtk, Abc_ObjName(pNetLI), Abc_ObjName(pNetLO) );
704  // set the initial value
705  Abc_LatchSetInit0( pLatch );
706  // feed the latch with constant1- node
707 // pNode = Abc_NtkCreateNode( pNtk );
708 // pNode->pData = Abc_SopRegister( (Extra_MmFlex_t *)pNtk->pManFunc, "2\n1\n" );
709  pNode = Abc_NtkCreateNodeConst1( pNtk );
710  Abc_ObjAddFanin( Abc_ObjFanin0(Abc_ObjFanin0(pLatch)), pNode );
711  return pLatch;
712 }
713 
714 /**Function*************************************************************
715 
716  Synopsis [Create node and the net driven by it.]
717 
718  Description []
719 
720  SideEffects []
721 
722  SeeAlso []
723 
724 ***********************************************************************/
725 Abc_Obj_t * Io_ReadCreateNode( Abc_Ntk_t * pNtk, char * pNameOut, char * pNamesIn[], int nInputs )
726 {
727  Abc_Obj_t * pNet, * pNode;
728  int i;
729  // create a new node
730  pNode = Abc_NtkCreateNode( pNtk );
731  // add the fanin nets
732  for ( i = 0; i < nInputs; i++ )
733  {
734  pNet = Abc_NtkFindOrCreateNet( pNtk, pNamesIn[i] );
735  Abc_ObjAddFanin( pNode, pNet );
736  }
737  // add the fanout net
738  pNet = Abc_NtkFindOrCreateNet( pNtk, pNameOut );
739  Abc_ObjAddFanin( pNet, pNode );
740  return pNode;
741 }
742 
743 /**Function*************************************************************
744 
745  Synopsis [Create a constant 0 node driving the net with this name.]
746 
747  Description [Assumes that the net already exists.]
748 
749  SideEffects []
750 
751  SeeAlso []
752 
753 ***********************************************************************/
754 Abc_Obj_t * Io_ReadCreateConst( Abc_Ntk_t * pNtk, char * pName, int fConst1 )
755 {
756  Abc_Obj_t * pNet, * pTerm;
757  pTerm = fConst1? Abc_NtkCreateNodeConst1(pNtk) : Abc_NtkCreateNodeConst0(pNtk);
758  pNet = Abc_NtkFindNet(pNtk, pName); assert( pNet );
759  Abc_ObjAddFanin( pNet, pTerm );
760  return pTerm;
761 }
762 
763 /**Function*************************************************************
764 
765  Synopsis [Create an inverter or buffer for the given net.]
766 
767  Description [Assumes that the nets already exist.]
768 
769  SideEffects []
770 
771  SeeAlso []
772 
773 ***********************************************************************/
774 Abc_Obj_t * Io_ReadCreateInv( Abc_Ntk_t * pNtk, char * pNameIn, char * pNameOut )
775 {
776  Abc_Obj_t * pNet, * pNode;
777  pNet = Abc_NtkFindNet(pNtk, pNameIn); assert( pNet );
778  pNode = Abc_NtkCreateNodeInv(pNtk, pNet);
779  pNet = Abc_NtkFindNet(pNtk, pNameOut); assert( pNet );
780  Abc_ObjAddFanin( pNet, pNode );
781  return pNode;
782 }
783 
784 /**Function*************************************************************
785 
786  Synopsis [Create an inverter or buffer for the given net.]
787 
788  Description [Assumes that the nets already exist.]
789 
790  SideEffects []
791 
792  SeeAlso []
793 
794 ***********************************************************************/
795 Abc_Obj_t * Io_ReadCreateBuf( Abc_Ntk_t * pNtk, char * pNameIn, char * pNameOut )
796 {
797  Abc_Obj_t * pNet, * pNode;
798  pNet = Abc_NtkFindNet(pNtk, pNameIn); assert( pNet );
799  pNode = Abc_NtkCreateNodeBuf(pNtk, pNet);
800  pNet = Abc_NtkFindNet(pNtk, pNameOut); assert( pNet );
801  Abc_ObjAddFanin( pNet, pNode );
802  return pNet;
803 }
804 
805 
806 /**Function*************************************************************
807 
808  Synopsis [Provide an fopen replacement with path lookup]
809 
810  Description [Provide an fopen replacement where the path stored
811  in pathvar MVSIS variable is used to look up the path
812  for name. Returns NULL if file cannot be opened.]
813 
814  SideEffects []
815 
816  SeeAlso []
817 
818 ***********************************************************************/
819 FILE * Io_FileOpen( const char * FileName, const char * PathVar, const char * Mode, int fVerbose )
820 {
821  char * t = 0, * c = 0, * i;
822 
823  if ( PathVar == 0 )
824  {
825  return fopen( FileName, Mode );
826  }
827  else
828  {
829  if ( (c = Abc_FrameReadFlag( (char*)PathVar )) )
830  {
831  char ActualFileName[4096];
832  FILE * fp = 0;
833  t = Extra_UtilStrsav( c );
834  for (i = strtok( t, ":" ); i != 0; i = strtok( 0, ":") )
835  {
836 #ifdef WIN32
837  _snprintf ( ActualFileName, 4096, "%s/%s", i, FileName );
838 #else
839  snprintf ( ActualFileName, 4096, "%s/%s", i, FileName );
840 #endif
841  if ( ( fp = fopen ( ActualFileName, Mode ) ) )
842  {
843  if ( fVerbose )
844  fprintf ( stdout, "Using file %s\n", ActualFileName );
845  ABC_FREE( t );
846  return fp;
847  }
848  }
849  ABC_FREE( t );
850  return 0;
851  }
852  else
853  {
854  return fopen( FileName, Mode );
855  }
856  }
857 }
858 
859 ////////////////////////////////////////////////////////////////////////
860 /// END OF FILE ///
861 ////////////////////////////////////////////////////////////////////////
862 
863 
865 
Abc_Ntk_t * Io_ReadAiger(char *pFileName, int fCheck)
FUNCTION DECLARATIONS ///.
Definition: ioReadAiger.c:234
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
Abc_Ntk_t * Io_ReadBlifMv(char *pFileName, int fBlifMv, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadBlifMv.c:142
void Io_WriteEqn(Abc_Ntk_t *pNtk, char *pFileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteEqn.c:50
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
Vec_Ptr_t * vLtlProperties
Definition: abc.h:169
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Abc_Obj_t * Io_ReadCreateBuf(Abc_Ntk_t *pNtk, char *pNameIn, char *pNameOut)
Definition: ioUtil.c:795
static int Abc_NtkIsComb(Abc_Ntk_t *pNtk)
Definition: abc.h:297
ABC_DLL void Abc_NtkMakeComb(Abc_Ntk_t *pNtk, int fRemoveLatches)
Definition: abcNtk.c:1422
Abc_Ntk_t * Io_ReadBblif(char *pFileName, int fCheck)
Definition: ioReadBblif.c:324
Abc_Ntk_t * Io_Read(char *pFileName, Io_FileType_t FileType, int fCheck, int fBarBufs)
Definition: ioUtil.c:238
static int Abc_NtkHasSop(Abc_Ntk_t *pNtk)
Definition: abc.h:253
Vec_Ptr_t * temporaryLtlStore(Abc_Ntk_t *pNtk)
Definition: ioUtil.c:188
Io_FileType_t
INCLUDES ///.
Definition: ioAbc.h:46
static int Abc_NtkIsNetlist(Abc_Ntk_t *pNtk)
Definition: abc.h:249
void Io_WriteVerilog(Abc_Ntk_t *pNtk, char *FileName)
FUNCTION DEFINITIONS ///.
char * Extra_FileGetSimilarName(char *pFileNameWrong, char *pS1, char *pS2, char *pS3, char *pS4, char *pS5)
Definition: extraUtilFile.c:71
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
void updateLtlStoreOfNtk(Abc_Ntk_t *pNtk, Vec_Ptr_t *tempLtlStore)
Definition: ioUtil.c:217
static int Abc_NtkHasMapping(Abc_Ntk_t *pNtk)
Definition: abc.h:256
char * strtok()
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition: abcObj.c:633
Abc_Ntk_t * Io_ReadEdif(char *pFileName, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadEdif.c:47
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_NAMESPACE_IMPL_START Io_FileType_t Io_ReadFileType(char *pFileName)
DECLARATIONS ///.
Definition: ioUtil.c:46
ABC_DLL Abc_Ntk_t * Abc_NtkFlattenLogicHierarchy(Abc_Ntk_t *pNtk)
Definition: abcHie.c:514
ABC_DLL Abc_Ntk_t * Abc_NtkToNetlist(Abc_Ntk_t *pNtk)
Definition: abcNetlist.c:97
Abc_Obj_t * Io_ReadCreateInv(Abc_Ntk_t *pNtk, char *pNameIn, char *pNameOut)
Definition: ioUtil.c:774
void Io_WriteBlif(Abc_Ntk_t *pNtk, char *pFileName, int fWriteLatches, int fBb2Wb, int fSeq)
Definition: ioWriteBlif.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkToNetlistBench(Abc_Ntk_t *pNtk)
Definition: abcNetlist.c:122
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition: abcNames.c:68
static int Abc_NtkWhiteboxNum(Abc_Ntk_t *pNtk)
Definition: abc.h:295
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL int Abc_NtkConvertToBlifMv(Abc_Ntk_t *pNtk)
Definition: abcBlifMv.c:954
FILE * Io_FileOpen(const char *FileName, const char *PathVar, const char *Mode, int fVerbose)
Definition: ioUtil.c:819
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
ABC_DLL Abc_Ntk_t * Abc_NtkInsertBlifMv(Abc_Ntk_t *pNtkBase, Abc_Ntk_t *pNtkLogic)
Definition: abcBlifMv.c:909
char * Extra_UtilStrsav(const char *s)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
int Io_WriteSmv(Abc_Ntk_t *pNtk, char *FileName)
Definition: ioWriteSmv.c:71
int strcmp()
ABC_DLL int Abc_NtkIsAcyclicWithBoxes(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1510
ABC_DLL Abc_Ntk_t * Abc_NtkToLogic(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcNetlist.c:52
static Abc_Obj_t * Abc_NtkCreateBo(Abc_Ntk_t *pNtk)
Definition: abc.h:306
ABC_DLL Abc_Ntk_t * Abc_NtkStrashBlifMv(Abc_Ntk_t *pNtk)
Definition: abcBlifMv.c:380
ABC_DLL Abc_Ntk_t * Abc_NtkFromBarBufs(Abc_Ntk_t *pNtkBase, Abc_Ntk_t *pNtk)
Definition: abcBarBuf.c:263
Abc_Obj_t * Io_ReadCreateLatch(Abc_Ntk_t *pNtk, char *pNetLI, char *pNetLO)
Definition: ioUtil.c:660
Abc_Obj_t * Io_ReadCreateConst(Abc_Ntk_t *pNtk, char *pName, int fConst1)
Definition: ioUtil.c:754
Abc_Obj_t * Io_ReadCreateNode(Abc_Ntk_t *pNtk, char *pNameOut, char *pNamesIn[], int nInputs)
Definition: ioUtil.c:725
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:662
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fDirect)
Definition: abcFunc.c:1124
void Io_WriteBook(Abc_Ntk_t *pNtk, char *FileName)
Definition: ioWriteBook.c:100
void Io_WriteGml(Abc_Ntk_t *pNtk, char *pFileName)
DECLARATIONS ///.
Definition: ioWriteGml.c:46
Abc_Ntk_t * Io_ReadBench(char *pFileName, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadBench.c:47
#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
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeBuf(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:692
void Io_WriteHie(Abc_Ntk_t *pNtk, char *pBaseName, char *pFileName)
Definition: ioUtil.c:477
int Io_WritePla(Abc_Ntk_t *pNtk, char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ioWritePla.c:47
static Abc_Obj_t * Abc_NtkCreateLatch(Abc_Ntk_t *pNtk)
Definition: abc.h:309
Abc_Ntk_t * Io_ReadEqn(char *pFileName, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadEqn.c:50
void Io_Write(Abc_Ntk_t *pNtk, char *pFileName, Io_FileType_t FileType)
Definition: ioUtil.c:317
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
Abc_Obj_t * Io_ReadCreatePi(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:610
ABC_DLL Abc_Obj_t * Abc_NtkFindOrCreateNet(Abc_Ntk_t *pNtk, char *pName)
Definition: abcObj.c:579
ABC_DLL Abc_Ntk_t * Abc_NtkConvertBlackboxes(Abc_Ntk_t *pNtk)
Definition: abcHie.c:598
Abc_Ntk_t * Io_ReadVerilog(char *pFileName, int fCheck)
DECLARATIONS ///.
Definition: ioReadVerilog.c:48
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Abc_Ntk_t * Io_ReadPla(char *pFileName, int fZeros, int fCheck)
FUNCTION DEFINITIONS ///.
Definition: ioReadPla.c:47
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int nBarBufs
Definition: abc.h:174
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition: abcObj.c:604
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
void Io_WriteBaf(Abc_Ntk_t *pNtk, char *pFileName)
DECLARATIONS ///.
Definition: ioWriteBaf.c:84
void Io_WriteBlifMv(Abc_Ntk_t *pNtk, char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteBlifMv.c:58
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1192
void Io_WriteBblif(Abc_Ntk_t *pNtk, char *pFileName)
Definition: ioWriteBblif.c:99
Vec_Ptr_t * vModules
Definition: abc.h:223
#define assert(ex)
Definition: util_old.h:213
ABC_DLL Abc_Ntk_t * Abc_NtkToBarBufs(Abc_Ntk_t *pNtk)
Definition: abcBarBuf.c:180
static int Abc_NtkHasAig(Abc_Ntk_t *pNtk)
Definition: abc.h:255
ABC_DLL char * Abc_FrameReadFlag(char *pFlag)
Definition: mainFrame.c:64
char * Extra_FileNameExtension(char *FileName)
int Io_WriteCnf(Abc_Ntk_t *pNtk, char *FileName, int fAllPrimes)
FUNCTION DEFINITIONS ///.
Definition: ioWriteCnf.c:48
static int Abc_NtkBlackboxNum(Abc_Ntk_t *pNtk)
Definition: abc.h:296
static Abc_Obj_t * Abc_NtkCreateBi(Abc_Ntk_t *pNtk)
Definition: abc.h:305
int Io_WriteBench(Abc_Ntk_t *pNtk, const char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteBench.c:53
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Abc_Ntk_t * Io_ReadBaf(char *pFileName, int fCheck)
DECLARATIONS ///.
Definition: ioReadBaf.c:45
Abc_Des_t * pDesign
Definition: abc.h:180
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
ABC_DLL Abc_Ntk_t * Abc_NtkInsertNewLogic(Abc_Ntk_t *pNtkH, Abc_Ntk_t *pNtkL)
Definition: abcHie.c:691
static void Abc_LatchSetInit0(Abc_Obj_t *pLatch)
Definition: abc.h:418
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
void Io_WriteAiger(Abc_Ntk_t *pNtk, char *pFileName, int fWriteSymbols, int fCompact, int fUnique)
Definition: ioWriteAiger.c:635
void Io_WriteDot(Abc_Ntk_t *pNtk, char *FileName)
FUNCTION DEFINITIONS ///.
Definition: ioWriteDot.c:51
static Abc_Obj_t * Abc_NtkCreateNet(Abc_Ntk_t *pNtk)
Definition: abc.h:307
Abc_Obj_t * Io_ReadCreatePo(Abc_Ntk_t *pNtk, char *pName)
Definition: ioUtil.c:635
Abc_Ntk_t * Io_ReadNetlist(char *pFileName, Io_FileType_t FileType, int fCheck)
Definition: ioUtil.c:98
Abc_Obj_t * Io_ReadCreateResetLatch(Abc_Ntk_t *pNtk, int fBlifMv)
Definition: ioUtil.c:693