158{
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 {
167 fprintf( pFile, ",\n " );
168 }
169 if ( Wlc_NtkPoNum(
p) > 0 || (fNoFlops && Wlc_NtkCoNum(
p)) )
171 fprintf( pFile, " );\n" );
172
175 Wlc_ObjFanin1(
p, pObj)->Mark = 1;
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);
180 {
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, " " );
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 }
200 {
201 if ( Wlc_ObjFaninNum(pObj) == 0 )
202 continue;
203 fprintf( pFile, " assign " );
204 }
206 fprintf( pFile, "reg %s ", Range );
207 else
208 fprintf( pFile, "wire %s ", Range );
210 {
211
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)) );
215 }
217 {
218
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)) );
225 {
226 word Truth = Vec_WrdEntry(
p->vLutTruths, Wlc_ObjId(
p, pObj) );
227 fprintf( pFile, " ; // TT = " );
229 }
230 }
232 {
233 fprintf( pFile,
"%-16s = %d\'%sh",
Wlc_ObjName(
p, i), Wlc_ObjRange(pObj), Wlc_ObjIsSigned(pObj) ?
"s":
"" );
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 }
243 {
244
246 int Num0 = *Wlc_ObjConstValue(pShift);
247 int Num1 = Wlc_ObjRange(pObj) - Num0;
249 assert( Num0 > 0 && Num0 < Wlc_ObjRange(pObj) );
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 }
257 {
259 fprintf( pFile, " " );
260 fprintf( pFile, "always @( " );
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)) );
269 {
270 if ( !k ) continue;
271 fprintf( pFile, " " );
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 }
282 {
284 fprintf( pFile, " " );
285 fprintf( pFile, "always @( " );
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)) );
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) );
301 fprintf( pFile,
"%s ;\n",
Wlc_ObjName(
p, Wlc_ObjFaninId(pObj, k)) );
302 }
303 fprintf( pFile, " " );
304 fprintf( pFile, "default" );
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 }
317 {
318 int nRange = Wlc_ObjRange(Wlc_ObjFanin0(
p, pObj));
319 assert( (1 << nRange) == Wlc_ObjRange(pObj) );
321 for ( k = 0; k < Wlc_ObjRange(pObj); k++ )
322 {
323 fprintf( pFile, " " );
324 fprintf( pFile, "wire " );
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) ? " ":"~",
333 fprintf( pFile, " ;\n" );
334 }
335 fprintf( pFile, " " );
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 }
347 {
348
350 fprintf( pFile, " " );
351 fprintf( pFile, "assign " );
352 fprintf( pFile, "%s = %s ? %s + %s + %s : %s - %s - %s ;\n",
356 );
357 continue;
358 }
360 {
362 {
364 fprintf( pFile, " " );
365 fprintf( pFile,
"%s (", pObj->
Type ==
WLC_OBJ_READ ?
"ABC_READ" :
"ABC_WRITE" );
367 fprintf( pFile,
" .%s(%s),", k==0 ?
"mem_in" : (k==1 ?
"addr":
"data"),
Wlc_ObjName(
p, iFanin) );
369 continue;
370 }
371 else
372 {
373 int nBitsMem = Wlc_ObjRange( Wlc_ObjFanin(
p, pObj, 0) );
374
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 );
379 fprintf( pFile, " " );
380 fprintf( pFile,
"%s_%d (", pObj->
Type ==
WLC_OBJ_READ ?
"CPL_MEM_READ" :
"CPL_MEM_WRITE", Depth );
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 }
388 {
390 continue;
391 }
392 else
393 {
396 fprintf( pFile,
"%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
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 }
404 fprintf( pFile,
"-%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
406 fprintf( pFile,
"~%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
408 fprintf( pFile,
"!%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
410 fprintf( pFile,
"&%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
412 fprintf( pFile,
"|%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
414 fprintf( pFile,
"^%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
416 fprintf( pFile,
"~&%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
418 fprintf( pFile,
"~|%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
420 fprintf( pFile,
"~^%s",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
422 fprintf( pFile,
"%s [%d:%d]",
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)), Wlc_ObjRangeEnd(pObj), Wlc_ObjRangeBeg(pObj) );
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)) );
426 fprintf( pFile,
"{ {%d{1\'b0}}, %s }", Wlc_ObjRange(pObj) - Wlc_ObjRange(Wlc_ObjFanin0(
p, pObj)),
Wlc_ObjName(
p, Wlc_ObjFaninId0(pObj)) );
428 {
429 fprintf( pFile, "{" );
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)) );
438 fprintf( pFile, ">>" );
440 fprintf( pFile, ">>>" );
442 fprintf( pFile, "<<" );
444 fprintf( pFile, "<<<" );
446 fprintf( pFile, "&" );
448 fprintf( pFile, "|" );
450 fprintf( pFile, "^" );
452 fprintf( pFile, "~&" );
454 fprintf( pFile, "~|" );
456 fprintf( pFile, "~^" );
458 fprintf( pFile, "=>" );
460 fprintf( pFile, "&&" );
462 fprintf( pFile, "||" );
464 fprintf( pFile, "^^" );
466 fprintf( pFile, "==" );
468 fprintf( pFile, "!=" );
470 fprintf( pFile, "<" );
472 fprintf( pFile, ">" );
474 fprintf( pFile, "<=" );
476 fprintf( pFile, ">=" );
478 fprintf( pFile, "+" );
480 fprintf( pFile, "-" );
482 fprintf( pFile, "*" );
484 fprintf( pFile, "/" );
486 fprintf( pFile, "%%" );
488 fprintf( pFile, "%%" );
490 fprintf( pFile, "**" );
492 fprintf( pFile, "@" );
494 fprintf( pFile, "#" );
495 else
496 {
497
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)) );
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 {
515 {
516 int nDigits = Abc_Base10Log(pObj->
End+1) + 1;
518 assert( i == Wlc_ObjCiId(pObj) );
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 }
546 {
547 assert( i == Wlc_ObjCiId(pObj) );
549 continue;
550 fprintf( pFile, " " );
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))) );
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" );
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 }
582 }
583
584 fprintf( pFile, "\n" );
586 {
587 char * pInNames[8] = {"d", "clk", "reset", "set", "enable", "async", "sre", "init"};
588 fprintf( pFile, " " );
589 fprintf( pFile, "%s (", "ABC_DFFRSE" );
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}
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
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)
#define Wlc_NtkForEachFf2(p, pFf, i)
#define Wlc_NtkForEachCi(p, pCi, i)
#define Wlc_ObjForEachFanin(pObj, iFanin, i)
char * Wlc_ObjName(Wlc_Ntk_t *p, int iObj)