mirror of https://github.com/YosysHQ/abc.git
Adding switch to 'write_pla' to write random onset minterms of the first PO function.
This commit is contained in:
parent
3e33c91c3d
commit
75ed8581dd
|
|
@ -2678,14 +2678,24 @@ usage:
|
|||
***********************************************************************/
|
||||
int IoCommandWritePla( Abc_Frame_t * pAbc, int argc, char **argv )
|
||||
{
|
||||
extern int Io_WriteMoPlaM( Abc_Ntk_t * pNtk, char * pFileName, int nMints );
|
||||
char * pFileName;
|
||||
int c, fUseMoPla = 0;
|
||||
int c, fUseMoPla = 0, nMints = 0;
|
||||
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "mh" ) ) != EOF )
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "Mmh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
case 'M':
|
||||
if ( globalUtilOptind >= argc )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-M\" should be followed by an integer.\n" );
|
||||
goto usage;
|
||||
}
|
||||
nMints = atoi(argv[globalUtilOptind]);
|
||||
globalUtilOptind++;
|
||||
break;
|
||||
case 'm':
|
||||
fUseMoPla ^= 1;
|
||||
break;
|
||||
|
|
@ -2705,15 +2715,28 @@ int IoCommandWritePla( Abc_Frame_t * pAbc, int argc, char **argv )
|
|||
// get the output file name
|
||||
pFileName = argv[globalUtilOptind];
|
||||
// call the corresponding file writer
|
||||
Io_Write( pAbc->pNtkCur, pFileName, fUseMoPla ? IO_FILE_MOPLA : IO_FILE_PLA );
|
||||
if ( nMints )
|
||||
{
|
||||
if ( Abc_NtkIsBddLogic(pAbc->pNtkCur) )
|
||||
Io_WriteMoPlaM( pAbc->pNtkCur, pFileName, nMints );
|
||||
else
|
||||
{
|
||||
Abc_Ntk_t * pStrash = Abc_NtkStrash( pAbc->pNtkCur, 0, 0, 0 );
|
||||
Io_WriteMoPlaM( pStrash, pFileName, nMints );
|
||||
Abc_NtkDelete( pStrash );
|
||||
}
|
||||
}
|
||||
else
|
||||
Io_Write( pAbc->pNtkCur, pFileName, fUseMoPla ? IO_FILE_MOPLA : IO_FILE_PLA );
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
fprintf( pAbc->Err, "usage: write_pla [-mh] <file>\n" );
|
||||
fprintf( pAbc->Err, "\t writes the collapsed network into a PLA file\n" );
|
||||
fprintf( pAbc->Err, "\t-m : toggle writing multi-output PLA [default = %s]\n", fUseMoPla? "yes":"no" );
|
||||
fprintf( pAbc->Err, "\t-h : print the help massage\n" );
|
||||
fprintf( pAbc->Err, "\tfile : the name of the file to write\n" );
|
||||
fprintf( pAbc->Err, "usage: write_pla [-M <num>] [-mh] <file>\n" );
|
||||
fprintf( pAbc->Err, "\t writes the collapsed network into a PLA file\n" );
|
||||
fprintf( pAbc->Err, "\t-M <num> : the number of on-set minterms to write [default = %d]\n", nMints );
|
||||
fprintf( pAbc->Err, "\t-m : toggle writing multi-output PLA [default = %s]\n", fUseMoPla? "yes":"no" );
|
||||
fprintf( pAbc->Err, "\t-h : print the help massage\n" );
|
||||
fprintf( pAbc->Err, "\tfile : the name of the file to write\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -383,7 +383,7 @@ int Io_WriteMoPlaOneIntMinterms( FILE * pFile, Abc_Ntk_t * pNtk, DdManager * dd,
|
|||
***********************************************************************/
|
||||
int Io_WriteMoPlaOne( FILE * pFile, Abc_Ntk_t * pNtk )
|
||||
{
|
||||
int fVerbose = 1;
|
||||
int fVerbose = 0;
|
||||
DdManager * dd;
|
||||
DdNode * bFunc;
|
||||
Vec_Ptr_t * vFuncsGlob;
|
||||
|
|
@ -445,9 +445,130 @@ int Io_WriteMoPla( Abc_Ntk_t * pNtk, char * pFileName )
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Writes the network in PLA format.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Io_WriteMoPlaOneIntMintermsM( FILE * pFile, Abc_Ntk_t * pNtk, DdManager * dd, DdNode * bFunc, int nMints )
|
||||
{
|
||||
Abc_Obj_t * pNode;
|
||||
int * pArray = ABC_CALLOC( int, dd->size );
|
||||
DdNode ** pbMints = Cudd_bddPickArbitraryMinterms( dd, bFunc, dd->vars, dd->size, nMints );
|
||||
int i, k, nInputs = Abc_NtkCiNum(pNtk);
|
||||
assert( dd->size == Abc_NtkCiNum(pNtk) );
|
||||
|
||||
// write the header
|
||||
fprintf( pFile, ".i %d\n", nInputs );
|
||||
fprintf( pFile, ".o %d\n", 1 );
|
||||
fprintf( pFile, ".ilb" );
|
||||
Abc_NtkForEachCi( pNtk, pNode, i )
|
||||
fprintf( pFile, " %s", Abc_ObjName(pNode) );
|
||||
fprintf( pFile, "\n" );
|
||||
fprintf( pFile, ".ob" );
|
||||
fprintf( pFile, " %s", Abc_ObjName(Abc_NtkCo(pNtk, 0)) );
|
||||
fprintf( pFile, "\n" );
|
||||
fprintf( pFile, ".p %d\n", nMints );
|
||||
|
||||
// iterate through minterms
|
||||
for ( k = 0; k < nMints; k++ )
|
||||
{
|
||||
Cudd_BddToCubeArray( dd, pbMints[k], pArray );
|
||||
for ( i = 0; i < Abc_NtkCiNum(pNtk); i++ )
|
||||
if ( pArray[i] == 0 )
|
||||
fprintf( pFile, "%c", '0' );
|
||||
else if ( pArray[i] == 1 )
|
||||
fprintf( pFile, "%c", '1' );
|
||||
else if ( pArray[i] == 2 )
|
||||
fprintf( pFile, "%c", '-' );
|
||||
fprintf( pFile, " " );
|
||||
fprintf( pFile, "%c", '1' );
|
||||
fprintf( pFile, "\n" );
|
||||
}
|
||||
fprintf( pFile, ".e\n" );
|
||||
|
||||
//for ( k = 0; k < nMints; k++ )
|
||||
// Cudd_RecursiveDeref( dd, pbMints[k] );
|
||||
ABC_FREE( pbMints );
|
||||
ABC_FREE( pArray );
|
||||
return 1;
|
||||
}
|
||||
int Io_WriteMoPlaOneM( FILE * pFile, Abc_Ntk_t * pNtk, int nMints )
|
||||
{
|
||||
int fVerbose = 0;
|
||||
DdManager * dd;
|
||||
DdNode * bFunc;
|
||||
Vec_Ptr_t * vFuncsGlob;
|
||||
Abc_Obj_t * pObj;
|
||||
int i;
|
||||
if ( Abc_NtkIsStrash(pNtk) )
|
||||
{
|
||||
assert( Abc_NtkIsStrash(pNtk) );
|
||||
dd = (DdManager *)Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, 1, 0, fVerbose );
|
||||
if ( dd == NULL )
|
||||
return 0;
|
||||
if ( fVerbose )
|
||||
printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
|
||||
|
||||
// complement the global functions
|
||||
vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
|
||||
Abc_NtkForEachCo( pNtk, pObj, i )
|
||||
Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
|
||||
|
||||
// consider minterms
|
||||
Io_WriteMoPlaOneIntMintermsM( pFile, pNtk, dd, (DdNode *)Vec_PtrEntry(vFuncsGlob, 0), nMints );
|
||||
Abc_NtkFreeGlobalBdds( pNtk, 0 );
|
||||
|
||||
// cleanup
|
||||
Vec_PtrForEachEntry( DdNode *, vFuncsGlob, bFunc, i )
|
||||
Cudd_RecursiveDeref( dd, bFunc );
|
||||
Vec_PtrFree( vFuncsGlob );
|
||||
//Extra_StopManager( dd );
|
||||
Cudd_Quit( dd );
|
||||
}
|
||||
else if ( Abc_NtkIsBddLogic(pNtk) )
|
||||
{
|
||||
DdNode * bFunc = (DdNode *)Abc_ObjFanin0(Abc_NtkCo(pNtk, 0))->pData;
|
||||
dd = (DdManager *)pNtk->pManFunc;
|
||||
if ( dd->size == Abc_NtkCiNum(pNtk) )
|
||||
Io_WriteMoPlaOneIntMintermsM( pFile, pNtk, dd, bFunc, nMints );
|
||||
else
|
||||
{
|
||||
printf( "Cannot write minterms because the size of the manager for local BDDs is not equal to\n" );
|
||||
printf( "the number of primary inputs. (It is likely that the current network is not collapsed.)\n" );
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int Io_WriteMoPlaM( Abc_Ntk_t * pNtk, char * pFileName, int nMints )
|
||||
{
|
||||
FILE * pFile;
|
||||
assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsBddLogic(pNtk) );
|
||||
pFile = fopen( pFileName, "w" );
|
||||
if ( pFile == NULL )
|
||||
{
|
||||
fprintf( stdout, "Io_WriteMoPlaM(): Cannot open the output file.\n" );
|
||||
return 0;
|
||||
}
|
||||
fprintf( pFile, "# Benchmark \"%s\" written by ABC on %s\n", pNtk->pName, Extra_TimeStamp() );
|
||||
Io_WriteMoPlaOneM( pFile, pNtk, nMints );
|
||||
fclose( pFile );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
int Io_WriteMoPla( Abc_Ntk_t * pNtk, char * pFileName ) { return 1; }
|
||||
int Io_WriteMoPla( Abc_Ntk_t * pNtk, char * pFileName ) { return 1; }
|
||||
int Io_WriteMoPlaM( Abc_Ntk_t * pNtk, char * pFileName, int nMints ) { return 1; }
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue