452{
454 int i, k, iObj, iFin, iFon, StartPos,
Status;
455 int FileAttr = Cba_NtkStrId(
p,
"file" );
456 int LineAttr = Cba_NtkStrId(
p,
"line" );
457 int fUseNewLine = (int)(Cba_NtkPioNum(
p) > 5);
458
459 Vec_Bit_t * vPoFons = Vec_BitStart( Cba_NtkFonNum(
p)+1 );
461 if ( Cba_FonIsReal(iFon) && Cba_FonName(
p, iFon) == Cba_ObjName(
p, iObj) )
462 Vec_BitWriteEntry( vPoFons, iFon, 1 );
463
464 Vec_StrPrintStr( vStr, "module " );
465 Vec_StrPrintStr( vStr, Cba_NtkName(
p) );
466 Vec_StrPrintStr( vStr, fUseNewLine ? " (\n " : " ( " );
467 StartPos = Vec_StrSize(vStr);
469 {
470 Vec_StrPrintStr( vStr, i ? ", " : "" );
471 if ( Vec_StrSize(vStr) > StartPos + 70 )
472 {
473 StartPos = Vec_StrSize(vStr);
474 Vec_StrPrintStr( vStr, "\n " );
475 }
477 }
478 Vec_StrPrintStr( vStr, fUseNewLine ? "\n );" : " );" );
480 Vec_StrPrintStr( vStr, fUseNewLine ? "\n" : "\n\n" );
481
483 {
484 int Offset = Vec_StrSize(vStr);
485 Vec_StrPrintStr( vStr, " " );
486 Vec_StrPrintStr( vStr, Cba_ObjIsPi(
p, iObj) ?
"input " :
"output " );
489 Vec_StrPrintF( vStr, ";%*s", Offset + 40 - Vec_StrSize(vStr), "" );
491 Vec_StrPush( vStr, '\n' );
492 }
493 Vec_StrPrintStr( vStr, "\n" );
494
496 {
497
498
499 int Type = Cba_ObjType(
p, iObj);
500 if ( Cba_ObjIsSlice(
p, iObj) )
501 continue;
502 if ( fInlineConcat && Cba_ObjIsConcat(
p, iObj) )
503 continue;
504 if ( Cba_ObjIsBoxUser(
p, iObj) )
505 {
507
509 {
510 if ( Vec_BitEntry(vPoFons, iFon) )
511 continue;
512 Vec_StrPrintStr( vStr, " wire " );
515 Vec_StrPrintStr( vStr, ";\n" );
516 }
517
518 Vec_StrPrintStr( vStr, " " );
519 Vec_StrPrintStr( vStr, Cba_NtkName(pNtk) );
520 Vec_StrPush( vStr, ' ' );
521 if ( Cba_ObjName(
p, iObj) )
523
524 Vec_StrPrintStr( vStr, "( " );
526 {
527 Vec_StrPrintF( vStr,
"%s.%s(", i ?
", " :
"",
Cba_ObjGetName(pNtk, Cba_NtkPi(pNtk, i)) );
529 Vec_StrPush( vStr, ')' );
530 }
531
533 {
534 Vec_StrPrintF( vStr,
"%s.%s(", Cba_ObjFinNum(
p, iObj) ?
", " :
"",
Cba_ObjGetName(pNtk, Cba_NtkPo(pNtk, i)) );
536 Vec_StrPush( vStr, ')' );
537 }
538 Vec_StrPrintStr( vStr, ");" );
539 }
541 {
543 char * pBoxName[3] = { "RAM_WRITE", "RAM_READ", "RAM_BOX" };
544 char * pOutputs[3] = { "ram", "rdata", "out" };
545 char * pInputs[3][4] = { {"clk", "wen", "waddr", "wdata"}, {"ren", "raddr", "ram"}, {"in0", "in1", "in2", "in3"} };
546
547 int iFonOut = Cba_ObjFon0(
p, iObj);
548 if ( Vec_BitEntry(vPoFons, iFonOut) )
549 Vec_StrPrintStr( vStr, " assign " );
550 else
551 {
552 Vec_StrPrintStr( vStr, " wire " );
554 }
556 Vec_StrPrintStr( vStr, ";\n" );
557
558 Vec_StrPrintF( vStr, " %s( ", pBoxName[Num] );
560 {
561 Vec_StrPrintF( vStr, "%s.%s(", i ? ", " : "", pInputs[Num][i] );
563 Vec_StrPush( vStr, ')' );
564 }
565 Vec_StrPrintF( vStr,
"%s.%s(", Cba_ObjFinNum(
p, iObj) ?
", " :
"", pOutputs[Num] );
567 Vec_StrPrintStr( vStr, ") );" );
568 }
570 {
572 int nBits = fUseSel ? Cba_ObjFinNum(
p, iObj) - 1 : Abc_Base2Log(Cba_ObjFinNum(
p, iObj) - 1);
573 int iFonIn = Cba_ObjFinFon(
p, iObj, 0);
574 int iFonOut = Cba_ObjFon0(
p, iObj);
575
576 Vec_StrPrintStr( vStr, " function " );
578 Vec_StrPrintStr( vStr, "_func_" );
580 Vec_StrPrintStr( vStr, ";\n" );
581
582 Vec_StrPrintStr( vStr, " input " );
584 Vec_StrPrintStr( vStr, "s;\n" );
585
586 Vec_StrPrintStr( vStr, " input " );
589 {
590 if ( i == 0 ) continue;
591 Vec_StrPrintF( vStr, "%sd%d", i > 1 ? ", " : "", i-1 );
592 }
593 Vec_StrPrintStr( vStr, ";\n" );
594
595 Vec_StrPrintStr( vStr, " casez(s)" );
596 if ( fUseSel )
597 Vec_StrPrintStr( vStr, " // synopsys full_case parallel_case" );
598 Vec_StrPrintStr( vStr, "\n" );
599
601 {
602 if ( i == 0 ) continue;
603 Vec_StrPrintF( vStr, " %d\'b", nBits );
604 if ( fUseSel )
605 {
606 Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + nBits, '?' );
607 Vec_StrWriteEntry( vStr, Vec_StrSize(vStr) - i, '1' );
608 }
609 else
610 {
611 for ( k = nBits-1; k >= 0; k-- )
612 Vec_StrPrintNum( vStr, ((i-1) >> k) & 1 );
613 }
614 Vec_StrPrintStr( vStr, ": _func_" );
616 Vec_StrPrintF( vStr, " = d%d;\n", i-1 );
617 }
618 Vec_StrPrintStr( vStr, " endcase\n" );
619 Vec_StrPrintStr( vStr, " endfunction\n" );
620
621 if ( Vec_BitEntry(vPoFons, iFonOut) )
622 Vec_StrPrintStr( vStr, " assign " );
623 else
624 {
625 Vec_StrPrintStr( vStr, " wire " );
627 }
629 Vec_StrPrintStr( vStr, " = _func_" );
631 Vec_StrPrintStr( vStr, " ( " );
633 {
634 Vec_StrPrintStr( vStr, i ? ", " : "" );
636 }
637 Vec_StrPrintStr( vStr, " );" );
638 }
640 {
641 int iFonIn = Cba_ObjFinFon(
p, iObj, 0);
642 int iFonOut = Cba_ObjFon0(
p, iObj);
643 int nBitsIn = Cba_FonRangeSize(
p, iFonIn);
644 int nBitsOut = Cba_FonRangeSize(
p, iFonOut);
645 assert( (1 << nBitsIn) == nBitsOut );
646
647 Vec_StrPrintStr( vStr, " function " );
649 Vec_StrPrintStr( vStr, "_func_" );
651 Vec_StrPrintStr( vStr, ";\n" );
652
653 Vec_StrPrintStr( vStr, " input " );
655 Vec_StrPrintStr( vStr, "i;\n" );
656
657 Vec_StrPrintStr( vStr, " casez(i)\n" );
658
659 for ( i = 0; i < (1 << nBitsIn); i++ )
660 {
661 Vec_StrPrintF( vStr, " %d\'b", nBitsIn );
662 for ( k = nBitsIn-1; k >= 0; k-- )
663 Vec_StrPrintNum( vStr, (i >> k) & 1 );
664 Vec_StrPrintStr( vStr, ": _func_" );
666 Vec_StrPrintF( vStr, " = %d\'b%0*d;\n", nBitsOut, nBitsOut, 0 );
667 Vec_StrWriteEntry( vStr, Vec_StrSize(vStr) - i - 3, '1' );
668 }
669 Vec_StrPrintStr( vStr, " endcase\n" );
670 Vec_StrPrintStr( vStr, " endfunction\n" );
671
672 if ( Vec_BitEntry(vPoFons, iFonOut) )
673 Vec_StrPrintStr( vStr, " assign " );
674 else
675 {
676 Vec_StrPrintStr( vStr, " wire " );
678 }
680 Vec_StrPrintStr( vStr, " = _func_" );
682 Vec_StrPrintStr( vStr, " ( " );
684 Vec_StrPrintStr( vStr, " );" );
685 }
687 {
689 int iFonQ = Cba_ObjFon0(
p, iObj);
690 int iFonD = Cba_ObjFinFon(
p, iObj, 0);
691 int iFonSet = Cba_ObjFinFon(
p, iObj, 1);
692 int iFonRst = Cba_ObjFinFon(
p, iObj, 2);
693 int iFonC = Cba_ObjFinFon(
p, iObj, 3);
694 int Range = Cba_FonRangeSize(
p, iFonQ );
695 assert( Cba_FonRangeSize(
p, iFonSet) == 1 && Cba_FonRangeSize(
p, iFonRst) == 1 );
696
697 Vec_StrPrintStr( vStr, " reg " );
700 Vec_StrPrintStr( vStr, ";\n" );
701
702 Vec_StrPrintStr( vStr, " always @(" );
703 if ( fUseFlop )
704 Vec_StrPrintStr( vStr, "posedge " );
706 if ( !fUseFlop )
707 {
708 Vec_StrPrintStr( vStr, " or " );
710 }
711 if ( iFonSet > 0 )
712 {
713 Vec_StrPrintStr( vStr, " or " );
714 if ( fUseFlop )
715 Vec_StrPrintStr( vStr, "posedge " );
717 }
718 if ( iFonRst > 0 )
719 {
720 Vec_StrPrintStr( vStr, " or " );
721 if ( fUseFlop )
722 Vec_StrPrintStr( vStr, "posedge " );
724 }
725 Vec_StrPrintStr( vStr, ")\n" );
726
727 if ( iFonSet > 0 )
728 {
729 Vec_StrPrintStr( vStr, " if (" );
731 Vec_StrPrintStr( vStr, ") " );
733 Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " );
734
735 Vec_StrPrintNum( vStr, Range );
736 Vec_StrPrintStr( vStr, "\'b" );
737 Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '1' );
738 Vec_StrPrintStr( vStr, ";\n" );
739
740 }
741 if ( iFonRst > 0 )
742 {
743 Vec_StrPrintStr( vStr, iFonSet > 0 ? " else if (" : " if (" );
745 Vec_StrPrintStr( vStr, ") " );
747 Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " );
748
749 Vec_StrPrintNum( vStr, Range );
750 Vec_StrPrintStr( vStr, "\'b" );
751 Vec_StrFillExtra( vStr, Vec_StrSize(vStr) + Range, '0' );
752 Vec_StrPrintStr( vStr, ";\n" );
753
754 }
755 Vec_StrPrintStr( vStr, (iFonSet > 0 || iFonRst > 0) ? " else " : " " );
756 if ( !fUseFlop )
757 {
758 Vec_StrPrintStr( vStr, " if (" );
760 Vec_StrPrintStr( vStr, ") " );
761 }
763 Vec_StrPrintStr( vStr, fUseFlop ? " <= " : " = " );
765 Vec_StrPrintStr( vStr, ";" );
766 }
768 {
769
770 int iFon0 = Cba_ObjFon0(
p, iObj);
771 int iFon1 = Cba_ObjFon(
p, iObj, 1);
772 int Range = Cba_FonRangeSize(
p, iFon0 );
773 if ( !Vec_BitEntry(vPoFons, iFon0) )
774 {
775 Vec_StrPrintStr( vStr, " wire " );
778 Vec_StrPrintStr( vStr, ";\n" );
779 }
780 if ( !Vec_BitEntry(vPoFons, iFon1) && Cba_FonName(
p, iFon1) )
781 {
782 Vec_StrPrintStr( vStr, " wire " );
785 Vec_StrPrintStr( vStr, ";\n" );
786 }
787 Vec_StrPrintStr( vStr, " CPL_FF" );
788 if ( Range > 1 )
789 Vec_StrPrintF( vStr, "#%d", Range );
790 Vec_StrPrintStr( vStr, " " );
791 if ( Cba_ObjName(
p, iObj) )
793 Vec_StrPrintStr( vStr, " ( .d(" );
795 Vec_StrPrintStr( vStr, "), .arstval(" );
797 Vec_StrPrintStr( vStr, "), .arst(" );
799 Vec_StrPrintStr( vStr, "), .clk(" );
801 Vec_StrPrintStr( vStr, "), .q(" );
803 Vec_StrPrintStr( vStr, "), .qbar(" );
804 if ( Cba_FonName(
p, iFon1) )
806 Vec_StrPrintStr( vStr, ") );" );
807 }
809 {
810 int iFon0 = Cba_ObjFon0(
p, iObj);
811 int iFon1 = Cba_ObjFon(
p, iObj, 1);
812
813 if ( Cba_FonName(
p, iFon1) )
814 {
815 if ( !Vec_BitEntry(vPoFons, iFon0) )
816 {
817 Vec_StrPrintStr( vStr, " wire " );
820 Vec_StrPrintStr( vStr, ";\n" );
821 }
822 if ( !Vec_BitEntry(vPoFons, iFon1) )
823 {
824 Vec_StrPrintStr( vStr, " wire " );
827 Vec_StrPrintStr( vStr, ";\n" );
828 }
829 Vec_StrPrintStr( vStr, " assign {" );
831 Vec_StrPrintStr( vStr, ", " );
833 Vec_StrPrintStr( vStr, "} = " );
834 }
835 else
836 {
837 if ( Vec_BitEntry(vPoFons, iFon0) )
838 Vec_StrPrintStr( vStr, " assign " );
839 else
840 {
841 Vec_StrPrintStr( vStr, " wire " );
843 }
845 Vec_StrPrintStr( vStr, " = " );
846 }
847
848 if ( Cba_ObjFinFon(
p, iObj, 0) && Cba_ObjFinFon(
p, iObj, 0) != Cba_FonFromConst(1) )
849 {
850 Vec_StrPush( vStr, ' ' );
852 Vec_StrPush( vStr, ' ' );
853 Vec_StrPrintStr( vStr, "+" );
854 }
855 Vec_StrPush( vStr, ' ' );
857 Vec_StrPush( vStr, ' ' );
858 Vec_StrPrintStr( vStr, "+" );
859 Vec_StrPush( vStr, ' ' );
861 Vec_StrPush( vStr, ';' );
862 }
863 else
864 {
865 if ( Vec_BitEntry(vPoFons, Cba_ObjFon0(
p, iObj)) )
866 Vec_StrPrintStr( vStr, " assign " );
867 else
868 {
869 Vec_StrPrintStr( vStr, " wire " );
871 }
873 Vec_StrPrintStr( vStr, " = " );
874 if ( Cba_ObjIsConcat(
p, iObj) )
877 {
879 Vec_StrPrintStr( vStr, " ? " );
881 Vec_StrPrintStr( vStr, " : " );
883 }
885 {
886
887 int Range = Cba_FonRangeSize(
p, Cba_ObjFon0(
p, iObj) );
888 int iFinFon1 = Cba_ObjFinFon(
p, iObj, 1);
889 Vec_StrPush( vStr, '(' );
891 Vec_StrPrintStr( vStr, Type ==
CBA_BOX_ROTL ?
" << " :
" >> " );
892 if ( Cba_FonIsConst(iFinFon1) )
893 Vec_StrPrintNum( vStr, Cba_FonConst(iFinFon1) );
894 else
896 Vec_StrPrintStr( vStr, ") | (" );
898 Vec_StrPrintStr( vStr, Type ==
CBA_BOX_ROTL ?
" >> " :
" << " );
899 if ( Cba_FonIsConst(iFinFon1) )
900 Vec_StrPrintNum( vStr, Range - Cba_FonConst(iFinFon1) );
901 else
902 {
903 Vec_StrPush( vStr, '(' );
904 Vec_StrPrintNum( vStr, Range );
905 Vec_StrPrintStr( vStr, " - " );
907 Vec_StrPush( vStr, ')' );
908 }
909 Vec_StrPush( vStr, ')' );
910 }
912 {
913 int fLessThan = (Cba_ObjFinFon(
p, iObj, 0) == Cba_FonFromConst(1));
914 Vec_StrPush( vStr, ' ' );
916 Vec_StrPush( vStr, ' ' );
917 Vec_StrPrintStr( vStr, fLessThan ? "<" : "<=" );
918 Vec_StrPush( vStr, ' ' );
920 }
922 {
923 Vec_StrPrintStr( vStr, Cba_NtkTypeName(
p, Type) );
925 }
926 else if ( Cba_NtkTypeName(
p, Type) )
927 {
929 if ( fCompl )
930 Vec_StrPrintStr( vStr, "!(" );
932 Vec_StrPush( vStr, ' ' );
933 Vec_StrPrintStr( vStr, Cba_NtkTypeName(
p, Type) );
934 Vec_StrPush( vStr, ' ' );
936 if ( fCompl )
937 Vec_StrPrintStr( vStr, ")" );
938 }
939 else
940 {
942 Vec_StrPrintStr( vStr, "<unknown operator>" );
943 printf(
"Cba_ManWriteVerilog(): In module \"%s\", cannot write object \"%s\" with output name \"%s\".\n", Cba_NtkName(
p),
Cba_ObjGetName(
p, iObj), pName );
944 }
945 Vec_StrPush( vStr, ';' );
946 }
947
949 if ( !Cba_ObjIsBoxUser(
p, iObj) && Cba_ObjName(
p, iObj) )
950 {
951 if ( !Status )
952 Vec_StrPrintStr( vStr, " //" );
953 Vec_StrPrintStr( vStr, " name=" );
955 }
956 Vec_StrPush( vStr, '\n' );
957 }
958
960 {
961 iFon = Cba_ObjFinFon(
p, iObj, 0);
962 if ( !iFon || (!Cba_FonIsConst(iFon) && Cba_FonName(
p, iFon) == Cba_ObjName(
p, iObj)) )
963 continue;
964 Vec_StrPrintStr( vStr, " assign " );
966 Vec_StrPrintStr( vStr, " = " );
968 Vec_StrPush( vStr, ';' );
969 Vec_StrPush( vStr, '\n' );
970 }
971 Vec_StrPrintStr( vStr, "\n" );
972 Vec_StrPrintStr( vStr, "endmodule\n\n" );
973 Vec_BitFree( vPoFons );
974}
Cba_ObjType_t
INCLUDES ///.
void Cba_ManWriteFonRange(Cba_Ntk_t *p, int iFon)
char * Cba_ObjGetName(Cba_Ntk_t *p, int i)
int Cba_ManWriteLineFile(Cba_Ntk_t *p, int iObj, int FileAttr, int LineAttr)
#define Cba_NtkForEachPioOrder(p, iObj, i)
#define Cba_NtkForEachBox(p, i)
#define Cba_NtkForEachPo(p, iObj, i)
#define Cba_ObjForEachFon(p, iObj, iFon, k)
#define Cba_NtkForEachPoDriverFon(p, iObj, iFon, i)
typedefABC_NAMESPACE_HEADER_START struct Vec_Bit_t_ Vec_Bit_t
INCLUDES ///.