1 /**CFile****************************************************************
2
3 FileName [bacBlast.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Hierarchical word-level netlist.]
8
9 Synopsis [Bit-blasting of the netlist.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - November 29, 2014.]
16
17 Revision [$Id: bacBlast.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "bac.h"
22 #include "base/abc/abc.h"
23 #include "map/mio/mio.h"
24 #include "bool/dec/dec.h"
25 #include "base/main/mainInt.h"
26
27 ABC_NAMESPACE_IMPL_START
28
29 ////////////////////////////////////////////////////////////////////////
30 /// DECLARATIONS ///
31 ////////////////////////////////////////////////////////////////////////
32
33 ////////////////////////////////////////////////////////////////////////
34 /// FUNCTION DEFINITIONS ///
35 ////////////////////////////////////////////////////////////////////////
36
37 /**Function*************************************************************
38
39 Synopsis []
40
41 Description []
42
43 SideEffects []
44
45 SeeAlso []
46
47 ***********************************************************************/
Bac_ManPrepareGates(Bac_Man_t * p)48 void Bac_ManPrepareGates( Bac_Man_t * p )
49 {
50 Dec_Graph_t ** ppGraphs; int i;
51 if ( p->pMioLib == NULL )
52 return;
53 ppGraphs = ABC_CALLOC( Dec_Graph_t *, Abc_NamObjNumMax(p->pMods) );
54 for ( i = 1; i < Abc_NamObjNumMax(p->pMods); i++ )
55 {
56 char * pGateName = Abc_NamStr( p->pMods, i );
57 Mio_Gate_t * pGate = Mio_LibraryReadGateByName( (Mio_Library_t *)p->pMioLib, pGateName, NULL );
58 if ( pGate != NULL )
59 ppGraphs[i] = Dec_Factor( Mio_GateReadSop(pGate) );
60 }
61 assert( p->ppGraphs == NULL );
62 p->ppGraphs = (void **)ppGraphs;
63 }
Bac_ManUndoGates(Bac_Man_t * p)64 void Bac_ManUndoGates( Bac_Man_t * p )
65 {
66 int i;
67 if ( p->pMioLib == NULL )
68 return;
69 for ( i = 1; i < Abc_NamObjNumMax(p->pMods); i++ )
70 if ( p->ppGraphs[i] )
71 Dec_GraphFree( (Dec_Graph_t *)p->ppGraphs[i] );
72 ABC_FREE( p->ppGraphs );
73 }
74
75
76 /**Function*************************************************************
77
78 Synopsis []
79
80 Description []
81
82 SideEffects []
83
84 SeeAlso []
85
86 ***********************************************************************/
Bac_ManAddBarbuf(Gia_Man_t * pNew,int iRes,Bac_Man_t * p,int iLNtk,int iLObj,int iRNtk,int iRObj,Vec_Int_t * vMap)87 int Bac_ManAddBarbuf( Gia_Man_t * pNew, int iRes, Bac_Man_t * p, int iLNtk, int iLObj, int iRNtk, int iRObj, Vec_Int_t * vMap )
88 {
89 int iBufLit, iIdLit;
90 if ( iRes == 0 || iRes == 1 )
91 return iRes;
92 assert( iRes > 0 );
93 if ( vMap && Abc_Lit2Var(iRes) < Vec_IntSize(vMap) && (iIdLit = Vec_IntEntry(vMap, Abc_Lit2Var(iRes))) >= 0 &&
94 Vec_IntEntry(&p->vBuf2LeafNtk, Abc_Lit2Var(iIdLit)) == iLNtk && Vec_IntEntry(&p->vBuf2RootNtk, Abc_Lit2Var(iIdLit)) == iRNtk )
95 return Abc_LitNotCond( Vec_IntEntry(pNew->vBarBufs, Abc_Lit2Var(iIdLit)), Abc_LitIsCompl(iRes) ^ Abc_LitIsCompl(iIdLit) );
96 assert( Bac_ManNtkIsOk(p, iLNtk) && Bac_ManNtkIsOk(p, iRNtk) );
97 Vec_IntPush( &p->vBuf2LeafNtk, iLNtk );
98 Vec_IntPush( &p->vBuf2LeafObj, iLObj );
99 Vec_IntPush( &p->vBuf2RootNtk, iRNtk );
100 Vec_IntPush( &p->vBuf2RootObj, iRObj );
101 iBufLit = Gia_ManAppendBuf( pNew, iRes );
102 if ( vMap )
103 {
104 Vec_IntSetEntryFull( vMap, Abc_Lit2Var(iRes), Abc_Var2Lit(Vec_IntSize(pNew->vBarBufs), Abc_LitIsCompl(iRes)) );
105 Vec_IntPush( pNew->vBarBufs, iBufLit );
106 }
107 return iBufLit;
108 }
Bac_ManExtract_rec(Gia_Man_t * pNew,Bac_Ntk_t * p,int i,int fBuffers,Vec_Int_t * vMap)109 int Bac_ManExtract_rec( Gia_Man_t * pNew, Bac_Ntk_t * p, int i, int fBuffers, Vec_Int_t * vMap )
110 {
111 int iRes = Bac_ObjCopy( p, i );
112 if ( iRes >= 0 )
113 return iRes;
114 if ( Bac_ObjIsCo(p, i) )
115 iRes = Bac_ManExtract_rec( pNew, p, Bac_ObjFanin(p, i), fBuffers, vMap );
116 else if ( Bac_ObjIsPi(p, i) )
117 {
118 Bac_Ntk_t * pHost = Bac_NtkHostNtk( p );
119 int iObj = Bac_BoxBi( pHost, Bac_NtkHostObj(p), Bac_ObjIndex(p, i) );
120 iRes = Bac_ManExtract_rec( pNew, pHost, iObj, fBuffers, vMap );
121 if ( fBuffers )
122 iRes = Bac_ManAddBarbuf( pNew, iRes, p->pDesign, Bac_NtkId(p), i, Bac_NtkId(pHost), iObj, vMap );
123 }
124 else if ( Bac_ObjIsBo(p, i) )
125 {
126 int iBox = Bac_BoxBoBox(p, i);
127 if ( Bac_ObjIsBoxUser(p, iBox) ) // user box
128 {
129 Bac_Ntk_t * pBox = Bac_BoxBoNtk( p, i );
130 int iObj = Bac_NtkPo( pBox, Bac_ObjIndex(p, i) );
131 iRes = Bac_ManExtract_rec( pNew, pBox, iObj, fBuffers, vMap );
132 if ( fBuffers )
133 iRes = Bac_ManAddBarbuf( pNew, iRes, p->pDesign, Bac_NtkId(p), i, Bac_NtkId(pBox), iObj, vMap );
134 }
135 else // primitive
136 {
137 int iFanin, nLits, pLits[16];
138 assert( Bac_ObjIsBoxPrim(p, iBox) );
139 Bac_BoxForEachFanin( p, iBox, iFanin, nLits )
140 pLits[nLits] = Bac_ManExtract_rec( pNew, p, iFanin, fBuffers, vMap );
141 assert( nLits <= 16 );
142 if ( p->pDesign->ppGraphs ) // mapped gate
143 {
144 extern int Gia_ManFactorGraph( Gia_Man_t * p, Dec_Graph_t * pFForm, Vec_Int_t * vLeaves );
145 Dec_Graph_t * pGraph = (Dec_Graph_t *)p->pDesign->ppGraphs[Bac_BoxNtkId(p, iBox)];
146 Vec_Int_t Leaves = { nLits, nLits, pLits };
147 assert( pGraph != NULL );
148 return Gia_ManFactorGraph( pNew, pGraph, &Leaves );
149 }
150 else
151 {
152 Bac_ObjType_t Type = Bac_ObjType(p, iBox);
153 if ( nLits == 0 )
154 {
155 if ( Type == BAC_BOX_CF )
156 iRes = 0;
157 else if ( Type == BAC_BOX_CT )
158 iRes = 1;
159 else assert( 0 );
160 }
161 else if ( nLits == 1 )
162 {
163 if ( Type == BAC_BOX_BUF )
164 iRes = pLits[0];
165 else if ( Type == BAC_BOX_INV )
166 iRes = Abc_LitNot( pLits[0] );
167 else assert( 0 );
168 }
169 else if ( nLits == 2 )
170 {
171 if ( Type == BAC_BOX_AND )
172 iRes = Gia_ManHashAnd( pNew, pLits[0], pLits[1] );
173 else if ( Type == BAC_BOX_NAND )
174 iRes = Abc_LitNot( Gia_ManHashAnd( pNew, pLits[0], pLits[1] ) );
175 else if ( Type == BAC_BOX_OR )
176 iRes = Gia_ManHashOr( pNew, pLits[0], pLits[1] );
177 else if ( Type == BAC_BOX_NOR )
178 iRes = Abc_LitNot( Gia_ManHashOr( pNew, pLits[0], pLits[1] ) );
179 else if ( Type == BAC_BOX_XOR )
180 iRes = Gia_ManHashXor( pNew, pLits[0], pLits[1] );
181 else if ( Type == BAC_BOX_XNOR )
182 iRes = Abc_LitNot( Gia_ManHashXor( pNew, pLits[0], pLits[1] ) );
183 else if ( Type == BAC_BOX_SHARP )
184 iRes = Gia_ManHashAnd( pNew, pLits[0], Abc_LitNot(pLits[1]) );
185 else if ( Type == BAC_BOX_SHARPL )
186 iRes = Gia_ManHashAnd( pNew, Abc_LitNot(pLits[0]), pLits[1] );
187 else assert( 0 );
188 }
189 else if ( nLits == 3 )
190 {
191 if ( Type == BAC_BOX_MUX )
192 iRes = Gia_ManHashMux( pNew, pLits[0], pLits[1], pLits[2] );
193 else if ( Type == BAC_BOX_MAJ )
194 iRes = Gia_ManHashMaj( pNew, pLits[0], pLits[1], pLits[2] );
195 else if ( Type == BAC_BOX_ADD )
196 {
197 int iRes0 = Gia_ManHashAnd( pNew, pLits[1], pLits[2] );
198 int iRes1 = Gia_ManHashOr( pNew, pLits[1], pLits[2] );
199 assert( Bac_BoxBoNum(p, iBox) == 2 );
200 if ( Bac_BoxBo(p, iBox, 0) == i ) // sum
201 iRes = Gia_ManHashXor( pNew, pLits[0], Gia_ManHashAnd(pNew, Abc_LitNot(iRes0), iRes1) );
202 else if ( Bac_BoxBo(p, iBox, 1) == i ) // cout
203 iRes = Gia_ManHashOr( pNew, iRes0, Gia_ManHashAnd(pNew, pLits[0], iRes1) );
204 else assert( 0 );
205 }
206 else assert( 0 );
207 }
208 else assert( 0 );
209 }
210 }
211 }
212 else assert( 0 );
213 Bac_ObjSetCopy( p, i, iRes );
214 return iRes;
215 }
Bac_ManExtract(Bac_Man_t * p,int fBuffers,int fVerbose)216 Gia_Man_t * Bac_ManExtract( Bac_Man_t * p, int fBuffers, int fVerbose )
217 {
218 Bac_Ntk_t * pNtk, * pRoot = Bac_ManRoot(p);
219 Gia_Man_t * pNew, * pTemp;
220 Vec_Int_t * vMap = NULL;
221 int i, iObj;
222
223 Vec_IntClear( &p->vBuf2LeafNtk );
224 Vec_IntClear( &p->vBuf2LeafObj );
225 Vec_IntClear( &p->vBuf2RootNtk );
226 Vec_IntClear( &p->vBuf2RootObj );
227
228 Bac_ManForEachNtk( p, pNtk, i )
229 {
230 Bac_NtkDeriveIndex( pNtk );
231 Bac_NtkStartCopies( pNtk );
232 }
233
234 // start the manager
235 pNew = Gia_ManStart( Bac_ManNodeNum(p) );
236 pNew->pName = Abc_UtilStrsav(p->pName);
237 pNew->pSpec = Abc_UtilStrsav(p->pSpec);
238
239 // primary inputs
240 Bac_NtkForEachPi( pRoot, iObj, i )
241 Bac_ObjSetCopy( pRoot, iObj, Gia_ManAppendCi(pNew) );
242
243 // internal nodes
244 Gia_ManHashAlloc( pNew );
245 pNew->vBarBufs = Vec_IntAlloc( 10000 );
246 vMap = Vec_IntStartFull( 10000 );
247 Bac_ManPrepareGates( p );
248 Bac_NtkForEachPo( pRoot, iObj, i )
249 Bac_ManExtract_rec( pNew, pRoot, iObj, fBuffers, vMap );
250 Bac_ManUndoGates( p );
251 Vec_IntFreeP( &vMap );
252 Gia_ManHashStop( pNew );
253
254 // primary outputs
255 Bac_NtkForEachPo( pRoot, iObj, i )
256 Gia_ManAppendCo( pNew, Bac_ObjCopy(pRoot, iObj) );
257 assert( Vec_IntSize(&p->vBuf2LeafNtk) == pNew->nBufs );
258
259 // cleanup
260 pNew = Gia_ManCleanup( pTemp = pNew );
261 Gia_ManStop( pTemp );
262 //Gia_ManPrintStats( pNew, NULL );
263 return pNew;
264 }
265
266 /**Function*************************************************************
267
268 Synopsis [Mark each GIA node with the network it belongs to.]
269
270 Description []
271
272 SideEffects []
273
274 SeeAlso []
275
276 ***********************************************************************/
Bac_ManMarkNodesGia(Bac_Man_t * p,Gia_Man_t * pGia)277 void Bac_ManMarkNodesGia( Bac_Man_t * p, Gia_Man_t * pGia )
278 {
279 Gia_Obj_t * pObj; int i, Count = 0;
280 assert( Vec_IntSize(&p->vBuf2LeafNtk) == Gia_ManBufNum(pGia) );
281 Gia_ManConst0(pGia)->Value = 1;
282 Gia_ManForEachPi( pGia, pObj, i )
283 pObj->Value = 1;
284 Gia_ManForEachAnd( pGia, pObj, i )
285 {
286 if ( Gia_ObjIsBuf(pObj) )
287 pObj->Value = Vec_IntEntry( &p->vBuf2LeafNtk, Count++ );
288 else
289 {
290 pObj->Value = Gia_ObjFanin0(pObj)->Value;
291 assert( pObj->Value == Gia_ObjFanin1(pObj)->Value );
292 }
293 }
294 assert( Count == Gia_ManBufNum(pGia) );
295 Gia_ManForEachPo( pGia, pObj, i )
296 {
297 assert( Gia_ObjFanin0(pObj)->Value == 1 );
298 pObj->Value = 1;
299 }
300 }
Bac_ManRemapBarbufs(Bac_Man_t * pNew,Bac_Man_t * p)301 void Bac_ManRemapBarbufs( Bac_Man_t * pNew, Bac_Man_t * p )
302 {
303 Bac_Ntk_t * pNtk; int Entry, i;
304 //assert( Vec_IntSize(&p->vBuf2RootNtk) );
305 assert( !Vec_IntSize(&pNew->vBuf2RootNtk) );
306 Vec_IntAppend( &pNew->vBuf2RootNtk, &p->vBuf2RootNtk );
307 Vec_IntAppend( &pNew->vBuf2RootObj, &p->vBuf2RootObj );
308 Vec_IntAppend( &pNew->vBuf2LeafNtk, &p->vBuf2LeafNtk );
309 Vec_IntAppend( &pNew->vBuf2LeafObj, &p->vBuf2LeafObj );
310 Vec_IntForEachEntry( &p->vBuf2LeafObj, Entry, i )
311 {
312 pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2LeafNtk, i) );
313 Vec_IntWriteEntry( &pNew->vBuf2LeafObj, i, Bac_ObjCopy(pNtk, Entry) );
314 }
315 Vec_IntForEachEntry( &p->vBuf2RootObj, Entry, i )
316 {
317 pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, i) );
318 Vec_IntWriteEntry( &pNew->vBuf2RootObj, i, Bac_ObjCopy(pNtk, Entry) );
319 }
320 }
Bac_NtkCreateAndConnectBuffer(Gia_Man_t * pGia,Gia_Obj_t * pObj,Bac_Ntk_t * p,int iTerm)321 void Bac_NtkCreateAndConnectBuffer( Gia_Man_t * pGia, Gia_Obj_t * pObj, Bac_Ntk_t * p, int iTerm )
322 {
323 int iObj;
324 if ( pGia && Gia_ObjFaninId0p(pGia, pObj) > 0 )
325 {
326 iObj = Bac_ObjAlloc( p, BAC_OBJ_BI, Gia_ObjFanin0(pObj)->Value );
327 Bac_ObjAlloc( p, Gia_ObjFaninC0(pObj) ? BAC_BOX_INV : BAC_BOX_BUF, -1 );
328 }
329 else
330 {
331 Bac_ObjAlloc( p, pGia && Gia_ObjFaninC0(pObj) ? BAC_BOX_CT : BAC_BOX_CF, -1 );
332 }
333 iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 );
334 Bac_ObjSetFanin( p, iTerm, iObj );
335 }
Bac_NtkInsertGia(Bac_Man_t * p,Gia_Man_t * pGia)336 void Bac_NtkInsertGia( Bac_Man_t * p, Gia_Man_t * pGia )
337 {
338 Bac_Ntk_t * pNtk, * pRoot = Bac_ManRoot( p );
339 int i, j, k, iBox, iTerm, Count = 0;
340 Gia_Obj_t * pObj;
341
342 Gia_ManConst0(pGia)->Value = ~0;
343 Gia_ManForEachPi( pGia, pObj, i )
344 pObj->Value = Bac_NtkPi( pRoot, i );
345 Gia_ManForEachAnd( pGia, pObj, i )
346 {
347 if ( Gia_ObjIsBuf(pObj) )
348 {
349 pNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, Count) );
350 iTerm = Vec_IntEntry( &p->vBuf2RootObj, Count );
351 assert( Bac_ObjIsCo(pNtk, iTerm) );
352 if ( Bac_ObjFanin(pNtk, iTerm) == -1 ) // not a feedthrough
353 Bac_NtkCreateAndConnectBuffer( pGia, pObj, pNtk, iTerm );
354 // prepare leaf
355 pObj->Value = Vec_IntEntry( &p->vBuf2LeafObj, Count++ );
356 }
357 else
358 {
359 int iLit0 = Gia_ObjFanin0(pObj)->Value;
360 int iLit1 = Gia_ObjFanin1(pObj)->Value;
361 Bac_ObjType_t Type;
362 pNtk = Bac_ManNtk( p, pObj->Value );
363 if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) )
364 Type = BAC_BOX_NOR;
365 else if ( Gia_ObjFaninC1(pObj) )
366 Type = BAC_BOX_SHARP;
367 else if ( Gia_ObjFaninC0(pObj) )
368 {
369 Type = BAC_BOX_SHARP;
370 ABC_SWAP( int, iLit0, iLit1 );
371 }
372 else
373 Type = BAC_BOX_AND;
374 // create box
375 iTerm = Bac_ObjAlloc( pNtk, BAC_OBJ_BI, iLit1 );
376 iTerm = Bac_ObjAlloc( pNtk, BAC_OBJ_BI, iLit0 );
377 Bac_ObjAlloc( pNtk, Type, -1 );
378 pObj->Value = Bac_ObjAlloc( pNtk, BAC_OBJ_BO, -1 );
379 }
380 }
381 assert( Count == Gia_ManBufNum(pGia) );
382
383 // create constant 0 drivers for COs without barbufs
384 Bac_ManForEachNtk( p, pNtk, i )
385 {
386 Bac_NtkForEachBox( pNtk, iBox )
387 Bac_BoxForEachBi( pNtk, iBox, iTerm, j )
388 if ( Bac_ObjFanin(pNtk, iTerm) == -1 )
389 Bac_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm );
390 Bac_NtkForEachPo( pNtk, iTerm, k )
391 if ( pNtk != pRoot && Bac_ObjFanin(pNtk, iTerm) == -1 )
392 Bac_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm );
393 }
394 // create node and connect POs
395 Gia_ManForEachPo( pGia, pObj, i )
396 if ( Bac_ObjFanin(pRoot, Bac_NtkPo(pRoot, i)) == -1 ) // not a feedthrough
397 Bac_NtkCreateAndConnectBuffer( pGia, pObj, pRoot, Bac_NtkPo(pRoot, i) );
398 }
Bac_ManInsertGia(Bac_Man_t * p,Gia_Man_t * pGia)399 Bac_Man_t * Bac_ManInsertGia( Bac_Man_t * p, Gia_Man_t * pGia )
400 {
401 Bac_Man_t * pNew = Bac_ManDupUserBoxes( p );
402 Bac_ManMarkNodesGia( p, pGia );
403 Bac_ManRemapBarbufs( pNew, p );
404 Bac_NtkInsertGia( pNew, pGia );
405 Bac_ManMoveNames( pNew, p );
406 return pNew;
407 }
408
409 /**Function*************************************************************
410
411 Synopsis []
412
413 Description []
414
415 SideEffects []
416
417 SeeAlso []
418
419 ***********************************************************************/
Bac_ManBlastTest(Bac_Man_t * p)420 Bac_Man_t * Bac_ManBlastTest( Bac_Man_t * p )
421 {
422 Gia_Man_t * pGia = Bac_ManExtract( p, 1, 0 );
423 Bac_Man_t * pNew = Bac_ManInsertGia( p, pGia );
424 Gia_ManStop( pGia );
425 return pNew;
426 }
427
428 /**Function*************************************************************
429
430 Synopsis [Mark each GIA node with the network it belongs to.]
431
432 Description []
433
434 SideEffects []
435
436 SeeAlso []
437
438 ***********************************************************************/
Abc_NodeIsSeriousGate(Abc_Obj_t * p)439 static inline int Abc_NodeIsSeriousGate( Abc_Obj_t * p )
440 {
441 return Abc_ObjIsNode(p) && Abc_ObjFaninNum(p) > 0 && !Abc_ObjIsBarBuf(p);
442 }
Bac_ManMarkNodesAbc(Bac_Man_t * p,Abc_Ntk_t * pNtk)443 void Bac_ManMarkNodesAbc( Bac_Man_t * p, Abc_Ntk_t * pNtk )
444 {
445 Abc_Obj_t * pObj, * pFanin; int i, k, Count = 0;
446 assert( Vec_IntSize(&p->vBuf2LeafNtk) == pNtk->nBarBufs2 );
447 Abc_NtkForEachPi( pNtk, pObj, i )
448 pObj->iTemp = 1;
449 Abc_NtkForEachNode( pNtk, pObj, i )
450 {
451 if ( Abc_ObjIsBarBuf(pObj) )
452 pObj->iTemp = Vec_IntEntry( &p->vBuf2LeafNtk, Count++ );
453 else if ( Abc_NodeIsSeriousGate(pObj) )
454 {
455 pObj->iTemp = Abc_ObjFanin0(pObj)->iTemp;
456 Abc_ObjForEachFanin( pObj, pFanin, k )
457 assert( pObj->iTemp == pFanin->iTemp );
458 }
459 }
460 Abc_NtkForEachPo( pNtk, pObj, i )
461 {
462 if ( !Abc_NodeIsSeriousGate(Abc_ObjFanin0(pObj)) )
463 continue;
464 assert( Abc_ObjFanin0(pObj)->iTemp == 1 );
465 pObj->iTemp = Abc_ObjFanin0(pObj)->iTemp;
466 }
467 assert( Count == pNtk->nBarBufs2 );
468 }
Bac_NtkCreateOrConnectFanin(Abc_Obj_t * pFanin,Bac_Ntk_t * p,int iTerm)469 void Bac_NtkCreateOrConnectFanin( Abc_Obj_t * pFanin, Bac_Ntk_t * p, int iTerm )
470 {
471 int iObj;
472 if ( pFanin && Abc_NodeIsSeriousGate(pFanin) )//&& Bac_ObjName(p, pFanin->iTemp) == -1 ) // gate without name
473 {
474 iObj = pFanin->iTemp;
475 }
476 else if ( pFanin && (Abc_ObjIsPi(pFanin) || Abc_ObjIsBarBuf(pFanin) || Abc_NodeIsSeriousGate(pFanin)) ) // PI/BO or gate with name
477 {
478 iObj = Bac_ObjAlloc( p, BAC_OBJ_BI, pFanin->iTemp );
479 Bac_ObjAlloc( p, BAC_BOX_GATE, p->pDesign->ElemGates[2] ); // buffer
480 iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 );
481 }
482 else
483 {
484 assert( !pFanin || Abc_NodeIsConst0(pFanin) || Abc_NodeIsConst1(pFanin) );
485 Bac_ObjAlloc( p, BAC_BOX_GATE, p->pDesign->ElemGates[(pFanin && Abc_NodeIsConst1(pFanin))] ); // const 0/1
486 iObj = Bac_ObjAlloc( p, BAC_OBJ_BO, -1 );
487 }
488 Bac_ObjSetFanin( p, iTerm, iObj );
489 }
Bac_NtkPrepareLibrary(Bac_Man_t * p,Mio_Library_t * pLib)490 void Bac_NtkPrepareLibrary( Bac_Man_t * p, Mio_Library_t * pLib )
491 {
492 Mio_Gate_t * pGate;
493 Mio_Gate_t * pGate0 = Mio_LibraryReadConst0( pLib );
494 Mio_Gate_t * pGate1 = Mio_LibraryReadConst1( pLib );
495 Mio_Gate_t * pGate2 = Mio_LibraryReadBuf( pLib );
496 if ( !pGate0 || !pGate1 || !pGate2 )
497 {
498 printf( "The library does not have one of the elementary gates.\n" );
499 return;
500 }
501 p->ElemGates[0] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate0), NULL );
502 p->ElemGates[1] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate1), NULL );
503 p->ElemGates[2] = Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate2), NULL );
504 Mio_LibraryForEachGate( pLib, pGate )
505 if ( pGate != pGate0 && pGate != pGate1 && pGate != pGate2 )
506 Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate), NULL );
507 assert( Abc_NamObjNumMax(p->pMods) > 1 );
508 }
Bac_NtkBuildLibrary(Bac_Man_t * p)509 int Bac_NtkBuildLibrary( Bac_Man_t * p )
510 {
511 int RetValue = 1;
512 Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen();
513 if ( pLib == NULL )
514 printf( "The standard cell library is not available.\n" ), RetValue = 0;
515 else
516 Bac_NtkPrepareLibrary( p, pLib );
517 p->pMioLib = pLib;
518 return RetValue;
519 }
Bac_NtkInsertNtk(Bac_Man_t * p,Abc_Ntk_t * pNtk)520 void Bac_NtkInsertNtk( Bac_Man_t * p, Abc_Ntk_t * pNtk )
521 {
522 Bac_Ntk_t * pCbaNtk, * pRoot = Bac_ManRoot( p );
523 int i, j, k, iBox, iTerm, Count = 0;
524 Abc_Obj_t * pObj;
525 assert( Abc_NtkHasMapping(pNtk) );
526 Bac_NtkPrepareLibrary( p, (Mio_Library_t *)pNtk->pManFunc );
527 p->pMioLib = pNtk->pManFunc;
528
529 Abc_NtkForEachPi( pNtk, pObj, i )
530 pObj->iTemp = Bac_NtkPi( pRoot, i );
531 Abc_NtkForEachNode( pNtk, pObj, i )
532 {
533 if ( Abc_ObjIsBarBuf(pObj) )
534 {
535 pCbaNtk = Bac_ManNtk( p, Vec_IntEntry(&p->vBuf2RootNtk, Count) );
536 iTerm = Vec_IntEntry( &p->vBuf2RootObj, Count );
537 assert( Bac_ObjIsCo(pCbaNtk, iTerm) );
538 if ( Bac_ObjFanin(pCbaNtk, iTerm) == -1 ) // not a feedthrough
539 Bac_NtkCreateOrConnectFanin( Abc_ObjFanin0(pObj), pCbaNtk, iTerm );
540 // prepare leaf
541 pObj->iTemp = Vec_IntEntry( &p->vBuf2LeafObj, Count++ );
542 }
543 else if ( Abc_NodeIsSeriousGate(pObj) )
544 {
545 pCbaNtk = Bac_ManNtk( p, pObj->iTemp );
546 for ( k = Abc_ObjFaninNum(pObj)-1; k >= 0; k-- )
547 iTerm = Bac_ObjAlloc( pCbaNtk, BAC_OBJ_BI, Abc_ObjFanin(pObj, k)->iTemp );
548 Bac_ObjAlloc( pCbaNtk, BAC_BOX_GATE, Abc_NamStrFind(p->pMods, Mio_GateReadName((Mio_Gate_t *)pObj->pData)) );
549 pObj->iTemp = Bac_ObjAlloc( pCbaNtk, BAC_OBJ_BO, -1 );
550 }
551 }
552 assert( Count == pNtk->nBarBufs2 );
553
554 // create constant 0 drivers for COs without barbufs
555 Bac_ManForEachNtk( p, pCbaNtk, i )
556 {
557 Bac_NtkForEachBox( pCbaNtk, iBox )
558 Bac_BoxForEachBi( pCbaNtk, iBox, iTerm, j )
559 if ( Bac_ObjFanin(pCbaNtk, iTerm) == -1 )
560 Bac_NtkCreateOrConnectFanin( NULL, pCbaNtk, iTerm );
561 Bac_NtkForEachPo( pCbaNtk, iTerm, k )
562 if ( pCbaNtk != pRoot && Bac_ObjFanin(pCbaNtk, iTerm) == -1 )
563 Bac_NtkCreateOrConnectFanin( NULL, pCbaNtk, iTerm );
564 }
565 // create node and connect POs
566 Abc_NtkForEachPo( pNtk, pObj, i )
567 if ( Bac_ObjFanin(pRoot, Bac_NtkPo(pRoot, i)) == -1 ) // not a feedthrough
568 Bac_NtkCreateOrConnectFanin( Abc_ObjFanin0(pObj), pRoot, Bac_NtkPo(pRoot, i) );
569 }
Bac_ManInsertAbc(Bac_Man_t * p,void * pAbc)570 void * Bac_ManInsertAbc( Bac_Man_t * p, void * pAbc )
571 {
572 Abc_Ntk_t * pNtk = (Abc_Ntk_t *)pAbc;
573 Bac_Man_t * pNew = Bac_ManDupUserBoxes( p );
574 Bac_ManMarkNodesAbc( p, pNtk );
575 Bac_ManRemapBarbufs( pNew, p );
576 Bac_NtkInsertNtk( pNew, pNtk );
577 Bac_ManMoveNames( pNew, p );
578 return pNew;
579 }
580
581 ////////////////////////////////////////////////////////////////////////
582 /// END OF FILE ///
583 ////////////////////////////////////////////////////////////////////////
584
585
586 ABC_NAMESPACE_IMPL_END
587
588