ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlcNdr.c
Go to the documentation of this file.
1
20
21#include "wlc.h"
22#include "aig/miniaig/ndr.h"
23
25
29
33
45int Ndr_TypeNdr2Wlc( int Type )
46{
47 if ( Type == ABC_OPER_CONST ) return WLC_OBJ_CONST; // 06: constant
48 if ( Type == ABC_OPER_BIT_BUF ) return WLC_OBJ_BUF; // 07: buffer
49 if ( Type == ABC_OPER_BIT_MUX ) return WLC_OBJ_MUX; // 08: multiplexer
50 if ( Type == ABC_OPER_SHIFT_R ) return WLC_OBJ_SHIFT_R; // 09: shift right
51 if ( Type == ABC_OPER_SHIFT_RA ) return WLC_OBJ_SHIFT_RA; // 10: shift right (arithmetic)
52 if ( Type == ABC_OPER_SHIFT_L ) return WLC_OBJ_SHIFT_L; // 11: shift left
53 if ( Type == ABC_OPER_SHIFT_LA ) return WLC_OBJ_SHIFT_LA; // 12: shift left (arithmetic)
54 if ( Type == ABC_OPER_SHIFT_ROTR ) return WLC_OBJ_ROTATE_R; // 13: rotate right
55 if ( Type == ABC_OPER_SHIFT_ROTL ) return WLC_OBJ_ROTATE_L; // 14: rotate left
56 if ( Type == ABC_OPER_BIT_INV ) return WLC_OBJ_BIT_NOT; // 15: bitwise NOT
57 if ( Type == ABC_OPER_BIT_AND ) return WLC_OBJ_BIT_AND; // 16: bitwise AND
58 if ( Type == ABC_OPER_BIT_OR ) return WLC_OBJ_BIT_OR; // 17: bitwise OR
59 if ( Type == ABC_OPER_BIT_XOR ) return WLC_OBJ_BIT_XOR; // 18: bitwise XOR
60 if ( Type == ABC_OPER_BIT_NAND ) return WLC_OBJ_BIT_NAND; // 19: bitwise AND
61 if ( Type == ABC_OPER_BIT_NOR ) return WLC_OBJ_BIT_NOR; // 20: bitwise OR
62 if ( Type == ABC_OPER_BIT_NXOR ) return WLC_OBJ_BIT_NXOR; // 21: bitwise NXOR
63 if ( Type == ABC_OPER_SLICE ) return WLC_OBJ_BIT_SELECT; // 22: bit selection
64 if ( Type == ABC_OPER_CONCAT ) return WLC_OBJ_BIT_CONCAT; // 23: bit concatenation
65 if ( Type == ABC_OPER_ZEROPAD ) return WLC_OBJ_BIT_ZEROPAD; // 24: zero padding
66 if ( Type == ABC_OPER_SIGNEXT ) return WLC_OBJ_BIT_SIGNEXT; // 25: sign extension
67 if ( Type == ABC_OPER_LOGIC_NOT ) return WLC_OBJ_LOGIC_NOT; // 26: logic NOT
68 if ( Type == ABC_OPER_LOGIC_IMPL ) return WLC_OBJ_LOGIC_IMPL; // 27: logic implication
69 if ( Type == ABC_OPER_LOGIC_AND ) return WLC_OBJ_LOGIC_AND; // 28: logic AND
70 if ( Type == ABC_OPER_LOGIC_OR ) return WLC_OBJ_LOGIC_OR; // 29: logic OR
71 if ( Type == ABC_OPER_LOGIC_XOR ) return WLC_OBJ_LOGIC_XOR; // 30: logic XOR
72 if ( Type == ABC_OPER_SEL_NMUX ) return WLC_OBJ_MUX; // 08: multiplexer
73 if ( Type == ABC_OPER_SEL_SEL ) return WLC_OBJ_SEL; // 57: selector
74 if ( Type == ABC_OPER_SEL_DEC ) return WLC_OBJ_DEC; // 58: decoder
75 if ( Type == ABC_OPER_COMP_EQU ) return WLC_OBJ_COMP_EQU; // 31: compare equal
76 if ( Type == ABC_OPER_COMP_NOTEQU ) return WLC_OBJ_COMP_NOTEQU; // 32: compare not equal
77 if ( Type == ABC_OPER_COMP_LESS ) return WLC_OBJ_COMP_LESS; // 33: compare less
78 if ( Type == ABC_OPER_COMP_MORE ) return WLC_OBJ_COMP_MORE; // 34: compare more
79 if ( Type == ABC_OPER_COMP_LESSEQU ) return WLC_OBJ_COMP_LESSEQU; // 35: compare less or equal
80 if ( Type == ABC_OPER_COMP_MOREEQU ) return WLC_OBJ_COMP_MOREEQU; // 36: compare more or equal
81 if ( Type == ABC_OPER_RED_AND ) return WLC_OBJ_REDUCT_AND; // 37: reduction AND
82 if ( Type == ABC_OPER_RED_OR ) return WLC_OBJ_REDUCT_OR; // 38: reduction OR
83 if ( Type == ABC_OPER_RED_XOR ) return WLC_OBJ_REDUCT_XOR; // 39: reduction XOR
84 if ( Type == ABC_OPER_RED_NAND ) return WLC_OBJ_REDUCT_NAND; // 40: reduction NAND
85 if ( Type == ABC_OPER_RED_NOR ) return WLC_OBJ_REDUCT_NOR; // 41: reduction NOR
86 if ( Type == ABC_OPER_RED_NXOR ) return WLC_OBJ_REDUCT_NXOR; // 42: reduction NXOR
87 if ( Type == ABC_OPER_ARI_ADD ) return WLC_OBJ_ARI_ADD; // 43: arithmetic addition
88 if ( Type == ABC_OPER_ARI_SUB ) return WLC_OBJ_ARI_SUB; // 44: arithmetic subtraction
89 if ( Type == ABC_OPER_ARI_MUL ) return WLC_OBJ_ARI_MULTI; // 45: arithmetic multiplier
90 if ( Type == ABC_OPER_ARI_DIV ) return WLC_OBJ_ARI_DIVIDE; // 46: arithmetic division
91 if ( Type == ABC_OPER_ARI_REM ) return WLC_OBJ_ARI_REM; // 47: arithmetic remainder
92 if ( Type == ABC_OPER_ARI_MOD ) return WLC_OBJ_ARI_MODULUS; // 48: arithmetic modulus
93 if ( Type == ABC_OPER_ARI_POW ) return WLC_OBJ_ARI_POWER; // 49: arithmetic power
94 if ( Type == ABC_OPER_ARI_MIN ) return WLC_OBJ_ARI_MINUS; // 50: arithmetic minus
95 if ( Type == ABC_OPER_ARI_SQRT ) return WLC_OBJ_ARI_SQRT; // 51: integer square root
96 if ( Type == ABC_OPER_ARI_SQUARE ) return WLC_OBJ_ARI_SQUARE; // 52: integer square
97 if ( Type == ABC_OPER_ARI_ADDSUB ) return WLC_OBJ_ARI_ADDSUB; // 56: adder-subtractor
98 if ( Type == ABC_OPER_ARI_SMUL ) return WLC_OBJ_ARI_MULTI; // 45: signed multiplier
99 if ( Type == ABC_OPER_DFF ) return WLC_OBJ_FO; // 03: flop
100 if ( Type == ABC_OPER_DFFRSE ) return WLC_OBJ_FF; // 05: flop
101 if ( Type == ABC_OPER_RAMR ) return WLC_OBJ_READ; // 54: read port
102 if ( Type == ABC_OPER_RAMW ) return WLC_OBJ_WRITE; // 55: write port
103 if ( Type == ABC_OPER_LUT ) return WLC_OBJ_LUT; // 59: LUT
104 return -1;
105}
106int Ndr_TypeWlc2Ndr( int Type )
107{
108 if ( Type == WLC_OBJ_CONST ) return ABC_OPER_CONST; // 06: constant
109 if ( Type == WLC_OBJ_BUF ) return ABC_OPER_BIT_BUF; // 07: buffer
110 if ( Type == WLC_OBJ_MUX ) return ABC_OPER_BIT_MUX; // 08: multiplexer
111 if ( Type == WLC_OBJ_SHIFT_R ) return ABC_OPER_SHIFT_R; // 09: shift right
112 if ( Type == WLC_OBJ_SHIFT_RA ) return ABC_OPER_SHIFT_RA; // 10: shift right (arithmetic)
113 if ( Type == WLC_OBJ_SHIFT_L ) return ABC_OPER_SHIFT_L; // 11: shift left
114 if ( Type == WLC_OBJ_SHIFT_LA ) return ABC_OPER_SHIFT_LA; // 12: shift left (arithmetic)
115 if ( Type == WLC_OBJ_ROTATE_R ) return ABC_OPER_SHIFT_ROTR; // 13: rotate right
116 if ( Type == WLC_OBJ_ROTATE_L ) return ABC_OPER_SHIFT_ROTL; // 14: rotate left
117 if ( Type == WLC_OBJ_BIT_NOT ) return ABC_OPER_BIT_INV; // 15: bitwise NOT
118 if ( Type == WLC_OBJ_BIT_AND ) return ABC_OPER_BIT_AND; // 16: bitwise AND
119 if ( Type == WLC_OBJ_BIT_OR ) return ABC_OPER_BIT_OR; // 17: bitwise OR
120 if ( Type == WLC_OBJ_BIT_XOR ) return ABC_OPER_BIT_XOR; // 18: bitwise XOR
121 if ( Type == WLC_OBJ_BIT_NAND ) return ABC_OPER_BIT_NAND; // 19: bitwise AND
122 if ( Type == WLC_OBJ_BIT_NOR ) return ABC_OPER_BIT_NOR; // 20: bitwise OR
123 if ( Type == WLC_OBJ_BIT_NXOR ) return ABC_OPER_BIT_NXOR; // 21: bitwise NXOR
124 if ( Type == WLC_OBJ_BIT_SELECT ) return ABC_OPER_SLICE; // 22: bit selection
125 if ( Type == WLC_OBJ_BIT_CONCAT ) return ABC_OPER_CONCAT; // 23: bit concatenation
126 if ( Type == WLC_OBJ_BIT_ZEROPAD ) return ABC_OPER_ZEROPAD; // 24: zero padding
127 if ( Type == WLC_OBJ_BIT_SIGNEXT ) return ABC_OPER_SIGNEXT; // 25: sign extension
128 if ( Type == WLC_OBJ_LOGIC_NOT ) return ABC_OPER_LOGIC_NOT; // 26: logic NOT
129 if ( Type == WLC_OBJ_LOGIC_IMPL ) return ABC_OPER_LOGIC_IMPL; // 27: logic implication
130 if ( Type == WLC_OBJ_LOGIC_AND ) return ABC_OPER_LOGIC_AND; // 28: logic AND
131 if ( Type == WLC_OBJ_LOGIC_OR ) return ABC_OPER_LOGIC_OR; // 29: logic OR
132 if ( Type == WLC_OBJ_LOGIC_XOR ) return ABC_OPER_LOGIC_XOR; // 30: logic XOR
133 if ( Type == WLC_OBJ_SEL ) return ABC_OPER_SEL_SEL; // 57: selector
134 if ( Type == WLC_OBJ_DEC ) return ABC_OPER_SEL_DEC; // 58: decoder
135 if ( Type == WLC_OBJ_COMP_EQU ) return ABC_OPER_COMP_EQU; // 31: compare equal
136 if ( Type == WLC_OBJ_COMP_NOTEQU ) return ABC_OPER_COMP_NOTEQU; // 32: compare not equal
137 if ( Type == WLC_OBJ_COMP_LESS ) return ABC_OPER_COMP_LESS; // 33: compare less
138 if ( Type == WLC_OBJ_COMP_MORE ) return ABC_OPER_COMP_MORE; // 34: compare more
139 if ( Type == WLC_OBJ_COMP_LESSEQU ) return ABC_OPER_COMP_LESSEQU; // 35: compare less or equal
140 if ( Type == WLC_OBJ_COMP_MOREEQU ) return ABC_OPER_COMP_MOREEQU; // 36: compare more or equal
141 if ( Type == WLC_OBJ_REDUCT_AND ) return ABC_OPER_RED_AND; // 37: reduction AND
142 if ( Type == WLC_OBJ_REDUCT_OR ) return ABC_OPER_RED_OR; // 38: reduction OR
143 if ( Type == WLC_OBJ_REDUCT_XOR ) return ABC_OPER_RED_XOR; // 39: reduction XOR
144 if ( Type == WLC_OBJ_REDUCT_NAND ) return ABC_OPER_RED_NAND; // 40: reduction NAND
145 if ( Type == WLC_OBJ_REDUCT_NOR ) return ABC_OPER_RED_NOR; // 41: reduction NOR
146 if ( Type == WLC_OBJ_REDUCT_NXOR ) return ABC_OPER_RED_NXOR; // 42: reduction NXOR
147 if ( Type == WLC_OBJ_ARI_ADD ) return ABC_OPER_ARI_ADD; // 43: arithmetic addition
148 if ( Type == WLC_OBJ_ARI_SUB ) return ABC_OPER_ARI_SUB; // 44: arithmetic subtraction
149 if ( Type == WLC_OBJ_ARI_MULTI ) return ABC_OPER_ARI_MUL; // 45: arithmetic multiplier
150 if ( Type == WLC_OBJ_ARI_DIVIDE ) return ABC_OPER_ARI_DIV; // 46: arithmetic division
151 if ( Type == WLC_OBJ_ARI_REM ) return ABC_OPER_ARI_REM; // 47: arithmetic remainder
152 if ( Type == WLC_OBJ_ARI_MODULUS ) return ABC_OPER_ARI_MOD; // 48: arithmetic modulus
153 if ( Type == WLC_OBJ_ARI_POWER ) return ABC_OPER_ARI_POW; // 49: arithmetic power
154 if ( Type == WLC_OBJ_ARI_MINUS ) return ABC_OPER_ARI_MIN; // 50: arithmetic minus
155 if ( Type == WLC_OBJ_ARI_SQRT ) return ABC_OPER_ARI_SQRT; // 51: integer square root
156 if ( Type == WLC_OBJ_ARI_SQUARE ) return ABC_OPER_ARI_SQUARE; // 52: integer square
157 if ( Type == WLC_OBJ_ARI_ADDSUB ) return ABC_OPER_ARI_ADDSUB; // 56: adder-subtractor
158 if ( Type == WLC_OBJ_ARI_MULTI ) return ABC_OPER_ARI_SMUL; // 45: signed multiplier
159 if ( Type == WLC_OBJ_FO ) return ABC_OPER_DFFRSE; // 03: flop
160 if ( Type == WLC_OBJ_FF ) return ABC_OPER_DFFRSE; // 05: flop
161 if ( Type == WLC_OBJ_READ ) return ABC_OPER_RAMR; // 54: read port
162 if ( Type == WLC_OBJ_WRITE ) return ABC_OPER_RAMW; // 55: write port
163 if ( Type == WLC_OBJ_LUT ) return ABC_OPER_LUT; // 59: LUT
164 return -1;
165}
166
167
179char * Ndr_ObjWriteConstant( unsigned * pBits, int nBits )
180{
181 static char Buffer[10000]; int i, Len;
182 assert( nBits + 10 < 10000 );
183 sprintf( Buffer, "%d\'b", nBits );
184 Len = strlen(Buffer);
185 for ( i = nBits-1; i >= 0; i-- )
186 Buffer[Len++] = '0' + Abc_InfoHasBit(pBits, i);
187 Buffer[Len] = 0;
188 return Buffer;
189}
190void * Wlc_NtkToNdr( Wlc_Ntk_t * pNtk )
191{
192 Wlc_Obj_t * pObj;
193 int i, k, iFanin, iOutId, Type;
194 // create a new module
195 void * pDesign = Ndr_Create( 1 );
196 int ModId = Ndr_AddModule( pDesign, 1 );
197 // add primary inputs
198 Vec_Int_t * vFanins = Vec_IntAlloc( 10 );
199 Wlc_NtkForEachPi( pNtk, pObj, i )
200 {
201 iOutId = Wlc_ObjId(pNtk, pObj);
202 Ndr_AddObject( pDesign, ModId, ABC_OPER_CI, 0,
203 pObj->End, pObj->Beg, pObj->Signed,
204 0, NULL, 1, &iOutId, NULL ); // no fanins
205 }
206 // add internal nodes
207 Wlc_NtkForEachObj( pNtk, pObj, iOutId )
208 {
209 char * pFunction = NULL;
210 if ( Wlc_ObjIsPi(pObj) || pObj->Type == 0 )
211 continue;
212 Vec_IntClear( vFanins );
213 Wlc_ObjForEachFanin( pObj, iFanin, k )
214 Vec_IntPush( vFanins, iFanin );
215 if ( pObj->Type == WLC_OBJ_CONST )
216 pFunction = Ndr_ObjWriteConstant( (unsigned *)Wlc_ObjFanins(pObj), Wlc_ObjRange(pObj) );
217 if ( pObj->Type == WLC_OBJ_MUX && Wlc_ObjRange(Wlc_ObjFanin0(pNtk, pObj)) > 1 )
218 Type = ABC_OPER_SEL_NMUX;
219 else if ( pObj->Type == WLC_OBJ_FO )
220 {
221 Wlc_Obj_t * pFi = Wlc_ObjFo2Fi( pNtk, pObj );
222 assert( Vec_IntSize(vFanins) == 0 );
223 Vec_IntPush( vFanins, Wlc_ObjId(pNtk, pFi) );
224 Vec_IntFillExtra( vFanins, 7, 0 );
225 Type = ABC_OPER_DFFRSE;
226 }
227 else
228 Type = Ndr_TypeWlc2Ndr(pObj->Type);
229 assert( Type > 0 );
230 Ndr_AddObject( pDesign, ModId, Type, 0,
231 pObj->End, pObj->Beg, pObj->Signed,
232 Vec_IntSize(vFanins), Vec_IntArray(vFanins), 1, &iOutId, pFunction );
233 }
234 // add primary outputs
235 Wlc_NtkForEachObj( pNtk, pObj, iOutId )
236 {
237 if ( !Wlc_ObjIsPo(pObj) )
238 continue;
239 Vec_IntFill( vFanins, 1, iOutId );
240 Ndr_AddObject( pDesign, ModId, ABC_OPER_CO, 0,
241 pObj->End, pObj->Beg, pObj->Signed,
242 1, Vec_IntArray(vFanins), 0, NULL, NULL );
243 }
244 Vec_IntFree( vFanins );
245 return pDesign;
246}
247void Wlc_WriteNdr( Wlc_Ntk_t * pNtk, char * pFileName )
248{
249 void * pDesign = Wlc_NtkToNdr( pNtk );
250 Ndr_Write( pFileName, pDesign );
251 Ndr_Delete( pDesign );
252 printf( "Dumped the current design into file \"%s\".\n", pFileName );
253}
255{
256 // transform
257 void * pDesign = Wlc_NtkToNdr( pNtk );
258
259 // collect names
260 Wlc_Obj_t * pObj; int i;
261 char ** ppNames = ABC_ALLOC( char *, Wlc_NtkObjNum(pNtk) + 1 );
262 Wlc_NtkForEachObj( pNtk, pObj, i )
263 ppNames[i] = Wlc_ObjName(pNtk, i);
264
265 // verify by writing Verilog
266 Ndr_WriteVerilog( NULL, pDesign, ppNames, 0 );
267 Ndr_Write( "test.ndr", pDesign );
268
269 // cleanup
270 Ndr_Delete( pDesign );
271 ABC_FREE( ppNames );
272}
273
285int Ndr_ObjReadRange( Ndr_Data_t * p, int Obj, int * End, int * Beg )
286{
287 int * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_RANGE, &pArray );
288 int Signed = 0; *End = *Beg = 0;
289 if ( nArray == 0 )
290 return 0;
291 if ( nArray == 3 )
292 Signed = 1;
293 if ( nArray == 1 )
294 *End = *Beg = pArray[0];
295 else
296 *End = pArray[0], *Beg = pArray[1];
297 return Signed;
298}
299void Ndr_ObjReadConstant( Vec_Int_t * vFanins, char * pStr )
300{
301 int i, k, Len = pStr ? strlen(pStr) : 0;
302 for ( k = 0; k < Len; k++ )
303 if ( pStr[k] == 'b' )
304 break;
305 if ( pStr == NULL || pStr[k] != 'b' )
306 {
307 printf( "Constants should be represented in binary Verilog notation <nbits>\'b<bits> as char strings (for example, \"4'b1010\").\n" );
308 return;
309 }
310 Vec_IntFill( vFanins, Abc_BitWordNum(Len-k-1), 0 );
311 for ( i = k+1; i < Len; i++ )
312 if ( pStr[i] == '1' )
313 Abc_InfoSetBit( (unsigned *)Vec_IntArray(vFanins), Len-i-1 );
314 else if ( pStr[i] != '0' )
315 printf( "Wrongn symbol (%c) in binary Verilog constant \"%s\".\n", pStr[i], pStr );
316}
318{
319 Wlc_Obj_t * pObj; int i, k;
320 printf( "Node IDs and their fanins:\n" );
321 Wlc_NtkForEachObj( pNtk, pObj, i )
322 {
323 int * pFanins = Wlc_ObjFanins(pObj);
324 printf( "%5d = ", i );
325 for ( k = 0; k < Wlc_ObjFaninNum(pObj); k++ )
326 printf( "%5d ", pFanins[k] );
327 for ( ; k < 4; k++ )
328 printf( " " );
329 printf( " Name Id %d ", Wlc_ObjNameId(pNtk, i) );
330 if ( Wlc_ObjIsPi(pObj) )
331 printf( " pi " );
332 if ( Wlc_ObjIsPo(pObj) )
333 printf( " po " );
334 printf( "\n" );
335 }
336}
337void Wlc_NtkCheckIntegrity( void * pData )
338{
339 Ndr_Data_t * p = (Ndr_Data_t *)pData;
340 Vec_Int_t * vMap = Vec_IntAlloc( 100 );
341 int Mod = 2, Obj;
342 Ndr_ModForEachObj( p, Mod, Obj )
343 {
344 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
345 if ( NameId == -1 )
346 {
347 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
348 if ( Type != ABC_OPER_CO )
349 printf( "Internal object %d of type %s has no output name.\n", Obj, Abc_OperName(Type) );
350 continue;
351 }
352 if ( Vec_IntGetEntry(vMap, NameId) > 0 )
353 printf( "Output name %d is used more than once (obj %d and obj %d).\n", NameId, Vec_IntGetEntry(vMap, NameId), Obj );
354 Vec_IntSetEntry( vMap, NameId, Obj );
355 }
356 Ndr_ModForEachObj( p, Mod, Obj )
357 {
358 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
359 int i, * pArray, nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
360 for ( i = 0; i < nArray; i++ )
361 if ( Vec_IntGetEntry(vMap, pArray[i]) == 0 && !(Type == ABC_OPER_DFFRSE && (i >= 5 && i <= 7)) )
362 printf( "Input name %d appearing as fanin %d of obj %d is not used as output name in any object.\n", pArray[i], i, Obj );
363 }
364 Vec_IntFree( vMap );
365}
366Wlc_Ntk_t * Wlc_NtkFromNdr( void * pData )
367{
368 Ndr_Data_t * p = (Ndr_Data_t *)pData;
369 Wlc_Obj_t * pObj; Vec_Int_t * vName2Obj, * vFanins = Vec_IntAlloc( 100 );
370 int Mod = 2, i, k, Obj, * pArray, fFound, NameId, NameIdMax;
371 unsigned char nDigits;
372 Vec_Wrd_t * vTruths = NULL; int nTruths[2] = {0};
373 Wlc_Ntk_t * pTemp, * pNtk = Wlc_NtkAlloc( "top", Ndr_DataObjNum(p, Mod)+1 );
374 Wlc_NtkCheckIntegrity( pData );
375 Vec_IntClear( &pNtk->vFfs );
376 //pNtk->pSpec = Abc_UtilStrsav( pFileName );
377 // construct network and save name IDs
378 Wlc_NtkCleanNameId( pNtk );
379 Ndr_ModForEachPi( p, Mod, Obj )
380 {
381 int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
382 int iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_PI, Signed, End, Beg );
383 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
384 Wlc_ObjSetNameId( pNtk, iObj, NameId );
385 }
386 Ndr_ModForEachNode( p, Mod, Obj )
387 {
388 int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
389 int Type = Ndr_ObjReadBody( p, Obj, NDR_OPERTYPE );
390 int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
391 Vec_Int_t F = {nArray, nArray, pArray}, * vTemp = &F;
392 int iObj = Wlc_ObjAlloc( pNtk, Ndr_TypeNdr2Wlc(Type), Signed, End, Beg );
393 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
394 Vec_IntClear( vFanins );
395 Vec_IntAppend( vFanins, vTemp );
396 if ( Type == ABC_OPER_DFF )
397 {
398 // save init state
399 if ( pNtk->vInits == NULL )
400 pNtk->vInits = Vec_IntAlloc( 100 );
401 if ( Vec_IntSize(vFanins) == 2 )
402 Vec_IntPush( pNtk->vInits, Vec_IntPop(vFanins) );
403 else // assume const0 if init is not given
404 Vec_IntPush( pNtk->vInits, -(End-Beg+1) );
405 // save flop output
406 pObj = Wlc_NtkObj(pNtk, iObj);
407 assert( Wlc_ObjType(pObj) == WLC_OBJ_FO );
408 Wlc_ObjSetNameId( pNtk, iObj, NameId );
409 Vec_IntPush( &pNtk->vFfs, NameId );
410 // save flop input
411 assert( Vec_IntSize(vFanins) == 1 );
412 Vec_IntPush( &pNtk->vFfs, Vec_IntEntry(vFanins, 0) );
413 continue;
414 }
415 if ( Type == ABC_OPER_DFFRSE )
416 Vec_IntPush( &pNtk->vFfs2, iObj );
417 if ( Type == ABC_OPER_LUT )
418 {
419 word * pTruth;
420 if ( vTruths == NULL )
421 vTruths = Vec_WrdStart( 1000 );
422 if ( NameId >= Vec_WrdSize(vTruths) )
423 Vec_WrdFillExtra( vTruths, 2*NameId, 0 );
424 pTruth = (word *)Ndr_ObjReadBodyP(p, Obj, NDR_FUNCTION);
425 Vec_WrdWriteEntry( vTruths, NameId, pTruth ? *pTruth : 0 );
426 nTruths[ pTruth != NULL ]++;
427 }
428 if ( Type == ABC_OPER_SLICE )
429 Vec_IntPushTwo( vFanins, End, Beg );
430 else if ( Type == ABC_OPER_CONST )
431 Ndr_ObjReadConstant( vFanins, (char *)Ndr_ObjReadBodyP(p, Obj, NDR_FUNCTION) );
432 else if ( Type == ABC_OPER_BIT_MUX && Vec_IntSize(vFanins) == 3 )
433 ABC_SWAP( int, Vec_IntEntryP(vFanins, 1)[0], Vec_IntEntryP(vFanins, 2)[0] );
434 Wlc_ObjAddFanins( pNtk, Wlc_NtkObj(pNtk, iObj), vFanins );
435 Wlc_ObjSetNameId( pNtk, iObj, NameId );
436 if ( Type == ABC_OPER_ARI_SMUL )
437 {
438 pObj = Wlc_NtkObj(pNtk, iObj);
439 assert( Wlc_ObjFaninNum(pObj) == 2 );
440 Wlc_ObjFanin0(pNtk, pObj)->Signed = 1;
441 Wlc_ObjFanin1(pNtk, pObj)->Signed = 1;
442 }
443 }
444 if ( nTruths[0] )
445 printf( "Warning! The number of LUTs without function is %d (out of %d).\n", nTruths[0], nTruths[0]+nTruths[1] );
446 // mark primary outputs
447 Ndr_ModForEachPo( p, Mod, Obj )
448 {
449 int End, Beg, Signed = Ndr_ObjReadRange(p, Obj, &End, &Beg);
450 int nArray = Ndr_ObjReadArray( p, Obj, NDR_INPUT, &pArray );
451 int iObj = Wlc_ObjAlloc( pNtk, WLC_OBJ_BUF, Signed, End, Beg );
452 int NameId = Ndr_ObjReadBody( p, Obj, NDR_OUTPUT );
453 assert( nArray == 1 && NameId == -1 );
454 pObj = Wlc_NtkObj( pNtk, iObj );
455 Vec_IntFill( vFanins, 1, pArray[0] );
456 Wlc_ObjAddFanins( pNtk, pObj, vFanins );
457 Wlc_ObjSetCo( pNtk, pObj, 0 );
458 }
459 Vec_IntFree( vFanins );
460 // map name IDs into object IDs
461 vName2Obj = Vec_IntInvert( &pNtk->vNameIds, 0 );
462 Wlc_NtkForEachObj( pNtk, pObj, i )
463 {
464 int * pFanins = Wlc_ObjFanins(pObj);
465 for ( k = 0; k < Wlc_ObjFaninNum(pObj); k++ )
466 pFanins[k] = Vec_IntEntry(vName2Obj, pFanins[k]);
467 }
468 if ( pNtk->vInits )
469 {
470 Vec_IntForEachEntry( &pNtk->vFfs, NameId, i )
471 Vec_IntWriteEntry( &pNtk->vFfs, i, Vec_IntEntry(vName2Obj, NameId) );
472 Vec_IntForEachEntry( pNtk->vInits, NameId, i )
473 if ( NameId > 0 )
474 Vec_IntWriteEntry( pNtk->vInits, i, Vec_IntEntry(vName2Obj, NameId) );
475 // move FO/FI to be part of CI/CO
476 assert( (Vec_IntSize(&pNtk->vFfs) & 1) == 0 );
477 assert( Vec_IntSize(&pNtk->vFfs) == 2 * Vec_IntSize(pNtk->vInits) );
478 Wlc_NtkForEachFf( pNtk, pObj, i )
479 if ( i & 1 )
480 Wlc_ObjSetCo( pNtk, pObj, 1 );
481 //else
482 // Wlc_ObjSetCi( pNtk, pObj );
483 Vec_IntClear( &pNtk->vFfs );
484 // convert init values into binary string
485 //Vec_IntPrint( &p->pNtk->vInits );
486 pNtk->pInits = Wlc_PrsConvertInitValues( pNtk );
487 //printf( "%s", p->pNtk->pInits );
488 }
489 Vec_IntFree(vName2Obj);
490 // create fake object names
491 NameIdMax = Vec_IntFindMax(&pNtk->vNameIds);
492 nDigits = (unsigned char)Abc_Base10Log( NameIdMax+1 );
493 pNtk->pManName = Abc_NamStart( NameIdMax+1, 10 );
494 for ( i = 1; i <= NameIdMax; i++ )
495 {
496 char pName[1000]; sprintf( pName, "s%0*d", nDigits, i );
497 NameId = Abc_NamStrFindOrAdd( pNtk->pManName, pName, &fFound );
498 assert( !fFound && i == NameId );
499 }
500 //Ndr_NtkPrintNodes( pNtk );
501 //Wlc_WriteVer( pNtk, "temp_ndr.v", 0, 0 );
502 // derive topological order
503 pNtk = Wlc_NtkDupDfs( pTemp = pNtk, 0, 1 );
504 Wlc_NtkFree( pTemp );
505 // copy truth tables
506 if ( vTruths )
507 {
508 pNtk->vLutTruths = Vec_WrdStart( Wlc_NtkObjNumMax(pNtk) );
509 Wlc_NtkForEachObj( pNtk, pObj, i )
510 {
511 int iObj = Wlc_ObjId(pNtk, pObj);
512 int NameId = Wlc_ObjNameId(pNtk, iObj);
513 word Truth;
514 if ( pObj->Type != WLC_OBJ_LUT || NameId == 0 )
515 continue;
516 Truth = Vec_WrdEntry(vTruths, NameId);
517 assert( sizeof(void *) == 8 || Wlc_ObjFaninNum(pObj) < 6 );
518 Vec_WrdWriteEntry( pNtk->vLutTruths, iObj, Truth );
519 }
520 Vec_WrdFreeP( &vTruths );
521 }
522 //Ndr_NtkPrintNodes( pNtk );
523 pNtk->fMemPorts = 1; // the network contains memory ports
524 pNtk->fEasyFfs = 1; // the network contains simple flops
525 return pNtk;
526}
527
539void Ndr_DumpNdr( void * pDesign )
540{
541 int i;
542 char ** pNames = ABC_CALLOC( char *, 10000 );
543 for ( i = 0; i < 10000; i++ )
544 {
545 char Buffer[100];
546 sprintf( Buffer, "s%d", i );
547 pNames[i] = Abc_UtilStrsav( Buffer );
548 }
549 Ndr_WriteVerilog( "temp.v", pDesign, pNames, 0 );
550}
551Wlc_Ntk_t * Wlc_ReadNdr( char * pFileName )
552{
553 void * pData = Ndr_Read( pFileName );
554 Wlc_Ntk_t * pNtk = Wlc_NtkFromNdr( pData );
555 //Ndr_DumpNdr( pData );
556 //char * ppNames[10] = { NULL, "a", "b", "c", "d", "e", "f", "g", "h", "i" };
557 //Ndr_WriteVerilog( NULL, pData, ppNames, 0 );
558 //Ndr_Delete( pData );
560 return pNtk;
561}
563{
564 Wlc_Ntk_t * pNtk = Wlc_ReadNdr( "top.ndr" );
565 Wlc_WriteVer( pNtk, "top.v", 0, 0 );
566 Wlc_NtkFree( pNtk );
567}
568
572
573
575
@ ABC_OPER_DFF
Definition abcOper.h:142
@ ABC_OPER_ARI_SMUL
Definition abcOper.h:102
@ ABC_OPER_ZEROPAD
Definition abcOper.h:148
@ ABC_OPER_COMP_LESS
Definition abcOper.h:112
@ ABC_OPER_LOGIC_IMPL
Definition abcOper.h:151
@ ABC_OPER_LUT
Definition abcOper.h:127
@ ABC_OPER_CI
Definition abcOper.h:45
@ ABC_OPER_LOGIC_OR
Definition abcOper.h:86
@ ABC_OPER_RED_XOR
Definition abcOper.h:80
@ ABC_OPER_COMP_EQU
Definition abcOper.h:116
@ ABC_OPER_ARI_MUL
Definition abcOper.h:101
@ ABC_OPER_RED_NAND
Definition abcOper.h:77
@ ABC_OPER_DFFRSE
Definition abcOper.h:143
@ ABC_OPER_SIGNEXT
Definition abcOper.h:149
@ ABC_OPER_SEL_NMUX
Definition abcOper.h:91
@ ABC_OPER_BIT_NAND
Definition abcOper.h:58
@ ABC_OPER_SHIFT_RA
Definition abcOper.h:122
@ ABC_OPER_RAMW
Definition abcOper.h:134
@ ABC_OPER_ARI_REM
Definition abcOper.h:105
@ ABC_OPER_BIT_XOR
Definition abcOper.h:61
@ ABC_OPER_COMP_MORE
Definition abcOper.h:115
@ ABC_OPER_RED_NXOR
Definition abcOper.h:81
@ ABC_OPER_SHIFT_L
Definition abcOper.h:119
@ ABC_OPER_SHIFT_ROTL
Definition abcOper.h:123
@ ABC_OPER_RED_NOR
Definition abcOper.h:79
@ ABC_OPER_LOGIC_NOT
Definition abcOper.h:83
@ ABC_OPER_ARI_DIV
Definition abcOper.h:103
@ ABC_OPER_RED_AND
Definition abcOper.h:76
@ ABC_OPER_RED_OR
Definition abcOper.h:78
@ ABC_OPER_ARI_SQUARE
Definition abcOper.h:152
@ ABC_OPER_SEL_SEL
Definition abcOper.h:92
@ ABC_OPER_ARI_POW
Definition abcOper.h:106
@ ABC_OPER_CONCAT
Definition abcOper.h:147
@ ABC_OPER_BIT_MUX
Definition abcOper.h:65
@ ABC_OPER_COMP_LESSEQU
Definition abcOper.h:113
@ ABC_OPER_LOGIC_AND
Definition abcOper.h:84
@ ABC_OPER_COMP_MOREEQU
Definition abcOper.h:114
@ ABC_OPER_ARI_MOD
Definition abcOper.h:104
@ ABC_OPER_SHIFT_R
Definition abcOper.h:120
@ ABC_OPER_RAMR
Definition abcOper.h:133
@ ABC_OPER_SHIFT_LA
Definition abcOper.h:121
@ ABC_OPER_BIT_INV
Definition abcOper.h:56
@ ABC_OPER_ARI_SQRT
Definition abcOper.h:108
@ ABC_OPER_BIT_AND
Definition abcOper.h:57
@ ABC_OPER_CONST
Definition abcOper.h:153
@ ABC_OPER_SEL_DEC
Definition abcOper.h:96
@ ABC_OPER_SLICE
Definition abcOper.h:146
@ ABC_OPER_ARI_ADDSUB
Definition abcOper.h:155
@ ABC_OPER_COMP_NOTEQU
Definition abcOper.h:117
@ ABC_OPER_BIT_NOR
Definition abcOper.h:60
@ ABC_OPER_SHIFT_ROTR
Definition abcOper.h:124
@ ABC_OPER_BIT_OR
Definition abcOper.h:59
@ ABC_OPER_BIT_BUF
Definition abcOper.h:55
@ ABC_OPER_LOGIC_XOR
Definition abcOper.h:88
@ ABC_OPER_ARI_SUB
Definition abcOper.h:100
@ ABC_OPER_BIT_NXOR
Definition abcOper.h:62
@ ABC_OPER_ARI_MIN
Definition abcOper.h:107
@ ABC_OPER_CO
Definition abcOper.h:46
@ ABC_OPER_ARI_ADD
Definition abcOper.h:99
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void Abc_FrameInputNdr(Abc_Frame_t *pAbc, void *pData)
Definition mainFrame.c:89
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
Definition mainFrame.c:643
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 __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
@ NDR_RANGE
Definition ndr.h:107
@ NDR_INPUT
Definition ndr.h:103
@ NDR_FUNCTION
Definition ndr.h:108
@ NDR_OPERTYPE
Definition ndr.h:105
@ NDR_OUTPUT
Definition ndr.h:104
#define Ndr_ModForEachObj(p, Mod, Obj)
Definition ndr.h:147
struct Ndr_Data_t_ Ndr_Data_t
BASIC TYPES ///.
Definition ndr.h:119
#define Ndr_ModForEachPo(p, Mod, Obj)
Definition ndr.h:159
#define Ndr_ModForEachPi(p, Mod, Obj)
Definition ndr.h:155
#define Ndr_ModForEachNode(p, Mod, Obj)
Definition ndr.h:163
char * pInits
Definition wlc.h:148
Vec_Int_t vFfs
Definition wlc.h:144
Vec_Int_t vFfs2
Definition wlc.h:145
int fEasyFfs
Definition wlc.h:154
Vec_Wrd_t * vLutTruths
Definition wlc.h:163
Abc_Nam_t * pManName
Definition wlc.h:165
int fMemPorts
Definition wlc.h:153
Vec_Int_t * vInits
Definition wlc.h:147
Vec_Int_t vNameIds
Definition wlc.h:166
unsigned Type
Definition wlc.h:121
int End
Definition wlc.h:129
unsigned Signed
Definition wlc.h:122
int Beg
Definition wlc.h:130
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
Definition utilNam.c:453
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 Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
int Ndr_ObjReadRange(Ndr_Data_t *p, int Obj, int *End, int *Beg)
Definition wlcNdr.c:285
int Ndr_TypeWlc2Ndr(int Type)
DECLARATIONS ///.
Definition wlcNdr.c:106
void Wlc_ReadNdrTest()
Definition wlcNdr.c:562
void Wlc_WriteNdr(Wlc_Ntk_t *pNtk, char *pFileName)
Definition wlcNdr.c:247
void Wlc_NtkCheckIntegrity(void *pData)
Definition wlcNdr.c:337
Wlc_Ntk_t * Wlc_NtkFromNdr(void *pData)
Definition wlcNdr.c:366
void Wlc_NtkToNdrTest(Wlc_Ntk_t *pNtk)
Definition wlcNdr.c:254
void * Wlc_NtkToNdr(Wlc_Ntk_t *pNtk)
Definition wlcNdr.c:190
ABC_NAMESPACE_IMPL_START int Ndr_TypeNdr2Wlc(int Type)
DECLARATIONS ///.
Definition wlcNdr.c:45
void Ndr_DumpNdr(void *pDesign)
Definition wlcNdr.c:539
void Ndr_ObjReadConstant(Vec_Int_t *vFanins, char *pStr)
Definition wlcNdr.c:299
Wlc_Ntk_t * Wlc_ReadNdr(char *pFileName)
Definition wlcNdr.c:551
char * Ndr_ObjWriteConstant(unsigned *pBits, int nBits)
Definition wlcNdr.c:179
void Ndr_NtkPrintNodes(Wlc_Ntk_t *pNtk)
Definition wlcNdr.c:317
int Wlc_ObjAlloc(Wlc_Ntk_t *p, int Type, int Signed, int End, int Beg)
Definition wlcNtk.c:199
void Wlc_ObjSetCo(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, int fFlopInput)
Definition wlcNtk.c:188
Wlc_Ntk_t * Wlc_NtkDupDfs(Wlc_Ntk_t *p, int fMarked, int fSeq)
Definition wlcNtk.c:986
#define Wlc_NtkForEachFf(p, pFf, i)
Definition wlc.h:370
Wlc_Ntk_t * Wlc_NtkAlloc(char *pName, int nObjsAlloc)
Definition wlcNtk.c:152
void Wlc_NtkFree(Wlc_Ntk_t *p)
Definition wlcNtk.c:253
#define Wlc_NtkForEachPi(p, pPi, i)
Definition wlc.h:362
struct Wlc_Ntk_t_ Wlc_Ntk_t
Definition wlc.h:135
char * Wlc_PrsConvertInitValues(Wlc_Ntk_t *p)
Definition wlcReadVer.c:440
void Wlc_ObjAddFanins(Wlc_Ntk_t *p, Wlc_Obj_t *pObj, Vec_Int_t *vFanins)
Definition wlcNtk.c:240
void Wlc_WriteVer(Wlc_Ntk_t *p, char *pFileName, int fAddCos, int fNoFlops)
#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_ARI_MULTI
Definition wlc.h:90
@ WLC_OBJ_READ
Definition wlc.h:99
@ WLC_OBJ_BIT_SIGNEXT
Definition wlc.h:70
@ WLC_OBJ_COMP_LESSEQU
Definition wlc.h:80
@ WLC_OBJ_LOGIC_XOR
Definition wlc.h:75
@ WLC_OBJ_WRITE
Definition wlc.h:100
@ WLC_OBJ_SHIFT_LA
Definition wlc.h:57
@ WLC_OBJ_BIT_ZEROPAD
Definition wlc.h:69
@ WLC_OBJ_COMP_MOREEQU
Definition wlc.h:81
@ WLC_OBJ_BUF
Definition wlc.h:52
@ WLC_OBJ_COMP_MORE
Definition wlc.h:79
@ WLC_OBJ_REDUCT_AND
Definition wlc.h:82
@ WLC_OBJ_ARI_POWER
Definition wlc.h:94
@ WLC_OBJ_ARI_REM
Definition wlc.h:92
@ WLC_OBJ_ARI_SUB
Definition wlc.h:89
@ WLC_OBJ_LOGIC_OR
Definition wlc.h:74
@ WLC_OBJ_SEL
Definition wlc.h:102
@ WLC_OBJ_LOGIC_AND
Definition wlc.h:73
@ WLC_OBJ_COMP_LESS
Definition wlc.h:78
@ WLC_OBJ_ARI_SQUARE
Definition wlc.h:97
@ WLC_OBJ_REDUCT_NOR
Definition wlc.h:86
@ WLC_OBJ_BIT_NOT
Definition wlc.h:60
@ WLC_OBJ_SHIFT_R
Definition wlc.h:54
@ WLC_OBJ_BIT_AND
Definition wlc.h:61
@ WLC_OBJ_CONST
Definition wlc.h:51
@ WLC_OBJ_FO
Definition wlc.h:48
@ WLC_OBJ_ARI_DIVIDE
Definition wlc.h:91
@ WLC_OBJ_REDUCT_NAND
Definition wlc.h:85
@ WLC_OBJ_BIT_SELECT
Definition wlc.h:67
@ WLC_OBJ_REDUCT_OR
Definition wlc.h:83
@ WLC_OBJ_MUX
Definition wlc.h:53
@ WLC_OBJ_BIT_NAND
Definition wlc.h:64
@ WLC_OBJ_ARI_ADDSUB
Definition wlc.h:101
@ WLC_OBJ_LOGIC_NOT
Definition wlc.h:71
@ WLC_OBJ_COMP_NOTEQU
Definition wlc.h:77
@ WLC_OBJ_PI
Definition wlc.h:46
@ WLC_OBJ_REDUCT_XOR
Definition wlc.h:84
@ WLC_OBJ_BIT_NOR
Definition wlc.h:65
@ WLC_OBJ_BIT_CONCAT
Definition wlc.h:68
@ WLC_OBJ_BIT_OR
Definition wlc.h:62
@ WLC_OBJ_BIT_XOR
Definition wlc.h:63
@ WLC_OBJ_ARI_MINUS
Definition wlc.h:95
@ WLC_OBJ_DEC
Definition wlc.h:103
@ WLC_OBJ_ARI_MODULUS
Definition wlc.h:93
@ WLC_OBJ_ARI_ADD
Definition wlc.h:88
@ WLC_OBJ_COMP_EQU
Definition wlc.h:76
@ WLC_OBJ_ARI_SQRT
Definition wlc.h:96
@ WLC_OBJ_LOGIC_IMPL
Definition wlc.h:72
@ WLC_OBJ_SHIFT_L
Definition wlc.h:56
@ WLC_OBJ_REDUCT_NXOR
Definition wlc.h:87
@ WLC_OBJ_BIT_NXOR
Definition wlc.h:66
@ WLC_OBJ_ROTATE_L
Definition wlc.h:59
@ WLC_OBJ_LUT
Definition wlc.h:104
@ WLC_OBJ_SHIFT_RA
Definition wlc.h:55
@ WLC_OBJ_FF
Definition wlc.h:50
@ WLC_OBJ_ROTATE_R
Definition wlc.h:58
struct Wlc_Obj_t_ Wlc_Obj_t
BASIC TYPES ///.
Definition wlc.h:118