ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlnWlc.c
Go to the documentation of this file.
1
20
21#include "wln.h"
22#include "base/wlc/wlc.h"
23
25
29
30extern int Ndr_TypeWlc2Ndr( int Type );
31
35
47char * Wln_ConstFromBits( int * pBits, int nBits )
48{
49 char * pBuffer = ABC_ALLOC( char, nBits+100 ); int i, Len;
50 sprintf( pBuffer, "%d\'b", nBits );
51 Len = strlen(pBuffer);
52 for ( i = nBits-1; i >= 0; i-- )
53 pBuffer[Len++] = '0' + Abc_InfoHasBit((unsigned *)pBits, i);
54 pBuffer[Len] = 0;
55 return pBuffer;
56}
57char * Wln_ConstFromStr( char * pBits, int nBits )
58{
59 char * pBuffer = ABC_ALLOC( char, nBits+100 ); int i, Len;
60 sprintf( pBuffer, "%d\'b", nBits );
61 Len = strlen(pBuffer);
62 for ( i = 0; i < nBits; i++ )
63 pBuffer[Len++] = pBits[i];
64 pBuffer[Len] = 0;
65 return pBuffer;
66}
68{
69 return Abc_NamStrFindOrAdd( pNew->pManName, Wlc_ObjName(p, Wlc_ObjId(p, pObj)), NULL );
70}
72{
73 Wlc_Obj_t * pObj;
74 char Buffer[1000];
75 int i, j, n, Type, iFanin, iOutId, iBit = 0;
76 Vec_Int_t * vFanins = Vec_IntAlloc( 10 );
77 Vec_Int_t * vInits = Vec_IntAlloc( Wlc_NtkFfNum(p) );
78 Wln_Ntk_t * pNew = Wln_NtkAlloc( p->pName, Wlc_NtkObjNum(p)+Wlc_NtkCoNum(p)+Wlc_NtkFfNum(p) );
79 pNew->pManName = Abc_NamStart( Abc_NamObjNumMax(p->pManName), 10 );
80 if ( p->pSpec ) pNew->pSpec = Abc_UtilStrsav( p->pSpec );
81 pNew->fSmtLib = p->fSmtLib;
82 Wlc_NtkCleanCopy( p );
83 Wln_NtkCleanNameId( pNew );
84 // add primary inputs
85 Wlc_NtkForEachPi( p, pObj, i )
86 {
87 iOutId = Wln_ObjAlloc( pNew, ABC_OPER_CI, pObj->Signed, pObj->End, pObj->Beg );
88 Wln_ObjSetNameId( pNew, iOutId, Wln_TrasformNameId(pNew, p, pObj) );
89 Wlc_ObjSetCopy( p, Wlc_ObjId(p, pObj), iOutId );
90 }
91 // create initial state of the flops
92 Wlc_NtkForEachCi( p, pObj, i )
93 {
94 assert( i == Wlc_ObjCiId(pObj) );
95 if ( pObj->Type == WLC_OBJ_PI )
96 continue;
97 for ( j = 0; j < Wlc_ObjRange(pObj); j++ )
98 if ( p->pInits[iBit+j] == 'x' )
99 break;
100 // print flop init state
101 if ( 1 )
102 {
103 printf( "Flop %3d init state: %d\'b", i-Wlc_NtkPiNum(p), Wlc_ObjRange(pObj) );
104 if ( j == Wlc_ObjRange(pObj) )
105 {
106 int Count = 0;
107 for ( n = 0; n < Wlc_ObjRange(pObj); n++ )
108 Count += p->pInits[iBit+n] == '0';
109 if ( Count == Wlc_ObjRange(pObj) )
110 printf( "0" );
111 else
112 for ( n = 0; n < Wlc_ObjRange(pObj); n++ )
113 printf( "%c", p->pInits[iBit+n] );
114 }
115 else
116 {
117 int Count = 0;
118 for ( n = 0; n < Wlc_ObjRange(pObj); n++ )
119 Count += p->pInits[iBit+n] == 'x';
120 printf( "x" );
121 if ( Count != Wlc_ObjRange(pObj) )
122 printf( " (range %d)", Wlc_ObjRange(pObj) );
123 }
124 printf( "\n" );
125 }
126 Type = j == Wlc_ObjRange(pObj) ? ABC_OPER_CONST : ABC_OPER_CI;
127 iOutId = Wln_ObjAlloc( pNew, Type, pObj->Signed, pObj->End, pObj->Beg );
128 if ( j == Wlc_ObjRange(pObj) ) // constant
129 {
130 char * pString = Wln_ConstFromStr(p->pInits + iBit, Wlc_ObjRange(pObj));
131 Wln_ObjSetConst( pNew, iOutId, Abc_NamStrFindOrAdd(pNew->pManName, pString, NULL) );
132 ABC_FREE( pString );
133 }
134 sprintf( Buffer, "ff_init_%d", Vec_IntSize(vInits) );
135 Wln_ObjSetNameId( pNew, iOutId, Abc_NamStrFindOrAdd(pNew->pManName, Buffer, NULL) );
136 Vec_IntPush( vInits, iOutId );
137 iBit += Wlc_ObjRange(pObj);
138 }
139 assert( p->pInits == NULL || iBit == (int)strlen(p->pInits) );
140 // add flop outputs
141 Wlc_NtkForEachCi( p, pObj, i )
142 {
143 assert( i == Wlc_ObjCiId(pObj) );
144 if ( pObj->Type == WLC_OBJ_PI )
145 continue;
146 iOutId = Wln_ObjAlloc( pNew, ABC_OPER_DFFRSE, pObj->Signed, pObj->End, pObj->Beg );
147 Wln_ObjSetNameId( pNew, iOutId, Wln_TrasformNameId(pNew, p, pObj) );
148 Wlc_ObjSetCopy( p, Wlc_ObjId(p, pObj), iOutId );
149 }
150 // add internal nodes
151 Wlc_NtkForEachObj( p, pObj, i )
152 {
153 if ( Wlc_ObjIsCi(pObj) || pObj->Type == 0 )
154 continue;
155 iOutId = Wln_ObjAlloc( pNew, Ndr_TypeWlc2Ndr(pObj->Type), pObj->Signed, pObj->End, pObj->Beg );
156 Vec_IntClear( vFanins );
157 Wlc_ObjForEachFanin( pObj, iFanin, n )
158 Vec_IntPush( vFanins, Wlc_ObjCopy(p, iFanin) );
159 Wln_ObjAddFanins( pNew, iOutId, vFanins );
160 if ( pObj->Type == WLC_OBJ_BIT_SELECT )
161 Wln_ObjSetSlice( pNew, iOutId, Hash_Int2ManInsert(pNew->pRanges, pObj->End, pObj->Beg, 0) );
162 else if ( pObj->Type == WLC_OBJ_CONST )
163 {
164 char * pString = Wln_ConstFromBits(Wlc_ObjConstValue(pObj), Wlc_ObjRange(pObj));
165 Wln_ObjSetConst( pNew, iOutId, Abc_NamStrFindOrAdd(pNew->pManName, pString, NULL) );
166 ABC_FREE( pString );
167 }
168// else if ( Type == ABC_OPER_BIT_MUX && Vec_IntSize(vFanins) == 3 )
169// ABC_SWAP( int, Wln_ObjFanins(p, iObj)[1], Wln_ObjFanins(p, iObj)[2] );
170 Wln_ObjSetNameId( pNew, iOutId, Wln_TrasformNameId(pNew, p, pObj) );
171 Wlc_ObjSetCopy( p, i, iOutId );
172 }
173 Wlc_NtkForEachPo( p, pObj, i )
174 {
175 iOutId = Wln_ObjAlloc( pNew, ABC_OPER_CO, pObj->Signed, pObj->End, pObj->Beg );
176 Wln_ObjAddFanin( pNew, iOutId, Wlc_ObjCopy(p, Wlc_ObjId(p, pObj)) );
177 //Wln_ObjSetNameId( pNew, iOutId, Wln_TrasformNameId(pNew, p, pObj) );
178 }
179 assert( Vec_IntSize(vInits) == Wlc_NtkCoNum(p) - Wlc_NtkPoNum(p) );
180 Wlc_NtkForEachCo( p, pObj, i )
181 {
182 if ( i < Wlc_NtkPoNum(p) )
183 continue;
184 //char * pInNames[8] = {"d", "clk", "reset", "set", "enable", "async", "sre", "init"};
185 Vec_IntClear( vFanins );
186 Vec_IntPush( vFanins, Wlc_ObjCopy(p, Wlc_ObjFaninId0(pObj)) );
187 for ( n = 0; n < 6; n++ )
188 Vec_IntPush( vFanins, 0 );
189 Vec_IntPush( vFanins, Vec_IntEntry(vInits, i-Wlc_NtkPoNum(p)) );
190 Wln_ObjAddFanins( pNew, Vec_IntEntry(&pNew->vFfs, i-Wlc_NtkPoNum(p)), vFanins );
191 }
192 Vec_IntFree( vFanins );
193 Vec_IntFree( vInits );
194 return pNew;
195}
197{
198 Wln_Ntk_t * pNew = Wln_NtkFromWlc( p );
199 Wln_WriteVer( pNew, "test_wlc2wln.v" );
200 Wln_NtkFree( pNew );
201}
202
214
218
219
221
@ ABC_OPER_CI
Definition abcOper.h:45
@ ABC_OPER_DFFRSE
Definition abcOper.h:143
@ ABC_OPER_CONST
Definition abcOper.h:153
@ ABC_OPER_CO
Definition abcOper.h:46
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define Len
Definition deflate.h:78
Cube * p
Definition exorList.c:222
unsigned Type
Definition wlc.h:121
int End
Definition wlc.h:129
unsigned Signed
Definition wlc.h:122
int Beg
Definition wlc.h:130
Hash_IntMan_t * pRanges
Definition wln.h:67
int fSmtLib
Definition wln.h:60
char * pSpec
Definition wln.h:59
Abc_Nam_t * pManName
Definition wln.h:70
Vec_Int_t vFfs
Definition wln.h:63
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition utilNam.c:453
int Abc_NamObjNumMax(Abc_Nam_t *p)
Definition utilNam.c:231
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
Definition utilNam.c:80
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
#define Wlc_NtkForEachPo(p, pPo, i)
Definition wlc.h:364
#define Wlc_NtkForEachCi(p, pCi, i)
Definition wlc.h:366
#define Wlc_NtkForEachPi(p, pPi, i)
Definition wlc.h:362
struct Wlc_Ntk_t_ Wlc_Ntk_t
Definition wlc.h:135
#define Wlc_NtkForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition wlc.h:356
#define Wlc_ObjForEachFanin(pObj, iFanin, i)
Definition wlc.h:375
char * Wlc_ObjName(Wlc_Ntk_t *p, int iObj)
Definition wlcNtk.c:225
@ WLC_OBJ_CONST
Definition wlc.h:51
@ WLC_OBJ_BIT_SELECT
Definition wlc.h:67
@ WLC_OBJ_PI
Definition wlc.h:46
struct Wlc_Obj_t_ Wlc_Obj_t
BASIC TYPES ///.
Definition wlc.h:118
#define Wlc_NtkForEachCo(p, pCo, i)
Definition wlc.h:368
int Wln_TrasformNameId(Wln_Ntk_t *pNew, Wlc_Ntk_t *p, Wlc_Obj_t *pObj)
Definition wlnWlc.c:67
void Wln_NtkFromWlcTest(Wlc_Ntk_t *p)
Definition wlnWlc.c:196
char * Wln_ConstFromBits(int *pBits, int nBits)
FUNCTION DEFINITIONS ///.
Definition wlnWlc.c:47
char * Wln_ConstFromStr(char *pBits, int nBits)
Definition wlnWlc.c:57
ABC_NAMESPACE_IMPL_START int Ndr_TypeWlc2Ndr(int Type)
DECLARATIONS ///.
Definition wlcNdr.c:106
Wln_Ntk_t * Wln_NtkFromWlc(Wlc_Ntk_t *p)
Definition wlnWlc.c:71
void Wln_WriteVer(Wln_Ntk_t *p, char *pFileName)
void Wln_ObjSetSlice(Wln_Ntk_t *p, int iObj, int SliceId)
Definition wlnObj.c:70
void Wln_ObjAddFanin(Wln_Ntk_t *p, int iObj, int i)
Definition wlnObj.c:75
void Wln_NtkFree(Wln_Ntk_t *p)
Definition wlnNtk.c:68
int Wln_ObjAlloc(Wln_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition wlnObj.c:105
struct Wln_Ntk_t_ Wln_Ntk_t
Definition wln.h:55
void Wln_ObjSetConst(Wln_Ntk_t *p, int iObj, int NameId)
Definition wlnObj.c:65
Wln_Ntk_t * Wln_NtkAlloc(char *pName, int nObjsMax)
DECLARATIONS ///.
Definition wlnNtk.c:45
int Wln_ObjAddFanins(Wln_Ntk_t *p, int iObj, Vec_Int_t *vFanins)
Definition wlnObj.c:98