abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioReadBblif.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioReadBblif.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to read AIG in the binary 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: ioReadBblif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 #include "bool/dec/dec.h"
23 #include "misc/bbl/bblif.h"
24 
26 
27 
28 // For description of Binary BLIF format, refer to "abc/src/aig/bbl/bblif.h"
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// DECLARATIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 ////////////////////////////////////////////////////////////////////////
35 /// FUNCTION DEFINITIONS ///
36 ////////////////////////////////////////////////////////////////////////
37 
38 /**Fnction*************************************************************
39 
40  Synopsis [Constructs ABC network from the manager.]
41 
42  Description [The ABC network is started, as well as the array vCopy,
43  which will map the new ID of each object in the BBLIF manager into
44  the ponter ot the corresponding object in the ABC. For each internal
45  node, determined by Bbl_ObjIsLut(), the SOP representation is created
46  by retrieving the SOP representation of the BBLIF object. Finally,
47  the objects are connected using fanin/fanout creation, and the dummy
48  names are assigned because ABC requires each CI/CO to have a name.]
49 
50  SideEffects []
51 
52  SeeAlso []
53 
54 ***********************************************************************/
56 {
57  Abc_Ntk_t * pNtk;
58  Abc_Obj_t * pObjNew;
59  Bbl_Obj_t * pObj, * pFanin;
60  Vec_Ptr_t * vCopy;
61  // start the network
63  pNtk->pName = Extra_UtilStrsav( Bbl_ManName(p) );
64  // create objects
65  vCopy = Vec_PtrStart( 1000 );
66  Bbl_ManForEachObj( p, pObj )
67  {
68  if ( Bbl_ObjIsInput(pObj) )
69  pObjNew = Abc_NtkCreatePi( pNtk );
70  else if ( Bbl_ObjIsOutput(pObj) )
71  pObjNew = Abc_NtkCreatePo( pNtk );
72  else if ( Bbl_ObjIsLut(pObj) )
73  pObjNew = Abc_NtkCreateNode( pNtk );
74  else assert( 0 );
75  if ( Bbl_ObjIsLut(pObj) )
76  pObjNew->pData = Abc_SopRegister( (Mem_Flex_t *)pNtk->pManFunc, Bbl_ObjSop(p, pObj) );
77  Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), pObjNew );
78  }
79  // connect objects
80  Bbl_ManForEachObj( p, pObj )
81  Bbl_ObjForEachFanin( pObj, pFanin )
82  Abc_ObjAddFanin( (Abc_Obj_t *)Vec_PtrEntry(vCopy, Bbl_ObjId(pObj)), (Abc_Obj_t *)Vec_PtrEntry(vCopy, Bbl_ObjId(pFanin)) );
83  // finalize
84  Vec_PtrFree( vCopy );
85  Abc_NtkAddDummyPiNames( pNtk );
86  Abc_NtkAddDummyPoNames( pNtk );
87  if ( !Abc_NtkCheck( pNtk ) )
88  printf( "Bbl_ManToAbc(): Network check has failed.\n" );
89  return pNtk;
90 }
91 
92 /**Fnction*************************************************************
93 
94  Synopsis [Collects internal nodes in the DFS order.]
95 
96  Description []
97 
98  SideEffects []
99 
100  SeeAlso []
101 
102 ***********************************************************************/
103 void Bbl_ManDfs_rec( Bbl_Obj_t * pObj, Vec_Ptr_t * vNodes )
104 {
105  extern void Bbl_ObjMark( Bbl_Obj_t * p );
106  extern int Bbl_ObjIsMarked( Bbl_Obj_t * p );
107  Bbl_Obj_t * pFanin;
108  if ( Bbl_ObjIsMarked(pObj) || Bbl_ObjIsInput(pObj) )
109  return;
110  Bbl_ObjForEachFanin( pObj, pFanin )
111  Bbl_ManDfs_rec( pFanin, vNodes );
112  assert( !Bbl_ObjIsMarked(pObj) ); // checks if acyclic
113  Bbl_ObjMark( pObj );
114  Vec_PtrPush( vNodes, pObj );
115 }
116 
117 /**Fnction*************************************************************
118 
119  Synopsis [Collects internal nodes in the DFS order.]
120 
121  Description []
122 
123  SideEffects []
124 
125  SeeAlso []
126 
127 ***********************************************************************/
129 {
130  Vec_Ptr_t * vNodes;
131  Bbl_Obj_t * pObj;
132  vNodes = Vec_PtrAlloc( 1000 );
133  Bbl_ManForEachObj( p, pObj )
134  if ( Bbl_ObjIsLut(pObj) )
135  Bbl_ManDfs_rec( pObj, vNodes );
136  return vNodes;
137 }
138 
139 /**Fnction*************************************************************
140 
141  Synopsis [Constructs AIG in ABC from the manager.]
142 
143  Description [The ABC network is started, as well as the array vCopy,
144  which will map the new ID of each object in the BBLIF manager into
145  the ponter ot the corresponding AIG object in the ABC. For each internal
146  node in a topological oder the AIG representation is created
147  by factoring the SOP representation of the BBLIF object. Finally,
148  the CO objects are created, and the dummy names are assigned because
149  ABC requires each CI/CO to have a name.]
150 
151  SideEffects []
152 
153  SeeAlso []
154 
155 ***********************************************************************/
157 {
158  extern int Bbl_ManFncSize( Bbl_Man_t * p );
159  extern int Bbl_ObjFncHandle( Bbl_Obj_t * p );
160  extern Abc_Obj_t * Dec_GraphToAig( Abc_Ntk_t * pNtk, Dec_Graph_t * pFForm, Vec_Ptr_t * vFaninAigs );
161  int fVerbose = 0;
162  Abc_Ntk_t * pNtk;
163  Abc_Obj_t * pObjNew;
164  Bbl_Obj_t * pObj, * pFanin;
165  Vec_Ptr_t * vCopy, * vNodes, * vFaninAigs;
166  Dec_Graph_t ** pFForms;
167  int i;
168  abctime clk;
169 clk = Abc_Clock();
170  // map SOP handles into factored forms
171  pFForms = ABC_CALLOC( Dec_Graph_t *, Bbl_ManFncSize(p) );
172  Bbl_ManForEachObj( p, pObj )
173  if ( pFForms[Bbl_ObjFncHandle(pObj)] == NULL )
174  pFForms[Bbl_ObjFncHandle(pObj)] = Dec_Factor( Bbl_ObjSop(p, pObj) );
175 if ( fVerbose )
176 ABC_PRT( "Fct", Abc_Clock() - clk );
177  // start the network
179  pNtk->pName = Extra_UtilStrsav( Bbl_ManName(p) );
180  vCopy = Vec_PtrStart( 1000 );
181  // create CIs
182  Bbl_ManForEachObj( p, pObj )
183  {
184  if ( !Bbl_ObjIsInput(pObj) )
185  continue;
186  Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), Abc_NtkCreatePi(pNtk) );
187  }
188 clk = Abc_Clock();
189  // create internal nodes
190  vNodes = Bbl_ManDfs( p );
191  vFaninAigs = Vec_PtrAlloc( 100 );
192  Vec_PtrForEachEntry( Bbl_Obj_t *, vNodes, pObj, i )
193  {
194  // collect fanin AIGs
195  Vec_PtrClear( vFaninAigs );
196  Bbl_ObjForEachFanin( pObj, pFanin )
197  Vec_PtrPush( vFaninAigs, Vec_PtrEntry( vCopy, Bbl_ObjId(pFanin) ) );
198  // create the new node
199  pObjNew = Dec_GraphToAig( pNtk, pFForms[Bbl_ObjFncHandle(pObj)], vFaninAigs );
200  Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), pObjNew );
201  }
202  Vec_PtrFree( vFaninAigs );
203  Vec_PtrFree( vNodes );
204 if ( fVerbose )
205 ABC_PRT( "AIG", Abc_Clock() - clk );
206  // create COs
207  Bbl_ManForEachObj( p, pObj )
208  {
209  if ( !Bbl_ObjIsOutput(pObj) )
210  continue;
211  pObjNew = (Abc_Obj_t *)Vec_PtrEntry( vCopy, Bbl_ObjId(Bbl_ObjFaninFirst(pObj)) );
212  Abc_ObjAddFanin( Abc_NtkCreatePo(pNtk), pObjNew );
213  }
214  Abc_AigCleanup( (Abc_Aig_t *)pNtk->pManFunc );
215  // clear factored forms
216  for ( i = Bbl_ManFncSize(p) - 1; i >= 0; i-- )
217  if ( pFForms[i] )
218  Dec_GraphFree( pFForms[i] );
219  ABC_FREE( pFForms );
220  // finalize
221 clk = Abc_Clock();
222  Vec_PtrFree( vCopy );
223  Abc_NtkAddDummyPiNames( pNtk );
224  Abc_NtkAddDummyPoNames( pNtk );
225 if ( fVerbose )
226 ABC_PRT( "Nam", Abc_Clock() - clk );
227 // if ( !Abc_NtkCheck( pNtk ) )
228 // printf( "Bbl_ManToAig(): Network check has failed.\n" );
229  return pNtk;
230 }
231 
232 /**Fnction*************************************************************
233 
234  Synopsis [Verifies equivalence for two combinational networks.]
235 
236  Description []
237 
238  SideEffects []
239 
240  SeeAlso []
241 
242 ***********************************************************************/
243 void Bbl_ManVerify( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2 )
244 {
245  extern void Abc_NtkCecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose );
246  Abc_Ntk_t * pAig1, * pAig2;
247  pAig1 = Abc_NtkStrash( pNtk1, 0, 1, 0 );
248  pAig2 = Abc_NtkStrash( pNtk2, 0, 1, 0 );
249  Abc_NtkShortNames( pAig1 );
250  Abc_NtkShortNames( pAig2 );
251  Abc_NtkCecFraig( pAig1, pAig2, 0, 0 );
252  Abc_NtkDelete( pAig1 );
253  Abc_NtkDelete( pAig2 );
254 }
255 
256 /**Fnction*************************************************************
257 
258  Synopsis [Performs testing of the new manager.]
259 
260  Description []
261 
262  SideEffects []
263 
264  SeeAlso []
265 
266 ***********************************************************************/
267 void Bbl_ManTest( Abc_Ntk_t * pNtk )
268 {
269  extern Bbl_Man_t * Bbl_ManFromAbc( Abc_Ntk_t * pNtk );
270 
271  Abc_Ntk_t * pNtkNew;
272  Bbl_Man_t * p, * pNew;
273  char * pFileName = "test.bblif";
274  abctime clk, clk1, clk2, clk3, clk4, clk5;
275 clk = Abc_Clock();
276  p = Bbl_ManFromAbc( pNtk );
277  Bbl_ManPrintStats( p );
278 clk1 = Abc_Clock() - clk;
279 //Bbl_ManDumpBlif( p, "test_bbl.blif" );
280 
281  // write into file and back
282 clk = Abc_Clock();
283  Bbl_ManDumpBinaryBlif( p, pFileName );
284 clk2 = Abc_Clock() - clk;
285 
286  // read from file
287 clk = Abc_Clock();
288  pNew = Bbl_ManReadBinaryBlif( pFileName );
289  Bbl_ManStop( p ); p = pNew;
290 clk3 = Abc_Clock() - clk;
291 
292  // generate ABC network
293 clk = Abc_Clock();
294  pNtkNew = Bbl_ManToAig( p );
295 // pNtkNew = Bbl_ManToAbc( p );
296  Bbl_ManStop( p );
297 clk4 = Abc_Clock() - clk;
298 
299  // equivalence check
300 clk = Abc_Clock();
301 // Bbl_ManVerify( pNtk, pNtkNew );
302  Abc_NtkDelete( pNtkNew );
303 clk5 = Abc_Clock() - clk;
304 
305 printf( "Runtime stats:\n" );
306 ABC_PRT( "ABC to Man", clk1 );
307 ABC_PRT( "Writing ", clk2 );
308 ABC_PRT( "Reading ", clk3 );
309 ABC_PRT( "Man to ABC", clk4 );
310 ABC_PRT( "Verify ", clk5 );
311 }
312 
313 /**Function*************************************************************
314 
315  Synopsis [Reads the AIG in the binary format.]
316 
317  Description []
318 
319  SideEffects []
320 
321  SeeAlso []
322 
323 ***********************************************************************/
324 Abc_Ntk_t * Io_ReadBblif( char * pFileName, int fCheck )
325 {
326  Bbl_Man_t * p;
327  Abc_Ntk_t * pNtkNew;
328  // read the file
329  p = Bbl_ManReadBinaryBlif( pFileName );
330  pNtkNew = Bbl_ManToAig( p );
331  Bbl_ManStop( p );
332  // check the result
333  if ( fCheck && !Abc_NtkCheckRead( pNtkNew ) )
334  {
335  printf( "Io_ReadBaf: The network check has failed.\n" );
336  Abc_NtkDelete( pNtkNew );
337  return NULL;
338  }
339  return pNtkNew;
340 }
341 
342 ////////////////////////////////////////////////////////////////////////
343 /// END OF FILE ///
344 ////////////////////////////////////////////////////////////////////////
345 
346 
348 
void Bbl_ManDfs_rec(Bbl_Obj_t *pObj, Vec_Ptr_t *vNodes)
Definition: ioReadBblif.c:103
static Vec_Ptr_t * Vec_PtrStart(int nSize)
Definition: vecPtr.h:106
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_PtrSetEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:511
int Bbl_ObjIsInput(Bbl_Obj_t *p)
Definition: bblif.c:1093
void Bbl_ManPrintStats(Bbl_Man_t *p)
Definition: bblif.c:749
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * Bbl_ManName(Bbl_Man_t *p)
Definition: bblif.c:1115
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition: abcStrash.c:265
void Bbl_ManVerify(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2)
Definition: ioReadBblif.c:243
ABC_DLL void Abc_NtkShortNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:490
int Bbl_ObjId(Bbl_Obj_t *p)
Definition: bblif.c:1096
int Bbl_ObjIsLut(Bbl_Obj_t *p)
Definition: bblif.c:1095
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
Dec_Graph_t * Dec_Factor(char *pSop)
FUNCTION DECLARATIONS ///.
Definition: decFactor.c:55
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static abctime Abc_Clock()
Definition: abc_global.h:279
DECLARATIONS ///.
Definition: abcAig.c:52
ABC_NAMESPACE_IMPL_START Bbl_Man_t * Bbl_ManFromAbc(Abc_Ntk_t *pNtk)
DECLARATIONS ///.
Definition: ioWriteBblif.c:54
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
char * Extra_UtilStrsav(const char *s)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
void * pManFunc
Definition: abc.h:191
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:398
ABC_DLL char * Abc_SopRegister(Mem_Flex_t *pMan, char *pName)
DECLARATIONS ///.
Definition: abcSop.c:56
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition: abcAig.c:194
Abc_Obj_t * Dec_GraphToAig(Abc_Ntk_t *pNtk, Dec_Graph_t *pFForm, Vec_Ptr_t *vFaninAigs)
Definition: decAbc.c:104
#define Bbl_ManForEachObj(p, pObj)
Definition: bblif.h:257
ABC_DLL int Abc_NtkCheckRead(Abc_Ntk_t *pNtk)
Definition: abcCheck.c:77
Bbl_Obj_t * Bbl_ObjFaninFirst(Bbl_Obj_t *p)
Definition: bblif.c:1181
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Bbl_Man_t * Bbl_ManReadBinaryBlif(char *pFileName)
Definition: bblif.c:712
Vec_Ptr_t * Bbl_ManDfs(Bbl_Man_t *p)
Definition: ioReadBblif.c:128
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
Abc_Ntk_t * Io_ReadBblif(char *pFileName, int fCheck)
Definition: ioReadBblif.c:324
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Bbl_ManToAbc(Bbl_Man_t *p)
DECLARATIONS ///.
Definition: ioReadBblif.c:55
Abc_Ntk_t * Bbl_ManToAig(Bbl_Man_t *p)
Definition: ioReadBblif.c:156
void Abc_NtkCecFraig(Abc_Ntk_t *pNtk1, Abc_Ntk_t *pNtk2, int nSeconds, int fVerbose)
Definition: abcVerify.c:123
void Bbl_ManTest(Abc_Ntk_t *pNtk)
Definition: ioReadBblif.c:267
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static Abc_Obj_t * Abc_NtkCreateNode(Abc_Ntk_t *pNtk)
Definition: abc.h:308
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
int Bbl_ObjIsMarked(Bbl_Obj_t *p)
Definition: bblif.c:1100
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
#define assert(ex)
Definition: util_old.h:213
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
#define Bbl_ObjForEachFanin(pObj, pFanin)
Definition: bblif.h:260
void * pData
Definition: abc.h:145
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
ABC_INT64_T abctime
Definition: abc_global.h:278
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:378
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
void Bbl_ManDumpBinaryBlif(Bbl_Man_t *p, char *pFileName)
Definition: bblif.c:691
char * pName
Definition: abc.h:158
int Bbl_ObjIsOutput(Bbl_Obj_t *p)
Definition: bblif.c:1094
void Bbl_ManStop(Bbl_Man_t *p)
Definition: bblif.c:775
int Bbl_ManFncSize(Bbl_Man_t *p)
Definition: bblif.c:1131
char * Bbl_ObjSop(Bbl_Man_t *pMan, Bbl_Obj_t *p)
Definition: bblif.c:1099
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Bbl_ObjFncHandle(Bbl_Obj_t *p)
Definition: bblif.c:1102
void Bbl_ObjMark(Bbl_Obj_t *p)
Definition: bblif.c:1101