abc/src/base/abc/abcHie.c
/**Function*************************************************************

  Synopsis    [Inserts blackboxes into the netlist.]

  Description [The first arg is the netlist with blackboxes without logic hierarchy.
  The second arg is a non-hierarchical netlist derived from the above netlist after processing.
  This procedure create a new netlist, which is comparable to the original netlist with
  blackboxes, except that it contains logic nodes from the netlist after processing.]
               
  SideEffects [This procedure silently assumes that blackboxes appear
  only in the top-level model. If they appear in other models as well, 
  the name of the model and its number were appended to the names of 
  blackbox inputs/outputs.]

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Inserts blackboxes into the netlist.]

Description [The first arg is the netlist with blackboxes without logic hierarchy.
The second arg is a non-hierarchical netlist derived from the above netlist after processing.
This procedure create a new netlist, which is comparable to the original netlist with
blackboxes, except that it contains logic nodes from the netlist after processing.]

SideEffects [This procedure silently assumes that blackboxes appear
only in the top-level model. If they appear in other models as well,
the name of the model and its number were appended to the names of
blackbox inputs/outputs.]


Function Synopsis [ Inserts blackboxes into the netlist . ] Description [ The first arg is the netlist with blackboxes without logic hierarchy . The second arg is a non - hierarchical netlist derived from the above netlist after processing . This procedure create a new netlist which is comparable to the original netlist with blackboxes except that it contains logic nodes from the netlist after processing . ] SideEffects [ This procedure silently assumes that blackboxes appear only in the top - level model . If they appear in other models as well the name of the model and its number were appended to the names of blackbox inputs / outputs . ]
Abc_Ntk_t * Abc_NtkInsertNewLogic( Abc_Ntk_t * pNtkH, Abc_Ntk_t * pNtkL )
{
    Abc_Des_t * pDesign;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pObjH, * pObjL, * pNetH, * pNetL, * pTermH;
    int i, k;
    assert( Abc_NtkIsNetlist(pNtkH) );
    assert( Abc_NtkWhiteboxNum(pNtkH) == 0 );
    assert( Abc_NtkBlackboxNum(pNtkH) > 0 );
    assert( Abc_NtkIsNetlist(pNtkL) );
    assert( Abc_NtkWhiteboxNum(pNtkL) == 0 );
    assert( Abc_NtkBlackboxNum(pNtkL) == 0 );
    Abc_NtkCleanCopy( pNtkL );
    pNtkNew = Abc_NtkAlloc( pNtkL->ntkType, pNtkL->ntkFunc, 1 );
    pNtkNew->pName = Extra_UtilStrsav( pNtkH->pName );
    pNtkNew->pSpec = Extra_UtilStrsav( pNtkH->pSpec );
    Abc_NtkForEachPi( pNtkH, pObjH, i )
    {
        pNetH = Abc_ObjFanout0(pObjH);
        pNetL = Abc_NtkFindNet( pNtkL, Abc_ObjName(pNetH) );
        if ( pNetL == NULL || !Abc_ObjIsPi( Abc_ObjFanin0(pNetL) ) )
        {
            printf( "Error in Abc_NtkInsertNewLogic(): There is no PI corresponding to the PI %s.\n", Abc_ObjName(pNetH) );
            Abc_NtkDelete( pNtkNew );
            return NULL;
        }
        if ( pNetL->pCopy )
        {
            printf( "Error in Abc_NtkInsertNewLogic(): Primary input %s is repeated twice.\n", Abc_ObjName(pNetH) );
            Abc_NtkDelete( pNtkNew );
            return NULL;
        }
        pNetL->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjName(pNetH) );
        Abc_NtkDupObj( pNtkNew, Abc_ObjFanin0(pNetL), 0 );
    }
    Abc_NtkForEachBlackbox( pNtkH, pObjH, i )
    {
        Abc_NtkDupBox( pNtkNew, pObjH, 0 );
        pObjH->pCopy->pData = pObjH->pData;
        Abc_ObjForEachFanout( pObjH, pTermH, k )
        {
            pNetH = Abc_ObjFanout0( pTermH );
            pNetL = Abc_NtkFindNet( pNtkL, Abc_ObjName(pNetH) );
            if ( pNetL == NULL || !Abc_ObjIsPi( Abc_ObjFanin0(pNetL) ) )
            {
                printf( "Error in Abc_NtkInsertNewLogic(): There is no PI corresponding to the inpout %s of blackbox %s.\n", Abc_ObjName(pNetH), Abc_ObjName(pObjH) );
                Abc_NtkDelete( pNtkNew );
                return NULL;
            }
            if ( pNetL->pCopy )
            {
                printf( "Error in Abc_NtkInsertNewLogic(): Box output %s is repeated twice.\n", Abc_ObjName(pNetH) );
                Abc_NtkDelete( pNtkNew );
                return NULL;
            }
            pNetL->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjName(pNetH) );
            Abc_ObjFanin0(pNetL)->pCopy = pTermH->pCopy;
        }
    }
    Abc_NtkForEachPo( pNtkH, pObjH, i )
    {
        pNetH = Abc_ObjFanin0(pObjH);
        pNetL = Abc_NtkFindNet( pNtkL, Abc_ObjName(pNetH) );
        if ( pNetL == NULL || !Abc_ObjIsPo( Abc_ObjFanout0(pNetL) ) )
        {
            printf( "Error in Abc_NtkInsertNewLogic(): There is no PO corresponding to the PO %s.\n", Abc_ObjName(pNetH) );
            Abc_NtkDelete( pNtkNew );
            return NULL;
        }
        if ( pNetL->pCopy )
            continue;
        pNetL->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjName(pNetH) );
        Abc_NtkDupObj( pNtkNew, Abc_ObjFanout0(pNetL), 0 );
    }
    Abc_NtkForEachBlackbox( pNtkH, pObjH, i )
    {
        Abc_ObjForEachFanin( pObjH, pTermH, k )
        {
            char * pName;
            pNetH = Abc_ObjFanin0( pTermH );
            pName = Abc_ObjName(pNetH);
            pNetL = Abc_NtkFindNet( pNtkL, Abc_ObjName(pNetH) );
            if ( pNetL == NULL || !Abc_ObjIsPo( Abc_ObjFanout0(pNetL) ) )
            {
                printf( "There is no PO corresponding to the input %s of blackbox %s.\n", Abc_ObjName(pNetH), Abc_ObjName(pObjH) );
                Abc_NtkDelete( pNtkNew );
                return NULL;
            }
            if ( pNetL->pCopy )
            {
                if ( Abc_ObjFanout0(pNetL)->pCopy == NULL )
                    Abc_ObjFanout0(pNetL)->pCopy = pTermH->pCopy;
                else
                    Abc_ObjAddFanin( pTermH->pCopy, pNetL->pCopy );
                continue;
            }
            pNetL->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjName(pNetH) );
            Abc_ObjFanout0(pNetL)->pCopy = pTermH->pCopy;
        }
    }
    Abc_NtkForEachObj( pNtkL, pObjL, i )
        if ( pObjL->pCopy == NULL && !Abc_ObjIsPo(pObjL) ) 
            Abc_NtkDupObj( pNtkNew, pObjL, Abc_ObjIsNet(pObjL) );
    Abc_NtkForEachObj( pNtkL, pObjL, i )
        Abc_ObjForEachFanin( pObjL, pNetL, k )
            if ( pObjL->pCopy )
                Abc_ObjAddFanin( pObjL->pCopy, pNetL->pCopy );
    pDesign = pNtkH->pDesign;  pNtkH->pDesign = NULL;
    assert( Vec_PtrEntry( pDesign->vModules, 0 ) == pNtkH );
    Vec_PtrWriteEntry( pDesign->vModules, 0, pNtkNew );
    pNtkNew->pDesign = pDesign;
    if ( !Abc_NtkCheck( pNtkNew ) )
    {
        fprintf( stdout, "Abc_NtkInsertNewLogic(): Network check has failed.\n" );
        Abc_NtkDelete( pNtkNew );
        return NULL;
    }
    return pNtkNew;
}
Abc_Ntk_t * Abc_NtkInsertNewLogic ( Abc_Ntk_t * pNtkH , Abc_Ntk_t * pNtkL ) { Abc_Des_t * pDesign ; Abc_Ntk_t * pNtkNew ; Abc_Obj_t * pObjH , * pObjL , * pNetH , * pNetL , * pTermH ; int i , k ; assert ( Abc_NtkIsNetlist ( pNtkH ) ) ; assert ( Abc_NtkWhiteboxNum ( pNtkH ) == 0 ) ; assert ( Abc_NtkBlackboxNum ( pNtkH ) > 0 ) ; assert ( Abc_NtkIsNetlist ( pNtkL ) ) ; assert ( Abc_NtkWhiteboxNum ( pNtkL ) == 0 ) ; assert ( Abc_NtkBlackboxNum ( pNtkL ) == 0 ) ; Abc_NtkCleanCopy ( pNtkL ) ; pNtkNew = Abc_NtkAlloc ( pNtkL -> ntkType , pNtkL -> ntkFunc , 1 ) ; pNtkNew -> pName = Extra_UtilStrsav ( pNtkH -> pName ) ; pNtkNew -> pSpec = Extra_UtilStrsav ( pNtkH -> pSpec ) ; Abc_NtkForEachPi ( pNtkH , pObjH , i ) { pNetH = Abc_ObjFanout0 ( pObjH ) ; pNetL = Abc_NtkFindNet ( pNtkL , Abc_ObjName ( pNetH ) ) ; if ( pNetL == NULL || ! Abc_ObjIsPi ( Abc_ObjFanin0 ( pNetL ) ) ) { printf ( " \n " , Abc_ObjName ( pNetH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } if ( pNetL -> pCopy ) { printf ( " \n " , Abc_ObjName ( pNetH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } pNetL -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjName ( pNetH ) ) ; Abc_NtkDupObj ( pNtkNew , Abc_ObjFanin0 ( pNetL ) , 0 ) ; } Abc_NtkForEachBlackbox ( pNtkH , pObjH , i ) { Abc_NtkDupBox ( pNtkNew , pObjH , 0 ) ; pObjH -> pCopy -> pData = pObjH -> pData ; Abc_ObjForEachFanout ( pObjH , pTermH , k ) { pNetH = Abc_ObjFanout0 ( pTermH ) ; pNetL = Abc_NtkFindNet ( pNtkL , Abc_ObjName ( pNetH ) ) ; if ( pNetL == NULL || ! Abc_ObjIsPi ( Abc_ObjFanin0 ( pNetL ) ) ) { printf ( " \n " , Abc_ObjName ( pNetH ) , Abc_ObjName ( pObjH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } if ( pNetL -> pCopy ) { printf ( " \n " , Abc_ObjName ( pNetH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } pNetL -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjName ( pNetH ) ) ; Abc_ObjFanin0 ( pNetL ) -> pCopy = pTermH -> pCopy ; } } Abc_NtkForEachPo ( pNtkH , pObjH , i ) { pNetH = Abc_ObjFanin0 ( pObjH ) ; pNetL = Abc_NtkFindNet ( pNtkL , Abc_ObjName ( pNetH ) ) ; if ( pNetL == NULL || ! Abc_ObjIsPo ( Abc_ObjFanout0 ( pNetL ) ) ) { printf ( " \n " , Abc_ObjName ( pNetH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } if ( pNetL -> pCopy ) continue ; pNetL -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjName ( pNetH ) ) ; Abc_NtkDupObj ( pNtkNew , Abc_ObjFanout0 ( pNetL ) , 0 ) ; } Abc_NtkForEachBlackbox ( pNtkH , pObjH , i ) { Abc_ObjForEachFanin ( pObjH , pTermH , k ) { char * pName ; pNetH = Abc_ObjFanin0 ( pTermH ) ; pName = Abc_ObjName ( pNetH ) ; pNetL = Abc_NtkFindNet ( pNtkL , Abc_ObjName ( pNetH ) ) ; if ( pNetL == NULL || ! Abc_ObjIsPo ( Abc_ObjFanout0 ( pNetL ) ) ) { printf ( " \n " , Abc_ObjName ( pNetH ) , Abc_ObjName ( pObjH ) ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } if ( pNetL -> pCopy ) { if ( Abc_ObjFanout0 ( pNetL ) -> pCopy == NULL ) Abc_ObjFanout0 ( pNetL ) -> pCopy = pTermH -> pCopy ; else Abc_ObjAddFanin ( pTermH -> pCopy , pNetL -> pCopy ) ; continue ; } pNetL -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjName ( pNetH ) ) ; Abc_ObjFanout0 ( pNetL ) -> pCopy = pTermH -> pCopy ; } } Abc_NtkForEachObj ( pNtkL , pObjL , i ) if ( pObjL -> pCopy == NULL && ! Abc_ObjIsPo ( pObjL ) ) Abc_NtkDupObj ( pNtkNew , pObjL , Abc_ObjIsNet ( pObjL ) ) ; Abc_NtkForEachObj ( pNtkL , pObjL , i ) Abc_ObjForEachFanin ( pObjL , pNetL , k ) if ( pObjL -> pCopy ) Abc_ObjAddFanin ( pObjL -> pCopy , pNetL -> pCopy ) ; pDesign = pNtkH -> pDesign ; pNtkH -> pDesign = NULL ; assert ( Vec_PtrEntry ( pDesign -> vModules , 0 ) == pNtkH ) ; Vec_PtrWriteEntry ( pDesign -> vModules , 0 , pNtkNew ) ; pNtkNew -> pDesign = pDesign ; if ( ! Abc_NtkCheck ( pNtkNew ) ) { fprintf ( stdout , " \n " ) ; Abc_NtkDelete ( pNtkNew ) ; return NULL ; } return pNtkNew ; }
Function
Synopsis    [Inserts blackboxes into the netlist.]
Function Synopsis [ Inserts blackboxes into the netlist . ]
// prepare the logic network for copying // start the network // duplicate the name and the spec // make sure every PI/PO has a PI/PO in the processed network // create the new net // make sure every BB has a PI/PO in the processed network // duplicate the box  // create PIs // create net and map the PI // create the new net // create net and map the PO // duplicate other objects of the logic network // skip POs feeding into PIs // connect objects // transfer the design // check integrity