diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2020-10-01 21:24:32 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2020-10-01 21:24:32 -0700 |
commit | ada073110ef495115fdc43d3a2ef4df16e36dfeb (patch) | |
tree | 2e817a692ae0f8a00a4e4fa46e5f64385d959426 | |
parent | f1eb933992b23a54ec7d6c894152d0e581915450 (diff) | |
download | abc-ada073110ef495115fdc43d3a2ef4df16e36dfeb.tar.gz abc-ada073110ef495115fdc43d3a2ef4df16e36dfeb.tar.bz2 abc-ada073110ef495115fdc43d3a2ef4df16e36dfeb.zip |
New command 'read_sf'.
-rw-r--r-- | src/base/io/io.c | 73 | ||||
-rw-r--r-- | src/base/io/ioUtil.c | 55 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c index a5cffbf4..c2363cb5 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -24,6 +24,10 @@ #include "proof/abs/abs.h" #include "sat/bmc/bmc.h" +#ifdef WIN32 +#define unlink _unlink +#endif + ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// @@ -49,6 +53,7 @@ static int IoCommandReadVerilog ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandReadStatus ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandReadGig ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandReadJson ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int IoCommandReadSF ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWrite ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWriteHie ( Abc_Frame_t * pAbc, int argc, char **argv ); @@ -118,6 +123,7 @@ void Io_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "I/O", "read_status", IoCommandReadStatus, 0 ); Cmd_CommandAdd( pAbc, "I/O", "&read_gig", IoCommandReadGig, 0 ); Cmd_CommandAdd( pAbc, "I/O", "read_json", IoCommandReadJson, 0 ); + Cmd_CommandAdd( pAbc, "I/O", "read_sf", IoCommandReadSF, 0 ); Cmd_CommandAdd( pAbc, "I/O", "write", IoCommandWrite, 0 ); Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 ); @@ -1415,6 +1421,73 @@ usage: return 1; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int IoCommandReadSF( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + extern void Io_TransformSF2PLA( char * pNameIn, char * pNameOut ); + + Abc_Ntk_t * pNtk; + FILE * pFile; + char * pFileName, * pFileTemp = "_temp_sf_.pla"; + int c; + + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) + { + switch ( c ) + { + case 'h': + goto usage; + default: + goto usage; + } + } + if ( argc != globalUtilOptind + 1 ) + { + goto usage; + } + + // get the input file name + pFileName = argv[globalUtilOptind]; + if ( (pFile = fopen( pFileName, "r" )) == NULL ) + { + fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName ); + return 1; + } + fclose( pFile ); + Io_TransformSF2PLA( pFileName, pFileTemp ); + pNtk = Io_Read( pFileTemp, IO_FILE_PLA, 1, 0 ); + unlink( pFileTemp ); + if ( pNtk == NULL ) + return 1; + ABC_FREE( pNtk->pName ); + pNtk->pName = Extra_FileNameGeneric( pFileName ); + ABC_FREE( pNtk->pSpec ); + pNtk->pSpec = Abc_UtilStrsav( pFileName ); + // replace the current network + Abc_FrameReplaceCurrentNetwork( pAbc, pNtk ); + Abc_FrameClearVerifStatus( pAbc ); + + return 0; + +usage: + fprintf( pAbc->Err, "usage: read_sf [-h] <file>\n" ); + fprintf( pAbc->Err, "\t reads file in SF format\n" ); + fprintf( pAbc->Err, "\t-h : prints the command summary\n" ); + fprintf( pAbc->Err, "\tfile : the name of a file to read\n" ); + return 1; +} + /**Function************************************************************* diff --git a/src/base/io/ioUtil.c b/src/base/io/ioUtil.c index c6b47b11..01fe4f45 100644 --- a/src/base/io/ioUtil.c +++ b/src/base/io/ioUtil.c @@ -862,6 +862,61 @@ FILE * Io_FileOpen( const char * FileName, const char * PathVar, const char * Mo } } +/**Function************************************************************* + + Synopsis [Tranform SF into PLA.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Io_TransformSF2PLA( char * pNameIn, char * pNameOut ) +{ + int fStart = 0, Size = 1000000; + char * pBuffer, * pToken; + FILE * pFileIn = fopen( pNameIn, "rb" ); + FILE * pFileOut = fopen( pNameOut, "wb" ); + if ( pFileIn == NULL ) + { + if ( pFileOut ) fclose( pFileOut ); + printf( "Cannot open file \"%s\" for reading.\n", pNameIn ); + return; + } + if ( pFileOut == NULL ) + { + if ( pFileIn ) fclose( pFileIn ); + printf( "Cannot open file \"%s\" for reading.\n", pNameOut ); + return; + } + pBuffer = ABC_ALLOC( char, Size ); + fprintf( pFileOut, ".type fd\n" ); + while ( fgets(pBuffer, Size, pFileIn) ) + { + if ( strstr(pBuffer, "END_SDF") ) + break; + if ( strstr(pBuffer, "SDF") ) + { + fgets(pBuffer, Size, pFileIn); + if ( (pToken = strtok( pBuffer, " \t\r\n" )) ) + fprintf( pFileOut, ".i %d\n", atoi(pToken) ); + if ( (pToken = strtok( NULL, " \t\r\n" )) ) + fprintf( pFileOut, ".o %d\n", atoi(pToken) ); + if ( (pToken = strtok( NULL, " \t\r\n" )) ) + fprintf( pFileOut, ".p %d\n", atoi(pToken) ); + fStart = 1; + } + else if ( fStart ) + fprintf( pFileOut, "%s", pBuffer ); + } + fprintf( pFileOut, ".e\n" ); + fclose( pFileIn ); + fclose( pFileOut ); + ABC_FREE( pBuffer ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// |