1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/**CFile****************************************************************
FileName [abcLib.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Functions to manipulate verilog libraries.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: abcLib.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "abc.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Create the library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Lib_t * Abc_LibCreate( char * pName )
{
Abc_Lib_t * p;
p = ALLOC( Abc_Lib_t, 1 );
memset( p, 0, sizeof(Abc_Lib_t) );
p->pName = Extra_UtilStrsav( pName );
p->tModules = st_init_table( strcmp, st_strhash );
p->vModules = Vec_PtrAlloc( 100 );
p->pManFunc = Aig_ManStart();
p->pLibrary = NULL;
return p;
}
/**Function*************************************************************
Synopsis [Frees the library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_LibFree( Abc_Lib_t * pLib )
{
Abc_Ntk_t * pNtk;
int i;
if ( pLib->pName )
free( pLib->pName );
if ( pLib->pManFunc )
Aig_ManStop( pLib->pManFunc );
if ( pLib->tModules )
st_free_table( pLib->tModules );
if ( pLib->vModules )
{
Vec_PtrForEachEntry( pLib->vModules, pNtk, i )
{
pNtk->pManFunc = NULL;
Abc_NtkDelete( pNtk );
}
Vec_PtrFree( pLib->vModules );
}
free( pLib );
}
/**Function*************************************************************
Synopsis [Frees the library.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t * Abc_LibDeriveRoot( Abc_Lib_t * pLib )
{
Abc_Ntk_t * pNtk;
if ( Vec_PtrSize(pLib->vModules) > 1 )
{
printf( "The design includes more than one module and is currently not used.\n" );
return NULL;
}
pNtk = Vec_PtrEntry( pLib->vModules, 0 ); Vec_PtrClear( pLib->vModules );
pNtk->pManFunc = pLib->pManFunc; pLib->pManFunc = NULL;
return pNtk;
}
/**Function*************************************************************
Synopsis [Surround boxes without content (black boxes) with BIs/BOs.]
Description [Returns the number of black boxes converted.]
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_LibDeriveBlackBoxes( Abc_Ntk_t * pNtk, Abc_Lib_t * pLib )
{
/*
Abc_Obj_t * pObj, * pFanin, * pFanout;
int i, k;
assert( Abc_NtkIsNetlist(pNtk) );
// collect blackbox nodes
assert( Vec_PtrSize(pNtk->vBoxes) == 0 );
Vec_PtrClear( pNtk->vBoxes );
Abc_NtkForEachBox( pNtk, pObj, i )
if ( Abc_NtkNodeNum(pObj->pData) == 0 )
Vec_PtrPush( pNtk->vBoxes, pObj );
// return if there is no black boxes without content
if ( Vec_PtrSize(pNtk->vBoxes) == 0 )
return 0;
// print the boxes
printf( "Black boxes are: " );
Abc_NtkForEachBox( pNtk, pObj, i )
printf( " %s", ((Abc_Ntk_t *)pObj->pData)->pName );
printf( "\n" );
// iterate through the boxes and add BIs/BOs
Abc_NtkForEachBox( pNtk, pObj, i )
{
// go through the fanin nets
Abc_ObjForEachFanin( pObj, pFanin, k )
Abc_ObjInsertBetween( pFanin, pObj, ABC_OBJ_BO );
// go through the fanout nets
Abc_ObjForEachFanout( pObj, pFanout, k )
{
Abc_ObjInsertBetween( pObj, pFanout, ABC_OBJ_BI );
// if the name is not given assign name
if ( pFanout->pData == NULL )
{
pFanout->pData = Abc_ObjName( pFanout );
Nm_ManStoreIdName( pNtk->pManName, pFanout->Id, pFanout->pData, NULL );
}
}
}
return Vec_PtrSize(pNtk->vBoxes);
*/
return 0;
}
/**Function*************************************************************
Synopsis [Derive the AIG of the logic in the netlist.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NodeStrashUsingNetwork_rec( Abc_Ntk_t * pNtkAig, Abc_Obj_t * pObj )
{
Abc_Obj_t * pFanin;
int i;
assert( !Abc_ObjIsNet(pObj) );
if ( pObj->pCopy )
return;
// call for the fanins
Abc_ObjForEachFanin( pObj, pFanin, i )
Abc_NodeStrashUsingNetwork_rec( pNtkAig, Abc_ObjFanin0Ntk(Abc_ObjFanin0(pObj)) );
// compute for the node
pObj->pCopy = Abc_NodeStrash( pNtkAig, pObj );
// set for the fanout net
Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
}
/**Function*************************************************************
Synopsis [Derive the AIG of the logic in the netlist.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NodeStrashUsingNetwork( Abc_Ntk_t * pNtkAig, Abc_Obj_t * pBox )
{
Abc_Ntk_t * pNtkGate;
Abc_Obj_t * pObj;
unsigned * pPolarity;
int i, fCompl;
assert( Abc_ObjIsBox(pBox) );
pNtkGate = pBox->pData;
pPolarity = (unsigned *)pBox->pNext;
assert( Abc_NtkIsNetlist(pNtkGate) );
assert( Abc_NtkLatchNum(pNtkGate) == 0 );
Abc_NtkCleanCopy( pNtkGate );
// set the PI values
Abc_NtkForEachPi( pNtkGate, pObj, i )
{
fCompl = (pPolarity && Abc_InfoHasBit(pPolarity, i));
pObj->pCopy = Abc_ObjNotCond( Abc_ObjFanin(pBox,i)->pCopy, fCompl );
Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
}
// build recursively and set the PO values
Abc_NtkForEachPo( pNtkGate, pObj, i )
{
Abc_NodeStrashUsingNetwork_rec( pNtkAig, Abc_ObjFanin0Ntk(Abc_ObjFanin0(pObj)) );
Abc_ObjFanout(pBox,i)->pCopy = Abc_ObjFanin0(pObj)->pCopy;
}
//printf( "processing %d\n", pBox->Id );
}
/**Function*************************************************************
Synopsis [Derive the AIG of the logic in the netlist.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t * Abc_LibDeriveAig( Abc_Ntk_t * pNtk, Abc_Lib_t * pLib )
{
ProgressBar * pProgress;
Vec_Ptr_t * vNodes;
Abc_Ntk_t * pNtkAig;
Abc_Obj_t * pObj;
int i, nBoxes;
// explicitly derive black boxes
assert( Abc_NtkIsNetlist(pNtk) );
nBoxes = Abc_LibDeriveBlackBoxes( pNtk, pLib );
if ( nBoxes )
printf( "Detected and transformed %d black boxes.\n", nBoxes );
// create the new network with black boxes in place
pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG );
// transer to the nets
Abc_NtkForEachCi( pNtk, pObj, i )
Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
// build the AIG for the remaining logic in the netlist
vNodes = Abc_NtkDfs( pNtk, 0 );
pProgress = Extra_ProgressBarStart( stdout, Vec_PtrSize(vNodes) );
Vec_PtrForEachEntry( vNodes, pObj, i )
{
Extra_ProgressBarUpdate( pProgress, i, NULL );
if ( Abc_ObjIsNode(pObj) )
{
pObj->pCopy = Abc_NodeStrash( pNtkAig, pObj );
Abc_ObjFanout0(pObj)->pCopy = pObj->pCopy;
continue;
}
Abc_NodeStrashUsingNetwork( pNtkAig, pObj );
}
Extra_ProgressBarStop( pProgress );
Vec_PtrFree( vNodes );
// deallocate memory manager, which remembers the phase
if ( pNtk->pData )
{
Extra_MmFlexStop( pNtk->pData, 0 );
pNtk->pData = NULL;
}
// set the COs
// Abc_NtkFinalize( pNtk, pNtkAig );
Abc_NtkForEachCo( pNtk, pObj, i )
Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pObj)->pCopy );
Abc_AigCleanup( pNtkAig->pManFunc );
// make sure that everything is okay
if ( !Abc_NtkCheck( pNtkAig ) )
{
printf( "Abc_LibDeriveAig: The network check has failed.\n" );
return 0;
}
return pNtkAig;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|