diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2016-10-25 17:17:37 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2016-10-25 17:17:37 -0700 |
commit | 76c4d22229f24a7547861ccbe3b5e9e4882b4602 (patch) | |
tree | 63fc9de82cadceaff45267492b75ed92edd48b47 /src/base/io/io.c | |
parent | befb73079a08dae3e5bb0a742520bbe1a48cda83 (diff) | |
download | abc-76c4d22229f24a7547861ccbe3b5e9e4882b4602.tar.gz abc-76c4d22229f24a7547861ccbe3b5e9e4882b4602.tar.bz2 abc-76c4d22229f24a7547861ccbe3b5e9e4882b4602.zip |
Parser for JSON format.
Diffstat (limited to 'src/base/io/io.c')
-rw-r--r-- | src/base/io/io.c | 117 |
1 files changed, 115 insertions, 2 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c index 6605fc39..b181bc1d 100644 --- a/src/base/io/io.c +++ b/src/base/io/io.c @@ -48,6 +48,7 @@ static int IoCommandReadTruth ( Abc_Frame_t * pAbc, int argc, char **argv ); 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 IoCommandWrite ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWriteHie ( Abc_Frame_t * pAbc, int argc, char **argv ); @@ -74,6 +75,7 @@ static int IoCommandWriteTruth ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWriteTruths ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWriteStatus ( Abc_Frame_t * pAbc, int argc, char **argv ); static int IoCommandWriteSmv ( Abc_Frame_t * pAbc, int argc, char **argv ); +static int IoCommandWriteJson ( Abc_Frame_t * pAbc, int argc, char **argv ); extern void Abc_FrameCopyLTLDataBase( Abc_Frame_t *pAbc, Abc_Ntk_t * pNtk ); @@ -114,6 +116,7 @@ void Io_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "I/O", "read_verilog", IoCommandReadVerilog, 1 ); 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", "write", IoCommandWrite, 0 ); Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 ); @@ -141,6 +144,7 @@ void Io_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "I/O", "&write_truths", IoCommandWriteTruths, 0 ); Cmd_CommandAdd( pAbc, "I/O", "write_status", IoCommandWriteStatus, 0 ); Cmd_CommandAdd( pAbc, "I/O", "write_smv", IoCommandWriteSmv, 0 ); + Cmd_CommandAdd( pAbc, "I/O", "write_json", IoCommandWriteJson, 0 ); } /**Function************************************************************* @@ -1334,6 +1338,67 @@ usage: return 1; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int IoCommandReadJson( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + extern Vec_Wec_t * Json_Read( char * pFileName, Abc_Nam_t ** ppStrs ); + Vec_Wec_t * vObjs; + Abc_Nam_t * pStrs; + char * pFileName; + FILE * pFile; + 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 ); + + // set the new network + vObjs = Json_Read( pFileName, &pStrs ); + if ( vObjs == NULL ) + return 0; + Abc_FrameSetJsonStrs( pStrs ); + Abc_FrameSetJsonObjs( vObjs ); + return 0; + +usage: + fprintf( pAbc->Err, "usage: read_json [-h] <file>\n" ); + fprintf( pAbc->Err, "\t reads file in JSON 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************************************************************* @@ -2999,10 +3064,8 @@ usage: int IoCommandWriteSmv( Abc_Frame_t * pAbc, int argc, char **argv ) { char * pFileName; - int fUseLuts; int c; - fUseLuts = 0; Extra_UtilGetoptReset(); while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) { @@ -3034,6 +3097,56 @@ usage: fprintf( pAbc->Err, "\tfile : the name of the file to write (extension .smv)\n" ); return 1; } + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int IoCommandWriteJson( Abc_Frame_t * pAbc, int argc, char **argv ) +{ + extern void Json_Write( char * pFileName, Abc_Nam_t * pStr, Vec_Wec_t * vObjs ); + char * pFileName; + int c; + + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) + { + switch ( c ) + { + case 'h': + goto usage; + default: + goto usage; + } + } + if ( Abc_FrameReadJsonStrs(Abc_FrameReadGlobalFrame()) == NULL ) + { + fprintf( pAbc->Out, "No JSON info is available.\n" ); + return 0; + } + if ( argc != globalUtilOptind + 1 ) + goto usage; + // get the output file name + pFileName = argv[globalUtilOptind]; + // call the corresponding file writer + Json_Write( pFileName, Abc_FrameReadJsonStrs(Abc_FrameReadGlobalFrame()), Abc_FrameReadJsonObjs(Abc_FrameReadGlobalFrame()) ); + return 0; + +usage: + fprintf( pAbc->Err, "usage: write_json [-h] <file>\n" ); + fprintf( pAbc->Err, "\t write the network in JSON format\n" ); + fprintf( pAbc->Err, "\t-h : print the help message\n" ); + fprintf( pAbc->Err, "\tfile : the name of the file to write (extension .json)\n" ); + return 1; +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// |