ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
wlcWriteVer.c
Go to the documentation of this file.
1
20
21#include "wlc.h"
22
24
25
29
33
45void Wlc_WriteTableOne( FILE * pFile, int nFans, int nOuts, word * pTable, int Id )
46{
47 int m, nMints = (1<<nFans);
48// Abc_TtPrintHexArrayRev( stdout, pTable, nMints ); printf( "\n" );
49 assert( nOuts > 0 && nOuts <= 64 && (64 % nOuts) == 0 );
50 fprintf( pFile, "module table%d(ind, val);\n", Id );
51 fprintf( pFile, " input [%d:0] ind;\n", nFans-1 );
52 fprintf( pFile, " output [%d:0] val;\n", nOuts-1 );
53 fprintf( pFile, " reg [%d:0] val;\n", nOuts-1 );
54 fprintf( pFile, " always @(ind)\n" );
55 fprintf( pFile, " begin\n" );
56 fprintf( pFile, " case (ind)\n" );
57 for ( m = 0; m < nMints; m++ )
58 fprintf( pFile, " %d\'h%x: val = %d\'h%x;\n", nFans, m, nOuts, (unsigned)((pTable[(nOuts * m) >> 6] >> ((nOuts * m) & 63)) & Abc_Tt6Mask(nOuts)) );
59 fprintf( pFile, " endcase\n" );
60 fprintf( pFile, " end\n" );
61 fprintf( pFile, "endmodule\n" );
62 fprintf( pFile, "\n" );
63}
64void Wlc_WriteTables( FILE * pFile, Wlc_Ntk_t * p )
65{
66 Vec_Int_t * vNodes;
67 Wlc_Obj_t * pObj, * pFanin;
68 word * pTable;
69 int i;
70 if ( p->vTables == NULL || Vec_PtrSize(p->vTables) == 0 )
71 return;
72 // map tables into their nodes
73 vNodes = Vec_IntStart( Vec_PtrSize(p->vTables) );
74 Wlc_NtkForEachObj( p, pObj, i )
75 if ( pObj->Type == WLC_OBJ_TABLE )
76 Vec_IntWriteEntry( vNodes, Wlc_ObjTableId(pObj), i );
77 // write tables
78 Vec_PtrForEachEntry( word *, p->vTables, pTable, i )
79 {
80 pObj = Wlc_NtkObj( p, Vec_IntEntry(vNodes, i) );
81 assert( pObj->Type == WLC_OBJ_TABLE );
82 pFanin = Wlc_ObjFanin0( p, pObj );
83 Wlc_WriteTableOne( pFile, Wlc_ObjRange(pFanin), Wlc_ObjRange(pObj), pTable, i );
84 }
85 Vec_IntFree( vNodes );
86}
87
100{
101 Wlc_Obj_t * pObj;
102 int i;
103 Vec_IntClear( &p->vPos );
104 Wlc_NtkForEachObj( p, pObj, i )
105 if ( pObj->Type != WLC_OBJ_PI && pObj->Type != WLC_OBJ_MUX )
106 {
107 pObj->fIsPo = 1;
108 Vec_IntPush( &p->vPos, Wlc_ObjId(p, pObj) );
109 }
110}
111
112
124void Wlc_WriteVerIntVec( FILE * pFile, Wlc_Ntk_t * p, Vec_Int_t * vVec, int Start )
125{
126 char * pName;
127 int LineLength = Start;
128 int NameCounter = 0;
129 int AddedLength, i, iObj;
130 Vec_IntForEachEntry( vVec, iObj, i )
131 {
132 pName = Wlc_ObjName( p, iObj );
133 // get the line length after this name is written
134 AddedLength = strlen(pName) + 2;
135 if ( NameCounter && LineLength + AddedLength + 3 > 70 )
136 { // write the line extender
137 fprintf( pFile, "\n " );
138 // reset the line length
139 LineLength = Start;
140 NameCounter = 0;
141 }
142 fprintf( pFile, " %s%s", pName, (i==Vec_IntSize(vVec)-1)? "" : "," );
143 LineLength += AddedLength;
144 NameCounter++;
145 }
146}
147
149{
150 Wlc_Obj_t * pFanin;
151 int i, Count = 0;
152 Wlc_ObjForEachFaninObj( p, pObj, pFanin, i )
153 Count += Wlc_ObjRange(pFanin);
154 return Count;
155}
156
157void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p, int fNoFlops )
158{
159 Wlc_Obj_t * pObj;
160 int i, k, j, iFanin;
161 char Range[100];
162 fprintf( pFile, "module %s ( ", p->pName );
163 fprintf( pFile, "\n " );
164 if ( Wlc_NtkPiNum(p) > 0 || (fNoFlops && Wlc_NtkCiNum(p)) )
165 {
166 Wlc_WriteVerIntVec( pFile, p, fNoFlops ? &p->vCis : &p->vPis, 3 );
167 fprintf( pFile, ",\n " );
168 }
169 if ( Wlc_NtkPoNum(p) > 0 || (fNoFlops && Wlc_NtkCoNum(p)) )
170 Wlc_WriteVerIntVec( pFile, p, fNoFlops ? &p->vCos : &p->vPos, 3 );
171 fprintf( pFile, " );\n" );
172 // mark fanins of rotation shifts
173 Wlc_NtkForEachObj( p, pObj, i )
174 if ( pObj->Type == WLC_OBJ_ROTATE_R || pObj->Type == WLC_OBJ_ROTATE_L )
175 Wlc_ObjFanin1(p, pObj)->Mark = 1;
176 Wlc_NtkForEachObj( p, pObj, i )
177 {
178 int nDigits = Abc_Base10Log(Abc_AbsInt(pObj->End)+1) + Abc_Base10Log(Abc_AbsInt(pObj->Beg)+1) + (int)(pObj->End < 0) + (int)(pObj->Beg < 0);
179 if ( pObj->Mark )
180 {
181 pObj->Mark = 0;
182 continue;
183 }
184 sprintf( Range, "%s[%d:%d]%*s", (!p->fSmtLib && Wlc_ObjIsSigned(pObj)) ? "signed ":" ", pObj->End, pObj->Beg, 8-nDigits, "" );
185 fprintf( pFile, " " );
186 if ( pObj->Type == WLC_OBJ_PI || (fNoFlops && pObj->Type == WLC_OBJ_FO) )
187 fprintf( pFile, "input " );
188 else if ( pObj->fIsPo || (fNoFlops && pObj->fIsFi) )
189 fprintf( pFile, "output " );
190 else
191 fprintf( pFile, " " );
192 if ( Wlc_ObjIsCi(pObj) || pObj->fIsPo || (fNoFlops && pObj->fIsFi) )
193 {
194 fprintf( pFile, "wire %s %s ;\n", Range, Wlc_ObjName(p, i) );
195 if ( Wlc_ObjIsCi(pObj) )
196 continue;
197 Range[0] = 0;
198 }
199 if ( (pObj->fIsPo || (fNoFlops && pObj->fIsFi)) && pObj->Type != WLC_OBJ_FF )
200 {
201 if ( Wlc_ObjFaninNum(pObj) == 0 )
202 continue;
203 fprintf( pFile, " assign " );
204 }
205 else if ( (pObj->Type == WLC_OBJ_MUX && Wlc_ObjFaninNum(pObj) > 3) || pObj->Type == WLC_OBJ_SEL )
206 fprintf( pFile, "reg %s ", Range );
207 else
208 fprintf( pFile, "wire %s ", Range );
209 if ( pObj->Type == WLC_OBJ_TABLE )
210 {
211 // wire [3:0] s4972; table0 s4972_Index(s4971, s4972);
212 fprintf( pFile, "%s ; table%d", Wlc_ObjName(p, i), Wlc_ObjTableId(pObj) );
213 fprintf( pFile, " s%d_Index(%s, ", i, Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
214 fprintf( pFile, "%s)", Wlc_ObjName(p, i) );
215 }
216 else if ( pObj->Type == WLC_OBJ_LUT )
217 {
218 // wire [3:0] s4972; LUT lut4972_Index(s4971, s4972);
219 fprintf( pFile, "%s ; LUT", Wlc_ObjName(p, i) );
220 fprintf( pFile, " lut%d (%s, ", i, Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
221 for ( k = 1; k < Wlc_ObjFaninNum(pObj); k++ )
222 fprintf( pFile, "%s, ", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)) );
223 fprintf( pFile, "%s)", Wlc_ObjName(p, i) );
224 if ( p->vLutTruths )
225 {
226 word Truth = Vec_WrdEntry( p->vLutTruths, Wlc_ObjId(p, pObj) );
227 fprintf( pFile, " ; // TT = " );
228 Extra_PrintHex( pFile, (unsigned *)&Truth, Wlc_ObjFaninBitNum(p, pObj) );
229 }
230 }
231 else if ( pObj->Type == WLC_OBJ_CONST )
232 {
233 fprintf( pFile, "%-16s = %d\'%sh", Wlc_ObjName(p, i), Wlc_ObjRange(pObj), Wlc_ObjIsSigned(pObj) ? "s":"" );
234 if ( pObj->fXConst )
235 {
236 for ( k = 0; k < (Wlc_ObjRange(pObj) + 3) / 4; k++ )
237 fprintf( pFile, "x" );
238 }
239 else
240 Abc_TtPrintHexArrayRev( pFile, (word *)Wlc_ObjConstValue(pObj), (Wlc_ObjRange(pObj) + 3) / 4 );
241 }
242 else if ( pObj->Type == WLC_OBJ_ROTATE_R || pObj->Type == WLC_OBJ_ROTATE_L )
243 {
244 // wire [27:0] s4960 = (s57 >> 17) | (s57 << 11);
245 Wlc_Obj_t * pShift = Wlc_ObjFanin1(p, pObj);
246 int Num0 = *Wlc_ObjConstValue(pShift);
247 int Num1 = Wlc_ObjRange(pObj) - Num0;
248 assert( pShift->Type == WLC_OBJ_CONST );
249 assert( Num0 > 0 && Num0 < Wlc_ObjRange(pObj) );
250 fprintf( pFile, "%-16s = ", Wlc_ObjName(p, i) );
251 if ( pObj->Type == WLC_OBJ_ROTATE_R )
252 fprintf( pFile, "(%s >> %d) | (%s << %d)", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Num0, Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Num1 );
253 else
254 fprintf( pFile, "(%s << %d) | (%s >> %d)", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Num0, Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Num1 );
255 }
256 else if ( pObj->Type == WLC_OBJ_MUX && Wlc_ObjFaninNum(pObj) > 3 )
257 {
258 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
259 fprintf( pFile, " " );
260 fprintf( pFile, "always @( " );
261 Wlc_ObjForEachFanin( pObj, iFanin, k )
262 fprintf( pFile, "%s%s", k ? " or ":"", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)) );
263 fprintf( pFile, " )\n" );
264 fprintf( pFile, " " );
265 fprintf( pFile, "begin\n" );
266 fprintf( pFile, " " );
267 fprintf( pFile, "case ( %s )\n", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 0)) );
268 Wlc_ObjForEachFanin( pObj, iFanin, k )
269 {
270 if ( !k ) continue;
271 fprintf( pFile, " " );
272 fprintf( pFile, "%d : %s = ", k-1, Wlc_ObjName(p, i) );
273 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)) );
274 }
275 fprintf( pFile, " " );
276 fprintf( pFile, "endcase\n" );
277 fprintf( pFile, " " );
278 fprintf( pFile, "end\n" );
279 continue;
280 }
281 else if ( pObj->Type == WLC_OBJ_SEL )
282 {
283 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
284 fprintf( pFile, " " );
285 fprintf( pFile, "always @( " );
286 Wlc_ObjForEachFanin( pObj, iFanin, k )
287 fprintf( pFile, "%s%s", k ? " or ":"", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)) );
288 fprintf( pFile, " )\n" );
289 fprintf( pFile, " " );
290 fprintf( pFile, "begin\n" );
291 fprintf( pFile, " " );
292 fprintf( pFile, "case ( %s )\n", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 0)) );
293 Wlc_ObjForEachFanin( pObj, iFanin, k )
294 {
295 if ( !k ) continue;
296 fprintf( pFile, " " );
297 fprintf( pFile, "%d\'b", Wlc_ObjFaninNum(pObj)-1 );
298 for ( j = Wlc_ObjFaninNum(pObj)-1; j > 0; j-- )
299 fprintf( pFile, "%d", (int)(j==k) );
300 fprintf( pFile, " : %s = ", Wlc_ObjName(p, i) );
301 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)) );
302 }
303 fprintf( pFile, " " );
304 fprintf( pFile, "default" );
305 fprintf( pFile, " : %s = ", Wlc_ObjName(p, i) );
306 fprintf( pFile, "%d\'b", Wlc_ObjRange(pObj) );
307 for ( j = Wlc_ObjRange(pObj)-1; j >= 0; j-- )
308 fprintf( pFile, "%d", 0 );
309 fprintf( pFile, " ;\n" );
310 fprintf( pFile, " " );
311 fprintf( pFile, "endcase\n" );
312 fprintf( pFile, " " );
313 fprintf( pFile, "end\n" );
314 continue;
315 }
316 else if ( pObj->Type == WLC_OBJ_DEC )
317 {
318 int nRange = Wlc_ObjRange(Wlc_ObjFanin0(p, pObj));
319 assert( (1 << nRange) == Wlc_ObjRange(pObj) );
320 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
321 for ( k = 0; k < Wlc_ObjRange(pObj); k++ )
322 {
323 fprintf( pFile, " " );
324 fprintf( pFile, "wire " );
325 fprintf( pFile, "%s_", Wlc_ObjName(p, i) );
326 for ( j = 0; j < nRange; j++ )
327 fprintf( pFile, "%d", (k >> (nRange-1-j)) & 1 );
328 fprintf( pFile, " = " );
329 for ( j = 0; j < nRange; j++ )
330 fprintf( pFile, "%s%s%s[%d]",
331 j ? " & ":"", ((k >> (nRange-1-j)) & 1) ? " ":"~",
332 Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 0)), nRange-1-j );
333 fprintf( pFile, " ;\n" );
334 }
335 fprintf( pFile, " " );
336 fprintf( pFile, "assign %s = { ", Wlc_ObjName(p, i) );
337 for ( k = Wlc_ObjRange(pObj)-1; k >= 0; k-- )
338 {
339 fprintf( pFile, "%s%s_", k < Wlc_ObjRange(pObj)-1 ? ", ":"", Wlc_ObjName(p, i) );
340 for ( j = 0; j < nRange; j++ )
341 fprintf( pFile, "%d", (k >> (nRange-1-j)) & 1 );
342 }
343 fprintf( pFile, " } ;\n" );
344 continue;
345 }
346 else if ( pObj->Type == WLC_OBJ_ARI_ADDSUB )
347 {
348 // out = mode ? a+b+cin : a-b-cin
349 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
350 fprintf( pFile, " " );
351 fprintf( pFile, "assign " );
352 fprintf( pFile, "%s = %s ? %s + %s + %s : %s - %s - %s ;\n",
353 Wlc_ObjName(p, i), Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)),
354 Wlc_ObjName(p, Wlc_ObjFaninId2(pObj)), Wlc_ObjName(p, Wlc_ObjFaninId(pObj,3)), Wlc_ObjName(p, Wlc_ObjFaninId1(pObj)),
355 Wlc_ObjName(p, Wlc_ObjFaninId2(pObj)), Wlc_ObjName(p, Wlc_ObjFaninId(pObj,3)), Wlc_ObjName(p, Wlc_ObjFaninId1(pObj))
356 );
357 continue;
358 }
359 else if ( pObj->Type == WLC_OBJ_READ || pObj->Type == WLC_OBJ_WRITE )
360 {
361 if ( p->fMemPorts )
362 {
363 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
364 fprintf( pFile, " " );
365 fprintf( pFile, "%s (", pObj->Type == WLC_OBJ_READ ? "ABC_READ" : "ABC_WRITE" );
366 Wlc_ObjForEachFanin( pObj, iFanin, k )
367 fprintf( pFile, " .%s(%s),", k==0 ? "mem_in" : (k==1 ? "addr": "data"), Wlc_ObjName(p, iFanin) );
368 fprintf( pFile, " .%s(%s) ) ;\n", pObj->Type == WLC_OBJ_READ ? "data" : "mem_out", Wlc_ObjName(p, i) );
369 continue;
370 }
371 else
372 {
373 int nBitsMem = Wlc_ObjRange( Wlc_ObjFanin(p, pObj, 0) );
374 //int nBitsAddr = Wlc_ObjRange( Wlc_ObjFanin(p, pObj, 1) );
375 int nBitsDat = pObj->Type == WLC_OBJ_READ ? Wlc_ObjRange(pObj) : Wlc_ObjRange(Wlc_ObjFanin(p, pObj, 2));
376 int Depth = nBitsMem / nBitsDat;
377 assert( nBitsMem % nBitsDat == 0 );
378 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
379 fprintf( pFile, " " );
380 fprintf( pFile, "%s_%d (", pObj->Type == WLC_OBJ_READ ? "CPL_MEM_READ" : "CPL_MEM_WRITE", Depth );
381 Wlc_ObjForEachFanin( pObj, iFanin, k )
382 fprintf( pFile, " .%s(%s),", k==0 ? "mem_data_in" : (k==1 ? "addr_in": "data_in"), Wlc_ObjName(p, iFanin) );
383 fprintf( pFile, " .%s(%s) ) ;\n", "data_out", Wlc_ObjName(p, i) );
384 continue;
385 }
386 }
387 else if ( pObj->Type == WLC_OBJ_FF )
388 {
389 fprintf( pFile, "%s ;\n", Wlc_ObjName(p, i) );
390 continue;
391 }
392 else
393 {
394 fprintf( pFile, "%-16s = ", Wlc_ObjName(p, i) );
395 if ( pObj->Type == WLC_OBJ_BUF )
396 fprintf( pFile, "%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
397 else if ( pObj->Type == WLC_OBJ_MUX )
398 {
399 fprintf( pFile, "%s ? ", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
400 fprintf( pFile, "%s : ", Wlc_ObjName(p, Wlc_ObjFaninId2(pObj)) );
401 fprintf( pFile, "%s", Wlc_ObjName(p, Wlc_ObjFaninId1(pObj)) );
402 }
403 else if ( pObj->Type == WLC_OBJ_ARI_MINUS )
404 fprintf( pFile, "-%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
405 else if ( pObj->Type == WLC_OBJ_BIT_NOT )
406 fprintf( pFile, "~%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
407 else if ( pObj->Type == WLC_OBJ_LOGIC_NOT )
408 fprintf( pFile, "!%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
409 else if ( pObj->Type == WLC_OBJ_REDUCT_AND )
410 fprintf( pFile, "&%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
411 else if ( pObj->Type == WLC_OBJ_REDUCT_OR )
412 fprintf( pFile, "|%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
413 else if ( pObj->Type == WLC_OBJ_REDUCT_XOR )
414 fprintf( pFile, "^%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
415 else if ( pObj->Type == WLC_OBJ_REDUCT_NAND )
416 fprintf( pFile, "~&%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
417 else if ( pObj->Type == WLC_OBJ_REDUCT_NOR )
418 fprintf( pFile, "~|%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
419 else if ( pObj->Type == WLC_OBJ_REDUCT_NXOR )
420 fprintf( pFile, "~^%s", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
421 else if ( pObj->Type == WLC_OBJ_BIT_SELECT )
422 fprintf( pFile, "%s [%d:%d]", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Wlc_ObjRangeEnd(pObj), Wlc_ObjRangeBeg(pObj) );
423 else if ( pObj->Type == WLC_OBJ_BIT_SIGNEXT )
424 fprintf( pFile, "{ {%d{%s[%d]}}, %s }", Wlc_ObjRange(pObj) - Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)), Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) - 1, Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
425 else if ( pObj->Type == WLC_OBJ_BIT_ZEROPAD )
426 fprintf( pFile, "{ {%d{1\'b0}}, %s }", Wlc_ObjRange(pObj) - Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)), Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) );
427 else if ( pObj->Type == WLC_OBJ_BIT_CONCAT )
428 {
429 fprintf( pFile, "{" );
430 Wlc_ObjForEachFanin( pObj, iFanin, k )
431 fprintf( pFile, " %s%s", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)), k == Wlc_ObjFaninNum(pObj)-1 ? "":"," );
432 fprintf( pFile, " }" );
433 }
434 else
435 {
436 fprintf( pFile, "%s ", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 0)) );
437 if ( pObj->Type == WLC_OBJ_SHIFT_R )
438 fprintf( pFile, ">>" );
439 else if ( pObj->Type == WLC_OBJ_SHIFT_RA )
440 fprintf( pFile, ">>>" );
441 else if ( pObj->Type == WLC_OBJ_SHIFT_L )
442 fprintf( pFile, "<<" );
443 else if ( pObj->Type == WLC_OBJ_SHIFT_LA )
444 fprintf( pFile, "<<<" );
445 else if ( pObj->Type == WLC_OBJ_BIT_AND )
446 fprintf( pFile, "&" );
447 else if ( pObj->Type == WLC_OBJ_BIT_OR )
448 fprintf( pFile, "|" );
449 else if ( pObj->Type == WLC_OBJ_BIT_XOR )
450 fprintf( pFile, "^" );
451 else if ( pObj->Type == WLC_OBJ_BIT_NAND )
452 fprintf( pFile, "~&" );
453 else if ( pObj->Type == WLC_OBJ_BIT_NOR )
454 fprintf( pFile, "~|" );
455 else if ( pObj->Type == WLC_OBJ_BIT_NXOR )
456 fprintf( pFile, "~^" );
457 else if ( pObj->Type == WLC_OBJ_LOGIC_IMPL )
458 fprintf( pFile, "=>" );
459 else if ( pObj->Type == WLC_OBJ_LOGIC_AND )
460 fprintf( pFile, "&&" );
461 else if ( pObj->Type == WLC_OBJ_LOGIC_OR )
462 fprintf( pFile, "||" );
463 else if ( pObj->Type == WLC_OBJ_LOGIC_XOR )
464 fprintf( pFile, "^^" );
465 else if ( pObj->Type == WLC_OBJ_COMP_EQU )
466 fprintf( pFile, "==" );
467 else if ( pObj->Type == WLC_OBJ_COMP_NOTEQU )
468 fprintf( pFile, "!=" );
469 else if ( pObj->Type == WLC_OBJ_COMP_LESS )
470 fprintf( pFile, "<" );
471 else if ( pObj->Type == WLC_OBJ_COMP_MORE )
472 fprintf( pFile, ">" );
473 else if ( pObj->Type == WLC_OBJ_COMP_LESSEQU )
474 fprintf( pFile, "<=" );
475 else if ( pObj->Type == WLC_OBJ_COMP_MOREEQU )
476 fprintf( pFile, ">=" );
477 else if ( pObj->Type == WLC_OBJ_ARI_ADD )
478 fprintf( pFile, "+" );
479 else if ( pObj->Type == WLC_OBJ_ARI_SUB )
480 fprintf( pFile, "-" );
481 else if ( pObj->Type == WLC_OBJ_ARI_MULTI )
482 fprintf( pFile, "*" );
483 else if ( pObj->Type == WLC_OBJ_ARI_DIVIDE )
484 fprintf( pFile, "/" );
485 else if ( pObj->Type == WLC_OBJ_ARI_REM )
486 fprintf( pFile, "%%" );
487 else if ( pObj->Type == WLC_OBJ_ARI_MODULUS )
488 fprintf( pFile, "%%" );
489 else if ( pObj->Type == WLC_OBJ_ARI_POWER )
490 fprintf( pFile, "**" );
491 else if ( pObj->Type == WLC_OBJ_ARI_SQRT )
492 fprintf( pFile, "@" );
493 else if ( pObj->Type == WLC_OBJ_ARI_SQUARE )
494 fprintf( pFile, "#" );
495 else
496 {
497 //assert( 0 );
498 printf( "Failed to write node \"%s\" with unknown operator type (%d).\n", Wlc_ObjName(p, i), pObj->Type );
499 fprintf( pFile, "???\n" );
500 continue;
501 }
502 fprintf( pFile, " %s", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 1)) );
503 if ( Wlc_ObjFaninNum(pObj) == 3 && pObj->Type == WLC_OBJ_ARI_ADD )
504 fprintf( pFile, " + %s", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 2)) );
505 }
506 }
507 fprintf( pFile, " ;%s\n", (p->fSmtLib && Wlc_ObjIsSigned(pObj)) ? " // signed SMT-LIB operator" : "" );
508 }
509 iFanin = 0;
510 assert( !p->vInits || Wlc_NtkFfNum(p) == Vec_IntSize(p->vInits) );
511 if ( !fNoFlops )
512 {
513 if ( p->vInits )
514 Wlc_NtkForEachCi( p, pObj, i )
515 {
516 int nDigits = Abc_Base10Log(pObj->End+1) + 1;
517 char * pName = Wlc_ObjName(p, Wlc_ObjId(p, pObj));
518 assert( i == Wlc_ObjCiId(pObj) );
519 if ( pObj->Type == WLC_OBJ_PI )
520 continue;
521 sprintf( Range, " [%d:%d]%*s", Wlc_ObjRange(pObj) - 1, 0, 8-nDigits, "" );
522 fprintf( pFile, " " );
523 fprintf( pFile, "wire %s ", Range );
524 fprintf( pFile, "%s_init%*s = ", pName, 11 - (int)strlen(pName), "" );
525 if ( Vec_IntEntry(p->vInits, i-Wlc_NtkPiNum(p)) > 0 )
526 fprintf( pFile, "%s", Wlc_ObjName(p, Wlc_ObjId(p, Wlc_NtkPi(p, Vec_IntEntry(p->vInits, i-Wlc_NtkPiNum(p))))));
527 else
528 {
529 if ( p->pInits[iFanin] == 'x' || p->pInits[iFanin] == 'X' )
530 {
531 fprintf( pFile, "%d\'h", Wlc_ObjRange(pObj) );
532 for ( k = 0; k < (Wlc_ObjRange(pObj) + 3) / 4; k++ )
533 fprintf( pFile, "x" );
534 }
535 else
536 {
537 fprintf( pFile, "%d\'b", Wlc_ObjRange(pObj) );
538 for ( k = Wlc_ObjRange(pObj)-1; k >= 0; k-- )
539 fprintf( pFile, "%c", p->pInits[iFanin + k] );
540 }
541 }
542 fprintf( pFile, ";\n" );
543 iFanin += Wlc_ObjRange(pObj);
544 }
545 Wlc_NtkForEachCi( p, pObj, i )
546 {
547 assert( i == Wlc_ObjCiId(pObj) );
548 if ( pObj->Type == WLC_OBJ_PI )
549 continue;
550 fprintf( pFile, " " );
551 if ( p->fEasyFfs )
552 {
553 fprintf( pFile, "ABC_DFF" );
554 fprintf( pFile, " reg%d (", i );
555 fprintf( pFile, " .q(%s),", Wlc_ObjName(p, Wlc_ObjId(p, pObj)) );
556 fprintf( pFile, " .d(%s),", Wlc_ObjName(p, Wlc_ObjId(p, Wlc_ObjFo2Fi(p, pObj))) );
557 if ( p->vInits )
558 fprintf( pFile, " .init(%s_init)", Wlc_ObjName(p, Wlc_ObjId(p, pObj)) );
559 fprintf( pFile, " ) ;\n" );
560 }
561 else
562 {
563 fprintf( pFile, "CPL_FF" );
564 if ( Wlc_ObjRange(pObj) > 1 )
565 fprintf( pFile, "#%d%*s", Wlc_ObjRange(pObj), 4 - Abc_Base10Log(Wlc_ObjRange(pObj)+1), "" );
566 else
567 fprintf( pFile, " " );
568 fprintf( pFile, " reg%d (", i );
569 fprintf( pFile, " .q(%s),", Wlc_ObjName(p, Wlc_ObjId(p, pObj)) );
570 fprintf( pFile, " .qbar()," );
571 fprintf( pFile, " .d(%s),", Wlc_ObjName(p, Wlc_ObjId(p, Wlc_ObjFo2Fi(p, pObj))) );
572 fprintf( pFile, " .clk(%s),", "1\'b0" );
573 fprintf( pFile, " .arst(%s),", "1\'b0" );
574 if ( p->vInits )
575 fprintf( pFile, " .arstval(%s_init)", Wlc_ObjName(p, Wlc_ObjId(p, pObj)) );
576 else
577 fprintf( pFile, " .arstval(%s)", "1\'b0" );
578 fprintf( pFile, " ) ;\n" );
579 }
580 }
581 assert( !p->vInits || iFanin == (int)strlen(p->pInits) );
582 }
583 // write DFFs in the end
584 fprintf( pFile, "\n" );
585 Wlc_NtkForEachFf2( p, pObj, i )
586 {
587 char * pInNames[8] = {"d", "clk", "reset", "set", "enable", "async", "sre", "init"};
588 fprintf( pFile, " " );
589 fprintf( pFile, "%s (", "ABC_DFFRSE" );
590 Wlc_ObjForEachFanin( pObj, iFanin, k )
591 if ( iFanin ) fprintf( pFile, " .%s(%s),", pInNames[k], Wlc_ObjName(p, iFanin) );
592 fprintf( pFile, " .%s(%s) ) ;\n", "q", Wlc_ObjName(p, Wlc_ObjId(p, pObj)) );
593 }
594 fprintf( pFile, "\n" );
595 fprintf( pFile, "endmodule\n\n" );
596}
597void Wlc_WriteVer( Wlc_Ntk_t * p, char * pFileName, int fAddCos, int fNoFlops )
598{
599 FILE * pFile;
600 pFile = fopen( pFileName, "w" );
601 if ( pFile == NULL )
602 {
603 fprintf( stdout, "Wlc_WriteVer(): Cannot open the output file \"%s\".\n", pFileName );
604 return;
605 }
606 fprintf( pFile, "// Benchmark \"%s\" from file \"%s\" written by ABC on %s\n", p->pName, p->pSpec ? p->pSpec : "unknown", Extra_TimeStamp() );
607 fprintf( pFile, "\n" );
608 Wlc_WriteTables( pFile, p );
609 if ( fAddCos )
611 Wlc_WriteVerInt( pFile, p, fNoFlops );
612 fprintf( pFile, "\n" );
613 fclose( pFile );
614}
615
619
620
622
#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
Cube * p
Definition exorList.c:222
char * Extra_TimeStamp()
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
unsigned fIsPo
Definition wlc.h:125
unsigned Type
Definition wlc.h:121
int End
Definition wlc.h:129
unsigned fIsFi
Definition wlc.h:126
unsigned fXConst
Definition wlc.h:127
unsigned Mark
Definition wlc.h:123
int Beg
Definition wlc.h:130
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
void Wlc_WriteVerInt(FILE *pFile, Wlc_Ntk_t *p, int fNoFlops)
ABC_NAMESPACE_IMPL_START void Wlc_WriteTableOne(FILE *pFile, int nFans, int nOuts, word *pTable, int Id)
DECLARATIONS ///.
Definition wlcWriteVer.c:45
int Wlc_ObjFaninBitNum(Wlc_Ntk_t *p, Wlc_Obj_t *pObj)
void Wlc_WriteVerIntVec(FILE *pFile, Wlc_Ntk_t *p, Vec_Int_t *vVec, int Start)
void Wlc_WriteTables(FILE *pFile, Wlc_Ntk_t *p)
Definition wlcWriteVer.c:64
void Wlc_WriteVer(Wlc_Ntk_t *p, char *pFileName, int fAddCos, int fNoFlops)
void Wlc_WriteAddPos(Wlc_Ntk_t *p)
Definition wlcWriteVer.c:99
#define Wlc_ObjForEachFaninObj(p, pObj, pFanin, i)
Definition wlc.h:377
#define Wlc_NtkForEachFf2(p, pFf, i)
Definition wlc.h:372
#define Wlc_NtkForEachCi(p, pCi, i)
Definition wlc.h:366
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_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_TABLE
Definition wlc.h:98
@ 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