1 /**CFile****************************************************************
2 
3   FileName    [wlnObj.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Word-level network.]
8 
9   Synopsis    [Object construction procedures.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - September 23, 2018.]
16 
17   Revision    [$Id: wlnObj.c,v 1.00 2018/09/23 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "wln.h"
22 
23 ABC_NAMESPACE_IMPL_START
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 ///                        DECLARATIONS                              ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 ///                     FUNCTION DEFINITIONS                         ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36   Synopsis    [Creating objects.]
37 
38   Description []
39 
40   SideEffects []
41 
42   SeeAlso     []
43 
44 ***********************************************************************/
Wln_ObjName(Wln_Ntk_t * p,int iObj)45 char * Wln_ObjName( Wln_Ntk_t * p, int iObj )
46 {
47     static char Buffer[100];
48     if ( Wln_NtkHasNameId(p) && Wln_ObjNameId(p, iObj) )
49         return Abc_NamStr( p->pManName, Wln_ObjNameId(p, iObj) );
50     sprintf( Buffer, "n%d", iObj );
51     return Buffer;
52 }
Wln_ObjConstString(Wln_Ntk_t * p,int iObj)53 char * Wln_ObjConstString( Wln_Ntk_t * p, int iObj )
54 {
55     assert( Wln_ObjIsConst(p, iObj) );
56     return Abc_NamStr( p->pManName, Wln_ObjFanin0(p, iObj) );
57 }
Wln_ObjUpdateType(Wln_Ntk_t * p,int iObj,int Type)58 void Wln_ObjUpdateType( Wln_Ntk_t * p, int iObj, int Type )
59 {
60     assert( Wln_ObjIsNone(p, iObj) );
61     p->nObjs[Wln_ObjType(p, iObj)]--;
62     Vec_IntWriteEntry( &p->vTypes, iObj, Type );
63     p->nObjs[Wln_ObjType(p, iObj)]++;
64 }
Wln_ObjSetConst(Wln_Ntk_t * p,int iObj,int NameId)65 void Wln_ObjSetConst( Wln_Ntk_t * p, int iObj, int NameId )
66 {
67     assert( Wln_ObjIsConst(p, iObj) );
68     Wln_ObjSetFanin( p, iObj, 0, NameId );
69 }
Wln_ObjSetSlice(Wln_Ntk_t * p,int iObj,int SliceId)70 void Wln_ObjSetSlice( Wln_Ntk_t * p, int iObj, int SliceId )
71 {
72     assert( Wln_ObjIsSlice(p, iObj) );
73     Wln_ObjSetFanin( p, iObj, 1, SliceId );
74 }
Wln_ObjAddFanin(Wln_Ntk_t * p,int iObj,int i)75 void Wln_ObjAddFanin( Wln_Ntk_t * p, int iObj, int i )
76 {
77     Wln_Vec_t * pVec = p->vFanins + iObj;
78     if ( Wln_ObjFaninNum(p, iObj) < 2 )
79         pVec->Array[pVec->nSize++] = i;
80     else if ( Wln_ObjFaninNum(p, iObj) == 2 )
81     {
82         int * pArray = ABC_ALLOC( int, 4 );
83         pArray[0] = pVec->Array[0];
84         pArray[1] = pVec->Array[1];
85         pArray[2] = i;
86         pVec->pArray[0] = pArray;
87         pVec->nSize     = 3;
88         pVec->nCap      = 4;
89     }
90     else
91     {
92         if ( pVec->nSize == pVec->nCap )
93             pVec->pArray[0] = ABC_REALLOC( int, pVec->pArray[0], (pVec->nCap = 2*pVec->nSize) );
94         assert( pVec->nSize < pVec->nCap );
95         pVec->pArray[0][pVec->nSize++] = i;
96     }
97 }
Wln_ObjAddFanins(Wln_Ntk_t * p,int iObj,Vec_Int_t * vFanins)98 int Wln_ObjAddFanins( Wln_Ntk_t * p, int iObj, Vec_Int_t * vFanins )
99 {
100     int i, iFanin;
101     Vec_IntForEachEntry( vFanins, iFanin, i )
102         Wln_ObjAddFanin( p, iObj, iFanin );
103     return iObj;
104 }
Wln_ObjAlloc(Wln_Ntk_t * p,int Type,int Signed,int End,int Beg)105 int Wln_ObjAlloc( Wln_Ntk_t * p, int Type, int Signed, int End, int Beg )
106 {
107     int iObj = Vec_IntSize(&p->vTypes);
108     if ( iObj == Vec_IntCap(&p->vTypes) )
109     {
110         p->vFanins = ABC_REALLOC( Wln_Vec_t, p->vFanins, 2 * iObj );
111         memset( p->vFanins + iObj, 0, sizeof(Wln_Vec_t) * iObj );
112         Vec_IntGrow( &p->vTypes, 2 * iObj );
113     }
114     assert( iObj == Vec_StrSize(&p->vSigns) );
115     assert( iObj == Vec_IntSize(&p->vRanges) );
116     Vec_IntPush( &p->vTypes, Type );
117     Vec_StrPush( &p->vSigns, (char)Signed );
118     Vec_IntPush( &p->vRanges, Hash_Int2ManInsert(p->pRanges, End, Beg, 0) );
119     if ( Wln_ObjIsCi(p, iObj) ) Wln_ObjSetFanin( p, iObj, 1, Vec_IntSize(&p->vCis) ), Vec_IntPush( &p->vCis, iObj );
120     if ( Wln_ObjIsCo(p, iObj) ) Wln_ObjSetFanin( p, iObj, 1, Vec_IntSize(&p->vCos) ), Vec_IntPush( &p->vCos, iObj );
121     if ( Wln_ObjIsFf(p, iObj) ) Vec_IntPush( &p->vFfs, iObj );
122     p->nObjs[Type]++;
123     return iObj;
124 }
Wln_ObjClone(Wln_Ntk_t * pNew,Wln_Ntk_t * p,int iObj)125 int Wln_ObjClone( Wln_Ntk_t * pNew, Wln_Ntk_t * p, int iObj )
126 {
127     return Wln_ObjAlloc( pNew, Wln_ObjType(p, iObj), Wln_ObjIsSigned(p, iObj), Wln_ObjRangeEnd(p, iObj), Wln_ObjRangeBeg(p, iObj) );
128 }
Wln_ObjCreateCo(Wln_Ntk_t * p,int iFanin)129 int Wln_ObjCreateCo( Wln_Ntk_t * p, int iFanin )
130 {
131     int iCo = Wln_ObjClone( p, p, iFanin );
132     Wln_ObjUpdateType( p, iCo, ABC_OPER_CO );
133     Wln_ObjAddFanin( p, iCo, iFanin );
134     return iCo;
135 }
Wln_ObjPrint(Wln_Ntk_t * p,int iObj)136 void Wln_ObjPrint( Wln_Ntk_t * p, int iObj )
137 {
138     int k, iFanin, Type = Wln_ObjType(p, iObj);
139     printf( "Obj %6d : Type = %6s  Fanins = %d : ", iObj, Abc_OperName(Type), Wln_ObjFaninNum(p, iObj) );
140     Wln_ObjForEachFanin( p, iObj, iFanin, k )
141         printf( "%5d ", iFanin );
142     printf( "\n" );
143 }
144 
145 ////////////////////////////////////////////////////////////////////////
146 ///                       END OF FILE                                ///
147 ////////////////////////////////////////////////////////////////////////
148 
149 
150 ABC_NAMESPACE_IMPL_END
151 
152