abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkFanio.c File Reference
#include "nwk.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Nwk_ObjCollectFanins (Nwk_Obj_t *pNode, Vec_Ptr_t *vNodes)
 DECLARATIONS ///. More...
 
void Nwk_ObjCollectFanouts (Nwk_Obj_t *pNode, Vec_Ptr_t *vNodes)
 
int Nwk_ObjFindFanin (Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
 
int Nwk_ObjFindFanout (Nwk_Obj_t *pObj, Nwk_Obj_t *pFanout)
 
static int Nwk_ObjReallocIsNeeded (Nwk_Obj_t *pObj)
 
static Nwk_Obj_tNwk_ManReallocNode (Nwk_Obj_t *pObj)
 
void Nwk_ObjAddFanin (Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
 
void Nwk_ObjDeleteFanin (Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
 
void Nwk_ObjPatchFanin (Nwk_Obj_t *pObj, Nwk_Obj_t *pFaninOld, Nwk_Obj_t *pFaninNew)
 
void Nwk_ObjTransferFanout (Nwk_Obj_t *pNodeFrom, Nwk_Obj_t *pNodeTo)
 
void Nwk_ObjReplace (Nwk_Obj_t *pNodeOld, Nwk_Obj_t *pNodeNew)
 

Function Documentation

static Nwk_Obj_t* Nwk_ManReallocNode ( Nwk_Obj_t pObj)
static

Function*************************************************************

Synopsis [Reallocates the object.]

Description []

SideEffects []

SeeAlso []

Definition at line 143 of file nwkFanio.c.

144 {
145  Nwk_Obj_t ** pFanioOld = pObj->pFanio;
147  pObj->pFanio = (Nwk_Obj_t **)Aig_MmFlexEntryFetch( pObj->pMan->pMemObjs, 2 * pObj->nFanioAlloc * sizeof(Nwk_Obj_t *) );
148  memmove( pObj->pFanio, pFanioOld, pObj->nFanioAlloc * sizeof(Nwk_Obj_t *) );
149  pObj->nFanioAlloc *= 2;
150  pObj->pMan->nRealloced++;
151  return NULL;
152 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Definition: aigMem.c:366
char * memmove()
#define assert(ex)
Definition: util_old.h:213
static int Nwk_ObjReallocIsNeeded(Nwk_Obj_t *pObj)
Definition: nwkFanio.c:127
void Nwk_ObjAddFanin ( Nwk_Obj_t pObj,
Nwk_Obj_t pFanin 
)

Function*************************************************************

Synopsis [Creates fanout/fanin relationship between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file nwkFanio.c.

166 {
167  int i;
168  assert( pObj->pMan == pFanin->pMan );
169  assert( pObj->Id >= 0 && pFanin->Id >= 0 );
170  if ( Nwk_ObjReallocIsNeeded(pObj) )
171  Nwk_ManReallocNode( pObj );
172  if ( Nwk_ObjReallocIsNeeded(pFanin) )
173  Nwk_ManReallocNode( pFanin );
174  for ( i = pObj->nFanins + pObj->nFanouts; i > pObj->nFanins; i-- )
175  pObj->pFanio[i] = pObj->pFanio[i-1];
176  pObj->pFanio[pObj->nFanins++] = pFanin;
177  pFanin->pFanio[pFanin->nFanins + pFanin->nFanouts++] = pObj;
178  pObj->Level = Abc_MaxInt( pObj->Level, pFanin->Level + Nwk_ObjIsNode(pObj) );
179 }
static Nwk_Obj_t * Nwk_ManReallocNode(Nwk_Obj_t *pObj)
Definition: nwkFanio.c:143
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define assert(ex)
Definition: util_old.h:213
static int Nwk_ObjReallocIsNeeded(Nwk_Obj_t *pObj)
Definition: nwkFanio.c:127
ABC_NAMESPACE_IMPL_START void Nwk_ObjCollectFanins ( Nwk_Obj_t pNode,
Vec_Ptr_t vNodes 
)

DECLARATIONS ///.

CFile****************************************************************

FileName [nwkFanio.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Logic network representation.]

Synopsis [Manipulation of fanins/fanouts.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
nwkFanio.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [Collects fanins of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file nwkFanio.c.

46 {
47  Nwk_Obj_t * pFanin;
48  int i;
49  Vec_PtrClear(vNodes);
50  Nwk_ObjForEachFanin( pNode, pFanin, i )
51  Vec_PtrPush( vNodes, pFanin );
52 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Nwk_ObjCollectFanouts ( Nwk_Obj_t pNode,
Vec_Ptr_t vNodes 
)

Function*************************************************************

Synopsis [Collects fanouts of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 65 of file nwkFanio.c.

66 {
67  Nwk_Obj_t * pFanout;
68  int i;
69  Vec_PtrClear(vNodes);
70  Nwk_ObjForEachFanout( pNode, pFanout, i )
71  Vec_PtrPush( vNodes, pFanout );
72 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
static void Vec_PtrClear(Vec_Ptr_t *p)
Definition: vecPtr.h:545
void Nwk_ObjDeleteFanin ( Nwk_Obj_t pObj,
Nwk_Obj_t pFanin 
)

Function*************************************************************

Synopsis [Removes fanout/fanin relationship between the nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 192 of file nwkFanio.c.

193 {
194  int i, k, Limit, fFound;
195  // remove pFanin from the fanin list of pObj
196  Limit = pObj->nFanins + pObj->nFanouts;
197  fFound = 0;
198  for ( k = i = 0; i < Limit; i++ )
199  if ( fFound || pObj->pFanio[i] != pFanin )
200  pObj->pFanio[k++] = pObj->pFanio[i];
201  else
202  fFound = 1;
203  assert( i == k + 1 ); // if it fails, likely because of duplicated fanin
204  pObj->nFanins--;
205  // remove pObj from the fanout list of pFanin
206  Limit = pFanin->nFanins + pFanin->nFanouts;
207  fFound = 0;
208  for ( k = i = pFanin->nFanins; i < Limit; i++ )
209  if ( fFound || pFanin->pFanio[i] != pObj )
210  pFanin->pFanio[k++] = pFanin->pFanio[i];
211  else
212  fFound = 1;
213  assert( i == k + 1 ); // if it fails, likely because of duplicated fanout
214  pFanin->nFanouts--;
215 }
#define assert(ex)
Definition: util_old.h:213
int Nwk_ObjFindFanin ( Nwk_Obj_t pObj,
Nwk_Obj_t pFanin 
)

Function*************************************************************

Synopsis [Returns the number of the fanin of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 85 of file nwkFanio.c.

86 {
87  Nwk_Obj_t * pTemp;
88  int i;
89  Nwk_ObjForEachFanin( pObj, pTemp, i )
90  if ( pTemp == pFanin )
91  return i;
92  return -1;
93 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
if(last==0)
Definition: sparse_int.h:34
#define Nwk_ObjForEachFanin(pObj, pFanin, i)
Definition: nwk.h:199
int Nwk_ObjFindFanout ( Nwk_Obj_t pObj,
Nwk_Obj_t pFanout 
)

Function*************************************************************

Synopsis [Returns the number of the fanout of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 106 of file nwkFanio.c.

107 {
108  Nwk_Obj_t * pTemp;
109  int i;
110  Nwk_ObjForEachFanout( pObj, pTemp, i )
111  if ( pTemp == pFanout )
112  return i;
113  return -1;
114 }
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
#define Nwk_ObjForEachFanout(pObj, pFanout, i)
Definition: nwk.h:201
if(last==0)
Definition: sparse_int.h:34
void Nwk_ObjPatchFanin ( Nwk_Obj_t pObj,
Nwk_Obj_t pFaninOld,
Nwk_Obj_t pFaninNew 
)

Function*************************************************************

Synopsis [Replaces a fanin of the node.]

Description [The node is pObj. An old fanin of this node (pFaninOld) has to be replaced by a new fanin (pFaninNew). Assumes that the node and the old fanin are not complemented. The new fanin can be complemented. In this case, the polarity of the new fanin will change, compared to the polarity of the old fanin.]

SideEffects []

SeeAlso []

Definition at line 231 of file nwkFanio.c.

232 {
233  int i, k, iFanin, Limit;
234  assert( pFaninOld != pFaninNew );
235  assert( pObj != pFaninOld );
236  assert( pObj != pFaninNew );
237  assert( pObj->pMan == pFaninOld->pMan );
238  assert( pObj->pMan == pFaninNew->pMan );
239  // update the fanin
240  iFanin = Nwk_ObjFindFanin( pObj, pFaninOld );
241  if ( iFanin == -1 )
242  {
243  printf( "Nwk_ObjPatchFanin(); Error! Node %d is not among", pFaninOld->Id );
244  printf( " the fanins of node %d...\n", pObj->Id );
245  return;
246  }
247  pObj->pFanio[iFanin] = pFaninNew;
248  // remove pObj from the fanout list of pFaninOld
249  Limit = pFaninOld->nFanins + pFaninOld->nFanouts;
250  for ( k = i = pFaninOld->nFanins; i < Limit; i++ )
251  if ( pFaninOld->pFanio[i] != pObj )
252  pFaninOld->pFanio[k++] = pFaninOld->pFanio[i];
253  pFaninOld->nFanouts--;
254  // add pObj to the fanout list of pFaninNew
255  if ( Nwk_ObjReallocIsNeeded(pFaninNew) )
256  Nwk_ManReallocNode( pFaninNew );
257  pFaninNew->pFanio[pFaninNew->nFanins + pFaninNew->nFanouts++] = pObj;
258 }
static Nwk_Obj_t * Nwk_ManReallocNode(Nwk_Obj_t *pObj)
Definition: nwkFanio.c:143
int Nwk_ObjFindFanin(Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
Definition: nwkFanio.c:85
#define assert(ex)
Definition: util_old.h:213
static int Nwk_ObjReallocIsNeeded(Nwk_Obj_t *pObj)
Definition: nwkFanio.c:127
static int Nwk_ObjReallocIsNeeded ( Nwk_Obj_t pObj)
inlinestatic

Function*************************************************************

Synopsis [Returns 1 if the node has to be reallocated.]

Description []

SideEffects []

SeeAlso []

Definition at line 127 of file nwkFanio.c.

128 {
129  return pObj->nFanins + pObj->nFanouts == pObj->nFanioAlloc;
130 }
void Nwk_ObjReplace ( Nwk_Obj_t pNodeOld,
Nwk_Obj_t pNodeNew 
)

Function*************************************************************

Synopsis [Replaces the node by a new node.]

Description []

SideEffects []

SeeAlso []

Definition at line 302 of file nwkFanio.c.

303 {
304  assert( pNodeOld->pMan == pNodeNew->pMan );
305  assert( pNodeOld != pNodeNew );
306  assert( Nwk_ObjFanoutNum(pNodeOld) > 0 );
307  // transfer the fanouts to the old node
308  Nwk_ObjTransferFanout( pNodeOld, pNodeNew );
309  // remove the old node
310  Nwk_ManDeleteNode_rec( pNodeOld );
311 }
ABC_DLL void Nwk_ManDeleteNode_rec(Nwk_Obj_t *pObj)
Definition: nwkObj.c:183
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
#define assert(ex)
Definition: util_old.h:213
void Nwk_ObjTransferFanout(Nwk_Obj_t *pNodeFrom, Nwk_Obj_t *pNodeTo)
Definition: nwkFanio.c:272
void Nwk_ObjTransferFanout ( Nwk_Obj_t pNodeFrom,
Nwk_Obj_t pNodeTo 
)

Function*************************************************************

Synopsis [Transfers fanout from the old node to the new node.]

Description []

SideEffects []

SeeAlso []

Definition at line 272 of file nwkFanio.c.

273 {
274  Vec_Ptr_t * vFanouts = pNodeFrom->pMan->vTemp;
275  Nwk_Obj_t * pTemp;
276  int nFanoutsOld, i;
277  assert( !Nwk_ObjIsCo(pNodeFrom) && !Nwk_ObjIsCo(pNodeTo) );
278  assert( pNodeFrom->pMan == pNodeTo->pMan );
279  assert( pNodeFrom != pNodeTo );
280  assert( Nwk_ObjFanoutNum(pNodeFrom) > 0 );
281  // get the fanouts of the old node
282  nFanoutsOld = Nwk_ObjFanoutNum(pNodeTo);
283  Nwk_ObjCollectFanouts( pNodeFrom, vFanouts );
284  // patch the fanin of each of them
285  Vec_PtrForEachEntry( Nwk_Obj_t *, vFanouts, pTemp, i )
286  Nwk_ObjPatchFanin( pTemp, pNodeFrom, pNodeTo );
287  assert( Nwk_ObjFanoutNum(pNodeFrom) == 0 );
288  assert( Nwk_ObjFanoutNum(pNodeTo) == nFanoutsOld + Vec_PtrSize(vFanouts) );
289 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static int Nwk_ObjIsCo(Nwk_Obj_t *p)
Definition: nwk.h:147
void Nwk_ObjCollectFanouts(Nwk_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: nwkFanio.c:65
void Nwk_ObjPatchFanin(Nwk_Obj_t *pObj, Nwk_Obj_t *pFaninOld, Nwk_Obj_t *pFaninNew)
Definition: nwkFanio.c:231
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55