abc/src/aig/aig/aigObj.c
/**Function*************************************************************

  Synopsis    [Replaces one object by another.]

  Description [The new object (pObjNew) should be used instead of the old 
  object (pObjOld). If the new object is complemented or used, the buffer 
  is added and the new object remains in the manager; otherwise, the new
  object is deleted.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Replaces one object by another.]

Description [The new object (pObjNew) should be used instead of the old
object (pObjOld). If the new object is complemented or used, the buffer
is added and the new object remains in the manager; otherwise, the new
object is deleted.]




Function Synopsis [ Replaces one object by another . ] Description [ The new object ( pObjNew ) should be used instead of the old object ( pObjOld ) . If the new object is complemented or used the buffer is added and the new object remains in the manager ; otherwise the new object is deleted . ]
void Aig_ObjReplace( Aig_Man_t * p, Aig_Obj_t * pObjOld, Aig_Obj_t * pObjNew, int fUpdateLevel )
{
    Aig_Obj_t * pObjNewR = Aig_Regular(pObjNew);
    assert( !Aig_IsComplement(pObjOld) );
    assert( !Aig_ObjIsCi(pObjOld) && !Aig_ObjIsCo(pObjOld) );
    assert( !Aig_ObjIsBuf(pObjNewR) && !Aig_ObjIsCo(pObjNewR) );
    assert( pObjOld != pObjNewR );
    assert( pObjOld != Aig_ObjFanin0(pObjNewR) );
    assert( pObjOld != Aig_ObjFanin1(pObjNewR) );
    if ( pObjOld == Aig_ObjFanin0(pObjNewR) || pObjOld == Aig_ObjFanin1(pObjNewR) )
    {
        printf( "Aig_ObjReplace(): Internal error!\n" );
        exit(1);
    }
    pObjNewR->nRefs++;
    Aig_ObjDelete_rec( p, pObjOld, 0 );
    pObjNewR->nRefs--;
    p->nObjs[pObjOld->Type]--;
    if ( Aig_IsComplement(pObjNew) || Aig_ObjRefs(pObjNew) > 0 || !Aig_ObjIsNode(pObjNew) )
    {
        pObjOld->Type = AIG_OBJ_BUF;
        Aig_ObjConnect( p, pObjOld, pObjNew, NULL );
        p->nBufReplaces++;
    }
    else
    {
        Aig_Obj_t * pFanin0 = pObjNew->pFanin0;
        Aig_Obj_t * pFanin1 = pObjNew->pFanin1;
        int LevelOld = pObjOld->Level;
        pObjOld->Type = pObjNew->Type;
        Aig_ObjDisconnect( p, pObjNew );
        Aig_ObjConnect( p, pObjOld, pFanin0, pFanin1 );
        Aig_ObjDelete( p, pObjNew );
        if ( p->pFanData )
        {
            pObjOld->Level = LevelOld;
            Aig_ManUpdateLevel( p, pObjOld );
        }
        if ( fUpdateLevel )
        {
            Aig_ObjClearReverseLevel( p, pObjOld );
            Aig_ManUpdateReverseLevel( p, pObjOld );
        }
    }
    p->nObjs[pObjOld->Type]++;
    if ( p->pFanData && Aig_ObjIsBuf(pObjOld) )
    {
        Vec_PtrPush( p->vBufs, pObjOld );
        p->nBufMax = Abc_MaxInt( p->nBufMax, Vec_PtrSize(p->vBufs) );
        Aig_ManPropagateBuffers( p, fUpdateLevel );
    }
}
void Aig_ObjReplace ( Aig_Man_t * p , Aig_Obj_t * pObjOld , Aig_Obj_t * pObjNew , int fUpdateLevel ) { Aig_Obj_t * pObjNewR = Aig_Regular ( pObjNew ) ; assert ( ! Aig_IsComplement ( pObjOld ) ) ; assert ( ! Aig_ObjIsCi ( pObjOld ) && ! Aig_ObjIsCo ( pObjOld ) ) ; assert ( ! Aig_ObjIsBuf ( pObjNewR ) && ! Aig_ObjIsCo ( pObjNewR ) ) ; assert ( pObjOld != pObjNewR ) ; assert ( pObjOld != Aig_ObjFanin0 ( pObjNewR ) ) ; assert ( pObjOld != Aig_ObjFanin1 ( pObjNewR ) ) ; if ( pObjOld == Aig_ObjFanin0 ( pObjNewR ) || pObjOld == Aig_ObjFanin1 ( pObjNewR ) ) { printf ( " \n " ) ; exit ( 1 ) ; } pObjNewR -> nRefs ++ ; Aig_ObjDelete_rec ( p , pObjOld , 0 ) ; pObjNewR -> nRefs -- ; p -> nObjs [ pObjOld -> Type ] -- ; if ( Aig_IsComplement ( pObjNew ) || Aig_ObjRefs ( pObjNew ) > 0 || ! Aig_ObjIsNode ( pObjNew ) ) { pObjOld -> Type = AIG_OBJ_BUF ; Aig_ObjConnect ( p , pObjOld , pObjNew , NULL ) ; p -> nBufReplaces ++ ; } else { Aig_Obj_t * pFanin0 = pObjNew -> pFanin0 ; Aig_Obj_t * pFanin1 = pObjNew -> pFanin1 ; int LevelOld = pObjOld -> Level ; pObjOld -> Type = pObjNew -> Type ; Aig_ObjDisconnect ( p , pObjNew ) ; Aig_ObjConnect ( p , pObjOld , pFanin0 , pFanin1 ) ; Aig_ObjDelete ( p , pObjNew ) ; if ( p -> pFanData ) { pObjOld -> Level = LevelOld ; Aig_ManUpdateLevel ( p , pObjOld ) ; } if ( fUpdateLevel ) { Aig_ObjClearReverseLevel ( p , pObjOld ) ; Aig_ManUpdateReverseLevel ( p , pObjOld ) ; } } p -> nObjs [ pObjOld -> Type ] ++ ; if ( p -> pFanData && Aig_ObjIsBuf ( pObjOld ) ) { Vec_PtrPush ( p -> vBufs , pObjOld ) ; p -> nBufMax = Abc_MaxInt ( p -> nBufMax , Vec_PtrSize ( p -> vBufs ) ) ; Aig_ManPropagateBuffers ( p , fUpdateLevel ) ; } }
Function
Synopsis    [Replaces one object by another.]
Function Synopsis [ Replaces one object by another . ]
// the object to be replaced cannot be complemented // the object to be replaced cannot be a terminal // the object to be used cannot be a buffer or a PO // the object cannot be the same // make sure object is not pointing to itself // recursively delete the old node - but leave the object there // if the new object is complemented or already used, create a buffer // delete the new object // update levels // store buffers if fanout is allocated