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

  Synopsis    [Recursively flattens logic hierarchy of the netlist.]

  Description [When this procedure is called, the PI/PO nets of the old 
  netlist point to the corresponding nets of the flattened netlist.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Function
Synopsis    [Recursively flattens logic hierarchy of the netlist.]

Description [When this procedure is called, the PI/PO nets of the old
netlist point to the corresponding nets of the flattened netlist.]




Function Synopsis [ Recursively flattens logic hierarchy of the netlist . ] Description [ When this procedure is called the PI / PO nets of the old netlist point to the corresponding nets of the flattened netlist . ]
void Abc_NtkFlattenLogicHierarchy_rec( Abc_Ntk_t * pNtkNew, Abc_Ntk_t * pNtk, int * pCounter, Vec_Str_t * vPref )
{
    Abc_Ntk_t * pNtkModel;
    Abc_Obj_t * pObj, * pTerm, * pNet, * pFanin;
    int i, k, Length;
    if ( Abc_NtkHasBlackbox(pNtk) )
    {
        assert( Abc_NtkBoxNum(pNtk) == 1 );
        pObj = Abc_NtkBox( pNtk, 0 );
        Abc_NtkDupBox( pNtkNew, pObj, 1 );
        pObj->pCopy->pData = pNtk;
        assert( Abc_ObjFaninNum(pObj->pCopy) == Abc_NtkPiNum(pNtk) );
        Abc_NtkForEachPi( pNtk, pTerm, i )
            Abc_ObjAddFanin( Abc_ObjFanin(pObj->pCopy,i), Abc_ObjFanout0(pTerm)->pCopy );
        assert( Abc_ObjFanoutNum(pObj->pCopy) == Abc_NtkPoNum(pNtk) );
        Abc_NtkForEachPo( pNtk, pTerm, i )
            Abc_ObjAddFanin( Abc_ObjFanin0(pTerm)->pCopy, Abc_ObjFanout(pObj->pCopy,i) );
        return;
    }
    (*pCounter)++;
    if ( *pCounter )
    {
        char Buffer[20];
        sprintf( Buffer, "(%d)", *pCounter );
        Vec_StrPrintStr( vPref, Buffer );
    }
    Vec_StrPush( vPref, '|' );
    Vec_StrPush( vPref, 0 );
    Abc_NtkForEachBox( pNtk, pObj, i )
    {
        Abc_ObjForEachFanin( pObj, pTerm, k )
        {
            pNet = Abc_ObjFanin0(pTerm);
            if ( pNet->pCopy )
                continue;
            pNet->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjNamePrefix(pNet, Vec_StrArray(vPref)) );
        }
        Abc_ObjForEachFanout( pObj, pTerm, k )
        {
            pNet = Abc_ObjFanout0(pTerm);
            if ( pNet->pCopy )
                continue;
            pNet->pCopy = Abc_NtkFindOrCreateNet( pNtkNew, Abc_ObjNamePrefix(pNet, Vec_StrArray(vPref)) );
        }
    }
    Abc_NtkIncrementTravId( pNtk );
    Abc_NtkForEachPi( pNtk, pTerm, i )
        Abc_NodeSetTravIdCurrent( pTerm );
    Abc_NtkForEachPo( pNtk, pTerm, i )
    {
        Abc_NodeSetTravIdCurrent( pTerm );
        pNet = Abc_ObjFanin0(pTerm);
        if ( strncmp( Abc_ObjName(pNet), "abc_property", 12 ) )
            continue;
        Abc_ObjAddFanin( Abc_NtkCreatePo(pNet->pCopy->pNtk), pNet->pCopy );
        if ( Nm_ManFindNameById(pNet->pCopy->pNtk->pManName, pNet->pCopy->Id) )
            Nm_ManDeleteIdName(pNet->pCopy->pNtk->pManName, pNet->pCopy->Id);
        Abc_ObjAssignName( pNet->pCopy, Vec_StrArray(vPref), Abc_ObjName(pNet) );
    }
    Abc_NtkForEachBox( pNtk, pObj, i )
    {
        if ( Abc_ObjIsLatch(pObj) )
            continue;
        Abc_NodeSetTravIdCurrent( pObj );
        Abc_ObjForEachFanin( pObj, pTerm, k )
            Abc_NodeSetTravIdCurrent( pTerm );
        Abc_ObjForEachFanout( pObj, pTerm, k )
            Abc_NodeSetTravIdCurrent( pTerm );
    }
    Abc_NtkForEachObj( pNtk, pObj, i )
    {
        if ( Abc_NodeIsTravIdCurrent(pObj) )
            continue;
        if ( pObj->pCopy )
            continue;
        Abc_NtkDupObj( pNtkNew, pObj, 0 );
    }
    Abc_NtkForEachObj( pNtk, pObj, i )
        if ( !Abc_NodeIsTravIdCurrent(pObj) )
            Abc_ObjForEachFanin( pObj, pFanin, k )
                if ( !Abc_NodeIsTravIdCurrent(pFanin) )
                    Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
    Vec_StrPop( vPref );
    Length = Vec_StrSize( vPref );
    Abc_NtkForEachBox( pNtk, pObj, i )
    {
        if ( Abc_ObjIsLatch(pObj) )
            continue;
        pNtkModel = (Abc_Ntk_t *)pObj->pData;
        assert( Abc_ObjFaninNum(pObj) == Abc_NtkPiNum(pNtkModel) );
        assert( Abc_ObjFanoutNum(pObj) == Abc_NtkPoNum(pNtkModel) );
        Abc_NtkCleanCopy( pNtkModel );
        Abc_ObjForEachFanin( pObj, pTerm, k )
            Abc_ObjFanout0( Abc_NtkPi(pNtkModel, k) )->pCopy = Abc_ObjFanin0(pTerm)->pCopy;
        Abc_ObjForEachFanout( pObj, pTerm, k )
            Abc_ObjFanin0( Abc_NtkPo(pNtkModel, k) )->pCopy = Abc_ObjFanout0(pTerm)->pCopy;
        Vec_StrShrink( vPref, Length );
        Vec_StrPrintStr( vPref, Abc_NtkName(pNtkModel) );
        Abc_NtkFlattenLogicHierarchy_rec( pNtkNew, pNtkModel, pCounter, vPref );
    }
    if ( Abc_NtkHasBlifMv(pNtk) && Abc_NtkMvVar(pNtk) )
    {
        if ( Abc_NtkMvVar( pNtkNew ) == NULL )
            Abc_NtkStartMvVars( pNtkNew );
        Abc_NtkForEachNet( pNtk, pObj, i )
            Abc_NtkSetMvVarValues( pObj->pCopy, Abc_ObjMvVarNum(pObj) );
    }
}
void Abc_NtkFlattenLogicHierarchy_rec ( Abc_Ntk_t * pNtkNew , Abc_Ntk_t * pNtk , int * pCounter , Vec_Str_t * vPref ) { Abc_Ntk_t * pNtkModel ; Abc_Obj_t * pObj , * pTerm , * pNet , * pFanin ; int i , k , Length ; if ( Abc_NtkHasBlackbox ( pNtk ) ) { assert ( Abc_NtkBoxNum ( pNtk ) == 1 ) ; pObj = Abc_NtkBox ( pNtk , 0 ) ; Abc_NtkDupBox ( pNtkNew , pObj , 1 ) ; pObj -> pCopy -> pData = pNtk ; assert ( Abc_ObjFaninNum ( pObj -> pCopy ) == Abc_NtkPiNum ( pNtk ) ) ; Abc_NtkForEachPi ( pNtk , pTerm , i ) Abc_ObjAddFanin ( Abc_ObjFanin ( pObj -> pCopy , i ) , Abc_ObjFanout0 ( pTerm ) -> pCopy ) ; assert ( Abc_ObjFanoutNum ( pObj -> pCopy ) == Abc_NtkPoNum ( pNtk ) ) ; Abc_NtkForEachPo ( pNtk , pTerm , i ) Abc_ObjAddFanin ( Abc_ObjFanin0 ( pTerm ) -> pCopy , Abc_ObjFanout ( pObj -> pCopy , i ) ) ; return ; } ( * pCounter ) ++ ; if ( * pCounter ) { char Buffer [ 20 ] ; sprintf ( Buffer , " " , * pCounter ) ; Vec_StrPrintStr ( vPref , Buffer ) ; } Vec_StrPush ( vPref , ' ' ) ; Vec_StrPush ( vPref , 0 ) ; Abc_NtkForEachBox ( pNtk , pObj , i ) { Abc_ObjForEachFanin ( pObj , pTerm , k ) { pNet = Abc_ObjFanin0 ( pTerm ) ; if ( pNet -> pCopy ) continue ; pNet -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjNamePrefix ( pNet , Vec_StrArray ( vPref ) ) ) ; } Abc_ObjForEachFanout ( pObj , pTerm , k ) { pNet = Abc_ObjFanout0 ( pTerm ) ; if ( pNet -> pCopy ) continue ; pNet -> pCopy = Abc_NtkFindOrCreateNet ( pNtkNew , Abc_ObjNamePrefix ( pNet , Vec_StrArray ( vPref ) ) ) ; } } Abc_NtkIncrementTravId ( pNtk ) ; Abc_NtkForEachPi ( pNtk , pTerm , i ) Abc_NodeSetTravIdCurrent ( pTerm ) ; Abc_NtkForEachPo ( pNtk , pTerm , i ) { Abc_NodeSetTravIdCurrent ( pTerm ) ; pNet = Abc_ObjFanin0 ( pTerm ) ; if ( strncmp ( Abc_ObjName ( pNet ) , " " , 12 ) ) continue ; Abc_ObjAddFanin ( Abc_NtkCreatePo ( pNet -> pCopy -> pNtk ) , pNet -> pCopy ) ; if ( Nm_ManFindNameById ( pNet -> pCopy -> pNtk -> pManName , pNet -> pCopy -> Id ) ) Nm_ManDeleteIdName ( pNet -> pCopy -> pNtk -> pManName , pNet -> pCopy -> Id ) ; Abc_ObjAssignName ( pNet -> pCopy , Vec_StrArray ( vPref ) , Abc_ObjName ( pNet ) ) ; } Abc_NtkForEachBox ( pNtk , pObj , i ) { if ( Abc_ObjIsLatch ( pObj ) ) continue ; Abc_NodeSetTravIdCurrent ( pObj ) ; Abc_ObjForEachFanin ( pObj , pTerm , k ) Abc_NodeSetTravIdCurrent ( pTerm ) ; Abc_ObjForEachFanout ( pObj , pTerm , k ) Abc_NodeSetTravIdCurrent ( pTerm ) ; } Abc_NtkForEachObj ( pNtk , pObj , i ) { if ( Abc_NodeIsTravIdCurrent ( pObj ) ) continue ; if ( pObj -> pCopy ) continue ; Abc_NtkDupObj ( pNtkNew , pObj , 0 ) ; } Abc_NtkForEachObj ( pNtk , pObj , i ) if ( ! Abc_NodeIsTravIdCurrent ( pObj ) ) Abc_ObjForEachFanin ( pObj , pFanin , k ) if ( ! Abc_NodeIsTravIdCurrent ( pFanin ) ) Abc_ObjAddFanin ( pObj -> pCopy , pFanin -> pCopy ) ; Vec_StrPop ( vPref ) ; Length = Vec_StrSize ( vPref ) ; Abc_NtkForEachBox ( pNtk , pObj , i ) { if ( Abc_ObjIsLatch ( pObj ) ) continue ; pNtkModel = ( Abc_Ntk_t * ) pObj -> pData ; assert ( Abc_ObjFaninNum ( pObj ) == Abc_NtkPiNum ( pNtkModel ) ) ; assert ( Abc_ObjFanoutNum ( pObj ) == Abc_NtkPoNum ( pNtkModel ) ) ; Abc_NtkCleanCopy ( pNtkModel ) ; Abc_ObjForEachFanin ( pObj , pTerm , k ) Abc_ObjFanout0 ( Abc_NtkPi ( pNtkModel , k ) ) -> pCopy = Abc_ObjFanin0 ( pTerm ) -> pCopy ; Abc_ObjForEachFanout ( pObj , pTerm , k ) Abc_ObjFanin0 ( Abc_NtkPo ( pNtkModel , k ) ) -> pCopy = Abc_ObjFanout0 ( pTerm ) -> pCopy ; Vec_StrShrink ( vPref , Length ) ; Vec_StrPrintStr ( vPref , Abc_NtkName ( pNtkModel ) ) ; Abc_NtkFlattenLogicHierarchy_rec ( pNtkNew , pNtkModel , pCounter , vPref ) ; } if ( Abc_NtkHasBlifMv ( pNtk ) && Abc_NtkMvVar ( pNtk ) ) { if ( Abc_NtkMvVar ( pNtkNew ) == NULL ) Abc_NtkStartMvVars ( pNtkNew ) ; Abc_NtkForEachNet ( pNtk , pObj , i ) Abc_NtkSetMvVarValues ( pObj -> pCopy , Abc_ObjMvVarNum ( pObj ) ) ; } }
Function
Synopsis    [Recursively flattens logic hierarchy of the netlist.]
Function Synopsis [ Recursively flattens logic hierarchy of the netlist . ]
// process the blackbox //printf( "Flatting black box \"%s\".\n", pNtk->pName ); // duplicate the blackbox // connect blackbox fanins to the PI nets // connect blackbox fanouts to the PO nets // create the suffix, which will be appended to the internal names // duplicate nets of all boxes, including latches // mark objects that will not be used // if the netlist has net names beginning with "abc_property_" // these names will be addes as primary outputs of the network // duplicate objects that do not have prototypes yet // connect objects // call recursively // check the match between the number of actual and formal parameters // clean the node copy fields // map PIs/POs // create name // call recursively // if it is a BLIF-MV netlist transfer the values of all nets