hopMan.c 4.76 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [hopMan.c]
Alan Mishchenko committed
4 5 6 7 8 9 10 11 12 13 14 15 16

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Minimalistic And-Inverter Graph package.]

  Synopsis    [AIG manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - May 11, 2006.]

Alan Mishchenko committed
17
  Revision    [$Id: hopMan.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20

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

Alan Mishchenko committed
21
#include "hop.h"
Alan Mishchenko committed
22

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
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Starts the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
45
Hop_Man_t * Hop_ManStart()
Alan Mishchenko committed
46
{
Alan Mishchenko committed
47
    Hop_Man_t * p;
Alan Mishchenko committed
48
    // start the manager
Alan Mishchenko committed
49
    p = ABC_ALLOC( Hop_Man_t, 1 );
Alan Mishchenko committed
50
    memset( p, 0, sizeof(Hop_Man_t) );
Alan Mishchenko committed
51 52 53 54 55 56 57 58
    // perform initializations
    p->nTravIds = 1;
    p->fRefCount = 1;
    p->fCatchExor = 0;
    // allocate arrays for nodes
    p->vPis = Vec_PtrAlloc( 100 );
    p->vPos = Vec_PtrAlloc( 100 );
    // prepare the internal memory manager
Alan Mishchenko committed
59
    Hop_ManStartMemory( p );
Alan Mishchenko committed
60
    // create the constant node
Alan Mishchenko committed
61
    p->pConst1 = Hop_ManFetchMemory( p );
Alan Mishchenko committed
62
    p->pConst1->Type = AIG_CONST1;
Alan Mishchenko committed
63 64 65
    p->pConst1->fPhase = 1;
    p->nCreated = 1;
    // start the table
Alan Mishchenko committed
66
//    p->nTableSize = 107;
Alan Mishchenko committed
67
    p->nTableSize = 10007;
Alan Mishchenko committed
68
    p->pTable = ABC_ALLOC( Hop_Obj_t *, p->nTableSize );
Alan Mishchenko committed
69
    memset( p->pTable, 0, sizeof(Hop_Obj_t *) * p->nTableSize );
Alan Mishchenko committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83
    return p;
}

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

  Synopsis    [Stops the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
84
void Hop_ManStop( Hop_Man_t * p )
Alan Mishchenko committed
85
{
Alan Mishchenko committed
86
    Hop_Obj_t * pObj;
Alan Mishchenko committed
87 88
    int i;
    // make sure the nodes have clean marks
Alan Mishchenko committed
89
    pObj = Hop_ManConst1(p);
Alan Mishchenko committed
90
    assert( !pObj->fMarkA && !pObj->fMarkB );
Alan Mishchenko committed
91
    Hop_ManForEachPi( p, pObj, i )
Alan Mishchenko committed
92
        assert( !pObj->fMarkA && !pObj->fMarkB );
Alan Mishchenko committed
93
    Hop_ManForEachPo( p, pObj, i )
Alan Mishchenko committed
94
        assert( !pObj->fMarkA && !pObj->fMarkB );
Alan Mishchenko committed
95
    Hop_ManForEachNode( p, pObj, i )
Alan Mishchenko committed
96 97
        assert( !pObj->fMarkA && !pObj->fMarkB );
    // print time
Alan Mishchenko committed
98 99
    if ( p->time1 ) { ABC_PRT( "time1", p->time1 ); }
    if ( p->time2 ) { ABC_PRT( "time2", p->time2 ); }
Alan Mishchenko committed
100
//    Hop_TableProfile( p );
Alan Mishchenko committed
101 102 103 104
    if ( p->vChunks )  Hop_ManStopMemory( p );
    if ( p->vPis )     Vec_PtrFree( p->vPis );
    if ( p->vPos )     Vec_PtrFree( p->vPos );
    if ( p->vObjs )    Vec_PtrFree( p->vObjs );
Alan Mishchenko committed
105 106
    ABC_FREE( p->pTable );
    ABC_FREE( p );
Alan Mishchenko committed
107 108 109 110 111 112 113 114 115 116 117 118 119
}

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

  Synopsis    [Returns the number of dangling nodes removed.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
120
int Hop_ManCleanup( Hop_Man_t * p )
Alan Mishchenko committed
121
{
Alan Mishchenko committed
122
    Vec_Ptr_t * vObjs;
Alan Mishchenko committed
123
    Hop_Obj_t * pNode;
Alan Mishchenko committed
124 125
    int i, nNodesOld;
    assert( p->fRefCount );
Alan Mishchenko committed
126
    nNodesOld = Hop_ManNodeNum(p);
Alan Mishchenko committed
127
    // collect roots of dangling nodes
Alan Mishchenko committed
128
    vObjs = Vec_PtrAlloc( 100 );
Alan Mishchenko committed
129 130
    Hop_ManForEachNode( p, pNode, i )
        if ( Hop_ObjRefs(pNode) == 0 )
Alan Mishchenko committed
131
            Vec_PtrPush( vObjs, pNode );
Alan Mishchenko committed
132
    // recursively remove dangling nodes
133
    Vec_PtrForEachEntry( Hop_Obj_t *, vObjs, pNode, i )
Alan Mishchenko committed
134
        Hop_ObjDelete_rec( p, pNode );
Alan Mishchenko committed
135
    Vec_PtrFree( vObjs );
Alan Mishchenko committed
136
    return nNodesOld - Hop_ManNodeNum(p);
Alan Mishchenko committed
137 138 139 140 141 142 143 144 145 146 147 148 149
}

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

  Synopsis    [Stops the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
150
void Hop_ManPrintStats( Hop_Man_t * p )
Alan Mishchenko committed
151
{
Alan Mishchenko committed
152 153 154
    printf( "PI/PO = %d/%d. ", Hop_ManPiNum(p), Hop_ManPoNum(p) );
    printf( "A = %7d. ",       Hop_ManAndNum(p) );
    printf( "X = %5d. ",       Hop_ManExorNum(p) );
Alan Mishchenko committed
155 156
    printf( "Cre = %7d. ",     p->nCreated );
    printf( "Del = %7d. ",     p->nDeleted );
Alan Mishchenko committed
157
    printf( "Lev = %3d. ",     Hop_ManCountLevels(p) );
Alan Mishchenko committed
158 159 160 161 162 163 164 165 166 167
    printf( "\n" );
}



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


168 169
ABC_NAMESPACE_IMPL_END