📄 io.c
字号:
/**CFile**************************************************************** FileName [io.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Commands defined in the IO package.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: io.c,v 1.20 2003/05/27 23:14:13 alanmi Exp $]***********************************************************************/#include "ioInt.h"#include "mvInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////static int IoCommandReadBlif ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandReadBlifMv ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandReadBlifMvs ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandReadPla ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandReadPlaMv ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandWriteBlif ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandWriteBlifMv ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandWriteBlifMvs( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandWritePla ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandWritePlaMv ( Mv_Frame_t * pMvsis, int argc, char **argv );static int IoCommandSplit ( Mv_Frame_t * pMvsis, int argc, char **argv );/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function******************************************************************** Synopsis [Initializes the I/O package.] SideEffects [] SeeAlso [Io_End]******************************************************************************/void Io_Init( Mv_Frame_t * pMvsis ){ Cmd_CommandAdd( pMvsis, "Reading", "read_blif", IoCommandReadBlif, 1 ); Cmd_CommandAdd( pMvsis, "Reading", "read_blif_mv", IoCommandReadBlifMv, 1 ); Cmd_CommandAdd( pMvsis, "Reading", "read_blif_mvs", IoCommandReadBlifMvs, 1 ); Cmd_CommandAdd( pMvsis, "Reading", "read_pla", IoCommandReadPla, 1 );// Cmd_CommandAdd( pMvsis, "Reading", "read_pla_mv", IoCommandReadPlaMv, 1 ); Cmd_CommandAdd( pMvsis, "Writing", "write_blif", IoCommandWriteBlif, 0 ); Cmd_CommandAdd( pMvsis, "Writing", "write_blif_mv", IoCommandWriteBlifMv, 0 ); Cmd_CommandAdd( pMvsis, "Writing", "write_blif_mvs",IoCommandWriteBlifMvs, 0 ); Cmd_CommandAdd( pMvsis, "Writing", "write_pla", IoCommandWritePla, 0 );// Cmd_CommandAdd( pMvsis, "Writing", "write_pla_mv", IoCommandWritePlaMv, 0 ); Cmd_CommandAdd( pMvsis, "Various", "_split", IoCommandSplit, 0 );}/**Function******************************************************************** Synopsis [Ends the I/O package.] SideEffects [] SeeAlso [Io_Init]******************************************************************************/void Io_End( Mv_Frame_t * pMvsis ){}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandReadBlif( Mv_Frame_t * pMvsis, int argc, char ** argv ){ Ntk_Network_t * pNet; char * FileName; FILE * pFile; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( argc != util_optind + 1 ) { goto usage; } // get the input file name FileName = argv[util_optind]; if ( (pFile = fopen( FileName, "r" )) == NULL ) { fprintf( pMvsis->Err, "Cannot open input file \"%s\". ", FileName ); if ( FileName = Io_ReadFileGetSimilar( FileName ) ) fprintf( pMvsis->Err, "Did you mean \"%s\"?", FileName ); fprintf( pMvsis->Err, "\n" ); return 1; } fclose( pFile ); // set the new network pNet = Io_ReadNetwork( pMvsis, FileName ); // replace the current network Mv_FrameReplaceCurrentNetwork( pMvsis, pNet ); return 0;usage: fprintf( pMvsis->Err, "usage: read_blif [-h] [file]\n" ); fprintf( pMvsis->Err, " -h reads the network from file\n" ); fprintf( pMvsis->Err, " file the name of a file in BLIF/BLIF-MVS/BLIF-MV/PLA/PLA-MV format\n" ); return 1;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandReadBlifMv( Mv_Frame_t * pMvsis, int argc, char **argv ){ return IoCommandReadBlif( pMvsis, argc, argv );}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandReadBlifMvs( Mv_Frame_t * pMvsis, int argc, char **argv ){ return IoCommandReadBlif( pMvsis, argc, argv );}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandReadPla( Mv_Frame_t * pMvsis, int argc, char ** argv ){ return IoCommandReadBlif( pMvsis, argc, argv );}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandReadPlaMv( Mv_Frame_t * pMvsis, int argc, char ** argv ){ return IoCommandReadBlif( pMvsis, argc, argv );}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandWriteBlif( Mv_Frame_t * pMvsis, int argc, char **argv ){ char * FileName; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( pMvsis->pNetCur == NULL ) { fprintf( pMvsis->Out, "Empty network.\n" ); return 0; } if ( argc != util_optind + 1 ) { goto usage; } // get the input file name FileName = argv[util_optind]; // check if the network is binary if ( !Ntk_NetworkIsBinary(pMvsis->pNetCur) ) { fprintf( pMvsis->Out, "The current network is not binary. Use \"write_blif_mv\" or \"write_blif_mvs\".\n" ); return 0; } // write the file Io_WriteNetwork( pMvsis->pNetCur, FileName, IO_FILE_BLIF ); return 0;usage: fprintf( pMvsis->Err, "usage: write_blif [-h] [file]\n" ); fprintf( pMvsis->Err, " -h write the network into a BLIF file\n" ); fprintf( pMvsis->Err, " file the name of the file to write\n" ); return 1;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandWriteBlifMv( Mv_Frame_t * pMvsis, int argc, char **argv ){ char * FileName; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( pMvsis->pNetCur == NULL ) { fprintf( pMvsis->Out, "Empty network.\n" ); return 0; } if ( argc != util_optind + 1 ) { goto usage; } // get the input file name FileName = argv[util_optind]; // write the file Io_WriteNetwork( pMvsis->pNetCur, FileName, IO_FILE_BLIF_MV ); return 0;usage: fprintf( pMvsis->Err, "usage: write_blif_mv [-h] [file]\n" ); fprintf( pMvsis->Err, " -h write the network into a BLIF-MV file\n" ); fprintf( pMvsis->Err, " file the name of the file to write\n" ); return 1;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandWriteBlifMvs( Mv_Frame_t * pMvsis, int argc, char **argv ){ char * FileName; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( pMvsis->pNetCur == NULL ) { fprintf( pMvsis->Out, "Empty network.\n" ); return 0; } if ( argc != util_optind + 1 ) { goto usage; } // get the input file name FileName = argv[util_optind]; // write the file Io_WriteNetwork( pMvsis->pNetCur, FileName, IO_FILE_BLIF_MVS ); return 0;usage: fprintf( pMvsis->Err, "usage: write_blif_mvs [-h] [file]\n" ); fprintf( pMvsis->Err, " -h write the network into a BLIF-MVS file\n" ); fprintf( pMvsis->Err, " file the name of the file to write\n" ); return 1;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandWritePla( Mv_Frame_t * pMvsis, int argc, char **argv ){ char * FileName; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( pMvsis->pNetCur == NULL ) { fprintf( pMvsis->Out, "Empty network.\n" ); return 0; } if ( argc != util_optind + 1 ) { goto usage; } // get the input file name FileName = argv[util_optind]; // check if the network is binary if ( !Ntk_NetworkIsBinary(pMvsis->pNetCur) ) { fprintf( pMvsis->Out, "Cannot write binary PLA for the MV network.\n" ); return 0; } if ( Ntk_NetworkGetNumLevels(pMvsis->pNetCur) > 1 ) { fprintf( pMvsis->Out, "Cannot write PLA for a multi-level network.\n" ); return 0; } // write the file Io_WritePla( pMvsis->pNetCur, FileName ); return 0;usage: fprintf( pMvsis->Err, "usage: write_pla [-h] [file]\n" ); fprintf( pMvsis->Err, " -h write the binary two-level network into a PLA file\n" ); fprintf( pMvsis->Err, " file the name of the file to write\n" ); return 1;}/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandWritePlaMv( Mv_Frame_t * pMvsis, int argc, char **argv ){ char * NodeName; char * FileName; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( pMvsis->pNetCur == NULL ) { fprintf( pMvsis->Out, "Empty network.\n" ); return 0; } if ( argc != util_optind + 2 ) { goto usage; } // get the input file name NodeName = argv[util_optind]; FileName = argv[util_optind+1]; // write the file Io_WritePlaMv( pMvsis->pNetCur, NodeName, FileName ); return 0;usage: fprintf( pMvsis->Err, "usage: write_pla_mv [-h] [node] [file]\n" ); fprintf( pMvsis->Err, " -h write the MV PLA file for one node\n" ); fprintf( pMvsis->Err, " node the name of the node to write into a file\n" ); fprintf( pMvsis->Err, " file the name of the file to write\n" ); return 1;}/**Function************************************************************* Synopsis [Splits the multi-output function into many single output ones.] Description [] SideEffects [] SeeAlso []***********************************************************************/int IoCommandSplit( Mv_Frame_t * pMvsis, int argc, char **argv ){ Ntk_Network_t * pNet; FILE * pOut, * pErr; int Output = -1; int fWriteBlif = 1; int fAllInputs = 0; int fVerbose = 0; int OutSuppMin = 0; int NodeFanMax = 1000; int c; pNet = Mv_FrameReadNet(pMvsis); pOut = Mv_FrameReadOut(pMvsis); pErr = Mv_FrameReadErr(pMvsis); util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "o:s:f:ibv" ) ) != EOF ) { switch ( c ) { case 'o': Output = atoi(util_optarg); break; case 's': OutSuppMin = atoi(util_optarg); break; case 'f': NodeFanMax = atoi(util_optarg); break; case 'i': fAllInputs ^= 1; break; case 'b': fWriteBlif ^= 1; break; case 'v': fVerbose ^= 1; break; default: goto usage; } } if ( pNet == NULL ) { fprintf( pOut, "Empty network.\n" ); return 0; } IoNetworkSplit( pNet, Output, OutSuppMin, NodeFanMax, fAllInputs, fWriteBlif, fVerbose ); return 0;usage: fprintf( pErr, "\n" ); fprintf( pErr, "Usage: _split [-o num] [-s num] [-f num] [-v]\n"); fprintf( pErr, " writes primary output cone(s) into separate BLIF-MV file(s)\n" ); fprintf( pErr, " -o num : the zero-based output number to write [default = all]\n" ); fprintf( pErr, " -s num : the lower limit on the output support size [default = %d]\n", OutSuppMin ); fprintf( pErr, " -f num : the upper limit on the nodes' fanin count [default = %d]\n", NodeFanMax ); fprintf( pErr, " -i : toggles between all/support inputs [default = %s]\n", (fAllInputs? "all": "support") ); fprintf( pErr, " -b : toggles between BLIF and BLIF-MV [default = %s]\n", (fWriteBlif? "BLIF": "BLIF-MV") ); fprintf( pErr, " -v : toggles verbose [default = disabled]\n" ); return 1; // error exit }/////////////////////////////////////////////////////////////////////////// END OF FILE ///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -