abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cbaWriteBlif.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cbaWriteBlif.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Verilog parser.]
8 
9  Synopsis [Parses several flavors of word-level Verilog.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - November 29, 2014.]
16 
17  Revision [$Id: cbaWriteVer.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cba.h"
22 #include "cbaPrs.h"
23 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Writing parser state into a file.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 void Cba_PrsWriteBlifArray( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins, int fFirst )
46 {
47  int NameId, i;
48  Vec_IntForEachEntryStart( vFanins, NameId, i, fFirst )
49  fprintf( pFile, " %s", Cba_NtkStr(p, NameId) );
50  if ( fFirst )
51  fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins,0)) );
52  fprintf( pFile, "\n" );
53 }
54 void Cba_PrsWriteBlifArray2( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vFanins )
55 {
56  int FormId, NameId, i;
57  assert( Vec_IntSize(vFanins) % 2 == 0 );
58  Vec_IntForEachEntryDouble( vFanins, FormId, NameId, i )
59  fprintf( pFile, " %s=%s", Cba_NtkStr(p, FormId), Cba_NtkStr(p, NameId) );
60  fprintf( pFile, "\n" );
61 }
62 void Cba_PrsWriteBlifLines( FILE * pFile, Cba_Ntk_t * p )
63 {
64  Vec_Int_t * vFanins;
65  int Type, Func, i;
66  Cba_NtkForEachObjTypeFuncFanins( p, Type, Func, vFanins, i )
67  if ( Type == CBA_PRS_NODE ) // .names/assign/box2 (no formal/actual binding)
68  {
69  fprintf( pFile, ".names" );
70  Cba_PrsWriteBlifArray( pFile, p, vFanins, 1 );
71  fprintf( pFile, "%s", Cba_NtkFuncStr(p, Func) );
72  }
73  else if ( Type == CBA_PRS_BOX ) // .names/assign/box2 (no formal/actual binding)
74  {
75  fprintf( pFile, ".subckt" );
76  fprintf( pFile, " %s", Cba_NtkStr(p, Func) );
77  Cba_PrsWriteBlifArray2( pFile, p, vFanins );
78  }
79  else if ( Type == CBA_PRS_LATCH ) // .names/assign/box2 (no formal/actual binding)
80  {
81  fprintf( pFile, ".latch" );
82  fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins, 1)) );
83  fprintf( pFile, " %s", Cba_NtkStr(p, Vec_IntEntry(vFanins, 0)) );
84  fprintf( pFile, " %c\n", '0' + Func );
85  }
86 }
87 void Cba_PrsWriteBlifNtk( FILE * pFile, Cba_Ntk_t * p )
88 {
89  assert( Vec_IntSize(&p->vTypes) == Cba_NtkObjNum(p) );
90  assert( Vec_IntSize(&p->vFuncs) == Cba_NtkObjNum(p) );
91  // write header
92  fprintf( pFile, ".model %s\n", Cba_NtkName(p) );
93  if ( Vec_IntSize(&p->vInouts) )
94  fprintf( pFile, ".inouts" );
95  if ( Vec_IntSize(&p->vInouts) )
96  Cba_PrsWriteBlifArray( pFile, p, &p->vInouts, 0 );
97  fprintf( pFile, ".inputs" );
98  Cba_PrsWriteBlifArray( pFile, p, &p->vInputs, 0 );
99  fprintf( pFile, ".outputs" );
100  Cba_PrsWriteBlifArray( pFile, p, &p->vOutputs, 0 );
101  // write objects
102  Cba_PrsWriteBlifLines( pFile, p );
103  fprintf( pFile, ".end\n\n" );
104 }
105 void Cba_PrsWriteBlif( char * pFileName, Cba_Man_t * pDes )
106 {
107  FILE * pFile;
108  Cba_Ntk_t * pNtk;
109  int i;
110  pFile = fopen( pFileName, "wb" );
111  if ( pFile == NULL )
112  {
113  printf( "Cannot open output file \"%s\".\n", pFileName );
114  return;
115  }
116  fprintf( pFile, "// Design \"%s\" written by ABC on %s\n\n", Cba_ManName(pDes), Extra_TimeStamp() );
117  Cba_ManForEachNtk( pDes, pNtk, i )
118  Cba_PrsWriteBlifNtk( pFile, pNtk );
119  fclose( pFile );
120 }
121 
122 /**Function*************************************************************
123 
124  Synopsis []
125 
126  Description []
127 
128  SideEffects []
129 
130  SeeAlso []
131 
132 ***********************************************************************/
133 
134 
135 ////////////////////////////////////////////////////////////////////////
136 /// END OF FILE ///
137 ////////////////////////////////////////////////////////////////////////
138 
139 
141 
Definition: cba.h:99
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static char * Cba_NtkName(Cba_Ntk_t *p)
Definition: cba.h:125
Vec_Int_t vInputs
Definition: cba.h:105
Vec_Int_t vOutputs
Definition: cba.h:106
Vec_Int_t vFuncs
Definition: cba.h:110
static int Cba_NtkObjNum(Cba_Ntk_t *p)
Definition: cba.h:126
#define Cba_NtkForEachObjTypeFuncFanins(p, Type, Func, vFanins, i)
Definition: cba.h:160
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
static char * Cba_ManName(Cba_Man_t *p)
Definition: cba.h:120
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
static char * Cba_NtkStr(Cba_Ntk_t *p, int i)
Definition: cba.h:127
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition: vecInt.h:56
ABC_NAMESPACE_IMPL_START void Cba_PrsWriteBlifArray(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins, int fFirst)
DECLARATIONS ///.
Definition: cbaWriteBlif.c:45
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition: vecInt.h:66
Definition: cba.h:82
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Cba_PrsWriteBlifNtk(FILE *pFile, Cba_Ntk_t *p)
Definition: cbaWriteBlif.c:87
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
char * Extra_TimeStamp()
void Cba_PrsWriteBlif(char *pFileName, Cba_Man_t *pDes)
Definition: cbaWriteBlif.c:105
void Cba_PrsWriteBlifArray2(FILE *pFile, Cba_Ntk_t *p, Vec_Int_t *vFanins)
Definition: cbaWriteBlif.c:54
#define assert(ex)
Definition: util_old.h:213
static char * Cba_NtkFuncStr(Cba_Ntk_t *p, int i)
Definition: cba.h:129
Vec_Int_t vInouts
Definition: cba.h:104
void Cba_PrsWriteBlifLines(FILE *pFile, Cba_Ntk_t *p)
Definition: cbaWriteBlif.c:62
Vec_Int_t vTypes
Definition: cba.h:109
#define Cba_ManForEachNtk(p, pNtk, i)
MACRO DEFINITIONS ///.
Definition: cba.h:155