Adding a switch to read mapped Verilog using command %yosys.

This commit is contained in:
Alan Mishchenko 2025-05-09 11:47:26 -07:00
parent 71b60a9830
commit 9dc7ade063
2 changed files with 71 additions and 3 deletions

View File

@ -92,6 +92,7 @@ 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 * pTopModule, char * pDefines, int fSkipStrash, int fInvert, int fTechMap, int fLibInDir, int fVerbose );
extern Rtl_Lib_t * Wln_ReadSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, int fCollapse, int fVerbose );
@ -99,6 +100,7 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
char * pFileName = NULL;
char * pTopModule= NULL;
char * pDefines = NULL;
char * pLibrary = NULL;
int fBlast = 0;
int fInvert = 0;
int fTechMap = 1;
@ -107,7 +109,7 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
int fCollapse = 0;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "TDbismlcvh" ) ) != EOF )
while ( ( c = Extra_UtilGetopt( argc, argv, "TDLbismlcvh" ) ) != EOF )
{
switch ( c )
{
@ -129,6 +131,15 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
pDefines = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'L':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-L\" should be followed by a file name.\n" );
goto usage;
}
pLibrary = argv[globalUtilOptind];
globalUtilOptind++;
break;
case 'b':
fBlast ^= 1;
break;
@ -174,7 +185,21 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
fclose( pFile );
// perform reading
if ( fBlast )
if ( pLibrary )
{
Abc_Ntk_t * pNtk = NULL;
if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) )
pNtk = Wln_ReadMappedSystemVerilog( pFileName, pTopModule, pDefines, pLibrary, fVerbose );
else if ( !strcmp( Extra_FileNameExtension(pFileName), "sv" ) )
pNtk = Wln_ReadMappedSystemVerilog( pFileName, pTopModule, pDefines, pLibrary, fVerbose );
else
{
printf( "Abc_CommandYosys(): Unknown file extension.\n" );
return 0;
}
Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
}
else if ( fBlast )
{
Gia_Man_t * pNew = NULL;
if ( !strcmp( Extra_FileNameExtension(pFileName), "v" ) )
@ -208,10 +233,11 @@ int Abc_CommandYosys( Abc_Frame_t * pAbc, int argc, char ** argv )
}
return 0;
usage:
Abc_Print( -2, "usage: %%yosys [-T <module>] [-D <defines>] [-bismlcvh] <file_name>\n" );
Abc_Print( -2, "usage: %%yosys [-T <module>] [-D <defines>] [-L <liberty_file>] [-bismlcvh] <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-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-b : toggle bit-blasting the design into an AIG using Yosys [default = %s]\n", fBlast? "yes": "no" );
Abc_Print( -2, "\t-i : toggle inverting the outputs (useful for miters) [default = %s]\n", fInvert? "yes": "no" );
Abc_Print( -2, "\t-s : toggle no structural hashing during bit-blasting [default = %s]\n", fSkipStrash? "no strash": "strash" );

View File

@ -211,6 +211,48 @@ Gia_Man_t * Wln_BlastSystemVerilog( char * pFileName, char * pTopModule, char *
}
return pGia;
}
Abc_Ntk_t * Wln_ReadMappedSystemVerilog( char * pFileName, char * pTopModule, char * pDefines, char * pLibrary, int fVerbose )
{
Abc_Ntk_t * pNtk = NULL;
char Command[1000];
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; write_blif %s%s -impltf -gates %s\"",
Wln_GetYosysName(),
pLibrary,
fSVlog ? "-sv " : "-vlog95",
pDefines ? "-D" : "",
pDefines ? pDefines : "",
pFileName,
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 ) )
{
fprintf( stdout, "Cannot execute ABC command \"%s\".\n", Command );
unlink( pFileTemp );
return NULL;
}
pNtk = Io_Read( pFileTemp, IO_FILE_BLIF, 1, 0 );
if ( pNtk == NULL )
{
printf( "Reading mapped BLIF from file \"%s\" has failed.\n", pFileTemp );
return NULL;
}
if ( pTopModule ) {
ABC_FREE( pNtk->pName );
pNtk->pName = Abc_UtilStrsav(pTopModule);
}
unlink( pFileTemp );
return pNtk;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///