abc/src/opt/nwk/nwkFanio.c
/**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     []

***********************************************************************/
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.]




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 . ]
void Nwk_ObjPatchFanin( Nwk_Obj_t * pObj, Nwk_Obj_t * pFaninOld, Nwk_Obj_t * pFaninNew )
{
    int i, k, iFanin, Limit;
    assert( pFaninOld != pFaninNew );
    assert( pObj != pFaninOld );
    assert( pObj != pFaninNew );
    assert( pObj->pMan == pFaninOld->pMan );
    assert( pObj->pMan == pFaninNew->pMan );
    iFanin = Nwk_ObjFindFanin( pObj, pFaninOld );
    if ( iFanin == -1 )
    {
        printf( "Nwk_ObjPatchFanin(); Error! Node %d is not among", pFaninOld->Id );
        printf( " the fanins of node %d...\n", pObj->Id );
        return;
    }
    pObj->pFanio[iFanin] = pFaninNew;
    Limit = pFaninOld->nFanins + pFaninOld->nFanouts;
    for ( k = i = pFaninOld->nFanins; i < Limit; i++ )
        if ( pFaninOld->pFanio[i] != pObj )
            pFaninOld->pFanio[k++] = pFaninOld->pFanio[i];
    pFaninOld->nFanouts--;
    if ( Nwk_ObjReallocIsNeeded(pFaninNew) )
        Nwk_ManReallocNode( pFaninNew );
    pFaninNew->pFanio[pFaninNew->nFanins + pFaninNew->nFanouts++] = pObj;
}
void Nwk_ObjPatchFanin ( Nwk_Obj_t * pObj , Nwk_Obj_t * pFaninOld , Nwk_Obj_t * pFaninNew ) { int i , k , iFanin , Limit ; assert ( pFaninOld != pFaninNew ) ; assert ( pObj != pFaninOld ) ; assert ( pObj != pFaninNew ) ; assert ( pObj -> pMan == pFaninOld -> pMan ) ; assert ( pObj -> pMan == pFaninNew -> pMan ) ; iFanin = Nwk_ObjFindFanin ( pObj , pFaninOld ) ; if ( iFanin == -1 ) { printf ( " " , pFaninOld -> Id ) ; printf ( " \n " , pObj -> Id ) ; return ; } pObj -> pFanio [ iFanin ] = pFaninNew ; Limit = pFaninOld -> nFanins + pFaninOld -> nFanouts ; for ( k = i = pFaninOld -> nFanins ; i < Limit ; i ++ ) if ( pFaninOld -> pFanio [ i ] != pObj ) pFaninOld -> pFanio [ k ++ ] = pFaninOld -> pFanio [ i ] ; pFaninOld -> nFanouts -- ; if ( Nwk_ObjReallocIsNeeded ( pFaninNew ) ) Nwk_ManReallocNode ( pFaninNew ) ; pFaninNew -> pFanio [ pFaninNew -> nFanins + pFaninNew -> nFanouts ++ ] = pObj ; }
Function
Synopsis    [Replaces a fanin of the node.]
Function Synopsis [ Replaces a fanin of the node . ]
// update the fanin // remove pObj from the fanout list of pFaninOld // add pObj to the fanout list of pFaninNew