nwkStrash.c 4.74 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [nwkStrash.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Logic network representation.]

  Synopsis    [Performs structural hashing for the network.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: nwkStrash.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "nwk.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Derives AIG from the local functions of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManStrashNode_rec( Aig_Man_t * p, Hop_Obj_t * pObj )
{
    assert( !Hop_IsComplement(pObj) );
    if ( !Hop_ObjIsNode(pObj) || Hop_ObjIsMarkA(pObj) )
        return;
    Nwk_ManStrashNode_rec( p, Hop_ObjFanin0(pObj) ); 
    Nwk_ManStrashNode_rec( p, Hop_ObjFanin1(pObj) );
    pObj->pData = Aig_And( p, (Aig_Obj_t *)Hop_ObjChild0Copy(pObj), (Aig_Obj_t *)Hop_ObjChild1Copy(pObj) );
    assert( !Hop_ObjIsMarkA(pObj) ); // loop detection
    Hop_ObjSetMarkA( pObj );
}

/**Function*************************************************************

  Synopsis    [Derives AIG from the local functions of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Obj_t * Nwk_ManStrashNode( Aig_Man_t * p, Nwk_Obj_t * pObj )
{
    Hop_Man_t * pMan = pObj->pMan->pManHop;
    Hop_Obj_t * pRoot = pObj->pFunc;
    Nwk_Obj_t * pFanin;
    int i;
    assert( Nwk_ObjIsNode(pObj) );
    // check the constant case
    if ( Hop_Regular(pRoot) == Hop_ManConst1(pMan) )
        return Aig_NotCond( Aig_ManConst1(p), Hop_IsComplement(pRoot) );
    // set elementary variables
    Nwk_ObjForEachFanin( pObj, pFanin, i )
        Hop_IthVar(pMan, i)->pData = pFanin->pCopy;
    // strash the AIG of this node
    Nwk_ManStrashNode_rec( p, Hop_Regular(pRoot) );
    Hop_ConeUnmark_rec( Hop_Regular(pRoot) );
    // return the final node
85
    return Aig_NotCond( (Aig_Obj_t *)Hop_Regular(pRoot)->pData, Hop_IsComplement(pRoot) );
Alan Mishchenko committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
}

/**Function*************************************************************

  Synopsis    [Derives AIG from the logic network.]

  Description [Assumes topological ordering of nodes.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Aig_Man_t * Nwk_ManStrash( Nwk_Man_t * pNtk )
{
Alan Mishchenko committed
101 102
    Vec_Ptr_t * vObjs;
    Aig_Man_t * pMan;
Alan Mishchenko committed
103 104 105 106
    Aig_Obj_t * pObjNew;
    Nwk_Obj_t * pObj;
    int i, Level;
    pMan = Aig_ManStart( Nwk_ManGetAigNodeNum(pNtk) );
Alan Mishchenko committed
107 108
    pMan->pName = Aig_UtilStrsav( pNtk->pName );
    pMan->pSpec = Aig_UtilStrsav( pNtk->pSpec );
109 110
    pMan->pManTime = Tim_ManDup( (Tim_Man_t *)pNtk->pManTime, 1 );
    Tim_ManIncrementTravId( (Tim_Man_t *)pMan->pManTime );
Alan Mishchenko committed
111
    Nwk_ManForEachObj( pNtk, pObj, i )
Alan Mishchenko committed
112 113 114
        pObj->pCopy = NULL;
//    Nwk_ManForEachObj( pNtk, pObj, i )
    vObjs = Nwk_ManDfs( pNtk );
115
    Vec_PtrForEachEntry( Nwk_Obj_t *, vObjs, pObj, i )
Alan Mishchenko committed
116 117 118 119
    {
        if ( Nwk_ObjIsCi(pObj) )
        {
            pObjNew = Aig_ObjCreatePi(pMan);
120
            Level = Tim_ManGetCiArrival( (Tim_Man_t *)pMan->pManTime, pObj->PioId );
Alan Mishchenko committed
121 122 123 124
            Aig_ObjSetLevel( pObjNew, Level );
        }
        else if ( Nwk_ObjIsCo(pObj) )
        {
125
            pObjNew = Aig_ObjCreatePo( pMan, Aig_NotCond((Aig_Obj_t *)Nwk_ObjFanin0(pObj)->pCopy, pObj->fInvert) );
Alan Mishchenko committed
126
            Level = Aig_ObjLevel( pObjNew );
127
            Tim_ManSetCoArrival( (Tim_Man_t *)pMan->pManTime, pObj->PioId, (float)Level );
Alan Mishchenko committed
128 129 130 131 132 133 134 135 136
        }
        else if ( Nwk_ObjIsNode(pObj) )
        {
            pObjNew = Nwk_ManStrashNode( pMan, pObj );
        }
        else
            assert( 0 );
        pObj->pCopy = pObjNew;
    }
Alan Mishchenko committed
137
    Vec_PtrFree( vObjs );
Alan Mishchenko committed
138
    Aig_ManCleanup( pMan );
Alan Mishchenko committed
139
    Aig_ManSetRegNum( pMan, 0 );
Alan Mishchenko committed
140 141 142 143 144 145 146 147
    return pMan;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


148 149
ABC_NAMESPACE_IMPL_END