Commit dcb7d0d3 by Alan Mishchenko

New word-level representation package.

parent ae7e2862
......@@ -14,7 +14,7 @@ PROG := abc
MODULES := \
$(wildcard src/ext) src/misc/ext \
src/base/abc src/base/abci src/base/cmd src/base/io \
src/base/main src/base/ver src/base/test \
src/base/main src/base/ver src/base/wlc src/base/test \
src/bdd/cudd src/bdd/dsd src/bdd/epd src/bdd/mtr src/bdd/parse \
src/bdd/reo src/bdd/cas \
src/map/mapper src/map/mio src/map/super src/map/if \
......
......@@ -599,10 +599,6 @@ SOURCE=.\src\base\io\ioReadVerilog.c
# End Source File
# Begin Source File
SOURCE=.\src\base\io\ioReadWord.c
# End Source File
# Begin Source File
SOURCE=.\src\base\io\ioUtil.c
# End Source File
# Begin Source File
......@@ -746,6 +742,38 @@ SOURCE=.\src\base\test\test.c
# PROP Default_Filter ""
# End Group
# Begin Group "wlc"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\src\base\wlc\wlc.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlc.h
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlcBlast.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlcCom.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlcNtk.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlcReadVer.c
# End Source File
# Begin Source File
SOURCE=.\src\base\wlc\wlcWriteVer.c
# End Source File
# End Group
# End Group
# Begin Group "bdd"
......
......@@ -309,10 +309,12 @@ void Abc_ShowFile( char * FileNameDot )
if ( _spawnl( _P_NOWAIT, pGsNameWin, pGsNameWin, FileNamePs, NULL ) == -1 )
if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe",
"C:\\Program Files\\Ghostgum\\gsview\\gsview32.exe", FileNamePs, NULL ) == -1 )
{
fprintf( stdout, "Cannot find \"%s\".\n", pGsNameWin );
return;
}
if ( _spawnl( _P_NOWAIT, "C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe",
"C:\\Program Files\\Ghostgum\\gsview\\gsview64.exe", FileNamePs, NULL ) == -1 )
{
fprintf( stdout, "Cannot find \"%s\".\n", pGsNameWin );
return;
}
#else
{
char CommandPs[1000];
......
......@@ -46,7 +46,6 @@ static int IoCommandReadTruth ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadVerilog ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadStatus ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadGig ( Abc_Frame_t * pAbc, int argc, char **argv );
static int IoCommandReadWord ( 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 );
......@@ -111,7 +110,6 @@ void Io_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "I/O", "read_verilog", IoCommandReadVerilog, 1 );
Cmd_CommandAdd( pAbc, "I/O", "read_status", IoCommandReadStatus, 0 );
Cmd_CommandAdd( pAbc, "I/O", "&read_gig", IoCommandReadGig, 0 );
Cmd_CommandAdd( pAbc, "I/O", "read_word", IoCommandReadWord, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write", IoCommandWrite, 0 );
Cmd_CommandAdd( pAbc, "I/O", "write_hie", IoCommandWriteHie, 0 );
......@@ -1193,61 +1191,6 @@ usage:
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int IoCommandReadWord( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Io_ReadWordTest( char * pFileName );
char * pFileName;
FILE * pFile;
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;
}
// get the input file name
pFileName = argv[globalUtilOptind];
if ( (pFile = fopen( pFileName, "r" )) == NULL )
{
fprintf( pAbc->Err, "Cannot open input file \"%s\". \n", pFileName );
return 1;
}
fclose( pFile );
// set the new network
// Io_ReadWordTest( pFileName );
return 0;
usage:
fprintf( pAbc->Err, "usage: read_word [-h] <file>\n" );
fprintf( pAbc->Err, "\t reads design in word-level Verilog\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*************************************************************
......
......@@ -50,6 +50,8 @@ extern void Load_Init( Abc_Frame_t * pAbc );
extern void Load_End( Abc_Frame_t * pAbc );
extern void Scl_Init( Abc_Frame_t * pAbc );
extern void Scl_End( Abc_Frame_t * pAbc );
extern void Wlc_Init( Abc_Frame_t * pAbc );
extern void Wlc_End( Abc_Frame_t * pAbc );
extern void Test_Init( Abc_Frame_t * pAbc );
extern void Test_End( Abc_Frame_t * pAbc );
extern void Abc2_Init( Abc_Frame_t * pAbc );
......@@ -85,6 +87,7 @@ void Abc_FrameInit( Abc_Frame_t * pAbc )
Libs_Init( pAbc );
Load_Init( pAbc );
Scl_Init( pAbc );
Wlc_Init( pAbc );
Test_Init( pAbc );
#ifdef USE_ABC2
Abc2_Init( pAbc );
......@@ -119,6 +122,7 @@ void Abc_FrameEnd( Abc_Frame_t * pAbc )
Libs_End( pAbc );
Load_End( pAbc );
Scl_End( pAbc );
Wlc_End( pAbc );
Test_End( pAbc );
#ifdef USE_ABC2
Abc2_End( pAbc );
......
......@@ -126,6 +126,7 @@ struct Abc_Frame_t_
void * pAbc85Ntl2;
void * pAbc85Best;
void * pAbc85Delay;
void * pAbcWlc;
EXT_ABC_FRAME // plugin for external functionality
};
......
SRC += src/base/wlc/wlc.c \
src/base/wlc/wlcBlast.c \
src/base/wlc/wlcCom.c \
src/base/wlc/wlcNtk.c \
src/base/wlc/wlcReadVer.c \
src/base/wlc/wlcWriteVer.c
/**CFile****************************************************************
FileName [wlc.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Parses several flavors of word-level Verilog.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 22, 2014.]
Revision [$Id: wlc.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wlc.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
/**CFile****************************************************************
FileName [wlcCom.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Command handlers.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 22, 2014.]
Revision [$Id: wlcCom.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wlc.h"
#include "base/main/mainInt.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Abc_CommandReadVer ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandWriteVer ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandPs ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandBlast ( Abc_Frame_t * pAbc, int argc, char ** argv );
static inline Wlc_Ntk_t * Wlc_AbcGetNtk( Abc_Frame_t * pAbc ) { return (Wlc_Ntk_t *)pAbc->pAbcWlc; }
static inline void Wlc_AbcFreeNtk( Abc_Frame_t * pAbc ) { if ( pAbc->pAbcWlc ) Wlc_NtkFree(Wlc_AbcGetNtk(pAbc)); }
static inline void Wlc_AbcUpdateNtk( Abc_Frame_t * pAbc, Wlc_Ntk_t * pNtk ) { Wlc_AbcFreeNtk(pAbc); pAbc->pAbcWlc = pNtk; }
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
void Wlc_Init( Abc_Frame_t * pAbc )
{
Cmd_CommandAdd( pAbc, "Word level", "%read_ver", Abc_CommandReadVer, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%write_ver", Abc_CommandWriteVer, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%ps", Abc_CommandPs, 0 );
Cmd_CommandAdd( pAbc, "Word level", "%blast", Abc_CommandBlast, 0 );
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
void Wlc_End( Abc_Frame_t * pAbc )
{
Wlc_AbcFreeNtk( pAbc );
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandReadVer( Abc_Frame_t * pAbc, int argc, char ** argv )
{
FILE * pFile;
Wlc_Ntk_t * pNtk = NULL;
char * pFileName = NULL;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
{
switch ( c )
{
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( argc != globalUtilOptind + 1 )
{
printf( "Abc_CommandReadVer(): Input file name should be given on the command line.\n" );
return 0;
}
// get the file name
pFileName = argv[globalUtilOptind];
if ( (pFile = fopen( pFileName, "r" )) == NULL )
{
Abc_Print( 1, "Cannot open input file \"%s\". ", pFileName );
if ( (pFileName = Extra_FileGetSimilarName( pFileName, ".v", ".smt", NULL, NULL, NULL )) )
Abc_Print( 1, "Did you mean \"%s\"?", pFileName );
Abc_Print( 1, "\n" );
return 0;
}
fclose( pFile );
// perform reading
pNtk = Wlc_ReadVer( pFileName );
Wlc_AbcUpdateNtk( pAbc, pNtk );
return 0;
usage:
Abc_Print( -2, "usage: %%read_ver [-vh] <file_name>\n" );
Abc_Print( -2, "\t reads word-level design from Verilog file\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandWriteVer( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
char * pFileName = NULL;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
{
switch ( c )
{
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pNtk == NULL )
{
Abc_Print( 1, "Abc_CommandWriteVer(): There is no current design.\n" );
return 0;
}
if ( argc == globalUtilOptind )
pFileName = Extra_FileNameGenericAppend( pNtk->pName, "_out.v" );
else if ( argc == globalUtilOptind + 1 )
pFileName = argv[globalUtilOptind];
else
{
printf( "Output file name should be given on the command line.\n" );
return 0;
}
Wlc_WriteVer( pNtk, pFileName );
return 0;
usage:
Abc_Print( -2, "usage: %%write_ver [-vh]\n" );
Abc_Print( -2, "\t writes the design into a file\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandPs( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
int fShowMulti = 0;
int fShowAdder = 0;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "mavh" ) ) != EOF )
{
switch ( c )
{
case 'm':
fShowMulti ^= 1;
break;
case 'a':
fShowAdder ^= 1;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pNtk == NULL )
{
Abc_Print( 1, "Abc_CommandPs(): There is no current design.\n" );
return 0;
}
Wlc_NtkPrintStats( pNtk, fVerbose );
if ( fShowMulti )
Wlc_NtkPrintNodes( pNtk, WLC_OBJ_ARI_MULTI );
if ( fShowAdder )
Wlc_NtkPrintNodes( pNtk, WLC_OBJ_ARI_ADD );
return 0;
usage:
Abc_Print( -2, "usage: %%ps [-mavh]\n" );
Abc_Print( -2, "\t prints statistics\n" );
Abc_Print( -2, "\t-m : toggle printing multipliers [default = %s]\n", fShowMulti? "yes": "no" );
Abc_Print( -2, "\t-a : toggle printing adders [default = %s]\n", fShowAdder? "yes": "no" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
/**Function********************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
******************************************************************************/
int Abc_CommandBlast( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Wlc_Ntk_t * pNtk = Wlc_AbcGetNtk(pAbc);
Gia_Man_t * pNew = NULL;
int c, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
{
switch ( c )
{
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
if ( pNtk == NULL )
{
Abc_Print( 1, "Abc_CommandBlast(): There is no current design.\n" );
return 0;
}
// transform
pNew = Wlc_NtkBitBlast( pNtk );
if ( pNew == NULL )
{
Abc_Print( 1, "Abc_CommandBlast(): Bit-blasting has failed.\n" );
return 0;
}
Abc_FrameUpdateGia( pAbc, pNew );
return 0;
usage:
Abc_Print( -2, "usage: %%blast [-vh]\n" );
Abc_Print( -2, "\t performs bit-blasting of the word-level design\n" );
Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");
return 1;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
/**CFile****************************************************************
FileName [wlcNtk.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Network data-structure.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 22, 2014.]
Revision [$Id: wlcNtk.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wlc.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Working with models.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Wlc_Ntk_t * Wlc_NtkAlloc( char * pName, int nObjsAlloc )
{
Wlc_Ntk_t * p;
p = ABC_CALLOC( Wlc_Ntk_t, 1 );
p->pName = Extra_FileNameGeneric( pName );
Vec_IntGrow( &p->vPis, 111 );
Vec_IntGrow( &p->vPos, 111 );
Vec_IntGrow( &p->vCis, 111 );
Vec_IntGrow( &p->vCos, 111 );
Vec_IntGrow( &p->vFfs, 111 );
p->pMemFanin = Mem_FlexStart();
p->nObjsAlloc = nObjsAlloc;
p->pObjs = ABC_CALLOC( Wlc_Obj_t, p->nObjsAlloc );
p->iObj = 1;
return p;
}
int Wlc_ObjAlloc( Wlc_Ntk_t * p, int Type, int Signed, int End, int Beg )
{
Wlc_Obj_t * pObj;
if ( p->iObj == p->nObjsAlloc )
{
p->pObjs = ABC_REALLOC( Wlc_Obj_t, p->pObjs, 2 * p->nObjsAlloc );
memset( p->pObjs + p->nObjsAlloc, 0, sizeof(Wlc_Obj_t) * p->nObjsAlloc );
p->nObjsAlloc *= 2;
}
pObj = Wlc_NtkObj( p, p->iObj );
pObj->Type = Type;
pObj->Signed = Signed;
pObj->End = End;
pObj->Beg = Beg;
if ( Type == WLC_OBJ_PI )
{
pObj->Fanins[1] = Vec_IntSize(&p->vPis);
Vec_IntPush( &p->vPis, p->iObj );
}
else if ( Type == WLC_OBJ_PO )
{
pObj->Fanins[1] = Vec_IntSize(&p->vPos);
Vec_IntPush( &p->vPos, p->iObj );
}
p->nObjs[Type]++;
return p->iObj++;
}
char * Wlc_ObjName( Wlc_Ntk_t * p, int iObj )
{
static char Buffer[100];
if ( Wlc_NtkHasNameId(p) && Wlc_ObjNameId(p, iObj) )
return Abc_NamStr( p->pManName, Wlc_ObjNameId(p, iObj) );
sprintf( Buffer, "n%d", iObj );
return Buffer;
}
void Wlc_ObjUpdateType( Wlc_Ntk_t * p, Wlc_Obj_t * pObj, int Type )
{
if ( pObj->Type == WLC_OBJ_PO )
{
assert( Type == WLC_OBJ_BUF );
return;
}
p->nObjs[pObj->Type]--;
pObj->Type = Type;
p->nObjs[pObj->Type]++;
}
void Wlc_ObjAddFanins( Wlc_Ntk_t * p, Wlc_Obj_t * pObj, Vec_Int_t * vFanins )
{
assert( pObj->nFanins == 0 );
pObj->nFanins = Vec_IntSize(vFanins);
if ( Wlc_ObjHasArray(pObj) )
pObj->pFanins[0] = (int *)Mem_FlexEntryFetch( p->pMemFanin, Vec_IntSize(vFanins) * sizeof(int) );
memcpy( Wlc_ObjFanins(pObj), Vec_IntArray(vFanins), sizeof(int) * Vec_IntSize(vFanins) );
// special treatment of CONST and SELECT
if ( pObj->Type == WLC_OBJ_CONST )
pObj->nFanins = 0;
else if ( pObj->Type == WLC_OBJ_BIT_SELECT )
pObj->nFanins = 1;
}
void Wlc_NtkFree( Wlc_Ntk_t * p )
{
if ( p->pManName )
Abc_NamStop( p->pManName );
if ( p->pMemFanin )
Mem_FlexStop( p->pMemFanin, 0 );
ABC_FREE( p->vPis.pArray );
ABC_FREE( p->vPos.pArray );
ABC_FREE( p->vCis.pArray );
ABC_FREE( p->vCos.pArray );
ABC_FREE( p->vFfs.pArray );
ABC_FREE( p->vTravIds.pArray );
ABC_FREE( p->vNameIds.pArray );
ABC_FREE( p->vCopies.pArray );
ABC_FREE( p->pObjs );
ABC_FREE( p->pName );
ABC_FREE( p );
}
int Wlc_NtkMemUsage( Wlc_Ntk_t * p )
{
int Mem = sizeof(Wlc_Ntk_t);
Mem += 4 * p->vPis.nCap;
Mem += 4 * p->vPos.nCap;
Mem += 4 * p->vCis.nCap;
Mem += 4 * p->vCos.nCap;
Mem += 4 * p->vFfs.nCap;
Mem += sizeof(Wlc_Obj_t) * p->nObjsAlloc;
Mem += Abc_NamMemUsed(p->pManName);
Mem += Mem_FlexReadMemUsage(p->pMemFanin);
return Mem;
}
void Wlc_NtkPrintNodes( Wlc_Ntk_t * p, int Type )
{
Wlc_Obj_t * pObj;
int i, Counter = 0;
printf( "Operation %s\n", Wlc_Names[Type] );
Wlc_NtkForEachObj( p, pObj, i )
{
if ( (int)pObj->Type != Type )
continue;
printf( "%8d :", Counter++ );
printf( "%8d : ", i );
printf( "%3d%s = ", Wlc_ObjRange(pObj), pObj->Signed ? "s" : " " );
printf( "%3d%s %s ", Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)), Wlc_ObjFanin0(p, pObj)->Signed ? "s" : " ", Wlc_Names[Type] );
printf( "%3d%s ", Wlc_ObjRange(Wlc_ObjFanin1(p, pObj)), Wlc_ObjFanin1(p, pObj)->Signed ? "s" : " " );
printf( " : " );
printf( "%-12s = ", Wlc_ObjName(p, i) );
printf( "%-12s %s ", Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)), Wlc_Names[Type] );
printf( "%-12s ", Wlc_ObjName(p, Wlc_ObjFaninId1(pObj)) );
printf( "\n" );
}
}
void Wlc_NtkPrintStats( Wlc_Ntk_t * p, int fVerbose )
{
int i;
printf( "%-20s : ", p->pName );
printf( "PI = %4d ", Wlc_NtkPiNum(p) );
printf( "PO = %4d ", Wlc_NtkPoNum(p) );
printf( "FF = %4d ", Wlc_NtkFfNum(p) );
printf( "Obj = %6d ", Wlc_NtkObjNum(p) );
printf( "Mem = %.3f MB", 1.0*Wlc_NtkMemUsage(p)/(1<<20) );
printf( "\n" );
if ( !fVerbose )
return;
printf( "Node type statisticts:\n" );
for ( i = 0; i < WLC_OBJ_NUMBER; i++ )
if ( p->nObjs[i] )
printf( "%2d : %6d %-8s\n", i, p->nObjs[i], Wlc_Names[i] );
// Wlc_NtkPrintNodes( p, WLC_OBJ_ARI_MULTI );
}
/**Function*************************************************************
Synopsis [Duplicates the network in a topological order.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Wlc_ObjCollectCopyFanins( Wlc_Ntk_t * p, int iObj, Vec_Int_t * vFanins )
{
int i, iFanin;
Wlc_Obj_t * pObj = Wlc_NtkObj( p, iObj );
Vec_IntClear( vFanins );
Wlc_ObjForEachFanin( pObj, iFanin, i )
Vec_IntPush( vFanins, Wlc_ObjCopy(p, iFanin) );
// special treatment of CONST and SELECT
if ( pObj->Type == WLC_OBJ_CONST )
{
int * pInts = Wlc_ObjConstValue( pObj );
int nInts = Abc_BitWordNum( Wlc_ObjRange(pObj) );
for ( i = 0; i < nInts; i++ )
Vec_IntPush( vFanins, pInts[i] );
}
else if ( pObj->Type == WLC_OBJ_BIT_SELECT )
{
assert( Vec_IntSize(vFanins) == 1 );
Vec_IntPush( vFanins, pObj->Fanins[1] );
}
}
int Wlc_ObjDup( Wlc_Ntk_t * pNew, Wlc_Ntk_t * p, int iObj, Vec_Int_t * vFanins )
{
Wlc_Obj_t * pObj = Wlc_NtkObj( p, iObj );
int iFaninNew = Wlc_ObjAlloc( pNew, pObj->Type, pObj->Signed, pObj->End, pObj->Beg );
Wlc_Obj_t * pObjNew = Wlc_NtkObj(pNew, iFaninNew);
Wlc_ObjCollectCopyFanins( p, iObj, vFanins );
Wlc_ObjAddFanins( pNew, pObjNew, vFanins );
Wlc_ObjSetCopy( p, iObj, iFaninNew );
return iFaninNew;
}
void Wlc_NtkDupDfs_rec( Wlc_Ntk_t * pNew, Wlc_Ntk_t * p, int iObj, Vec_Int_t * vFanins )
{
Wlc_Obj_t * pObj;
int i, iFanin;
if ( Wlc_ObjCopy(p, iObj) )
return;
pObj = Wlc_NtkObj( p, iObj );
Wlc_ObjForEachFanin( pObj, iFanin, i )
Wlc_NtkDupDfs_rec( pNew, p, iFanin, vFanins );
Wlc_ObjDup( pNew, p, iObj, vFanins );
}
Wlc_Ntk_t * Wlc_NtkDupDfs( Wlc_Ntk_t * p )
{
Wlc_Ntk_t * pNew;
Wlc_Obj_t * pObj;
Vec_Int_t * vFanins;
int i;
Wlc_NtkCleanCopy( p );
vFanins = Vec_IntAlloc( 100 );
pNew = Wlc_NtkAlloc( p->pName, p->nObjsAlloc );
Wlc_NtkForEachPi( p, pObj, i )
Wlc_ObjDup( pNew, p, Wlc_ObjId(p, pObj), vFanins );
Wlc_NtkForEachPo( p, pObj, i )
Wlc_NtkDupDfs_rec( pNew, p, Wlc_ObjFaninId0(pObj), vFanins );
Wlc_NtkForEachPo( p, pObj, i )
Wlc_ObjDup( pNew, p, Wlc_ObjId(p, pObj), vFanins );
Vec_IntFree( vFanins );
return pNew;
}
void Wlc_NtkTransferNames( Wlc_Ntk_t * pNew, Wlc_Ntk_t * p )
{
int i;
assert( !Wlc_NtkHasCopy(pNew) && Wlc_NtkHasCopy(p) );
assert( !Wlc_NtkHasNameId(pNew) && Wlc_NtkHasNameId(p) );
assert( pNew->pManName == NULL && p->pManName != NULL );
Wlc_NtkCleanNameId( pNew );
for ( i = 0; i < p->nObjsAlloc; i++ )
if ( Wlc_ObjCopy(p, i) && Wlc_ObjNameId(p, i) )
Wlc_ObjSetNameId( pNew, Wlc_ObjCopy(p, i), Wlc_ObjNameId(p, i) );
pNew->pManName = p->pManName;
p->pManName = NULL;
Vec_IntErase( &p->vNameIds );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
/**CFile****************************************************************
FileName [wlcWriteVer.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Verilog parser.]
Synopsis [Writes word-level Verilog.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - August 22, 2014.]
Revision [$Id: wlcWriteVer.c,v 1.00 2014/09/12 00:00:00 alanmi Exp $]
***********************************************************************/
#include "wlc.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Wlc_WriteVerIntVec( FILE * pFile, Wlc_Ntk_t * p, Vec_Int_t * vVec, int Start )
{
char * pName;
int LineLength = Start;
int NameCounter = 0;
int AddedLength, i, iObj;
Vec_IntForEachEntry( vVec, iObj, i )
{
pName = Wlc_ObjName( p, iObj );
// get the line length after this name is written
AddedLength = strlen(pName) + 2;
if ( NameCounter && LineLength + AddedLength + 3 > 70 )
{ // write the line extender
fprintf( pFile, "\n " );
// reset the line length
LineLength = Start;
NameCounter = 0;
}
fprintf( pFile, " %s%s", pName, (i==Vec_IntSize(vVec)-1)? "" : "," );
LineLength += AddedLength;
NameCounter++;
}
}
void Wlc_WriteVerInt( FILE * pFile, Wlc_Ntk_t * p )
{
Wlc_Obj_t * pObj;
int i, k, iFanin;
char Range[100];
fprintf( pFile, "module %s ( ", p->pName );
fprintf( pFile, "\n " );
if ( Wlc_NtkPiNum(p) > 0 )
{
Wlc_WriteVerIntVec( pFile, p, &p->vPis, 3 );
fprintf( pFile, ",\n " );
}
if ( Wlc_NtkPoNum(p) > 0 )
Wlc_WriteVerIntVec( pFile, p, &p->vPos, 3 );
fprintf( pFile, " );\n" );
Wlc_NtkForEachObj( p, pObj, i )
{
char * pName = Wlc_ObjName(p, i);
char * pName0 = Wlc_ObjFaninNum(pObj) ? Wlc_ObjName(p, Wlc_ObjFaninId0(pObj)) : NULL;
int nDigits = Abc_Base10Log(pObj->End+1) + Abc_Base10Log(pObj->Beg+1);
sprintf( Range, "%s[%d:%d]%*s", pObj->Signed ? "signed ":" ", pObj->End, pObj->Beg, 8-nDigits, "" );
fprintf( pFile, " " );
if ( pObj->Type == WLC_OBJ_PI )
fprintf( pFile, "input wire %s %-16s", Range, pName );
else if ( pObj->Type == WLC_OBJ_PO )
fprintf( pFile, "output wire %s %-16s = %s", Range, pName, pName0 );
else if ( pObj->Type == WLC_OBJ_CONST )
{
fprintf( pFile, " wire %s %-16s = %d\'%sh", Range, pName, Wlc_ObjRange(pObj), pObj->Signed ? "s":"" );
Abc_TtPrintHexArrayRev( pFile, (word *)Wlc_ObjConstValue(pObj), (Wlc_ObjRange(pObj) + 3) / 4 );
}
else
{
fprintf( pFile, " wire %s %-16s = ", Range, Wlc_ObjName(p, i) );
if ( pObj->Type == WLC_OBJ_BUF )
fprintf( pFile, "%s", pName0 );
else if ( pObj->Type == WLC_OBJ_MUX )
fprintf( pFile, "%s ? %s : %s", pName0, Wlc_ObjName(p, Wlc_ObjFaninId1(pObj)), Wlc_ObjName(p, Wlc_ObjFaninId2(pObj)) );
else if ( pObj->Type == WLC_OBJ_BIT_NOT )
fprintf( pFile, "~%s", pName0 );
else if ( pObj->Type == WLC_OBJ_LOGIC_NOT )
fprintf( pFile, "!%s", pName0 );
else if ( pObj->Type == WLC_OBJ_REDUCT_AND )
fprintf( pFile, "&%s", pName0 );
else if ( pObj->Type == WLC_OBJ_REDUCT_OR )
fprintf( pFile, "|%s", pName0 );
else if ( pObj->Type == WLC_OBJ_REDUCT_XOR )
fprintf( pFile, "^%s", pName0 );
else if ( pObj->Type == WLC_OBJ_BIT_SELECT )
fprintf( pFile, "%s [%d:%d]", pName0, Wlc_ObjRangeEnd(pObj), Wlc_ObjRangeBeg(pObj) );
else if ( pObj->Type == WLC_OBJ_BIT_SIGNEXT )
fprintf( pFile, "{ {%d{%s[%d]}}, %s }", Wlc_ObjRange(pObj) - Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)), pName0, Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)) - 1, pName0 );
else if ( pObj->Type == WLC_OBJ_BIT_ZEROPAD )
fprintf( pFile, "{ {%d{1\'b0}}, %s }", Wlc_ObjRange(pObj) - Wlc_ObjRange(Wlc_ObjFanin0(p, pObj)), pName0 );
else if ( pObj->Type == WLC_OBJ_BIT_CONCAT )
{
fprintf( pFile, "{" );
Wlc_ObjForEachFanin( pObj, iFanin, k )
fprintf( pFile, " %s%s", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, k)), k == Wlc_ObjFaninNum(pObj)-1 ? "":"," );
fprintf( pFile, " }" );
}
else
{
fprintf( pFile, "%s ", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 0)) );
if ( pObj->Type == WLC_OBJ_SHIFT_R )
fprintf( pFile, ">>" );
else if ( pObj->Type == WLC_OBJ_SHIFT_RA )
fprintf( pFile, ">>>" );
else if ( pObj->Type == WLC_OBJ_SHIFT_L )
fprintf( pFile, "<<" );
else if ( pObj->Type == WLC_OBJ_SHIFT_LA )
fprintf( pFile, "<<<" );
else if ( pObj->Type == WLC_OBJ_BIT_AND )
fprintf( pFile, "&" );
else if ( pObj->Type == WLC_OBJ_BIT_OR )
fprintf( pFile, "|" );
else if ( pObj->Type == WLC_OBJ_BIT_XOR )
fprintf( pFile, "^" );
else if ( pObj->Type == WLC_OBJ_LOGIC_AND )
fprintf( pFile, "&&" );
else if ( pObj->Type == WLC_OBJ_LOGIC_OR )
fprintf( pFile, "||" );
else if ( pObj->Type == WLC_OBJ_COMP_EQU )
fprintf( pFile, "==" );
else if ( pObj->Type == WLC_OBJ_COMP_NOT )
fprintf( pFile, "!=" );
else if ( pObj->Type == WLC_OBJ_COMP_LESS )
fprintf( pFile, "<" );
else if ( pObj->Type == WLC_OBJ_COMP_MORE )
fprintf( pFile, ">" );
else if ( pObj->Type == WLC_OBJ_COMP_LESSEQU )
fprintf( pFile, "<=" );
else if ( pObj->Type == WLC_OBJ_COMP_MOREEQU )
fprintf( pFile, ">=" );
else if ( pObj->Type == WLC_OBJ_ARI_ADD )
fprintf( pFile, "+" );
else if ( pObj->Type == WLC_OBJ_ARI_SUB )
fprintf( pFile, "-" );
else if ( pObj->Type == WLC_OBJ_ARI_MULTI )
fprintf( pFile, "*" );
else if ( pObj->Type == WLC_OBJ_ARI_DIVIDE )
fprintf( pFile, "//" );
else if ( pObj->Type == WLC_OBJ_ARI_MODULUS )
fprintf( pFile, "%" );
else if ( pObj->Type == WLC_OBJ_ARI_POWER )
fprintf( pFile, "**" );
else assert( 0 );
fprintf( pFile, " %s", Wlc_ObjName(p, Wlc_ObjFaninId(pObj, 1)) );
}
}
fprintf( pFile, " ;\n" );
}
fprintf( pFile, "endmodule\n\n" );
}
void Wlc_WriteVer( Wlc_Ntk_t * p, char * pFileName )
{
FILE * pFile;
pFile = fopen( pFileName, "w" );
if ( pFile == NULL )
{
fprintf( stdout, "Wlc_WriteVer(): Cannot open the output file \"%s\".\n", pFileName );
return;
}
fprintf( pFile, "// Benchmark \"%s\" written by ABC on %s\n", p->pName, Extra_TimeStamp() );
fprintf( pFile, "\n" );
Wlc_WriteVerInt( pFile, p );
fprintf( pFile, "\n" );
fclose( pFile );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
......@@ -732,6 +732,13 @@ static inline char Abc_TtPrintDigit( int Digit )
return '0' + Digit;
return 'A' + Digit-10;
}
static inline char Abc_TtPrintDigitLower( int Digit )
{
assert( Digit >= 0 && Digit < 16 );
if ( Digit < 10 )
return '0' + Digit;
return 'a' + Digit-10;
}
static inline int Abc_TtReadHexDigit( char HexChar )
{
if ( HexChar >= '0' && HexChar <= '9' )
......@@ -796,6 +803,12 @@ static inline int Abc_TtWriteHexRev( char * pStr, word * pTruth, int nVars )
*pStr++ = Abc_TtPrintDigit( (int)(pThis[0] >> (k << 2)) & 15 );
return pStr - pStrInit;
}
static inline void Abc_TtPrintHexArrayRev( FILE * pFile, word * pTruth, int nDigits )
{
int k;
for ( k = nDigits - 1; k >= 0; k-- )
fprintf( pFile, "%c", Abc_TtPrintDigitLower( Abc_TtGetHex(pTruth, k) ) );
}
/**Function*************************************************************
......@@ -848,6 +861,22 @@ static inline int Abc_TtReadHex( word * pTruth, char * pString )
pTruth[0] = Abc_Tt6Stretch( pTruth[0], nVars );
return nVars;
}
static inline int Abc_TtReadHexNumber( word * pTruth, char * pString )
{
// count the number of hex digits
int k, Digit, nDigits = 0;
for ( k = 0; Abc_TtIsHexDigit(pString[k]); k++ )
nDigits++;
// read hexadecimal digits in the reverse order
// (the last symbol in the string is the least significant digit)
for ( k = 0; k < nDigits; k++ )
{
Digit = Abc_TtReadHexDigit( pString[nDigits - 1 - k] );
assert( Digit >= 0 && Digit < 16 );
Abc_TtSetHex( pTruth, k, Digit );
}
return nDigits;
}
/**Function*************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment