1 /**CFile****************************************************************
2
3 FileName [hopObj.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Minimalistic And-Inverter Graph package.]
8
9 Synopsis [Adding/removing objects.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - May 11, 2006.]
16
17 Revision [$Id: hopObj.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "hop.h"
22
23 ABC_NAMESPACE_IMPL_START
24
25
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33
34 /**Function*************************************************************
35
36 Synopsis [Creates primary input.]
37
38 Description []
39
40 SideEffects []
41
42 SeeAlso []
43
44 ***********************************************************************/
Hop_ObjCreatePi(Hop_Man_t * p)45 Hop_Obj_t * Hop_ObjCreatePi( Hop_Man_t * p )
46 {
47 Hop_Obj_t * pObj;
48 pObj = Hop_ManFetchMemory( p );
49 pObj->Type = AIG_PI;
50 pObj->PioNum = Vec_PtrSize( p->vPis );
51 Vec_PtrPush( p->vPis, pObj );
52 p->nObjs[AIG_PI]++;
53 return pObj;
54 }
55
56 /**Function*************************************************************
57
58 Synopsis [Creates primary output with the given driver.]
59
60 Description []
61
62 SideEffects []
63
64 SeeAlso []
65
66 ***********************************************************************/
Hop_ObjCreatePo(Hop_Man_t * p,Hop_Obj_t * pDriver)67 Hop_Obj_t * Hop_ObjCreatePo( Hop_Man_t * p, Hop_Obj_t * pDriver )
68 {
69 Hop_Obj_t * pObj;
70 pObj = Hop_ManFetchMemory( p );
71 pObj->Type = AIG_PO;
72 Vec_PtrPush( p->vPos, pObj );
73 // add connections
74 pObj->pFanin0 = pDriver;
75 if ( p->fRefCount )
76 Hop_ObjRef( Hop_Regular(pDriver) );
77 else
78 pObj->nRefs = Hop_ObjLevel( Hop_Regular(pDriver) );
79 // set the phase
80 pObj->fPhase = Hop_ObjPhaseCompl(pDriver);
81 // update node counters of the manager
82 p->nObjs[AIG_PO]++;
83 return pObj;
84 }
85
86 /**Function*************************************************************
87
88 Synopsis [Create the new node assuming it does not exist.]
89
90 Description []
91
92 SideEffects []
93
94 SeeAlso []
95
96 ***********************************************************************/
Hop_ObjCreate(Hop_Man_t * p,Hop_Obj_t * pGhost)97 Hop_Obj_t * Hop_ObjCreate( Hop_Man_t * p, Hop_Obj_t * pGhost )
98 {
99 Hop_Obj_t * pObj;
100 assert( !Hop_IsComplement(pGhost) );
101 assert( Hop_ObjIsNode(pGhost) );
102 assert( pGhost == &p->Ghost );
103 // get memory for the new object
104 pObj = Hop_ManFetchMemory( p );
105 pObj->Type = pGhost->Type;
106 // add connections
107 Hop_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 );
108 // update node counters of the manager
109 p->nObjs[Hop_ObjType(pObj)]++;
110 assert( pObj->pData == NULL );
111 return pObj;
112 }
113
114 /**Function*************************************************************
115
116 Synopsis [Connect the object to the fanin.]
117
118 Description []
119
120 SideEffects []
121
122 SeeAlso []
123
124 ***********************************************************************/
Hop_ObjConnect(Hop_Man_t * p,Hop_Obj_t * pObj,Hop_Obj_t * pFan0,Hop_Obj_t * pFan1)125 void Hop_ObjConnect( Hop_Man_t * p, Hop_Obj_t * pObj, Hop_Obj_t * pFan0, Hop_Obj_t * pFan1 )
126 {
127 assert( !Hop_IsComplement(pObj) );
128 assert( Hop_ObjIsNode(pObj) );
129 // add the first fanin
130 pObj->pFanin0 = pFan0;
131 pObj->pFanin1 = pFan1;
132 // increment references of the fanins and add their fanouts
133 if ( p->fRefCount )
134 {
135 if ( pFan0 != NULL )
136 Hop_ObjRef( Hop_ObjFanin0(pObj) );
137 if ( pFan1 != NULL )
138 Hop_ObjRef( Hop_ObjFanin1(pObj) );
139 }
140 else
141 pObj->nRefs = Hop_ObjLevelNew( pObj );
142 // set the phase
143 pObj->fPhase = Hop_ObjPhaseCompl(pFan0) & Hop_ObjPhaseCompl(pFan1);
144 // add the node to the structural hash table
145 Hop_TableInsert( p, pObj );
146 }
147
148 /**Function*************************************************************
149
150 Synopsis [Connect the object to the fanin.]
151
152 Description []
153
154 SideEffects []
155
156 SeeAlso []
157
158 ***********************************************************************/
Hop_ObjDisconnect(Hop_Man_t * p,Hop_Obj_t * pObj)159 void Hop_ObjDisconnect( Hop_Man_t * p, Hop_Obj_t * pObj )
160 {
161 assert( !Hop_IsComplement(pObj) );
162 assert( Hop_ObjIsNode(pObj) );
163 // remove connections
164 if ( pObj->pFanin0 != NULL )
165 Hop_ObjDeref(Hop_ObjFanin0(pObj));
166 if ( pObj->pFanin1 != NULL )
167 Hop_ObjDeref(Hop_ObjFanin1(pObj));
168 // remove the node from the structural hash table
169 Hop_TableDelete( p, pObj );
170 // add the first fanin
171 pObj->pFanin0 = NULL;
172 pObj->pFanin1 = NULL;
173 }
174
175 /**Function*************************************************************
176
177 Synopsis [Deletes the node.]
178
179 Description []
180
181 SideEffects []
182
183 SeeAlso []
184
185 ***********************************************************************/
Hop_ObjDelete(Hop_Man_t * p,Hop_Obj_t * pObj)186 void Hop_ObjDelete( Hop_Man_t * p, Hop_Obj_t * pObj )
187 {
188 assert( !Hop_IsComplement(pObj) );
189 assert( !Hop_ObjIsTerm(pObj) );
190 assert( Hop_ObjRefs(pObj) == 0 );
191 // update node counters of the manager
192 p->nObjs[pObj->Type]--;
193 p->nDeleted++;
194 // remove connections
195 Hop_ObjDisconnect( p, pObj );
196 // remove PIs/POs from the arrays
197 if ( Hop_ObjIsPi(pObj) )
198 Vec_PtrRemove( p->vPis, pObj );
199 // free the node
200 Hop_ManRecycleMemory( p, pObj );
201 }
202
203 /**Function*************************************************************
204
205 Synopsis [Deletes the MFFC of the node.]
206
207 Description []
208
209 SideEffects []
210
211 SeeAlso []
212
213 ***********************************************************************/
Hop_ObjDelete_rec(Hop_Man_t * p,Hop_Obj_t * pObj)214 void Hop_ObjDelete_rec( Hop_Man_t * p, Hop_Obj_t * pObj )
215 {
216 Hop_Obj_t * pFanin0, * pFanin1;
217 assert( !Hop_IsComplement(pObj) );
218 if ( Hop_ObjIsConst1(pObj) || Hop_ObjIsPi(pObj) )
219 return;
220 assert( Hop_ObjIsNode(pObj) );
221 pFanin0 = Hop_ObjFanin0(pObj);
222 pFanin1 = Hop_ObjFanin1(pObj);
223 Hop_ObjDelete( p, pObj );
224 if ( pFanin0 && !Hop_ObjIsNone(pFanin0) && Hop_ObjRefs(pFanin0) == 0 )
225 Hop_ObjDelete_rec( p, pFanin0 );
226 if ( pFanin1 && !Hop_ObjIsNone(pFanin1) && Hop_ObjRefs(pFanin1) == 0 )
227 Hop_ObjDelete_rec( p, pFanin1 );
228 }
229
230 /**Function*************************************************************
231
232 Synopsis [Returns the representative of the node.]
233
234 Description []
235
236 SideEffects []
237
238 SeeAlso []
239
240 ***********************************************************************/
Hop_ObjRepr(Hop_Obj_t * pObj)241 Hop_Obj_t * Hop_ObjRepr( Hop_Obj_t * pObj )
242 {
243 assert( !Hop_IsComplement(pObj) );
244 if ( pObj->pData == NULL || pObj->pData == pObj )
245 return pObj;
246 return Hop_ObjRepr( (Hop_Obj_t *)pObj->pData );
247 }
248
249 /**Function*************************************************************
250
251 Synopsis [Sets an equivalence relation between the nodes.]
252
253 Description [Makes the representative of pNew point to the representaive of pOld.]
254
255 SideEffects []
256
257 SeeAlso []
258
259 ***********************************************************************/
Hop_ObjCreateChoice(Hop_Obj_t * pOld,Hop_Obj_t * pNew)260 void Hop_ObjCreateChoice( Hop_Obj_t * pOld, Hop_Obj_t * pNew )
261 {
262 Hop_Obj_t * pOldRepr;
263 Hop_Obj_t * pNewRepr;
264 assert( pOld != NULL && pNew != NULL );
265 pOldRepr = Hop_ObjRepr(pOld);
266 pNewRepr = Hop_ObjRepr(pNew);
267 if ( pNewRepr != pOldRepr )
268 pNewRepr->pData = pOldRepr;
269 }
270
271 ////////////////////////////////////////////////////////////////////////
272 /// END OF FILE ///
273 ////////////////////////////////////////////////////////////////////////
274
275
276 ABC_NAMESPACE_IMPL_END
277
278