diff --git a/src/base/wln/wlnCom.c b/src/base/wln/wlnCom.c index 2436932cd..e471bc877 100644 --- a/src/base/wln/wlnCom.c +++ b/src/base/wln/wlnCom.c @@ -92,13 +92,16 @@ void Wln_End( Abc_Frame_t * pAbc ) ******************************************************************************/ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose ); - extern Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pFileName2, char * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fSetUndef, int fVerbose ); - extern Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fCollapse, int fVerbose ); + extern Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose ); + extern Gia_Man_t * Wln_BlastSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fSetUndef, int fVerbose ); + extern Rtl_Lib_t * Wln_ReadSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, int fCollapse, int fVerbose ); FILE * pFile; char * pFileName = NULL; char * pFileName2= NULL; + char ** ppFileNames = NULL; + int nFileNames = 0; + int fFileNamesAlloc = 0; char * pTopModule= NULL; char * pDefines = NULL; char * pLibrary = NULL; @@ -194,48 +197,64 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv ) goto usage; } } - if ( argc != globalUtilOptind + 1 ) + nFileNames = argc - globalUtilOptind; + if ( nFileNames < 1 ) { - printf( "Abc_CommandReadWlc(): Input file name should be given on the command line.\n" ); + printf( "Abc_CommandReadWlc(): Input file name(s) should be given on the command line.\n" ); return 0; } - // get the file name - pFileName = argv[globalUtilOptind]; - if ( (pFile = fopen( pFileName, "r" )) == NULL ) - { - Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName ); - if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".sv", NULL, NULL, NULL )) ) - Abc_Print( 1, "Did you mean \"%s\"?", pFileName ); - Abc_Print( 1, "\n" ); - return 0; - } - fclose( pFile ); + ppFileNames = pFileName2 ? ABC_ALLOC( char *, nFileNames + 1 ) : argv + globalUtilOptind; + fFileNamesAlloc = pFileName2 != NULL; if ( pFileName2 ) { - if ( (pFile = fopen( pFileName2, "r" )) == NULL ) + int i; + for ( i = 0; i < nFileNames; i++ ) + ppFileNames[i] = argv[globalUtilOptind + i]; + ppFileNames[nFileNames++] = pFileName2; + } + pFileName = ppFileNames[0]; + for ( c = 0; c < nFileNames; c++ ) + { + if ( (pFile = fopen( ppFileNames[c], "r" )) == NULL ) { - Abc_Print( 1, "Cannot open input file \"%s\".\n", pFileName2 ); + Abc_Print( 1, "Cannot open input file \"%s\". ", ppFileNames[c] ); + if ( (pFileName = Extra_FileGetSimilarName( ppFileNames[c], ".v", ".sv", NULL, NULL, NULL )) ) + Abc_Print( 1, "Did you mean \"%s\"?", pFileName ); + Abc_Print( 1, "\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } fclose( pFile ); } - - // perform reading - if ( pLibrary ) + pFileName = ppFileNames[0]; + if ( nFileNames > 1 ) { - if ( pFileName2 ) + int i, fAllVerilog = 1; + for ( i = 0; i < nFileNames; i++ ) + fAllVerilog &= Extra_FileIsType( ppFileNames[i], ".v", ".sv", NULL ); + if ( !fAllVerilog ) { - Abc_Print( 1, "Command line switch \"-F\" only applies in the default bit-blasting path.\n" ); + Abc_Print( 1, "Multiple input files are supported only for Verilog/SystemVerilog files.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } + } + + // perform reading + if ( pLibrary ) + { Abc_Ntk_t * pNtk = NULL; if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - pNtk = Wln_ReadMappedSystemVerilog( pFileName, pTopModule, pDefines, pLibrary, fVerbose ); + pNtk = Wln_ReadMappedSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, pLibrary, fVerbose ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) ) - pNtk = Wln_ReadMappedSystemVerilog( pFileName, pTopModule, pDefines, pLibrary, fVerbose ); + pNtk = Wln_ReadMappedSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, pLibrary, fVerbose ); else { printf( "Abc_CommandYosys(): Unknown file extension.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } Abc_FrameReplaceCurrentNetwork( pAbc, pNtk ); @@ -244,55 +263,67 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv ) { Gia_Man_t * pNew = NULL; if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - pNew = Wln_BlastSystemVerilog( pFileName, pFileName2, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); + pNew = Wln_BlastSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) ) - pNew = Wln_BlastSystemVerilog( pFileName, pFileName2, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); + pNew = Wln_BlastSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "rtlil" ) ) { - if ( pFileName2 ) + if ( nFileNames > 1 ) { - Abc_Print( 1, "Command line switch \"-F\" is only supported when the main input is Verilog/SystemVerilog.\n" ); + Abc_Print( 1, "Multiple input files are supported only for Verilog/SystemVerilog files.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } - pNew = Wln_BlastSystemVerilog( pFileName, NULL, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); + pNew = Wln_BlastSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fSkipStrash, fInvert, fTechMap, fLibInDir, fSetUndef, fVerbose ); } else { printf( "Abc_CommandYosys(): Unknown file extension.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } Abc_FrameUpdateGia( pAbc, pNew ); } else { - if ( pFileName2 ) - { - Abc_Print( 1, "Command line switch \"-F\" only applies in the default bit-blasting path.\n" ); - return 0; - } Rtl_Lib_t * pLib = NULL; if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) ) - pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, pDefines, fCollapse, fVerbose ); + pLib = Wln_ReadSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fCollapse, fVerbose ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) ) - pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, pDefines, fCollapse, fVerbose ); + pLib = Wln_ReadSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fCollapse, fVerbose ); else if ( !strcmp( Extra_FileNameExtension(pFileName), "rtlil" ) ) - pLib = Wln_ReadSystemVerilog( pFileName, pTopModule, pDefines, fCollapse, fVerbose ); + { + if ( nFileNames > 1 ) + { + Abc_Print( 1, "Multiple input files are supported only for Verilog/SystemVerilog files.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); + return 0; + } + pLib = Wln_ReadSystemVerilog( ppFileNames, nFileNames, pTopModule, pDefines, fCollapse, fVerbose ); + } else { printf( "Abc_CommandYosys(): Unknown file extension.\n" ); + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; } Wln_AbcUpdateRtl( pAbc, pLib ); } + if ( fFileNamesAlloc ) + ABC_FREE( ppFileNames ); return 0; usage: - Abc_Print( -2, "usage: %%yosys [-TM ] [-D ] [-L ] [-F ] [-bdisumlcvh] \n" ); + Abc_Print( -2, "usage: %%yosys [-TM ] [-D ] [-L ] [-F ] [-bdisumlcvh] [file_name...]\n" ); Abc_Print( -2, "\t reads Verilog or SystemVerilog using Yosys\n" ); Abc_Print( -2, "\t-T : specify the top module name (default uses \"-auto-top\")\n" ); Abc_Print( -2, "\t-M : specify the top module name (default uses \"-auto-top\") (equivalent to \"-T\")\n" ); Abc_Print( -2, "\t-D : specify defines to be used by Yosys (default \"not used\")\n" ); Abc_Print( -2, "\t-L : specify the Liberty library to read a mapped design (default \"not used\")\n" ); - Abc_Print( -2, "\t-F : specify a second Verilog/SystemVerilog file for the default bit-blasting flow (default \"not used\")\n" ); + Abc_Print( -2, "\t-F : specify an additional Verilog/SystemVerilog file (default \"not used\")\n" ); Abc_Print( -2, "\t-b : toggle bit-blasting the design into an AIG using Yosys (this switch has no effect)\n" ); Abc_Print( -2, "\t-d : toggle bit-blasting the design into an AIG using Yosys [default = %s]\n", !fDontBlast? "yes": "no" ); Abc_Print( -2, "\t-i : toggle inverting the outputs (useful for miters) [default = %s]\n", fInvert? "yes": "no" ); diff --git a/src/base/wln/wlnRtl.c b/src/base/wln/wlnRtl.c index ffe8e457d..f9ed19924 100644 --- a/src/base/wln/wlnRtl.c +++ b/src/base/wln/wlnRtl.c @@ -122,6 +122,30 @@ char * Wln_GetYosysName() #endif return pYosysName; } +static char * Wln_FileNamesJoin( char ** ppFileNames, int nFileNames ) +{ + char * pFileNames; + int i, nChars = 1; + for ( i = 0; i < nFileNames; i++ ) + nChars += strlen( ppFileNames[i] ) + 1; + pFileNames = ABC_ALLOC( char, nChars ); + pFileNames[0] = 0; + for ( i = 0; i < nFileNames; i++ ) + { + if ( i ) + strcat( pFileNames, " " ); + strcat( pFileNames, ppFileNames[i] ); + } + return pFileNames; +} +static int Wln_FileNamesHasSv( char ** ppFileNames, int nFileNames ) +{ + int i; + for ( i = 0; i < nFileNames; i++ ) + if ( strstr( ppFileNames[i], ".sv" ) != NULL ) + return 1; + return 0; +} int Wln_ConvertToRtl( char * pCommand, char * pFileTemp ) { #if defined(__wasm) @@ -142,29 +166,39 @@ int Wln_ConvertToRtl( char * pCommand, char * pFileTemp ) return 1; #endif } -Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fCollapse, int fVerbose ) +Rtl_Lib_t * Wln_ReadSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, int fCollapse, int fVerbose ) { Rtl_Lib_t * pNtk = NULL; - char Command[1000]; + char * pFileNames, * pCommand; char * pFileTemp = "_temp_.rtlil"; - int fSVlog = strstr(pFileName, ".sv") != NULL; - if ( strstr(pFileName, ".rtl") ) - return Rtl_LibReadFile( pFileName, pFileName ); - sprintf( Command, "%s -qp \"read_verilog %s%s %s%s; hierarchy %s%s; %sproc; memory -nomap; memory_map; write_rtlil %s\"", + int fSVlog = Wln_FileNamesHasSv(ppFileNames, nFileNames); + int nCommand; + if ( nFileNames == 1 && strstr(ppFileNames[0], ".rtl") ) + return Rtl_LibReadFile( ppFileNames[0], ppFileNames[0] ); + pFileNames = Wln_FileNamesJoin( ppFileNames, nFileNames ); + nCommand = strlen(Wln_GetYosysName()) + strlen(pFileNames) + (pDefines ? strlen(pDefines) : 0) + (pTopModule ? strlen(pTopModule) : 0) + strlen(pFileTemp) + 200; + pCommand = ABC_ALLOC( char, nCommand ); + sprintf( pCommand, "%s -qp \"read_verilog %s%s %s%s; hierarchy %s%s; %sproc; memory -nomap; memory_map; write_rtlil %s\"", Wln_GetYosysName(), pDefines ? "-D" : "", pDefines ? pDefines : "", fSVlog ? "-sv " : "", - pFileName, + pFileNames, pTopModule ? "-top " : "", pTopModule ? pTopModule : "", fCollapse ? "flatten; ": "", pFileTemp ); if ( fVerbose ) - printf( "%s\n", Command ); - if ( !Wln_ConvertToRtl(Command, pFileTemp) ) + printf( "%s\n", pCommand ); + if ( !Wln_ConvertToRtl(pCommand, pFileTemp) ) + { + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); return NULL; - pNtk = Rtl_LibReadFile( pFileTemp, pFileName ); + } + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); + pNtk = Rtl_LibReadFile( pFileTemp, ppFileNames[0] ); if ( pNtk == NULL ) { printf( "Dumped the design into file \"%s\".\n", pFileTemp ); @@ -174,33 +208,41 @@ Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * p unlink( pFileTemp ); return pNtk; } -Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pFileName2, char * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fSetUndef, int fVerbose ) +Gia_Man_t * Wln_BlastSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fSetUndef, int fVerbose ) { Gia_Man_t * pGia = NULL; - char Command[1000]; + char * pFileNames, * pCommand; char * pFileTemp = "_temp_.aig"; - int fRtlil = strstr(pFileName, ".rtl") != NULL; - int fSVlog = strstr(pFileName, ".sv") != NULL || (pFileName2 && strstr(pFileName2, ".sv") != NULL); - sprintf( Command, "%s -qp \"%s %s%s %s%s%s%s; hierarchy %s%s; flatten; proc; opt; async2sync; opt; setundef -undriven -zero; %s%smemory -nomap; memory_map; dffunmap; opt_clean; opt_expr; %saigmap; write_aiger -symbols %s\"", + int fRtlil = nFileNames == 1 && strstr(ppFileNames[0], ".rtl") != NULL; + int fSVlog = Wln_FileNamesHasSv(ppFileNames, nFileNames); + int nCommand; + pFileNames = Wln_FileNamesJoin( ppFileNames, nFileNames ); + nCommand = strlen(Wln_GetYosysName()) + strlen(pFileNames) + (pDefines ? strlen(pDefines) : 0) + (pTopModule ? strlen(pTopModule) : 0) + strlen(pFileTemp) + 500; + pCommand = ABC_ALLOC( char, nCommand ); + sprintf( pCommand, "%s -qp \"%s %s%s %s%s; hierarchy %s%s; flatten; proc; opt; async2sync; opt; setundef -undriven -zero; %s%smemory -nomap; memory_map; dffunmap; opt_clean; opt_expr; %saigmap; write_aiger -symbols %s\"", Wln_GetYosysName(), fRtlil ? "read_rtlil" : "read_verilog", pDefines ? "-D" : "", pDefines ? pDefines : "", fSVlog ? "-sv " : "", - pFileName, - pFileName2 ? " " : "", - pFileName2 ? pFileName2 : "", + pFileNames, pTopModule ? "-top " : "-auto-top", pTopModule ? pTopModule : "", fTechMap ? (fLibInDir ? "techmap -map techmap.v; " : "techmap; ") : "", fSetUndef ? "setundef -init -zero; " : "", - pFileName2 ? "delete t:\\$scopeinfo; " : "", + nFileNames > 1 ? "delete t:\\$scopeinfo; " : "", pFileTemp ); if ( fVerbose ) - printf( "%s\n", Command ); - if ( !Wln_ConvertToRtl(Command, pFileTemp) ) + printf( "%s\n", pCommand ); + if ( !Wln_ConvertToRtl(pCommand, pFileTemp) ) + { + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); return NULL; - if ( pFileName2 ) + } + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); + if ( nFileNames > 1 ) { extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters ); Aig_Man_t * pAig = NULL; @@ -229,7 +271,7 @@ Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pFileName2, char * } ABC_FREE( pGia->pName ); pGia->pName = pTopModule ? Abc_UtilStrsav(pTopModule) : - Extra_FileNameGeneric( Extra_FileNameWithoutPath(pFileName) ); + Extra_FileNameGeneric( Extra_FileNameWithoutPath(ppFileNames[0]) ); unlink( pFileTemp ); // complement the outputs if ( fInvert ) @@ -240,35 +282,48 @@ Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pFileName2, char * } return pGia; } -Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose ) +Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char ** ppFileNames, int nFileNames, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose ) { Abc_Ntk_t * pNtk = NULL; - char Command[1000]; + char * pFileNames, * pCommand; char * pFileTemp = "_temp_.blif"; - int fSVlog = strstr(pFileName, ".sv") != NULL; - sprintf( Command, "%s -qp \"read_liberty -lib %s; read %s %s%s %s; hierarchy %s%s; flatten; proc; memory -nomap; memory_map; write_blif %s%s -impltf -gates %s\"", + int fSVlog = Wln_FileNamesHasSv(ppFileNames, nFileNames); + int nCommand; + pFileNames = Wln_FileNamesJoin( ppFileNames, nFileNames ); + nCommand = strlen(Wln_GetYosysName()) + strlen(pLibrary) + strlen(pFileNames) + (pDefines ? strlen(pDefines) : 0) + 2 * (pTopModule ? strlen(pTopModule) : 0) + strlen(pFileTemp) + 300; + pCommand = ABC_ALLOC( char, nCommand ); + sprintf( pCommand, "%s -qp \"read_liberty -lib %s; read %s %s%s %s; hierarchy %s%s; flatten; proc; memory -nomap; memory_map; write_blif %s%s -impltf -gates %s\"", Wln_GetYosysName(), pLibrary, fSVlog ? "-sv " : "-vlog95", pDefines ? "-D" : "", pDefines ? pDefines : "", - pFileName, + pFileNames, pTopModule ? "-top " : "-auto-top", pTopModule ? pTopModule : "", pTopModule ? "-top " : "", pTopModule ? pTopModule : "", pFileTemp ); if ( fVerbose ) - printf( "%s\n", Command ); - if ( !Wln_ConvertToRtl(Command, pFileTemp) ) - return NULL; - sprintf( Command, "read_lib %s", pLibrary ); - if ( Cmd_CommandExecute( Abc_FrameReadGlobalFrame(), Command ) ) + printf( "%s\n", pCommand ); + if ( !Wln_ConvertToRtl(pCommand, pFileTemp) ) { - fprintf( stdout, "Cannot execute ABC command \"%s\".\n", Command ); + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); + return NULL; + } + ABC_FREE( pCommand ); + ABC_FREE( pFileNames ); + pCommand = ABC_ALLOC( char, strlen(pLibrary) + 20 ); + sprintf( pCommand, "read_lib %s", pLibrary ); + if ( Cmd_CommandExecute( Abc_FrameReadGlobalFrame(), pCommand ) ) + { + fprintf( stdout, "Cannot execute ABC command \"%s\".\n", pCommand ); + ABC_FREE( pCommand ); unlink( pFileTemp ); return NULL; } + ABC_FREE( pCommand ); pNtk = Io_Read( pFileTemp, IO_FILE_BLIF, 1, 0 ); if ( pNtk == NULL ) {