summaryrefslogtreecommitdiffstats
path: root/src/base/io
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2018-09-28 17:46:06 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2018-09-28 17:46:06 -0700
commit75ed8581dd9b22312c9ed0fd2d24d963ab4ff4ed (patch)
tree7a9a54415d7b55955b73e5ab6c1f301b05fc5d82 /src/base/io
parent3e33c91c3dc5d95c4152ffa7d280607e974d2fdc (diff)
downloadabc-75ed8581dd9b22312c9ed0fd2d24d963ab4ff4ed.tar.gz
abc-75ed8581dd9b22312c9ed0fd2d24d963ab4ff4ed.tar.bz2
abc-75ed8581dd9b22312c9ed0fd2d24d963ab4ff4ed.zip
Adding switch to 'write_pla' to write random onset minterms of the first PO function.
Diffstat (limited to 'src/base/io')
-rw-r--r--src/base/io/io.c39
-rw-r--r--src/base/io/ioWritePla.c125
2 files changed, 154 insertions, 10 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c
index 5133ef0d..f155c7b6 100644
--- a/src/base/io/io.c
+++ b/src/base/io/io.c
@@ -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;
}
diff --git a/src/base/io/ioWritePla.c b/src/base/io/ioWritePla.c
index df2618c9..d9d3f76c 100644
--- a/src/base/io/ioWritePla.c
+++ b/src/base/io/ioWritePla.c
@@ -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