abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nwkObj.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [nwkObj.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Logic network representation.]
8 
9  Synopsis [Manipulation of objects.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: nwkObj.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "nwk.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis [Creates an object.]
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
45 Nwk_Obj_t * Nwk_ManCreateObj( Nwk_Man_t * p, int nFanins, int nFanouts )
46 {
47  Nwk_Obj_t * pObj;
48  pObj = (Nwk_Obj_t *)Aig_MmFlexEntryFetch( p->pMemObjs, sizeof(Nwk_Obj_t) + (nFanins + nFanouts + p->nFanioPlus) * sizeof(Nwk_Obj_t *) );
49  memset( pObj, 0, sizeof(Nwk_Obj_t) );
50  pObj->pFanio = (Nwk_Obj_t **)((char *)pObj + sizeof(Nwk_Obj_t));
51  pObj->Id = Vec_PtrSize( p->vObjs );
52  Vec_PtrPush( p->vObjs, pObj );
53  pObj->pMan = p;
54  pObj->nFanioAlloc = nFanins + nFanouts + p->nFanioPlus;
55  return pObj;
56 }
57 
58 
59 /**Function*************************************************************
60 
61  Synopsis [Creates a primary input.]
62 
63  Description []
64 
65  SideEffects []
66 
67  SeeAlso []
68 
69 ***********************************************************************/
70 Nwk_Obj_t * Nwk_ManCreateCi( Nwk_Man_t * p, int nFanouts )
71 {
72  Nwk_Obj_t * pObj;
73  pObj = Nwk_ManCreateObj( p, 1, nFanouts );
74  pObj->PioId = Vec_PtrSize( p->vCis );
75  Vec_PtrPush( p->vCis, pObj );
76  pObj->Type = NWK_OBJ_CI;
77  p->nObjs[NWK_OBJ_CI]++;
78  return pObj;
79 }
80 
81 /**Function*************************************************************
82 
83  Synopsis [Creates a primary output.]
84 
85  Description []
86 
87  SideEffects []
88 
89  SeeAlso []
90 
91 ***********************************************************************/
93 {
94  Nwk_Obj_t * pObj;
95  pObj = Nwk_ManCreateObj( p, 1, 1 );
96  pObj->PioId = Vec_PtrSize( p->vCos );
97  Vec_PtrPush( p->vCos, pObj );
98  pObj->Type = NWK_OBJ_CO;
99  p->nObjs[NWK_OBJ_CO]++;
100  return pObj;
101 }
102 
103 /**Function*************************************************************
104 
105  Synopsis [Creates a latch.]
106 
107  Description []
108 
109  SideEffects []
110 
111  SeeAlso []
112 
113 ***********************************************************************/
115 {
116  Nwk_Obj_t * pObj;
117  pObj = Nwk_ManCreateObj( p, 1, 1 );
118  pObj->Type = NWK_OBJ_LATCH;
119  p->nObjs[NWK_OBJ_LATCH]++;
120  return pObj;
121 }
122 
123 /**Function*************************************************************
124 
125  Synopsis [Creates a node.]
126 
127  Description []
128 
129  SideEffects []
130 
131  SeeAlso []
132 
133 ***********************************************************************/
134 Nwk_Obj_t * Nwk_ManCreateNode( Nwk_Man_t * p, int nFanins, int nFanouts )
135 {
136  Nwk_Obj_t * pObj;
137  pObj = Nwk_ManCreateObj( p, nFanins, nFanouts );
138  pObj->Type = NWK_OBJ_NODE;
139  p->nObjs[NWK_OBJ_NODE]++;
140  return pObj;
141 }
142 
143 
144 /**Function*************************************************************
145 
146  Synopsis [Deletes the node.]
147 
148  Description []
149 
150  SideEffects []
151 
152  SeeAlso []
153 
154 ***********************************************************************/
156 {
157  Vec_Ptr_t * vNodes = pObj->pMan->vTemp;
158  Nwk_Obj_t * pTemp;
159  int i;
160  assert( Nwk_ObjFanoutNum(pObj) == 0 );
161  // delete fanins
162  Nwk_ObjCollectFanins( pObj, vNodes );
163  Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pTemp, i )
164  Nwk_ObjDeleteFanin( pObj, pTemp );
165  // remove from the list of objects
166  Vec_PtrWriteEntry( pObj->pMan->vObjs, pObj->Id, NULL );
167  pObj->pMan->nObjs[pObj->Type]--;
168  memset( pObj, 0, sizeof(Nwk_Obj_t) );
169  pObj->Id = -1;
170 }
171 
172 /**Function*************************************************************
173 
174  Synopsis [Deletes the node and MFFC of the node.]
175 
176  Description []
177 
178  SideEffects []
179 
180  SeeAlso []
181 
182 ***********************************************************************/
184 {
185  Vec_Ptr_t * vNodes;
186  int i;
187  assert( !Nwk_ObjIsCi(pObj) );
188  assert( Nwk_ObjFanoutNum(pObj) == 0 );
189  vNodes = Vec_PtrAlloc( 100 );
190  Nwk_ObjCollectFanins( pObj, vNodes );
191  Nwk_ManDeleteNode( pObj );
192  Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pObj, i )
193  if ( Nwk_ObjIsNode(pObj) && Nwk_ObjFanoutNum(pObj) == 0 )
194  Nwk_ManDeleteNode_rec( pObj );
195  Vec_PtrFree( vNodes );
196 }
197 
198 ////////////////////////////////////////////////////////////////////////
199 /// END OF FILE ///
200 ////////////////////////////////////////////////////////////////////////
201 
202 
204 
char * memset()
static int Nwk_ObjIsCi(Nwk_Obj_t *p)
Definition: nwk.h:146
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
void Nwk_ManDeleteNode(Nwk_Obj_t *pObj)
Definition: nwkObj.c:155
static int Nwk_ObjFanoutNum(Nwk_Obj_t *p)
Definition: nwk.h:138
typedefABC_NAMESPACE_HEADER_START struct Nwk_Obj_t_ Nwk_Obj_t
INCLUDES ///.
Definition: nwk.h:49
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Definition: aigMem.c:366
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_NAMESPACE_IMPL_START Nwk_Obj_t * Nwk_ManCreateObj(Nwk_Man_t *p, int nFanins, int nFanouts)
DECLARATIONS ///.
Definition: nwkObj.c:45
Aig_MmFlex_t * pMemObjs
Definition: nwk.h:76
Vec_Ptr_t * vCos
Definition: nwk.h:68
void Nwk_ManDeleteNode_rec(Nwk_Obj_t *pObj)
Definition: nwkObj.c:183
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
Vec_Ptr_t * vCis
Definition: nwk.h:67
Nwk_Obj_t * Nwk_ManCreateNode(Nwk_Man_t *p, int nFanins, int nFanouts)
Definition: nwkObj.c:134
Definition: nwk.h:61
Definition: nwk.h:54
int nObjs[NWK_OBJ_VOID]
Definition: nwk.h:70
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Vec_Ptr_t * vObjs
Definition: nwk.h:69
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
Definition: vecPtr.h:396
static int Nwk_ObjIsNode(Nwk_Obj_t *p)
Definition: nwk.h:148
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
ABC_DLL void Nwk_ObjCollectFanins(Nwk_Obj_t *pNode, Vec_Ptr_t *vNodes)
DECLARATIONS ///.
Definition: nwkFanio.c:45
Nwk_Obj_t * Nwk_ManCreateCi(Nwk_Man_t *p, int nFanouts)
Definition: nwkObj.c:70
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Nwk_Obj_t * Nwk_ManCreateLatch(Nwk_Man_t *p)
Definition: nwkObj.c:114
ABC_DLL void Nwk_ObjDeleteFanin(Nwk_Obj_t *pObj, Nwk_Obj_t *pFanin)
Definition: nwkFanio.c:192
Definition: nwk.h:55
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
Nwk_Obj_t * Nwk_ManCreateCo(Nwk_Man_t *p)
Definition: nwkObj.c:92
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int nFanioPlus
Definition: nwk.h:71