summaryrefslogtreecommitdiffstats
path: root/src/base/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/io')
-rw-r--r--src/base/io/io.c106
-rw-r--r--src/base/io/ioAbc.h5
-rw-r--r--src/base/io/ioReadAiger.c14
-rw-r--r--src/base/io/ioReadBblif.c342
-rw-r--r--src/base/io/ioUtil.c22
-rw-r--r--src/base/io/ioWriteAiger.c6
-rw-r--r--src/base/io/ioWriteBblif.c111
-rw-r--r--src/base/io/module.make2
8 files changed, 595 insertions, 13 deletions
diff --git a/src/base/io/io.c b/src/base/io/io.c
index ee5df414..e8af161e 100644
--- a/src/base/io/io.c
+++ b/src/base/io/io.c
@@ -28,6 +28,7 @@
static int IoCommandRead ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadAiger ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadBaf ( Abc_Frame_t * pAbc, int argc, char **argv );
+static int IoCommandReadBblif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadBlif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadBench ( Abc_Frame_t * pAbc, int argc, char **argv );
@@ -45,6 +46,7 @@ static int IoCommandWrite ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteHie ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteAiger ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBaf ( Abc_Frame_t * pAbc, int argc, char **argv );
+static int IoCommandWriteBblif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBlif ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBlifMv ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandWriteBench ( Abc_Frame_t * pAbc, int argc, char **argv );
@@ -83,6 +85,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "read", IoCommandRead, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_aiger", IoCommandReadAiger, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_baf", IoCommandReadBaf, 1 );
+ Cmd_CommandAdd( pAbc, "I/O", "read_bblif", IoCommandReadBblif, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_blif", IoCommandReadBlif, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_blif_mv", IoCommandReadBlifMv, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_bench", IoCommandReadBench, 1 );
@@ -100,6 +103,7 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_aiger", IoCommandWriteAiger, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_baf", IoCommandWriteBaf, 0 );
+ Cmd_CommandAdd( pAbc, "I/O", "write_bblif", IoCommandWriteBblif, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_blif", IoCommandWriteBlif, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_blif_mv", IoCommandWriteBlifMv, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_bench", IoCommandWriteBench, 0 );
@@ -316,6 +320,60 @@ usage:
SeeAlso []
***********************************************************************/
+int IoCommandReadBblif( Abc_Frame_t * pAbc, int argc, char ** argv )
+{
+ Abc_Ntk_t * pNtk;
+ char * pFileName;
+ int fCheck;
+ int c;
+
+ fCheck = 1;
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "ch" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'c':
+ fCheck ^= 1;
+ break;
+ case 'h':
+ goto usage;
+ default:
+ goto usage;
+ }
+ }
+ if ( argc != globalUtilOptind + 1 )
+ goto usage;
+ // get the input file name
+ pFileName = argv[globalUtilOptind];
+ // read the file using the corresponding file reader
+ pNtk = Io_Read( pFileName, IO_FILE_BBLIF, fCheck );
+ if ( pNtk == NULL )
+ return 1;
+ // replace the current network
+ Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
+ return 0;
+
+usage:
+ fprintf( pAbc->Err, "usage: read_bblif [-ch] <file>\n" );
+ fprintf( pAbc->Err, "\t read the network in a binary BLIF format\n" );
+ fprintf( pAbc->Err, "\t-c : toggle network check after reading [default = %s]\n", fCheck? "yes":"no" );
+ 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 []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int IoCommandReadBlif( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk;
@@ -1329,6 +1387,54 @@ usage:
SeeAlso []
***********************************************************************/
+int IoCommandWriteBblif( Abc_Frame_t * pAbc, int argc, char **argv )
+{
+ char * pFileName;
+ int c;
+
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'h':
+ goto usage;
+ default:
+ goto usage;
+ }
+ }
+ if ( pAbc->pNtkCur == NULL )
+ {
+ fprintf( pAbc->Out, "Empty network.\n" );
+ return 0;
+ }
+ if ( argc != globalUtilOptind + 1 )
+ goto usage;
+ // get the output file name
+ pFileName = argv[globalUtilOptind];
+ // call the corresponding file writer
+ Io_Write( pAbc->pNtkCur, pFileName, IO_FILE_BBLIF );
+ return 0;
+
+usage:
+ fprintf( pAbc->Err, "usage: write_bblif [-h] <file>\n" );
+ fprintf( pAbc->Err, "\t write the network into a binary BLIF file\n" );
+ fprintf( pAbc->Err, "\t-h : print the help massage\n" );
+ fprintf( pAbc->Err, "\tfile : the name of the file to write (extension .bblif)\n" );
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int IoCommandWriteBlif( Abc_Frame_t * pAbc, int argc, char **argv )
{
char * pFileName;
diff --git a/src/base/io/ioAbc.h b/src/base/io/ioAbc.h
index c11168df..bade17df 100644
--- a/src/base/io/ioAbc.h
+++ b/src/base/io/ioAbc.h
@@ -44,6 +44,7 @@ typedef enum {
IO_FILE_NONE = 0,
IO_FILE_AIGER,
IO_FILE_BAF,
+ IO_FILE_BBLIF,
IO_FILE_BLIF,
IO_FILE_BLIFMV,
IO_FILE_BENCH,
@@ -73,6 +74,8 @@ typedef enum {
extern Abc_Ntk_t * Io_ReadAiger( char * pFileName, int fCheck );
/*=== abcReadBaf.c ============================================================*/
extern Abc_Ntk_t * Io_ReadBaf( char * pFileName, int fCheck );
+/*=== abcReadBblif.c ============================================================*/
+extern Abc_Ntk_t * Io_ReadBblif( char * pFileName, int fCheck );
/*=== abcReadBlif.c ===========================================================*/
extern Abc_Ntk_t * Io_ReadBlif( char * pFileName, int fCheck );
/*=== abcReadBlifMv.c =========================================================*/
@@ -91,6 +94,8 @@ extern Abc_Ntk_t * Io_ReadVerilog( char * pFileName, int fCheck );
extern void Io_WriteAiger( Abc_Ntk_t * pNtk, char * pFileName, int fWriteSymbols, int fCompact );
/*=== abcWriteBaf.c ===========================================================*/
extern void Io_WriteBaf( Abc_Ntk_t * pNtk, char * pFileName );
+/*=== abcWriteBblif.c ===========================================================*/
+extern void Io_WriteBblif( Abc_Ntk_t * pNtk, char * pFileName );
/*=== abcWriteBlif.c ==========================================================*/
extern void Io_WriteBlifLogic( Abc_Ntk_t * pNtk, char * pFileName, int fWriteLatches );
extern void Io_WriteBlif( Abc_Ntk_t * pNtk, char * pFileName, int fWriteLatches );
diff --git a/src/base/io/ioReadAiger.c b/src/base/io/ioReadAiger.c
index 2c37e210..c26e4cd5 100644
--- a/src/base/io/ioReadAiger.c
+++ b/src/base/io/ioReadAiger.c
@@ -463,19 +463,19 @@ Abc_Ntk_t * Io_ReadAiger( char * pFileName, int fCheck )
}
// read the name of the model if given
- if ( *pCur == 'c' && pCur < pContents + nFileSize )
+ pCur = pSymbols;
+ if ( pCur + 1 < pContents + nFileSize && *pCur == 'c' )
{
- if ( !strncmp( pCur + 2, ".model", 6 ) )
+ pCur++;
+ if ( *pCur == 'n' )
{
- char * pTemp;
- for ( pTemp = pCur + 9; *pTemp && *pTemp != '\n'; pTemp++ );
- *pTemp = 0;
+ pCur++;
+ // read model name
ABC_FREE( pNtkNew->pName );
- pNtkNew->pName = Extra_UtilStrsav( pCur + 9 );
+ pNtkNew->pName = Extra_UtilStrsav( pCur );
}
}
-
// skipping the comments
ABC_FREE( pContents );
Vec_PtrFree( vNodes );
diff --git a/src/base/io/ioReadBblif.c b/src/base/io/ioReadBblif.c
new file mode 100644
index 00000000..84ef1e29
--- /dev/null
+++ b/src/base/io/ioReadBblif.c
@@ -0,0 +1,342 @@
+/**CFile****************************************************************
+
+ FileName [ioReadBblif.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Command processing package.]
+
+ Synopsis [Procedures to read AIG in the binary format.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: ioReadBblif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "ioAbc.h"
+#include "dec.h"
+#include "bblif.h"
+
+// For description of Binary BLIF format, refer to "abc/src/aig/bbl/bblif.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Fnction*************************************************************
+
+ Synopsis [Constructs ABC network from the manager.]
+
+ Description [The ABC network is started, as well as the array vCopy,
+ which will map the new ID of each object in the BBLIF manager into
+ the ponter ot the corresponding object in the ABC. For each internal
+ node, determined by Bbl_ObjIsLut(), the SOP representation is created
+ by retrieving the SOP representation of the BBLIF object. Finally,
+ the objects are connected using fanin/fanout creation, and the dummy
+ names are assigned because ABC requires each CI/CO to have a name.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Bbl_ManToAbc( Bbl_Man_t * p )
+{
+ Abc_Ntk_t * pNtk;
+ Abc_Obj_t * pObjNew;
+ Bbl_Obj_t * pObj, * pFanin;
+ Vec_Ptr_t * vCopy;
+ // start the network
+ pNtk = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_SOP, 1 );
+ pNtk->pName = Extra_UtilStrsav( Bbl_ManName(p) );
+ // create objects
+ vCopy = Vec_PtrStart( 1000 );
+ Bbl_ManForEachObj( p, pObj )
+ {
+ if ( Bbl_ObjIsInput(pObj) )
+ pObjNew = Abc_NtkCreatePi( pNtk );
+ else if ( Bbl_ObjIsOutput(pObj) )
+ pObjNew = Abc_NtkCreatePo( pNtk );
+ else if ( Bbl_ObjIsLut(pObj) )
+ pObjNew = Abc_NtkCreateNode( pNtk );
+ else assert( 0 );
+ if ( Bbl_ObjIsLut(pObj) )
+ pObjNew->pData = Abc_SopRegister( pNtk->pManFunc, Bbl_ObjSop(p, pObj) );
+ Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), pObjNew );
+ }
+ // connect objects
+ Bbl_ManForEachObj( p, pObj )
+ Bbl_ObjForEachFanin( pObj, pFanin )
+ Abc_ObjAddFanin( Vec_PtrEntry(vCopy, Bbl_ObjId(pObj)), Vec_PtrEntry(vCopy, Bbl_ObjId(pFanin)) );
+ // finalize
+ Vec_PtrFree( vCopy );
+ Abc_NtkAddDummyPiNames( pNtk );
+ Abc_NtkAddDummyPoNames( pNtk );
+ if ( !Abc_NtkCheck( pNtk ) )
+ printf( "Bbl_ManToAbc(): Network check has failed.\n" );
+ return pNtk;
+}
+
+/**Fnction*************************************************************
+
+ Synopsis [Collects internal nodes in the DFS order.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bbl_ManDfs_rec( Bbl_Obj_t * pObj, Vec_Ptr_t * vNodes )
+{
+ extern void Bbl_ObjMark( Bbl_Obj_t * p );
+ extern int Bbl_ObjIsMarked( Bbl_Obj_t * p );
+ Bbl_Obj_t * pFanin;
+ if ( Bbl_ObjIsMarked(pObj) || Bbl_ObjIsInput(pObj) )
+ return;
+ Bbl_ObjForEachFanin( pObj, pFanin )
+ Bbl_ManDfs_rec( pFanin, vNodes );
+ assert( !Bbl_ObjIsMarked(pObj) ); // checks if acyclic
+ Bbl_ObjMark( pObj );
+ Vec_PtrPush( vNodes, pObj );
+}
+
+/**Fnction*************************************************************
+
+ Synopsis [Collects internal nodes in the DFS order.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Ptr_t * Bbl_ManDfs( Bbl_Man_t * p )
+{
+ Vec_Ptr_t * vNodes;
+ Bbl_Obj_t * pObj;
+ vNodes = Vec_PtrAlloc( 1000 );
+ Bbl_ManForEachObj( p, pObj )
+ if ( Bbl_ObjIsLut(pObj) )
+ Bbl_ManDfs_rec( pObj, vNodes );
+ return vNodes;
+}
+
+/**Fnction*************************************************************
+
+ Synopsis [Constructs AIG in ABC from the manager.]
+
+ Description [The ABC network is started, as well as the array vCopy,
+ which will map the new ID of each object in the BBLIF manager into
+ the ponter ot the corresponding AIG object in the ABC. For each internal
+ node in a topological oder the AIG representation is created
+ by factoring the SOP representation of the BBLIF object. Finally,
+ the CO objects are created, and the dummy names are assigned because
+ ABC requires each CI/CO to have a name.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Bbl_ManToAig( Bbl_Man_t * p )
+{
+ extern int Bbl_ManFncSize( Bbl_Man_t * p );
+ extern int Bbl_ObjFncHandle( Bbl_Obj_t * p );
+ extern Abc_Obj_t * Dec_GraphToAig( Abc_Ntk_t * pNtk, Dec_Graph_t * pFForm, Vec_Ptr_t * vFaninAigs );
+ int fVerbose = 0;
+ Abc_Ntk_t * pNtk;
+ Abc_Obj_t * pObjNew;
+ Bbl_Obj_t * pObj, * pFanin;
+ Vec_Ptr_t * vCopy, * vNodes, * vFaninAigs;
+ Dec_Graph_t ** pFForms;
+ int i, clk;
+clk = clock();
+ // map SOP handles into factored forms
+ pFForms = ABC_CALLOC( Dec_Graph_t *, Bbl_ManFncSize(p) );
+ Bbl_ManForEachObj( p, pObj )
+ if ( pFForms[Bbl_ObjFncHandle(pObj)] == NULL )
+ pFForms[Bbl_ObjFncHandle(pObj)] = Dec_Factor( Bbl_ObjSop(p, pObj) );
+if ( fVerbose )
+ABC_PRT( "Fct", clock() - clk );
+ // start the network
+ pNtk = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
+ pNtk->pName = Extra_UtilStrsav( Bbl_ManName(p) );
+ vCopy = Vec_PtrStart( 1000 );
+ // create CIs
+ Bbl_ManForEachObj( p, pObj )
+ {
+ if ( !Bbl_ObjIsInput(pObj) )
+ continue;
+ Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), Abc_NtkCreatePi(pNtk) );
+ }
+clk = clock();
+ // create internal nodes
+ vNodes = Bbl_ManDfs( p );
+ vFaninAigs = Vec_PtrAlloc( 100 );
+ Vec_PtrForEachEntry( vNodes, pObj, i )
+ {
+ // collect fanin AIGs
+ Vec_PtrClear( vFaninAigs );
+ Bbl_ObjForEachFanin( pObj, pFanin )
+ Vec_PtrPush( vFaninAigs, Vec_PtrEntry( vCopy, Bbl_ObjId(pFanin) ) );
+ // create the new node
+ pObjNew = Dec_GraphToAig( pNtk, pFForms[Bbl_ObjFncHandle(pObj)], vFaninAigs );
+ Vec_PtrSetEntry( vCopy, Bbl_ObjId(pObj), pObjNew );
+ }
+ Vec_PtrFree( vFaninAigs );
+ Vec_PtrFree( vNodes );
+if ( fVerbose )
+ABC_PRT( "AIG", clock() - clk );
+ // create COs
+ Bbl_ManForEachObj( p, pObj )
+ {
+ if ( !Bbl_ObjIsOutput(pObj) )
+ continue;
+ pObjNew = Vec_PtrEntry( vCopy, Bbl_ObjId(Bbl_ObjFaninFirst(pObj)) );
+ Abc_ObjAddFanin( Abc_NtkCreatePo(pNtk), pObjNew );
+ }
+ Abc_AigCleanup( pNtk->pManFunc );
+ // clear factored forms
+ for ( i = Bbl_ManFncSize(p) - 1; i >= 0; i-- )
+ if ( pFForms[i] )
+ Dec_GraphFree( pFForms[i] );
+ ABC_FREE( pFForms );
+ // finalize
+clk = clock();
+ Vec_PtrFree( vCopy );
+ Abc_NtkAddDummyPiNames( pNtk );
+ Abc_NtkAddDummyPoNames( pNtk );
+if ( fVerbose )
+ABC_PRT( "Nam", clock() - clk );
+// if ( !Abc_NtkCheck( pNtk ) )
+// printf( "Bbl_ManToAig(): Network check has failed.\n" );
+ return pNtk;
+}
+
+/**Fnction*************************************************************
+
+ Synopsis [Verifies equivalence for two combinational networks.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bbl_ManVerify( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2 )
+{
+ extern void Abc_NtkCecFraig( Abc_Ntk_t * pNtk1, Abc_Ntk_t * pNtk2, int nSeconds, int fVerbose );
+ Abc_Ntk_t * pAig1, * pAig2;
+ pAig1 = Abc_NtkStrash( pNtk1, 0, 1, 0 );
+ pAig2 = Abc_NtkStrash( pNtk2, 0, 1, 0 );
+ Abc_NtkShortNames( pAig1 );
+ Abc_NtkShortNames( pAig2 );
+ Abc_NtkCecFraig( pAig1, pAig2, 0, 0 );
+ Abc_NtkDelete( pAig1 );
+ Abc_NtkDelete( pAig2 );
+}
+
+/**Fnction*************************************************************
+
+ Synopsis [Performs testing of the new manager.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Bbl_ManTest( Abc_Ntk_t * pNtk )
+{
+ extern Bbl_Man_t * Bbl_ManFromAbc( Abc_Ntk_t * pNtk );
+
+ Abc_Ntk_t * pNtkNew;
+ Bbl_Man_t * p, * pNew;
+ char * pFileName = "test.bblif";
+ int clk, clk1, clk2, clk3, clk4, clk5;
+clk = clock();
+ p = Bbl_ManFromAbc( pNtk );
+ Bbl_ManPrintStats( p );
+clk1 = clock() - clk;
+//Bbl_ManDumpBlif( p, "test_bbl.blif" );
+
+ // write into file and back
+clk = clock();
+ Bbl_ManDumpBinaryBlif( p, pFileName );
+clk2 = clock() - clk;
+
+ // read from file
+clk = clock();
+ pNew = Bbl_ManReadBinaryBlif( pFileName );
+ Bbl_ManStop( p ); p = pNew;
+clk3 = clock() - clk;
+
+ // generate ABC network
+clk = clock();
+ pNtkNew = Bbl_ManToAig( p );
+// pNtkNew = Bbl_ManToAbc( p );
+ Bbl_ManStop( p );
+clk4 = clock() - clk;
+
+ // equivalence check
+clk = clock();
+// Bbl_ManVerify( pNtk, pNtkNew );
+ Abc_NtkDelete( pNtkNew );
+clk5 = clock() - clk;
+
+printf( "Runtime stats:\n" );
+ABC_PRT( "ABC to Man", clk1 );
+ABC_PRT( "Writing ", clk2 );
+ABC_PRT( "Reading ", clk3 );
+ABC_PRT( "Man to ABC", clk4 );
+ABC_PRT( "Verify ", clk5 );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Reads the AIG in the binary format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Io_ReadBblif( char * pFileName, int fCheck )
+{
+ Bbl_Man_t * p;
+ Abc_Ntk_t * pNtkNew;
+ // read the file
+ p = Bbl_ManReadBinaryBlif( pFileName );
+ pNtkNew = Bbl_ManToAig( p );
+ Bbl_ManStop( p );
+ // check the result
+ if ( fCheck && !Abc_NtkCheckRead( pNtkNew ) )
+ {
+ printf( "Io_ReadBaf: The network check has failed.\n" );
+ Abc_NtkDelete( pNtkNew );
+ return NULL;
+ }
+ return pNtkNew;
+}
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/io/ioUtil.c b/src/base/io/ioUtil.c
index c67c183d..c00c3008 100644
--- a/src/base/io/ioUtil.c
+++ b/src/base/io/ioUtil.c
@@ -51,6 +51,8 @@ Io_FileType_t Io_ReadFileType( char * pFileName )
return IO_FILE_AIGER;
if ( !strcmp( pExt, "baf" ) )
return IO_FILE_BAF;
+ if ( !strcmp( pExt, "bblif" ) )
+ return IO_FILE_BBLIF;
if ( !strcmp( pExt, "blif" ) )
return IO_FILE_BLIF;
if ( !strcmp( pExt, "bench" ) )
@@ -108,12 +110,14 @@ Abc_Ntk_t * Io_ReadNetlist( char * pFileName, Io_FileType_t FileType, int fCheck
}
fclose( pFile );
// read the AIG
- if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF )
+ if ( FileType == IO_FILE_AIGER || FileType == IO_FILE_BAF || FileType == IO_FILE_BBLIF )
{
if ( FileType == IO_FILE_AIGER )
pNtk = Io_ReadAiger( pFileName, fCheck );
- else // if ( FileType == IO_FILE_BAF )
+ else if ( FileType == IO_FILE_BAF )
pNtk = Io_ReadBaf( pFileName, fCheck );
+ else // if ( FileType == IO_FILE_BBLIF )
+ pNtk = Io_ReadBblif( pFileName, fCheck );
if ( pNtk == NULL )
{
fprintf( stdout, "Reading AIG from file has failed.\n" );
@@ -258,7 +262,7 @@ void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType )
}
if ( FileType == IO_FILE_AIGER )
Io_WriteAiger( pNtk, pFileName, 1, 0 );
- else // if ( FileType == IO_FILE_BAF )
+ else //if ( FileType == IO_FILE_BAF )
Io_WriteBaf( pNtk, pFileName );
return;
}
@@ -278,6 +282,18 @@ void Io_Write( Abc_Ntk_t * pNtk, char * pFileName, Io_FileType_t FileType )
Io_WriteGml( pNtk, pFileName );
return;
}
+ if ( FileType == IO_FILE_BBLIF )
+ {
+ if ( !Abc_NtkIsLogic(pNtk) )
+ {
+ fprintf( stdout, "Writing Binary BLIF is only possible for logic networks.\n" );
+ return;
+ }
+ if ( !Abc_NtkHasSop(pNtk) )
+ Abc_NtkToSop( pNtk, 0 );
+ Io_WriteBblif( pNtk, pFileName );
+ return;
+ }
/*
if ( FileType == IO_FILE_BLIFMV )
{
diff --git a/src/base/io/ioWriteAiger.c b/src/base/io/ioWriteAiger.c
index f1793a59..8957743c 100644
--- a/src/base/io/ioWriteAiger.c
+++ b/src/base/io/ioWriteAiger.c
@@ -726,10 +726,10 @@ void Io_WriteAiger( Abc_Ntk_t * pNtk, char * pFileName, int fWriteSymbols, int f
}
// write the comment
- fprintfBz2Aig( &b, "c\n" );
+ fprintfBz2Aig( &b, "c" );
if ( pNtk->pName && strlen(pNtk->pName) > 0 )
- fprintfBz2Aig( &b, ".model %s\n", pNtk->pName );
- fprintfBz2Aig( &b, "This file was produced by ABC on %s\n", Extra_TimeStamp() );
+ fprintfBz2Aig( &b, "n%s%c", pNtk->pName, '\0' );
+ fprintfBz2Aig( &b, "\nThis file was written by ABC on %s\n", Extra_TimeStamp() );
fprintfBz2Aig( &b, "For information about AIGER format, refer to %s\n", "http://fmv.jku.at/aiger" );
// close the file
diff --git a/src/base/io/ioWriteBblif.c b/src/base/io/ioWriteBblif.c
new file mode 100644
index 00000000..e5bd6503
--- /dev/null
+++ b/src/base/io/ioWriteBblif.c
@@ -0,0 +1,111 @@
+/**CFile****************************************************************
+
+ FileName [ioWriteBblif.c]
+
+ SystemName [ABC: Logic synthesis and verification system.]
+
+ PackageName [Command processing package.]
+
+ Synopsis [Procedures to write AIG in the binary format.]
+
+ Author [Alan Mishchenko]
+
+ Affiliation [UC Berkeley]
+
+ Date [Ver. 1.0. Started - June 20, 2005.]
+
+ Revision [$Id: ioWriteBblif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
+
+***********************************************************************/
+
+#include "ioAbc.h"
+#include "bblif.h"
+
+// For description of Binary BLIF format, refer to "abc/src/aig/bbl/bblif.h"
+
+////////////////////////////////////////////////////////////////////////
+/// DECLARATIONS ///
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+/// FUNCTION DEFINITIONS ///
+////////////////////////////////////////////////////////////////////////
+
+/**Fnction*************************************************************
+
+ Synopsis [Construct manager from the ABC network.]
+
+ Description [In the ABC network each object has a unique integer ID.
+ This ID is used when we construct objects of the BBLIF manager
+ corresponding to each object of the ABC network. The objects can be
+ added to the manager in any order (although below they are added in the
+ topological order), but by the time fanin/fanout connections are created,
+ corresponding objects are already constructed. In the end the checking
+ procedure is called.]
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Bbl_Man_t * Bbl_ManFromAbc( Abc_Ntk_t * pNtk )
+{
+ Bbl_Man_t * p;
+ Vec_Ptr_t * vNodes;
+ Abc_Obj_t * pObj, * pFanin;
+ int i, k;
+ assert( Abc_NtkIsSopLogic(pNtk) );
+ // start the data manager
+ p = Bbl_ManStart( Abc_NtkName(pNtk) );
+ // collect internal nodes to be added
+ vNodes = Abc_NtkDfs( pNtk, 0 );
+ // create combinational inputs
+ Abc_NtkForEachCi( pNtk, pObj, i )
+ Bbl_ManCreateObject( p, BBL_OBJ_CI, Abc_ObjId(pObj), 0, NULL );
+ // create internal nodes
+ Vec_PtrForEachEntry( vNodes, pObj, i )
+ Bbl_ManCreateObject( p, BBL_OBJ_NODE, Abc_ObjId(pObj), Abc_ObjFaninNum(pObj), pObj->pData );
+ // create combinational outputs
+ Abc_NtkForEachCo( pNtk, pObj, i )
+ Bbl_ManCreateObject( p, BBL_OBJ_CO, Abc_ObjId(pObj), 1, NULL );
+ // create fanin/fanout connections for internal nodes
+ Vec_PtrForEachEntry( vNodes, pObj, i )
+ Abc_ObjForEachFanin( pObj, pFanin, k )
+ Bbl_ManAddFanin( p, Abc_ObjId(pObj), Abc_ObjId(pFanin) );
+ // create fanin/fanout connections for combinational outputs
+ Abc_NtkForEachCo( pNtk, pObj, i )
+ Abc_ObjForEachFanin( pObj, pFanin, k )
+ Bbl_ManAddFanin( p, Abc_ObjId(pObj), Abc_ObjId(pFanin) );
+ Vec_PtrFree( vNodes );
+ // sanity check
+ Bbl_ManCheck( p );
+ return p;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Writes the AIG in the binary format.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Io_WriteBblif( Abc_Ntk_t * pNtk, char * pFileName )
+{
+ Bbl_Man_t * p;
+ p = Bbl_ManFromAbc( pNtk );
+//Bbl_ManPrintStats( p );
+//Bbl_ManDumpBlif( p, "test_bbl.blif" );
+ Bbl_ManDumpBinaryBlif( p, pFileName );
+ Bbl_ManStop( p );
+}
+
+
+////////////////////////////////////////////////////////////////////////
+/// END OF FILE ///
+////////////////////////////////////////////////////////////////////////
+
+
diff --git a/src/base/io/module.make b/src/base/io/module.make
index 6f4e2539..993bd7d2 100644
--- a/src/base/io/module.make
+++ b/src/base/io/module.make
@@ -1,6 +1,7 @@
SRC += src/base/io/io.c \
src/base/io/ioReadAiger.c \
src/base/io/ioReadBaf.c \
+ src/base/io/ioReadBblif.c \
src/base/io/ioReadBench.c \
src/base/io/ioReadBlif.c \
src/base/io/ioReadBlifAig.c \
@@ -13,6 +14,7 @@ SRC += src/base/io/io.c \
src/base/io/ioUtil.c \
src/base/io/ioWriteAiger.c \
src/base/io/ioWriteBaf.c \
+ src/base/io/ioWriteBblif.c \
src/base/io/ioWriteBench.c \
src/base/io/ioWriteBlif.c \
src/base/io/ioWriteBlifMv.c \