nwkObj.c 5.4 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [nwkObj.c]
Alan Mishchenko committed
4 5 6

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [Logic network representation.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16

  Synopsis    [Manipulation of objects.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

Alan Mishchenko committed
17
  Revision    [$Id: nwkObj.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20

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

Alan Mishchenko committed
21
#include "nwk.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    [Creates an object.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
45
Nwk_Obj_t * Nwk_ManCreateObj( Nwk_Man_t * p, int nFanins, int nFanouts )
Alan Mishchenko committed
46
{
Alan Mishchenko committed
47 48 49 50
    Nwk_Obj_t * pObj;
    pObj = (Nwk_Obj_t *)Aig_MmFlexEntryFetch( p->pMemObjs, sizeof(Nwk_Obj_t) + (nFanins + nFanouts + p->nFanioPlus) * sizeof(Nwk_Obj_t *) );
    memset( pObj, 0, sizeof(Nwk_Obj_t) );
    pObj->pFanio = (Nwk_Obj_t **)((char *)pObj + sizeof(Nwk_Obj_t));
Alan Mishchenko committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    pObj->Id = Vec_PtrSize( p->vObjs );
    Vec_PtrPush( p->vObjs, pObj );
    pObj->pMan        = p;
    pObj->nFanioAlloc = nFanins + nFanouts + p->nFanioPlus;
    return pObj;
}


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

  Synopsis    [Creates a primary input.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
70
Nwk_Obj_t * Nwk_ManCreateCi( Nwk_Man_t * p, int nFanouts )
Alan Mishchenko committed
71
{
Alan Mishchenko committed
72 73
    Nwk_Obj_t * pObj;
    pObj = Nwk_ManCreateObj( p, 1, nFanouts );
Alan Mishchenko committed
74
    pObj->PioId = Vec_PtrSize( p->vCis );
Alan Mishchenko committed
75
    Vec_PtrPush( p->vCis, pObj );
Alan Mishchenko committed
76 77
    pObj->Type = NWK_OBJ_CI;
    p->nObjs[NWK_OBJ_CI]++;
Alan Mishchenko committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
    return pObj;
}

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

  Synopsis    [Creates a primary output.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
92
Nwk_Obj_t * Nwk_ManCreateCo( Nwk_Man_t * p )
Alan Mishchenko committed
93
{
Alan Mishchenko committed
94 95
    Nwk_Obj_t * pObj;
    pObj = Nwk_ManCreateObj( p, 1, 1 );
Alan Mishchenko committed
96
    pObj->PioId = Vec_PtrSize( p->vCos );
Alan Mishchenko committed
97
    Vec_PtrPush( p->vCos, pObj );
Alan Mishchenko committed
98 99
    pObj->Type = NWK_OBJ_CO;
    p->nObjs[NWK_OBJ_CO]++;
Alan Mishchenko committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113
    return pObj;
}

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

  Synopsis    [Creates a latch.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
114
Nwk_Obj_t * Nwk_ManCreateLatch( Nwk_Man_t * p )
Alan Mishchenko committed
115
{
Alan Mishchenko committed
116 117 118 119
    Nwk_Obj_t * pObj;
    pObj = Nwk_ManCreateObj( p, 1, 1 );
    pObj->Type = NWK_OBJ_LATCH;
    p->nObjs[NWK_OBJ_LATCH]++;
Alan Mishchenko committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133
    return pObj;
}

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

  Synopsis    [Creates a node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
134
Nwk_Obj_t * Nwk_ManCreateNode( Nwk_Man_t * p, int nFanins, int nFanouts )
Alan Mishchenko committed
135
{
Alan Mishchenko committed
136 137 138 139
    Nwk_Obj_t * pObj;
    pObj = Nwk_ManCreateObj( p, nFanins, nFanouts );
    pObj->Type = NWK_OBJ_NODE;
    p->nObjs[NWK_OBJ_NODE]++;
Alan Mishchenko committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    return pObj;
}


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

  Synopsis    [Deletes the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
155
void Nwk_ManDeleteNode( Nwk_Obj_t * pObj )
Alan Mishchenko committed
156 157
{
    Vec_Ptr_t * vNodes = pObj->pMan->vTemp;
Alan Mishchenko committed
158
    Nwk_Obj_t * pTemp;
Alan Mishchenko committed
159
    int i;
Alan Mishchenko committed
160 161
    assert( Nwk_ObjFanoutNum(pObj) == 0 );
    // delete fanins
Alan Mishchenko committed
162
    Nwk_ObjCollectFanins( pObj, vNodes );
163
    Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pTemp, i )
Alan Mishchenko committed
164
        Nwk_ObjDeleteFanin( pObj, pTemp );
Alan Mishchenko committed
165 166 167
    // remove from the list of objects
    Vec_PtrWriteEntry( pObj->pMan->vObjs, pObj->Id, NULL );
    pObj->pMan->nObjs[pObj->Type]--;
Alan Mishchenko committed
168
    memset( pObj, 0, sizeof(Nwk_Obj_t) );
Alan Mishchenko committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182
    pObj->Id = -1;
}

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

  Synopsis    [Deletes the node and MFFC of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
183
void Nwk_ManDeleteNode_rec( Nwk_Obj_t * pObj )
Alan Mishchenko committed
184 185 186
{
    Vec_Ptr_t * vNodes;
    int i;
Alan Mishchenko committed
187 188
    assert( !Nwk_ObjIsCi(pObj) );
    assert( Nwk_ObjFanoutNum(pObj) == 0 );
Alan Mishchenko committed
189
    vNodes = Vec_PtrAlloc( 100 );
Alan Mishchenko committed
190 191
    Nwk_ObjCollectFanins( pObj, vNodes );
    Nwk_ManDeleteNode( pObj );
192
    Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
193 194
        if ( Nwk_ObjIsNode(pObj) && Nwk_ObjFanoutNum(pObj) == 0 )
            Nwk_ManDeleteNode_rec( pObj );
Alan Mishchenko committed
195 196 197 198 199 200 201 202
    Vec_PtrFree( vNodes );
}

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


203 204
ABC_NAMESPACE_IMPL_END