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
|
/**CFile****************************************************************
FileName [hopObj.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Minimalistic And-Inverter Graph package.]
Synopsis [Adding/removing objects.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - May 11, 2006.]
Revision [$Id: hopObj.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
***********************************************************************/
#include "hop.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Creates primary input.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Hop_Obj_t * Hop_ObjCreatePi( Hop_Man_t * p )
{
Hop_Obj_t * pObj;
pObj = Hop_ManFetchMemory( p );
pObj->Type = AIG_PI;
pObj->PioNum = Vec_PtrSize( p->vPis );
Vec_PtrPush( p->vPis, pObj );
p->nObjs[AIG_PI]++;
return pObj;
}
/**Function*************************************************************
Synopsis [Creates primary output with the given driver.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Hop_Obj_t * Hop_ObjCreatePo( Hop_Man_t * p, Hop_Obj_t * pDriver )
{
Hop_Obj_t * pObj;
pObj = Hop_ManFetchMemory( p );
pObj->Type = AIG_PO;
Vec_PtrPush( p->vPos, pObj );
// add connections
pObj->pFanin0 = pDriver;
if ( p->fRefCount )
Hop_ObjRef( Hop_Regular(pDriver) );
else
pObj->nRefs = Hop_ObjLevel( Hop_Regular(pDriver) );
// set the phase
pObj->fPhase = Hop_ObjPhaseCompl(pDriver);
// update node counters of the manager
p->nObjs[AIG_PO]++;
return pObj;
}
/**Function*************************************************************
Synopsis [Create the new node assuming it does not exist.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Hop_Obj_t * Hop_ObjCreate( Hop_Man_t * p, Hop_Obj_t * pGhost )
{
Hop_Obj_t * pObj;
assert( !Hop_IsComplement(pGhost) );
assert( Hop_ObjIsNode(pGhost) );
assert( pGhost == &p->Ghost );
// get memory for the new object
pObj = Hop_ManFetchMemory( p );
pObj->Type = pGhost->Type;
// add connections
Hop_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
// update node counters of the manager
p->nObjs[Hop_ObjType(pObj)]++;
assert( pObj->pData == NULL );
return pObj;
}
/**Function*************************************************************
Synopsis [Connect the object to the fanin.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ObjConnect( Hop_Man_t * p, Hop_Obj_t * pObj, Hop_Obj_t * pFan0, Hop_Obj_t * pFan1 )
{
assert( !Hop_IsComplement(pObj) );
assert( Hop_ObjIsNode(pObj) );
// add the first fanin
pObj->pFanin0 = pFan0;
pObj->pFanin1 = pFan1;
// increment references of the fanins and add their fanouts
if ( p->fRefCount )
{
if ( pFan0 != NULL )
Hop_ObjRef( Hop_ObjFanin0(pObj) );
if ( pFan1 != NULL )
Hop_ObjRef( Hop_ObjFanin1(pObj) );
}
else
pObj->nRefs = Hop_ObjLevelNew( pObj );
// set the phase
pObj->fPhase = Hop_ObjPhaseCompl(pFan0) & Hop_ObjPhaseCompl(pFan1);
// add the node to the structural hash table
Hop_TableInsert( p, pObj );
}
/**Function*************************************************************
Synopsis [Connect the object to the fanin.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ObjDisconnect( Hop_Man_t * p, Hop_Obj_t * pObj )
{
assert( !Hop_IsComplement(pObj) );
assert( Hop_ObjIsNode(pObj) );
// remove connections
if ( pObj->pFanin0 != NULL )
Hop_ObjDeref(Hop_ObjFanin0(pObj));
if ( pObj->pFanin1 != NULL )
Hop_ObjDeref(Hop_ObjFanin1(pObj));
// remove the node from the structural hash table
Hop_TableDelete( p, pObj );
// add the first fanin
pObj->pFanin0 = NULL;
pObj->pFanin1 = NULL;
}
/**Function*************************************************************
Synopsis [Deletes the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ObjDelete( Hop_Man_t * p, Hop_Obj_t * pObj )
{
assert( !Hop_IsComplement(pObj) );
assert( !Hop_ObjIsTerm(pObj) );
assert( Hop_ObjRefs(pObj) == 0 );
// update node counters of the manager
p->nObjs[pObj->Type]--;
p->nDeleted++;
// remove connections
Hop_ObjDisconnect( p, pObj );
// remove PIs/POs from the arrays
if ( Hop_ObjIsPi(pObj) )
Vec_PtrRemove( p->vPis, pObj );
// free the node
Hop_ManRecycleMemory( p, pObj );
}
/**Function*************************************************************
Synopsis [Deletes the MFFC of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ObjDelete_rec( Hop_Man_t * p, Hop_Obj_t * pObj )
{
Hop_Obj_t * pFanin0, * pFanin1;
assert( !Hop_IsComplement(pObj) );
if ( Hop_ObjIsConst1(pObj) || Hop_ObjIsPi(pObj) )
return;
assert( Hop_ObjIsNode(pObj) );
pFanin0 = Hop_ObjFanin0(pObj);
pFanin1 = Hop_ObjFanin1(pObj);
Hop_ObjDelete( p, pObj );
if ( pFanin0 && !Hop_ObjIsNone(pFanin0) && Hop_ObjRefs(pFanin0) == 0 )
Hop_ObjDelete_rec( p, pFanin0 );
if ( pFanin1 && !Hop_ObjIsNone(pFanin1) && Hop_ObjRefs(pFanin1) == 0 )
Hop_ObjDelete_rec( p, pFanin1 );
}
/**Function*************************************************************
Synopsis [Returns the representative of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Hop_Obj_t * Hop_ObjRepr( Hop_Obj_t * pObj )
{
assert( !Hop_IsComplement(pObj) );
if ( pObj->pData == NULL || pObj->pData == pObj )
return pObj;
return Hop_ObjRepr( (Hop_Obj_t *)pObj->pData );
}
/**Function*************************************************************
Synopsis [Sets an equivalence relation between the nodes.]
Description [Makes the representative of pNew point to the representaive of pOld.]
SideEffects []
SeeAlso []
***********************************************************************/
void Hop_ObjCreateChoice( Hop_Obj_t * pOld, Hop_Obj_t * pNew )
{
Hop_Obj_t * pOldRepr;
Hop_Obj_t * pNewRepr;
assert( pOld != NULL && pNew != NULL );
pOldRepr = Hop_ObjRepr(pOld);
pNewRepr = Hop_ObjRepr(pNew);
if ( pNewRepr != pOldRepr )
pNewRepr->pData = pOldRepr;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|