Adding direct file interface for mapped networks.

This commit is contained in:
Alan Mishchenko 2025-03-10 14:38:51 -07:00
parent ecc27e80dc
commit bd9fb45808
2 changed files with 158 additions and 1 deletions

View File

@ -908,6 +908,7 @@ Abc_Ntk_t * Abc_NtkFromMiniMapping( int *pArray )
}
Abc_Ntk_t *pNtkMapped = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_MAP, 1 );
pNtkMapped->pName = Extra_UtilStrsav( "mapped" );
pNtkMapped->pManFunc = pLib;
int nCis, nCos, nNodes, nFlops;
int i, k, nLeaves, Pos = 4;
char * pBuffer, * pName;
@ -945,12 +946,68 @@ Abc_Ntk_t * Abc_NtkFromMiniMapping( int *pArray )
}
Abc_NtkAddDummyPiNames( pNtkMapped );
Abc_NtkAddDummyPoNames( pNtkMapped );
if ( !Abc_NtkCheck( pNtkMapped ) )
// decouple the PO driver nodes to reduce the number of levels
int fFixDrivers = 1, fUseBuffs = 1, fVerbose = 1;
if ( fFixDrivers )
{
int nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkMapped, !fUseBuffs );
if ( fVerbose && nDupGates && !Abc_FrameReadFlag("silentmode") )
{
if ( fUseBuffs )
printf( "Added %d buffers/inverters to decouple the CO drivers.\n", nDupGates );
else
printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
}
}
if ( !Abc_NtkCheck( pNtkMapped ) ) {
//extern void Abc_NtkPrintMiniMapping( int * pArray );
//Abc_NtkPrintMiniMapping( pArray );
fprintf( stdout, "Abc_NtkFromMiniMapping(): Network check has failed.\n" );
}
return pNtkMapped;
}
/**Function*************************************************************
Synopsis [File IO.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Ntk_t * Abc_NtkReadFromFile( char * pFileName )
{
int nSize = Extra_FileSize( pFileName );
if ( nSize == 0 )
return NULL;
FILE * pFile = fopen( pFileName, "rb" );
int * pArray = ABC_ALLOC( int, nSize );
int nSize2 = fread( pArray, sizeof(char), nSize, pFile );
assert( nSize2 == nSize );
fclose( pFile );
Abc_Ntk_t * pNtk = Abc_NtkFromMiniMapping( pArray );
ABC_FREE( pArray );
return pNtk;
}
int Abc_NtkWriteToFile( char * pFileName, Abc_Ntk_t * pNtk )
{
Vec_Int_t * vRes = Abc_NtkWriteMiniMapping( pNtk );
FILE * pFile = fopen( pFileName, "wb" );
if ( pFile == NULL ) { printf( "Cannot open input file \"%s\" for writing.\n", pFileName ); return 0; }
int nSize = fwrite( Vec_IntArray(vRes), sizeof(int), Vec_IntSize(vRes), pFile );
assert( nSize == Vec_IntSize(vRes) );
Vec_IntFree( vRes );
fclose( pFile );
return 1;
}
/**Function*************************************************************
Synopsis [Prints mapped network represented in mini-mapped format.]

View File

@ -60,6 +60,7 @@ 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 IoCommandReadRom ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadMM ( 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 );
@ -90,6 +91,7 @@ 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 );
static int IoCommandWriteResub ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteMM ( Abc_Frame_t * pAbc, int argc, char **argv );
extern void Abc_FrameCopyLTLDataBase( Abc_Frame_t *pAbc, Abc_Ntk_t * pNtk );
@ -136,6 +138,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "read_json", IoCommandReadJson, 0 );
Cmd_CommandAdd( pAbc, "I/O", "read_sf", IoCommandReadSF, 0 );
Cmd_CommandAdd( pAbc, "I/O", "read_rom", IoCommandReadRom, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_mm", IoCommandReadMM, 1 );
Cmd_CommandAdd( pAbc, "I/O", "write", IoCommandWrite, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 );
@ -168,6 +171,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "write_smv", IoCommandWriteSmv, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_json", IoCommandWriteJson, 0 );
Cmd_CommandAdd( pAbc, "I/O", "&write_resub", IoCommandWriteResub, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_mm", IoCommandWriteMM, 0 );
}
/**Function*************************************************************
@ -1999,6 +2003,51 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int IoCommandReadMM( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Abc_Ntk_t * Abc_NtkReadFromFile( char * pFileName );
Abc_Ntk_t * pNtk; char * pFileName; 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;
pFileName = argv[globalUtilOptind];
pNtk = Abc_NtkReadFromFile( pFileName );
if ( pNtk == NULL )
return 0;
Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
Abc_FrameClearVerifStatus( pAbc );
return 0;
usage:
fprintf( pAbc->Err, "usage: read_mm [-h] <file>\n" );
fprintf( pAbc->Err, "\t reads mapped network from file\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*************************************************************
Synopsis []
@ -4217,6 +4266,57 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int IoCommandWriteMM( Abc_Frame_t * pAbc, int argc, char **argv )
{
extern int Abc_NtkWriteToFile( char * pFileName, Abc_Ntk_t * pNtk );
Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc);
char * pFileName = NULL; 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;
pFileName = argv[globalUtilOptind];
if ( pNtk == NULL )
{
Abc_Print( -1, "IoCommandWriteMM(): There is no current network.\n" );
return 1;
}
if ( !Abc_NtkIsMappedLogic(pNtk) )
{
Abc_Print( -1, "IoCommandWriteMM(): The current network is not mapped.\n" );
return 1;
}
Abc_NtkWriteToFile( pFileName, pNtk );
return 0;
usage:
fprintf( pAbc->Err, "usage: write_mm [-h] <file>\n" );
fprintf( pAbc->Err, "\t write mapped network into a file\n" );
fprintf( pAbc->Err, "\t-h : print the help message\n" );
fprintf( pAbc->Err, "\tfile : the name of the file to write\n" );
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////